blob: f82e955875c9c407d332b9d29861f1c1139f832d [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>
Adrian Bunk62239ac2007-07-17 04:03:45 -070030#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/init.h>
32#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010033#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030034#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/sysrq.h>
36#include <linux/highuid.h>
37#include <linux/writeback.h>
38#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070040#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/times.h>
42#include <linux/limits.h>
43#include <linux/dcache.h>
44#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070045#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080046#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020049#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010050#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020051#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/uaccess.h>
54#include <asm/processor.h>
55
Andi Kleen29cbc782006-09-30 01:47:55 +020056#ifdef CONFIG_X86
57#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010058#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010059#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020060#endif
61
Eric W. Biederman7058cb02007-10-18 03:05:58 -070062
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#if defined(CONFIG_SYSCTL)
64
65/* External variables not in a header file. */
66extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070067extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int sysctl_overcommit_memory;
69extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070070extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070071extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080072extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070075extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070077extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int pid_max;
79extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080081extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080082extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020083extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000086#ifndef CONFIG_MMU
87extern int sysctl_nr_trim_pages;
88#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070089#ifdef CONFIG_RCU_TORTURE_TEST
90extern int rcutorture_runnable;
91#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Jens Axboecb684b52009-09-15 21:53:11 +020092#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +020093extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +020094#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080097#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020099static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100#endif
101
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700102static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700103static int __maybe_unused one = 1;
104static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800105static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700106static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700107#ifdef CONFIG_PRINTK
108static int ten_thousand = 10000;
109#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700110
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700111/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
112static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
115static int maxolduid = 65535;
116static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800117static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119static int ngroups_max = NGROUPS_MAX;
120
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200121#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700123extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#ifdef CONFIG_CHR_DEV_SG
126extern int sg_big_buff;
127#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
David S. Miller72c57ed2008-09-11 23:29:54 -0700129#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700130#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#endif
132
David S. Miller08714202008-11-16 23:49:24 -0800133#ifdef CONFIG_SPARC64
134extern int sysctl_tsb_ratio;
135#endif
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef __hppa__
138extern int pwrsw_enabled;
139extern int unaligned_enabled;
140#endif
141
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800142#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#ifdef CONFIG_MATHEMU
144extern int sysctl_ieee_emulation_warnings;
145#endif
146extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700147extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#endif
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#ifdef CONFIG_BSD_PROCESS_ACCT
151extern int acct_parm[];
152#endif
153
Jes Sorensend2b176e2006-02-28 09:42:23 -0800154#ifdef CONFIG_IA64
155extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800156extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800157#endif
158
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700159#ifdef CONFIG_RT_MUTEXES
160extern int max_lock_depth;
161#endif
162
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700163#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700164static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700165 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700166static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800167 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700168#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700169
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700170static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100171static struct ctl_table_root sysctl_table_root;
172static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100173 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100174 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400175 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400177 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100178};
179static struct ctl_table_root sysctl_table_root = {
180 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400181 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100182};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700184static struct ctl_table kern_table[];
185static struct ctl_table vm_table[];
186static struct ctl_table fs_table[];
187static struct ctl_table debug_table[];
188static struct ctl_table dev_table[];
189extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700190#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700191extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400192#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800193#ifdef CONFIG_EPOLL
194extern struct ctl_table epoll_table[];
195#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
198int sysctl_legacy_va_layout;
199#endif
200
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700201extern int prove_locking;
202extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204/* The default sysctl tables: */
205
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700206static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 {
208 .ctl_name = CTL_KERN,
209 .procname = "kernel",
210 .mode = 0555,
211 .child = kern_table,
212 },
213 {
214 .ctl_name = CTL_VM,
215 .procname = "vm",
216 .mode = 0555,
217 .child = vm_table,
218 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 .ctl_name = CTL_FS,
221 .procname = "fs",
222 .mode = 0555,
223 .child = fs_table,
224 },
225 {
226 .ctl_name = CTL_DEBUG,
227 .procname = "debug",
228 .mode = 0555,
229 .child = debug_table,
230 },
231 {
232 .ctl_name = CTL_DEV,
233 .procname = "dev",
234 .mode = 0555,
235 .child = dev_table,
236 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700237/*
238 * NOTE: do not add new entries to this table unless you have read
239 * Documentation/sysctl/ctl_unnumbered.txt
240 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 { .ctl_name = 0 }
242};
243
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100245static int min_sched_granularity_ns = 100000; /* 100 usecs */
246static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
247static int min_wakeup_granularity_ns; /* 0 usecs */
248static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249#endif
250
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700251static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200252 {
253 .ctl_name = CTL_UNNUMBERED,
254 .procname = "sched_child_runs_first",
255 .data = &sysctl_sched_child_runs_first,
256 .maxlen = sizeof(unsigned int),
257 .mode = 0644,
258 .proc_handler = &proc_dointvec,
259 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200260#ifdef CONFIG_SCHED_DEBUG
261 {
262 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100263 .procname = "sched_min_granularity_ns",
264 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200265 .maxlen = sizeof(unsigned int),
266 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100267 .proc_handler = &sched_nr_latency_handler,
268 .strategy = &sysctl_intvec,
269 .extra1 = &min_sched_granularity_ns,
270 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200271 },
272 {
273 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200274 .procname = "sched_latency_ns",
275 .data = &sysctl_sched_latency,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100278 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200279 .strategy = &sysctl_intvec,
280 .extra1 = &min_sched_granularity_ns,
281 .extra2 = &max_sched_granularity_ns,
282 },
283 {
284 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200285 .procname = "sched_wakeup_granularity_ns",
286 .data = &sysctl_sched_wakeup_granularity,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
289 .proc_handler = &proc_dointvec_minmax,
290 .strategy = &sysctl_intvec,
291 .extra1 = &min_wakeup_granularity_ns,
292 .extra2 = &max_wakeup_granularity_ns,
293 },
294 {
295 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200296 .procname = "sched_shares_ratelimit",
297 .data = &sysctl_sched_shares_ratelimit,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
300 .proc_handler = &proc_dointvec,
301 },
302 {
303 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200304 .procname = "sched_shares_thresh",
305 .data = &sysctl_sched_shares_thresh,
306 .maxlen = sizeof(unsigned int),
307 .mode = 0644,
308 .proc_handler = &proc_dointvec_minmax,
309 .strategy = &sysctl_intvec,
310 .extra1 = &zero,
311 },
312 {
313 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200314 .procname = "sched_features",
315 .data = &sysctl_sched_features,
316 .maxlen = sizeof(unsigned int),
317 .mode = 0644,
318 .proc_handler = &proc_dointvec,
319 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200320 {
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_migration_cost",
323 .data = &sysctl_sched_migration_cost,
324 .maxlen = sizeof(unsigned int),
325 .mode = 0644,
326 .proc_handler = &proc_dointvec,
327 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100328 {
329 .ctl_name = CTL_UNNUMBERED,
330 .procname = "sched_nr_migrate",
331 .data = &sysctl_sched_nr_migrate,
332 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100333 .mode = 0644,
334 .proc_handler = &proc_dointvec,
335 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530336 {
337 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200338 .procname = "sched_time_avg",
339 .data = &sysctl_sched_time_avg,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
343 },
344 {
345 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530346 .procname = "timer_migration",
347 .data = &sysctl_timer_migration,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530350 .proc_handler = &proc_dointvec_minmax,
351 .strategy = &sysctl_intvec,
352 .extra1 = &zero,
353 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530354 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200355#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200356 {
357 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100358 .procname = "sched_rt_period_us",
359 .data = &sysctl_sched_rt_period,
360 .maxlen = sizeof(unsigned int),
361 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200362 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100363 },
364 {
365 .ctl_name = CTL_UNNUMBERED,
366 .procname = "sched_rt_runtime_us",
367 .data = &sysctl_sched_rt_runtime,
368 .maxlen = sizeof(int),
369 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200370 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100371 },
372 {
373 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200374 .procname = "sched_compat_yield",
375 .data = &sysctl_sched_compat_yield,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
378 .proc_handler = &proc_dointvec,
379 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700380#ifdef CONFIG_PROVE_LOCKING
381 {
382 .ctl_name = CTL_UNNUMBERED,
383 .procname = "prove_locking",
384 .data = &prove_locking,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = &proc_dointvec,
388 },
389#endif
390#ifdef CONFIG_LOCK_STAT
391 {
392 .ctl_name = CTL_UNNUMBERED,
393 .procname = "lock_stat",
394 .data = &lock_stat,
395 .maxlen = sizeof(int),
396 .mode = 0644,
397 .proc_handler = &proc_dointvec,
398 },
399#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200400 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 .ctl_name = KERN_PANIC,
402 .procname = "panic",
403 .data = &panic_timeout,
404 .maxlen = sizeof(int),
405 .mode = 0644,
406 .proc_handler = &proc_dointvec,
407 },
408 {
409 .ctl_name = KERN_CORE_USES_PID,
410 .procname = "core_uses_pid",
411 .data = &core_uses_pid,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = &proc_dointvec,
415 },
416 {
417 .ctl_name = KERN_CORE_PATTERN,
418 .procname = "core_pattern",
419 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700420 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .mode = 0644,
422 .proc_handler = &proc_dostring,
423 .strategy = &sysctl_string,
424 },
Neil Hormana2939802009-09-23 15:56:56 -0700425 {
426 .ctl_name = CTL_UNNUMBERED,
427 .procname = "core_pipe_limit",
428 .data = &core_pipe_limit,
429 .maxlen = sizeof(unsigned int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
432 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800433#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700436 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800437 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700438 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800440#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100441#ifdef CONFIG_LATENCYTOP
442 {
443 .procname = "latencytop",
444 .data = &latencytop_enabled,
445 .maxlen = sizeof(int),
446 .mode = 0644,
447 .proc_handler = &proc_dointvec,
448 },
449#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450#ifdef CONFIG_BLK_DEV_INITRD
451 {
452 .ctl_name = KERN_REALROOTDEV,
453 .procname = "real-root-dev",
454 .data = &real_root_dev,
455 .maxlen = sizeof(int),
456 .mode = 0644,
457 .proc_handler = &proc_dointvec,
458 },
459#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700460 {
461 .ctl_name = CTL_UNNUMBERED,
462 .procname = "print-fatal-signals",
463 .data = &print_fatal_signals,
464 .maxlen = sizeof(int),
465 .mode = 0644,
466 .proc_handler = &proc_dointvec,
467 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700468#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 {
470 .ctl_name = KERN_SPARC_REBOOT,
471 .procname = "reboot-cmd",
472 .data = reboot_command,
473 .maxlen = 256,
474 .mode = 0644,
475 .proc_handler = &proc_dostring,
476 .strategy = &sysctl_string,
477 },
478 {
479 .ctl_name = KERN_SPARC_STOP_A,
480 .procname = "stop-a",
481 .data = &stop_a_enabled,
482 .maxlen = sizeof (int),
483 .mode = 0644,
484 .proc_handler = &proc_dointvec,
485 },
486 {
487 .ctl_name = KERN_SPARC_SCONS_PWROFF,
488 .procname = "scons-poweroff",
489 .data = &scons_pwroff,
490 .maxlen = sizeof (int),
491 .mode = 0644,
492 .proc_handler = &proc_dointvec,
493 },
494#endif
David S. Miller08714202008-11-16 23:49:24 -0800495#ifdef CONFIG_SPARC64
496 {
497 .ctl_name = CTL_UNNUMBERED,
498 .procname = "tsb-ratio",
499 .data = &sysctl_tsb_ratio,
500 .maxlen = sizeof (int),
501 .mode = 0644,
502 .proc_handler = &proc_dointvec,
503 },
504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#ifdef __hppa__
506 {
507 .ctl_name = KERN_HPPA_PWRSW,
508 .procname = "soft-power",
509 .data = &pwrsw_enabled,
510 .maxlen = sizeof (int),
511 .mode = 0644,
512 .proc_handler = &proc_dointvec,
513 },
514 {
515 .ctl_name = KERN_HPPA_UNALIGNED,
516 .procname = "unaligned-trap",
517 .data = &unaligned_enabled,
518 .maxlen = sizeof (int),
519 .mode = 0644,
520 .proc_handler = &proc_dointvec,
521 },
522#endif
523 {
524 .ctl_name = KERN_CTLALTDEL,
525 .procname = "ctrl-alt-del",
526 .data = &C_A_D,
527 .maxlen = sizeof(int),
528 .mode = 0644,
529 .proc_handler = &proc_dointvec,
530 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400531#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200532 {
533 .ctl_name = CTL_UNNUMBERED,
534 .procname = "ftrace_enabled",
535 .data = &ftrace_enabled,
536 .maxlen = sizeof(int),
537 .mode = 0644,
538 .proc_handler = &ftrace_enable_sysctl,
539 },
540#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500541#ifdef CONFIG_STACK_TRACER
542 {
543 .ctl_name = CTL_UNNUMBERED,
544 .procname = "stack_tracer_enabled",
545 .data = &stack_tracer_enabled,
546 .maxlen = sizeof(int),
547 .mode = 0644,
548 .proc_handler = &stack_trace_sysctl,
549 },
550#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400551#ifdef CONFIG_TRACING
552 {
553 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100554 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400555 .data = &ftrace_dump_on_oops,
556 .maxlen = sizeof(int),
557 .mode = 0644,
558 .proc_handler = &proc_dointvec,
559 },
560#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200561#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 {
563 .ctl_name = KERN_MODPROBE,
564 .procname = "modprobe",
565 .data = &modprobe_path,
566 .maxlen = KMOD_PATH_LEN,
567 .mode = 0644,
568 .proc_handler = &proc_dostring,
569 .strategy = &sysctl_string,
570 },
Kees Cook3d433212009-04-02 15:49:29 -0700571 {
572 .ctl_name = CTL_UNNUMBERED,
573 .procname = "modules_disabled",
574 .data = &modules_disabled,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 /* only handle a transition from default "0" to "1" */
578 .proc_handler = &proc_dointvec_minmax,
579 .extra1 = &one,
580 .extra2 = &one,
581 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700583#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 {
585 .ctl_name = KERN_HOTPLUG,
586 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100587 .data = &uevent_helper,
588 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 .mode = 0644,
590 .proc_handler = &proc_dostring,
591 .strategy = &sysctl_string,
592 },
593#endif
594#ifdef CONFIG_CHR_DEV_SG
595 {
596 .ctl_name = KERN_SG_BIG_BUFF,
597 .procname = "sg-big-buff",
598 .data = &sg_big_buff,
599 .maxlen = sizeof (int),
600 .mode = 0444,
601 .proc_handler = &proc_dointvec,
602 },
603#endif
604#ifdef CONFIG_BSD_PROCESS_ACCT
605 {
606 .ctl_name = KERN_ACCT,
607 .procname = "acct",
608 .data = &acct_parm,
609 .maxlen = 3*sizeof(int),
610 .mode = 0644,
611 .proc_handler = &proc_dointvec,
612 },
613#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614#ifdef CONFIG_MAGIC_SYSRQ
615 {
616 .ctl_name = KERN_SYSRQ,
617 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800618 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .maxlen = sizeof (int),
620 .mode = 0644,
621 .proc_handler = &proc_dointvec,
622 },
623#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700624#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700627 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 .maxlen = sizeof (int),
629 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700630 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700632#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 {
634 .ctl_name = KERN_MAX_THREADS,
635 .procname = "threads-max",
636 .data = &max_threads,
637 .maxlen = sizeof(int),
638 .mode = 0644,
639 .proc_handler = &proc_dointvec,
640 },
641 {
642 .ctl_name = KERN_RANDOM,
643 .procname = "random",
644 .mode = 0555,
645 .child = random_table,
646 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 {
648 .ctl_name = KERN_OVERFLOWUID,
649 .procname = "overflowuid",
650 .data = &overflowuid,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec_minmax,
654 .strategy = &sysctl_intvec,
655 .extra1 = &minolduid,
656 .extra2 = &maxolduid,
657 },
658 {
659 .ctl_name = KERN_OVERFLOWGID,
660 .procname = "overflowgid",
661 .data = &overflowgid,
662 .maxlen = sizeof(int),
663 .mode = 0644,
664 .proc_handler = &proc_dointvec_minmax,
665 .strategy = &sysctl_intvec,
666 .extra1 = &minolduid,
667 .extra2 = &maxolduid,
668 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800669#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670#ifdef CONFIG_MATHEMU
671 {
672 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
673 .procname = "ieee_emulation_warnings",
674 .data = &sysctl_ieee_emulation_warnings,
675 .maxlen = sizeof(int),
676 .mode = 0644,
677 .proc_handler = &proc_dointvec,
678 },
679#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 {
681 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
682 .procname = "userprocess_debug",
683 .data = &sysctl_userprocess_debug,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec,
687 },
688#endif
689 {
690 .ctl_name = KERN_PIDMAX,
691 .procname = "pid_max",
692 .data = &pid_max,
693 .maxlen = sizeof (int),
694 .mode = 0644,
695 .proc_handler = &proc_dointvec_minmax,
696 .strategy = sysctl_intvec,
697 .extra1 = &pid_max_min,
698 .extra2 = &pid_max_max,
699 },
700 {
701 .ctl_name = KERN_PANIC_ON_OOPS,
702 .procname = "panic_on_oops",
703 .data = &panic_on_oops,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 .proc_handler = &proc_dointvec,
707 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800708#if defined CONFIG_PRINTK
709 {
710 .ctl_name = KERN_PRINTK,
711 .procname = "printk",
712 .data = &console_loglevel,
713 .maxlen = 4*sizeof(int),
714 .mode = 0644,
715 .proc_handler = &proc_dointvec,
716 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 {
718 .ctl_name = KERN_PRINTK_RATELIMIT,
719 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700720 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec_jiffies,
724 .strategy = &sysctl_jiffies,
725 },
726 {
727 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
728 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700729 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 .maxlen = sizeof(int),
731 .mode = 0644,
732 .proc_handler = &proc_dointvec,
733 },
Dave Youngaf913222009-09-22 16:43:33 -0700734 {
735 .ctl_name = CTL_UNNUMBERED,
736 .procname = "printk_delay",
737 .data = &printk_delay_msec,
738 .maxlen = sizeof(int),
739 .mode = 0644,
740 .proc_handler = &proc_dointvec_minmax,
741 .strategy = &sysctl_intvec,
742 .extra1 = &zero,
743 .extra2 = &ten_thousand,
744 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800745#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 {
747 .ctl_name = KERN_NGROUPS_MAX,
748 .procname = "ngroups_max",
749 .data = &ngroups_max,
750 .maxlen = sizeof (int),
751 .mode = 0444,
752 .proc_handler = &proc_dointvec,
753 },
754#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
755 {
756 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
757 .procname = "unknown_nmi_panic",
758 .data = &unknown_nmi_panic,
759 .maxlen = sizeof (int),
760 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200761 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 },
Don Zickus407984f2006-09-26 10:52:27 +0200763 {
Don Zickus407984f2006-09-26 10:52:27 +0200764 .procname = "nmi_watchdog",
765 .data = &nmi_watchdog_enabled,
766 .maxlen = sizeof (int),
767 .mode = 0644,
768 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 },
770#endif
771#if defined(CONFIG_X86)
772 {
Don Zickus8da5add2006-09-26 10:52:27 +0200773 .ctl_name = KERN_PANIC_ON_NMI,
774 .procname = "panic_on_unrecovered_nmi",
775 .data = &panic_on_unrecovered_nmi,
776 .maxlen = sizeof(int),
777 .mode = 0644,
778 .proc_handler = &proc_dointvec,
779 },
780 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "panic_on_io_nmi",
783 .data = &panic_on_io_nmi,
784 .maxlen = sizeof(int),
785 .mode = 0644,
786 .proc_handler = &proc_dointvec,
787 },
788 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .ctl_name = KERN_BOOTLOADER_TYPE,
790 .procname = "bootloader_type",
791 .data = &bootloader_type,
792 .maxlen = sizeof (int),
793 .mode = 0444,
794 .proc_handler = &proc_dointvec,
795 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100796 {
797 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700798 .procname = "bootloader_version",
799 .data = &bootloader_version,
800 .maxlen = sizeof (int),
801 .mode = 0444,
802 .proc_handler = &proc_dointvec,
803 },
804 {
805 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100806 .procname = "kstack_depth_to_print",
807 .data = &kstack_depth_to_print,
808 .maxlen = sizeof(int),
809 .mode = 0644,
810 .proc_handler = &proc_dointvec,
811 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100812 {
813 .ctl_name = CTL_UNNUMBERED,
814 .procname = "io_delay_type",
815 .data = &io_delay_type,
816 .maxlen = sizeof(int),
817 .mode = 0644,
818 .proc_handler = &proc_dointvec,
819 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800821#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 {
823 .ctl_name = KERN_RANDOMIZE,
824 .procname = "randomize_va_space",
825 .data = &randomize_va_space,
826 .maxlen = sizeof(int),
827 .mode = 0644,
828 .proc_handler = &proc_dointvec,
829 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800830#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800831#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700832 {
833 .ctl_name = KERN_SPIN_RETRY,
834 .procname = "spin_retry",
835 .data = &spin_retry,
836 .maxlen = sizeof (int),
837 .mode = 0644,
838 .proc_handler = &proc_dointvec,
839 },
840#endif
Len Brown673d5b42007-07-28 03:33:16 -0400841#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800842 {
Pavel Machekc255d842006-02-20 18:27:58 -0800843 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700844 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800845 .maxlen = sizeof (unsigned long),
846 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800847 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800848 },
849#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800850#ifdef CONFIG_IA64
851 {
852 .ctl_name = KERN_IA64_UNALIGNED,
853 .procname = "ignore-unaligned-usertrap",
854 .data = &no_unaligned_warning,
855 .maxlen = sizeof (int),
856 .mode = 0644,
857 .proc_handler = &proc_dointvec,
858 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800859 {
860 .ctl_name = CTL_UNNUMBERED,
861 .procname = "unaligned-dump-stack",
862 .data = &unaligned_dump_stack,
863 .maxlen = sizeof (int),
864 .mode = 0644,
865 .proc_handler = &proc_dointvec,
866 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800867#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700868#ifdef CONFIG_DETECT_SOFTLOCKUP
869 {
870 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200871 .procname = "softlockup_panic",
872 .data = &softlockup_panic,
873 .maxlen = sizeof(int),
874 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700875 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200876 .strategy = &sysctl_intvec,
877 .extra1 = &zero,
878 .extra2 = &one,
879 },
880 {
881 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700882 .procname = "softlockup_thresh",
883 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200884 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700885 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800886 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700887 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200888 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700889 .extra2 = &sixty,
890 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800891#endif
892#ifdef CONFIG_DETECT_HUNG_TASK
893 {
894 .ctl_name = CTL_UNNUMBERED,
895 .procname = "hung_task_panic",
896 .data = &sysctl_hung_task_panic,
897 .maxlen = sizeof(int),
898 .mode = 0644,
899 .proc_handler = &proc_dointvec_minmax,
900 .strategy = &sysctl_intvec,
901 .extra1 = &zero,
902 .extra2 = &one,
903 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100904 {
905 .ctl_name = CTL_UNNUMBERED,
906 .procname = "hung_task_check_count",
907 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100908 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100909 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100910 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100911 .strategy = &sysctl_intvec,
912 },
913 {
914 .ctl_name = CTL_UNNUMBERED,
915 .procname = "hung_task_timeout_secs",
916 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100917 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100918 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800919 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100920 .strategy = &sysctl_intvec,
921 },
922 {
923 .ctl_name = CTL_UNNUMBERED,
924 .procname = "hung_task_warnings",
925 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100926 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100927 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100928 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100929 .strategy = &sysctl_intvec,
930 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700931#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200932#ifdef CONFIG_COMPAT
933 {
934 .ctl_name = KERN_COMPAT_LOG,
935 .procname = "compat-log",
936 .data = &compat_log,
937 .maxlen = sizeof (int),
938 .mode = 0644,
939 .proc_handler = &proc_dointvec,
940 },
941#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700942#ifdef CONFIG_RT_MUTEXES
943 {
944 .ctl_name = KERN_MAX_LOCK_DEPTH,
945 .procname = "max_lock_depth",
946 .data = &max_lock_depth,
947 .maxlen = sizeof(int),
948 .mode = 0644,
949 .proc_handler = &proc_dointvec,
950 },
951#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700952 {
953 .ctl_name = CTL_UNNUMBERED,
954 .procname = "poweroff_cmd",
955 .data = &poweroff_cmd,
956 .maxlen = POWEROFF_CMD_PATH_LEN,
957 .mode = 0644,
958 .proc_handler = &proc_dostring,
959 .strategy = &sysctl_string,
960 },
David Howells0b77f5b2008-04-29 01:01:32 -0700961#ifdef CONFIG_KEYS
962 {
963 .ctl_name = CTL_UNNUMBERED,
964 .procname = "keys",
965 .mode = 0555,
966 .child = key_sysctls,
967 },
968#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700969#ifdef CONFIG_RCU_TORTURE_TEST
970 {
971 .ctl_name = CTL_UNNUMBERED,
972 .procname = "rcutorture_runnable",
973 .data = &rcutorture_runnable,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = &proc_dointvec,
977 },
978#endif
David Howells12e22c52009-04-03 16:42:35 +0100979#ifdef CONFIG_SLOW_WORK
980 {
981 .ctl_name = CTL_UNNUMBERED,
982 .procname = "slow-work",
983 .mode = 0555,
984 .child = slow_work_sysctls,
985 },
986#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200987#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200988 {
989 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200990 .procname = "perf_event_paranoid",
991 .data = &sysctl_perf_event_paranoid,
992 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200993 .mode = 0644,
994 .proc_handler = &proc_dointvec,
995 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200996 {
997 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200998 .procname = "perf_event_mlock_kb",
999 .data = &sysctl_perf_event_mlock,
1000 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001001 .mode = 0644,
1002 .proc_handler = &proc_dointvec,
1003 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001004 {
1005 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001006 .procname = "perf_event_max_sample_rate",
1007 .data = &sysctl_perf_event_sample_rate,
1008 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001009 .mode = 0644,
1010 .proc_handler = &proc_dointvec,
1011 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001012#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001013#ifdef CONFIG_KMEMCHECK
1014 {
1015 .ctl_name = CTL_UNNUMBERED,
1016 .procname = "kmemcheck",
1017 .data = &kmemcheck_enabled,
1018 .maxlen = sizeof(int),
1019 .mode = 0644,
1020 .proc_handler = &proc_dointvec,
1021 },
1022#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001023#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001024 {
1025 .ctl_name = CTL_UNNUMBERED,
1026 .procname = "blk_iopoll",
1027 .data = &blk_iopoll_enabled,
1028 .maxlen = sizeof(int),
1029 .mode = 0644,
1030 .proc_handler = &proc_dointvec,
1031 },
Jens Axboecb684b52009-09-15 21:53:11 +02001032#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001033/*
1034 * NOTE: do not add new entries to this table unless you have read
1035 * Documentation/sysctl/ctl_unnumbered.txt
1036 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 { .ctl_name = 0 }
1038};
1039
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001040static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 {
1042 .ctl_name = VM_OVERCOMMIT_MEMORY,
1043 .procname = "overcommit_memory",
1044 .data = &sysctl_overcommit_memory,
1045 .maxlen = sizeof(sysctl_overcommit_memory),
1046 .mode = 0644,
1047 .proc_handler = &proc_dointvec,
1048 },
1049 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001050 .ctl_name = VM_PANIC_ON_OOM,
1051 .procname = "panic_on_oom",
1052 .data = &sysctl_panic_on_oom,
1053 .maxlen = sizeof(sysctl_panic_on_oom),
1054 .mode = 0644,
1055 .proc_handler = &proc_dointvec,
1056 },
1057 {
David Rientjesfe071d72007-10-16 23:25:56 -07001058 .ctl_name = CTL_UNNUMBERED,
1059 .procname = "oom_kill_allocating_task",
1060 .data = &sysctl_oom_kill_allocating_task,
1061 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1062 .mode = 0644,
1063 .proc_handler = &proc_dointvec,
1064 },
1065 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001066 .ctl_name = CTL_UNNUMBERED,
1067 .procname = "oom_dump_tasks",
1068 .data = &sysctl_oom_dump_tasks,
1069 .maxlen = sizeof(sysctl_oom_dump_tasks),
1070 .mode = 0644,
1071 .proc_handler = &proc_dointvec,
1072 },
1073 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 .ctl_name = VM_OVERCOMMIT_RATIO,
1075 .procname = "overcommit_ratio",
1076 .data = &sysctl_overcommit_ratio,
1077 .maxlen = sizeof(sysctl_overcommit_ratio),
1078 .mode = 0644,
1079 .proc_handler = &proc_dointvec,
1080 },
1081 {
1082 .ctl_name = VM_PAGE_CLUSTER,
1083 .procname = "page-cluster",
1084 .data = &page_cluster,
1085 .maxlen = sizeof(int),
1086 .mode = 0644,
1087 .proc_handler = &proc_dointvec,
1088 },
1089 {
1090 .ctl_name = VM_DIRTY_BACKGROUND,
1091 .procname = "dirty_background_ratio",
1092 .data = &dirty_background_ratio,
1093 .maxlen = sizeof(dirty_background_ratio),
1094 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001095 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 .strategy = &sysctl_intvec,
1097 .extra1 = &zero,
1098 .extra2 = &one_hundred,
1099 },
1100 {
David Rientjes2da02992009-01-06 14:39:31 -08001101 .ctl_name = CTL_UNNUMBERED,
1102 .procname = "dirty_background_bytes",
1103 .data = &dirty_background_bytes,
1104 .maxlen = sizeof(dirty_background_bytes),
1105 .mode = 0644,
1106 .proc_handler = &dirty_background_bytes_handler,
1107 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001108 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001109 },
1110 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 .ctl_name = VM_DIRTY_RATIO,
1112 .procname = "dirty_ratio",
1113 .data = &vm_dirty_ratio,
1114 .maxlen = sizeof(vm_dirty_ratio),
1115 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001116 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 .strategy = &sysctl_intvec,
1118 .extra1 = &zero,
1119 .extra2 = &one_hundred,
1120 },
1121 {
David Rientjes2da02992009-01-06 14:39:31 -08001122 .ctl_name = CTL_UNNUMBERED,
1123 .procname = "dirty_bytes",
1124 .data = &vm_dirty_bytes,
1125 .maxlen = sizeof(vm_dirty_bytes),
1126 .mode = 0644,
1127 .proc_handler = &dirty_bytes_handler,
1128 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001129 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001130 },
1131 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001133 .data = &dirty_writeback_interval,
1134 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 .mode = 0644,
1136 .proc_handler = &dirty_writeback_centisecs_handler,
1137 },
1138 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001140 .data = &dirty_expire_interval,
1141 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001143 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 },
1145 {
1146 .ctl_name = VM_NR_PDFLUSH_THREADS,
1147 .procname = "nr_pdflush_threads",
1148 .data = &nr_pdflush_threads,
1149 .maxlen = sizeof nr_pdflush_threads,
1150 .mode = 0444 /* read-only*/,
1151 .proc_handler = &proc_dointvec,
1152 },
1153 {
1154 .ctl_name = VM_SWAPPINESS,
1155 .procname = "swappiness",
1156 .data = &vm_swappiness,
1157 .maxlen = sizeof(vm_swappiness),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec_minmax,
1160 .strategy = &sysctl_intvec,
1161 .extra1 = &zero,
1162 .extra2 = &one_hundred,
1163 },
1164#ifdef CONFIG_HUGETLB_PAGE
1165 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001167 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 .maxlen = sizeof(unsigned long),
1169 .mode = 0644,
1170 .proc_handler = &hugetlb_sysctl_handler,
1171 .extra1 = (void *)&hugetlb_zero,
1172 .extra2 = (void *)&hugetlb_infinity,
1173 },
1174 {
1175 .ctl_name = VM_HUGETLB_GROUP,
1176 .procname = "hugetlb_shm_group",
1177 .data = &sysctl_hugetlb_shm_group,
1178 .maxlen = sizeof(gid_t),
1179 .mode = 0644,
1180 .proc_handler = &proc_dointvec,
1181 },
Mel Gorman396faf02007-07-17 04:03:13 -07001182 {
1183 .ctl_name = CTL_UNNUMBERED,
1184 .procname = "hugepages_treat_as_movable",
1185 .data = &hugepages_treat_as_movable,
1186 .maxlen = sizeof(int),
1187 .mode = 0644,
1188 .proc_handler = &hugetlb_treat_movable_handler,
1189 },
Adam Litke54f9f802007-10-16 01:26:20 -07001190 {
1191 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001192 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001193 .data = NULL,
1194 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001195 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001196 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001197 .extra1 = (void *)&hugetlb_zero,
1198 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001199 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200#endif
1201 {
1202 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1203 .procname = "lowmem_reserve_ratio",
1204 .data = &sysctl_lowmem_reserve_ratio,
1205 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1206 .mode = 0644,
1207 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1208 .strategy = &sysctl_intvec,
1209 },
1210 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001211 .ctl_name = VM_DROP_PAGECACHE,
1212 .procname = "drop_caches",
1213 .data = &sysctl_drop_caches,
1214 .maxlen = sizeof(int),
1215 .mode = 0644,
1216 .proc_handler = drop_caches_sysctl_handler,
1217 .strategy = &sysctl_intvec,
1218 },
1219 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 .ctl_name = VM_MIN_FREE_KBYTES,
1221 .procname = "min_free_kbytes",
1222 .data = &min_free_kbytes,
1223 .maxlen = sizeof(min_free_kbytes),
1224 .mode = 0644,
1225 .proc_handler = &min_free_kbytes_sysctl_handler,
1226 .strategy = &sysctl_intvec,
1227 .extra1 = &zero,
1228 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001229 {
1230 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1231 .procname = "percpu_pagelist_fraction",
1232 .data = &percpu_pagelist_fraction,
1233 .maxlen = sizeof(percpu_pagelist_fraction),
1234 .mode = 0644,
1235 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1236 .strategy = &sysctl_intvec,
1237 .extra1 = &min_percpu_pagelist_fract,
1238 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239#ifdef CONFIG_MMU
1240 {
1241 .ctl_name = VM_MAX_MAP_COUNT,
1242 .procname = "max_map_count",
1243 .data = &sysctl_max_map_count,
1244 .maxlen = sizeof(sysctl_max_map_count),
1245 .mode = 0644,
1246 .proc_handler = &proc_dointvec
1247 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001248#else
1249 {
1250 .ctl_name = CTL_UNNUMBERED,
1251 .procname = "nr_trim_pages",
1252 .data = &sysctl_nr_trim_pages,
1253 .maxlen = sizeof(sysctl_nr_trim_pages),
1254 .mode = 0644,
1255 .proc_handler = &proc_dointvec_minmax,
1256 .strategy = &sysctl_intvec,
1257 .extra1 = &zero,
1258 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259#endif
1260 {
1261 .ctl_name = VM_LAPTOP_MODE,
1262 .procname = "laptop_mode",
1263 .data = &laptop_mode,
1264 .maxlen = sizeof(laptop_mode),
1265 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001266 .proc_handler = &proc_dointvec_jiffies,
1267 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 },
1269 {
1270 .ctl_name = VM_BLOCK_DUMP,
1271 .procname = "block_dump",
1272 .data = &block_dump,
1273 .maxlen = sizeof(block_dump),
1274 .mode = 0644,
1275 .proc_handler = &proc_dointvec,
1276 .strategy = &sysctl_intvec,
1277 .extra1 = &zero,
1278 },
1279 {
1280 .ctl_name = VM_VFS_CACHE_PRESSURE,
1281 .procname = "vfs_cache_pressure",
1282 .data = &sysctl_vfs_cache_pressure,
1283 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1284 .mode = 0644,
1285 .proc_handler = &proc_dointvec,
1286 .strategy = &sysctl_intvec,
1287 .extra1 = &zero,
1288 },
1289#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1290 {
1291 .ctl_name = VM_LEGACY_VA_LAYOUT,
1292 .procname = "legacy_va_layout",
1293 .data = &sysctl_legacy_va_layout,
1294 .maxlen = sizeof(sysctl_legacy_va_layout),
1295 .mode = 0644,
1296 .proc_handler = &proc_dointvec,
1297 .strategy = &sysctl_intvec,
1298 .extra1 = &zero,
1299 },
1300#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001301#ifdef CONFIG_NUMA
1302 {
1303 .ctl_name = VM_ZONE_RECLAIM_MODE,
1304 .procname = "zone_reclaim_mode",
1305 .data = &zone_reclaim_mode,
1306 .maxlen = sizeof(zone_reclaim_mode),
1307 .mode = 0644,
1308 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001309 .strategy = &sysctl_intvec,
1310 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001311 },
Christoph Lameter96146342006-07-03 00:24:13 -07001312 {
1313 .ctl_name = VM_MIN_UNMAPPED,
1314 .procname = "min_unmapped_ratio",
1315 .data = &sysctl_min_unmapped_ratio,
1316 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1317 .mode = 0644,
1318 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1319 .strategy = &sysctl_intvec,
1320 .extra1 = &zero,
1321 .extra2 = &one_hundred,
1322 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001323 {
1324 .ctl_name = VM_MIN_SLAB,
1325 .procname = "min_slab_ratio",
1326 .data = &sysctl_min_slab_ratio,
1327 .maxlen = sizeof(sysctl_min_slab_ratio),
1328 .mode = 0644,
1329 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1330 .strategy = &sysctl_intvec,
1331 .extra1 = &zero,
1332 .extra2 = &one_hundred,
1333 },
Christoph Lameter17436602006-01-18 17:42:32 -08001334#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001335#ifdef CONFIG_SMP
1336 {
1337 .ctl_name = CTL_UNNUMBERED,
1338 .procname = "stat_interval",
1339 .data = &sysctl_stat_interval,
1340 .maxlen = sizeof(sysctl_stat_interval),
1341 .mode = 0644,
1342 .proc_handler = &proc_dointvec_jiffies,
1343 .strategy = &sysctl_jiffies,
1344 },
1345#endif
Eric Parised032182007-06-28 15:55:21 -04001346 {
1347 .ctl_name = CTL_UNNUMBERED,
1348 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001349 .data = &dac_mmap_min_addr,
1350 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001351 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001352 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001353 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001354#ifdef CONFIG_NUMA
1355 {
1356 .ctl_name = CTL_UNNUMBERED,
1357 .procname = "numa_zonelist_order",
1358 .data = &numa_zonelist_order,
1359 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1360 .mode = 0644,
1361 .proc_handler = &numa_zonelist_order_handler,
1362 .strategy = &sysctl_string,
1363 },
1364#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001365#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001366 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001367 {
1368 .ctl_name = VM_VDSO_ENABLED,
1369 .procname = "vdso_enabled",
1370 .data = &vdso_enabled,
1371 .maxlen = sizeof(vdso_enabled),
1372 .mode = 0644,
1373 .proc_handler = &proc_dointvec,
1374 .strategy = &sysctl_intvec,
1375 .extra1 = &zero,
1376 },
1377#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001378#ifdef CONFIG_HIGHMEM
1379 {
1380 .ctl_name = CTL_UNNUMBERED,
1381 .procname = "highmem_is_dirtyable",
1382 .data = &vm_highmem_is_dirtyable,
1383 .maxlen = sizeof(vm_highmem_is_dirtyable),
1384 .mode = 0644,
1385 .proc_handler = &proc_dointvec_minmax,
1386 .strategy = &sysctl_intvec,
1387 .extra1 = &zero,
1388 .extra2 = &one,
1389 },
1390#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001391 {
1392 .ctl_name = CTL_UNNUMBERED,
1393 .procname = "scan_unevictable_pages",
1394 .data = &scan_unevictable_pages,
1395 .maxlen = sizeof(scan_unevictable_pages),
1396 .mode = 0644,
1397 .proc_handler = &scan_unevictable_handler,
1398 },
Andi Kleen6a460792009-09-16 11:50:15 +02001399#ifdef CONFIG_MEMORY_FAILURE
1400 {
1401 .ctl_name = CTL_UNNUMBERED,
1402 .procname = "memory_failure_early_kill",
1403 .data = &sysctl_memory_failure_early_kill,
1404 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1405 .mode = 0644,
1406 .proc_handler = &proc_dointvec_minmax,
1407 .strategy = &sysctl_intvec,
1408 .extra1 = &zero,
1409 .extra2 = &one,
1410 },
1411 {
1412 .ctl_name = CTL_UNNUMBERED,
1413 .procname = "memory_failure_recovery",
1414 .data = &sysctl_memory_failure_recovery,
1415 .maxlen = sizeof(sysctl_memory_failure_recovery),
1416 .mode = 0644,
1417 .proc_handler = &proc_dointvec_minmax,
1418 .strategy = &sysctl_intvec,
1419 .extra1 = &zero,
1420 .extra2 = &one,
1421 },
1422#endif
1423
Andrew Morton2be7fe02007-07-15 23:41:21 -07001424/*
1425 * NOTE: do not add new entries to this table unless you have read
1426 * Documentation/sysctl/ctl_unnumbered.txt
1427 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 { .ctl_name = 0 }
1429};
1430
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001431#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001432static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001433 { .ctl_name = 0 }
1434};
1435#endif
1436
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001437static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 {
1439 .ctl_name = FS_NRINODE,
1440 .procname = "inode-nr",
1441 .data = &inodes_stat,
1442 .maxlen = 2*sizeof(int),
1443 .mode = 0444,
1444 .proc_handler = &proc_dointvec,
1445 },
1446 {
1447 .ctl_name = FS_STATINODE,
1448 .procname = "inode-state",
1449 .data = &inodes_stat,
1450 .maxlen = 7*sizeof(int),
1451 .mode = 0444,
1452 .proc_handler = &proc_dointvec,
1453 },
1454 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 .procname = "file-nr",
1456 .data = &files_stat,
1457 .maxlen = 3*sizeof(int),
1458 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001459 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 },
1461 {
1462 .ctl_name = FS_MAXFILE,
1463 .procname = "file-max",
1464 .data = &files_stat.max_files,
1465 .maxlen = sizeof(int),
1466 .mode = 0644,
1467 .proc_handler = &proc_dointvec,
1468 },
1469 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001470 .ctl_name = CTL_UNNUMBERED,
1471 .procname = "nr_open",
1472 .data = &sysctl_nr_open,
1473 .maxlen = sizeof(int),
1474 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001475 .proc_handler = &proc_dointvec_minmax,
1476 .extra1 = &sysctl_nr_open_min,
1477 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001478 },
1479 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 .ctl_name = FS_DENTRY,
1481 .procname = "dentry-state",
1482 .data = &dentry_stat,
1483 .maxlen = 6*sizeof(int),
1484 .mode = 0444,
1485 .proc_handler = &proc_dointvec,
1486 },
1487 {
1488 .ctl_name = FS_OVERFLOWUID,
1489 .procname = "overflowuid",
1490 .data = &fs_overflowuid,
1491 .maxlen = sizeof(int),
1492 .mode = 0644,
1493 .proc_handler = &proc_dointvec_minmax,
1494 .strategy = &sysctl_intvec,
1495 .extra1 = &minolduid,
1496 .extra2 = &maxolduid,
1497 },
1498 {
1499 .ctl_name = FS_OVERFLOWGID,
1500 .procname = "overflowgid",
1501 .data = &fs_overflowgid,
1502 .maxlen = sizeof(int),
1503 .mode = 0644,
1504 .proc_handler = &proc_dointvec_minmax,
1505 .strategy = &sysctl_intvec,
1506 .extra1 = &minolduid,
1507 .extra2 = &maxolduid,
1508 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001509#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 {
1511 .ctl_name = FS_LEASES,
1512 .procname = "leases-enable",
1513 .data = &leases_enable,
1514 .maxlen = sizeof(int),
1515 .mode = 0644,
1516 .proc_handler = &proc_dointvec,
1517 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001518#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519#ifdef CONFIG_DNOTIFY
1520 {
1521 .ctl_name = FS_DIR_NOTIFY,
1522 .procname = "dir-notify-enable",
1523 .data = &dir_notify_enable,
1524 .maxlen = sizeof(int),
1525 .mode = 0644,
1526 .proc_handler = &proc_dointvec,
1527 },
1528#endif
1529#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001530#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 {
1532 .ctl_name = FS_LEASE_TIME,
1533 .procname = "lease-break-time",
1534 .data = &lease_break_time,
1535 .maxlen = sizeof(int),
1536 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001537 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001539#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001540#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 .procname = "aio-nr",
1543 .data = &aio_nr,
1544 .maxlen = sizeof(aio_nr),
1545 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001546 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 },
1548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 .procname = "aio-max-nr",
1550 .data = &aio_max_nr,
1551 .maxlen = sizeof(aio_max_nr),
1552 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001553 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001555#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001556#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001557 {
1558 .ctl_name = FS_INOTIFY,
1559 .procname = "inotify",
1560 .mode = 0555,
1561 .child = inotify_table,
1562 },
1563#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001564#ifdef CONFIG_EPOLL
1565 {
1566 .procname = "epoll",
1567 .mode = 0555,
1568 .child = epoll_table,
1569 },
1570#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001572 {
1573 .ctl_name = KERN_SETUID_DUMPABLE,
1574 .procname = "suid_dumpable",
1575 .data = &suid_dumpable,
1576 .maxlen = sizeof(int),
1577 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001578 .proc_handler = &proc_dointvec_minmax,
1579 .strategy = &sysctl_intvec,
1580 .extra1 = &zero,
1581 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001582 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001583#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1584 {
1585 .ctl_name = CTL_UNNUMBERED,
1586 .procname = "binfmt_misc",
1587 .mode = 0555,
1588 .child = binfmt_misc_table,
1589 },
1590#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001591/*
1592 * NOTE: do not add new entries to this table unless you have read
1593 * Documentation/sysctl/ctl_unnumbered.txt
1594 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 { .ctl_name = 0 }
1596};
1597
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001598static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001599#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001600 {
1601 .ctl_name = CTL_UNNUMBERED,
1602 .procname = "exception-trace",
1603 .data = &show_unhandled_signals,
1604 .maxlen = sizeof(int),
1605 .mode = 0644,
1606 .proc_handler = proc_dointvec
1607 },
1608#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 { .ctl_name = 0 }
1610};
1611
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001612static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001614};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Al Viro330d57f2005-11-04 10:18:40 +00001616static DEFINE_SPINLOCK(sysctl_lock);
1617
1618/* called under sysctl_lock */
1619static int use_table(struct ctl_table_header *p)
1620{
1621 if (unlikely(p->unregistering))
1622 return 0;
1623 p->used++;
1624 return 1;
1625}
1626
1627/* called under sysctl_lock */
1628static void unuse_table(struct ctl_table_header *p)
1629{
1630 if (!--p->used)
1631 if (unlikely(p->unregistering))
1632 complete(p->unregistering);
1633}
1634
1635/* called under sysctl_lock, will reacquire if has to wait */
1636static void start_unregistering(struct ctl_table_header *p)
1637{
1638 /*
1639 * if p->used is 0, nobody will ever touch that entry again;
1640 * we'll eliminate all paths to it before dropping sysctl_lock
1641 */
1642 if (unlikely(p->used)) {
1643 struct completion wait;
1644 init_completion(&wait);
1645 p->unregistering = &wait;
1646 spin_unlock(&sysctl_lock);
1647 wait_for_completion(&wait);
1648 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001649 } else {
1650 /* anything non-NULL; we'll never dereference it */
1651 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001652 }
1653 /*
1654 * do not remove from the list until nobody holds it; walking the
1655 * list in do_sysctl() relies on that.
1656 */
1657 list_del_init(&p->ctl_entry);
1658}
1659
Al Virof7e6ced2008-07-15 01:44:23 -04001660void sysctl_head_get(struct ctl_table_header *head)
1661{
1662 spin_lock(&sysctl_lock);
1663 head->count++;
1664 spin_unlock(&sysctl_lock);
1665}
1666
1667void sysctl_head_put(struct ctl_table_header *head)
1668{
1669 spin_lock(&sysctl_lock);
1670 if (!--head->count)
1671 kfree(head);
1672 spin_unlock(&sysctl_lock);
1673}
1674
1675struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1676{
1677 if (!head)
1678 BUG();
1679 spin_lock(&sysctl_lock);
1680 if (!use_table(head))
1681 head = ERR_PTR(-ENOENT);
1682 spin_unlock(&sysctl_lock);
1683 return head;
1684}
1685
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001686void sysctl_head_finish(struct ctl_table_header *head)
1687{
1688 if (!head)
1689 return;
1690 spin_lock(&sysctl_lock);
1691 unuse_table(head);
1692 spin_unlock(&sysctl_lock);
1693}
1694
Al Viro73455092008-07-14 21:22:20 -04001695static struct ctl_table_set *
1696lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1697{
1698 struct ctl_table_set *set = &root->default_set;
1699 if (root->lookup)
1700 set = root->lookup(root, namespaces);
1701 return set;
1702}
1703
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001704static struct list_head *
1705lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001706{
Al Viro73455092008-07-14 21:22:20 -04001707 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1708 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001709}
1710
1711struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1712 struct ctl_table_header *prev)
1713{
1714 struct ctl_table_root *root;
1715 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001716 struct ctl_table_header *head;
1717 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001718
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001719 spin_lock(&sysctl_lock);
1720 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001721 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001722 tmp = &prev->ctl_entry;
1723 unuse_table(prev);
1724 goto next;
1725 }
1726 tmp = &root_table_header.ctl_entry;
1727 for (;;) {
1728 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1729
1730 if (!use_table(head))
1731 goto next;
1732 spin_unlock(&sysctl_lock);
1733 return head;
1734 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001735 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001736 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001737 header_list = lookup_header_list(root, namespaces);
1738 if (tmp != header_list)
1739 continue;
1740
1741 do {
1742 root = list_entry(root->root_list.next,
1743 struct ctl_table_root, root_list);
1744 if (root == &sysctl_table_root)
1745 goto out;
1746 header_list = lookup_header_list(root, namespaces);
1747 } while (list_empty(header_list));
1748 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001749 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001750out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001751 spin_unlock(&sysctl_lock);
1752 return NULL;
1753}
1754
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001755struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1756{
1757 return __sysctl_head_next(current->nsproxy, prev);
1758}
1759
1760void register_sysctl_root(struct ctl_table_root *root)
1761{
1762 spin_lock(&sysctl_lock);
1763 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1764 spin_unlock(&sysctl_lock);
1765}
1766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001768 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 * some sysctl variables are readonly even to root.
1770 */
1771
1772static int test_perm(int mode, int op)
1773{
David Howells76aac0e2008-11-14 10:39:12 +11001774 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 mode >>= 6;
1776 else if (in_egroup_p(0))
1777 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001778 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 return 0;
1780 return -EACCES;
1781}
1782
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001783int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
1785 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001786 int mode;
1787
Al Viroe6305c42008-07-15 21:03:57 -04001788 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 if (error)
1790 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001791
1792 if (root->permissions)
1793 mode = root->permissions(root, current->nsproxy, table);
1794 else
1795 mode = table->mode;
1796
1797 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798}
1799
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001800static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1801{
1802 for (; table->ctl_name || table->procname; table++) {
1803 table->parent = parent;
1804 if (table->child)
1805 sysctl_set_parent(table, table->child);
1806 }
1807}
1808
1809static __init int sysctl_init(void)
1810{
1811 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001812#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1813 {
1814 int err;
1815 err = sysctl_check_table(current->nsproxy, root_table);
1816 }
1817#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001818 return 0;
1819}
1820
1821core_initcall(sysctl_init);
1822
Al Virobfbcf032008-07-27 06:31:22 +01001823static struct ctl_table *is_branch_in(struct ctl_table *branch,
1824 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001825{
1826 struct ctl_table *p;
1827 const char *s = branch->procname;
1828
1829 /* branch should have named subdirectory as its first element */
1830 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001831 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001832
1833 /* ... and nothing else */
1834 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001835 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001836
1837 /* table should contain subdirectory with the same name */
1838 for (p = table; p->procname || p->ctl_name; p++) {
1839 if (!p->child)
1840 continue;
1841 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001842 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001843 }
Al Virobfbcf032008-07-27 06:31:22 +01001844 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001845}
1846
1847/* see if attaching q to p would be an improvement */
1848static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1849{
1850 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001851 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001852 int is_better = 0;
1853 int not_in_parent = !p->attached_by;
1854
Al Virobfbcf032008-07-27 06:31:22 +01001855 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001856 if (by == q->attached_by)
1857 is_better = 1;
1858 if (to == p->attached_by)
1859 not_in_parent = 1;
1860 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001861 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001862 }
1863
1864 if (is_better && not_in_parent) {
1865 q->attached_by = by;
1866 q->attached_to = to;
1867 q->parent = p;
1868 }
1869}
1870
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001872 * __register_sysctl_paths - register a sysctl hierarchy
1873 * @root: List of sysctl headers to register on
1874 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001875 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 *
1878 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001879 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001881 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 *
1883 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1884 * must be unique within that level of sysctl
1885 *
1886 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1887 * enter a sysctl file
1888 *
1889 * data - a pointer to data for use by proc_handler
1890 *
1891 * maxlen - the maximum size in bytes of the data
1892 *
1893 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1894 *
1895 * child - a pointer to the child sysctl table if this entry is a directory, or
1896 * %NULL.
1897 *
1898 * proc_handler - the text handler routine (described below)
1899 *
1900 * strategy - the strategy routine (described below)
1901 *
1902 * de - for internal use by the sysctl routines
1903 *
1904 * extra1, extra2 - extra pointers usable by the proc handler routines
1905 *
1906 * Leaf nodes in the sysctl tree will be represented by a single file
1907 * under /proc; non-leaf nodes will be represented by directories.
1908 *
1909 * sysctl(2) can automatically manage read and write requests through
1910 * the sysctl table. The data and maxlen fields of the ctl_table
1911 * struct enable minimal validation of the values being written to be
1912 * performed, and the mode field allows minimal authentication.
1913 *
1914 * More sophisticated management can be enabled by the provision of a
1915 * strategy routine with the table entry. This will be called before
1916 * any automatic read or write of the data is performed.
1917 *
1918 * The strategy routine may return
1919 *
1920 * < 0 - Error occurred (error is passed to user process)
1921 *
1922 * 0 - OK - proceed with automatic read or write.
1923 *
1924 * > 0 - OK - read or write has been done by the strategy routine, so
1925 * return immediately.
1926 *
1927 * There must be a proc_handler routine for any terminal nodes
1928 * mirrored under /proc/sys (non-terminals are handled by a built-in
1929 * directory handler). Several default handlers are available to
1930 * cover common cases -
1931 *
1932 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1933 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1934 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1935 *
1936 * It is the handler's job to read the input buffer from user memory
1937 * and process it. The handler should return 0 on success.
1938 *
1939 * This routine returns %NULL on a failure to register, and a pointer
1940 * to the table header on success.
1941 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001942struct ctl_table_header *__register_sysctl_paths(
1943 struct ctl_table_root *root,
1944 struct nsproxy *namespaces,
1945 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001947 struct ctl_table_header *header;
1948 struct ctl_table *new, **prevp;
1949 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001950 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001951
1952 /* Count the path components */
1953 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1954 ;
1955
1956 /*
1957 * For each path component, allocate a 2-element ctl_table array.
1958 * The first array element will be filled with the sysctl entry
1959 * for this, the second will be the sentinel (ctl_name == 0).
1960 *
1961 * We allocate everything in one go so that we don't have to
1962 * worry about freeing additional memory in unregister_sysctl_table.
1963 */
1964 header = kzalloc(sizeof(struct ctl_table_header) +
1965 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1966 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001968
1969 new = (struct ctl_table *) (header + 1);
1970
1971 /* Now connect the dots */
1972 prevp = &header->ctl_table;
1973 for (n = 0; n < npath; ++n, ++path) {
1974 /* Copy the procname */
1975 new->procname = path->procname;
1976 new->ctl_name = path->ctl_name;
1977 new->mode = 0555;
1978
1979 *prevp = new;
1980 prevp = &new->child;
1981
1982 new += 2;
1983 }
1984 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001985 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001986
1987 INIT_LIST_HEAD(&header->ctl_entry);
1988 header->used = 0;
1989 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001990 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001991 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001992 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001993#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001994 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001995 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001996 return NULL;
1997 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001998#endif
Al Viro330d57f2005-11-04 10:18:40 +00001999 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002000 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002001 header->attached_by = header->ctl_table;
2002 header->attached_to = root_table;
2003 header->parent = &root_table_header;
2004 for (set = header->set; set; set = set->parent) {
2005 struct ctl_table_header *p;
2006 list_for_each_entry(p, &set->list, ctl_entry) {
2007 if (p->unregistering)
2008 continue;
2009 try_attach(p, header);
2010 }
2011 }
2012 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002013 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002014 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002015
2016 return header;
2017}
2018
2019/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002020 * register_sysctl_table_path - register a sysctl table hierarchy
2021 * @path: The path to the directory the sysctl table is in.
2022 * @table: the top-level table structure
2023 *
2024 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2025 * array. A completely 0 filled entry terminates the table.
2026 *
2027 * See __register_sysctl_paths for more details.
2028 */
2029struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2030 struct ctl_table *table)
2031{
2032 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2033 path, table);
2034}
2035
2036/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002037 * register_sysctl_table - register a sysctl table hierarchy
2038 * @table: the top-level table structure
2039 *
2040 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2041 * array. A completely 0 filled entry terminates the table.
2042 *
2043 * See register_sysctl_paths for more details.
2044 */
2045struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2046{
2047 static const struct ctl_path null_path[] = { {} };
2048
2049 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050}
2051
2052/**
2053 * unregister_sysctl_table - unregister a sysctl table hierarchy
2054 * @header: the header returned from register_sysctl_table
2055 *
2056 * Unregisters the sysctl table and all children. proc entries may not
2057 * actually be removed until they are no longer used by anyone.
2058 */
2059void unregister_sysctl_table(struct ctl_table_header * header)
2060{
Al Viro330d57f2005-11-04 10:18:40 +00002061 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002062
2063 if (header == NULL)
2064 return;
2065
Al Viro330d57f2005-11-04 10:18:40 +00002066 spin_lock(&sysctl_lock);
2067 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002068 if (!--header->parent->count) {
2069 WARN_ON(1);
2070 kfree(header->parent);
2071 }
Al Virof7e6ced2008-07-15 01:44:23 -04002072 if (!--header->count)
2073 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002074 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075}
2076
Al Viro9043476f2008-07-15 08:54:06 -04002077int sysctl_is_seen(struct ctl_table_header *p)
2078{
2079 struct ctl_table_set *set = p->set;
2080 int res;
2081 spin_lock(&sysctl_lock);
2082 if (p->unregistering)
2083 res = 0;
2084 else if (!set->is_seen)
2085 res = 1;
2086 else
2087 res = set->is_seen(set);
2088 spin_unlock(&sysctl_lock);
2089 return res;
2090}
2091
Al Viro73455092008-07-14 21:22:20 -04002092void setup_sysctl_set(struct ctl_table_set *p,
2093 struct ctl_table_set *parent,
2094 int (*is_seen)(struct ctl_table_set *))
2095{
2096 INIT_LIST_HEAD(&p->list);
2097 p->parent = parent ? parent : &sysctl_table_root.default_set;
2098 p->is_seen = is_seen;
2099}
2100
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002101#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002102struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002103{
2104 return NULL;
2105}
2106
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002107struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2108 struct ctl_table *table)
2109{
2110 return NULL;
2111}
2112
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002113void unregister_sysctl_table(struct ctl_table_header * table)
2114{
2115}
2116
Al Viro73455092008-07-14 21:22:20 -04002117void setup_sysctl_set(struct ctl_table_set *p,
2118 struct ctl_table_set *parent,
2119 int (*is_seen)(struct ctl_table_set *))
2120{
2121}
2122
Al Virof7e6ced2008-07-15 01:44:23 -04002123void sysctl_head_put(struct ctl_table_header *head)
2124{
2125}
2126
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002127#endif /* CONFIG_SYSCTL */
2128
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129/*
2130 * /proc/sys support
2131 */
2132
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002133#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002135static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002136 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002137 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002138{
2139 size_t len;
2140 char __user *p;
2141 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002142
2143 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002144 *lenp = 0;
2145 return 0;
2146 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002147
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002148 if (write) {
2149 len = 0;
2150 p = buffer;
2151 while (len < *lenp) {
2152 if (get_user(c, p++))
2153 return -EFAULT;
2154 if (c == 0 || c == '\n')
2155 break;
2156 len++;
2157 }
2158 if (len >= maxlen)
2159 len = maxlen-1;
2160 if(copy_from_user(data, buffer, len))
2161 return -EFAULT;
2162 ((char *) data)[len] = 0;
2163 *ppos += *lenp;
2164 } else {
2165 len = strlen(data);
2166 if (len > maxlen)
2167 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002168
2169 if (*ppos > len) {
2170 *lenp = 0;
2171 return 0;
2172 }
2173
2174 data += *ppos;
2175 len -= *ppos;
2176
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002177 if (len > *lenp)
2178 len = *lenp;
2179 if (len)
2180 if(copy_to_user(buffer, data, len))
2181 return -EFAULT;
2182 if (len < *lenp) {
2183 if(put_user('\n', ((char __user *) buffer) + len))
2184 return -EFAULT;
2185 len++;
2186 }
2187 *lenp = len;
2188 *ppos += len;
2189 }
2190 return 0;
2191}
2192
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193/**
2194 * proc_dostring - read a string sysctl
2195 * @table: the sysctl table
2196 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 * @buffer: the user buffer
2198 * @lenp: the size of the user buffer
2199 * @ppos: file position
2200 *
2201 * Reads/writes a string from/to the user buffer. If the kernel
2202 * buffer provided is not large enough to hold the string, the
2203 * string is truncated. The copied string is %NULL-terminated.
2204 * If the string is being read by the user process, it is copied
2205 * and a newline '\n' is added. It is truncated if the buffer is
2206 * not large enough.
2207 *
2208 * Returns 0 on success.
2209 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002210int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 void __user *buffer, size_t *lenp, loff_t *ppos)
2212{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002213 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002214 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215}
2216
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
2218static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2219 int *valp,
2220 int write, void *data)
2221{
2222 if (write) {
2223 *valp = *negp ? -*lvalp : *lvalp;
2224 } else {
2225 int val = *valp;
2226 if (val < 0) {
2227 *negp = -1;
2228 *lvalp = (unsigned long)-val;
2229 } else {
2230 *negp = 0;
2231 *lvalp = (unsigned long)val;
2232 }
2233 }
2234 return 0;
2235}
2236
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002237static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002238 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002239 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2241 int write, void *data),
2242 void *data)
2243{
2244#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002245 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 unsigned long lval;
2247 size_t left, len;
2248
2249 char buf[TMPBUFLEN], *p;
2250 char __user *s = buffer;
2251
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002252 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 (*ppos && !write)) {
2254 *lenp = 0;
2255 return 0;
2256 }
2257
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002258 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 vleft = table->maxlen / sizeof(*i);
2260 left = *lenp;
2261
2262 if (!conv)
2263 conv = do_proc_dointvec_conv;
2264
2265 for (; left && vleft--; i++, first=0) {
2266 if (write) {
2267 while (left) {
2268 char c;
2269 if (get_user(c, s))
2270 return -EFAULT;
2271 if (!isspace(c))
2272 break;
2273 left--;
2274 s++;
2275 }
2276 if (!left)
2277 break;
2278 neg = 0;
2279 len = left;
2280 if (len > sizeof(buf) - 1)
2281 len = sizeof(buf) - 1;
2282 if (copy_from_user(buf, s, len))
2283 return -EFAULT;
2284 buf[len] = 0;
2285 p = buf;
2286 if (*p == '-' && left > 1) {
2287 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002288 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 }
2290 if (*p < '0' || *p > '9')
2291 break;
2292
2293 lval = simple_strtoul(p, &p, 0);
2294
2295 len = p-buf;
2296 if ((len < left) && *p && !isspace(*p))
2297 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 s += len;
2299 left -= len;
2300
2301 if (conv(&neg, &lval, i, 1, data))
2302 break;
2303 } else {
2304 p = buf;
2305 if (!first)
2306 *p++ = '\t';
2307
2308 if (conv(&neg, &lval, i, 0, data))
2309 break;
2310
2311 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2312 len = strlen(buf);
2313 if (len > left)
2314 len = left;
2315 if(copy_to_user(s, buf, len))
2316 return -EFAULT;
2317 left -= len;
2318 s += len;
2319 }
2320 }
2321
2322 if (!write && !first && left) {
2323 if(put_user('\n', s))
2324 return -EFAULT;
2325 left--, s++;
2326 }
2327 if (write) {
2328 while (left) {
2329 char c;
2330 if (get_user(c, s++))
2331 return -EFAULT;
2332 if (!isspace(c))
2333 break;
2334 left--;
2335 }
2336 }
2337 if (write && first)
2338 return -EINVAL;
2339 *lenp -= left;
2340 *ppos += *lenp;
2341 return 0;
2342#undef TMPBUFLEN
2343}
2344
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002345static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002346 void __user *buffer, size_t *lenp, loff_t *ppos,
2347 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2348 int write, void *data),
2349 void *data)
2350{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002351 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002352 buffer, lenp, ppos, conv, data);
2353}
2354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355/**
2356 * proc_dointvec - read a vector of integers
2357 * @table: the sysctl table
2358 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 * @buffer: the user buffer
2360 * @lenp: the size of the user buffer
2361 * @ppos: file position
2362 *
2363 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2364 * values from/to the user buffer, treated as an ASCII string.
2365 *
2366 * Returns 0 on success.
2367 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002368int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 void __user *buffer, size_t *lenp, loff_t *ppos)
2370{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002371 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 NULL,NULL);
2373}
2374
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002375/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002376 * Taint values can only be increased
2377 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002378 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002379static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002380 void __user *buffer, size_t *lenp, loff_t *ppos)
2381{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002382 struct ctl_table t;
2383 unsigned long tmptaint = get_taint();
2384 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002385
Bastian Blank91fcd412007-04-23 14:41:14 -07002386 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002387 return -EPERM;
2388
Andi Kleen25ddbb12008-10-15 22:01:41 -07002389 t = *table;
2390 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002391 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002392 if (err < 0)
2393 return err;
2394
2395 if (write) {
2396 /*
2397 * Poor man's atomic or. Not worth adding a primitive
2398 * to everyone's atomic.h for this
2399 */
2400 int i;
2401 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2402 if ((tmptaint >> i) & 1)
2403 add_taint(i);
2404 }
2405 }
2406
2407 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002408}
2409
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410struct do_proc_dointvec_minmax_conv_param {
2411 int *min;
2412 int *max;
2413};
2414
2415static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2416 int *valp,
2417 int write, void *data)
2418{
2419 struct do_proc_dointvec_minmax_conv_param *param = data;
2420 if (write) {
2421 int val = *negp ? -*lvalp : *lvalp;
2422 if ((param->min && *param->min > val) ||
2423 (param->max && *param->max < val))
2424 return -EINVAL;
2425 *valp = val;
2426 } else {
2427 int val = *valp;
2428 if (val < 0) {
2429 *negp = -1;
2430 *lvalp = (unsigned long)-val;
2431 } else {
2432 *negp = 0;
2433 *lvalp = (unsigned long)val;
2434 }
2435 }
2436 return 0;
2437}
2438
2439/**
2440 * proc_dointvec_minmax - read a vector of integers with min/max values
2441 * @table: the sysctl table
2442 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 * @buffer: the user buffer
2444 * @lenp: the size of the user buffer
2445 * @ppos: file position
2446 *
2447 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2448 * values from/to the user buffer, treated as an ASCII string.
2449 *
2450 * This routine will ensure the values are within the range specified by
2451 * table->extra1 (min) and table->extra2 (max).
2452 *
2453 * Returns 0 on success.
2454 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002455int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 void __user *buffer, size_t *lenp, loff_t *ppos)
2457{
2458 struct do_proc_dointvec_minmax_conv_param param = {
2459 .min = (int *) table->extra1,
2460 .max = (int *) table->extra2,
2461 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002462 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 do_proc_dointvec_minmax_conv, &param);
2464}
2465
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002466static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 void __user *buffer,
2468 size_t *lenp, loff_t *ppos,
2469 unsigned long convmul,
2470 unsigned long convdiv)
2471{
2472#define TMPBUFLEN 21
2473 unsigned long *i, *min, *max, val;
2474 int vleft, first=1, neg;
2475 size_t len, left;
2476 char buf[TMPBUFLEN], *p;
2477 char __user *s = buffer;
2478
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002479 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 (*ppos && !write)) {
2481 *lenp = 0;
2482 return 0;
2483 }
2484
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002485 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 min = (unsigned long *) table->extra1;
2487 max = (unsigned long *) table->extra2;
2488 vleft = table->maxlen / sizeof(unsigned long);
2489 left = *lenp;
2490
2491 for (; left && vleft--; i++, min++, max++, first=0) {
2492 if (write) {
2493 while (left) {
2494 char c;
2495 if (get_user(c, s))
2496 return -EFAULT;
2497 if (!isspace(c))
2498 break;
2499 left--;
2500 s++;
2501 }
2502 if (!left)
2503 break;
2504 neg = 0;
2505 len = left;
2506 if (len > TMPBUFLEN-1)
2507 len = TMPBUFLEN-1;
2508 if (copy_from_user(buf, s, len))
2509 return -EFAULT;
2510 buf[len] = 0;
2511 p = buf;
2512 if (*p == '-' && left > 1) {
2513 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002514 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 }
2516 if (*p < '0' || *p > '9')
2517 break;
2518 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2519 len = p-buf;
2520 if ((len < left) && *p && !isspace(*p))
2521 break;
2522 if (neg)
2523 val = -val;
2524 s += len;
2525 left -= len;
2526
2527 if(neg)
2528 continue;
2529 if ((min && val < *min) || (max && val > *max))
2530 continue;
2531 *i = val;
2532 } else {
2533 p = buf;
2534 if (!first)
2535 *p++ = '\t';
2536 sprintf(p, "%lu", convdiv * (*i) / convmul);
2537 len = strlen(buf);
2538 if (len > left)
2539 len = left;
2540 if(copy_to_user(s, buf, len))
2541 return -EFAULT;
2542 left -= len;
2543 s += len;
2544 }
2545 }
2546
2547 if (!write && !first && left) {
2548 if(put_user('\n', s))
2549 return -EFAULT;
2550 left--, s++;
2551 }
2552 if (write) {
2553 while (left) {
2554 char c;
2555 if (get_user(c, s++))
2556 return -EFAULT;
2557 if (!isspace(c))
2558 break;
2559 left--;
2560 }
2561 }
2562 if (write && first)
2563 return -EINVAL;
2564 *lenp -= left;
2565 *ppos += *lenp;
2566 return 0;
2567#undef TMPBUFLEN
2568}
2569
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002570static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002571 void __user *buffer,
2572 size_t *lenp, loff_t *ppos,
2573 unsigned long convmul,
2574 unsigned long convdiv)
2575{
2576 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002577 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002578}
2579
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580/**
2581 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2582 * @table: the sysctl table
2583 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 * @buffer: the user buffer
2585 * @lenp: the size of the user buffer
2586 * @ppos: file position
2587 *
2588 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2589 * values from/to the user buffer, treated as an ASCII string.
2590 *
2591 * This routine will ensure the values are within the range specified by
2592 * table->extra1 (min) and table->extra2 (max).
2593 *
2594 * Returns 0 on success.
2595 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002596int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 void __user *buffer, size_t *lenp, loff_t *ppos)
2598{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002599 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600}
2601
2602/**
2603 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2604 * @table: the sysctl table
2605 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 * @buffer: the user buffer
2607 * @lenp: the size of the user buffer
2608 * @ppos: file position
2609 *
2610 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2611 * values from/to the user buffer, treated as an ASCII string. The values
2612 * are treated as milliseconds, and converted to jiffies when they are stored.
2613 *
2614 * This routine will ensure the values are within the range specified by
2615 * table->extra1 (min) and table->extra2 (max).
2616 *
2617 * Returns 0 on success.
2618 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002619int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 void __user *buffer,
2621 size_t *lenp, loff_t *ppos)
2622{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002623 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 lenp, ppos, HZ, 1000l);
2625}
2626
2627
2628static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2629 int *valp,
2630 int write, void *data)
2631{
2632 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002633 if (*lvalp > LONG_MAX / HZ)
2634 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2636 } else {
2637 int val = *valp;
2638 unsigned long lval;
2639 if (val < 0) {
2640 *negp = -1;
2641 lval = (unsigned long)-val;
2642 } else {
2643 *negp = 0;
2644 lval = (unsigned long)val;
2645 }
2646 *lvalp = lval / HZ;
2647 }
2648 return 0;
2649}
2650
2651static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2652 int *valp,
2653 int write, void *data)
2654{
2655 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002656 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2657 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2659 } else {
2660 int val = *valp;
2661 unsigned long lval;
2662 if (val < 0) {
2663 *negp = -1;
2664 lval = (unsigned long)-val;
2665 } else {
2666 *negp = 0;
2667 lval = (unsigned long)val;
2668 }
2669 *lvalp = jiffies_to_clock_t(lval);
2670 }
2671 return 0;
2672}
2673
2674static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2675 int *valp,
2676 int write, void *data)
2677{
2678 if (write) {
2679 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2680 } else {
2681 int val = *valp;
2682 unsigned long lval;
2683 if (val < 0) {
2684 *negp = -1;
2685 lval = (unsigned long)-val;
2686 } else {
2687 *negp = 0;
2688 lval = (unsigned long)val;
2689 }
2690 *lvalp = jiffies_to_msecs(lval);
2691 }
2692 return 0;
2693}
2694
2695/**
2696 * proc_dointvec_jiffies - read a vector of integers as seconds
2697 * @table: the sysctl table
2698 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 * @buffer: the user buffer
2700 * @lenp: the size of the user buffer
2701 * @ppos: file position
2702 *
2703 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2704 * values from/to the user buffer, treated as an ASCII string.
2705 * The values read are assumed to be in seconds, and are converted into
2706 * jiffies.
2707 *
2708 * Returns 0 on success.
2709 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002710int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 void __user *buffer, size_t *lenp, loff_t *ppos)
2712{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002713 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 do_proc_dointvec_jiffies_conv,NULL);
2715}
2716
2717/**
2718 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2719 * @table: the sysctl table
2720 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 * @buffer: the user buffer
2722 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002723 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 *
2725 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2726 * values from/to the user buffer, treated as an ASCII string.
2727 * The values read are assumed to be in 1/USER_HZ seconds, and
2728 * are converted into jiffies.
2729 *
2730 * Returns 0 on success.
2731 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002732int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 void __user *buffer, size_t *lenp, loff_t *ppos)
2734{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002735 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 do_proc_dointvec_userhz_jiffies_conv,NULL);
2737}
2738
2739/**
2740 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2741 * @table: the sysctl table
2742 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 * @buffer: the user buffer
2744 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002745 * @ppos: file position
2746 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 *
2748 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2749 * values from/to the user buffer, treated as an ASCII string.
2750 * The values read are assumed to be in 1/1000 seconds, and
2751 * are converted into jiffies.
2752 *
2753 * Returns 0 on success.
2754 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002755int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 void __user *buffer, size_t *lenp, loff_t *ppos)
2757{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002758 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 do_proc_dointvec_ms_jiffies_conv, NULL);
2760}
2761
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002762static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002763 void __user *buffer, size_t *lenp, loff_t *ppos)
2764{
2765 struct pid *new_pid;
2766 pid_t tmp;
2767 int r;
2768
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002769 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002770
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002771 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002772 lenp, ppos, NULL, NULL);
2773 if (r || !write)
2774 return r;
2775
2776 new_pid = find_get_pid(tmp);
2777 if (!new_pid)
2778 return -ESRCH;
2779
2780 put_pid(xchg(&cad_pid, new_pid));
2781 return 0;
2782}
2783
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784#else /* CONFIG_PROC_FS */
2785
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002786int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 void __user *buffer, size_t *lenp, loff_t *ppos)
2788{
2789 return -ENOSYS;
2790}
2791
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002792int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 void __user *buffer, size_t *lenp, loff_t *ppos)
2794{
2795 return -ENOSYS;
2796}
2797
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002798int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 void __user *buffer, size_t *lenp, loff_t *ppos)
2800{
2801 return -ENOSYS;
2802}
2803
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002804int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 void __user *buffer, size_t *lenp, loff_t *ppos)
2806{
2807 return -ENOSYS;
2808}
2809
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002810int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 void __user *buffer, size_t *lenp, loff_t *ppos)
2812{
2813 return -ENOSYS;
2814}
2815
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002816int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 void __user *buffer, size_t *lenp, loff_t *ppos)
2818{
2819 return -ENOSYS;
2820}
2821
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002822int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 void __user *buffer, size_t *lenp, loff_t *ppos)
2824{
2825 return -ENOSYS;
2826}
2827
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002828int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 void __user *buffer,
2830 size_t *lenp, loff_t *ppos)
2831{
2832 return -ENOSYS;
2833}
2834
2835
2836#endif /* CONFIG_PROC_FS */
2837
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002838int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002839 void __user *oldval, size_t __user *oldlenp,
2840 void __user *newval, size_t newlen)
2841{
2842 return -ENOSYS;
2843}
2844
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002845int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002847 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848{
2849 return -ENOSYS;
2850}
2851
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002852int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002854 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855{
2856 return -ENOSYS;
2857}
2858
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002859int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002861 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862{
2863 return -ENOSYS;
2864}
2865
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002866int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002868 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869{
2870 return -ENOSYS;
2871}
2872
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873/*
2874 * No sense putting this after each symbol definition, twice,
2875 * exception granted :-)
2876 */
2877EXPORT_SYMBOL(proc_dointvec);
2878EXPORT_SYMBOL(proc_dointvec_jiffies);
2879EXPORT_SYMBOL(proc_dointvec_minmax);
2880EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2881EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2882EXPORT_SYMBOL(proc_dostring);
2883EXPORT_SYMBOL(proc_doulongvec_minmax);
2884EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2885EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002886EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887EXPORT_SYMBOL(sysctl_intvec);
2888EXPORT_SYMBOL(sysctl_jiffies);
2889EXPORT_SYMBOL(sysctl_ms_jiffies);
2890EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002891EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892EXPORT_SYMBOL(unregister_sysctl_table);