blob: b9e5a45f1e28e50936db393fc13703af86361479 [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>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020029#include <linux/kmemcheck.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070042#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/times.h>
44#include <linux/limits.h>
45#include <linux/dcache.h>
46#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070047#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080048#include <linux/nfs_fs.h>
49#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070050#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020051#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010052#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020053#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#include <asm/uaccess.h>
56#include <asm/processor.h>
57
Andi Kleen29cbc782006-09-30 01:47:55 +020058#ifdef CONFIG_X86
59#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010060#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010061#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020062#endif
63
Eric W. Biederman7058cb02007-10-18 03:05:58 -070064static int deprecated_sysctl_warning(struct __sysctl_args *args);
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#if defined(CONFIG_SYSCTL)
67
68/* External variables not in a header file. */
69extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070070extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int sysctl_overcommit_memory;
72extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070073extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070074extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080075extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070078extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070080extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern int pid_max;
82extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080084extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080085extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020086extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010087extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040088extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000089#ifndef CONFIG_MMU
90extern int sysctl_nr_trim_pages;
91#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070092#ifdef CONFIG_RCU_TORTURE_TEST
93extern int rcutorture_runnable;
94#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Jens Axboecb684b52009-09-15 21:53:11 +020095#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +020096extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +020097#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -0800100#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700101static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200102static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103#endif
104
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700105static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700106static int __maybe_unused one = 1;
107static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800108static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700109static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700110#ifdef CONFIG_PRINTK
111static int ten_thousand = 10000;
112#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700114/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
115static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
118static int maxolduid = 65535;
119static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800120static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122static int ngroups_max = NGROUPS_MAX;
123
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200124#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700126extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef CONFIG_CHR_DEV_SG
129extern int sg_big_buff;
130#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
David S. Miller72c57ed2008-09-11 23:29:54 -0700132#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700133#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
David S. Miller08714202008-11-16 23:49:24 -0800136#ifdef CONFIG_SPARC64
137extern int sysctl_tsb_ratio;
138#endif
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef __hppa__
141extern int pwrsw_enabled;
142extern int unaligned_enabled;
143#endif
144
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800145#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef CONFIG_MATHEMU
147extern int sysctl_ieee_emulation_warnings;
148#endif
149extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700150extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#ifdef CONFIG_BSD_PROCESS_ACCT
154extern int acct_parm[];
155#endif
156
Jes Sorensend2b176e2006-02-28 09:42:23 -0800157#ifdef CONFIG_IA64
158extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800159extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800160#endif
161
Ingo Molnar3fff4c42009-09-22 16:18:09 +0200162extern struct ratelimit_state printk_ratelimit_state;
163
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700164#ifdef CONFIG_RT_MUTEXES
165extern int max_lock_depth;
166#endif
167
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700168#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700169static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700171static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800172 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700173#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700174
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700175static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176static struct ctl_table_root sysctl_table_root;
177static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100178 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100179 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400180 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100181 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400182 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100183};
184static struct ctl_table_root sysctl_table_root = {
185 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400186 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100187};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700189static struct ctl_table kern_table[];
190static struct ctl_table vm_table[];
191static struct ctl_table fs_table[];
192static struct ctl_table debug_table[];
193static struct ctl_table dev_table[];
194extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700195#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700196extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400197#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800198#ifdef CONFIG_EPOLL
199extern struct ctl_table epoll_table[];
200#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
203int sysctl_legacy_va_layout;
204#endif
205
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700206extern int prove_locking;
207extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/* The default sysctl tables: */
210
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700211static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 {
213 .ctl_name = CTL_KERN,
214 .procname = "kernel",
215 .mode = 0555,
216 .child = kern_table,
217 },
218 {
219 .ctl_name = CTL_VM,
220 .procname = "vm",
221 .mode = 0555,
222 .child = vm_table,
223 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 .ctl_name = CTL_FS,
226 .procname = "fs",
227 .mode = 0555,
228 .child = fs_table,
229 },
230 {
231 .ctl_name = CTL_DEBUG,
232 .procname = "debug",
233 .mode = 0555,
234 .child = debug_table,
235 },
236 {
237 .ctl_name = CTL_DEV,
238 .procname = "dev",
239 .mode = 0555,
240 .child = dev_table,
241 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700242/*
243 * NOTE: do not add new entries to this table unless you have read
244 * Documentation/sysctl/ctl_unnumbered.txt
245 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 { .ctl_name = 0 }
247};
248
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100250static int min_sched_granularity_ns = 100000; /* 100 usecs */
251static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
252static int min_wakeup_granularity_ns; /* 0 usecs */
253static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100254static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
255static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100256static int min_sched_shares_ratelimit = 100000; /* 100 usec */
257static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200258#endif
259
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700260static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200261 {
262 .ctl_name = CTL_UNNUMBERED,
263 .procname = "sched_child_runs_first",
264 .data = &sysctl_sched_child_runs_first,
265 .maxlen = sizeof(unsigned int),
266 .mode = 0644,
267 .proc_handler = &proc_dointvec,
268 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200269#ifdef CONFIG_SCHED_DEBUG
270 {
271 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100272 .procname = "sched_min_granularity_ns",
273 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100276 .proc_handler = &sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100277 .strategy = &sysctl_intvec,
278 .extra1 = &min_sched_granularity_ns,
279 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200280 },
281 {
282 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200283 .procname = "sched_latency_ns",
284 .data = &sysctl_sched_latency,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100287 .proc_handler = &sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200288 .strategy = &sysctl_intvec,
289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
291 },
292 {
293 .ctl_name = CTL_UNNUMBERED,
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,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100298 .proc_handler = &sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299 .strategy = &sysctl_intvec,
300 .extra1 = &min_wakeup_granularity_ns,
301 .extra2 = &max_wakeup_granularity_ns,
302 },
303 {
304 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200305 .procname = "sched_shares_ratelimit",
306 .data = &sysctl_sched_shares_ratelimit,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100309 .proc_handler = &sched_proc_update_handler,
310 .extra1 = &min_sched_shares_ratelimit,
311 .extra2 = &max_sched_shares_ratelimit,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200312 },
313 {
314 .ctl_name = CTL_UNNUMBERED,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100315 .procname = "sched_tunable_scaling",
316 .data = &sysctl_sched_tunable_scaling,
317 .maxlen = sizeof(enum sched_tunable_scaling),
318 .mode = 0644,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100319 .proc_handler = &sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100320 .strategy = &sysctl_intvec,
321 .extra1 = &min_sched_tunable_scaling,
322 .extra2 = &max_sched_tunable_scaling,
323 },
324
325 {
326 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200327 .procname = "sched_shares_thresh",
328 .data = &sysctl_sched_shares_thresh,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = &proc_dointvec_minmax,
332 .strategy = &sysctl_intvec,
333 .extra1 = &zero,
334 },
335 {
336 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarda84d962007-10-15 17:00:18 +0200337 .procname = "sched_migration_cost",
338 .data = &sysctl_sched_migration_cost,
339 .maxlen = sizeof(unsigned int),
340 .mode = 0644,
341 .proc_handler = &proc_dointvec,
342 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100343 {
344 .ctl_name = CTL_UNNUMBERED,
345 .procname = "sched_nr_migrate",
346 .data = &sysctl_sched_nr_migrate,
347 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100348 .mode = 0644,
349 .proc_handler = &proc_dointvec,
350 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530351 {
352 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200353 .procname = "sched_time_avg",
354 .data = &sysctl_sched_time_avg,
355 .maxlen = sizeof(unsigned int),
356 .mode = 0644,
357 .proc_handler = &proc_dointvec,
358 },
359 {
360 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530361 .procname = "timer_migration",
362 .data = &sysctl_timer_migration,
363 .maxlen = sizeof(unsigned int),
364 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530365 .proc_handler = &proc_dointvec_minmax,
366 .strategy = &sysctl_intvec,
367 .extra1 = &zero,
368 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530369 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200370#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200371 {
372 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100373 .procname = "sched_rt_period_us",
374 .data = &sysctl_sched_rt_period,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200377 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100378 },
379 {
380 .ctl_name = CTL_UNNUMBERED,
381 .procname = "sched_rt_runtime_us",
382 .data = &sysctl_sched_rt_runtime,
383 .maxlen = sizeof(int),
384 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200385 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100386 },
387 {
388 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200389 .procname = "sched_compat_yield",
390 .data = &sysctl_sched_compat_yield,
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
394 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700395#ifdef CONFIG_PROVE_LOCKING
396 {
397 .ctl_name = CTL_UNNUMBERED,
398 .procname = "prove_locking",
399 .data = &prove_locking,
400 .maxlen = sizeof(int),
401 .mode = 0644,
402 .proc_handler = &proc_dointvec,
403 },
404#endif
405#ifdef CONFIG_LOCK_STAT
406 {
407 .ctl_name = CTL_UNNUMBERED,
408 .procname = "lock_stat",
409 .data = &lock_stat,
410 .maxlen = sizeof(int),
411 .mode = 0644,
412 .proc_handler = &proc_dointvec,
413 },
414#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200415 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 .ctl_name = KERN_PANIC,
417 .procname = "panic",
418 .data = &panic_timeout,
419 .maxlen = sizeof(int),
420 .mode = 0644,
421 .proc_handler = &proc_dointvec,
422 },
423 {
424 .ctl_name = KERN_CORE_USES_PID,
425 .procname = "core_uses_pid",
426 .data = &core_uses_pid,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
431 {
432 .ctl_name = KERN_CORE_PATTERN,
433 .procname = "core_pattern",
434 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700435 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 .mode = 0644,
437 .proc_handler = &proc_dostring,
438 .strategy = &sysctl_string,
439 },
Neil Hormana2939802009-09-23 15:56:56 -0700440 {
441 .ctl_name = CTL_UNNUMBERED,
442 .procname = "core_pipe_limit",
443 .data = &core_pipe_limit,
444 .maxlen = sizeof(unsigned int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
447 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800448#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700451 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800452 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700453 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800455#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100456#ifdef CONFIG_LATENCYTOP
457 {
458 .procname = "latencytop",
459 .data = &latencytop_enabled,
460 .maxlen = sizeof(int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
463 },
464#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#ifdef CONFIG_BLK_DEV_INITRD
466 {
467 .ctl_name = KERN_REALROOTDEV,
468 .procname = "real-root-dev",
469 .data = &real_root_dev,
470 .maxlen = sizeof(int),
471 .mode = 0644,
472 .proc_handler = &proc_dointvec,
473 },
474#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700475 {
476 .ctl_name = CTL_UNNUMBERED,
477 .procname = "print-fatal-signals",
478 .data = &print_fatal_signals,
479 .maxlen = sizeof(int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
482 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700483#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 {
485 .ctl_name = KERN_SPARC_REBOOT,
486 .procname = "reboot-cmd",
487 .data = reboot_command,
488 .maxlen = 256,
489 .mode = 0644,
490 .proc_handler = &proc_dostring,
491 .strategy = &sysctl_string,
492 },
493 {
494 .ctl_name = KERN_SPARC_STOP_A,
495 .procname = "stop-a",
496 .data = &stop_a_enabled,
497 .maxlen = sizeof (int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
500 },
501 {
502 .ctl_name = KERN_SPARC_SCONS_PWROFF,
503 .procname = "scons-poweroff",
504 .data = &scons_pwroff,
505 .maxlen = sizeof (int),
506 .mode = 0644,
507 .proc_handler = &proc_dointvec,
508 },
509#endif
David S. Miller08714202008-11-16 23:49:24 -0800510#ifdef CONFIG_SPARC64
511 {
512 .ctl_name = CTL_UNNUMBERED,
513 .procname = "tsb-ratio",
514 .data = &sysctl_tsb_ratio,
515 .maxlen = sizeof (int),
516 .mode = 0644,
517 .proc_handler = &proc_dointvec,
518 },
519#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#ifdef __hppa__
521 {
522 .ctl_name = KERN_HPPA_PWRSW,
523 .procname = "soft-power",
524 .data = &pwrsw_enabled,
525 .maxlen = sizeof (int),
526 .mode = 0644,
527 .proc_handler = &proc_dointvec,
528 },
529 {
530 .ctl_name = KERN_HPPA_UNALIGNED,
531 .procname = "unaligned-trap",
532 .data = &unaligned_enabled,
533 .maxlen = sizeof (int),
534 .mode = 0644,
535 .proc_handler = &proc_dointvec,
536 },
537#endif
538 {
539 .ctl_name = KERN_CTLALTDEL,
540 .procname = "ctrl-alt-del",
541 .data = &C_A_D,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 .proc_handler = &proc_dointvec,
545 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400546#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200547 {
548 .ctl_name = CTL_UNNUMBERED,
549 .procname = "ftrace_enabled",
550 .data = &ftrace_enabled,
551 .maxlen = sizeof(int),
552 .mode = 0644,
553 .proc_handler = &ftrace_enable_sysctl,
554 },
555#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500556#ifdef CONFIG_STACK_TRACER
557 {
558 .ctl_name = CTL_UNNUMBERED,
559 .procname = "stack_tracer_enabled",
560 .data = &stack_tracer_enabled,
561 .maxlen = sizeof(int),
562 .mode = 0644,
563 .proc_handler = &stack_trace_sysctl,
564 },
565#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400566#ifdef CONFIG_TRACING
567 {
568 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100569 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400570 .data = &ftrace_dump_on_oops,
571 .maxlen = sizeof(int),
572 .mode = 0644,
573 .proc_handler = &proc_dointvec,
574 },
575#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200576#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 {
578 .ctl_name = KERN_MODPROBE,
579 .procname = "modprobe",
580 .data = &modprobe_path,
581 .maxlen = KMOD_PATH_LEN,
582 .mode = 0644,
583 .proc_handler = &proc_dostring,
584 .strategy = &sysctl_string,
585 },
Kees Cook3d433212009-04-02 15:49:29 -0700586 {
587 .ctl_name = CTL_UNNUMBERED,
588 .procname = "modules_disabled",
589 .data = &modules_disabled,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 /* only handle a transition from default "0" to "1" */
593 .proc_handler = &proc_dointvec_minmax,
594 .extra1 = &one,
595 .extra2 = &one,
596 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700598#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 {
600 .ctl_name = KERN_HOTPLUG,
601 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100602 .data = &uevent_helper,
603 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .mode = 0644,
605 .proc_handler = &proc_dostring,
606 .strategy = &sysctl_string,
607 },
608#endif
609#ifdef CONFIG_CHR_DEV_SG
610 {
611 .ctl_name = KERN_SG_BIG_BUFF,
612 .procname = "sg-big-buff",
613 .data = &sg_big_buff,
614 .maxlen = sizeof (int),
615 .mode = 0444,
616 .proc_handler = &proc_dointvec,
617 },
618#endif
619#ifdef CONFIG_BSD_PROCESS_ACCT
620 {
621 .ctl_name = KERN_ACCT,
622 .procname = "acct",
623 .data = &acct_parm,
624 .maxlen = 3*sizeof(int),
625 .mode = 0644,
626 .proc_handler = &proc_dointvec,
627 },
628#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#ifdef CONFIG_MAGIC_SYSRQ
630 {
631 .ctl_name = KERN_SYSRQ,
632 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800633 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .maxlen = sizeof (int),
635 .mode = 0644,
636 .proc_handler = &proc_dointvec,
637 },
638#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700639#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700642 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 .maxlen = sizeof (int),
644 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700645 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700647#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 {
649 .ctl_name = KERN_MAX_THREADS,
650 .procname = "threads-max",
651 .data = &max_threads,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = &proc_dointvec,
655 },
656 {
657 .ctl_name = KERN_RANDOM,
658 .procname = "random",
659 .mode = 0555,
660 .child = random_table,
661 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 {
663 .ctl_name = KERN_OVERFLOWUID,
664 .procname = "overflowuid",
665 .data = &overflowuid,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec_minmax,
669 .strategy = &sysctl_intvec,
670 .extra1 = &minolduid,
671 .extra2 = &maxolduid,
672 },
673 {
674 .ctl_name = KERN_OVERFLOWGID,
675 .procname = "overflowgid",
676 .data = &overflowgid,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec_minmax,
680 .strategy = &sysctl_intvec,
681 .extra1 = &minolduid,
682 .extra2 = &maxolduid,
683 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800684#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#ifdef CONFIG_MATHEMU
686 {
687 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
688 .procname = "ieee_emulation_warnings",
689 .data = &sysctl_ieee_emulation_warnings,
690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = &proc_dointvec,
693 },
694#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 {
696 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
697 .procname = "userprocess_debug",
698 .data = &sysctl_userprocess_debug,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = &proc_dointvec,
702 },
703#endif
704 {
705 .ctl_name = KERN_PIDMAX,
706 .procname = "pid_max",
707 .data = &pid_max,
708 .maxlen = sizeof (int),
709 .mode = 0644,
710 .proc_handler = &proc_dointvec_minmax,
711 .strategy = sysctl_intvec,
712 .extra1 = &pid_max_min,
713 .extra2 = &pid_max_max,
714 },
715 {
716 .ctl_name = KERN_PANIC_ON_OOPS,
717 .procname = "panic_on_oops",
718 .data = &panic_on_oops,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
722 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800723#if defined CONFIG_PRINTK
724 {
725 .ctl_name = KERN_PRINTK,
726 .procname = "printk",
727 .data = &console_loglevel,
728 .maxlen = 4*sizeof(int),
729 .mode = 0644,
730 .proc_handler = &proc_dointvec,
731 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 {
733 .ctl_name = KERN_PRINTK_RATELIMIT,
734 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700735 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 .maxlen = sizeof(int),
737 .mode = 0644,
738 .proc_handler = &proc_dointvec_jiffies,
739 .strategy = &sysctl_jiffies,
740 },
741 {
742 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
743 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700744 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
748 },
Dave Youngaf913222009-09-22 16:43:33 -0700749 {
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "printk_delay",
752 .data = &printk_delay_msec,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = &proc_dointvec_minmax,
756 .strategy = &sysctl_intvec,
757 .extra1 = &zero,
758 .extra2 = &ten_thousand,
759 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800760#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 {
762 .ctl_name = KERN_NGROUPS_MAX,
763 .procname = "ngroups_max",
764 .data = &ngroups_max,
765 .maxlen = sizeof (int),
766 .mode = 0444,
767 .proc_handler = &proc_dointvec,
768 },
769#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
770 {
771 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
772 .procname = "unknown_nmi_panic",
773 .data = &unknown_nmi_panic,
774 .maxlen = sizeof (int),
775 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200776 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 },
Don Zickus407984f2006-09-26 10:52:27 +0200778 {
Don Zickus407984f2006-09-26 10:52:27 +0200779 .procname = "nmi_watchdog",
780 .data = &nmi_watchdog_enabled,
781 .maxlen = sizeof (int),
782 .mode = 0644,
783 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 },
785#endif
786#if defined(CONFIG_X86)
787 {
Don Zickus8da5add2006-09-26 10:52:27 +0200788 .ctl_name = KERN_PANIC_ON_NMI,
789 .procname = "panic_on_unrecovered_nmi",
790 .data = &panic_on_unrecovered_nmi,
791 .maxlen = sizeof(int),
792 .mode = 0644,
793 .proc_handler = &proc_dointvec,
794 },
795 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700796 .ctl_name = CTL_UNNUMBERED,
797 .procname = "panic_on_io_nmi",
798 .data = &panic_on_io_nmi,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
803 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 .ctl_name = KERN_BOOTLOADER_TYPE,
805 .procname = "bootloader_type",
806 .data = &bootloader_type,
807 .maxlen = sizeof (int),
808 .mode = 0444,
809 .proc_handler = &proc_dointvec,
810 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100811 {
812 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700813 .procname = "bootloader_version",
814 .data = &bootloader_version,
815 .maxlen = sizeof (int),
816 .mode = 0444,
817 .proc_handler = &proc_dointvec,
818 },
819 {
820 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100821 .procname = "kstack_depth_to_print",
822 .data = &kstack_depth_to_print,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec,
826 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100827 {
828 .ctl_name = CTL_UNNUMBERED,
829 .procname = "io_delay_type",
830 .data = &io_delay_type,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec,
834 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800836#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 {
838 .ctl_name = KERN_RANDOMIZE,
839 .procname = "randomize_va_space",
840 .data = &randomize_va_space,
841 .maxlen = sizeof(int),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
844 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800845#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800846#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700847 {
848 .ctl_name = KERN_SPIN_RETRY,
849 .procname = "spin_retry",
850 .data = &spin_retry,
851 .maxlen = sizeof (int),
852 .mode = 0644,
853 .proc_handler = &proc_dointvec,
854 },
855#endif
Len Brown673d5b42007-07-28 03:33:16 -0400856#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800857 {
Pavel Machekc255d842006-02-20 18:27:58 -0800858 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700859 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800860 .maxlen = sizeof (unsigned long),
861 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800862 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800863 },
864#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800865#ifdef CONFIG_IA64
866 {
867 .ctl_name = KERN_IA64_UNALIGNED,
868 .procname = "ignore-unaligned-usertrap",
869 .data = &no_unaligned_warning,
870 .maxlen = sizeof (int),
871 .mode = 0644,
872 .proc_handler = &proc_dointvec,
873 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800874 {
875 .ctl_name = CTL_UNNUMBERED,
876 .procname = "unaligned-dump-stack",
877 .data = &unaligned_dump_stack,
878 .maxlen = sizeof (int),
879 .mode = 0644,
880 .proc_handler = &proc_dointvec,
881 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800882#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700883#ifdef CONFIG_DETECT_SOFTLOCKUP
884 {
885 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200886 .procname = "softlockup_panic",
887 .data = &softlockup_panic,
888 .maxlen = sizeof(int),
889 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700890 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200891 .strategy = &sysctl_intvec,
892 .extra1 = &zero,
893 .extra2 = &one,
894 },
895 {
896 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700897 .procname = "softlockup_thresh",
898 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200899 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700900 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800901 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700902 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200903 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700904 .extra2 = &sixty,
905 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800906#endif
907#ifdef CONFIG_DETECT_HUNG_TASK
908 {
909 .ctl_name = CTL_UNNUMBERED,
910 .procname = "hung_task_panic",
911 .data = &sysctl_hung_task_panic,
912 .maxlen = sizeof(int),
913 .mode = 0644,
914 .proc_handler = &proc_dointvec_minmax,
915 .strategy = &sysctl_intvec,
916 .extra1 = &zero,
917 .extra2 = &one,
918 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100919 {
920 .ctl_name = CTL_UNNUMBERED,
921 .procname = "hung_task_check_count",
922 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100923 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100924 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100925 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100926 .strategy = &sysctl_intvec,
927 },
928 {
929 .ctl_name = CTL_UNNUMBERED,
930 .procname = "hung_task_timeout_secs",
931 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100932 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100933 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800934 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100935 .strategy = &sysctl_intvec,
936 },
937 {
938 .ctl_name = CTL_UNNUMBERED,
939 .procname = "hung_task_warnings",
940 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100941 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100942 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100943 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100944 .strategy = &sysctl_intvec,
945 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700946#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200947#ifdef CONFIG_COMPAT
948 {
949 .ctl_name = KERN_COMPAT_LOG,
950 .procname = "compat-log",
951 .data = &compat_log,
952 .maxlen = sizeof (int),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
955 },
956#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700957#ifdef CONFIG_RT_MUTEXES
958 {
959 .ctl_name = KERN_MAX_LOCK_DEPTH,
960 .procname = "max_lock_depth",
961 .data = &max_lock_depth,
962 .maxlen = sizeof(int),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 },
966#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700967 {
968 .ctl_name = CTL_UNNUMBERED,
969 .procname = "poweroff_cmd",
970 .data = &poweroff_cmd,
971 .maxlen = POWEROFF_CMD_PATH_LEN,
972 .mode = 0644,
973 .proc_handler = &proc_dostring,
974 .strategy = &sysctl_string,
975 },
David Howells0b77f5b2008-04-29 01:01:32 -0700976#ifdef CONFIG_KEYS
977 {
978 .ctl_name = CTL_UNNUMBERED,
979 .procname = "keys",
980 .mode = 0555,
981 .child = key_sysctls,
982 },
983#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700984#ifdef CONFIG_RCU_TORTURE_TEST
985 {
986 .ctl_name = CTL_UNNUMBERED,
987 .procname = "rcutorture_runnable",
988 .data = &rcutorture_runnable,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = &proc_dointvec,
992 },
993#endif
David Howells12e22c52009-04-03 16:42:35 +0100994#ifdef CONFIG_SLOW_WORK
995 {
996 .ctl_name = CTL_UNNUMBERED,
997 .procname = "slow-work",
998 .mode = 0555,
999 .child = slow_work_sysctls,
1000 },
1001#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001002#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001003 {
1004 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001005 .procname = "perf_event_paranoid",
1006 .data = &sysctl_perf_event_paranoid,
1007 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001008 .mode = 0644,
1009 .proc_handler = &proc_dointvec,
1010 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001011 {
1012 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001013 .procname = "perf_event_mlock_kb",
1014 .data = &sysctl_perf_event_mlock,
1015 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001016 .mode = 0644,
1017 .proc_handler = &proc_dointvec,
1018 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001019 {
1020 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001021 .procname = "perf_event_max_sample_rate",
1022 .data = &sysctl_perf_event_sample_rate,
1023 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001024 .mode = 0644,
1025 .proc_handler = &proc_dointvec,
1026 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001027#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001028#ifdef CONFIG_KMEMCHECK
1029 {
1030 .ctl_name = CTL_UNNUMBERED,
1031 .procname = "kmemcheck",
1032 .data = &kmemcheck_enabled,
1033 .maxlen = sizeof(int),
1034 .mode = 0644,
1035 .proc_handler = &proc_dointvec,
1036 },
1037#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001038#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001039 {
1040 .ctl_name = CTL_UNNUMBERED,
1041 .procname = "blk_iopoll",
1042 .data = &blk_iopoll_enabled,
1043 .maxlen = sizeof(int),
1044 .mode = 0644,
1045 .proc_handler = &proc_dointvec,
1046 },
Jens Axboecb684b52009-09-15 21:53:11 +02001047#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001048/*
1049 * NOTE: do not add new entries to this table unless you have read
1050 * Documentation/sysctl/ctl_unnumbered.txt
1051 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 { .ctl_name = 0 }
1053};
1054
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001055static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 {
1057 .ctl_name = VM_OVERCOMMIT_MEMORY,
1058 .procname = "overcommit_memory",
1059 .data = &sysctl_overcommit_memory,
1060 .maxlen = sizeof(sysctl_overcommit_memory),
1061 .mode = 0644,
1062 .proc_handler = &proc_dointvec,
1063 },
1064 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001065 .ctl_name = VM_PANIC_ON_OOM,
1066 .procname = "panic_on_oom",
1067 .data = &sysctl_panic_on_oom,
1068 .maxlen = sizeof(sysctl_panic_on_oom),
1069 .mode = 0644,
1070 .proc_handler = &proc_dointvec,
1071 },
1072 {
David Rientjesfe071d72007-10-16 23:25:56 -07001073 .ctl_name = CTL_UNNUMBERED,
1074 .procname = "oom_kill_allocating_task",
1075 .data = &sysctl_oom_kill_allocating_task,
1076 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1077 .mode = 0644,
1078 .proc_handler = &proc_dointvec,
1079 },
1080 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001081 .ctl_name = CTL_UNNUMBERED,
1082 .procname = "oom_dump_tasks",
1083 .data = &sysctl_oom_dump_tasks,
1084 .maxlen = sizeof(sysctl_oom_dump_tasks),
1085 .mode = 0644,
1086 .proc_handler = &proc_dointvec,
1087 },
1088 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 .ctl_name = VM_OVERCOMMIT_RATIO,
1090 .procname = "overcommit_ratio",
1091 .data = &sysctl_overcommit_ratio,
1092 .maxlen = sizeof(sysctl_overcommit_ratio),
1093 .mode = 0644,
1094 .proc_handler = &proc_dointvec,
1095 },
1096 {
1097 .ctl_name = VM_PAGE_CLUSTER,
1098 .procname = "page-cluster",
1099 .data = &page_cluster,
1100 .maxlen = sizeof(int),
1101 .mode = 0644,
1102 .proc_handler = &proc_dointvec,
1103 },
1104 {
1105 .ctl_name = VM_DIRTY_BACKGROUND,
1106 .procname = "dirty_background_ratio",
1107 .data = &dirty_background_ratio,
1108 .maxlen = sizeof(dirty_background_ratio),
1109 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001110 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 .strategy = &sysctl_intvec,
1112 .extra1 = &zero,
1113 .extra2 = &one_hundred,
1114 },
1115 {
David Rientjes2da02992009-01-06 14:39:31 -08001116 .ctl_name = CTL_UNNUMBERED,
1117 .procname = "dirty_background_bytes",
1118 .data = &dirty_background_bytes,
1119 .maxlen = sizeof(dirty_background_bytes),
1120 .mode = 0644,
1121 .proc_handler = &dirty_background_bytes_handler,
1122 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001123 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001124 },
1125 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 .ctl_name = VM_DIRTY_RATIO,
1127 .procname = "dirty_ratio",
1128 .data = &vm_dirty_ratio,
1129 .maxlen = sizeof(vm_dirty_ratio),
1130 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001131 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 .strategy = &sysctl_intvec,
1133 .extra1 = &zero,
1134 .extra2 = &one_hundred,
1135 },
1136 {
David Rientjes2da02992009-01-06 14:39:31 -08001137 .ctl_name = CTL_UNNUMBERED,
1138 .procname = "dirty_bytes",
1139 .data = &vm_dirty_bytes,
1140 .maxlen = sizeof(vm_dirty_bytes),
1141 .mode = 0644,
1142 .proc_handler = &dirty_bytes_handler,
1143 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001144 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001145 },
1146 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001148 .data = &dirty_writeback_interval,
1149 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 .mode = 0644,
1151 .proc_handler = &dirty_writeback_centisecs_handler,
1152 },
1153 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001155 .data = &dirty_expire_interval,
1156 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001158 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 },
1160 {
1161 .ctl_name = VM_NR_PDFLUSH_THREADS,
1162 .procname = "nr_pdflush_threads",
1163 .data = &nr_pdflush_threads,
1164 .maxlen = sizeof nr_pdflush_threads,
1165 .mode = 0444 /* read-only*/,
1166 .proc_handler = &proc_dointvec,
1167 },
1168 {
1169 .ctl_name = VM_SWAPPINESS,
1170 .procname = "swappiness",
1171 .data = &vm_swappiness,
1172 .maxlen = sizeof(vm_swappiness),
1173 .mode = 0644,
1174 .proc_handler = &proc_dointvec_minmax,
1175 .strategy = &sysctl_intvec,
1176 .extra1 = &zero,
1177 .extra2 = &one_hundred,
1178 },
1179#ifdef CONFIG_HUGETLB_PAGE
1180 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001182 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 .maxlen = sizeof(unsigned long),
1184 .mode = 0644,
1185 .proc_handler = &hugetlb_sysctl_handler,
1186 .extra1 = (void *)&hugetlb_zero,
1187 .extra2 = (void *)&hugetlb_infinity,
1188 },
1189 {
1190 .ctl_name = VM_HUGETLB_GROUP,
1191 .procname = "hugetlb_shm_group",
1192 .data = &sysctl_hugetlb_shm_group,
1193 .maxlen = sizeof(gid_t),
1194 .mode = 0644,
1195 .proc_handler = &proc_dointvec,
1196 },
Mel Gorman396faf02007-07-17 04:03:13 -07001197 {
1198 .ctl_name = CTL_UNNUMBERED,
1199 .procname = "hugepages_treat_as_movable",
1200 .data = &hugepages_treat_as_movable,
1201 .maxlen = sizeof(int),
1202 .mode = 0644,
1203 .proc_handler = &hugetlb_treat_movable_handler,
1204 },
Adam Litke54f9f802007-10-16 01:26:20 -07001205 {
1206 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001207 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001208 .data = NULL,
1209 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001210 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001211 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001212 .extra1 = (void *)&hugetlb_zero,
1213 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001214 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215#endif
1216 {
1217 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1218 .procname = "lowmem_reserve_ratio",
1219 .data = &sysctl_lowmem_reserve_ratio,
1220 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1221 .mode = 0644,
1222 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1223 .strategy = &sysctl_intvec,
1224 },
1225 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001226 .ctl_name = VM_DROP_PAGECACHE,
1227 .procname = "drop_caches",
1228 .data = &sysctl_drop_caches,
1229 .maxlen = sizeof(int),
1230 .mode = 0644,
1231 .proc_handler = drop_caches_sysctl_handler,
1232 .strategy = &sysctl_intvec,
1233 },
1234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 .ctl_name = VM_MIN_FREE_KBYTES,
1236 .procname = "min_free_kbytes",
1237 .data = &min_free_kbytes,
1238 .maxlen = sizeof(min_free_kbytes),
1239 .mode = 0644,
1240 .proc_handler = &min_free_kbytes_sysctl_handler,
1241 .strategy = &sysctl_intvec,
1242 .extra1 = &zero,
1243 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001244 {
1245 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1246 .procname = "percpu_pagelist_fraction",
1247 .data = &percpu_pagelist_fraction,
1248 .maxlen = sizeof(percpu_pagelist_fraction),
1249 .mode = 0644,
1250 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1251 .strategy = &sysctl_intvec,
1252 .extra1 = &min_percpu_pagelist_fract,
1253 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254#ifdef CONFIG_MMU
1255 {
1256 .ctl_name = VM_MAX_MAP_COUNT,
1257 .procname = "max_map_count",
1258 .data = &sysctl_max_map_count,
1259 .maxlen = sizeof(sysctl_max_map_count),
1260 .mode = 0644,
1261 .proc_handler = &proc_dointvec
1262 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001263#else
1264 {
1265 .ctl_name = CTL_UNNUMBERED,
1266 .procname = "nr_trim_pages",
1267 .data = &sysctl_nr_trim_pages,
1268 .maxlen = sizeof(sysctl_nr_trim_pages),
1269 .mode = 0644,
1270 .proc_handler = &proc_dointvec_minmax,
1271 .strategy = &sysctl_intvec,
1272 .extra1 = &zero,
1273 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274#endif
1275 {
1276 .ctl_name = VM_LAPTOP_MODE,
1277 .procname = "laptop_mode",
1278 .data = &laptop_mode,
1279 .maxlen = sizeof(laptop_mode),
1280 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001281 .proc_handler = &proc_dointvec_jiffies,
1282 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 },
1284 {
1285 .ctl_name = VM_BLOCK_DUMP,
1286 .procname = "block_dump",
1287 .data = &block_dump,
1288 .maxlen = sizeof(block_dump),
1289 .mode = 0644,
1290 .proc_handler = &proc_dointvec,
1291 .strategy = &sysctl_intvec,
1292 .extra1 = &zero,
1293 },
1294 {
1295 .ctl_name = VM_VFS_CACHE_PRESSURE,
1296 .procname = "vfs_cache_pressure",
1297 .data = &sysctl_vfs_cache_pressure,
1298 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1299 .mode = 0644,
1300 .proc_handler = &proc_dointvec,
1301 .strategy = &sysctl_intvec,
1302 .extra1 = &zero,
1303 },
1304#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1305 {
1306 .ctl_name = VM_LEGACY_VA_LAYOUT,
1307 .procname = "legacy_va_layout",
1308 .data = &sysctl_legacy_va_layout,
1309 .maxlen = sizeof(sysctl_legacy_va_layout),
1310 .mode = 0644,
1311 .proc_handler = &proc_dointvec,
1312 .strategy = &sysctl_intvec,
1313 .extra1 = &zero,
1314 },
1315#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001316#ifdef CONFIG_NUMA
1317 {
1318 .ctl_name = VM_ZONE_RECLAIM_MODE,
1319 .procname = "zone_reclaim_mode",
1320 .data = &zone_reclaim_mode,
1321 .maxlen = sizeof(zone_reclaim_mode),
1322 .mode = 0644,
1323 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001324 .strategy = &sysctl_intvec,
1325 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001326 },
Christoph Lameter96146342006-07-03 00:24:13 -07001327 {
1328 .ctl_name = VM_MIN_UNMAPPED,
1329 .procname = "min_unmapped_ratio",
1330 .data = &sysctl_min_unmapped_ratio,
1331 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1332 .mode = 0644,
1333 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1334 .strategy = &sysctl_intvec,
1335 .extra1 = &zero,
1336 .extra2 = &one_hundred,
1337 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001338 {
1339 .ctl_name = VM_MIN_SLAB,
1340 .procname = "min_slab_ratio",
1341 .data = &sysctl_min_slab_ratio,
1342 .maxlen = sizeof(sysctl_min_slab_ratio),
1343 .mode = 0644,
1344 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1345 .strategy = &sysctl_intvec,
1346 .extra1 = &zero,
1347 .extra2 = &one_hundred,
1348 },
Christoph Lameter17436602006-01-18 17:42:32 -08001349#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001350#ifdef CONFIG_SMP
1351 {
1352 .ctl_name = CTL_UNNUMBERED,
1353 .procname = "stat_interval",
1354 .data = &sysctl_stat_interval,
1355 .maxlen = sizeof(sysctl_stat_interval),
1356 .mode = 0644,
1357 .proc_handler = &proc_dointvec_jiffies,
1358 .strategy = &sysctl_jiffies,
1359 },
1360#endif
Eric Parised032182007-06-28 15:55:21 -04001361 {
1362 .ctl_name = CTL_UNNUMBERED,
1363 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001364 .data = &dac_mmap_min_addr,
1365 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001366 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001367 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001368 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001369#ifdef CONFIG_NUMA
1370 {
1371 .ctl_name = CTL_UNNUMBERED,
1372 .procname = "numa_zonelist_order",
1373 .data = &numa_zonelist_order,
1374 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1375 .mode = 0644,
1376 .proc_handler = &numa_zonelist_order_handler,
1377 .strategy = &sysctl_string,
1378 },
1379#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001380#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001381 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001382 {
1383 .ctl_name = VM_VDSO_ENABLED,
1384 .procname = "vdso_enabled",
1385 .data = &vdso_enabled,
1386 .maxlen = sizeof(vdso_enabled),
1387 .mode = 0644,
1388 .proc_handler = &proc_dointvec,
1389 .strategy = &sysctl_intvec,
1390 .extra1 = &zero,
1391 },
1392#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001393#ifdef CONFIG_HIGHMEM
1394 {
1395 .ctl_name = CTL_UNNUMBERED,
1396 .procname = "highmem_is_dirtyable",
1397 .data = &vm_highmem_is_dirtyable,
1398 .maxlen = sizeof(vm_highmem_is_dirtyable),
1399 .mode = 0644,
1400 .proc_handler = &proc_dointvec_minmax,
1401 .strategy = &sysctl_intvec,
1402 .extra1 = &zero,
1403 .extra2 = &one,
1404 },
1405#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001406 {
1407 .ctl_name = CTL_UNNUMBERED,
1408 .procname = "scan_unevictable_pages",
1409 .data = &scan_unevictable_pages,
1410 .maxlen = sizeof(scan_unevictable_pages),
1411 .mode = 0644,
1412 .proc_handler = &scan_unevictable_handler,
1413 },
Andi Kleen6a460792009-09-16 11:50:15 +02001414#ifdef CONFIG_MEMORY_FAILURE
1415 {
1416 .ctl_name = CTL_UNNUMBERED,
1417 .procname = "memory_failure_early_kill",
1418 .data = &sysctl_memory_failure_early_kill,
1419 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1420 .mode = 0644,
1421 .proc_handler = &proc_dointvec_minmax,
1422 .strategy = &sysctl_intvec,
1423 .extra1 = &zero,
1424 .extra2 = &one,
1425 },
1426 {
1427 .ctl_name = CTL_UNNUMBERED,
1428 .procname = "memory_failure_recovery",
1429 .data = &sysctl_memory_failure_recovery,
1430 .maxlen = sizeof(sysctl_memory_failure_recovery),
1431 .mode = 0644,
1432 .proc_handler = &proc_dointvec_minmax,
1433 .strategy = &sysctl_intvec,
1434 .extra1 = &zero,
1435 .extra2 = &one,
1436 },
1437#endif
1438
Andrew Morton2be7fe02007-07-15 23:41:21 -07001439/*
1440 * NOTE: do not add new entries to this table unless you have read
1441 * Documentation/sysctl/ctl_unnumbered.txt
1442 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 { .ctl_name = 0 }
1444};
1445
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001446#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001447static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001448 { .ctl_name = 0 }
1449};
1450#endif
1451
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001452static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 {
1454 .ctl_name = FS_NRINODE,
1455 .procname = "inode-nr",
1456 .data = &inodes_stat,
1457 .maxlen = 2*sizeof(int),
1458 .mode = 0444,
1459 .proc_handler = &proc_dointvec,
1460 },
1461 {
1462 .ctl_name = FS_STATINODE,
1463 .procname = "inode-state",
1464 .data = &inodes_stat,
1465 .maxlen = 7*sizeof(int),
1466 .mode = 0444,
1467 .proc_handler = &proc_dointvec,
1468 },
1469 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 .procname = "file-nr",
1471 .data = &files_stat,
1472 .maxlen = 3*sizeof(int),
1473 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001474 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 },
1476 {
1477 .ctl_name = FS_MAXFILE,
1478 .procname = "file-max",
1479 .data = &files_stat.max_files,
1480 .maxlen = sizeof(int),
1481 .mode = 0644,
1482 .proc_handler = &proc_dointvec,
1483 },
1484 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001485 .ctl_name = CTL_UNNUMBERED,
1486 .procname = "nr_open",
1487 .data = &sysctl_nr_open,
1488 .maxlen = sizeof(int),
1489 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001490 .proc_handler = &proc_dointvec_minmax,
1491 .extra1 = &sysctl_nr_open_min,
1492 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001493 },
1494 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 .ctl_name = FS_DENTRY,
1496 .procname = "dentry-state",
1497 .data = &dentry_stat,
1498 .maxlen = 6*sizeof(int),
1499 .mode = 0444,
1500 .proc_handler = &proc_dointvec,
1501 },
1502 {
1503 .ctl_name = FS_OVERFLOWUID,
1504 .procname = "overflowuid",
1505 .data = &fs_overflowuid,
1506 .maxlen = sizeof(int),
1507 .mode = 0644,
1508 .proc_handler = &proc_dointvec_minmax,
1509 .strategy = &sysctl_intvec,
1510 .extra1 = &minolduid,
1511 .extra2 = &maxolduid,
1512 },
1513 {
1514 .ctl_name = FS_OVERFLOWGID,
1515 .procname = "overflowgid",
1516 .data = &fs_overflowgid,
1517 .maxlen = sizeof(int),
1518 .mode = 0644,
1519 .proc_handler = &proc_dointvec_minmax,
1520 .strategy = &sysctl_intvec,
1521 .extra1 = &minolduid,
1522 .extra2 = &maxolduid,
1523 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001524#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 {
1526 .ctl_name = FS_LEASES,
1527 .procname = "leases-enable",
1528 .data = &leases_enable,
1529 .maxlen = sizeof(int),
1530 .mode = 0644,
1531 .proc_handler = &proc_dointvec,
1532 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001533#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534#ifdef CONFIG_DNOTIFY
1535 {
1536 .ctl_name = FS_DIR_NOTIFY,
1537 .procname = "dir-notify-enable",
1538 .data = &dir_notify_enable,
1539 .maxlen = sizeof(int),
1540 .mode = 0644,
1541 .proc_handler = &proc_dointvec,
1542 },
1543#endif
1544#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001545#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 {
1547 .ctl_name = FS_LEASE_TIME,
1548 .procname = "lease-break-time",
1549 .data = &lease_break_time,
1550 .maxlen = sizeof(int),
1551 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001552 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001554#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001555#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 .procname = "aio-nr",
1558 .data = &aio_nr,
1559 .maxlen = sizeof(aio_nr),
1560 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001561 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 },
1563 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 .procname = "aio-max-nr",
1565 .data = &aio_max_nr,
1566 .maxlen = sizeof(aio_max_nr),
1567 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001568 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001570#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001571#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001572 {
1573 .ctl_name = FS_INOTIFY,
1574 .procname = "inotify",
1575 .mode = 0555,
1576 .child = inotify_table,
1577 },
1578#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001579#ifdef CONFIG_EPOLL
1580 {
1581 .procname = "epoll",
1582 .mode = 0555,
1583 .child = epoll_table,
1584 },
1585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001587 {
1588 .ctl_name = KERN_SETUID_DUMPABLE,
1589 .procname = "suid_dumpable",
1590 .data = &suid_dumpable,
1591 .maxlen = sizeof(int),
1592 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001593 .proc_handler = &proc_dointvec_minmax,
1594 .strategy = &sysctl_intvec,
1595 .extra1 = &zero,
1596 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001597 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001598#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1599 {
1600 .ctl_name = CTL_UNNUMBERED,
1601 .procname = "binfmt_misc",
1602 .mode = 0555,
1603 .child = binfmt_misc_table,
1604 },
1605#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001606/*
1607 * NOTE: do not add new entries to this table unless you have read
1608 * Documentation/sysctl/ctl_unnumbered.txt
1609 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 { .ctl_name = 0 }
1611};
1612
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001613static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001614#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001615 {
1616 .ctl_name = CTL_UNNUMBERED,
1617 .procname = "exception-trace",
1618 .data = &show_unhandled_signals,
1619 .maxlen = sizeof(int),
1620 .mode = 0644,
1621 .proc_handler = proc_dointvec
1622 },
1623#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 { .ctl_name = 0 }
1625};
1626
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001627static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001629};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
Al Viro330d57f2005-11-04 10:18:40 +00001631static DEFINE_SPINLOCK(sysctl_lock);
1632
1633/* called under sysctl_lock */
1634static int use_table(struct ctl_table_header *p)
1635{
1636 if (unlikely(p->unregistering))
1637 return 0;
1638 p->used++;
1639 return 1;
1640}
1641
1642/* called under sysctl_lock */
1643static void unuse_table(struct ctl_table_header *p)
1644{
1645 if (!--p->used)
1646 if (unlikely(p->unregistering))
1647 complete(p->unregistering);
1648}
1649
1650/* called under sysctl_lock, will reacquire if has to wait */
1651static void start_unregistering(struct ctl_table_header *p)
1652{
1653 /*
1654 * if p->used is 0, nobody will ever touch that entry again;
1655 * we'll eliminate all paths to it before dropping sysctl_lock
1656 */
1657 if (unlikely(p->used)) {
1658 struct completion wait;
1659 init_completion(&wait);
1660 p->unregistering = &wait;
1661 spin_unlock(&sysctl_lock);
1662 wait_for_completion(&wait);
1663 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001664 } else {
1665 /* anything non-NULL; we'll never dereference it */
1666 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001667 }
1668 /*
1669 * do not remove from the list until nobody holds it; walking the
1670 * list in do_sysctl() relies on that.
1671 */
1672 list_del_init(&p->ctl_entry);
1673}
1674
Al Virof7e6ced2008-07-15 01:44:23 -04001675void sysctl_head_get(struct ctl_table_header *head)
1676{
1677 spin_lock(&sysctl_lock);
1678 head->count++;
1679 spin_unlock(&sysctl_lock);
1680}
1681
1682void sysctl_head_put(struct ctl_table_header *head)
1683{
1684 spin_lock(&sysctl_lock);
1685 if (!--head->count)
1686 kfree(head);
1687 spin_unlock(&sysctl_lock);
1688}
1689
1690struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1691{
1692 if (!head)
1693 BUG();
1694 spin_lock(&sysctl_lock);
1695 if (!use_table(head))
1696 head = ERR_PTR(-ENOENT);
1697 spin_unlock(&sysctl_lock);
1698 return head;
1699}
1700
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001701void sysctl_head_finish(struct ctl_table_header *head)
1702{
1703 if (!head)
1704 return;
1705 spin_lock(&sysctl_lock);
1706 unuse_table(head);
1707 spin_unlock(&sysctl_lock);
1708}
1709
Al Viro73455092008-07-14 21:22:20 -04001710static struct ctl_table_set *
1711lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1712{
1713 struct ctl_table_set *set = &root->default_set;
1714 if (root->lookup)
1715 set = root->lookup(root, namespaces);
1716 return set;
1717}
1718
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001719static struct list_head *
1720lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001721{
Al Viro73455092008-07-14 21:22:20 -04001722 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1723 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001724}
1725
1726struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1727 struct ctl_table_header *prev)
1728{
1729 struct ctl_table_root *root;
1730 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001731 struct ctl_table_header *head;
1732 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001733
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001734 spin_lock(&sysctl_lock);
1735 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001736 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001737 tmp = &prev->ctl_entry;
1738 unuse_table(prev);
1739 goto next;
1740 }
1741 tmp = &root_table_header.ctl_entry;
1742 for (;;) {
1743 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1744
1745 if (!use_table(head))
1746 goto next;
1747 spin_unlock(&sysctl_lock);
1748 return head;
1749 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001750 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001751 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001752 header_list = lookup_header_list(root, namespaces);
1753 if (tmp != header_list)
1754 continue;
1755
1756 do {
1757 root = list_entry(root->root_list.next,
1758 struct ctl_table_root, root_list);
1759 if (root == &sysctl_table_root)
1760 goto out;
1761 header_list = lookup_header_list(root, namespaces);
1762 } while (list_empty(header_list));
1763 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001764 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001765out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001766 spin_unlock(&sysctl_lock);
1767 return NULL;
1768}
1769
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001770struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1771{
1772 return __sysctl_head_next(current->nsproxy, prev);
1773}
1774
1775void register_sysctl_root(struct ctl_table_root *root)
1776{
1777 spin_lock(&sysctl_lock);
1778 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1779 spin_unlock(&sysctl_lock);
1780}
1781
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001782#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001783/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001784static int do_sysctl_strategy(struct ctl_table_root *root,
1785 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001786 void __user *oldval, size_t __user *oldlenp,
1787 void __user *newval, size_t newlen)
1788{
1789 int op = 0, rc;
1790
1791 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001792 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001793 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001794 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001795 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001796 return -EPERM;
1797
1798 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001799 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001800 if (rc < 0)
1801 return rc;
1802 if (rc > 0)
1803 return 0;
1804 }
1805
1806 /* If there is no strategy routine, or if the strategy returns
1807 * zero, proceed with automatic r/w */
1808 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001809 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001810 if (rc < 0)
1811 return rc;
1812 }
1813 return 0;
1814}
1815
1816static int parse_table(int __user *name, int nlen,
1817 void __user *oldval, size_t __user *oldlenp,
1818 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001819 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001820 struct ctl_table *table)
1821{
1822 int n;
1823repeat:
1824 if (!nlen)
1825 return -ENOTDIR;
1826 if (get_user(n, name))
1827 return -EFAULT;
1828 for ( ; table->ctl_name || table->procname; table++) {
1829 if (!table->ctl_name)
1830 continue;
1831 if (n == table->ctl_name) {
1832 int error;
1833 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001834 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001835 return -EPERM;
1836 name++;
1837 nlen--;
1838 table = table->child;
1839 goto repeat;
1840 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001841 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001842 oldval, oldlenp,
1843 newval, newlen);
1844 return error;
1845 }
1846 }
1847 return -ENOTDIR;
1848}
1849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1851 void __user *newval, size_t newlen)
1852{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001853 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001854 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
1856 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1857 return -ENOTDIR;
1858 if (oldval) {
1859 int old_len;
1860 if (!oldlenp || get_user(old_len, oldlenp))
1861 return -EFAULT;
1862 }
Al Viro330d57f2005-11-04 10:18:40 +00001863
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001864 for (head = sysctl_head_next(NULL); head;
1865 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001866 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001867 newval, newlen,
1868 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001869 if (error != -ENOTDIR) {
1870 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001871 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001872 }
1873 }
Al Viro330d57f2005-11-04 10:18:40 +00001874 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875}
1876
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001877SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
1879 struct __sysctl_args tmp;
1880 int error;
1881
1882 if (copy_from_user(&tmp, args, sizeof(tmp)))
1883 return -EFAULT;
1884
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001885 error = deprecated_sysctl_warning(&tmp);
1886 if (error)
1887 goto out;
1888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 lock_kernel();
1890 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1891 tmp.newval, tmp.newlen);
1892 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001893out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 return error;
1895}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001896#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
1898/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001899 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 * some sysctl variables are readonly even to root.
1901 */
1902
1903static int test_perm(int mode, int op)
1904{
David Howells76aac0e2008-11-14 10:39:12 +11001905 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 mode >>= 6;
1907 else if (in_egroup_p(0))
1908 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001909 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 return 0;
1911 return -EACCES;
1912}
1913
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001914int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915{
1916 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001917 int mode;
1918
Al Viroe6305c42008-07-15 21:03:57 -04001919 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 if (error)
1921 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001922
1923 if (root->permissions)
1924 mode = root->permissions(root, current->nsproxy, table);
1925 else
1926 mode = table->mode;
1927
1928 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929}
1930
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001931static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1932{
1933 for (; table->ctl_name || table->procname; table++) {
1934 table->parent = parent;
1935 if (table->child)
1936 sysctl_set_parent(table, table->child);
1937 }
1938}
1939
1940static __init int sysctl_init(void)
1941{
1942 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001943#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1944 {
1945 int err;
1946 err = sysctl_check_table(current->nsproxy, root_table);
1947 }
1948#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001949 return 0;
1950}
1951
1952core_initcall(sysctl_init);
1953
Al Virobfbcf032008-07-27 06:31:22 +01001954static struct ctl_table *is_branch_in(struct ctl_table *branch,
1955 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001956{
1957 struct ctl_table *p;
1958 const char *s = branch->procname;
1959
1960 /* branch should have named subdirectory as its first element */
1961 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001962 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001963
1964 /* ... and nothing else */
1965 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001966 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001967
1968 /* table should contain subdirectory with the same name */
1969 for (p = table; p->procname || p->ctl_name; p++) {
1970 if (!p->child)
1971 continue;
1972 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001973 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001974 }
Al Virobfbcf032008-07-27 06:31:22 +01001975 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001976}
1977
1978/* see if attaching q to p would be an improvement */
1979static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1980{
1981 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001982 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001983 int is_better = 0;
1984 int not_in_parent = !p->attached_by;
1985
Al Virobfbcf032008-07-27 06:31:22 +01001986 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001987 if (by == q->attached_by)
1988 is_better = 1;
1989 if (to == p->attached_by)
1990 not_in_parent = 1;
1991 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001992 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001993 }
1994
1995 if (is_better && not_in_parent) {
1996 q->attached_by = by;
1997 q->attached_to = to;
1998 q->parent = p;
1999 }
2000}
2001
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002003 * __register_sysctl_paths - register a sysctl hierarchy
2004 * @root: List of sysctl headers to register on
2005 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002006 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 *
2009 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002010 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002012 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 *
2014 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
2015 * must be unique within that level of sysctl
2016 *
2017 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2018 * enter a sysctl file
2019 *
2020 * data - a pointer to data for use by proc_handler
2021 *
2022 * maxlen - the maximum size in bytes of the data
2023 *
2024 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2025 *
2026 * child - a pointer to the child sysctl table if this entry is a directory, or
2027 * %NULL.
2028 *
2029 * proc_handler - the text handler routine (described below)
2030 *
2031 * strategy - the strategy routine (described below)
2032 *
2033 * de - for internal use by the sysctl routines
2034 *
2035 * extra1, extra2 - extra pointers usable by the proc handler routines
2036 *
2037 * Leaf nodes in the sysctl tree will be represented by a single file
2038 * under /proc; non-leaf nodes will be represented by directories.
2039 *
2040 * sysctl(2) can automatically manage read and write requests through
2041 * the sysctl table. The data and maxlen fields of the ctl_table
2042 * struct enable minimal validation of the values being written to be
2043 * performed, and the mode field allows minimal authentication.
2044 *
2045 * More sophisticated management can be enabled by the provision of a
2046 * strategy routine with the table entry. This will be called before
2047 * any automatic read or write of the data is performed.
2048 *
2049 * The strategy routine may return
2050 *
2051 * < 0 - Error occurred (error is passed to user process)
2052 *
2053 * 0 - OK - proceed with automatic read or write.
2054 *
2055 * > 0 - OK - read or write has been done by the strategy routine, so
2056 * return immediately.
2057 *
2058 * There must be a proc_handler routine for any terminal nodes
2059 * mirrored under /proc/sys (non-terminals are handled by a built-in
2060 * directory handler). Several default handlers are available to
2061 * cover common cases -
2062 *
2063 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2064 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2065 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2066 *
2067 * It is the handler's job to read the input buffer from user memory
2068 * and process it. The handler should return 0 on success.
2069 *
2070 * This routine returns %NULL on a failure to register, and a pointer
2071 * to the table header on success.
2072 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002073struct ctl_table_header *__register_sysctl_paths(
2074 struct ctl_table_root *root,
2075 struct nsproxy *namespaces,
2076 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002078 struct ctl_table_header *header;
2079 struct ctl_table *new, **prevp;
2080 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04002081 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002082
2083 /* Count the path components */
2084 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2085 ;
2086
2087 /*
2088 * For each path component, allocate a 2-element ctl_table array.
2089 * The first array element will be filled with the sysctl entry
2090 * for this, the second will be the sentinel (ctl_name == 0).
2091 *
2092 * We allocate everything in one go so that we don't have to
2093 * worry about freeing additional memory in unregister_sysctl_table.
2094 */
2095 header = kzalloc(sizeof(struct ctl_table_header) +
2096 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2097 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002099
2100 new = (struct ctl_table *) (header + 1);
2101
2102 /* Now connect the dots */
2103 prevp = &header->ctl_table;
2104 for (n = 0; n < npath; ++n, ++path) {
2105 /* Copy the procname */
2106 new->procname = path->procname;
2107 new->ctl_name = path->ctl_name;
2108 new->mode = 0555;
2109
2110 *prevp = new;
2111 prevp = &new->child;
2112
2113 new += 2;
2114 }
2115 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002116 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002117
2118 INIT_LIST_HEAD(&header->ctl_entry);
2119 header->used = 0;
2120 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002121 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002122 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002123 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002124#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002125 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002126 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002127 return NULL;
2128 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002129#endif
Al Viro330d57f2005-11-04 10:18:40 +00002130 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002131 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002132 header->attached_by = header->ctl_table;
2133 header->attached_to = root_table;
2134 header->parent = &root_table_header;
2135 for (set = header->set; set; set = set->parent) {
2136 struct ctl_table_header *p;
2137 list_for_each_entry(p, &set->list, ctl_entry) {
2138 if (p->unregistering)
2139 continue;
2140 try_attach(p, header);
2141 }
2142 }
2143 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002144 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002145 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002146
2147 return header;
2148}
2149
2150/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002151 * register_sysctl_table_path - register a sysctl table hierarchy
2152 * @path: The path to the directory the sysctl table is in.
2153 * @table: the top-level table structure
2154 *
2155 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2156 * array. A completely 0 filled entry terminates the table.
2157 *
2158 * See __register_sysctl_paths for more details.
2159 */
2160struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2161 struct ctl_table *table)
2162{
2163 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2164 path, table);
2165}
2166
2167/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002168 * register_sysctl_table - register a sysctl table hierarchy
2169 * @table: the top-level table structure
2170 *
2171 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2172 * array. A completely 0 filled entry terminates the table.
2173 *
2174 * See register_sysctl_paths for more details.
2175 */
2176struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2177{
2178 static const struct ctl_path null_path[] = { {} };
2179
2180 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181}
2182
2183/**
2184 * unregister_sysctl_table - unregister a sysctl table hierarchy
2185 * @header: the header returned from register_sysctl_table
2186 *
2187 * Unregisters the sysctl table and all children. proc entries may not
2188 * actually be removed until they are no longer used by anyone.
2189 */
2190void unregister_sysctl_table(struct ctl_table_header * header)
2191{
Al Viro330d57f2005-11-04 10:18:40 +00002192 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002193
2194 if (header == NULL)
2195 return;
2196
Al Viro330d57f2005-11-04 10:18:40 +00002197 spin_lock(&sysctl_lock);
2198 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002199 if (!--header->parent->count) {
2200 WARN_ON(1);
2201 kfree(header->parent);
2202 }
Al Virof7e6ced2008-07-15 01:44:23 -04002203 if (!--header->count)
2204 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002205 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206}
2207
Al Viro9043476f2008-07-15 08:54:06 -04002208int sysctl_is_seen(struct ctl_table_header *p)
2209{
2210 struct ctl_table_set *set = p->set;
2211 int res;
2212 spin_lock(&sysctl_lock);
2213 if (p->unregistering)
2214 res = 0;
2215 else if (!set->is_seen)
2216 res = 1;
2217 else
2218 res = set->is_seen(set);
2219 spin_unlock(&sysctl_lock);
2220 return res;
2221}
2222
Al Viro73455092008-07-14 21:22:20 -04002223void setup_sysctl_set(struct ctl_table_set *p,
2224 struct ctl_table_set *parent,
2225 int (*is_seen)(struct ctl_table_set *))
2226{
2227 INIT_LIST_HEAD(&p->list);
2228 p->parent = parent ? parent : &sysctl_table_root.default_set;
2229 p->is_seen = is_seen;
2230}
2231
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002232#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002233struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002234{
2235 return NULL;
2236}
2237
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002238struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2239 struct ctl_table *table)
2240{
2241 return NULL;
2242}
2243
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002244void unregister_sysctl_table(struct ctl_table_header * table)
2245{
2246}
2247
Al Viro73455092008-07-14 21:22:20 -04002248void setup_sysctl_set(struct ctl_table_set *p,
2249 struct ctl_table_set *parent,
2250 int (*is_seen)(struct ctl_table_set *))
2251{
2252}
2253
Al Virof7e6ced2008-07-15 01:44:23 -04002254void sysctl_head_put(struct ctl_table_header *head)
2255{
2256}
2257
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002258#endif /* CONFIG_SYSCTL */
2259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260/*
2261 * /proc/sys support
2262 */
2263
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002264#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002266static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002267 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002268 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002269{
2270 size_t len;
2271 char __user *p;
2272 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002273
2274 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002275 *lenp = 0;
2276 return 0;
2277 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002278
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002279 if (write) {
2280 len = 0;
2281 p = buffer;
2282 while (len < *lenp) {
2283 if (get_user(c, p++))
2284 return -EFAULT;
2285 if (c == 0 || c == '\n')
2286 break;
2287 len++;
2288 }
2289 if (len >= maxlen)
2290 len = maxlen-1;
2291 if(copy_from_user(data, buffer, len))
2292 return -EFAULT;
2293 ((char *) data)[len] = 0;
2294 *ppos += *lenp;
2295 } else {
2296 len = strlen(data);
2297 if (len > maxlen)
2298 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002299
2300 if (*ppos > len) {
2301 *lenp = 0;
2302 return 0;
2303 }
2304
2305 data += *ppos;
2306 len -= *ppos;
2307
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002308 if (len > *lenp)
2309 len = *lenp;
2310 if (len)
2311 if(copy_to_user(buffer, data, len))
2312 return -EFAULT;
2313 if (len < *lenp) {
2314 if(put_user('\n', ((char __user *) buffer) + len))
2315 return -EFAULT;
2316 len++;
2317 }
2318 *lenp = len;
2319 *ppos += len;
2320 }
2321 return 0;
2322}
2323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324/**
2325 * proc_dostring - read a string sysctl
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 a string from/to the user buffer. If the kernel
2333 * buffer provided is not large enough to hold the string, the
2334 * string is truncated. The copied string is %NULL-terminated.
2335 * If the string is being read by the user process, it is copied
2336 * and a newline '\n' is added. It is truncated if the buffer is
2337 * not large enough.
2338 *
2339 * Returns 0 on success.
2340 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002341int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 void __user *buffer, size_t *lenp, loff_t *ppos)
2343{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002344 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002345 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346}
2347
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
2349static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2350 int *valp,
2351 int write, void *data)
2352{
2353 if (write) {
2354 *valp = *negp ? -*lvalp : *lvalp;
2355 } else {
2356 int val = *valp;
2357 if (val < 0) {
2358 *negp = -1;
2359 *lvalp = (unsigned long)-val;
2360 } else {
2361 *negp = 0;
2362 *lvalp = (unsigned long)val;
2363 }
2364 }
2365 return 0;
2366}
2367
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002368static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002369 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002370 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2372 int write, void *data),
2373 void *data)
2374{
2375#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002376 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 unsigned long lval;
2378 size_t left, len;
2379
2380 char buf[TMPBUFLEN], *p;
2381 char __user *s = buffer;
2382
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002383 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 (*ppos && !write)) {
2385 *lenp = 0;
2386 return 0;
2387 }
2388
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002389 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 vleft = table->maxlen / sizeof(*i);
2391 left = *lenp;
2392
2393 if (!conv)
2394 conv = do_proc_dointvec_conv;
2395
2396 for (; left && vleft--; i++, first=0) {
2397 if (write) {
2398 while (left) {
2399 char c;
2400 if (get_user(c, s))
2401 return -EFAULT;
2402 if (!isspace(c))
2403 break;
2404 left--;
2405 s++;
2406 }
2407 if (!left)
2408 break;
2409 neg = 0;
2410 len = left;
2411 if (len > sizeof(buf) - 1)
2412 len = sizeof(buf) - 1;
2413 if (copy_from_user(buf, s, len))
2414 return -EFAULT;
2415 buf[len] = 0;
2416 p = buf;
2417 if (*p == '-' && left > 1) {
2418 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002419 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 }
2421 if (*p < '0' || *p > '9')
2422 break;
2423
2424 lval = simple_strtoul(p, &p, 0);
2425
2426 len = p-buf;
2427 if ((len < left) && *p && !isspace(*p))
2428 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 s += len;
2430 left -= len;
2431
2432 if (conv(&neg, &lval, i, 1, data))
2433 break;
2434 } else {
2435 p = buf;
2436 if (!first)
2437 *p++ = '\t';
2438
2439 if (conv(&neg, &lval, i, 0, data))
2440 break;
2441
2442 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2443 len = strlen(buf);
2444 if (len > left)
2445 len = left;
2446 if(copy_to_user(s, buf, len))
2447 return -EFAULT;
2448 left -= len;
2449 s += len;
2450 }
2451 }
2452
2453 if (!write && !first && left) {
2454 if(put_user('\n', s))
2455 return -EFAULT;
2456 left--, s++;
2457 }
2458 if (write) {
2459 while (left) {
2460 char c;
2461 if (get_user(c, s++))
2462 return -EFAULT;
2463 if (!isspace(c))
2464 break;
2465 left--;
2466 }
2467 }
2468 if (write && first)
2469 return -EINVAL;
2470 *lenp -= left;
2471 *ppos += *lenp;
2472 return 0;
2473#undef TMPBUFLEN
2474}
2475
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002476static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002477 void __user *buffer, size_t *lenp, loff_t *ppos,
2478 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2479 int write, void *data),
2480 void *data)
2481{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002482 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002483 buffer, lenp, ppos, conv, data);
2484}
2485
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486/**
2487 * proc_dointvec - read a vector of integers
2488 * @table: the sysctl table
2489 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2493 *
2494 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2495 * values from/to the user buffer, treated as an ASCII string.
2496 *
2497 * Returns 0 on success.
2498 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002499int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 void __user *buffer, size_t *lenp, loff_t *ppos)
2501{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002502 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 NULL,NULL);
2504}
2505
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002506/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002507 * Taint values can only be increased
2508 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002509 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002510static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002511 void __user *buffer, size_t *lenp, loff_t *ppos)
2512{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002513 struct ctl_table t;
2514 unsigned long tmptaint = get_taint();
2515 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002516
Bastian Blank91fcd412007-04-23 14:41:14 -07002517 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002518 return -EPERM;
2519
Andi Kleen25ddbb12008-10-15 22:01:41 -07002520 t = *table;
2521 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002522 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002523 if (err < 0)
2524 return err;
2525
2526 if (write) {
2527 /*
2528 * Poor man's atomic or. Not worth adding a primitive
2529 * to everyone's atomic.h for this
2530 */
2531 int i;
2532 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2533 if ((tmptaint >> i) & 1)
2534 add_taint(i);
2535 }
2536 }
2537
2538 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002539}
2540
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541struct do_proc_dointvec_minmax_conv_param {
2542 int *min;
2543 int *max;
2544};
2545
2546static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2547 int *valp,
2548 int write, void *data)
2549{
2550 struct do_proc_dointvec_minmax_conv_param *param = data;
2551 if (write) {
2552 int val = *negp ? -*lvalp : *lvalp;
2553 if ((param->min && *param->min > val) ||
2554 (param->max && *param->max < val))
2555 return -EINVAL;
2556 *valp = val;
2557 } else {
2558 int val = *valp;
2559 if (val < 0) {
2560 *negp = -1;
2561 *lvalp = (unsigned long)-val;
2562 } else {
2563 *negp = 0;
2564 *lvalp = (unsigned long)val;
2565 }
2566 }
2567 return 0;
2568}
2569
2570/**
2571 * proc_dointvec_minmax - read a vector of integers with min/max values
2572 * @table: the sysctl table
2573 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 * @buffer: the user buffer
2575 * @lenp: the size of the user buffer
2576 * @ppos: file position
2577 *
2578 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2579 * values from/to the user buffer, treated as an ASCII string.
2580 *
2581 * This routine will ensure the values are within the range specified by
2582 * table->extra1 (min) and table->extra2 (max).
2583 *
2584 * Returns 0 on success.
2585 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002586int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 void __user *buffer, size_t *lenp, loff_t *ppos)
2588{
2589 struct do_proc_dointvec_minmax_conv_param param = {
2590 .min = (int *) table->extra1,
2591 .max = (int *) table->extra2,
2592 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002593 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 do_proc_dointvec_minmax_conv, &param);
2595}
2596
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002597static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 void __user *buffer,
2599 size_t *lenp, loff_t *ppos,
2600 unsigned long convmul,
2601 unsigned long convdiv)
2602{
2603#define TMPBUFLEN 21
2604 unsigned long *i, *min, *max, val;
2605 int vleft, first=1, neg;
2606 size_t len, left;
2607 char buf[TMPBUFLEN], *p;
2608 char __user *s = buffer;
2609
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002610 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 (*ppos && !write)) {
2612 *lenp = 0;
2613 return 0;
2614 }
2615
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002616 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 min = (unsigned long *) table->extra1;
2618 max = (unsigned long *) table->extra2;
2619 vleft = table->maxlen / sizeof(unsigned long);
2620 left = *lenp;
2621
2622 for (; left && vleft--; i++, min++, max++, first=0) {
2623 if (write) {
2624 while (left) {
2625 char c;
2626 if (get_user(c, s))
2627 return -EFAULT;
2628 if (!isspace(c))
2629 break;
2630 left--;
2631 s++;
2632 }
2633 if (!left)
2634 break;
2635 neg = 0;
2636 len = left;
2637 if (len > TMPBUFLEN-1)
2638 len = TMPBUFLEN-1;
2639 if (copy_from_user(buf, s, len))
2640 return -EFAULT;
2641 buf[len] = 0;
2642 p = buf;
2643 if (*p == '-' && left > 1) {
2644 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002645 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 }
2647 if (*p < '0' || *p > '9')
2648 break;
2649 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2650 len = p-buf;
2651 if ((len < left) && *p && !isspace(*p))
2652 break;
2653 if (neg)
2654 val = -val;
2655 s += len;
2656 left -= len;
2657
2658 if(neg)
2659 continue;
2660 if ((min && val < *min) || (max && val > *max))
2661 continue;
2662 *i = val;
2663 } else {
2664 p = buf;
2665 if (!first)
2666 *p++ = '\t';
2667 sprintf(p, "%lu", convdiv * (*i) / convmul);
2668 len = strlen(buf);
2669 if (len > left)
2670 len = left;
2671 if(copy_to_user(s, buf, len))
2672 return -EFAULT;
2673 left -= len;
2674 s += len;
2675 }
2676 }
2677
2678 if (!write && !first && left) {
2679 if(put_user('\n', s))
2680 return -EFAULT;
2681 left--, s++;
2682 }
2683 if (write) {
2684 while (left) {
2685 char c;
2686 if (get_user(c, s++))
2687 return -EFAULT;
2688 if (!isspace(c))
2689 break;
2690 left--;
2691 }
2692 }
2693 if (write && first)
2694 return -EINVAL;
2695 *lenp -= left;
2696 *ppos += *lenp;
2697 return 0;
2698#undef TMPBUFLEN
2699}
2700
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002701static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002702 void __user *buffer,
2703 size_t *lenp, loff_t *ppos,
2704 unsigned long convmul,
2705 unsigned long convdiv)
2706{
2707 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002708 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002709}
2710
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711/**
2712 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2713 * @table: the sysctl table
2714 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 * @buffer: the user buffer
2716 * @lenp: the size of the user buffer
2717 * @ppos: file position
2718 *
2719 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2720 * values from/to the user buffer, treated as an ASCII string.
2721 *
2722 * This routine will ensure the values are within the range specified by
2723 * table->extra1 (min) and table->extra2 (max).
2724 *
2725 * Returns 0 on success.
2726 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002727int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 void __user *buffer, size_t *lenp, loff_t *ppos)
2729{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002730 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731}
2732
2733/**
2734 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2735 * @table: the sysctl table
2736 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 * @buffer: the user buffer
2738 * @lenp: the size of the user buffer
2739 * @ppos: file position
2740 *
2741 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2742 * values from/to the user buffer, treated as an ASCII string. The values
2743 * are treated as milliseconds, and converted to jiffies when they are stored.
2744 *
2745 * This routine will ensure the values are within the range specified by
2746 * table->extra1 (min) and table->extra2 (max).
2747 *
2748 * Returns 0 on success.
2749 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002750int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 void __user *buffer,
2752 size_t *lenp, loff_t *ppos)
2753{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002754 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 lenp, ppos, HZ, 1000l);
2756}
2757
2758
2759static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2760 int *valp,
2761 int write, void *data)
2762{
2763 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002764 if (*lvalp > LONG_MAX / HZ)
2765 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2767 } else {
2768 int val = *valp;
2769 unsigned long lval;
2770 if (val < 0) {
2771 *negp = -1;
2772 lval = (unsigned long)-val;
2773 } else {
2774 *negp = 0;
2775 lval = (unsigned long)val;
2776 }
2777 *lvalp = lval / HZ;
2778 }
2779 return 0;
2780}
2781
2782static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2783 int *valp,
2784 int write, void *data)
2785{
2786 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002787 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2788 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2790 } else {
2791 int val = *valp;
2792 unsigned long lval;
2793 if (val < 0) {
2794 *negp = -1;
2795 lval = (unsigned long)-val;
2796 } else {
2797 *negp = 0;
2798 lval = (unsigned long)val;
2799 }
2800 *lvalp = jiffies_to_clock_t(lval);
2801 }
2802 return 0;
2803}
2804
2805static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2806 int *valp,
2807 int write, void *data)
2808{
2809 if (write) {
2810 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2811 } else {
2812 int val = *valp;
2813 unsigned long lval;
2814 if (val < 0) {
2815 *negp = -1;
2816 lval = (unsigned long)-val;
2817 } else {
2818 *negp = 0;
2819 lval = (unsigned long)val;
2820 }
2821 *lvalp = jiffies_to_msecs(lval);
2822 }
2823 return 0;
2824}
2825
2826/**
2827 * proc_dointvec_jiffies - read a vector of integers as seconds
2828 * @table: the sysctl table
2829 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 * @buffer: the user buffer
2831 * @lenp: the size of the user buffer
2832 * @ppos: file position
2833 *
2834 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2835 * values from/to the user buffer, treated as an ASCII string.
2836 * The values read are assumed to be in seconds, and are converted into
2837 * jiffies.
2838 *
2839 * Returns 0 on success.
2840 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002841int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 void __user *buffer, size_t *lenp, loff_t *ppos)
2843{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002844 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 do_proc_dointvec_jiffies_conv,NULL);
2846}
2847
2848/**
2849 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2850 * @table: the sysctl table
2851 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 * @buffer: the user buffer
2853 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002854 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 *
2856 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2857 * values from/to the user buffer, treated as an ASCII string.
2858 * The values read are assumed to be in 1/USER_HZ seconds, and
2859 * are converted into jiffies.
2860 *
2861 * Returns 0 on success.
2862 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002863int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 void __user *buffer, size_t *lenp, loff_t *ppos)
2865{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002866 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 do_proc_dointvec_userhz_jiffies_conv,NULL);
2868}
2869
2870/**
2871 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2872 * @table: the sysctl table
2873 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 * @buffer: the user buffer
2875 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002876 * @ppos: file position
2877 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 *
2879 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2880 * values from/to the user buffer, treated as an ASCII string.
2881 * The values read are assumed to be in 1/1000 seconds, and
2882 * are converted into jiffies.
2883 *
2884 * Returns 0 on success.
2885 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002886int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 void __user *buffer, size_t *lenp, loff_t *ppos)
2888{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002889 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 do_proc_dointvec_ms_jiffies_conv, NULL);
2891}
2892
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002893static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002894 void __user *buffer, size_t *lenp, loff_t *ppos)
2895{
2896 struct pid *new_pid;
2897 pid_t tmp;
2898 int r;
2899
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002900 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002901
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002902 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002903 lenp, ppos, NULL, NULL);
2904 if (r || !write)
2905 return r;
2906
2907 new_pid = find_get_pid(tmp);
2908 if (!new_pid)
2909 return -ESRCH;
2910
2911 put_pid(xchg(&cad_pid, new_pid));
2912 return 0;
2913}
2914
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915#else /* CONFIG_PROC_FS */
2916
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002917int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 void __user *buffer, size_t *lenp, loff_t *ppos)
2919{
2920 return -ENOSYS;
2921}
2922
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002923int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 void __user *buffer, size_t *lenp, loff_t *ppos)
2925{
2926 return -ENOSYS;
2927}
2928
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002929int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 void __user *buffer, size_t *lenp, loff_t *ppos)
2931{
2932 return -ENOSYS;
2933}
2934
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002935int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 void __user *buffer, size_t *lenp, loff_t *ppos)
2937{
2938 return -ENOSYS;
2939}
2940
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002941int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 void __user *buffer, size_t *lenp, loff_t *ppos)
2943{
2944 return -ENOSYS;
2945}
2946
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002947int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 void __user *buffer, size_t *lenp, loff_t *ppos)
2949{
2950 return -ENOSYS;
2951}
2952
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002953int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 void __user *buffer, size_t *lenp, loff_t *ppos)
2955{
2956 return -ENOSYS;
2957}
2958
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002959int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 void __user *buffer,
2961 size_t *lenp, loff_t *ppos)
2962{
2963 return -ENOSYS;
2964}
2965
2966
2967#endif /* CONFIG_PROC_FS */
2968
2969
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002970#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971/*
2972 * General sysctl support routines
2973 */
2974
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002975/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002976int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002977 void __user *oldval, size_t __user *oldlenp,
2978 void __user *newval, size_t newlen)
2979{
2980 size_t len;
2981
2982 /* Get out of I don't have a variable */
2983 if (!table->data || !table->maxlen)
2984 return -ENOTDIR;
2985
2986 if (oldval && oldlenp) {
2987 if (get_user(len, oldlenp))
2988 return -EFAULT;
2989 if (len) {
2990 if (len > table->maxlen)
2991 len = table->maxlen;
2992 if (copy_to_user(oldval, table->data, len))
2993 return -EFAULT;
2994 if (put_user(len, oldlenp))
2995 return -EFAULT;
2996 }
2997 }
2998
2999 if (newval && newlen) {
3000 if (newlen > table->maxlen)
3001 newlen = table->maxlen;
3002
3003 if (copy_from_user(table->data, newval, newlen))
3004 return -EFAULT;
3005 }
3006 return 1;
3007}
3008
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003010int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003012 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 if (!table->data || !table->maxlen)
3015 return -ENOTDIR;
3016
3017 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003018 size_t bufsize;
3019 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003021 if (bufsize) {
3022 size_t len = strlen(table->data), copied;
3023
3024 /* This shouldn't trigger for a well-formed sysctl */
3025 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003027
3028 /* Copy up to a max of bufsize-1 bytes of the string */
3029 copied = (len >= bufsize) ? bufsize - 1 : len;
3030
3031 if (copy_to_user(oldval, table->data, copied) ||
3032 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003034 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 return -EFAULT;
3036 }
3037 }
3038 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003039 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 if (len > table->maxlen)
3041 len = table->maxlen;
3042 if(copy_from_user(table->data, newval, len))
3043 return -EFAULT;
3044 if (len == table->maxlen)
3045 len--;
3046 ((char *) table->data)[len] = 0;
3047 }
Yi Yang82c9df82005-12-30 16:37:10 +08003048 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049}
3050
3051/*
3052 * This function makes sure that all of the integers in the vector
3053 * are between the minimum and maximum values given in the arrays
3054 * table->extra1 and table->extra2, respectively.
3055 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003056int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003058 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059{
3060
3061 if (newval && newlen) {
3062 int __user *vec = (int __user *) newval;
3063 int *min = (int *) table->extra1;
3064 int *max = (int *) table->extra2;
3065 size_t length;
3066 int i;
3067
3068 if (newlen % sizeof(int) != 0)
3069 return -EINVAL;
3070
3071 if (!table->extra1 && !table->extra2)
3072 return 0;
3073
3074 if (newlen > table->maxlen)
3075 newlen = table->maxlen;
3076 length = newlen / sizeof(int);
3077
3078 for (i = 0; i < length; i++) {
3079 int value;
3080 if (get_user(value, vec + i))
3081 return -EFAULT;
3082 if (min && value < min[i])
3083 return -EINVAL;
3084 if (max && value > max[i])
3085 return -EINVAL;
3086 }
3087 }
3088 return 0;
3089}
3090
3091/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003092int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003094 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003096 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003098
3099 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003101 if (olen) {
3102 int val;
3103
3104 if (olen < sizeof(int))
3105 return -EINVAL;
3106
3107 val = *(int *)(table->data) / HZ;
3108 if (put_user(val, (int __user *)oldval))
3109 return -EFAULT;
3110 if (put_user(sizeof(int), oldlenp))
3111 return -EFAULT;
3112 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 }
3114 if (newval && newlen) {
3115 int new;
3116 if (newlen != sizeof(int))
3117 return -EINVAL;
3118 if (get_user(new, (int __user *)newval))
3119 return -EFAULT;
3120 *(int *)(table->data) = new*HZ;
3121 }
3122 return 1;
3123}
3124
3125/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003126int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003128 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003130 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003132
3133 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003135 if (olen) {
3136 int val;
3137
3138 if (olen < sizeof(int))
3139 return -EINVAL;
3140
3141 val = jiffies_to_msecs(*(int *)(table->data));
3142 if (put_user(val, (int __user *)oldval))
3143 return -EFAULT;
3144 if (put_user(sizeof(int), oldlenp))
3145 return -EFAULT;
3146 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 }
3148 if (newval && newlen) {
3149 int new;
3150 if (newlen != sizeof(int))
3151 return -EINVAL;
3152 if (get_user(new, (int __user *)newval))
3153 return -EFAULT;
3154 *(int *)(table->data) = msecs_to_jiffies(new);
3155 }
3156 return 1;
3157}
3158
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003159
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003160
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003161#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162
3163
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003164SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003166 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003167 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003168
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003169 if (copy_from_user(&tmp, args, sizeof(tmp)))
3170 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003171
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003172 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003173
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003174 /* If no error reading the parameters then just -ENOSYS ... */
3175 if (!error)
3176 error = -ENOSYS;
3177
3178 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179}
3180
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003181int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003182 void __user *oldval, size_t __user *oldlenp,
3183 void __user *newval, size_t newlen)
3184{
3185 return -ENOSYS;
3186}
3187
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003188int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003190 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191{
3192 return -ENOSYS;
3193}
3194
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003195int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003197 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198{
3199 return -ENOSYS;
3200}
3201
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003202int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003204 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205{
3206 return -ENOSYS;
3207}
3208
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003209int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003211 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212{
3213 return -ENOSYS;
3214}
3215
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003216#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003218static int deprecated_sysctl_warning(struct __sysctl_args *args)
3219{
3220 static int msg_count;
3221 int name[CTL_MAXNAME];
3222 int i;
3223
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003224 /* Check args->nlen. */
3225 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3226 return -ENOTDIR;
3227
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003228 /* Read in the sysctl name for better debug message logging */
3229 for (i = 0; i < args->nlen; i++)
3230 if (get_user(name[i], args->name + i))
3231 return -EFAULT;
3232
3233 /* Ignore accesses to kernel.version */
3234 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3235 return 0;
3236
3237 if (msg_count < 5) {
3238 msg_count++;
3239 printk(KERN_INFO
3240 "warning: process `%s' used the deprecated sysctl "
3241 "system call with ", current->comm);
3242 for (i = 0; i < args->nlen; i++)
3243 printk("%d.", name[i]);
3244 printk("\n");
3245 }
3246 return 0;
3247}
3248
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249/*
3250 * No sense putting this after each symbol definition, twice,
3251 * exception granted :-)
3252 */
3253EXPORT_SYMBOL(proc_dointvec);
3254EXPORT_SYMBOL(proc_dointvec_jiffies);
3255EXPORT_SYMBOL(proc_dointvec_minmax);
3256EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3257EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3258EXPORT_SYMBOL(proc_dostring);
3259EXPORT_SYMBOL(proc_doulongvec_minmax);
3260EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3261EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003262EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263EXPORT_SYMBOL(sysctl_intvec);
3264EXPORT_SYMBOL(sysctl_jiffies);
3265EXPORT_SYMBOL(sysctl_ms_jiffies);
3266EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003267EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268EXPORT_SYMBOL(unregister_sysctl_table);