blob: bc86bb32e12620c463699c9e461c836ce37733c1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080027#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070029#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020031#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020040#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070041#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070044#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/times.h>
46#include <linux/limits.h>
47#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020048#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070050#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080051#include <linux/nfs_fs.h>
52#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070053#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020054#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020055#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050056#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020057#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070058#include <linux/oom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#include <asm/uaccess.h>
61#include <asm/processor.h>
62
Andi Kleen29cbc782006-09-30 01:47:55 +020063#ifdef CONFIG_X86
64#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010065#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010066#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020067#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080068#ifdef CONFIG_BSD_PROCESS_ACCT
69#include <linux/acct.h>
70#endif
Dave Young4f0e0562010-03-10 15:24:09 -080071#ifdef CONFIG_RT_MUTEXES
72#include <linux/rtmutex.h>
73#endif
Dave Young2edf5e42010-03-10 15:24:10 -080074#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75#include <linux/lockdep.h>
76#endif
Dave Young15485a42010-03-10 15:24:07 -080077#ifdef CONFIG_CHR_DEV_SG
78#include <scsi/sg.h>
79#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020080
Don Zickus58687ac2010-05-07 17:11:44 -040081#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050082#include <linux/nmi.h>
83#endif
84
Eric W. Biederman7058cb02007-10-18 03:05:58 -070085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#if defined(CONFIG_SYSCTL)
87
88/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089extern int sysctl_overcommit_memory;
90extern int sysctl_overcommit_ratio;
91extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070093extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070095extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096extern int pid_max;
97extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080099extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800100extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200101extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100102extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400103extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000104#ifndef CONFIG_MMU
105extern int sysctl_nr_trim_pages;
106#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200107#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200108extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400112#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200114static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700115#endif
116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700118static int __maybe_unused one = 1;
119static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800120static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700121static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700122#ifdef CONFIG_PRINTK
123static int ten_thousand = 10000;
124#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700125
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700126/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
127static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
130static int maxolduid = 65535;
131static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800132static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134static int ngroups_max = NGROUPS_MAX;
135
Dave Youngd14f1722010-02-25 20:28:57 -0500136#ifdef CONFIG_INOTIFY_USER
137#include <linux/inotify.h>
138#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700139#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700140#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif
142
David S. Miller08714202008-11-16 23:49:24 -0800143#ifdef CONFIG_SPARC64
144extern int sysctl_tsb_ratio;
145#endif
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#ifdef __hppa__
148extern int pwrsw_enabled;
149extern int unaligned_enabled;
150#endif
151
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800152#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#ifdef CONFIG_MATHEMU
154extern int sysctl_ieee_emulation_warnings;
155#endif
156extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700157extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#endif
159
Jes Sorensend2b176e2006-02-28 09:42:23 -0800160#ifdef CONFIG_IA64
161extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800162extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800163#endif
164
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700165#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700166static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700167 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700168static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800169 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700170#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700171
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700172#ifdef CONFIG_MAGIC_SYSRQ
173static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
174
175static int sysrq_sysctl_handler(ctl_table *table, int write,
176 void __user *buffer, size_t *lenp,
177 loff_t *ppos)
178{
179 int error;
180
181 error = proc_dointvec(table, write, buffer, lenp, ppos);
182 if (error)
183 return error;
184
185 if (write)
186 sysrq_toggle_support(__sysrq_enabled);
187
188 return 0;
189}
190
191#endif
192
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700193static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100194static struct ctl_table_root sysctl_table_root;
195static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100196 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100197 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400198 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100199 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400200 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100201};
202static struct ctl_table_root sysctl_table_root = {
203 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400204 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100205};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700207static struct ctl_table kern_table[];
208static struct ctl_table vm_table[];
209static struct ctl_table fs_table[];
210static struct ctl_table debug_table[];
211static struct ctl_table dev_table[];
212extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800213#ifdef CONFIG_EPOLL
214extern struct ctl_table epoll_table[];
215#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
218int sysctl_legacy_va_layout;
219#endif
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221/* The default sysctl tables: */
222
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700223static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 .procname = "kernel",
226 .mode = 0555,
227 .child = kern_table,
228 },
229 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 .procname = "vm",
231 .mode = 0555,
232 .child = vm_table,
233 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 .procname = "fs",
236 .mode = 0555,
237 .child = fs_table,
238 },
239 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .procname = "debug",
241 .mode = 0555,
242 .child = debug_table,
243 },
244 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 .procname = "dev",
246 .mode = 0555,
247 .child = dev_table,
248 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700249 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250};
251
Ingo Molnar77e54a12007-07-09 18:52:00 +0200252#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100253static int min_sched_granularity_ns = 100000; /* 100 usecs */
254static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
255static int min_wakeup_granularity_ns; /* 0 usecs */
256static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100257static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
258static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200259#endif
260
Mel Gorman5e771902010-05-24 14:32:31 -0700261#ifdef CONFIG_COMPACTION
262static int min_extfrag_threshold;
263static int max_extfrag_threshold = 1000;
264#endif
265
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700266static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200267 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200268 .procname = "sched_child_runs_first",
269 .data = &sysctl_sched_child_runs_first,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800272 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200273 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200274#ifdef CONFIG_SCHED_DEBUG
275 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100276 .procname = "sched_min_granularity_ns",
277 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800280 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200283 },
284 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200285 .procname = "sched_latency_ns",
286 .data = &sysctl_sched_latency,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800289 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
292 },
293 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200294 .procname = "sched_wakeup_granularity_ns",
295 .data = &sysctl_sched_wakeup_granularity,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800298 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299 .extra1 = &min_wakeup_granularity_ns,
300 .extra2 = &max_wakeup_granularity_ns,
301 },
302 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100303 .procname = "sched_tunable_scaling",
304 .data = &sysctl_sched_tunable_scaling,
305 .maxlen = sizeof(enum sched_tunable_scaling),
306 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800307 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100308 .extra1 = &min_sched_tunable_scaling,
309 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200310 },
311 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200312 .procname = "sched_migration_cost",
313 .data = &sysctl_sched_migration_cost,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800316 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200317 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100318 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100319 .procname = "sched_nr_migrate",
320 .data = &sysctl_sched_nr_migrate,
321 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100322 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800323 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100324 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530325 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200326 .procname = "sched_time_avg",
327 .data = &sysctl_sched_time_avg,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800330 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200331 },
332 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800333 .procname = "sched_shares_window",
334 .data = &sysctl_sched_shares_window,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = proc_dointvec,
338 },
339 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530340 .procname = "timer_migration",
341 .data = &sysctl_timer_migration,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800344 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530345 .extra1 = &zero,
346 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530347 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200348#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200349 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100350 .procname = "sched_rt_period_us",
351 .data = &sysctl_sched_rt_period,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800354 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100355 },
356 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100357 .procname = "sched_rt_runtime_us",
358 .data = &sysctl_sched_rt_runtime,
359 .maxlen = sizeof(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 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200364 .procname = "sched_compat_yield",
365 .data = &sysctl_sched_compat_yield,
366 .maxlen = sizeof(unsigned int),
367 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800368 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200369 },
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,
376 .proc_handler = proc_dointvec,
377 .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,
715 .proc_handler = proc_dointvec_minmax,
716 .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,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800950 .proc_handler = proc_dointvec,
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,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800980 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 },
982 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700983 .procname = "panic_on_oom",
984 .data = &sysctl_panic_on_oom,
985 .maxlen = sizeof(sysctl_panic_on_oom),
986 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800987 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700988 },
989 {
David Rientjesfe071d72007-10-16 23:25:56 -0700990 .procname = "oom_kill_allocating_task",
991 .data = &sysctl_oom_kill_allocating_task,
992 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
993 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800994 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700995 },
996 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800997 .procname = "oom_dump_tasks",
998 .data = &sysctl_oom_dump_tasks,
999 .maxlen = sizeof(sysctl_oom_dump_tasks),
1000 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001001 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001002 },
1003 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 .procname = "overcommit_ratio",
1005 .data = &sysctl_overcommit_ratio,
1006 .maxlen = sizeof(sysctl_overcommit_ratio),
1007 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001008 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 },
1010 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 .procname = "page-cluster",
1012 .data = &page_cluster,
1013 .maxlen = sizeof(int),
1014 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001015 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 },
1017 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 .procname = "dirty_background_ratio",
1019 .data = &dirty_background_ratio,
1020 .maxlen = sizeof(dirty_background_ratio),
1021 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001022 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 .extra1 = &zero,
1024 .extra2 = &one_hundred,
1025 },
1026 {
David Rientjes2da02992009-01-06 14:39:31 -08001027 .procname = "dirty_background_bytes",
1028 .data = &dirty_background_bytes,
1029 .maxlen = sizeof(dirty_background_bytes),
1030 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001031 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001032 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001033 },
1034 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 .procname = "dirty_ratio",
1036 .data = &vm_dirty_ratio,
1037 .maxlen = sizeof(vm_dirty_ratio),
1038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .extra1 = &zero,
1041 .extra2 = &one_hundred,
1042 },
1043 {
David Rientjes2da02992009-01-06 14:39:31 -08001044 .procname = "dirty_bytes",
1045 .data = &vm_dirty_bytes,
1046 .maxlen = sizeof(vm_dirty_bytes),
1047 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001048 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001049 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001050 },
1051 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001053 .data = &dirty_writeback_interval,
1054 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001056 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 },
1058 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001060 .data = &dirty_expire_interval,
1061 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001063 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 },
1065 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 .procname = "nr_pdflush_threads",
1067 .data = &nr_pdflush_threads,
1068 .maxlen = sizeof nr_pdflush_threads,
1069 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 },
1072 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 .procname = "swappiness",
1074 .data = &vm_swappiness,
1075 .maxlen = sizeof(vm_swappiness),
1076 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001077 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 .extra1 = &zero,
1079 .extra2 = &one_hundred,
1080 },
1081#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001082 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001084 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 .maxlen = sizeof(unsigned long),
1086 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 .extra1 = (void *)&hugetlb_zero,
1089 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001090 },
1091#ifdef CONFIG_NUMA
1092 {
1093 .procname = "nr_hugepages_mempolicy",
1094 .data = NULL,
1095 .maxlen = sizeof(unsigned long),
1096 .mode = 0644,
1097 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1098 .extra1 = (void *)&hugetlb_zero,
1099 .extra2 = (void *)&hugetlb_infinity,
1100 },
1101#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 .procname = "hugetlb_shm_group",
1104 .data = &sysctl_hugetlb_shm_group,
1105 .maxlen = sizeof(gid_t),
1106 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001107 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 },
Mel Gorman396faf02007-07-17 04:03:13 -07001109 {
Mel Gorman396faf02007-07-17 04:03:13 -07001110 .procname = "hugepages_treat_as_movable",
1111 .data = &hugepages_treat_as_movable,
1112 .maxlen = sizeof(int),
1113 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001114 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001115 },
Adam Litke54f9f802007-10-16 01:26:20 -07001116 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001117 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001118 .data = NULL,
1119 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001120 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001121 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001122 .extra1 = (void *)&hugetlb_zero,
1123 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001124 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125#endif
1126 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 .procname = "lowmem_reserve_ratio",
1128 .data = &sysctl_lowmem_reserve_ratio,
1129 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1130 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001131 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 },
1133 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001134 .procname = "drop_caches",
1135 .data = &sysctl_drop_caches,
1136 .maxlen = sizeof(int),
1137 .mode = 0644,
1138 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001139 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001140#ifdef CONFIG_COMPACTION
1141 {
1142 .procname = "compact_memory",
1143 .data = &sysctl_compact_memory,
1144 .maxlen = sizeof(int),
1145 .mode = 0200,
1146 .proc_handler = sysctl_compaction_handler,
1147 },
Mel Gorman5e771902010-05-24 14:32:31 -07001148 {
1149 .procname = "extfrag_threshold",
1150 .data = &sysctl_extfrag_threshold,
1151 .maxlen = sizeof(int),
1152 .mode = 0644,
1153 .proc_handler = sysctl_extfrag_handler,
1154 .extra1 = &min_extfrag_threshold,
1155 .extra2 = &max_extfrag_threshold,
1156 },
1157
Mel Gorman76ab0f52010-05-24 14:32:28 -07001158#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001159 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 .procname = "min_free_kbytes",
1161 .data = &min_free_kbytes,
1162 .maxlen = sizeof(min_free_kbytes),
1163 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001164 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 .extra1 = &zero,
1166 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001167 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001168 .procname = "percpu_pagelist_fraction",
1169 .data = &percpu_pagelist_fraction,
1170 .maxlen = sizeof(percpu_pagelist_fraction),
1171 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001172 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001173 .extra1 = &min_percpu_pagelist_fract,
1174 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175#ifdef CONFIG_MMU
1176 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 .procname = "max_map_count",
1178 .data = &sysctl_max_map_count,
1179 .maxlen = sizeof(sysctl_max_map_count),
1180 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001181 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001182 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001184#else
1185 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001186 .procname = "nr_trim_pages",
1187 .data = &sysctl_nr_trim_pages,
1188 .maxlen = sizeof(sysctl_nr_trim_pages),
1189 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001190 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001191 .extra1 = &zero,
1192 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193#endif
1194 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 .procname = "laptop_mode",
1196 .data = &laptop_mode,
1197 .maxlen = sizeof(laptop_mode),
1198 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001199 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 },
1201 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 .procname = "block_dump",
1203 .data = &block_dump,
1204 .maxlen = sizeof(block_dump),
1205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001206 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 .extra1 = &zero,
1208 },
1209 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 .procname = "vfs_cache_pressure",
1211 .data = &sysctl_vfs_cache_pressure,
1212 .maxlen = sizeof(sysctl_vfs_cache_pressure),
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#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1218 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 .procname = "legacy_va_layout",
1220 .data = &sysctl_legacy_va_layout,
1221 .maxlen = sizeof(sysctl_legacy_va_layout),
1222 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001223 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 .extra1 = &zero,
1225 },
1226#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001227#ifdef CONFIG_NUMA
1228 {
Christoph Lameter17436602006-01-18 17:42:32 -08001229 .procname = "zone_reclaim_mode",
1230 .data = &zone_reclaim_mode,
1231 .maxlen = sizeof(zone_reclaim_mode),
1232 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001233 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001234 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001235 },
Christoph Lameter96146342006-07-03 00:24:13 -07001236 {
Christoph Lameter96146342006-07-03 00:24:13 -07001237 .procname = "min_unmapped_ratio",
1238 .data = &sysctl_min_unmapped_ratio,
1239 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1240 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001241 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001242 .extra1 = &zero,
1243 .extra2 = &one_hundred,
1244 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001245 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001246 .procname = "min_slab_ratio",
1247 .data = &sysctl_min_slab_ratio,
1248 .maxlen = sizeof(sysctl_min_slab_ratio),
1249 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001250 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001251 .extra1 = &zero,
1252 .extra2 = &one_hundred,
1253 },
Christoph Lameter17436602006-01-18 17:42:32 -08001254#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001255#ifdef CONFIG_SMP
1256 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001257 .procname = "stat_interval",
1258 .data = &sysctl_stat_interval,
1259 .maxlen = sizeof(sysctl_stat_interval),
1260 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001261 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001262 },
1263#endif
David Howells6e141542009-12-15 19:27:45 +00001264#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001265 {
Eric Parised032182007-06-28 15:55:21 -04001266 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001267 .data = &dac_mmap_min_addr,
1268 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001269 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001270 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001271 },
David Howells6e141542009-12-15 19:27:45 +00001272#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001273#ifdef CONFIG_NUMA
1274 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001275 .procname = "numa_zonelist_order",
1276 .data = &numa_zonelist_order,
1277 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1278 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001279 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001280 },
1281#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001282#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001283 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001284 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001285 .procname = "vdso_enabled",
1286 .data = &vdso_enabled,
1287 .maxlen = sizeof(vdso_enabled),
1288 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001289 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001290 .extra1 = &zero,
1291 },
1292#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001293#ifdef CONFIG_HIGHMEM
1294 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001295 .procname = "highmem_is_dirtyable",
1296 .data = &vm_highmem_is_dirtyable,
1297 .maxlen = sizeof(vm_highmem_is_dirtyable),
1298 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001299 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001300 .extra1 = &zero,
1301 .extra2 = &one,
1302 },
1303#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001304 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001305 .procname = "scan_unevictable_pages",
1306 .data = &scan_unevictable_pages,
1307 .maxlen = sizeof(scan_unevictable_pages),
1308 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001309 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001310 },
Andi Kleen6a460792009-09-16 11:50:15 +02001311#ifdef CONFIG_MEMORY_FAILURE
1312 {
Andi Kleen6a460792009-09-16 11:50:15 +02001313 .procname = "memory_failure_early_kill",
1314 .data = &sysctl_memory_failure_early_kill,
1315 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001317 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001318 .extra1 = &zero,
1319 .extra2 = &one,
1320 },
1321 {
Andi Kleen6a460792009-09-16 11:50:15 +02001322 .procname = "memory_failure_recovery",
1323 .data = &sysctl_memory_failure_recovery,
1324 .maxlen = sizeof(sysctl_memory_failure_recovery),
1325 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001326 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001327 .extra1 = &zero,
1328 .extra2 = &one,
1329 },
1330#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001331 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332};
1333
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001334#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001335static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001336 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001337};
1338#endif
1339
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001340static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 .procname = "inode-nr",
1343 .data = &inodes_stat,
1344 .maxlen = 2*sizeof(int),
1345 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001346 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 },
1348 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 .procname = "inode-state",
1350 .data = &inodes_stat,
1351 .maxlen = 7*sizeof(int),
1352 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001353 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 },
1355 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 .procname = "file-nr",
1357 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001358 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001360 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 },
1362 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 .procname = "file-max",
1364 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001365 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001367 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 },
1369 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001370 .procname = "nr_open",
1371 .data = &sysctl_nr_open,
1372 .maxlen = sizeof(int),
1373 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001374 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001375 .extra1 = &sysctl_nr_open_min,
1376 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001377 },
1378 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 .procname = "dentry-state",
1380 .data = &dentry_stat,
1381 .maxlen = 6*sizeof(int),
1382 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001383 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 },
1385 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .procname = "overflowuid",
1387 .data = &fs_overflowuid,
1388 .maxlen = sizeof(int),
1389 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001390 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 .extra1 = &minolduid,
1392 .extra2 = &maxolduid,
1393 },
1394 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .procname = "overflowgid",
1396 .data = &fs_overflowgid,
1397 .maxlen = sizeof(int),
1398 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001399 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 .extra1 = &minolduid,
1401 .extra2 = &maxolduid,
1402 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001403#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 .procname = "leases-enable",
1406 .data = &leases_enable,
1407 .maxlen = sizeof(int),
1408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001409 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001411#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412#ifdef CONFIG_DNOTIFY
1413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .procname = "dir-notify-enable",
1415 .data = &dir_notify_enable,
1416 .maxlen = sizeof(int),
1417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001418 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 },
1420#endif
1421#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001422#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 .procname = "lease-break-time",
1425 .data = &lease_break_time,
1426 .maxlen = sizeof(int),
1427 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001428 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001430#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001431#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 .procname = "aio-nr",
1434 .data = &aio_nr,
1435 .maxlen = sizeof(aio_nr),
1436 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001437 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 },
1439 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 .procname = "aio-max-nr",
1441 .data = &aio_max_nr,
1442 .maxlen = sizeof(aio_max_nr),
1443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001444 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001446#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001447#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001448 {
Robert Love0399cb02005-07-13 12:38:18 -04001449 .procname = "inotify",
1450 .mode = 0555,
1451 .child = inotify_table,
1452 },
1453#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001454#ifdef CONFIG_EPOLL
1455 {
1456 .procname = "epoll",
1457 .mode = 0555,
1458 .child = epoll_table,
1459 },
1460#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001462 {
Alan Coxd6e71142005-06-23 00:09:43 -07001463 .procname = "suid_dumpable",
1464 .data = &suid_dumpable,
1465 .maxlen = sizeof(int),
1466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001467 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001468 .extra1 = &zero,
1469 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001470 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001471#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1472 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001473 .procname = "binfmt_misc",
1474 .mode = 0555,
1475 .child = binfmt_misc_table,
1476 },
1477#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001478 {
Jens Axboeff9da692010-06-03 14:54:39 +02001479 .procname = "pipe-max-size",
1480 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001481 .maxlen = sizeof(int),
1482 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001483 .proc_handler = &pipe_proc_fn,
1484 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001485 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001486 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487};
1488
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001489static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001490#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1491 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001492 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001493 .procname = "exception-trace",
1494 .data = &show_unhandled_signals,
1495 .maxlen = sizeof(int),
1496 .mode = 0644,
1497 .proc_handler = proc_dointvec
1498 },
1499#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001500#if defined(CONFIG_OPTPROBES)
1501 {
1502 .procname = "kprobes-optimization",
1503 .data = &sysctl_kprobes_optimization,
1504 .maxlen = sizeof(int),
1505 .mode = 0644,
1506 .proc_handler = proc_kprobes_optimization_handler,
1507 .extra1 = &zero,
1508 .extra2 = &one,
1509 },
1510#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001511 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512};
1513
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001514static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001515 { }
Robert Love0eeca282005-07-12 17:06:03 -04001516};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Al Viro330d57f2005-11-04 10:18:40 +00001518static DEFINE_SPINLOCK(sysctl_lock);
1519
1520/* called under sysctl_lock */
1521static int use_table(struct ctl_table_header *p)
1522{
1523 if (unlikely(p->unregistering))
1524 return 0;
1525 p->used++;
1526 return 1;
1527}
1528
1529/* called under sysctl_lock */
1530static void unuse_table(struct ctl_table_header *p)
1531{
1532 if (!--p->used)
1533 if (unlikely(p->unregistering))
1534 complete(p->unregistering);
1535}
1536
1537/* called under sysctl_lock, will reacquire if has to wait */
1538static void start_unregistering(struct ctl_table_header *p)
1539{
1540 /*
1541 * if p->used is 0, nobody will ever touch that entry again;
1542 * we'll eliminate all paths to it before dropping sysctl_lock
1543 */
1544 if (unlikely(p->used)) {
1545 struct completion wait;
1546 init_completion(&wait);
1547 p->unregistering = &wait;
1548 spin_unlock(&sysctl_lock);
1549 wait_for_completion(&wait);
1550 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001551 } else {
1552 /* anything non-NULL; we'll never dereference it */
1553 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001554 }
1555 /*
1556 * do not remove from the list until nobody holds it; walking the
1557 * list in do_sysctl() relies on that.
1558 */
1559 list_del_init(&p->ctl_entry);
1560}
1561
Al Virof7e6ced2008-07-15 01:44:23 -04001562void sysctl_head_get(struct ctl_table_header *head)
1563{
1564 spin_lock(&sysctl_lock);
1565 head->count++;
1566 spin_unlock(&sysctl_lock);
1567}
1568
1569void sysctl_head_put(struct ctl_table_header *head)
1570{
1571 spin_lock(&sysctl_lock);
1572 if (!--head->count)
1573 kfree(head);
1574 spin_unlock(&sysctl_lock);
1575}
1576
1577struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1578{
1579 if (!head)
1580 BUG();
1581 spin_lock(&sysctl_lock);
1582 if (!use_table(head))
1583 head = ERR_PTR(-ENOENT);
1584 spin_unlock(&sysctl_lock);
1585 return head;
1586}
1587
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001588void sysctl_head_finish(struct ctl_table_header *head)
1589{
1590 if (!head)
1591 return;
1592 spin_lock(&sysctl_lock);
1593 unuse_table(head);
1594 spin_unlock(&sysctl_lock);
1595}
1596
Al Viro73455092008-07-14 21:22:20 -04001597static struct ctl_table_set *
1598lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1599{
1600 struct ctl_table_set *set = &root->default_set;
1601 if (root->lookup)
1602 set = root->lookup(root, namespaces);
1603 return set;
1604}
1605
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001606static struct list_head *
1607lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001608{
Al Viro73455092008-07-14 21:22:20 -04001609 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1610 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001611}
1612
1613struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1614 struct ctl_table_header *prev)
1615{
1616 struct ctl_table_root *root;
1617 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001618 struct ctl_table_header *head;
1619 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001620
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001621 spin_lock(&sysctl_lock);
1622 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001623 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001624 tmp = &prev->ctl_entry;
1625 unuse_table(prev);
1626 goto next;
1627 }
1628 tmp = &root_table_header.ctl_entry;
1629 for (;;) {
1630 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1631
1632 if (!use_table(head))
1633 goto next;
1634 spin_unlock(&sysctl_lock);
1635 return head;
1636 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001637 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001638 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001639 header_list = lookup_header_list(root, namespaces);
1640 if (tmp != header_list)
1641 continue;
1642
1643 do {
1644 root = list_entry(root->root_list.next,
1645 struct ctl_table_root, root_list);
1646 if (root == &sysctl_table_root)
1647 goto out;
1648 header_list = lookup_header_list(root, namespaces);
1649 } while (list_empty(header_list));
1650 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001651 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001652out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001653 spin_unlock(&sysctl_lock);
1654 return NULL;
1655}
1656
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001657struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1658{
1659 return __sysctl_head_next(current->nsproxy, prev);
1660}
1661
1662void register_sysctl_root(struct ctl_table_root *root)
1663{
1664 spin_lock(&sysctl_lock);
1665 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1666 spin_unlock(&sysctl_lock);
1667}
1668
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001670 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 * some sysctl variables are readonly even to root.
1672 */
1673
1674static int test_perm(int mode, int op)
1675{
David Howells76aac0e2008-11-14 10:39:12 +11001676 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 mode >>= 6;
1678 else if (in_egroup_p(0))
1679 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001680 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 return 0;
1682 return -EACCES;
1683}
1684
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001685int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686{
1687 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001688 int mode;
1689
Al Viroe6305c42008-07-15 21:03:57 -04001690 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 if (error)
1692 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001693
1694 if (root->permissions)
1695 mode = root->permissions(root, current->nsproxy, table);
1696 else
1697 mode = table->mode;
1698
1699 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001702static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1703{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001704 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001705 table->parent = parent;
1706 if (table->child)
1707 sysctl_set_parent(table, table->child);
1708 }
1709}
1710
1711static __init int sysctl_init(void)
1712{
1713 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001714#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001715 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001716#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001717 return 0;
1718}
1719
1720core_initcall(sysctl_init);
1721
Al Virobfbcf032008-07-27 06:31:22 +01001722static struct ctl_table *is_branch_in(struct ctl_table *branch,
1723 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001724{
1725 struct ctl_table *p;
1726 const char *s = branch->procname;
1727
1728 /* branch should have named subdirectory as its first element */
1729 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001730 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001731
1732 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001733 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001734 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001735
1736 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001737 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001738 if (!p->child)
1739 continue;
1740 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001741 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001742 }
Al Virobfbcf032008-07-27 06:31:22 +01001743 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001744}
1745
1746/* see if attaching q to p would be an improvement */
1747static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1748{
1749 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001750 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001751 int is_better = 0;
1752 int not_in_parent = !p->attached_by;
1753
Al Virobfbcf032008-07-27 06:31:22 +01001754 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001755 if (by == q->attached_by)
1756 is_better = 1;
1757 if (to == p->attached_by)
1758 not_in_parent = 1;
1759 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001760 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001761 }
1762
1763 if (is_better && not_in_parent) {
1764 q->attached_by = by;
1765 q->attached_to = to;
1766 q->parent = p;
1767 }
1768}
1769
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001771 * __register_sysctl_paths - register a sysctl hierarchy
1772 * @root: List of sysctl headers to register on
1773 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001774 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 *
1777 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001778 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001780 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1783 * enter a sysctl file
1784 *
1785 * data - a pointer to data for use by proc_handler
1786 *
1787 * maxlen - the maximum size in bytes of the data
1788 *
1789 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1790 *
1791 * child - a pointer to the child sysctl table if this entry is a directory, or
1792 * %NULL.
1793 *
1794 * proc_handler - the text handler routine (described below)
1795 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 * de - for internal use by the sysctl routines
1797 *
1798 * extra1, extra2 - extra pointers usable by the proc handler routines
1799 *
1800 * Leaf nodes in the sysctl tree will be represented by a single file
1801 * under /proc; non-leaf nodes will be represented by directories.
1802 *
1803 * sysctl(2) can automatically manage read and write requests through
1804 * the sysctl table. The data and maxlen fields of the ctl_table
1805 * struct enable minimal validation of the values being written to be
1806 * performed, and the mode field allows minimal authentication.
1807 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 * There must be a proc_handler routine for any terminal nodes
1809 * mirrored under /proc/sys (non-terminals are handled by a built-in
1810 * directory handler). Several default handlers are available to
1811 * cover common cases -
1812 *
1813 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1814 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1815 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1816 *
1817 * It is the handler's job to read the input buffer from user memory
1818 * and process it. The handler should return 0 on success.
1819 *
1820 * This routine returns %NULL on a failure to register, and a pointer
1821 * to the table header on success.
1822 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001823struct ctl_table_header *__register_sysctl_paths(
1824 struct ctl_table_root *root,
1825 struct nsproxy *namespaces,
1826 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001828 struct ctl_table_header *header;
1829 struct ctl_table *new, **prevp;
1830 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001831 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001832
1833 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001834 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001835 ;
1836
1837 /*
1838 * For each path component, allocate a 2-element ctl_table array.
1839 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001840 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001841 *
1842 * We allocate everything in one go so that we don't have to
1843 * worry about freeing additional memory in unregister_sysctl_table.
1844 */
1845 header = kzalloc(sizeof(struct ctl_table_header) +
1846 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1847 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001849
1850 new = (struct ctl_table *) (header + 1);
1851
1852 /* Now connect the dots */
1853 prevp = &header->ctl_table;
1854 for (n = 0; n < npath; ++n, ++path) {
1855 /* Copy the procname */
1856 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001857 new->mode = 0555;
1858
1859 *prevp = new;
1860 prevp = &new->child;
1861
1862 new += 2;
1863 }
1864 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001865 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001866
1867 INIT_LIST_HEAD(&header->ctl_entry);
1868 header->used = 0;
1869 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001870 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001871 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001872 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001873#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001874 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001875 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001876 return NULL;
1877 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001878#endif
Al Viro330d57f2005-11-04 10:18:40 +00001879 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001880 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001881 header->attached_by = header->ctl_table;
1882 header->attached_to = root_table;
1883 header->parent = &root_table_header;
1884 for (set = header->set; set; set = set->parent) {
1885 struct ctl_table_header *p;
1886 list_for_each_entry(p, &set->list, ctl_entry) {
1887 if (p->unregistering)
1888 continue;
1889 try_attach(p, header);
1890 }
1891 }
1892 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001893 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001894 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001895
1896 return header;
1897}
1898
1899/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001900 * register_sysctl_table_path - register a sysctl table hierarchy
1901 * @path: The path to the directory the sysctl table is in.
1902 * @table: the top-level table structure
1903 *
1904 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1905 * array. A completely 0 filled entry terminates the table.
1906 *
1907 * See __register_sysctl_paths for more details.
1908 */
1909struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1910 struct ctl_table *table)
1911{
1912 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1913 path, table);
1914}
1915
1916/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001917 * register_sysctl_table - register a sysctl table hierarchy
1918 * @table: the top-level table structure
1919 *
1920 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1921 * array. A completely 0 filled entry terminates the table.
1922 *
1923 * See register_sysctl_paths for more details.
1924 */
1925struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1926{
1927 static const struct ctl_path null_path[] = { {} };
1928
1929 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930}
1931
1932/**
1933 * unregister_sysctl_table - unregister a sysctl table hierarchy
1934 * @header: the header returned from register_sysctl_table
1935 *
1936 * Unregisters the sysctl table and all children. proc entries may not
1937 * actually be removed until they are no longer used by anyone.
1938 */
1939void unregister_sysctl_table(struct ctl_table_header * header)
1940{
Al Viro330d57f2005-11-04 10:18:40 +00001941 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001942
1943 if (header == NULL)
1944 return;
1945
Al Viro330d57f2005-11-04 10:18:40 +00001946 spin_lock(&sysctl_lock);
1947 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001948 if (!--header->parent->count) {
1949 WARN_ON(1);
1950 kfree(header->parent);
1951 }
Al Virof7e6ced2008-07-15 01:44:23 -04001952 if (!--header->count)
1953 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001954 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955}
1956
Al Viro90434762008-07-15 08:54:06 -04001957int sysctl_is_seen(struct ctl_table_header *p)
1958{
1959 struct ctl_table_set *set = p->set;
1960 int res;
1961 spin_lock(&sysctl_lock);
1962 if (p->unregistering)
1963 res = 0;
1964 else if (!set->is_seen)
1965 res = 1;
1966 else
1967 res = set->is_seen(set);
1968 spin_unlock(&sysctl_lock);
1969 return res;
1970}
1971
Al Viro73455092008-07-14 21:22:20 -04001972void setup_sysctl_set(struct ctl_table_set *p,
1973 struct ctl_table_set *parent,
1974 int (*is_seen)(struct ctl_table_set *))
1975{
1976 INIT_LIST_HEAD(&p->list);
1977 p->parent = parent ? parent : &sysctl_table_root.default_set;
1978 p->is_seen = is_seen;
1979}
1980
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001981#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001982struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001983{
1984 return NULL;
1985}
1986
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001987struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1988 struct ctl_table *table)
1989{
1990 return NULL;
1991}
1992
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001993void unregister_sysctl_table(struct ctl_table_header * table)
1994{
1995}
1996
Al Viro73455092008-07-14 21:22:20 -04001997void setup_sysctl_set(struct ctl_table_set *p,
1998 struct ctl_table_set *parent,
1999 int (*is_seen)(struct ctl_table_set *))
2000{
2001}
2002
Al Virof7e6ced2008-07-15 01:44:23 -04002003void sysctl_head_put(struct ctl_table_header *head)
2004{
2005}
2006
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002007#endif /* CONFIG_SYSCTL */
2008
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009/*
2010 * /proc/sys support
2011 */
2012
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002013#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002015static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002016 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002017 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002018{
2019 size_t len;
2020 char __user *p;
2021 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002022
2023 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002024 *lenp = 0;
2025 return 0;
2026 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002027
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002028 if (write) {
2029 len = 0;
2030 p = buffer;
2031 while (len < *lenp) {
2032 if (get_user(c, p++))
2033 return -EFAULT;
2034 if (c == 0 || c == '\n')
2035 break;
2036 len++;
2037 }
2038 if (len >= maxlen)
2039 len = maxlen-1;
2040 if(copy_from_user(data, buffer, len))
2041 return -EFAULT;
2042 ((char *) data)[len] = 0;
2043 *ppos += *lenp;
2044 } else {
2045 len = strlen(data);
2046 if (len > maxlen)
2047 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002048
2049 if (*ppos > len) {
2050 *lenp = 0;
2051 return 0;
2052 }
2053
2054 data += *ppos;
2055 len -= *ppos;
2056
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002057 if (len > *lenp)
2058 len = *lenp;
2059 if (len)
2060 if(copy_to_user(buffer, data, len))
2061 return -EFAULT;
2062 if (len < *lenp) {
2063 if(put_user('\n', ((char __user *) buffer) + len))
2064 return -EFAULT;
2065 len++;
2066 }
2067 *lenp = len;
2068 *ppos += len;
2069 }
2070 return 0;
2071}
2072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073/**
2074 * proc_dostring - read a string sysctl
2075 * @table: the sysctl table
2076 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 * @buffer: the user buffer
2078 * @lenp: the size of the user buffer
2079 * @ppos: file position
2080 *
2081 * Reads/writes a string from/to the user buffer. If the kernel
2082 * buffer provided is not large enough to hold the string, the
2083 * string is truncated. The copied string is %NULL-terminated.
2084 * If the string is being read by the user process, it is copied
2085 * and a newline '\n' is added. It is truncated if the buffer is
2086 * not large enough.
2087 *
2088 * Returns 0 on success.
2089 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002090int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 void __user *buffer, size_t *lenp, loff_t *ppos)
2092{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002093 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002094 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095}
2096
Amerigo Wang00b7c332010-05-05 00:26:45 +00002097static size_t proc_skip_spaces(char **buf)
2098{
2099 size_t ret;
2100 char *tmp = skip_spaces(*buf);
2101 ret = tmp - *buf;
2102 *buf = tmp;
2103 return ret;
2104}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002106static void proc_skip_char(char **buf, size_t *size, const char v)
2107{
2108 while (*size) {
2109 if (**buf != v)
2110 break;
2111 (*size)--;
2112 (*buf)++;
2113 }
2114}
2115
Amerigo Wang00b7c332010-05-05 00:26:45 +00002116#define TMPBUFLEN 22
2117/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002118 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002119 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002120 * @buf: a kernel buffer
2121 * @size: size of the kernel buffer
2122 * @val: this is where the number will be stored
2123 * @neg: set to %TRUE if number is negative
2124 * @perm_tr: a vector which contains the allowed trailers
2125 * @perm_tr_len: size of the perm_tr vector
2126 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002127 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002128 * In case of success %0 is returned and @buf and @size are updated with
2129 * the amount of bytes read. If @tr is non-NULL and a trailing
2130 * character exists (size is non-zero after returning from this
2131 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002132 */
2133static int proc_get_long(char **buf, size_t *size,
2134 unsigned long *val, bool *neg,
2135 const char *perm_tr, unsigned perm_tr_len, char *tr)
2136{
2137 int len;
2138 char *p, tmp[TMPBUFLEN];
2139
2140 if (!*size)
2141 return -EINVAL;
2142
2143 len = *size;
2144 if (len > TMPBUFLEN - 1)
2145 len = TMPBUFLEN - 1;
2146
2147 memcpy(tmp, *buf, len);
2148
2149 tmp[len] = 0;
2150 p = tmp;
2151 if (*p == '-' && *size > 1) {
2152 *neg = true;
2153 p++;
2154 } else
2155 *neg = false;
2156 if (!isdigit(*p))
2157 return -EINVAL;
2158
2159 *val = simple_strtoul(p, &p, 0);
2160
2161 len = p - tmp;
2162
2163 /* We don't know if the next char is whitespace thus we may accept
2164 * invalid integers (e.g. 1234...a) or two integers instead of one
2165 * (e.g. 123...1). So lets not allow such large numbers. */
2166 if (len == TMPBUFLEN - 1)
2167 return -EINVAL;
2168
2169 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2170 return -EINVAL;
2171
2172 if (tr && (len < *size))
2173 *tr = *p;
2174
2175 *buf += len;
2176 *size -= len;
2177
2178 return 0;
2179}
2180
2181/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002182 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002183 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002184 * @buf: the user buffer
2185 * @size: the size of the user buffer
2186 * @val: the integer to be converted
2187 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002188 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002189 * In case of success %0 is returned and @buf and @size are updated with
2190 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002191 */
2192static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2193 bool neg)
2194{
2195 int len;
2196 char tmp[TMPBUFLEN], *p = tmp;
2197
2198 sprintf(p, "%s%lu", neg ? "-" : "", val);
2199 len = strlen(tmp);
2200 if (len > *size)
2201 len = *size;
2202 if (copy_to_user(*buf, tmp, len))
2203 return -EFAULT;
2204 *size -= len;
2205 *buf += len;
2206 return 0;
2207}
2208#undef TMPBUFLEN
2209
2210static int proc_put_char(void __user **buf, size_t *size, char c)
2211{
2212 if (*size) {
2213 char __user **buffer = (char __user **)buf;
2214 if (put_user(c, *buffer))
2215 return -EFAULT;
2216 (*size)--, (*buffer)++;
2217 *buf = *buffer;
2218 }
2219 return 0;
2220}
2221
2222static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 int *valp,
2224 int write, void *data)
2225{
2226 if (write) {
2227 *valp = *negp ? -*lvalp : *lvalp;
2228 } else {
2229 int val = *valp;
2230 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002231 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 *lvalp = (unsigned long)-val;
2233 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002234 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 *lvalp = (unsigned long)val;
2236 }
2237 }
2238 return 0;
2239}
2240
Amerigo Wang00b7c332010-05-05 00:26:45 +00002241static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2242
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002243static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002244 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002245 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002246 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 int write, void *data),
2248 void *data)
2249{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002250 int *i, vleft, first = 1, err = 0;
2251 unsigned long page = 0;
2252 size_t left;
2253 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Amerigo Wang00b7c332010-05-05 00:26:45 +00002255 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 *lenp = 0;
2257 return 0;
2258 }
2259
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002260 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 vleft = table->maxlen / sizeof(*i);
2262 left = *lenp;
2263
2264 if (!conv)
2265 conv = do_proc_dointvec_conv;
2266
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268 if (left > PAGE_SIZE - 1)
2269 left = PAGE_SIZE - 1;
2270 page = __get_free_page(GFP_TEMPORARY);
2271 kbuf = (char *) page;
2272 if (!kbuf)
2273 return -ENOMEM;
2274 if (copy_from_user(kbuf, buffer, left)) {
2275 err = -EFAULT;
2276 goto free;
2277 }
2278 kbuf[left] = 0;
2279 }
2280
2281 for (; left && vleft--; i++, first=0) {
2282 unsigned long lval;
2283 bool neg;
2284
2285 if (write) {
2286 left -= proc_skip_spaces(&kbuf);
2287
J. R. Okajima563b0462010-05-25 16:10:14 -07002288 if (!left)
2289 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002290 err = proc_get_long(&kbuf, &left, &lval, &neg,
2291 proc_wspace_sep,
2292 sizeof(proc_wspace_sep), NULL);
2293 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002295 if (conv(&neg, &lval, i, 1, data)) {
2296 err = -EINVAL;
2297 break;
2298 }
2299 } else {
2300 if (conv(&neg, &lval, i, 0, data)) {
2301 err = -EINVAL;
2302 break;
2303 }
2304 if (!first)
2305 err = proc_put_char(&buffer, &left, '\t');
2306 if (err)
2307 break;
2308 err = proc_put_long(&buffer, &left, lval, neg);
2309 if (err)
2310 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 }
2312 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002313
2314 if (!write && !first && left && !err)
2315 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002316 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002317 left -= proc_skip_spaces(&kbuf);
2318free:
2319 if (write) {
2320 free_page(page);
2321 if (first)
2322 return err ? : -EINVAL;
2323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 *lenp -= left;
2325 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002326 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002329static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002330 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002331 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002332 int write, void *data),
2333 void *data)
2334{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002335 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002336 buffer, lenp, ppos, conv, data);
2337}
2338
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339/**
2340 * proc_dointvec - read a vector of integers
2341 * @table: the sysctl table
2342 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 * @buffer: the user buffer
2344 * @lenp: the size of the user buffer
2345 * @ppos: file position
2346 *
2347 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2348 * values from/to the user buffer, treated as an ASCII string.
2349 *
2350 * Returns 0 on success.
2351 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002352int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 void __user *buffer, size_t *lenp, loff_t *ppos)
2354{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002355 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 NULL,NULL);
2357}
2358
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002359/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002360 * Taint values can only be increased
2361 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002362 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002363static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002364 void __user *buffer, size_t *lenp, loff_t *ppos)
2365{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002366 struct ctl_table t;
2367 unsigned long tmptaint = get_taint();
2368 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002369
Bastian Blank91fcd412007-04-23 14:41:14 -07002370 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002371 return -EPERM;
2372
Andi Kleen25ddbb12008-10-15 22:01:41 -07002373 t = *table;
2374 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002375 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002376 if (err < 0)
2377 return err;
2378
2379 if (write) {
2380 /*
2381 * Poor man's atomic or. Not worth adding a primitive
2382 * to everyone's atomic.h for this
2383 */
2384 int i;
2385 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2386 if ((tmptaint >> i) & 1)
2387 add_taint(i);
2388 }
2389 }
2390
2391 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002392}
2393
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394struct do_proc_dointvec_minmax_conv_param {
2395 int *min;
2396 int *max;
2397};
2398
Amerigo Wang00b7c332010-05-05 00:26:45 +00002399static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2400 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 int write, void *data)
2402{
2403 struct do_proc_dointvec_minmax_conv_param *param = data;
2404 if (write) {
2405 int val = *negp ? -*lvalp : *lvalp;
2406 if ((param->min && *param->min > val) ||
2407 (param->max && *param->max < val))
2408 return -EINVAL;
2409 *valp = val;
2410 } else {
2411 int val = *valp;
2412 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002413 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 *lvalp = (unsigned long)-val;
2415 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002416 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 *lvalp = (unsigned long)val;
2418 }
2419 }
2420 return 0;
2421}
2422
2423/**
2424 * proc_dointvec_minmax - read a vector of integers with min/max values
2425 * @table: the sysctl table
2426 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 * @buffer: the user buffer
2428 * @lenp: the size of the user buffer
2429 * @ppos: file position
2430 *
2431 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2432 * values from/to the user buffer, treated as an ASCII string.
2433 *
2434 * This routine will ensure the values are within the range specified by
2435 * table->extra1 (min) and table->extra2 (max).
2436 *
2437 * Returns 0 on success.
2438 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002439int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 void __user *buffer, size_t *lenp, loff_t *ppos)
2441{
2442 struct do_proc_dointvec_minmax_conv_param param = {
2443 .min = (int *) table->extra1,
2444 .max = (int *) table->extra2,
2445 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002446 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 do_proc_dointvec_minmax_conv, &param);
2448}
2449
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002450static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 void __user *buffer,
2452 size_t *lenp, loff_t *ppos,
2453 unsigned long convmul,
2454 unsigned long convdiv)
2455{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002456 unsigned long *i, *min, *max;
2457 int vleft, first = 1, err = 0;
2458 unsigned long page = 0;
2459 size_t left;
2460 char *kbuf;
2461
2462 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 *lenp = 0;
2464 return 0;
2465 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002466
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002467 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 min = (unsigned long *) table->extra1;
2469 max = (unsigned long *) table->extra2;
2470 vleft = table->maxlen / sizeof(unsigned long);
2471 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002472
2473 if (write) {
2474 if (left > PAGE_SIZE - 1)
2475 left = PAGE_SIZE - 1;
2476 page = __get_free_page(GFP_TEMPORARY);
2477 kbuf = (char *) page;
2478 if (!kbuf)
2479 return -ENOMEM;
2480 if (copy_from_user(kbuf, buffer, left)) {
2481 err = -EFAULT;
2482 goto free;
2483 }
2484 kbuf[left] = 0;
2485 }
2486
Eric Dumazet27b3d802010-10-07 12:59:29 -07002487 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002488 unsigned long val;
2489
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002491 bool neg;
2492
2493 left -= proc_skip_spaces(&kbuf);
2494
2495 err = proc_get_long(&kbuf, &left, &val, &neg,
2496 proc_wspace_sep,
2497 sizeof(proc_wspace_sep), NULL);
2498 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 break;
2500 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 continue;
2502 if ((min && val < *min) || (max && val > *max))
2503 continue;
2504 *i = val;
2505 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002506 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002508 err = proc_put_char(&buffer, &left, '\t');
2509 err = proc_put_long(&buffer, &left, val, false);
2510 if (err)
2511 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 }
2513 }
2514
Amerigo Wang00b7c332010-05-05 00:26:45 +00002515 if (!write && !first && left && !err)
2516 err = proc_put_char(&buffer, &left, '\n');
2517 if (write && !err)
2518 left -= proc_skip_spaces(&kbuf);
2519free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002521 free_page(page);
2522 if (first)
2523 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 *lenp -= left;
2526 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002527 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002530static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002531 void __user *buffer,
2532 size_t *lenp, loff_t *ppos,
2533 unsigned long convmul,
2534 unsigned long convdiv)
2535{
2536 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002537 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002538}
2539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540/**
2541 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2542 * @table: the sysctl table
2543 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 * @buffer: the user buffer
2545 * @lenp: the size of the user buffer
2546 * @ppos: file position
2547 *
2548 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2549 * values from/to the user buffer, treated as an ASCII string.
2550 *
2551 * This routine will ensure the values are within the range specified by
2552 * table->extra1 (min) and table->extra2 (max).
2553 *
2554 * Returns 0 on success.
2555 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002556int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 void __user *buffer, size_t *lenp, loff_t *ppos)
2558{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002559 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560}
2561
2562/**
2563 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2564 * @table: the sysctl table
2565 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 * @buffer: the user buffer
2567 * @lenp: the size of the user buffer
2568 * @ppos: file position
2569 *
2570 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2571 * values from/to the user buffer, treated as an ASCII string. The values
2572 * are treated as milliseconds, and converted to jiffies when they are stored.
2573 *
2574 * This routine will ensure the values are within the range specified by
2575 * table->extra1 (min) and table->extra2 (max).
2576 *
2577 * Returns 0 on success.
2578 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002579int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 void __user *buffer,
2581 size_t *lenp, loff_t *ppos)
2582{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002583 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 lenp, ppos, HZ, 1000l);
2585}
2586
2587
Amerigo Wang00b7c332010-05-05 00:26:45 +00002588static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 int *valp,
2590 int write, void *data)
2591{
2592 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002593 if (*lvalp > LONG_MAX / HZ)
2594 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2596 } else {
2597 int val = *valp;
2598 unsigned long lval;
2599 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002600 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 lval = (unsigned long)-val;
2602 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002603 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 lval = (unsigned long)val;
2605 }
2606 *lvalp = lval / HZ;
2607 }
2608 return 0;
2609}
2610
Amerigo Wang00b7c332010-05-05 00:26:45 +00002611static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 int *valp,
2613 int write, void *data)
2614{
2615 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002616 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2617 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2619 } else {
2620 int val = *valp;
2621 unsigned long lval;
2622 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002623 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 lval = (unsigned long)-val;
2625 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002626 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 lval = (unsigned long)val;
2628 }
2629 *lvalp = jiffies_to_clock_t(lval);
2630 }
2631 return 0;
2632}
2633
Amerigo Wang00b7c332010-05-05 00:26:45 +00002634static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 int *valp,
2636 int write, void *data)
2637{
2638 if (write) {
2639 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2640 } else {
2641 int val = *valp;
2642 unsigned long lval;
2643 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002644 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 lval = (unsigned long)-val;
2646 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002647 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 lval = (unsigned long)val;
2649 }
2650 *lvalp = jiffies_to_msecs(lval);
2651 }
2652 return 0;
2653}
2654
2655/**
2656 * proc_dointvec_jiffies - read a vector of integers as seconds
2657 * @table: the sysctl table
2658 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 * @buffer: the user buffer
2660 * @lenp: the size of the user buffer
2661 * @ppos: file position
2662 *
2663 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2664 * values from/to the user buffer, treated as an ASCII string.
2665 * The values read are assumed to be in seconds, and are converted into
2666 * jiffies.
2667 *
2668 * Returns 0 on success.
2669 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002670int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 void __user *buffer, size_t *lenp, loff_t *ppos)
2672{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002673 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 do_proc_dointvec_jiffies_conv,NULL);
2675}
2676
2677/**
2678 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2679 * @table: the sysctl table
2680 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 * @buffer: the user buffer
2682 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002683 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 *
2685 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2686 * values from/to the user buffer, treated as an ASCII string.
2687 * The values read are assumed to be in 1/USER_HZ seconds, and
2688 * are converted into jiffies.
2689 *
2690 * Returns 0 on success.
2691 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002692int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 void __user *buffer, size_t *lenp, loff_t *ppos)
2694{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002695 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 do_proc_dointvec_userhz_jiffies_conv,NULL);
2697}
2698
2699/**
2700 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2701 * @table: the sysctl table
2702 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 * @buffer: the user buffer
2704 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002705 * @ppos: file position
2706 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 *
2708 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2709 * values from/to the user buffer, treated as an ASCII string.
2710 * The values read are assumed to be in 1/1000 seconds, and
2711 * are converted into jiffies.
2712 *
2713 * Returns 0 on success.
2714 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002715int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 void __user *buffer, size_t *lenp, loff_t *ppos)
2717{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002718 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 do_proc_dointvec_ms_jiffies_conv, NULL);
2720}
2721
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002722static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002723 void __user *buffer, size_t *lenp, loff_t *ppos)
2724{
2725 struct pid *new_pid;
2726 pid_t tmp;
2727 int r;
2728
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002729 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002730
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002731 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002732 lenp, ppos, NULL, NULL);
2733 if (r || !write)
2734 return r;
2735
2736 new_pid = find_get_pid(tmp);
2737 if (!new_pid)
2738 return -ESRCH;
2739
2740 put_pid(xchg(&cad_pid, new_pid));
2741 return 0;
2742}
2743
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002744/**
2745 * proc_do_large_bitmap - read/write from/to a large bitmap
2746 * @table: the sysctl table
2747 * @write: %TRUE if this is a write to the sysctl file
2748 * @buffer: the user buffer
2749 * @lenp: the size of the user buffer
2750 * @ppos: file position
2751 *
2752 * The bitmap is stored at table->data and the bitmap length (in bits)
2753 * in table->maxlen.
2754 *
2755 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2756 * large bitmaps may be represented in a compact manner. Writing into
2757 * the file will clear the bitmap then update it with the given input.
2758 *
2759 * Returns 0 on success.
2760 */
2761int proc_do_large_bitmap(struct ctl_table *table, int write,
2762 void __user *buffer, size_t *lenp, loff_t *ppos)
2763{
2764 int err = 0;
2765 bool first = 1;
2766 size_t left = *lenp;
2767 unsigned long bitmap_len = table->maxlen;
2768 unsigned long *bitmap = (unsigned long *) table->data;
2769 unsigned long *tmp_bitmap = NULL;
2770 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2771
2772 if (!bitmap_len || !left || (*ppos && !write)) {
2773 *lenp = 0;
2774 return 0;
2775 }
2776
2777 if (write) {
2778 unsigned long page = 0;
2779 char *kbuf;
2780
2781 if (left > PAGE_SIZE - 1)
2782 left = PAGE_SIZE - 1;
2783
2784 page = __get_free_page(GFP_TEMPORARY);
2785 kbuf = (char *) page;
2786 if (!kbuf)
2787 return -ENOMEM;
2788 if (copy_from_user(kbuf, buffer, left)) {
2789 free_page(page);
2790 return -EFAULT;
2791 }
2792 kbuf[left] = 0;
2793
2794 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2795 GFP_KERNEL);
2796 if (!tmp_bitmap) {
2797 free_page(page);
2798 return -ENOMEM;
2799 }
2800 proc_skip_char(&kbuf, &left, '\n');
2801 while (!err && left) {
2802 unsigned long val_a, val_b;
2803 bool neg;
2804
2805 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2806 sizeof(tr_a), &c);
2807 if (err)
2808 break;
2809 if (val_a >= bitmap_len || neg) {
2810 err = -EINVAL;
2811 break;
2812 }
2813
2814 val_b = val_a;
2815 if (left) {
2816 kbuf++;
2817 left--;
2818 }
2819
2820 if (c == '-') {
2821 err = proc_get_long(&kbuf, &left, &val_b,
2822 &neg, tr_b, sizeof(tr_b),
2823 &c);
2824 if (err)
2825 break;
2826 if (val_b >= bitmap_len || neg ||
2827 val_a > val_b) {
2828 err = -EINVAL;
2829 break;
2830 }
2831 if (left) {
2832 kbuf++;
2833 left--;
2834 }
2835 }
2836
2837 while (val_a <= val_b)
2838 set_bit(val_a++, tmp_bitmap);
2839
2840 first = 0;
2841 proc_skip_char(&kbuf, &left, '\n');
2842 }
2843 free_page(page);
2844 } else {
2845 unsigned long bit_a, bit_b = 0;
2846
2847 while (left) {
2848 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2849 if (bit_a >= bitmap_len)
2850 break;
2851 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2852 bit_a + 1) - 1;
2853
2854 if (!first) {
2855 err = proc_put_char(&buffer, &left, ',');
2856 if (err)
2857 break;
2858 }
2859 err = proc_put_long(&buffer, &left, bit_a, false);
2860 if (err)
2861 break;
2862 if (bit_a != bit_b) {
2863 err = proc_put_char(&buffer, &left, '-');
2864 if (err)
2865 break;
2866 err = proc_put_long(&buffer, &left, bit_b, false);
2867 if (err)
2868 break;
2869 }
2870
2871 first = 0; bit_b++;
2872 }
2873 if (!err)
2874 err = proc_put_char(&buffer, &left, '\n');
2875 }
2876
2877 if (!err) {
2878 if (write) {
2879 if (*ppos)
2880 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2881 else
2882 memcpy(bitmap, tmp_bitmap,
2883 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2884 }
2885 kfree(tmp_bitmap);
2886 *lenp -= left;
2887 *ppos += *lenp;
2888 return 0;
2889 } else {
2890 kfree(tmp_bitmap);
2891 return err;
2892 }
2893}
2894
Jovi Zhang55610502011-01-12 17:00:45 -08002895#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002897int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 void __user *buffer, size_t *lenp, loff_t *ppos)
2899{
2900 return -ENOSYS;
2901}
2902
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002903int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 void __user *buffer, size_t *lenp, loff_t *ppos)
2905{
2906 return -ENOSYS;
2907}
2908
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002909int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 void __user *buffer, size_t *lenp, loff_t *ppos)
2911{
2912 return -ENOSYS;
2913}
2914
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002915int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 void __user *buffer, size_t *lenp, loff_t *ppos)
2917{
2918 return -ENOSYS;
2919}
2920
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002921int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 void __user *buffer, size_t *lenp, loff_t *ppos)
2923{
2924 return -ENOSYS;
2925}
2926
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002927int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 void __user *buffer, size_t *lenp, loff_t *ppos)
2929{
2930 return -ENOSYS;
2931}
2932
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002933int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 void __user *buffer, size_t *lenp, loff_t *ppos)
2935{
2936 return -ENOSYS;
2937}
2938
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002939int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 void __user *buffer,
2941 size_t *lenp, loff_t *ppos)
2942{
2943 return -ENOSYS;
2944}
2945
2946
Jovi Zhang55610502011-01-12 17:00:45 -08002947#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949/*
2950 * No sense putting this after each symbol definition, twice,
2951 * exception granted :-)
2952 */
2953EXPORT_SYMBOL(proc_dointvec);
2954EXPORT_SYMBOL(proc_dointvec_jiffies);
2955EXPORT_SYMBOL(proc_dointvec_minmax);
2956EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2957EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2958EXPORT_SYMBOL(proc_dostring);
2959EXPORT_SYMBOL(proc_doulongvec_minmax);
2960EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2961EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002962EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963EXPORT_SYMBOL(unregister_sysctl_table);