blob: 4dbf93a52ee9f0734d694e5227e6b7f9c1b7f0b2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020029#include <linux/kmemcheck.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020039#include <linux/ratelimit.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070042#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/times.h>
44#include <linux/limits.h>
45#include <linux/dcache.h>
46#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070047#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080048#include <linux/nfs_fs.h>
49#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070050#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020051#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010052#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020053#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#include <asm/uaccess.h>
56#include <asm/processor.h>
57
Andi Kleen29cbc782006-09-30 01:47:55 +020058#ifdef CONFIG_X86
59#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010060#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010061#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020062#endif
63
Eric W. Biederman7058cb02007-10-18 03:05:58 -070064static int deprecated_sysctl_warning(struct __sysctl_args *args);
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#if defined(CONFIG_SYSCTL)
67
68/* External variables not in a header file. */
69extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070070extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int sysctl_overcommit_memory;
72extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070073extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070074extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080075extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070078extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070080extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern int pid_max;
82extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080084extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080085extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020086extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010087extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040088extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000089#ifndef CONFIG_MMU
90extern int sysctl_nr_trim_pages;
91#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070092#ifdef CONFIG_RCU_TORTURE_TEST
93extern int rcutorture_runnable;
94#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Jens Axboecb684b52009-09-15 21:53:11 +020095#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +020096extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +020097#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -0800100#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700101static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200102static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103#endif
104
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700105static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700106static int __maybe_unused one = 1;
107static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800108static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700109static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700110#ifdef CONFIG_PRINTK
111static int ten_thousand = 10000;
112#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700114/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
115static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
118static int maxolduid = 65535;
119static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800120static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122static int ngroups_max = NGROUPS_MAX;
123
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200124#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700126extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef CONFIG_CHR_DEV_SG
129extern int sg_big_buff;
130#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
David S. Miller72c57ed2008-09-11 23:29:54 -0700132#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700133#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
David S. Miller08714202008-11-16 23:49:24 -0800136#ifdef CONFIG_SPARC64
137extern int sysctl_tsb_ratio;
138#endif
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef __hppa__
141extern int pwrsw_enabled;
142extern int unaligned_enabled;
143#endif
144
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800145#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef CONFIG_MATHEMU
147extern int sysctl_ieee_emulation_warnings;
148#endif
149extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700150extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#ifdef CONFIG_BSD_PROCESS_ACCT
154extern int acct_parm[];
155#endif
156
Jes Sorensend2b176e2006-02-28 09:42:23 -0800157#ifdef CONFIG_IA64
158extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800159extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800160#endif
161
Ingo Molnar3fff4c42009-09-22 16:18:09 +0200162extern struct ratelimit_state printk_ratelimit_state;
163
Ingo Molnar23f78d42006-06-27 02:54:53 -0700164#ifdef CONFIG_RT_MUTEXES
165extern int max_lock_depth;
166#endif
167
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700168#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700169static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700171static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800172 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700173#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700174
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700175static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176static struct ctl_table_root sysctl_table_root;
177static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100178 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100179 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400180 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100181 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400182 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100183};
184static struct ctl_table_root sysctl_table_root = {
185 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400186 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100187};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700189static struct ctl_table kern_table[];
190static struct ctl_table vm_table[];
191static struct ctl_table fs_table[];
192static struct ctl_table debug_table[];
193static struct ctl_table dev_table[];
194extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700195#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700196extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400197#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800198#ifdef CONFIG_EPOLL
199extern struct ctl_table epoll_table[];
200#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
203int sysctl_legacy_va_layout;
204#endif
205
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700206extern int prove_locking;
207extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209/* The default sysctl tables: */
210
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700211static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 {
213 .ctl_name = CTL_KERN,
214 .procname = "kernel",
215 .mode = 0555,
216 .child = kern_table,
217 },
218 {
219 .ctl_name = CTL_VM,
220 .procname = "vm",
221 .mode = 0555,
222 .child = vm_table,
223 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 .ctl_name = CTL_FS,
226 .procname = "fs",
227 .mode = 0555,
228 .child = fs_table,
229 },
230 {
231 .ctl_name = CTL_DEBUG,
232 .procname = "debug",
233 .mode = 0555,
234 .child = debug_table,
235 },
236 {
237 .ctl_name = CTL_DEV,
238 .procname = "dev",
239 .mode = 0555,
240 .child = dev_table,
241 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700242/*
243 * NOTE: do not add new entries to this table unless you have read
244 * Documentation/sysctl/ctl_unnumbered.txt
245 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 { .ctl_name = 0 }
247};
248
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100250static int min_sched_granularity_ns = 100000; /* 100 usecs */
251static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
252static int min_wakeup_granularity_ns; /* 0 usecs */
253static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200254#endif
255
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700256static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200257 {
258 .ctl_name = CTL_UNNUMBERED,
259 .procname = "sched_child_runs_first",
260 .data = &sysctl_sched_child_runs_first,
261 .maxlen = sizeof(unsigned int),
262 .mode = 0644,
263 .proc_handler = &proc_dointvec,
264 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200265#ifdef CONFIG_SCHED_DEBUG
266 {
267 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100268 .procname = "sched_min_granularity_ns",
269 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100272 .proc_handler = &sched_nr_latency_handler,
273 .strategy = &sysctl_intvec,
274 .extra1 = &min_sched_granularity_ns,
275 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200276 },
277 {
278 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200279 .procname = "sched_latency_ns",
280 .data = &sysctl_sched_latency,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100283 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200284 .strategy = &sysctl_intvec,
285 .extra1 = &min_sched_granularity_ns,
286 .extra2 = &max_sched_granularity_ns,
287 },
288 {
289 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200290 .procname = "sched_wakeup_granularity_ns",
291 .data = &sysctl_sched_wakeup_granularity,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
296 .extra1 = &min_wakeup_granularity_ns,
297 .extra2 = &max_wakeup_granularity_ns,
298 },
299 {
300 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200301 .procname = "sched_shares_ratelimit",
302 .data = &sysctl_sched_shares_ratelimit,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = &proc_dointvec,
306 },
307 {
308 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200309 .procname = "sched_shares_thresh",
310 .data = &sysctl_sched_shares_thresh,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = &proc_dointvec_minmax,
314 .strategy = &sysctl_intvec,
315 .extra1 = &zero,
316 },
317 {
318 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200319 .procname = "sched_features",
320 .data = &sysctl_sched_features,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
323 .proc_handler = &proc_dointvec,
324 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200325 {
326 .ctl_name = CTL_UNNUMBERED,
327 .procname = "sched_migration_cost",
328 .data = &sysctl_sched_migration_cost,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = &proc_dointvec,
332 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100333 {
334 .ctl_name = CTL_UNNUMBERED,
335 .procname = "sched_nr_migrate",
336 .data = &sysctl_sched_nr_migrate,
337 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530341 {
342 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200343 .procname = "sched_time_avg",
344 .data = &sysctl_sched_time_avg,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
348 },
349 {
350 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530351 .procname = "timer_migration",
352 .data = &sysctl_timer_migration,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530355 .proc_handler = &proc_dointvec_minmax,
356 .strategy = &sysctl_intvec,
357 .extra1 = &zero,
358 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530359 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200360#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200361 {
362 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100363 .procname = "sched_rt_period_us",
364 .data = &sysctl_sched_rt_period,
365 .maxlen = sizeof(unsigned int),
366 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200367 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100368 },
369 {
370 .ctl_name = CTL_UNNUMBERED,
371 .procname = "sched_rt_runtime_us",
372 .data = &sysctl_sched_rt_runtime,
373 .maxlen = sizeof(int),
374 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200375 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100376 },
377 {
378 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200379 .procname = "sched_compat_yield",
380 .data = &sysctl_sched_compat_yield,
381 .maxlen = sizeof(unsigned int),
382 .mode = 0644,
383 .proc_handler = &proc_dointvec,
384 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700385#ifdef CONFIG_PROVE_LOCKING
386 {
387 .ctl_name = CTL_UNNUMBERED,
388 .procname = "prove_locking",
389 .data = &prove_locking,
390 .maxlen = sizeof(int),
391 .mode = 0644,
392 .proc_handler = &proc_dointvec,
393 },
394#endif
395#ifdef CONFIG_LOCK_STAT
396 {
397 .ctl_name = CTL_UNNUMBERED,
398 .procname = "lock_stat",
399 .data = &lock_stat,
400 .maxlen = sizeof(int),
401 .mode = 0644,
402 .proc_handler = &proc_dointvec,
403 },
404#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .ctl_name = KERN_PANIC,
407 .procname = "panic",
408 .data = &panic_timeout,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
412 },
413 {
414 .ctl_name = KERN_CORE_USES_PID,
415 .procname = "core_uses_pid",
416 .data = &core_uses_pid,
417 .maxlen = sizeof(int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
420 },
421 {
422 .ctl_name = KERN_CORE_PATTERN,
423 .procname = "core_pattern",
424 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700425 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 .mode = 0644,
427 .proc_handler = &proc_dostring,
428 .strategy = &sysctl_string,
429 },
Neil Hormana2939802009-09-23 15:56:56 -0700430 {
431 .ctl_name = CTL_UNNUMBERED,
432 .procname = "core_pipe_limit",
433 .data = &core_pipe_limit,
434 .maxlen = sizeof(unsigned int),
435 .mode = 0644,
436 .proc_handler = &proc_dointvec,
437 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800438#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700441 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800442 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700443 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800445#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100446#ifdef CONFIG_LATENCYTOP
447 {
448 .procname = "latencytop",
449 .data = &latencytop_enabled,
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
453 },
454#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#ifdef CONFIG_BLK_DEV_INITRD
456 {
457 .ctl_name = KERN_REALROOTDEV,
458 .procname = "real-root-dev",
459 .data = &real_root_dev,
460 .maxlen = sizeof(int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
463 },
464#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700465 {
466 .ctl_name = CTL_UNNUMBERED,
467 .procname = "print-fatal-signals",
468 .data = &print_fatal_signals,
469 .maxlen = sizeof(int),
470 .mode = 0644,
471 .proc_handler = &proc_dointvec,
472 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700473#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 {
475 .ctl_name = KERN_SPARC_REBOOT,
476 .procname = "reboot-cmd",
477 .data = reboot_command,
478 .maxlen = 256,
479 .mode = 0644,
480 .proc_handler = &proc_dostring,
481 .strategy = &sysctl_string,
482 },
483 {
484 .ctl_name = KERN_SPARC_STOP_A,
485 .procname = "stop-a",
486 .data = &stop_a_enabled,
487 .maxlen = sizeof (int),
488 .mode = 0644,
489 .proc_handler = &proc_dointvec,
490 },
491 {
492 .ctl_name = KERN_SPARC_SCONS_PWROFF,
493 .procname = "scons-poweroff",
494 .data = &scons_pwroff,
495 .maxlen = sizeof (int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
498 },
499#endif
David S. Miller08714202008-11-16 23:49:24 -0800500#ifdef CONFIG_SPARC64
501 {
502 .ctl_name = CTL_UNNUMBERED,
503 .procname = "tsb-ratio",
504 .data = &sysctl_tsb_ratio,
505 .maxlen = sizeof (int),
506 .mode = 0644,
507 .proc_handler = &proc_dointvec,
508 },
509#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510#ifdef __hppa__
511 {
512 .ctl_name = KERN_HPPA_PWRSW,
513 .procname = "soft-power",
514 .data = &pwrsw_enabled,
515 .maxlen = sizeof (int),
516 .mode = 0644,
517 .proc_handler = &proc_dointvec,
518 },
519 {
520 .ctl_name = KERN_HPPA_UNALIGNED,
521 .procname = "unaligned-trap",
522 .data = &unaligned_enabled,
523 .maxlen = sizeof (int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec,
526 },
527#endif
528 {
529 .ctl_name = KERN_CTLALTDEL,
530 .procname = "ctrl-alt-del",
531 .data = &C_A_D,
532 .maxlen = sizeof(int),
533 .mode = 0644,
534 .proc_handler = &proc_dointvec,
535 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400536#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200537 {
538 .ctl_name = CTL_UNNUMBERED,
539 .procname = "ftrace_enabled",
540 .data = &ftrace_enabled,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = &ftrace_enable_sysctl,
544 },
545#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500546#ifdef CONFIG_STACK_TRACER
547 {
548 .ctl_name = CTL_UNNUMBERED,
549 .procname = "stack_tracer_enabled",
550 .data = &stack_tracer_enabled,
551 .maxlen = sizeof(int),
552 .mode = 0644,
553 .proc_handler = &stack_trace_sysctl,
554 },
555#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400556#ifdef CONFIG_TRACING
557 {
558 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100559 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400560 .data = &ftrace_dump_on_oops,
561 .maxlen = sizeof(int),
562 .mode = 0644,
563 .proc_handler = &proc_dointvec,
564 },
565#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200566#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 {
568 .ctl_name = KERN_MODPROBE,
569 .procname = "modprobe",
570 .data = &modprobe_path,
571 .maxlen = KMOD_PATH_LEN,
572 .mode = 0644,
573 .proc_handler = &proc_dostring,
574 .strategy = &sysctl_string,
575 },
Kees Cook3d433212009-04-02 15:49:29 -0700576 {
577 .ctl_name = CTL_UNNUMBERED,
578 .procname = "modules_disabled",
579 .data = &modules_disabled,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 /* only handle a transition from default "0" to "1" */
583 .proc_handler = &proc_dointvec_minmax,
584 .extra1 = &one,
585 .extra2 = &one,
586 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700588#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 {
590 .ctl_name = KERN_HOTPLUG,
591 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100592 .data = &uevent_helper,
593 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .mode = 0644,
595 .proc_handler = &proc_dostring,
596 .strategy = &sysctl_string,
597 },
598#endif
599#ifdef CONFIG_CHR_DEV_SG
600 {
601 .ctl_name = KERN_SG_BIG_BUFF,
602 .procname = "sg-big-buff",
603 .data = &sg_big_buff,
604 .maxlen = sizeof (int),
605 .mode = 0444,
606 .proc_handler = &proc_dointvec,
607 },
608#endif
609#ifdef CONFIG_BSD_PROCESS_ACCT
610 {
611 .ctl_name = KERN_ACCT,
612 .procname = "acct",
613 .data = &acct_parm,
614 .maxlen = 3*sizeof(int),
615 .mode = 0644,
616 .proc_handler = &proc_dointvec,
617 },
618#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619#ifdef CONFIG_MAGIC_SYSRQ
620 {
621 .ctl_name = KERN_SYSRQ,
622 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800623 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 .maxlen = sizeof (int),
625 .mode = 0644,
626 .proc_handler = &proc_dointvec,
627 },
628#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700629#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700632 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 .maxlen = sizeof (int),
634 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700635 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700637#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 {
639 .ctl_name = KERN_MAX_THREADS,
640 .procname = "threads-max",
641 .data = &max_threads,
642 .maxlen = sizeof(int),
643 .mode = 0644,
644 .proc_handler = &proc_dointvec,
645 },
646 {
647 .ctl_name = KERN_RANDOM,
648 .procname = "random",
649 .mode = 0555,
650 .child = random_table,
651 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 {
653 .ctl_name = KERN_OVERFLOWUID,
654 .procname = "overflowuid",
655 .data = &overflowuid,
656 .maxlen = sizeof(int),
657 .mode = 0644,
658 .proc_handler = &proc_dointvec_minmax,
659 .strategy = &sysctl_intvec,
660 .extra1 = &minolduid,
661 .extra2 = &maxolduid,
662 },
663 {
664 .ctl_name = KERN_OVERFLOWGID,
665 .procname = "overflowgid",
666 .data = &overflowgid,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = &proc_dointvec_minmax,
670 .strategy = &sysctl_intvec,
671 .extra1 = &minolduid,
672 .extra2 = &maxolduid,
673 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800674#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#ifdef CONFIG_MATHEMU
676 {
677 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
678 .procname = "ieee_emulation_warnings",
679 .data = &sysctl_ieee_emulation_warnings,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
683 },
684#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 {
686 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
687 .procname = "userprocess_debug",
688 .data = &sysctl_userprocess_debug,
689 .maxlen = sizeof(int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec,
692 },
693#endif
694 {
695 .ctl_name = KERN_PIDMAX,
696 .procname = "pid_max",
697 .data = &pid_max,
698 .maxlen = sizeof (int),
699 .mode = 0644,
700 .proc_handler = &proc_dointvec_minmax,
701 .strategy = sysctl_intvec,
702 .extra1 = &pid_max_min,
703 .extra2 = &pid_max_max,
704 },
705 {
706 .ctl_name = KERN_PANIC_ON_OOPS,
707 .procname = "panic_on_oops",
708 .data = &panic_on_oops,
709 .maxlen = sizeof(int),
710 .mode = 0644,
711 .proc_handler = &proc_dointvec,
712 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800713#if defined CONFIG_PRINTK
714 {
715 .ctl_name = KERN_PRINTK,
716 .procname = "printk",
717 .data = &console_loglevel,
718 .maxlen = 4*sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
721 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 {
723 .ctl_name = KERN_PRINTK_RATELIMIT,
724 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700725 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .maxlen = sizeof(int),
727 .mode = 0644,
728 .proc_handler = &proc_dointvec_jiffies,
729 .strategy = &sysctl_jiffies,
730 },
731 {
732 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
733 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700734 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
738 },
Dave Youngaf913222009-09-22 16:43:33 -0700739 {
740 .ctl_name = CTL_UNNUMBERED,
741 .procname = "printk_delay",
742 .data = &printk_delay_msec,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = &proc_dointvec_minmax,
746 .strategy = &sysctl_intvec,
747 .extra1 = &zero,
748 .extra2 = &ten_thousand,
749 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800750#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 {
752 .ctl_name = KERN_NGROUPS_MAX,
753 .procname = "ngroups_max",
754 .data = &ngroups_max,
755 .maxlen = sizeof (int),
756 .mode = 0444,
757 .proc_handler = &proc_dointvec,
758 },
759#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
760 {
761 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
762 .procname = "unknown_nmi_panic",
763 .data = &unknown_nmi_panic,
764 .maxlen = sizeof (int),
765 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200766 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 },
Don Zickus407984f2006-09-26 10:52:27 +0200768 {
Don Zickus407984f2006-09-26 10:52:27 +0200769 .procname = "nmi_watchdog",
770 .data = &nmi_watchdog_enabled,
771 .maxlen = sizeof (int),
772 .mode = 0644,
773 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 },
775#endif
776#if defined(CONFIG_X86)
777 {
Don Zickus8da5add2006-09-26 10:52:27 +0200778 .ctl_name = KERN_PANIC_ON_NMI,
779 .procname = "panic_on_unrecovered_nmi",
780 .data = &panic_on_unrecovered_nmi,
781 .maxlen = sizeof(int),
782 .mode = 0644,
783 .proc_handler = &proc_dointvec,
784 },
785 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700786 .ctl_name = CTL_UNNUMBERED,
787 .procname = "panic_on_io_nmi",
788 .data = &panic_on_io_nmi,
789 .maxlen = sizeof(int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
792 },
793 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .ctl_name = KERN_BOOTLOADER_TYPE,
795 .procname = "bootloader_type",
796 .data = &bootloader_type,
797 .maxlen = sizeof (int),
798 .mode = 0444,
799 .proc_handler = &proc_dointvec,
800 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100801 {
802 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700803 .procname = "bootloader_version",
804 .data = &bootloader_version,
805 .maxlen = sizeof (int),
806 .mode = 0444,
807 .proc_handler = &proc_dointvec,
808 },
809 {
810 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100811 .procname = "kstack_depth_to_print",
812 .data = &kstack_depth_to_print,
813 .maxlen = sizeof(int),
814 .mode = 0644,
815 .proc_handler = &proc_dointvec,
816 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100817 {
818 .ctl_name = CTL_UNNUMBERED,
819 .procname = "io_delay_type",
820 .data = &io_delay_type,
821 .maxlen = sizeof(int),
822 .mode = 0644,
823 .proc_handler = &proc_dointvec,
824 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800826#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 {
828 .ctl_name = KERN_RANDOMIZE,
829 .procname = "randomize_va_space",
830 .data = &randomize_va_space,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec,
834 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800835#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800836#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700837 {
838 .ctl_name = KERN_SPIN_RETRY,
839 .procname = "spin_retry",
840 .data = &spin_retry,
841 .maxlen = sizeof (int),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
844 },
845#endif
Len Brown673d5b42007-07-28 03:33:16 -0400846#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800847 {
Pavel Machekc255d842006-02-20 18:27:58 -0800848 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700849 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800850 .maxlen = sizeof (unsigned long),
851 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800852 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800853 },
854#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800855#ifdef CONFIG_IA64
856 {
857 .ctl_name = KERN_IA64_UNALIGNED,
858 .procname = "ignore-unaligned-usertrap",
859 .data = &no_unaligned_warning,
860 .maxlen = sizeof (int),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec,
863 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800864 {
865 .ctl_name = CTL_UNNUMBERED,
866 .procname = "unaligned-dump-stack",
867 .data = &unaligned_dump_stack,
868 .maxlen = sizeof (int),
869 .mode = 0644,
870 .proc_handler = &proc_dointvec,
871 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800872#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700873#ifdef CONFIG_DETECT_SOFTLOCKUP
874 {
875 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200876 .procname = "softlockup_panic",
877 .data = &softlockup_panic,
878 .maxlen = sizeof(int),
879 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700880 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200881 .strategy = &sysctl_intvec,
882 .extra1 = &zero,
883 .extra2 = &one,
884 },
885 {
886 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700887 .procname = "softlockup_thresh",
888 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200889 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700890 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800891 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700892 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200893 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700894 .extra2 = &sixty,
895 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800896#endif
897#ifdef CONFIG_DETECT_HUNG_TASK
898 {
899 .ctl_name = CTL_UNNUMBERED,
900 .procname = "hung_task_panic",
901 .data = &sysctl_hung_task_panic,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = &proc_dointvec_minmax,
905 .strategy = &sysctl_intvec,
906 .extra1 = &zero,
907 .extra2 = &one,
908 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100909 {
910 .ctl_name = CTL_UNNUMBERED,
911 .procname = "hung_task_check_count",
912 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100913 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100914 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100915 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100916 .strategy = &sysctl_intvec,
917 },
918 {
919 .ctl_name = CTL_UNNUMBERED,
920 .procname = "hung_task_timeout_secs",
921 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100922 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100923 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800924 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100925 .strategy = &sysctl_intvec,
926 },
927 {
928 .ctl_name = CTL_UNNUMBERED,
929 .procname = "hung_task_warnings",
930 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100931 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100932 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100933 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100934 .strategy = &sysctl_intvec,
935 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700936#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200937#ifdef CONFIG_COMPAT
938 {
939 .ctl_name = KERN_COMPAT_LOG,
940 .procname = "compat-log",
941 .data = &compat_log,
942 .maxlen = sizeof (int),
943 .mode = 0644,
944 .proc_handler = &proc_dointvec,
945 },
946#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700947#ifdef CONFIG_RT_MUTEXES
948 {
949 .ctl_name = KERN_MAX_LOCK_DEPTH,
950 .procname = "max_lock_depth",
951 .data = &max_lock_depth,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
955 },
956#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700957 {
958 .ctl_name = CTL_UNNUMBERED,
959 .procname = "poweroff_cmd",
960 .data = &poweroff_cmd,
961 .maxlen = POWEROFF_CMD_PATH_LEN,
962 .mode = 0644,
963 .proc_handler = &proc_dostring,
964 .strategy = &sysctl_string,
965 },
David Howells0b77f5b2008-04-29 01:01:32 -0700966#ifdef CONFIG_KEYS
967 {
968 .ctl_name = CTL_UNNUMBERED,
969 .procname = "keys",
970 .mode = 0555,
971 .child = key_sysctls,
972 },
973#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700974#ifdef CONFIG_RCU_TORTURE_TEST
975 {
976 .ctl_name = CTL_UNNUMBERED,
977 .procname = "rcutorture_runnable",
978 .data = &rcutorture_runnable,
979 .maxlen = sizeof(int),
980 .mode = 0644,
981 .proc_handler = &proc_dointvec,
982 },
983#endif
David Howells12e22c52009-04-03 16:42:35 +0100984#ifdef CONFIG_SLOW_WORK
985 {
986 .ctl_name = CTL_UNNUMBERED,
987 .procname = "slow-work",
988 .mode = 0555,
989 .child = slow_work_sysctls,
990 },
991#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200992#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200993 {
994 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200995 .procname = "perf_event_paranoid",
996 .data = &sysctl_perf_event_paranoid,
997 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200998 .mode = 0644,
999 .proc_handler = &proc_dointvec,
1000 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001001 {
1002 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001003 .procname = "perf_event_mlock_kb",
1004 .data = &sysctl_perf_event_mlock,
1005 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001006 .mode = 0644,
1007 .proc_handler = &proc_dointvec,
1008 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001009 {
1010 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001011 .procname = "perf_event_max_sample_rate",
1012 .data = &sysctl_perf_event_sample_rate,
1013 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001014 .mode = 0644,
1015 .proc_handler = &proc_dointvec,
1016 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001017#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001018#ifdef CONFIG_KMEMCHECK
1019 {
1020 .ctl_name = CTL_UNNUMBERED,
1021 .procname = "kmemcheck",
1022 .data = &kmemcheck_enabled,
1023 .maxlen = sizeof(int),
1024 .mode = 0644,
1025 .proc_handler = &proc_dointvec,
1026 },
1027#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001028#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001029 {
1030 .ctl_name = CTL_UNNUMBERED,
1031 .procname = "blk_iopoll",
1032 .data = &blk_iopoll_enabled,
1033 .maxlen = sizeof(int),
1034 .mode = 0644,
1035 .proc_handler = &proc_dointvec,
1036 },
Jens Axboecb684b52009-09-15 21:53:11 +02001037#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001038/*
1039 * NOTE: do not add new entries to this table unless you have read
1040 * Documentation/sysctl/ctl_unnumbered.txt
1041 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 { .ctl_name = 0 }
1043};
1044
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001045static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 {
1047 .ctl_name = VM_OVERCOMMIT_MEMORY,
1048 .procname = "overcommit_memory",
1049 .data = &sysctl_overcommit_memory,
1050 .maxlen = sizeof(sysctl_overcommit_memory),
1051 .mode = 0644,
1052 .proc_handler = &proc_dointvec,
1053 },
1054 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001055 .ctl_name = VM_PANIC_ON_OOM,
1056 .procname = "panic_on_oom",
1057 .data = &sysctl_panic_on_oom,
1058 .maxlen = sizeof(sysctl_panic_on_oom),
1059 .mode = 0644,
1060 .proc_handler = &proc_dointvec,
1061 },
1062 {
David Rientjesfe071d72007-10-16 23:25:56 -07001063 .ctl_name = CTL_UNNUMBERED,
1064 .procname = "oom_kill_allocating_task",
1065 .data = &sysctl_oom_kill_allocating_task,
1066 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1067 .mode = 0644,
1068 .proc_handler = &proc_dointvec,
1069 },
1070 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001071 .ctl_name = CTL_UNNUMBERED,
1072 .procname = "oom_dump_tasks",
1073 .data = &sysctl_oom_dump_tasks,
1074 .maxlen = sizeof(sysctl_oom_dump_tasks),
1075 .mode = 0644,
1076 .proc_handler = &proc_dointvec,
1077 },
1078 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 .ctl_name = VM_OVERCOMMIT_RATIO,
1080 .procname = "overcommit_ratio",
1081 .data = &sysctl_overcommit_ratio,
1082 .maxlen = sizeof(sysctl_overcommit_ratio),
1083 .mode = 0644,
1084 .proc_handler = &proc_dointvec,
1085 },
1086 {
1087 .ctl_name = VM_PAGE_CLUSTER,
1088 .procname = "page-cluster",
1089 .data = &page_cluster,
1090 .maxlen = sizeof(int),
1091 .mode = 0644,
1092 .proc_handler = &proc_dointvec,
1093 },
1094 {
1095 .ctl_name = VM_DIRTY_BACKGROUND,
1096 .procname = "dirty_background_ratio",
1097 .data = &dirty_background_ratio,
1098 .maxlen = sizeof(dirty_background_ratio),
1099 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001100 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 .strategy = &sysctl_intvec,
1102 .extra1 = &zero,
1103 .extra2 = &one_hundred,
1104 },
1105 {
David Rientjes2da02992009-01-06 14:39:31 -08001106 .ctl_name = CTL_UNNUMBERED,
1107 .procname = "dirty_background_bytes",
1108 .data = &dirty_background_bytes,
1109 .maxlen = sizeof(dirty_background_bytes),
1110 .mode = 0644,
1111 .proc_handler = &dirty_background_bytes_handler,
1112 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001113 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001114 },
1115 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 .ctl_name = VM_DIRTY_RATIO,
1117 .procname = "dirty_ratio",
1118 .data = &vm_dirty_ratio,
1119 .maxlen = sizeof(vm_dirty_ratio),
1120 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001121 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 .strategy = &sysctl_intvec,
1123 .extra1 = &zero,
1124 .extra2 = &one_hundred,
1125 },
1126 {
David Rientjes2da02992009-01-06 14:39:31 -08001127 .ctl_name = CTL_UNNUMBERED,
1128 .procname = "dirty_bytes",
1129 .data = &vm_dirty_bytes,
1130 .maxlen = sizeof(vm_dirty_bytes),
1131 .mode = 0644,
1132 .proc_handler = &dirty_bytes_handler,
1133 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001134 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001135 },
1136 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001138 .data = &dirty_writeback_interval,
1139 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 .mode = 0644,
1141 .proc_handler = &dirty_writeback_centisecs_handler,
1142 },
1143 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001145 .data = &dirty_expire_interval,
1146 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001148 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 },
1150 {
1151 .ctl_name = VM_NR_PDFLUSH_THREADS,
1152 .procname = "nr_pdflush_threads",
1153 .data = &nr_pdflush_threads,
1154 .maxlen = sizeof nr_pdflush_threads,
1155 .mode = 0444 /* read-only*/,
1156 .proc_handler = &proc_dointvec,
1157 },
1158 {
1159 .ctl_name = VM_SWAPPINESS,
1160 .procname = "swappiness",
1161 .data = &vm_swappiness,
1162 .maxlen = sizeof(vm_swappiness),
1163 .mode = 0644,
1164 .proc_handler = &proc_dointvec_minmax,
1165 .strategy = &sysctl_intvec,
1166 .extra1 = &zero,
1167 .extra2 = &one_hundred,
1168 },
1169#ifdef CONFIG_HUGETLB_PAGE
1170 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001172 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 .maxlen = sizeof(unsigned long),
1174 .mode = 0644,
1175 .proc_handler = &hugetlb_sysctl_handler,
1176 .extra1 = (void *)&hugetlb_zero,
1177 .extra2 = (void *)&hugetlb_infinity,
1178 },
1179 {
1180 .ctl_name = VM_HUGETLB_GROUP,
1181 .procname = "hugetlb_shm_group",
1182 .data = &sysctl_hugetlb_shm_group,
1183 .maxlen = sizeof(gid_t),
1184 .mode = 0644,
1185 .proc_handler = &proc_dointvec,
1186 },
Mel Gorman396faf02007-07-17 04:03:13 -07001187 {
1188 .ctl_name = CTL_UNNUMBERED,
1189 .procname = "hugepages_treat_as_movable",
1190 .data = &hugepages_treat_as_movable,
1191 .maxlen = sizeof(int),
1192 .mode = 0644,
1193 .proc_handler = &hugetlb_treat_movable_handler,
1194 },
Adam Litke54f9f802007-10-16 01:26:20 -07001195 {
1196 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001197 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001198 .data = NULL,
1199 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001200 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001201 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001202 .extra1 = (void *)&hugetlb_zero,
1203 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001204 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205#endif
1206 {
1207 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1208 .procname = "lowmem_reserve_ratio",
1209 .data = &sysctl_lowmem_reserve_ratio,
1210 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1211 .mode = 0644,
1212 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1213 .strategy = &sysctl_intvec,
1214 },
1215 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001216 .ctl_name = VM_DROP_PAGECACHE,
1217 .procname = "drop_caches",
1218 .data = &sysctl_drop_caches,
1219 .maxlen = sizeof(int),
1220 .mode = 0644,
1221 .proc_handler = drop_caches_sysctl_handler,
1222 .strategy = &sysctl_intvec,
1223 },
1224 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 .ctl_name = VM_MIN_FREE_KBYTES,
1226 .procname = "min_free_kbytes",
1227 .data = &min_free_kbytes,
1228 .maxlen = sizeof(min_free_kbytes),
1229 .mode = 0644,
1230 .proc_handler = &min_free_kbytes_sysctl_handler,
1231 .strategy = &sysctl_intvec,
1232 .extra1 = &zero,
1233 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001234 {
1235 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1236 .procname = "percpu_pagelist_fraction",
1237 .data = &percpu_pagelist_fraction,
1238 .maxlen = sizeof(percpu_pagelist_fraction),
1239 .mode = 0644,
1240 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1241 .strategy = &sysctl_intvec,
1242 .extra1 = &min_percpu_pagelist_fract,
1243 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244#ifdef CONFIG_MMU
1245 {
1246 .ctl_name = VM_MAX_MAP_COUNT,
1247 .procname = "max_map_count",
1248 .data = &sysctl_max_map_count,
1249 .maxlen = sizeof(sysctl_max_map_count),
1250 .mode = 0644,
1251 .proc_handler = &proc_dointvec
1252 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001253#else
1254 {
1255 .ctl_name = CTL_UNNUMBERED,
1256 .procname = "nr_trim_pages",
1257 .data = &sysctl_nr_trim_pages,
1258 .maxlen = sizeof(sysctl_nr_trim_pages),
1259 .mode = 0644,
1260 .proc_handler = &proc_dointvec_minmax,
1261 .strategy = &sysctl_intvec,
1262 .extra1 = &zero,
1263 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264#endif
1265 {
1266 .ctl_name = VM_LAPTOP_MODE,
1267 .procname = "laptop_mode",
1268 .data = &laptop_mode,
1269 .maxlen = sizeof(laptop_mode),
1270 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001271 .proc_handler = &proc_dointvec_jiffies,
1272 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 },
1274 {
1275 .ctl_name = VM_BLOCK_DUMP,
1276 .procname = "block_dump",
1277 .data = &block_dump,
1278 .maxlen = sizeof(block_dump),
1279 .mode = 0644,
1280 .proc_handler = &proc_dointvec,
1281 .strategy = &sysctl_intvec,
1282 .extra1 = &zero,
1283 },
1284 {
1285 .ctl_name = VM_VFS_CACHE_PRESSURE,
1286 .procname = "vfs_cache_pressure",
1287 .data = &sysctl_vfs_cache_pressure,
1288 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1289 .mode = 0644,
1290 .proc_handler = &proc_dointvec,
1291 .strategy = &sysctl_intvec,
1292 .extra1 = &zero,
1293 },
1294#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1295 {
1296 .ctl_name = VM_LEGACY_VA_LAYOUT,
1297 .procname = "legacy_va_layout",
1298 .data = &sysctl_legacy_va_layout,
1299 .maxlen = sizeof(sysctl_legacy_va_layout),
1300 .mode = 0644,
1301 .proc_handler = &proc_dointvec,
1302 .strategy = &sysctl_intvec,
1303 .extra1 = &zero,
1304 },
1305#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001306#ifdef CONFIG_NUMA
1307 {
1308 .ctl_name = VM_ZONE_RECLAIM_MODE,
1309 .procname = "zone_reclaim_mode",
1310 .data = &zone_reclaim_mode,
1311 .maxlen = sizeof(zone_reclaim_mode),
1312 .mode = 0644,
1313 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001314 .strategy = &sysctl_intvec,
1315 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001316 },
Christoph Lameter96146342006-07-03 00:24:13 -07001317 {
1318 .ctl_name = VM_MIN_UNMAPPED,
1319 .procname = "min_unmapped_ratio",
1320 .data = &sysctl_min_unmapped_ratio,
1321 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1322 .mode = 0644,
1323 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1324 .strategy = &sysctl_intvec,
1325 .extra1 = &zero,
1326 .extra2 = &one_hundred,
1327 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001328 {
1329 .ctl_name = VM_MIN_SLAB,
1330 .procname = "min_slab_ratio",
1331 .data = &sysctl_min_slab_ratio,
1332 .maxlen = sizeof(sysctl_min_slab_ratio),
1333 .mode = 0644,
1334 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1335 .strategy = &sysctl_intvec,
1336 .extra1 = &zero,
1337 .extra2 = &one_hundred,
1338 },
Christoph Lameter17436602006-01-18 17:42:32 -08001339#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001340#ifdef CONFIG_SMP
1341 {
1342 .ctl_name = CTL_UNNUMBERED,
1343 .procname = "stat_interval",
1344 .data = &sysctl_stat_interval,
1345 .maxlen = sizeof(sysctl_stat_interval),
1346 .mode = 0644,
1347 .proc_handler = &proc_dointvec_jiffies,
1348 .strategy = &sysctl_jiffies,
1349 },
1350#endif
Eric Parised032182007-06-28 15:55:21 -04001351 {
1352 .ctl_name = CTL_UNNUMBERED,
1353 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001354 .data = &dac_mmap_min_addr,
1355 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001356 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001357 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001358 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001359#ifdef CONFIG_NUMA
1360 {
1361 .ctl_name = CTL_UNNUMBERED,
1362 .procname = "numa_zonelist_order",
1363 .data = &numa_zonelist_order,
1364 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1365 .mode = 0644,
1366 .proc_handler = &numa_zonelist_order_handler,
1367 .strategy = &sysctl_string,
1368 },
1369#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001370#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001371 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001372 {
1373 .ctl_name = VM_VDSO_ENABLED,
1374 .procname = "vdso_enabled",
1375 .data = &vdso_enabled,
1376 .maxlen = sizeof(vdso_enabled),
1377 .mode = 0644,
1378 .proc_handler = &proc_dointvec,
1379 .strategy = &sysctl_intvec,
1380 .extra1 = &zero,
1381 },
1382#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001383#ifdef CONFIG_HIGHMEM
1384 {
1385 .ctl_name = CTL_UNNUMBERED,
1386 .procname = "highmem_is_dirtyable",
1387 .data = &vm_highmem_is_dirtyable,
1388 .maxlen = sizeof(vm_highmem_is_dirtyable),
1389 .mode = 0644,
1390 .proc_handler = &proc_dointvec_minmax,
1391 .strategy = &sysctl_intvec,
1392 .extra1 = &zero,
1393 .extra2 = &one,
1394 },
1395#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001396 {
1397 .ctl_name = CTL_UNNUMBERED,
1398 .procname = "scan_unevictable_pages",
1399 .data = &scan_unevictable_pages,
1400 .maxlen = sizeof(scan_unevictable_pages),
1401 .mode = 0644,
1402 .proc_handler = &scan_unevictable_handler,
1403 },
Andi Kleen6a460792009-09-16 11:50:15 +02001404#ifdef CONFIG_MEMORY_FAILURE
1405 {
1406 .ctl_name = CTL_UNNUMBERED,
1407 .procname = "memory_failure_early_kill",
1408 .data = &sysctl_memory_failure_early_kill,
1409 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1410 .mode = 0644,
1411 .proc_handler = &proc_dointvec_minmax,
1412 .strategy = &sysctl_intvec,
1413 .extra1 = &zero,
1414 .extra2 = &one,
1415 },
1416 {
1417 .ctl_name = CTL_UNNUMBERED,
1418 .procname = "memory_failure_recovery",
1419 .data = &sysctl_memory_failure_recovery,
1420 .maxlen = sizeof(sysctl_memory_failure_recovery),
1421 .mode = 0644,
1422 .proc_handler = &proc_dointvec_minmax,
1423 .strategy = &sysctl_intvec,
1424 .extra1 = &zero,
1425 .extra2 = &one,
1426 },
1427#endif
1428
Andrew Morton2be7fe02007-07-15 23:41:21 -07001429/*
1430 * NOTE: do not add new entries to this table unless you have read
1431 * Documentation/sysctl/ctl_unnumbered.txt
1432 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 { .ctl_name = 0 }
1434};
1435
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001436#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001437static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001438 { .ctl_name = 0 }
1439};
1440#endif
1441
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001442static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 {
1444 .ctl_name = FS_NRINODE,
1445 .procname = "inode-nr",
1446 .data = &inodes_stat,
1447 .maxlen = 2*sizeof(int),
1448 .mode = 0444,
1449 .proc_handler = &proc_dointvec,
1450 },
1451 {
1452 .ctl_name = FS_STATINODE,
1453 .procname = "inode-state",
1454 .data = &inodes_stat,
1455 .maxlen = 7*sizeof(int),
1456 .mode = 0444,
1457 .proc_handler = &proc_dointvec,
1458 },
1459 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 .procname = "file-nr",
1461 .data = &files_stat,
1462 .maxlen = 3*sizeof(int),
1463 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001464 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 },
1466 {
1467 .ctl_name = FS_MAXFILE,
1468 .procname = "file-max",
1469 .data = &files_stat.max_files,
1470 .maxlen = sizeof(int),
1471 .mode = 0644,
1472 .proc_handler = &proc_dointvec,
1473 },
1474 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001475 .ctl_name = CTL_UNNUMBERED,
1476 .procname = "nr_open",
1477 .data = &sysctl_nr_open,
1478 .maxlen = sizeof(int),
1479 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001480 .proc_handler = &proc_dointvec_minmax,
1481 .extra1 = &sysctl_nr_open_min,
1482 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001483 },
1484 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 .ctl_name = FS_DENTRY,
1486 .procname = "dentry-state",
1487 .data = &dentry_stat,
1488 .maxlen = 6*sizeof(int),
1489 .mode = 0444,
1490 .proc_handler = &proc_dointvec,
1491 },
1492 {
1493 .ctl_name = FS_OVERFLOWUID,
1494 .procname = "overflowuid",
1495 .data = &fs_overflowuid,
1496 .maxlen = sizeof(int),
1497 .mode = 0644,
1498 .proc_handler = &proc_dointvec_minmax,
1499 .strategy = &sysctl_intvec,
1500 .extra1 = &minolduid,
1501 .extra2 = &maxolduid,
1502 },
1503 {
1504 .ctl_name = FS_OVERFLOWGID,
1505 .procname = "overflowgid",
1506 .data = &fs_overflowgid,
1507 .maxlen = sizeof(int),
1508 .mode = 0644,
1509 .proc_handler = &proc_dointvec_minmax,
1510 .strategy = &sysctl_intvec,
1511 .extra1 = &minolduid,
1512 .extra2 = &maxolduid,
1513 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001514#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 {
1516 .ctl_name = FS_LEASES,
1517 .procname = "leases-enable",
1518 .data = &leases_enable,
1519 .maxlen = sizeof(int),
1520 .mode = 0644,
1521 .proc_handler = &proc_dointvec,
1522 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001523#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524#ifdef CONFIG_DNOTIFY
1525 {
1526 .ctl_name = FS_DIR_NOTIFY,
1527 .procname = "dir-notify-enable",
1528 .data = &dir_notify_enable,
1529 .maxlen = sizeof(int),
1530 .mode = 0644,
1531 .proc_handler = &proc_dointvec,
1532 },
1533#endif
1534#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001535#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 {
1537 .ctl_name = FS_LEASE_TIME,
1538 .procname = "lease-break-time",
1539 .data = &lease_break_time,
1540 .maxlen = sizeof(int),
1541 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001542 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001544#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001545#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 .procname = "aio-nr",
1548 .data = &aio_nr,
1549 .maxlen = sizeof(aio_nr),
1550 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001551 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 },
1553 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 .procname = "aio-max-nr",
1555 .data = &aio_max_nr,
1556 .maxlen = sizeof(aio_max_nr),
1557 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001558 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001560#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001561#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001562 {
1563 .ctl_name = FS_INOTIFY,
1564 .procname = "inotify",
1565 .mode = 0555,
1566 .child = inotify_table,
1567 },
1568#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001569#ifdef CONFIG_EPOLL
1570 {
1571 .procname = "epoll",
1572 .mode = 0555,
1573 .child = epoll_table,
1574 },
1575#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001577 {
1578 .ctl_name = KERN_SETUID_DUMPABLE,
1579 .procname = "suid_dumpable",
1580 .data = &suid_dumpable,
1581 .maxlen = sizeof(int),
1582 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001583 .proc_handler = &proc_dointvec_minmax,
1584 .strategy = &sysctl_intvec,
1585 .extra1 = &zero,
1586 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001587 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001588#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1589 {
1590 .ctl_name = CTL_UNNUMBERED,
1591 .procname = "binfmt_misc",
1592 .mode = 0555,
1593 .child = binfmt_misc_table,
1594 },
1595#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001596/*
1597 * NOTE: do not add new entries to this table unless you have read
1598 * Documentation/sysctl/ctl_unnumbered.txt
1599 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 { .ctl_name = 0 }
1601};
1602
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001603static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001604#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001605 {
1606 .ctl_name = CTL_UNNUMBERED,
1607 .procname = "exception-trace",
1608 .data = &show_unhandled_signals,
1609 .maxlen = sizeof(int),
1610 .mode = 0644,
1611 .proc_handler = proc_dointvec
1612 },
1613#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 { .ctl_name = 0 }
1615};
1616
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001617static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001619};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Al Viro330d57f2005-11-04 10:18:40 +00001621static DEFINE_SPINLOCK(sysctl_lock);
1622
1623/* called under sysctl_lock */
1624static int use_table(struct ctl_table_header *p)
1625{
1626 if (unlikely(p->unregistering))
1627 return 0;
1628 p->used++;
1629 return 1;
1630}
1631
1632/* called under sysctl_lock */
1633static void unuse_table(struct ctl_table_header *p)
1634{
1635 if (!--p->used)
1636 if (unlikely(p->unregistering))
1637 complete(p->unregistering);
1638}
1639
1640/* called under sysctl_lock, will reacquire if has to wait */
1641static void start_unregistering(struct ctl_table_header *p)
1642{
1643 /*
1644 * if p->used is 0, nobody will ever touch that entry again;
1645 * we'll eliminate all paths to it before dropping sysctl_lock
1646 */
1647 if (unlikely(p->used)) {
1648 struct completion wait;
1649 init_completion(&wait);
1650 p->unregistering = &wait;
1651 spin_unlock(&sysctl_lock);
1652 wait_for_completion(&wait);
1653 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001654 } else {
1655 /* anything non-NULL; we'll never dereference it */
1656 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001657 }
1658 /*
1659 * do not remove from the list until nobody holds it; walking the
1660 * list in do_sysctl() relies on that.
1661 */
1662 list_del_init(&p->ctl_entry);
1663}
1664
Al Virof7e6ced2008-07-15 01:44:23 -04001665void sysctl_head_get(struct ctl_table_header *head)
1666{
1667 spin_lock(&sysctl_lock);
1668 head->count++;
1669 spin_unlock(&sysctl_lock);
1670}
1671
1672void sysctl_head_put(struct ctl_table_header *head)
1673{
1674 spin_lock(&sysctl_lock);
1675 if (!--head->count)
1676 kfree(head);
1677 spin_unlock(&sysctl_lock);
1678}
1679
1680struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1681{
1682 if (!head)
1683 BUG();
1684 spin_lock(&sysctl_lock);
1685 if (!use_table(head))
1686 head = ERR_PTR(-ENOENT);
1687 spin_unlock(&sysctl_lock);
1688 return head;
1689}
1690
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001691void sysctl_head_finish(struct ctl_table_header *head)
1692{
1693 if (!head)
1694 return;
1695 spin_lock(&sysctl_lock);
1696 unuse_table(head);
1697 spin_unlock(&sysctl_lock);
1698}
1699
Al Viro73455092008-07-14 21:22:20 -04001700static struct ctl_table_set *
1701lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1702{
1703 struct ctl_table_set *set = &root->default_set;
1704 if (root->lookup)
1705 set = root->lookup(root, namespaces);
1706 return set;
1707}
1708
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001709static struct list_head *
1710lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001711{
Al Viro73455092008-07-14 21:22:20 -04001712 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1713 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001714}
1715
1716struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1717 struct ctl_table_header *prev)
1718{
1719 struct ctl_table_root *root;
1720 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001721 struct ctl_table_header *head;
1722 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001723
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001724 spin_lock(&sysctl_lock);
1725 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001726 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001727 tmp = &prev->ctl_entry;
1728 unuse_table(prev);
1729 goto next;
1730 }
1731 tmp = &root_table_header.ctl_entry;
1732 for (;;) {
1733 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1734
1735 if (!use_table(head))
1736 goto next;
1737 spin_unlock(&sysctl_lock);
1738 return head;
1739 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001740 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001741 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001742 header_list = lookup_header_list(root, namespaces);
1743 if (tmp != header_list)
1744 continue;
1745
1746 do {
1747 root = list_entry(root->root_list.next,
1748 struct ctl_table_root, root_list);
1749 if (root == &sysctl_table_root)
1750 goto out;
1751 header_list = lookup_header_list(root, namespaces);
1752 } while (list_empty(header_list));
1753 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001754 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001755out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001756 spin_unlock(&sysctl_lock);
1757 return NULL;
1758}
1759
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001760struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1761{
1762 return __sysctl_head_next(current->nsproxy, prev);
1763}
1764
1765void register_sysctl_root(struct ctl_table_root *root)
1766{
1767 spin_lock(&sysctl_lock);
1768 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1769 spin_unlock(&sysctl_lock);
1770}
1771
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001772#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001773/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001774static int do_sysctl_strategy(struct ctl_table_root *root,
1775 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001776 void __user *oldval, size_t __user *oldlenp,
1777 void __user *newval, size_t newlen)
1778{
1779 int op = 0, rc;
1780
1781 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001782 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001783 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001784 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001785 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001786 return -EPERM;
1787
1788 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001789 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001790 if (rc < 0)
1791 return rc;
1792 if (rc > 0)
1793 return 0;
1794 }
1795
1796 /* If there is no strategy routine, or if the strategy returns
1797 * zero, proceed with automatic r/w */
1798 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001799 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001800 if (rc < 0)
1801 return rc;
1802 }
1803 return 0;
1804}
1805
1806static int parse_table(int __user *name, int nlen,
1807 void __user *oldval, size_t __user *oldlenp,
1808 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001809 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001810 struct ctl_table *table)
1811{
1812 int n;
1813repeat:
1814 if (!nlen)
1815 return -ENOTDIR;
1816 if (get_user(n, name))
1817 return -EFAULT;
1818 for ( ; table->ctl_name || table->procname; table++) {
1819 if (!table->ctl_name)
1820 continue;
1821 if (n == table->ctl_name) {
1822 int error;
1823 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001824 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001825 return -EPERM;
1826 name++;
1827 nlen--;
1828 table = table->child;
1829 goto repeat;
1830 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001831 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001832 oldval, oldlenp,
1833 newval, newlen);
1834 return error;
1835 }
1836 }
1837 return -ENOTDIR;
1838}
1839
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1841 void __user *newval, size_t newlen)
1842{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001843 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001844 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1847 return -ENOTDIR;
1848 if (oldval) {
1849 int old_len;
1850 if (!oldlenp || get_user(old_len, oldlenp))
1851 return -EFAULT;
1852 }
Al Viro330d57f2005-11-04 10:18:40 +00001853
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001854 for (head = sysctl_head_next(NULL); head;
1855 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001856 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001857 newval, newlen,
1858 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001859 if (error != -ENOTDIR) {
1860 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001861 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001862 }
1863 }
Al Viro330d57f2005-11-04 10:18:40 +00001864 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865}
1866
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001867SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868{
1869 struct __sysctl_args tmp;
1870 int error;
1871
1872 if (copy_from_user(&tmp, args, sizeof(tmp)))
1873 return -EFAULT;
1874
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001875 error = deprecated_sysctl_warning(&tmp);
1876 if (error)
1877 goto out;
1878
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 lock_kernel();
1880 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1881 tmp.newval, tmp.newlen);
1882 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001883out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 return error;
1885}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001886#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
1888/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001889 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 * some sysctl variables are readonly even to root.
1891 */
1892
1893static int test_perm(int mode, int op)
1894{
David Howells76aac0e2008-11-14 10:39:12 +11001895 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 mode >>= 6;
1897 else if (in_egroup_p(0))
1898 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001899 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 return 0;
1901 return -EACCES;
1902}
1903
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001904int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905{
1906 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001907 int mode;
1908
Al Viroe6305c42008-07-15 21:03:57 -04001909 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 if (error)
1911 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001912
1913 if (root->permissions)
1914 mode = root->permissions(root, current->nsproxy, table);
1915 else
1916 mode = table->mode;
1917
1918 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919}
1920
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001921static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1922{
1923 for (; table->ctl_name || table->procname; table++) {
1924 table->parent = parent;
1925 if (table->child)
1926 sysctl_set_parent(table, table->child);
1927 }
1928}
1929
1930static __init int sysctl_init(void)
1931{
1932 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001933#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1934 {
1935 int err;
1936 err = sysctl_check_table(current->nsproxy, root_table);
1937 }
1938#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001939 return 0;
1940}
1941
1942core_initcall(sysctl_init);
1943
Al Virobfbcf032008-07-27 06:31:22 +01001944static struct ctl_table *is_branch_in(struct ctl_table *branch,
1945 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001946{
1947 struct ctl_table *p;
1948 const char *s = branch->procname;
1949
1950 /* branch should have named subdirectory as its first element */
1951 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001952 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001953
1954 /* ... and nothing else */
1955 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001956 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001957
1958 /* table should contain subdirectory with the same name */
1959 for (p = table; p->procname || p->ctl_name; p++) {
1960 if (!p->child)
1961 continue;
1962 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001963 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001964 }
Al Virobfbcf032008-07-27 06:31:22 +01001965 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001966}
1967
1968/* see if attaching q to p would be an improvement */
1969static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1970{
1971 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001972 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001973 int is_better = 0;
1974 int not_in_parent = !p->attached_by;
1975
Al Virobfbcf032008-07-27 06:31:22 +01001976 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001977 if (by == q->attached_by)
1978 is_better = 1;
1979 if (to == p->attached_by)
1980 not_in_parent = 1;
1981 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001982 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001983 }
1984
1985 if (is_better && not_in_parent) {
1986 q->attached_by = by;
1987 q->attached_to = to;
1988 q->parent = p;
1989 }
1990}
1991
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001993 * __register_sysctl_paths - register a sysctl hierarchy
1994 * @root: List of sysctl headers to register on
1995 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001996 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 *
1999 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002000 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002002 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 *
2004 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
2005 * must be unique within that level of sysctl
2006 *
2007 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2008 * enter a sysctl file
2009 *
2010 * data - a pointer to data for use by proc_handler
2011 *
2012 * maxlen - the maximum size in bytes of the data
2013 *
2014 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2015 *
2016 * child - a pointer to the child sysctl table if this entry is a directory, or
2017 * %NULL.
2018 *
2019 * proc_handler - the text handler routine (described below)
2020 *
2021 * strategy - the strategy routine (described below)
2022 *
2023 * de - for internal use by the sysctl routines
2024 *
2025 * extra1, extra2 - extra pointers usable by the proc handler routines
2026 *
2027 * Leaf nodes in the sysctl tree will be represented by a single file
2028 * under /proc; non-leaf nodes will be represented by directories.
2029 *
2030 * sysctl(2) can automatically manage read and write requests through
2031 * the sysctl table. The data and maxlen fields of the ctl_table
2032 * struct enable minimal validation of the values being written to be
2033 * performed, and the mode field allows minimal authentication.
2034 *
2035 * More sophisticated management can be enabled by the provision of a
2036 * strategy routine with the table entry. This will be called before
2037 * any automatic read or write of the data is performed.
2038 *
2039 * The strategy routine may return
2040 *
2041 * < 0 - Error occurred (error is passed to user process)
2042 *
2043 * 0 - OK - proceed with automatic read or write.
2044 *
2045 * > 0 - OK - read or write has been done by the strategy routine, so
2046 * return immediately.
2047 *
2048 * There must be a proc_handler routine for any terminal nodes
2049 * mirrored under /proc/sys (non-terminals are handled by a built-in
2050 * directory handler). Several default handlers are available to
2051 * cover common cases -
2052 *
2053 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2054 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2055 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2056 *
2057 * It is the handler's job to read the input buffer from user memory
2058 * and process it. The handler should return 0 on success.
2059 *
2060 * This routine returns %NULL on a failure to register, and a pointer
2061 * to the table header on success.
2062 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002063struct ctl_table_header *__register_sysctl_paths(
2064 struct ctl_table_root *root,
2065 struct nsproxy *namespaces,
2066 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002068 struct ctl_table_header *header;
2069 struct ctl_table *new, **prevp;
2070 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04002071 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002072
2073 /* Count the path components */
2074 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2075 ;
2076
2077 /*
2078 * For each path component, allocate a 2-element ctl_table array.
2079 * The first array element will be filled with the sysctl entry
2080 * for this, the second will be the sentinel (ctl_name == 0).
2081 *
2082 * We allocate everything in one go so that we don't have to
2083 * worry about freeing additional memory in unregister_sysctl_table.
2084 */
2085 header = kzalloc(sizeof(struct ctl_table_header) +
2086 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2087 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002089
2090 new = (struct ctl_table *) (header + 1);
2091
2092 /* Now connect the dots */
2093 prevp = &header->ctl_table;
2094 for (n = 0; n < npath; ++n, ++path) {
2095 /* Copy the procname */
2096 new->procname = path->procname;
2097 new->ctl_name = path->ctl_name;
2098 new->mode = 0555;
2099
2100 *prevp = new;
2101 prevp = &new->child;
2102
2103 new += 2;
2104 }
2105 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002106 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002107
2108 INIT_LIST_HEAD(&header->ctl_entry);
2109 header->used = 0;
2110 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002111 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002112 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002113 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002114#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002115 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002116 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002117 return NULL;
2118 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002119#endif
Al Viro330d57f2005-11-04 10:18:40 +00002120 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002121 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002122 header->attached_by = header->ctl_table;
2123 header->attached_to = root_table;
2124 header->parent = &root_table_header;
2125 for (set = header->set; set; set = set->parent) {
2126 struct ctl_table_header *p;
2127 list_for_each_entry(p, &set->list, ctl_entry) {
2128 if (p->unregistering)
2129 continue;
2130 try_attach(p, header);
2131 }
2132 }
2133 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002134 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002135 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002136
2137 return header;
2138}
2139
2140/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002141 * register_sysctl_table_path - register a sysctl table hierarchy
2142 * @path: The path to the directory the sysctl table is in.
2143 * @table: the top-level table structure
2144 *
2145 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2146 * array. A completely 0 filled entry terminates the table.
2147 *
2148 * See __register_sysctl_paths for more details.
2149 */
2150struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2151 struct ctl_table *table)
2152{
2153 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2154 path, table);
2155}
2156
2157/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002158 * register_sysctl_table - register a sysctl table hierarchy
2159 * @table: the top-level table structure
2160 *
2161 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2162 * array. A completely 0 filled entry terminates the table.
2163 *
2164 * See register_sysctl_paths for more details.
2165 */
2166struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2167{
2168 static const struct ctl_path null_path[] = { {} };
2169
2170 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/**
2174 * unregister_sysctl_table - unregister a sysctl table hierarchy
2175 * @header: the header returned from register_sysctl_table
2176 *
2177 * Unregisters the sysctl table and all children. proc entries may not
2178 * actually be removed until they are no longer used by anyone.
2179 */
2180void unregister_sysctl_table(struct ctl_table_header * header)
2181{
Al Viro330d57f2005-11-04 10:18:40 +00002182 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002183
2184 if (header == NULL)
2185 return;
2186
Al Viro330d57f2005-11-04 10:18:40 +00002187 spin_lock(&sysctl_lock);
2188 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002189 if (!--header->parent->count) {
2190 WARN_ON(1);
2191 kfree(header->parent);
2192 }
Al Virof7e6ced2008-07-15 01:44:23 -04002193 if (!--header->count)
2194 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002195 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196}
2197
Al Viro90434762008-07-15 08:54:06 -04002198int sysctl_is_seen(struct ctl_table_header *p)
2199{
2200 struct ctl_table_set *set = p->set;
2201 int res;
2202 spin_lock(&sysctl_lock);
2203 if (p->unregistering)
2204 res = 0;
2205 else if (!set->is_seen)
2206 res = 1;
2207 else
2208 res = set->is_seen(set);
2209 spin_unlock(&sysctl_lock);
2210 return res;
2211}
2212
Al Viro73455092008-07-14 21:22:20 -04002213void setup_sysctl_set(struct ctl_table_set *p,
2214 struct ctl_table_set *parent,
2215 int (*is_seen)(struct ctl_table_set *))
2216{
2217 INIT_LIST_HEAD(&p->list);
2218 p->parent = parent ? parent : &sysctl_table_root.default_set;
2219 p->is_seen = is_seen;
2220}
2221
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002222#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002223struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002224{
2225 return NULL;
2226}
2227
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002228struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2229 struct ctl_table *table)
2230{
2231 return NULL;
2232}
2233
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002234void unregister_sysctl_table(struct ctl_table_header * table)
2235{
2236}
2237
Al Viro73455092008-07-14 21:22:20 -04002238void setup_sysctl_set(struct ctl_table_set *p,
2239 struct ctl_table_set *parent,
2240 int (*is_seen)(struct ctl_table_set *))
2241{
2242}
2243
Al Virof7e6ced2008-07-15 01:44:23 -04002244void sysctl_head_put(struct ctl_table_header *head)
2245{
2246}
2247
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002248#endif /* CONFIG_SYSCTL */
2249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250/*
2251 * /proc/sys support
2252 */
2253
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002254#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002256static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002257 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002258 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002259{
2260 size_t len;
2261 char __user *p;
2262 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002263
2264 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002265 *lenp = 0;
2266 return 0;
2267 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002268
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002269 if (write) {
2270 len = 0;
2271 p = buffer;
2272 while (len < *lenp) {
2273 if (get_user(c, p++))
2274 return -EFAULT;
2275 if (c == 0 || c == '\n')
2276 break;
2277 len++;
2278 }
2279 if (len >= maxlen)
2280 len = maxlen-1;
2281 if(copy_from_user(data, buffer, len))
2282 return -EFAULT;
2283 ((char *) data)[len] = 0;
2284 *ppos += *lenp;
2285 } else {
2286 len = strlen(data);
2287 if (len > maxlen)
2288 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002289
2290 if (*ppos > len) {
2291 *lenp = 0;
2292 return 0;
2293 }
2294
2295 data += *ppos;
2296 len -= *ppos;
2297
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002298 if (len > *lenp)
2299 len = *lenp;
2300 if (len)
2301 if(copy_to_user(buffer, data, len))
2302 return -EFAULT;
2303 if (len < *lenp) {
2304 if(put_user('\n', ((char __user *) buffer) + len))
2305 return -EFAULT;
2306 len++;
2307 }
2308 *lenp = len;
2309 *ppos += len;
2310 }
2311 return 0;
2312}
2313
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314/**
2315 * proc_dostring - read a string sysctl
2316 * @table: the sysctl table
2317 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2321 *
2322 * Reads/writes a string from/to the user buffer. If the kernel
2323 * buffer provided is not large enough to hold the string, the
2324 * string is truncated. The copied string is %NULL-terminated.
2325 * If the string is being read by the user process, it is copied
2326 * and a newline '\n' is added. It is truncated if the buffer is
2327 * not large enough.
2328 *
2329 * Returns 0 on success.
2330 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002331int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 void __user *buffer, size_t *lenp, loff_t *ppos)
2333{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002334 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002335 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336}
2337
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
2339static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2340 int *valp,
2341 int write, void *data)
2342{
2343 if (write) {
2344 *valp = *negp ? -*lvalp : *lvalp;
2345 } else {
2346 int val = *valp;
2347 if (val < 0) {
2348 *negp = -1;
2349 *lvalp = (unsigned long)-val;
2350 } else {
2351 *negp = 0;
2352 *lvalp = (unsigned long)val;
2353 }
2354 }
2355 return 0;
2356}
2357
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002358static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002359 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002360 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2362 int write, void *data),
2363 void *data)
2364{
2365#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002366 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 unsigned long lval;
2368 size_t left, len;
2369
2370 char buf[TMPBUFLEN], *p;
2371 char __user *s = buffer;
2372
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002373 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 (*ppos && !write)) {
2375 *lenp = 0;
2376 return 0;
2377 }
2378
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002379 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 vleft = table->maxlen / sizeof(*i);
2381 left = *lenp;
2382
2383 if (!conv)
2384 conv = do_proc_dointvec_conv;
2385
2386 for (; left && vleft--; i++, first=0) {
2387 if (write) {
2388 while (left) {
2389 char c;
2390 if (get_user(c, s))
2391 return -EFAULT;
2392 if (!isspace(c))
2393 break;
2394 left--;
2395 s++;
2396 }
2397 if (!left)
2398 break;
2399 neg = 0;
2400 len = left;
2401 if (len > sizeof(buf) - 1)
2402 len = sizeof(buf) - 1;
2403 if (copy_from_user(buf, s, len))
2404 return -EFAULT;
2405 buf[len] = 0;
2406 p = buf;
2407 if (*p == '-' && left > 1) {
2408 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002409 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 }
2411 if (*p < '0' || *p > '9')
2412 break;
2413
2414 lval = simple_strtoul(p, &p, 0);
2415
2416 len = p-buf;
2417 if ((len < left) && *p && !isspace(*p))
2418 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 s += len;
2420 left -= len;
2421
2422 if (conv(&neg, &lval, i, 1, data))
2423 break;
2424 } else {
2425 p = buf;
2426 if (!first)
2427 *p++ = '\t';
2428
2429 if (conv(&neg, &lval, i, 0, data))
2430 break;
2431
2432 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2433 len = strlen(buf);
2434 if (len > left)
2435 len = left;
2436 if(copy_to_user(s, buf, len))
2437 return -EFAULT;
2438 left -= len;
2439 s += len;
2440 }
2441 }
2442
2443 if (!write && !first && left) {
2444 if(put_user('\n', s))
2445 return -EFAULT;
2446 left--, s++;
2447 }
2448 if (write) {
2449 while (left) {
2450 char c;
2451 if (get_user(c, s++))
2452 return -EFAULT;
2453 if (!isspace(c))
2454 break;
2455 left--;
2456 }
2457 }
2458 if (write && first)
2459 return -EINVAL;
2460 *lenp -= left;
2461 *ppos += *lenp;
2462 return 0;
2463#undef TMPBUFLEN
2464}
2465
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002466static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002467 void __user *buffer, size_t *lenp, loff_t *ppos,
2468 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2469 int write, void *data),
2470 void *data)
2471{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002472 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002473 buffer, lenp, ppos, conv, data);
2474}
2475
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476/**
2477 * proc_dointvec - read a vector of integers
2478 * @table: the sysctl table
2479 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 * @buffer: the user buffer
2481 * @lenp: the size of the user buffer
2482 * @ppos: file position
2483 *
2484 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2485 * values from/to the user buffer, treated as an ASCII string.
2486 *
2487 * Returns 0 on success.
2488 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002489int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 void __user *buffer, size_t *lenp, loff_t *ppos)
2491{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002492 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 NULL,NULL);
2494}
2495
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002496/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002497 * Taint values can only be increased
2498 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002499 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002500static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002501 void __user *buffer, size_t *lenp, loff_t *ppos)
2502{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002503 struct ctl_table t;
2504 unsigned long tmptaint = get_taint();
2505 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002506
Bastian Blank91fcd412007-04-23 14:41:14 -07002507 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002508 return -EPERM;
2509
Andi Kleen25ddbb12008-10-15 22:01:41 -07002510 t = *table;
2511 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002512 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002513 if (err < 0)
2514 return err;
2515
2516 if (write) {
2517 /*
2518 * Poor man's atomic or. Not worth adding a primitive
2519 * to everyone's atomic.h for this
2520 */
2521 int i;
2522 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2523 if ((tmptaint >> i) & 1)
2524 add_taint(i);
2525 }
2526 }
2527
2528 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002529}
2530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531struct do_proc_dointvec_minmax_conv_param {
2532 int *min;
2533 int *max;
2534};
2535
2536static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2537 int *valp,
2538 int write, void *data)
2539{
2540 struct do_proc_dointvec_minmax_conv_param *param = data;
2541 if (write) {
2542 int val = *negp ? -*lvalp : *lvalp;
2543 if ((param->min && *param->min > val) ||
2544 (param->max && *param->max < val))
2545 return -EINVAL;
2546 *valp = val;
2547 } else {
2548 int val = *valp;
2549 if (val < 0) {
2550 *negp = -1;
2551 *lvalp = (unsigned long)-val;
2552 } else {
2553 *negp = 0;
2554 *lvalp = (unsigned long)val;
2555 }
2556 }
2557 return 0;
2558}
2559
2560/**
2561 * proc_dointvec_minmax - read a vector of integers with min/max values
2562 * @table: the sysctl table
2563 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 * @buffer: the user buffer
2565 * @lenp: the size of the user buffer
2566 * @ppos: file position
2567 *
2568 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2569 * values from/to the user buffer, treated as an ASCII string.
2570 *
2571 * This routine will ensure the values are within the range specified by
2572 * table->extra1 (min) and table->extra2 (max).
2573 *
2574 * Returns 0 on success.
2575 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002576int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 void __user *buffer, size_t *lenp, loff_t *ppos)
2578{
2579 struct do_proc_dointvec_minmax_conv_param param = {
2580 .min = (int *) table->extra1,
2581 .max = (int *) table->extra2,
2582 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002583 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 do_proc_dointvec_minmax_conv, &param);
2585}
2586
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002587static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 void __user *buffer,
2589 size_t *lenp, loff_t *ppos,
2590 unsigned long convmul,
2591 unsigned long convdiv)
2592{
2593#define TMPBUFLEN 21
2594 unsigned long *i, *min, *max, val;
2595 int vleft, first=1, neg;
2596 size_t len, left;
2597 char buf[TMPBUFLEN], *p;
2598 char __user *s = buffer;
2599
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002600 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 (*ppos && !write)) {
2602 *lenp = 0;
2603 return 0;
2604 }
2605
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002606 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 min = (unsigned long *) table->extra1;
2608 max = (unsigned long *) table->extra2;
2609 vleft = table->maxlen / sizeof(unsigned long);
2610 left = *lenp;
2611
2612 for (; left && vleft--; i++, min++, max++, first=0) {
2613 if (write) {
2614 while (left) {
2615 char c;
2616 if (get_user(c, s))
2617 return -EFAULT;
2618 if (!isspace(c))
2619 break;
2620 left--;
2621 s++;
2622 }
2623 if (!left)
2624 break;
2625 neg = 0;
2626 len = left;
2627 if (len > TMPBUFLEN-1)
2628 len = TMPBUFLEN-1;
2629 if (copy_from_user(buf, s, len))
2630 return -EFAULT;
2631 buf[len] = 0;
2632 p = buf;
2633 if (*p == '-' && left > 1) {
2634 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002635 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 }
2637 if (*p < '0' || *p > '9')
2638 break;
2639 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2640 len = p-buf;
2641 if ((len < left) && *p && !isspace(*p))
2642 break;
2643 if (neg)
2644 val = -val;
2645 s += len;
2646 left -= len;
2647
2648 if(neg)
2649 continue;
2650 if ((min && val < *min) || (max && val > *max))
2651 continue;
2652 *i = val;
2653 } else {
2654 p = buf;
2655 if (!first)
2656 *p++ = '\t';
2657 sprintf(p, "%lu", convdiv * (*i) / convmul);
2658 len = strlen(buf);
2659 if (len > left)
2660 len = left;
2661 if(copy_to_user(s, buf, len))
2662 return -EFAULT;
2663 left -= len;
2664 s += len;
2665 }
2666 }
2667
2668 if (!write && !first && left) {
2669 if(put_user('\n', s))
2670 return -EFAULT;
2671 left--, s++;
2672 }
2673 if (write) {
2674 while (left) {
2675 char c;
2676 if (get_user(c, s++))
2677 return -EFAULT;
2678 if (!isspace(c))
2679 break;
2680 left--;
2681 }
2682 }
2683 if (write && first)
2684 return -EINVAL;
2685 *lenp -= left;
2686 *ppos += *lenp;
2687 return 0;
2688#undef TMPBUFLEN
2689}
2690
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002691static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002692 void __user *buffer,
2693 size_t *lenp, loff_t *ppos,
2694 unsigned long convmul,
2695 unsigned long convdiv)
2696{
2697 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002698 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002699}
2700
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701/**
2702 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2703 * @table: the sysctl table
2704 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 * @buffer: the user buffer
2706 * @lenp: the size of the user buffer
2707 * @ppos: file position
2708 *
2709 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2710 * values from/to the user buffer, treated as an ASCII string.
2711 *
2712 * This routine will ensure the values are within the range specified by
2713 * table->extra1 (min) and table->extra2 (max).
2714 *
2715 * Returns 0 on success.
2716 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002717int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 void __user *buffer, size_t *lenp, loff_t *ppos)
2719{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002720 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721}
2722
2723/**
2724 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2725 * @table: the sysctl table
2726 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 * @buffer: the user buffer
2728 * @lenp: the size of the user buffer
2729 * @ppos: file position
2730 *
2731 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2732 * values from/to the user buffer, treated as an ASCII string. The values
2733 * are treated as milliseconds, and converted to jiffies when they are stored.
2734 *
2735 * This routine will ensure the values are within the range specified by
2736 * table->extra1 (min) and table->extra2 (max).
2737 *
2738 * Returns 0 on success.
2739 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002740int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 void __user *buffer,
2742 size_t *lenp, loff_t *ppos)
2743{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002744 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 lenp, ppos, HZ, 1000l);
2746}
2747
2748
2749static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2750 int *valp,
2751 int write, void *data)
2752{
2753 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002754 if (*lvalp > LONG_MAX / HZ)
2755 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2757 } else {
2758 int val = *valp;
2759 unsigned long lval;
2760 if (val < 0) {
2761 *negp = -1;
2762 lval = (unsigned long)-val;
2763 } else {
2764 *negp = 0;
2765 lval = (unsigned long)val;
2766 }
2767 *lvalp = lval / HZ;
2768 }
2769 return 0;
2770}
2771
2772static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2773 int *valp,
2774 int write, void *data)
2775{
2776 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002777 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2778 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2780 } else {
2781 int val = *valp;
2782 unsigned long lval;
2783 if (val < 0) {
2784 *negp = -1;
2785 lval = (unsigned long)-val;
2786 } else {
2787 *negp = 0;
2788 lval = (unsigned long)val;
2789 }
2790 *lvalp = jiffies_to_clock_t(lval);
2791 }
2792 return 0;
2793}
2794
2795static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2796 int *valp,
2797 int write, void *data)
2798{
2799 if (write) {
2800 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2801 } else {
2802 int val = *valp;
2803 unsigned long lval;
2804 if (val < 0) {
2805 *negp = -1;
2806 lval = (unsigned long)-val;
2807 } else {
2808 *negp = 0;
2809 lval = (unsigned long)val;
2810 }
2811 *lvalp = jiffies_to_msecs(lval);
2812 }
2813 return 0;
2814}
2815
2816/**
2817 * proc_dointvec_jiffies - read a vector of integers as seconds
2818 * @table: the sysctl table
2819 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 * @buffer: the user buffer
2821 * @lenp: the size of the user buffer
2822 * @ppos: file position
2823 *
2824 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2825 * values from/to the user buffer, treated as an ASCII string.
2826 * The values read are assumed to be in seconds, and are converted into
2827 * jiffies.
2828 *
2829 * Returns 0 on success.
2830 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002831int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 void __user *buffer, size_t *lenp, loff_t *ppos)
2833{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002834 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 do_proc_dointvec_jiffies_conv,NULL);
2836}
2837
2838/**
2839 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2840 * @table: the sysctl table
2841 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 * @buffer: the user buffer
2843 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002844 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 *
2846 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2847 * values from/to the user buffer, treated as an ASCII string.
2848 * The values read are assumed to be in 1/USER_HZ seconds, and
2849 * are converted into jiffies.
2850 *
2851 * Returns 0 on success.
2852 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002853int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 void __user *buffer, size_t *lenp, loff_t *ppos)
2855{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002856 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 do_proc_dointvec_userhz_jiffies_conv,NULL);
2858}
2859
2860/**
2861 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2862 * @table: the sysctl table
2863 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 * @buffer: the user buffer
2865 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002866 * @ppos: file position
2867 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 *
2869 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2870 * values from/to the user buffer, treated as an ASCII string.
2871 * The values read are assumed to be in 1/1000 seconds, and
2872 * are converted into jiffies.
2873 *
2874 * Returns 0 on success.
2875 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002876int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 void __user *buffer, size_t *lenp, loff_t *ppos)
2878{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002879 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 do_proc_dointvec_ms_jiffies_conv, NULL);
2881}
2882
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002883static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002884 void __user *buffer, size_t *lenp, loff_t *ppos)
2885{
2886 struct pid *new_pid;
2887 pid_t tmp;
2888 int r;
2889
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002890 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002891
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002892 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002893 lenp, ppos, NULL, NULL);
2894 if (r || !write)
2895 return r;
2896
2897 new_pid = find_get_pid(tmp);
2898 if (!new_pid)
2899 return -ESRCH;
2900
2901 put_pid(xchg(&cad_pid, new_pid));
2902 return 0;
2903}
2904
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905#else /* CONFIG_PROC_FS */
2906
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002907int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 void __user *buffer, size_t *lenp, loff_t *ppos)
2909{
2910 return -ENOSYS;
2911}
2912
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002913int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 void __user *buffer, size_t *lenp, loff_t *ppos)
2915{
2916 return -ENOSYS;
2917}
2918
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002919int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 void __user *buffer, size_t *lenp, loff_t *ppos)
2921{
2922 return -ENOSYS;
2923}
2924
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002925int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 void __user *buffer, size_t *lenp, loff_t *ppos)
2927{
2928 return -ENOSYS;
2929}
2930
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002931int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 void __user *buffer, size_t *lenp, loff_t *ppos)
2933{
2934 return -ENOSYS;
2935}
2936
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002937int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 void __user *buffer, size_t *lenp, loff_t *ppos)
2939{
2940 return -ENOSYS;
2941}
2942
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002943int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 void __user *buffer, size_t *lenp, loff_t *ppos)
2945{
2946 return -ENOSYS;
2947}
2948
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002949int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 void __user *buffer,
2951 size_t *lenp, loff_t *ppos)
2952{
2953 return -ENOSYS;
2954}
2955
2956
2957#endif /* CONFIG_PROC_FS */
2958
2959
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002960#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961/*
2962 * General sysctl support routines
2963 */
2964
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002965/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002966int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002967 void __user *oldval, size_t __user *oldlenp,
2968 void __user *newval, size_t newlen)
2969{
2970 size_t len;
2971
2972 /* Get out of I don't have a variable */
2973 if (!table->data || !table->maxlen)
2974 return -ENOTDIR;
2975
2976 if (oldval && oldlenp) {
2977 if (get_user(len, oldlenp))
2978 return -EFAULT;
2979 if (len) {
2980 if (len > table->maxlen)
2981 len = table->maxlen;
2982 if (copy_to_user(oldval, table->data, len))
2983 return -EFAULT;
2984 if (put_user(len, oldlenp))
2985 return -EFAULT;
2986 }
2987 }
2988
2989 if (newval && newlen) {
2990 if (newlen > table->maxlen)
2991 newlen = table->maxlen;
2992
2993 if (copy_from_user(table->data, newval, newlen))
2994 return -EFAULT;
2995 }
2996 return 1;
2997}
2998
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003000int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003002 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 if (!table->data || !table->maxlen)
3005 return -ENOTDIR;
3006
3007 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003008 size_t bufsize;
3009 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003011 if (bufsize) {
3012 size_t len = strlen(table->data), copied;
3013
3014 /* This shouldn't trigger for a well-formed sysctl */
3015 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003017
3018 /* Copy up to a max of bufsize-1 bytes of the string */
3019 copied = (len >= bufsize) ? bufsize - 1 : len;
3020
3021 if (copy_to_user(oldval, table->data, copied) ||
3022 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003024 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 return -EFAULT;
3026 }
3027 }
3028 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003029 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 if (len > table->maxlen)
3031 len = table->maxlen;
3032 if(copy_from_user(table->data, newval, len))
3033 return -EFAULT;
3034 if (len == table->maxlen)
3035 len--;
3036 ((char *) table->data)[len] = 0;
3037 }
Yi Yang82c9df82005-12-30 16:37:10 +08003038 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039}
3040
3041/*
3042 * This function makes sure that all of the integers in the vector
3043 * are between the minimum and maximum values given in the arrays
3044 * table->extra1 and table->extra2, respectively.
3045 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003046int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003048 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049{
3050
3051 if (newval && newlen) {
3052 int __user *vec = (int __user *) newval;
3053 int *min = (int *) table->extra1;
3054 int *max = (int *) table->extra2;
3055 size_t length;
3056 int i;
3057
3058 if (newlen % sizeof(int) != 0)
3059 return -EINVAL;
3060
3061 if (!table->extra1 && !table->extra2)
3062 return 0;
3063
3064 if (newlen > table->maxlen)
3065 newlen = table->maxlen;
3066 length = newlen / sizeof(int);
3067
3068 for (i = 0; i < length; i++) {
3069 int value;
3070 if (get_user(value, vec + i))
3071 return -EFAULT;
3072 if (min && value < min[i])
3073 return -EINVAL;
3074 if (max && value > max[i])
3075 return -EINVAL;
3076 }
3077 }
3078 return 0;
3079}
3080
3081/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003082int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003084 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003086 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003088
3089 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003091 if (olen) {
3092 int val;
3093
3094 if (olen < sizeof(int))
3095 return -EINVAL;
3096
3097 val = *(int *)(table->data) / HZ;
3098 if (put_user(val, (int __user *)oldval))
3099 return -EFAULT;
3100 if (put_user(sizeof(int), oldlenp))
3101 return -EFAULT;
3102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 }
3104 if (newval && newlen) {
3105 int new;
3106 if (newlen != sizeof(int))
3107 return -EINVAL;
3108 if (get_user(new, (int __user *)newval))
3109 return -EFAULT;
3110 *(int *)(table->data) = new*HZ;
3111 }
3112 return 1;
3113}
3114
3115/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003116int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003118 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003120 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003122
3123 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003125 if (olen) {
3126 int val;
3127
3128 if (olen < sizeof(int))
3129 return -EINVAL;
3130
3131 val = jiffies_to_msecs(*(int *)(table->data));
3132 if (put_user(val, (int __user *)oldval))
3133 return -EFAULT;
3134 if (put_user(sizeof(int), oldlenp))
3135 return -EFAULT;
3136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 }
3138 if (newval && newlen) {
3139 int new;
3140 if (newlen != sizeof(int))
3141 return -EINVAL;
3142 if (get_user(new, (int __user *)newval))
3143 return -EFAULT;
3144 *(int *)(table->data) = msecs_to_jiffies(new);
3145 }
3146 return 1;
3147}
3148
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003149
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003150
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003151#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
3153
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003154SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003156 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003157 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003158
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003159 if (copy_from_user(&tmp, args, sizeof(tmp)))
3160 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003161
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003162 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003163
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003164 /* If no error reading the parameters then just -ENOSYS ... */
3165 if (!error)
3166 error = -ENOSYS;
3167
3168 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169}
3170
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003171int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003172 void __user *oldval, size_t __user *oldlenp,
3173 void __user *newval, size_t newlen)
3174{
3175 return -ENOSYS;
3176}
3177
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003178int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003180 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181{
3182 return -ENOSYS;
3183}
3184
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003185int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003187 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188{
3189 return -ENOSYS;
3190}
3191
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003192int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003194 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195{
3196 return -ENOSYS;
3197}
3198
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003199int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003201 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202{
3203 return -ENOSYS;
3204}
3205
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003206#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003208static int deprecated_sysctl_warning(struct __sysctl_args *args)
3209{
3210 static int msg_count;
3211 int name[CTL_MAXNAME];
3212 int i;
3213
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003214 /* Check args->nlen. */
3215 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3216 return -ENOTDIR;
3217
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003218 /* Read in the sysctl name for better debug message logging */
3219 for (i = 0; i < args->nlen; i++)
3220 if (get_user(name[i], args->name + i))
3221 return -EFAULT;
3222
3223 /* Ignore accesses to kernel.version */
3224 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3225 return 0;
3226
3227 if (msg_count < 5) {
3228 msg_count++;
3229 printk(KERN_INFO
3230 "warning: process `%s' used the deprecated sysctl "
3231 "system call with ", current->comm);
3232 for (i = 0; i < args->nlen; i++)
3233 printk("%d.", name[i]);
3234 printk("\n");
3235 }
3236 return 0;
3237}
3238
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239/*
3240 * No sense putting this after each symbol definition, twice,
3241 * exception granted :-)
3242 */
3243EXPORT_SYMBOL(proc_dointvec);
3244EXPORT_SYMBOL(proc_dointvec_jiffies);
3245EXPORT_SYMBOL(proc_dointvec_minmax);
3246EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3247EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3248EXPORT_SYMBOL(proc_dostring);
3249EXPORT_SYMBOL(proc_doulongvec_minmax);
3250EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3251EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003252EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253EXPORT_SYMBOL(sysctl_intvec);
3254EXPORT_SYMBOL(sysctl_jiffies);
3255EXPORT_SYMBOL(sysctl_ms_jiffies);
3256EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003257EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258EXPORT_SYMBOL(unregister_sysctl_table);