blob: 9b520d74f052ca10ac6b1645c0faeb121567cd72 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070028#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020030#include <linux/kmemcheck.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020039#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070040#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070043#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/times.h>
45#include <linux/limits.h>
46#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020047#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070049#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080050#include <linux/nfs_fs.h>
51#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070052#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020053#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020054#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050055#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020056#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070057#include <linux/oom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#include <asm/uaccess.h>
60#include <asm/processor.h>
61
Andi Kleen29cbc782006-09-30 01:47:55 +020062#ifdef CONFIG_X86
63#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010064#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010065#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020066#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080067#ifdef CONFIG_BSD_PROCESS_ACCT
68#include <linux/acct.h>
69#endif
Dave Young4f0e0562010-03-10 15:24:09 -080070#ifdef CONFIG_RT_MUTEXES
71#include <linux/rtmutex.h>
72#endif
Dave Young2edf5e42010-03-10 15:24:10 -080073#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74#include <linux/lockdep.h>
75#endif
Dave Young15485a42010-03-10 15:24:07 -080076#ifdef CONFIG_CHR_DEV_SG
77#include <scsi/sg.h>
78#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020079
Don Zickus58687ac2010-05-07 17:11:44 -040080#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050081#include <linux/nmi.h>
82#endif
83
Eric W. Biederman7058cb02007-10-18 03:05:58 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#if defined(CONFIG_SYSCTL)
86
87/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088extern int sysctl_overcommit_memory;
89extern int sysctl_overcommit_ratio;
90extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070092extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070094extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095extern int pid_max;
96extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080098extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080099extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200100extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100101extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400102extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000103#ifndef CONFIG_MMU
104extern int sysctl_nr_trim_pages;
105#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200106#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200107extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700110/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400111#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700112static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200113static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700114#endif
115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700117static int __maybe_unused one = 1;
118static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800119static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700121#ifdef CONFIG_PRINTK
122static int ten_thousand = 10000;
123#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700125/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129static int maxolduid = 65535;
130static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800131static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133static int ngroups_max = NGROUPS_MAX;
134
Dave Youngd14f1722010-02-25 20:28:57 -0500135#ifdef CONFIG_INOTIFY_USER
136#include <linux/inotify.h>
137#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700138#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700139#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#endif
141
David S. Miller08714202008-11-16 23:49:24 -0800142#ifdef CONFIG_SPARC64
143extern int sysctl_tsb_ratio;
144#endif
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef __hppa__
147extern int pwrsw_enabled;
148extern int unaligned_enabled;
149#endif
150
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800151#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#ifdef CONFIG_MATHEMU
153extern int sysctl_ieee_emulation_warnings;
154#endif
155extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700156extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif
158
Jes Sorensend2b176e2006-02-28 09:42:23 -0800159#ifdef CONFIG_IA64
160extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800161extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800162#endif
163
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700164#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700165static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700166 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700167static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800168 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700169#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700171#ifdef CONFIG_MAGIC_SYSRQ
172static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
173
174static int sysrq_sysctl_handler(ctl_table *table, int write,
175 void __user *buffer, size_t *lenp,
176 loff_t *ppos)
177{
178 int error;
179
180 error = proc_dointvec(table, write, buffer, lenp, ppos);
181 if (error)
182 return error;
183
184 if (write)
185 sysrq_toggle_support(__sysrq_enabled);
186
187 return 0;
188}
189
190#endif
191
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700192static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100193static struct ctl_table_root sysctl_table_root;
194static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100195 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100196 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400197 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100198 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400199 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100200};
201static struct ctl_table_root sysctl_table_root = {
202 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400203 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100204};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700206static struct ctl_table kern_table[];
207static struct ctl_table vm_table[];
208static struct ctl_table fs_table[];
209static struct ctl_table debug_table[];
210static struct ctl_table dev_table[];
211extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800212#ifdef CONFIG_EPOLL
213extern struct ctl_table epoll_table[];
214#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
217int sysctl_legacy_va_layout;
218#endif
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/* The default sysctl tables: */
221
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700222static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 .procname = "kernel",
225 .mode = 0555,
226 .child = kern_table,
227 },
228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 .procname = "vm",
230 .mode = 0555,
231 .child = vm_table,
232 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 .procname = "fs",
235 .mode = 0555,
236 .child = fs_table,
237 },
238 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 .procname = "debug",
240 .mode = 0555,
241 .child = debug_table,
242 },
243 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 .procname = "dev",
245 .mode = 0555,
246 .child = dev_table,
247 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700248/*
249 * NOTE: do not add new entries to this table unless you have read
250 * Documentation/sysctl/ctl_unnumbered.txt
251 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700252 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253};
254
Ingo Molnar77e54a12007-07-09 18:52:00 +0200255#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100256static int min_sched_granularity_ns = 100000; /* 100 usecs */
257static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
258static int min_wakeup_granularity_ns; /* 0 usecs */
259static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100260static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
261static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200262#endif
263
Mel Gorman5e771902010-05-24 14:32:31 -0700264#ifdef CONFIG_COMPACTION
265static int min_extfrag_threshold;
266static int max_extfrag_threshold = 1000;
267#endif
268
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700269static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200270 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200271 .procname = "sched_child_runs_first",
272 .data = &sysctl_sched_child_runs_first,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800275 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200276 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200277#ifdef CONFIG_SCHED_DEBUG
278 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100279 .procname = "sched_min_granularity_ns",
280 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800283 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100284 .extra1 = &min_sched_granularity_ns,
285 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200286 },
287 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200288 .procname = "sched_latency_ns",
289 .data = &sysctl_sched_latency,
290 .maxlen = sizeof(unsigned int),
291 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800292 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200293 .extra1 = &min_sched_granularity_ns,
294 .extra2 = &max_sched_granularity_ns,
295 },
296 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200297 .procname = "sched_wakeup_granularity_ns",
298 .data = &sysctl_sched_wakeup_granularity,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800301 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200302 .extra1 = &min_wakeup_granularity_ns,
303 .extra2 = &max_wakeup_granularity_ns,
304 },
305 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100306 .procname = "sched_tunable_scaling",
307 .data = &sysctl_sched_tunable_scaling,
308 .maxlen = sizeof(enum sched_tunable_scaling),
309 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800310 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100311 .extra1 = &min_sched_tunable_scaling,
312 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200313 },
314 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200315 .procname = "sched_migration_cost",
316 .data = &sysctl_sched_migration_cost,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800319 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200320 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100321 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100322 .procname = "sched_nr_migrate",
323 .data = &sysctl_sched_nr_migrate,
324 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100325 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800326 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100327 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530328 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200329 .procname = "sched_time_avg",
330 .data = &sysctl_sched_time_avg,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800333 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200334 },
335 {
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800336 .procname = "sched_shares_window",
337 .data = &sysctl_sched_shares_window,
338 .maxlen = sizeof(unsigned int),
339 .mode = 0644,
340 .proc_handler = proc_dointvec,
341 },
342 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530343 .procname = "timer_migration",
344 .data = &sysctl_timer_migration,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800347 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530348 .extra1 = &zero,
349 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530350 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200351#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200352 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100353 .procname = "sched_rt_period_us",
354 .data = &sysctl_sched_rt_period,
355 .maxlen = sizeof(unsigned int),
356 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800357 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100358 },
359 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100360 .procname = "sched_rt_runtime_us",
361 .data = &sysctl_sched_rt_runtime,
362 .maxlen = sizeof(int),
363 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800364 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100365 },
366 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200367 .procname = "sched_compat_yield",
368 .data = &sysctl_sched_compat_yield,
369 .maxlen = sizeof(unsigned int),
370 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800371 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200372 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700373#ifdef CONFIG_PROVE_LOCKING
374 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700375 .procname = "prove_locking",
376 .data = &prove_locking,
377 .maxlen = sizeof(int),
378 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800379 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700380 },
381#endif
382#ifdef CONFIG_LOCK_STAT
383 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700384 .procname = "lock_stat",
385 .data = &lock_stat,
386 .maxlen = sizeof(int),
387 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800388 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700389 },
390#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 .procname = "panic",
393 .data = &panic_timeout,
394 .maxlen = sizeof(int),
395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800396 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 },
398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .procname = "core_uses_pid",
400 .data = &core_uses_pid,
401 .maxlen = sizeof(int),
402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800403 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 },
405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .procname = "core_pattern",
407 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700408 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800410 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 },
Neil Hormana2939802009-09-23 15:56:56 -0700412 {
Neil Hormana2939802009-09-23 15:56:56 -0700413 .procname = "core_pipe_limit",
414 .data = &core_pipe_limit,
415 .maxlen = sizeof(unsigned int),
416 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800417 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700418 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800419#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700422 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800423 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800424 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800426#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100427#ifdef CONFIG_LATENCYTOP
428 {
429 .procname = "latencytop",
430 .data = &latencytop_enabled,
431 .maxlen = sizeof(int),
432 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800433 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100434 },
435#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#ifdef CONFIG_BLK_DEV_INITRD
437 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 .procname = "real-root-dev",
439 .data = &real_root_dev,
440 .maxlen = sizeof(int),
441 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800442 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 },
444#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700445 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700446 .procname = "print-fatal-signals",
447 .data = &print_fatal_signals,
448 .maxlen = sizeof(int),
449 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800450 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700451 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700452#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 .procname = "reboot-cmd",
455 .data = reboot_command,
456 .maxlen = 256,
457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800458 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 },
460 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 .procname = "stop-a",
462 .data = &stop_a_enabled,
463 .maxlen = sizeof (int),
464 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800465 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 },
467 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 .procname = "scons-poweroff",
469 .data = &scons_pwroff,
470 .maxlen = sizeof (int),
471 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800472 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 },
474#endif
David S. Miller08714202008-11-16 23:49:24 -0800475#ifdef CONFIG_SPARC64
476 {
David S. Miller08714202008-11-16 23:49:24 -0800477 .procname = "tsb-ratio",
478 .data = &sysctl_tsb_ratio,
479 .maxlen = sizeof (int),
480 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800481 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800482 },
483#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484#ifdef __hppa__
485 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 .procname = "soft-power",
487 .data = &pwrsw_enabled,
488 .maxlen = sizeof (int),
489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800490 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 },
492 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .procname = "unaligned-trap",
494 .data = &unaligned_enabled,
495 .maxlen = sizeof (int),
496 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800497 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 },
499#endif
500 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .procname = "ctrl-alt-del",
502 .data = &C_A_D,
503 .maxlen = sizeof(int),
504 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800505 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400507#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200508 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200509 .procname = "ftrace_enabled",
510 .data = &ftrace_enabled,
511 .maxlen = sizeof(int),
512 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800513 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200514 },
515#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500516#ifdef CONFIG_STACK_TRACER
517 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500518 .procname = "stack_tracer_enabled",
519 .data = &stack_tracer_enabled,
520 .maxlen = sizeof(int),
521 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800522 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500523 },
524#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400525#ifdef CONFIG_TRACING
526 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100527 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400528 .data = &ftrace_dump_on_oops,
529 .maxlen = sizeof(int),
530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800531 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400532 },
533#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200534#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 .procname = "modprobe",
537 .data = &modprobe_path,
538 .maxlen = KMOD_PATH_LEN,
539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800540 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 },
Kees Cook3d433212009-04-02 15:49:29 -0700542 {
Kees Cook3d433212009-04-02 15:49:29 -0700543 .procname = "modules_disabled",
544 .data = &modules_disabled,
545 .maxlen = sizeof(int),
546 .mode = 0644,
547 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800548 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700549 .extra1 = &one,
550 .extra2 = &one,
551 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100553#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100556 .data = &uevent_helper,
557 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800559 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 },
561#endif
562#ifdef CONFIG_CHR_DEV_SG
563 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .procname = "sg-big-buff",
565 .data = &sg_big_buff,
566 .maxlen = sizeof (int),
567 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800568 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 },
570#endif
571#ifdef CONFIG_BSD_PROCESS_ACCT
572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .procname = "acct",
574 .data = &acct_parm,
575 .maxlen = 3*sizeof(int),
576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 },
579#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580#ifdef CONFIG_MAGIC_SYSRQ
581 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800583 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 .maxlen = sizeof (int),
585 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700586 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 },
588#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700589#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700592 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 .maxlen = sizeof (int),
594 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800595 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700597#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .procname = "threads-max",
600 .data = &max_threads,
601 .maxlen = sizeof(int),
602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800603 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 },
605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .procname = "random",
607 .mode = 0555,
608 .child = random_table,
609 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 .procname = "overflowuid",
612 .data = &overflowuid,
613 .maxlen = sizeof(int),
614 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800615 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 .extra1 = &minolduid,
617 .extra2 = &maxolduid,
618 },
619 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 .procname = "overflowgid",
621 .data = &overflowgid,
622 .maxlen = sizeof(int),
623 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800624 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 .extra1 = &minolduid,
626 .extra2 = &maxolduid,
627 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800628#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#ifdef CONFIG_MATHEMU
630 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .procname = "ieee_emulation_warnings",
632 .data = &sysctl_ieee_emulation_warnings,
633 .maxlen = sizeof(int),
634 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800635 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 },
637#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200640 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .maxlen = sizeof(int),
642 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800643 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 },
645#endif
646 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 .procname = "pid_max",
648 .data = &pid_max,
649 .maxlen = sizeof (int),
650 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800651 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 .extra1 = &pid_max_min,
653 .extra2 = &pid_max_max,
654 },
655 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 .procname = "panic_on_oops",
657 .data = &panic_on_oops,
658 .maxlen = sizeof(int),
659 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800660 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800662#if defined CONFIG_PRINTK
663 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800664 .procname = "printk",
665 .data = &console_loglevel,
666 .maxlen = 4*sizeof(int),
667 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800668 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800669 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700672 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 .maxlen = sizeof(int),
674 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800675 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 },
677 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700679 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 .maxlen = sizeof(int),
681 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800682 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 },
Dave Youngaf913222009-09-22 16:43:33 -0700684 {
Dave Youngaf913222009-09-22 16:43:33 -0700685 .procname = "printk_delay",
686 .data = &printk_delay_msec,
687 .maxlen = sizeof(int),
688 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800689 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700690 .extra1 = &zero,
691 .extra2 = &ten_thousand,
692 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800693#endif
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 },
703 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .procname = "ngroups_max",
705 .data = &ngroups_max,
706 .maxlen = sizeof (int),
707 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800708 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 },
Don Zickus58687ac2010-05-07 17:11:44 -0400710#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500711 {
Don Zickus58687ac2010-05-07 17:11:44 -0400712 .procname = "watchdog",
713 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500714 .maxlen = sizeof (int),
715 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400716 .proc_handler = proc_dowatchdog_enabled,
717 },
718 {
719 .procname = "watchdog_thresh",
720 .data = &softlockup_thresh,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = proc_dowatchdog_thresh,
724 .extra1 = &neg_one,
725 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500726 },
Don Zickus2508ce12010-05-07 17:11:46 -0400727 {
728 .procname = "softlockup_panic",
729 .data = &softlockup_panic,
730 .maxlen = sizeof(int),
731 .mode = 0644,
732 .proc_handler = proc_dointvec_minmax,
733 .extra1 = &zero,
734 .extra2 = &one,
735 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500736#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400737#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .procname = "unknown_nmi_panic",
740 .data = &unknown_nmi_panic,
741 .maxlen = sizeof (int),
742 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800743 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 },
Don Zickus407984f2006-09-26 10:52:27 +0200745 {
Don Zickus407984f2006-09-26 10:52:27 +0200746 .procname = "nmi_watchdog",
747 .data = &nmi_watchdog_enabled,
748 .maxlen = sizeof (int),
749 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800750 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 },
752#endif
753#if defined(CONFIG_X86)
754 {
Don Zickus8da5add2006-09-26 10:52:27 +0200755 .procname = "panic_on_unrecovered_nmi",
756 .data = &panic_on_unrecovered_nmi,
757 .maxlen = sizeof(int),
758 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800759 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200760 },
761 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700762 .procname = "panic_on_io_nmi",
763 .data = &panic_on_io_nmi,
764 .maxlen = sizeof(int),
765 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800766 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700767 },
768 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .procname = "bootloader_type",
770 .data = &bootloader_type,
771 .maxlen = sizeof (int),
772 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800773 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100775 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700776 .procname = "bootloader_version",
777 .data = &bootloader_version,
778 .maxlen = sizeof (int),
779 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800780 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700781 },
782 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100783 .procname = "kstack_depth_to_print",
784 .data = &kstack_depth_to_print,
785 .maxlen = sizeof(int),
786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100788 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100789 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100790 .procname = "io_delay_type",
791 .data = &io_delay_type,
792 .maxlen = sizeof(int),
793 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800794 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100795 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800797#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .procname = "randomize_va_space",
800 .data = &randomize_va_space,
801 .maxlen = sizeof(int),
802 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800803 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800805#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800806#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700807 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700808 .procname = "spin_retry",
809 .data = &spin_retry,
810 .maxlen = sizeof (int),
811 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800812 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700813 },
814#endif
Len Brown673d5b42007-07-28 03:33:16 -0400815#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800816 {
Pavel Machekc255d842006-02-20 18:27:58 -0800817 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700818 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800819 .maxlen = sizeof (unsigned long),
820 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800821 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800822 },
823#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800824#ifdef CONFIG_IA64
825 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800826 .procname = "ignore-unaligned-usertrap",
827 .data = &no_unaligned_warning,
828 .maxlen = sizeof (int),
829 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800830 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800831 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800832 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800833 .procname = "unaligned-dump-stack",
834 .data = &unaligned_dump_stack,
835 .maxlen = sizeof (int),
836 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800837 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800838 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800839#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800840#ifdef CONFIG_DETECT_HUNG_TASK
841 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800842 .procname = "hung_task_panic",
843 .data = &sysctl_hung_task_panic,
844 .maxlen = sizeof(int),
845 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800846 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800847 .extra1 = &zero,
848 .extra2 = &one,
849 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100850 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100851 .procname = "hung_task_check_count",
852 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100853 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100854 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800855 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100856 },
857 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100858 .procname = "hung_task_timeout_secs",
859 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100860 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800862 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100863 },
864 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100865 .procname = "hung_task_warnings",
866 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100867 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800869 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100870 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700871#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200872#ifdef CONFIG_COMPAT
873 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200874 .procname = "compat-log",
875 .data = &compat_log,
876 .maxlen = sizeof (int),
877 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800878 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200879 },
880#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700881#ifdef CONFIG_RT_MUTEXES
882 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700883 .procname = "max_lock_depth",
884 .data = &max_lock_depth,
885 .maxlen = sizeof(int),
886 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800887 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700888 },
889#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700890 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700891 .procname = "poweroff_cmd",
892 .data = &poweroff_cmd,
893 .maxlen = POWEROFF_CMD_PATH_LEN,
894 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800895 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700896 },
David Howells0b77f5b2008-04-29 01:01:32 -0700897#ifdef CONFIG_KEYS
898 {
David Howells0b77f5b2008-04-29 01:01:32 -0700899 .procname = "keys",
900 .mode = 0555,
901 .child = key_sysctls,
902 },
903#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700904#ifdef CONFIG_RCU_TORTURE_TEST
905 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700906 .procname = "rcutorture_runnable",
907 .data = &rcutorture_runnable,
908 .maxlen = sizeof(int),
909 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800910 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700911 },
912#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200913#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200914 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200915 .procname = "perf_event_paranoid",
916 .data = &sysctl_perf_event_paranoid,
917 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200918 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800919 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200920 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200921 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200922 .procname = "perf_event_mlock_kb",
923 .data = &sysctl_perf_event_mlock,
924 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200925 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800926 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200927 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200928 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200929 .procname = "perf_event_max_sample_rate",
930 .data = &sysctl_perf_event_sample_rate,
931 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200932 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800933 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200934 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200935#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200936#ifdef CONFIG_KMEMCHECK
937 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200938 .procname = "kmemcheck",
939 .data = &kmemcheck_enabled,
940 .maxlen = sizeof(int),
941 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800942 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200943 },
944#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200945#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200946 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200947 .procname = "blk_iopoll",
948 .data = &blk_iopoll_enabled,
949 .maxlen = sizeof(int),
950 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800951 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200952 },
Jens Axboecb684b52009-09-15 21:53:11 +0200953#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700954/*
955 * NOTE: do not add new entries to this table unless you have read
956 * Documentation/sysctl/ctl_unnumbered.txt
957 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700958 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959};
960
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700961static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 .procname = "overcommit_memory",
964 .data = &sysctl_overcommit_memory,
965 .maxlen = sizeof(sysctl_overcommit_memory),
966 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800967 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 },
969 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700970 .procname = "panic_on_oom",
971 .data = &sysctl_panic_on_oom,
972 .maxlen = sizeof(sysctl_panic_on_oom),
973 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800974 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700975 },
976 {
David Rientjesfe071d72007-10-16 23:25:56 -0700977 .procname = "oom_kill_allocating_task",
978 .data = &sysctl_oom_kill_allocating_task,
979 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
980 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800981 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700982 },
983 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800984 .procname = "oom_dump_tasks",
985 .data = &sysctl_oom_dump_tasks,
986 .maxlen = sizeof(sysctl_oom_dump_tasks),
987 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800988 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -0800989 },
990 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 .procname = "overcommit_ratio",
992 .data = &sysctl_overcommit_ratio,
993 .maxlen = sizeof(sysctl_overcommit_ratio),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 },
997 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 .procname = "page-cluster",
999 .data = &page_cluster,
1000 .maxlen = sizeof(int),
1001 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 },
1004 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 .procname = "dirty_background_ratio",
1006 .data = &dirty_background_ratio,
1007 .maxlen = sizeof(dirty_background_ratio),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 .extra1 = &zero,
1011 .extra2 = &one_hundred,
1012 },
1013 {
David Rientjes2da02992009-01-06 14:39:31 -08001014 .procname = "dirty_background_bytes",
1015 .data = &dirty_background_bytes,
1016 .maxlen = sizeof(dirty_background_bytes),
1017 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001018 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001019 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001020 },
1021 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 .procname = "dirty_ratio",
1023 .data = &vm_dirty_ratio,
1024 .maxlen = sizeof(vm_dirty_ratio),
1025 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001026 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 .extra1 = &zero,
1028 .extra2 = &one_hundred,
1029 },
1030 {
David Rientjes2da02992009-01-06 14:39:31 -08001031 .procname = "dirty_bytes",
1032 .data = &vm_dirty_bytes,
1033 .maxlen = sizeof(vm_dirty_bytes),
1034 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001035 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001036 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001037 },
1038 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001040 .data = &dirty_writeback_interval,
1041 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001043 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 },
1045 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001047 .data = &dirty_expire_interval,
1048 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001050 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 },
1052 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 .procname = "nr_pdflush_threads",
1054 .data = &nr_pdflush_threads,
1055 .maxlen = sizeof nr_pdflush_threads,
1056 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001057 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 },
1059 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 .procname = "swappiness",
1061 .data = &vm_swappiness,
1062 .maxlen = sizeof(vm_swappiness),
1063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 .extra1 = &zero,
1066 .extra2 = &one_hundred,
1067 },
1068#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001069 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001071 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 .maxlen = sizeof(unsigned long),
1073 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001074 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 .extra1 = (void *)&hugetlb_zero,
1076 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001077 },
1078#ifdef CONFIG_NUMA
1079 {
1080 .procname = "nr_hugepages_mempolicy",
1081 .data = NULL,
1082 .maxlen = sizeof(unsigned long),
1083 .mode = 0644,
1084 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1085 .extra1 = (void *)&hugetlb_zero,
1086 .extra2 = (void *)&hugetlb_infinity,
1087 },
1088#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 .procname = "hugetlb_shm_group",
1091 .data = &sysctl_hugetlb_shm_group,
1092 .maxlen = sizeof(gid_t),
1093 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001094 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 },
Mel Gorman396faf02007-07-17 04:03:13 -07001096 {
Mel Gorman396faf02007-07-17 04:03:13 -07001097 .procname = "hugepages_treat_as_movable",
1098 .data = &hugepages_treat_as_movable,
1099 .maxlen = sizeof(int),
1100 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001101 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001102 },
Adam Litke54f9f802007-10-16 01:26:20 -07001103 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001104 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001105 .data = NULL,
1106 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001107 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001108 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001109 .extra1 = (void *)&hugetlb_zero,
1110 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001111 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112#endif
1113 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 .procname = "lowmem_reserve_ratio",
1115 .data = &sysctl_lowmem_reserve_ratio,
1116 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1117 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001118 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 },
1120 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001121 .procname = "drop_caches",
1122 .data = &sysctl_drop_caches,
1123 .maxlen = sizeof(int),
1124 .mode = 0644,
1125 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001126 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001127#ifdef CONFIG_COMPACTION
1128 {
1129 .procname = "compact_memory",
1130 .data = &sysctl_compact_memory,
1131 .maxlen = sizeof(int),
1132 .mode = 0200,
1133 .proc_handler = sysctl_compaction_handler,
1134 },
Mel Gorman5e771902010-05-24 14:32:31 -07001135 {
1136 .procname = "extfrag_threshold",
1137 .data = &sysctl_extfrag_threshold,
1138 .maxlen = sizeof(int),
1139 .mode = 0644,
1140 .proc_handler = sysctl_extfrag_handler,
1141 .extra1 = &min_extfrag_threshold,
1142 .extra2 = &max_extfrag_threshold,
1143 },
1144
Mel Gorman76ab0f52010-05-24 14:32:28 -07001145#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001146 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 .procname = "min_free_kbytes",
1148 .data = &min_free_kbytes,
1149 .maxlen = sizeof(min_free_kbytes),
1150 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001151 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 .extra1 = &zero,
1153 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001154 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001155 .procname = "percpu_pagelist_fraction",
1156 .data = &percpu_pagelist_fraction,
1157 .maxlen = sizeof(percpu_pagelist_fraction),
1158 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001159 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001160 .extra1 = &min_percpu_pagelist_fract,
1161 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162#ifdef CONFIG_MMU
1163 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 .procname = "max_map_count",
1165 .data = &sysctl_max_map_count,
1166 .maxlen = sizeof(sysctl_max_map_count),
1167 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001168 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001169 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001171#else
1172 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001173 .procname = "nr_trim_pages",
1174 .data = &sysctl_nr_trim_pages,
1175 .maxlen = sizeof(sysctl_nr_trim_pages),
1176 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001177 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001178 .extra1 = &zero,
1179 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#endif
1181 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 .procname = "laptop_mode",
1183 .data = &laptop_mode,
1184 .maxlen = sizeof(laptop_mode),
1185 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001186 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 },
1188 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 .procname = "block_dump",
1190 .data = &block_dump,
1191 .maxlen = sizeof(block_dump),
1192 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001193 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 .extra1 = &zero,
1195 },
1196 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 .procname = "vfs_cache_pressure",
1198 .data = &sysctl_vfs_cache_pressure,
1199 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1200 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001201 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 .extra1 = &zero,
1203 },
1204#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1205 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 .procname = "legacy_va_layout",
1207 .data = &sysctl_legacy_va_layout,
1208 .maxlen = sizeof(sysctl_legacy_va_layout),
1209 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001210 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 .extra1 = &zero,
1212 },
1213#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001214#ifdef CONFIG_NUMA
1215 {
Christoph Lameter17436602006-01-18 17:42:32 -08001216 .procname = "zone_reclaim_mode",
1217 .data = &zone_reclaim_mode,
1218 .maxlen = sizeof(zone_reclaim_mode),
1219 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001220 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001221 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001222 },
Christoph Lameter96146342006-07-03 00:24:13 -07001223 {
Christoph Lameter96146342006-07-03 00:24:13 -07001224 .procname = "min_unmapped_ratio",
1225 .data = &sysctl_min_unmapped_ratio,
1226 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1227 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001228 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001229 .extra1 = &zero,
1230 .extra2 = &one_hundred,
1231 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001232 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001233 .procname = "min_slab_ratio",
1234 .data = &sysctl_min_slab_ratio,
1235 .maxlen = sizeof(sysctl_min_slab_ratio),
1236 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001237 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001238 .extra1 = &zero,
1239 .extra2 = &one_hundred,
1240 },
Christoph Lameter17436602006-01-18 17:42:32 -08001241#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001242#ifdef CONFIG_SMP
1243 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001244 .procname = "stat_interval",
1245 .data = &sysctl_stat_interval,
1246 .maxlen = sizeof(sysctl_stat_interval),
1247 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001248 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001249 },
1250#endif
David Howells6e141542009-12-15 19:27:45 +00001251#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001252 {
Eric Parised032182007-06-28 15:55:21 -04001253 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001254 .data = &dac_mmap_min_addr,
1255 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001256 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001257 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001258 },
David Howells6e141542009-12-15 19:27:45 +00001259#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001260#ifdef CONFIG_NUMA
1261 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001262 .procname = "numa_zonelist_order",
1263 .data = &numa_zonelist_order,
1264 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1265 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001266 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001267 },
1268#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001269#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001270 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001271 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001272 .procname = "vdso_enabled",
1273 .data = &vdso_enabled,
1274 .maxlen = sizeof(vdso_enabled),
1275 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001276 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001277 .extra1 = &zero,
1278 },
1279#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001280#ifdef CONFIG_HIGHMEM
1281 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001282 .procname = "highmem_is_dirtyable",
1283 .data = &vm_highmem_is_dirtyable,
1284 .maxlen = sizeof(vm_highmem_is_dirtyable),
1285 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001286 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001287 .extra1 = &zero,
1288 .extra2 = &one,
1289 },
1290#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001291 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001292 .procname = "scan_unevictable_pages",
1293 .data = &scan_unevictable_pages,
1294 .maxlen = sizeof(scan_unevictable_pages),
1295 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001296 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001297 },
Andi Kleen6a460792009-09-16 11:50:15 +02001298#ifdef CONFIG_MEMORY_FAILURE
1299 {
Andi Kleen6a460792009-09-16 11:50:15 +02001300 .procname = "memory_failure_early_kill",
1301 .data = &sysctl_memory_failure_early_kill,
1302 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1303 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001304 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001305 .extra1 = &zero,
1306 .extra2 = &one,
1307 },
1308 {
Andi Kleen6a460792009-09-16 11:50:15 +02001309 .procname = "memory_failure_recovery",
1310 .data = &sysctl_memory_failure_recovery,
1311 .maxlen = sizeof(sysctl_memory_failure_recovery),
1312 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001313 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001314 .extra1 = &zero,
1315 .extra2 = &one,
1316 },
1317#endif
1318
Andrew Morton2be7fe02007-07-15 23:41:21 -07001319/*
1320 * NOTE: do not add new entries to this table unless you have read
1321 * Documentation/sysctl/ctl_unnumbered.txt
1322 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001323 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324};
1325
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001326#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001327static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001328 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001329};
1330#endif
1331
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001332static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 .procname = "inode-nr",
1335 .data = &inodes_stat,
1336 .maxlen = 2*sizeof(int),
1337 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001338 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 },
1340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .procname = "inode-state",
1342 .data = &inodes_stat,
1343 .maxlen = 7*sizeof(int),
1344 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001345 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 },
1347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .procname = "file-nr",
1349 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001350 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 },
1354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .procname = "file-max",
1356 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001357 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001359 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 },
1361 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001362 .procname = "nr_open",
1363 .data = &sysctl_nr_open,
1364 .maxlen = sizeof(int),
1365 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001366 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001367 .extra1 = &sysctl_nr_open_min,
1368 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001369 },
1370 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 .procname = "dentry-state",
1372 .data = &dentry_stat,
1373 .maxlen = 6*sizeof(int),
1374 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001375 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 },
1377 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 .procname = "overflowuid",
1379 .data = &fs_overflowuid,
1380 .maxlen = sizeof(int),
1381 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001382 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .extra1 = &minolduid,
1384 .extra2 = &maxolduid,
1385 },
1386 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 .procname = "overflowgid",
1388 .data = &fs_overflowgid,
1389 .maxlen = sizeof(int),
1390 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001391 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .extra1 = &minolduid,
1393 .extra2 = &maxolduid,
1394 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001395#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 .procname = "leases-enable",
1398 .data = &leases_enable,
1399 .maxlen = sizeof(int),
1400 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001401 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001403#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404#ifdef CONFIG_DNOTIFY
1405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 .procname = "dir-notify-enable",
1407 .data = &dir_notify_enable,
1408 .maxlen = sizeof(int),
1409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001410 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 },
1412#endif
1413#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001414#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 .procname = "lease-break-time",
1417 .data = &lease_break_time,
1418 .maxlen = sizeof(int),
1419 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001420 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001422#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001423#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 .procname = "aio-nr",
1426 .data = &aio_nr,
1427 .maxlen = sizeof(aio_nr),
1428 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001429 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 },
1431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 .procname = "aio-max-nr",
1433 .data = &aio_max_nr,
1434 .maxlen = sizeof(aio_max_nr),
1435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001436 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001438#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001439#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001440 {
Robert Love0399cb02005-07-13 12:38:18 -04001441 .procname = "inotify",
1442 .mode = 0555,
1443 .child = inotify_table,
1444 },
1445#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001446#ifdef CONFIG_EPOLL
1447 {
1448 .procname = "epoll",
1449 .mode = 0555,
1450 .child = epoll_table,
1451 },
1452#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001454 {
Alan Coxd6e71142005-06-23 00:09:43 -07001455 .procname = "suid_dumpable",
1456 .data = &suid_dumpable,
1457 .maxlen = sizeof(int),
1458 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001459 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001460 .extra1 = &zero,
1461 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001462 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001463#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1464 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001465 .procname = "binfmt_misc",
1466 .mode = 0555,
1467 .child = binfmt_misc_table,
1468 },
1469#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001470 {
Jens Axboeff9da692010-06-03 14:54:39 +02001471 .procname = "pipe-max-size",
1472 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001473 .maxlen = sizeof(int),
1474 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001475 .proc_handler = &pipe_proc_fn,
1476 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001477 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001478/*
1479 * NOTE: do not add new entries to this table unless you have read
1480 * Documentation/sysctl/ctl_unnumbered.txt
1481 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001482 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483};
1484
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001485static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001486#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1487 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001488 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001489 .procname = "exception-trace",
1490 .data = &show_unhandled_signals,
1491 .maxlen = sizeof(int),
1492 .mode = 0644,
1493 .proc_handler = proc_dointvec
1494 },
1495#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001496#if defined(CONFIG_OPTPROBES)
1497 {
1498 .procname = "kprobes-optimization",
1499 .data = &sysctl_kprobes_optimization,
1500 .maxlen = sizeof(int),
1501 .mode = 0644,
1502 .proc_handler = proc_kprobes_optimization_handler,
1503 .extra1 = &zero,
1504 .extra2 = &one,
1505 },
1506#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001507 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508};
1509
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001510static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001511 { }
Robert Love0eeca282005-07-12 17:06:03 -04001512};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
Al Viro330d57f2005-11-04 10:18:40 +00001514static DEFINE_SPINLOCK(sysctl_lock);
1515
1516/* called under sysctl_lock */
1517static int use_table(struct ctl_table_header *p)
1518{
1519 if (unlikely(p->unregistering))
1520 return 0;
1521 p->used++;
1522 return 1;
1523}
1524
1525/* called under sysctl_lock */
1526static void unuse_table(struct ctl_table_header *p)
1527{
1528 if (!--p->used)
1529 if (unlikely(p->unregistering))
1530 complete(p->unregistering);
1531}
1532
1533/* called under sysctl_lock, will reacquire if has to wait */
1534static void start_unregistering(struct ctl_table_header *p)
1535{
1536 /*
1537 * if p->used is 0, nobody will ever touch that entry again;
1538 * we'll eliminate all paths to it before dropping sysctl_lock
1539 */
1540 if (unlikely(p->used)) {
1541 struct completion wait;
1542 init_completion(&wait);
1543 p->unregistering = &wait;
1544 spin_unlock(&sysctl_lock);
1545 wait_for_completion(&wait);
1546 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001547 } else {
1548 /* anything non-NULL; we'll never dereference it */
1549 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001550 }
1551 /*
1552 * do not remove from the list until nobody holds it; walking the
1553 * list in do_sysctl() relies on that.
1554 */
1555 list_del_init(&p->ctl_entry);
1556}
1557
Al Virof7e6ced2008-07-15 01:44:23 -04001558void sysctl_head_get(struct ctl_table_header *head)
1559{
1560 spin_lock(&sysctl_lock);
1561 head->count++;
1562 spin_unlock(&sysctl_lock);
1563}
1564
1565void sysctl_head_put(struct ctl_table_header *head)
1566{
1567 spin_lock(&sysctl_lock);
1568 if (!--head->count)
1569 kfree(head);
1570 spin_unlock(&sysctl_lock);
1571}
1572
1573struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1574{
1575 if (!head)
1576 BUG();
1577 spin_lock(&sysctl_lock);
1578 if (!use_table(head))
1579 head = ERR_PTR(-ENOENT);
1580 spin_unlock(&sysctl_lock);
1581 return head;
1582}
1583
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001584void sysctl_head_finish(struct ctl_table_header *head)
1585{
1586 if (!head)
1587 return;
1588 spin_lock(&sysctl_lock);
1589 unuse_table(head);
1590 spin_unlock(&sysctl_lock);
1591}
1592
Al Viro73455092008-07-14 21:22:20 -04001593static struct ctl_table_set *
1594lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1595{
1596 struct ctl_table_set *set = &root->default_set;
1597 if (root->lookup)
1598 set = root->lookup(root, namespaces);
1599 return set;
1600}
1601
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001602static struct list_head *
1603lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001604{
Al Viro73455092008-07-14 21:22:20 -04001605 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1606 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001607}
1608
1609struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1610 struct ctl_table_header *prev)
1611{
1612 struct ctl_table_root *root;
1613 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001614 struct ctl_table_header *head;
1615 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001616
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001617 spin_lock(&sysctl_lock);
1618 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001619 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001620 tmp = &prev->ctl_entry;
1621 unuse_table(prev);
1622 goto next;
1623 }
1624 tmp = &root_table_header.ctl_entry;
1625 for (;;) {
1626 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1627
1628 if (!use_table(head))
1629 goto next;
1630 spin_unlock(&sysctl_lock);
1631 return head;
1632 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001633 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001634 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001635 header_list = lookup_header_list(root, namespaces);
1636 if (tmp != header_list)
1637 continue;
1638
1639 do {
1640 root = list_entry(root->root_list.next,
1641 struct ctl_table_root, root_list);
1642 if (root == &sysctl_table_root)
1643 goto out;
1644 header_list = lookup_header_list(root, namespaces);
1645 } while (list_empty(header_list));
1646 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001647 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001648out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001649 spin_unlock(&sysctl_lock);
1650 return NULL;
1651}
1652
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001653struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1654{
1655 return __sysctl_head_next(current->nsproxy, prev);
1656}
1657
1658void register_sysctl_root(struct ctl_table_root *root)
1659{
1660 spin_lock(&sysctl_lock);
1661 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1662 spin_unlock(&sysctl_lock);
1663}
1664
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001666 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 * some sysctl variables are readonly even to root.
1668 */
1669
1670static int test_perm(int mode, int op)
1671{
David Howells76aac0e2008-11-14 10:39:12 +11001672 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 mode >>= 6;
1674 else if (in_egroup_p(0))
1675 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001676 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 return 0;
1678 return -EACCES;
1679}
1680
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001681int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
1683 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001684 int mode;
1685
Al Viroe6305c42008-07-15 21:03:57 -04001686 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 if (error)
1688 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001689
1690 if (root->permissions)
1691 mode = root->permissions(root, current->nsproxy, table);
1692 else
1693 mode = table->mode;
1694
1695 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696}
1697
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001698static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1699{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001700 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001701 table->parent = parent;
1702 if (table->child)
1703 sysctl_set_parent(table, table->child);
1704 }
1705}
1706
1707static __init int sysctl_init(void)
1708{
1709 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001710#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001711 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001712#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001713 return 0;
1714}
1715
1716core_initcall(sysctl_init);
1717
Al Virobfbcf032008-07-27 06:31:22 +01001718static struct ctl_table *is_branch_in(struct ctl_table *branch,
1719 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001720{
1721 struct ctl_table *p;
1722 const char *s = branch->procname;
1723
1724 /* branch should have named subdirectory as its first element */
1725 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001726 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001727
1728 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001729 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001730 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001731
1732 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001733 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001734 if (!p->child)
1735 continue;
1736 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001737 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001738 }
Al Virobfbcf032008-07-27 06:31:22 +01001739 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001740}
1741
1742/* see if attaching q to p would be an improvement */
1743static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1744{
1745 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001746 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001747 int is_better = 0;
1748 int not_in_parent = !p->attached_by;
1749
Al Virobfbcf032008-07-27 06:31:22 +01001750 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001751 if (by == q->attached_by)
1752 is_better = 1;
1753 if (to == p->attached_by)
1754 not_in_parent = 1;
1755 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001756 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001757 }
1758
1759 if (is_better && not_in_parent) {
1760 q->attached_by = by;
1761 q->attached_to = to;
1762 q->parent = p;
1763 }
1764}
1765
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001767 * __register_sysctl_paths - register a sysctl hierarchy
1768 * @root: List of sysctl headers to register on
1769 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001770 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 *
1773 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001774 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001776 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1779 * enter a sysctl file
1780 *
1781 * data - a pointer to data for use by proc_handler
1782 *
1783 * maxlen - the maximum size in bytes of the data
1784 *
1785 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1786 *
1787 * child - a pointer to the child sysctl table if this entry is a directory, or
1788 * %NULL.
1789 *
1790 * proc_handler - the text handler routine (described below)
1791 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 * de - for internal use by the sysctl routines
1793 *
1794 * extra1, extra2 - extra pointers usable by the proc handler routines
1795 *
1796 * Leaf nodes in the sysctl tree will be represented by a single file
1797 * under /proc; non-leaf nodes will be represented by directories.
1798 *
1799 * sysctl(2) can automatically manage read and write requests through
1800 * the sysctl table. The data and maxlen fields of the ctl_table
1801 * struct enable minimal validation of the values being written to be
1802 * performed, and the mode field allows minimal authentication.
1803 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 * There must be a proc_handler routine for any terminal nodes
1805 * mirrored under /proc/sys (non-terminals are handled by a built-in
1806 * directory handler). Several default handlers are available to
1807 * cover common cases -
1808 *
1809 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1810 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1811 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1812 *
1813 * It is the handler's job to read the input buffer from user memory
1814 * and process it. The handler should return 0 on success.
1815 *
1816 * This routine returns %NULL on a failure to register, and a pointer
1817 * to the table header on success.
1818 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001819struct ctl_table_header *__register_sysctl_paths(
1820 struct ctl_table_root *root,
1821 struct nsproxy *namespaces,
1822 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001824 struct ctl_table_header *header;
1825 struct ctl_table *new, **prevp;
1826 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001827 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001828
1829 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001830 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001831 ;
1832
1833 /*
1834 * For each path component, allocate a 2-element ctl_table array.
1835 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001836 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001837 *
1838 * We allocate everything in one go so that we don't have to
1839 * worry about freeing additional memory in unregister_sysctl_table.
1840 */
1841 header = kzalloc(sizeof(struct ctl_table_header) +
1842 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1843 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001845
1846 new = (struct ctl_table *) (header + 1);
1847
1848 /* Now connect the dots */
1849 prevp = &header->ctl_table;
1850 for (n = 0; n < npath; ++n, ++path) {
1851 /* Copy the procname */
1852 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001853 new->mode = 0555;
1854
1855 *prevp = new;
1856 prevp = &new->child;
1857
1858 new += 2;
1859 }
1860 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001861 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001862
1863 INIT_LIST_HEAD(&header->ctl_entry);
1864 header->used = 0;
1865 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001866 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001867 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001868 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001869#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001870 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001871 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001872 return NULL;
1873 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001874#endif
Al Viro330d57f2005-11-04 10:18:40 +00001875 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001876 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001877 header->attached_by = header->ctl_table;
1878 header->attached_to = root_table;
1879 header->parent = &root_table_header;
1880 for (set = header->set; set; set = set->parent) {
1881 struct ctl_table_header *p;
1882 list_for_each_entry(p, &set->list, ctl_entry) {
1883 if (p->unregistering)
1884 continue;
1885 try_attach(p, header);
1886 }
1887 }
1888 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001889 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001890 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001891
1892 return header;
1893}
1894
1895/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001896 * register_sysctl_table_path - register a sysctl table hierarchy
1897 * @path: The path to the directory the sysctl table is in.
1898 * @table: the top-level table structure
1899 *
1900 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1901 * array. A completely 0 filled entry terminates the table.
1902 *
1903 * See __register_sysctl_paths for more details.
1904 */
1905struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1906 struct ctl_table *table)
1907{
1908 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1909 path, table);
1910}
1911
1912/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001913 * register_sysctl_table - register a sysctl table hierarchy
1914 * @table: the top-level table structure
1915 *
1916 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1917 * array. A completely 0 filled entry terminates the table.
1918 *
1919 * See register_sysctl_paths for more details.
1920 */
1921struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1922{
1923 static const struct ctl_path null_path[] = { {} };
1924
1925 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926}
1927
1928/**
1929 * unregister_sysctl_table - unregister a sysctl table hierarchy
1930 * @header: the header returned from register_sysctl_table
1931 *
1932 * Unregisters the sysctl table and all children. proc entries may not
1933 * actually be removed until they are no longer used by anyone.
1934 */
1935void unregister_sysctl_table(struct ctl_table_header * header)
1936{
Al Viro330d57f2005-11-04 10:18:40 +00001937 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001938
1939 if (header == NULL)
1940 return;
1941
Al Viro330d57f2005-11-04 10:18:40 +00001942 spin_lock(&sysctl_lock);
1943 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001944 if (!--header->parent->count) {
1945 WARN_ON(1);
1946 kfree(header->parent);
1947 }
Al Virof7e6ced2008-07-15 01:44:23 -04001948 if (!--header->count)
1949 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001950 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
Al Viro9043476f2008-07-15 08:54:06 -04001953int sysctl_is_seen(struct ctl_table_header *p)
1954{
1955 struct ctl_table_set *set = p->set;
1956 int res;
1957 spin_lock(&sysctl_lock);
1958 if (p->unregistering)
1959 res = 0;
1960 else if (!set->is_seen)
1961 res = 1;
1962 else
1963 res = set->is_seen(set);
1964 spin_unlock(&sysctl_lock);
1965 return res;
1966}
1967
Al Viro73455092008-07-14 21:22:20 -04001968void setup_sysctl_set(struct ctl_table_set *p,
1969 struct ctl_table_set *parent,
1970 int (*is_seen)(struct ctl_table_set *))
1971{
1972 INIT_LIST_HEAD(&p->list);
1973 p->parent = parent ? parent : &sysctl_table_root.default_set;
1974 p->is_seen = is_seen;
1975}
1976
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001977#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001978struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001979{
1980 return NULL;
1981}
1982
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001983struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1984 struct ctl_table *table)
1985{
1986 return NULL;
1987}
1988
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001989void unregister_sysctl_table(struct ctl_table_header * table)
1990{
1991}
1992
Al Viro73455092008-07-14 21:22:20 -04001993void setup_sysctl_set(struct ctl_table_set *p,
1994 struct ctl_table_set *parent,
1995 int (*is_seen)(struct ctl_table_set *))
1996{
1997}
1998
Al Virof7e6ced2008-07-15 01:44:23 -04001999void sysctl_head_put(struct ctl_table_header *head)
2000{
2001}
2002
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002003#endif /* CONFIG_SYSCTL */
2004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005/*
2006 * /proc/sys support
2007 */
2008
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002009#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002011static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002012 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002013 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002014{
2015 size_t len;
2016 char __user *p;
2017 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002018
2019 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002020 *lenp = 0;
2021 return 0;
2022 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002023
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002024 if (write) {
2025 len = 0;
2026 p = buffer;
2027 while (len < *lenp) {
2028 if (get_user(c, p++))
2029 return -EFAULT;
2030 if (c == 0 || c == '\n')
2031 break;
2032 len++;
2033 }
2034 if (len >= maxlen)
2035 len = maxlen-1;
2036 if(copy_from_user(data, buffer, len))
2037 return -EFAULT;
2038 ((char *) data)[len] = 0;
2039 *ppos += *lenp;
2040 } else {
2041 len = strlen(data);
2042 if (len > maxlen)
2043 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002044
2045 if (*ppos > len) {
2046 *lenp = 0;
2047 return 0;
2048 }
2049
2050 data += *ppos;
2051 len -= *ppos;
2052
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002053 if (len > *lenp)
2054 len = *lenp;
2055 if (len)
2056 if(copy_to_user(buffer, data, len))
2057 return -EFAULT;
2058 if (len < *lenp) {
2059 if(put_user('\n', ((char __user *) buffer) + len))
2060 return -EFAULT;
2061 len++;
2062 }
2063 *lenp = len;
2064 *ppos += len;
2065 }
2066 return 0;
2067}
2068
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069/**
2070 * proc_dostring - read a string sysctl
2071 * @table: the sysctl table
2072 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 * @buffer: the user buffer
2074 * @lenp: the size of the user buffer
2075 * @ppos: file position
2076 *
2077 * Reads/writes a string from/to the user buffer. If the kernel
2078 * buffer provided is not large enough to hold the string, the
2079 * string is truncated. The copied string is %NULL-terminated.
2080 * If the string is being read by the user process, it is copied
2081 * and a newline '\n' is added. It is truncated if the buffer is
2082 * not large enough.
2083 *
2084 * Returns 0 on success.
2085 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002086int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 void __user *buffer, size_t *lenp, loff_t *ppos)
2088{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002089 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002090 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
Amerigo Wang00b7c332010-05-05 00:26:45 +00002093static size_t proc_skip_spaces(char **buf)
2094{
2095 size_t ret;
2096 char *tmp = skip_spaces(*buf);
2097 ret = tmp - *buf;
2098 *buf = tmp;
2099 return ret;
2100}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002102static void proc_skip_char(char **buf, size_t *size, const char v)
2103{
2104 while (*size) {
2105 if (**buf != v)
2106 break;
2107 (*size)--;
2108 (*buf)++;
2109 }
2110}
2111
Amerigo Wang00b7c332010-05-05 00:26:45 +00002112#define TMPBUFLEN 22
2113/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002114 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002115 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002116 * @buf: a kernel buffer
2117 * @size: size of the kernel buffer
2118 * @val: this is where the number will be stored
2119 * @neg: set to %TRUE if number is negative
2120 * @perm_tr: a vector which contains the allowed trailers
2121 * @perm_tr_len: size of the perm_tr vector
2122 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002123 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002124 * In case of success %0 is returned and @buf and @size are updated with
2125 * the amount of bytes read. If @tr is non-NULL and a trailing
2126 * character exists (size is non-zero after returning from this
2127 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002128 */
2129static int proc_get_long(char **buf, size_t *size,
2130 unsigned long *val, bool *neg,
2131 const char *perm_tr, unsigned perm_tr_len, char *tr)
2132{
2133 int len;
2134 char *p, tmp[TMPBUFLEN];
2135
2136 if (!*size)
2137 return -EINVAL;
2138
2139 len = *size;
2140 if (len > TMPBUFLEN - 1)
2141 len = TMPBUFLEN - 1;
2142
2143 memcpy(tmp, *buf, len);
2144
2145 tmp[len] = 0;
2146 p = tmp;
2147 if (*p == '-' && *size > 1) {
2148 *neg = true;
2149 p++;
2150 } else
2151 *neg = false;
2152 if (!isdigit(*p))
2153 return -EINVAL;
2154
2155 *val = simple_strtoul(p, &p, 0);
2156
2157 len = p - tmp;
2158
2159 /* We don't know if the next char is whitespace thus we may accept
2160 * invalid integers (e.g. 1234...a) or two integers instead of one
2161 * (e.g. 123...1). So lets not allow such large numbers. */
2162 if (len == TMPBUFLEN - 1)
2163 return -EINVAL;
2164
2165 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2166 return -EINVAL;
2167
2168 if (tr && (len < *size))
2169 *tr = *p;
2170
2171 *buf += len;
2172 *size -= len;
2173
2174 return 0;
2175}
2176
2177/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002178 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002179 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002180 * @buf: the user buffer
2181 * @size: the size of the user buffer
2182 * @val: the integer to be converted
2183 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002184 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002185 * In case of success %0 is returned and @buf and @size are updated with
2186 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002187 */
2188static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2189 bool neg)
2190{
2191 int len;
2192 char tmp[TMPBUFLEN], *p = tmp;
2193
2194 sprintf(p, "%s%lu", neg ? "-" : "", val);
2195 len = strlen(tmp);
2196 if (len > *size)
2197 len = *size;
2198 if (copy_to_user(*buf, tmp, len))
2199 return -EFAULT;
2200 *size -= len;
2201 *buf += len;
2202 return 0;
2203}
2204#undef TMPBUFLEN
2205
2206static int proc_put_char(void __user **buf, size_t *size, char c)
2207{
2208 if (*size) {
2209 char __user **buffer = (char __user **)buf;
2210 if (put_user(c, *buffer))
2211 return -EFAULT;
2212 (*size)--, (*buffer)++;
2213 *buf = *buffer;
2214 }
2215 return 0;
2216}
2217
2218static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 int *valp,
2220 int write, void *data)
2221{
2222 if (write) {
2223 *valp = *negp ? -*lvalp : *lvalp;
2224 } else {
2225 int val = *valp;
2226 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002227 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 *lvalp = (unsigned long)-val;
2229 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002230 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 *lvalp = (unsigned long)val;
2232 }
2233 }
2234 return 0;
2235}
2236
Amerigo Wang00b7c332010-05-05 00:26:45 +00002237static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2238
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002239static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002240 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002241 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 int write, void *data),
2244 void *data)
2245{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002246 int *i, vleft, first = 1, err = 0;
2247 unsigned long page = 0;
2248 size_t left;
2249 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
Amerigo Wang00b7c332010-05-05 00:26:45 +00002251 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 *lenp = 0;
2253 return 0;
2254 }
2255
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002256 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 vleft = table->maxlen / sizeof(*i);
2258 left = *lenp;
2259
2260 if (!conv)
2261 conv = do_proc_dointvec_conv;
2262
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002264 if (left > PAGE_SIZE - 1)
2265 left = PAGE_SIZE - 1;
2266 page = __get_free_page(GFP_TEMPORARY);
2267 kbuf = (char *) page;
2268 if (!kbuf)
2269 return -ENOMEM;
2270 if (copy_from_user(kbuf, buffer, left)) {
2271 err = -EFAULT;
2272 goto free;
2273 }
2274 kbuf[left] = 0;
2275 }
2276
2277 for (; left && vleft--; i++, first=0) {
2278 unsigned long lval;
2279 bool neg;
2280
2281 if (write) {
2282 left -= proc_skip_spaces(&kbuf);
2283
J. R. Okajima563b0462010-05-25 16:10:14 -07002284 if (!left)
2285 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002286 err = proc_get_long(&kbuf, &left, &lval, &neg,
2287 proc_wspace_sep,
2288 sizeof(proc_wspace_sep), NULL);
2289 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002291 if (conv(&neg, &lval, i, 1, data)) {
2292 err = -EINVAL;
2293 break;
2294 }
2295 } else {
2296 if (conv(&neg, &lval, i, 0, data)) {
2297 err = -EINVAL;
2298 break;
2299 }
2300 if (!first)
2301 err = proc_put_char(&buffer, &left, '\t');
2302 if (err)
2303 break;
2304 err = proc_put_long(&buffer, &left, lval, neg);
2305 if (err)
2306 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 }
2308 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002309
2310 if (!write && !first && left && !err)
2311 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002312 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002313 left -= proc_skip_spaces(&kbuf);
2314free:
2315 if (write) {
2316 free_page(page);
2317 if (first)
2318 return err ? : -EINVAL;
2319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 *lenp -= left;
2321 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002322 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323}
2324
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002325static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002326 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002327 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002328 int write, void *data),
2329 void *data)
2330{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002331 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002332 buffer, lenp, ppos, conv, data);
2333}
2334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335/**
2336 * proc_dointvec - read a vector of integers
2337 * @table: the sysctl table
2338 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 * @buffer: the user buffer
2340 * @lenp: the size of the user buffer
2341 * @ppos: file position
2342 *
2343 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2344 * values from/to the user buffer, treated as an ASCII string.
2345 *
2346 * Returns 0 on success.
2347 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002348int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 void __user *buffer, size_t *lenp, loff_t *ppos)
2350{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002351 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 NULL,NULL);
2353}
2354
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002355/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002356 * Taint values can only be increased
2357 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002358 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002359static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002360 void __user *buffer, size_t *lenp, loff_t *ppos)
2361{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002362 struct ctl_table t;
2363 unsigned long tmptaint = get_taint();
2364 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002365
Bastian Blank91fcd412007-04-23 14:41:14 -07002366 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002367 return -EPERM;
2368
Andi Kleen25ddbb12008-10-15 22:01:41 -07002369 t = *table;
2370 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002371 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002372 if (err < 0)
2373 return err;
2374
2375 if (write) {
2376 /*
2377 * Poor man's atomic or. Not worth adding a primitive
2378 * to everyone's atomic.h for this
2379 */
2380 int i;
2381 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2382 if ((tmptaint >> i) & 1)
2383 add_taint(i);
2384 }
2385 }
2386
2387 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002388}
2389
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390struct do_proc_dointvec_minmax_conv_param {
2391 int *min;
2392 int *max;
2393};
2394
Amerigo Wang00b7c332010-05-05 00:26:45 +00002395static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2396 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 int write, void *data)
2398{
2399 struct do_proc_dointvec_minmax_conv_param *param = data;
2400 if (write) {
2401 int val = *negp ? -*lvalp : *lvalp;
2402 if ((param->min && *param->min > val) ||
2403 (param->max && *param->max < val))
2404 return -EINVAL;
2405 *valp = val;
2406 } else {
2407 int val = *valp;
2408 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002409 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 *lvalp = (unsigned long)-val;
2411 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002412 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 *lvalp = (unsigned long)val;
2414 }
2415 }
2416 return 0;
2417}
2418
2419/**
2420 * proc_dointvec_minmax - read a vector of integers with min/max values
2421 * @table: the sysctl table
2422 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 * @buffer: the user buffer
2424 * @lenp: the size of the user buffer
2425 * @ppos: file position
2426 *
2427 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2428 * values from/to the user buffer, treated as an ASCII string.
2429 *
2430 * This routine will ensure the values are within the range specified by
2431 * table->extra1 (min) and table->extra2 (max).
2432 *
2433 * Returns 0 on success.
2434 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002435int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 void __user *buffer, size_t *lenp, loff_t *ppos)
2437{
2438 struct do_proc_dointvec_minmax_conv_param param = {
2439 .min = (int *) table->extra1,
2440 .max = (int *) table->extra2,
2441 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002442 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 do_proc_dointvec_minmax_conv, &param);
2444}
2445
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002446static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 void __user *buffer,
2448 size_t *lenp, loff_t *ppos,
2449 unsigned long convmul,
2450 unsigned long convdiv)
2451{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002452 unsigned long *i, *min, *max;
2453 int vleft, first = 1, err = 0;
2454 unsigned long page = 0;
2455 size_t left;
2456 char *kbuf;
2457
2458 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 *lenp = 0;
2460 return 0;
2461 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002462
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002463 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 min = (unsigned long *) table->extra1;
2465 max = (unsigned long *) table->extra2;
2466 vleft = table->maxlen / sizeof(unsigned long);
2467 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002468
2469 if (write) {
2470 if (left > PAGE_SIZE - 1)
2471 left = PAGE_SIZE - 1;
2472 page = __get_free_page(GFP_TEMPORARY);
2473 kbuf = (char *) page;
2474 if (!kbuf)
2475 return -ENOMEM;
2476 if (copy_from_user(kbuf, buffer, left)) {
2477 err = -EFAULT;
2478 goto free;
2479 }
2480 kbuf[left] = 0;
2481 }
2482
Eric Dumazet27b3d802010-10-07 12:59:29 -07002483 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002484 unsigned long val;
2485
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002487 bool neg;
2488
2489 left -= proc_skip_spaces(&kbuf);
2490
2491 err = proc_get_long(&kbuf, &left, &val, &neg,
2492 proc_wspace_sep,
2493 sizeof(proc_wspace_sep), NULL);
2494 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 break;
2496 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 continue;
2498 if ((min && val < *min) || (max && val > *max))
2499 continue;
2500 *i = val;
2501 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002502 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002504 err = proc_put_char(&buffer, &left, '\t');
2505 err = proc_put_long(&buffer, &left, val, false);
2506 if (err)
2507 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 }
2509 }
2510
Amerigo Wang00b7c332010-05-05 00:26:45 +00002511 if (!write && !first && left && !err)
2512 err = proc_put_char(&buffer, &left, '\n');
2513 if (write && !err)
2514 left -= proc_skip_spaces(&kbuf);
2515free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002517 free_page(page);
2518 if (first)
2519 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 *lenp -= left;
2522 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002523 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524}
2525
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002526static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002527 void __user *buffer,
2528 size_t *lenp, loff_t *ppos,
2529 unsigned long convmul,
2530 unsigned long convdiv)
2531{
2532 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002533 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002534}
2535
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536/**
2537 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2538 * @table: the sysctl table
2539 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 * @buffer: the user buffer
2541 * @lenp: the size of the user buffer
2542 * @ppos: file position
2543 *
2544 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2545 * values from/to the user buffer, treated as an ASCII string.
2546 *
2547 * This routine will ensure the values are within the range specified by
2548 * table->extra1 (min) and table->extra2 (max).
2549 *
2550 * Returns 0 on success.
2551 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002552int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 void __user *buffer, size_t *lenp, loff_t *ppos)
2554{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002555 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556}
2557
2558/**
2559 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2560 * @table: the sysctl table
2561 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 * @buffer: the user buffer
2563 * @lenp: the size of the user buffer
2564 * @ppos: file position
2565 *
2566 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2567 * values from/to the user buffer, treated as an ASCII string. The values
2568 * are treated as milliseconds, and converted to jiffies when they are stored.
2569 *
2570 * This routine will ensure the values are within the range specified by
2571 * table->extra1 (min) and table->extra2 (max).
2572 *
2573 * Returns 0 on success.
2574 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002575int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 void __user *buffer,
2577 size_t *lenp, loff_t *ppos)
2578{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002579 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 lenp, ppos, HZ, 1000l);
2581}
2582
2583
Amerigo Wang00b7c332010-05-05 00:26:45 +00002584static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 int *valp,
2586 int write, void *data)
2587{
2588 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002589 if (*lvalp > LONG_MAX / HZ)
2590 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2592 } else {
2593 int val = *valp;
2594 unsigned long lval;
2595 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002596 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 lval = (unsigned long)-val;
2598 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002599 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 lval = (unsigned long)val;
2601 }
2602 *lvalp = lval / HZ;
2603 }
2604 return 0;
2605}
2606
Amerigo Wang00b7c332010-05-05 00:26:45 +00002607static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 int *valp,
2609 int write, void *data)
2610{
2611 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002612 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2613 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2615 } else {
2616 int val = *valp;
2617 unsigned long lval;
2618 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002619 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 lval = (unsigned long)-val;
2621 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002622 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 lval = (unsigned long)val;
2624 }
2625 *lvalp = jiffies_to_clock_t(lval);
2626 }
2627 return 0;
2628}
2629
Amerigo Wang00b7c332010-05-05 00:26:45 +00002630static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 int *valp,
2632 int write, void *data)
2633{
2634 if (write) {
2635 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2636 } else {
2637 int val = *valp;
2638 unsigned long lval;
2639 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002640 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 lval = (unsigned long)-val;
2642 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002643 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 lval = (unsigned long)val;
2645 }
2646 *lvalp = jiffies_to_msecs(lval);
2647 }
2648 return 0;
2649}
2650
2651/**
2652 * proc_dointvec_jiffies - read a vector of integers as seconds
2653 * @table: the sysctl table
2654 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 * @buffer: the user buffer
2656 * @lenp: the size of the user buffer
2657 * @ppos: file position
2658 *
2659 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2660 * values from/to the user buffer, treated as an ASCII string.
2661 * The values read are assumed to be in seconds, and are converted into
2662 * jiffies.
2663 *
2664 * Returns 0 on success.
2665 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002666int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 void __user *buffer, size_t *lenp, loff_t *ppos)
2668{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002669 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 do_proc_dointvec_jiffies_conv,NULL);
2671}
2672
2673/**
2674 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2675 * @table: the sysctl table
2676 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 * @buffer: the user buffer
2678 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002679 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 *
2681 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2682 * values from/to the user buffer, treated as an ASCII string.
2683 * The values read are assumed to be in 1/USER_HZ seconds, and
2684 * are converted into jiffies.
2685 *
2686 * Returns 0 on success.
2687 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002688int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 void __user *buffer, size_t *lenp, loff_t *ppos)
2690{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002691 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 do_proc_dointvec_userhz_jiffies_conv,NULL);
2693}
2694
2695/**
2696 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2697 * @table: the sysctl table
2698 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 * @buffer: the user buffer
2700 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002701 * @ppos: file position
2702 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 *
2704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2705 * values from/to the user buffer, treated as an ASCII string.
2706 * The values read are assumed to be in 1/1000 seconds, and
2707 * are converted into jiffies.
2708 *
2709 * Returns 0 on success.
2710 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002711int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 void __user *buffer, size_t *lenp, loff_t *ppos)
2713{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002714 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 do_proc_dointvec_ms_jiffies_conv, NULL);
2716}
2717
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002718static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002719 void __user *buffer, size_t *lenp, loff_t *ppos)
2720{
2721 struct pid *new_pid;
2722 pid_t tmp;
2723 int r;
2724
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002725 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002726
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002727 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002728 lenp, ppos, NULL, NULL);
2729 if (r || !write)
2730 return r;
2731
2732 new_pid = find_get_pid(tmp);
2733 if (!new_pid)
2734 return -ESRCH;
2735
2736 put_pid(xchg(&cad_pid, new_pid));
2737 return 0;
2738}
2739
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002740/**
2741 * proc_do_large_bitmap - read/write from/to a large bitmap
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
2746 * @ppos: file position
2747 *
2748 * The bitmap is stored at table->data and the bitmap length (in bits)
2749 * in table->maxlen.
2750 *
2751 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2752 * large bitmaps may be represented in a compact manner. Writing into
2753 * the file will clear the bitmap then update it with the given input.
2754 *
2755 * Returns 0 on success.
2756 */
2757int proc_do_large_bitmap(struct ctl_table *table, int write,
2758 void __user *buffer, size_t *lenp, loff_t *ppos)
2759{
2760 int err = 0;
2761 bool first = 1;
2762 size_t left = *lenp;
2763 unsigned long bitmap_len = table->maxlen;
2764 unsigned long *bitmap = (unsigned long *) table->data;
2765 unsigned long *tmp_bitmap = NULL;
2766 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2767
2768 if (!bitmap_len || !left || (*ppos && !write)) {
2769 *lenp = 0;
2770 return 0;
2771 }
2772
2773 if (write) {
2774 unsigned long page = 0;
2775 char *kbuf;
2776
2777 if (left > PAGE_SIZE - 1)
2778 left = PAGE_SIZE - 1;
2779
2780 page = __get_free_page(GFP_TEMPORARY);
2781 kbuf = (char *) page;
2782 if (!kbuf)
2783 return -ENOMEM;
2784 if (copy_from_user(kbuf, buffer, left)) {
2785 free_page(page);
2786 return -EFAULT;
2787 }
2788 kbuf[left] = 0;
2789
2790 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2791 GFP_KERNEL);
2792 if (!tmp_bitmap) {
2793 free_page(page);
2794 return -ENOMEM;
2795 }
2796 proc_skip_char(&kbuf, &left, '\n');
2797 while (!err && left) {
2798 unsigned long val_a, val_b;
2799 bool neg;
2800
2801 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2802 sizeof(tr_a), &c);
2803 if (err)
2804 break;
2805 if (val_a >= bitmap_len || neg) {
2806 err = -EINVAL;
2807 break;
2808 }
2809
2810 val_b = val_a;
2811 if (left) {
2812 kbuf++;
2813 left--;
2814 }
2815
2816 if (c == '-') {
2817 err = proc_get_long(&kbuf, &left, &val_b,
2818 &neg, tr_b, sizeof(tr_b),
2819 &c);
2820 if (err)
2821 break;
2822 if (val_b >= bitmap_len || neg ||
2823 val_a > val_b) {
2824 err = -EINVAL;
2825 break;
2826 }
2827 if (left) {
2828 kbuf++;
2829 left--;
2830 }
2831 }
2832
2833 while (val_a <= val_b)
2834 set_bit(val_a++, tmp_bitmap);
2835
2836 first = 0;
2837 proc_skip_char(&kbuf, &left, '\n');
2838 }
2839 free_page(page);
2840 } else {
2841 unsigned long bit_a, bit_b = 0;
2842
2843 while (left) {
2844 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2845 if (bit_a >= bitmap_len)
2846 break;
2847 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2848 bit_a + 1) - 1;
2849
2850 if (!first) {
2851 err = proc_put_char(&buffer, &left, ',');
2852 if (err)
2853 break;
2854 }
2855 err = proc_put_long(&buffer, &left, bit_a, false);
2856 if (err)
2857 break;
2858 if (bit_a != bit_b) {
2859 err = proc_put_char(&buffer, &left, '-');
2860 if (err)
2861 break;
2862 err = proc_put_long(&buffer, &left, bit_b, false);
2863 if (err)
2864 break;
2865 }
2866
2867 first = 0; bit_b++;
2868 }
2869 if (!err)
2870 err = proc_put_char(&buffer, &left, '\n');
2871 }
2872
2873 if (!err) {
2874 if (write) {
2875 if (*ppos)
2876 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2877 else
2878 memcpy(bitmap, tmp_bitmap,
2879 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2880 }
2881 kfree(tmp_bitmap);
2882 *lenp -= left;
2883 *ppos += *lenp;
2884 return 0;
2885 } else {
2886 kfree(tmp_bitmap);
2887 return err;
2888 }
2889}
2890
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891#else /* CONFIG_PROC_FS */
2892
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002893int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 void __user *buffer, size_t *lenp, loff_t *ppos)
2895{
2896 return -ENOSYS;
2897}
2898
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002899int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 void __user *buffer, size_t *lenp, loff_t *ppos)
2901{
2902 return -ENOSYS;
2903}
2904
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002905int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 void __user *buffer, size_t *lenp, loff_t *ppos)
2907{
2908 return -ENOSYS;
2909}
2910
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002911int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 void __user *buffer, size_t *lenp, loff_t *ppos)
2913{
2914 return -ENOSYS;
2915}
2916
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002917int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 void __user *buffer, size_t *lenp, loff_t *ppos)
2919{
2920 return -ENOSYS;
2921}
2922
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002923int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 void __user *buffer, size_t *lenp, loff_t *ppos)
2925{
2926 return -ENOSYS;
2927}
2928
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002929int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 void __user *buffer, size_t *lenp, loff_t *ppos)
2931{
2932 return -ENOSYS;
2933}
2934
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002935int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 void __user *buffer,
2937 size_t *lenp, loff_t *ppos)
2938{
2939 return -ENOSYS;
2940}
2941
2942
2943#endif /* CONFIG_PROC_FS */
2944
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945/*
2946 * No sense putting this after each symbol definition, twice,
2947 * exception granted :-)
2948 */
2949EXPORT_SYMBOL(proc_dointvec);
2950EXPORT_SYMBOL(proc_dointvec_jiffies);
2951EXPORT_SYMBOL(proc_dointvec_minmax);
2952EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2953EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2954EXPORT_SYMBOL(proc_dostring);
2955EXPORT_SYMBOL(proc_doulongvec_minmax);
2956EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2957EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002958EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959EXPORT_SYMBOL(unregister_sysctl_table);