blob: 121e4fff03d16c7582acf4eed832b845cf02b034 [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 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100373#ifdef CONFIG_SCHED_AUTOGROUP
374 {
375 .procname = "sched_autogroup_enabled",
376 .data = &sysctl_sched_autogroup_enabled,
377 .maxlen = sizeof(unsigned int),
378 .mode = 0644,
379 .proc_handler = proc_dointvec,
380 .extra1 = &zero,
381 .extra2 = &one,
382 },
383#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700384#ifdef CONFIG_PROVE_LOCKING
385 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700386 .procname = "prove_locking",
387 .data = &prove_locking,
388 .maxlen = sizeof(int),
389 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800390 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700391 },
392#endif
393#ifdef CONFIG_LOCK_STAT
394 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700395 .procname = "lock_stat",
396 .data = &lock_stat,
397 .maxlen = sizeof(int),
398 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800399 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700400 },
401#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200402 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 .procname = "panic",
404 .data = &panic_timeout,
405 .maxlen = sizeof(int),
406 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800407 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 },
409 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 .procname = "core_uses_pid",
411 .data = &core_uses_pid,
412 .maxlen = sizeof(int),
413 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800414 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 },
416 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 .procname = "core_pattern",
418 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700419 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800421 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 },
Neil Hormana2939802009-09-23 15:56:56 -0700423 {
Neil Hormana2939802009-09-23 15:56:56 -0700424 .procname = "core_pipe_limit",
425 .data = &core_pipe_limit,
426 .maxlen = sizeof(unsigned int),
427 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800428 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700429 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800430#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700433 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800434 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800435 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800437#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100438#ifdef CONFIG_LATENCYTOP
439 {
440 .procname = "latencytop",
441 .data = &latencytop_enabled,
442 .maxlen = sizeof(int),
443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800444 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100445 },
446#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#ifdef CONFIG_BLK_DEV_INITRD
448 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 .procname = "real-root-dev",
450 .data = &real_root_dev,
451 .maxlen = sizeof(int),
452 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800453 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 },
455#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700456 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700457 .procname = "print-fatal-signals",
458 .data = &print_fatal_signals,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800461 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700462 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700463#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .procname = "reboot-cmd",
466 .data = reboot_command,
467 .maxlen = 256,
468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800469 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 },
471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 .procname = "stop-a",
473 .data = &stop_a_enabled,
474 .maxlen = sizeof (int),
475 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800476 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 },
478 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 .procname = "scons-poweroff",
480 .data = &scons_pwroff,
481 .maxlen = sizeof (int),
482 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800483 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 },
485#endif
David S. Miller08714202008-11-16 23:49:24 -0800486#ifdef CONFIG_SPARC64
487 {
David S. Miller08714202008-11-16 23:49:24 -0800488 .procname = "tsb-ratio",
489 .data = &sysctl_tsb_ratio,
490 .maxlen = sizeof (int),
491 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800492 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800493 },
494#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495#ifdef __hppa__
496 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 .procname = "soft-power",
498 .data = &pwrsw_enabled,
499 .maxlen = sizeof (int),
500 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800501 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 },
503 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .procname = "unaligned-trap",
505 .data = &unaligned_enabled,
506 .maxlen = sizeof (int),
507 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800508 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 },
510#endif
511 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 .procname = "ctrl-alt-del",
513 .data = &C_A_D,
514 .maxlen = sizeof(int),
515 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800516 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400518#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200519 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200520 .procname = "ftrace_enabled",
521 .data = &ftrace_enabled,
522 .maxlen = sizeof(int),
523 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800524 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200525 },
526#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500527#ifdef CONFIG_STACK_TRACER
528 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500529 .procname = "stack_tracer_enabled",
530 .data = &stack_tracer_enabled,
531 .maxlen = sizeof(int),
532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800533 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500534 },
535#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400536#ifdef CONFIG_TRACING
537 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100538 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400539 .data = &ftrace_dump_on_oops,
540 .maxlen = sizeof(int),
541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800542 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400543 },
544#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200545#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 .procname = "modprobe",
548 .data = &modprobe_path,
549 .maxlen = KMOD_PATH_LEN,
550 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800551 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 },
Kees Cook3d433212009-04-02 15:49:29 -0700553 {
Kees Cook3d433212009-04-02 15:49:29 -0700554 .procname = "modules_disabled",
555 .data = &modules_disabled,
556 .maxlen = sizeof(int),
557 .mode = 0644,
558 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800559 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700560 .extra1 = &one,
561 .extra2 = &one,
562 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100564#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100567 .data = &uevent_helper,
568 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800570 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 },
572#endif
573#ifdef CONFIG_CHR_DEV_SG
574 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .procname = "sg-big-buff",
576 .data = &sg_big_buff,
577 .maxlen = sizeof (int),
578 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800579 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 },
581#endif
582#ifdef CONFIG_BSD_PROCESS_ACCT
583 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 .procname = "acct",
585 .data = &acct_parm,
586 .maxlen = 3*sizeof(int),
587 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800588 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 },
590#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#ifdef CONFIG_MAGIC_SYSRQ
592 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800594 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .maxlen = sizeof (int),
596 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700597 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 },
599#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700600#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700603 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .maxlen = sizeof (int),
605 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800606 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700608#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 .procname = "threads-max",
611 .data = &max_threads,
612 .maxlen = sizeof(int),
613 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800614 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 },
616 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 .procname = "random",
618 .mode = 0555,
619 .child = random_table,
620 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .procname = "overflowuid",
623 .data = &overflowuid,
624 .maxlen = sizeof(int),
625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800626 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 .extra1 = &minolduid,
628 .extra2 = &maxolduid,
629 },
630 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .procname = "overflowgid",
632 .data = &overflowgid,
633 .maxlen = sizeof(int),
634 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800635 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 .extra1 = &minolduid,
637 .extra2 = &maxolduid,
638 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800639#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640#ifdef CONFIG_MATHEMU
641 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 .procname = "ieee_emulation_warnings",
643 .data = &sysctl_ieee_emulation_warnings,
644 .maxlen = sizeof(int),
645 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800646 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 },
648#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200651 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 .maxlen = sizeof(int),
653 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800654 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 },
656#endif
657 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .procname = "pid_max",
659 .data = &pid_max,
660 .maxlen = sizeof (int),
661 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800662 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .extra1 = &pid_max_min,
664 .extra2 = &pid_max_max,
665 },
666 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 .procname = "panic_on_oops",
668 .data = &panic_on_oops,
669 .maxlen = sizeof(int),
670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800671 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800673#if defined CONFIG_PRINTK
674 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800675 .procname = "printk",
676 .data = &console_loglevel,
677 .maxlen = 4*sizeof(int),
678 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800679 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800680 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700683 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 .maxlen = sizeof(int),
685 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800686 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 },
688 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700690 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .maxlen = sizeof(int),
692 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800693 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 },
Dave Youngaf913222009-09-22 16:43:33 -0700695 {
Dave Youngaf913222009-09-22 16:43:33 -0700696 .procname = "printk_delay",
697 .data = &printk_delay_msec,
698 .maxlen = sizeof(int),
699 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700701 .extra1 = &zero,
702 .extra2 = &ten_thousand,
703 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800705 .procname = "dmesg_restrict",
706 .data = &dmesg_restrict,
707 .maxlen = sizeof(int),
708 .mode = 0644,
709 .proc_handler = proc_dointvec_minmax,
710 .extra1 = &zero,
711 .extra2 = &one,
712 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800713#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800714 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 .procname = "ngroups_max",
716 .data = &ngroups_max,
717 .maxlen = sizeof (int),
718 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800719 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 },
Don Zickus58687ac2010-05-07 17:11:44 -0400721#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500722 {
Don Zickus58687ac2010-05-07 17:11:44 -0400723 .procname = "watchdog",
724 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500725 .maxlen = sizeof (int),
726 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400727 .proc_handler = proc_dowatchdog_enabled,
728 },
729 {
730 .procname = "watchdog_thresh",
731 .data = &softlockup_thresh,
732 .maxlen = sizeof(int),
733 .mode = 0644,
734 .proc_handler = proc_dowatchdog_thresh,
735 .extra1 = &neg_one,
736 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500737 },
Don Zickus2508ce12010-05-07 17:11:46 -0400738 {
739 .procname = "softlockup_panic",
740 .data = &softlockup_panic,
741 .maxlen = sizeof(int),
742 .mode = 0644,
743 .proc_handler = proc_dointvec_minmax,
744 .extra1 = &zero,
745 .extra2 = &one,
746 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500747#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400748#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .procname = "unknown_nmi_panic",
751 .data = &unknown_nmi_panic,
752 .maxlen = sizeof (int),
753 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800754 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 },
Don Zickus407984f2006-09-26 10:52:27 +0200756 {
Don Zickus407984f2006-09-26 10:52:27 +0200757 .procname = "nmi_watchdog",
758 .data = &nmi_watchdog_enabled,
759 .maxlen = sizeof (int),
760 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800761 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 },
763#endif
764#if defined(CONFIG_X86)
765 {
Don Zickus8da5add2006-09-26 10:52:27 +0200766 .procname = "panic_on_unrecovered_nmi",
767 .data = &panic_on_unrecovered_nmi,
768 .maxlen = sizeof(int),
769 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800770 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200771 },
772 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700773 .procname = "panic_on_io_nmi",
774 .data = &panic_on_io_nmi,
775 .maxlen = sizeof(int),
776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800777 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700778 },
779 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 .procname = "bootloader_type",
781 .data = &bootloader_type,
782 .maxlen = sizeof (int),
783 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800784 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100786 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700787 .procname = "bootloader_version",
788 .data = &bootloader_version,
789 .maxlen = sizeof (int),
790 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700792 },
793 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100794 .procname = "kstack_depth_to_print",
795 .data = &kstack_depth_to_print,
796 .maxlen = sizeof(int),
797 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100799 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100800 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100801 .procname = "io_delay_type",
802 .data = &io_delay_type,
803 .maxlen = sizeof(int),
804 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800805 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100806 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800808#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 .procname = "randomize_va_space",
811 .data = &randomize_va_space,
812 .maxlen = sizeof(int),
813 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800814 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800816#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800817#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700818 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700819 .procname = "spin_retry",
820 .data = &spin_retry,
821 .maxlen = sizeof (int),
822 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800823 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700824 },
825#endif
Len Brown673d5b42007-07-28 03:33:16 -0400826#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800827 {
Pavel Machekc255d842006-02-20 18:27:58 -0800828 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700829 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800830 .maxlen = sizeof (unsigned long),
831 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800832 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800833 },
834#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800835#ifdef CONFIG_IA64
836 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800837 .procname = "ignore-unaligned-usertrap",
838 .data = &no_unaligned_warning,
839 .maxlen = sizeof (int),
840 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800841 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800842 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800843 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800844 .procname = "unaligned-dump-stack",
845 .data = &unaligned_dump_stack,
846 .maxlen = sizeof (int),
847 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800848 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800849 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800850#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800851#ifdef CONFIG_DETECT_HUNG_TASK
852 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800853 .procname = "hung_task_panic",
854 .data = &sysctl_hung_task_panic,
855 .maxlen = sizeof(int),
856 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800857 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800858 .extra1 = &zero,
859 .extra2 = &one,
860 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100862 .procname = "hung_task_check_count",
863 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100864 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100865 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800866 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100867 },
868 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100869 .procname = "hung_task_timeout_secs",
870 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100871 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100872 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800873 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100874 },
875 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100876 .procname = "hung_task_warnings",
877 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100878 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100879 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800880 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100881 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700882#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200883#ifdef CONFIG_COMPAT
884 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200885 .procname = "compat-log",
886 .data = &compat_log,
887 .maxlen = sizeof (int),
888 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800889 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200890 },
891#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700892#ifdef CONFIG_RT_MUTEXES
893 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700894 .procname = "max_lock_depth",
895 .data = &max_lock_depth,
896 .maxlen = sizeof(int),
897 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800898 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700899 },
900#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700901 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700902 .procname = "poweroff_cmd",
903 .data = &poweroff_cmd,
904 .maxlen = POWEROFF_CMD_PATH_LEN,
905 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800906 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700907 },
David Howells0b77f5b2008-04-29 01:01:32 -0700908#ifdef CONFIG_KEYS
909 {
David Howells0b77f5b2008-04-29 01:01:32 -0700910 .procname = "keys",
911 .mode = 0555,
912 .child = key_sysctls,
913 },
914#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700915#ifdef CONFIG_RCU_TORTURE_TEST
916 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700917 .procname = "rcutorture_runnable",
918 .data = &rcutorture_runnable,
919 .maxlen = sizeof(int),
920 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800921 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700922 },
923#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200924#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200925 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200926 .procname = "perf_event_paranoid",
927 .data = &sysctl_perf_event_paranoid,
928 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200929 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800930 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200931 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200932 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200933 .procname = "perf_event_mlock_kb",
934 .data = &sysctl_perf_event_mlock,
935 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200936 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800937 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200938 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200939 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200940 .procname = "perf_event_max_sample_rate",
941 .data = &sysctl_perf_event_sample_rate,
942 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200943 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800944 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200945 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200946#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200947#ifdef CONFIG_KMEMCHECK
948 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200949 .procname = "kmemcheck",
950 .data = &kmemcheck_enabled,
951 .maxlen = sizeof(int),
952 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800953 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200954 },
955#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200956#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200957 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200958 .procname = "blk_iopoll",
959 .data = &blk_iopoll_enabled,
960 .maxlen = sizeof(int),
961 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800962 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200963 },
Jens Axboecb684b52009-09-15 21:53:11 +0200964#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700965/*
966 * NOTE: do not add new entries to this table unless you have read
967 * Documentation/sysctl/ctl_unnumbered.txt
968 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700969 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970};
971
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700972static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 .procname = "overcommit_memory",
975 .data = &sysctl_overcommit_memory,
976 .maxlen = sizeof(sysctl_overcommit_memory),
977 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800978 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 },
980 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700981 .procname = "panic_on_oom",
982 .data = &sysctl_panic_on_oom,
983 .maxlen = sizeof(sysctl_panic_on_oom),
984 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800985 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700986 },
987 {
David Rientjesfe071d72007-10-16 23:25:56 -0700988 .procname = "oom_kill_allocating_task",
989 .data = &sysctl_oom_kill_allocating_task,
990 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
991 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800992 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700993 },
994 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800995 .procname = "oom_dump_tasks",
996 .data = &sysctl_oom_dump_tasks,
997 .maxlen = sizeof(sysctl_oom_dump_tasks),
998 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800999 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001000 },
1001 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 .procname = "overcommit_ratio",
1003 .data = &sysctl_overcommit_ratio,
1004 .maxlen = sizeof(sysctl_overcommit_ratio),
1005 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001006 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 },
1008 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 .procname = "page-cluster",
1010 .data = &page_cluster,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001013 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 },
1015 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 .procname = "dirty_background_ratio",
1017 .data = &dirty_background_ratio,
1018 .maxlen = sizeof(dirty_background_ratio),
1019 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001020 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 .extra1 = &zero,
1022 .extra2 = &one_hundred,
1023 },
1024 {
David Rientjes2da02992009-01-06 14:39:31 -08001025 .procname = "dirty_background_bytes",
1026 .data = &dirty_background_bytes,
1027 .maxlen = sizeof(dirty_background_bytes),
1028 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001029 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001030 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001031 },
1032 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 .procname = "dirty_ratio",
1034 .data = &vm_dirty_ratio,
1035 .maxlen = sizeof(vm_dirty_ratio),
1036 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001037 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 .extra1 = &zero,
1039 .extra2 = &one_hundred,
1040 },
1041 {
David Rientjes2da02992009-01-06 14:39:31 -08001042 .procname = "dirty_bytes",
1043 .data = &vm_dirty_bytes,
1044 .maxlen = sizeof(vm_dirty_bytes),
1045 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001046 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001047 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001048 },
1049 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001051 .data = &dirty_writeback_interval,
1052 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001054 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 },
1056 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001058 .data = &dirty_expire_interval,
1059 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001061 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 },
1063 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 .procname = "nr_pdflush_threads",
1065 .data = &nr_pdflush_threads,
1066 .maxlen = sizeof nr_pdflush_threads,
1067 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001068 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 },
1070 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .procname = "swappiness",
1072 .data = &vm_swappiness,
1073 .maxlen = sizeof(vm_swappiness),
1074 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001075 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .extra1 = &zero,
1077 .extra2 = &one_hundred,
1078 },
1079#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001080 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001082 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 .maxlen = sizeof(unsigned long),
1084 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001085 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 .extra1 = (void *)&hugetlb_zero,
1087 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001088 },
1089#ifdef CONFIG_NUMA
1090 {
1091 .procname = "nr_hugepages_mempolicy",
1092 .data = NULL,
1093 .maxlen = sizeof(unsigned long),
1094 .mode = 0644,
1095 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1096 .extra1 = (void *)&hugetlb_zero,
1097 .extra2 = (void *)&hugetlb_infinity,
1098 },
1099#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 .procname = "hugetlb_shm_group",
1102 .data = &sysctl_hugetlb_shm_group,
1103 .maxlen = sizeof(gid_t),
1104 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001105 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 },
Mel Gorman396faf02007-07-17 04:03:13 -07001107 {
Mel Gorman396faf02007-07-17 04:03:13 -07001108 .procname = "hugepages_treat_as_movable",
1109 .data = &hugepages_treat_as_movable,
1110 .maxlen = sizeof(int),
1111 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001112 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001113 },
Adam Litke54f9f802007-10-16 01:26:20 -07001114 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001115 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001116 .data = NULL,
1117 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001118 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001119 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001120 .extra1 = (void *)&hugetlb_zero,
1121 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001122 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123#endif
1124 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 .procname = "lowmem_reserve_ratio",
1126 .data = &sysctl_lowmem_reserve_ratio,
1127 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1128 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001129 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 },
1131 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001132 .procname = "drop_caches",
1133 .data = &sysctl_drop_caches,
1134 .maxlen = sizeof(int),
1135 .mode = 0644,
1136 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001137 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001138#ifdef CONFIG_COMPACTION
1139 {
1140 .procname = "compact_memory",
1141 .data = &sysctl_compact_memory,
1142 .maxlen = sizeof(int),
1143 .mode = 0200,
1144 .proc_handler = sysctl_compaction_handler,
1145 },
Mel Gorman5e771902010-05-24 14:32:31 -07001146 {
1147 .procname = "extfrag_threshold",
1148 .data = &sysctl_extfrag_threshold,
1149 .maxlen = sizeof(int),
1150 .mode = 0644,
1151 .proc_handler = sysctl_extfrag_handler,
1152 .extra1 = &min_extfrag_threshold,
1153 .extra2 = &max_extfrag_threshold,
1154 },
1155
Mel Gorman76ab0f52010-05-24 14:32:28 -07001156#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001157 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 .procname = "min_free_kbytes",
1159 .data = &min_free_kbytes,
1160 .maxlen = sizeof(min_free_kbytes),
1161 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001162 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 .extra1 = &zero,
1164 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001165 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001166 .procname = "percpu_pagelist_fraction",
1167 .data = &percpu_pagelist_fraction,
1168 .maxlen = sizeof(percpu_pagelist_fraction),
1169 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001170 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001171 .extra1 = &min_percpu_pagelist_fract,
1172 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173#ifdef CONFIG_MMU
1174 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 .procname = "max_map_count",
1176 .data = &sysctl_max_map_count,
1177 .maxlen = sizeof(sysctl_max_map_count),
1178 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001179 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001180 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001182#else
1183 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001184 .procname = "nr_trim_pages",
1185 .data = &sysctl_nr_trim_pages,
1186 .maxlen = sizeof(sysctl_nr_trim_pages),
1187 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001188 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001189 .extra1 = &zero,
1190 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191#endif
1192 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 .procname = "laptop_mode",
1194 .data = &laptop_mode,
1195 .maxlen = sizeof(laptop_mode),
1196 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001197 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 },
1199 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 .procname = "block_dump",
1201 .data = &block_dump,
1202 .maxlen = sizeof(block_dump),
1203 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001204 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 .extra1 = &zero,
1206 },
1207 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 .procname = "vfs_cache_pressure",
1209 .data = &sysctl_vfs_cache_pressure,
1210 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1211 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001212 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 .extra1 = &zero,
1214 },
1215#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1216 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 .procname = "legacy_va_layout",
1218 .data = &sysctl_legacy_va_layout,
1219 .maxlen = sizeof(sysctl_legacy_va_layout),
1220 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001221 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 .extra1 = &zero,
1223 },
1224#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001225#ifdef CONFIG_NUMA
1226 {
Christoph Lameter17436602006-01-18 17:42:32 -08001227 .procname = "zone_reclaim_mode",
1228 .data = &zone_reclaim_mode,
1229 .maxlen = sizeof(zone_reclaim_mode),
1230 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001231 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001232 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001233 },
Christoph Lameter96146342006-07-03 00:24:13 -07001234 {
Christoph Lameter96146342006-07-03 00:24:13 -07001235 .procname = "min_unmapped_ratio",
1236 .data = &sysctl_min_unmapped_ratio,
1237 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1238 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001239 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001240 .extra1 = &zero,
1241 .extra2 = &one_hundred,
1242 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001243 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001244 .procname = "min_slab_ratio",
1245 .data = &sysctl_min_slab_ratio,
1246 .maxlen = sizeof(sysctl_min_slab_ratio),
1247 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001248 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001249 .extra1 = &zero,
1250 .extra2 = &one_hundred,
1251 },
Christoph Lameter17436602006-01-18 17:42:32 -08001252#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001253#ifdef CONFIG_SMP
1254 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001255 .procname = "stat_interval",
1256 .data = &sysctl_stat_interval,
1257 .maxlen = sizeof(sysctl_stat_interval),
1258 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001259 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001260 },
1261#endif
David Howells6e141542009-12-15 19:27:45 +00001262#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001263 {
Eric Parised032182007-06-28 15:55:21 -04001264 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001265 .data = &dac_mmap_min_addr,
1266 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001267 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001268 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001269 },
David Howells6e141542009-12-15 19:27:45 +00001270#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001271#ifdef CONFIG_NUMA
1272 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001273 .procname = "numa_zonelist_order",
1274 .data = &numa_zonelist_order,
1275 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1276 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001277 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001278 },
1279#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001280#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001281 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001282 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001283 .procname = "vdso_enabled",
1284 .data = &vdso_enabled,
1285 .maxlen = sizeof(vdso_enabled),
1286 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001287 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001288 .extra1 = &zero,
1289 },
1290#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001291#ifdef CONFIG_HIGHMEM
1292 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001293 .procname = "highmem_is_dirtyable",
1294 .data = &vm_highmem_is_dirtyable,
1295 .maxlen = sizeof(vm_highmem_is_dirtyable),
1296 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001297 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001298 .extra1 = &zero,
1299 .extra2 = &one,
1300 },
1301#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001302 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001303 .procname = "scan_unevictable_pages",
1304 .data = &scan_unevictable_pages,
1305 .maxlen = sizeof(scan_unevictable_pages),
1306 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001307 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001308 },
Andi Kleen6a460792009-09-16 11:50:15 +02001309#ifdef CONFIG_MEMORY_FAILURE
1310 {
Andi Kleen6a460792009-09-16 11:50:15 +02001311 .procname = "memory_failure_early_kill",
1312 .data = &sysctl_memory_failure_early_kill,
1313 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1314 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001315 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001316 .extra1 = &zero,
1317 .extra2 = &one,
1318 },
1319 {
Andi Kleen6a460792009-09-16 11:50:15 +02001320 .procname = "memory_failure_recovery",
1321 .data = &sysctl_memory_failure_recovery,
1322 .maxlen = sizeof(sysctl_memory_failure_recovery),
1323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001324 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001325 .extra1 = &zero,
1326 .extra2 = &one,
1327 },
1328#endif
1329
Andrew Morton2be7fe02007-07-15 23:41:21 -07001330/*
1331 * NOTE: do not add new entries to this table unless you have read
1332 * Documentation/sysctl/ctl_unnumbered.txt
1333 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001334 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335};
1336
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001337#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001338static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001339 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001340};
1341#endif
1342
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001343static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 .procname = "inode-nr",
1346 .data = &inodes_stat,
1347 .maxlen = 2*sizeof(int),
1348 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001349 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 },
1351 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 .procname = "inode-state",
1353 .data = &inodes_stat,
1354 .maxlen = 7*sizeof(int),
1355 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001356 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 },
1358 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 .procname = "file-nr",
1360 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001361 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001363 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 },
1365 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 .procname = "file-max",
1367 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001368 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001370 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 },
1372 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001373 .procname = "nr_open",
1374 .data = &sysctl_nr_open,
1375 .maxlen = sizeof(int),
1376 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001377 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001378 .extra1 = &sysctl_nr_open_min,
1379 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001380 },
1381 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 .procname = "dentry-state",
1383 .data = &dentry_stat,
1384 .maxlen = 6*sizeof(int),
1385 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001386 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 },
1388 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 .procname = "overflowuid",
1390 .data = &fs_overflowuid,
1391 .maxlen = sizeof(int),
1392 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001393 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .extra1 = &minolduid,
1395 .extra2 = &maxolduid,
1396 },
1397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .procname = "overflowgid",
1399 .data = &fs_overflowgid,
1400 .maxlen = sizeof(int),
1401 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001402 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .extra1 = &minolduid,
1404 .extra2 = &maxolduid,
1405 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001406#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 .procname = "leases-enable",
1409 .data = &leases_enable,
1410 .maxlen = sizeof(int),
1411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001412 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001414#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415#ifdef CONFIG_DNOTIFY
1416 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 .procname = "dir-notify-enable",
1418 .data = &dir_notify_enable,
1419 .maxlen = sizeof(int),
1420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 },
1423#endif
1424#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001425#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 .procname = "lease-break-time",
1428 .data = &lease_break_time,
1429 .maxlen = sizeof(int),
1430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001431 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001433#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001434#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 .procname = "aio-nr",
1437 .data = &aio_nr,
1438 .maxlen = sizeof(aio_nr),
1439 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001440 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 },
1442 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 .procname = "aio-max-nr",
1444 .data = &aio_max_nr,
1445 .maxlen = sizeof(aio_max_nr),
1446 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001447 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001449#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001450#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001451 {
Robert Love0399cb02005-07-13 12:38:18 -04001452 .procname = "inotify",
1453 .mode = 0555,
1454 .child = inotify_table,
1455 },
1456#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001457#ifdef CONFIG_EPOLL
1458 {
1459 .procname = "epoll",
1460 .mode = 0555,
1461 .child = epoll_table,
1462 },
1463#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001465 {
Alan Coxd6e71142005-06-23 00:09:43 -07001466 .procname = "suid_dumpable",
1467 .data = &suid_dumpable,
1468 .maxlen = sizeof(int),
1469 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001470 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001471 .extra1 = &zero,
1472 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001473 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001474#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1475 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001476 .procname = "binfmt_misc",
1477 .mode = 0555,
1478 .child = binfmt_misc_table,
1479 },
1480#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001481 {
Jens Axboeff9da692010-06-03 14:54:39 +02001482 .procname = "pipe-max-size",
1483 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001484 .maxlen = sizeof(int),
1485 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001486 .proc_handler = &pipe_proc_fn,
1487 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001488 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001489/*
1490 * NOTE: do not add new entries to this table unless you have read
1491 * Documentation/sysctl/ctl_unnumbered.txt
1492 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001493 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494};
1495
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001496static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001497#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1498 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001499 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001500 .procname = "exception-trace",
1501 .data = &show_unhandled_signals,
1502 .maxlen = sizeof(int),
1503 .mode = 0644,
1504 .proc_handler = proc_dointvec
1505 },
1506#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001507#if defined(CONFIG_OPTPROBES)
1508 {
1509 .procname = "kprobes-optimization",
1510 .data = &sysctl_kprobes_optimization,
1511 .maxlen = sizeof(int),
1512 .mode = 0644,
1513 .proc_handler = proc_kprobes_optimization_handler,
1514 .extra1 = &zero,
1515 .extra2 = &one,
1516 },
1517#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001518 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519};
1520
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001521static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001522 { }
Robert Love0eeca282005-07-12 17:06:03 -04001523};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
Al Viro330d57f2005-11-04 10:18:40 +00001525static DEFINE_SPINLOCK(sysctl_lock);
1526
1527/* called under sysctl_lock */
1528static int use_table(struct ctl_table_header *p)
1529{
1530 if (unlikely(p->unregistering))
1531 return 0;
1532 p->used++;
1533 return 1;
1534}
1535
1536/* called under sysctl_lock */
1537static void unuse_table(struct ctl_table_header *p)
1538{
1539 if (!--p->used)
1540 if (unlikely(p->unregistering))
1541 complete(p->unregistering);
1542}
1543
1544/* called under sysctl_lock, will reacquire if has to wait */
1545static void start_unregistering(struct ctl_table_header *p)
1546{
1547 /*
1548 * if p->used is 0, nobody will ever touch that entry again;
1549 * we'll eliminate all paths to it before dropping sysctl_lock
1550 */
1551 if (unlikely(p->used)) {
1552 struct completion wait;
1553 init_completion(&wait);
1554 p->unregistering = &wait;
1555 spin_unlock(&sysctl_lock);
1556 wait_for_completion(&wait);
1557 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001558 } else {
1559 /* anything non-NULL; we'll never dereference it */
1560 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001561 }
1562 /*
1563 * do not remove from the list until nobody holds it; walking the
1564 * list in do_sysctl() relies on that.
1565 */
1566 list_del_init(&p->ctl_entry);
1567}
1568
Al Virof7e6ced2008-07-15 01:44:23 -04001569void sysctl_head_get(struct ctl_table_header *head)
1570{
1571 spin_lock(&sysctl_lock);
1572 head->count++;
1573 spin_unlock(&sysctl_lock);
1574}
1575
1576void sysctl_head_put(struct ctl_table_header *head)
1577{
1578 spin_lock(&sysctl_lock);
1579 if (!--head->count)
1580 kfree(head);
1581 spin_unlock(&sysctl_lock);
1582}
1583
1584struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1585{
1586 if (!head)
1587 BUG();
1588 spin_lock(&sysctl_lock);
1589 if (!use_table(head))
1590 head = ERR_PTR(-ENOENT);
1591 spin_unlock(&sysctl_lock);
1592 return head;
1593}
1594
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001595void sysctl_head_finish(struct ctl_table_header *head)
1596{
1597 if (!head)
1598 return;
1599 spin_lock(&sysctl_lock);
1600 unuse_table(head);
1601 spin_unlock(&sysctl_lock);
1602}
1603
Al Viro73455092008-07-14 21:22:20 -04001604static struct ctl_table_set *
1605lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1606{
1607 struct ctl_table_set *set = &root->default_set;
1608 if (root->lookup)
1609 set = root->lookup(root, namespaces);
1610 return set;
1611}
1612
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001613static struct list_head *
1614lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001615{
Al Viro73455092008-07-14 21:22:20 -04001616 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1617 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001618}
1619
1620struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1621 struct ctl_table_header *prev)
1622{
1623 struct ctl_table_root *root;
1624 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001625 struct ctl_table_header *head;
1626 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001627
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001628 spin_lock(&sysctl_lock);
1629 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001630 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001631 tmp = &prev->ctl_entry;
1632 unuse_table(prev);
1633 goto next;
1634 }
1635 tmp = &root_table_header.ctl_entry;
1636 for (;;) {
1637 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1638
1639 if (!use_table(head))
1640 goto next;
1641 spin_unlock(&sysctl_lock);
1642 return head;
1643 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001644 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001645 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001646 header_list = lookup_header_list(root, namespaces);
1647 if (tmp != header_list)
1648 continue;
1649
1650 do {
1651 root = list_entry(root->root_list.next,
1652 struct ctl_table_root, root_list);
1653 if (root == &sysctl_table_root)
1654 goto out;
1655 header_list = lookup_header_list(root, namespaces);
1656 } while (list_empty(header_list));
1657 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001658 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001659out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001660 spin_unlock(&sysctl_lock);
1661 return NULL;
1662}
1663
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001664struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1665{
1666 return __sysctl_head_next(current->nsproxy, prev);
1667}
1668
1669void register_sysctl_root(struct ctl_table_root *root)
1670{
1671 spin_lock(&sysctl_lock);
1672 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1673 spin_unlock(&sysctl_lock);
1674}
1675
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001677 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 * some sysctl variables are readonly even to root.
1679 */
1680
1681static int test_perm(int mode, int op)
1682{
David Howells76aac0e2008-11-14 10:39:12 +11001683 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 mode >>= 6;
1685 else if (in_egroup_p(0))
1686 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001687 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 return 0;
1689 return -EACCES;
1690}
1691
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001692int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693{
1694 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001695 int mode;
1696
Al Viroe6305c42008-07-15 21:03:57 -04001697 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 if (error)
1699 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001700
1701 if (root->permissions)
1702 mode = root->permissions(root, current->nsproxy, table);
1703 else
1704 mode = table->mode;
1705
1706 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707}
1708
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001709static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1710{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001711 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001712 table->parent = parent;
1713 if (table->child)
1714 sysctl_set_parent(table, table->child);
1715 }
1716}
1717
1718static __init int sysctl_init(void)
1719{
1720 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001721#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001722 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001723#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001724 return 0;
1725}
1726
1727core_initcall(sysctl_init);
1728
Al Virobfbcf032008-07-27 06:31:22 +01001729static struct ctl_table *is_branch_in(struct ctl_table *branch,
1730 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001731{
1732 struct ctl_table *p;
1733 const char *s = branch->procname;
1734
1735 /* branch should have named subdirectory as its first element */
1736 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001737 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001738
1739 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001740 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001741 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001742
1743 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001744 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001745 if (!p->child)
1746 continue;
1747 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001748 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001749 }
Al Virobfbcf032008-07-27 06:31:22 +01001750 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001751}
1752
1753/* see if attaching q to p would be an improvement */
1754static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1755{
1756 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001757 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001758 int is_better = 0;
1759 int not_in_parent = !p->attached_by;
1760
Al Virobfbcf032008-07-27 06:31:22 +01001761 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001762 if (by == q->attached_by)
1763 is_better = 1;
1764 if (to == p->attached_by)
1765 not_in_parent = 1;
1766 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001767 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001768 }
1769
1770 if (is_better && not_in_parent) {
1771 q->attached_by = by;
1772 q->attached_to = to;
1773 q->parent = p;
1774 }
1775}
1776
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001778 * __register_sysctl_paths - register a sysctl hierarchy
1779 * @root: List of sysctl headers to register on
1780 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001781 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 *
1784 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001785 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001787 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1790 * enter a sysctl file
1791 *
1792 * data - a pointer to data for use by proc_handler
1793 *
1794 * maxlen - the maximum size in bytes of the data
1795 *
1796 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1797 *
1798 * child - a pointer to the child sysctl table if this entry is a directory, or
1799 * %NULL.
1800 *
1801 * proc_handler - the text handler routine (described below)
1802 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 * de - for internal use by the sysctl routines
1804 *
1805 * extra1, extra2 - extra pointers usable by the proc handler routines
1806 *
1807 * Leaf nodes in the sysctl tree will be represented by a single file
1808 * under /proc; non-leaf nodes will be represented by directories.
1809 *
1810 * sysctl(2) can automatically manage read and write requests through
1811 * the sysctl table. The data and maxlen fields of the ctl_table
1812 * struct enable minimal validation of the values being written to be
1813 * performed, and the mode field allows minimal authentication.
1814 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 * There must be a proc_handler routine for any terminal nodes
1816 * mirrored under /proc/sys (non-terminals are handled by a built-in
1817 * directory handler). Several default handlers are available to
1818 * cover common cases -
1819 *
1820 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1821 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1822 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1823 *
1824 * It is the handler's job to read the input buffer from user memory
1825 * and process it. The handler should return 0 on success.
1826 *
1827 * This routine returns %NULL on a failure to register, and a pointer
1828 * to the table header on success.
1829 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001830struct ctl_table_header *__register_sysctl_paths(
1831 struct ctl_table_root *root,
1832 struct nsproxy *namespaces,
1833 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001835 struct ctl_table_header *header;
1836 struct ctl_table *new, **prevp;
1837 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001838 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001839
1840 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001841 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001842 ;
1843
1844 /*
1845 * For each path component, allocate a 2-element ctl_table array.
1846 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001847 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001848 *
1849 * We allocate everything in one go so that we don't have to
1850 * worry about freeing additional memory in unregister_sysctl_table.
1851 */
1852 header = kzalloc(sizeof(struct ctl_table_header) +
1853 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1854 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001856
1857 new = (struct ctl_table *) (header + 1);
1858
1859 /* Now connect the dots */
1860 prevp = &header->ctl_table;
1861 for (n = 0; n < npath; ++n, ++path) {
1862 /* Copy the procname */
1863 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001864 new->mode = 0555;
1865
1866 *prevp = new;
1867 prevp = &new->child;
1868
1869 new += 2;
1870 }
1871 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001872 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001873
1874 INIT_LIST_HEAD(&header->ctl_entry);
1875 header->used = 0;
1876 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001877 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001878 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001879 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001880#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001881 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001882 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001883 return NULL;
1884 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001885#endif
Al Viro330d57f2005-11-04 10:18:40 +00001886 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001887 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001888 header->attached_by = header->ctl_table;
1889 header->attached_to = root_table;
1890 header->parent = &root_table_header;
1891 for (set = header->set; set; set = set->parent) {
1892 struct ctl_table_header *p;
1893 list_for_each_entry(p, &set->list, ctl_entry) {
1894 if (p->unregistering)
1895 continue;
1896 try_attach(p, header);
1897 }
1898 }
1899 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001900 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001901 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001902
1903 return header;
1904}
1905
1906/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001907 * register_sysctl_table_path - register a sysctl table hierarchy
1908 * @path: The path to the directory the sysctl table is in.
1909 * @table: the top-level table structure
1910 *
1911 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1912 * array. A completely 0 filled entry terminates the table.
1913 *
1914 * See __register_sysctl_paths for more details.
1915 */
1916struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1917 struct ctl_table *table)
1918{
1919 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1920 path, table);
1921}
1922
1923/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001924 * register_sysctl_table - register a sysctl table hierarchy
1925 * @table: the top-level table structure
1926 *
1927 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1928 * array. A completely 0 filled entry terminates the table.
1929 *
1930 * See register_sysctl_paths for more details.
1931 */
1932struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1933{
1934 static const struct ctl_path null_path[] = { {} };
1935
1936 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937}
1938
1939/**
1940 * unregister_sysctl_table - unregister a sysctl table hierarchy
1941 * @header: the header returned from register_sysctl_table
1942 *
1943 * Unregisters the sysctl table and all children. proc entries may not
1944 * actually be removed until they are no longer used by anyone.
1945 */
1946void unregister_sysctl_table(struct ctl_table_header * header)
1947{
Al Viro330d57f2005-11-04 10:18:40 +00001948 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001949
1950 if (header == NULL)
1951 return;
1952
Al Viro330d57f2005-11-04 10:18:40 +00001953 spin_lock(&sysctl_lock);
1954 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001955 if (!--header->parent->count) {
1956 WARN_ON(1);
1957 kfree(header->parent);
1958 }
Al Virof7e6ced2008-07-15 01:44:23 -04001959 if (!--header->count)
1960 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001961 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962}
1963
Al Viro90434762008-07-15 08:54:06 -04001964int sysctl_is_seen(struct ctl_table_header *p)
1965{
1966 struct ctl_table_set *set = p->set;
1967 int res;
1968 spin_lock(&sysctl_lock);
1969 if (p->unregistering)
1970 res = 0;
1971 else if (!set->is_seen)
1972 res = 1;
1973 else
1974 res = set->is_seen(set);
1975 spin_unlock(&sysctl_lock);
1976 return res;
1977}
1978
Al Viro73455092008-07-14 21:22:20 -04001979void setup_sysctl_set(struct ctl_table_set *p,
1980 struct ctl_table_set *parent,
1981 int (*is_seen)(struct ctl_table_set *))
1982{
1983 INIT_LIST_HEAD(&p->list);
1984 p->parent = parent ? parent : &sysctl_table_root.default_set;
1985 p->is_seen = is_seen;
1986}
1987
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001988#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001989struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001990{
1991 return NULL;
1992}
1993
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001994struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1995 struct ctl_table *table)
1996{
1997 return NULL;
1998}
1999
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002000void unregister_sysctl_table(struct ctl_table_header * table)
2001{
2002}
2003
Al Viro73455092008-07-14 21:22:20 -04002004void setup_sysctl_set(struct ctl_table_set *p,
2005 struct ctl_table_set *parent,
2006 int (*is_seen)(struct ctl_table_set *))
2007{
2008}
2009
Al Virof7e6ced2008-07-15 01:44:23 -04002010void sysctl_head_put(struct ctl_table_header *head)
2011{
2012}
2013
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002014#endif /* CONFIG_SYSCTL */
2015
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016/*
2017 * /proc/sys support
2018 */
2019
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002020#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002022static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002023 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002024 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002025{
2026 size_t len;
2027 char __user *p;
2028 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002029
2030 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002031 *lenp = 0;
2032 return 0;
2033 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002034
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002035 if (write) {
2036 len = 0;
2037 p = buffer;
2038 while (len < *lenp) {
2039 if (get_user(c, p++))
2040 return -EFAULT;
2041 if (c == 0 || c == '\n')
2042 break;
2043 len++;
2044 }
2045 if (len >= maxlen)
2046 len = maxlen-1;
2047 if(copy_from_user(data, buffer, len))
2048 return -EFAULT;
2049 ((char *) data)[len] = 0;
2050 *ppos += *lenp;
2051 } else {
2052 len = strlen(data);
2053 if (len > maxlen)
2054 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002055
2056 if (*ppos > len) {
2057 *lenp = 0;
2058 return 0;
2059 }
2060
2061 data += *ppos;
2062 len -= *ppos;
2063
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002064 if (len > *lenp)
2065 len = *lenp;
2066 if (len)
2067 if(copy_to_user(buffer, data, len))
2068 return -EFAULT;
2069 if (len < *lenp) {
2070 if(put_user('\n', ((char __user *) buffer) + len))
2071 return -EFAULT;
2072 len++;
2073 }
2074 *lenp = len;
2075 *ppos += len;
2076 }
2077 return 0;
2078}
2079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080/**
2081 * proc_dostring - read a string sysctl
2082 * @table: the sysctl table
2083 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 * @buffer: the user buffer
2085 * @lenp: the size of the user buffer
2086 * @ppos: file position
2087 *
2088 * Reads/writes a string from/to the user buffer. If the kernel
2089 * buffer provided is not large enough to hold the string, the
2090 * string is truncated. The copied string is %NULL-terminated.
2091 * If the string is being read by the user process, it is copied
2092 * and a newline '\n' is added. It is truncated if the buffer is
2093 * not large enough.
2094 *
2095 * Returns 0 on success.
2096 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002097int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 void __user *buffer, size_t *lenp, loff_t *ppos)
2099{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002100 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002101 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102}
2103
Amerigo Wang00b7c332010-05-05 00:26:45 +00002104static size_t proc_skip_spaces(char **buf)
2105{
2106 size_t ret;
2107 char *tmp = skip_spaces(*buf);
2108 ret = tmp - *buf;
2109 *buf = tmp;
2110 return ret;
2111}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002113static void proc_skip_char(char **buf, size_t *size, const char v)
2114{
2115 while (*size) {
2116 if (**buf != v)
2117 break;
2118 (*size)--;
2119 (*buf)++;
2120 }
2121}
2122
Amerigo Wang00b7c332010-05-05 00:26:45 +00002123#define TMPBUFLEN 22
2124/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002125 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002126 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002127 * @buf: a kernel buffer
2128 * @size: size of the kernel buffer
2129 * @val: this is where the number will be stored
2130 * @neg: set to %TRUE if number is negative
2131 * @perm_tr: a vector which contains the allowed trailers
2132 * @perm_tr_len: size of the perm_tr vector
2133 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002134 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002135 * In case of success %0 is returned and @buf and @size are updated with
2136 * the amount of bytes read. If @tr is non-NULL and a trailing
2137 * character exists (size is non-zero after returning from this
2138 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002139 */
2140static int proc_get_long(char **buf, size_t *size,
2141 unsigned long *val, bool *neg,
2142 const char *perm_tr, unsigned perm_tr_len, char *tr)
2143{
2144 int len;
2145 char *p, tmp[TMPBUFLEN];
2146
2147 if (!*size)
2148 return -EINVAL;
2149
2150 len = *size;
2151 if (len > TMPBUFLEN - 1)
2152 len = TMPBUFLEN - 1;
2153
2154 memcpy(tmp, *buf, len);
2155
2156 tmp[len] = 0;
2157 p = tmp;
2158 if (*p == '-' && *size > 1) {
2159 *neg = true;
2160 p++;
2161 } else
2162 *neg = false;
2163 if (!isdigit(*p))
2164 return -EINVAL;
2165
2166 *val = simple_strtoul(p, &p, 0);
2167
2168 len = p - tmp;
2169
2170 /* We don't know if the next char is whitespace thus we may accept
2171 * invalid integers (e.g. 1234...a) or two integers instead of one
2172 * (e.g. 123...1). So lets not allow such large numbers. */
2173 if (len == TMPBUFLEN - 1)
2174 return -EINVAL;
2175
2176 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2177 return -EINVAL;
2178
2179 if (tr && (len < *size))
2180 *tr = *p;
2181
2182 *buf += len;
2183 *size -= len;
2184
2185 return 0;
2186}
2187
2188/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002189 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002190 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002191 * @buf: the user buffer
2192 * @size: the size of the user buffer
2193 * @val: the integer to be converted
2194 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002195 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002196 * In case of success %0 is returned and @buf and @size are updated with
2197 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002198 */
2199static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2200 bool neg)
2201{
2202 int len;
2203 char tmp[TMPBUFLEN], *p = tmp;
2204
2205 sprintf(p, "%s%lu", neg ? "-" : "", val);
2206 len = strlen(tmp);
2207 if (len > *size)
2208 len = *size;
2209 if (copy_to_user(*buf, tmp, len))
2210 return -EFAULT;
2211 *size -= len;
2212 *buf += len;
2213 return 0;
2214}
2215#undef TMPBUFLEN
2216
2217static int proc_put_char(void __user **buf, size_t *size, char c)
2218{
2219 if (*size) {
2220 char __user **buffer = (char __user **)buf;
2221 if (put_user(c, *buffer))
2222 return -EFAULT;
2223 (*size)--, (*buffer)++;
2224 *buf = *buffer;
2225 }
2226 return 0;
2227}
2228
2229static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 int *valp,
2231 int write, void *data)
2232{
2233 if (write) {
2234 *valp = *negp ? -*lvalp : *lvalp;
2235 } else {
2236 int val = *valp;
2237 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002238 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 *lvalp = (unsigned long)-val;
2240 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002241 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 *lvalp = (unsigned long)val;
2243 }
2244 }
2245 return 0;
2246}
2247
Amerigo Wang00b7c332010-05-05 00:26:45 +00002248static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2249
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002250static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002251 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002252 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002253 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 int write, void *data),
2255 void *data)
2256{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002257 int *i, vleft, first = 1, err = 0;
2258 unsigned long page = 0;
2259 size_t left;
2260 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Amerigo Wang00b7c332010-05-05 00:26:45 +00002262 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 *lenp = 0;
2264 return 0;
2265 }
2266
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002267 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 vleft = table->maxlen / sizeof(*i);
2269 left = *lenp;
2270
2271 if (!conv)
2272 conv = do_proc_dointvec_conv;
2273
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002275 if (left > PAGE_SIZE - 1)
2276 left = PAGE_SIZE - 1;
2277 page = __get_free_page(GFP_TEMPORARY);
2278 kbuf = (char *) page;
2279 if (!kbuf)
2280 return -ENOMEM;
2281 if (copy_from_user(kbuf, buffer, left)) {
2282 err = -EFAULT;
2283 goto free;
2284 }
2285 kbuf[left] = 0;
2286 }
2287
2288 for (; left && vleft--; i++, first=0) {
2289 unsigned long lval;
2290 bool neg;
2291
2292 if (write) {
2293 left -= proc_skip_spaces(&kbuf);
2294
J. R. Okajima563b0462010-05-25 16:10:14 -07002295 if (!left)
2296 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002297 err = proc_get_long(&kbuf, &left, &lval, &neg,
2298 proc_wspace_sep,
2299 sizeof(proc_wspace_sep), NULL);
2300 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002302 if (conv(&neg, &lval, i, 1, data)) {
2303 err = -EINVAL;
2304 break;
2305 }
2306 } else {
2307 if (conv(&neg, &lval, i, 0, data)) {
2308 err = -EINVAL;
2309 break;
2310 }
2311 if (!first)
2312 err = proc_put_char(&buffer, &left, '\t');
2313 if (err)
2314 break;
2315 err = proc_put_long(&buffer, &left, lval, neg);
2316 if (err)
2317 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 }
2319 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002320
2321 if (!write && !first && left && !err)
2322 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002323 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002324 left -= proc_skip_spaces(&kbuf);
2325free:
2326 if (write) {
2327 free_page(page);
2328 if (first)
2329 return err ? : -EINVAL;
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 *lenp -= left;
2332 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002333 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334}
2335
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002336static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002337 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002338 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002339 int write, void *data),
2340 void *data)
2341{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002342 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002343 buffer, lenp, ppos, conv, data);
2344}
2345
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346/**
2347 * proc_dointvec - read a vector of integers
2348 * @table: the sysctl table
2349 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 * @buffer: the user buffer
2351 * @lenp: the size of the user buffer
2352 * @ppos: file position
2353 *
2354 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2355 * values from/to the user buffer, treated as an ASCII string.
2356 *
2357 * Returns 0 on success.
2358 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002359int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 void __user *buffer, size_t *lenp, loff_t *ppos)
2361{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002362 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 NULL,NULL);
2364}
2365
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002366/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002367 * Taint values can only be increased
2368 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002369 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002370static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002371 void __user *buffer, size_t *lenp, loff_t *ppos)
2372{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002373 struct ctl_table t;
2374 unsigned long tmptaint = get_taint();
2375 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002376
Bastian Blank91fcd412007-04-23 14:41:14 -07002377 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002378 return -EPERM;
2379
Andi Kleen25ddbb12008-10-15 22:01:41 -07002380 t = *table;
2381 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002382 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002383 if (err < 0)
2384 return err;
2385
2386 if (write) {
2387 /*
2388 * Poor man's atomic or. Not worth adding a primitive
2389 * to everyone's atomic.h for this
2390 */
2391 int i;
2392 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2393 if ((tmptaint >> i) & 1)
2394 add_taint(i);
2395 }
2396 }
2397
2398 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002399}
2400
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401struct do_proc_dointvec_minmax_conv_param {
2402 int *min;
2403 int *max;
2404};
2405
Amerigo Wang00b7c332010-05-05 00:26:45 +00002406static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2407 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 int write, void *data)
2409{
2410 struct do_proc_dointvec_minmax_conv_param *param = data;
2411 if (write) {
2412 int val = *negp ? -*lvalp : *lvalp;
2413 if ((param->min && *param->min > val) ||
2414 (param->max && *param->max < val))
2415 return -EINVAL;
2416 *valp = val;
2417 } else {
2418 int val = *valp;
2419 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002420 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 *lvalp = (unsigned long)-val;
2422 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002423 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 *lvalp = (unsigned long)val;
2425 }
2426 }
2427 return 0;
2428}
2429
2430/**
2431 * proc_dointvec_minmax - read a vector of integers with min/max values
2432 * @table: the sysctl table
2433 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 * @buffer: the user buffer
2435 * @lenp: the size of the user buffer
2436 * @ppos: file position
2437 *
2438 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2439 * values from/to the user buffer, treated as an ASCII string.
2440 *
2441 * This routine will ensure the values are within the range specified by
2442 * table->extra1 (min) and table->extra2 (max).
2443 *
2444 * Returns 0 on success.
2445 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002446int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 void __user *buffer, size_t *lenp, loff_t *ppos)
2448{
2449 struct do_proc_dointvec_minmax_conv_param param = {
2450 .min = (int *) table->extra1,
2451 .max = (int *) table->extra2,
2452 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002453 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 do_proc_dointvec_minmax_conv, &param);
2455}
2456
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002457static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 void __user *buffer,
2459 size_t *lenp, loff_t *ppos,
2460 unsigned long convmul,
2461 unsigned long convdiv)
2462{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002463 unsigned long *i, *min, *max;
2464 int vleft, first = 1, err = 0;
2465 unsigned long page = 0;
2466 size_t left;
2467 char *kbuf;
2468
2469 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 *lenp = 0;
2471 return 0;
2472 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002473
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002474 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 min = (unsigned long *) table->extra1;
2476 max = (unsigned long *) table->extra2;
2477 vleft = table->maxlen / sizeof(unsigned long);
2478 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002479
2480 if (write) {
2481 if (left > PAGE_SIZE - 1)
2482 left = PAGE_SIZE - 1;
2483 page = __get_free_page(GFP_TEMPORARY);
2484 kbuf = (char *) page;
2485 if (!kbuf)
2486 return -ENOMEM;
2487 if (copy_from_user(kbuf, buffer, left)) {
2488 err = -EFAULT;
2489 goto free;
2490 }
2491 kbuf[left] = 0;
2492 }
2493
Eric Dumazet27b3d802010-10-07 12:59:29 -07002494 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002495 unsigned long val;
2496
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002498 bool neg;
2499
2500 left -= proc_skip_spaces(&kbuf);
2501
2502 err = proc_get_long(&kbuf, &left, &val, &neg,
2503 proc_wspace_sep,
2504 sizeof(proc_wspace_sep), NULL);
2505 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 break;
2507 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 continue;
2509 if ((min && val < *min) || (max && val > *max))
2510 continue;
2511 *i = val;
2512 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002513 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002515 err = proc_put_char(&buffer, &left, '\t');
2516 err = proc_put_long(&buffer, &left, val, false);
2517 if (err)
2518 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 }
2520 }
2521
Amerigo Wang00b7c332010-05-05 00:26:45 +00002522 if (!write && !first && left && !err)
2523 err = proc_put_char(&buffer, &left, '\n');
2524 if (write && !err)
2525 left -= proc_skip_spaces(&kbuf);
2526free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002528 free_page(page);
2529 if (first)
2530 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 *lenp -= left;
2533 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002534 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002537static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002538 void __user *buffer,
2539 size_t *lenp, loff_t *ppos,
2540 unsigned long convmul,
2541 unsigned long convdiv)
2542{
2543 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002544 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002545}
2546
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547/**
2548 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2549 * @table: the sysctl table
2550 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 * @buffer: the user buffer
2552 * @lenp: the size of the user buffer
2553 * @ppos: file position
2554 *
2555 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2556 * values from/to the user buffer, treated as an ASCII string.
2557 *
2558 * This routine will ensure the values are within the range specified by
2559 * table->extra1 (min) and table->extra2 (max).
2560 *
2561 * Returns 0 on success.
2562 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002563int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 void __user *buffer, size_t *lenp, loff_t *ppos)
2565{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002566 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567}
2568
2569/**
2570 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2571 * @table: the sysctl table
2572 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 * @buffer: the user buffer
2574 * @lenp: the size of the user buffer
2575 * @ppos: file position
2576 *
2577 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2578 * values from/to the user buffer, treated as an ASCII string. The values
2579 * are treated as milliseconds, and converted to jiffies when they are stored.
2580 *
2581 * This routine will ensure the values are within the range specified by
2582 * table->extra1 (min) and table->extra2 (max).
2583 *
2584 * Returns 0 on success.
2585 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002586int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 void __user *buffer,
2588 size_t *lenp, loff_t *ppos)
2589{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002590 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 lenp, ppos, HZ, 1000l);
2592}
2593
2594
Amerigo Wang00b7c332010-05-05 00:26:45 +00002595static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 int *valp,
2597 int write, void *data)
2598{
2599 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002600 if (*lvalp > LONG_MAX / HZ)
2601 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2603 } else {
2604 int val = *valp;
2605 unsigned long lval;
2606 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002607 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 lval = (unsigned long)-val;
2609 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002610 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 lval = (unsigned long)val;
2612 }
2613 *lvalp = lval / HZ;
2614 }
2615 return 0;
2616}
2617
Amerigo Wang00b7c332010-05-05 00:26:45 +00002618static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 int *valp,
2620 int write, void *data)
2621{
2622 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002623 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2624 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2626 } else {
2627 int val = *valp;
2628 unsigned long lval;
2629 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002630 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 lval = (unsigned long)-val;
2632 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002633 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 lval = (unsigned long)val;
2635 }
2636 *lvalp = jiffies_to_clock_t(lval);
2637 }
2638 return 0;
2639}
2640
Amerigo Wang00b7c332010-05-05 00:26:45 +00002641static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 int *valp,
2643 int write, void *data)
2644{
2645 if (write) {
2646 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2647 } else {
2648 int val = *valp;
2649 unsigned long lval;
2650 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002651 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 lval = (unsigned long)-val;
2653 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002654 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 lval = (unsigned long)val;
2656 }
2657 *lvalp = jiffies_to_msecs(lval);
2658 }
2659 return 0;
2660}
2661
2662/**
2663 * proc_dointvec_jiffies - read a vector of integers as seconds
2664 * @table: the sysctl table
2665 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 * @buffer: the user buffer
2667 * @lenp: the size of the user buffer
2668 * @ppos: file position
2669 *
2670 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2671 * values from/to the user buffer, treated as an ASCII string.
2672 * The values read are assumed to be in seconds, and are converted into
2673 * jiffies.
2674 *
2675 * Returns 0 on success.
2676 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002677int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 void __user *buffer, size_t *lenp, loff_t *ppos)
2679{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002680 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 do_proc_dointvec_jiffies_conv,NULL);
2682}
2683
2684/**
2685 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2686 * @table: the sysctl table
2687 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 * @buffer: the user buffer
2689 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002690 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 *
2692 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2693 * values from/to the user buffer, treated as an ASCII string.
2694 * The values read are assumed to be in 1/USER_HZ seconds, and
2695 * are converted into jiffies.
2696 *
2697 * Returns 0 on success.
2698 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002699int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 void __user *buffer, size_t *lenp, loff_t *ppos)
2701{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002702 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 do_proc_dointvec_userhz_jiffies_conv,NULL);
2704}
2705
2706/**
2707 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2708 * @table: the sysctl table
2709 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 * @buffer: the user buffer
2711 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002712 * @ppos: file position
2713 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 *
2715 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2716 * values from/to the user buffer, treated as an ASCII string.
2717 * The values read are assumed to be in 1/1000 seconds, and
2718 * are converted into jiffies.
2719 *
2720 * Returns 0 on success.
2721 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002722int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 void __user *buffer, size_t *lenp, loff_t *ppos)
2724{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002725 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 do_proc_dointvec_ms_jiffies_conv, NULL);
2727}
2728
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002729static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002730 void __user *buffer, size_t *lenp, loff_t *ppos)
2731{
2732 struct pid *new_pid;
2733 pid_t tmp;
2734 int r;
2735
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002736 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002737
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002738 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002739 lenp, ppos, NULL, NULL);
2740 if (r || !write)
2741 return r;
2742
2743 new_pid = find_get_pid(tmp);
2744 if (!new_pid)
2745 return -ESRCH;
2746
2747 put_pid(xchg(&cad_pid, new_pid));
2748 return 0;
2749}
2750
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002751/**
2752 * proc_do_large_bitmap - read/write from/to a large bitmap
2753 * @table: the sysctl table
2754 * @write: %TRUE if this is a write to the sysctl file
2755 * @buffer: the user buffer
2756 * @lenp: the size of the user buffer
2757 * @ppos: file position
2758 *
2759 * The bitmap is stored at table->data and the bitmap length (in bits)
2760 * in table->maxlen.
2761 *
2762 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2763 * large bitmaps may be represented in a compact manner. Writing into
2764 * the file will clear the bitmap then update it with the given input.
2765 *
2766 * Returns 0 on success.
2767 */
2768int proc_do_large_bitmap(struct ctl_table *table, int write,
2769 void __user *buffer, size_t *lenp, loff_t *ppos)
2770{
2771 int err = 0;
2772 bool first = 1;
2773 size_t left = *lenp;
2774 unsigned long bitmap_len = table->maxlen;
2775 unsigned long *bitmap = (unsigned long *) table->data;
2776 unsigned long *tmp_bitmap = NULL;
2777 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2778
2779 if (!bitmap_len || !left || (*ppos && !write)) {
2780 *lenp = 0;
2781 return 0;
2782 }
2783
2784 if (write) {
2785 unsigned long page = 0;
2786 char *kbuf;
2787
2788 if (left > PAGE_SIZE - 1)
2789 left = PAGE_SIZE - 1;
2790
2791 page = __get_free_page(GFP_TEMPORARY);
2792 kbuf = (char *) page;
2793 if (!kbuf)
2794 return -ENOMEM;
2795 if (copy_from_user(kbuf, buffer, left)) {
2796 free_page(page);
2797 return -EFAULT;
2798 }
2799 kbuf[left] = 0;
2800
2801 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2802 GFP_KERNEL);
2803 if (!tmp_bitmap) {
2804 free_page(page);
2805 return -ENOMEM;
2806 }
2807 proc_skip_char(&kbuf, &left, '\n');
2808 while (!err && left) {
2809 unsigned long val_a, val_b;
2810 bool neg;
2811
2812 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2813 sizeof(tr_a), &c);
2814 if (err)
2815 break;
2816 if (val_a >= bitmap_len || neg) {
2817 err = -EINVAL;
2818 break;
2819 }
2820
2821 val_b = val_a;
2822 if (left) {
2823 kbuf++;
2824 left--;
2825 }
2826
2827 if (c == '-') {
2828 err = proc_get_long(&kbuf, &left, &val_b,
2829 &neg, tr_b, sizeof(tr_b),
2830 &c);
2831 if (err)
2832 break;
2833 if (val_b >= bitmap_len || neg ||
2834 val_a > val_b) {
2835 err = -EINVAL;
2836 break;
2837 }
2838 if (left) {
2839 kbuf++;
2840 left--;
2841 }
2842 }
2843
2844 while (val_a <= val_b)
2845 set_bit(val_a++, tmp_bitmap);
2846
2847 first = 0;
2848 proc_skip_char(&kbuf, &left, '\n');
2849 }
2850 free_page(page);
2851 } else {
2852 unsigned long bit_a, bit_b = 0;
2853
2854 while (left) {
2855 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2856 if (bit_a >= bitmap_len)
2857 break;
2858 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2859 bit_a + 1) - 1;
2860
2861 if (!first) {
2862 err = proc_put_char(&buffer, &left, ',');
2863 if (err)
2864 break;
2865 }
2866 err = proc_put_long(&buffer, &left, bit_a, false);
2867 if (err)
2868 break;
2869 if (bit_a != bit_b) {
2870 err = proc_put_char(&buffer, &left, '-');
2871 if (err)
2872 break;
2873 err = proc_put_long(&buffer, &left, bit_b, false);
2874 if (err)
2875 break;
2876 }
2877
2878 first = 0; bit_b++;
2879 }
2880 if (!err)
2881 err = proc_put_char(&buffer, &left, '\n');
2882 }
2883
2884 if (!err) {
2885 if (write) {
2886 if (*ppos)
2887 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2888 else
2889 memcpy(bitmap, tmp_bitmap,
2890 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2891 }
2892 kfree(tmp_bitmap);
2893 *lenp -= left;
2894 *ppos += *lenp;
2895 return 0;
2896 } else {
2897 kfree(tmp_bitmap);
2898 return err;
2899 }
2900}
2901
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902#else /* CONFIG_PROC_FS */
2903
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002904int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 void __user *buffer, size_t *lenp, loff_t *ppos)
2906{
2907 return -ENOSYS;
2908}
2909
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002910int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 void __user *buffer, size_t *lenp, loff_t *ppos)
2912{
2913 return -ENOSYS;
2914}
2915
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002916int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 void __user *buffer, size_t *lenp, loff_t *ppos)
2918{
2919 return -ENOSYS;
2920}
2921
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002922int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 void __user *buffer, size_t *lenp, loff_t *ppos)
2924{
2925 return -ENOSYS;
2926}
2927
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002928int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 void __user *buffer, size_t *lenp, loff_t *ppos)
2930{
2931 return -ENOSYS;
2932}
2933
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002934int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 void __user *buffer, size_t *lenp, loff_t *ppos)
2936{
2937 return -ENOSYS;
2938}
2939
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002940int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 void __user *buffer, size_t *lenp, loff_t *ppos)
2942{
2943 return -ENOSYS;
2944}
2945
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002946int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 void __user *buffer,
2948 size_t *lenp, loff_t *ppos)
2949{
2950 return -ENOSYS;
2951}
2952
2953
2954#endif /* CONFIG_PROC_FS */
2955
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956/*
2957 * No sense putting this after each symbol definition, twice,
2958 * exception granted :-)
2959 */
2960EXPORT_SYMBOL(proc_dointvec);
2961EXPORT_SYMBOL(proc_dointvec_jiffies);
2962EXPORT_SYMBOL(proc_dointvec_minmax);
2963EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2964EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2965EXPORT_SYMBOL(proc_dostring);
2966EXPORT_SYMBOL(proc_doulongvec_minmax);
2967EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2968EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002969EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970EXPORT_SYMBOL(unregister_sysctl_table);