blob: db23ab7e56c0dc1cfe7aea51257e153f95fe0152 [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>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020052#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <asm/uaccess.h>
55#include <asm/processor.h>
56
Andi Kleen29cbc782006-09-30 01:47:55 +020057#ifdef CONFIG_X86
58#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010059#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010060#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020061#endif
62
Eric W. Biederman7058cb02007-10-18 03:05:58 -070063static int deprecated_sysctl_warning(struct __sysctl_args *args);
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#if defined(CONFIG_SYSCTL)
66
67/* External variables not in a header file. */
68extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070069extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int sysctl_overcommit_memory;
71extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070072extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070073extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080074extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070077extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070079extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max;
81extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080083extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080084extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020085extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010086extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040087extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000088#ifndef CONFIG_MMU
89extern int sysctl_nr_trim_pages;
90#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070091#ifdef CONFIG_RCU_TORTURE_TEST
92extern int rcutorture_runnable;
93#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Jens Axboecb684b52009-09-15 21:53:11 +020094#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +020095extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +020096#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080099#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200101static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700102#endif
103
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700104static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700105static int __maybe_unused one = 1;
106static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800107static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700108static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700109#ifdef CONFIG_PRINTK
110static int ten_thousand = 10000;
111#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700112
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700113/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
114static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
117static int maxolduid = 65535;
118static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800119static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121static int ngroups_max = NGROUPS_MAX;
122
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200123#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700125extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#ifdef CONFIG_CHR_DEV_SG
128extern int sg_big_buff;
129#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
David S. Miller72c57ed2008-09-11 23:29:54 -0700131#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700132#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#endif
134
David S. Miller08714202008-11-16 23:49:24 -0800135#ifdef CONFIG_SPARC64
136extern int sysctl_tsb_ratio;
137#endif
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#ifdef __hppa__
140extern int pwrsw_enabled;
141extern int unaligned_enabled;
142#endif
143
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800144#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#ifdef CONFIG_MATHEMU
146extern int sysctl_ieee_emulation_warnings;
147#endif
148extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700149extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#endif
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#ifdef CONFIG_BSD_PROCESS_ACCT
153extern int acct_parm[];
154#endif
155
Jes Sorensend2b176e2006-02-28 09:42:23 -0800156#ifdef CONFIG_IA64
157extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800158extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800159#endif
160
Ingo Molnar23f78d42006-06-27 02:54:53 -0700161#ifdef CONFIG_RT_MUTEXES
162extern int max_lock_depth;
163#endif
164
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700165#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700166static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700167 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700168static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800169 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700170#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700171
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700172static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100173static struct ctl_table_root sysctl_table_root;
174static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100175 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400177 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100178 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400179 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100180};
181static struct ctl_table_root sysctl_table_root = {
182 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400183 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100184};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700186static struct ctl_table kern_table[];
187static struct ctl_table vm_table[];
188static struct ctl_table fs_table[];
189static struct ctl_table debug_table[];
190static struct ctl_table dev_table[];
191extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700192#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700193extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400194#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800195#ifdef CONFIG_EPOLL
196extern struct ctl_table epoll_table[];
197#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
200int sysctl_legacy_va_layout;
201#endif
202
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700203extern int prove_locking;
204extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/* The default sysctl tables: */
207
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700208static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 {
210 .ctl_name = CTL_KERN,
211 .procname = "kernel",
212 .mode = 0555,
213 .child = kern_table,
214 },
215 {
216 .ctl_name = CTL_VM,
217 .procname = "vm",
218 .mode = 0555,
219 .child = vm_table,
220 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 .ctl_name = CTL_FS,
223 .procname = "fs",
224 .mode = 0555,
225 .child = fs_table,
226 },
227 {
228 .ctl_name = CTL_DEBUG,
229 .procname = "debug",
230 .mode = 0555,
231 .child = debug_table,
232 },
233 {
234 .ctl_name = CTL_DEV,
235 .procname = "dev",
236 .mode = 0555,
237 .child = dev_table,
238 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700239/*
240 * NOTE: do not add new entries to this table unless you have read
241 * Documentation/sysctl/ctl_unnumbered.txt
242 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 { .ctl_name = 0 }
244};
245
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100247static int min_sched_granularity_ns = 100000; /* 100 usecs */
248static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
249static int min_wakeup_granularity_ns; /* 0 usecs */
250static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200251#endif
252
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700253static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200254 {
255 .ctl_name = CTL_UNNUMBERED,
256 .procname = "sched_child_runs_first",
257 .data = &sysctl_sched_child_runs_first,
258 .maxlen = sizeof(unsigned int),
259 .mode = 0644,
260 .proc_handler = &proc_dointvec,
261 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200262#ifdef CONFIG_SCHED_DEBUG
263 {
264 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100265 .procname = "sched_min_granularity_ns",
266 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200267 .maxlen = sizeof(unsigned int),
268 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100269 .proc_handler = &sched_nr_latency_handler,
270 .strategy = &sysctl_intvec,
271 .extra1 = &min_sched_granularity_ns,
272 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200273 },
274 {
275 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200276 .procname = "sched_latency_ns",
277 .data = &sysctl_sched_latency,
278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100280 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200281 .strategy = &sysctl_intvec,
282 .extra1 = &min_sched_granularity_ns,
283 .extra2 = &max_sched_granularity_ns,
284 },
285 {
286 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200287 .procname = "sched_wakeup_granularity_ns",
288 .data = &sysctl_sched_wakeup_granularity,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = &proc_dointvec_minmax,
292 .strategy = &sysctl_intvec,
293 .extra1 = &min_wakeup_granularity_ns,
294 .extra2 = &max_wakeup_granularity_ns,
295 },
296 {
297 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200298 .procname = "sched_shares_ratelimit",
299 .data = &sysctl_sched_shares_ratelimit,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
302 .proc_handler = &proc_dointvec,
303 },
304 {
305 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200306 .procname = "sched_shares_thresh",
307 .data = &sysctl_sched_shares_thresh,
308 .maxlen = sizeof(unsigned int),
309 .mode = 0644,
310 .proc_handler = &proc_dointvec_minmax,
311 .strategy = &sysctl_intvec,
312 .extra1 = &zero,
313 },
314 {
315 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200316 .procname = "sched_features",
317 .data = &sysctl_sched_features,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200322 {
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_migration_cost",
325 .data = &sysctl_sched_migration_cost,
326 .maxlen = sizeof(unsigned int),
327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
329 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100330 {
331 .ctl_name = CTL_UNNUMBERED,
332 .procname = "sched_nr_migrate",
333 .data = &sysctl_sched_nr_migrate,
334 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100335 .mode = 0644,
336 .proc_handler = &proc_dointvec,
337 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530338 {
339 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200340 .procname = "sched_time_avg",
341 .data = &sysctl_sched_time_avg,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = &proc_dointvec,
345 },
346 {
347 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530348 .procname = "timer_migration",
349 .data = &sysctl_timer_migration,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530352 .proc_handler = &proc_dointvec_minmax,
353 .strategy = &sysctl_intvec,
354 .extra1 = &zero,
355 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530356 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200357#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200358 {
359 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100360 .procname = "sched_rt_period_us",
361 .data = &sysctl_sched_rt_period,
362 .maxlen = sizeof(unsigned int),
363 .mode = 0644,
Peter Zijlstrad0b27fa72008-04-19 19:44:57 +0200364 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100365 },
366 {
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "sched_rt_runtime_us",
369 .data = &sysctl_sched_rt_runtime,
370 .maxlen = sizeof(int),
371 .mode = 0644,
Peter Zijlstrad0b27fa72008-04-19 19:44:57 +0200372 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100373 },
374 {
375 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200376 .procname = "sched_compat_yield",
377 .data = &sysctl_sched_compat_yield,
378 .maxlen = sizeof(unsigned int),
379 .mode = 0644,
380 .proc_handler = &proc_dointvec,
381 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700382#ifdef CONFIG_PROVE_LOCKING
383 {
384 .ctl_name = CTL_UNNUMBERED,
385 .procname = "prove_locking",
386 .data = &prove_locking,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
391#endif
392#ifdef CONFIG_LOCK_STAT
393 {
394 .ctl_name = CTL_UNNUMBERED,
395 .procname = "lock_stat",
396 .data = &lock_stat,
397 .maxlen = sizeof(int),
398 .mode = 0644,
399 .proc_handler = &proc_dointvec,
400 },
401#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200402 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 .ctl_name = KERN_PANIC,
404 .procname = "panic",
405 .data = &panic_timeout,
406 .maxlen = sizeof(int),
407 .mode = 0644,
408 .proc_handler = &proc_dointvec,
409 },
410 {
411 .ctl_name = KERN_CORE_USES_PID,
412 .procname = "core_uses_pid",
413 .data = &core_uses_pid,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
417 },
418 {
419 .ctl_name = KERN_CORE_PATTERN,
420 .procname = "core_pattern",
421 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700422 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 .mode = 0644,
424 .proc_handler = &proc_dostring,
425 .strategy = &sysctl_string,
426 },
Neil Hormana2939802009-09-23 15:56:56 -0700427 {
428 .ctl_name = CTL_UNNUMBERED,
429 .procname = "core_pipe_limit",
430 .data = &core_pipe_limit,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800435#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700438 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800439 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700440 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800442#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100443#ifdef CONFIG_LATENCYTOP
444 {
445 .procname = "latencytop",
446 .data = &latencytop_enabled,
447 .maxlen = sizeof(int),
448 .mode = 0644,
449 .proc_handler = &proc_dointvec,
450 },
451#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452#ifdef CONFIG_BLK_DEV_INITRD
453 {
454 .ctl_name = KERN_REALROOTDEV,
455 .procname = "real-root-dev",
456 .data = &real_root_dev,
457 .maxlen = sizeof(int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
460 },
461#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700462 {
463 .ctl_name = CTL_UNNUMBERED,
464 .procname = "print-fatal-signals",
465 .data = &print_fatal_signals,
466 .maxlen = sizeof(int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
469 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700470#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 {
472 .ctl_name = KERN_SPARC_REBOOT,
473 .procname = "reboot-cmd",
474 .data = reboot_command,
475 .maxlen = 256,
476 .mode = 0644,
477 .proc_handler = &proc_dostring,
478 .strategy = &sysctl_string,
479 },
480 {
481 .ctl_name = KERN_SPARC_STOP_A,
482 .procname = "stop-a",
483 .data = &stop_a_enabled,
484 .maxlen = sizeof (int),
485 .mode = 0644,
486 .proc_handler = &proc_dointvec,
487 },
488 {
489 .ctl_name = KERN_SPARC_SCONS_PWROFF,
490 .procname = "scons-poweroff",
491 .data = &scons_pwroff,
492 .maxlen = sizeof (int),
493 .mode = 0644,
494 .proc_handler = &proc_dointvec,
495 },
496#endif
David S. Miller08714202008-11-16 23:49:24 -0800497#ifdef CONFIG_SPARC64
498 {
499 .ctl_name = CTL_UNNUMBERED,
500 .procname = "tsb-ratio",
501 .data = &sysctl_tsb_ratio,
502 .maxlen = sizeof (int),
503 .mode = 0644,
504 .proc_handler = &proc_dointvec,
505 },
506#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#ifdef __hppa__
508 {
509 .ctl_name = KERN_HPPA_PWRSW,
510 .procname = "soft-power",
511 .data = &pwrsw_enabled,
512 .maxlen = sizeof (int),
513 .mode = 0644,
514 .proc_handler = &proc_dointvec,
515 },
516 {
517 .ctl_name = KERN_HPPA_UNALIGNED,
518 .procname = "unaligned-trap",
519 .data = &unaligned_enabled,
520 .maxlen = sizeof (int),
521 .mode = 0644,
522 .proc_handler = &proc_dointvec,
523 },
524#endif
525 {
526 .ctl_name = KERN_CTLALTDEL,
527 .procname = "ctrl-alt-del",
528 .data = &C_A_D,
529 .maxlen = sizeof(int),
530 .mode = 0644,
531 .proc_handler = &proc_dointvec,
532 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400533#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200534 {
535 .ctl_name = CTL_UNNUMBERED,
536 .procname = "ftrace_enabled",
537 .data = &ftrace_enabled,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = &ftrace_enable_sysctl,
541 },
542#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500543#ifdef CONFIG_STACK_TRACER
544 {
545 .ctl_name = CTL_UNNUMBERED,
546 .procname = "stack_tracer_enabled",
547 .data = &stack_tracer_enabled,
548 .maxlen = sizeof(int),
549 .mode = 0644,
550 .proc_handler = &stack_trace_sysctl,
551 },
552#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400553#ifdef CONFIG_TRACING
554 {
555 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100556 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400557 .data = &ftrace_dump_on_oops,
558 .maxlen = sizeof(int),
559 .mode = 0644,
560 .proc_handler = &proc_dointvec,
561 },
562#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200563#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 {
565 .ctl_name = KERN_MODPROBE,
566 .procname = "modprobe",
567 .data = &modprobe_path,
568 .maxlen = KMOD_PATH_LEN,
569 .mode = 0644,
570 .proc_handler = &proc_dostring,
571 .strategy = &sysctl_string,
572 },
Kees Cook3d433212009-04-02 15:49:29 -0700573 {
574 .ctl_name = CTL_UNNUMBERED,
575 .procname = "modules_disabled",
576 .data = &modules_disabled,
577 .maxlen = sizeof(int),
578 .mode = 0644,
579 /* only handle a transition from default "0" to "1" */
580 .proc_handler = &proc_dointvec_minmax,
581 .extra1 = &one,
582 .extra2 = &one,
583 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700585#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 {
587 .ctl_name = KERN_HOTPLUG,
588 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100589 .data = &uevent_helper,
590 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 .mode = 0644,
592 .proc_handler = &proc_dostring,
593 .strategy = &sysctl_string,
594 },
595#endif
596#ifdef CONFIG_CHR_DEV_SG
597 {
598 .ctl_name = KERN_SG_BIG_BUFF,
599 .procname = "sg-big-buff",
600 .data = &sg_big_buff,
601 .maxlen = sizeof (int),
602 .mode = 0444,
603 .proc_handler = &proc_dointvec,
604 },
605#endif
606#ifdef CONFIG_BSD_PROCESS_ACCT
607 {
608 .ctl_name = KERN_ACCT,
609 .procname = "acct",
610 .data = &acct_parm,
611 .maxlen = 3*sizeof(int),
612 .mode = 0644,
613 .proc_handler = &proc_dointvec,
614 },
615#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616#ifdef CONFIG_MAGIC_SYSRQ
617 {
618 .ctl_name = KERN_SYSRQ,
619 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800620 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 .maxlen = sizeof (int),
622 .mode = 0644,
623 .proc_handler = &proc_dointvec,
624 },
625#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700626#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700629 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 .maxlen = sizeof (int),
631 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700632 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700634#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 {
636 .ctl_name = KERN_MAX_THREADS,
637 .procname = "threads-max",
638 .data = &max_threads,
639 .maxlen = sizeof(int),
640 .mode = 0644,
641 .proc_handler = &proc_dointvec,
642 },
643 {
644 .ctl_name = KERN_RANDOM,
645 .procname = "random",
646 .mode = 0555,
647 .child = random_table,
648 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 {
650 .ctl_name = KERN_OVERFLOWUID,
651 .procname = "overflowuid",
652 .data = &overflowuid,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec_minmax,
656 .strategy = &sysctl_intvec,
657 .extra1 = &minolduid,
658 .extra2 = &maxolduid,
659 },
660 {
661 .ctl_name = KERN_OVERFLOWGID,
662 .procname = "overflowgid",
663 .data = &overflowgid,
664 .maxlen = sizeof(int),
665 .mode = 0644,
666 .proc_handler = &proc_dointvec_minmax,
667 .strategy = &sysctl_intvec,
668 .extra1 = &minolduid,
669 .extra2 = &maxolduid,
670 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800671#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672#ifdef CONFIG_MATHEMU
673 {
674 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
675 .procname = "ieee_emulation_warnings",
676 .data = &sysctl_ieee_emulation_warnings,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec,
680 },
681#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 {
683 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
684 .procname = "userprocess_debug",
685 .data = &sysctl_userprocess_debug,
686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec,
689 },
690#endif
691 {
692 .ctl_name = KERN_PIDMAX,
693 .procname = "pid_max",
694 .data = &pid_max,
695 .maxlen = sizeof (int),
696 .mode = 0644,
697 .proc_handler = &proc_dointvec_minmax,
698 .strategy = sysctl_intvec,
699 .extra1 = &pid_max_min,
700 .extra2 = &pid_max_max,
701 },
702 {
703 .ctl_name = KERN_PANIC_ON_OOPS,
704 .procname = "panic_on_oops",
705 .data = &panic_on_oops,
706 .maxlen = sizeof(int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
709 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800710#if defined CONFIG_PRINTK
711 {
712 .ctl_name = KERN_PRINTK,
713 .procname = "printk",
714 .data = &console_loglevel,
715 .maxlen = 4*sizeof(int),
716 .mode = 0644,
717 .proc_handler = &proc_dointvec,
718 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 {
720 .ctl_name = KERN_PRINTK_RATELIMIT,
721 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700722 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = &proc_dointvec_jiffies,
726 .strategy = &sysctl_jiffies,
727 },
728 {
729 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
730 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700731 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .maxlen = sizeof(int),
733 .mode = 0644,
734 .proc_handler = &proc_dointvec,
735 },
Dave Youngaf913222009-09-22 16:43:33 -0700736 {
737 .ctl_name = CTL_UNNUMBERED,
738 .procname = "printk_delay",
739 .data = &printk_delay_msec,
740 .maxlen = sizeof(int),
741 .mode = 0644,
742 .proc_handler = &proc_dointvec_minmax,
743 .strategy = &sysctl_intvec,
744 .extra1 = &zero,
745 .extra2 = &ten_thousand,
746 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800747#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 {
749 .ctl_name = KERN_NGROUPS_MAX,
750 .procname = "ngroups_max",
751 .data = &ngroups_max,
752 .maxlen = sizeof (int),
753 .mode = 0444,
754 .proc_handler = &proc_dointvec,
755 },
756#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
757 {
758 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
759 .procname = "unknown_nmi_panic",
760 .data = &unknown_nmi_panic,
761 .maxlen = sizeof (int),
762 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200763 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 },
Don Zickus407984f2006-09-26 10:52:27 +0200765 {
Don Zickus407984f2006-09-26 10:52:27 +0200766 .procname = "nmi_watchdog",
767 .data = &nmi_watchdog_enabled,
768 .maxlen = sizeof (int),
769 .mode = 0644,
770 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 },
772#endif
773#if defined(CONFIG_X86)
774 {
Don Zickus8da5add2006-09-26 10:52:27 +0200775 .ctl_name = KERN_PANIC_ON_NMI,
776 .procname = "panic_on_unrecovered_nmi",
777 .data = &panic_on_unrecovered_nmi,
778 .maxlen = sizeof(int),
779 .mode = 0644,
780 .proc_handler = &proc_dointvec,
781 },
782 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700783 .ctl_name = CTL_UNNUMBERED,
784 .procname = "panic_on_io_nmi",
785 .data = &panic_on_io_nmi,
786 .maxlen = sizeof(int),
787 .mode = 0644,
788 .proc_handler = &proc_dointvec,
789 },
790 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .ctl_name = KERN_BOOTLOADER_TYPE,
792 .procname = "bootloader_type",
793 .data = &bootloader_type,
794 .maxlen = sizeof (int),
795 .mode = 0444,
796 .proc_handler = &proc_dointvec,
797 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100798 {
799 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700800 .procname = "bootloader_version",
801 .data = &bootloader_version,
802 .maxlen = sizeof (int),
803 .mode = 0444,
804 .proc_handler = &proc_dointvec,
805 },
806 {
807 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100808 .procname = "kstack_depth_to_print",
809 .data = &kstack_depth_to_print,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = &proc_dointvec,
813 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100814 {
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "io_delay_type",
817 .data = &io_delay_type,
818 .maxlen = sizeof(int),
819 .mode = 0644,
820 .proc_handler = &proc_dointvec,
821 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800823#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 {
825 .ctl_name = KERN_RANDOMIZE,
826 .procname = "randomize_va_space",
827 .data = &randomize_va_space,
828 .maxlen = sizeof(int),
829 .mode = 0644,
830 .proc_handler = &proc_dointvec,
831 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800832#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800833#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700834 {
835 .ctl_name = KERN_SPIN_RETRY,
836 .procname = "spin_retry",
837 .data = &spin_retry,
838 .maxlen = sizeof (int),
839 .mode = 0644,
840 .proc_handler = &proc_dointvec,
841 },
842#endif
Len Brown673d5b42007-07-28 03:33:16 -0400843#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800844 {
Pavel Machekc255d842006-02-20 18:27:58 -0800845 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700846 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800847 .maxlen = sizeof (unsigned long),
848 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800849 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800850 },
851#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800852#ifdef CONFIG_IA64
853 {
854 .ctl_name = KERN_IA64_UNALIGNED,
855 .procname = "ignore-unaligned-usertrap",
856 .data = &no_unaligned_warning,
857 .maxlen = sizeof (int),
858 .mode = 0644,
859 .proc_handler = &proc_dointvec,
860 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800861 {
862 .ctl_name = CTL_UNNUMBERED,
863 .procname = "unaligned-dump-stack",
864 .data = &unaligned_dump_stack,
865 .maxlen = sizeof (int),
866 .mode = 0644,
867 .proc_handler = &proc_dointvec,
868 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800869#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700870#ifdef CONFIG_DETECT_SOFTLOCKUP
871 {
872 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200873 .procname = "softlockup_panic",
874 .data = &softlockup_panic,
875 .maxlen = sizeof(int),
876 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700877 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200878 .strategy = &sysctl_intvec,
879 .extra1 = &zero,
880 .extra2 = &one,
881 },
882 {
883 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700884 .procname = "softlockup_thresh",
885 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200886 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700887 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800888 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700889 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200890 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700891 .extra2 = &sixty,
892 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800893#endif
894#ifdef CONFIG_DETECT_HUNG_TASK
895 {
896 .ctl_name = CTL_UNNUMBERED,
897 .procname = "hung_task_panic",
898 .data = &sysctl_hung_task_panic,
899 .maxlen = sizeof(int),
900 .mode = 0644,
901 .proc_handler = &proc_dointvec_minmax,
902 .strategy = &sysctl_intvec,
903 .extra1 = &zero,
904 .extra2 = &one,
905 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100906 {
907 .ctl_name = CTL_UNNUMBERED,
908 .procname = "hung_task_check_count",
909 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100910 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100911 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100912 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100913 .strategy = &sysctl_intvec,
914 },
915 {
916 .ctl_name = CTL_UNNUMBERED,
917 .procname = "hung_task_timeout_secs",
918 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100919 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100920 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800921 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100922 .strategy = &sysctl_intvec,
923 },
924 {
925 .ctl_name = CTL_UNNUMBERED,
926 .procname = "hung_task_warnings",
927 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100928 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100929 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100930 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100931 .strategy = &sysctl_intvec,
932 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700933#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200934#ifdef CONFIG_COMPAT
935 {
936 .ctl_name = KERN_COMPAT_LOG,
937 .procname = "compat-log",
938 .data = &compat_log,
939 .maxlen = sizeof (int),
940 .mode = 0644,
941 .proc_handler = &proc_dointvec,
942 },
943#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700944#ifdef CONFIG_RT_MUTEXES
945 {
946 .ctl_name = KERN_MAX_LOCK_DEPTH,
947 .procname = "max_lock_depth",
948 .data = &max_lock_depth,
949 .maxlen = sizeof(int),
950 .mode = 0644,
951 .proc_handler = &proc_dointvec,
952 },
953#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700954 {
955 .ctl_name = CTL_UNNUMBERED,
956 .procname = "poweroff_cmd",
957 .data = &poweroff_cmd,
958 .maxlen = POWEROFF_CMD_PATH_LEN,
959 .mode = 0644,
960 .proc_handler = &proc_dostring,
961 .strategy = &sysctl_string,
962 },
David Howells0b77f5b2008-04-29 01:01:32 -0700963#ifdef CONFIG_KEYS
964 {
965 .ctl_name = CTL_UNNUMBERED,
966 .procname = "keys",
967 .mode = 0555,
968 .child = key_sysctls,
969 },
970#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700971#ifdef CONFIG_RCU_TORTURE_TEST
972 {
973 .ctl_name = CTL_UNNUMBERED,
974 .procname = "rcutorture_runnable",
975 .data = &rcutorture_runnable,
976 .maxlen = sizeof(int),
977 .mode = 0644,
978 .proc_handler = &proc_dointvec,
979 },
980#endif
David Howells12e22c52009-04-03 16:42:35 +0100981#ifdef CONFIG_SLOW_WORK
982 {
983 .ctl_name = CTL_UNNUMBERED,
984 .procname = "slow-work",
985 .mode = 0555,
986 .child = slow_work_sysctls,
987 },
988#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200989#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200990 {
991 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200992 .procname = "perf_event_paranoid",
993 .data = &sysctl_perf_event_paranoid,
994 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200995 .mode = 0644,
996 .proc_handler = &proc_dointvec,
997 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200998 {
999 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001000 .procname = "perf_event_mlock_kb",
1001 .data = &sysctl_perf_event_mlock,
1002 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001003 .mode = 0644,
1004 .proc_handler = &proc_dointvec,
1005 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001006 {
1007 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001008 .procname = "perf_event_max_sample_rate",
1009 .data = &sysctl_perf_event_sample_rate,
1010 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001011 .mode = 0644,
1012 .proc_handler = &proc_dointvec,
1013 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001014#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001015#ifdef CONFIG_KMEMCHECK
1016 {
1017 .ctl_name = CTL_UNNUMBERED,
1018 .procname = "kmemcheck",
1019 .data = &kmemcheck_enabled,
1020 .maxlen = sizeof(int),
1021 .mode = 0644,
1022 .proc_handler = &proc_dointvec,
1023 },
1024#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001025#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001026 {
1027 .ctl_name = CTL_UNNUMBERED,
1028 .procname = "blk_iopoll",
1029 .data = &blk_iopoll_enabled,
1030 .maxlen = sizeof(int),
1031 .mode = 0644,
1032 .proc_handler = &proc_dointvec,
1033 },
Jens Axboecb684b52009-09-15 21:53:11 +02001034#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001035/*
1036 * NOTE: do not add new entries to this table unless you have read
1037 * Documentation/sysctl/ctl_unnumbered.txt
1038 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 { .ctl_name = 0 }
1040};
1041
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001042static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 {
1044 .ctl_name = VM_OVERCOMMIT_MEMORY,
1045 .procname = "overcommit_memory",
1046 .data = &sysctl_overcommit_memory,
1047 .maxlen = sizeof(sysctl_overcommit_memory),
1048 .mode = 0644,
1049 .proc_handler = &proc_dointvec,
1050 },
1051 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001052 .ctl_name = VM_PANIC_ON_OOM,
1053 .procname = "panic_on_oom",
1054 .data = &sysctl_panic_on_oom,
1055 .maxlen = sizeof(sysctl_panic_on_oom),
1056 .mode = 0644,
1057 .proc_handler = &proc_dointvec,
1058 },
1059 {
David Rientjesfe071d72007-10-16 23:25:56 -07001060 .ctl_name = CTL_UNNUMBERED,
1061 .procname = "oom_kill_allocating_task",
1062 .data = &sysctl_oom_kill_allocating_task,
1063 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1064 .mode = 0644,
1065 .proc_handler = &proc_dointvec,
1066 },
1067 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001068 .ctl_name = CTL_UNNUMBERED,
1069 .procname = "oom_dump_tasks",
1070 .data = &sysctl_oom_dump_tasks,
1071 .maxlen = sizeof(sysctl_oom_dump_tasks),
1072 .mode = 0644,
1073 .proc_handler = &proc_dointvec,
1074 },
1075 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .ctl_name = VM_OVERCOMMIT_RATIO,
1077 .procname = "overcommit_ratio",
1078 .data = &sysctl_overcommit_ratio,
1079 .maxlen = sizeof(sysctl_overcommit_ratio),
1080 .mode = 0644,
1081 .proc_handler = &proc_dointvec,
1082 },
1083 {
1084 .ctl_name = VM_PAGE_CLUSTER,
1085 .procname = "page-cluster",
1086 .data = &page_cluster,
1087 .maxlen = sizeof(int),
1088 .mode = 0644,
1089 .proc_handler = &proc_dointvec,
1090 },
1091 {
1092 .ctl_name = VM_DIRTY_BACKGROUND,
1093 .procname = "dirty_background_ratio",
1094 .data = &dirty_background_ratio,
1095 .maxlen = sizeof(dirty_background_ratio),
1096 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001097 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 .strategy = &sysctl_intvec,
1099 .extra1 = &zero,
1100 .extra2 = &one_hundred,
1101 },
1102 {
David Rientjes2da02992009-01-06 14:39:31 -08001103 .ctl_name = CTL_UNNUMBERED,
1104 .procname = "dirty_background_bytes",
1105 .data = &dirty_background_bytes,
1106 .maxlen = sizeof(dirty_background_bytes),
1107 .mode = 0644,
1108 .proc_handler = &dirty_background_bytes_handler,
1109 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001110 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001111 },
1112 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 .ctl_name = VM_DIRTY_RATIO,
1114 .procname = "dirty_ratio",
1115 .data = &vm_dirty_ratio,
1116 .maxlen = sizeof(vm_dirty_ratio),
1117 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001118 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 .strategy = &sysctl_intvec,
1120 .extra1 = &zero,
1121 .extra2 = &one_hundred,
1122 },
1123 {
David Rientjes2da02992009-01-06 14:39:31 -08001124 .ctl_name = CTL_UNNUMBERED,
1125 .procname = "dirty_bytes",
1126 .data = &vm_dirty_bytes,
1127 .maxlen = sizeof(vm_dirty_bytes),
1128 .mode = 0644,
1129 .proc_handler = &dirty_bytes_handler,
1130 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001131 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001132 },
1133 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001135 .data = &dirty_writeback_interval,
1136 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 .mode = 0644,
1138 .proc_handler = &dirty_writeback_centisecs_handler,
1139 },
1140 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001142 .data = &dirty_expire_interval,
1143 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001145 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 },
1147 {
1148 .ctl_name = VM_NR_PDFLUSH_THREADS,
1149 .procname = "nr_pdflush_threads",
1150 .data = &nr_pdflush_threads,
1151 .maxlen = sizeof nr_pdflush_threads,
1152 .mode = 0444 /* read-only*/,
1153 .proc_handler = &proc_dointvec,
1154 },
1155 {
1156 .ctl_name = VM_SWAPPINESS,
1157 .procname = "swappiness",
1158 .data = &vm_swappiness,
1159 .maxlen = sizeof(vm_swappiness),
1160 .mode = 0644,
1161 .proc_handler = &proc_dointvec_minmax,
1162 .strategy = &sysctl_intvec,
1163 .extra1 = &zero,
1164 .extra2 = &one_hundred,
1165 },
1166#ifdef CONFIG_HUGETLB_PAGE
1167 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001169 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 .maxlen = sizeof(unsigned long),
1171 .mode = 0644,
1172 .proc_handler = &hugetlb_sysctl_handler,
1173 .extra1 = (void *)&hugetlb_zero,
1174 .extra2 = (void *)&hugetlb_infinity,
1175 },
1176 {
1177 .ctl_name = VM_HUGETLB_GROUP,
1178 .procname = "hugetlb_shm_group",
1179 .data = &sysctl_hugetlb_shm_group,
1180 .maxlen = sizeof(gid_t),
1181 .mode = 0644,
1182 .proc_handler = &proc_dointvec,
1183 },
Mel Gorman396faf02007-07-17 04:03:13 -07001184 {
1185 .ctl_name = CTL_UNNUMBERED,
1186 .procname = "hugepages_treat_as_movable",
1187 .data = &hugepages_treat_as_movable,
1188 .maxlen = sizeof(int),
1189 .mode = 0644,
1190 .proc_handler = &hugetlb_treat_movable_handler,
1191 },
Adam Litke54f9f802007-10-16 01:26:20 -07001192 {
1193 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001194 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001195 .data = NULL,
1196 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001197 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001198 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001199 .extra1 = (void *)&hugetlb_zero,
1200 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001201 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202#endif
David Howells03991232009-12-15 19:27:45 +00001203#ifdef CONFIG_MMU
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 {
1205 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1206 .procname = "lowmem_reserve_ratio",
1207 .data = &sysctl_lowmem_reserve_ratio,
1208 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1209 .mode = 0644,
1210 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1211 .strategy = &sysctl_intvec,
1212 },
1213 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001214 .ctl_name = VM_DROP_PAGECACHE,
1215 .procname = "drop_caches",
1216 .data = &sysctl_drop_caches,
1217 .maxlen = sizeof(int),
1218 .mode = 0644,
1219 .proc_handler = drop_caches_sysctl_handler,
1220 .strategy = &sysctl_intvec,
1221 },
1222 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 .ctl_name = VM_MIN_FREE_KBYTES,
1224 .procname = "min_free_kbytes",
1225 .data = &min_free_kbytes,
1226 .maxlen = sizeof(min_free_kbytes),
1227 .mode = 0644,
1228 .proc_handler = &min_free_kbytes_sysctl_handler,
1229 .strategy = &sysctl_intvec,
1230 .extra1 = &zero,
1231 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001232 {
1233 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1234 .procname = "percpu_pagelist_fraction",
1235 .data = &percpu_pagelist_fraction,
1236 .maxlen = sizeof(percpu_pagelist_fraction),
1237 .mode = 0644,
1238 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1239 .strategy = &sysctl_intvec,
1240 .extra1 = &min_percpu_pagelist_fract,
1241 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242#ifdef CONFIG_MMU
1243 {
1244 .ctl_name = VM_MAX_MAP_COUNT,
1245 .procname = "max_map_count",
1246 .data = &sysctl_max_map_count,
1247 .maxlen = sizeof(sysctl_max_map_count),
1248 .mode = 0644,
1249 .proc_handler = &proc_dointvec
1250 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001251#else
1252 {
1253 .ctl_name = CTL_UNNUMBERED,
1254 .procname = "nr_trim_pages",
1255 .data = &sysctl_nr_trim_pages,
1256 .maxlen = sizeof(sysctl_nr_trim_pages),
1257 .mode = 0644,
1258 .proc_handler = &proc_dointvec_minmax,
1259 .strategy = &sysctl_intvec,
1260 .extra1 = &zero,
1261 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262#endif
1263 {
1264 .ctl_name = VM_LAPTOP_MODE,
1265 .procname = "laptop_mode",
1266 .data = &laptop_mode,
1267 .maxlen = sizeof(laptop_mode),
1268 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001269 .proc_handler = &proc_dointvec_jiffies,
1270 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 },
1272 {
1273 .ctl_name = VM_BLOCK_DUMP,
1274 .procname = "block_dump",
1275 .data = &block_dump,
1276 .maxlen = sizeof(block_dump),
1277 .mode = 0644,
1278 .proc_handler = &proc_dointvec,
1279 .strategy = &sysctl_intvec,
1280 .extra1 = &zero,
1281 },
1282 {
1283 .ctl_name = VM_VFS_CACHE_PRESSURE,
1284 .procname = "vfs_cache_pressure",
1285 .data = &sysctl_vfs_cache_pressure,
1286 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1287 .mode = 0644,
1288 .proc_handler = &proc_dointvec,
1289 .strategy = &sysctl_intvec,
1290 .extra1 = &zero,
1291 },
1292#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1293 {
1294 .ctl_name = VM_LEGACY_VA_LAYOUT,
1295 .procname = "legacy_va_layout",
1296 .data = &sysctl_legacy_va_layout,
1297 .maxlen = sizeof(sysctl_legacy_va_layout),
1298 .mode = 0644,
1299 .proc_handler = &proc_dointvec,
1300 .strategy = &sysctl_intvec,
1301 .extra1 = &zero,
1302 },
1303#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001304#ifdef CONFIG_NUMA
1305 {
1306 .ctl_name = VM_ZONE_RECLAIM_MODE,
1307 .procname = "zone_reclaim_mode",
1308 .data = &zone_reclaim_mode,
1309 .maxlen = sizeof(zone_reclaim_mode),
1310 .mode = 0644,
1311 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001312 .strategy = &sysctl_intvec,
1313 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001314 },
Christoph Lameter96146342006-07-03 00:24:13 -07001315 {
1316 .ctl_name = VM_MIN_UNMAPPED,
1317 .procname = "min_unmapped_ratio",
1318 .data = &sysctl_min_unmapped_ratio,
1319 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1320 .mode = 0644,
1321 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1322 .strategy = &sysctl_intvec,
1323 .extra1 = &zero,
1324 .extra2 = &one_hundred,
1325 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001326 {
1327 .ctl_name = VM_MIN_SLAB,
1328 .procname = "min_slab_ratio",
1329 .data = &sysctl_min_slab_ratio,
1330 .maxlen = sizeof(sysctl_min_slab_ratio),
1331 .mode = 0644,
1332 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1333 .strategy = &sysctl_intvec,
1334 .extra1 = &zero,
1335 .extra2 = &one_hundred,
1336 },
Christoph Lameter17436602006-01-18 17:42:32 -08001337#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001338#ifdef CONFIG_SMP
1339 {
1340 .ctl_name = CTL_UNNUMBERED,
1341 .procname = "stat_interval",
1342 .data = &sysctl_stat_interval,
1343 .maxlen = sizeof(sysctl_stat_interval),
1344 .mode = 0644,
1345 .proc_handler = &proc_dointvec_jiffies,
1346 .strategy = &sysctl_jiffies,
1347 },
1348#endif
Eric Parised032182007-06-28 15:55:21 -04001349 {
1350 .ctl_name = CTL_UNNUMBERED,
1351 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001352 .data = &dac_mmap_min_addr,
1353 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001354 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001355 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001356 },
David Howells03991232009-12-15 19:27:45 +00001357#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001358#ifdef CONFIG_NUMA
1359 {
1360 .ctl_name = CTL_UNNUMBERED,
1361 .procname = "numa_zonelist_order",
1362 .data = &numa_zonelist_order,
1363 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1364 .mode = 0644,
1365 .proc_handler = &numa_zonelist_order_handler,
1366 .strategy = &sysctl_string,
1367 },
1368#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001369#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001370 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001371 {
1372 .ctl_name = VM_VDSO_ENABLED,
1373 .procname = "vdso_enabled",
1374 .data = &vdso_enabled,
1375 .maxlen = sizeof(vdso_enabled),
1376 .mode = 0644,
1377 .proc_handler = &proc_dointvec,
1378 .strategy = &sysctl_intvec,
1379 .extra1 = &zero,
1380 },
1381#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001382#ifdef CONFIG_HIGHMEM
1383 {
1384 .ctl_name = CTL_UNNUMBERED,
1385 .procname = "highmem_is_dirtyable",
1386 .data = &vm_highmem_is_dirtyable,
1387 .maxlen = sizeof(vm_highmem_is_dirtyable),
1388 .mode = 0644,
1389 .proc_handler = &proc_dointvec_minmax,
1390 .strategy = &sysctl_intvec,
1391 .extra1 = &zero,
1392 .extra2 = &one,
1393 },
1394#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001395 {
1396 .ctl_name = CTL_UNNUMBERED,
1397 .procname = "scan_unevictable_pages",
1398 .data = &scan_unevictable_pages,
1399 .maxlen = sizeof(scan_unevictable_pages),
1400 .mode = 0644,
1401 .proc_handler = &scan_unevictable_handler,
1402 },
Andi Kleen6a460792009-09-16 11:50:15 +02001403#ifdef CONFIG_MEMORY_FAILURE
1404 {
1405 .ctl_name = CTL_UNNUMBERED,
1406 .procname = "memory_failure_early_kill",
1407 .data = &sysctl_memory_failure_early_kill,
1408 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1409 .mode = 0644,
1410 .proc_handler = &proc_dointvec_minmax,
1411 .strategy = &sysctl_intvec,
1412 .extra1 = &zero,
1413 .extra2 = &one,
1414 },
1415 {
1416 .ctl_name = CTL_UNNUMBERED,
1417 .procname = "memory_failure_recovery",
1418 .data = &sysctl_memory_failure_recovery,
1419 .maxlen = sizeof(sysctl_memory_failure_recovery),
1420 .mode = 0644,
1421 .proc_handler = &proc_dointvec_minmax,
1422 .strategy = &sysctl_intvec,
1423 .extra1 = &zero,
1424 .extra2 = &one,
1425 },
1426#endif
1427
Andrew Morton2be7fe02007-07-15 23:41:21 -07001428/*
1429 * NOTE: do not add new entries to this table unless you have read
1430 * Documentation/sysctl/ctl_unnumbered.txt
1431 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 { .ctl_name = 0 }
1433};
1434
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001435#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001436static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001437 { .ctl_name = 0 }
1438};
1439#endif
1440
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001441static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 {
1443 .ctl_name = FS_NRINODE,
1444 .procname = "inode-nr",
1445 .data = &inodes_stat,
1446 .maxlen = 2*sizeof(int),
1447 .mode = 0444,
1448 .proc_handler = &proc_dointvec,
1449 },
1450 {
1451 .ctl_name = FS_STATINODE,
1452 .procname = "inode-state",
1453 .data = &inodes_stat,
1454 .maxlen = 7*sizeof(int),
1455 .mode = 0444,
1456 .proc_handler = &proc_dointvec,
1457 },
1458 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 .procname = "file-nr",
1460 .data = &files_stat,
1461 .maxlen = 3*sizeof(int),
1462 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001463 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 },
1465 {
1466 .ctl_name = FS_MAXFILE,
1467 .procname = "file-max",
1468 .data = &files_stat.max_files,
1469 .maxlen = sizeof(int),
1470 .mode = 0644,
1471 .proc_handler = &proc_dointvec,
1472 },
1473 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001474 .ctl_name = CTL_UNNUMBERED,
1475 .procname = "nr_open",
1476 .data = &sysctl_nr_open,
1477 .maxlen = sizeof(int),
1478 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001479 .proc_handler = &proc_dointvec_minmax,
1480 .extra1 = &sysctl_nr_open_min,
1481 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001482 },
1483 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 .ctl_name = FS_DENTRY,
1485 .procname = "dentry-state",
1486 .data = &dentry_stat,
1487 .maxlen = 6*sizeof(int),
1488 .mode = 0444,
1489 .proc_handler = &proc_dointvec,
1490 },
1491 {
1492 .ctl_name = FS_OVERFLOWUID,
1493 .procname = "overflowuid",
1494 .data = &fs_overflowuid,
1495 .maxlen = sizeof(int),
1496 .mode = 0644,
1497 .proc_handler = &proc_dointvec_minmax,
1498 .strategy = &sysctl_intvec,
1499 .extra1 = &minolduid,
1500 .extra2 = &maxolduid,
1501 },
1502 {
1503 .ctl_name = FS_OVERFLOWGID,
1504 .procname = "overflowgid",
1505 .data = &fs_overflowgid,
1506 .maxlen = sizeof(int),
1507 .mode = 0644,
1508 .proc_handler = &proc_dointvec_minmax,
1509 .strategy = &sysctl_intvec,
1510 .extra1 = &minolduid,
1511 .extra2 = &maxolduid,
1512 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001513#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 {
1515 .ctl_name = FS_LEASES,
1516 .procname = "leases-enable",
1517 .data = &leases_enable,
1518 .maxlen = sizeof(int),
1519 .mode = 0644,
1520 .proc_handler = &proc_dointvec,
1521 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001522#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523#ifdef CONFIG_DNOTIFY
1524 {
1525 .ctl_name = FS_DIR_NOTIFY,
1526 .procname = "dir-notify-enable",
1527 .data = &dir_notify_enable,
1528 .maxlen = sizeof(int),
1529 .mode = 0644,
1530 .proc_handler = &proc_dointvec,
1531 },
1532#endif
1533#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001534#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 {
1536 .ctl_name = FS_LEASE_TIME,
1537 .procname = "lease-break-time",
1538 .data = &lease_break_time,
1539 .maxlen = sizeof(int),
1540 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001541 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001543#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001544#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 .procname = "aio-nr",
1547 .data = &aio_nr,
1548 .maxlen = sizeof(aio_nr),
1549 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001550 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 },
1552 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 .procname = "aio-max-nr",
1554 .data = &aio_max_nr,
1555 .maxlen = sizeof(aio_max_nr),
1556 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001557 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001559#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001560#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001561 {
1562 .ctl_name = FS_INOTIFY,
1563 .procname = "inotify",
1564 .mode = 0555,
1565 .child = inotify_table,
1566 },
1567#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001568#ifdef CONFIG_EPOLL
1569 {
1570 .procname = "epoll",
1571 .mode = 0555,
1572 .child = epoll_table,
1573 },
1574#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001576 {
1577 .ctl_name = KERN_SETUID_DUMPABLE,
1578 .procname = "suid_dumpable",
1579 .data = &suid_dumpable,
1580 .maxlen = sizeof(int),
1581 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001582 .proc_handler = &proc_dointvec_minmax,
1583 .strategy = &sysctl_intvec,
1584 .extra1 = &zero,
1585 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001586 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001587#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1588 {
1589 .ctl_name = CTL_UNNUMBERED,
1590 .procname = "binfmt_misc",
1591 .mode = 0555,
1592 .child = binfmt_misc_table,
1593 },
1594#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001595/*
1596 * NOTE: do not add new entries to this table unless you have read
1597 * Documentation/sysctl/ctl_unnumbered.txt
1598 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 { .ctl_name = 0 }
1600};
1601
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001602static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001603#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001604 {
1605 .ctl_name = CTL_UNNUMBERED,
1606 .procname = "exception-trace",
1607 .data = &show_unhandled_signals,
1608 .maxlen = sizeof(int),
1609 .mode = 0644,
1610 .proc_handler = proc_dointvec
1611 },
1612#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 { .ctl_name = 0 }
1614};
1615
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001616static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001618};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
Al Viro330d57f2005-11-04 10:18:40 +00001620static DEFINE_SPINLOCK(sysctl_lock);
1621
1622/* called under sysctl_lock */
1623static int use_table(struct ctl_table_header *p)
1624{
1625 if (unlikely(p->unregistering))
1626 return 0;
1627 p->used++;
1628 return 1;
1629}
1630
1631/* called under sysctl_lock */
1632static void unuse_table(struct ctl_table_header *p)
1633{
1634 if (!--p->used)
1635 if (unlikely(p->unregistering))
1636 complete(p->unregistering);
1637}
1638
1639/* called under sysctl_lock, will reacquire if has to wait */
1640static void start_unregistering(struct ctl_table_header *p)
1641{
1642 /*
1643 * if p->used is 0, nobody will ever touch that entry again;
1644 * we'll eliminate all paths to it before dropping sysctl_lock
1645 */
1646 if (unlikely(p->used)) {
1647 struct completion wait;
1648 init_completion(&wait);
1649 p->unregistering = &wait;
1650 spin_unlock(&sysctl_lock);
1651 wait_for_completion(&wait);
1652 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001653 } else {
1654 /* anything non-NULL; we'll never dereference it */
1655 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001656 }
1657 /*
1658 * do not remove from the list until nobody holds it; walking the
1659 * list in do_sysctl() relies on that.
1660 */
1661 list_del_init(&p->ctl_entry);
1662}
1663
Al Virof7e6ced2008-07-15 01:44:23 -04001664void sysctl_head_get(struct ctl_table_header *head)
1665{
1666 spin_lock(&sysctl_lock);
1667 head->count++;
1668 spin_unlock(&sysctl_lock);
1669}
1670
1671void sysctl_head_put(struct ctl_table_header *head)
1672{
1673 spin_lock(&sysctl_lock);
1674 if (!--head->count)
1675 kfree(head);
1676 spin_unlock(&sysctl_lock);
1677}
1678
1679struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1680{
1681 if (!head)
1682 BUG();
1683 spin_lock(&sysctl_lock);
1684 if (!use_table(head))
1685 head = ERR_PTR(-ENOENT);
1686 spin_unlock(&sysctl_lock);
1687 return head;
1688}
1689
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001690void sysctl_head_finish(struct ctl_table_header *head)
1691{
1692 if (!head)
1693 return;
1694 spin_lock(&sysctl_lock);
1695 unuse_table(head);
1696 spin_unlock(&sysctl_lock);
1697}
1698
Al Viro73455092008-07-14 21:22:20 -04001699static struct ctl_table_set *
1700lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1701{
1702 struct ctl_table_set *set = &root->default_set;
1703 if (root->lookup)
1704 set = root->lookup(root, namespaces);
1705 return set;
1706}
1707
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001708static struct list_head *
1709lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001710{
Al Viro73455092008-07-14 21:22:20 -04001711 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1712 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001713}
1714
1715struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1716 struct ctl_table_header *prev)
1717{
1718 struct ctl_table_root *root;
1719 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001720 struct ctl_table_header *head;
1721 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001722
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001723 spin_lock(&sysctl_lock);
1724 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001725 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001726 tmp = &prev->ctl_entry;
1727 unuse_table(prev);
1728 goto next;
1729 }
1730 tmp = &root_table_header.ctl_entry;
1731 for (;;) {
1732 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1733
1734 if (!use_table(head))
1735 goto next;
1736 spin_unlock(&sysctl_lock);
1737 return head;
1738 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001739 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001740 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001741 header_list = lookup_header_list(root, namespaces);
1742 if (tmp != header_list)
1743 continue;
1744
1745 do {
1746 root = list_entry(root->root_list.next,
1747 struct ctl_table_root, root_list);
1748 if (root == &sysctl_table_root)
1749 goto out;
1750 header_list = lookup_header_list(root, namespaces);
1751 } while (list_empty(header_list));
1752 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001753 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001754out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001755 spin_unlock(&sysctl_lock);
1756 return NULL;
1757}
1758
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001759struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1760{
1761 return __sysctl_head_next(current->nsproxy, prev);
1762}
1763
1764void register_sysctl_root(struct ctl_table_root *root)
1765{
1766 spin_lock(&sysctl_lock);
1767 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1768 spin_unlock(&sysctl_lock);
1769}
1770
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001771#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001772/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001773static int do_sysctl_strategy(struct ctl_table_root *root,
1774 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001775 void __user *oldval, size_t __user *oldlenp,
1776 void __user *newval, size_t newlen)
1777{
1778 int op = 0, rc;
1779
1780 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001781 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001782 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001783 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001784 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001785 return -EPERM;
1786
1787 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001788 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001789 if (rc < 0)
1790 return rc;
1791 if (rc > 0)
1792 return 0;
1793 }
1794
1795 /* If there is no strategy routine, or if the strategy returns
1796 * zero, proceed with automatic r/w */
1797 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001798 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001799 if (rc < 0)
1800 return rc;
1801 }
1802 return 0;
1803}
1804
1805static int parse_table(int __user *name, int nlen,
1806 void __user *oldval, size_t __user *oldlenp,
1807 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001808 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001809 struct ctl_table *table)
1810{
1811 int n;
1812repeat:
1813 if (!nlen)
1814 return -ENOTDIR;
1815 if (get_user(n, name))
1816 return -EFAULT;
1817 for ( ; table->ctl_name || table->procname; table++) {
1818 if (!table->ctl_name)
1819 continue;
1820 if (n == table->ctl_name) {
1821 int error;
1822 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001823 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001824 return -EPERM;
1825 name++;
1826 nlen--;
1827 table = table->child;
1828 goto repeat;
1829 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001830 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001831 oldval, oldlenp,
1832 newval, newlen);
1833 return error;
1834 }
1835 }
1836 return -ENOTDIR;
1837}
1838
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1840 void __user *newval, size_t newlen)
1841{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001842 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001843 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
1845 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1846 return -ENOTDIR;
1847 if (oldval) {
1848 int old_len;
1849 if (!oldlenp || get_user(old_len, oldlenp))
1850 return -EFAULT;
1851 }
Al Viro330d57f2005-11-04 10:18:40 +00001852
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001853 for (head = sysctl_head_next(NULL); head;
1854 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001855 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001856 newval, newlen,
1857 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001858 if (error != -ENOTDIR) {
1859 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001860 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001861 }
1862 }
Al Viro330d57f2005-11-04 10:18:40 +00001863 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864}
1865
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001866SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867{
1868 struct __sysctl_args tmp;
1869 int error;
1870
1871 if (copy_from_user(&tmp, args, sizeof(tmp)))
1872 return -EFAULT;
1873
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001874 error = deprecated_sysctl_warning(&tmp);
1875 if (error)
1876 goto out;
1877
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 lock_kernel();
1879 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1880 tmp.newval, tmp.newlen);
1881 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001882out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 return error;
1884}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001885#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
1887/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001888 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 * some sysctl variables are readonly even to root.
1890 */
1891
1892static int test_perm(int mode, int op)
1893{
David Howells76aac0e2008-11-14 10:39:12 +11001894 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 mode >>= 6;
1896 else if (in_egroup_p(0))
1897 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001898 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 return 0;
1900 return -EACCES;
1901}
1902
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001903int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904{
1905 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001906 int mode;
1907
Al Viroe6305c42008-07-15 21:03:57 -04001908 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 if (error)
1910 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001911
1912 if (root->permissions)
1913 mode = root->permissions(root, current->nsproxy, table);
1914 else
1915 mode = table->mode;
1916
1917 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918}
1919
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001920static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1921{
1922 for (; table->ctl_name || table->procname; table++) {
1923 table->parent = parent;
1924 if (table->child)
1925 sysctl_set_parent(table, table->child);
1926 }
1927}
1928
1929static __init int sysctl_init(void)
1930{
1931 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001932#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1933 {
1934 int err;
1935 err = sysctl_check_table(current->nsproxy, root_table);
1936 }
1937#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001938 return 0;
1939}
1940
1941core_initcall(sysctl_init);
1942
Al Virobfbcf032008-07-27 06:31:22 +01001943static struct ctl_table *is_branch_in(struct ctl_table *branch,
1944 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001945{
1946 struct ctl_table *p;
1947 const char *s = branch->procname;
1948
1949 /* branch should have named subdirectory as its first element */
1950 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001951 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001952
1953 /* ... and nothing else */
1954 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001955 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001956
1957 /* table should contain subdirectory with the same name */
1958 for (p = table; p->procname || p->ctl_name; p++) {
1959 if (!p->child)
1960 continue;
1961 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001962 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001963 }
Al Virobfbcf032008-07-27 06:31:22 +01001964 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001965}
1966
1967/* see if attaching q to p would be an improvement */
1968static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1969{
1970 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001971 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001972 int is_better = 0;
1973 int not_in_parent = !p->attached_by;
1974
Al Virobfbcf032008-07-27 06:31:22 +01001975 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001976 if (by == q->attached_by)
1977 is_better = 1;
1978 if (to == p->attached_by)
1979 not_in_parent = 1;
1980 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001981 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001982 }
1983
1984 if (is_better && not_in_parent) {
1985 q->attached_by = by;
1986 q->attached_to = to;
1987 q->parent = p;
1988 }
1989}
1990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001992 * __register_sysctl_paths - register a sysctl hierarchy
1993 * @root: List of sysctl headers to register on
1994 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001995 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 *
1998 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001999 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002001 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 *
2003 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
2004 * must be unique within that level of sysctl
2005 *
2006 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2007 * enter a sysctl file
2008 *
2009 * data - a pointer to data for use by proc_handler
2010 *
2011 * maxlen - the maximum size in bytes of the data
2012 *
2013 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2014 *
2015 * child - a pointer to the child sysctl table if this entry is a directory, or
2016 * %NULL.
2017 *
2018 * proc_handler - the text handler routine (described below)
2019 *
2020 * strategy - the strategy routine (described below)
2021 *
2022 * de - for internal use by the sysctl routines
2023 *
2024 * extra1, extra2 - extra pointers usable by the proc handler routines
2025 *
2026 * Leaf nodes in the sysctl tree will be represented by a single file
2027 * under /proc; non-leaf nodes will be represented by directories.
2028 *
2029 * sysctl(2) can automatically manage read and write requests through
2030 * the sysctl table. The data and maxlen fields of the ctl_table
2031 * struct enable minimal validation of the values being written to be
2032 * performed, and the mode field allows minimal authentication.
2033 *
2034 * More sophisticated management can be enabled by the provision of a
2035 * strategy routine with the table entry. This will be called before
2036 * any automatic read or write of the data is performed.
2037 *
2038 * The strategy routine may return
2039 *
2040 * < 0 - Error occurred (error is passed to user process)
2041 *
2042 * 0 - OK - proceed with automatic read or write.
2043 *
2044 * > 0 - OK - read or write has been done by the strategy routine, so
2045 * return immediately.
2046 *
2047 * There must be a proc_handler routine for any terminal nodes
2048 * mirrored under /proc/sys (non-terminals are handled by a built-in
2049 * directory handler). Several default handlers are available to
2050 * cover common cases -
2051 *
2052 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2053 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2054 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2055 *
2056 * It is the handler's job to read the input buffer from user memory
2057 * and process it. The handler should return 0 on success.
2058 *
2059 * This routine returns %NULL on a failure to register, and a pointer
2060 * to the table header on success.
2061 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002062struct ctl_table_header *__register_sysctl_paths(
2063 struct ctl_table_root *root,
2064 struct nsproxy *namespaces,
2065 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002067 struct ctl_table_header *header;
2068 struct ctl_table *new, **prevp;
2069 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04002070 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002071
2072 /* Count the path components */
2073 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2074 ;
2075
2076 /*
2077 * For each path component, allocate a 2-element ctl_table array.
2078 * The first array element will be filled with the sysctl entry
2079 * for this, the second will be the sentinel (ctl_name == 0).
2080 *
2081 * We allocate everything in one go so that we don't have to
2082 * worry about freeing additional memory in unregister_sysctl_table.
2083 */
2084 header = kzalloc(sizeof(struct ctl_table_header) +
2085 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2086 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002088
2089 new = (struct ctl_table *) (header + 1);
2090
2091 /* Now connect the dots */
2092 prevp = &header->ctl_table;
2093 for (n = 0; n < npath; ++n, ++path) {
2094 /* Copy the procname */
2095 new->procname = path->procname;
2096 new->ctl_name = path->ctl_name;
2097 new->mode = 0555;
2098
2099 *prevp = new;
2100 prevp = &new->child;
2101
2102 new += 2;
2103 }
2104 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002105 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002106
2107 INIT_LIST_HEAD(&header->ctl_entry);
2108 header->used = 0;
2109 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002110 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002111 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002112 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002113#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002114 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002115 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002116 return NULL;
2117 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002118#endif
Al Viro330d57f2005-11-04 10:18:40 +00002119 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002120 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002121 header->attached_by = header->ctl_table;
2122 header->attached_to = root_table;
2123 header->parent = &root_table_header;
2124 for (set = header->set; set; set = set->parent) {
2125 struct ctl_table_header *p;
2126 list_for_each_entry(p, &set->list, ctl_entry) {
2127 if (p->unregistering)
2128 continue;
2129 try_attach(p, header);
2130 }
2131 }
2132 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002133 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002134 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002135
2136 return header;
2137}
2138
2139/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002140 * register_sysctl_table_path - register a sysctl table hierarchy
2141 * @path: The path to the directory the sysctl table is in.
2142 * @table: the top-level table structure
2143 *
2144 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2145 * array. A completely 0 filled entry terminates the table.
2146 *
2147 * See __register_sysctl_paths for more details.
2148 */
2149struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2150 struct ctl_table *table)
2151{
2152 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2153 path, table);
2154}
2155
2156/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002157 * register_sysctl_table - register a sysctl table hierarchy
2158 * @table: the top-level table structure
2159 *
2160 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2161 * array. A completely 0 filled entry terminates the table.
2162 *
2163 * See register_sysctl_paths for more details.
2164 */
2165struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2166{
2167 static const struct ctl_path null_path[] = { {} };
2168
2169 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170}
2171
2172/**
2173 * unregister_sysctl_table - unregister a sysctl table hierarchy
2174 * @header: the header returned from register_sysctl_table
2175 *
2176 * Unregisters the sysctl table and all children. proc entries may not
2177 * actually be removed until they are no longer used by anyone.
2178 */
2179void unregister_sysctl_table(struct ctl_table_header * header)
2180{
Al Viro330d57f2005-11-04 10:18:40 +00002181 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002182
2183 if (header == NULL)
2184 return;
2185
Al Viro330d57f2005-11-04 10:18:40 +00002186 spin_lock(&sysctl_lock);
2187 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002188 if (!--header->parent->count) {
2189 WARN_ON(1);
2190 kfree(header->parent);
2191 }
Al Virof7e6ced2008-07-15 01:44:23 -04002192 if (!--header->count)
2193 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002194 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195}
2196
Al Viro90434762008-07-15 08:54:06 -04002197int sysctl_is_seen(struct ctl_table_header *p)
2198{
2199 struct ctl_table_set *set = p->set;
2200 int res;
2201 spin_lock(&sysctl_lock);
2202 if (p->unregistering)
2203 res = 0;
2204 else if (!set->is_seen)
2205 res = 1;
2206 else
2207 res = set->is_seen(set);
2208 spin_unlock(&sysctl_lock);
2209 return res;
2210}
2211
Al Viro73455092008-07-14 21:22:20 -04002212void setup_sysctl_set(struct ctl_table_set *p,
2213 struct ctl_table_set *parent,
2214 int (*is_seen)(struct ctl_table_set *))
2215{
2216 INIT_LIST_HEAD(&p->list);
2217 p->parent = parent ? parent : &sysctl_table_root.default_set;
2218 p->is_seen = is_seen;
2219}
2220
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002221#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002222struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002223{
2224 return NULL;
2225}
2226
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002227struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2228 struct ctl_table *table)
2229{
2230 return NULL;
2231}
2232
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002233void unregister_sysctl_table(struct ctl_table_header * table)
2234{
2235}
2236
Al Viro73455092008-07-14 21:22:20 -04002237void setup_sysctl_set(struct ctl_table_set *p,
2238 struct ctl_table_set *parent,
2239 int (*is_seen)(struct ctl_table_set *))
2240{
2241}
2242
Al Virof7e6ced2008-07-15 01:44:23 -04002243void sysctl_head_put(struct ctl_table_header *head)
2244{
2245}
2246
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002247#endif /* CONFIG_SYSCTL */
2248
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249/*
2250 * /proc/sys support
2251 */
2252
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002253#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002255static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002256 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002257 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002258{
2259 size_t len;
2260 char __user *p;
2261 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002262
2263 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002264 *lenp = 0;
2265 return 0;
2266 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002267
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002268 if (write) {
2269 len = 0;
2270 p = buffer;
2271 while (len < *lenp) {
2272 if (get_user(c, p++))
2273 return -EFAULT;
2274 if (c == 0 || c == '\n')
2275 break;
2276 len++;
2277 }
2278 if (len >= maxlen)
2279 len = maxlen-1;
2280 if(copy_from_user(data, buffer, len))
2281 return -EFAULT;
2282 ((char *) data)[len] = 0;
2283 *ppos += *lenp;
2284 } else {
2285 len = strlen(data);
2286 if (len > maxlen)
2287 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002288
2289 if (*ppos > len) {
2290 *lenp = 0;
2291 return 0;
2292 }
2293
2294 data += *ppos;
2295 len -= *ppos;
2296
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002297 if (len > *lenp)
2298 len = *lenp;
2299 if (len)
2300 if(copy_to_user(buffer, data, len))
2301 return -EFAULT;
2302 if (len < *lenp) {
2303 if(put_user('\n', ((char __user *) buffer) + len))
2304 return -EFAULT;
2305 len++;
2306 }
2307 *lenp = len;
2308 *ppos += len;
2309 }
2310 return 0;
2311}
2312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313/**
2314 * proc_dostring - read a string sysctl
2315 * @table: the sysctl table
2316 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 * @buffer: the user buffer
2318 * @lenp: the size of the user buffer
2319 * @ppos: file position
2320 *
2321 * Reads/writes a string from/to the user buffer. If the kernel
2322 * buffer provided is not large enough to hold the string, the
2323 * string is truncated. The copied string is %NULL-terminated.
2324 * If the string is being read by the user process, it is copied
2325 * and a newline '\n' is added. It is truncated if the buffer is
2326 * not large enough.
2327 *
2328 * Returns 0 on success.
2329 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002330int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 void __user *buffer, size_t *lenp, loff_t *ppos)
2332{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002333 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002334 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335}
2336
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
2338static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2339 int *valp,
2340 int write, void *data)
2341{
2342 if (write) {
2343 *valp = *negp ? -*lvalp : *lvalp;
2344 } else {
2345 int val = *valp;
2346 if (val < 0) {
2347 *negp = -1;
2348 *lvalp = (unsigned long)-val;
2349 } else {
2350 *negp = 0;
2351 *lvalp = (unsigned long)val;
2352 }
2353 }
2354 return 0;
2355}
2356
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002357static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002358 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002359 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2361 int write, void *data),
2362 void *data)
2363{
2364#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002365 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 unsigned long lval;
2367 size_t left, len;
2368
2369 char buf[TMPBUFLEN], *p;
2370 char __user *s = buffer;
2371
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002372 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 (*ppos && !write)) {
2374 *lenp = 0;
2375 return 0;
2376 }
2377
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002378 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 vleft = table->maxlen / sizeof(*i);
2380 left = *lenp;
2381
2382 if (!conv)
2383 conv = do_proc_dointvec_conv;
2384
2385 for (; left && vleft--; i++, first=0) {
2386 if (write) {
2387 while (left) {
2388 char c;
2389 if (get_user(c, s))
2390 return -EFAULT;
2391 if (!isspace(c))
2392 break;
2393 left--;
2394 s++;
2395 }
2396 if (!left)
2397 break;
2398 neg = 0;
2399 len = left;
2400 if (len > sizeof(buf) - 1)
2401 len = sizeof(buf) - 1;
2402 if (copy_from_user(buf, s, len))
2403 return -EFAULT;
2404 buf[len] = 0;
2405 p = buf;
2406 if (*p == '-' && left > 1) {
2407 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002408 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 }
2410 if (*p < '0' || *p > '9')
2411 break;
2412
2413 lval = simple_strtoul(p, &p, 0);
2414
2415 len = p-buf;
2416 if ((len < left) && *p && !isspace(*p))
2417 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 s += len;
2419 left -= len;
2420
2421 if (conv(&neg, &lval, i, 1, data))
2422 break;
2423 } else {
2424 p = buf;
2425 if (!first)
2426 *p++ = '\t';
2427
2428 if (conv(&neg, &lval, i, 0, data))
2429 break;
2430
2431 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2432 len = strlen(buf);
2433 if (len > left)
2434 len = left;
2435 if(copy_to_user(s, buf, len))
2436 return -EFAULT;
2437 left -= len;
2438 s += len;
2439 }
2440 }
2441
2442 if (!write && !first && left) {
2443 if(put_user('\n', s))
2444 return -EFAULT;
2445 left--, s++;
2446 }
2447 if (write) {
2448 while (left) {
2449 char c;
2450 if (get_user(c, s++))
2451 return -EFAULT;
2452 if (!isspace(c))
2453 break;
2454 left--;
2455 }
2456 }
2457 if (write && first)
2458 return -EINVAL;
2459 *lenp -= left;
2460 *ppos += *lenp;
2461 return 0;
2462#undef TMPBUFLEN
2463}
2464
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002465static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002466 void __user *buffer, size_t *lenp, loff_t *ppos,
2467 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2468 int write, void *data),
2469 void *data)
2470{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002471 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002472 buffer, lenp, ppos, conv, data);
2473}
2474
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475/**
2476 * proc_dointvec - read a vector of integers
2477 * @table: the sysctl table
2478 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 * @buffer: the user buffer
2480 * @lenp: the size of the user buffer
2481 * @ppos: file position
2482 *
2483 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2484 * values from/to the user buffer, treated as an ASCII string.
2485 *
2486 * Returns 0 on success.
2487 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002488int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 void __user *buffer, size_t *lenp, loff_t *ppos)
2490{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002491 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 NULL,NULL);
2493}
2494
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002495/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002496 * Taint values can only be increased
2497 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002498 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002499static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002500 void __user *buffer, size_t *lenp, loff_t *ppos)
2501{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002502 struct ctl_table t;
2503 unsigned long tmptaint = get_taint();
2504 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002505
Bastian Blank91fcd412007-04-23 14:41:14 -07002506 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002507 return -EPERM;
2508
Andi Kleen25ddbb12008-10-15 22:01:41 -07002509 t = *table;
2510 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002511 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002512 if (err < 0)
2513 return err;
2514
2515 if (write) {
2516 /*
2517 * Poor man's atomic or. Not worth adding a primitive
2518 * to everyone's atomic.h for this
2519 */
2520 int i;
2521 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2522 if ((tmptaint >> i) & 1)
2523 add_taint(i);
2524 }
2525 }
2526
2527 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002528}
2529
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530struct do_proc_dointvec_minmax_conv_param {
2531 int *min;
2532 int *max;
2533};
2534
2535static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2536 int *valp,
2537 int write, void *data)
2538{
2539 struct do_proc_dointvec_minmax_conv_param *param = data;
2540 if (write) {
2541 int val = *negp ? -*lvalp : *lvalp;
2542 if ((param->min && *param->min > val) ||
2543 (param->max && *param->max < val))
2544 return -EINVAL;
2545 *valp = val;
2546 } else {
2547 int val = *valp;
2548 if (val < 0) {
2549 *negp = -1;
2550 *lvalp = (unsigned long)-val;
2551 } else {
2552 *negp = 0;
2553 *lvalp = (unsigned long)val;
2554 }
2555 }
2556 return 0;
2557}
2558
2559/**
2560 * proc_dointvec_minmax - read a vector of integers with min/max values
2561 * @table: the sysctl table
2562 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 * @buffer: the user buffer
2564 * @lenp: the size of the user buffer
2565 * @ppos: file position
2566 *
2567 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2568 * values from/to the user buffer, treated as an ASCII string.
2569 *
2570 * This routine will ensure the values are within the range specified by
2571 * table->extra1 (min) and table->extra2 (max).
2572 *
2573 * Returns 0 on success.
2574 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002575int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 void __user *buffer, size_t *lenp, loff_t *ppos)
2577{
2578 struct do_proc_dointvec_minmax_conv_param param = {
2579 .min = (int *) table->extra1,
2580 .max = (int *) table->extra2,
2581 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002582 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 do_proc_dointvec_minmax_conv, &param);
2584}
2585
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002586static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 void __user *buffer,
2588 size_t *lenp, loff_t *ppos,
2589 unsigned long convmul,
2590 unsigned long convdiv)
2591{
2592#define TMPBUFLEN 21
2593 unsigned long *i, *min, *max, val;
2594 int vleft, first=1, neg;
2595 size_t len, left;
2596 char buf[TMPBUFLEN], *p;
2597 char __user *s = buffer;
2598
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002599 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 (*ppos && !write)) {
2601 *lenp = 0;
2602 return 0;
2603 }
2604
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002605 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 min = (unsigned long *) table->extra1;
2607 max = (unsigned long *) table->extra2;
2608 vleft = table->maxlen / sizeof(unsigned long);
2609 left = *lenp;
2610
2611 for (; left && vleft--; i++, min++, max++, first=0) {
2612 if (write) {
2613 while (left) {
2614 char c;
2615 if (get_user(c, s))
2616 return -EFAULT;
2617 if (!isspace(c))
2618 break;
2619 left--;
2620 s++;
2621 }
2622 if (!left)
2623 break;
2624 neg = 0;
2625 len = left;
2626 if (len > TMPBUFLEN-1)
2627 len = TMPBUFLEN-1;
2628 if (copy_from_user(buf, s, len))
2629 return -EFAULT;
2630 buf[len] = 0;
2631 p = buf;
2632 if (*p == '-' && left > 1) {
2633 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002634 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 }
2636 if (*p < '0' || *p > '9')
2637 break;
2638 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2639 len = p-buf;
2640 if ((len < left) && *p && !isspace(*p))
2641 break;
2642 if (neg)
2643 val = -val;
2644 s += len;
2645 left -= len;
2646
2647 if(neg)
2648 continue;
2649 if ((min && val < *min) || (max && val > *max))
2650 continue;
2651 *i = val;
2652 } else {
2653 p = buf;
2654 if (!first)
2655 *p++ = '\t';
2656 sprintf(p, "%lu", convdiv * (*i) / convmul);
2657 len = strlen(buf);
2658 if (len > left)
2659 len = left;
2660 if(copy_to_user(s, buf, len))
2661 return -EFAULT;
2662 left -= len;
2663 s += len;
2664 }
2665 }
2666
2667 if (!write && !first && left) {
2668 if(put_user('\n', s))
2669 return -EFAULT;
2670 left--, s++;
2671 }
2672 if (write) {
2673 while (left) {
2674 char c;
2675 if (get_user(c, s++))
2676 return -EFAULT;
2677 if (!isspace(c))
2678 break;
2679 left--;
2680 }
2681 }
2682 if (write && first)
2683 return -EINVAL;
2684 *lenp -= left;
2685 *ppos += *lenp;
2686 return 0;
2687#undef TMPBUFLEN
2688}
2689
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002690static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002691 void __user *buffer,
2692 size_t *lenp, loff_t *ppos,
2693 unsigned long convmul,
2694 unsigned long convdiv)
2695{
2696 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002697 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002698}
2699
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700/**
2701 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2702 * @table: the sysctl table
2703 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 * @buffer: the user buffer
2705 * @lenp: the size of the user buffer
2706 * @ppos: file position
2707 *
2708 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2709 * values from/to the user buffer, treated as an ASCII string.
2710 *
2711 * This routine will ensure the values are within the range specified by
2712 * table->extra1 (min) and table->extra2 (max).
2713 *
2714 * Returns 0 on success.
2715 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002716int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 void __user *buffer, size_t *lenp, loff_t *ppos)
2718{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002719 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720}
2721
2722/**
2723 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2724 * @table: the sysctl table
2725 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 * @buffer: the user buffer
2727 * @lenp: the size of the user buffer
2728 * @ppos: file position
2729 *
2730 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2731 * values from/to the user buffer, treated as an ASCII string. The values
2732 * are treated as milliseconds, and converted to jiffies when they are stored.
2733 *
2734 * This routine will ensure the values are within the range specified by
2735 * table->extra1 (min) and table->extra2 (max).
2736 *
2737 * Returns 0 on success.
2738 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002739int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 void __user *buffer,
2741 size_t *lenp, loff_t *ppos)
2742{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002743 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 lenp, ppos, HZ, 1000l);
2745}
2746
2747
2748static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2749 int *valp,
2750 int write, void *data)
2751{
2752 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002753 if (*lvalp > LONG_MAX / HZ)
2754 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2756 } else {
2757 int val = *valp;
2758 unsigned long lval;
2759 if (val < 0) {
2760 *negp = -1;
2761 lval = (unsigned long)-val;
2762 } else {
2763 *negp = 0;
2764 lval = (unsigned long)val;
2765 }
2766 *lvalp = lval / HZ;
2767 }
2768 return 0;
2769}
2770
2771static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2772 int *valp,
2773 int write, void *data)
2774{
2775 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002776 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2777 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2779 } else {
2780 int val = *valp;
2781 unsigned long lval;
2782 if (val < 0) {
2783 *negp = -1;
2784 lval = (unsigned long)-val;
2785 } else {
2786 *negp = 0;
2787 lval = (unsigned long)val;
2788 }
2789 *lvalp = jiffies_to_clock_t(lval);
2790 }
2791 return 0;
2792}
2793
2794static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2795 int *valp,
2796 int write, void *data)
2797{
2798 if (write) {
2799 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2800 } else {
2801 int val = *valp;
2802 unsigned long lval;
2803 if (val < 0) {
2804 *negp = -1;
2805 lval = (unsigned long)-val;
2806 } else {
2807 *negp = 0;
2808 lval = (unsigned long)val;
2809 }
2810 *lvalp = jiffies_to_msecs(lval);
2811 }
2812 return 0;
2813}
2814
2815/**
2816 * proc_dointvec_jiffies - read a vector of integers as seconds
2817 * @table: the sysctl table
2818 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 * @buffer: the user buffer
2820 * @lenp: the size of the user buffer
2821 * @ppos: file position
2822 *
2823 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2824 * values from/to the user buffer, treated as an ASCII string.
2825 * The values read are assumed to be in seconds, and are converted into
2826 * jiffies.
2827 *
2828 * Returns 0 on success.
2829 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002830int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 void __user *buffer, size_t *lenp, loff_t *ppos)
2832{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002833 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 do_proc_dointvec_jiffies_conv,NULL);
2835}
2836
2837/**
2838 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2839 * @table: the sysctl table
2840 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 * @buffer: the user buffer
2842 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002843 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 *
2845 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2846 * values from/to the user buffer, treated as an ASCII string.
2847 * The values read are assumed to be in 1/USER_HZ seconds, and
2848 * are converted into jiffies.
2849 *
2850 * Returns 0 on success.
2851 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002852int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 void __user *buffer, size_t *lenp, loff_t *ppos)
2854{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002855 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 do_proc_dointvec_userhz_jiffies_conv,NULL);
2857}
2858
2859/**
2860 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2861 * @table: the sysctl table
2862 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 * @buffer: the user buffer
2864 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002865 * @ppos: file position
2866 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 *
2868 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2869 * values from/to the user buffer, treated as an ASCII string.
2870 * The values read are assumed to be in 1/1000 seconds, and
2871 * are converted into jiffies.
2872 *
2873 * Returns 0 on success.
2874 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002875int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 void __user *buffer, size_t *lenp, loff_t *ppos)
2877{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002878 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 do_proc_dointvec_ms_jiffies_conv, NULL);
2880}
2881
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002882static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002883 void __user *buffer, size_t *lenp, loff_t *ppos)
2884{
2885 struct pid *new_pid;
2886 pid_t tmp;
2887 int r;
2888
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002889 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002890
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002891 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002892 lenp, ppos, NULL, NULL);
2893 if (r || !write)
2894 return r;
2895
2896 new_pid = find_get_pid(tmp);
2897 if (!new_pid)
2898 return -ESRCH;
2899
2900 put_pid(xchg(&cad_pid, new_pid));
2901 return 0;
2902}
2903
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904#else /* CONFIG_PROC_FS */
2905
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002906int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 void __user *buffer, size_t *lenp, loff_t *ppos)
2908{
2909 return -ENOSYS;
2910}
2911
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002912int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 void __user *buffer, size_t *lenp, loff_t *ppos)
2914{
2915 return -ENOSYS;
2916}
2917
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002918int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 void __user *buffer, size_t *lenp, loff_t *ppos)
2920{
2921 return -ENOSYS;
2922}
2923
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002924int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 void __user *buffer, size_t *lenp, loff_t *ppos)
2926{
2927 return -ENOSYS;
2928}
2929
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002930int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 void __user *buffer, size_t *lenp, loff_t *ppos)
2932{
2933 return -ENOSYS;
2934}
2935
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002936int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 void __user *buffer, size_t *lenp, loff_t *ppos)
2938{
2939 return -ENOSYS;
2940}
2941
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002942int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 void __user *buffer, size_t *lenp, loff_t *ppos)
2944{
2945 return -ENOSYS;
2946}
2947
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002948int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 void __user *buffer,
2950 size_t *lenp, loff_t *ppos)
2951{
2952 return -ENOSYS;
2953}
2954
2955
2956#endif /* CONFIG_PROC_FS */
2957
2958
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002959#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960/*
2961 * General sysctl support routines
2962 */
2963
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002964/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002965int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002966 void __user *oldval, size_t __user *oldlenp,
2967 void __user *newval, size_t newlen)
2968{
2969 size_t len;
2970
2971 /* Get out of I don't have a variable */
2972 if (!table->data || !table->maxlen)
2973 return -ENOTDIR;
2974
2975 if (oldval && oldlenp) {
2976 if (get_user(len, oldlenp))
2977 return -EFAULT;
2978 if (len) {
2979 if (len > table->maxlen)
2980 len = table->maxlen;
2981 if (copy_to_user(oldval, table->data, len))
2982 return -EFAULT;
2983 if (put_user(len, oldlenp))
2984 return -EFAULT;
2985 }
2986 }
2987
2988 if (newval && newlen) {
2989 if (newlen > table->maxlen)
2990 newlen = table->maxlen;
2991
2992 if (copy_from_user(table->data, newval, newlen))
2993 return -EFAULT;
2994 }
2995 return 1;
2996}
2997
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002999int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003001 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 if (!table->data || !table->maxlen)
3004 return -ENOTDIR;
3005
3006 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003007 size_t bufsize;
3008 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003010 if (bufsize) {
3011 size_t len = strlen(table->data), copied;
3012
3013 /* This shouldn't trigger for a well-formed sysctl */
3014 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003016
3017 /* Copy up to a max of bufsize-1 bytes of the string */
3018 copied = (len >= bufsize) ? bufsize - 1 : len;
3019
3020 if (copy_to_user(oldval, table->data, copied) ||
3021 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003023 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 return -EFAULT;
3025 }
3026 }
3027 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003028 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 if (len > table->maxlen)
3030 len = table->maxlen;
3031 if(copy_from_user(table->data, newval, len))
3032 return -EFAULT;
3033 if (len == table->maxlen)
3034 len--;
3035 ((char *) table->data)[len] = 0;
3036 }
Yi Yang82c9df82005-12-30 16:37:10 +08003037 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038}
3039
3040/*
3041 * This function makes sure that all of the integers in the vector
3042 * are between the minimum and maximum values given in the arrays
3043 * table->extra1 and table->extra2, respectively.
3044 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003045int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003047 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048{
3049
3050 if (newval && newlen) {
3051 int __user *vec = (int __user *) newval;
3052 int *min = (int *) table->extra1;
3053 int *max = (int *) table->extra2;
3054 size_t length;
3055 int i;
3056
3057 if (newlen % sizeof(int) != 0)
3058 return -EINVAL;
3059
3060 if (!table->extra1 && !table->extra2)
3061 return 0;
3062
3063 if (newlen > table->maxlen)
3064 newlen = table->maxlen;
3065 length = newlen / sizeof(int);
3066
3067 for (i = 0; i < length; i++) {
3068 int value;
3069 if (get_user(value, vec + i))
3070 return -EFAULT;
3071 if (min && value < min[i])
3072 return -EINVAL;
3073 if (max && value > max[i])
3074 return -EINVAL;
3075 }
3076 }
3077 return 0;
3078}
3079
3080/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003081int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003083 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003085 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003087
3088 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003090 if (olen) {
3091 int val;
3092
3093 if (olen < sizeof(int))
3094 return -EINVAL;
3095
3096 val = *(int *)(table->data) / HZ;
3097 if (put_user(val, (int __user *)oldval))
3098 return -EFAULT;
3099 if (put_user(sizeof(int), oldlenp))
3100 return -EFAULT;
3101 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 }
3103 if (newval && newlen) {
3104 int new;
3105 if (newlen != sizeof(int))
3106 return -EINVAL;
3107 if (get_user(new, (int __user *)newval))
3108 return -EFAULT;
3109 *(int *)(table->data) = new*HZ;
3110 }
3111 return 1;
3112}
3113
3114/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003115int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003117 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003119 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003121
3122 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003124 if (olen) {
3125 int val;
3126
3127 if (olen < sizeof(int))
3128 return -EINVAL;
3129
3130 val = jiffies_to_msecs(*(int *)(table->data));
3131 if (put_user(val, (int __user *)oldval))
3132 return -EFAULT;
3133 if (put_user(sizeof(int), oldlenp))
3134 return -EFAULT;
3135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 }
3137 if (newval && newlen) {
3138 int new;
3139 if (newlen != sizeof(int))
3140 return -EINVAL;
3141 if (get_user(new, (int __user *)newval))
3142 return -EFAULT;
3143 *(int *)(table->data) = msecs_to_jiffies(new);
3144 }
3145 return 1;
3146}
3147
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003148
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003149
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003150#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
3152
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003153SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003155 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003156 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003157
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003158 if (copy_from_user(&tmp, args, sizeof(tmp)))
3159 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003160
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003161 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003162
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003163 /* If no error reading the parameters then just -ENOSYS ... */
3164 if (!error)
3165 error = -ENOSYS;
3166
3167 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168}
3169
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003170int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003171 void __user *oldval, size_t __user *oldlenp,
3172 void __user *newval, size_t newlen)
3173{
3174 return -ENOSYS;
3175}
3176
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003177int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003179 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180{
3181 return -ENOSYS;
3182}
3183
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003184int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003186 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187{
3188 return -ENOSYS;
3189}
3190
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003191int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003193 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194{
3195 return -ENOSYS;
3196}
3197
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003198int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003200 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201{
3202 return -ENOSYS;
3203}
3204
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003205#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003207static int deprecated_sysctl_warning(struct __sysctl_args *args)
3208{
3209 static int msg_count;
3210 int name[CTL_MAXNAME];
3211 int i;
3212
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003213 /* Check args->nlen. */
3214 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3215 return -ENOTDIR;
3216
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003217 /* Read in the sysctl name for better debug message logging */
3218 for (i = 0; i < args->nlen; i++)
3219 if (get_user(name[i], args->name + i))
3220 return -EFAULT;
3221
3222 /* Ignore accesses to kernel.version */
3223 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3224 return 0;
3225
3226 if (msg_count < 5) {
3227 msg_count++;
3228 printk(KERN_INFO
3229 "warning: process `%s' used the deprecated sysctl "
3230 "system call with ", current->comm);
3231 for (i = 0; i < args->nlen; i++)
3232 printk("%d.", name[i]);
3233 printk("\n");
3234 }
3235 return 0;
3236}
3237
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238/*
3239 * No sense putting this after each symbol definition, twice,
3240 * exception granted :-)
3241 */
3242EXPORT_SYMBOL(proc_dointvec);
3243EXPORT_SYMBOL(proc_dointvec_jiffies);
3244EXPORT_SYMBOL(proc_dointvec_minmax);
3245EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3246EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3247EXPORT_SYMBOL(proc_dostring);
3248EXPORT_SYMBOL(proc_doulongvec_minmax);
3249EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3250EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003251EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252EXPORT_SYMBOL(sysctl_intvec);
3253EXPORT_SYMBOL(sysctl_jiffies);
3254EXPORT_SYMBOL(sysctl_ms_jiffies);
3255EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003256EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257EXPORT_SYMBOL(unregister_sysctl_table);