blob: cbfda7e2416e48a913d3a8a5cd2cb91897eb8109 [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 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100363#ifdef CONFIG_SCHED_AUTOGROUP
364 {
365 .procname = "sched_autogroup_enabled",
366 .data = &sysctl_sched_autogroup_enabled,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
369 .proc_handler = proc_dointvec,
370 .extra1 = &zero,
371 .extra2 = &one,
372 },
373#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700374#ifdef CONFIG_PROVE_LOCKING
375 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700376 .procname = "prove_locking",
377 .data = &prove_locking,
378 .maxlen = sizeof(int),
379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800380 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700381 },
382#endif
383#ifdef CONFIG_LOCK_STAT
384 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700385 .procname = "lock_stat",
386 .data = &lock_stat,
387 .maxlen = sizeof(int),
388 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800389 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700390 },
391#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200392 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 .procname = "panic",
394 .data = &panic_timeout,
395 .maxlen = sizeof(int),
396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800397 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 },
399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .procname = "core_uses_pid",
401 .data = &core_uses_pid,
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_pattern",
408 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700409 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800411 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 },
Neil Hormana2939802009-09-23 15:56:56 -0700413 {
Neil Hormana2939802009-09-23 15:56:56 -0700414 .procname = "core_pipe_limit",
415 .data = &core_pipe_limit,
416 .maxlen = sizeof(unsigned int),
417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800418 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700419 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800420#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700423 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800425 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800427#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100428#ifdef CONFIG_LATENCYTOP
429 {
430 .procname = "latencytop",
431 .data = &latencytop_enabled,
432 .maxlen = sizeof(int),
433 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800434 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100435 },
436#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#ifdef CONFIG_BLK_DEV_INITRD
438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .procname = "real-root-dev",
440 .data = &real_root_dev,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800443 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 },
445#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700446 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700447 .procname = "print-fatal-signals",
448 .data = &print_fatal_signals,
449 .maxlen = sizeof(int),
450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800451 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700452 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700453#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 .procname = "reboot-cmd",
456 .data = reboot_command,
457 .maxlen = 256,
458 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800459 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 },
461 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 .procname = "stop-a",
463 .data = &stop_a_enabled,
464 .maxlen = sizeof (int),
465 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800466 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 },
468 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 .procname = "scons-poweroff",
470 .data = &scons_pwroff,
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#endif
David S. Miller08714202008-11-16 23:49:24 -0800476#ifdef CONFIG_SPARC64
477 {
David S. Miller08714202008-11-16 23:49:24 -0800478 .procname = "tsb-ratio",
479 .data = &sysctl_tsb_ratio,
480 .maxlen = sizeof (int),
481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800482 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800483 },
484#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#ifdef __hppa__
486 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .procname = "soft-power",
488 .data = &pwrsw_enabled,
489 .maxlen = sizeof (int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 },
493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .procname = "unaligned-trap",
495 .data = &unaligned_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#endif
501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .procname = "ctrl-alt-del",
503 .data = &C_A_D,
504 .maxlen = sizeof(int),
505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800506 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400508#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200509 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200510 .procname = "ftrace_enabled",
511 .data = &ftrace_enabled,
512 .maxlen = sizeof(int),
513 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800514 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200515 },
516#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500517#ifdef CONFIG_STACK_TRACER
518 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500519 .procname = "stack_tracer_enabled",
520 .data = &stack_tracer_enabled,
521 .maxlen = sizeof(int),
522 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800523 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500524 },
525#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400526#ifdef CONFIG_TRACING
527 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100528 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400529 .data = &ftrace_dump_on_oops,
530 .maxlen = sizeof(int),
531 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800532 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400533 },
534#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200535#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 .procname = "modprobe",
538 .data = &modprobe_path,
539 .maxlen = KMOD_PATH_LEN,
540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800541 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 },
Kees Cook3d433212009-04-02 15:49:29 -0700543 {
Kees Cook3d433212009-04-02 15:49:29 -0700544 .procname = "modules_disabled",
545 .data = &modules_disabled,
546 .maxlen = sizeof(int),
547 .mode = 0644,
548 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800549 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700550 .extra1 = &one,
551 .extra2 = &one,
552 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100554#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100557 .data = &uevent_helper,
558 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800560 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 },
562#endif
563#ifdef CONFIG_CHR_DEV_SG
564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .procname = "sg-big-buff",
566 .data = &sg_big_buff,
567 .maxlen = sizeof (int),
568 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800569 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 },
571#endif
572#ifdef CONFIG_BSD_PROCESS_ACCT
573 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .procname = "acct",
575 .data = &acct_parm,
576 .maxlen = 3*sizeof(int),
577 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800578 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 },
580#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#ifdef CONFIG_MAGIC_SYSRQ
582 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800584 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 .maxlen = sizeof (int),
586 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700587 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 },
589#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700590#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700593 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .maxlen = sizeof (int),
595 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800596 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700598#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .procname = "threads-max",
601 .data = &max_threads,
602 .maxlen = sizeof(int),
603 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800604 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 },
606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 .procname = "random",
608 .mode = 0555,
609 .child = random_table,
610 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 .procname = "overflowuid",
613 .data = &overflowuid,
614 .maxlen = sizeof(int),
615 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800616 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 .extra1 = &minolduid,
618 .extra2 = &maxolduid,
619 },
620 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 .procname = "overflowgid",
622 .data = &overflowgid,
623 .maxlen = sizeof(int),
624 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800625 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 .extra1 = &minolduid,
627 .extra2 = &maxolduid,
628 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800629#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630#ifdef CONFIG_MATHEMU
631 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .procname = "ieee_emulation_warnings",
633 .data = &sysctl_ieee_emulation_warnings,
634 .maxlen = sizeof(int),
635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800636 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 },
638#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200641 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 .maxlen = sizeof(int),
643 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800644 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 },
646#endif
647 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 .procname = "pid_max",
649 .data = &pid_max,
650 .maxlen = sizeof (int),
651 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800652 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 .extra1 = &pid_max_min,
654 .extra2 = &pid_max_max,
655 },
656 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 .procname = "panic_on_oops",
658 .data = &panic_on_oops,
659 .maxlen = sizeof(int),
660 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800661 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800663#if defined CONFIG_PRINTK
664 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800665 .procname = "printk",
666 .data = &console_loglevel,
667 .maxlen = 4*sizeof(int),
668 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800669 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800670 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700673 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 .maxlen = sizeof(int),
675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800676 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 },
678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700680 .data = &printk_ratelimit_state.burst,
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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 },
Dave Youngaf913222009-09-22 16:43:33 -0700685 {
Dave Youngaf913222009-09-22 16:43:33 -0700686 .procname = "printk_delay",
687 .data = &printk_delay_msec,
688 .maxlen = sizeof(int),
689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800690 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700691 .extra1 = &zero,
692 .extra2 = &ten_thousand,
693 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800695 .procname = "dmesg_restrict",
696 .data = &dmesg_restrict,
697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = proc_dointvec_minmax,
700 .extra1 = &zero,
701 .extra2 = &one,
702 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800703 {
704 .procname = "kptr_restrict",
705 .data = &kptr_restrict,
706 .maxlen = sizeof(int),
707 .mode = 0644,
708 .proc_handler = proc_dointvec_minmax,
709 .extra1 = &zero,
710 .extra2 = &two,
711 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800712#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800713 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 .procname = "ngroups_max",
715 .data = &ngroups_max,
716 .maxlen = sizeof (int),
717 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800718 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 },
Don Zickus58687ac2010-05-07 17:11:44 -0400720#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500721 {
Don Zickus58687ac2010-05-07 17:11:44 -0400722 .procname = "watchdog",
723 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500724 .maxlen = sizeof (int),
725 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400726 .proc_handler = proc_dowatchdog_enabled,
727 },
728 {
729 .procname = "watchdog_thresh",
730 .data = &softlockup_thresh,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = proc_dowatchdog_thresh,
734 .extra1 = &neg_one,
735 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500736 },
Don Zickus2508ce12010-05-07 17:11:46 -0400737 {
738 .procname = "softlockup_panic",
739 .data = &softlockup_panic,
740 .maxlen = sizeof(int),
741 .mode = 0644,
742 .proc_handler = proc_dointvec_minmax,
743 .extra1 = &zero,
744 .extra2 = &one,
745 },
Don Zickus5dc30552010-11-29 17:07:17 -0500746 {
747 .procname = "nmi_watchdog",
748 .data = &watchdog_enabled,
749 .maxlen = sizeof (int),
750 .mode = 0644,
751 .proc_handler = proc_dowatchdog_enabled,
752 },
753#endif
754#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
755 {
756 .procname = "unknown_nmi_panic",
757 .data = &unknown_nmi_panic,
758 .maxlen = sizeof (int),
759 .mode = 0644,
760 .proc_handler = proc_dointvec,
761 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500762#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763#if defined(CONFIG_X86)
764 {
Don Zickus8da5add2006-09-26 10:52:27 +0200765 .procname = "panic_on_unrecovered_nmi",
766 .data = &panic_on_unrecovered_nmi,
767 .maxlen = sizeof(int),
768 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800769 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200770 },
771 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700772 .procname = "panic_on_io_nmi",
773 .data = &panic_on_io_nmi,
774 .maxlen = sizeof(int),
775 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800776 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700777 },
778 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 .procname = "bootloader_type",
780 .data = &bootloader_type,
781 .maxlen = sizeof (int),
782 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800783 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100785 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700786 .procname = "bootloader_version",
787 .data = &bootloader_version,
788 .maxlen = sizeof (int),
789 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800790 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700791 },
792 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100793 .procname = "kstack_depth_to_print",
794 .data = &kstack_depth_to_print,
795 .maxlen = sizeof(int),
796 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800797 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100798 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100799 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100800 .procname = "io_delay_type",
801 .data = &io_delay_type,
802 .maxlen = sizeof(int),
803 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800804 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100805 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800807#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 .procname = "randomize_va_space",
810 .data = &randomize_va_space,
811 .maxlen = sizeof(int),
812 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800813 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800815#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800816#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700817 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700818 .procname = "spin_retry",
819 .data = &spin_retry,
820 .maxlen = sizeof (int),
821 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800822 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700823 },
824#endif
Len Brown673d5b42007-07-28 03:33:16 -0400825#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800826 {
Pavel Machekc255d842006-02-20 18:27:58 -0800827 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700828 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800829 .maxlen = sizeof (unsigned long),
830 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800831 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800832 },
833#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800834#ifdef CONFIG_IA64
835 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800836 .procname = "ignore-unaligned-usertrap",
837 .data = &no_unaligned_warning,
838 .maxlen = sizeof (int),
839 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800840 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800841 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800842 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800843 .procname = "unaligned-dump-stack",
844 .data = &unaligned_dump_stack,
845 .maxlen = sizeof (int),
846 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800847 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800848 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800849#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800850#ifdef CONFIG_DETECT_HUNG_TASK
851 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800852 .procname = "hung_task_panic",
853 .data = &sysctl_hung_task_panic,
854 .maxlen = sizeof(int),
855 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800856 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800857 .extra1 = &zero,
858 .extra2 = &one,
859 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100860 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 .procname = "hung_task_check_count",
862 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100863 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100864 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800865 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100866 },
867 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 .procname = "hung_task_timeout_secs",
869 .data = &sysctl_hung_task_timeout_secs,
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_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100873 },
874 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100875 .procname = "hung_task_warnings",
876 .data = &sysctl_hung_task_warnings,
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_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100880 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700881#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200882#ifdef CONFIG_COMPAT
883 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200884 .procname = "compat-log",
885 .data = &compat_log,
886 .maxlen = sizeof (int),
887 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800888 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200889 },
890#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700891#ifdef CONFIG_RT_MUTEXES
892 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700893 .procname = "max_lock_depth",
894 .data = &max_lock_depth,
895 .maxlen = sizeof(int),
896 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800897 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700898 },
899#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700900 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700901 .procname = "poweroff_cmd",
902 .data = &poweroff_cmd,
903 .maxlen = POWEROFF_CMD_PATH_LEN,
904 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800905 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700906 },
David Howells0b77f5b2008-04-29 01:01:32 -0700907#ifdef CONFIG_KEYS
908 {
David Howells0b77f5b2008-04-29 01:01:32 -0700909 .procname = "keys",
910 .mode = 0555,
911 .child = key_sysctls,
912 },
913#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700914#ifdef CONFIG_RCU_TORTURE_TEST
915 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700916 .procname = "rcutorture_runnable",
917 .data = &rcutorture_runnable,
918 .maxlen = sizeof(int),
919 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800920 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700921 },
922#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200923#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200924 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200925 .procname = "perf_event_paranoid",
926 .data = &sysctl_perf_event_paranoid,
927 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200928 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800929 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200930 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200931 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200932 .procname = "perf_event_mlock_kb",
933 .data = &sysctl_perf_event_mlock,
934 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200935 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800936 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200937 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200938 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200939 .procname = "perf_event_max_sample_rate",
940 .data = &sysctl_perf_event_sample_rate,
941 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200942 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800943 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200944 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200945#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200946#ifdef CONFIG_KMEMCHECK
947 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200948 .procname = "kmemcheck",
949 .data = &kmemcheck_enabled,
950 .maxlen = sizeof(int),
951 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800952 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200953 },
954#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200955#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200956 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200957 .procname = "blk_iopoll",
958 .data = &blk_iopoll_enabled,
959 .maxlen = sizeof(int),
960 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800961 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200962 },
Jens Axboecb684b52009-09-15 21:53:11 +0200963#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700964 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965};
966
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700967static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 .procname = "overcommit_memory",
970 .data = &sysctl_overcommit_memory,
971 .maxlen = sizeof(sysctl_overcommit_memory),
972 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800973 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 },
975 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700976 .procname = "panic_on_oom",
977 .data = &sysctl_panic_on_oom,
978 .maxlen = sizeof(sysctl_panic_on_oom),
979 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800980 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700981 },
982 {
David Rientjesfe071d72007-10-16 23:25:56 -0700983 .procname = "oom_kill_allocating_task",
984 .data = &sysctl_oom_kill_allocating_task,
985 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
986 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800987 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700988 },
989 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800990 .procname = "oom_dump_tasks",
991 .data = &sysctl_oom_dump_tasks,
992 .maxlen = sizeof(sysctl_oom_dump_tasks),
993 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800994 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -0800995 },
996 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 .procname = "overcommit_ratio",
998 .data = &sysctl_overcommit_ratio,
999 .maxlen = sizeof(sysctl_overcommit_ratio),
1000 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001001 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 },
1003 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 .procname = "page-cluster",
1005 .data = &page_cluster,
1006 .maxlen = sizeof(int),
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 = "dirty_background_ratio",
1012 .data = &dirty_background_ratio,
1013 .maxlen = sizeof(dirty_background_ratio),
1014 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001015 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 .extra1 = &zero,
1017 .extra2 = &one_hundred,
1018 },
1019 {
David Rientjes2da02992009-01-06 14:39:31 -08001020 .procname = "dirty_background_bytes",
1021 .data = &dirty_background_bytes,
1022 .maxlen = sizeof(dirty_background_bytes),
1023 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001024 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001025 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001026 },
1027 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 .procname = "dirty_ratio",
1029 .data = &vm_dirty_ratio,
1030 .maxlen = sizeof(vm_dirty_ratio),
1031 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 .extra1 = &zero,
1034 .extra2 = &one_hundred,
1035 },
1036 {
David Rientjes2da02992009-01-06 14:39:31 -08001037 .procname = "dirty_bytes",
1038 .data = &vm_dirty_bytes,
1039 .maxlen = sizeof(vm_dirty_bytes),
1040 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001042 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001043 },
1044 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001046 .data = &dirty_writeback_interval,
1047 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001049 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 },
1051 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001053 .data = &dirty_expire_interval,
1054 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001056 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 },
1058 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 .procname = "nr_pdflush_threads",
1060 .data = &nr_pdflush_threads,
1061 .maxlen = sizeof nr_pdflush_threads,
1062 .mode = 0444 /* read-only*/,
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 = "swappiness",
1067 .data = &vm_swappiness,
1068 .maxlen = sizeof(vm_swappiness),
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .extra1 = &zero,
1072 .extra2 = &one_hundred,
1073 },
1074#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001075 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001077 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 .maxlen = sizeof(unsigned long),
1079 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001080 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 .extra1 = (void *)&hugetlb_zero,
1082 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001083 },
1084#ifdef CONFIG_NUMA
1085 {
1086 .procname = "nr_hugepages_mempolicy",
1087 .data = NULL,
1088 .maxlen = sizeof(unsigned long),
1089 .mode = 0644,
1090 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1091 .extra1 = (void *)&hugetlb_zero,
1092 .extra2 = (void *)&hugetlb_infinity,
1093 },
1094#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 .procname = "hugetlb_shm_group",
1097 .data = &sysctl_hugetlb_shm_group,
1098 .maxlen = sizeof(gid_t),
1099 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001100 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 },
Mel Gorman396faf02007-07-17 04:03:13 -07001102 {
Mel Gorman396faf02007-07-17 04:03:13 -07001103 .procname = "hugepages_treat_as_movable",
1104 .data = &hugepages_treat_as_movable,
1105 .maxlen = sizeof(int),
1106 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001107 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001108 },
Adam Litke54f9f802007-10-16 01:26:20 -07001109 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001110 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001111 .data = NULL,
1112 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001113 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001114 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001115 .extra1 = (void *)&hugetlb_zero,
1116 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001117 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118#endif
1119 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 .procname = "lowmem_reserve_ratio",
1121 .data = &sysctl_lowmem_reserve_ratio,
1122 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1123 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001124 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 },
1126 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001127 .procname = "drop_caches",
1128 .data = &sysctl_drop_caches,
1129 .maxlen = sizeof(int),
1130 .mode = 0644,
1131 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001132 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001133#ifdef CONFIG_COMPACTION
1134 {
1135 .procname = "compact_memory",
1136 .data = &sysctl_compact_memory,
1137 .maxlen = sizeof(int),
1138 .mode = 0200,
1139 .proc_handler = sysctl_compaction_handler,
1140 },
Mel Gorman5e771902010-05-24 14:32:31 -07001141 {
1142 .procname = "extfrag_threshold",
1143 .data = &sysctl_extfrag_threshold,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = sysctl_extfrag_handler,
1147 .extra1 = &min_extfrag_threshold,
1148 .extra2 = &max_extfrag_threshold,
1149 },
1150
Mel Gorman76ab0f52010-05-24 14:32:28 -07001151#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001152 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 .procname = "min_free_kbytes",
1154 .data = &min_free_kbytes,
1155 .maxlen = sizeof(min_free_kbytes),
1156 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001157 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 .extra1 = &zero,
1159 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001160 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001161 .procname = "percpu_pagelist_fraction",
1162 .data = &percpu_pagelist_fraction,
1163 .maxlen = sizeof(percpu_pagelist_fraction),
1164 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001165 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001166 .extra1 = &min_percpu_pagelist_fract,
1167 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168#ifdef CONFIG_MMU
1169 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 .procname = "max_map_count",
1171 .data = &sysctl_max_map_count,
1172 .maxlen = sizeof(sysctl_max_map_count),
1173 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001174 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001175 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001177#else
1178 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001179 .procname = "nr_trim_pages",
1180 .data = &sysctl_nr_trim_pages,
1181 .maxlen = sizeof(sysctl_nr_trim_pages),
1182 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001183 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001184 .extra1 = &zero,
1185 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186#endif
1187 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 .procname = "laptop_mode",
1189 .data = &laptop_mode,
1190 .maxlen = sizeof(laptop_mode),
1191 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001192 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 },
1194 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 .procname = "block_dump",
1196 .data = &block_dump,
1197 .maxlen = sizeof(block_dump),
1198 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001199 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 .extra1 = &zero,
1201 },
1202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 .procname = "vfs_cache_pressure",
1204 .data = &sysctl_vfs_cache_pressure,
1205 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1206 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001207 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 .extra1 = &zero,
1209 },
1210#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1211 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 .procname = "legacy_va_layout",
1213 .data = &sysctl_legacy_va_layout,
1214 .maxlen = sizeof(sysctl_legacy_va_layout),
1215 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001216 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 .extra1 = &zero,
1218 },
1219#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001220#ifdef CONFIG_NUMA
1221 {
Christoph Lameter17436602006-01-18 17:42:32 -08001222 .procname = "zone_reclaim_mode",
1223 .data = &zone_reclaim_mode,
1224 .maxlen = sizeof(zone_reclaim_mode),
1225 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001226 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001227 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001228 },
Christoph Lameter96146342006-07-03 00:24:13 -07001229 {
Christoph Lameter96146342006-07-03 00:24:13 -07001230 .procname = "min_unmapped_ratio",
1231 .data = &sysctl_min_unmapped_ratio,
1232 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1233 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001234 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001235 .extra1 = &zero,
1236 .extra2 = &one_hundred,
1237 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001238 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001239 .procname = "min_slab_ratio",
1240 .data = &sysctl_min_slab_ratio,
1241 .maxlen = sizeof(sysctl_min_slab_ratio),
1242 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001243 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001244 .extra1 = &zero,
1245 .extra2 = &one_hundred,
1246 },
Christoph Lameter17436602006-01-18 17:42:32 -08001247#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001248#ifdef CONFIG_SMP
1249 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001250 .procname = "stat_interval",
1251 .data = &sysctl_stat_interval,
1252 .maxlen = sizeof(sysctl_stat_interval),
1253 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001254 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001255 },
1256#endif
David Howells6e141542009-12-15 19:27:45 +00001257#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001258 {
Eric Parised032182007-06-28 15:55:21 -04001259 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001260 .data = &dac_mmap_min_addr,
1261 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001262 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001263 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001264 },
David Howells6e141542009-12-15 19:27:45 +00001265#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001266#ifdef CONFIG_NUMA
1267 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001268 .procname = "numa_zonelist_order",
1269 .data = &numa_zonelist_order,
1270 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001272 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001273 },
1274#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001275#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001276 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001277 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001278 .procname = "vdso_enabled",
1279 .data = &vdso_enabled,
1280 .maxlen = sizeof(vdso_enabled),
1281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001283 .extra1 = &zero,
1284 },
1285#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001286#ifdef CONFIG_HIGHMEM
1287 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001288 .procname = "highmem_is_dirtyable",
1289 .data = &vm_highmem_is_dirtyable,
1290 .maxlen = sizeof(vm_highmem_is_dirtyable),
1291 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001292 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001293 .extra1 = &zero,
1294 .extra2 = &one,
1295 },
1296#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001297 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001298 .procname = "scan_unevictable_pages",
1299 .data = &scan_unevictable_pages,
1300 .maxlen = sizeof(scan_unevictable_pages),
1301 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001302 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001303 },
Andi Kleen6a460792009-09-16 11:50:15 +02001304#ifdef CONFIG_MEMORY_FAILURE
1305 {
Andi Kleen6a460792009-09-16 11:50:15 +02001306 .procname = "memory_failure_early_kill",
1307 .data = &sysctl_memory_failure_early_kill,
1308 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1309 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001310 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001311 .extra1 = &zero,
1312 .extra2 = &one,
1313 },
1314 {
Andi Kleen6a460792009-09-16 11:50:15 +02001315 .procname = "memory_failure_recovery",
1316 .data = &sysctl_memory_failure_recovery,
1317 .maxlen = sizeof(sysctl_memory_failure_recovery),
1318 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001319 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001320 .extra1 = &zero,
1321 .extra2 = &one,
1322 },
1323#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001324 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325};
1326
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001327#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001328static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001329 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001330};
1331#endif
1332
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001333static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 .procname = "inode-nr",
1336 .data = &inodes_stat,
1337 .maxlen = 2*sizeof(int),
1338 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001339 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 },
1341 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 .procname = "inode-state",
1343 .data = &inodes_stat,
1344 .maxlen = 7*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 = "file-nr",
1350 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001351 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001353 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 },
1355 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 .procname = "file-max",
1357 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001358 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001360 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 },
1362 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001363 .procname = "nr_open",
1364 .data = &sysctl_nr_open,
1365 .maxlen = sizeof(int),
1366 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001367 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001368 .extra1 = &sysctl_nr_open_min,
1369 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001370 },
1371 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 .procname = "dentry-state",
1373 .data = &dentry_stat,
1374 .maxlen = 6*sizeof(int),
1375 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001376 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 },
1378 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 .procname = "overflowuid",
1380 .data = &fs_overflowuid,
1381 .maxlen = sizeof(int),
1382 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001383 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 .extra1 = &minolduid,
1385 .extra2 = &maxolduid,
1386 },
1387 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .procname = "overflowgid",
1389 .data = &fs_overflowgid,
1390 .maxlen = sizeof(int),
1391 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001392 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 .extra1 = &minolduid,
1394 .extra2 = &maxolduid,
1395 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001396#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .procname = "leases-enable",
1399 .data = &leases_enable,
1400 .maxlen = sizeof(int),
1401 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001402 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001404#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405#ifdef CONFIG_DNOTIFY
1406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 .procname = "dir-notify-enable",
1408 .data = &dir_notify_enable,
1409 .maxlen = sizeof(int),
1410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001411 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 },
1413#endif
1414#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001415#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 .procname = "lease-break-time",
1418 .data = &lease_break_time,
1419 .maxlen = sizeof(int),
1420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001423#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001424#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 .procname = "aio-nr",
1427 .data = &aio_nr,
1428 .maxlen = sizeof(aio_nr),
1429 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001430 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 },
1432 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 .procname = "aio-max-nr",
1434 .data = &aio_max_nr,
1435 .maxlen = sizeof(aio_max_nr),
1436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001437 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001439#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001440#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001441 {
Robert Love0399cb02005-07-13 12:38:18 -04001442 .procname = "inotify",
1443 .mode = 0555,
1444 .child = inotify_table,
1445 },
1446#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001447#ifdef CONFIG_EPOLL
1448 {
1449 .procname = "epoll",
1450 .mode = 0555,
1451 .child = epoll_table,
1452 },
1453#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001455 {
Alan Coxd6e71142005-06-23 00:09:43 -07001456 .procname = "suid_dumpable",
1457 .data = &suid_dumpable,
1458 .maxlen = sizeof(int),
1459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001460 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001461 .extra1 = &zero,
1462 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001463 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001464#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1465 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001466 .procname = "binfmt_misc",
1467 .mode = 0555,
1468 .child = binfmt_misc_table,
1469 },
1470#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001471 {
Jens Axboeff9da692010-06-03 14:54:39 +02001472 .procname = "pipe-max-size",
1473 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001474 .maxlen = sizeof(int),
1475 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001476 .proc_handler = &pipe_proc_fn,
1477 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001478 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001479 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480};
1481
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001482static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001483#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1484 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001485 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001486 .procname = "exception-trace",
1487 .data = &show_unhandled_signals,
1488 .maxlen = sizeof(int),
1489 .mode = 0644,
1490 .proc_handler = proc_dointvec
1491 },
1492#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001493#if defined(CONFIG_OPTPROBES)
1494 {
1495 .procname = "kprobes-optimization",
1496 .data = &sysctl_kprobes_optimization,
1497 .maxlen = sizeof(int),
1498 .mode = 0644,
1499 .proc_handler = proc_kprobes_optimization_handler,
1500 .extra1 = &zero,
1501 .extra2 = &one,
1502 },
1503#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001504 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505};
1506
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001507static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001508 { }
Robert Love0eeca282005-07-12 17:06:03 -04001509};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Al Viro330d57f2005-11-04 10:18:40 +00001511static DEFINE_SPINLOCK(sysctl_lock);
1512
1513/* called under sysctl_lock */
1514static int use_table(struct ctl_table_header *p)
1515{
1516 if (unlikely(p->unregistering))
1517 return 0;
1518 p->used++;
1519 return 1;
1520}
1521
1522/* called under sysctl_lock */
1523static void unuse_table(struct ctl_table_header *p)
1524{
1525 if (!--p->used)
1526 if (unlikely(p->unregistering))
1527 complete(p->unregistering);
1528}
1529
1530/* called under sysctl_lock, will reacquire if has to wait */
1531static void start_unregistering(struct ctl_table_header *p)
1532{
1533 /*
1534 * if p->used is 0, nobody will ever touch that entry again;
1535 * we'll eliminate all paths to it before dropping sysctl_lock
1536 */
1537 if (unlikely(p->used)) {
1538 struct completion wait;
1539 init_completion(&wait);
1540 p->unregistering = &wait;
1541 spin_unlock(&sysctl_lock);
1542 wait_for_completion(&wait);
1543 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001544 } else {
1545 /* anything non-NULL; we'll never dereference it */
1546 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001547 }
1548 /*
1549 * do not remove from the list until nobody holds it; walking the
1550 * list in do_sysctl() relies on that.
1551 */
1552 list_del_init(&p->ctl_entry);
1553}
1554
Al Virof7e6ced2008-07-15 01:44:23 -04001555void sysctl_head_get(struct ctl_table_header *head)
1556{
1557 spin_lock(&sysctl_lock);
1558 head->count++;
1559 spin_unlock(&sysctl_lock);
1560}
1561
1562void sysctl_head_put(struct ctl_table_header *head)
1563{
1564 spin_lock(&sysctl_lock);
1565 if (!--head->count)
1566 kfree(head);
1567 spin_unlock(&sysctl_lock);
1568}
1569
1570struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1571{
1572 if (!head)
1573 BUG();
1574 spin_lock(&sysctl_lock);
1575 if (!use_table(head))
1576 head = ERR_PTR(-ENOENT);
1577 spin_unlock(&sysctl_lock);
1578 return head;
1579}
1580
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001581void sysctl_head_finish(struct ctl_table_header *head)
1582{
1583 if (!head)
1584 return;
1585 spin_lock(&sysctl_lock);
1586 unuse_table(head);
1587 spin_unlock(&sysctl_lock);
1588}
1589
Al Viro73455092008-07-14 21:22:20 -04001590static struct ctl_table_set *
1591lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1592{
1593 struct ctl_table_set *set = &root->default_set;
1594 if (root->lookup)
1595 set = root->lookup(root, namespaces);
1596 return set;
1597}
1598
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001599static struct list_head *
1600lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001601{
Al Viro73455092008-07-14 21:22:20 -04001602 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1603 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001604}
1605
1606struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1607 struct ctl_table_header *prev)
1608{
1609 struct ctl_table_root *root;
1610 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001611 struct ctl_table_header *head;
1612 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001613
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001614 spin_lock(&sysctl_lock);
1615 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001616 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001617 tmp = &prev->ctl_entry;
1618 unuse_table(prev);
1619 goto next;
1620 }
1621 tmp = &root_table_header.ctl_entry;
1622 for (;;) {
1623 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1624
1625 if (!use_table(head))
1626 goto next;
1627 spin_unlock(&sysctl_lock);
1628 return head;
1629 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001630 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001631 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001632 header_list = lookup_header_list(root, namespaces);
1633 if (tmp != header_list)
1634 continue;
1635
1636 do {
1637 root = list_entry(root->root_list.next,
1638 struct ctl_table_root, root_list);
1639 if (root == &sysctl_table_root)
1640 goto out;
1641 header_list = lookup_header_list(root, namespaces);
1642 } while (list_empty(header_list));
1643 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001644 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001645out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001646 spin_unlock(&sysctl_lock);
1647 return NULL;
1648}
1649
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001650struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1651{
1652 return __sysctl_head_next(current->nsproxy, prev);
1653}
1654
1655void register_sysctl_root(struct ctl_table_root *root)
1656{
1657 spin_lock(&sysctl_lock);
1658 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1659 spin_unlock(&sysctl_lock);
1660}
1661
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001663 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 * some sysctl variables are readonly even to root.
1665 */
1666
1667static int test_perm(int mode, int op)
1668{
David Howells76aac0e2008-11-14 10:39:12 +11001669 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 mode >>= 6;
1671 else if (in_egroup_p(0))
1672 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001673 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 return 0;
1675 return -EACCES;
1676}
1677
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001678int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
1680 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001681 int mode;
1682
Al Viroe6305c42008-07-15 21:03:57 -04001683 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 if (error)
1685 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001686
1687 if (root->permissions)
1688 mode = root->permissions(root, current->nsproxy, table);
1689 else
1690 mode = table->mode;
1691
1692 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693}
1694
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001695static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1696{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001697 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001698 table->parent = parent;
1699 if (table->child)
1700 sysctl_set_parent(table, table->child);
1701 }
1702}
1703
1704static __init int sysctl_init(void)
1705{
1706 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001707#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001708 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001709#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001710 return 0;
1711}
1712
1713core_initcall(sysctl_init);
1714
Al Virobfbcf032008-07-27 06:31:22 +01001715static struct ctl_table *is_branch_in(struct ctl_table *branch,
1716 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001717{
1718 struct ctl_table *p;
1719 const char *s = branch->procname;
1720
1721 /* branch should have named subdirectory as its first element */
1722 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001723 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001724
1725 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001726 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001727 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001728
1729 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001730 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001731 if (!p->child)
1732 continue;
1733 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001734 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001735 }
Al Virobfbcf032008-07-27 06:31:22 +01001736 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001737}
1738
1739/* see if attaching q to p would be an improvement */
1740static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1741{
1742 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001743 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001744 int is_better = 0;
1745 int not_in_parent = !p->attached_by;
1746
Al Virobfbcf032008-07-27 06:31:22 +01001747 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001748 if (by == q->attached_by)
1749 is_better = 1;
1750 if (to == p->attached_by)
1751 not_in_parent = 1;
1752 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001753 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001754 }
1755
1756 if (is_better && not_in_parent) {
1757 q->attached_by = by;
1758 q->attached_to = to;
1759 q->parent = p;
1760 }
1761}
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001764 * __register_sysctl_paths - register a sysctl hierarchy
1765 * @root: List of sysctl headers to register on
1766 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001767 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 *
1770 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001771 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001773 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1776 * enter a sysctl file
1777 *
1778 * data - a pointer to data for use by proc_handler
1779 *
1780 * maxlen - the maximum size in bytes of the data
1781 *
1782 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1783 *
1784 * child - a pointer to the child sysctl table if this entry is a directory, or
1785 * %NULL.
1786 *
1787 * proc_handler - the text handler routine (described below)
1788 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 * de - for internal use by the sysctl routines
1790 *
1791 * extra1, extra2 - extra pointers usable by the proc handler routines
1792 *
1793 * Leaf nodes in the sysctl tree will be represented by a single file
1794 * under /proc; non-leaf nodes will be represented by directories.
1795 *
1796 * sysctl(2) can automatically manage read and write requests through
1797 * the sysctl table. The data and maxlen fields of the ctl_table
1798 * struct enable minimal validation of the values being written to be
1799 * performed, and the mode field allows minimal authentication.
1800 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 * There must be a proc_handler routine for any terminal nodes
1802 * mirrored under /proc/sys (non-terminals are handled by a built-in
1803 * directory handler). Several default handlers are available to
1804 * cover common cases -
1805 *
1806 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1807 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1808 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1809 *
1810 * It is the handler's job to read the input buffer from user memory
1811 * and process it. The handler should return 0 on success.
1812 *
1813 * This routine returns %NULL on a failure to register, and a pointer
1814 * to the table header on success.
1815 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001816struct ctl_table_header *__register_sysctl_paths(
1817 struct ctl_table_root *root,
1818 struct nsproxy *namespaces,
1819 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001821 struct ctl_table_header *header;
1822 struct ctl_table *new, **prevp;
1823 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001824 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001825
1826 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001827 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001828 ;
1829
1830 /*
1831 * For each path component, allocate a 2-element ctl_table array.
1832 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001833 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001834 *
1835 * We allocate everything in one go so that we don't have to
1836 * worry about freeing additional memory in unregister_sysctl_table.
1837 */
1838 header = kzalloc(sizeof(struct ctl_table_header) +
1839 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1840 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001842
1843 new = (struct ctl_table *) (header + 1);
1844
1845 /* Now connect the dots */
1846 prevp = &header->ctl_table;
1847 for (n = 0; n < npath; ++n, ++path) {
1848 /* Copy the procname */
1849 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001850 new->mode = 0555;
1851
1852 *prevp = new;
1853 prevp = &new->child;
1854
1855 new += 2;
1856 }
1857 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001858 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001859
1860 INIT_LIST_HEAD(&header->ctl_entry);
1861 header->used = 0;
1862 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001863 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001864 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001865 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001866#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001867 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001868 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001869 return NULL;
1870 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001871#endif
Al Viro330d57f2005-11-04 10:18:40 +00001872 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001873 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001874 header->attached_by = header->ctl_table;
1875 header->attached_to = root_table;
1876 header->parent = &root_table_header;
1877 for (set = header->set; set; set = set->parent) {
1878 struct ctl_table_header *p;
1879 list_for_each_entry(p, &set->list, ctl_entry) {
1880 if (p->unregistering)
1881 continue;
1882 try_attach(p, header);
1883 }
1884 }
1885 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001886 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001887 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001888
1889 return header;
1890}
1891
1892/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001893 * register_sysctl_table_path - register a sysctl table hierarchy
1894 * @path: The path to the directory the sysctl table is in.
1895 * @table: the top-level table structure
1896 *
1897 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1898 * array. A completely 0 filled entry terminates the table.
1899 *
1900 * See __register_sysctl_paths for more details.
1901 */
1902struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1903 struct ctl_table *table)
1904{
1905 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1906 path, table);
1907}
1908
1909/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001910 * register_sysctl_table - register a sysctl table hierarchy
1911 * @table: the top-level table structure
1912 *
1913 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1914 * array. A completely 0 filled entry terminates the table.
1915 *
1916 * See register_sysctl_paths for more details.
1917 */
1918struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1919{
1920 static const struct ctl_path null_path[] = { {} };
1921
1922 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923}
1924
1925/**
1926 * unregister_sysctl_table - unregister a sysctl table hierarchy
1927 * @header: the header returned from register_sysctl_table
1928 *
1929 * Unregisters the sysctl table and all children. proc entries may not
1930 * actually be removed until they are no longer used by anyone.
1931 */
1932void unregister_sysctl_table(struct ctl_table_header * header)
1933{
Al Viro330d57f2005-11-04 10:18:40 +00001934 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001935
1936 if (header == NULL)
1937 return;
1938
Al Viro330d57f2005-11-04 10:18:40 +00001939 spin_lock(&sysctl_lock);
1940 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001941 if (!--header->parent->count) {
1942 WARN_ON(1);
1943 kfree(header->parent);
1944 }
Al Virof7e6ced2008-07-15 01:44:23 -04001945 if (!--header->count)
1946 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001947 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948}
1949
Al Viro90434762008-07-15 08:54:06 -04001950int sysctl_is_seen(struct ctl_table_header *p)
1951{
1952 struct ctl_table_set *set = p->set;
1953 int res;
1954 spin_lock(&sysctl_lock);
1955 if (p->unregistering)
1956 res = 0;
1957 else if (!set->is_seen)
1958 res = 1;
1959 else
1960 res = set->is_seen(set);
1961 spin_unlock(&sysctl_lock);
1962 return res;
1963}
1964
Al Viro73455092008-07-14 21:22:20 -04001965void setup_sysctl_set(struct ctl_table_set *p,
1966 struct ctl_table_set *parent,
1967 int (*is_seen)(struct ctl_table_set *))
1968{
1969 INIT_LIST_HEAD(&p->list);
1970 p->parent = parent ? parent : &sysctl_table_root.default_set;
1971 p->is_seen = is_seen;
1972}
1973
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001974#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001975struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001976{
1977 return NULL;
1978}
1979
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001980struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1981 struct ctl_table *table)
1982{
1983 return NULL;
1984}
1985
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001986void unregister_sysctl_table(struct ctl_table_header * table)
1987{
1988}
1989
Al Viro73455092008-07-14 21:22:20 -04001990void setup_sysctl_set(struct ctl_table_set *p,
1991 struct ctl_table_set *parent,
1992 int (*is_seen)(struct ctl_table_set *))
1993{
1994}
1995
Al Virof7e6ced2008-07-15 01:44:23 -04001996void sysctl_head_put(struct ctl_table_header *head)
1997{
1998}
1999
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002000#endif /* CONFIG_SYSCTL */
2001
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002/*
2003 * /proc/sys support
2004 */
2005
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002006#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002008static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002009 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002010 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002011{
2012 size_t len;
2013 char __user *p;
2014 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002015
2016 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002017 *lenp = 0;
2018 return 0;
2019 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002020
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002021 if (write) {
2022 len = 0;
2023 p = buffer;
2024 while (len < *lenp) {
2025 if (get_user(c, p++))
2026 return -EFAULT;
2027 if (c == 0 || c == '\n')
2028 break;
2029 len++;
2030 }
2031 if (len >= maxlen)
2032 len = maxlen-1;
2033 if(copy_from_user(data, buffer, len))
2034 return -EFAULT;
2035 ((char *) data)[len] = 0;
2036 *ppos += *lenp;
2037 } else {
2038 len = strlen(data);
2039 if (len > maxlen)
2040 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002041
2042 if (*ppos > len) {
2043 *lenp = 0;
2044 return 0;
2045 }
2046
2047 data += *ppos;
2048 len -= *ppos;
2049
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002050 if (len > *lenp)
2051 len = *lenp;
2052 if (len)
2053 if(copy_to_user(buffer, data, len))
2054 return -EFAULT;
2055 if (len < *lenp) {
2056 if(put_user('\n', ((char __user *) buffer) + len))
2057 return -EFAULT;
2058 len++;
2059 }
2060 *lenp = len;
2061 *ppos += len;
2062 }
2063 return 0;
2064}
2065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066/**
2067 * proc_dostring - read a string sysctl
2068 * @table: the sysctl table
2069 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 * @buffer: the user buffer
2071 * @lenp: the size of the user buffer
2072 * @ppos: file position
2073 *
2074 * Reads/writes a string from/to the user buffer. If the kernel
2075 * buffer provided is not large enough to hold the string, the
2076 * string is truncated. The copied string is %NULL-terminated.
2077 * If the string is being read by the user process, it is copied
2078 * and a newline '\n' is added. It is truncated if the buffer is
2079 * not large enough.
2080 *
2081 * Returns 0 on success.
2082 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002083int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 void __user *buffer, size_t *lenp, loff_t *ppos)
2085{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002086 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002087 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088}
2089
Amerigo Wang00b7c332010-05-05 00:26:45 +00002090static size_t proc_skip_spaces(char **buf)
2091{
2092 size_t ret;
2093 char *tmp = skip_spaces(*buf);
2094 ret = tmp - *buf;
2095 *buf = tmp;
2096 return ret;
2097}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002099static void proc_skip_char(char **buf, size_t *size, const char v)
2100{
2101 while (*size) {
2102 if (**buf != v)
2103 break;
2104 (*size)--;
2105 (*buf)++;
2106 }
2107}
2108
Amerigo Wang00b7c332010-05-05 00:26:45 +00002109#define TMPBUFLEN 22
2110/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002111 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002112 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002113 * @buf: a kernel buffer
2114 * @size: size of the kernel buffer
2115 * @val: this is where the number will be stored
2116 * @neg: set to %TRUE if number is negative
2117 * @perm_tr: a vector which contains the allowed trailers
2118 * @perm_tr_len: size of the perm_tr vector
2119 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002120 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002121 * In case of success %0 is returned and @buf and @size are updated with
2122 * the amount of bytes read. If @tr is non-NULL and a trailing
2123 * character exists (size is non-zero after returning from this
2124 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002125 */
2126static int proc_get_long(char **buf, size_t *size,
2127 unsigned long *val, bool *neg,
2128 const char *perm_tr, unsigned perm_tr_len, char *tr)
2129{
2130 int len;
2131 char *p, tmp[TMPBUFLEN];
2132
2133 if (!*size)
2134 return -EINVAL;
2135
2136 len = *size;
2137 if (len > TMPBUFLEN - 1)
2138 len = TMPBUFLEN - 1;
2139
2140 memcpy(tmp, *buf, len);
2141
2142 tmp[len] = 0;
2143 p = tmp;
2144 if (*p == '-' && *size > 1) {
2145 *neg = true;
2146 p++;
2147 } else
2148 *neg = false;
2149 if (!isdigit(*p))
2150 return -EINVAL;
2151
2152 *val = simple_strtoul(p, &p, 0);
2153
2154 len = p - tmp;
2155
2156 /* We don't know if the next char is whitespace thus we may accept
2157 * invalid integers (e.g. 1234...a) or two integers instead of one
2158 * (e.g. 123...1). So lets not allow such large numbers. */
2159 if (len == TMPBUFLEN - 1)
2160 return -EINVAL;
2161
2162 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2163 return -EINVAL;
2164
2165 if (tr && (len < *size))
2166 *tr = *p;
2167
2168 *buf += len;
2169 *size -= len;
2170
2171 return 0;
2172}
2173
2174/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002175 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002176 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002177 * @buf: the user buffer
2178 * @size: the size of the user buffer
2179 * @val: the integer to be converted
2180 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002181 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002182 * In case of success %0 is returned and @buf and @size are updated with
2183 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002184 */
2185static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2186 bool neg)
2187{
2188 int len;
2189 char tmp[TMPBUFLEN], *p = tmp;
2190
2191 sprintf(p, "%s%lu", neg ? "-" : "", val);
2192 len = strlen(tmp);
2193 if (len > *size)
2194 len = *size;
2195 if (copy_to_user(*buf, tmp, len))
2196 return -EFAULT;
2197 *size -= len;
2198 *buf += len;
2199 return 0;
2200}
2201#undef TMPBUFLEN
2202
2203static int proc_put_char(void __user **buf, size_t *size, char c)
2204{
2205 if (*size) {
2206 char __user **buffer = (char __user **)buf;
2207 if (put_user(c, *buffer))
2208 return -EFAULT;
2209 (*size)--, (*buffer)++;
2210 *buf = *buffer;
2211 }
2212 return 0;
2213}
2214
2215static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 int *valp,
2217 int write, void *data)
2218{
2219 if (write) {
2220 *valp = *negp ? -*lvalp : *lvalp;
2221 } else {
2222 int val = *valp;
2223 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002224 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 *lvalp = (unsigned long)-val;
2226 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002227 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 *lvalp = (unsigned long)val;
2229 }
2230 }
2231 return 0;
2232}
2233
Amerigo Wang00b7c332010-05-05 00:26:45 +00002234static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2235
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002236static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002237 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002238 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 int write, void *data),
2241 void *data)
2242{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002243 int *i, vleft, first = 1, err = 0;
2244 unsigned long page = 0;
2245 size_t left;
2246 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Amerigo Wang00b7c332010-05-05 00:26:45 +00002248 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 *lenp = 0;
2250 return 0;
2251 }
2252
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002253 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 vleft = table->maxlen / sizeof(*i);
2255 left = *lenp;
2256
2257 if (!conv)
2258 conv = do_proc_dointvec_conv;
2259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002261 if (left > PAGE_SIZE - 1)
2262 left = PAGE_SIZE - 1;
2263 page = __get_free_page(GFP_TEMPORARY);
2264 kbuf = (char *) page;
2265 if (!kbuf)
2266 return -ENOMEM;
2267 if (copy_from_user(kbuf, buffer, left)) {
2268 err = -EFAULT;
2269 goto free;
2270 }
2271 kbuf[left] = 0;
2272 }
2273
2274 for (; left && vleft--; i++, first=0) {
2275 unsigned long lval;
2276 bool neg;
2277
2278 if (write) {
2279 left -= proc_skip_spaces(&kbuf);
2280
J. R. Okajima563b0462010-05-25 16:10:14 -07002281 if (!left)
2282 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002283 err = proc_get_long(&kbuf, &left, &lval, &neg,
2284 proc_wspace_sep,
2285 sizeof(proc_wspace_sep), NULL);
2286 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002288 if (conv(&neg, &lval, i, 1, data)) {
2289 err = -EINVAL;
2290 break;
2291 }
2292 } else {
2293 if (conv(&neg, &lval, i, 0, data)) {
2294 err = -EINVAL;
2295 break;
2296 }
2297 if (!first)
2298 err = proc_put_char(&buffer, &left, '\t');
2299 if (err)
2300 break;
2301 err = proc_put_long(&buffer, &left, lval, neg);
2302 if (err)
2303 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 }
2305 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002306
2307 if (!write && !first && left && !err)
2308 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002309 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002310 left -= proc_skip_spaces(&kbuf);
2311free:
2312 if (write) {
2313 free_page(page);
2314 if (first)
2315 return err ? : -EINVAL;
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 *lenp -= left;
2318 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002319 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320}
2321
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002322static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002323 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002324 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002325 int write, void *data),
2326 void *data)
2327{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002328 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002329 buffer, lenp, ppos, conv, data);
2330}
2331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332/**
2333 * proc_dointvec - read a vector of integers
2334 * @table: the sysctl table
2335 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 * @buffer: the user buffer
2337 * @lenp: the size of the user buffer
2338 * @ppos: file position
2339 *
2340 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2341 * values from/to the user buffer, treated as an ASCII string.
2342 *
2343 * Returns 0 on success.
2344 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002345int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 void __user *buffer, size_t *lenp, loff_t *ppos)
2347{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002348 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 NULL,NULL);
2350}
2351
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002352/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002353 * Taint values can only be increased
2354 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002355 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002356static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002357 void __user *buffer, size_t *lenp, loff_t *ppos)
2358{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002359 struct ctl_table t;
2360 unsigned long tmptaint = get_taint();
2361 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002362
Bastian Blank91fcd412007-04-23 14:41:14 -07002363 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002364 return -EPERM;
2365
Andi Kleen25ddbb12008-10-15 22:01:41 -07002366 t = *table;
2367 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002368 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002369 if (err < 0)
2370 return err;
2371
2372 if (write) {
2373 /*
2374 * Poor man's atomic or. Not worth adding a primitive
2375 * to everyone's atomic.h for this
2376 */
2377 int i;
2378 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2379 if ((tmptaint >> i) & 1)
2380 add_taint(i);
2381 }
2382 }
2383
2384 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002385}
2386
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387struct do_proc_dointvec_minmax_conv_param {
2388 int *min;
2389 int *max;
2390};
2391
Amerigo Wang00b7c332010-05-05 00:26:45 +00002392static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2393 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 int write, void *data)
2395{
2396 struct do_proc_dointvec_minmax_conv_param *param = data;
2397 if (write) {
2398 int val = *negp ? -*lvalp : *lvalp;
2399 if ((param->min && *param->min > val) ||
2400 (param->max && *param->max < val))
2401 return -EINVAL;
2402 *valp = val;
2403 } else {
2404 int val = *valp;
2405 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002406 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 *lvalp = (unsigned long)-val;
2408 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002409 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 *lvalp = (unsigned long)val;
2411 }
2412 }
2413 return 0;
2414}
2415
2416/**
2417 * proc_dointvec_minmax - read a vector of integers with min/max values
2418 * @table: the sysctl table
2419 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 * @buffer: the user buffer
2421 * @lenp: the size of the user buffer
2422 * @ppos: file position
2423 *
2424 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2425 * values from/to the user buffer, treated as an ASCII string.
2426 *
2427 * This routine will ensure the values are within the range specified by
2428 * table->extra1 (min) and table->extra2 (max).
2429 *
2430 * Returns 0 on success.
2431 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002432int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 void __user *buffer, size_t *lenp, loff_t *ppos)
2434{
2435 struct do_proc_dointvec_minmax_conv_param param = {
2436 .min = (int *) table->extra1,
2437 .max = (int *) table->extra2,
2438 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002439 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 do_proc_dointvec_minmax_conv, &param);
2441}
2442
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002443static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 void __user *buffer,
2445 size_t *lenp, loff_t *ppos,
2446 unsigned long convmul,
2447 unsigned long convdiv)
2448{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002449 unsigned long *i, *min, *max;
2450 int vleft, first = 1, err = 0;
2451 unsigned long page = 0;
2452 size_t left;
2453 char *kbuf;
2454
2455 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 *lenp = 0;
2457 return 0;
2458 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002459
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002460 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 min = (unsigned long *) table->extra1;
2462 max = (unsigned long *) table->extra2;
2463 vleft = table->maxlen / sizeof(unsigned long);
2464 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002465
2466 if (write) {
2467 if (left > PAGE_SIZE - 1)
2468 left = PAGE_SIZE - 1;
2469 page = __get_free_page(GFP_TEMPORARY);
2470 kbuf = (char *) page;
2471 if (!kbuf)
2472 return -ENOMEM;
2473 if (copy_from_user(kbuf, buffer, left)) {
2474 err = -EFAULT;
2475 goto free;
2476 }
2477 kbuf[left] = 0;
2478 }
2479
Eric Dumazet27b3d802010-10-07 12:59:29 -07002480 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002481 unsigned long val;
2482
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002484 bool neg;
2485
2486 left -= proc_skip_spaces(&kbuf);
2487
2488 err = proc_get_long(&kbuf, &left, &val, &neg,
2489 proc_wspace_sep,
2490 sizeof(proc_wspace_sep), NULL);
2491 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 break;
2493 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 continue;
2495 if ((min && val < *min) || (max && val > *max))
2496 continue;
2497 *i = val;
2498 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002499 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002501 err = proc_put_char(&buffer, &left, '\t');
2502 err = proc_put_long(&buffer, &left, val, false);
2503 if (err)
2504 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 }
2506 }
2507
Amerigo Wang00b7c332010-05-05 00:26:45 +00002508 if (!write && !first && left && !err)
2509 err = proc_put_char(&buffer, &left, '\n');
2510 if (write && !err)
2511 left -= proc_skip_spaces(&kbuf);
2512free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002514 free_page(page);
2515 if (first)
2516 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 *lenp -= left;
2519 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002520 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521}
2522
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002523static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002524 void __user *buffer,
2525 size_t *lenp, loff_t *ppos,
2526 unsigned long convmul,
2527 unsigned long convdiv)
2528{
2529 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002530 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002531}
2532
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533/**
2534 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2535 * @table: the sysctl table
2536 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 * @buffer: the user buffer
2538 * @lenp: the size of the user buffer
2539 * @ppos: file position
2540 *
2541 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2542 * values from/to the user buffer, treated as an ASCII string.
2543 *
2544 * This routine will ensure the values are within the range specified by
2545 * table->extra1 (min) and table->extra2 (max).
2546 *
2547 * Returns 0 on success.
2548 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002549int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 void __user *buffer, size_t *lenp, loff_t *ppos)
2551{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002552 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553}
2554
2555/**
2556 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2557 * @table: the sysctl table
2558 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 * @buffer: the user buffer
2560 * @lenp: the size of the user buffer
2561 * @ppos: file position
2562 *
2563 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2564 * values from/to the user buffer, treated as an ASCII string. The values
2565 * are treated as milliseconds, and converted to jiffies when they are stored.
2566 *
2567 * This routine will ensure the values are within the range specified by
2568 * table->extra1 (min) and table->extra2 (max).
2569 *
2570 * Returns 0 on success.
2571 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002572int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 void __user *buffer,
2574 size_t *lenp, loff_t *ppos)
2575{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002576 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 lenp, ppos, HZ, 1000l);
2578}
2579
2580
Amerigo Wang00b7c332010-05-05 00:26:45 +00002581static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 int *valp,
2583 int write, void *data)
2584{
2585 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002586 if (*lvalp > LONG_MAX / HZ)
2587 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2589 } else {
2590 int val = *valp;
2591 unsigned long lval;
2592 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002593 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 lval = (unsigned long)-val;
2595 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002596 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 lval = (unsigned long)val;
2598 }
2599 *lvalp = lval / HZ;
2600 }
2601 return 0;
2602}
2603
Amerigo Wang00b7c332010-05-05 00:26:45 +00002604static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 int *valp,
2606 int write, void *data)
2607{
2608 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002609 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2610 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2612 } else {
2613 int val = *valp;
2614 unsigned long lval;
2615 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002616 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 lval = (unsigned long)-val;
2618 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002619 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 lval = (unsigned long)val;
2621 }
2622 *lvalp = jiffies_to_clock_t(lval);
2623 }
2624 return 0;
2625}
2626
Amerigo Wang00b7c332010-05-05 00:26:45 +00002627static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 int *valp,
2629 int write, void *data)
2630{
2631 if (write) {
2632 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2633 } else {
2634 int val = *valp;
2635 unsigned long lval;
2636 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002637 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 lval = (unsigned long)-val;
2639 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002640 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 lval = (unsigned long)val;
2642 }
2643 *lvalp = jiffies_to_msecs(lval);
2644 }
2645 return 0;
2646}
2647
2648/**
2649 * proc_dointvec_jiffies - read a vector of integers as seconds
2650 * @table: the sysctl table
2651 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 * @buffer: the user buffer
2653 * @lenp: the size of the user buffer
2654 * @ppos: file position
2655 *
2656 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2657 * values from/to the user buffer, treated as an ASCII string.
2658 * The values read are assumed to be in seconds, and are converted into
2659 * jiffies.
2660 *
2661 * Returns 0 on success.
2662 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002663int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 void __user *buffer, size_t *lenp, loff_t *ppos)
2665{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002666 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 do_proc_dointvec_jiffies_conv,NULL);
2668}
2669
2670/**
2671 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2672 * @table: the sysctl table
2673 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 * @buffer: the user buffer
2675 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002676 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 *
2678 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2679 * values from/to the user buffer, treated as an ASCII string.
2680 * The values read are assumed to be in 1/USER_HZ seconds, and
2681 * are converted into jiffies.
2682 *
2683 * Returns 0 on success.
2684 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002685int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 void __user *buffer, size_t *lenp, loff_t *ppos)
2687{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002688 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 do_proc_dointvec_userhz_jiffies_conv,NULL);
2690}
2691
2692/**
2693 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2694 * @table: the sysctl table
2695 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 * @buffer: the user buffer
2697 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002698 * @ppos: file position
2699 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 *
2701 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2702 * values from/to the user buffer, treated as an ASCII string.
2703 * The values read are assumed to be in 1/1000 seconds, and
2704 * are converted into jiffies.
2705 *
2706 * Returns 0 on success.
2707 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002708int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 void __user *buffer, size_t *lenp, loff_t *ppos)
2710{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002711 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 do_proc_dointvec_ms_jiffies_conv, NULL);
2713}
2714
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002715static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002716 void __user *buffer, size_t *lenp, loff_t *ppos)
2717{
2718 struct pid *new_pid;
2719 pid_t tmp;
2720 int r;
2721
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002722 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002723
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002724 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002725 lenp, ppos, NULL, NULL);
2726 if (r || !write)
2727 return r;
2728
2729 new_pid = find_get_pid(tmp);
2730 if (!new_pid)
2731 return -ESRCH;
2732
2733 put_pid(xchg(&cad_pid, new_pid));
2734 return 0;
2735}
2736
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002737/**
2738 * proc_do_large_bitmap - read/write from/to a large bitmap
2739 * @table: the sysctl table
2740 * @write: %TRUE if this is a write to the sysctl file
2741 * @buffer: the user buffer
2742 * @lenp: the size of the user buffer
2743 * @ppos: file position
2744 *
2745 * The bitmap is stored at table->data and the bitmap length (in bits)
2746 * in table->maxlen.
2747 *
2748 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2749 * large bitmaps may be represented in a compact manner. Writing into
2750 * the file will clear the bitmap then update it with the given input.
2751 *
2752 * Returns 0 on success.
2753 */
2754int proc_do_large_bitmap(struct ctl_table *table, int write,
2755 void __user *buffer, size_t *lenp, loff_t *ppos)
2756{
2757 int err = 0;
2758 bool first = 1;
2759 size_t left = *lenp;
2760 unsigned long bitmap_len = table->maxlen;
2761 unsigned long *bitmap = (unsigned long *) table->data;
2762 unsigned long *tmp_bitmap = NULL;
2763 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2764
2765 if (!bitmap_len || !left || (*ppos && !write)) {
2766 *lenp = 0;
2767 return 0;
2768 }
2769
2770 if (write) {
2771 unsigned long page = 0;
2772 char *kbuf;
2773
2774 if (left > PAGE_SIZE - 1)
2775 left = PAGE_SIZE - 1;
2776
2777 page = __get_free_page(GFP_TEMPORARY);
2778 kbuf = (char *) page;
2779 if (!kbuf)
2780 return -ENOMEM;
2781 if (copy_from_user(kbuf, buffer, left)) {
2782 free_page(page);
2783 return -EFAULT;
2784 }
2785 kbuf[left] = 0;
2786
2787 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2788 GFP_KERNEL);
2789 if (!tmp_bitmap) {
2790 free_page(page);
2791 return -ENOMEM;
2792 }
2793 proc_skip_char(&kbuf, &left, '\n');
2794 while (!err && left) {
2795 unsigned long val_a, val_b;
2796 bool neg;
2797
2798 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2799 sizeof(tr_a), &c);
2800 if (err)
2801 break;
2802 if (val_a >= bitmap_len || neg) {
2803 err = -EINVAL;
2804 break;
2805 }
2806
2807 val_b = val_a;
2808 if (left) {
2809 kbuf++;
2810 left--;
2811 }
2812
2813 if (c == '-') {
2814 err = proc_get_long(&kbuf, &left, &val_b,
2815 &neg, tr_b, sizeof(tr_b),
2816 &c);
2817 if (err)
2818 break;
2819 if (val_b >= bitmap_len || neg ||
2820 val_a > val_b) {
2821 err = -EINVAL;
2822 break;
2823 }
2824 if (left) {
2825 kbuf++;
2826 left--;
2827 }
2828 }
2829
2830 while (val_a <= val_b)
2831 set_bit(val_a++, tmp_bitmap);
2832
2833 first = 0;
2834 proc_skip_char(&kbuf, &left, '\n');
2835 }
2836 free_page(page);
2837 } else {
2838 unsigned long bit_a, bit_b = 0;
2839
2840 while (left) {
2841 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2842 if (bit_a >= bitmap_len)
2843 break;
2844 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2845 bit_a + 1) - 1;
2846
2847 if (!first) {
2848 err = proc_put_char(&buffer, &left, ',');
2849 if (err)
2850 break;
2851 }
2852 err = proc_put_long(&buffer, &left, bit_a, false);
2853 if (err)
2854 break;
2855 if (bit_a != bit_b) {
2856 err = proc_put_char(&buffer, &left, '-');
2857 if (err)
2858 break;
2859 err = proc_put_long(&buffer, &left, bit_b, false);
2860 if (err)
2861 break;
2862 }
2863
2864 first = 0; bit_b++;
2865 }
2866 if (!err)
2867 err = proc_put_char(&buffer, &left, '\n');
2868 }
2869
2870 if (!err) {
2871 if (write) {
2872 if (*ppos)
2873 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2874 else
2875 memcpy(bitmap, tmp_bitmap,
2876 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2877 }
2878 kfree(tmp_bitmap);
2879 *lenp -= left;
2880 *ppos += *lenp;
2881 return 0;
2882 } else {
2883 kfree(tmp_bitmap);
2884 return err;
2885 }
2886}
2887
Jovi Zhang55610502011-01-12 17:00:45 -08002888#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002890int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 void __user *buffer, size_t *lenp, loff_t *ppos)
2892{
2893 return -ENOSYS;
2894}
2895
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002896int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 void __user *buffer, size_t *lenp, loff_t *ppos)
2898{
2899 return -ENOSYS;
2900}
2901
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002902int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 void __user *buffer, size_t *lenp, loff_t *ppos)
2904{
2905 return -ENOSYS;
2906}
2907
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002908int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 void __user *buffer, size_t *lenp, loff_t *ppos)
2910{
2911 return -ENOSYS;
2912}
2913
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002914int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 void __user *buffer, size_t *lenp, loff_t *ppos)
2916{
2917 return -ENOSYS;
2918}
2919
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002920int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 void __user *buffer, size_t *lenp, loff_t *ppos)
2922{
2923 return -ENOSYS;
2924}
2925
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002926int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 void __user *buffer, size_t *lenp, loff_t *ppos)
2928{
2929 return -ENOSYS;
2930}
2931
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002932int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 void __user *buffer,
2934 size_t *lenp, loff_t *ppos)
2935{
2936 return -ENOSYS;
2937}
2938
2939
Jovi Zhang55610502011-01-12 17:00:45 -08002940#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942/*
2943 * No sense putting this after each symbol definition, twice,
2944 * exception granted :-)
2945 */
2946EXPORT_SYMBOL(proc_dointvec);
2947EXPORT_SYMBOL(proc_dointvec_jiffies);
2948EXPORT_SYMBOL(proc_dointvec_minmax);
2949EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2950EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2951EXPORT_SYMBOL(proc_dostring);
2952EXPORT_SYMBOL(proc_doulongvec_minmax);
2953EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2954EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002955EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956EXPORT_SYMBOL(unregister_sysctl_table);