blob: 284f330d6a018c3bc1327408d83a367ea2556080 [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>
47#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070048#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080049#include <linux/nfs_fs.h>
50#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070051#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020052#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010053#include <linux/slow-work.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
58#include <asm/uaccess.h>
59#include <asm/processor.h>
60
Andi Kleen29cbc782006-09-30 01:47:55 +020061#ifdef CONFIG_X86
62#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010063#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010064#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020065#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080066#ifdef CONFIG_BSD_PROCESS_ACCT
67#include <linux/acct.h>
68#endif
Dave Young4f0e0562010-03-10 15:24:09 -080069#ifdef CONFIG_RT_MUTEXES
70#include <linux/rtmutex.h>
71#endif
Dave Young2edf5e42010-03-10 15:24:10 -080072#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
73#include <linux/lockdep.h>
74#endif
Dave Young15485a42010-03-10 15:24:07 -080075#ifdef CONFIG_CHR_DEV_SG
76#include <scsi/sg.h>
77#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020078
Eric W. Biederman7058cb02007-10-18 03:05:58 -070079
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#if defined(CONFIG_SYSCTL)
81
82/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083extern int sysctl_overcommit_memory;
84extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070085extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070086extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080087extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070090extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070092extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093extern int pid_max;
94extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080096extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080097extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020098extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010099extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400100extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000101#ifndef CONFIG_MMU
102extern int sysctl_nr_trim_pages;
103#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200104#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200105extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200106#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700108/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -0800109#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700110static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200111static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700112#endif
113
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700114static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700115static int __maybe_unused one = 1;
116static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800117static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700119#ifdef CONFIG_PRINTK
120static int ten_thousand = 10000;
121#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700123/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
124static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
127static int maxolduid = 65535;
128static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800129static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131static int ngroups_max = NGROUPS_MAX;
132
David S. Miller72c57ed2008-09-11 23:29:54 -0700133#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700134#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#endif
136
David S. Miller08714202008-11-16 23:49:24 -0800137#ifdef CONFIG_SPARC64
138extern int sysctl_tsb_ratio;
139#endif
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#ifdef __hppa__
142extern int pwrsw_enabled;
143extern int unaligned_enabled;
144#endif
145
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800146#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#ifdef CONFIG_MATHEMU
148extern int sysctl_ieee_emulation_warnings;
149#endif
150extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700151extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#endif
153
Jes Sorensend2b176e2006-02-28 09:42:23 -0800154#ifdef CONFIG_IA64
155extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800156extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800157#endif
158
Ingo Molnar3fff4c42009-09-22 16:18:09 +0200159extern struct ratelimit_state printk_ratelimit_state;
160
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700161#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700162static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700163 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700164static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800165 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700166#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700167
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700168#ifdef CONFIG_MAGIC_SYSRQ
169static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
170
171static int sysrq_sysctl_handler(ctl_table *table, int write,
172 void __user *buffer, size_t *lenp,
173 loff_t *ppos)
174{
175 int error;
176
177 error = proc_dointvec(table, write, buffer, lenp, ppos);
178 if (error)
179 return error;
180
181 if (write)
182 sysrq_toggle_support(__sysrq_enabled);
183
184 return 0;
185}
186
187#endif
188
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700189static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100190static struct ctl_table_root sysctl_table_root;
191static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100192 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100193 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400194 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100195 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400196 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100197};
198static struct ctl_table_root sysctl_table_root = {
199 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400200 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100201};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700203static struct ctl_table kern_table[];
204static struct ctl_table vm_table[];
205static struct ctl_table fs_table[];
206static struct ctl_table debug_table[];
207static struct ctl_table dev_table[];
208extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700209#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700210extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400211#endif
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;
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100262static int min_sched_shares_ratelimit = 100000; /* 100 usec */
263static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200264#endif
265
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700266static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200267 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200268 .procname = "sched_child_runs_first",
269 .data = &sysctl_sched_child_runs_first,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800272 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200273 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200274#ifdef CONFIG_SCHED_DEBUG
275 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100276 .procname = "sched_min_granularity_ns",
277 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800280 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200283 },
284 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200285 .procname = "sched_latency_ns",
286 .data = &sysctl_sched_latency,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800289 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
292 },
293 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200294 .procname = "sched_wakeup_granularity_ns",
295 .data = &sysctl_sched_wakeup_granularity,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800298 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299 .extra1 = &min_wakeup_granularity_ns,
300 .extra2 = &max_wakeup_granularity_ns,
301 },
302 {
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200303 .procname = "sched_shares_ratelimit",
304 .data = &sysctl_sched_shares_ratelimit,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800307 .proc_handler = sched_proc_update_handler,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100308 .extra1 = &min_sched_shares_ratelimit,
309 .extra2 = &max_sched_shares_ratelimit,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200310 },
311 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100312 .procname = "sched_tunable_scaling",
313 .data = &sysctl_sched_tunable_scaling,
314 .maxlen = sizeof(enum sched_tunable_scaling),
315 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800316 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200319 },
320 {
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200321 .procname = "sched_shares_thresh",
322 .data = &sysctl_sched_shares_thresh,
323 .maxlen = sizeof(unsigned int),
324 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800325 .proc_handler = proc_dointvec_minmax,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200326 .extra1 = &zero,
327 },
328 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200329 .procname = "sched_migration_cost",
330 .data = &sysctl_sched_migration_cost,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800333 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200334 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100335 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100336 .procname = "sched_nr_migrate",
337 .data = &sysctl_sched_nr_migrate,
338 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100339 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800340 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100341 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530342 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200343 .procname = "sched_time_avg",
344 .data = &sysctl_sched_time_avg,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800347 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200348 },
349 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530350 .procname = "timer_migration",
351 .data = &sysctl_timer_migration,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800354 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530355 .extra1 = &zero,
356 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530357 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200358#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200359 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100360 .procname = "sched_rt_period_us",
361 .data = &sysctl_sched_rt_period,
362 .maxlen = sizeof(unsigned int),
363 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800364 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100365 },
366 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100367 .procname = "sched_rt_runtime_us",
368 .data = &sysctl_sched_rt_runtime,
369 .maxlen = sizeof(int),
370 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800371 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100372 },
373 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200374 .procname = "sched_compat_yield",
375 .data = &sysctl_sched_compat_yield,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800378 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200379 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700380#ifdef CONFIG_PROVE_LOCKING
381 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700382 .procname = "prove_locking",
383 .data = &prove_locking,
384 .maxlen = sizeof(int),
385 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800386 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700387 },
388#endif
389#ifdef CONFIG_LOCK_STAT
390 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700391 .procname = "lock_stat",
392 .data = &lock_stat,
393 .maxlen = sizeof(int),
394 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800395 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700396 },
397#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .procname = "panic",
400 .data = &panic_timeout,
401 .maxlen = sizeof(int),
402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800403 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 },
405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .procname = "core_uses_pid",
407 .data = &core_uses_pid,
408 .maxlen = sizeof(int),
409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800410 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 },
412 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 .procname = "core_pattern",
414 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700415 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800417 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 },
Neil Hormana2939802009-09-23 15:56:56 -0700419 {
Neil Hormana2939802009-09-23 15:56:56 -0700420 .procname = "core_pipe_limit",
421 .data = &core_pipe_limit,
422 .maxlen = sizeof(unsigned int),
423 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800424 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700425 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800426#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700429 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800431 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800433#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100434#ifdef CONFIG_LATENCYTOP
435 {
436 .procname = "latencytop",
437 .data = &latencytop_enabled,
438 .maxlen = sizeof(int),
439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800440 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100441 },
442#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#ifdef CONFIG_BLK_DEV_INITRD
444 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 .procname = "real-root-dev",
446 .data = &real_root_dev,
447 .maxlen = sizeof(int),
448 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800449 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 },
451#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700452 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700453 .procname = "print-fatal-signals",
454 .data = &print_fatal_signals,
455 .maxlen = sizeof(int),
456 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800457 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700458 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700459#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 .procname = "reboot-cmd",
462 .data = reboot_command,
463 .maxlen = 256,
464 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800465 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 },
467 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 .procname = "stop-a",
469 .data = &stop_a_enabled,
470 .maxlen = sizeof (int),
471 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800472 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 },
474 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .procname = "scons-poweroff",
476 .data = &scons_pwroff,
477 .maxlen = sizeof (int),
478 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800479 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 },
481#endif
David S. Miller08714202008-11-16 23:49:24 -0800482#ifdef CONFIG_SPARC64
483 {
David S. Miller08714202008-11-16 23:49:24 -0800484 .procname = "tsb-ratio",
485 .data = &sysctl_tsb_ratio,
486 .maxlen = sizeof (int),
487 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800488 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800489 },
490#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#ifdef __hppa__
492 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .procname = "soft-power",
494 .data = &pwrsw_enabled,
495 .maxlen = sizeof (int),
496 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800497 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 },
499 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .procname = "unaligned-trap",
501 .data = &unaligned_enabled,
502 .maxlen = sizeof (int),
503 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800504 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 },
506#endif
507 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .procname = "ctrl-alt-del",
509 .data = &C_A_D,
510 .maxlen = sizeof(int),
511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800512 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400514#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200515 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200516 .procname = "ftrace_enabled",
517 .data = &ftrace_enabled,
518 .maxlen = sizeof(int),
519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800520 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200521 },
522#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500523#ifdef CONFIG_STACK_TRACER
524 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500525 .procname = "stack_tracer_enabled",
526 .data = &stack_tracer_enabled,
527 .maxlen = sizeof(int),
528 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800529 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500530 },
531#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400532#ifdef CONFIG_TRACING
533 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100534 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400535 .data = &ftrace_dump_on_oops,
536 .maxlen = sizeof(int),
537 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800538 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400539 },
540#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200541#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 .procname = "modprobe",
544 .data = &modprobe_path,
545 .maxlen = KMOD_PATH_LEN,
546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800547 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 },
Kees Cook3d433212009-04-02 15:49:29 -0700549 {
Kees Cook3d433212009-04-02 15:49:29 -0700550 .procname = "modules_disabled",
551 .data = &modules_disabled,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800555 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700556 .extra1 = &one,
557 .extra2 = &one,
558 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700560#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100563 .data = &uevent_helper,
564 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800566 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 },
568#endif
569#ifdef CONFIG_CHR_DEV_SG
570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .procname = "sg-big-buff",
572 .data = &sg_big_buff,
573 .maxlen = sizeof (int),
574 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800575 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 },
577#endif
578#ifdef CONFIG_BSD_PROCESS_ACCT
579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .procname = "acct",
581 .data = &acct_parm,
582 .maxlen = 3*sizeof(int),
583 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800584 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 },
586#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587#ifdef CONFIG_MAGIC_SYSRQ
588 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800590 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 .maxlen = sizeof (int),
592 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700593 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 },
595#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700596#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700599 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .maxlen = sizeof (int),
601 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800602 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700604#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .procname = "threads-max",
607 .data = &max_threads,
608 .maxlen = sizeof(int),
609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800610 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 },
612 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 .procname = "random",
614 .mode = 0555,
615 .child = random_table,
616 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 .procname = "overflowuid",
619 .data = &overflowuid,
620 .maxlen = sizeof(int),
621 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800622 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 .extra1 = &minolduid,
624 .extra2 = &maxolduid,
625 },
626 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 .procname = "overflowgid",
628 .data = &overflowgid,
629 .maxlen = sizeof(int),
630 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800631 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .extra1 = &minolduid,
633 .extra2 = &maxolduid,
634 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800635#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636#ifdef CONFIG_MATHEMU
637 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 .procname = "ieee_emulation_warnings",
639 .data = &sysctl_ieee_emulation_warnings,
640 .maxlen = sizeof(int),
641 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800642 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 },
644#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200647 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 .maxlen = sizeof(int),
649 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800650 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 },
652#endif
653 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 .procname = "pid_max",
655 .data = &pid_max,
656 .maxlen = sizeof (int),
657 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800658 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .extra1 = &pid_max_min,
660 .extra2 = &pid_max_max,
661 },
662 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .procname = "panic_on_oops",
664 .data = &panic_on_oops,
665 .maxlen = sizeof(int),
666 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800667 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800669#if defined CONFIG_PRINTK
670 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800671 .procname = "printk",
672 .data = &console_loglevel,
673 .maxlen = 4*sizeof(int),
674 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800675 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800676 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700679 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 .maxlen = sizeof(int),
681 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800682 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 },
684 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700686 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .maxlen = sizeof(int),
688 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800689 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 },
Dave Youngaf913222009-09-22 16:43:33 -0700691 {
Dave Youngaf913222009-09-22 16:43:33 -0700692 .procname = "printk_delay",
693 .data = &printk_delay_msec,
694 .maxlen = sizeof(int),
695 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800696 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700697 .extra1 = &zero,
698 .extra2 = &ten_thousand,
699 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800700#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .procname = "ngroups_max",
703 .data = &ngroups_max,
704 .maxlen = sizeof (int),
705 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800706 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
708#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .procname = "unknown_nmi_panic",
711 .data = &unknown_nmi_panic,
712 .maxlen = sizeof (int),
713 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800714 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 },
Don Zickus407984f2006-09-26 10:52:27 +0200716 {
Don Zickus407984f2006-09-26 10:52:27 +0200717 .procname = "nmi_watchdog",
718 .data = &nmi_watchdog_enabled,
719 .maxlen = sizeof (int),
720 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800721 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 },
723#endif
724#if defined(CONFIG_X86)
725 {
Don Zickus8da5add2006-09-26 10:52:27 +0200726 .procname = "panic_on_unrecovered_nmi",
727 .data = &panic_on_unrecovered_nmi,
728 .maxlen = sizeof(int),
729 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800730 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200731 },
732 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700733 .procname = "panic_on_io_nmi",
734 .data = &panic_on_io_nmi,
735 .maxlen = sizeof(int),
736 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800737 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700738 },
739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .procname = "bootloader_type",
741 .data = &bootloader_type,
742 .maxlen = sizeof (int),
743 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800744 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100746 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700747 .procname = "bootloader_version",
748 .data = &bootloader_version,
749 .maxlen = sizeof (int),
750 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800751 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700752 },
753 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100754 .procname = "kstack_depth_to_print",
755 .data = &kstack_depth_to_print,
756 .maxlen = sizeof(int),
757 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800758 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100759 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100760 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100761 .procname = "io_delay_type",
762 .data = &io_delay_type,
763 .maxlen = sizeof(int),
764 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800765 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100766 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800768#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 .procname = "randomize_va_space",
771 .data = &randomize_va_space,
772 .maxlen = sizeof(int),
773 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800774 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800776#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800777#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700778 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700779 .procname = "spin_retry",
780 .data = &spin_retry,
781 .maxlen = sizeof (int),
782 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800783 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700784 },
785#endif
Len Brown673d5b42007-07-28 03:33:16 -0400786#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800787 {
Pavel Machekc255d842006-02-20 18:27:58 -0800788 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700789 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800790 .maxlen = sizeof (unsigned long),
791 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800792 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800793 },
794#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800795#ifdef CONFIG_IA64
796 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800797 .procname = "ignore-unaligned-usertrap",
798 .data = &no_unaligned_warning,
799 .maxlen = sizeof (int),
800 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800802 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800803 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800804 .procname = "unaligned-dump-stack",
805 .data = &unaligned_dump_stack,
806 .maxlen = sizeof (int),
807 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800808 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800809 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800810#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700811#ifdef CONFIG_DETECT_SOFTLOCKUP
812 {
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200813 .procname = "softlockup_panic",
814 .data = &softlockup_panic,
815 .maxlen = sizeof(int),
816 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800817 .proc_handler = proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200818 .extra1 = &zero,
819 .extra2 = &one,
820 },
821 {
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700822 .procname = "softlockup_thresh",
823 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200824 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700825 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800826 .proc_handler = proc_dosoftlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200827 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700828 .extra2 = &sixty,
829 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800830#endif
831#ifdef CONFIG_DETECT_HUNG_TASK
832 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800833 .procname = "hung_task_panic",
834 .data = &sysctl_hung_task_panic,
835 .maxlen = sizeof(int),
836 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800837 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800838 .extra1 = &zero,
839 .extra2 = &one,
840 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100841 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100842 .procname = "hung_task_check_count",
843 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100844 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100845 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800846 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100847 },
848 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100849 .procname = "hung_task_timeout_secs",
850 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100851 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100852 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800853 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100854 },
855 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100856 .procname = "hung_task_warnings",
857 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100858 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100859 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800860 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700862#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200863#ifdef CONFIG_COMPAT
864 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200865 .procname = "compat-log",
866 .data = &compat_log,
867 .maxlen = sizeof (int),
868 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800869 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200870 },
871#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700872#ifdef CONFIG_RT_MUTEXES
873 {
Ingo Molnar23f78d42006-06-27 02:54:53 -0700874 .procname = "max_lock_depth",
875 .data = &max_lock_depth,
876 .maxlen = sizeof(int),
877 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800878 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -0700879 },
880#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700881 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700882 .procname = "poweroff_cmd",
883 .data = &poweroff_cmd,
884 .maxlen = POWEROFF_CMD_PATH_LEN,
885 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800886 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700887 },
David Howells0b77f5b2008-04-29 01:01:32 -0700888#ifdef CONFIG_KEYS
889 {
David Howells0b77f5b2008-04-29 01:01:32 -0700890 .procname = "keys",
891 .mode = 0555,
892 .child = key_sysctls,
893 },
894#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700895#ifdef CONFIG_RCU_TORTURE_TEST
896 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700897 .procname = "rcutorture_runnable",
898 .data = &rcutorture_runnable,
899 .maxlen = sizeof(int),
900 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800901 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700902 },
903#endif
David Howells12e22c52009-04-03 16:42:35 +0100904#ifdef CONFIG_SLOW_WORK
905 {
David Howells12e22c52009-04-03 16:42:35 +0100906 .procname = "slow-work",
907 .mode = 0555,
908 .child = slow_work_sysctls,
909 },
910#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200911#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200912 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200913 .procname = "perf_event_paranoid",
914 .data = &sysctl_perf_event_paranoid,
915 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200916 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800917 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200918 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200919 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200920 .procname = "perf_event_mlock_kb",
921 .data = &sysctl_perf_event_mlock,
922 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200923 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800924 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200925 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200926 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200927 .procname = "perf_event_max_sample_rate",
928 .data = &sysctl_perf_event_sample_rate,
929 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200930 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800931 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200932 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200933#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200934#ifdef CONFIG_KMEMCHECK
935 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200936 .procname = "kmemcheck",
937 .data = &kmemcheck_enabled,
938 .maxlen = sizeof(int),
939 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800940 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200941 },
942#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200943#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200944 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200945 .procname = "blk_iopoll",
946 .data = &blk_iopoll_enabled,
947 .maxlen = sizeof(int),
948 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800949 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200950 },
Jens Axboecb684b52009-09-15 21:53:11 +0200951#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700952/*
953 * NOTE: do not add new entries to this table unless you have read
954 * Documentation/sysctl/ctl_unnumbered.txt
955 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700956 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957};
958
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700959static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 .procname = "overcommit_memory",
962 .data = &sysctl_overcommit_memory,
963 .maxlen = sizeof(sysctl_overcommit_memory),
964 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800965 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 },
967 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700968 .procname = "panic_on_oom",
969 .data = &sysctl_panic_on_oom,
970 .maxlen = sizeof(sysctl_panic_on_oom),
971 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800972 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700973 },
974 {
David Rientjesfe071d72007-10-16 23:25:56 -0700975 .procname = "oom_kill_allocating_task",
976 .data = &sysctl_oom_kill_allocating_task,
977 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
978 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800979 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700980 },
981 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800982 .procname = "oom_dump_tasks",
983 .data = &sysctl_oom_dump_tasks,
984 .maxlen = sizeof(sysctl_oom_dump_tasks),
985 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800986 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -0800987 },
988 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 .procname = "overcommit_ratio",
990 .data = &sysctl_overcommit_ratio,
991 .maxlen = sizeof(sysctl_overcommit_ratio),
992 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800993 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 },
995 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 .procname = "page-cluster",
997 .data = &page_cluster,
998 .maxlen = sizeof(int),
999 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001000 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 },
1002 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 .procname = "dirty_background_ratio",
1004 .data = &dirty_background_ratio,
1005 .maxlen = sizeof(dirty_background_ratio),
1006 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001007 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 .extra1 = &zero,
1009 .extra2 = &one_hundred,
1010 },
1011 {
David Rientjes2da02992009-01-06 14:39:31 -08001012 .procname = "dirty_background_bytes",
1013 .data = &dirty_background_bytes,
1014 .maxlen = sizeof(dirty_background_bytes),
1015 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001016 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001017 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001018 },
1019 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 .procname = "dirty_ratio",
1021 .data = &vm_dirty_ratio,
1022 .maxlen = sizeof(vm_dirty_ratio),
1023 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001024 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 .extra1 = &zero,
1026 .extra2 = &one_hundred,
1027 },
1028 {
David Rientjes2da02992009-01-06 14:39:31 -08001029 .procname = "dirty_bytes",
1030 .data = &vm_dirty_bytes,
1031 .maxlen = sizeof(vm_dirty_bytes),
1032 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001033 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001034 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001035 },
1036 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001038 .data = &dirty_writeback_interval,
1039 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 },
1043 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001045 .data = &dirty_expire_interval,
1046 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001048 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 },
1050 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 .procname = "nr_pdflush_threads",
1052 .data = &nr_pdflush_threads,
1053 .maxlen = sizeof nr_pdflush_threads,
1054 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001055 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 },
1057 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 .procname = "swappiness",
1059 .data = &vm_swappiness,
1060 .maxlen = sizeof(vm_swappiness),
1061 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001062 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 .extra1 = &zero,
1064 .extra2 = &one_hundred,
1065 },
1066#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001067 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001069 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 .maxlen = sizeof(unsigned long),
1071 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001072 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 .extra1 = (void *)&hugetlb_zero,
1074 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001075 },
1076#ifdef CONFIG_NUMA
1077 {
1078 .procname = "nr_hugepages_mempolicy",
1079 .data = NULL,
1080 .maxlen = sizeof(unsigned long),
1081 .mode = 0644,
1082 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1083 .extra1 = (void *)&hugetlb_zero,
1084 .extra2 = (void *)&hugetlb_infinity,
1085 },
1086#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 .procname = "hugetlb_shm_group",
1089 .data = &sysctl_hugetlb_shm_group,
1090 .maxlen = sizeof(gid_t),
1091 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001092 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 },
Mel Gorman396faf02007-07-17 04:03:13 -07001094 {
Mel Gorman396faf02007-07-17 04:03:13 -07001095 .procname = "hugepages_treat_as_movable",
1096 .data = &hugepages_treat_as_movable,
1097 .maxlen = sizeof(int),
1098 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001099 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001100 },
Adam Litke54f9f802007-10-16 01:26:20 -07001101 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001102 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001103 .data = NULL,
1104 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001105 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001106 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001107 .extra1 = (void *)&hugetlb_zero,
1108 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001109 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110#endif
1111 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 .procname = "lowmem_reserve_ratio",
1113 .data = &sysctl_lowmem_reserve_ratio,
1114 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1115 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001116 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 },
1118 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001119 .procname = "drop_caches",
1120 .data = &sysctl_drop_caches,
1121 .maxlen = sizeof(int),
1122 .mode = 0644,
1123 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001124 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001125#ifdef CONFIG_COMPACTION
1126 {
1127 .procname = "compact_memory",
1128 .data = &sysctl_compact_memory,
1129 .maxlen = sizeof(int),
1130 .mode = 0200,
1131 .proc_handler = sysctl_compaction_handler,
1132 },
1133#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001134 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 .procname = "min_free_kbytes",
1136 .data = &min_free_kbytes,
1137 .maxlen = sizeof(min_free_kbytes),
1138 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001139 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 .extra1 = &zero,
1141 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001142 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001143 .procname = "percpu_pagelist_fraction",
1144 .data = &percpu_pagelist_fraction,
1145 .maxlen = sizeof(percpu_pagelist_fraction),
1146 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001147 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001148 .extra1 = &min_percpu_pagelist_fract,
1149 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150#ifdef CONFIG_MMU
1151 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 .procname = "max_map_count",
1153 .data = &sysctl_max_map_count,
1154 .maxlen = sizeof(sysctl_max_map_count),
1155 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001156 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001157 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001159#else
1160 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001161 .procname = "nr_trim_pages",
1162 .data = &sysctl_nr_trim_pages,
1163 .maxlen = sizeof(sysctl_nr_trim_pages),
1164 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001165 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001166 .extra1 = &zero,
1167 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168#endif
1169 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 .procname = "laptop_mode",
1171 .data = &laptop_mode,
1172 .maxlen = sizeof(laptop_mode),
1173 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001174 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 },
1176 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 .procname = "block_dump",
1178 .data = &block_dump,
1179 .maxlen = sizeof(block_dump),
1180 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001181 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 .extra1 = &zero,
1183 },
1184 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 .procname = "vfs_cache_pressure",
1186 .data = &sysctl_vfs_cache_pressure,
1187 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1188 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001189 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 .extra1 = &zero,
1191 },
1192#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1193 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 .procname = "legacy_va_layout",
1195 .data = &sysctl_legacy_va_layout,
1196 .maxlen = sizeof(sysctl_legacy_va_layout),
1197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001198 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 .extra1 = &zero,
1200 },
1201#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001202#ifdef CONFIG_NUMA
1203 {
Christoph Lameter17436602006-01-18 17:42:32 -08001204 .procname = "zone_reclaim_mode",
1205 .data = &zone_reclaim_mode,
1206 .maxlen = sizeof(zone_reclaim_mode),
1207 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001208 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001209 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001210 },
Christoph Lameter96146342006-07-03 00:24:13 -07001211 {
Christoph Lameter96146342006-07-03 00:24:13 -07001212 .procname = "min_unmapped_ratio",
1213 .data = &sysctl_min_unmapped_ratio,
1214 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1215 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001216 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001217 .extra1 = &zero,
1218 .extra2 = &one_hundred,
1219 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001220 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001221 .procname = "min_slab_ratio",
1222 .data = &sysctl_min_slab_ratio,
1223 .maxlen = sizeof(sysctl_min_slab_ratio),
1224 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001225 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001226 .extra1 = &zero,
1227 .extra2 = &one_hundred,
1228 },
Christoph Lameter17436602006-01-18 17:42:32 -08001229#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001230#ifdef CONFIG_SMP
1231 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001232 .procname = "stat_interval",
1233 .data = &sysctl_stat_interval,
1234 .maxlen = sizeof(sysctl_stat_interval),
1235 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001236 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001237 },
1238#endif
David Howells6e141542009-12-15 19:27:45 +00001239#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001240 {
Eric Parised032182007-06-28 15:55:21 -04001241 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001242 .data = &dac_mmap_min_addr,
1243 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001244 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001245 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001246 },
David Howells6e141542009-12-15 19:27:45 +00001247#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001248#ifdef CONFIG_NUMA
1249 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001250 .procname = "numa_zonelist_order",
1251 .data = &numa_zonelist_order,
1252 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1253 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001254 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001255 },
1256#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001257#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001258 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001259 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001260 .procname = "vdso_enabled",
1261 .data = &vdso_enabled,
1262 .maxlen = sizeof(vdso_enabled),
1263 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001264 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001265 .extra1 = &zero,
1266 },
1267#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001268#ifdef CONFIG_HIGHMEM
1269 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001270 .procname = "highmem_is_dirtyable",
1271 .data = &vm_highmem_is_dirtyable,
1272 .maxlen = sizeof(vm_highmem_is_dirtyable),
1273 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001274 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001275 .extra1 = &zero,
1276 .extra2 = &one,
1277 },
1278#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001279 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001280 .procname = "scan_unevictable_pages",
1281 .data = &scan_unevictable_pages,
1282 .maxlen = sizeof(scan_unevictable_pages),
1283 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001284 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001285 },
Andi Kleen6a460792009-09-16 11:50:15 +02001286#ifdef CONFIG_MEMORY_FAILURE
1287 {
Andi Kleen6a460792009-09-16 11:50:15 +02001288 .procname = "memory_failure_early_kill",
1289 .data = &sysctl_memory_failure_early_kill,
1290 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1291 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001292 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001293 .extra1 = &zero,
1294 .extra2 = &one,
1295 },
1296 {
Andi Kleen6a460792009-09-16 11:50:15 +02001297 .procname = "memory_failure_recovery",
1298 .data = &sysctl_memory_failure_recovery,
1299 .maxlen = sizeof(sysctl_memory_failure_recovery),
1300 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001301 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001302 .extra1 = &zero,
1303 .extra2 = &one,
1304 },
1305#endif
1306
Andrew Morton2be7fe02007-07-15 23:41:21 -07001307/*
1308 * NOTE: do not add new entries to this table unless you have read
1309 * Documentation/sysctl/ctl_unnumbered.txt
1310 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001311 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312};
1313
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001314#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001315static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001316 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001317};
1318#endif
1319
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001320static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 .procname = "inode-nr",
1323 .data = &inodes_stat,
1324 .maxlen = 2*sizeof(int),
1325 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001326 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 },
1328 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 .procname = "inode-state",
1330 .data = &inodes_stat,
1331 .maxlen = 7*sizeof(int),
1332 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001333 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 },
1335 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 .procname = "file-nr",
1337 .data = &files_stat,
1338 .maxlen = 3*sizeof(int),
1339 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001340 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 },
1342 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 .procname = "file-max",
1344 .data = &files_stat.max_files,
1345 .maxlen = sizeof(int),
1346 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001347 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 },
1349 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001350 .procname = "nr_open",
1351 .data = &sysctl_nr_open,
1352 .maxlen = sizeof(int),
1353 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001354 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001355 .extra1 = &sysctl_nr_open_min,
1356 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001357 },
1358 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 .procname = "dentry-state",
1360 .data = &dentry_stat,
1361 .maxlen = 6*sizeof(int),
1362 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001363 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 },
1365 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 .procname = "overflowuid",
1367 .data = &fs_overflowuid,
1368 .maxlen = sizeof(int),
1369 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001370 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 .extra1 = &minolduid,
1372 .extra2 = &maxolduid,
1373 },
1374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 .procname = "overflowgid",
1376 .data = &fs_overflowgid,
1377 .maxlen = sizeof(int),
1378 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001379 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 .extra1 = &minolduid,
1381 .extra2 = &maxolduid,
1382 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001383#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 .procname = "leases-enable",
1386 .data = &leases_enable,
1387 .maxlen = sizeof(int),
1388 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001389 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001391#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392#ifdef CONFIG_DNOTIFY
1393 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .procname = "dir-notify-enable",
1395 .data = &dir_notify_enable,
1396 .maxlen = sizeof(int),
1397 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001398 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 },
1400#endif
1401#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001402#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 .procname = "lease-break-time",
1405 .data = &lease_break_time,
1406 .maxlen = sizeof(int),
1407 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001408 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001410#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001411#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 .procname = "aio-nr",
1414 .data = &aio_nr,
1415 .maxlen = sizeof(aio_nr),
1416 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001417 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 },
1419 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 .procname = "aio-max-nr",
1421 .data = &aio_max_nr,
1422 .maxlen = sizeof(aio_max_nr),
1423 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001424 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001426#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001427#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001428 {
Robert Love0399cb02005-07-13 12:38:18 -04001429 .procname = "inotify",
1430 .mode = 0555,
1431 .child = inotify_table,
1432 },
1433#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001434#ifdef CONFIG_EPOLL
1435 {
1436 .procname = "epoll",
1437 .mode = 0555,
1438 .child = epoll_table,
1439 },
1440#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001442 {
Alan Coxd6e71142005-06-23 00:09:43 -07001443 .procname = "suid_dumpable",
1444 .data = &suid_dumpable,
1445 .maxlen = sizeof(int),
1446 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001447 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001448 .extra1 = &zero,
1449 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001450 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001451#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1452 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001453 .procname = "binfmt_misc",
1454 .mode = 0555,
1455 .child = binfmt_misc_table,
1456 },
1457#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001458 {
1459 .procname = "pipe-max-pages",
1460 .data = &pipe_max_pages,
1461 .maxlen = sizeof(int),
1462 .mode = 0644,
1463 .proc_handler = &proc_dointvec_minmax,
1464 .extra1 = &two,
1465 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001466/*
1467 * NOTE: do not add new entries to this table unless you have read
1468 * Documentation/sysctl/ctl_unnumbered.txt
1469 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001470 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471};
1472
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001473static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001474#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1475 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001476 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001477 .procname = "exception-trace",
1478 .data = &show_unhandled_signals,
1479 .maxlen = sizeof(int),
1480 .mode = 0644,
1481 .proc_handler = proc_dointvec
1482 },
1483#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001484#if defined(CONFIG_OPTPROBES)
1485 {
1486 .procname = "kprobes-optimization",
1487 .data = &sysctl_kprobes_optimization,
1488 .maxlen = sizeof(int),
1489 .mode = 0644,
1490 .proc_handler = proc_kprobes_optimization_handler,
1491 .extra1 = &zero,
1492 .extra2 = &one,
1493 },
1494#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001495 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496};
1497
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001498static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001499 { }
Robert Love0eeca282005-07-12 17:06:03 -04001500};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Al Viro330d57f2005-11-04 10:18:40 +00001502static DEFINE_SPINLOCK(sysctl_lock);
1503
1504/* called under sysctl_lock */
1505static int use_table(struct ctl_table_header *p)
1506{
1507 if (unlikely(p->unregistering))
1508 return 0;
1509 p->used++;
1510 return 1;
1511}
1512
1513/* called under sysctl_lock */
1514static void unuse_table(struct ctl_table_header *p)
1515{
1516 if (!--p->used)
1517 if (unlikely(p->unregistering))
1518 complete(p->unregistering);
1519}
1520
1521/* called under sysctl_lock, will reacquire if has to wait */
1522static void start_unregistering(struct ctl_table_header *p)
1523{
1524 /*
1525 * if p->used is 0, nobody will ever touch that entry again;
1526 * we'll eliminate all paths to it before dropping sysctl_lock
1527 */
1528 if (unlikely(p->used)) {
1529 struct completion wait;
1530 init_completion(&wait);
1531 p->unregistering = &wait;
1532 spin_unlock(&sysctl_lock);
1533 wait_for_completion(&wait);
1534 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001535 } else {
1536 /* anything non-NULL; we'll never dereference it */
1537 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001538 }
1539 /*
1540 * do not remove from the list until nobody holds it; walking the
1541 * list in do_sysctl() relies on that.
1542 */
1543 list_del_init(&p->ctl_entry);
1544}
1545
Al Virof7e6ced2008-07-15 01:44:23 -04001546void sysctl_head_get(struct ctl_table_header *head)
1547{
1548 spin_lock(&sysctl_lock);
1549 head->count++;
1550 spin_unlock(&sysctl_lock);
1551}
1552
1553void sysctl_head_put(struct ctl_table_header *head)
1554{
1555 spin_lock(&sysctl_lock);
1556 if (!--head->count)
1557 kfree(head);
1558 spin_unlock(&sysctl_lock);
1559}
1560
1561struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1562{
1563 if (!head)
1564 BUG();
1565 spin_lock(&sysctl_lock);
1566 if (!use_table(head))
1567 head = ERR_PTR(-ENOENT);
1568 spin_unlock(&sysctl_lock);
1569 return head;
1570}
1571
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001572void sysctl_head_finish(struct ctl_table_header *head)
1573{
1574 if (!head)
1575 return;
1576 spin_lock(&sysctl_lock);
1577 unuse_table(head);
1578 spin_unlock(&sysctl_lock);
1579}
1580
Al Viro73455092008-07-14 21:22:20 -04001581static struct ctl_table_set *
1582lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1583{
1584 struct ctl_table_set *set = &root->default_set;
1585 if (root->lookup)
1586 set = root->lookup(root, namespaces);
1587 return set;
1588}
1589
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001590static struct list_head *
1591lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001592{
Al Viro73455092008-07-14 21:22:20 -04001593 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1594 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001595}
1596
1597struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1598 struct ctl_table_header *prev)
1599{
1600 struct ctl_table_root *root;
1601 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001602 struct ctl_table_header *head;
1603 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001604
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001605 spin_lock(&sysctl_lock);
1606 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001607 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001608 tmp = &prev->ctl_entry;
1609 unuse_table(prev);
1610 goto next;
1611 }
1612 tmp = &root_table_header.ctl_entry;
1613 for (;;) {
1614 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1615
1616 if (!use_table(head))
1617 goto next;
1618 spin_unlock(&sysctl_lock);
1619 return head;
1620 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001621 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001622 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001623 header_list = lookup_header_list(root, namespaces);
1624 if (tmp != header_list)
1625 continue;
1626
1627 do {
1628 root = list_entry(root->root_list.next,
1629 struct ctl_table_root, root_list);
1630 if (root == &sysctl_table_root)
1631 goto out;
1632 header_list = lookup_header_list(root, namespaces);
1633 } while (list_empty(header_list));
1634 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001635 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001636out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001637 spin_unlock(&sysctl_lock);
1638 return NULL;
1639}
1640
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001641struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1642{
1643 return __sysctl_head_next(current->nsproxy, prev);
1644}
1645
1646void register_sysctl_root(struct ctl_table_root *root)
1647{
1648 spin_lock(&sysctl_lock);
1649 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1650 spin_unlock(&sysctl_lock);
1651}
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001654 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 * some sysctl variables are readonly even to root.
1656 */
1657
1658static int test_perm(int mode, int op)
1659{
David Howells76aac0e2008-11-14 10:39:12 +11001660 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 mode >>= 6;
1662 else if (in_egroup_p(0))
1663 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001664 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 return 0;
1666 return -EACCES;
1667}
1668
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001669int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
1671 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001672 int mode;
1673
Al Viroe6305c42008-07-15 21:03:57 -04001674 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 if (error)
1676 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001677
1678 if (root->permissions)
1679 mode = root->permissions(root, current->nsproxy, table);
1680 else
1681 mode = table->mode;
1682
1683 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
1685
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001686static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1687{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001688 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001689 table->parent = parent;
1690 if (table->child)
1691 sysctl_set_parent(table, table->child);
1692 }
1693}
1694
1695static __init int sysctl_init(void)
1696{
1697 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001698#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1699 {
1700 int err;
1701 err = sysctl_check_table(current->nsproxy, root_table);
1702 }
1703#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001704 return 0;
1705}
1706
1707core_initcall(sysctl_init);
1708
Al Virobfbcf032008-07-27 06:31:22 +01001709static struct ctl_table *is_branch_in(struct ctl_table *branch,
1710 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001711{
1712 struct ctl_table *p;
1713 const char *s = branch->procname;
1714
1715 /* branch should have named subdirectory as its first element */
1716 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001717 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001718
1719 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001720 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001721 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001722
1723 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001724 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001725 if (!p->child)
1726 continue;
1727 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001728 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001729 }
Al Virobfbcf032008-07-27 06:31:22 +01001730 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001731}
1732
1733/* see if attaching q to p would be an improvement */
1734static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1735{
1736 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001737 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001738 int is_better = 0;
1739 int not_in_parent = !p->attached_by;
1740
Al Virobfbcf032008-07-27 06:31:22 +01001741 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001742 if (by == q->attached_by)
1743 is_better = 1;
1744 if (to == p->attached_by)
1745 not_in_parent = 1;
1746 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001747 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001748 }
1749
1750 if (is_better && not_in_parent) {
1751 q->attached_by = by;
1752 q->attached_to = to;
1753 q->parent = p;
1754 }
1755}
1756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001758 * __register_sysctl_paths - register a sysctl hierarchy
1759 * @root: List of sysctl headers to register on
1760 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001761 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 *
1764 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001765 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001767 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1770 * enter a sysctl file
1771 *
1772 * data - a pointer to data for use by proc_handler
1773 *
1774 * maxlen - the maximum size in bytes of the data
1775 *
1776 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1777 *
1778 * child - a pointer to the child sysctl table if this entry is a directory, or
1779 * %NULL.
1780 *
1781 * proc_handler - the text handler routine (described below)
1782 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 * de - for internal use by the sysctl routines
1784 *
1785 * extra1, extra2 - extra pointers usable by the proc handler routines
1786 *
1787 * Leaf nodes in the sysctl tree will be represented by a single file
1788 * under /proc; non-leaf nodes will be represented by directories.
1789 *
1790 * sysctl(2) can automatically manage read and write requests through
1791 * the sysctl table. The data and maxlen fields of the ctl_table
1792 * struct enable minimal validation of the values being written to be
1793 * performed, and the mode field allows minimal authentication.
1794 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 * There must be a proc_handler routine for any terminal nodes
1796 * mirrored under /proc/sys (non-terminals are handled by a built-in
1797 * directory handler). Several default handlers are available to
1798 * cover common cases -
1799 *
1800 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1801 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1802 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1803 *
1804 * It is the handler's job to read the input buffer from user memory
1805 * and process it. The handler should return 0 on success.
1806 *
1807 * This routine returns %NULL on a failure to register, and a pointer
1808 * to the table header on success.
1809 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001810struct ctl_table_header *__register_sysctl_paths(
1811 struct ctl_table_root *root,
1812 struct nsproxy *namespaces,
1813 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001815 struct ctl_table_header *header;
1816 struct ctl_table *new, **prevp;
1817 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001818 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001819
1820 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001821 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001822 ;
1823
1824 /*
1825 * For each path component, allocate a 2-element ctl_table array.
1826 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001827 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001828 *
1829 * We allocate everything in one go so that we don't have to
1830 * worry about freeing additional memory in unregister_sysctl_table.
1831 */
1832 header = kzalloc(sizeof(struct ctl_table_header) +
1833 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1834 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001836
1837 new = (struct ctl_table *) (header + 1);
1838
1839 /* Now connect the dots */
1840 prevp = &header->ctl_table;
1841 for (n = 0; n < npath; ++n, ++path) {
1842 /* Copy the procname */
1843 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001844 new->mode = 0555;
1845
1846 *prevp = new;
1847 prevp = &new->child;
1848
1849 new += 2;
1850 }
1851 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001852 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001853
1854 INIT_LIST_HEAD(&header->ctl_entry);
1855 header->used = 0;
1856 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001857 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001858 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001859 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001860#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001861 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001862 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001863 return NULL;
1864 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001865#endif
Al Viro330d57f2005-11-04 10:18:40 +00001866 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001867 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001868 header->attached_by = header->ctl_table;
1869 header->attached_to = root_table;
1870 header->parent = &root_table_header;
1871 for (set = header->set; set; set = set->parent) {
1872 struct ctl_table_header *p;
1873 list_for_each_entry(p, &set->list, ctl_entry) {
1874 if (p->unregistering)
1875 continue;
1876 try_attach(p, header);
1877 }
1878 }
1879 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001880 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001881 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001882
1883 return header;
1884}
1885
1886/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001887 * register_sysctl_table_path - register a sysctl table hierarchy
1888 * @path: The path to the directory the sysctl table is in.
1889 * @table: the top-level table structure
1890 *
1891 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1892 * array. A completely 0 filled entry terminates the table.
1893 *
1894 * See __register_sysctl_paths for more details.
1895 */
1896struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1897 struct ctl_table *table)
1898{
1899 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1900 path, table);
1901}
1902
1903/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001904 * register_sysctl_table - register a sysctl table hierarchy
1905 * @table: the top-level table structure
1906 *
1907 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1908 * array. A completely 0 filled entry terminates the table.
1909 *
1910 * See register_sysctl_paths for more details.
1911 */
1912struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1913{
1914 static const struct ctl_path null_path[] = { {} };
1915
1916 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917}
1918
1919/**
1920 * unregister_sysctl_table - unregister a sysctl table hierarchy
1921 * @header: the header returned from register_sysctl_table
1922 *
1923 * Unregisters the sysctl table and all children. proc entries may not
1924 * actually be removed until they are no longer used by anyone.
1925 */
1926void unregister_sysctl_table(struct ctl_table_header * header)
1927{
Al Viro330d57f2005-11-04 10:18:40 +00001928 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001929
1930 if (header == NULL)
1931 return;
1932
Al Viro330d57f2005-11-04 10:18:40 +00001933 spin_lock(&sysctl_lock);
1934 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001935 if (!--header->parent->count) {
1936 WARN_ON(1);
1937 kfree(header->parent);
1938 }
Al Virof7e6ced2008-07-15 01:44:23 -04001939 if (!--header->count)
1940 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001941 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942}
1943
Al Viro90434762008-07-15 08:54:06 -04001944int sysctl_is_seen(struct ctl_table_header *p)
1945{
1946 struct ctl_table_set *set = p->set;
1947 int res;
1948 spin_lock(&sysctl_lock);
1949 if (p->unregistering)
1950 res = 0;
1951 else if (!set->is_seen)
1952 res = 1;
1953 else
1954 res = set->is_seen(set);
1955 spin_unlock(&sysctl_lock);
1956 return res;
1957}
1958
Al Viro73455092008-07-14 21:22:20 -04001959void setup_sysctl_set(struct ctl_table_set *p,
1960 struct ctl_table_set *parent,
1961 int (*is_seen)(struct ctl_table_set *))
1962{
1963 INIT_LIST_HEAD(&p->list);
1964 p->parent = parent ? parent : &sysctl_table_root.default_set;
1965 p->is_seen = is_seen;
1966}
1967
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001968#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001969struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001970{
1971 return NULL;
1972}
1973
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001974struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1975 struct ctl_table *table)
1976{
1977 return NULL;
1978}
1979
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001980void unregister_sysctl_table(struct ctl_table_header * table)
1981{
1982}
1983
Al Viro73455092008-07-14 21:22:20 -04001984void setup_sysctl_set(struct ctl_table_set *p,
1985 struct ctl_table_set *parent,
1986 int (*is_seen)(struct ctl_table_set *))
1987{
1988}
1989
Al Virof7e6ced2008-07-15 01:44:23 -04001990void sysctl_head_put(struct ctl_table_header *head)
1991{
1992}
1993
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001994#endif /* CONFIG_SYSCTL */
1995
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996/*
1997 * /proc/sys support
1998 */
1999
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002000#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002002static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002003 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002004 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002005{
2006 size_t len;
2007 char __user *p;
2008 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002009
2010 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002011 *lenp = 0;
2012 return 0;
2013 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002014
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002015 if (write) {
2016 len = 0;
2017 p = buffer;
2018 while (len < *lenp) {
2019 if (get_user(c, p++))
2020 return -EFAULT;
2021 if (c == 0 || c == '\n')
2022 break;
2023 len++;
2024 }
2025 if (len >= maxlen)
2026 len = maxlen-1;
2027 if(copy_from_user(data, buffer, len))
2028 return -EFAULT;
2029 ((char *) data)[len] = 0;
2030 *ppos += *lenp;
2031 } else {
2032 len = strlen(data);
2033 if (len > maxlen)
2034 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002035
2036 if (*ppos > len) {
2037 *lenp = 0;
2038 return 0;
2039 }
2040
2041 data += *ppos;
2042 len -= *ppos;
2043
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002044 if (len > *lenp)
2045 len = *lenp;
2046 if (len)
2047 if(copy_to_user(buffer, data, len))
2048 return -EFAULT;
2049 if (len < *lenp) {
2050 if(put_user('\n', ((char __user *) buffer) + len))
2051 return -EFAULT;
2052 len++;
2053 }
2054 *lenp = len;
2055 *ppos += len;
2056 }
2057 return 0;
2058}
2059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060/**
2061 * proc_dostring - read a string sysctl
2062 * @table: the sysctl table
2063 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 * @buffer: the user buffer
2065 * @lenp: the size of the user buffer
2066 * @ppos: file position
2067 *
2068 * Reads/writes a string from/to the user buffer. If the kernel
2069 * buffer provided is not large enough to hold the string, the
2070 * string is truncated. The copied string is %NULL-terminated.
2071 * If the string is being read by the user process, it is copied
2072 * and a newline '\n' is added. It is truncated if the buffer is
2073 * not large enough.
2074 *
2075 * Returns 0 on success.
2076 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002077int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 void __user *buffer, size_t *lenp, loff_t *ppos)
2079{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002080 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002081 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082}
2083
Amerigo Wang00b7c332010-05-05 00:26:45 +00002084static size_t proc_skip_spaces(char **buf)
2085{
2086 size_t ret;
2087 char *tmp = skip_spaces(*buf);
2088 ret = tmp - *buf;
2089 *buf = tmp;
2090 return ret;
2091}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002093static void proc_skip_char(char **buf, size_t *size, const char v)
2094{
2095 while (*size) {
2096 if (**buf != v)
2097 break;
2098 (*size)--;
2099 (*buf)++;
2100 }
2101}
2102
Amerigo Wang00b7c332010-05-05 00:26:45 +00002103#define TMPBUFLEN 22
2104/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002105 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002106 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002107 * @buf: a kernel buffer
2108 * @size: size of the kernel buffer
2109 * @val: this is where the number will be stored
2110 * @neg: set to %TRUE if number is negative
2111 * @perm_tr: a vector which contains the allowed trailers
2112 * @perm_tr_len: size of the perm_tr vector
2113 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002114 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002115 * In case of success %0 is returned and @buf and @size are updated with
2116 * the amount of bytes read. If @tr is non-NULL and a trailing
2117 * character exists (size is non-zero after returning from this
2118 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002119 */
2120static int proc_get_long(char **buf, size_t *size,
2121 unsigned long *val, bool *neg,
2122 const char *perm_tr, unsigned perm_tr_len, char *tr)
2123{
2124 int len;
2125 char *p, tmp[TMPBUFLEN];
2126
2127 if (!*size)
2128 return -EINVAL;
2129
2130 len = *size;
2131 if (len > TMPBUFLEN - 1)
2132 len = TMPBUFLEN - 1;
2133
2134 memcpy(tmp, *buf, len);
2135
2136 tmp[len] = 0;
2137 p = tmp;
2138 if (*p == '-' && *size > 1) {
2139 *neg = true;
2140 p++;
2141 } else
2142 *neg = false;
2143 if (!isdigit(*p))
2144 return -EINVAL;
2145
2146 *val = simple_strtoul(p, &p, 0);
2147
2148 len = p - tmp;
2149
2150 /* We don't know if the next char is whitespace thus we may accept
2151 * invalid integers (e.g. 1234...a) or two integers instead of one
2152 * (e.g. 123...1). So lets not allow such large numbers. */
2153 if (len == TMPBUFLEN - 1)
2154 return -EINVAL;
2155
2156 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2157 return -EINVAL;
2158
2159 if (tr && (len < *size))
2160 *tr = *p;
2161
2162 *buf += len;
2163 *size -= len;
2164
2165 return 0;
2166}
2167
2168/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002169 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002170 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002171 * @buf: the user buffer
2172 * @size: the size of the user buffer
2173 * @val: the integer to be converted
2174 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002175 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002176 * In case of success %0 is returned and @buf and @size are updated with
2177 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002178 */
2179static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2180 bool neg)
2181{
2182 int len;
2183 char tmp[TMPBUFLEN], *p = tmp;
2184
2185 sprintf(p, "%s%lu", neg ? "-" : "", val);
2186 len = strlen(tmp);
2187 if (len > *size)
2188 len = *size;
2189 if (copy_to_user(*buf, tmp, len))
2190 return -EFAULT;
2191 *size -= len;
2192 *buf += len;
2193 return 0;
2194}
2195#undef TMPBUFLEN
2196
2197static int proc_put_char(void __user **buf, size_t *size, char c)
2198{
2199 if (*size) {
2200 char __user **buffer = (char __user **)buf;
2201 if (put_user(c, *buffer))
2202 return -EFAULT;
2203 (*size)--, (*buffer)++;
2204 *buf = *buffer;
2205 }
2206 return 0;
2207}
2208
2209static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 int *valp,
2211 int write, void *data)
2212{
2213 if (write) {
2214 *valp = *negp ? -*lvalp : *lvalp;
2215 } else {
2216 int val = *valp;
2217 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002218 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 *lvalp = (unsigned long)-val;
2220 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002221 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 *lvalp = (unsigned long)val;
2223 }
2224 }
2225 return 0;
2226}
2227
Amerigo Wang00b7c332010-05-05 00:26:45 +00002228static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2229
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002230static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002231 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002232 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002233 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 int write, void *data),
2235 void *data)
2236{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002237 int *i, vleft, first = 1, err = 0;
2238 unsigned long page = 0;
2239 size_t left;
2240 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 *lenp = 0;
2244 return 0;
2245 }
2246
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002247 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 vleft = table->maxlen / sizeof(*i);
2249 left = *lenp;
2250
2251 if (!conv)
2252 conv = do_proc_dointvec_conv;
2253
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002255 if (left > PAGE_SIZE - 1)
2256 left = PAGE_SIZE - 1;
2257 page = __get_free_page(GFP_TEMPORARY);
2258 kbuf = (char *) page;
2259 if (!kbuf)
2260 return -ENOMEM;
2261 if (copy_from_user(kbuf, buffer, left)) {
2262 err = -EFAULT;
2263 goto free;
2264 }
2265 kbuf[left] = 0;
2266 }
2267
2268 for (; left && vleft--; i++, first=0) {
2269 unsigned long lval;
2270 bool neg;
2271
2272 if (write) {
2273 left -= proc_skip_spaces(&kbuf);
2274
2275 err = proc_get_long(&kbuf, &left, &lval, &neg,
2276 proc_wspace_sep,
2277 sizeof(proc_wspace_sep), NULL);
2278 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002280 if (conv(&neg, &lval, i, 1, data)) {
2281 err = -EINVAL;
2282 break;
2283 }
2284 } else {
2285 if (conv(&neg, &lval, i, 0, data)) {
2286 err = -EINVAL;
2287 break;
2288 }
2289 if (!first)
2290 err = proc_put_char(&buffer, &left, '\t');
2291 if (err)
2292 break;
2293 err = proc_put_long(&buffer, &left, lval, neg);
2294 if (err)
2295 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 }
2297 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002298
2299 if (!write && !first && left && !err)
2300 err = proc_put_char(&buffer, &left, '\n');
2301 if (write && !err)
2302 left -= proc_skip_spaces(&kbuf);
2303free:
2304 if (write) {
2305 free_page(page);
2306 if (first)
2307 return err ? : -EINVAL;
2308 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 *lenp -= left;
2310 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002311 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312}
2313
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002314static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002315 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002316 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002317 int write, void *data),
2318 void *data)
2319{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002320 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002321 buffer, lenp, ppos, conv, data);
2322}
2323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324/**
2325 * proc_dointvec - read a vector of integers
2326 * @table: the sysctl table
2327 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2331 *
2332 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2333 * values from/to the user buffer, treated as an ASCII string.
2334 *
2335 * Returns 0 on success.
2336 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002337int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 void __user *buffer, size_t *lenp, loff_t *ppos)
2339{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002340 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 NULL,NULL);
2342}
2343
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002344/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002345 * Taint values can only be increased
2346 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002347 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002348static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002349 void __user *buffer, size_t *lenp, loff_t *ppos)
2350{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002351 struct ctl_table t;
2352 unsigned long tmptaint = get_taint();
2353 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002354
Bastian Blank91fcd412007-04-23 14:41:14 -07002355 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002356 return -EPERM;
2357
Andi Kleen25ddbb12008-10-15 22:01:41 -07002358 t = *table;
2359 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002360 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002361 if (err < 0)
2362 return err;
2363
2364 if (write) {
2365 /*
2366 * Poor man's atomic or. Not worth adding a primitive
2367 * to everyone's atomic.h for this
2368 */
2369 int i;
2370 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2371 if ((tmptaint >> i) & 1)
2372 add_taint(i);
2373 }
2374 }
2375
2376 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002377}
2378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379struct do_proc_dointvec_minmax_conv_param {
2380 int *min;
2381 int *max;
2382};
2383
Amerigo Wang00b7c332010-05-05 00:26:45 +00002384static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2385 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 int write, void *data)
2387{
2388 struct do_proc_dointvec_minmax_conv_param *param = data;
2389 if (write) {
2390 int val = *negp ? -*lvalp : *lvalp;
2391 if ((param->min && *param->min > val) ||
2392 (param->max && *param->max < val))
2393 return -EINVAL;
2394 *valp = val;
2395 } else {
2396 int val = *valp;
2397 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002398 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 *lvalp = (unsigned long)-val;
2400 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002401 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 *lvalp = (unsigned long)val;
2403 }
2404 }
2405 return 0;
2406}
2407
2408/**
2409 * proc_dointvec_minmax - read a vector of integers with min/max values
2410 * @table: the sysctl table
2411 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 * @buffer: the user buffer
2413 * @lenp: the size of the user buffer
2414 * @ppos: file position
2415 *
2416 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2417 * values from/to the user buffer, treated as an ASCII string.
2418 *
2419 * This routine will ensure the values are within the range specified by
2420 * table->extra1 (min) and table->extra2 (max).
2421 *
2422 * Returns 0 on success.
2423 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002424int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 void __user *buffer, size_t *lenp, loff_t *ppos)
2426{
2427 struct do_proc_dointvec_minmax_conv_param param = {
2428 .min = (int *) table->extra1,
2429 .max = (int *) table->extra2,
2430 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002431 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 do_proc_dointvec_minmax_conv, &param);
2433}
2434
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002435static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 void __user *buffer,
2437 size_t *lenp, loff_t *ppos,
2438 unsigned long convmul,
2439 unsigned long convdiv)
2440{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002441 unsigned long *i, *min, *max;
2442 int vleft, first = 1, err = 0;
2443 unsigned long page = 0;
2444 size_t left;
2445 char *kbuf;
2446
2447 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 *lenp = 0;
2449 return 0;
2450 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002451
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002452 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 min = (unsigned long *) table->extra1;
2454 max = (unsigned long *) table->extra2;
2455 vleft = table->maxlen / sizeof(unsigned long);
2456 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002457
2458 if (write) {
2459 if (left > PAGE_SIZE - 1)
2460 left = PAGE_SIZE - 1;
2461 page = __get_free_page(GFP_TEMPORARY);
2462 kbuf = (char *) page;
2463 if (!kbuf)
2464 return -ENOMEM;
2465 if (copy_from_user(kbuf, buffer, left)) {
2466 err = -EFAULT;
2467 goto free;
2468 }
2469 kbuf[left] = 0;
2470 }
2471
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 for (; left && vleft--; i++, min++, max++, first=0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002473 unsigned long val;
2474
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002476 bool neg;
2477
2478 left -= proc_skip_spaces(&kbuf);
2479
2480 err = proc_get_long(&kbuf, &left, &val, &neg,
2481 proc_wspace_sep,
2482 sizeof(proc_wspace_sep), NULL);
2483 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 break;
2485 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 continue;
2487 if ((min && val < *min) || (max && val > *max))
2488 continue;
2489 *i = val;
2490 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002491 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002493 err = proc_put_char(&buffer, &left, '\t');
2494 err = proc_put_long(&buffer, &left, val, false);
2495 if (err)
2496 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 }
2498 }
2499
Amerigo Wang00b7c332010-05-05 00:26:45 +00002500 if (!write && !first && left && !err)
2501 err = proc_put_char(&buffer, &left, '\n');
2502 if (write && !err)
2503 left -= proc_skip_spaces(&kbuf);
2504free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002506 free_page(page);
2507 if (first)
2508 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 *lenp -= left;
2511 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002512 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513}
2514
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002515static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002516 void __user *buffer,
2517 size_t *lenp, loff_t *ppos,
2518 unsigned long convmul,
2519 unsigned long convdiv)
2520{
2521 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002522 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002523}
2524
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525/**
2526 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2527 * @table: the sysctl table
2528 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 * @buffer: the user buffer
2530 * @lenp: the size of the user buffer
2531 * @ppos: file position
2532 *
2533 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2534 * values from/to the user buffer, treated as an ASCII string.
2535 *
2536 * This routine will ensure the values are within the range specified by
2537 * table->extra1 (min) and table->extra2 (max).
2538 *
2539 * Returns 0 on success.
2540 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002541int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 void __user *buffer, size_t *lenp, loff_t *ppos)
2543{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002544 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545}
2546
2547/**
2548 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2549 * @table: the sysctl table
2550 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 * @buffer: the user buffer
2552 * @lenp: the size of the user buffer
2553 * @ppos: file position
2554 *
2555 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2556 * values from/to the user buffer, treated as an ASCII string. The values
2557 * are treated as milliseconds, and converted to jiffies when they are stored.
2558 *
2559 * This routine will ensure the values are within the range specified by
2560 * table->extra1 (min) and table->extra2 (max).
2561 *
2562 * Returns 0 on success.
2563 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002564int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 void __user *buffer,
2566 size_t *lenp, loff_t *ppos)
2567{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002568 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 lenp, ppos, HZ, 1000l);
2570}
2571
2572
Amerigo Wang00b7c332010-05-05 00:26:45 +00002573static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 int *valp,
2575 int write, void *data)
2576{
2577 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002578 if (*lvalp > LONG_MAX / HZ)
2579 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2581 } else {
2582 int val = *valp;
2583 unsigned long lval;
2584 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002585 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 lval = (unsigned long)-val;
2587 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002588 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 lval = (unsigned long)val;
2590 }
2591 *lvalp = lval / HZ;
2592 }
2593 return 0;
2594}
2595
Amerigo Wang00b7c332010-05-05 00:26:45 +00002596static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 int *valp,
2598 int write, void *data)
2599{
2600 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002601 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2602 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2604 } else {
2605 int val = *valp;
2606 unsigned long lval;
2607 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002608 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 lval = (unsigned long)-val;
2610 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002611 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 lval = (unsigned long)val;
2613 }
2614 *lvalp = jiffies_to_clock_t(lval);
2615 }
2616 return 0;
2617}
2618
Amerigo Wang00b7c332010-05-05 00:26:45 +00002619static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 int *valp,
2621 int write, void *data)
2622{
2623 if (write) {
2624 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2625 } else {
2626 int val = *valp;
2627 unsigned long lval;
2628 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002629 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 lval = (unsigned long)-val;
2631 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002632 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 lval = (unsigned long)val;
2634 }
2635 *lvalp = jiffies_to_msecs(lval);
2636 }
2637 return 0;
2638}
2639
2640/**
2641 * proc_dointvec_jiffies - read a vector of integers as seconds
2642 * @table: the sysctl table
2643 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 * @buffer: the user buffer
2645 * @lenp: the size of the user buffer
2646 * @ppos: file position
2647 *
2648 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2649 * values from/to the user buffer, treated as an ASCII string.
2650 * The values read are assumed to be in seconds, and are converted into
2651 * jiffies.
2652 *
2653 * Returns 0 on success.
2654 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002655int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 void __user *buffer, size_t *lenp, loff_t *ppos)
2657{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002658 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 do_proc_dointvec_jiffies_conv,NULL);
2660}
2661
2662/**
2663 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2664 * @table: the sysctl table
2665 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 * @buffer: the user buffer
2667 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002668 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 *
2670 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2671 * values from/to the user buffer, treated as an ASCII string.
2672 * The values read are assumed to be in 1/USER_HZ seconds, and
2673 * are converted into jiffies.
2674 *
2675 * Returns 0 on success.
2676 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002677int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 void __user *buffer, size_t *lenp, loff_t *ppos)
2679{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002680 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 do_proc_dointvec_userhz_jiffies_conv,NULL);
2682}
2683
2684/**
2685 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2686 * @table: the sysctl table
2687 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 * @buffer: the user buffer
2689 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002690 * @ppos: file position
2691 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 *
2693 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2694 * values from/to the user buffer, treated as an ASCII string.
2695 * The values read are assumed to be in 1/1000 seconds, and
2696 * are converted into jiffies.
2697 *
2698 * Returns 0 on success.
2699 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002700int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 void __user *buffer, size_t *lenp, loff_t *ppos)
2702{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002703 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 do_proc_dointvec_ms_jiffies_conv, NULL);
2705}
2706
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002707static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002708 void __user *buffer, size_t *lenp, loff_t *ppos)
2709{
2710 struct pid *new_pid;
2711 pid_t tmp;
2712 int r;
2713
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002714 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002715
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002716 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002717 lenp, ppos, NULL, NULL);
2718 if (r || !write)
2719 return r;
2720
2721 new_pid = find_get_pid(tmp);
2722 if (!new_pid)
2723 return -ESRCH;
2724
2725 put_pid(xchg(&cad_pid, new_pid));
2726 return 0;
2727}
2728
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002729/**
2730 * proc_do_large_bitmap - read/write from/to a large bitmap
2731 * @table: the sysctl table
2732 * @write: %TRUE if this is a write to the sysctl file
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
2735 * @ppos: file position
2736 *
2737 * The bitmap is stored at table->data and the bitmap length (in bits)
2738 * in table->maxlen.
2739 *
2740 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2741 * large bitmaps may be represented in a compact manner. Writing into
2742 * the file will clear the bitmap then update it with the given input.
2743 *
2744 * Returns 0 on success.
2745 */
2746int proc_do_large_bitmap(struct ctl_table *table, int write,
2747 void __user *buffer, size_t *lenp, loff_t *ppos)
2748{
2749 int err = 0;
2750 bool first = 1;
2751 size_t left = *lenp;
2752 unsigned long bitmap_len = table->maxlen;
2753 unsigned long *bitmap = (unsigned long *) table->data;
2754 unsigned long *tmp_bitmap = NULL;
2755 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2756
2757 if (!bitmap_len || !left || (*ppos && !write)) {
2758 *lenp = 0;
2759 return 0;
2760 }
2761
2762 if (write) {
2763 unsigned long page = 0;
2764 char *kbuf;
2765
2766 if (left > PAGE_SIZE - 1)
2767 left = PAGE_SIZE - 1;
2768
2769 page = __get_free_page(GFP_TEMPORARY);
2770 kbuf = (char *) page;
2771 if (!kbuf)
2772 return -ENOMEM;
2773 if (copy_from_user(kbuf, buffer, left)) {
2774 free_page(page);
2775 return -EFAULT;
2776 }
2777 kbuf[left] = 0;
2778
2779 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2780 GFP_KERNEL);
2781 if (!tmp_bitmap) {
2782 free_page(page);
2783 return -ENOMEM;
2784 }
2785 proc_skip_char(&kbuf, &left, '\n');
2786 while (!err && left) {
2787 unsigned long val_a, val_b;
2788 bool neg;
2789
2790 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2791 sizeof(tr_a), &c);
2792 if (err)
2793 break;
2794 if (val_a >= bitmap_len || neg) {
2795 err = -EINVAL;
2796 break;
2797 }
2798
2799 val_b = val_a;
2800 if (left) {
2801 kbuf++;
2802 left--;
2803 }
2804
2805 if (c == '-') {
2806 err = proc_get_long(&kbuf, &left, &val_b,
2807 &neg, tr_b, sizeof(tr_b),
2808 &c);
2809 if (err)
2810 break;
2811 if (val_b >= bitmap_len || neg ||
2812 val_a > val_b) {
2813 err = -EINVAL;
2814 break;
2815 }
2816 if (left) {
2817 kbuf++;
2818 left--;
2819 }
2820 }
2821
2822 while (val_a <= val_b)
2823 set_bit(val_a++, tmp_bitmap);
2824
2825 first = 0;
2826 proc_skip_char(&kbuf, &left, '\n');
2827 }
2828 free_page(page);
2829 } else {
2830 unsigned long bit_a, bit_b = 0;
2831
2832 while (left) {
2833 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2834 if (bit_a >= bitmap_len)
2835 break;
2836 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2837 bit_a + 1) - 1;
2838
2839 if (!first) {
2840 err = proc_put_char(&buffer, &left, ',');
2841 if (err)
2842 break;
2843 }
2844 err = proc_put_long(&buffer, &left, bit_a, false);
2845 if (err)
2846 break;
2847 if (bit_a != bit_b) {
2848 err = proc_put_char(&buffer, &left, '-');
2849 if (err)
2850 break;
2851 err = proc_put_long(&buffer, &left, bit_b, false);
2852 if (err)
2853 break;
2854 }
2855
2856 first = 0; bit_b++;
2857 }
2858 if (!err)
2859 err = proc_put_char(&buffer, &left, '\n');
2860 }
2861
2862 if (!err) {
2863 if (write) {
2864 if (*ppos)
2865 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2866 else
2867 memcpy(bitmap, tmp_bitmap,
2868 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2869 }
2870 kfree(tmp_bitmap);
2871 *lenp -= left;
2872 *ppos += *lenp;
2873 return 0;
2874 } else {
2875 kfree(tmp_bitmap);
2876 return err;
2877 }
2878}
2879
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880#else /* CONFIG_PROC_FS */
2881
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002882int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 void __user *buffer, size_t *lenp, loff_t *ppos)
2884{
2885 return -ENOSYS;
2886}
2887
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002888int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 void __user *buffer, size_t *lenp, loff_t *ppos)
2890{
2891 return -ENOSYS;
2892}
2893
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002894int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 void __user *buffer, size_t *lenp, loff_t *ppos)
2896{
2897 return -ENOSYS;
2898}
2899
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002900int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 void __user *buffer, size_t *lenp, loff_t *ppos)
2902{
2903 return -ENOSYS;
2904}
2905
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002906int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 void __user *buffer, size_t *lenp, loff_t *ppos)
2908{
2909 return -ENOSYS;
2910}
2911
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002912int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 void __user *buffer, size_t *lenp, loff_t *ppos)
2914{
2915 return -ENOSYS;
2916}
2917
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002918int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 void __user *buffer, size_t *lenp, loff_t *ppos)
2920{
2921 return -ENOSYS;
2922}
2923
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002924int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 void __user *buffer,
2926 size_t *lenp, loff_t *ppos)
2927{
2928 return -ENOSYS;
2929}
2930
2931
2932#endif /* CONFIG_PROC_FS */
2933
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934/*
2935 * No sense putting this after each symbol definition, twice,
2936 * exception granted :-)
2937 */
2938EXPORT_SYMBOL(proc_dointvec);
2939EXPORT_SYMBOL(proc_dointvec_jiffies);
2940EXPORT_SYMBOL(proc_dointvec_minmax);
2941EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2942EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2943EXPORT_SYMBOL(proc_dostring);
2944EXPORT_SYMBOL(proc_doulongvec_minmax);
2945EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2946EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002947EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948EXPORT_SYMBOL(unregister_sysctl_table);