blob: 3132b25193db692acf94382f77385365b72ce93d [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 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530336 .procname = "timer_migration",
337 .data = &sysctl_timer_migration,
338 .maxlen = sizeof(unsigned int),
339 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800340 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530341 .extra1 = &zero,
342 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530343 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200344#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200345 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100346 .procname = "sched_rt_period_us",
347 .data = &sysctl_sched_rt_period,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800350 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100351 },
352 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100353 .procname = "sched_rt_runtime_us",
354 .data = &sysctl_sched_rt_runtime,
355 .maxlen = sizeof(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 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200360 .procname = "sched_compat_yield",
361 .data = &sysctl_sched_compat_yield,
362 .maxlen = sizeof(unsigned int),
363 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800364 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200365 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700366#ifdef CONFIG_PROVE_LOCKING
367 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700368 .procname = "prove_locking",
369 .data = &prove_locking,
370 .maxlen = sizeof(int),
371 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800372 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700373 },
374#endif
375#ifdef CONFIG_LOCK_STAT
376 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700377 .procname = "lock_stat",
378 .data = &lock_stat,
379 .maxlen = sizeof(int),
380 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800381 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700382 },
383#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .procname = "panic",
386 .data = &panic_timeout,
387 .maxlen = sizeof(int),
388 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800389 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 },
391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 .procname = "core_uses_pid",
393 .data = &core_uses_pid,
394 .maxlen = sizeof(int),
395 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800396 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 },
398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .procname = "core_pattern",
400 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700401 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800403 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 },
Neil Hormana2939802009-09-23 15:56:56 -0700405 {
Neil Hormana2939802009-09-23 15:56:56 -0700406 .procname = "core_pipe_limit",
407 .data = &core_pipe_limit,
408 .maxlen = sizeof(unsigned int),
409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800410 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700411 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800412#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700415 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800416 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800417 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800419#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100420#ifdef CONFIG_LATENCYTOP
421 {
422 .procname = "latencytop",
423 .data = &latencytop_enabled,
424 .maxlen = sizeof(int),
425 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800426 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100427 },
428#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#ifdef CONFIG_BLK_DEV_INITRD
430 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 .procname = "real-root-dev",
432 .data = &real_root_dev,
433 .maxlen = sizeof(int),
434 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800435 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 },
437#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700438 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700439 .procname = "print-fatal-signals",
440 .data = &print_fatal_signals,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800443 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700444 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700445#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 .procname = "reboot-cmd",
448 .data = reboot_command,
449 .maxlen = 256,
450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800451 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 },
453 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 .procname = "stop-a",
455 .data = &stop_a_enabled,
456 .maxlen = sizeof (int),
457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800458 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 },
460 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 .procname = "scons-poweroff",
462 .data = &scons_pwroff,
463 .maxlen = sizeof (int),
464 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800465 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 },
467#endif
David S. Miller08714202008-11-16 23:49:24 -0800468#ifdef CONFIG_SPARC64
469 {
David S. Miller08714202008-11-16 23:49:24 -0800470 .procname = "tsb-ratio",
471 .data = &sysctl_tsb_ratio,
472 .maxlen = sizeof (int),
473 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800474 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800475 },
476#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#ifdef __hppa__
478 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 .procname = "soft-power",
480 .data = &pwrsw_enabled,
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 .procname = "unaligned-trap",
487 .data = &unaligned_enabled,
488 .maxlen = sizeof (int),
489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800490 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 },
492#endif
493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .procname = "ctrl-alt-del",
495 .data = &C_A_D,
496 .maxlen = sizeof(int),
497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800498 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400500#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200501 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200502 .procname = "ftrace_enabled",
503 .data = &ftrace_enabled,
504 .maxlen = sizeof(int),
505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800506 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200507 },
508#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500509#ifdef CONFIG_STACK_TRACER
510 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500511 .procname = "stack_tracer_enabled",
512 .data = &stack_tracer_enabled,
513 .maxlen = sizeof(int),
514 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800515 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500516 },
517#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400518#ifdef CONFIG_TRACING
519 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100520 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400521 .data = &ftrace_dump_on_oops,
522 .maxlen = sizeof(int),
523 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800524 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400525 },
526#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200527#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 .procname = "modprobe",
530 .data = &modprobe_path,
531 .maxlen = KMOD_PATH_LEN,
532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800533 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 },
Kees Cook3d433212009-04-02 15:49:29 -0700535 {
Kees Cook3d433212009-04-02 15:49:29 -0700536 .procname = "modules_disabled",
537 .data = &modules_disabled,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800541 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700542 .extra1 = &one,
543 .extra2 = &one,
544 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#endif
Ian Abbott94f17cd2010-06-07 12:57:12 +0100546#ifdef CONFIG_HOTPLUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100549 .data = &uevent_helper,
550 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800552 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 },
554#endif
555#ifdef CONFIG_CHR_DEV_SG
556 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .procname = "sg-big-buff",
558 .data = &sg_big_buff,
559 .maxlen = sizeof (int),
560 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800561 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 },
563#endif
564#ifdef CONFIG_BSD_PROCESS_ACCT
565 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 .procname = "acct",
567 .data = &acct_parm,
568 .maxlen = 3*sizeof(int),
569 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800570 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 },
572#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#ifdef CONFIG_MAGIC_SYSRQ
574 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800576 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 .maxlen = sizeof (int),
578 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700579 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 },
581#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700582#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700585 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 .maxlen = sizeof (int),
587 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800588 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700590#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .procname = "threads-max",
593 .data = &max_threads,
594 .maxlen = sizeof(int),
595 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800596 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 },
598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .procname = "random",
600 .mode = 0555,
601 .child = random_table,
602 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .procname = "overflowuid",
605 .data = &overflowuid,
606 .maxlen = sizeof(int),
607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .extra1 = &minolduid,
610 .extra2 = &maxolduid,
611 },
612 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 .procname = "overflowgid",
614 .data = &overflowgid,
615 .maxlen = sizeof(int),
616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800617 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 .extra1 = &minolduid,
619 .extra2 = &maxolduid,
620 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800621#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#ifdef CONFIG_MATHEMU
623 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 .procname = "ieee_emulation_warnings",
625 .data = &sysctl_ieee_emulation_warnings,
626 .maxlen = sizeof(int),
627 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800628 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 },
630#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200633 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .maxlen = sizeof(int),
635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800636 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 },
638#endif
639 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .procname = "pid_max",
641 .data = &pid_max,
642 .maxlen = sizeof (int),
643 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800644 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 .extra1 = &pid_max_min,
646 .extra2 = &pid_max_max,
647 },
648 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .procname = "panic_on_oops",
650 .data = &panic_on_oops,
651 .maxlen = sizeof(int),
652 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800653 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800655#if defined CONFIG_PRINTK
656 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800657 .procname = "printk",
658 .data = &console_loglevel,
659 .maxlen = 4*sizeof(int),
660 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800661 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800662 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700665 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 .maxlen = sizeof(int),
667 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800668 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 },
670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700672 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 .maxlen = sizeof(int),
674 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800675 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 },
Dave Youngaf913222009-09-22 16:43:33 -0700677 {
Dave Youngaf913222009-09-22 16:43:33 -0700678 .procname = "printk_delay",
679 .data = &printk_delay_msec,
680 .maxlen = sizeof(int),
681 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800682 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700683 .extra1 = &zero,
684 .extra2 = &ten_thousand,
685 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800686#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800688 .procname = "dmesg_restrict",
689 .data = &dmesg_restrict,
690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = proc_dointvec_minmax,
693 .extra1 = &zero,
694 .extra2 = &one,
695 },
696 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .procname = "ngroups_max",
698 .data = &ngroups_max,
699 .maxlen = sizeof (int),
700 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800701 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 },
Don Zickus58687ac2010-05-07 17:11:44 -0400703#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500704 {
Don Zickus58687ac2010-05-07 17:11:44 -0400705 .procname = "watchdog",
706 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500707 .maxlen = sizeof (int),
708 .mode = 0644,
Don Zickus58687ac2010-05-07 17:11:44 -0400709 .proc_handler = proc_dowatchdog_enabled,
710 },
711 {
712 .procname = "watchdog_thresh",
713 .data = &softlockup_thresh,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = proc_dowatchdog_thresh,
717 .extra1 = &neg_one,
718 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500719 },
Don Zickus2508ce12010-05-07 17:11:46 -0400720 {
721 .procname = "softlockup_panic",
722 .data = &softlockup_panic,
723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = proc_dointvec_minmax,
726 .extra1 = &zero,
727 .extra2 = &one,
728 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500729#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400730#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .procname = "unknown_nmi_panic",
733 .data = &unknown_nmi_panic,
734 .maxlen = sizeof (int),
735 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800736 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 },
Don Zickus407984f2006-09-26 10:52:27 +0200738 {
Don Zickus407984f2006-09-26 10:52:27 +0200739 .procname = "nmi_watchdog",
740 .data = &nmi_watchdog_enabled,
741 .maxlen = sizeof (int),
742 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800743 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 },
745#endif
746#if defined(CONFIG_X86)
747 {
Don Zickus8da5add2006-09-26 10:52:27 +0200748 .procname = "panic_on_unrecovered_nmi",
749 .data = &panic_on_unrecovered_nmi,
750 .maxlen = sizeof(int),
751 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800752 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200753 },
754 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700755 .procname = "panic_on_io_nmi",
756 .data = &panic_on_io_nmi,
757 .maxlen = sizeof(int),
758 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800759 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700760 },
761 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 .procname = "bootloader_type",
763 .data = &bootloader_type,
764 .maxlen = sizeof (int),
765 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800766 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100768 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700769 .procname = "bootloader_version",
770 .data = &bootloader_version,
771 .maxlen = sizeof (int),
772 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800773 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700774 },
775 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100776 .procname = "kstack_depth_to_print",
777 .data = &kstack_depth_to_print,
778 .maxlen = sizeof(int),
779 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800780 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100781 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100782 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100783 .procname = "io_delay_type",
784 .data = &io_delay_type,
785 .maxlen = sizeof(int),
786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100788 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800790#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .procname = "randomize_va_space",
793 .data = &randomize_va_space,
794 .maxlen = sizeof(int),
795 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800796 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800798#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800799#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700800 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700801 .procname = "spin_retry",
802 .data = &spin_retry,
803 .maxlen = sizeof (int),
804 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800805 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700806 },
807#endif
Len Brown673d5b42007-07-28 03:33:16 -0400808#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800809 {
Pavel Machekc255d842006-02-20 18:27:58 -0800810 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700811 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800812 .maxlen = sizeof (unsigned long),
813 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800814 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800815 },
816#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800817#ifdef CONFIG_IA64
818 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800819 .procname = "ignore-unaligned-usertrap",
820 .data = &no_unaligned_warning,
821 .maxlen = sizeof (int),
822 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800823 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800824 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800825 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800826 .procname = "unaligned-dump-stack",
827 .data = &unaligned_dump_stack,
828 .maxlen = sizeof (int),
829 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800830 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800831 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800832#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800833#ifdef CONFIG_DETECT_HUNG_TASK
834 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800835 .procname = "hung_task_panic",
836 .data = &sysctl_hung_task_panic,
837 .maxlen = sizeof(int),
838 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800839 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800840 .extra1 = &zero,
841 .extra2 = &one,
842 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100843 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100844 .procname = "hung_task_check_count",
845 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100846 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100847 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800848 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100849 },
850 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100851 .procname = "hung_task_timeout_secs",
852 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100853 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100854 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800855 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100856 },
857 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100858 .procname = "hung_task_warnings",
859 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100860 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800862 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100863 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700864#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200865#ifdef CONFIG_COMPAT
866 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200867 .procname = "compat-log",
868 .data = &compat_log,
869 .maxlen = sizeof (int),
870 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800871 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200872 },
873#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700874#ifdef CONFIG_RT_MUTEXES
875 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700876 .procname = "max_lock_depth",
877 .data = &max_lock_depth,
878 .maxlen = sizeof(int),
879 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800880 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700881 },
882#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700883 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700884 .procname = "poweroff_cmd",
885 .data = &poweroff_cmd,
886 .maxlen = POWEROFF_CMD_PATH_LEN,
887 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800888 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700889 },
David Howells0b77f5b2008-04-29 01:01:32 -0700890#ifdef CONFIG_KEYS
891 {
David Howells0b77f5b2008-04-29 01:01:32 -0700892 .procname = "keys",
893 .mode = 0555,
894 .child = key_sysctls,
895 },
896#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700897#ifdef CONFIG_RCU_TORTURE_TEST
898 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700899 .procname = "rcutorture_runnable",
900 .data = &rcutorture_runnable,
901 .maxlen = sizeof(int),
902 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800903 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700904 },
905#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200906#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200907 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200908 .procname = "perf_event_paranoid",
909 .data = &sysctl_perf_event_paranoid,
910 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200911 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800912 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200913 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200914 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200915 .procname = "perf_event_mlock_kb",
916 .data = &sysctl_perf_event_mlock,
917 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200918 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800919 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200920 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200921 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200922 .procname = "perf_event_max_sample_rate",
923 .data = &sysctl_perf_event_sample_rate,
924 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200925 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800926 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200927 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200928#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200929#ifdef CONFIG_KMEMCHECK
930 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200931 .procname = "kmemcheck",
932 .data = &kmemcheck_enabled,
933 .maxlen = sizeof(int),
934 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800935 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200936 },
937#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200938#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200939 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200940 .procname = "blk_iopoll",
941 .data = &blk_iopoll_enabled,
942 .maxlen = sizeof(int),
943 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800944 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200945 },
Jens Axboecb684b52009-09-15 21:53:11 +0200946#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700947/*
948 * NOTE: do not add new entries to this table unless you have read
949 * Documentation/sysctl/ctl_unnumbered.txt
950 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700951 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952};
953
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700954static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 .procname = "overcommit_memory",
957 .data = &sysctl_overcommit_memory,
958 .maxlen = sizeof(sysctl_overcommit_memory),
959 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800960 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 },
962 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700963 .procname = "panic_on_oom",
964 .data = &sysctl_panic_on_oom,
965 .maxlen = sizeof(sysctl_panic_on_oom),
966 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800967 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700968 },
969 {
David Rientjesfe071d72007-10-16 23:25:56 -0700970 .procname = "oom_kill_allocating_task",
971 .data = &sysctl_oom_kill_allocating_task,
972 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
973 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800974 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700975 },
976 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800977 .procname = "oom_dump_tasks",
978 .data = &sysctl_oom_dump_tasks,
979 .maxlen = sizeof(sysctl_oom_dump_tasks),
980 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800981 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -0800982 },
983 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 .procname = "overcommit_ratio",
985 .data = &sysctl_overcommit_ratio,
986 .maxlen = sizeof(sysctl_overcommit_ratio),
987 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800988 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 },
990 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 .procname = "page-cluster",
992 .data = &page_cluster,
993 .maxlen = sizeof(int),
994 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800995 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 },
997 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 .procname = "dirty_background_ratio",
999 .data = &dirty_background_ratio,
1000 .maxlen = sizeof(dirty_background_ratio),
1001 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 .extra1 = &zero,
1004 .extra2 = &one_hundred,
1005 },
1006 {
David Rientjes2da02992009-01-06 14:39:31 -08001007 .procname = "dirty_background_bytes",
1008 .data = &dirty_background_bytes,
1009 .maxlen = sizeof(dirty_background_bytes),
1010 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001011 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001012 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001013 },
1014 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .procname = "dirty_ratio",
1016 .data = &vm_dirty_ratio,
1017 .maxlen = sizeof(vm_dirty_ratio),
1018 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001019 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 .extra1 = &zero,
1021 .extra2 = &one_hundred,
1022 },
1023 {
David Rientjes2da02992009-01-06 14:39:31 -08001024 .procname = "dirty_bytes",
1025 .data = &vm_dirty_bytes,
1026 .maxlen = sizeof(vm_dirty_bytes),
1027 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001028 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001029 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001030 },
1031 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001033 .data = &dirty_writeback_interval,
1034 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001036 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 },
1038 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001040 .data = &dirty_expire_interval,
1041 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001043 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 },
1045 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 .procname = "nr_pdflush_threads",
1047 .data = &nr_pdflush_threads,
1048 .maxlen = sizeof nr_pdflush_threads,
1049 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001050 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 },
1052 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 .procname = "swappiness",
1054 .data = &vm_swappiness,
1055 .maxlen = sizeof(vm_swappiness),
1056 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001057 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 .extra1 = &zero,
1059 .extra2 = &one_hundred,
1060 },
1061#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001062 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001064 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 .maxlen = sizeof(unsigned long),
1066 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001067 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 .extra1 = (void *)&hugetlb_zero,
1069 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001070 },
1071#ifdef CONFIG_NUMA
1072 {
1073 .procname = "nr_hugepages_mempolicy",
1074 .data = NULL,
1075 .maxlen = sizeof(unsigned long),
1076 .mode = 0644,
1077 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1078 .extra1 = (void *)&hugetlb_zero,
1079 .extra2 = (void *)&hugetlb_infinity,
1080 },
1081#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 .procname = "hugetlb_shm_group",
1084 .data = &sysctl_hugetlb_shm_group,
1085 .maxlen = sizeof(gid_t),
1086 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 },
Mel Gorman396faf02007-07-17 04:03:13 -07001089 {
Mel Gorman396faf02007-07-17 04:03:13 -07001090 .procname = "hugepages_treat_as_movable",
1091 .data = &hugepages_treat_as_movable,
1092 .maxlen = sizeof(int),
1093 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001094 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001095 },
Adam Litke54f9f802007-10-16 01:26:20 -07001096 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001097 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001098 .data = NULL,
1099 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001100 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001101 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001102 .extra1 = (void *)&hugetlb_zero,
1103 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001104 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105#endif
1106 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 .procname = "lowmem_reserve_ratio",
1108 .data = &sysctl_lowmem_reserve_ratio,
1109 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1110 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001111 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 },
1113 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001114 .procname = "drop_caches",
1115 .data = &sysctl_drop_caches,
1116 .maxlen = sizeof(int),
1117 .mode = 0644,
1118 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001119 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001120#ifdef CONFIG_COMPACTION
1121 {
1122 .procname = "compact_memory",
1123 .data = &sysctl_compact_memory,
1124 .maxlen = sizeof(int),
1125 .mode = 0200,
1126 .proc_handler = sysctl_compaction_handler,
1127 },
Mel Gorman5e771902010-05-24 14:32:31 -07001128 {
1129 .procname = "extfrag_threshold",
1130 .data = &sysctl_extfrag_threshold,
1131 .maxlen = sizeof(int),
1132 .mode = 0644,
1133 .proc_handler = sysctl_extfrag_handler,
1134 .extra1 = &min_extfrag_threshold,
1135 .extra2 = &max_extfrag_threshold,
1136 },
1137
Mel Gorman76ab0f52010-05-24 14:32:28 -07001138#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001139 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 .procname = "min_free_kbytes",
1141 .data = &min_free_kbytes,
1142 .maxlen = sizeof(min_free_kbytes),
1143 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001144 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 .extra1 = &zero,
1146 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001147 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001148 .procname = "percpu_pagelist_fraction",
1149 .data = &percpu_pagelist_fraction,
1150 .maxlen = sizeof(percpu_pagelist_fraction),
1151 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001152 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001153 .extra1 = &min_percpu_pagelist_fract,
1154 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155#ifdef CONFIG_MMU
1156 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 .procname = "max_map_count",
1158 .data = &sysctl_max_map_count,
1159 .maxlen = sizeof(sysctl_max_map_count),
1160 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001161 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001162 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001164#else
1165 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001166 .procname = "nr_trim_pages",
1167 .data = &sysctl_nr_trim_pages,
1168 .maxlen = sizeof(sysctl_nr_trim_pages),
1169 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001170 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001171 .extra1 = &zero,
1172 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173#endif
1174 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 .procname = "laptop_mode",
1176 .data = &laptop_mode,
1177 .maxlen = sizeof(laptop_mode),
1178 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001179 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 },
1181 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 .procname = "block_dump",
1183 .data = &block_dump,
1184 .maxlen = sizeof(block_dump),
1185 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001186 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 .extra1 = &zero,
1188 },
1189 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 .procname = "vfs_cache_pressure",
1191 .data = &sysctl_vfs_cache_pressure,
1192 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1193 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001194 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 .extra1 = &zero,
1196 },
1197#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1198 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 .procname = "legacy_va_layout",
1200 .data = &sysctl_legacy_va_layout,
1201 .maxlen = sizeof(sysctl_legacy_va_layout),
1202 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001203 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 .extra1 = &zero,
1205 },
1206#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001207#ifdef CONFIG_NUMA
1208 {
Christoph Lameter17436602006-01-18 17:42:32 -08001209 .procname = "zone_reclaim_mode",
1210 .data = &zone_reclaim_mode,
1211 .maxlen = sizeof(zone_reclaim_mode),
1212 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001213 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001214 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001215 },
Christoph Lameter96146342006-07-03 00:24:13 -07001216 {
Christoph Lameter96146342006-07-03 00:24:13 -07001217 .procname = "min_unmapped_ratio",
1218 .data = &sysctl_min_unmapped_ratio,
1219 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1220 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001221 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001222 .extra1 = &zero,
1223 .extra2 = &one_hundred,
1224 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001225 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001226 .procname = "min_slab_ratio",
1227 .data = &sysctl_min_slab_ratio,
1228 .maxlen = sizeof(sysctl_min_slab_ratio),
1229 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001230 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001231 .extra1 = &zero,
1232 .extra2 = &one_hundred,
1233 },
Christoph Lameter17436602006-01-18 17:42:32 -08001234#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001235#ifdef CONFIG_SMP
1236 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001237 .procname = "stat_interval",
1238 .data = &sysctl_stat_interval,
1239 .maxlen = sizeof(sysctl_stat_interval),
1240 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001241 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001242 },
1243#endif
David Howells6e141542009-12-15 19:27:45 +00001244#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001245 {
Eric Parised032182007-06-28 15:55:21 -04001246 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001247 .data = &dac_mmap_min_addr,
1248 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001249 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001250 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001251 },
David Howells6e141542009-12-15 19:27:45 +00001252#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001253#ifdef CONFIG_NUMA
1254 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001255 .procname = "numa_zonelist_order",
1256 .data = &numa_zonelist_order,
1257 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1258 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001259 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001260 },
1261#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001262#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001263 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001264 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001265 .procname = "vdso_enabled",
1266 .data = &vdso_enabled,
1267 .maxlen = sizeof(vdso_enabled),
1268 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001269 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001270 .extra1 = &zero,
1271 },
1272#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001273#ifdef CONFIG_HIGHMEM
1274 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001275 .procname = "highmem_is_dirtyable",
1276 .data = &vm_highmem_is_dirtyable,
1277 .maxlen = sizeof(vm_highmem_is_dirtyable),
1278 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001279 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001280 .extra1 = &zero,
1281 .extra2 = &one,
1282 },
1283#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001284 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001285 .procname = "scan_unevictable_pages",
1286 .data = &scan_unevictable_pages,
1287 .maxlen = sizeof(scan_unevictable_pages),
1288 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001289 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001290 },
Andi Kleen6a460792009-09-16 11:50:15 +02001291#ifdef CONFIG_MEMORY_FAILURE
1292 {
Andi Kleen6a460792009-09-16 11:50:15 +02001293 .procname = "memory_failure_early_kill",
1294 .data = &sysctl_memory_failure_early_kill,
1295 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1296 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001297 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001298 .extra1 = &zero,
1299 .extra2 = &one,
1300 },
1301 {
Andi Kleen6a460792009-09-16 11:50:15 +02001302 .procname = "memory_failure_recovery",
1303 .data = &sysctl_memory_failure_recovery,
1304 .maxlen = sizeof(sysctl_memory_failure_recovery),
1305 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001306 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001307 .extra1 = &zero,
1308 .extra2 = &one,
1309 },
1310#endif
1311
Andrew Morton2be7fe02007-07-15 23:41:21 -07001312/*
1313 * NOTE: do not add new entries to this table unless you have read
1314 * Documentation/sysctl/ctl_unnumbered.txt
1315 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001316 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317};
1318
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001319#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001320static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001321 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001322};
1323#endif
1324
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001325static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 .procname = "inode-nr",
1328 .data = &inodes_stat,
1329 .maxlen = 2*sizeof(int),
1330 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001331 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 },
1333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 .procname = "inode-state",
1335 .data = &inodes_stat,
1336 .maxlen = 7*sizeof(int),
1337 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001338 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 },
1340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .procname = "file-nr",
1342 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001343 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001345 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 },
1347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .procname = "file-max",
1349 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001350 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001352 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 },
1354 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001355 .procname = "nr_open",
1356 .data = &sysctl_nr_open,
1357 .maxlen = sizeof(int),
1358 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001359 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001360 .extra1 = &sysctl_nr_open_min,
1361 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001362 },
1363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .procname = "dentry-state",
1365 .data = &dentry_stat,
1366 .maxlen = 6*sizeof(int),
1367 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001368 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 },
1370 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 .procname = "overflowuid",
1372 .data = &fs_overflowuid,
1373 .maxlen = sizeof(int),
1374 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001375 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .extra1 = &minolduid,
1377 .extra2 = &maxolduid,
1378 },
1379 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 .procname = "overflowgid",
1381 .data = &fs_overflowgid,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001384 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 .extra1 = &minolduid,
1386 .extra2 = &maxolduid,
1387 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001388#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .procname = "leases-enable",
1391 .data = &leases_enable,
1392 .maxlen = sizeof(int),
1393 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001394 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001396#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397#ifdef CONFIG_DNOTIFY
1398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "dir-notify-enable",
1400 .data = &dir_notify_enable,
1401 .maxlen = sizeof(int),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 },
1405#endif
1406#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001407#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 .procname = "lease-break-time",
1410 .data = &lease_break_time,
1411 .maxlen = sizeof(int),
1412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001413 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001415#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001416#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "aio-nr",
1419 .data = &aio_nr,
1420 .maxlen = sizeof(aio_nr),
1421 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 },
1424 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 .procname = "aio-max-nr",
1426 .data = &aio_max_nr,
1427 .maxlen = sizeof(aio_max_nr),
1428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001429 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001431#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001432#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001433 {
Robert Love0399cb02005-07-13 12:38:18 -04001434 .procname = "inotify",
1435 .mode = 0555,
1436 .child = inotify_table,
1437 },
1438#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001439#ifdef CONFIG_EPOLL
1440 {
1441 .procname = "epoll",
1442 .mode = 0555,
1443 .child = epoll_table,
1444 },
1445#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001447 {
Alan Coxd6e71142005-06-23 00:09:43 -07001448 .procname = "suid_dumpable",
1449 .data = &suid_dumpable,
1450 .maxlen = sizeof(int),
1451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001452 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001453 .extra1 = &zero,
1454 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001455 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001456#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1457 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001458 .procname = "binfmt_misc",
1459 .mode = 0555,
1460 .child = binfmt_misc_table,
1461 },
1462#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001463 {
Jens Axboeff9da692010-06-03 14:54:39 +02001464 .procname = "pipe-max-size",
1465 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001466 .maxlen = sizeof(int),
1467 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001468 .proc_handler = &pipe_proc_fn,
1469 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001470 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001471/*
1472 * NOTE: do not add new entries to this table unless you have read
1473 * Documentation/sysctl/ctl_unnumbered.txt
1474 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001475 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476};
1477
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001478static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001479#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1480 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001481 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001482 .procname = "exception-trace",
1483 .data = &show_unhandled_signals,
1484 .maxlen = sizeof(int),
1485 .mode = 0644,
1486 .proc_handler = proc_dointvec
1487 },
1488#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001489#if defined(CONFIG_OPTPROBES)
1490 {
1491 .procname = "kprobes-optimization",
1492 .data = &sysctl_kprobes_optimization,
1493 .maxlen = sizeof(int),
1494 .mode = 0644,
1495 .proc_handler = proc_kprobes_optimization_handler,
1496 .extra1 = &zero,
1497 .extra2 = &one,
1498 },
1499#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001500 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501};
1502
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001503static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001504 { }
Robert Love0eeca282005-07-12 17:06:03 -04001505};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
Al Viro330d57f2005-11-04 10:18:40 +00001507static DEFINE_SPINLOCK(sysctl_lock);
1508
1509/* called under sysctl_lock */
1510static int use_table(struct ctl_table_header *p)
1511{
1512 if (unlikely(p->unregistering))
1513 return 0;
1514 p->used++;
1515 return 1;
1516}
1517
1518/* called under sysctl_lock */
1519static void unuse_table(struct ctl_table_header *p)
1520{
1521 if (!--p->used)
1522 if (unlikely(p->unregistering))
1523 complete(p->unregistering);
1524}
1525
1526/* called under sysctl_lock, will reacquire if has to wait */
1527static void start_unregistering(struct ctl_table_header *p)
1528{
1529 /*
1530 * if p->used is 0, nobody will ever touch that entry again;
1531 * we'll eliminate all paths to it before dropping sysctl_lock
1532 */
1533 if (unlikely(p->used)) {
1534 struct completion wait;
1535 init_completion(&wait);
1536 p->unregistering = &wait;
1537 spin_unlock(&sysctl_lock);
1538 wait_for_completion(&wait);
1539 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001540 } else {
1541 /* anything non-NULL; we'll never dereference it */
1542 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001543 }
1544 /*
1545 * do not remove from the list until nobody holds it; walking the
1546 * list in do_sysctl() relies on that.
1547 */
1548 list_del_init(&p->ctl_entry);
1549}
1550
Al Virof7e6ced2008-07-15 01:44:23 -04001551void sysctl_head_get(struct ctl_table_header *head)
1552{
1553 spin_lock(&sysctl_lock);
1554 head->count++;
1555 spin_unlock(&sysctl_lock);
1556}
1557
1558void sysctl_head_put(struct ctl_table_header *head)
1559{
1560 spin_lock(&sysctl_lock);
1561 if (!--head->count)
1562 kfree(head);
1563 spin_unlock(&sysctl_lock);
1564}
1565
1566struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1567{
1568 if (!head)
1569 BUG();
1570 spin_lock(&sysctl_lock);
1571 if (!use_table(head))
1572 head = ERR_PTR(-ENOENT);
1573 spin_unlock(&sysctl_lock);
1574 return head;
1575}
1576
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001577void sysctl_head_finish(struct ctl_table_header *head)
1578{
1579 if (!head)
1580 return;
1581 spin_lock(&sysctl_lock);
1582 unuse_table(head);
1583 spin_unlock(&sysctl_lock);
1584}
1585
Al Viro73455092008-07-14 21:22:20 -04001586static struct ctl_table_set *
1587lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1588{
1589 struct ctl_table_set *set = &root->default_set;
1590 if (root->lookup)
1591 set = root->lookup(root, namespaces);
1592 return set;
1593}
1594
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001595static struct list_head *
1596lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001597{
Al Viro73455092008-07-14 21:22:20 -04001598 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1599 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001600}
1601
1602struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1603 struct ctl_table_header *prev)
1604{
1605 struct ctl_table_root *root;
1606 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001607 struct ctl_table_header *head;
1608 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001609
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001610 spin_lock(&sysctl_lock);
1611 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001612 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001613 tmp = &prev->ctl_entry;
1614 unuse_table(prev);
1615 goto next;
1616 }
1617 tmp = &root_table_header.ctl_entry;
1618 for (;;) {
1619 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1620
1621 if (!use_table(head))
1622 goto next;
1623 spin_unlock(&sysctl_lock);
1624 return head;
1625 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001626 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001627 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001628 header_list = lookup_header_list(root, namespaces);
1629 if (tmp != header_list)
1630 continue;
1631
1632 do {
1633 root = list_entry(root->root_list.next,
1634 struct ctl_table_root, root_list);
1635 if (root == &sysctl_table_root)
1636 goto out;
1637 header_list = lookup_header_list(root, namespaces);
1638 } while (list_empty(header_list));
1639 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001640 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001641out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001642 spin_unlock(&sysctl_lock);
1643 return NULL;
1644}
1645
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001646struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1647{
1648 return __sysctl_head_next(current->nsproxy, prev);
1649}
1650
1651void register_sysctl_root(struct ctl_table_root *root)
1652{
1653 spin_lock(&sysctl_lock);
1654 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1655 spin_unlock(&sysctl_lock);
1656}
1657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001659 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 * some sysctl variables are readonly even to root.
1661 */
1662
1663static int test_perm(int mode, int op)
1664{
David Howells76aac0e2008-11-14 10:39:12 +11001665 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 mode >>= 6;
1667 else if (in_egroup_p(0))
1668 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001669 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 return 0;
1671 return -EACCES;
1672}
1673
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001674int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675{
1676 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001677 int mode;
1678
Al Viroe6305c42008-07-15 21:03:57 -04001679 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 if (error)
1681 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001682
1683 if (root->permissions)
1684 mode = root->permissions(root, current->nsproxy, table);
1685 else
1686 mode = table->mode;
1687
1688 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689}
1690
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001691static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1692{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001693 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001694 table->parent = parent;
1695 if (table->child)
1696 sysctl_set_parent(table, table->child);
1697 }
1698}
1699
1700static __init int sysctl_init(void)
1701{
1702 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001703#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Andi Kleenb3bd3de2010-08-10 14:17:51 -07001704 sysctl_check_table(current->nsproxy, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001705#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001706 return 0;
1707}
1708
1709core_initcall(sysctl_init);
1710
Al Virobfbcf032008-07-27 06:31:22 +01001711static struct ctl_table *is_branch_in(struct ctl_table *branch,
1712 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001713{
1714 struct ctl_table *p;
1715 const char *s = branch->procname;
1716
1717 /* branch should have named subdirectory as its first element */
1718 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001719 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001720
1721 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001722 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001723 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001724
1725 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001726 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001727 if (!p->child)
1728 continue;
1729 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001730 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001731 }
Al Virobfbcf032008-07-27 06:31:22 +01001732 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001733}
1734
1735/* see if attaching q to p would be an improvement */
1736static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1737{
1738 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001739 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001740 int is_better = 0;
1741 int not_in_parent = !p->attached_by;
1742
Al Virobfbcf032008-07-27 06:31:22 +01001743 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001744 if (by == q->attached_by)
1745 is_better = 1;
1746 if (to == p->attached_by)
1747 not_in_parent = 1;
1748 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001749 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001750 }
1751
1752 if (is_better && not_in_parent) {
1753 q->attached_by = by;
1754 q->attached_to = to;
1755 q->parent = p;
1756 }
1757}
1758
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001760 * __register_sysctl_paths - register a sysctl hierarchy
1761 * @root: List of sysctl headers to register on
1762 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001763 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 *
1766 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001767 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001769 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1772 * enter a sysctl file
1773 *
1774 * data - a pointer to data for use by proc_handler
1775 *
1776 * maxlen - the maximum size in bytes of the data
1777 *
1778 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1779 *
1780 * child - a pointer to the child sysctl table if this entry is a directory, or
1781 * %NULL.
1782 *
1783 * proc_handler - the text handler routine (described below)
1784 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 * de - for internal use by the sysctl routines
1786 *
1787 * extra1, extra2 - extra pointers usable by the proc handler routines
1788 *
1789 * Leaf nodes in the sysctl tree will be represented by a single file
1790 * under /proc; non-leaf nodes will be represented by directories.
1791 *
1792 * sysctl(2) can automatically manage read and write requests through
1793 * the sysctl table. The data and maxlen fields of the ctl_table
1794 * struct enable minimal validation of the values being written to be
1795 * performed, and the mode field allows minimal authentication.
1796 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 * There must be a proc_handler routine for any terminal nodes
1798 * mirrored under /proc/sys (non-terminals are handled by a built-in
1799 * directory handler). Several default handlers are available to
1800 * cover common cases -
1801 *
1802 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1803 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1804 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1805 *
1806 * It is the handler's job to read the input buffer from user memory
1807 * and process it. The handler should return 0 on success.
1808 *
1809 * This routine returns %NULL on a failure to register, and a pointer
1810 * to the table header on success.
1811 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001812struct ctl_table_header *__register_sysctl_paths(
1813 struct ctl_table_root *root,
1814 struct nsproxy *namespaces,
1815 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001817 struct ctl_table_header *header;
1818 struct ctl_table *new, **prevp;
1819 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001820 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001821
1822 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001823 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001824 ;
1825
1826 /*
1827 * For each path component, allocate a 2-element ctl_table array.
1828 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001829 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001830 *
1831 * We allocate everything in one go so that we don't have to
1832 * worry about freeing additional memory in unregister_sysctl_table.
1833 */
1834 header = kzalloc(sizeof(struct ctl_table_header) +
1835 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1836 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001838
1839 new = (struct ctl_table *) (header + 1);
1840
1841 /* Now connect the dots */
1842 prevp = &header->ctl_table;
1843 for (n = 0; n < npath; ++n, ++path) {
1844 /* Copy the procname */
1845 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001846 new->mode = 0555;
1847
1848 *prevp = new;
1849 prevp = &new->child;
1850
1851 new += 2;
1852 }
1853 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001854 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001855
1856 INIT_LIST_HEAD(&header->ctl_entry);
1857 header->used = 0;
1858 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001859 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001860 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001861 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001862#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001863 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001864 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001865 return NULL;
1866 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001867#endif
Al Viro330d57f2005-11-04 10:18:40 +00001868 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001869 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001870 header->attached_by = header->ctl_table;
1871 header->attached_to = root_table;
1872 header->parent = &root_table_header;
1873 for (set = header->set; set; set = set->parent) {
1874 struct ctl_table_header *p;
1875 list_for_each_entry(p, &set->list, ctl_entry) {
1876 if (p->unregistering)
1877 continue;
1878 try_attach(p, header);
1879 }
1880 }
1881 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001882 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001883 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001884
1885 return header;
1886}
1887
1888/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001889 * register_sysctl_table_path - register a sysctl table hierarchy
1890 * @path: The path to the directory the sysctl table is in.
1891 * @table: the top-level table structure
1892 *
1893 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1894 * array. A completely 0 filled entry terminates the table.
1895 *
1896 * See __register_sysctl_paths for more details.
1897 */
1898struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1899 struct ctl_table *table)
1900{
1901 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1902 path, table);
1903}
1904
1905/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001906 * register_sysctl_table - register a sysctl table hierarchy
1907 * @table: the top-level table structure
1908 *
1909 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1910 * array. A completely 0 filled entry terminates the table.
1911 *
1912 * See register_sysctl_paths for more details.
1913 */
1914struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1915{
1916 static const struct ctl_path null_path[] = { {} };
1917
1918 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
1921/**
1922 * unregister_sysctl_table - unregister a sysctl table hierarchy
1923 * @header: the header returned from register_sysctl_table
1924 *
1925 * Unregisters the sysctl table and all children. proc entries may not
1926 * actually be removed until they are no longer used by anyone.
1927 */
1928void unregister_sysctl_table(struct ctl_table_header * header)
1929{
Al Viro330d57f2005-11-04 10:18:40 +00001930 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001931
1932 if (header == NULL)
1933 return;
1934
Al Viro330d57f2005-11-04 10:18:40 +00001935 spin_lock(&sysctl_lock);
1936 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001937 if (!--header->parent->count) {
1938 WARN_ON(1);
1939 kfree(header->parent);
1940 }
Al Virof7e6ced2008-07-15 01:44:23 -04001941 if (!--header->count)
1942 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001943 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944}
1945
Al Viro9043476f2008-07-15 08:54:06 -04001946int sysctl_is_seen(struct ctl_table_header *p)
1947{
1948 struct ctl_table_set *set = p->set;
1949 int res;
1950 spin_lock(&sysctl_lock);
1951 if (p->unregistering)
1952 res = 0;
1953 else if (!set->is_seen)
1954 res = 1;
1955 else
1956 res = set->is_seen(set);
1957 spin_unlock(&sysctl_lock);
1958 return res;
1959}
1960
Al Viro73455092008-07-14 21:22:20 -04001961void setup_sysctl_set(struct ctl_table_set *p,
1962 struct ctl_table_set *parent,
1963 int (*is_seen)(struct ctl_table_set *))
1964{
1965 INIT_LIST_HEAD(&p->list);
1966 p->parent = parent ? parent : &sysctl_table_root.default_set;
1967 p->is_seen = is_seen;
1968}
1969
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001970#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001971struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001972{
1973 return NULL;
1974}
1975
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001976struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1977 struct ctl_table *table)
1978{
1979 return NULL;
1980}
1981
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001982void unregister_sysctl_table(struct ctl_table_header * table)
1983{
1984}
1985
Al Viro73455092008-07-14 21:22:20 -04001986void setup_sysctl_set(struct ctl_table_set *p,
1987 struct ctl_table_set *parent,
1988 int (*is_seen)(struct ctl_table_set *))
1989{
1990}
1991
Al Virof7e6ced2008-07-15 01:44:23 -04001992void sysctl_head_put(struct ctl_table_header *head)
1993{
1994}
1995
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001996#endif /* CONFIG_SYSCTL */
1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998/*
1999 * /proc/sys support
2000 */
2001
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002002#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002004static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002005 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002006 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002007{
2008 size_t len;
2009 char __user *p;
2010 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002011
2012 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002013 *lenp = 0;
2014 return 0;
2015 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002016
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002017 if (write) {
2018 len = 0;
2019 p = buffer;
2020 while (len < *lenp) {
2021 if (get_user(c, p++))
2022 return -EFAULT;
2023 if (c == 0 || c == '\n')
2024 break;
2025 len++;
2026 }
2027 if (len >= maxlen)
2028 len = maxlen-1;
2029 if(copy_from_user(data, buffer, len))
2030 return -EFAULT;
2031 ((char *) data)[len] = 0;
2032 *ppos += *lenp;
2033 } else {
2034 len = strlen(data);
2035 if (len > maxlen)
2036 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002037
2038 if (*ppos > len) {
2039 *lenp = 0;
2040 return 0;
2041 }
2042
2043 data += *ppos;
2044 len -= *ppos;
2045
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002046 if (len > *lenp)
2047 len = *lenp;
2048 if (len)
2049 if(copy_to_user(buffer, data, len))
2050 return -EFAULT;
2051 if (len < *lenp) {
2052 if(put_user('\n', ((char __user *) buffer) + len))
2053 return -EFAULT;
2054 len++;
2055 }
2056 *lenp = len;
2057 *ppos += len;
2058 }
2059 return 0;
2060}
2061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062/**
2063 * proc_dostring - read a string sysctl
2064 * @table: the sysctl table
2065 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 * @buffer: the user buffer
2067 * @lenp: the size of the user buffer
2068 * @ppos: file position
2069 *
2070 * Reads/writes a string from/to the user buffer. If the kernel
2071 * buffer provided is not large enough to hold the string, the
2072 * string is truncated. The copied string is %NULL-terminated.
2073 * If the string is being read by the user process, it is copied
2074 * and a newline '\n' is added. It is truncated if the buffer is
2075 * not large enough.
2076 *
2077 * Returns 0 on success.
2078 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002079int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 void __user *buffer, size_t *lenp, loff_t *ppos)
2081{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002082 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002083 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084}
2085
Amerigo Wang00b7c332010-05-05 00:26:45 +00002086static size_t proc_skip_spaces(char **buf)
2087{
2088 size_t ret;
2089 char *tmp = skip_spaces(*buf);
2090 ret = tmp - *buf;
2091 *buf = tmp;
2092 return ret;
2093}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002095static void proc_skip_char(char **buf, size_t *size, const char v)
2096{
2097 while (*size) {
2098 if (**buf != v)
2099 break;
2100 (*size)--;
2101 (*buf)++;
2102 }
2103}
2104
Amerigo Wang00b7c332010-05-05 00:26:45 +00002105#define TMPBUFLEN 22
2106/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002107 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002108 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002109 * @buf: a kernel buffer
2110 * @size: size of the kernel buffer
2111 * @val: this is where the number will be stored
2112 * @neg: set to %TRUE if number is negative
2113 * @perm_tr: a vector which contains the allowed trailers
2114 * @perm_tr_len: size of the perm_tr vector
2115 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002116 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002117 * In case of success %0 is returned and @buf and @size are updated with
2118 * the amount of bytes read. If @tr is non-NULL and a trailing
2119 * character exists (size is non-zero after returning from this
2120 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002121 */
2122static int proc_get_long(char **buf, size_t *size,
2123 unsigned long *val, bool *neg,
2124 const char *perm_tr, unsigned perm_tr_len, char *tr)
2125{
2126 int len;
2127 char *p, tmp[TMPBUFLEN];
2128
2129 if (!*size)
2130 return -EINVAL;
2131
2132 len = *size;
2133 if (len > TMPBUFLEN - 1)
2134 len = TMPBUFLEN - 1;
2135
2136 memcpy(tmp, *buf, len);
2137
2138 tmp[len] = 0;
2139 p = tmp;
2140 if (*p == '-' && *size > 1) {
2141 *neg = true;
2142 p++;
2143 } else
2144 *neg = false;
2145 if (!isdigit(*p))
2146 return -EINVAL;
2147
2148 *val = simple_strtoul(p, &p, 0);
2149
2150 len = p - tmp;
2151
2152 /* We don't know if the next char is whitespace thus we may accept
2153 * invalid integers (e.g. 1234...a) or two integers instead of one
2154 * (e.g. 123...1). So lets not allow such large numbers. */
2155 if (len == TMPBUFLEN - 1)
2156 return -EINVAL;
2157
2158 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2159 return -EINVAL;
2160
2161 if (tr && (len < *size))
2162 *tr = *p;
2163
2164 *buf += len;
2165 *size -= len;
2166
2167 return 0;
2168}
2169
2170/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002171 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002172 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002173 * @buf: the user buffer
2174 * @size: the size of the user buffer
2175 * @val: the integer to be converted
2176 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002177 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002178 * In case of success %0 is returned and @buf and @size are updated with
2179 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002180 */
2181static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2182 bool neg)
2183{
2184 int len;
2185 char tmp[TMPBUFLEN], *p = tmp;
2186
2187 sprintf(p, "%s%lu", neg ? "-" : "", val);
2188 len = strlen(tmp);
2189 if (len > *size)
2190 len = *size;
2191 if (copy_to_user(*buf, tmp, len))
2192 return -EFAULT;
2193 *size -= len;
2194 *buf += len;
2195 return 0;
2196}
2197#undef TMPBUFLEN
2198
2199static int proc_put_char(void __user **buf, size_t *size, char c)
2200{
2201 if (*size) {
2202 char __user **buffer = (char __user **)buf;
2203 if (put_user(c, *buffer))
2204 return -EFAULT;
2205 (*size)--, (*buffer)++;
2206 *buf = *buffer;
2207 }
2208 return 0;
2209}
2210
2211static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 int *valp,
2213 int write, void *data)
2214{
2215 if (write) {
2216 *valp = *negp ? -*lvalp : *lvalp;
2217 } else {
2218 int val = *valp;
2219 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002220 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 *lvalp = (unsigned long)-val;
2222 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002223 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 *lvalp = (unsigned long)val;
2225 }
2226 }
2227 return 0;
2228}
2229
Amerigo Wang00b7c332010-05-05 00:26:45 +00002230static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2231
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002232static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002233 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002234 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002235 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 int write, void *data),
2237 void *data)
2238{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 int *i, vleft, first = 1, err = 0;
2240 unsigned long page = 0;
2241 size_t left;
2242 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
Amerigo Wang00b7c332010-05-05 00:26:45 +00002244 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 *lenp = 0;
2246 return 0;
2247 }
2248
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002249 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 vleft = table->maxlen / sizeof(*i);
2251 left = *lenp;
2252
2253 if (!conv)
2254 conv = do_proc_dointvec_conv;
2255
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002257 if (left > PAGE_SIZE - 1)
2258 left = PAGE_SIZE - 1;
2259 page = __get_free_page(GFP_TEMPORARY);
2260 kbuf = (char *) page;
2261 if (!kbuf)
2262 return -ENOMEM;
2263 if (copy_from_user(kbuf, buffer, left)) {
2264 err = -EFAULT;
2265 goto free;
2266 }
2267 kbuf[left] = 0;
2268 }
2269
2270 for (; left && vleft--; i++, first=0) {
2271 unsigned long lval;
2272 bool neg;
2273
2274 if (write) {
2275 left -= proc_skip_spaces(&kbuf);
2276
J. R. Okajima563b0462010-05-25 16:10:14 -07002277 if (!left)
2278 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002279 err = proc_get_long(&kbuf, &left, &lval, &neg,
2280 proc_wspace_sep,
2281 sizeof(proc_wspace_sep), NULL);
2282 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002284 if (conv(&neg, &lval, i, 1, data)) {
2285 err = -EINVAL;
2286 break;
2287 }
2288 } else {
2289 if (conv(&neg, &lval, i, 0, data)) {
2290 err = -EINVAL;
2291 break;
2292 }
2293 if (!first)
2294 err = proc_put_char(&buffer, &left, '\t');
2295 if (err)
2296 break;
2297 err = proc_put_long(&buffer, &left, lval, neg);
2298 if (err)
2299 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 }
2301 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002302
2303 if (!write && !first && left && !err)
2304 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002305 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002306 left -= proc_skip_spaces(&kbuf);
2307free:
2308 if (write) {
2309 free_page(page);
2310 if (first)
2311 return err ? : -EINVAL;
2312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 *lenp -= left;
2314 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002315 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316}
2317
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002318static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002319 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002320 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002321 int write, void *data),
2322 void *data)
2323{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002324 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002325 buffer, lenp, ppos, conv, data);
2326}
2327
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328/**
2329 * proc_dointvec - read a vector of integers
2330 * @table: the sysctl table
2331 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 * @buffer: the user buffer
2333 * @lenp: the size of the user buffer
2334 * @ppos: file position
2335 *
2336 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2337 * values from/to the user buffer, treated as an ASCII string.
2338 *
2339 * Returns 0 on success.
2340 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002341int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 void __user *buffer, size_t *lenp, loff_t *ppos)
2343{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002344 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 NULL,NULL);
2346}
2347
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002348/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002349 * Taint values can only be increased
2350 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002351 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002352static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002353 void __user *buffer, size_t *lenp, loff_t *ppos)
2354{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002355 struct ctl_table t;
2356 unsigned long tmptaint = get_taint();
2357 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002358
Bastian Blank91fcd412007-04-23 14:41:14 -07002359 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002360 return -EPERM;
2361
Andi Kleen25ddbb12008-10-15 22:01:41 -07002362 t = *table;
2363 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002364 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002365 if (err < 0)
2366 return err;
2367
2368 if (write) {
2369 /*
2370 * Poor man's atomic or. Not worth adding a primitive
2371 * to everyone's atomic.h for this
2372 */
2373 int i;
2374 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2375 if ((tmptaint >> i) & 1)
2376 add_taint(i);
2377 }
2378 }
2379
2380 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002381}
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383struct do_proc_dointvec_minmax_conv_param {
2384 int *min;
2385 int *max;
2386};
2387
Amerigo Wang00b7c332010-05-05 00:26:45 +00002388static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2389 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 int write, void *data)
2391{
2392 struct do_proc_dointvec_minmax_conv_param *param = data;
2393 if (write) {
2394 int val = *negp ? -*lvalp : *lvalp;
2395 if ((param->min && *param->min > val) ||
2396 (param->max && *param->max < val))
2397 return -EINVAL;
2398 *valp = val;
2399 } else {
2400 int val = *valp;
2401 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002402 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 *lvalp = (unsigned long)-val;
2404 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002405 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 *lvalp = (unsigned long)val;
2407 }
2408 }
2409 return 0;
2410}
2411
2412/**
2413 * proc_dointvec_minmax - read a vector of integers with min/max values
2414 * @table: the sysctl table
2415 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 * @buffer: the user buffer
2417 * @lenp: the size of the user buffer
2418 * @ppos: file position
2419 *
2420 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2421 * values from/to the user buffer, treated as an ASCII string.
2422 *
2423 * This routine will ensure the values are within the range specified by
2424 * table->extra1 (min) and table->extra2 (max).
2425 *
2426 * Returns 0 on success.
2427 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002428int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 void __user *buffer, size_t *lenp, loff_t *ppos)
2430{
2431 struct do_proc_dointvec_minmax_conv_param param = {
2432 .min = (int *) table->extra1,
2433 .max = (int *) table->extra2,
2434 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002435 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 do_proc_dointvec_minmax_conv, &param);
2437}
2438
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002439static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 void __user *buffer,
2441 size_t *lenp, loff_t *ppos,
2442 unsigned long convmul,
2443 unsigned long convdiv)
2444{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002445 unsigned long *i, *min, *max;
2446 int vleft, first = 1, err = 0;
2447 unsigned long page = 0;
2448 size_t left;
2449 char *kbuf;
2450
2451 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 *lenp = 0;
2453 return 0;
2454 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002455
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002456 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 min = (unsigned long *) table->extra1;
2458 max = (unsigned long *) table->extra2;
2459 vleft = table->maxlen / sizeof(unsigned long);
2460 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002461
2462 if (write) {
2463 if (left > PAGE_SIZE - 1)
2464 left = PAGE_SIZE - 1;
2465 page = __get_free_page(GFP_TEMPORARY);
2466 kbuf = (char *) page;
2467 if (!kbuf)
2468 return -ENOMEM;
2469 if (copy_from_user(kbuf, buffer, left)) {
2470 err = -EFAULT;
2471 goto free;
2472 }
2473 kbuf[left] = 0;
2474 }
2475
Eric Dumazet27b3d802010-10-07 12:59:29 -07002476 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002477 unsigned long val;
2478
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002480 bool neg;
2481
2482 left -= proc_skip_spaces(&kbuf);
2483
2484 err = proc_get_long(&kbuf, &left, &val, &neg,
2485 proc_wspace_sep,
2486 sizeof(proc_wspace_sep), NULL);
2487 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 break;
2489 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 continue;
2491 if ((min && val < *min) || (max && val > *max))
2492 continue;
2493 *i = val;
2494 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002495 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002497 err = proc_put_char(&buffer, &left, '\t');
2498 err = proc_put_long(&buffer, &left, val, false);
2499 if (err)
2500 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 }
2502 }
2503
Amerigo Wang00b7c332010-05-05 00:26:45 +00002504 if (!write && !first && left && !err)
2505 err = proc_put_char(&buffer, &left, '\n');
2506 if (write && !err)
2507 left -= proc_skip_spaces(&kbuf);
2508free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002510 free_page(page);
2511 if (first)
2512 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 *lenp -= left;
2515 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002516 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517}
2518
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002519static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002520 void __user *buffer,
2521 size_t *lenp, loff_t *ppos,
2522 unsigned long convmul,
2523 unsigned long convdiv)
2524{
2525 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002526 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002527}
2528
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529/**
2530 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2531 * @table: the sysctl table
2532 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 * @buffer: the user buffer
2534 * @lenp: the size of the user buffer
2535 * @ppos: file position
2536 *
2537 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2538 * values from/to the user buffer, treated as an ASCII string.
2539 *
2540 * This routine will ensure the values are within the range specified by
2541 * table->extra1 (min) and table->extra2 (max).
2542 *
2543 * Returns 0 on success.
2544 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002545int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 void __user *buffer, size_t *lenp, loff_t *ppos)
2547{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002548 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549}
2550
2551/**
2552 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2553 * @table: the sysctl table
2554 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 * @buffer: the user buffer
2556 * @lenp: the size of the user buffer
2557 * @ppos: file position
2558 *
2559 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2560 * values from/to the user buffer, treated as an ASCII string. The values
2561 * are treated as milliseconds, and converted to jiffies when they are stored.
2562 *
2563 * This routine will ensure the values are within the range specified by
2564 * table->extra1 (min) and table->extra2 (max).
2565 *
2566 * Returns 0 on success.
2567 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002568int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 void __user *buffer,
2570 size_t *lenp, loff_t *ppos)
2571{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002572 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 lenp, ppos, HZ, 1000l);
2574}
2575
2576
Amerigo Wang00b7c332010-05-05 00:26:45 +00002577static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 int *valp,
2579 int write, void *data)
2580{
2581 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002582 if (*lvalp > LONG_MAX / HZ)
2583 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2585 } else {
2586 int val = *valp;
2587 unsigned long lval;
2588 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002589 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 lval = (unsigned long)-val;
2591 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002592 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 lval = (unsigned long)val;
2594 }
2595 *lvalp = lval / HZ;
2596 }
2597 return 0;
2598}
2599
Amerigo Wang00b7c332010-05-05 00:26:45 +00002600static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 int *valp,
2602 int write, void *data)
2603{
2604 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002605 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2606 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2608 } else {
2609 int val = *valp;
2610 unsigned long lval;
2611 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002612 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 lval = (unsigned long)-val;
2614 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002615 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 lval = (unsigned long)val;
2617 }
2618 *lvalp = jiffies_to_clock_t(lval);
2619 }
2620 return 0;
2621}
2622
Amerigo Wang00b7c332010-05-05 00:26:45 +00002623static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 int *valp,
2625 int write, void *data)
2626{
2627 if (write) {
2628 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2629 } else {
2630 int val = *valp;
2631 unsigned long lval;
2632 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002633 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 lval = (unsigned long)-val;
2635 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002636 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 lval = (unsigned long)val;
2638 }
2639 *lvalp = jiffies_to_msecs(lval);
2640 }
2641 return 0;
2642}
2643
2644/**
2645 * proc_dointvec_jiffies - read a vector of integers as seconds
2646 * @table: the sysctl table
2647 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 * @buffer: the user buffer
2649 * @lenp: the size of the user buffer
2650 * @ppos: file position
2651 *
2652 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2653 * values from/to the user buffer, treated as an ASCII string.
2654 * The values read are assumed to be in seconds, and are converted into
2655 * jiffies.
2656 *
2657 * Returns 0 on success.
2658 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002659int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 void __user *buffer, size_t *lenp, loff_t *ppos)
2661{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002662 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 do_proc_dointvec_jiffies_conv,NULL);
2664}
2665
2666/**
2667 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2668 * @table: the sysctl table
2669 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 * @buffer: the user buffer
2671 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002672 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 *
2674 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2675 * values from/to the user buffer, treated as an ASCII string.
2676 * The values read are assumed to be in 1/USER_HZ seconds, and
2677 * are converted into jiffies.
2678 *
2679 * Returns 0 on success.
2680 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002681int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 void __user *buffer, size_t *lenp, loff_t *ppos)
2683{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002684 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 do_proc_dointvec_userhz_jiffies_conv,NULL);
2686}
2687
2688/**
2689 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2690 * @table: the sysctl table
2691 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 * @buffer: the user buffer
2693 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002694 * @ppos: file position
2695 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 *
2697 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2698 * values from/to the user buffer, treated as an ASCII string.
2699 * The values read are assumed to be in 1/1000 seconds, and
2700 * are converted into jiffies.
2701 *
2702 * Returns 0 on success.
2703 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002704int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 void __user *buffer, size_t *lenp, loff_t *ppos)
2706{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002707 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 do_proc_dointvec_ms_jiffies_conv, NULL);
2709}
2710
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002711static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002712 void __user *buffer, size_t *lenp, loff_t *ppos)
2713{
2714 struct pid *new_pid;
2715 pid_t tmp;
2716 int r;
2717
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002718 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002719
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002720 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002721 lenp, ppos, NULL, NULL);
2722 if (r || !write)
2723 return r;
2724
2725 new_pid = find_get_pid(tmp);
2726 if (!new_pid)
2727 return -ESRCH;
2728
2729 put_pid(xchg(&cad_pid, new_pid));
2730 return 0;
2731}
2732
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002733/**
2734 * proc_do_large_bitmap - read/write from/to a large bitmap
2735 * @table: the sysctl table
2736 * @write: %TRUE if this is a write to the sysctl file
2737 * @buffer: the user buffer
2738 * @lenp: the size of the user buffer
2739 * @ppos: file position
2740 *
2741 * The bitmap is stored at table->data and the bitmap length (in bits)
2742 * in table->maxlen.
2743 *
2744 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2745 * large bitmaps may be represented in a compact manner. Writing into
2746 * the file will clear the bitmap then update it with the given input.
2747 *
2748 * Returns 0 on success.
2749 */
2750int proc_do_large_bitmap(struct ctl_table *table, int write,
2751 void __user *buffer, size_t *lenp, loff_t *ppos)
2752{
2753 int err = 0;
2754 bool first = 1;
2755 size_t left = *lenp;
2756 unsigned long bitmap_len = table->maxlen;
2757 unsigned long *bitmap = (unsigned long *) table->data;
2758 unsigned long *tmp_bitmap = NULL;
2759 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2760
2761 if (!bitmap_len || !left || (*ppos && !write)) {
2762 *lenp = 0;
2763 return 0;
2764 }
2765
2766 if (write) {
2767 unsigned long page = 0;
2768 char *kbuf;
2769
2770 if (left > PAGE_SIZE - 1)
2771 left = PAGE_SIZE - 1;
2772
2773 page = __get_free_page(GFP_TEMPORARY);
2774 kbuf = (char *) page;
2775 if (!kbuf)
2776 return -ENOMEM;
2777 if (copy_from_user(kbuf, buffer, left)) {
2778 free_page(page);
2779 return -EFAULT;
2780 }
2781 kbuf[left] = 0;
2782
2783 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2784 GFP_KERNEL);
2785 if (!tmp_bitmap) {
2786 free_page(page);
2787 return -ENOMEM;
2788 }
2789 proc_skip_char(&kbuf, &left, '\n');
2790 while (!err && left) {
2791 unsigned long val_a, val_b;
2792 bool neg;
2793
2794 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2795 sizeof(tr_a), &c);
2796 if (err)
2797 break;
2798 if (val_a >= bitmap_len || neg) {
2799 err = -EINVAL;
2800 break;
2801 }
2802
2803 val_b = val_a;
2804 if (left) {
2805 kbuf++;
2806 left--;
2807 }
2808
2809 if (c == '-') {
2810 err = proc_get_long(&kbuf, &left, &val_b,
2811 &neg, tr_b, sizeof(tr_b),
2812 &c);
2813 if (err)
2814 break;
2815 if (val_b >= bitmap_len || neg ||
2816 val_a > val_b) {
2817 err = -EINVAL;
2818 break;
2819 }
2820 if (left) {
2821 kbuf++;
2822 left--;
2823 }
2824 }
2825
2826 while (val_a <= val_b)
2827 set_bit(val_a++, tmp_bitmap);
2828
2829 first = 0;
2830 proc_skip_char(&kbuf, &left, '\n');
2831 }
2832 free_page(page);
2833 } else {
2834 unsigned long bit_a, bit_b = 0;
2835
2836 while (left) {
2837 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2838 if (bit_a >= bitmap_len)
2839 break;
2840 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2841 bit_a + 1) - 1;
2842
2843 if (!first) {
2844 err = proc_put_char(&buffer, &left, ',');
2845 if (err)
2846 break;
2847 }
2848 err = proc_put_long(&buffer, &left, bit_a, false);
2849 if (err)
2850 break;
2851 if (bit_a != bit_b) {
2852 err = proc_put_char(&buffer, &left, '-');
2853 if (err)
2854 break;
2855 err = proc_put_long(&buffer, &left, bit_b, false);
2856 if (err)
2857 break;
2858 }
2859
2860 first = 0; bit_b++;
2861 }
2862 if (!err)
2863 err = proc_put_char(&buffer, &left, '\n');
2864 }
2865
2866 if (!err) {
2867 if (write) {
2868 if (*ppos)
2869 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2870 else
2871 memcpy(bitmap, tmp_bitmap,
2872 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2873 }
2874 kfree(tmp_bitmap);
2875 *lenp -= left;
2876 *ppos += *lenp;
2877 return 0;
2878 } else {
2879 kfree(tmp_bitmap);
2880 return err;
2881 }
2882}
2883
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884#else /* CONFIG_PROC_FS */
2885
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002886int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 void __user *buffer, size_t *lenp, loff_t *ppos)
2888{
2889 return -ENOSYS;
2890}
2891
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002892int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 void __user *buffer, size_t *lenp, loff_t *ppos)
2894{
2895 return -ENOSYS;
2896}
2897
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002898int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 void __user *buffer, size_t *lenp, loff_t *ppos)
2900{
2901 return -ENOSYS;
2902}
2903
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002904int proc_dointvec_jiffies(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_userhz_jiffies(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_ms_jiffies(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_doulongvec_minmax(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
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002928int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 void __user *buffer,
2930 size_t *lenp, loff_t *ppos)
2931{
2932 return -ENOSYS;
2933}
2934
2935
2936#endif /* CONFIG_PROC_FS */
2937
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938/*
2939 * No sense putting this after each symbol definition, twice,
2940 * exception granted :-)
2941 */
2942EXPORT_SYMBOL(proc_dointvec);
2943EXPORT_SYMBOL(proc_dointvec_jiffies);
2944EXPORT_SYMBOL(proc_dointvec_minmax);
2945EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2946EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2947EXPORT_SYMBOL(proc_dostring);
2948EXPORT_SYMBOL(proc_doulongvec_minmax);
2949EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2950EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002951EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952EXPORT_SYMBOL(unregister_sysctl_table);