blob: c0bb32414b174d575f836c9eb779f2e30cb793dd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080027#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070029#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020031#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020040#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070041#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070044#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/times.h>
46#include <linux/limits.h>
47#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020048#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070050#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080051#include <linux/nfs_fs.h>
52#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070053#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020054#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020055#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050056#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020057#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070058#include <linux/oom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#include <asm/uaccess.h>
61#include <asm/processor.h>
62
Andi Kleen29cbc782006-09-30 01:47:55 +020063#ifdef CONFIG_X86
64#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010065#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010066#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020067#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080068#ifdef CONFIG_BSD_PROCESS_ACCT
69#include <linux/acct.h>
70#endif
Dave Young4f0e0562010-03-10 15:24:09 -080071#ifdef CONFIG_RT_MUTEXES
72#include <linux/rtmutex.h>
73#endif
Dave Young2edf5e42010-03-10 15:24:10 -080074#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75#include <linux/lockdep.h>
76#endif
Dave Young15485a42010-03-10 15:24:07 -080077#ifdef CONFIG_CHR_DEV_SG
78#include <scsi/sg.h>
79#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020080
Don Zickus58687ac2010-05-07 17:11:44 -040081#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050082#include <linux/nmi.h>
83#endif
84
Eric W. Biederman7058cb02007-10-18 03:05:58 -070085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#if defined(CONFIG_SYSCTL)
87
88/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089extern int sysctl_overcommit_memory;
90extern int sysctl_overcommit_ratio;
91extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070093extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070095extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern int pid_max;
97extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080099extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800100extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200101extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100102extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400103extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000104#ifndef CONFIG_MMU
105extern int sysctl_nr_trim_pages;
106#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200107#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200108extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400112#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200114static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115#endif
116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700118static int __maybe_unused one = 1;
119static int __maybe_unused two = 2;
Petr Holasekcb16e952011-03-23 16:43:09 -0700120static int __maybe_unused three = 3;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800121static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700123#ifdef CONFIG_PRINTK
124static int ten_thousand = 10000;
125#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700126
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700127/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
128static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
131static int maxolduid = 65535;
132static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800133static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135static int ngroups_max = NGROUPS_MAX;
136
Dave Youngd14f1722010-02-25 20:28:57 -0500137#ifdef CONFIG_INOTIFY_USER
138#include <linux/inotify.h>
139#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700140#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700141#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif
143
David S. Miller08714202008-11-16 23:49:24 -0800144#ifdef CONFIG_SPARC64
145extern int sysctl_tsb_ratio;
146#endif
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#ifdef __hppa__
149extern int pwrsw_enabled;
150extern int unaligned_enabled;
151#endif
152
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800153#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154#ifdef CONFIG_MATHEMU
155extern int sysctl_ieee_emulation_warnings;
156#endif
157extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700158extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#endif
160
Jes Sorensend2b176e2006-02-28 09:42:23 -0800161#ifdef CONFIG_IA64
162extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800163extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800164#endif
165
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700166#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700168 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700169static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800170 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700171#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700172
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700173#ifdef CONFIG_PRINTK
174static int proc_dmesg_restrict(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
176#endif
177
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700178#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800179/* Note: sysrq code uses it's own private copy */
180static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700181
182static int sysrq_sysctl_handler(ctl_table *table, int write,
183 void __user *buffer, size_t *lenp,
184 loff_t *ppos)
185{
186 int error;
187
188 error = proc_dointvec(table, write, buffer, lenp, ppos);
189 if (error)
190 return error;
191
192 if (write)
193 sysrq_toggle_support(__sysrq_enabled);
194
195 return 0;
196}
197
198#endif
199
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700200static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100201static struct ctl_table_root sysctl_table_root;
202static struct ctl_table_header root_table_header = {
Al Virodfef6dcd32011-03-08 01:25:28 -0500203 {{.count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100204 .ctl_table = root_table,
Al Virodfef6dcd32011-03-08 01:25:28 -0500205 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100206 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400207 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100208};
209static struct ctl_table_root sysctl_table_root = {
210 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400211 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100212};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700214static struct ctl_table kern_table[];
215static struct ctl_table vm_table[];
216static struct ctl_table fs_table[];
217static struct ctl_table debug_table[];
218static struct ctl_table dev_table[];
219extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800220#ifdef CONFIG_EPOLL
221extern struct ctl_table epoll_table[];
222#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
225int sysctl_legacy_va_layout;
226#endif
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228/* The default sysctl tables: */
229
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700230static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 .procname = "kernel",
233 .mode = 0555,
234 .child = kern_table,
235 },
236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "vm",
238 .mode = 0555,
239 .child = vm_table,
240 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .procname = "fs",
243 .mode = 0555,
244 .child = fs_table,
245 },
246 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .procname = "debug",
248 .mode = 0555,
249 .child = debug_table,
250 },
251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 .procname = "dev",
253 .mode = 0555,
254 .child = dev_table,
255 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700256 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257};
258
Ingo Molnar77e54a12007-07-09 18:52:00 +0200259#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100260static int min_sched_granularity_ns = 100000; /* 100 usecs */
261static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
262static int min_wakeup_granularity_ns; /* 0 usecs */
263static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100264static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
265static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200266#endif
267
Mel Gorman5e771902010-05-24 14:32:31 -0700268#ifdef CONFIG_COMPACTION
269static int min_extfrag_threshold;
270static int max_extfrag_threshold = 1000;
271#endif
272
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700273static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200274 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200275 .procname = "sched_child_runs_first",
276 .data = &sysctl_sched_child_runs_first,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800279 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200280 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200281#ifdef CONFIG_SCHED_DEBUG
282 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100283 .procname = "sched_min_granularity_ns",
284 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800287 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200290 },
291 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200292 .procname = "sched_latency_ns",
293 .data = &sysctl_sched_latency,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800296 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200297 .extra1 = &min_sched_granularity_ns,
298 .extra2 = &max_sched_granularity_ns,
299 },
300 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301 .procname = "sched_wakeup_granularity_ns",
302 .data = &sysctl_sched_wakeup_granularity,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800305 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200306 .extra1 = &min_wakeup_granularity_ns,
307 .extra2 = &max_wakeup_granularity_ns,
308 },
309 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100310 .procname = "sched_tunable_scaling",
311 .data = &sysctl_sched_tunable_scaling,
312 .maxlen = sizeof(enum sched_tunable_scaling),
313 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800314 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100315 .extra1 = &min_sched_tunable_scaling,
316 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200317 },
318 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200319 .procname = "sched_migration_cost",
320 .data = &sysctl_sched_migration_cost,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800323 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200324 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100325 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100326 .procname = "sched_nr_migrate",
327 .data = &sysctl_sched_nr_migrate,
328 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800330 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100331 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530332 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200333 .procname = "sched_time_avg",
334 .data = &sysctl_sched_time_avg,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800337 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200338 },
339 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800340 .procname = "sched_shares_window",
341 .data = &sysctl_sched_shares_window,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = proc_dointvec,
345 },
346 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530347 .procname = "timer_migration",
348 .data = &sysctl_timer_migration,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800351 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530352 .extra1 = &zero,
353 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530354 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200355#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200356 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100357 .procname = "sched_rt_period_us",
358 .data = &sysctl_sched_rt_period,
359 .maxlen = sizeof(unsigned int),
360 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800361 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100362 },
363 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100364 .procname = "sched_rt_runtime_us",
365 .data = &sysctl_sched_rt_runtime,
366 .maxlen = sizeof(int),
367 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800368 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100369 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100370#ifdef CONFIG_SCHED_AUTOGROUP
371 {
372 .procname = "sched_autogroup_enabled",
373 .data = &sysctl_sched_autogroup_enabled,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800376 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100377 .extra1 = &zero,
378 .extra2 = &one,
379 },
380#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700381#ifdef CONFIG_PROVE_LOCKING
382 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700383 .procname = "prove_locking",
384 .data = &prove_locking,
385 .maxlen = sizeof(int),
386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800387 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700388 },
389#endif
390#ifdef CONFIG_LOCK_STAT
391 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700392 .procname = "lock_stat",
393 .data = &lock_stat,
394 .maxlen = sizeof(int),
395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800396 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700397 },
398#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .procname = "panic",
401 .data = &panic_timeout,
402 .maxlen = sizeof(int),
403 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800404 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 },
406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 .procname = "core_uses_pid",
408 .data = &core_uses_pid,
409 .maxlen = sizeof(int),
410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800411 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 },
413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 .procname = "core_pattern",
415 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700416 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800418 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 },
Neil Hormana2939802009-09-23 15:56:56 -0700420 {
Neil Hormana2939802009-09-23 15:56:56 -0700421 .procname = "core_pipe_limit",
422 .data = &core_pipe_limit,
423 .maxlen = sizeof(unsigned int),
424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800425 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700426 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800427#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700430 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800432 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800434#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100435#ifdef CONFIG_LATENCYTOP
436 {
437 .procname = "latencytop",
438 .data = &latencytop_enabled,
439 .maxlen = sizeof(int),
440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800441 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100442 },
443#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#ifdef CONFIG_BLK_DEV_INITRD
445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .procname = "real-root-dev",
447 .data = &real_root_dev,
448 .maxlen = sizeof(int),
449 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800450 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 },
452#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700453 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700454 .procname = "print-fatal-signals",
455 .data = &print_fatal_signals,
456 .maxlen = sizeof(int),
457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800458 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700459 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700460#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 .procname = "reboot-cmd",
463 .data = reboot_command,
464 .maxlen = 256,
465 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800466 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 },
468 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 .procname = "stop-a",
470 .data = &stop_a_enabled,
471 .maxlen = sizeof (int),
472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800473 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 },
475 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 .procname = "scons-poweroff",
477 .data = &scons_pwroff,
478 .maxlen = sizeof (int),
479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800480 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 },
482#endif
David S. Miller08714202008-11-16 23:49:24 -0800483#ifdef CONFIG_SPARC64
484 {
David S. Miller08714202008-11-16 23:49:24 -0800485 .procname = "tsb-ratio",
486 .data = &sysctl_tsb_ratio,
487 .maxlen = sizeof (int),
488 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800489 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800490 },
491#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#ifdef __hppa__
493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .procname = "soft-power",
495 .data = &pwrsw_enabled,
496 .maxlen = sizeof (int),
497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800498 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 },
500 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .procname = "unaligned-trap",
502 .data = &unaligned_enabled,
503 .maxlen = sizeof (int),
504 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800505 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 },
507#endif
508 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .procname = "ctrl-alt-del",
510 .data = &C_A_D,
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 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400515#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200516 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200517 .procname = "ftrace_enabled",
518 .data = &ftrace_enabled,
519 .maxlen = sizeof(int),
520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800521 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200522 },
523#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500524#ifdef CONFIG_STACK_TRACER
525 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500526 .procname = "stack_tracer_enabled",
527 .data = &stack_tracer_enabled,
528 .maxlen = sizeof(int),
529 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800530 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500531 },
532#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400533#ifdef CONFIG_TRACING
534 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100535 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400536 .data = &ftrace_dump_on_oops,
537 .maxlen = sizeof(int),
538 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800539 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400540 },
541#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200542#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .procname = "modprobe",
545 .data = &modprobe_path,
546 .maxlen = KMOD_PATH_LEN,
547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800548 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 },
Kees Cook3d433212009-04-02 15:49:29 -0700550 {
Kees Cook3d433212009-04-02 15:49:29 -0700551 .procname = "modules_disabled",
552 .data = &modules_disabled,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700557 .extra1 = &one,
558 .extra2 = &one,
559 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100561#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100564 .data = &uevent_helper,
565 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800567 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 },
569#endif
570#ifdef CONFIG_CHR_DEV_SG
571 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .procname = "sg-big-buff",
573 .data = &sg_big_buff,
574 .maxlen = sizeof (int),
575 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800576 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 },
578#endif
579#ifdef CONFIG_BSD_PROCESS_ACCT
580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "acct",
582 .data = &acct_parm,
583 .maxlen = 3*sizeof(int),
584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800585 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
587#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#ifdef CONFIG_MAGIC_SYSRQ
589 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800591 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .maxlen = sizeof (int),
593 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700594 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 },
596#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700597#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700600 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .maxlen = sizeof (int),
602 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800603 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700605#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 .procname = "threads-max",
608 .data = &max_threads,
609 .maxlen = sizeof(int),
610 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800611 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 },
613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 .procname = "random",
615 .mode = 0555,
616 .child = random_table,
617 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .procname = "overflowuid",
620 .data = &overflowuid,
621 .maxlen = sizeof(int),
622 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800623 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 .extra1 = &minolduid,
625 .extra2 = &maxolduid,
626 },
627 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 .procname = "overflowgid",
629 .data = &overflowgid,
630 .maxlen = sizeof(int),
631 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800632 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 .extra1 = &minolduid,
634 .extra2 = &maxolduid,
635 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800636#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#ifdef CONFIG_MATHEMU
638 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 .procname = "ieee_emulation_warnings",
640 .data = &sysctl_ieee_emulation_warnings,
641 .maxlen = sizeof(int),
642 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800643 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 },
645#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200648 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .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
654 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 .procname = "pid_max",
656 .data = &pid_max,
657 .maxlen = sizeof (int),
658 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800659 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 .extra1 = &pid_max_min,
661 .extra2 = &pid_max_max,
662 },
663 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 .procname = "panic_on_oops",
665 .data = &panic_on_oops,
666 .maxlen = sizeof(int),
667 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800668 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800670#if defined CONFIG_PRINTK
671 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800672 .procname = "printk",
673 .data = &console_loglevel,
674 .maxlen = 4*sizeof(int),
675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800676 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800677 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700680 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 .maxlen = sizeof(int),
682 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800683 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 },
685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700687 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .maxlen = sizeof(int),
689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800690 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 },
Dave Youngaf913222009-09-22 16:43:33 -0700692 {
Dave Youngaf913222009-09-22 16:43:33 -0700693 .procname = "printk_delay",
694 .data = &printk_delay_msec,
695 .maxlen = sizeof(int),
696 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800697 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700698 .extra1 = &zero,
699 .extra2 = &ten_thousand,
700 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800702 .procname = "dmesg_restrict",
703 .data = &dmesg_restrict,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 .proc_handler = proc_dointvec_minmax,
707 .extra1 = &zero,
708 .extra2 = &one,
709 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800710 {
711 .procname = "kptr_restrict",
712 .data = &kptr_restrict,
713 .maxlen = sizeof(int),
714 .mode = 0644,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700715 .proc_handler = proc_dmesg_restrict,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800716 .extra1 = &zero,
717 .extra2 = &two,
718 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800719#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .procname = "ngroups_max",
722 .data = &ngroups_max,
723 .maxlen = sizeof (int),
724 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800725 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 },
Don Zickus58687ac2010-05-07 17:11:44 -0400727#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500728 {
Don Zickus58687ac2010-05-07 17:11:44 -0400729 .procname = "watchdog",
730 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500731 .maxlen = sizeof (int),
732 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400733 .proc_handler = proc_dowatchdog_enabled,
734 },
735 {
736 .procname = "watchdog_thresh",
737 .data = &softlockup_thresh,
738 .maxlen = sizeof(int),
739 .mode = 0644,
740 .proc_handler = proc_dowatchdog_thresh,
741 .extra1 = &neg_one,
742 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500743 },
Don Zickus2508ce12010-05-07 17:11:46 -0400744 {
745 .procname = "softlockup_panic",
746 .data = &softlockup_panic,
747 .maxlen = sizeof(int),
748 .mode = 0644,
749 .proc_handler = proc_dointvec_minmax,
750 .extra1 = &zero,
751 .extra2 = &one,
752 },
Don Zickus5dc30552010-11-29 17:07:17 -0500753 {
754 .procname = "nmi_watchdog",
755 .data = &watchdog_enabled,
756 .maxlen = sizeof (int),
757 .mode = 0644,
758 .proc_handler = proc_dowatchdog_enabled,
759 },
760#endif
761#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
762 {
763 .procname = "unknown_nmi_panic",
764 .data = &unknown_nmi_panic,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = proc_dointvec,
768 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500769#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770#if defined(CONFIG_X86)
771 {
Don Zickus8da5add2006-09-26 10:52:27 +0200772 .procname = "panic_on_unrecovered_nmi",
773 .data = &panic_on_unrecovered_nmi,
774 .maxlen = sizeof(int),
775 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800776 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200777 },
778 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700779 .procname = "panic_on_io_nmi",
780 .data = &panic_on_io_nmi,
781 .maxlen = sizeof(int),
782 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800783 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700784 },
785 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 .procname = "bootloader_type",
787 .data = &bootloader_type,
788 .maxlen = sizeof (int),
789 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800790 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100792 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700793 .procname = "bootloader_version",
794 .data = &bootloader_version,
795 .maxlen = sizeof (int),
796 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800797 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700798 },
799 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100800 .procname = "kstack_depth_to_print",
801 .data = &kstack_depth_to_print,
802 .maxlen = sizeof(int),
803 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800804 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100805 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100806 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100807 .procname = "io_delay_type",
808 .data = &io_delay_type,
809 .maxlen = sizeof(int),
810 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800811 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100812 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800814#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 .procname = "randomize_va_space",
817 .data = &randomize_va_space,
818 .maxlen = sizeof(int),
819 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800820 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800822#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800823#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700824 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700825 .procname = "spin_retry",
826 .data = &spin_retry,
827 .maxlen = sizeof (int),
828 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800829 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700830 },
831#endif
Len Brown673d5b42007-07-28 03:33:16 -0400832#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800833 {
Pavel Machekc255d842006-02-20 18:27:58 -0800834 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700835 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800836 .maxlen = sizeof (unsigned long),
837 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800838 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800839 },
840#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800841#ifdef CONFIG_IA64
842 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800843 .procname = "ignore-unaligned-usertrap",
844 .data = &no_unaligned_warning,
845 .maxlen = sizeof (int),
846 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800847 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800848 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800849 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800850 .procname = "unaligned-dump-stack",
851 .data = &unaligned_dump_stack,
852 .maxlen = sizeof (int),
853 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800854 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800855 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800856#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800857#ifdef CONFIG_DETECT_HUNG_TASK
858 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800859 .procname = "hung_task_panic",
860 .data = &sysctl_hung_task_panic,
861 .maxlen = sizeof(int),
862 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800863 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800864 .extra1 = &zero,
865 .extra2 = &one,
866 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100867 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 .procname = "hung_task_check_count",
869 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100870 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100871 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800872 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100873 },
874 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100875 .procname = "hung_task_timeout_secs",
876 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100877 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100878 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800879 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100880 },
881 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100882 .procname = "hung_task_warnings",
883 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100884 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100885 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800886 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100887 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700888#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200889#ifdef CONFIG_COMPAT
890 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200891 .procname = "compat-log",
892 .data = &compat_log,
893 .maxlen = sizeof (int),
894 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800895 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200896 },
897#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700898#ifdef CONFIG_RT_MUTEXES
899 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700900 .procname = "max_lock_depth",
901 .data = &max_lock_depth,
902 .maxlen = sizeof(int),
903 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800904 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700905 },
906#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700907 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700908 .procname = "poweroff_cmd",
909 .data = &poweroff_cmd,
910 .maxlen = POWEROFF_CMD_PATH_LEN,
911 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800912 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700913 },
David Howells0b77f5b2008-04-29 01:01:32 -0700914#ifdef CONFIG_KEYS
915 {
David Howells0b77f5b2008-04-29 01:01:32 -0700916 .procname = "keys",
917 .mode = 0555,
918 .child = key_sysctls,
919 },
920#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700921#ifdef CONFIG_RCU_TORTURE_TEST
922 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700923 .procname = "rcutorture_runnable",
924 .data = &rcutorture_runnable,
925 .maxlen = sizeof(int),
926 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800927 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700928 },
929#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200930#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200931 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200932 .procname = "perf_event_paranoid",
933 .data = &sysctl_perf_event_paranoid,
934 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200935 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800936 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200937 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200938 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200939 .procname = "perf_event_mlock_kb",
940 .data = &sysctl_perf_event_mlock,
941 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200942 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800943 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200944 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200945 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200946 .procname = "perf_event_max_sample_rate",
947 .data = &sysctl_perf_event_sample_rate,
948 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200949 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +0100950 .proc_handler = perf_proc_update_handler,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200951 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200952#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200953#ifdef CONFIG_KMEMCHECK
954 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200955 .procname = "kmemcheck",
956 .data = &kmemcheck_enabled,
957 .maxlen = sizeof(int),
958 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800959 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200960 },
961#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200962#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200963 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200964 .procname = "blk_iopoll",
965 .data = &blk_iopoll_enabled,
966 .maxlen = sizeof(int),
967 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800968 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200969 },
Jens Axboecb684b52009-09-15 21:53:11 +0200970#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700971 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972};
973
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700974static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 .procname = "overcommit_memory",
977 .data = &sysctl_overcommit_memory,
978 .maxlen = sizeof(sysctl_overcommit_memory),
979 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -0700980 .proc_handler = proc_dointvec_minmax,
981 .extra1 = &zero,
982 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 },
984 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700985 .procname = "panic_on_oom",
986 .data = &sysctl_panic_on_oom,
987 .maxlen = sizeof(sysctl_panic_on_oom),
988 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -0700989 .proc_handler = proc_dointvec_minmax,
990 .extra1 = &zero,
991 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700992 },
993 {
David Rientjesfe071d72007-10-16 23:25:56 -0700994 .procname = "oom_kill_allocating_task",
995 .data = &sysctl_oom_kill_allocating_task,
996 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
997 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800998 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700999 },
1000 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001001 .procname = "oom_dump_tasks",
1002 .data = &sysctl_oom_dump_tasks,
1003 .maxlen = sizeof(sysctl_oom_dump_tasks),
1004 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001005 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001006 },
1007 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 .procname = "overcommit_ratio",
1009 .data = &sysctl_overcommit_ratio,
1010 .maxlen = sizeof(sysctl_overcommit_ratio),
1011 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001012 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 },
1014 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .procname = "page-cluster",
1016 .data = &page_cluster,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001019 .proc_handler = proc_dointvec_minmax,
1020 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 },
1022 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 .procname = "dirty_background_ratio",
1024 .data = &dirty_background_ratio,
1025 .maxlen = sizeof(dirty_background_ratio),
1026 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001027 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 .extra1 = &zero,
1029 .extra2 = &one_hundred,
1030 },
1031 {
David Rientjes2da02992009-01-06 14:39:31 -08001032 .procname = "dirty_background_bytes",
1033 .data = &dirty_background_bytes,
1034 .maxlen = sizeof(dirty_background_bytes),
1035 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001036 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001037 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001038 },
1039 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .procname = "dirty_ratio",
1041 .data = &vm_dirty_ratio,
1042 .maxlen = sizeof(vm_dirty_ratio),
1043 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001044 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 .extra1 = &zero,
1046 .extra2 = &one_hundred,
1047 },
1048 {
David Rientjes2da02992009-01-06 14:39:31 -08001049 .procname = "dirty_bytes",
1050 .data = &vm_dirty_bytes,
1051 .maxlen = sizeof(vm_dirty_bytes),
1052 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001054 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001055 },
1056 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001058 .data = &dirty_writeback_interval,
1059 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001061 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 },
1063 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001065 .data = &dirty_expire_interval,
1066 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001068 .proc_handler = proc_dointvec_minmax,
1069 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 },
1071 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 .procname = "nr_pdflush_threads",
1073 .data = &nr_pdflush_threads,
1074 .maxlen = sizeof nr_pdflush_threads,
1075 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001076 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 },
1078 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 .procname = "swappiness",
1080 .data = &vm_swappiness,
1081 .maxlen = sizeof(vm_swappiness),
1082 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001083 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 .extra1 = &zero,
1085 .extra2 = &one_hundred,
1086 },
1087#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001088 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001090 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 .maxlen = sizeof(unsigned long),
1092 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001093 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 .extra1 = (void *)&hugetlb_zero,
1095 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001096 },
1097#ifdef CONFIG_NUMA
1098 {
1099 .procname = "nr_hugepages_mempolicy",
1100 .data = NULL,
1101 .maxlen = sizeof(unsigned long),
1102 .mode = 0644,
1103 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1104 .extra1 = (void *)&hugetlb_zero,
1105 .extra2 = (void *)&hugetlb_infinity,
1106 },
1107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 .procname = "hugetlb_shm_group",
1110 .data = &sysctl_hugetlb_shm_group,
1111 .maxlen = sizeof(gid_t),
1112 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001113 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 },
Mel Gorman396faf02007-07-17 04:03:13 -07001115 {
Mel Gorman396faf02007-07-17 04:03:13 -07001116 .procname = "hugepages_treat_as_movable",
1117 .data = &hugepages_treat_as_movable,
1118 .maxlen = sizeof(int),
1119 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001120 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001121 },
Adam Litke54f9f802007-10-16 01:26:20 -07001122 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001123 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001124 .data = NULL,
1125 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001126 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001127 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001128 .extra1 = (void *)&hugetlb_zero,
1129 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001130 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131#endif
1132 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 .procname = "lowmem_reserve_ratio",
1134 .data = &sysctl_lowmem_reserve_ratio,
1135 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1136 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001137 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 },
1139 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001140 .procname = "drop_caches",
1141 .data = &sysctl_drop_caches,
1142 .maxlen = sizeof(int),
1143 .mode = 0644,
1144 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001145 .extra1 = &one,
1146 .extra2 = &three,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001147 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001148#ifdef CONFIG_COMPACTION
1149 {
1150 .procname = "compact_memory",
1151 .data = &sysctl_compact_memory,
1152 .maxlen = sizeof(int),
1153 .mode = 0200,
1154 .proc_handler = sysctl_compaction_handler,
1155 },
Mel Gorman5e771902010-05-24 14:32:31 -07001156 {
1157 .procname = "extfrag_threshold",
1158 .data = &sysctl_extfrag_threshold,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = sysctl_extfrag_handler,
1162 .extra1 = &min_extfrag_threshold,
1163 .extra2 = &max_extfrag_threshold,
1164 },
1165
Mel Gorman76ab0f52010-05-24 14:32:28 -07001166#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001167 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 .procname = "min_free_kbytes",
1169 .data = &min_free_kbytes,
1170 .maxlen = sizeof(min_free_kbytes),
1171 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001172 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 .extra1 = &zero,
1174 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001175 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001176 .procname = "percpu_pagelist_fraction",
1177 .data = &percpu_pagelist_fraction,
1178 .maxlen = sizeof(percpu_pagelist_fraction),
1179 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001180 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001181 .extra1 = &min_percpu_pagelist_fract,
1182 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183#ifdef CONFIG_MMU
1184 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 .procname = "max_map_count",
1186 .data = &sysctl_max_map_count,
1187 .maxlen = sizeof(sysctl_max_map_count),
1188 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001189 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001190 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001192#else
1193 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001194 .procname = "nr_trim_pages",
1195 .data = &sysctl_nr_trim_pages,
1196 .maxlen = sizeof(sysctl_nr_trim_pages),
1197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001198 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001199 .extra1 = &zero,
1200 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201#endif
1202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 .procname = "laptop_mode",
1204 .data = &laptop_mode,
1205 .maxlen = sizeof(laptop_mode),
1206 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001207 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 },
1209 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 .procname = "block_dump",
1211 .data = &block_dump,
1212 .maxlen = sizeof(block_dump),
1213 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001214 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 .extra1 = &zero,
1216 },
1217 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .procname = "vfs_cache_pressure",
1219 .data = &sysctl_vfs_cache_pressure,
1220 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1221 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001222 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 .extra1 = &zero,
1224 },
1225#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .procname = "legacy_va_layout",
1228 .data = &sysctl_legacy_va_layout,
1229 .maxlen = sizeof(sysctl_legacy_va_layout),
1230 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001231 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 .extra1 = &zero,
1233 },
1234#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001235#ifdef CONFIG_NUMA
1236 {
Christoph Lameter17436602006-01-18 17:42:32 -08001237 .procname = "zone_reclaim_mode",
1238 .data = &zone_reclaim_mode,
1239 .maxlen = sizeof(zone_reclaim_mode),
1240 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001241 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001242 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001243 },
Christoph Lameter96146342006-07-03 00:24:13 -07001244 {
Christoph Lameter96146342006-07-03 00:24:13 -07001245 .procname = "min_unmapped_ratio",
1246 .data = &sysctl_min_unmapped_ratio,
1247 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1248 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001249 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001250 .extra1 = &zero,
1251 .extra2 = &one_hundred,
1252 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001253 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001254 .procname = "min_slab_ratio",
1255 .data = &sysctl_min_slab_ratio,
1256 .maxlen = sizeof(sysctl_min_slab_ratio),
1257 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001258 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001259 .extra1 = &zero,
1260 .extra2 = &one_hundred,
1261 },
Christoph Lameter17436602006-01-18 17:42:32 -08001262#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001263#ifdef CONFIG_SMP
1264 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001265 .procname = "stat_interval",
1266 .data = &sysctl_stat_interval,
1267 .maxlen = sizeof(sysctl_stat_interval),
1268 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001269 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001270 },
1271#endif
David Howells6e141542009-12-15 19:27:45 +00001272#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001273 {
Eric Parised032182007-06-28 15:55:21 -04001274 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001275 .data = &dac_mmap_min_addr,
1276 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001277 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001278 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001279 },
David Howells6e141542009-12-15 19:27:45 +00001280#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001281#ifdef CONFIG_NUMA
1282 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001283 .procname = "numa_zonelist_order",
1284 .data = &numa_zonelist_order,
1285 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1286 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001287 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001288 },
1289#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001290#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001291 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001292 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001293 .procname = "vdso_enabled",
1294 .data = &vdso_enabled,
1295 .maxlen = sizeof(vdso_enabled),
1296 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001297 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001298 .extra1 = &zero,
1299 },
1300#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001301#ifdef CONFIG_HIGHMEM
1302 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001303 .procname = "highmem_is_dirtyable",
1304 .data = &vm_highmem_is_dirtyable,
1305 .maxlen = sizeof(vm_highmem_is_dirtyable),
1306 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001307 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001308 .extra1 = &zero,
1309 .extra2 = &one,
1310 },
1311#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001312 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001313 .procname = "scan_unevictable_pages",
1314 .data = &scan_unevictable_pages,
1315 .maxlen = sizeof(scan_unevictable_pages),
1316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001317 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001318 },
Andi Kleen6a460792009-09-16 11:50:15 +02001319#ifdef CONFIG_MEMORY_FAILURE
1320 {
Andi Kleen6a460792009-09-16 11:50:15 +02001321 .procname = "memory_failure_early_kill",
1322 .data = &sysctl_memory_failure_early_kill,
1323 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1324 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001325 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001326 .extra1 = &zero,
1327 .extra2 = &one,
1328 },
1329 {
Andi Kleen6a460792009-09-16 11:50:15 +02001330 .procname = "memory_failure_recovery",
1331 .data = &sysctl_memory_failure_recovery,
1332 .maxlen = sizeof(sysctl_memory_failure_recovery),
1333 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001334 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001335 .extra1 = &zero,
1336 .extra2 = &one,
1337 },
1338#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001339 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340};
1341
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001342#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001343static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001344 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001345};
1346#endif
1347
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001348static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 .procname = "inode-nr",
1351 .data = &inodes_stat,
1352 .maxlen = 2*sizeof(int),
1353 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001354 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 },
1356 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 .procname = "inode-state",
1358 .data = &inodes_stat,
1359 .maxlen = 7*sizeof(int),
1360 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001361 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 },
1363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .procname = "file-nr",
1365 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001366 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001368 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 },
1370 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 .procname = "file-max",
1372 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001373 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001375 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 },
1377 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001378 .procname = "nr_open",
1379 .data = &sysctl_nr_open,
1380 .maxlen = sizeof(int),
1381 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001382 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001383 .extra1 = &sysctl_nr_open_min,
1384 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001385 },
1386 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 .procname = "dentry-state",
1388 .data = &dentry_stat,
1389 .maxlen = 6*sizeof(int),
1390 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001391 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 },
1393 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .procname = "overflowuid",
1395 .data = &fs_overflowuid,
1396 .maxlen = sizeof(int),
1397 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001398 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .extra1 = &minolduid,
1400 .extra2 = &maxolduid,
1401 },
1402 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .procname = "overflowgid",
1404 .data = &fs_overflowgid,
1405 .maxlen = sizeof(int),
1406 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001407 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 .extra1 = &minolduid,
1409 .extra2 = &maxolduid,
1410 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001411#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 .procname = "leases-enable",
1414 .data = &leases_enable,
1415 .maxlen = sizeof(int),
1416 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001417 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001419#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420#ifdef CONFIG_DNOTIFY
1421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 .procname = "dir-notify-enable",
1423 .data = &dir_notify_enable,
1424 .maxlen = sizeof(int),
1425 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001426 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 },
1428#endif
1429#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001430#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 .procname = "lease-break-time",
1433 .data = &lease_break_time,
1434 .maxlen = sizeof(int),
1435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001436 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001438#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001439#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 .procname = "aio-nr",
1442 .data = &aio_nr,
1443 .maxlen = sizeof(aio_nr),
1444 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001445 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 },
1447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .procname = "aio-max-nr",
1449 .data = &aio_max_nr,
1450 .maxlen = sizeof(aio_max_nr),
1451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001452 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001454#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001455#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001456 {
Robert Love0399cb02005-07-13 12:38:18 -04001457 .procname = "inotify",
1458 .mode = 0555,
1459 .child = inotify_table,
1460 },
1461#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001462#ifdef CONFIG_EPOLL
1463 {
1464 .procname = "epoll",
1465 .mode = 0555,
1466 .child = epoll_table,
1467 },
1468#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001470 {
Alan Coxd6e71142005-06-23 00:09:43 -07001471 .procname = "suid_dumpable",
1472 .data = &suid_dumpable,
1473 .maxlen = sizeof(int),
1474 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001475 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001476 .extra1 = &zero,
1477 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001478 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001479#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1480 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001481 .procname = "binfmt_misc",
1482 .mode = 0555,
1483 .child = binfmt_misc_table,
1484 },
1485#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001486 {
Jens Axboeff9da692010-06-03 14:54:39 +02001487 .procname = "pipe-max-size",
1488 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001489 .maxlen = sizeof(int),
1490 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001491 .proc_handler = &pipe_proc_fn,
1492 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001493 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001494 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495};
1496
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001497static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001498#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1499 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001500 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001501 .procname = "exception-trace",
1502 .data = &show_unhandled_signals,
1503 .maxlen = sizeof(int),
1504 .mode = 0644,
1505 .proc_handler = proc_dointvec
1506 },
1507#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001508#if defined(CONFIG_OPTPROBES)
1509 {
1510 .procname = "kprobes-optimization",
1511 .data = &sysctl_kprobes_optimization,
1512 .maxlen = sizeof(int),
1513 .mode = 0644,
1514 .proc_handler = proc_kprobes_optimization_handler,
1515 .extra1 = &zero,
1516 .extra2 = &one,
1517 },
1518#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001519 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520};
1521
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001522static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001523 { }
Robert Love0eeca282005-07-12 17:06:03 -04001524};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Al Viro330d57f2005-11-04 10:18:40 +00001526static DEFINE_SPINLOCK(sysctl_lock);
1527
1528/* called under sysctl_lock */
1529static int use_table(struct ctl_table_header *p)
1530{
1531 if (unlikely(p->unregistering))
1532 return 0;
1533 p->used++;
1534 return 1;
1535}
1536
1537/* called under sysctl_lock */
1538static void unuse_table(struct ctl_table_header *p)
1539{
1540 if (!--p->used)
1541 if (unlikely(p->unregistering))
1542 complete(p->unregistering);
1543}
1544
1545/* called under sysctl_lock, will reacquire if has to wait */
1546static void start_unregistering(struct ctl_table_header *p)
1547{
1548 /*
1549 * if p->used is 0, nobody will ever touch that entry again;
1550 * we'll eliminate all paths to it before dropping sysctl_lock
1551 */
1552 if (unlikely(p->used)) {
1553 struct completion wait;
1554 init_completion(&wait);
1555 p->unregistering = &wait;
1556 spin_unlock(&sysctl_lock);
1557 wait_for_completion(&wait);
1558 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001559 } else {
1560 /* anything non-NULL; we'll never dereference it */
1561 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001562 }
1563 /*
1564 * do not remove from the list until nobody holds it; walking the
1565 * list in do_sysctl() relies on that.
1566 */
1567 list_del_init(&p->ctl_entry);
1568}
1569
Al Virof7e6ced2008-07-15 01:44:23 -04001570void sysctl_head_get(struct ctl_table_header *head)
1571{
1572 spin_lock(&sysctl_lock);
1573 head->count++;
1574 spin_unlock(&sysctl_lock);
1575}
1576
Al Virodfef6dcd32011-03-08 01:25:28 -05001577static void free_head(struct rcu_head *rcu)
1578{
1579 kfree(container_of(rcu, struct ctl_table_header, rcu));
1580}
1581
Al Virof7e6ced2008-07-15 01:44:23 -04001582void sysctl_head_put(struct ctl_table_header *head)
1583{
1584 spin_lock(&sysctl_lock);
1585 if (!--head->count)
Al Virodfef6dcd32011-03-08 01:25:28 -05001586 call_rcu(&head->rcu, free_head);
Al Virof7e6ced2008-07-15 01:44:23 -04001587 spin_unlock(&sysctl_lock);
1588}
1589
1590struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1591{
1592 if (!head)
1593 BUG();
1594 spin_lock(&sysctl_lock);
1595 if (!use_table(head))
1596 head = ERR_PTR(-ENOENT);
1597 spin_unlock(&sysctl_lock);
1598 return head;
1599}
1600
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001601void sysctl_head_finish(struct ctl_table_header *head)
1602{
1603 if (!head)
1604 return;
1605 spin_lock(&sysctl_lock);
1606 unuse_table(head);
1607 spin_unlock(&sysctl_lock);
1608}
1609
Al Viro73455092008-07-14 21:22:20 -04001610static struct ctl_table_set *
1611lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1612{
1613 struct ctl_table_set *set = &root->default_set;
1614 if (root->lookup)
1615 set = root->lookup(root, namespaces);
1616 return set;
1617}
1618
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001619static struct list_head *
1620lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001621{
Al Viro73455092008-07-14 21:22:20 -04001622 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1623 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001624}
1625
1626struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1627 struct ctl_table_header *prev)
1628{
1629 struct ctl_table_root *root;
1630 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001631 struct ctl_table_header *head;
1632 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001633
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001634 spin_lock(&sysctl_lock);
1635 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001636 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001637 tmp = &prev->ctl_entry;
1638 unuse_table(prev);
1639 goto next;
1640 }
1641 tmp = &root_table_header.ctl_entry;
1642 for (;;) {
1643 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1644
1645 if (!use_table(head))
1646 goto next;
1647 spin_unlock(&sysctl_lock);
1648 return head;
1649 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001650 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001651 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001652 header_list = lookup_header_list(root, namespaces);
1653 if (tmp != header_list)
1654 continue;
1655
1656 do {
1657 root = list_entry(root->root_list.next,
1658 struct ctl_table_root, root_list);
1659 if (root == &sysctl_table_root)
1660 goto out;
1661 header_list = lookup_header_list(root, namespaces);
1662 } while (list_empty(header_list));
1663 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001664 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001665out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001666 spin_unlock(&sysctl_lock);
1667 return NULL;
1668}
1669
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001670struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1671{
1672 return __sysctl_head_next(current->nsproxy, prev);
1673}
1674
1675void register_sysctl_root(struct ctl_table_root *root)
1676{
1677 spin_lock(&sysctl_lock);
1678 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1679 spin_unlock(&sysctl_lock);
1680}
1681
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001683 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 * some sysctl variables are readonly even to root.
1685 */
1686
1687static int test_perm(int mode, int op)
1688{
David Howells76aac0e2008-11-14 10:39:12 +11001689 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 mode >>= 6;
1691 else if (in_egroup_p(0))
1692 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001693 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 return 0;
1695 return -EACCES;
1696}
1697
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001698int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699{
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001700 int mode;
1701
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001702 if (root->permissions)
1703 mode = root->permissions(root, current->nsproxy, table);
1704 else
1705 mode = table->mode;
1706
1707 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001710static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1711{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001712 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001713 table->parent = parent;
1714 if (table->child)
1715 sysctl_set_parent(table, table->child);
1716 }
1717}
1718
1719static __init int sysctl_init(void)
1720{
1721 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001722#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001723 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001724#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001725 return 0;
1726}
1727
1728core_initcall(sysctl_init);
1729
Al Virobfbcf032008-07-27 06:31:22 +01001730static struct ctl_table *is_branch_in(struct ctl_table *branch,
1731 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001732{
1733 struct ctl_table *p;
1734 const char *s = branch->procname;
1735
1736 /* branch should have named subdirectory as its first element */
1737 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001738 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001739
1740 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001741 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001742 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001743
1744 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001745 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001746 if (!p->child)
1747 continue;
1748 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001749 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001750 }
Al Virobfbcf032008-07-27 06:31:22 +01001751 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001752}
1753
1754/* see if attaching q to p would be an improvement */
1755static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1756{
1757 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001758 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001759 int is_better = 0;
1760 int not_in_parent = !p->attached_by;
1761
Al Virobfbcf032008-07-27 06:31:22 +01001762 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001763 if (by == q->attached_by)
1764 is_better = 1;
1765 if (to == p->attached_by)
1766 not_in_parent = 1;
1767 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001768 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001769 }
1770
1771 if (is_better && not_in_parent) {
1772 q->attached_by = by;
1773 q->attached_to = to;
1774 q->parent = p;
1775 }
1776}
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001779 * __register_sysctl_paths - register a sysctl hierarchy
1780 * @root: List of sysctl headers to register on
1781 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001782 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 *
1785 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001786 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001788 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1791 * enter a sysctl file
1792 *
1793 * data - a pointer to data for use by proc_handler
1794 *
1795 * maxlen - the maximum size in bytes of the data
1796 *
1797 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1798 *
1799 * child - a pointer to the child sysctl table if this entry is a directory, or
1800 * %NULL.
1801 *
1802 * proc_handler - the text handler routine (described below)
1803 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 * de - for internal use by the sysctl routines
1805 *
1806 * extra1, extra2 - extra pointers usable by the proc handler routines
1807 *
1808 * Leaf nodes in the sysctl tree will be represented by a single file
1809 * under /proc; non-leaf nodes will be represented by directories.
1810 *
1811 * sysctl(2) can automatically manage read and write requests through
1812 * the sysctl table. The data and maxlen fields of the ctl_table
1813 * struct enable minimal validation of the values being written to be
1814 * performed, and the mode field allows minimal authentication.
1815 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 * There must be a proc_handler routine for any terminal nodes
1817 * mirrored under /proc/sys (non-terminals are handled by a built-in
1818 * directory handler). Several default handlers are available to
1819 * cover common cases -
1820 *
1821 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1822 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1823 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1824 *
1825 * It is the handler's job to read the input buffer from user memory
1826 * and process it. The handler should return 0 on success.
1827 *
1828 * This routine returns %NULL on a failure to register, and a pointer
1829 * to the table header on success.
1830 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001831struct ctl_table_header *__register_sysctl_paths(
1832 struct ctl_table_root *root,
1833 struct nsproxy *namespaces,
1834 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001836 struct ctl_table_header *header;
1837 struct ctl_table *new, **prevp;
1838 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001839 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001840
1841 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001842 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001843 ;
1844
1845 /*
1846 * For each path component, allocate a 2-element ctl_table array.
1847 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001848 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001849 *
1850 * We allocate everything in one go so that we don't have to
1851 * worry about freeing additional memory in unregister_sysctl_table.
1852 */
1853 header = kzalloc(sizeof(struct ctl_table_header) +
1854 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1855 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001857
1858 new = (struct ctl_table *) (header + 1);
1859
1860 /* Now connect the dots */
1861 prevp = &header->ctl_table;
1862 for (n = 0; n < npath; ++n, ++path) {
1863 /* Copy the procname */
1864 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001865 new->mode = 0555;
1866
1867 *prevp = new;
1868 prevp = &new->child;
1869
1870 new += 2;
1871 }
1872 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001873 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001874
1875 INIT_LIST_HEAD(&header->ctl_entry);
1876 header->used = 0;
1877 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001878 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001879 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001880 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001881#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001882 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001883 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001884 return NULL;
1885 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001886#endif
Al Viro330d57f2005-11-04 10:18:40 +00001887 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001888 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001889 header->attached_by = header->ctl_table;
1890 header->attached_to = root_table;
1891 header->parent = &root_table_header;
1892 for (set = header->set; set; set = set->parent) {
1893 struct ctl_table_header *p;
1894 list_for_each_entry(p, &set->list, ctl_entry) {
1895 if (p->unregistering)
1896 continue;
1897 try_attach(p, header);
1898 }
1899 }
1900 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001901 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001902 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001903
1904 return header;
1905}
1906
1907/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001908 * register_sysctl_table_path - register a sysctl table hierarchy
1909 * @path: The path to the directory the sysctl table is in.
1910 * @table: the top-level table structure
1911 *
1912 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1913 * array. A completely 0 filled entry terminates the table.
1914 *
1915 * See __register_sysctl_paths for more details.
1916 */
1917struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1918 struct ctl_table *table)
1919{
1920 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1921 path, table);
1922}
1923
1924/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001925 * register_sysctl_table - register a sysctl table hierarchy
1926 * @table: the top-level table structure
1927 *
1928 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1929 * array. A completely 0 filled entry terminates the table.
1930 *
1931 * See register_sysctl_paths for more details.
1932 */
1933struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1934{
1935 static const struct ctl_path null_path[] = { {} };
1936
1937 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938}
1939
1940/**
1941 * unregister_sysctl_table - unregister a sysctl table hierarchy
1942 * @header: the header returned from register_sysctl_table
1943 *
1944 * Unregisters the sysctl table and all children. proc entries may not
1945 * actually be removed until they are no longer used by anyone.
1946 */
1947void unregister_sysctl_table(struct ctl_table_header * header)
1948{
Al Viro330d57f2005-11-04 10:18:40 +00001949 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001950
1951 if (header == NULL)
1952 return;
1953
Al Viro330d57f2005-11-04 10:18:40 +00001954 spin_lock(&sysctl_lock);
1955 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001956 if (!--header->parent->count) {
1957 WARN_ON(1);
Al Virodfef6dcd32011-03-08 01:25:28 -05001958 call_rcu(&header->parent->rcu, free_head);
Al Viroae7edec2008-07-15 06:33:31 -04001959 }
Al Virof7e6ced2008-07-15 01:44:23 -04001960 if (!--header->count)
Al Virodfef6dcd32011-03-08 01:25:28 -05001961 call_rcu(&header->rcu, free_head);
Al Viro330d57f2005-11-04 10:18:40 +00001962 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963}
1964
Al Viro9043476f2008-07-15 08:54:06 -04001965int sysctl_is_seen(struct ctl_table_header *p)
1966{
1967 struct ctl_table_set *set = p->set;
1968 int res;
1969 spin_lock(&sysctl_lock);
1970 if (p->unregistering)
1971 res = 0;
1972 else if (!set->is_seen)
1973 res = 1;
1974 else
1975 res = set->is_seen(set);
1976 spin_unlock(&sysctl_lock);
1977 return res;
1978}
1979
Al Viro73455092008-07-14 21:22:20 -04001980void setup_sysctl_set(struct ctl_table_set *p,
1981 struct ctl_table_set *parent,
1982 int (*is_seen)(struct ctl_table_set *))
1983{
1984 INIT_LIST_HEAD(&p->list);
1985 p->parent = parent ? parent : &sysctl_table_root.default_set;
1986 p->is_seen = is_seen;
1987}
1988
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001989#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001990struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001991{
1992 return NULL;
1993}
1994
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001995struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1996 struct ctl_table *table)
1997{
1998 return NULL;
1999}
2000
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002001void unregister_sysctl_table(struct ctl_table_header * table)
2002{
2003}
2004
Al Viro73455092008-07-14 21:22:20 -04002005void setup_sysctl_set(struct ctl_table_set *p,
2006 struct ctl_table_set *parent,
2007 int (*is_seen)(struct ctl_table_set *))
2008{
2009}
2010
Al Virof7e6ced2008-07-15 01:44:23 -04002011void sysctl_head_put(struct ctl_table_header *head)
2012{
2013}
2014
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002015#endif /* CONFIG_SYSCTL */
2016
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017/*
2018 * /proc/sys support
2019 */
2020
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002021#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002023static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002024 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002025 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002026{
2027 size_t len;
2028 char __user *p;
2029 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002030
2031 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002032 *lenp = 0;
2033 return 0;
2034 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002035
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002036 if (write) {
2037 len = 0;
2038 p = buffer;
2039 while (len < *lenp) {
2040 if (get_user(c, p++))
2041 return -EFAULT;
2042 if (c == 0 || c == '\n')
2043 break;
2044 len++;
2045 }
2046 if (len >= maxlen)
2047 len = maxlen-1;
2048 if(copy_from_user(data, buffer, len))
2049 return -EFAULT;
2050 ((char *) data)[len] = 0;
2051 *ppos += *lenp;
2052 } else {
2053 len = strlen(data);
2054 if (len > maxlen)
2055 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002056
2057 if (*ppos > len) {
2058 *lenp = 0;
2059 return 0;
2060 }
2061
2062 data += *ppos;
2063 len -= *ppos;
2064
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002065 if (len > *lenp)
2066 len = *lenp;
2067 if (len)
2068 if(copy_to_user(buffer, data, len))
2069 return -EFAULT;
2070 if (len < *lenp) {
2071 if(put_user('\n', ((char __user *) buffer) + len))
2072 return -EFAULT;
2073 len++;
2074 }
2075 *lenp = len;
2076 *ppos += len;
2077 }
2078 return 0;
2079}
2080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081/**
2082 * proc_dostring - read a string sysctl
2083 * @table: the sysctl table
2084 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 * @buffer: the user buffer
2086 * @lenp: the size of the user buffer
2087 * @ppos: file position
2088 *
2089 * Reads/writes a string from/to the user buffer. If the kernel
2090 * buffer provided is not large enough to hold the string, the
2091 * string is truncated. The copied string is %NULL-terminated.
2092 * If the string is being read by the user process, it is copied
2093 * and a newline '\n' is added. It is truncated if the buffer is
2094 * not large enough.
2095 *
2096 * Returns 0 on success.
2097 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002098int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 void __user *buffer, size_t *lenp, loff_t *ppos)
2100{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002101 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002102 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
Amerigo Wang00b7c332010-05-05 00:26:45 +00002105static size_t proc_skip_spaces(char **buf)
2106{
2107 size_t ret;
2108 char *tmp = skip_spaces(*buf);
2109 ret = tmp - *buf;
2110 *buf = tmp;
2111 return ret;
2112}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002114static void proc_skip_char(char **buf, size_t *size, const char v)
2115{
2116 while (*size) {
2117 if (**buf != v)
2118 break;
2119 (*size)--;
2120 (*buf)++;
2121 }
2122}
2123
Amerigo Wang00b7c332010-05-05 00:26:45 +00002124#define TMPBUFLEN 22
2125/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002126 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002127 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002128 * @buf: a kernel buffer
2129 * @size: size of the kernel buffer
2130 * @val: this is where the number will be stored
2131 * @neg: set to %TRUE if number is negative
2132 * @perm_tr: a vector which contains the allowed trailers
2133 * @perm_tr_len: size of the perm_tr vector
2134 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002135 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002136 * In case of success %0 is returned and @buf and @size are updated with
2137 * the amount of bytes read. If @tr is non-NULL and a trailing
2138 * character exists (size is non-zero after returning from this
2139 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002140 */
2141static int proc_get_long(char **buf, size_t *size,
2142 unsigned long *val, bool *neg,
2143 const char *perm_tr, unsigned perm_tr_len, char *tr)
2144{
2145 int len;
2146 char *p, tmp[TMPBUFLEN];
2147
2148 if (!*size)
2149 return -EINVAL;
2150
2151 len = *size;
2152 if (len > TMPBUFLEN - 1)
2153 len = TMPBUFLEN - 1;
2154
2155 memcpy(tmp, *buf, len);
2156
2157 tmp[len] = 0;
2158 p = tmp;
2159 if (*p == '-' && *size > 1) {
2160 *neg = true;
2161 p++;
2162 } else
2163 *neg = false;
2164 if (!isdigit(*p))
2165 return -EINVAL;
2166
2167 *val = simple_strtoul(p, &p, 0);
2168
2169 len = p - tmp;
2170
2171 /* We don't know if the next char is whitespace thus we may accept
2172 * invalid integers (e.g. 1234...a) or two integers instead of one
2173 * (e.g. 123...1). So lets not allow such large numbers. */
2174 if (len == TMPBUFLEN - 1)
2175 return -EINVAL;
2176
2177 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2178 return -EINVAL;
2179
2180 if (tr && (len < *size))
2181 *tr = *p;
2182
2183 *buf += len;
2184 *size -= len;
2185
2186 return 0;
2187}
2188
2189/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002190 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002191 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002192 * @buf: the user buffer
2193 * @size: the size of the user buffer
2194 * @val: the integer to be converted
2195 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002197 * In case of success %0 is returned and @buf and @size are updated with
2198 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002199 */
2200static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2201 bool neg)
2202{
2203 int len;
2204 char tmp[TMPBUFLEN], *p = tmp;
2205
2206 sprintf(p, "%s%lu", neg ? "-" : "", val);
2207 len = strlen(tmp);
2208 if (len > *size)
2209 len = *size;
2210 if (copy_to_user(*buf, tmp, len))
2211 return -EFAULT;
2212 *size -= len;
2213 *buf += len;
2214 return 0;
2215}
2216#undef TMPBUFLEN
2217
2218static int proc_put_char(void __user **buf, size_t *size, char c)
2219{
2220 if (*size) {
2221 char __user **buffer = (char __user **)buf;
2222 if (put_user(c, *buffer))
2223 return -EFAULT;
2224 (*size)--, (*buffer)++;
2225 *buf = *buffer;
2226 }
2227 return 0;
2228}
2229
2230static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 int *valp,
2232 int write, void *data)
2233{
2234 if (write) {
2235 *valp = *negp ? -*lvalp : *lvalp;
2236 } else {
2237 int val = *valp;
2238 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 *lvalp = (unsigned long)-val;
2241 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 *lvalp = (unsigned long)val;
2244 }
2245 }
2246 return 0;
2247}
2248
Amerigo Wang00b7c332010-05-05 00:26:45 +00002249static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2250
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002251static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002252 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002253 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002254 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 int write, void *data),
2256 void *data)
2257{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002258 int *i, vleft, first = 1, err = 0;
2259 unsigned long page = 0;
2260 size_t left;
2261 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 *lenp = 0;
2265 return 0;
2266 }
2267
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002268 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 vleft = table->maxlen / sizeof(*i);
2270 left = *lenp;
2271
2272 if (!conv)
2273 conv = do_proc_dointvec_conv;
2274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002276 if (left > PAGE_SIZE - 1)
2277 left = PAGE_SIZE - 1;
2278 page = __get_free_page(GFP_TEMPORARY);
2279 kbuf = (char *) page;
2280 if (!kbuf)
2281 return -ENOMEM;
2282 if (copy_from_user(kbuf, buffer, left)) {
2283 err = -EFAULT;
2284 goto free;
2285 }
2286 kbuf[left] = 0;
2287 }
2288
2289 for (; left && vleft--; i++, first=0) {
2290 unsigned long lval;
2291 bool neg;
2292
2293 if (write) {
2294 left -= proc_skip_spaces(&kbuf);
2295
J. R. Okajima563b0462010-05-25 16:10:14 -07002296 if (!left)
2297 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002298 err = proc_get_long(&kbuf, &left, &lval, &neg,
2299 proc_wspace_sep,
2300 sizeof(proc_wspace_sep), NULL);
2301 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002303 if (conv(&neg, &lval, i, 1, data)) {
2304 err = -EINVAL;
2305 break;
2306 }
2307 } else {
2308 if (conv(&neg, &lval, i, 0, data)) {
2309 err = -EINVAL;
2310 break;
2311 }
2312 if (!first)
2313 err = proc_put_char(&buffer, &left, '\t');
2314 if (err)
2315 break;
2316 err = proc_put_long(&buffer, &left, lval, neg);
2317 if (err)
2318 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002321
2322 if (!write && !first && left && !err)
2323 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002324 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325 left -= proc_skip_spaces(&kbuf);
2326free:
2327 if (write) {
2328 free_page(page);
2329 if (first)
2330 return err ? : -EINVAL;
2331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 *lenp -= left;
2333 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002334 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335}
2336
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002337static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002338 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002339 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002340 int write, void *data),
2341 void *data)
2342{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002343 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002344 buffer, lenp, ppos, conv, data);
2345}
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347/**
2348 * proc_dointvec - read a vector of integers
2349 * @table: the sysctl table
2350 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 * @buffer: the user buffer
2352 * @lenp: the size of the user buffer
2353 * @ppos: file position
2354 *
2355 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2356 * values from/to the user buffer, treated as an ASCII string.
2357 *
2358 * Returns 0 on success.
2359 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002360int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 void __user *buffer, size_t *lenp, loff_t *ppos)
2362{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002363 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 NULL,NULL);
2365}
2366
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002367/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002368 * Taint values can only be increased
2369 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002370 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002371static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002372 void __user *buffer, size_t *lenp, loff_t *ppos)
2373{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002374 struct ctl_table t;
2375 unsigned long tmptaint = get_taint();
2376 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002377
Bastian Blank91fcd412007-04-23 14:41:14 -07002378 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002379 return -EPERM;
2380
Andi Kleen25ddbb12008-10-15 22:01:41 -07002381 t = *table;
2382 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002383 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002384 if (err < 0)
2385 return err;
2386
2387 if (write) {
2388 /*
2389 * Poor man's atomic or. Not worth adding a primitive
2390 * to everyone's atomic.h for this
2391 */
2392 int i;
2393 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2394 if ((tmptaint >> i) & 1)
2395 add_taint(i);
2396 }
2397 }
2398
2399 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002400}
2401
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002402#ifdef CONFIG_PRINTK
2403static int proc_dmesg_restrict(struct ctl_table *table, int write,
2404 void __user *buffer, size_t *lenp, loff_t *ppos)
2405{
2406 if (write && !capable(CAP_SYS_ADMIN))
2407 return -EPERM;
2408
2409 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2410}
2411#endif
2412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413struct do_proc_dointvec_minmax_conv_param {
2414 int *min;
2415 int *max;
2416};
2417
Amerigo Wang00b7c332010-05-05 00:26:45 +00002418static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2419 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 int write, void *data)
2421{
2422 struct do_proc_dointvec_minmax_conv_param *param = data;
2423 if (write) {
2424 int val = *negp ? -*lvalp : *lvalp;
2425 if ((param->min && *param->min > val) ||
2426 (param->max && *param->max < val))
2427 return -EINVAL;
2428 *valp = val;
2429 } else {
2430 int val = *valp;
2431 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002432 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 *lvalp = (unsigned long)-val;
2434 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002435 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 *lvalp = (unsigned long)val;
2437 }
2438 }
2439 return 0;
2440}
2441
2442/**
2443 * proc_dointvec_minmax - read a vector of integers with min/max values
2444 * @table: the sysctl table
2445 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2449 *
2450 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2451 * values from/to the user buffer, treated as an ASCII string.
2452 *
2453 * This routine will ensure the values are within the range specified by
2454 * table->extra1 (min) and table->extra2 (max).
2455 *
2456 * Returns 0 on success.
2457 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002458int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 void __user *buffer, size_t *lenp, loff_t *ppos)
2460{
2461 struct do_proc_dointvec_minmax_conv_param param = {
2462 .min = (int *) table->extra1,
2463 .max = (int *) table->extra2,
2464 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002465 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 do_proc_dointvec_minmax_conv, &param);
2467}
2468
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002469static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 void __user *buffer,
2471 size_t *lenp, loff_t *ppos,
2472 unsigned long convmul,
2473 unsigned long convdiv)
2474{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002475 unsigned long *i, *min, *max;
2476 int vleft, first = 1, err = 0;
2477 unsigned long page = 0;
2478 size_t left;
2479 char *kbuf;
2480
2481 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 *lenp = 0;
2483 return 0;
2484 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002485
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002486 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 min = (unsigned long *) table->extra1;
2488 max = (unsigned long *) table->extra2;
2489 vleft = table->maxlen / sizeof(unsigned long);
2490 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002491
2492 if (write) {
2493 if (left > PAGE_SIZE - 1)
2494 left = PAGE_SIZE - 1;
2495 page = __get_free_page(GFP_TEMPORARY);
2496 kbuf = (char *) page;
2497 if (!kbuf)
2498 return -ENOMEM;
2499 if (copy_from_user(kbuf, buffer, left)) {
2500 err = -EFAULT;
2501 goto free;
2502 }
2503 kbuf[left] = 0;
2504 }
2505
Eric Dumazet27b3d802010-10-07 12:59:29 -07002506 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002507 unsigned long val;
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002510 bool neg;
2511
2512 left -= proc_skip_spaces(&kbuf);
2513
2514 err = proc_get_long(&kbuf, &left, &val, &neg,
2515 proc_wspace_sep,
2516 sizeof(proc_wspace_sep), NULL);
2517 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 break;
2519 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 continue;
2521 if ((min && val < *min) || (max && val > *max))
2522 continue;
2523 *i = val;
2524 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002525 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002527 err = proc_put_char(&buffer, &left, '\t');
2528 err = proc_put_long(&buffer, &left, val, false);
2529 if (err)
2530 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 }
2532 }
2533
Amerigo Wang00b7c332010-05-05 00:26:45 +00002534 if (!write && !first && left && !err)
2535 err = proc_put_char(&buffer, &left, '\n');
2536 if (write && !err)
2537 left -= proc_skip_spaces(&kbuf);
2538free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002540 free_page(page);
2541 if (first)
2542 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 *lenp -= left;
2545 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002546 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547}
2548
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002549static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002550 void __user *buffer,
2551 size_t *lenp, loff_t *ppos,
2552 unsigned long convmul,
2553 unsigned long convdiv)
2554{
2555 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002556 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002557}
2558
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559/**
2560 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2561 * @table: the sysctl table
2562 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 * @buffer: the user buffer
2564 * @lenp: the size of the user buffer
2565 * @ppos: file position
2566 *
2567 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2568 * values from/to the user buffer, treated as an ASCII string.
2569 *
2570 * This routine will ensure the values are within the range specified by
2571 * table->extra1 (min) and table->extra2 (max).
2572 *
2573 * Returns 0 on success.
2574 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002575int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 void __user *buffer, size_t *lenp, loff_t *ppos)
2577{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002578 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579}
2580
2581/**
2582 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2583 * @table: the sysctl table
2584 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 * @buffer: the user buffer
2586 * @lenp: the size of the user buffer
2587 * @ppos: file position
2588 *
2589 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2590 * values from/to the user buffer, treated as an ASCII string. The values
2591 * are treated as milliseconds, and converted to jiffies when they are stored.
2592 *
2593 * This routine will ensure the values are within the range specified by
2594 * table->extra1 (min) and table->extra2 (max).
2595 *
2596 * Returns 0 on success.
2597 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002598int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 void __user *buffer,
2600 size_t *lenp, loff_t *ppos)
2601{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002602 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 lenp, ppos, HZ, 1000l);
2604}
2605
2606
Amerigo Wang00b7c332010-05-05 00:26:45 +00002607static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 int *valp,
2609 int write, void *data)
2610{
2611 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002612 if (*lvalp > LONG_MAX / HZ)
2613 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2615 } else {
2616 int val = *valp;
2617 unsigned long lval;
2618 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002619 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 lval = (unsigned long)-val;
2621 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002622 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 lval = (unsigned long)val;
2624 }
2625 *lvalp = lval / HZ;
2626 }
2627 return 0;
2628}
2629
Amerigo Wang00b7c332010-05-05 00:26:45 +00002630static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 int *valp,
2632 int write, void *data)
2633{
2634 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002635 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2636 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2638 } else {
2639 int val = *valp;
2640 unsigned long lval;
2641 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002642 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 lval = (unsigned long)-val;
2644 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002645 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 lval = (unsigned long)val;
2647 }
2648 *lvalp = jiffies_to_clock_t(lval);
2649 }
2650 return 0;
2651}
2652
Amerigo Wang00b7c332010-05-05 00:26:45 +00002653static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 int *valp,
2655 int write, void *data)
2656{
2657 if (write) {
2658 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2659 } else {
2660 int val = *valp;
2661 unsigned long lval;
2662 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002663 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 lval = (unsigned long)-val;
2665 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002666 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 lval = (unsigned long)val;
2668 }
2669 *lvalp = jiffies_to_msecs(lval);
2670 }
2671 return 0;
2672}
2673
2674/**
2675 * proc_dointvec_jiffies - read a vector of integers as seconds
2676 * @table: the sysctl table
2677 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 * @buffer: the user buffer
2679 * @lenp: the size of the user buffer
2680 * @ppos: file position
2681 *
2682 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2683 * values from/to the user buffer, treated as an ASCII string.
2684 * The values read are assumed to be in seconds, and are converted into
2685 * jiffies.
2686 *
2687 * Returns 0 on success.
2688 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002689int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 void __user *buffer, size_t *lenp, loff_t *ppos)
2691{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002692 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 do_proc_dointvec_jiffies_conv,NULL);
2694}
2695
2696/**
2697 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2698 * @table: the sysctl table
2699 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 * @buffer: the user buffer
2701 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002702 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 *
2704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2705 * values from/to the user buffer, treated as an ASCII string.
2706 * The values read are assumed to be in 1/USER_HZ seconds, and
2707 * are converted into jiffies.
2708 *
2709 * Returns 0 on success.
2710 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002711int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 void __user *buffer, size_t *lenp, loff_t *ppos)
2713{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002714 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 do_proc_dointvec_userhz_jiffies_conv,NULL);
2716}
2717
2718/**
2719 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2720 * @table: the sysctl table
2721 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002724 * @ppos: file position
2725 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 *
2727 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2728 * values from/to the user buffer, treated as an ASCII string.
2729 * The values read are assumed to be in 1/1000 seconds, and
2730 * are converted into jiffies.
2731 *
2732 * Returns 0 on success.
2733 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002734int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 void __user *buffer, size_t *lenp, loff_t *ppos)
2736{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002737 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 do_proc_dointvec_ms_jiffies_conv, NULL);
2739}
2740
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002741static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002742 void __user *buffer, size_t *lenp, loff_t *ppos)
2743{
2744 struct pid *new_pid;
2745 pid_t tmp;
2746 int r;
2747
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002748 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002749
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002750 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002751 lenp, ppos, NULL, NULL);
2752 if (r || !write)
2753 return r;
2754
2755 new_pid = find_get_pid(tmp);
2756 if (!new_pid)
2757 return -ESRCH;
2758
2759 put_pid(xchg(&cad_pid, new_pid));
2760 return 0;
2761}
2762
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002763/**
2764 * proc_do_large_bitmap - read/write from/to a large bitmap
2765 * @table: the sysctl table
2766 * @write: %TRUE if this is a write to the sysctl file
2767 * @buffer: the user buffer
2768 * @lenp: the size of the user buffer
2769 * @ppos: file position
2770 *
2771 * The bitmap is stored at table->data and the bitmap length (in bits)
2772 * in table->maxlen.
2773 *
2774 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2775 * large bitmaps may be represented in a compact manner. Writing into
2776 * the file will clear the bitmap then update it with the given input.
2777 *
2778 * Returns 0 on success.
2779 */
2780int proc_do_large_bitmap(struct ctl_table *table, int write,
2781 void __user *buffer, size_t *lenp, loff_t *ppos)
2782{
2783 int err = 0;
2784 bool first = 1;
2785 size_t left = *lenp;
2786 unsigned long bitmap_len = table->maxlen;
2787 unsigned long *bitmap = (unsigned long *) table->data;
2788 unsigned long *tmp_bitmap = NULL;
2789 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2790
2791 if (!bitmap_len || !left || (*ppos && !write)) {
2792 *lenp = 0;
2793 return 0;
2794 }
2795
2796 if (write) {
2797 unsigned long page = 0;
2798 char *kbuf;
2799
2800 if (left > PAGE_SIZE - 1)
2801 left = PAGE_SIZE - 1;
2802
2803 page = __get_free_page(GFP_TEMPORARY);
2804 kbuf = (char *) page;
2805 if (!kbuf)
2806 return -ENOMEM;
2807 if (copy_from_user(kbuf, buffer, left)) {
2808 free_page(page);
2809 return -EFAULT;
2810 }
2811 kbuf[left] = 0;
2812
2813 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2814 GFP_KERNEL);
2815 if (!tmp_bitmap) {
2816 free_page(page);
2817 return -ENOMEM;
2818 }
2819 proc_skip_char(&kbuf, &left, '\n');
2820 while (!err && left) {
2821 unsigned long val_a, val_b;
2822 bool neg;
2823
2824 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2825 sizeof(tr_a), &c);
2826 if (err)
2827 break;
2828 if (val_a >= bitmap_len || neg) {
2829 err = -EINVAL;
2830 break;
2831 }
2832
2833 val_b = val_a;
2834 if (left) {
2835 kbuf++;
2836 left--;
2837 }
2838
2839 if (c == '-') {
2840 err = proc_get_long(&kbuf, &left, &val_b,
2841 &neg, tr_b, sizeof(tr_b),
2842 &c);
2843 if (err)
2844 break;
2845 if (val_b >= bitmap_len || neg ||
2846 val_a > val_b) {
2847 err = -EINVAL;
2848 break;
2849 }
2850 if (left) {
2851 kbuf++;
2852 left--;
2853 }
2854 }
2855
2856 while (val_a <= val_b)
2857 set_bit(val_a++, tmp_bitmap);
2858
2859 first = 0;
2860 proc_skip_char(&kbuf, &left, '\n');
2861 }
2862 free_page(page);
2863 } else {
2864 unsigned long bit_a, bit_b = 0;
2865
2866 while (left) {
2867 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2868 if (bit_a >= bitmap_len)
2869 break;
2870 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2871 bit_a + 1) - 1;
2872
2873 if (!first) {
2874 err = proc_put_char(&buffer, &left, ',');
2875 if (err)
2876 break;
2877 }
2878 err = proc_put_long(&buffer, &left, bit_a, false);
2879 if (err)
2880 break;
2881 if (bit_a != bit_b) {
2882 err = proc_put_char(&buffer, &left, '-');
2883 if (err)
2884 break;
2885 err = proc_put_long(&buffer, &left, bit_b, false);
2886 if (err)
2887 break;
2888 }
2889
2890 first = 0; bit_b++;
2891 }
2892 if (!err)
2893 err = proc_put_char(&buffer, &left, '\n');
2894 }
2895
2896 if (!err) {
2897 if (write) {
2898 if (*ppos)
2899 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2900 else
2901 memcpy(bitmap, tmp_bitmap,
2902 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2903 }
2904 kfree(tmp_bitmap);
2905 *lenp -= left;
2906 *ppos += *lenp;
2907 return 0;
2908 } else {
2909 kfree(tmp_bitmap);
2910 return err;
2911 }
2912}
2913
Jovi Zhang55610502011-01-12 17:00:45 -08002914#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002916int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 void __user *buffer, size_t *lenp, loff_t *ppos)
2918{
2919 return -ENOSYS;
2920}
2921
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002922int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 void __user *buffer, size_t *lenp, loff_t *ppos)
2924{
2925 return -ENOSYS;
2926}
2927
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002928int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 void __user *buffer, size_t *lenp, loff_t *ppos)
2930{
2931 return -ENOSYS;
2932}
2933
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002934int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 void __user *buffer, size_t *lenp, loff_t *ppos)
2936{
2937 return -ENOSYS;
2938}
2939
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002940int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 void __user *buffer, size_t *lenp, loff_t *ppos)
2942{
2943 return -ENOSYS;
2944}
2945
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002946int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 void __user *buffer, size_t *lenp, loff_t *ppos)
2948{
2949 return -ENOSYS;
2950}
2951
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002952int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 void __user *buffer, size_t *lenp, loff_t *ppos)
2954{
2955 return -ENOSYS;
2956}
2957
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002958int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 void __user *buffer,
2960 size_t *lenp, loff_t *ppos)
2961{
2962 return -ENOSYS;
2963}
2964
2965
Jovi Zhang55610502011-01-12 17:00:45 -08002966#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968/*
2969 * No sense putting this after each symbol definition, twice,
2970 * exception granted :-)
2971 */
2972EXPORT_SYMBOL(proc_dointvec);
2973EXPORT_SYMBOL(proc_dointvec_jiffies);
2974EXPORT_SYMBOL(proc_dointvec_minmax);
2975EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2976EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2977EXPORT_SYMBOL(proc_dostring);
2978EXPORT_SYMBOL(proc_doulongvec_minmax);
2979EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2980EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002981EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982EXPORT_SYMBOL(unregister_sysctl_table);