blob: e5cc53514caac527e0992b7237f759caa64cd2f1 [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 Gondwana195cf452008-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 Molnar23f78d42006-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 */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200254#endif
255
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700256static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200257 {
258 .ctl_name = CTL_UNNUMBERED,
259 .procname = "sched_child_runs_first",
260 .data = &sysctl_sched_child_runs_first,
261 .maxlen = sizeof(unsigned int),
262 .mode = 0644,
263 .proc_handler = &proc_dointvec,
264 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200265#ifdef CONFIG_SCHED_DEBUG
266 {
267 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100268 .procname = "sched_min_granularity_ns",
269 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100272 .proc_handler = &sched_nr_latency_handler,
273 .strategy = &sysctl_intvec,
274 .extra1 = &min_sched_granularity_ns,
275 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200276 },
277 {
278 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200279 .procname = "sched_latency_ns",
280 .data = &sysctl_sched_latency,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100283 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200284 .strategy = &sysctl_intvec,
285 .extra1 = &min_sched_granularity_ns,
286 .extra2 = &max_sched_granularity_ns,
287 },
288 {
289 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200290 .procname = "sched_wakeup_granularity_ns",
291 .data = &sysctl_sched_wakeup_granularity,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
296 .extra1 = &min_wakeup_granularity_ns,
297 .extra2 = &max_wakeup_granularity_ns,
298 },
299 {
300 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200301 .procname = "sched_shares_ratelimit",
302 .data = &sysctl_sched_shares_ratelimit,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = &proc_dointvec,
306 },
307 {
308 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200309 .procname = "sched_shares_thresh",
310 .data = &sysctl_sched_shares_thresh,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = &proc_dointvec_minmax,
314 .strategy = &sysctl_intvec,
315 .extra1 = &zero,
316 },
317 {
318 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarda84d962007-10-15 17:00:18 +0200319 .procname = "sched_migration_cost",
320 .data = &sysctl_sched_migration_cost,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
323 .proc_handler = &proc_dointvec,
324 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100325 {
326 .ctl_name = CTL_UNNUMBERED,
327 .procname = "sched_nr_migrate",
328 .data = &sysctl_sched_nr_migrate,
329 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100330 .mode = 0644,
331 .proc_handler = &proc_dointvec,
332 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530333 {
334 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200335 .procname = "sched_time_avg",
336 .data = &sysctl_sched_time_avg,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341 {
342 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530343 .procname = "timer_migration",
344 .data = &sysctl_timer_migration,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530347 .proc_handler = &proc_dointvec_minmax,
348 .strategy = &sysctl_intvec,
349 .extra1 = &zero,
350 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530351 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200352#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200353 {
354 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100355 .procname = "sched_rt_period_us",
356 .data = &sysctl_sched_rt_period,
357 .maxlen = sizeof(unsigned int),
358 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200359 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100360 },
361 {
362 .ctl_name = CTL_UNNUMBERED,
363 .procname = "sched_rt_runtime_us",
364 .data = &sysctl_sched_rt_runtime,
365 .maxlen = sizeof(int),
366 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200367 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100368 },
369 {
370 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200371 .procname = "sched_compat_yield",
372 .data = &sysctl_sched_compat_yield,
373 .maxlen = sizeof(unsigned int),
374 .mode = 0644,
375 .proc_handler = &proc_dointvec,
376 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700377#ifdef CONFIG_PROVE_LOCKING
378 {
379 .ctl_name = CTL_UNNUMBERED,
380 .procname = "prove_locking",
381 .data = &prove_locking,
382 .maxlen = sizeof(int),
383 .mode = 0644,
384 .proc_handler = &proc_dointvec,
385 },
386#endif
387#ifdef CONFIG_LOCK_STAT
388 {
389 .ctl_name = CTL_UNNUMBERED,
390 .procname = "lock_stat",
391 .data = &lock_stat,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = &proc_dointvec,
395 },
396#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .ctl_name = KERN_PANIC,
399 .procname = "panic",
400 .data = &panic_timeout,
401 .maxlen = sizeof(int),
402 .mode = 0644,
403 .proc_handler = &proc_dointvec,
404 },
405 {
406 .ctl_name = KERN_CORE_USES_PID,
407 .procname = "core_uses_pid",
408 .data = &core_uses_pid,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
412 },
413 {
414 .ctl_name = KERN_CORE_PATTERN,
415 .procname = "core_pattern",
416 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700417 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .mode = 0644,
419 .proc_handler = &proc_dostring,
420 .strategy = &sysctl_string,
421 },
Neil Hormana2939802009-09-23 15:56:56 -0700422 {
423 .ctl_name = CTL_UNNUMBERED,
424 .procname = "core_pipe_limit",
425 .data = &core_pipe_limit,
426 .maxlen = sizeof(unsigned int),
427 .mode = 0644,
428 .proc_handler = &proc_dointvec,
429 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800430#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700433 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800434 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700435 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800437#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100438#ifdef CONFIG_LATENCYTOP
439 {
440 .procname = "latencytop",
441 .data = &latencytop_enabled,
442 .maxlen = sizeof(int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
445 },
446#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#ifdef CONFIG_BLK_DEV_INITRD
448 {
449 .ctl_name = KERN_REALROOTDEV,
450 .procname = "real-root-dev",
451 .data = &real_root_dev,
452 .maxlen = sizeof(int),
453 .mode = 0644,
454 .proc_handler = &proc_dointvec,
455 },
456#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700457 {
458 .ctl_name = CTL_UNNUMBERED,
459 .procname = "print-fatal-signals",
460 .data = &print_fatal_signals,
461 .maxlen = sizeof(int),
462 .mode = 0644,
463 .proc_handler = &proc_dointvec,
464 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700465#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 {
467 .ctl_name = KERN_SPARC_REBOOT,
468 .procname = "reboot-cmd",
469 .data = reboot_command,
470 .maxlen = 256,
471 .mode = 0644,
472 .proc_handler = &proc_dostring,
473 .strategy = &sysctl_string,
474 },
475 {
476 .ctl_name = KERN_SPARC_STOP_A,
477 .procname = "stop-a",
478 .data = &stop_a_enabled,
479 .maxlen = sizeof (int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
482 },
483 {
484 .ctl_name = KERN_SPARC_SCONS_PWROFF,
485 .procname = "scons-poweroff",
486 .data = &scons_pwroff,
487 .maxlen = sizeof (int),
488 .mode = 0644,
489 .proc_handler = &proc_dointvec,
490 },
491#endif
David S. Miller08714202008-11-16 23:49:24 -0800492#ifdef CONFIG_SPARC64
493 {
494 .ctl_name = CTL_UNNUMBERED,
495 .procname = "tsb-ratio",
496 .data = &sysctl_tsb_ratio,
497 .maxlen = sizeof (int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
500 },
501#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502#ifdef __hppa__
503 {
504 .ctl_name = KERN_HPPA_PWRSW,
505 .procname = "soft-power",
506 .data = &pwrsw_enabled,
507 .maxlen = sizeof (int),
508 .mode = 0644,
509 .proc_handler = &proc_dointvec,
510 },
511 {
512 .ctl_name = KERN_HPPA_UNALIGNED,
513 .procname = "unaligned-trap",
514 .data = &unaligned_enabled,
515 .maxlen = sizeof (int),
516 .mode = 0644,
517 .proc_handler = &proc_dointvec,
518 },
519#endif
520 {
521 .ctl_name = KERN_CTLALTDEL,
522 .procname = "ctrl-alt-del",
523 .data = &C_A_D,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = &proc_dointvec,
527 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400528#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200529 {
530 .ctl_name = CTL_UNNUMBERED,
531 .procname = "ftrace_enabled",
532 .data = &ftrace_enabled,
533 .maxlen = sizeof(int),
534 .mode = 0644,
535 .proc_handler = &ftrace_enable_sysctl,
536 },
537#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500538#ifdef CONFIG_STACK_TRACER
539 {
540 .ctl_name = CTL_UNNUMBERED,
541 .procname = "stack_tracer_enabled",
542 .data = &stack_tracer_enabled,
543 .maxlen = sizeof(int),
544 .mode = 0644,
545 .proc_handler = &stack_trace_sysctl,
546 },
547#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400548#ifdef CONFIG_TRACING
549 {
550 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100551 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400552 .data = &ftrace_dump_on_oops,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 .proc_handler = &proc_dointvec,
556 },
557#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200558#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 {
560 .ctl_name = KERN_MODPROBE,
561 .procname = "modprobe",
562 .data = &modprobe_path,
563 .maxlen = KMOD_PATH_LEN,
564 .mode = 0644,
565 .proc_handler = &proc_dostring,
566 .strategy = &sysctl_string,
567 },
Kees Cook3d433212009-04-02 15:49:29 -0700568 {
569 .ctl_name = CTL_UNNUMBERED,
570 .procname = "modules_disabled",
571 .data = &modules_disabled,
572 .maxlen = sizeof(int),
573 .mode = 0644,
574 /* only handle a transition from default "0" to "1" */
575 .proc_handler = &proc_dointvec_minmax,
576 .extra1 = &one,
577 .extra2 = &one,
578 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700580#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 {
582 .ctl_name = KERN_HOTPLUG,
583 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100584 .data = &uevent_helper,
585 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 .mode = 0644,
587 .proc_handler = &proc_dostring,
588 .strategy = &sysctl_string,
589 },
590#endif
591#ifdef CONFIG_CHR_DEV_SG
592 {
593 .ctl_name = KERN_SG_BIG_BUFF,
594 .procname = "sg-big-buff",
595 .data = &sg_big_buff,
596 .maxlen = sizeof (int),
597 .mode = 0444,
598 .proc_handler = &proc_dointvec,
599 },
600#endif
601#ifdef CONFIG_BSD_PROCESS_ACCT
602 {
603 .ctl_name = KERN_ACCT,
604 .procname = "acct",
605 .data = &acct_parm,
606 .maxlen = 3*sizeof(int),
607 .mode = 0644,
608 .proc_handler = &proc_dointvec,
609 },
610#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611#ifdef CONFIG_MAGIC_SYSRQ
612 {
613 .ctl_name = KERN_SYSRQ,
614 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800615 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 .maxlen = sizeof (int),
617 .mode = 0644,
618 .proc_handler = &proc_dointvec,
619 },
620#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700621#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700624 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 .maxlen = sizeof (int),
626 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700627 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700629#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 {
631 .ctl_name = KERN_MAX_THREADS,
632 .procname = "threads-max",
633 .data = &max_threads,
634 .maxlen = sizeof(int),
635 .mode = 0644,
636 .proc_handler = &proc_dointvec,
637 },
638 {
639 .ctl_name = KERN_RANDOM,
640 .procname = "random",
641 .mode = 0555,
642 .child = random_table,
643 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 {
645 .ctl_name = KERN_OVERFLOWUID,
646 .procname = "overflowuid",
647 .data = &overflowuid,
648 .maxlen = sizeof(int),
649 .mode = 0644,
650 .proc_handler = &proc_dointvec_minmax,
651 .strategy = &sysctl_intvec,
652 .extra1 = &minolduid,
653 .extra2 = &maxolduid,
654 },
655 {
656 .ctl_name = KERN_OVERFLOWGID,
657 .procname = "overflowgid",
658 .data = &overflowgid,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = &proc_dointvec_minmax,
662 .strategy = &sysctl_intvec,
663 .extra1 = &minolduid,
664 .extra2 = &maxolduid,
665 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800666#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#ifdef CONFIG_MATHEMU
668 {
669 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
670 .procname = "ieee_emulation_warnings",
671 .data = &sysctl_ieee_emulation_warnings,
672 .maxlen = sizeof(int),
673 .mode = 0644,
674 .proc_handler = &proc_dointvec,
675 },
676#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 {
678 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
679 .procname = "userprocess_debug",
680 .data = &sysctl_userprocess_debug,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 .proc_handler = &proc_dointvec,
684 },
685#endif
686 {
687 .ctl_name = KERN_PIDMAX,
688 .procname = "pid_max",
689 .data = &pid_max,
690 .maxlen = sizeof (int),
691 .mode = 0644,
692 .proc_handler = &proc_dointvec_minmax,
693 .strategy = sysctl_intvec,
694 .extra1 = &pid_max_min,
695 .extra2 = &pid_max_max,
696 },
697 {
698 .ctl_name = KERN_PANIC_ON_OOPS,
699 .procname = "panic_on_oops",
700 .data = &panic_on_oops,
701 .maxlen = sizeof(int),
702 .mode = 0644,
703 .proc_handler = &proc_dointvec,
704 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800705#if defined CONFIG_PRINTK
706 {
707 .ctl_name = KERN_PRINTK,
708 .procname = "printk",
709 .data = &console_loglevel,
710 .maxlen = 4*sizeof(int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 {
715 .ctl_name = KERN_PRINTK_RATELIMIT,
716 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700717 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec_jiffies,
721 .strategy = &sysctl_jiffies,
722 },
723 {
724 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
725 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700726 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = &proc_dointvec,
730 },
Dave Youngaf913222009-09-22 16:43:33 -0700731 {
732 .ctl_name = CTL_UNNUMBERED,
733 .procname = "printk_delay",
734 .data = &printk_delay_msec,
735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec_minmax,
738 .strategy = &sysctl_intvec,
739 .extra1 = &zero,
740 .extra2 = &ten_thousand,
741 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800742#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 {
744 .ctl_name = KERN_NGROUPS_MAX,
745 .procname = "ngroups_max",
746 .data = &ngroups_max,
747 .maxlen = sizeof (int),
748 .mode = 0444,
749 .proc_handler = &proc_dointvec,
750 },
751#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
752 {
753 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
754 .procname = "unknown_nmi_panic",
755 .data = &unknown_nmi_panic,
756 .maxlen = sizeof (int),
757 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200758 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 },
Don Zickus407984f2006-09-26 10:52:27 +0200760 {
Don Zickus407984f2006-09-26 10:52:27 +0200761 .procname = "nmi_watchdog",
762 .data = &nmi_watchdog_enabled,
763 .maxlen = sizeof (int),
764 .mode = 0644,
765 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 },
767#endif
768#if defined(CONFIG_X86)
769 {
Don Zickus8da5add2006-09-26 10:52:27 +0200770 .ctl_name = KERN_PANIC_ON_NMI,
771 .procname = "panic_on_unrecovered_nmi",
772 .data = &panic_on_unrecovered_nmi,
773 .maxlen = sizeof(int),
774 .mode = 0644,
775 .proc_handler = &proc_dointvec,
776 },
777 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700778 .ctl_name = CTL_UNNUMBERED,
779 .procname = "panic_on_io_nmi",
780 .data = &panic_on_io_nmi,
781 .maxlen = sizeof(int),
782 .mode = 0644,
783 .proc_handler = &proc_dointvec,
784 },
785 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 .ctl_name = KERN_BOOTLOADER_TYPE,
787 .procname = "bootloader_type",
788 .data = &bootloader_type,
789 .maxlen = sizeof (int),
790 .mode = 0444,
791 .proc_handler = &proc_dointvec,
792 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100793 {
794 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700795 .procname = "bootloader_version",
796 .data = &bootloader_version,
797 .maxlen = sizeof (int),
798 .mode = 0444,
799 .proc_handler = &proc_dointvec,
800 },
801 {
802 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100803 .procname = "kstack_depth_to_print",
804 .data = &kstack_depth_to_print,
805 .maxlen = sizeof(int),
806 .mode = 0644,
807 .proc_handler = &proc_dointvec,
808 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100809 {
810 .ctl_name = CTL_UNNUMBERED,
811 .procname = "io_delay_type",
812 .data = &io_delay_type,
813 .maxlen = sizeof(int),
814 .mode = 0644,
815 .proc_handler = &proc_dointvec,
816 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800818#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 {
820 .ctl_name = KERN_RANDOMIZE,
821 .procname = "randomize_va_space",
822 .data = &randomize_va_space,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec,
826 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800827#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800828#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700829 {
830 .ctl_name = KERN_SPIN_RETRY,
831 .procname = "spin_retry",
832 .data = &spin_retry,
833 .maxlen = sizeof (int),
834 .mode = 0644,
835 .proc_handler = &proc_dointvec,
836 },
837#endif
Len Brown673d5b42007-07-28 03:33:16 -0400838#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800839 {
Pavel Machekc255d842006-02-20 18:27:58 -0800840 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700841 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800842 .maxlen = sizeof (unsigned long),
843 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800844 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800845 },
846#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800847#ifdef CONFIG_IA64
848 {
849 .ctl_name = KERN_IA64_UNALIGNED,
850 .procname = "ignore-unaligned-usertrap",
851 .data = &no_unaligned_warning,
852 .maxlen = sizeof (int),
853 .mode = 0644,
854 .proc_handler = &proc_dointvec,
855 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800856 {
857 .ctl_name = CTL_UNNUMBERED,
858 .procname = "unaligned-dump-stack",
859 .data = &unaligned_dump_stack,
860 .maxlen = sizeof (int),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec,
863 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800864#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700865#ifdef CONFIG_DETECT_SOFTLOCKUP
866 {
867 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200868 .procname = "softlockup_panic",
869 .data = &softlockup_panic,
870 .maxlen = sizeof(int),
871 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700872 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200873 .strategy = &sysctl_intvec,
874 .extra1 = &zero,
875 .extra2 = &one,
876 },
877 {
878 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700879 .procname = "softlockup_thresh",
880 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200881 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700882 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800883 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700884 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200885 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700886 .extra2 = &sixty,
887 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800888#endif
889#ifdef CONFIG_DETECT_HUNG_TASK
890 {
891 .ctl_name = CTL_UNNUMBERED,
892 .procname = "hung_task_panic",
893 .data = &sysctl_hung_task_panic,
894 .maxlen = sizeof(int),
895 .mode = 0644,
896 .proc_handler = &proc_dointvec_minmax,
897 .strategy = &sysctl_intvec,
898 .extra1 = &zero,
899 .extra2 = &one,
900 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100901 {
902 .ctl_name = CTL_UNNUMBERED,
903 .procname = "hung_task_check_count",
904 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100905 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100906 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100907 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100908 .strategy = &sysctl_intvec,
909 },
910 {
911 .ctl_name = CTL_UNNUMBERED,
912 .procname = "hung_task_timeout_secs",
913 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100914 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100915 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800916 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100917 .strategy = &sysctl_intvec,
918 },
919 {
920 .ctl_name = CTL_UNNUMBERED,
921 .procname = "hung_task_warnings",
922 .data = &sysctl_hung_task_warnings,
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 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700928#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200929#ifdef CONFIG_COMPAT
930 {
931 .ctl_name = KERN_COMPAT_LOG,
932 .procname = "compat-log",
933 .data = &compat_log,
934 .maxlen = sizeof (int),
935 .mode = 0644,
936 .proc_handler = &proc_dointvec,
937 },
938#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700939#ifdef CONFIG_RT_MUTEXES
940 {
941 .ctl_name = KERN_MAX_LOCK_DEPTH,
942 .procname = "max_lock_depth",
943 .data = &max_lock_depth,
944 .maxlen = sizeof(int),
945 .mode = 0644,
946 .proc_handler = &proc_dointvec,
947 },
948#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700949 {
950 .ctl_name = CTL_UNNUMBERED,
951 .procname = "poweroff_cmd",
952 .data = &poweroff_cmd,
953 .maxlen = POWEROFF_CMD_PATH_LEN,
954 .mode = 0644,
955 .proc_handler = &proc_dostring,
956 .strategy = &sysctl_string,
957 },
David Howells0b77f5b2008-04-29 01:01:32 -0700958#ifdef CONFIG_KEYS
959 {
960 .ctl_name = CTL_UNNUMBERED,
961 .procname = "keys",
962 .mode = 0555,
963 .child = key_sysctls,
964 },
965#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700966#ifdef CONFIG_RCU_TORTURE_TEST
967 {
968 .ctl_name = CTL_UNNUMBERED,
969 .procname = "rcutorture_runnable",
970 .data = &rcutorture_runnable,
971 .maxlen = sizeof(int),
972 .mode = 0644,
973 .proc_handler = &proc_dointvec,
974 },
975#endif
David Howells12e22c52009-04-03 16:42:35 +0100976#ifdef CONFIG_SLOW_WORK
977 {
978 .ctl_name = CTL_UNNUMBERED,
979 .procname = "slow-work",
980 .mode = 0555,
981 .child = slow_work_sysctls,
982 },
983#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200984#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200985 {
986 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200987 .procname = "perf_event_paranoid",
988 .data = &sysctl_perf_event_paranoid,
989 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200990 .mode = 0644,
991 .proc_handler = &proc_dointvec,
992 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200993 {
994 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200995 .procname = "perf_event_mlock_kb",
996 .data = &sysctl_perf_event_mlock,
997 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200998 .mode = 0644,
999 .proc_handler = &proc_dointvec,
1000 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001001 {
1002 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001003 .procname = "perf_event_max_sample_rate",
1004 .data = &sysctl_perf_event_sample_rate,
1005 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001006 .mode = 0644,
1007 .proc_handler = &proc_dointvec,
1008 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001009#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001010#ifdef CONFIG_KMEMCHECK
1011 {
1012 .ctl_name = CTL_UNNUMBERED,
1013 .procname = "kmemcheck",
1014 .data = &kmemcheck_enabled,
1015 .maxlen = sizeof(int),
1016 .mode = 0644,
1017 .proc_handler = &proc_dointvec,
1018 },
1019#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001020#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001021 {
1022 .ctl_name = CTL_UNNUMBERED,
1023 .procname = "blk_iopoll",
1024 .data = &blk_iopoll_enabled,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
1027 .proc_handler = &proc_dointvec,
1028 },
Jens Axboecb684b52009-09-15 21:53:11 +02001029#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001030/*
1031 * NOTE: do not add new entries to this table unless you have read
1032 * Documentation/sysctl/ctl_unnumbered.txt
1033 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 { .ctl_name = 0 }
1035};
1036
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001037static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 {
1039 .ctl_name = VM_OVERCOMMIT_MEMORY,
1040 .procname = "overcommit_memory",
1041 .data = &sysctl_overcommit_memory,
1042 .maxlen = sizeof(sysctl_overcommit_memory),
1043 .mode = 0644,
1044 .proc_handler = &proc_dointvec,
1045 },
1046 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001047 .ctl_name = VM_PANIC_ON_OOM,
1048 .procname = "panic_on_oom",
1049 .data = &sysctl_panic_on_oom,
1050 .maxlen = sizeof(sysctl_panic_on_oom),
1051 .mode = 0644,
1052 .proc_handler = &proc_dointvec,
1053 },
1054 {
David Rientjesfe071d72007-10-16 23:25:56 -07001055 .ctl_name = CTL_UNNUMBERED,
1056 .procname = "oom_kill_allocating_task",
1057 .data = &sysctl_oom_kill_allocating_task,
1058 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1059 .mode = 0644,
1060 .proc_handler = &proc_dointvec,
1061 },
1062 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001063 .ctl_name = CTL_UNNUMBERED,
1064 .procname = "oom_dump_tasks",
1065 .data = &sysctl_oom_dump_tasks,
1066 .maxlen = sizeof(sysctl_oom_dump_tasks),
1067 .mode = 0644,
1068 .proc_handler = &proc_dointvec,
1069 },
1070 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .ctl_name = VM_OVERCOMMIT_RATIO,
1072 .procname = "overcommit_ratio",
1073 .data = &sysctl_overcommit_ratio,
1074 .maxlen = sizeof(sysctl_overcommit_ratio),
1075 .mode = 0644,
1076 .proc_handler = &proc_dointvec,
1077 },
1078 {
1079 .ctl_name = VM_PAGE_CLUSTER,
1080 .procname = "page-cluster",
1081 .data = &page_cluster,
1082 .maxlen = sizeof(int),
1083 .mode = 0644,
1084 .proc_handler = &proc_dointvec,
1085 },
1086 {
1087 .ctl_name = VM_DIRTY_BACKGROUND,
1088 .procname = "dirty_background_ratio",
1089 .data = &dirty_background_ratio,
1090 .maxlen = sizeof(dirty_background_ratio),
1091 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001092 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 .strategy = &sysctl_intvec,
1094 .extra1 = &zero,
1095 .extra2 = &one_hundred,
1096 },
1097 {
David Rientjes2da02992009-01-06 14:39:31 -08001098 .ctl_name = CTL_UNNUMBERED,
1099 .procname = "dirty_background_bytes",
1100 .data = &dirty_background_bytes,
1101 .maxlen = sizeof(dirty_background_bytes),
1102 .mode = 0644,
1103 .proc_handler = &dirty_background_bytes_handler,
1104 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001105 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001106 },
1107 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 .ctl_name = VM_DIRTY_RATIO,
1109 .procname = "dirty_ratio",
1110 .data = &vm_dirty_ratio,
1111 .maxlen = sizeof(vm_dirty_ratio),
1112 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001113 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 .strategy = &sysctl_intvec,
1115 .extra1 = &zero,
1116 .extra2 = &one_hundred,
1117 },
1118 {
David Rientjes2da02992009-01-06 14:39:31 -08001119 .ctl_name = CTL_UNNUMBERED,
1120 .procname = "dirty_bytes",
1121 .data = &vm_dirty_bytes,
1122 .maxlen = sizeof(vm_dirty_bytes),
1123 .mode = 0644,
1124 .proc_handler = &dirty_bytes_handler,
1125 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001126 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001127 },
1128 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001130 .data = &dirty_writeback_interval,
1131 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 .mode = 0644,
1133 .proc_handler = &dirty_writeback_centisecs_handler,
1134 },
1135 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001137 .data = &dirty_expire_interval,
1138 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001140 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 },
1142 {
1143 .ctl_name = VM_NR_PDFLUSH_THREADS,
1144 .procname = "nr_pdflush_threads",
1145 .data = &nr_pdflush_threads,
1146 .maxlen = sizeof nr_pdflush_threads,
1147 .mode = 0444 /* read-only*/,
1148 .proc_handler = &proc_dointvec,
1149 },
1150 {
1151 .ctl_name = VM_SWAPPINESS,
1152 .procname = "swappiness",
1153 .data = &vm_swappiness,
1154 .maxlen = sizeof(vm_swappiness),
1155 .mode = 0644,
1156 .proc_handler = &proc_dointvec_minmax,
1157 .strategy = &sysctl_intvec,
1158 .extra1 = &zero,
1159 .extra2 = &one_hundred,
1160 },
1161#ifdef CONFIG_HUGETLB_PAGE
1162 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001164 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 .maxlen = sizeof(unsigned long),
1166 .mode = 0644,
1167 .proc_handler = &hugetlb_sysctl_handler,
1168 .extra1 = (void *)&hugetlb_zero,
1169 .extra2 = (void *)&hugetlb_infinity,
1170 },
1171 {
1172 .ctl_name = VM_HUGETLB_GROUP,
1173 .procname = "hugetlb_shm_group",
1174 .data = &sysctl_hugetlb_shm_group,
1175 .maxlen = sizeof(gid_t),
1176 .mode = 0644,
1177 .proc_handler = &proc_dointvec,
1178 },
Mel Gorman396faf02007-07-17 04:03:13 -07001179 {
1180 .ctl_name = CTL_UNNUMBERED,
1181 .procname = "hugepages_treat_as_movable",
1182 .data = &hugepages_treat_as_movable,
1183 .maxlen = sizeof(int),
1184 .mode = 0644,
1185 .proc_handler = &hugetlb_treat_movable_handler,
1186 },
Adam Litke54f9f802007-10-16 01:26:20 -07001187 {
1188 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001189 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001190 .data = NULL,
1191 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001192 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001193 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001194 .extra1 = (void *)&hugetlb_zero,
1195 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001196 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197#endif
1198 {
1199 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1200 .procname = "lowmem_reserve_ratio",
1201 .data = &sysctl_lowmem_reserve_ratio,
1202 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1203 .mode = 0644,
1204 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1205 .strategy = &sysctl_intvec,
1206 },
1207 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001208 .ctl_name = VM_DROP_PAGECACHE,
1209 .procname = "drop_caches",
1210 .data = &sysctl_drop_caches,
1211 .maxlen = sizeof(int),
1212 .mode = 0644,
1213 .proc_handler = drop_caches_sysctl_handler,
1214 .strategy = &sysctl_intvec,
1215 },
1216 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 .ctl_name = VM_MIN_FREE_KBYTES,
1218 .procname = "min_free_kbytes",
1219 .data = &min_free_kbytes,
1220 .maxlen = sizeof(min_free_kbytes),
1221 .mode = 0644,
1222 .proc_handler = &min_free_kbytes_sysctl_handler,
1223 .strategy = &sysctl_intvec,
1224 .extra1 = &zero,
1225 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001226 {
1227 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1228 .procname = "percpu_pagelist_fraction",
1229 .data = &percpu_pagelist_fraction,
1230 .maxlen = sizeof(percpu_pagelist_fraction),
1231 .mode = 0644,
1232 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1233 .strategy = &sysctl_intvec,
1234 .extra1 = &min_percpu_pagelist_fract,
1235 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236#ifdef CONFIG_MMU
1237 {
1238 .ctl_name = VM_MAX_MAP_COUNT,
1239 .procname = "max_map_count",
1240 .data = &sysctl_max_map_count,
1241 .maxlen = sizeof(sysctl_max_map_count),
1242 .mode = 0644,
1243 .proc_handler = &proc_dointvec
1244 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001245#else
1246 {
1247 .ctl_name = CTL_UNNUMBERED,
1248 .procname = "nr_trim_pages",
1249 .data = &sysctl_nr_trim_pages,
1250 .maxlen = sizeof(sysctl_nr_trim_pages),
1251 .mode = 0644,
1252 .proc_handler = &proc_dointvec_minmax,
1253 .strategy = &sysctl_intvec,
1254 .extra1 = &zero,
1255 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256#endif
1257 {
1258 .ctl_name = VM_LAPTOP_MODE,
1259 .procname = "laptop_mode",
1260 .data = &laptop_mode,
1261 .maxlen = sizeof(laptop_mode),
1262 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001263 .proc_handler = &proc_dointvec_jiffies,
1264 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 },
1266 {
1267 .ctl_name = VM_BLOCK_DUMP,
1268 .procname = "block_dump",
1269 .data = &block_dump,
1270 .maxlen = sizeof(block_dump),
1271 .mode = 0644,
1272 .proc_handler = &proc_dointvec,
1273 .strategy = &sysctl_intvec,
1274 .extra1 = &zero,
1275 },
1276 {
1277 .ctl_name = VM_VFS_CACHE_PRESSURE,
1278 .procname = "vfs_cache_pressure",
1279 .data = &sysctl_vfs_cache_pressure,
1280 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1281 .mode = 0644,
1282 .proc_handler = &proc_dointvec,
1283 .strategy = &sysctl_intvec,
1284 .extra1 = &zero,
1285 },
1286#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1287 {
1288 .ctl_name = VM_LEGACY_VA_LAYOUT,
1289 .procname = "legacy_va_layout",
1290 .data = &sysctl_legacy_va_layout,
1291 .maxlen = sizeof(sysctl_legacy_va_layout),
1292 .mode = 0644,
1293 .proc_handler = &proc_dointvec,
1294 .strategy = &sysctl_intvec,
1295 .extra1 = &zero,
1296 },
1297#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001298#ifdef CONFIG_NUMA
1299 {
1300 .ctl_name = VM_ZONE_RECLAIM_MODE,
1301 .procname = "zone_reclaim_mode",
1302 .data = &zone_reclaim_mode,
1303 .maxlen = sizeof(zone_reclaim_mode),
1304 .mode = 0644,
1305 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001306 .strategy = &sysctl_intvec,
1307 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001308 },
Christoph Lameter96146342006-07-03 00:24:13 -07001309 {
1310 .ctl_name = VM_MIN_UNMAPPED,
1311 .procname = "min_unmapped_ratio",
1312 .data = &sysctl_min_unmapped_ratio,
1313 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1314 .mode = 0644,
1315 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1316 .strategy = &sysctl_intvec,
1317 .extra1 = &zero,
1318 .extra2 = &one_hundred,
1319 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001320 {
1321 .ctl_name = VM_MIN_SLAB,
1322 .procname = "min_slab_ratio",
1323 .data = &sysctl_min_slab_ratio,
1324 .maxlen = sizeof(sysctl_min_slab_ratio),
1325 .mode = 0644,
1326 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1327 .strategy = &sysctl_intvec,
1328 .extra1 = &zero,
1329 .extra2 = &one_hundred,
1330 },
Christoph Lameter17436602006-01-18 17:42:32 -08001331#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001332#ifdef CONFIG_SMP
1333 {
1334 .ctl_name = CTL_UNNUMBERED,
1335 .procname = "stat_interval",
1336 .data = &sysctl_stat_interval,
1337 .maxlen = sizeof(sysctl_stat_interval),
1338 .mode = 0644,
1339 .proc_handler = &proc_dointvec_jiffies,
1340 .strategy = &sysctl_jiffies,
1341 },
1342#endif
Eric Parised032182007-06-28 15:55:21 -04001343 {
1344 .ctl_name = CTL_UNNUMBERED,
1345 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001346 .data = &dac_mmap_min_addr,
1347 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001348 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001349 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001350 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001351#ifdef CONFIG_NUMA
1352 {
1353 .ctl_name = CTL_UNNUMBERED,
1354 .procname = "numa_zonelist_order",
1355 .data = &numa_zonelist_order,
1356 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1357 .mode = 0644,
1358 .proc_handler = &numa_zonelist_order_handler,
1359 .strategy = &sysctl_string,
1360 },
1361#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001362#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001363 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001364 {
1365 .ctl_name = VM_VDSO_ENABLED,
1366 .procname = "vdso_enabled",
1367 .data = &vdso_enabled,
1368 .maxlen = sizeof(vdso_enabled),
1369 .mode = 0644,
1370 .proc_handler = &proc_dointvec,
1371 .strategy = &sysctl_intvec,
1372 .extra1 = &zero,
1373 },
1374#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001375#ifdef CONFIG_HIGHMEM
1376 {
1377 .ctl_name = CTL_UNNUMBERED,
1378 .procname = "highmem_is_dirtyable",
1379 .data = &vm_highmem_is_dirtyable,
1380 .maxlen = sizeof(vm_highmem_is_dirtyable),
1381 .mode = 0644,
1382 .proc_handler = &proc_dointvec_minmax,
1383 .strategy = &sysctl_intvec,
1384 .extra1 = &zero,
1385 .extra2 = &one,
1386 },
1387#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001388 {
1389 .ctl_name = CTL_UNNUMBERED,
1390 .procname = "scan_unevictable_pages",
1391 .data = &scan_unevictable_pages,
1392 .maxlen = sizeof(scan_unevictable_pages),
1393 .mode = 0644,
1394 .proc_handler = &scan_unevictable_handler,
1395 },
Andi Kleen6a460792009-09-16 11:50:15 +02001396#ifdef CONFIG_MEMORY_FAILURE
1397 {
1398 .ctl_name = CTL_UNNUMBERED,
1399 .procname = "memory_failure_early_kill",
1400 .data = &sysctl_memory_failure_early_kill,
1401 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1402 .mode = 0644,
1403 .proc_handler = &proc_dointvec_minmax,
1404 .strategy = &sysctl_intvec,
1405 .extra1 = &zero,
1406 .extra2 = &one,
1407 },
1408 {
1409 .ctl_name = CTL_UNNUMBERED,
1410 .procname = "memory_failure_recovery",
1411 .data = &sysctl_memory_failure_recovery,
1412 .maxlen = sizeof(sysctl_memory_failure_recovery),
1413 .mode = 0644,
1414 .proc_handler = &proc_dointvec_minmax,
1415 .strategy = &sysctl_intvec,
1416 .extra1 = &zero,
1417 .extra2 = &one,
1418 },
1419#endif
1420
Andrew Morton2be7fe02007-07-15 23:41:21 -07001421/*
1422 * NOTE: do not add new entries to this table unless you have read
1423 * Documentation/sysctl/ctl_unnumbered.txt
1424 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 { .ctl_name = 0 }
1426};
1427
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001428#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001429static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001430 { .ctl_name = 0 }
1431};
1432#endif
1433
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001434static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 {
1436 .ctl_name = FS_NRINODE,
1437 .procname = "inode-nr",
1438 .data = &inodes_stat,
1439 .maxlen = 2*sizeof(int),
1440 .mode = 0444,
1441 .proc_handler = &proc_dointvec,
1442 },
1443 {
1444 .ctl_name = FS_STATINODE,
1445 .procname = "inode-state",
1446 .data = &inodes_stat,
1447 .maxlen = 7*sizeof(int),
1448 .mode = 0444,
1449 .proc_handler = &proc_dointvec,
1450 },
1451 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 .procname = "file-nr",
1453 .data = &files_stat,
1454 .maxlen = 3*sizeof(int),
1455 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001456 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 },
1458 {
1459 .ctl_name = FS_MAXFILE,
1460 .procname = "file-max",
1461 .data = &files_stat.max_files,
1462 .maxlen = sizeof(int),
1463 .mode = 0644,
1464 .proc_handler = &proc_dointvec,
1465 },
1466 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001467 .ctl_name = CTL_UNNUMBERED,
1468 .procname = "nr_open",
1469 .data = &sysctl_nr_open,
1470 .maxlen = sizeof(int),
1471 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001472 .proc_handler = &proc_dointvec_minmax,
1473 .extra1 = &sysctl_nr_open_min,
1474 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001475 },
1476 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 .ctl_name = FS_DENTRY,
1478 .procname = "dentry-state",
1479 .data = &dentry_stat,
1480 .maxlen = 6*sizeof(int),
1481 .mode = 0444,
1482 .proc_handler = &proc_dointvec,
1483 },
1484 {
1485 .ctl_name = FS_OVERFLOWUID,
1486 .procname = "overflowuid",
1487 .data = &fs_overflowuid,
1488 .maxlen = sizeof(int),
1489 .mode = 0644,
1490 .proc_handler = &proc_dointvec_minmax,
1491 .strategy = &sysctl_intvec,
1492 .extra1 = &minolduid,
1493 .extra2 = &maxolduid,
1494 },
1495 {
1496 .ctl_name = FS_OVERFLOWGID,
1497 .procname = "overflowgid",
1498 .data = &fs_overflowgid,
1499 .maxlen = sizeof(int),
1500 .mode = 0644,
1501 .proc_handler = &proc_dointvec_minmax,
1502 .strategy = &sysctl_intvec,
1503 .extra1 = &minolduid,
1504 .extra2 = &maxolduid,
1505 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001506#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 {
1508 .ctl_name = FS_LEASES,
1509 .procname = "leases-enable",
1510 .data = &leases_enable,
1511 .maxlen = sizeof(int),
1512 .mode = 0644,
1513 .proc_handler = &proc_dointvec,
1514 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001515#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516#ifdef CONFIG_DNOTIFY
1517 {
1518 .ctl_name = FS_DIR_NOTIFY,
1519 .procname = "dir-notify-enable",
1520 .data = &dir_notify_enable,
1521 .maxlen = sizeof(int),
1522 .mode = 0644,
1523 .proc_handler = &proc_dointvec,
1524 },
1525#endif
1526#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001527#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 {
1529 .ctl_name = FS_LEASE_TIME,
1530 .procname = "lease-break-time",
1531 .data = &lease_break_time,
1532 .maxlen = sizeof(int),
1533 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001534 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001536#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001537#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 .procname = "aio-nr",
1540 .data = &aio_nr,
1541 .maxlen = sizeof(aio_nr),
1542 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001543 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 },
1545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 .procname = "aio-max-nr",
1547 .data = &aio_max_nr,
1548 .maxlen = sizeof(aio_max_nr),
1549 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001550 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001552#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001553#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001554 {
1555 .ctl_name = FS_INOTIFY,
1556 .procname = "inotify",
1557 .mode = 0555,
1558 .child = inotify_table,
1559 },
1560#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001561#ifdef CONFIG_EPOLL
1562 {
1563 .procname = "epoll",
1564 .mode = 0555,
1565 .child = epoll_table,
1566 },
1567#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001569 {
1570 .ctl_name = KERN_SETUID_DUMPABLE,
1571 .procname = "suid_dumpable",
1572 .data = &suid_dumpable,
1573 .maxlen = sizeof(int),
1574 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001575 .proc_handler = &proc_dointvec_minmax,
1576 .strategy = &sysctl_intvec,
1577 .extra1 = &zero,
1578 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001579 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001580#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1581 {
1582 .ctl_name = CTL_UNNUMBERED,
1583 .procname = "binfmt_misc",
1584 .mode = 0555,
1585 .child = binfmt_misc_table,
1586 },
1587#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001588/*
1589 * NOTE: do not add new entries to this table unless you have read
1590 * Documentation/sysctl/ctl_unnumbered.txt
1591 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 { .ctl_name = 0 }
1593};
1594
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001595static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001596#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001597 {
1598 .ctl_name = CTL_UNNUMBERED,
1599 .procname = "exception-trace",
1600 .data = &show_unhandled_signals,
1601 .maxlen = sizeof(int),
1602 .mode = 0644,
1603 .proc_handler = proc_dointvec
1604 },
1605#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 { .ctl_name = 0 }
1607};
1608
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001609static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001611};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Al Viro330d57f2005-11-04 10:18:40 +00001613static DEFINE_SPINLOCK(sysctl_lock);
1614
1615/* called under sysctl_lock */
1616static int use_table(struct ctl_table_header *p)
1617{
1618 if (unlikely(p->unregistering))
1619 return 0;
1620 p->used++;
1621 return 1;
1622}
1623
1624/* called under sysctl_lock */
1625static void unuse_table(struct ctl_table_header *p)
1626{
1627 if (!--p->used)
1628 if (unlikely(p->unregistering))
1629 complete(p->unregistering);
1630}
1631
1632/* called under sysctl_lock, will reacquire if has to wait */
1633static void start_unregistering(struct ctl_table_header *p)
1634{
1635 /*
1636 * if p->used is 0, nobody will ever touch that entry again;
1637 * we'll eliminate all paths to it before dropping sysctl_lock
1638 */
1639 if (unlikely(p->used)) {
1640 struct completion wait;
1641 init_completion(&wait);
1642 p->unregistering = &wait;
1643 spin_unlock(&sysctl_lock);
1644 wait_for_completion(&wait);
1645 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001646 } else {
1647 /* anything non-NULL; we'll never dereference it */
1648 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001649 }
1650 /*
1651 * do not remove from the list until nobody holds it; walking the
1652 * list in do_sysctl() relies on that.
1653 */
1654 list_del_init(&p->ctl_entry);
1655}
1656
Al Virof7e6ced2008-07-15 01:44:23 -04001657void sysctl_head_get(struct ctl_table_header *head)
1658{
1659 spin_lock(&sysctl_lock);
1660 head->count++;
1661 spin_unlock(&sysctl_lock);
1662}
1663
1664void sysctl_head_put(struct ctl_table_header *head)
1665{
1666 spin_lock(&sysctl_lock);
1667 if (!--head->count)
1668 kfree(head);
1669 spin_unlock(&sysctl_lock);
1670}
1671
1672struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1673{
1674 if (!head)
1675 BUG();
1676 spin_lock(&sysctl_lock);
1677 if (!use_table(head))
1678 head = ERR_PTR(-ENOENT);
1679 spin_unlock(&sysctl_lock);
1680 return head;
1681}
1682
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001683void sysctl_head_finish(struct ctl_table_header *head)
1684{
1685 if (!head)
1686 return;
1687 spin_lock(&sysctl_lock);
1688 unuse_table(head);
1689 spin_unlock(&sysctl_lock);
1690}
1691
Al Viro73455092008-07-14 21:22:20 -04001692static struct ctl_table_set *
1693lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1694{
1695 struct ctl_table_set *set = &root->default_set;
1696 if (root->lookup)
1697 set = root->lookup(root, namespaces);
1698 return set;
1699}
1700
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001701static struct list_head *
1702lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001703{
Al Viro73455092008-07-14 21:22:20 -04001704 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1705 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001706}
1707
1708struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1709 struct ctl_table_header *prev)
1710{
1711 struct ctl_table_root *root;
1712 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001713 struct ctl_table_header *head;
1714 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001715
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001716 spin_lock(&sysctl_lock);
1717 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001718 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001719 tmp = &prev->ctl_entry;
1720 unuse_table(prev);
1721 goto next;
1722 }
1723 tmp = &root_table_header.ctl_entry;
1724 for (;;) {
1725 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1726
1727 if (!use_table(head))
1728 goto next;
1729 spin_unlock(&sysctl_lock);
1730 return head;
1731 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001732 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001733 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001734 header_list = lookup_header_list(root, namespaces);
1735 if (tmp != header_list)
1736 continue;
1737
1738 do {
1739 root = list_entry(root->root_list.next,
1740 struct ctl_table_root, root_list);
1741 if (root == &sysctl_table_root)
1742 goto out;
1743 header_list = lookup_header_list(root, namespaces);
1744 } while (list_empty(header_list));
1745 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001746 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001747out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001748 spin_unlock(&sysctl_lock);
1749 return NULL;
1750}
1751
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001752struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1753{
1754 return __sysctl_head_next(current->nsproxy, prev);
1755}
1756
1757void register_sysctl_root(struct ctl_table_root *root)
1758{
1759 spin_lock(&sysctl_lock);
1760 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1761 spin_unlock(&sysctl_lock);
1762}
1763
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001764#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001765/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001766static int do_sysctl_strategy(struct ctl_table_root *root,
1767 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001768 void __user *oldval, size_t __user *oldlenp,
1769 void __user *newval, size_t newlen)
1770{
1771 int op = 0, rc;
1772
1773 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001774 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001775 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001776 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001777 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001778 return -EPERM;
1779
1780 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001781 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001782 if (rc < 0)
1783 return rc;
1784 if (rc > 0)
1785 return 0;
1786 }
1787
1788 /* If there is no strategy routine, or if the strategy returns
1789 * zero, proceed with automatic r/w */
1790 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001791 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001792 if (rc < 0)
1793 return rc;
1794 }
1795 return 0;
1796}
1797
1798static int parse_table(int __user *name, int nlen,
1799 void __user *oldval, size_t __user *oldlenp,
1800 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001801 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001802 struct ctl_table *table)
1803{
1804 int n;
1805repeat:
1806 if (!nlen)
1807 return -ENOTDIR;
1808 if (get_user(n, name))
1809 return -EFAULT;
1810 for ( ; table->ctl_name || table->procname; table++) {
1811 if (!table->ctl_name)
1812 continue;
1813 if (n == table->ctl_name) {
1814 int error;
1815 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001816 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001817 return -EPERM;
1818 name++;
1819 nlen--;
1820 table = table->child;
1821 goto repeat;
1822 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001823 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001824 oldval, oldlenp,
1825 newval, newlen);
1826 return error;
1827 }
1828 }
1829 return -ENOTDIR;
1830}
1831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1833 void __user *newval, size_t newlen)
1834{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001835 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001836 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
1838 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1839 return -ENOTDIR;
1840 if (oldval) {
1841 int old_len;
1842 if (!oldlenp || get_user(old_len, oldlenp))
1843 return -EFAULT;
1844 }
Al Viro330d57f2005-11-04 10:18:40 +00001845
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001846 for (head = sysctl_head_next(NULL); head;
1847 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001848 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001849 newval, newlen,
1850 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001851 if (error != -ENOTDIR) {
1852 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001853 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001854 }
1855 }
Al Viro330d57f2005-11-04 10:18:40 +00001856 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857}
1858
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001859SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860{
1861 struct __sysctl_args tmp;
1862 int error;
1863
1864 if (copy_from_user(&tmp, args, sizeof(tmp)))
1865 return -EFAULT;
1866
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001867 error = deprecated_sysctl_warning(&tmp);
1868 if (error)
1869 goto out;
1870
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 lock_kernel();
1872 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1873 tmp.newval, tmp.newlen);
1874 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001875out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 return error;
1877}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001878#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879
1880/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001881 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 * some sysctl variables are readonly even to root.
1883 */
1884
1885static int test_perm(int mode, int op)
1886{
David Howells76aac0e2008-11-14 10:39:12 +11001887 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 mode >>= 6;
1889 else if (in_egroup_p(0))
1890 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001891 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 return 0;
1893 return -EACCES;
1894}
1895
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001896int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897{
1898 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001899 int mode;
1900
Al Viroe6305c42008-07-15 21:03:57 -04001901 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 if (error)
1903 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001904
1905 if (root->permissions)
1906 mode = root->permissions(root, current->nsproxy, table);
1907 else
1908 mode = table->mode;
1909
1910 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911}
1912
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001913static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1914{
1915 for (; table->ctl_name || table->procname; table++) {
1916 table->parent = parent;
1917 if (table->child)
1918 sysctl_set_parent(table, table->child);
1919 }
1920}
1921
1922static __init int sysctl_init(void)
1923{
1924 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001925#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1926 {
1927 int err;
1928 err = sysctl_check_table(current->nsproxy, root_table);
1929 }
1930#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001931 return 0;
1932}
1933
1934core_initcall(sysctl_init);
1935
Al Virobfbcf032008-07-27 06:31:22 +01001936static struct ctl_table *is_branch_in(struct ctl_table *branch,
1937 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001938{
1939 struct ctl_table *p;
1940 const char *s = branch->procname;
1941
1942 /* branch should have named subdirectory as its first element */
1943 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001944 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001945
1946 /* ... and nothing else */
1947 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001948 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001949
1950 /* table should contain subdirectory with the same name */
1951 for (p = table; p->procname || p->ctl_name; p++) {
1952 if (!p->child)
1953 continue;
1954 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001955 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001956 }
Al Virobfbcf032008-07-27 06:31:22 +01001957 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001958}
1959
1960/* see if attaching q to p would be an improvement */
1961static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1962{
1963 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001964 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001965 int is_better = 0;
1966 int not_in_parent = !p->attached_by;
1967
Al Virobfbcf032008-07-27 06:31:22 +01001968 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001969 if (by == q->attached_by)
1970 is_better = 1;
1971 if (to == p->attached_by)
1972 not_in_parent = 1;
1973 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001974 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001975 }
1976
1977 if (is_better && not_in_parent) {
1978 q->attached_by = by;
1979 q->attached_to = to;
1980 q->parent = p;
1981 }
1982}
1983
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001985 * __register_sysctl_paths - register a sysctl hierarchy
1986 * @root: List of sysctl headers to register on
1987 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001988 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 *
1991 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001992 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001994 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 *
1996 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1997 * must be unique within that level of sysctl
1998 *
1999 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2000 * enter a sysctl file
2001 *
2002 * data - a pointer to data for use by proc_handler
2003 *
2004 * maxlen - the maximum size in bytes of the data
2005 *
2006 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2007 *
2008 * child - a pointer to the child sysctl table if this entry is a directory, or
2009 * %NULL.
2010 *
2011 * proc_handler - the text handler routine (described below)
2012 *
2013 * strategy - the strategy routine (described below)
2014 *
2015 * de - for internal use by the sysctl routines
2016 *
2017 * extra1, extra2 - extra pointers usable by the proc handler routines
2018 *
2019 * Leaf nodes in the sysctl tree will be represented by a single file
2020 * under /proc; non-leaf nodes will be represented by directories.
2021 *
2022 * sysctl(2) can automatically manage read and write requests through
2023 * the sysctl table. The data and maxlen fields of the ctl_table
2024 * struct enable minimal validation of the values being written to be
2025 * performed, and the mode field allows minimal authentication.
2026 *
2027 * More sophisticated management can be enabled by the provision of a
2028 * strategy routine with the table entry. This will be called before
2029 * any automatic read or write of the data is performed.
2030 *
2031 * The strategy routine may return
2032 *
2033 * < 0 - Error occurred (error is passed to user process)
2034 *
2035 * 0 - OK - proceed with automatic read or write.
2036 *
2037 * > 0 - OK - read or write has been done by the strategy routine, so
2038 * return immediately.
2039 *
2040 * There must be a proc_handler routine for any terminal nodes
2041 * mirrored under /proc/sys (non-terminals are handled by a built-in
2042 * directory handler). Several default handlers are available to
2043 * cover common cases -
2044 *
2045 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2046 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2047 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2048 *
2049 * It is the handler's job to read the input buffer from user memory
2050 * and process it. The handler should return 0 on success.
2051 *
2052 * This routine returns %NULL on a failure to register, and a pointer
2053 * to the table header on success.
2054 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002055struct ctl_table_header *__register_sysctl_paths(
2056 struct ctl_table_root *root,
2057 struct nsproxy *namespaces,
2058 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002060 struct ctl_table_header *header;
2061 struct ctl_table *new, **prevp;
2062 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04002063 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002064
2065 /* Count the path components */
2066 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2067 ;
2068
2069 /*
2070 * For each path component, allocate a 2-element ctl_table array.
2071 * The first array element will be filled with the sysctl entry
2072 * for this, the second will be the sentinel (ctl_name == 0).
2073 *
2074 * We allocate everything in one go so that we don't have to
2075 * worry about freeing additional memory in unregister_sysctl_table.
2076 */
2077 header = kzalloc(sizeof(struct ctl_table_header) +
2078 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2079 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002081
2082 new = (struct ctl_table *) (header + 1);
2083
2084 /* Now connect the dots */
2085 prevp = &header->ctl_table;
2086 for (n = 0; n < npath; ++n, ++path) {
2087 /* Copy the procname */
2088 new->procname = path->procname;
2089 new->ctl_name = path->ctl_name;
2090 new->mode = 0555;
2091
2092 *prevp = new;
2093 prevp = &new->child;
2094
2095 new += 2;
2096 }
2097 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002098 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002099
2100 INIT_LIST_HEAD(&header->ctl_entry);
2101 header->used = 0;
2102 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002103 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002104 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002105 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002106#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002107 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002108 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002109 return NULL;
2110 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002111#endif
Al Viro330d57f2005-11-04 10:18:40 +00002112 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002113 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002114 header->attached_by = header->ctl_table;
2115 header->attached_to = root_table;
2116 header->parent = &root_table_header;
2117 for (set = header->set; set; set = set->parent) {
2118 struct ctl_table_header *p;
2119 list_for_each_entry(p, &set->list, ctl_entry) {
2120 if (p->unregistering)
2121 continue;
2122 try_attach(p, header);
2123 }
2124 }
2125 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002126 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002127 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002128
2129 return header;
2130}
2131
2132/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002133 * register_sysctl_table_path - register a sysctl table hierarchy
2134 * @path: The path to the directory the sysctl table is in.
2135 * @table: the top-level table structure
2136 *
2137 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2138 * array. A completely 0 filled entry terminates the table.
2139 *
2140 * See __register_sysctl_paths for more details.
2141 */
2142struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2143 struct ctl_table *table)
2144{
2145 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2146 path, table);
2147}
2148
2149/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002150 * register_sysctl_table - register a sysctl table hierarchy
2151 * @table: the top-level table structure
2152 *
2153 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2154 * array. A completely 0 filled entry terminates the table.
2155 *
2156 * See register_sysctl_paths for more details.
2157 */
2158struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2159{
2160 static const struct ctl_path null_path[] = { {} };
2161
2162 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163}
2164
2165/**
2166 * unregister_sysctl_table - unregister a sysctl table hierarchy
2167 * @header: the header returned from register_sysctl_table
2168 *
2169 * Unregisters the sysctl table and all children. proc entries may not
2170 * actually be removed until they are no longer used by anyone.
2171 */
2172void unregister_sysctl_table(struct ctl_table_header * header)
2173{
Al Viro330d57f2005-11-04 10:18:40 +00002174 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002175
2176 if (header == NULL)
2177 return;
2178
Al Viro330d57f2005-11-04 10:18:40 +00002179 spin_lock(&sysctl_lock);
2180 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002181 if (!--header->parent->count) {
2182 WARN_ON(1);
2183 kfree(header->parent);
2184 }
Al Virof7e6ced2008-07-15 01:44:23 -04002185 if (!--header->count)
2186 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002187 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
Al Viro90434762008-07-15 08:54:06 -04002190int sysctl_is_seen(struct ctl_table_header *p)
2191{
2192 struct ctl_table_set *set = p->set;
2193 int res;
2194 spin_lock(&sysctl_lock);
2195 if (p->unregistering)
2196 res = 0;
2197 else if (!set->is_seen)
2198 res = 1;
2199 else
2200 res = set->is_seen(set);
2201 spin_unlock(&sysctl_lock);
2202 return res;
2203}
2204
Al Viro73455092008-07-14 21:22:20 -04002205void setup_sysctl_set(struct ctl_table_set *p,
2206 struct ctl_table_set *parent,
2207 int (*is_seen)(struct ctl_table_set *))
2208{
2209 INIT_LIST_HEAD(&p->list);
2210 p->parent = parent ? parent : &sysctl_table_root.default_set;
2211 p->is_seen = is_seen;
2212}
2213
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002214#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002215struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002216{
2217 return NULL;
2218}
2219
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002220struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2221 struct ctl_table *table)
2222{
2223 return NULL;
2224}
2225
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002226void unregister_sysctl_table(struct ctl_table_header * table)
2227{
2228}
2229
Al Viro73455092008-07-14 21:22:20 -04002230void setup_sysctl_set(struct ctl_table_set *p,
2231 struct ctl_table_set *parent,
2232 int (*is_seen)(struct ctl_table_set *))
2233{
2234}
2235
Al Virof7e6ced2008-07-15 01:44:23 -04002236void sysctl_head_put(struct ctl_table_header *head)
2237{
2238}
2239
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002240#endif /* CONFIG_SYSCTL */
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242/*
2243 * /proc/sys support
2244 */
2245
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002246#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002248static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002249 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002250 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002251{
2252 size_t len;
2253 char __user *p;
2254 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002255
2256 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002257 *lenp = 0;
2258 return 0;
2259 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002260
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002261 if (write) {
2262 len = 0;
2263 p = buffer;
2264 while (len < *lenp) {
2265 if (get_user(c, p++))
2266 return -EFAULT;
2267 if (c == 0 || c == '\n')
2268 break;
2269 len++;
2270 }
2271 if (len >= maxlen)
2272 len = maxlen-1;
2273 if(copy_from_user(data, buffer, len))
2274 return -EFAULT;
2275 ((char *) data)[len] = 0;
2276 *ppos += *lenp;
2277 } else {
2278 len = strlen(data);
2279 if (len > maxlen)
2280 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002281
2282 if (*ppos > len) {
2283 *lenp = 0;
2284 return 0;
2285 }
2286
2287 data += *ppos;
2288 len -= *ppos;
2289
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002290 if (len > *lenp)
2291 len = *lenp;
2292 if (len)
2293 if(copy_to_user(buffer, data, len))
2294 return -EFAULT;
2295 if (len < *lenp) {
2296 if(put_user('\n', ((char __user *) buffer) + len))
2297 return -EFAULT;
2298 len++;
2299 }
2300 *lenp = len;
2301 *ppos += len;
2302 }
2303 return 0;
2304}
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306/**
2307 * proc_dostring - read a string sysctl
2308 * @table: the sysctl table
2309 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 * @buffer: the user buffer
2311 * @lenp: the size of the user buffer
2312 * @ppos: file position
2313 *
2314 * Reads/writes a string from/to the user buffer. If the kernel
2315 * buffer provided is not large enough to hold the string, the
2316 * string is truncated. The copied string is %NULL-terminated.
2317 * If the string is being read by the user process, it is copied
2318 * and a newline '\n' is added. It is truncated if the buffer is
2319 * not large enough.
2320 *
2321 * Returns 0 on success.
2322 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002323int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 void __user *buffer, size_t *lenp, loff_t *ppos)
2325{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002326 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002327 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328}
2329
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2332 int *valp,
2333 int write, void *data)
2334{
2335 if (write) {
2336 *valp = *negp ? -*lvalp : *lvalp;
2337 } else {
2338 int val = *valp;
2339 if (val < 0) {
2340 *negp = -1;
2341 *lvalp = (unsigned long)-val;
2342 } else {
2343 *negp = 0;
2344 *lvalp = (unsigned long)val;
2345 }
2346 }
2347 return 0;
2348}
2349
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002350static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002351 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002352 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2354 int write, void *data),
2355 void *data)
2356{
2357#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002358 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 unsigned long lval;
2360 size_t left, len;
2361
2362 char buf[TMPBUFLEN], *p;
2363 char __user *s = buffer;
2364
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002365 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 (*ppos && !write)) {
2367 *lenp = 0;
2368 return 0;
2369 }
2370
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002371 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 vleft = table->maxlen / sizeof(*i);
2373 left = *lenp;
2374
2375 if (!conv)
2376 conv = do_proc_dointvec_conv;
2377
2378 for (; left && vleft--; i++, first=0) {
2379 if (write) {
2380 while (left) {
2381 char c;
2382 if (get_user(c, s))
2383 return -EFAULT;
2384 if (!isspace(c))
2385 break;
2386 left--;
2387 s++;
2388 }
2389 if (!left)
2390 break;
2391 neg = 0;
2392 len = left;
2393 if (len > sizeof(buf) - 1)
2394 len = sizeof(buf) - 1;
2395 if (copy_from_user(buf, s, len))
2396 return -EFAULT;
2397 buf[len] = 0;
2398 p = buf;
2399 if (*p == '-' && left > 1) {
2400 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002401 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 }
2403 if (*p < '0' || *p > '9')
2404 break;
2405
2406 lval = simple_strtoul(p, &p, 0);
2407
2408 len = p-buf;
2409 if ((len < left) && *p && !isspace(*p))
2410 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 s += len;
2412 left -= len;
2413
2414 if (conv(&neg, &lval, i, 1, data))
2415 break;
2416 } else {
2417 p = buf;
2418 if (!first)
2419 *p++ = '\t';
2420
2421 if (conv(&neg, &lval, i, 0, data))
2422 break;
2423
2424 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2425 len = strlen(buf);
2426 if (len > left)
2427 len = left;
2428 if(copy_to_user(s, buf, len))
2429 return -EFAULT;
2430 left -= len;
2431 s += len;
2432 }
2433 }
2434
2435 if (!write && !first && left) {
2436 if(put_user('\n', s))
2437 return -EFAULT;
2438 left--, s++;
2439 }
2440 if (write) {
2441 while (left) {
2442 char c;
2443 if (get_user(c, s++))
2444 return -EFAULT;
2445 if (!isspace(c))
2446 break;
2447 left--;
2448 }
2449 }
2450 if (write && first)
2451 return -EINVAL;
2452 *lenp -= left;
2453 *ppos += *lenp;
2454 return 0;
2455#undef TMPBUFLEN
2456}
2457
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002458static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002459 void __user *buffer, size_t *lenp, loff_t *ppos,
2460 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2461 int write, void *data),
2462 void *data)
2463{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002464 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002465 buffer, lenp, ppos, conv, data);
2466}
2467
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468/**
2469 * proc_dointvec - read a vector of integers
2470 * @table: the sysctl table
2471 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 * @buffer: the user buffer
2473 * @lenp: the size of the user buffer
2474 * @ppos: file position
2475 *
2476 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2477 * values from/to the user buffer, treated as an ASCII string.
2478 *
2479 * Returns 0 on success.
2480 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002481int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 void __user *buffer, size_t *lenp, loff_t *ppos)
2483{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002484 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 NULL,NULL);
2486}
2487
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002488/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002489 * Taint values can only be increased
2490 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002491 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002492static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002493 void __user *buffer, size_t *lenp, loff_t *ppos)
2494{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002495 struct ctl_table t;
2496 unsigned long tmptaint = get_taint();
2497 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002498
Bastian Blank91fcd412007-04-23 14:41:14 -07002499 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002500 return -EPERM;
2501
Andi Kleen25ddbb12008-10-15 22:01:41 -07002502 t = *table;
2503 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002504 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002505 if (err < 0)
2506 return err;
2507
2508 if (write) {
2509 /*
2510 * Poor man's atomic or. Not worth adding a primitive
2511 * to everyone's atomic.h for this
2512 */
2513 int i;
2514 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2515 if ((tmptaint >> i) & 1)
2516 add_taint(i);
2517 }
2518 }
2519
2520 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002521}
2522
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523struct do_proc_dointvec_minmax_conv_param {
2524 int *min;
2525 int *max;
2526};
2527
2528static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2529 int *valp,
2530 int write, void *data)
2531{
2532 struct do_proc_dointvec_minmax_conv_param *param = data;
2533 if (write) {
2534 int val = *negp ? -*lvalp : *lvalp;
2535 if ((param->min && *param->min > val) ||
2536 (param->max && *param->max < val))
2537 return -EINVAL;
2538 *valp = val;
2539 } else {
2540 int val = *valp;
2541 if (val < 0) {
2542 *negp = -1;
2543 *lvalp = (unsigned long)-val;
2544 } else {
2545 *negp = 0;
2546 *lvalp = (unsigned long)val;
2547 }
2548 }
2549 return 0;
2550}
2551
2552/**
2553 * proc_dointvec_minmax - read a vector of integers with min/max values
2554 * @table: the sysctl table
2555 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 * @buffer: the user buffer
2557 * @lenp: the size of the user buffer
2558 * @ppos: file position
2559 *
2560 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2561 * values from/to the user buffer, treated as an ASCII string.
2562 *
2563 * This routine will ensure the values are within the range specified by
2564 * table->extra1 (min) and table->extra2 (max).
2565 *
2566 * Returns 0 on success.
2567 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002568int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 void __user *buffer, size_t *lenp, loff_t *ppos)
2570{
2571 struct do_proc_dointvec_minmax_conv_param param = {
2572 .min = (int *) table->extra1,
2573 .max = (int *) table->extra2,
2574 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002575 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 do_proc_dointvec_minmax_conv, &param);
2577}
2578
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002579static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 void __user *buffer,
2581 size_t *lenp, loff_t *ppos,
2582 unsigned long convmul,
2583 unsigned long convdiv)
2584{
2585#define TMPBUFLEN 21
2586 unsigned long *i, *min, *max, val;
2587 int vleft, first=1, neg;
2588 size_t len, left;
2589 char buf[TMPBUFLEN], *p;
2590 char __user *s = buffer;
2591
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002592 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 (*ppos && !write)) {
2594 *lenp = 0;
2595 return 0;
2596 }
2597
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002598 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 min = (unsigned long *) table->extra1;
2600 max = (unsigned long *) table->extra2;
2601 vleft = table->maxlen / sizeof(unsigned long);
2602 left = *lenp;
2603
2604 for (; left && vleft--; i++, min++, max++, first=0) {
2605 if (write) {
2606 while (left) {
2607 char c;
2608 if (get_user(c, s))
2609 return -EFAULT;
2610 if (!isspace(c))
2611 break;
2612 left--;
2613 s++;
2614 }
2615 if (!left)
2616 break;
2617 neg = 0;
2618 len = left;
2619 if (len > TMPBUFLEN-1)
2620 len = TMPBUFLEN-1;
2621 if (copy_from_user(buf, s, len))
2622 return -EFAULT;
2623 buf[len] = 0;
2624 p = buf;
2625 if (*p == '-' && left > 1) {
2626 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002627 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 }
2629 if (*p < '0' || *p > '9')
2630 break;
2631 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2632 len = p-buf;
2633 if ((len < left) && *p && !isspace(*p))
2634 break;
2635 if (neg)
2636 val = -val;
2637 s += len;
2638 left -= len;
2639
2640 if(neg)
2641 continue;
2642 if ((min && val < *min) || (max && val > *max))
2643 continue;
2644 *i = val;
2645 } else {
2646 p = buf;
2647 if (!first)
2648 *p++ = '\t';
2649 sprintf(p, "%lu", convdiv * (*i) / convmul);
2650 len = strlen(buf);
2651 if (len > left)
2652 len = left;
2653 if(copy_to_user(s, buf, len))
2654 return -EFAULT;
2655 left -= len;
2656 s += len;
2657 }
2658 }
2659
2660 if (!write && !first && left) {
2661 if(put_user('\n', s))
2662 return -EFAULT;
2663 left--, s++;
2664 }
2665 if (write) {
2666 while (left) {
2667 char c;
2668 if (get_user(c, s++))
2669 return -EFAULT;
2670 if (!isspace(c))
2671 break;
2672 left--;
2673 }
2674 }
2675 if (write && first)
2676 return -EINVAL;
2677 *lenp -= left;
2678 *ppos += *lenp;
2679 return 0;
2680#undef TMPBUFLEN
2681}
2682
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002683static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002684 void __user *buffer,
2685 size_t *lenp, loff_t *ppos,
2686 unsigned long convmul,
2687 unsigned long convdiv)
2688{
2689 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002690 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002691}
2692
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693/**
2694 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2695 * @table: the sysctl table
2696 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 * @buffer: the user buffer
2698 * @lenp: the size of the user buffer
2699 * @ppos: file position
2700 *
2701 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2702 * values from/to the user buffer, treated as an ASCII string.
2703 *
2704 * This routine will ensure the values are within the range specified by
2705 * table->extra1 (min) and table->extra2 (max).
2706 *
2707 * Returns 0 on success.
2708 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002709int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 void __user *buffer, size_t *lenp, loff_t *ppos)
2711{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002712 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713}
2714
2715/**
2716 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2717 * @table: the sysctl table
2718 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 * @buffer: the user buffer
2720 * @lenp: the size of the user buffer
2721 * @ppos: file position
2722 *
2723 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2724 * values from/to the user buffer, treated as an ASCII string. The values
2725 * are treated as milliseconds, and converted to jiffies when they are stored.
2726 *
2727 * This routine will ensure the values are within the range specified by
2728 * table->extra1 (min) and table->extra2 (max).
2729 *
2730 * Returns 0 on success.
2731 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002732int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 void __user *buffer,
2734 size_t *lenp, loff_t *ppos)
2735{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002736 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 lenp, ppos, HZ, 1000l);
2738}
2739
2740
2741static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2742 int *valp,
2743 int write, void *data)
2744{
2745 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002746 if (*lvalp > LONG_MAX / HZ)
2747 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2749 } else {
2750 int val = *valp;
2751 unsigned long lval;
2752 if (val < 0) {
2753 *negp = -1;
2754 lval = (unsigned long)-val;
2755 } else {
2756 *negp = 0;
2757 lval = (unsigned long)val;
2758 }
2759 *lvalp = lval / HZ;
2760 }
2761 return 0;
2762}
2763
2764static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2765 int *valp,
2766 int write, void *data)
2767{
2768 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002769 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2770 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2772 } else {
2773 int val = *valp;
2774 unsigned long lval;
2775 if (val < 0) {
2776 *negp = -1;
2777 lval = (unsigned long)-val;
2778 } else {
2779 *negp = 0;
2780 lval = (unsigned long)val;
2781 }
2782 *lvalp = jiffies_to_clock_t(lval);
2783 }
2784 return 0;
2785}
2786
2787static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2788 int *valp,
2789 int write, void *data)
2790{
2791 if (write) {
2792 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2793 } else {
2794 int val = *valp;
2795 unsigned long lval;
2796 if (val < 0) {
2797 *negp = -1;
2798 lval = (unsigned long)-val;
2799 } else {
2800 *negp = 0;
2801 lval = (unsigned long)val;
2802 }
2803 *lvalp = jiffies_to_msecs(lval);
2804 }
2805 return 0;
2806}
2807
2808/**
2809 * proc_dointvec_jiffies - read a vector of integers as seconds
2810 * @table: the sysctl table
2811 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 * @buffer: the user buffer
2813 * @lenp: the size of the user buffer
2814 * @ppos: file position
2815 *
2816 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2817 * values from/to the user buffer, treated as an ASCII string.
2818 * The values read are assumed to be in seconds, and are converted into
2819 * jiffies.
2820 *
2821 * Returns 0 on success.
2822 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002823int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 void __user *buffer, size_t *lenp, loff_t *ppos)
2825{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002826 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 do_proc_dointvec_jiffies_conv,NULL);
2828}
2829
2830/**
2831 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2832 * @table: the sysctl table
2833 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 * @buffer: the user buffer
2835 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002836 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 *
2838 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2839 * values from/to the user buffer, treated as an ASCII string.
2840 * The values read are assumed to be in 1/USER_HZ seconds, and
2841 * are converted into jiffies.
2842 *
2843 * Returns 0 on success.
2844 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002845int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 void __user *buffer, size_t *lenp, loff_t *ppos)
2847{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002848 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 do_proc_dointvec_userhz_jiffies_conv,NULL);
2850}
2851
2852/**
2853 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2854 * @table: the sysctl table
2855 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 * @buffer: the user buffer
2857 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002858 * @ppos: file position
2859 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 *
2861 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2862 * values from/to the user buffer, treated as an ASCII string.
2863 * The values read are assumed to be in 1/1000 seconds, and
2864 * are converted into jiffies.
2865 *
2866 * Returns 0 on success.
2867 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002868int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 void __user *buffer, size_t *lenp, loff_t *ppos)
2870{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002871 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 do_proc_dointvec_ms_jiffies_conv, NULL);
2873}
2874
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002875static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002876 void __user *buffer, size_t *lenp, loff_t *ppos)
2877{
2878 struct pid *new_pid;
2879 pid_t tmp;
2880 int r;
2881
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002882 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002883
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002884 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002885 lenp, ppos, NULL, NULL);
2886 if (r || !write)
2887 return r;
2888
2889 new_pid = find_get_pid(tmp);
2890 if (!new_pid)
2891 return -ESRCH;
2892
2893 put_pid(xchg(&cad_pid, new_pid));
2894 return 0;
2895}
2896
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897#else /* CONFIG_PROC_FS */
2898
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002899int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 void __user *buffer, size_t *lenp, loff_t *ppos)
2901{
2902 return -ENOSYS;
2903}
2904
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002905int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 void __user *buffer, size_t *lenp, loff_t *ppos)
2907{
2908 return -ENOSYS;
2909}
2910
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002911int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 void __user *buffer, size_t *lenp, loff_t *ppos)
2913{
2914 return -ENOSYS;
2915}
2916
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002917int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 void __user *buffer, size_t *lenp, loff_t *ppos)
2919{
2920 return -ENOSYS;
2921}
2922
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002923int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 void __user *buffer, size_t *lenp, loff_t *ppos)
2925{
2926 return -ENOSYS;
2927}
2928
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002929int proc_dointvec_ms_jiffies(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_doulongvec_minmax(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
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002941int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 void __user *buffer,
2943 size_t *lenp, loff_t *ppos)
2944{
2945 return -ENOSYS;
2946}
2947
2948
2949#endif /* CONFIG_PROC_FS */
2950
2951
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002952#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953/*
2954 * General sysctl support routines
2955 */
2956
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002957/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002958int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002959 void __user *oldval, size_t __user *oldlenp,
2960 void __user *newval, size_t newlen)
2961{
2962 size_t len;
2963
2964 /* Get out of I don't have a variable */
2965 if (!table->data || !table->maxlen)
2966 return -ENOTDIR;
2967
2968 if (oldval && oldlenp) {
2969 if (get_user(len, oldlenp))
2970 return -EFAULT;
2971 if (len) {
2972 if (len > table->maxlen)
2973 len = table->maxlen;
2974 if (copy_to_user(oldval, table->data, len))
2975 return -EFAULT;
2976 if (put_user(len, oldlenp))
2977 return -EFAULT;
2978 }
2979 }
2980
2981 if (newval && newlen) {
2982 if (newlen > table->maxlen)
2983 newlen = table->maxlen;
2984
2985 if (copy_from_user(table->data, newval, newlen))
2986 return -EFAULT;
2987 }
2988 return 1;
2989}
2990
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002992int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002994 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 if (!table->data || !table->maxlen)
2997 return -ENOTDIR;
2998
2999 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003000 size_t bufsize;
3001 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003003 if (bufsize) {
3004 size_t len = strlen(table->data), copied;
3005
3006 /* This shouldn't trigger for a well-formed sysctl */
3007 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003009
3010 /* Copy up to a max of bufsize-1 bytes of the string */
3011 copied = (len >= bufsize) ? bufsize - 1 : len;
3012
3013 if (copy_to_user(oldval, table->data, copied) ||
3014 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003016 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 return -EFAULT;
3018 }
3019 }
3020 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003021 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 if (len > table->maxlen)
3023 len = table->maxlen;
3024 if(copy_from_user(table->data, newval, len))
3025 return -EFAULT;
3026 if (len == table->maxlen)
3027 len--;
3028 ((char *) table->data)[len] = 0;
3029 }
Yi Yang82c9df82005-12-30 16:37:10 +08003030 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031}
3032
3033/*
3034 * This function makes sure that all of the integers in the vector
3035 * are between the minimum and maximum values given in the arrays
3036 * table->extra1 and table->extra2, respectively.
3037 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003038int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003040 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041{
3042
3043 if (newval && newlen) {
3044 int __user *vec = (int __user *) newval;
3045 int *min = (int *) table->extra1;
3046 int *max = (int *) table->extra2;
3047 size_t length;
3048 int i;
3049
3050 if (newlen % sizeof(int) != 0)
3051 return -EINVAL;
3052
3053 if (!table->extra1 && !table->extra2)
3054 return 0;
3055
3056 if (newlen > table->maxlen)
3057 newlen = table->maxlen;
3058 length = newlen / sizeof(int);
3059
3060 for (i = 0; i < length; i++) {
3061 int value;
3062 if (get_user(value, vec + i))
3063 return -EFAULT;
3064 if (min && value < min[i])
3065 return -EINVAL;
3066 if (max && value > max[i])
3067 return -EINVAL;
3068 }
3069 }
3070 return 0;
3071}
3072
3073/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003074int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003076 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003078 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003080
3081 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003083 if (olen) {
3084 int val;
3085
3086 if (olen < sizeof(int))
3087 return -EINVAL;
3088
3089 val = *(int *)(table->data) / HZ;
3090 if (put_user(val, (int __user *)oldval))
3091 return -EFAULT;
3092 if (put_user(sizeof(int), oldlenp))
3093 return -EFAULT;
3094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 }
3096 if (newval && newlen) {
3097 int new;
3098 if (newlen != sizeof(int))
3099 return -EINVAL;
3100 if (get_user(new, (int __user *)newval))
3101 return -EFAULT;
3102 *(int *)(table->data) = new*HZ;
3103 }
3104 return 1;
3105}
3106
3107/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003108int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003110 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003112 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003114
3115 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003117 if (olen) {
3118 int val;
3119
3120 if (olen < sizeof(int))
3121 return -EINVAL;
3122
3123 val = jiffies_to_msecs(*(int *)(table->data));
3124 if (put_user(val, (int __user *)oldval))
3125 return -EFAULT;
3126 if (put_user(sizeof(int), oldlenp))
3127 return -EFAULT;
3128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 }
3130 if (newval && newlen) {
3131 int new;
3132 if (newlen != sizeof(int))
3133 return -EINVAL;
3134 if (get_user(new, (int __user *)newval))
3135 return -EFAULT;
3136 *(int *)(table->data) = msecs_to_jiffies(new);
3137 }
3138 return 1;
3139}
3140
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003141
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003142
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003143#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144
3145
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003146SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003148 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003149 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003150
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003151 if (copy_from_user(&tmp, args, sizeof(tmp)))
3152 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003153
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003154 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003155
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003156 /* If no error reading the parameters then just -ENOSYS ... */
3157 if (!error)
3158 error = -ENOSYS;
3159
3160 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161}
3162
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003163int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003164 void __user *oldval, size_t __user *oldlenp,
3165 void __user *newval, size_t newlen)
3166{
3167 return -ENOSYS;
3168}
3169
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003170int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003172 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173{
3174 return -ENOSYS;
3175}
3176
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003177int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003179 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180{
3181 return -ENOSYS;
3182}
3183
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003184int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003186 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187{
3188 return -ENOSYS;
3189}
3190
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003191int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003193 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194{
3195 return -ENOSYS;
3196}
3197
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003198#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003200static int deprecated_sysctl_warning(struct __sysctl_args *args)
3201{
3202 static int msg_count;
3203 int name[CTL_MAXNAME];
3204 int i;
3205
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003206 /* Check args->nlen. */
3207 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3208 return -ENOTDIR;
3209
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003210 /* Read in the sysctl name for better debug message logging */
3211 for (i = 0; i < args->nlen; i++)
3212 if (get_user(name[i], args->name + i))
3213 return -EFAULT;
3214
3215 /* Ignore accesses to kernel.version */
3216 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3217 return 0;
3218
3219 if (msg_count < 5) {
3220 msg_count++;
3221 printk(KERN_INFO
3222 "warning: process `%s' used the deprecated sysctl "
3223 "system call with ", current->comm);
3224 for (i = 0; i < args->nlen; i++)
3225 printk("%d.", name[i]);
3226 printk("\n");
3227 }
3228 return 0;
3229}
3230
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231/*
3232 * No sense putting this after each symbol definition, twice,
3233 * exception granted :-)
3234 */
3235EXPORT_SYMBOL(proc_dointvec);
3236EXPORT_SYMBOL(proc_dointvec_jiffies);
3237EXPORT_SYMBOL(proc_dointvec_minmax);
3238EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3239EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3240EXPORT_SYMBOL(proc_dostring);
3241EXPORT_SYMBOL(proc_doulongvec_minmax);
3242EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3243EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003244EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245EXPORT_SYMBOL(sysctl_intvec);
3246EXPORT_SYMBOL(sysctl_jiffies);
3247EXPORT_SYMBOL(sysctl_ms_jiffies);
3248EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003249EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250EXPORT_SYMBOL(unregister_sysctl_table);