blob: d10406e5fdfe988ba6f5ea34bc13d2ab85f43950 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020029#include <linux/kmemcheck.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020039#include <linux/ratelimit.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070042#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/times.h>
44#include <linux/limits.h>
45#include <linux/dcache.h>
46#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070047#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080048#include <linux/nfs_fs.h>
49#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070050#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020051#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010052#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020053#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#include <asm/uaccess.h>
56#include <asm/processor.h>
57
Andi Kleen29cbc782006-09-30 01:47:55 +020058#ifdef CONFIG_X86
59#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010060#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010061#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020062#endif
63
Eric W. Biederman7058cb02007-10-18 03:05:58 -070064static int deprecated_sysctl_warning(struct __sysctl_args *args);
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#if defined(CONFIG_SYSCTL)
67
68/* External variables not in a header file. */
69extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070070extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int sysctl_overcommit_memory;
72extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070073extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070074extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080075extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070078extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070080extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern int pid_max;
82extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080084extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080085extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020086extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010087extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040088extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000089#ifndef CONFIG_MMU
90extern int sysctl_nr_trim_pages;
91#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070092#ifdef CONFIG_RCU_TORTURE_TEST
93extern int rcutorture_runnable;
94#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Jens Axboecb684b52009-09-15 21:53:11 +020095#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +020096extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +020097#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -0800100#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700101static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200102static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103#endif
104
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700105static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700106static int __maybe_unused one = 1;
107static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800108static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700109static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700110#ifdef CONFIG_PRINTK
111static int ten_thousand = 10000;
112#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700114/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
115static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
118static int maxolduid = 65535;
119static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800120static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122static int ngroups_max = NGROUPS_MAX;
123
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200124#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700126extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef CONFIG_CHR_DEV_SG
129extern int sg_big_buff;
130#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
David S. Miller72c57ed2008-09-11 23:29:54 -0700132#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700133#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
David S. Miller08714202008-11-16 23:49:24 -0800136#ifdef CONFIG_SPARC64
137extern int sysctl_tsb_ratio;
138#endif
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef __hppa__
141extern int pwrsw_enabled;
142extern int unaligned_enabled;
143#endif
144
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800145#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef CONFIG_MATHEMU
147extern int sysctl_ieee_emulation_warnings;
148#endif
149extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700150extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#ifdef CONFIG_BSD_PROCESS_ACCT
154extern int acct_parm[];
155#endif
156
Jes Sorensend2b176e2006-02-28 09:42:23 -0800157#ifdef CONFIG_IA64
158extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800159extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800160#endif
161
Ingo Molnar3fff4c42009-09-22 16:18:09 +0200162extern struct ratelimit_state printk_ratelimit_state;
163
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700164#ifdef CONFIG_RT_MUTEXES
165extern int max_lock_depth;
166#endif
167
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700168#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700169static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700171static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800172 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700173#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700174
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700175static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176static struct ctl_table_root sysctl_table_root;
177static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100178 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100179 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400180 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100181 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400182 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100183};
184static struct ctl_table_root sysctl_table_root = {
185 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400186 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100187};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700189static struct ctl_table kern_table[];
190static struct ctl_table vm_table[];
191static struct ctl_table fs_table[];
192static struct ctl_table debug_table[];
193static struct ctl_table dev_table[];
194extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700195#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700196extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400197#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800198#ifdef CONFIG_EPOLL
199extern struct ctl_table epoll_table[];
200#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
203int sysctl_legacy_va_layout;
204#endif
205
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700206extern int prove_locking;
207extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/* The default sysctl tables: */
210
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700211static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 {
213 .ctl_name = CTL_KERN,
214 .procname = "kernel",
215 .mode = 0555,
216 .child = kern_table,
217 },
218 {
219 .ctl_name = CTL_VM,
220 .procname = "vm",
221 .mode = 0555,
222 .child = vm_table,
223 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 .ctl_name = CTL_FS,
226 .procname = "fs",
227 .mode = 0555,
228 .child = fs_table,
229 },
230 {
231 .ctl_name = CTL_DEBUG,
232 .procname = "debug",
233 .mode = 0555,
234 .child = debug_table,
235 },
236 {
237 .ctl_name = CTL_DEV,
238 .procname = "dev",
239 .mode = 0555,
240 .child = dev_table,
241 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700242/*
243 * NOTE: do not add new entries to this table unless you have read
244 * Documentation/sysctl/ctl_unnumbered.txt
245 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 { .ctl_name = 0 }
247};
248
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100250static int min_sched_granularity_ns = 100000; /* 100 usecs */
251static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
252static int min_wakeup_granularity_ns; /* 0 usecs */
253static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100254static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
255static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Ingo Molnar77e54a12007-07-09 18:52:00 +0200256#endif
257
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700258static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200259 {
260 .ctl_name = CTL_UNNUMBERED,
261 .procname = "sched_child_runs_first",
262 .data = &sysctl_sched_child_runs_first,
263 .maxlen = sizeof(unsigned int),
264 .mode = 0644,
265 .proc_handler = &proc_dointvec,
266 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200267#ifdef CONFIG_SCHED_DEBUG
268 {
269 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100270 .procname = "sched_min_granularity_ns",
271 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200272 .maxlen = sizeof(unsigned int),
273 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100274 .proc_handler = &sched_nr_latency_handler,
275 .strategy = &sysctl_intvec,
276 .extra1 = &min_sched_granularity_ns,
277 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200278 },
279 {
280 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200281 .procname = "sched_latency_ns",
282 .data = &sysctl_sched_latency,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100285 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200286 .strategy = &sysctl_intvec,
287 .extra1 = &min_sched_granularity_ns,
288 .extra2 = &max_sched_granularity_ns,
289 },
290 {
291 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292 .procname = "sched_wakeup_granularity_ns",
293 .data = &sysctl_sched_wakeup_granularity,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec_minmax,
297 .strategy = &sysctl_intvec,
298 .extra1 = &min_wakeup_granularity_ns,
299 .extra2 = &max_wakeup_granularity_ns,
300 },
301 {
302 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200303 .procname = "sched_shares_ratelimit",
304 .data = &sysctl_sched_shares_ratelimit,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
307 .proc_handler = &proc_dointvec,
308 },
309 {
310 .ctl_name = CTL_UNNUMBERED,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100311 .procname = "sched_tunable_scaling",
312 .data = &sysctl_sched_tunable_scaling,
313 .maxlen = sizeof(enum sched_tunable_scaling),
314 .mode = 0644,
315 .proc_handler = &proc_dointvec_minmax,
316 .strategy = &sysctl_intvec,
317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
319 },
320
321 {
322 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200323 .procname = "sched_shares_thresh",
324 .data = &sysctl_sched_shares_thresh,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec_minmax,
328 .strategy = &sysctl_intvec,
329 .extra1 = &zero,
330 },
331 {
332 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarda84d962007-10-15 17:00:18 +0200333 .procname = "sched_migration_cost",
334 .data = &sysctl_sched_migration_cost,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
338 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100339 {
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_nr_migrate",
342 .data = &sysctl_sched_nr_migrate,
343 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100344 .mode = 0644,
345 .proc_handler = &proc_dointvec,
346 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530347 {
348 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200349 .procname = "sched_time_avg",
350 .data = &sysctl_sched_time_avg,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = &proc_dointvec,
354 },
355 {
356 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530357 .procname = "timer_migration",
358 .data = &sysctl_timer_migration,
359 .maxlen = sizeof(unsigned int),
360 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530361 .proc_handler = &proc_dointvec_minmax,
362 .strategy = &sysctl_intvec,
363 .extra1 = &zero,
364 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530365 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200366#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200367 {
368 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100369 .procname = "sched_rt_period_us",
370 .data = &sysctl_sched_rt_period,
371 .maxlen = sizeof(unsigned int),
372 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200373 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100374 },
375 {
376 .ctl_name = CTL_UNNUMBERED,
377 .procname = "sched_rt_runtime_us",
378 .data = &sysctl_sched_rt_runtime,
379 .maxlen = sizeof(int),
380 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200381 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100382 },
383 {
384 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200385 .procname = "sched_compat_yield",
386 .data = &sysctl_sched_compat_yield,
387 .maxlen = sizeof(unsigned int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700391#ifdef CONFIG_PROVE_LOCKING
392 {
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "prove_locking",
395 .data = &prove_locking,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
399 },
400#endif
401#ifdef CONFIG_LOCK_STAT
402 {
403 .ctl_name = CTL_UNNUMBERED,
404 .procname = "lock_stat",
405 .data = &lock_stat,
406 .maxlen = sizeof(int),
407 .mode = 0644,
408 .proc_handler = &proc_dointvec,
409 },
410#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200411 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .ctl_name = KERN_PANIC,
413 .procname = "panic",
414 .data = &panic_timeout,
415 .maxlen = sizeof(int),
416 .mode = 0644,
417 .proc_handler = &proc_dointvec,
418 },
419 {
420 .ctl_name = KERN_CORE_USES_PID,
421 .procname = "core_uses_pid",
422 .data = &core_uses_pid,
423 .maxlen = sizeof(int),
424 .mode = 0644,
425 .proc_handler = &proc_dointvec,
426 },
427 {
428 .ctl_name = KERN_CORE_PATTERN,
429 .procname = "core_pattern",
430 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700431 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 .mode = 0644,
433 .proc_handler = &proc_dostring,
434 .strategy = &sysctl_string,
435 },
Neil Hormana2939802009-09-23 15:56:56 -0700436 {
437 .ctl_name = CTL_UNNUMBERED,
438 .procname = "core_pipe_limit",
439 .data = &core_pipe_limit,
440 .maxlen = sizeof(unsigned int),
441 .mode = 0644,
442 .proc_handler = &proc_dointvec,
443 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800444#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700447 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800448 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700449 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800451#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100452#ifdef CONFIG_LATENCYTOP
453 {
454 .procname = "latencytop",
455 .data = &latencytop_enabled,
456 .maxlen = sizeof(int),
457 .mode = 0644,
458 .proc_handler = &proc_dointvec,
459 },
460#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#ifdef CONFIG_BLK_DEV_INITRD
462 {
463 .ctl_name = KERN_REALROOTDEV,
464 .procname = "real-root-dev",
465 .data = &real_root_dev,
466 .maxlen = sizeof(int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
469 },
470#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700471 {
472 .ctl_name = CTL_UNNUMBERED,
473 .procname = "print-fatal-signals",
474 .data = &print_fatal_signals,
475 .maxlen = sizeof(int),
476 .mode = 0644,
477 .proc_handler = &proc_dointvec,
478 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700479#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 {
481 .ctl_name = KERN_SPARC_REBOOT,
482 .procname = "reboot-cmd",
483 .data = reboot_command,
484 .maxlen = 256,
485 .mode = 0644,
486 .proc_handler = &proc_dostring,
487 .strategy = &sysctl_string,
488 },
489 {
490 .ctl_name = KERN_SPARC_STOP_A,
491 .procname = "stop-a",
492 .data = &stop_a_enabled,
493 .maxlen = sizeof (int),
494 .mode = 0644,
495 .proc_handler = &proc_dointvec,
496 },
497 {
498 .ctl_name = KERN_SPARC_SCONS_PWROFF,
499 .procname = "scons-poweroff",
500 .data = &scons_pwroff,
501 .maxlen = sizeof (int),
502 .mode = 0644,
503 .proc_handler = &proc_dointvec,
504 },
505#endif
David S. Miller08714202008-11-16 23:49:24 -0800506#ifdef CONFIG_SPARC64
507 {
508 .ctl_name = CTL_UNNUMBERED,
509 .procname = "tsb-ratio",
510 .data = &sysctl_tsb_ratio,
511 .maxlen = sizeof (int),
512 .mode = 0644,
513 .proc_handler = &proc_dointvec,
514 },
515#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516#ifdef __hppa__
517 {
518 .ctl_name = KERN_HPPA_PWRSW,
519 .procname = "soft-power",
520 .data = &pwrsw_enabled,
521 .maxlen = sizeof (int),
522 .mode = 0644,
523 .proc_handler = &proc_dointvec,
524 },
525 {
526 .ctl_name = KERN_HPPA_UNALIGNED,
527 .procname = "unaligned-trap",
528 .data = &unaligned_enabled,
529 .maxlen = sizeof (int),
530 .mode = 0644,
531 .proc_handler = &proc_dointvec,
532 },
533#endif
534 {
535 .ctl_name = KERN_CTLALTDEL,
536 .procname = "ctrl-alt-del",
537 .data = &C_A_D,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec,
541 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400542#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200543 {
544 .ctl_name = CTL_UNNUMBERED,
545 .procname = "ftrace_enabled",
546 .data = &ftrace_enabled,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = &ftrace_enable_sysctl,
550 },
551#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500552#ifdef CONFIG_STACK_TRACER
553 {
554 .ctl_name = CTL_UNNUMBERED,
555 .procname = "stack_tracer_enabled",
556 .data = &stack_tracer_enabled,
557 .maxlen = sizeof(int),
558 .mode = 0644,
559 .proc_handler = &stack_trace_sysctl,
560 },
561#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400562#ifdef CONFIG_TRACING
563 {
564 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100565 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400566 .data = &ftrace_dump_on_oops,
567 .maxlen = sizeof(int),
568 .mode = 0644,
569 .proc_handler = &proc_dointvec,
570 },
571#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200572#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 {
574 .ctl_name = KERN_MODPROBE,
575 .procname = "modprobe",
576 .data = &modprobe_path,
577 .maxlen = KMOD_PATH_LEN,
578 .mode = 0644,
579 .proc_handler = &proc_dostring,
580 .strategy = &sysctl_string,
581 },
Kees Cook3d433212009-04-02 15:49:29 -0700582 {
583 .ctl_name = CTL_UNNUMBERED,
584 .procname = "modules_disabled",
585 .data = &modules_disabled,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 /* only handle a transition from default "0" to "1" */
589 .proc_handler = &proc_dointvec_minmax,
590 .extra1 = &one,
591 .extra2 = &one,
592 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700594#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 {
596 .ctl_name = KERN_HOTPLUG,
597 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100598 .data = &uevent_helper,
599 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .mode = 0644,
601 .proc_handler = &proc_dostring,
602 .strategy = &sysctl_string,
603 },
604#endif
605#ifdef CONFIG_CHR_DEV_SG
606 {
607 .ctl_name = KERN_SG_BIG_BUFF,
608 .procname = "sg-big-buff",
609 .data = &sg_big_buff,
610 .maxlen = sizeof (int),
611 .mode = 0444,
612 .proc_handler = &proc_dointvec,
613 },
614#endif
615#ifdef CONFIG_BSD_PROCESS_ACCT
616 {
617 .ctl_name = KERN_ACCT,
618 .procname = "acct",
619 .data = &acct_parm,
620 .maxlen = 3*sizeof(int),
621 .mode = 0644,
622 .proc_handler = &proc_dointvec,
623 },
624#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#ifdef CONFIG_MAGIC_SYSRQ
626 {
627 .ctl_name = KERN_SYSRQ,
628 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800629 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 .maxlen = sizeof (int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec,
633 },
634#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700635#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700638 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 .maxlen = sizeof (int),
640 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700641 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700643#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 {
645 .ctl_name = KERN_MAX_THREADS,
646 .procname = "threads-max",
647 .data = &max_threads,
648 .maxlen = sizeof(int),
649 .mode = 0644,
650 .proc_handler = &proc_dointvec,
651 },
652 {
653 .ctl_name = KERN_RANDOM,
654 .procname = "random",
655 .mode = 0555,
656 .child = random_table,
657 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 {
659 .ctl_name = KERN_OVERFLOWUID,
660 .procname = "overflowuid",
661 .data = &overflowuid,
662 .maxlen = sizeof(int),
663 .mode = 0644,
664 .proc_handler = &proc_dointvec_minmax,
665 .strategy = &sysctl_intvec,
666 .extra1 = &minolduid,
667 .extra2 = &maxolduid,
668 },
669 {
670 .ctl_name = KERN_OVERFLOWGID,
671 .procname = "overflowgid",
672 .data = &overflowgid,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = &proc_dointvec_minmax,
676 .strategy = &sysctl_intvec,
677 .extra1 = &minolduid,
678 .extra2 = &maxolduid,
679 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800680#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#ifdef CONFIG_MATHEMU
682 {
683 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
684 .procname = "ieee_emulation_warnings",
685 .data = &sysctl_ieee_emulation_warnings,
686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec,
689 },
690#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 {
692 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
693 .procname = "userprocess_debug",
694 .data = &sysctl_userprocess_debug,
695 .maxlen = sizeof(int),
696 .mode = 0644,
697 .proc_handler = &proc_dointvec,
698 },
699#endif
700 {
701 .ctl_name = KERN_PIDMAX,
702 .procname = "pid_max",
703 .data = &pid_max,
704 .maxlen = sizeof (int),
705 .mode = 0644,
706 .proc_handler = &proc_dointvec_minmax,
707 .strategy = sysctl_intvec,
708 .extra1 = &pid_max_min,
709 .extra2 = &pid_max_max,
710 },
711 {
712 .ctl_name = KERN_PANIC_ON_OOPS,
713 .procname = "panic_on_oops",
714 .data = &panic_on_oops,
715 .maxlen = sizeof(int),
716 .mode = 0644,
717 .proc_handler = &proc_dointvec,
718 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800719#if defined CONFIG_PRINTK
720 {
721 .ctl_name = KERN_PRINTK,
722 .procname = "printk",
723 .data = &console_loglevel,
724 .maxlen = 4*sizeof(int),
725 .mode = 0644,
726 .proc_handler = &proc_dointvec,
727 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 {
729 .ctl_name = KERN_PRINTK_RATELIMIT,
730 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700731 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .maxlen = sizeof(int),
733 .mode = 0644,
734 .proc_handler = &proc_dointvec_jiffies,
735 .strategy = &sysctl_jiffies,
736 },
737 {
738 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
739 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700740 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 .maxlen = sizeof(int),
742 .mode = 0644,
743 .proc_handler = &proc_dointvec,
744 },
Dave Youngaf913222009-09-22 16:43:33 -0700745 {
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "printk_delay",
748 .data = &printk_delay_msec,
749 .maxlen = sizeof(int),
750 .mode = 0644,
751 .proc_handler = &proc_dointvec_minmax,
752 .strategy = &sysctl_intvec,
753 .extra1 = &zero,
754 .extra2 = &ten_thousand,
755 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800756#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 {
758 .ctl_name = KERN_NGROUPS_MAX,
759 .procname = "ngroups_max",
760 .data = &ngroups_max,
761 .maxlen = sizeof (int),
762 .mode = 0444,
763 .proc_handler = &proc_dointvec,
764 },
765#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
766 {
767 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
768 .procname = "unknown_nmi_panic",
769 .data = &unknown_nmi_panic,
770 .maxlen = sizeof (int),
771 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200772 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 },
Don Zickus407984f2006-09-26 10:52:27 +0200774 {
Don Zickus407984f2006-09-26 10:52:27 +0200775 .procname = "nmi_watchdog",
776 .data = &nmi_watchdog_enabled,
777 .maxlen = sizeof (int),
778 .mode = 0644,
779 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 },
781#endif
782#if defined(CONFIG_X86)
783 {
Don Zickus8da5add2006-09-26 10:52:27 +0200784 .ctl_name = KERN_PANIC_ON_NMI,
785 .procname = "panic_on_unrecovered_nmi",
786 .data = &panic_on_unrecovered_nmi,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = &proc_dointvec,
790 },
791 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700792 .ctl_name = CTL_UNNUMBERED,
793 .procname = "panic_on_io_nmi",
794 .data = &panic_on_io_nmi,
795 .maxlen = sizeof(int),
796 .mode = 0644,
797 .proc_handler = &proc_dointvec,
798 },
799 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 .ctl_name = KERN_BOOTLOADER_TYPE,
801 .procname = "bootloader_type",
802 .data = &bootloader_type,
803 .maxlen = sizeof (int),
804 .mode = 0444,
805 .proc_handler = &proc_dointvec,
806 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100807 {
808 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700809 .procname = "bootloader_version",
810 .data = &bootloader_version,
811 .maxlen = sizeof (int),
812 .mode = 0444,
813 .proc_handler = &proc_dointvec,
814 },
815 {
816 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100817 .procname = "kstack_depth_to_print",
818 .data = &kstack_depth_to_print,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = &proc_dointvec,
822 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100823 {
824 .ctl_name = CTL_UNNUMBERED,
825 .procname = "io_delay_type",
826 .data = &io_delay_type,
827 .maxlen = sizeof(int),
828 .mode = 0644,
829 .proc_handler = &proc_dointvec,
830 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800832#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 {
834 .ctl_name = KERN_RANDOMIZE,
835 .procname = "randomize_va_space",
836 .data = &randomize_va_space,
837 .maxlen = sizeof(int),
838 .mode = 0644,
839 .proc_handler = &proc_dointvec,
840 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800841#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800842#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700843 {
844 .ctl_name = KERN_SPIN_RETRY,
845 .procname = "spin_retry",
846 .data = &spin_retry,
847 .maxlen = sizeof (int),
848 .mode = 0644,
849 .proc_handler = &proc_dointvec,
850 },
851#endif
Len Brown673d5b42007-07-28 03:33:16 -0400852#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800853 {
Pavel Machekc255d842006-02-20 18:27:58 -0800854 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700855 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800856 .maxlen = sizeof (unsigned long),
857 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800858 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800859 },
860#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800861#ifdef CONFIG_IA64
862 {
863 .ctl_name = KERN_IA64_UNALIGNED,
864 .procname = "ignore-unaligned-usertrap",
865 .data = &no_unaligned_warning,
866 .maxlen = sizeof (int),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec,
869 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800870 {
871 .ctl_name = CTL_UNNUMBERED,
872 .procname = "unaligned-dump-stack",
873 .data = &unaligned_dump_stack,
874 .maxlen = sizeof (int),
875 .mode = 0644,
876 .proc_handler = &proc_dointvec,
877 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800878#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700879#ifdef CONFIG_DETECT_SOFTLOCKUP
880 {
881 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200882 .procname = "softlockup_panic",
883 .data = &softlockup_panic,
884 .maxlen = sizeof(int),
885 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700886 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200887 .strategy = &sysctl_intvec,
888 .extra1 = &zero,
889 .extra2 = &one,
890 },
891 {
892 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700893 .procname = "softlockup_thresh",
894 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200895 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700896 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800897 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700898 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200899 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700900 .extra2 = &sixty,
901 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800902#endif
903#ifdef CONFIG_DETECT_HUNG_TASK
904 {
905 .ctl_name = CTL_UNNUMBERED,
906 .procname = "hung_task_panic",
907 .data = &sysctl_hung_task_panic,
908 .maxlen = sizeof(int),
909 .mode = 0644,
910 .proc_handler = &proc_dointvec_minmax,
911 .strategy = &sysctl_intvec,
912 .extra1 = &zero,
913 .extra2 = &one,
914 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100915 {
916 .ctl_name = CTL_UNNUMBERED,
917 .procname = "hung_task_check_count",
918 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100919 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100920 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100921 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100922 .strategy = &sysctl_intvec,
923 },
924 {
925 .ctl_name = CTL_UNNUMBERED,
926 .procname = "hung_task_timeout_secs",
927 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100928 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100929 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800930 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100931 .strategy = &sysctl_intvec,
932 },
933 {
934 .ctl_name = CTL_UNNUMBERED,
935 .procname = "hung_task_warnings",
936 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100937 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100938 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100939 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100940 .strategy = &sysctl_intvec,
941 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700942#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200943#ifdef CONFIG_COMPAT
944 {
945 .ctl_name = KERN_COMPAT_LOG,
946 .procname = "compat-log",
947 .data = &compat_log,
948 .maxlen = sizeof (int),
949 .mode = 0644,
950 .proc_handler = &proc_dointvec,
951 },
952#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700953#ifdef CONFIG_RT_MUTEXES
954 {
955 .ctl_name = KERN_MAX_LOCK_DEPTH,
956 .procname = "max_lock_depth",
957 .data = &max_lock_depth,
958 .maxlen = sizeof(int),
959 .mode = 0644,
960 .proc_handler = &proc_dointvec,
961 },
962#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700963 {
964 .ctl_name = CTL_UNNUMBERED,
965 .procname = "poweroff_cmd",
966 .data = &poweroff_cmd,
967 .maxlen = POWEROFF_CMD_PATH_LEN,
968 .mode = 0644,
969 .proc_handler = &proc_dostring,
970 .strategy = &sysctl_string,
971 },
David Howells0b77f5b2008-04-29 01:01:32 -0700972#ifdef CONFIG_KEYS
973 {
974 .ctl_name = CTL_UNNUMBERED,
975 .procname = "keys",
976 .mode = 0555,
977 .child = key_sysctls,
978 },
979#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700980#ifdef CONFIG_RCU_TORTURE_TEST
981 {
982 .ctl_name = CTL_UNNUMBERED,
983 .procname = "rcutorture_runnable",
984 .data = &rcutorture_runnable,
985 .maxlen = sizeof(int),
986 .mode = 0644,
987 .proc_handler = &proc_dointvec,
988 },
989#endif
David Howells12e22c52009-04-03 16:42:35 +0100990#ifdef CONFIG_SLOW_WORK
991 {
992 .ctl_name = CTL_UNNUMBERED,
993 .procname = "slow-work",
994 .mode = 0555,
995 .child = slow_work_sysctls,
996 },
997#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200998#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200999 {
1000 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001001 .procname = "perf_event_paranoid",
1002 .data = &sysctl_perf_event_paranoid,
1003 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001004 .mode = 0644,
1005 .proc_handler = &proc_dointvec,
1006 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001007 {
1008 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001009 .procname = "perf_event_mlock_kb",
1010 .data = &sysctl_perf_event_mlock,
1011 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001012 .mode = 0644,
1013 .proc_handler = &proc_dointvec,
1014 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001015 {
1016 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001017 .procname = "perf_event_max_sample_rate",
1018 .data = &sysctl_perf_event_sample_rate,
1019 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001020 .mode = 0644,
1021 .proc_handler = &proc_dointvec,
1022 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001023#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001024#ifdef CONFIG_KMEMCHECK
1025 {
1026 .ctl_name = CTL_UNNUMBERED,
1027 .procname = "kmemcheck",
1028 .data = &kmemcheck_enabled,
1029 .maxlen = sizeof(int),
1030 .mode = 0644,
1031 .proc_handler = &proc_dointvec,
1032 },
1033#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001034#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001035 {
1036 .ctl_name = CTL_UNNUMBERED,
1037 .procname = "blk_iopoll",
1038 .data = &blk_iopoll_enabled,
1039 .maxlen = sizeof(int),
1040 .mode = 0644,
1041 .proc_handler = &proc_dointvec,
1042 },
Jens Axboecb684b52009-09-15 21:53:11 +02001043#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001044/*
1045 * NOTE: do not add new entries to this table unless you have read
1046 * Documentation/sysctl/ctl_unnumbered.txt
1047 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 { .ctl_name = 0 }
1049};
1050
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001051static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 {
1053 .ctl_name = VM_OVERCOMMIT_MEMORY,
1054 .procname = "overcommit_memory",
1055 .data = &sysctl_overcommit_memory,
1056 .maxlen = sizeof(sysctl_overcommit_memory),
1057 .mode = 0644,
1058 .proc_handler = &proc_dointvec,
1059 },
1060 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001061 .ctl_name = VM_PANIC_ON_OOM,
1062 .procname = "panic_on_oom",
1063 .data = &sysctl_panic_on_oom,
1064 .maxlen = sizeof(sysctl_panic_on_oom),
1065 .mode = 0644,
1066 .proc_handler = &proc_dointvec,
1067 },
1068 {
David Rientjesfe071d72007-10-16 23:25:56 -07001069 .ctl_name = CTL_UNNUMBERED,
1070 .procname = "oom_kill_allocating_task",
1071 .data = &sysctl_oom_kill_allocating_task,
1072 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1073 .mode = 0644,
1074 .proc_handler = &proc_dointvec,
1075 },
1076 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001077 .ctl_name = CTL_UNNUMBERED,
1078 .procname = "oom_dump_tasks",
1079 .data = &sysctl_oom_dump_tasks,
1080 .maxlen = sizeof(sysctl_oom_dump_tasks),
1081 .mode = 0644,
1082 .proc_handler = &proc_dointvec,
1083 },
1084 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 .ctl_name = VM_OVERCOMMIT_RATIO,
1086 .procname = "overcommit_ratio",
1087 .data = &sysctl_overcommit_ratio,
1088 .maxlen = sizeof(sysctl_overcommit_ratio),
1089 .mode = 0644,
1090 .proc_handler = &proc_dointvec,
1091 },
1092 {
1093 .ctl_name = VM_PAGE_CLUSTER,
1094 .procname = "page-cluster",
1095 .data = &page_cluster,
1096 .maxlen = sizeof(int),
1097 .mode = 0644,
1098 .proc_handler = &proc_dointvec,
1099 },
1100 {
1101 .ctl_name = VM_DIRTY_BACKGROUND,
1102 .procname = "dirty_background_ratio",
1103 .data = &dirty_background_ratio,
1104 .maxlen = sizeof(dirty_background_ratio),
1105 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001106 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 .strategy = &sysctl_intvec,
1108 .extra1 = &zero,
1109 .extra2 = &one_hundred,
1110 },
1111 {
David Rientjes2da02992009-01-06 14:39:31 -08001112 .ctl_name = CTL_UNNUMBERED,
1113 .procname = "dirty_background_bytes",
1114 .data = &dirty_background_bytes,
1115 .maxlen = sizeof(dirty_background_bytes),
1116 .mode = 0644,
1117 .proc_handler = &dirty_background_bytes_handler,
1118 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001119 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001120 },
1121 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 .ctl_name = VM_DIRTY_RATIO,
1123 .procname = "dirty_ratio",
1124 .data = &vm_dirty_ratio,
1125 .maxlen = sizeof(vm_dirty_ratio),
1126 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001127 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 .strategy = &sysctl_intvec,
1129 .extra1 = &zero,
1130 .extra2 = &one_hundred,
1131 },
1132 {
David Rientjes2da02992009-01-06 14:39:31 -08001133 .ctl_name = CTL_UNNUMBERED,
1134 .procname = "dirty_bytes",
1135 .data = &vm_dirty_bytes,
1136 .maxlen = sizeof(vm_dirty_bytes),
1137 .mode = 0644,
1138 .proc_handler = &dirty_bytes_handler,
1139 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001140 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001141 },
1142 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001144 .data = &dirty_writeback_interval,
1145 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 .mode = 0644,
1147 .proc_handler = &dirty_writeback_centisecs_handler,
1148 },
1149 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001151 .data = &dirty_expire_interval,
1152 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001154 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 },
1156 {
1157 .ctl_name = VM_NR_PDFLUSH_THREADS,
1158 .procname = "nr_pdflush_threads",
1159 .data = &nr_pdflush_threads,
1160 .maxlen = sizeof nr_pdflush_threads,
1161 .mode = 0444 /* read-only*/,
1162 .proc_handler = &proc_dointvec,
1163 },
1164 {
1165 .ctl_name = VM_SWAPPINESS,
1166 .procname = "swappiness",
1167 .data = &vm_swappiness,
1168 .maxlen = sizeof(vm_swappiness),
1169 .mode = 0644,
1170 .proc_handler = &proc_dointvec_minmax,
1171 .strategy = &sysctl_intvec,
1172 .extra1 = &zero,
1173 .extra2 = &one_hundred,
1174 },
1175#ifdef CONFIG_HUGETLB_PAGE
1176 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001178 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 .maxlen = sizeof(unsigned long),
1180 .mode = 0644,
1181 .proc_handler = &hugetlb_sysctl_handler,
1182 .extra1 = (void *)&hugetlb_zero,
1183 .extra2 = (void *)&hugetlb_infinity,
1184 },
1185 {
1186 .ctl_name = VM_HUGETLB_GROUP,
1187 .procname = "hugetlb_shm_group",
1188 .data = &sysctl_hugetlb_shm_group,
1189 .maxlen = sizeof(gid_t),
1190 .mode = 0644,
1191 .proc_handler = &proc_dointvec,
1192 },
Mel Gorman396faf02007-07-17 04:03:13 -07001193 {
1194 .ctl_name = CTL_UNNUMBERED,
1195 .procname = "hugepages_treat_as_movable",
1196 .data = &hugepages_treat_as_movable,
1197 .maxlen = sizeof(int),
1198 .mode = 0644,
1199 .proc_handler = &hugetlb_treat_movable_handler,
1200 },
Adam Litke54f9f802007-10-16 01:26:20 -07001201 {
1202 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001203 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001204 .data = NULL,
1205 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001206 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001207 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001208 .extra1 = (void *)&hugetlb_zero,
1209 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001210 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211#endif
1212 {
1213 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1214 .procname = "lowmem_reserve_ratio",
1215 .data = &sysctl_lowmem_reserve_ratio,
1216 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1217 .mode = 0644,
1218 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1219 .strategy = &sysctl_intvec,
1220 },
1221 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001222 .ctl_name = VM_DROP_PAGECACHE,
1223 .procname = "drop_caches",
1224 .data = &sysctl_drop_caches,
1225 .maxlen = sizeof(int),
1226 .mode = 0644,
1227 .proc_handler = drop_caches_sysctl_handler,
1228 .strategy = &sysctl_intvec,
1229 },
1230 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 .ctl_name = VM_MIN_FREE_KBYTES,
1232 .procname = "min_free_kbytes",
1233 .data = &min_free_kbytes,
1234 .maxlen = sizeof(min_free_kbytes),
1235 .mode = 0644,
1236 .proc_handler = &min_free_kbytes_sysctl_handler,
1237 .strategy = &sysctl_intvec,
1238 .extra1 = &zero,
1239 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001240 {
1241 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1242 .procname = "percpu_pagelist_fraction",
1243 .data = &percpu_pagelist_fraction,
1244 .maxlen = sizeof(percpu_pagelist_fraction),
1245 .mode = 0644,
1246 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1247 .strategy = &sysctl_intvec,
1248 .extra1 = &min_percpu_pagelist_fract,
1249 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250#ifdef CONFIG_MMU
1251 {
1252 .ctl_name = VM_MAX_MAP_COUNT,
1253 .procname = "max_map_count",
1254 .data = &sysctl_max_map_count,
1255 .maxlen = sizeof(sysctl_max_map_count),
1256 .mode = 0644,
1257 .proc_handler = &proc_dointvec
1258 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001259#else
1260 {
1261 .ctl_name = CTL_UNNUMBERED,
1262 .procname = "nr_trim_pages",
1263 .data = &sysctl_nr_trim_pages,
1264 .maxlen = sizeof(sysctl_nr_trim_pages),
1265 .mode = 0644,
1266 .proc_handler = &proc_dointvec_minmax,
1267 .strategy = &sysctl_intvec,
1268 .extra1 = &zero,
1269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270#endif
1271 {
1272 .ctl_name = VM_LAPTOP_MODE,
1273 .procname = "laptop_mode",
1274 .data = &laptop_mode,
1275 .maxlen = sizeof(laptop_mode),
1276 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001277 .proc_handler = &proc_dointvec_jiffies,
1278 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 },
1280 {
1281 .ctl_name = VM_BLOCK_DUMP,
1282 .procname = "block_dump",
1283 .data = &block_dump,
1284 .maxlen = sizeof(block_dump),
1285 .mode = 0644,
1286 .proc_handler = &proc_dointvec,
1287 .strategy = &sysctl_intvec,
1288 .extra1 = &zero,
1289 },
1290 {
1291 .ctl_name = VM_VFS_CACHE_PRESSURE,
1292 .procname = "vfs_cache_pressure",
1293 .data = &sysctl_vfs_cache_pressure,
1294 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1295 .mode = 0644,
1296 .proc_handler = &proc_dointvec,
1297 .strategy = &sysctl_intvec,
1298 .extra1 = &zero,
1299 },
1300#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1301 {
1302 .ctl_name = VM_LEGACY_VA_LAYOUT,
1303 .procname = "legacy_va_layout",
1304 .data = &sysctl_legacy_va_layout,
1305 .maxlen = sizeof(sysctl_legacy_va_layout),
1306 .mode = 0644,
1307 .proc_handler = &proc_dointvec,
1308 .strategy = &sysctl_intvec,
1309 .extra1 = &zero,
1310 },
1311#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001312#ifdef CONFIG_NUMA
1313 {
1314 .ctl_name = VM_ZONE_RECLAIM_MODE,
1315 .procname = "zone_reclaim_mode",
1316 .data = &zone_reclaim_mode,
1317 .maxlen = sizeof(zone_reclaim_mode),
1318 .mode = 0644,
1319 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001320 .strategy = &sysctl_intvec,
1321 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001322 },
Christoph Lameter96146342006-07-03 00:24:13 -07001323 {
1324 .ctl_name = VM_MIN_UNMAPPED,
1325 .procname = "min_unmapped_ratio",
1326 .data = &sysctl_min_unmapped_ratio,
1327 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1328 .mode = 0644,
1329 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1330 .strategy = &sysctl_intvec,
1331 .extra1 = &zero,
1332 .extra2 = &one_hundred,
1333 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001334 {
1335 .ctl_name = VM_MIN_SLAB,
1336 .procname = "min_slab_ratio",
1337 .data = &sysctl_min_slab_ratio,
1338 .maxlen = sizeof(sysctl_min_slab_ratio),
1339 .mode = 0644,
1340 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1341 .strategy = &sysctl_intvec,
1342 .extra1 = &zero,
1343 .extra2 = &one_hundred,
1344 },
Christoph Lameter17436602006-01-18 17:42:32 -08001345#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001346#ifdef CONFIG_SMP
1347 {
1348 .ctl_name = CTL_UNNUMBERED,
1349 .procname = "stat_interval",
1350 .data = &sysctl_stat_interval,
1351 .maxlen = sizeof(sysctl_stat_interval),
1352 .mode = 0644,
1353 .proc_handler = &proc_dointvec_jiffies,
1354 .strategy = &sysctl_jiffies,
1355 },
1356#endif
Eric Parised032182007-06-28 15:55:21 -04001357 {
1358 .ctl_name = CTL_UNNUMBERED,
1359 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001360 .data = &dac_mmap_min_addr,
1361 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001362 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001363 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001364 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001365#ifdef CONFIG_NUMA
1366 {
1367 .ctl_name = CTL_UNNUMBERED,
1368 .procname = "numa_zonelist_order",
1369 .data = &numa_zonelist_order,
1370 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1371 .mode = 0644,
1372 .proc_handler = &numa_zonelist_order_handler,
1373 .strategy = &sysctl_string,
1374 },
1375#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001376#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001377 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001378 {
1379 .ctl_name = VM_VDSO_ENABLED,
1380 .procname = "vdso_enabled",
1381 .data = &vdso_enabled,
1382 .maxlen = sizeof(vdso_enabled),
1383 .mode = 0644,
1384 .proc_handler = &proc_dointvec,
1385 .strategy = &sysctl_intvec,
1386 .extra1 = &zero,
1387 },
1388#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001389#ifdef CONFIG_HIGHMEM
1390 {
1391 .ctl_name = CTL_UNNUMBERED,
1392 .procname = "highmem_is_dirtyable",
1393 .data = &vm_highmem_is_dirtyable,
1394 .maxlen = sizeof(vm_highmem_is_dirtyable),
1395 .mode = 0644,
1396 .proc_handler = &proc_dointvec_minmax,
1397 .strategy = &sysctl_intvec,
1398 .extra1 = &zero,
1399 .extra2 = &one,
1400 },
1401#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001402 {
1403 .ctl_name = CTL_UNNUMBERED,
1404 .procname = "scan_unevictable_pages",
1405 .data = &scan_unevictable_pages,
1406 .maxlen = sizeof(scan_unevictable_pages),
1407 .mode = 0644,
1408 .proc_handler = &scan_unevictable_handler,
1409 },
Andi Kleen6a460792009-09-16 11:50:15 +02001410#ifdef CONFIG_MEMORY_FAILURE
1411 {
1412 .ctl_name = CTL_UNNUMBERED,
1413 .procname = "memory_failure_early_kill",
1414 .data = &sysctl_memory_failure_early_kill,
1415 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1416 .mode = 0644,
1417 .proc_handler = &proc_dointvec_minmax,
1418 .strategy = &sysctl_intvec,
1419 .extra1 = &zero,
1420 .extra2 = &one,
1421 },
1422 {
1423 .ctl_name = CTL_UNNUMBERED,
1424 .procname = "memory_failure_recovery",
1425 .data = &sysctl_memory_failure_recovery,
1426 .maxlen = sizeof(sysctl_memory_failure_recovery),
1427 .mode = 0644,
1428 .proc_handler = &proc_dointvec_minmax,
1429 .strategy = &sysctl_intvec,
1430 .extra1 = &zero,
1431 .extra2 = &one,
1432 },
1433#endif
1434
Andrew Morton2be7fe02007-07-15 23:41:21 -07001435/*
1436 * NOTE: do not add new entries to this table unless you have read
1437 * Documentation/sysctl/ctl_unnumbered.txt
1438 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 { .ctl_name = 0 }
1440};
1441
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001442#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001443static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001444 { .ctl_name = 0 }
1445};
1446#endif
1447
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001448static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 {
1450 .ctl_name = FS_NRINODE,
1451 .procname = "inode-nr",
1452 .data = &inodes_stat,
1453 .maxlen = 2*sizeof(int),
1454 .mode = 0444,
1455 .proc_handler = &proc_dointvec,
1456 },
1457 {
1458 .ctl_name = FS_STATINODE,
1459 .procname = "inode-state",
1460 .data = &inodes_stat,
1461 .maxlen = 7*sizeof(int),
1462 .mode = 0444,
1463 .proc_handler = &proc_dointvec,
1464 },
1465 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 .procname = "file-nr",
1467 .data = &files_stat,
1468 .maxlen = 3*sizeof(int),
1469 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001470 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 },
1472 {
1473 .ctl_name = FS_MAXFILE,
1474 .procname = "file-max",
1475 .data = &files_stat.max_files,
1476 .maxlen = sizeof(int),
1477 .mode = 0644,
1478 .proc_handler = &proc_dointvec,
1479 },
1480 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001481 .ctl_name = CTL_UNNUMBERED,
1482 .procname = "nr_open",
1483 .data = &sysctl_nr_open,
1484 .maxlen = sizeof(int),
1485 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001486 .proc_handler = &proc_dointvec_minmax,
1487 .extra1 = &sysctl_nr_open_min,
1488 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001489 },
1490 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 .ctl_name = FS_DENTRY,
1492 .procname = "dentry-state",
1493 .data = &dentry_stat,
1494 .maxlen = 6*sizeof(int),
1495 .mode = 0444,
1496 .proc_handler = &proc_dointvec,
1497 },
1498 {
1499 .ctl_name = FS_OVERFLOWUID,
1500 .procname = "overflowuid",
1501 .data = &fs_overflowuid,
1502 .maxlen = sizeof(int),
1503 .mode = 0644,
1504 .proc_handler = &proc_dointvec_minmax,
1505 .strategy = &sysctl_intvec,
1506 .extra1 = &minolduid,
1507 .extra2 = &maxolduid,
1508 },
1509 {
1510 .ctl_name = FS_OVERFLOWGID,
1511 .procname = "overflowgid",
1512 .data = &fs_overflowgid,
1513 .maxlen = sizeof(int),
1514 .mode = 0644,
1515 .proc_handler = &proc_dointvec_minmax,
1516 .strategy = &sysctl_intvec,
1517 .extra1 = &minolduid,
1518 .extra2 = &maxolduid,
1519 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001520#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 {
1522 .ctl_name = FS_LEASES,
1523 .procname = "leases-enable",
1524 .data = &leases_enable,
1525 .maxlen = sizeof(int),
1526 .mode = 0644,
1527 .proc_handler = &proc_dointvec,
1528 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001529#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530#ifdef CONFIG_DNOTIFY
1531 {
1532 .ctl_name = FS_DIR_NOTIFY,
1533 .procname = "dir-notify-enable",
1534 .data = &dir_notify_enable,
1535 .maxlen = sizeof(int),
1536 .mode = 0644,
1537 .proc_handler = &proc_dointvec,
1538 },
1539#endif
1540#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001541#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 {
1543 .ctl_name = FS_LEASE_TIME,
1544 .procname = "lease-break-time",
1545 .data = &lease_break_time,
1546 .maxlen = sizeof(int),
1547 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001548 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001550#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001551#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 .procname = "aio-nr",
1554 .data = &aio_nr,
1555 .maxlen = sizeof(aio_nr),
1556 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001557 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 },
1559 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 .procname = "aio-max-nr",
1561 .data = &aio_max_nr,
1562 .maxlen = sizeof(aio_max_nr),
1563 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001564 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001566#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001567#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001568 {
1569 .ctl_name = FS_INOTIFY,
1570 .procname = "inotify",
1571 .mode = 0555,
1572 .child = inotify_table,
1573 },
1574#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001575#ifdef CONFIG_EPOLL
1576 {
1577 .procname = "epoll",
1578 .mode = 0555,
1579 .child = epoll_table,
1580 },
1581#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001583 {
1584 .ctl_name = KERN_SETUID_DUMPABLE,
1585 .procname = "suid_dumpable",
1586 .data = &suid_dumpable,
1587 .maxlen = sizeof(int),
1588 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001589 .proc_handler = &proc_dointvec_minmax,
1590 .strategy = &sysctl_intvec,
1591 .extra1 = &zero,
1592 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001593 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001594#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1595 {
1596 .ctl_name = CTL_UNNUMBERED,
1597 .procname = "binfmt_misc",
1598 .mode = 0555,
1599 .child = binfmt_misc_table,
1600 },
1601#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001602/*
1603 * NOTE: do not add new entries to this table unless you have read
1604 * Documentation/sysctl/ctl_unnumbered.txt
1605 */
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 debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001610#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001611 {
1612 .ctl_name = CTL_UNNUMBERED,
1613 .procname = "exception-trace",
1614 .data = &show_unhandled_signals,
1615 .maxlen = sizeof(int),
1616 .mode = 0644,
1617 .proc_handler = proc_dointvec
1618 },
1619#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 { .ctl_name = 0 }
1621};
1622
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001623static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001625};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Al Viro330d57f2005-11-04 10:18:40 +00001627static DEFINE_SPINLOCK(sysctl_lock);
1628
1629/* called under sysctl_lock */
1630static int use_table(struct ctl_table_header *p)
1631{
1632 if (unlikely(p->unregistering))
1633 return 0;
1634 p->used++;
1635 return 1;
1636}
1637
1638/* called under sysctl_lock */
1639static void unuse_table(struct ctl_table_header *p)
1640{
1641 if (!--p->used)
1642 if (unlikely(p->unregistering))
1643 complete(p->unregistering);
1644}
1645
1646/* called under sysctl_lock, will reacquire if has to wait */
1647static void start_unregistering(struct ctl_table_header *p)
1648{
1649 /*
1650 * if p->used is 0, nobody will ever touch that entry again;
1651 * we'll eliminate all paths to it before dropping sysctl_lock
1652 */
1653 if (unlikely(p->used)) {
1654 struct completion wait;
1655 init_completion(&wait);
1656 p->unregistering = &wait;
1657 spin_unlock(&sysctl_lock);
1658 wait_for_completion(&wait);
1659 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001660 } else {
1661 /* anything non-NULL; we'll never dereference it */
1662 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001663 }
1664 /*
1665 * do not remove from the list until nobody holds it; walking the
1666 * list in do_sysctl() relies on that.
1667 */
1668 list_del_init(&p->ctl_entry);
1669}
1670
Al Virof7e6ced2008-07-15 01:44:23 -04001671void sysctl_head_get(struct ctl_table_header *head)
1672{
1673 spin_lock(&sysctl_lock);
1674 head->count++;
1675 spin_unlock(&sysctl_lock);
1676}
1677
1678void sysctl_head_put(struct ctl_table_header *head)
1679{
1680 spin_lock(&sysctl_lock);
1681 if (!--head->count)
1682 kfree(head);
1683 spin_unlock(&sysctl_lock);
1684}
1685
1686struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1687{
1688 if (!head)
1689 BUG();
1690 spin_lock(&sysctl_lock);
1691 if (!use_table(head))
1692 head = ERR_PTR(-ENOENT);
1693 spin_unlock(&sysctl_lock);
1694 return head;
1695}
1696
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001697void sysctl_head_finish(struct ctl_table_header *head)
1698{
1699 if (!head)
1700 return;
1701 spin_lock(&sysctl_lock);
1702 unuse_table(head);
1703 spin_unlock(&sysctl_lock);
1704}
1705
Al Viro73455092008-07-14 21:22:20 -04001706static struct ctl_table_set *
1707lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1708{
1709 struct ctl_table_set *set = &root->default_set;
1710 if (root->lookup)
1711 set = root->lookup(root, namespaces);
1712 return set;
1713}
1714
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001715static struct list_head *
1716lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001717{
Al Viro73455092008-07-14 21:22:20 -04001718 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1719 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001720}
1721
1722struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1723 struct ctl_table_header *prev)
1724{
1725 struct ctl_table_root *root;
1726 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001727 struct ctl_table_header *head;
1728 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001729
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001730 spin_lock(&sysctl_lock);
1731 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001732 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001733 tmp = &prev->ctl_entry;
1734 unuse_table(prev);
1735 goto next;
1736 }
1737 tmp = &root_table_header.ctl_entry;
1738 for (;;) {
1739 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1740
1741 if (!use_table(head))
1742 goto next;
1743 spin_unlock(&sysctl_lock);
1744 return head;
1745 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001746 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001747 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001748 header_list = lookup_header_list(root, namespaces);
1749 if (tmp != header_list)
1750 continue;
1751
1752 do {
1753 root = list_entry(root->root_list.next,
1754 struct ctl_table_root, root_list);
1755 if (root == &sysctl_table_root)
1756 goto out;
1757 header_list = lookup_header_list(root, namespaces);
1758 } while (list_empty(header_list));
1759 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001760 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001761out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001762 spin_unlock(&sysctl_lock);
1763 return NULL;
1764}
1765
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001766struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1767{
1768 return __sysctl_head_next(current->nsproxy, prev);
1769}
1770
1771void register_sysctl_root(struct ctl_table_root *root)
1772{
1773 spin_lock(&sysctl_lock);
1774 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1775 spin_unlock(&sysctl_lock);
1776}
1777
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001778#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001779/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001780static int do_sysctl_strategy(struct ctl_table_root *root,
1781 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001782 void __user *oldval, size_t __user *oldlenp,
1783 void __user *newval, size_t newlen)
1784{
1785 int op = 0, rc;
1786
1787 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001788 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001789 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001790 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001791 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001792 return -EPERM;
1793
1794 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001795 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001796 if (rc < 0)
1797 return rc;
1798 if (rc > 0)
1799 return 0;
1800 }
1801
1802 /* If there is no strategy routine, or if the strategy returns
1803 * zero, proceed with automatic r/w */
1804 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001805 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001806 if (rc < 0)
1807 return rc;
1808 }
1809 return 0;
1810}
1811
1812static int parse_table(int __user *name, int nlen,
1813 void __user *oldval, size_t __user *oldlenp,
1814 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001815 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001816 struct ctl_table *table)
1817{
1818 int n;
1819repeat:
1820 if (!nlen)
1821 return -ENOTDIR;
1822 if (get_user(n, name))
1823 return -EFAULT;
1824 for ( ; table->ctl_name || table->procname; table++) {
1825 if (!table->ctl_name)
1826 continue;
1827 if (n == table->ctl_name) {
1828 int error;
1829 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001830 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001831 return -EPERM;
1832 name++;
1833 nlen--;
1834 table = table->child;
1835 goto repeat;
1836 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001837 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001838 oldval, oldlenp,
1839 newval, newlen);
1840 return error;
1841 }
1842 }
1843 return -ENOTDIR;
1844}
1845
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1847 void __user *newval, size_t newlen)
1848{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001849 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001850 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
1852 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1853 return -ENOTDIR;
1854 if (oldval) {
1855 int old_len;
1856 if (!oldlenp || get_user(old_len, oldlenp))
1857 return -EFAULT;
1858 }
Al Viro330d57f2005-11-04 10:18:40 +00001859
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001860 for (head = sysctl_head_next(NULL); head;
1861 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001862 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001863 newval, newlen,
1864 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001865 if (error != -ENOTDIR) {
1866 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001867 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001868 }
1869 }
Al Viro330d57f2005-11-04 10:18:40 +00001870 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001873SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874{
1875 struct __sysctl_args tmp;
1876 int error;
1877
1878 if (copy_from_user(&tmp, args, sizeof(tmp)))
1879 return -EFAULT;
1880
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001881 error = deprecated_sysctl_warning(&tmp);
1882 if (error)
1883 goto out;
1884
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 lock_kernel();
1886 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1887 tmp.newval, tmp.newlen);
1888 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001889out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 return error;
1891}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001892#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
1894/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001895 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 * some sysctl variables are readonly even to root.
1897 */
1898
1899static int test_perm(int mode, int op)
1900{
David Howells76aac0e2008-11-14 10:39:12 +11001901 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 mode >>= 6;
1903 else if (in_egroup_p(0))
1904 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001905 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 return 0;
1907 return -EACCES;
1908}
1909
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001910int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911{
1912 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001913 int mode;
1914
Al Viroe6305c42008-07-15 21:03:57 -04001915 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 if (error)
1917 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001918
1919 if (root->permissions)
1920 mode = root->permissions(root, current->nsproxy, table);
1921 else
1922 mode = table->mode;
1923
1924 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925}
1926
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001927static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1928{
1929 for (; table->ctl_name || table->procname; table++) {
1930 table->parent = parent;
1931 if (table->child)
1932 sysctl_set_parent(table, table->child);
1933 }
1934}
1935
1936static __init int sysctl_init(void)
1937{
1938 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001939#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1940 {
1941 int err;
1942 err = sysctl_check_table(current->nsproxy, root_table);
1943 }
1944#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001945 return 0;
1946}
1947
1948core_initcall(sysctl_init);
1949
Al Virobfbcf032008-07-27 06:31:22 +01001950static struct ctl_table *is_branch_in(struct ctl_table *branch,
1951 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001952{
1953 struct ctl_table *p;
1954 const char *s = branch->procname;
1955
1956 /* branch should have named subdirectory as its first element */
1957 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001958 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001959
1960 /* ... and nothing else */
1961 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001962 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001963
1964 /* table should contain subdirectory with the same name */
1965 for (p = table; p->procname || p->ctl_name; p++) {
1966 if (!p->child)
1967 continue;
1968 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001969 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001970 }
Al Virobfbcf032008-07-27 06:31:22 +01001971 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001972}
1973
1974/* see if attaching q to p would be an improvement */
1975static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1976{
1977 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001978 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001979 int is_better = 0;
1980 int not_in_parent = !p->attached_by;
1981
Al Virobfbcf032008-07-27 06:31:22 +01001982 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001983 if (by == q->attached_by)
1984 is_better = 1;
1985 if (to == p->attached_by)
1986 not_in_parent = 1;
1987 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001988 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001989 }
1990
1991 if (is_better && not_in_parent) {
1992 q->attached_by = by;
1993 q->attached_to = to;
1994 q->parent = p;
1995 }
1996}
1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001999 * __register_sysctl_paths - register a sysctl hierarchy
2000 * @root: List of sysctl headers to register on
2001 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002002 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 *
2005 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002006 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002008 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 *
2010 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
2011 * must be unique within that level of sysctl
2012 *
2013 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2014 * enter a sysctl file
2015 *
2016 * data - a pointer to data for use by proc_handler
2017 *
2018 * maxlen - the maximum size in bytes of the data
2019 *
2020 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2021 *
2022 * child - a pointer to the child sysctl table if this entry is a directory, or
2023 * %NULL.
2024 *
2025 * proc_handler - the text handler routine (described below)
2026 *
2027 * strategy - the strategy routine (described below)
2028 *
2029 * de - for internal use by the sysctl routines
2030 *
2031 * extra1, extra2 - extra pointers usable by the proc handler routines
2032 *
2033 * Leaf nodes in the sysctl tree will be represented by a single file
2034 * under /proc; non-leaf nodes will be represented by directories.
2035 *
2036 * sysctl(2) can automatically manage read and write requests through
2037 * the sysctl table. The data and maxlen fields of the ctl_table
2038 * struct enable minimal validation of the values being written to be
2039 * performed, and the mode field allows minimal authentication.
2040 *
2041 * More sophisticated management can be enabled by the provision of a
2042 * strategy routine with the table entry. This will be called before
2043 * any automatic read or write of the data is performed.
2044 *
2045 * The strategy routine may return
2046 *
2047 * < 0 - Error occurred (error is passed to user process)
2048 *
2049 * 0 - OK - proceed with automatic read or write.
2050 *
2051 * > 0 - OK - read or write has been done by the strategy routine, so
2052 * return immediately.
2053 *
2054 * There must be a proc_handler routine for any terminal nodes
2055 * mirrored under /proc/sys (non-terminals are handled by a built-in
2056 * directory handler). Several default handlers are available to
2057 * cover common cases -
2058 *
2059 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2060 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2061 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2062 *
2063 * It is the handler's job to read the input buffer from user memory
2064 * and process it. The handler should return 0 on success.
2065 *
2066 * This routine returns %NULL on a failure to register, and a pointer
2067 * to the table header on success.
2068 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002069struct ctl_table_header *__register_sysctl_paths(
2070 struct ctl_table_root *root,
2071 struct nsproxy *namespaces,
2072 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002074 struct ctl_table_header *header;
2075 struct ctl_table *new, **prevp;
2076 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04002077 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002078
2079 /* Count the path components */
2080 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2081 ;
2082
2083 /*
2084 * For each path component, allocate a 2-element ctl_table array.
2085 * The first array element will be filled with the sysctl entry
2086 * for this, the second will be the sentinel (ctl_name == 0).
2087 *
2088 * We allocate everything in one go so that we don't have to
2089 * worry about freeing additional memory in unregister_sysctl_table.
2090 */
2091 header = kzalloc(sizeof(struct ctl_table_header) +
2092 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2093 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002095
2096 new = (struct ctl_table *) (header + 1);
2097
2098 /* Now connect the dots */
2099 prevp = &header->ctl_table;
2100 for (n = 0; n < npath; ++n, ++path) {
2101 /* Copy the procname */
2102 new->procname = path->procname;
2103 new->ctl_name = path->ctl_name;
2104 new->mode = 0555;
2105
2106 *prevp = new;
2107 prevp = &new->child;
2108
2109 new += 2;
2110 }
2111 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002112 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002113
2114 INIT_LIST_HEAD(&header->ctl_entry);
2115 header->used = 0;
2116 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002117 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002118 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002119 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002120#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002121 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002122 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002123 return NULL;
2124 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002125#endif
Al Viro330d57f2005-11-04 10:18:40 +00002126 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002127 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002128 header->attached_by = header->ctl_table;
2129 header->attached_to = root_table;
2130 header->parent = &root_table_header;
2131 for (set = header->set; set; set = set->parent) {
2132 struct ctl_table_header *p;
2133 list_for_each_entry(p, &set->list, ctl_entry) {
2134 if (p->unregistering)
2135 continue;
2136 try_attach(p, header);
2137 }
2138 }
2139 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002140 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002141 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002142
2143 return header;
2144}
2145
2146/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002147 * register_sysctl_table_path - register a sysctl table hierarchy
2148 * @path: The path to the directory the sysctl table is in.
2149 * @table: the top-level table structure
2150 *
2151 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2152 * array. A completely 0 filled entry terminates the table.
2153 *
2154 * See __register_sysctl_paths for more details.
2155 */
2156struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2157 struct ctl_table *table)
2158{
2159 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2160 path, table);
2161}
2162
2163/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002164 * register_sysctl_table - register a sysctl table hierarchy
2165 * @table: the top-level table structure
2166 *
2167 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2168 * array. A completely 0 filled entry terminates the table.
2169 *
2170 * See register_sysctl_paths for more details.
2171 */
2172struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2173{
2174 static const struct ctl_path null_path[] = { {} };
2175
2176 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177}
2178
2179/**
2180 * unregister_sysctl_table - unregister a sysctl table hierarchy
2181 * @header: the header returned from register_sysctl_table
2182 *
2183 * Unregisters the sysctl table and all children. proc entries may not
2184 * actually be removed until they are no longer used by anyone.
2185 */
2186void unregister_sysctl_table(struct ctl_table_header * header)
2187{
Al Viro330d57f2005-11-04 10:18:40 +00002188 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002189
2190 if (header == NULL)
2191 return;
2192
Al Viro330d57f2005-11-04 10:18:40 +00002193 spin_lock(&sysctl_lock);
2194 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002195 if (!--header->parent->count) {
2196 WARN_ON(1);
2197 kfree(header->parent);
2198 }
Al Virof7e6ced2008-07-15 01:44:23 -04002199 if (!--header->count)
2200 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002201 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202}
2203
Al Viro9043476f2008-07-15 08:54:06 -04002204int sysctl_is_seen(struct ctl_table_header *p)
2205{
2206 struct ctl_table_set *set = p->set;
2207 int res;
2208 spin_lock(&sysctl_lock);
2209 if (p->unregistering)
2210 res = 0;
2211 else if (!set->is_seen)
2212 res = 1;
2213 else
2214 res = set->is_seen(set);
2215 spin_unlock(&sysctl_lock);
2216 return res;
2217}
2218
Al Viro73455092008-07-14 21:22:20 -04002219void setup_sysctl_set(struct ctl_table_set *p,
2220 struct ctl_table_set *parent,
2221 int (*is_seen)(struct ctl_table_set *))
2222{
2223 INIT_LIST_HEAD(&p->list);
2224 p->parent = parent ? parent : &sysctl_table_root.default_set;
2225 p->is_seen = is_seen;
2226}
2227
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002228#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002229struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002230{
2231 return NULL;
2232}
2233
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002234struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2235 struct ctl_table *table)
2236{
2237 return NULL;
2238}
2239
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002240void unregister_sysctl_table(struct ctl_table_header * table)
2241{
2242}
2243
Al Viro73455092008-07-14 21:22:20 -04002244void setup_sysctl_set(struct ctl_table_set *p,
2245 struct ctl_table_set *parent,
2246 int (*is_seen)(struct ctl_table_set *))
2247{
2248}
2249
Al Virof7e6ced2008-07-15 01:44:23 -04002250void sysctl_head_put(struct ctl_table_header *head)
2251{
2252}
2253
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002254#endif /* CONFIG_SYSCTL */
2255
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256/*
2257 * /proc/sys support
2258 */
2259
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002260#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002262static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002263 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002264 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002265{
2266 size_t len;
2267 char __user *p;
2268 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002269
2270 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002271 *lenp = 0;
2272 return 0;
2273 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002274
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002275 if (write) {
2276 len = 0;
2277 p = buffer;
2278 while (len < *lenp) {
2279 if (get_user(c, p++))
2280 return -EFAULT;
2281 if (c == 0 || c == '\n')
2282 break;
2283 len++;
2284 }
2285 if (len >= maxlen)
2286 len = maxlen-1;
2287 if(copy_from_user(data, buffer, len))
2288 return -EFAULT;
2289 ((char *) data)[len] = 0;
2290 *ppos += *lenp;
2291 } else {
2292 len = strlen(data);
2293 if (len > maxlen)
2294 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002295
2296 if (*ppos > len) {
2297 *lenp = 0;
2298 return 0;
2299 }
2300
2301 data += *ppos;
2302 len -= *ppos;
2303
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002304 if (len > *lenp)
2305 len = *lenp;
2306 if (len)
2307 if(copy_to_user(buffer, data, len))
2308 return -EFAULT;
2309 if (len < *lenp) {
2310 if(put_user('\n', ((char __user *) buffer) + len))
2311 return -EFAULT;
2312 len++;
2313 }
2314 *lenp = len;
2315 *ppos += len;
2316 }
2317 return 0;
2318}
2319
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320/**
2321 * proc_dostring - read a string sysctl
2322 * @table: the sysctl table
2323 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 * @buffer: the user buffer
2325 * @lenp: the size of the user buffer
2326 * @ppos: file position
2327 *
2328 * Reads/writes a string from/to the user buffer. If the kernel
2329 * buffer provided is not large enough to hold the string, the
2330 * string is truncated. The copied string is %NULL-terminated.
2331 * If the string is being read by the user process, it is copied
2332 * and a newline '\n' is added. It is truncated if the buffer is
2333 * not large enough.
2334 *
2335 * Returns 0 on success.
2336 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002337int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 void __user *buffer, size_t *lenp, loff_t *ppos)
2339{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002340 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002341 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342}
2343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344
2345static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2346 int *valp,
2347 int write, void *data)
2348{
2349 if (write) {
2350 *valp = *negp ? -*lvalp : *lvalp;
2351 } else {
2352 int val = *valp;
2353 if (val < 0) {
2354 *negp = -1;
2355 *lvalp = (unsigned long)-val;
2356 } else {
2357 *negp = 0;
2358 *lvalp = (unsigned long)val;
2359 }
2360 }
2361 return 0;
2362}
2363
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002364static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002365 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002366 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2368 int write, void *data),
2369 void *data)
2370{
2371#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002372 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 unsigned long lval;
2374 size_t left, len;
2375
2376 char buf[TMPBUFLEN], *p;
2377 char __user *s = buffer;
2378
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002379 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 (*ppos && !write)) {
2381 *lenp = 0;
2382 return 0;
2383 }
2384
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002385 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 vleft = table->maxlen / sizeof(*i);
2387 left = *lenp;
2388
2389 if (!conv)
2390 conv = do_proc_dointvec_conv;
2391
2392 for (; left && vleft--; i++, first=0) {
2393 if (write) {
2394 while (left) {
2395 char c;
2396 if (get_user(c, s))
2397 return -EFAULT;
2398 if (!isspace(c))
2399 break;
2400 left--;
2401 s++;
2402 }
2403 if (!left)
2404 break;
2405 neg = 0;
2406 len = left;
2407 if (len > sizeof(buf) - 1)
2408 len = sizeof(buf) - 1;
2409 if (copy_from_user(buf, s, len))
2410 return -EFAULT;
2411 buf[len] = 0;
2412 p = buf;
2413 if (*p == '-' && left > 1) {
2414 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002415 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 }
2417 if (*p < '0' || *p > '9')
2418 break;
2419
2420 lval = simple_strtoul(p, &p, 0);
2421
2422 len = p-buf;
2423 if ((len < left) && *p && !isspace(*p))
2424 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 s += len;
2426 left -= len;
2427
2428 if (conv(&neg, &lval, i, 1, data))
2429 break;
2430 } else {
2431 p = buf;
2432 if (!first)
2433 *p++ = '\t';
2434
2435 if (conv(&neg, &lval, i, 0, data))
2436 break;
2437
2438 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2439 len = strlen(buf);
2440 if (len > left)
2441 len = left;
2442 if(copy_to_user(s, buf, len))
2443 return -EFAULT;
2444 left -= len;
2445 s += len;
2446 }
2447 }
2448
2449 if (!write && !first && left) {
2450 if(put_user('\n', s))
2451 return -EFAULT;
2452 left--, s++;
2453 }
2454 if (write) {
2455 while (left) {
2456 char c;
2457 if (get_user(c, s++))
2458 return -EFAULT;
2459 if (!isspace(c))
2460 break;
2461 left--;
2462 }
2463 }
2464 if (write && first)
2465 return -EINVAL;
2466 *lenp -= left;
2467 *ppos += *lenp;
2468 return 0;
2469#undef TMPBUFLEN
2470}
2471
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002472static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002473 void __user *buffer, size_t *lenp, loff_t *ppos,
2474 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2475 int write, void *data),
2476 void *data)
2477{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002478 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002479 buffer, lenp, ppos, conv, data);
2480}
2481
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482/**
2483 * proc_dointvec - read a vector of integers
2484 * @table: the sysctl table
2485 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 * @buffer: the user buffer
2487 * @lenp: the size of the user buffer
2488 * @ppos: file position
2489 *
2490 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2491 * values from/to the user buffer, treated as an ASCII string.
2492 *
2493 * Returns 0 on success.
2494 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002495int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 void __user *buffer, size_t *lenp, loff_t *ppos)
2497{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002498 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 NULL,NULL);
2500}
2501
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002502/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002503 * Taint values can only be increased
2504 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002505 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002506static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002507 void __user *buffer, size_t *lenp, loff_t *ppos)
2508{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002509 struct ctl_table t;
2510 unsigned long tmptaint = get_taint();
2511 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002512
Bastian Blank91fcd412007-04-23 14:41:14 -07002513 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002514 return -EPERM;
2515
Andi Kleen25ddbb12008-10-15 22:01:41 -07002516 t = *table;
2517 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002518 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002519 if (err < 0)
2520 return err;
2521
2522 if (write) {
2523 /*
2524 * Poor man's atomic or. Not worth adding a primitive
2525 * to everyone's atomic.h for this
2526 */
2527 int i;
2528 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2529 if ((tmptaint >> i) & 1)
2530 add_taint(i);
2531 }
2532 }
2533
2534 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002535}
2536
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537struct do_proc_dointvec_minmax_conv_param {
2538 int *min;
2539 int *max;
2540};
2541
2542static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2543 int *valp,
2544 int write, void *data)
2545{
2546 struct do_proc_dointvec_minmax_conv_param *param = data;
2547 if (write) {
2548 int val = *negp ? -*lvalp : *lvalp;
2549 if ((param->min && *param->min > val) ||
2550 (param->max && *param->max < val))
2551 return -EINVAL;
2552 *valp = val;
2553 } else {
2554 int val = *valp;
2555 if (val < 0) {
2556 *negp = -1;
2557 *lvalp = (unsigned long)-val;
2558 } else {
2559 *negp = 0;
2560 *lvalp = (unsigned long)val;
2561 }
2562 }
2563 return 0;
2564}
2565
2566/**
2567 * proc_dointvec_minmax - read a vector of integers with min/max values
2568 * @table: the sysctl table
2569 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 * @buffer: the user buffer
2571 * @lenp: the size of the user buffer
2572 * @ppos: file position
2573 *
2574 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2575 * values from/to the user buffer, treated as an ASCII string.
2576 *
2577 * This routine will ensure the values are within the range specified by
2578 * table->extra1 (min) and table->extra2 (max).
2579 *
2580 * Returns 0 on success.
2581 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002582int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 void __user *buffer, size_t *lenp, loff_t *ppos)
2584{
2585 struct do_proc_dointvec_minmax_conv_param param = {
2586 .min = (int *) table->extra1,
2587 .max = (int *) table->extra2,
2588 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002589 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 do_proc_dointvec_minmax_conv, &param);
2591}
2592
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002593static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 void __user *buffer,
2595 size_t *lenp, loff_t *ppos,
2596 unsigned long convmul,
2597 unsigned long convdiv)
2598{
2599#define TMPBUFLEN 21
2600 unsigned long *i, *min, *max, val;
2601 int vleft, first=1, neg;
2602 size_t len, left;
2603 char buf[TMPBUFLEN], *p;
2604 char __user *s = buffer;
2605
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002606 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 (*ppos && !write)) {
2608 *lenp = 0;
2609 return 0;
2610 }
2611
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002612 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 min = (unsigned long *) table->extra1;
2614 max = (unsigned long *) table->extra2;
2615 vleft = table->maxlen / sizeof(unsigned long);
2616 left = *lenp;
2617
2618 for (; left && vleft--; i++, min++, max++, first=0) {
2619 if (write) {
2620 while (left) {
2621 char c;
2622 if (get_user(c, s))
2623 return -EFAULT;
2624 if (!isspace(c))
2625 break;
2626 left--;
2627 s++;
2628 }
2629 if (!left)
2630 break;
2631 neg = 0;
2632 len = left;
2633 if (len > TMPBUFLEN-1)
2634 len = TMPBUFLEN-1;
2635 if (copy_from_user(buf, s, len))
2636 return -EFAULT;
2637 buf[len] = 0;
2638 p = buf;
2639 if (*p == '-' && left > 1) {
2640 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002641 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 }
2643 if (*p < '0' || *p > '9')
2644 break;
2645 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2646 len = p-buf;
2647 if ((len < left) && *p && !isspace(*p))
2648 break;
2649 if (neg)
2650 val = -val;
2651 s += len;
2652 left -= len;
2653
2654 if(neg)
2655 continue;
2656 if ((min && val < *min) || (max && val > *max))
2657 continue;
2658 *i = val;
2659 } else {
2660 p = buf;
2661 if (!first)
2662 *p++ = '\t';
2663 sprintf(p, "%lu", convdiv * (*i) / convmul);
2664 len = strlen(buf);
2665 if (len > left)
2666 len = left;
2667 if(copy_to_user(s, buf, len))
2668 return -EFAULT;
2669 left -= len;
2670 s += len;
2671 }
2672 }
2673
2674 if (!write && !first && left) {
2675 if(put_user('\n', s))
2676 return -EFAULT;
2677 left--, s++;
2678 }
2679 if (write) {
2680 while (left) {
2681 char c;
2682 if (get_user(c, s++))
2683 return -EFAULT;
2684 if (!isspace(c))
2685 break;
2686 left--;
2687 }
2688 }
2689 if (write && first)
2690 return -EINVAL;
2691 *lenp -= left;
2692 *ppos += *lenp;
2693 return 0;
2694#undef TMPBUFLEN
2695}
2696
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002697static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002698 void __user *buffer,
2699 size_t *lenp, loff_t *ppos,
2700 unsigned long convmul,
2701 unsigned long convdiv)
2702{
2703 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002704 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002705}
2706
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707/**
2708 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2709 * @table: the sysctl table
2710 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 * @buffer: the user buffer
2712 * @lenp: the size of the user buffer
2713 * @ppos: file position
2714 *
2715 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2716 * values from/to the user buffer, treated as an ASCII string.
2717 *
2718 * This routine will ensure the values are within the range specified by
2719 * table->extra1 (min) and table->extra2 (max).
2720 *
2721 * Returns 0 on success.
2722 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002723int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 void __user *buffer, size_t *lenp, loff_t *ppos)
2725{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002726 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727}
2728
2729/**
2730 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2731 * @table: the sysctl table
2732 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
2735 * @ppos: file position
2736 *
2737 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2738 * values from/to the user buffer, treated as an ASCII string. The values
2739 * are treated as milliseconds, and converted to jiffies when they are stored.
2740 *
2741 * This routine will ensure the values are within the range specified by
2742 * table->extra1 (min) and table->extra2 (max).
2743 *
2744 * Returns 0 on success.
2745 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002746int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 void __user *buffer,
2748 size_t *lenp, loff_t *ppos)
2749{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002750 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 lenp, ppos, HZ, 1000l);
2752}
2753
2754
2755static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2756 int *valp,
2757 int write, void *data)
2758{
2759 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002760 if (*lvalp > LONG_MAX / HZ)
2761 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2763 } else {
2764 int val = *valp;
2765 unsigned long lval;
2766 if (val < 0) {
2767 *negp = -1;
2768 lval = (unsigned long)-val;
2769 } else {
2770 *negp = 0;
2771 lval = (unsigned long)val;
2772 }
2773 *lvalp = lval / HZ;
2774 }
2775 return 0;
2776}
2777
2778static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2779 int *valp,
2780 int write, void *data)
2781{
2782 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002783 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2784 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2786 } else {
2787 int val = *valp;
2788 unsigned long lval;
2789 if (val < 0) {
2790 *negp = -1;
2791 lval = (unsigned long)-val;
2792 } else {
2793 *negp = 0;
2794 lval = (unsigned long)val;
2795 }
2796 *lvalp = jiffies_to_clock_t(lval);
2797 }
2798 return 0;
2799}
2800
2801static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2802 int *valp,
2803 int write, void *data)
2804{
2805 if (write) {
2806 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2807 } else {
2808 int val = *valp;
2809 unsigned long lval;
2810 if (val < 0) {
2811 *negp = -1;
2812 lval = (unsigned long)-val;
2813 } else {
2814 *negp = 0;
2815 lval = (unsigned long)val;
2816 }
2817 *lvalp = jiffies_to_msecs(lval);
2818 }
2819 return 0;
2820}
2821
2822/**
2823 * proc_dointvec_jiffies - read a vector of integers as seconds
2824 * @table: the sysctl table
2825 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 * @buffer: the user buffer
2827 * @lenp: the size of the user buffer
2828 * @ppos: file position
2829 *
2830 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2831 * values from/to the user buffer, treated as an ASCII string.
2832 * The values read are assumed to be in seconds, and are converted into
2833 * jiffies.
2834 *
2835 * Returns 0 on success.
2836 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002837int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 void __user *buffer, size_t *lenp, loff_t *ppos)
2839{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002840 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 do_proc_dointvec_jiffies_conv,NULL);
2842}
2843
2844/**
2845 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2846 * @table: the sysctl table
2847 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 * @buffer: the user buffer
2849 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002850 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 *
2852 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2853 * values from/to the user buffer, treated as an ASCII string.
2854 * The values read are assumed to be in 1/USER_HZ seconds, and
2855 * are converted into jiffies.
2856 *
2857 * Returns 0 on success.
2858 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002859int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 void __user *buffer, size_t *lenp, loff_t *ppos)
2861{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002862 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 do_proc_dointvec_userhz_jiffies_conv,NULL);
2864}
2865
2866/**
2867 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2868 * @table: the sysctl table
2869 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 * @buffer: the user buffer
2871 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002872 * @ppos: file position
2873 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 *
2875 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2876 * values from/to the user buffer, treated as an ASCII string.
2877 * The values read are assumed to be in 1/1000 seconds, and
2878 * are converted into jiffies.
2879 *
2880 * Returns 0 on success.
2881 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002882int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 void __user *buffer, size_t *lenp, loff_t *ppos)
2884{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002885 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 do_proc_dointvec_ms_jiffies_conv, NULL);
2887}
2888
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002889static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002890 void __user *buffer, size_t *lenp, loff_t *ppos)
2891{
2892 struct pid *new_pid;
2893 pid_t tmp;
2894 int r;
2895
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002896 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002897
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002898 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002899 lenp, ppos, NULL, NULL);
2900 if (r || !write)
2901 return r;
2902
2903 new_pid = find_get_pid(tmp);
2904 if (!new_pid)
2905 return -ESRCH;
2906
2907 put_pid(xchg(&cad_pid, new_pid));
2908 return 0;
2909}
2910
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911#else /* CONFIG_PROC_FS */
2912
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002913int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 void __user *buffer, size_t *lenp, loff_t *ppos)
2915{
2916 return -ENOSYS;
2917}
2918
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002919int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 void __user *buffer, size_t *lenp, loff_t *ppos)
2921{
2922 return -ENOSYS;
2923}
2924
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002925int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 void __user *buffer, size_t *lenp, loff_t *ppos)
2927{
2928 return -ENOSYS;
2929}
2930
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002931int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 void __user *buffer, size_t *lenp, loff_t *ppos)
2933{
2934 return -ENOSYS;
2935}
2936
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002937int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 void __user *buffer, size_t *lenp, loff_t *ppos)
2939{
2940 return -ENOSYS;
2941}
2942
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002943int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 void __user *buffer, size_t *lenp, loff_t *ppos)
2945{
2946 return -ENOSYS;
2947}
2948
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002949int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 void __user *buffer, size_t *lenp, loff_t *ppos)
2951{
2952 return -ENOSYS;
2953}
2954
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002955int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 void __user *buffer,
2957 size_t *lenp, loff_t *ppos)
2958{
2959 return -ENOSYS;
2960}
2961
2962
2963#endif /* CONFIG_PROC_FS */
2964
2965
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002966#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967/*
2968 * General sysctl support routines
2969 */
2970
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002971/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002972int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002973 void __user *oldval, size_t __user *oldlenp,
2974 void __user *newval, size_t newlen)
2975{
2976 size_t len;
2977
2978 /* Get out of I don't have a variable */
2979 if (!table->data || !table->maxlen)
2980 return -ENOTDIR;
2981
2982 if (oldval && oldlenp) {
2983 if (get_user(len, oldlenp))
2984 return -EFAULT;
2985 if (len) {
2986 if (len > table->maxlen)
2987 len = table->maxlen;
2988 if (copy_to_user(oldval, table->data, len))
2989 return -EFAULT;
2990 if (put_user(len, oldlenp))
2991 return -EFAULT;
2992 }
2993 }
2994
2995 if (newval && newlen) {
2996 if (newlen > table->maxlen)
2997 newlen = table->maxlen;
2998
2999 if (copy_from_user(table->data, newval, newlen))
3000 return -EFAULT;
3001 }
3002 return 1;
3003}
3004
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003006int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003008 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 if (!table->data || !table->maxlen)
3011 return -ENOTDIR;
3012
3013 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003014 size_t bufsize;
3015 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003017 if (bufsize) {
3018 size_t len = strlen(table->data), copied;
3019
3020 /* This shouldn't trigger for a well-formed sysctl */
3021 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003023
3024 /* Copy up to a max of bufsize-1 bytes of the string */
3025 copied = (len >= bufsize) ? bufsize - 1 : len;
3026
3027 if (copy_to_user(oldval, table->data, copied) ||
3028 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003030 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 return -EFAULT;
3032 }
3033 }
3034 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003035 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 if (len > table->maxlen)
3037 len = table->maxlen;
3038 if(copy_from_user(table->data, newval, len))
3039 return -EFAULT;
3040 if (len == table->maxlen)
3041 len--;
3042 ((char *) table->data)[len] = 0;
3043 }
Yi Yang82c9df82005-12-30 16:37:10 +08003044 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045}
3046
3047/*
3048 * This function makes sure that all of the integers in the vector
3049 * are between the minimum and maximum values given in the arrays
3050 * table->extra1 and table->extra2, respectively.
3051 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003052int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003054 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055{
3056
3057 if (newval && newlen) {
3058 int __user *vec = (int __user *) newval;
3059 int *min = (int *) table->extra1;
3060 int *max = (int *) table->extra2;
3061 size_t length;
3062 int i;
3063
3064 if (newlen % sizeof(int) != 0)
3065 return -EINVAL;
3066
3067 if (!table->extra1 && !table->extra2)
3068 return 0;
3069
3070 if (newlen > table->maxlen)
3071 newlen = table->maxlen;
3072 length = newlen / sizeof(int);
3073
3074 for (i = 0; i < length; i++) {
3075 int value;
3076 if (get_user(value, vec + i))
3077 return -EFAULT;
3078 if (min && value < min[i])
3079 return -EINVAL;
3080 if (max && value > max[i])
3081 return -EINVAL;
3082 }
3083 }
3084 return 0;
3085}
3086
3087/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003088int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003090 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003092 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003094
3095 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003097 if (olen) {
3098 int val;
3099
3100 if (olen < sizeof(int))
3101 return -EINVAL;
3102
3103 val = *(int *)(table->data) / HZ;
3104 if (put_user(val, (int __user *)oldval))
3105 return -EFAULT;
3106 if (put_user(sizeof(int), oldlenp))
3107 return -EFAULT;
3108 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 }
3110 if (newval && newlen) {
3111 int new;
3112 if (newlen != sizeof(int))
3113 return -EINVAL;
3114 if (get_user(new, (int __user *)newval))
3115 return -EFAULT;
3116 *(int *)(table->data) = new*HZ;
3117 }
3118 return 1;
3119}
3120
3121/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003122int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003124 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003126 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003128
3129 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003131 if (olen) {
3132 int val;
3133
3134 if (olen < sizeof(int))
3135 return -EINVAL;
3136
3137 val = jiffies_to_msecs(*(int *)(table->data));
3138 if (put_user(val, (int __user *)oldval))
3139 return -EFAULT;
3140 if (put_user(sizeof(int), oldlenp))
3141 return -EFAULT;
3142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 }
3144 if (newval && newlen) {
3145 int new;
3146 if (newlen != sizeof(int))
3147 return -EINVAL;
3148 if (get_user(new, (int __user *)newval))
3149 return -EFAULT;
3150 *(int *)(table->data) = msecs_to_jiffies(new);
3151 }
3152 return 1;
3153}
3154
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003155
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003156
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003157#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158
3159
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003160SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003162 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003163 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003164
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003165 if (copy_from_user(&tmp, args, sizeof(tmp)))
3166 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003167
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003168 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003169
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003170 /* If no error reading the parameters then just -ENOSYS ... */
3171 if (!error)
3172 error = -ENOSYS;
3173
3174 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175}
3176
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003177int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003178 void __user *oldval, size_t __user *oldlenp,
3179 void __user *newval, size_t newlen)
3180{
3181 return -ENOSYS;
3182}
3183
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003184int sysctl_string(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_intvec(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
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003198int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003200 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201{
3202 return -ENOSYS;
3203}
3204
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003205int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003207 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208{
3209 return -ENOSYS;
3210}
3211
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003212#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003214static int deprecated_sysctl_warning(struct __sysctl_args *args)
3215{
3216 static int msg_count;
3217 int name[CTL_MAXNAME];
3218 int i;
3219
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003220 /* Check args->nlen. */
3221 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3222 return -ENOTDIR;
3223
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003224 /* Read in the sysctl name for better debug message logging */
3225 for (i = 0; i < args->nlen; i++)
3226 if (get_user(name[i], args->name + i))
3227 return -EFAULT;
3228
3229 /* Ignore accesses to kernel.version */
3230 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3231 return 0;
3232
3233 if (msg_count < 5) {
3234 msg_count++;
3235 printk(KERN_INFO
3236 "warning: process `%s' used the deprecated sysctl "
3237 "system call with ", current->comm);
3238 for (i = 0; i < args->nlen; i++)
3239 printk("%d.", name[i]);
3240 printk("\n");
3241 }
3242 return 0;
3243}
3244
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245/*
3246 * No sense putting this after each symbol definition, twice,
3247 * exception granted :-)
3248 */
3249EXPORT_SYMBOL(proc_dointvec);
3250EXPORT_SYMBOL(proc_dointvec_jiffies);
3251EXPORT_SYMBOL(proc_dointvec_minmax);
3252EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3253EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3254EXPORT_SYMBOL(proc_dostring);
3255EXPORT_SYMBOL(proc_doulongvec_minmax);
3256EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3257EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003258EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259EXPORT_SYMBOL(sysctl_intvec);
3260EXPORT_SYMBOL(sysctl_jiffies);
3261EXPORT_SYMBOL(sysctl_ms_jiffies);
3262EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003263EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264EXPORT_SYMBOL(unregister_sysctl_table);