blob: 3b05c2b088d2aab2647a20eeb02c2b45ee5c43d9 [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>
29#include <linux/utsname.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>
Peter Zijlstra1ccd1542009-04-09 10:53:45 +020052#include <linux/perf_counter.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[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max;
80extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080082extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080083extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020084extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010085extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040086extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000087#ifndef CONFIG_MMU
88extern int sysctl_nr_trim_pages;
89#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070090#ifdef CONFIG_RCU_TORTURE_TEST
91extern int rcutorture_runnable;
92#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070094/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080095#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020097static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098#endif
99
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700101static int __maybe_unused one = 1;
102static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800103static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700104static int one_hundred = 100;
Peter W Morrealefafd6882009-04-06 19:00:29 -0700105static int one_thousand = 1000;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108static int maxolduid = 65535;
109static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112static int ngroups_max = NGROUPS_MAX;
113
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200114#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115extern char modprobe_path[];
116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#ifdef CONFIG_CHR_DEV_SG
118extern int sg_big_buff;
119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
David S. Miller72c57ed2008-09-11 23:29:54 -0700121#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700122#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#endif
124
David S. Miller08714202008-11-16 23:49:24 -0800125#ifdef CONFIG_SPARC64
126extern int sysctl_tsb_ratio;
127#endif
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#ifdef __hppa__
130extern int pwrsw_enabled;
131extern int unaligned_enabled;
132#endif
133
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800134#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#ifdef CONFIG_MATHEMU
136extern int sysctl_ieee_emulation_warnings;
137#endif
138extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700139extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#endif
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#ifdef CONFIG_BSD_PROCESS_ACCT
143extern int acct_parm[];
144#endif
145
Jes Sorensend2b176e2006-02-28 09:42:23 -0800146#ifdef CONFIG_IA64
147extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800148extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800149#endif
150
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700151#ifdef CONFIG_RT_MUTEXES
152extern int max_lock_depth;
153#endif
154
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700155#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700157 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700158static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800159 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700160#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700161
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700162static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100163static struct ctl_table_root sysctl_table_root;
164static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100165 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100166 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400167 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400169 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100170};
171static struct ctl_table_root sysctl_table_root = {
172 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400173 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100174};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700176static struct ctl_table kern_table[];
177static struct ctl_table vm_table[];
178static struct ctl_table fs_table[];
179static struct ctl_table debug_table[];
180static struct ctl_table dev_table[];
181extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700182#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700183extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400184#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800185#ifdef CONFIG_EPOLL
186extern struct ctl_table epoll_table[];
187#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
190int sysctl_legacy_va_layout;
191#endif
192
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700193extern int prove_locking;
194extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196/* The default sysctl tables: */
197
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700198static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 {
200 .ctl_name = CTL_KERN,
201 .procname = "kernel",
202 .mode = 0555,
203 .child = kern_table,
204 },
205 {
206 .ctl_name = CTL_VM,
207 .procname = "vm",
208 .mode = 0555,
209 .child = vm_table,
210 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 .ctl_name = CTL_FS,
213 .procname = "fs",
214 .mode = 0555,
215 .child = fs_table,
216 },
217 {
218 .ctl_name = CTL_DEBUG,
219 .procname = "debug",
220 .mode = 0555,
221 .child = debug_table,
222 },
223 {
224 .ctl_name = CTL_DEV,
225 .procname = "dev",
226 .mode = 0555,
227 .child = dev_table,
228 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700229/*
230 * NOTE: do not add new entries to this table unless you have read
231 * Documentation/sysctl/ctl_unnumbered.txt
232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 { .ctl_name = 0 }
234};
235
Ingo Molnar77e54a12007-07-09 18:52:00 +0200236#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100237static int min_sched_granularity_ns = 100000; /* 100 usecs */
238static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
239static int min_wakeup_granularity_ns; /* 0 usecs */
240static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200241#endif
242
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700243static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244#ifdef CONFIG_SCHED_DEBUG
245 {
246 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100247 .procname = "sched_min_granularity_ns",
248 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249 .maxlen = sizeof(unsigned int),
250 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100251 .proc_handler = &sched_nr_latency_handler,
252 .strategy = &sysctl_intvec,
253 .extra1 = &min_sched_granularity_ns,
254 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200255 },
256 {
257 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200258 .procname = "sched_latency_ns",
259 .data = &sysctl_sched_latency,
260 .maxlen = sizeof(unsigned int),
261 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100262 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200263 .strategy = &sysctl_intvec,
264 .extra1 = &min_sched_granularity_ns,
265 .extra2 = &max_sched_granularity_ns,
266 },
267 {
268 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200269 .procname = "sched_wakeup_granularity_ns",
270 .data = &sysctl_sched_wakeup_granularity,
271 .maxlen = sizeof(unsigned int),
272 .mode = 0644,
273 .proc_handler = &proc_dointvec_minmax,
274 .strategy = &sysctl_intvec,
275 .extra1 = &min_wakeup_granularity_ns,
276 .extra2 = &max_wakeup_granularity_ns,
277 },
278 {
279 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200280 .procname = "sched_shares_ratelimit",
281 .data = &sysctl_sched_shares_ratelimit,
282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
284 .proc_handler = &proc_dointvec,
285 },
286 {
287 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200288 .procname = "sched_shares_thresh",
289 .data = &sysctl_sched_shares_thresh,
290 .maxlen = sizeof(unsigned int),
291 .mode = 0644,
292 .proc_handler = &proc_dointvec_minmax,
293 .strategy = &sysctl_intvec,
294 .extra1 = &zero,
295 },
296 {
297 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200298 .procname = "sched_child_runs_first",
299 .data = &sysctl_sched_child_runs_first,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
302 .proc_handler = &proc_dointvec,
303 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200304 {
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_features",
307 .data = &sysctl_sched_features,
308 .maxlen = sizeof(unsigned int),
309 .mode = 0644,
310 .proc_handler = &proc_dointvec,
311 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200312 {
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "sched_migration_cost",
315 .data = &sysctl_sched_migration_cost,
316 .maxlen = sizeof(unsigned int),
317 .mode = 0644,
318 .proc_handler = &proc_dointvec,
319 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100320 {
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_nr_migrate",
323 .data = &sysctl_sched_nr_migrate,
324 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100325 .mode = 0644,
326 .proc_handler = &proc_dointvec,
327 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200328#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200329 {
330 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100331 .procname = "sched_rt_period_us",
332 .data = &sysctl_sched_rt_period,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200335 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100336 },
337 {
338 .ctl_name = CTL_UNNUMBERED,
339 .procname = "sched_rt_runtime_us",
340 .data = &sysctl_sched_rt_runtime,
341 .maxlen = sizeof(int),
342 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200343 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100344 },
345 {
346 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200347 .procname = "sched_compat_yield",
348 .data = &sysctl_sched_compat_yield,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
352 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700353#ifdef CONFIG_PROVE_LOCKING
354 {
355 .ctl_name = CTL_UNNUMBERED,
356 .procname = "prove_locking",
357 .data = &prove_locking,
358 .maxlen = sizeof(int),
359 .mode = 0644,
360 .proc_handler = &proc_dointvec,
361 },
362#endif
363#ifdef CONFIG_LOCK_STAT
364 {
365 .ctl_name = CTL_UNNUMBERED,
366 .procname = "lock_stat",
367 .data = &lock_stat,
368 .maxlen = sizeof(int),
369 .mode = 0644,
370 .proc_handler = &proc_dointvec,
371 },
372#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200373 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 .ctl_name = KERN_PANIC,
375 .procname = "panic",
376 .data = &panic_timeout,
377 .maxlen = sizeof(int),
378 .mode = 0644,
379 .proc_handler = &proc_dointvec,
380 },
381 {
382 .ctl_name = KERN_CORE_USES_PID,
383 .procname = "core_uses_pid",
384 .data = &core_uses_pid,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = &proc_dointvec,
388 },
389 {
390 .ctl_name = KERN_CORE_PATTERN,
391 .procname = "core_pattern",
392 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700393 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 .mode = 0644,
395 .proc_handler = &proc_dostring,
396 .strategy = &sysctl_string,
397 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800398#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700401 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800402 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700403 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800405#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100406#ifdef CONFIG_LATENCYTOP
407 {
408 .procname = "latencytop",
409 .data = &latencytop_enabled,
410 .maxlen = sizeof(int),
411 .mode = 0644,
412 .proc_handler = &proc_dointvec,
413 },
414#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415#ifdef CONFIG_BLK_DEV_INITRD
416 {
417 .ctl_name = KERN_REALROOTDEV,
418 .procname = "real-root-dev",
419 .data = &real_root_dev,
420 .maxlen = sizeof(int),
421 .mode = 0644,
422 .proc_handler = &proc_dointvec,
423 },
424#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700425 {
426 .ctl_name = CTL_UNNUMBERED,
427 .procname = "print-fatal-signals",
428 .data = &print_fatal_signals,
429 .maxlen = sizeof(int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
432 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700433#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 {
435 .ctl_name = KERN_SPARC_REBOOT,
436 .procname = "reboot-cmd",
437 .data = reboot_command,
438 .maxlen = 256,
439 .mode = 0644,
440 .proc_handler = &proc_dostring,
441 .strategy = &sysctl_string,
442 },
443 {
444 .ctl_name = KERN_SPARC_STOP_A,
445 .procname = "stop-a",
446 .data = &stop_a_enabled,
447 .maxlen = sizeof (int),
448 .mode = 0644,
449 .proc_handler = &proc_dointvec,
450 },
451 {
452 .ctl_name = KERN_SPARC_SCONS_PWROFF,
453 .procname = "scons-poweroff",
454 .data = &scons_pwroff,
455 .maxlen = sizeof (int),
456 .mode = 0644,
457 .proc_handler = &proc_dointvec,
458 },
459#endif
David S. Miller08714202008-11-16 23:49:24 -0800460#ifdef CONFIG_SPARC64
461 {
462 .ctl_name = CTL_UNNUMBERED,
463 .procname = "tsb-ratio",
464 .data = &sysctl_tsb_ratio,
465 .maxlen = sizeof (int),
466 .mode = 0644,
467 .proc_handler = &proc_dointvec,
468 },
469#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470#ifdef __hppa__
471 {
472 .ctl_name = KERN_HPPA_PWRSW,
473 .procname = "soft-power",
474 .data = &pwrsw_enabled,
475 .maxlen = sizeof (int),
476 .mode = 0644,
477 .proc_handler = &proc_dointvec,
478 },
479 {
480 .ctl_name = KERN_HPPA_UNALIGNED,
481 .procname = "unaligned-trap",
482 .data = &unaligned_enabled,
483 .maxlen = sizeof (int),
484 .mode = 0644,
485 .proc_handler = &proc_dointvec,
486 },
487#endif
488 {
489 .ctl_name = KERN_CTLALTDEL,
490 .procname = "ctrl-alt-del",
491 .data = &C_A_D,
492 .maxlen = sizeof(int),
493 .mode = 0644,
494 .proc_handler = &proc_dointvec,
495 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400496#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200497 {
498 .ctl_name = CTL_UNNUMBERED,
499 .procname = "ftrace_enabled",
500 .data = &ftrace_enabled,
501 .maxlen = sizeof(int),
502 .mode = 0644,
503 .proc_handler = &ftrace_enable_sysctl,
504 },
505#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500506#ifdef CONFIG_STACK_TRACER
507 {
508 .ctl_name = CTL_UNNUMBERED,
509 .procname = "stack_tracer_enabled",
510 .data = &stack_tracer_enabled,
511 .maxlen = sizeof(int),
512 .mode = 0644,
513 .proc_handler = &stack_trace_sysctl,
514 },
515#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400516#ifdef CONFIG_TRACING
517 {
518 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100519 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400520 .data = &ftrace_dump_on_oops,
521 .maxlen = sizeof(int),
522 .mode = 0644,
523 .proc_handler = &proc_dointvec,
524 },
525#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200526#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 {
528 .ctl_name = KERN_MODPROBE,
529 .procname = "modprobe",
530 .data = &modprobe_path,
531 .maxlen = KMOD_PATH_LEN,
532 .mode = 0644,
533 .proc_handler = &proc_dostring,
534 .strategy = &sysctl_string,
535 },
536#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700537#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
539 .ctl_name = KERN_HOTPLUG,
540 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100541 .data = &uevent_helper,
542 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 .mode = 0644,
544 .proc_handler = &proc_dostring,
545 .strategy = &sysctl_string,
546 },
547#endif
548#ifdef CONFIG_CHR_DEV_SG
549 {
550 .ctl_name = KERN_SG_BIG_BUFF,
551 .procname = "sg-big-buff",
552 .data = &sg_big_buff,
553 .maxlen = sizeof (int),
554 .mode = 0444,
555 .proc_handler = &proc_dointvec,
556 },
557#endif
558#ifdef CONFIG_BSD_PROCESS_ACCT
559 {
560 .ctl_name = KERN_ACCT,
561 .procname = "acct",
562 .data = &acct_parm,
563 .maxlen = 3*sizeof(int),
564 .mode = 0644,
565 .proc_handler = &proc_dointvec,
566 },
567#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#ifdef CONFIG_MAGIC_SYSRQ
569 {
570 .ctl_name = KERN_SYSRQ,
571 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800572 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .maxlen = sizeof (int),
574 .mode = 0644,
575 .proc_handler = &proc_dointvec,
576 },
577#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700578#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700581 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .maxlen = sizeof (int),
583 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700584 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700586#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 {
588 .ctl_name = KERN_MAX_THREADS,
589 .procname = "threads-max",
590 .data = &max_threads,
591 .maxlen = sizeof(int),
592 .mode = 0644,
593 .proc_handler = &proc_dointvec,
594 },
595 {
596 .ctl_name = KERN_RANDOM,
597 .procname = "random",
598 .mode = 0555,
599 .child = random_table,
600 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 {
602 .ctl_name = KERN_OVERFLOWUID,
603 .procname = "overflowuid",
604 .data = &overflowuid,
605 .maxlen = sizeof(int),
606 .mode = 0644,
607 .proc_handler = &proc_dointvec_minmax,
608 .strategy = &sysctl_intvec,
609 .extra1 = &minolduid,
610 .extra2 = &maxolduid,
611 },
612 {
613 .ctl_name = KERN_OVERFLOWGID,
614 .procname = "overflowgid",
615 .data = &overflowgid,
616 .maxlen = sizeof(int),
617 .mode = 0644,
618 .proc_handler = &proc_dointvec_minmax,
619 .strategy = &sysctl_intvec,
620 .extra1 = &minolduid,
621 .extra2 = &maxolduid,
622 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800623#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624#ifdef CONFIG_MATHEMU
625 {
626 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
627 .procname = "ieee_emulation_warnings",
628 .data = &sysctl_ieee_emulation_warnings,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = &proc_dointvec,
632 },
633#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 {
635 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
636 .procname = "userprocess_debug",
637 .data = &sysctl_userprocess_debug,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 .proc_handler = &proc_dointvec,
641 },
642#endif
643 {
644 .ctl_name = KERN_PIDMAX,
645 .procname = "pid_max",
646 .data = &pid_max,
647 .maxlen = sizeof (int),
648 .mode = 0644,
649 .proc_handler = &proc_dointvec_minmax,
650 .strategy = sysctl_intvec,
651 .extra1 = &pid_max_min,
652 .extra2 = &pid_max_max,
653 },
654 {
655 .ctl_name = KERN_PANIC_ON_OOPS,
656 .procname = "panic_on_oops",
657 .data = &panic_on_oops,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 .proc_handler = &proc_dointvec,
661 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800662#if defined CONFIG_PRINTK
663 {
664 .ctl_name = KERN_PRINTK,
665 .procname = "printk",
666 .data = &console_loglevel,
667 .maxlen = 4*sizeof(int),
668 .mode = 0644,
669 .proc_handler = &proc_dointvec,
670 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 {
672 .ctl_name = KERN_PRINTK_RATELIMIT,
673 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700674 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 .maxlen = sizeof(int),
676 .mode = 0644,
677 .proc_handler = &proc_dointvec_jiffies,
678 .strategy = &sysctl_jiffies,
679 },
680 {
681 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
682 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700683 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec,
687 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800688#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 {
690 .ctl_name = KERN_NGROUPS_MAX,
691 .procname = "ngroups_max",
692 .data = &ngroups_max,
693 .maxlen = sizeof (int),
694 .mode = 0444,
695 .proc_handler = &proc_dointvec,
696 },
697#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
698 {
699 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
700 .procname = "unknown_nmi_panic",
701 .data = &unknown_nmi_panic,
702 .maxlen = sizeof (int),
703 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200704 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 },
Don Zickus407984f2006-09-26 10:52:27 +0200706 {
Don Zickus407984f2006-09-26 10:52:27 +0200707 .procname = "nmi_watchdog",
708 .data = &nmi_watchdog_enabled,
709 .maxlen = sizeof (int),
710 .mode = 0644,
711 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 },
713#endif
714#if defined(CONFIG_X86)
715 {
Don Zickus8da5add2006-09-26 10:52:27 +0200716 .ctl_name = KERN_PANIC_ON_NMI,
717 .procname = "panic_on_unrecovered_nmi",
718 .data = &panic_on_unrecovered_nmi,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
722 },
723 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 .ctl_name = KERN_BOOTLOADER_TYPE,
725 .procname = "bootloader_type",
726 .data = &bootloader_type,
727 .maxlen = sizeof (int),
728 .mode = 0444,
729 .proc_handler = &proc_dointvec,
730 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100731 {
732 .ctl_name = CTL_UNNUMBERED,
733 .procname = "kstack_depth_to_print",
734 .data = &kstack_depth_to_print,
735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
738 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100739 {
740 .ctl_name = CTL_UNNUMBERED,
741 .procname = "io_delay_type",
742 .data = &io_delay_type,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = &proc_dointvec,
746 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800748#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 {
750 .ctl_name = KERN_RANDOMIZE,
751 .procname = "randomize_va_space",
752 .data = &randomize_va_space,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = &proc_dointvec,
756 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800757#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800758#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700759 {
760 .ctl_name = KERN_SPIN_RETRY,
761 .procname = "spin_retry",
762 .data = &spin_retry,
763 .maxlen = sizeof (int),
764 .mode = 0644,
765 .proc_handler = &proc_dointvec,
766 },
767#endif
Len Brown673d5b42007-07-28 03:33:16 -0400768#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800769 {
Pavel Machekc255d842006-02-20 18:27:58 -0800770 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700771 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800772 .maxlen = sizeof (unsigned long),
773 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800774 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800775 },
776#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800777#ifdef CONFIG_IA64
778 {
779 .ctl_name = KERN_IA64_UNALIGNED,
780 .procname = "ignore-unaligned-usertrap",
781 .data = &no_unaligned_warning,
782 .maxlen = sizeof (int),
783 .mode = 0644,
784 .proc_handler = &proc_dointvec,
785 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800786 {
787 .ctl_name = CTL_UNNUMBERED,
788 .procname = "unaligned-dump-stack",
789 .data = &unaligned_dump_stack,
790 .maxlen = sizeof (int),
791 .mode = 0644,
792 .proc_handler = &proc_dointvec,
793 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800794#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700795#ifdef CONFIG_DETECT_SOFTLOCKUP
796 {
797 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200798 .procname = "softlockup_panic",
799 .data = &softlockup_panic,
800 .maxlen = sizeof(int),
801 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700802 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200803 .strategy = &sysctl_intvec,
804 .extra1 = &zero,
805 .extra2 = &one,
806 },
807 {
808 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700809 .procname = "softlockup_thresh",
810 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200811 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700812 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800813 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700814 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200815 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700816 .extra2 = &sixty,
817 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800818#endif
819#ifdef CONFIG_DETECT_HUNG_TASK
820 {
821 .ctl_name = CTL_UNNUMBERED,
822 .procname = "hung_task_panic",
823 .data = &sysctl_hung_task_panic,
824 .maxlen = sizeof(int),
825 .mode = 0644,
826 .proc_handler = &proc_dointvec_minmax,
827 .strategy = &sysctl_intvec,
828 .extra1 = &zero,
829 .extra2 = &one,
830 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100831 {
832 .ctl_name = CTL_UNNUMBERED,
833 .procname = "hung_task_check_count",
834 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100835 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100836 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100837 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100838 .strategy = &sysctl_intvec,
839 },
840 {
841 .ctl_name = CTL_UNNUMBERED,
842 .procname = "hung_task_timeout_secs",
843 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100844 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100845 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800846 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100847 .strategy = &sysctl_intvec,
848 },
849 {
850 .ctl_name = CTL_UNNUMBERED,
851 .procname = "hung_task_warnings",
852 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100853 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100854 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100855 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100856 .strategy = &sysctl_intvec,
857 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700858#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200859#ifdef CONFIG_COMPAT
860 {
861 .ctl_name = KERN_COMPAT_LOG,
862 .procname = "compat-log",
863 .data = &compat_log,
864 .maxlen = sizeof (int),
865 .mode = 0644,
866 .proc_handler = &proc_dointvec,
867 },
868#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700869#ifdef CONFIG_RT_MUTEXES
870 {
871 .ctl_name = KERN_MAX_LOCK_DEPTH,
872 .procname = "max_lock_depth",
873 .data = &max_lock_depth,
874 .maxlen = sizeof(int),
875 .mode = 0644,
876 .proc_handler = &proc_dointvec,
877 },
878#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700879 {
880 .ctl_name = CTL_UNNUMBERED,
881 .procname = "poweroff_cmd",
882 .data = &poweroff_cmd,
883 .maxlen = POWEROFF_CMD_PATH_LEN,
884 .mode = 0644,
885 .proc_handler = &proc_dostring,
886 .strategy = &sysctl_string,
887 },
David Howells0b77f5b2008-04-29 01:01:32 -0700888#ifdef CONFIG_KEYS
889 {
890 .ctl_name = CTL_UNNUMBERED,
891 .procname = "keys",
892 .mode = 0555,
893 .child = key_sysctls,
894 },
895#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700896#ifdef CONFIG_RCU_TORTURE_TEST
897 {
898 .ctl_name = CTL_UNNUMBERED,
899 .procname = "rcutorture_runnable",
900 .data = &rcutorture_runnable,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = &proc_dointvec,
904 },
905#endif
David Howells12e22c52009-04-03 16:42:35 +0100906#ifdef CONFIG_SLOW_WORK
907 {
908 .ctl_name = CTL_UNNUMBERED,
909 .procname = "slow-work",
910 .mode = 0555,
911 .child = slow_work_sysctls,
912 },
913#endif
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200914#ifdef CONFIG_PERF_COUNTERS
915 {
916 .ctl_name = CTL_UNNUMBERED,
917 .procname = "perf_counter_privileged",
918 .data = &sysctl_perf_counter_priv,
919 .maxlen = sizeof(sysctl_perf_counter_priv),
920 .mode = 0644,
921 .proc_handler = &proc_dointvec,
922 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200923 {
924 .ctl_name = CTL_UNNUMBERED,
925 .procname = "perf_counter_mlock_kb",
926 .data = &sysctl_perf_counter_mlock,
927 .maxlen = sizeof(sysctl_perf_counter_mlock),
928 .mode = 0644,
929 .proc_handler = &proc_dointvec,
930 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200931#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700932/*
933 * NOTE: do not add new entries to this table unless you have read
934 * Documentation/sysctl/ctl_unnumbered.txt
935 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 { .ctl_name = 0 }
937};
938
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700939static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 {
941 .ctl_name = VM_OVERCOMMIT_MEMORY,
942 .procname = "overcommit_memory",
943 .data = &sysctl_overcommit_memory,
944 .maxlen = sizeof(sysctl_overcommit_memory),
945 .mode = 0644,
946 .proc_handler = &proc_dointvec,
947 },
948 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700949 .ctl_name = VM_PANIC_ON_OOM,
950 .procname = "panic_on_oom",
951 .data = &sysctl_panic_on_oom,
952 .maxlen = sizeof(sysctl_panic_on_oom),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
955 },
956 {
David Rientjesfe071d72007-10-16 23:25:56 -0700957 .ctl_name = CTL_UNNUMBERED,
958 .procname = "oom_kill_allocating_task",
959 .data = &sysctl_oom_kill_allocating_task,
960 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
961 .mode = 0644,
962 .proc_handler = &proc_dointvec,
963 },
964 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800965 .ctl_name = CTL_UNNUMBERED,
966 .procname = "oom_dump_tasks",
967 .data = &sysctl_oom_dump_tasks,
968 .maxlen = sizeof(sysctl_oom_dump_tasks),
969 .mode = 0644,
970 .proc_handler = &proc_dointvec,
971 },
972 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 .ctl_name = VM_OVERCOMMIT_RATIO,
974 .procname = "overcommit_ratio",
975 .data = &sysctl_overcommit_ratio,
976 .maxlen = sizeof(sysctl_overcommit_ratio),
977 .mode = 0644,
978 .proc_handler = &proc_dointvec,
979 },
980 {
981 .ctl_name = VM_PAGE_CLUSTER,
982 .procname = "page-cluster",
983 .data = &page_cluster,
984 .maxlen = sizeof(int),
985 .mode = 0644,
986 .proc_handler = &proc_dointvec,
987 },
988 {
989 .ctl_name = VM_DIRTY_BACKGROUND,
990 .procname = "dirty_background_ratio",
991 .data = &dirty_background_ratio,
992 .maxlen = sizeof(dirty_background_ratio),
993 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800994 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 .strategy = &sysctl_intvec,
996 .extra1 = &zero,
997 .extra2 = &one_hundred,
998 },
999 {
David Rientjes2da02992009-01-06 14:39:31 -08001000 .ctl_name = CTL_UNNUMBERED,
1001 .procname = "dirty_background_bytes",
1002 .data = &dirty_background_bytes,
1003 .maxlen = sizeof(dirty_background_bytes),
1004 .mode = 0644,
1005 .proc_handler = &dirty_background_bytes_handler,
1006 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001007 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001008 },
1009 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 .ctl_name = VM_DIRTY_RATIO,
1011 .procname = "dirty_ratio",
1012 .data = &vm_dirty_ratio,
1013 .maxlen = sizeof(vm_dirty_ratio),
1014 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001015 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 .strategy = &sysctl_intvec,
1017 .extra1 = &zero,
1018 .extra2 = &one_hundred,
1019 },
1020 {
David Rientjes2da02992009-01-06 14:39:31 -08001021 .ctl_name = CTL_UNNUMBERED,
1022 .procname = "dirty_bytes",
1023 .data = &vm_dirty_bytes,
1024 .maxlen = sizeof(vm_dirty_bytes),
1025 .mode = 0644,
1026 .proc_handler = &dirty_bytes_handler,
1027 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001028 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001029 },
1030 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001032 .data = &dirty_writeback_interval,
1033 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 .mode = 0644,
1035 .proc_handler = &dirty_writeback_centisecs_handler,
1036 },
1037 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001039 .data = &dirty_expire_interval,
1040 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001042 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 },
1044 {
1045 .ctl_name = VM_NR_PDFLUSH_THREADS,
1046 .procname = "nr_pdflush_threads",
1047 .data = &nr_pdflush_threads,
1048 .maxlen = sizeof nr_pdflush_threads,
1049 .mode = 0444 /* read-only*/,
1050 .proc_handler = &proc_dointvec,
1051 },
1052 {
Peter W Morrealefafd6882009-04-06 19:00:29 -07001053 .ctl_name = CTL_UNNUMBERED,
1054 .procname = "nr_pdflush_threads_min",
1055 .data = &nr_pdflush_threads_min,
1056 .maxlen = sizeof nr_pdflush_threads_min,
1057 .mode = 0644 /* read-write */,
1058 .proc_handler = &proc_dointvec_minmax,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &one,
1061 .extra2 = &nr_pdflush_threads_max,
1062 },
1063 {
1064 .ctl_name = CTL_UNNUMBERED,
1065 .procname = "nr_pdflush_threads_max",
1066 .data = &nr_pdflush_threads_max,
1067 .maxlen = sizeof nr_pdflush_threads_max,
1068 .mode = 0644 /* read-write */,
1069 .proc_handler = &proc_dointvec_minmax,
1070 .strategy = &sysctl_intvec,
1071 .extra1 = &nr_pdflush_threads_min,
1072 .extra2 = &one_thousand,
1073 },
1074 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 .ctl_name = VM_SWAPPINESS,
1076 .procname = "swappiness",
1077 .data = &vm_swappiness,
1078 .maxlen = sizeof(vm_swappiness),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec_minmax,
1081 .strategy = &sysctl_intvec,
1082 .extra1 = &zero,
1083 .extra2 = &one_hundred,
1084 },
1085#ifdef CONFIG_HUGETLB_PAGE
1086 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001088 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 .maxlen = sizeof(unsigned long),
1090 .mode = 0644,
1091 .proc_handler = &hugetlb_sysctl_handler,
1092 .extra1 = (void *)&hugetlb_zero,
1093 .extra2 = (void *)&hugetlb_infinity,
1094 },
1095 {
1096 .ctl_name = VM_HUGETLB_GROUP,
1097 .procname = "hugetlb_shm_group",
1098 .data = &sysctl_hugetlb_shm_group,
1099 .maxlen = sizeof(gid_t),
1100 .mode = 0644,
1101 .proc_handler = &proc_dointvec,
1102 },
Mel Gorman396faf02007-07-17 04:03:13 -07001103 {
1104 .ctl_name = CTL_UNNUMBERED,
1105 .procname = "hugepages_treat_as_movable",
1106 .data = &hugepages_treat_as_movable,
1107 .maxlen = sizeof(int),
1108 .mode = 0644,
1109 .proc_handler = &hugetlb_treat_movable_handler,
1110 },
Adam Litke54f9f802007-10-16 01:26:20 -07001111 {
1112 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001113 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001114 .data = NULL,
1115 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001116 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001117 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001118 .extra1 = (void *)&hugetlb_zero,
1119 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001120 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121#endif
1122 {
1123 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1124 .procname = "lowmem_reserve_ratio",
1125 .data = &sysctl_lowmem_reserve_ratio,
1126 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1127 .mode = 0644,
1128 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1129 .strategy = &sysctl_intvec,
1130 },
1131 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001132 .ctl_name = VM_DROP_PAGECACHE,
1133 .procname = "drop_caches",
1134 .data = &sysctl_drop_caches,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
1137 .proc_handler = drop_caches_sysctl_handler,
1138 .strategy = &sysctl_intvec,
1139 },
1140 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 .ctl_name = VM_MIN_FREE_KBYTES,
1142 .procname = "min_free_kbytes",
1143 .data = &min_free_kbytes,
1144 .maxlen = sizeof(min_free_kbytes),
1145 .mode = 0644,
1146 .proc_handler = &min_free_kbytes_sysctl_handler,
1147 .strategy = &sysctl_intvec,
1148 .extra1 = &zero,
1149 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001150 {
1151 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1152 .procname = "percpu_pagelist_fraction",
1153 .data = &percpu_pagelist_fraction,
1154 .maxlen = sizeof(percpu_pagelist_fraction),
1155 .mode = 0644,
1156 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1157 .strategy = &sysctl_intvec,
1158 .extra1 = &min_percpu_pagelist_fract,
1159 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160#ifdef CONFIG_MMU
1161 {
1162 .ctl_name = VM_MAX_MAP_COUNT,
1163 .procname = "max_map_count",
1164 .data = &sysctl_max_map_count,
1165 .maxlen = sizeof(sysctl_max_map_count),
1166 .mode = 0644,
1167 .proc_handler = &proc_dointvec
1168 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001169#else
1170 {
1171 .ctl_name = CTL_UNNUMBERED,
1172 .procname = "nr_trim_pages",
1173 .data = &sysctl_nr_trim_pages,
1174 .maxlen = sizeof(sysctl_nr_trim_pages),
1175 .mode = 0644,
1176 .proc_handler = &proc_dointvec_minmax,
1177 .strategy = &sysctl_intvec,
1178 .extra1 = &zero,
1179 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#endif
1181 {
1182 .ctl_name = VM_LAPTOP_MODE,
1183 .procname = "laptop_mode",
1184 .data = &laptop_mode,
1185 .maxlen = sizeof(laptop_mode),
1186 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001187 .proc_handler = &proc_dointvec_jiffies,
1188 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 },
1190 {
1191 .ctl_name = VM_BLOCK_DUMP,
1192 .procname = "block_dump",
1193 .data = &block_dump,
1194 .maxlen = sizeof(block_dump),
1195 .mode = 0644,
1196 .proc_handler = &proc_dointvec,
1197 .strategy = &sysctl_intvec,
1198 .extra1 = &zero,
1199 },
1200 {
1201 .ctl_name = VM_VFS_CACHE_PRESSURE,
1202 .procname = "vfs_cache_pressure",
1203 .data = &sysctl_vfs_cache_pressure,
1204 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1205 .mode = 0644,
1206 .proc_handler = &proc_dointvec,
1207 .strategy = &sysctl_intvec,
1208 .extra1 = &zero,
1209 },
1210#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1211 {
1212 .ctl_name = VM_LEGACY_VA_LAYOUT,
1213 .procname = "legacy_va_layout",
1214 .data = &sysctl_legacy_va_layout,
1215 .maxlen = sizeof(sysctl_legacy_va_layout),
1216 .mode = 0644,
1217 .proc_handler = &proc_dointvec,
1218 .strategy = &sysctl_intvec,
1219 .extra1 = &zero,
1220 },
1221#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001222#ifdef CONFIG_NUMA
1223 {
1224 .ctl_name = VM_ZONE_RECLAIM_MODE,
1225 .procname = "zone_reclaim_mode",
1226 .data = &zone_reclaim_mode,
1227 .maxlen = sizeof(zone_reclaim_mode),
1228 .mode = 0644,
1229 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001230 .strategy = &sysctl_intvec,
1231 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001232 },
Christoph Lameter96146342006-07-03 00:24:13 -07001233 {
1234 .ctl_name = VM_MIN_UNMAPPED,
1235 .procname = "min_unmapped_ratio",
1236 .data = &sysctl_min_unmapped_ratio,
1237 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1238 .mode = 0644,
1239 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1240 .strategy = &sysctl_intvec,
1241 .extra1 = &zero,
1242 .extra2 = &one_hundred,
1243 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001244 {
1245 .ctl_name = VM_MIN_SLAB,
1246 .procname = "min_slab_ratio",
1247 .data = &sysctl_min_slab_ratio,
1248 .maxlen = sizeof(sysctl_min_slab_ratio),
1249 .mode = 0644,
1250 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1251 .strategy = &sysctl_intvec,
1252 .extra1 = &zero,
1253 .extra2 = &one_hundred,
1254 },
Christoph Lameter17436602006-01-18 17:42:32 -08001255#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001256#ifdef CONFIG_SMP
1257 {
1258 .ctl_name = CTL_UNNUMBERED,
1259 .procname = "stat_interval",
1260 .data = &sysctl_stat_interval,
1261 .maxlen = sizeof(sysctl_stat_interval),
1262 .mode = 0644,
1263 .proc_handler = &proc_dointvec_jiffies,
1264 .strategy = &sysctl_jiffies,
1265 },
1266#endif
Eric Parised032182007-06-28 15:55:21 -04001267#ifdef CONFIG_SECURITY
1268 {
1269 .ctl_name = CTL_UNNUMBERED,
1270 .procname = "mmap_min_addr",
1271 .data = &mmap_min_addr,
1272 .maxlen = sizeof(unsigned long),
1273 .mode = 0644,
1274 .proc_handler = &proc_doulongvec_minmax,
1275 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001276#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001277#ifdef CONFIG_NUMA
1278 {
1279 .ctl_name = CTL_UNNUMBERED,
1280 .procname = "numa_zonelist_order",
1281 .data = &numa_zonelist_order,
1282 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1283 .mode = 0644,
1284 .proc_handler = &numa_zonelist_order_handler,
1285 .strategy = &sysctl_string,
1286 },
1287#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001288#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001289 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001290 {
1291 .ctl_name = VM_VDSO_ENABLED,
1292 .procname = "vdso_enabled",
1293 .data = &vdso_enabled,
1294 .maxlen = sizeof(vdso_enabled),
1295 .mode = 0644,
1296 .proc_handler = &proc_dointvec,
1297 .strategy = &sysctl_intvec,
1298 .extra1 = &zero,
1299 },
1300#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001301#ifdef CONFIG_HIGHMEM
1302 {
1303 .ctl_name = CTL_UNNUMBERED,
1304 .procname = "highmem_is_dirtyable",
1305 .data = &vm_highmem_is_dirtyable,
1306 .maxlen = sizeof(vm_highmem_is_dirtyable),
1307 .mode = 0644,
1308 .proc_handler = &proc_dointvec_minmax,
1309 .strategy = &sysctl_intvec,
1310 .extra1 = &zero,
1311 .extra2 = &one,
1312 },
1313#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001314#ifdef CONFIG_UNEVICTABLE_LRU
1315 {
1316 .ctl_name = CTL_UNNUMBERED,
1317 .procname = "scan_unevictable_pages",
1318 .data = &scan_unevictable_pages,
1319 .maxlen = sizeof(scan_unevictable_pages),
1320 .mode = 0644,
1321 .proc_handler = &scan_unevictable_handler,
1322 },
1323#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001324/*
1325 * NOTE: do not add new entries to this table unless you have read
1326 * Documentation/sysctl/ctl_unnumbered.txt
1327 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 { .ctl_name = 0 }
1329};
1330
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001331#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001332static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001333 { .ctl_name = 0 }
1334};
1335#endif
1336
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001337static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 {
1339 .ctl_name = FS_NRINODE,
1340 .procname = "inode-nr",
1341 .data = &inodes_stat,
1342 .maxlen = 2*sizeof(int),
1343 .mode = 0444,
1344 .proc_handler = &proc_dointvec,
1345 },
1346 {
1347 .ctl_name = FS_STATINODE,
1348 .procname = "inode-state",
1349 .data = &inodes_stat,
1350 .maxlen = 7*sizeof(int),
1351 .mode = 0444,
1352 .proc_handler = &proc_dointvec,
1353 },
1354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .procname = "file-nr",
1356 .data = &files_stat,
1357 .maxlen = 3*sizeof(int),
1358 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001359 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 },
1361 {
1362 .ctl_name = FS_MAXFILE,
1363 .procname = "file-max",
1364 .data = &files_stat.max_files,
1365 .maxlen = sizeof(int),
1366 .mode = 0644,
1367 .proc_handler = &proc_dointvec,
1368 },
1369 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001370 .ctl_name = CTL_UNNUMBERED,
1371 .procname = "nr_open",
1372 .data = &sysctl_nr_open,
1373 .maxlen = sizeof(int),
1374 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001375 .proc_handler = &proc_dointvec_minmax,
1376 .extra1 = &sysctl_nr_open_min,
1377 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001378 },
1379 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 .ctl_name = FS_DENTRY,
1381 .procname = "dentry-state",
1382 .data = &dentry_stat,
1383 .maxlen = 6*sizeof(int),
1384 .mode = 0444,
1385 .proc_handler = &proc_dointvec,
1386 },
1387 {
1388 .ctl_name = FS_OVERFLOWUID,
1389 .procname = "overflowuid",
1390 .data = &fs_overflowuid,
1391 .maxlen = sizeof(int),
1392 .mode = 0644,
1393 .proc_handler = &proc_dointvec_minmax,
1394 .strategy = &sysctl_intvec,
1395 .extra1 = &minolduid,
1396 .extra2 = &maxolduid,
1397 },
1398 {
1399 .ctl_name = FS_OVERFLOWGID,
1400 .procname = "overflowgid",
1401 .data = &fs_overflowgid,
1402 .maxlen = sizeof(int),
1403 .mode = 0644,
1404 .proc_handler = &proc_dointvec_minmax,
1405 .strategy = &sysctl_intvec,
1406 .extra1 = &minolduid,
1407 .extra2 = &maxolduid,
1408 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001409#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 {
1411 .ctl_name = FS_LEASES,
1412 .procname = "leases-enable",
1413 .data = &leases_enable,
1414 .maxlen = sizeof(int),
1415 .mode = 0644,
1416 .proc_handler = &proc_dointvec,
1417 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001418#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419#ifdef CONFIG_DNOTIFY
1420 {
1421 .ctl_name = FS_DIR_NOTIFY,
1422 .procname = "dir-notify-enable",
1423 .data = &dir_notify_enable,
1424 .maxlen = sizeof(int),
1425 .mode = 0644,
1426 .proc_handler = &proc_dointvec,
1427 },
1428#endif
1429#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001430#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 {
1432 .ctl_name = FS_LEASE_TIME,
1433 .procname = "lease-break-time",
1434 .data = &lease_break_time,
1435 .maxlen = sizeof(int),
1436 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001437 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001439#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001440#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 .procname = "aio-nr",
1443 .data = &aio_nr,
1444 .maxlen = sizeof(aio_nr),
1445 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001446 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 },
1448 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 .procname = "aio-max-nr",
1450 .data = &aio_max_nr,
1451 .maxlen = sizeof(aio_max_nr),
1452 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001453 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001455#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001456#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001457 {
1458 .ctl_name = FS_INOTIFY,
1459 .procname = "inotify",
1460 .mode = 0555,
1461 .child = inotify_table,
1462 },
1463#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001464#ifdef CONFIG_EPOLL
1465 {
1466 .procname = "epoll",
1467 .mode = 0555,
1468 .child = epoll_table,
1469 },
1470#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001472 {
1473 .ctl_name = KERN_SETUID_DUMPABLE,
1474 .procname = "suid_dumpable",
1475 .data = &suid_dumpable,
1476 .maxlen = sizeof(int),
1477 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001478 .proc_handler = &proc_dointvec_minmax,
1479 .strategy = &sysctl_intvec,
1480 .extra1 = &zero,
1481 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001482 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001483#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1484 {
1485 .ctl_name = CTL_UNNUMBERED,
1486 .procname = "binfmt_misc",
1487 .mode = 0555,
1488 .child = binfmt_misc_table,
1489 },
1490#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001491/*
1492 * NOTE: do not add new entries to this table unless you have read
1493 * Documentation/sysctl/ctl_unnumbered.txt
1494 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 { .ctl_name = 0 }
1496};
1497
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001498static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001499#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001500 {
1501 .ctl_name = CTL_UNNUMBERED,
1502 .procname = "exception-trace",
1503 .data = &show_unhandled_signals,
1504 .maxlen = sizeof(int),
1505 .mode = 0644,
1506 .proc_handler = proc_dointvec
1507 },
1508#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 { .ctl_name = 0 }
1510};
1511
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001512static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001514};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Al Viro330d57f2005-11-04 10:18:40 +00001516static DEFINE_SPINLOCK(sysctl_lock);
1517
1518/* called under sysctl_lock */
1519static int use_table(struct ctl_table_header *p)
1520{
1521 if (unlikely(p->unregistering))
1522 return 0;
1523 p->used++;
1524 return 1;
1525}
1526
1527/* called under sysctl_lock */
1528static void unuse_table(struct ctl_table_header *p)
1529{
1530 if (!--p->used)
1531 if (unlikely(p->unregistering))
1532 complete(p->unregistering);
1533}
1534
1535/* called under sysctl_lock, will reacquire if has to wait */
1536static void start_unregistering(struct ctl_table_header *p)
1537{
1538 /*
1539 * if p->used is 0, nobody will ever touch that entry again;
1540 * we'll eliminate all paths to it before dropping sysctl_lock
1541 */
1542 if (unlikely(p->used)) {
1543 struct completion wait;
1544 init_completion(&wait);
1545 p->unregistering = &wait;
1546 spin_unlock(&sysctl_lock);
1547 wait_for_completion(&wait);
1548 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001549 } else {
1550 /* anything non-NULL; we'll never dereference it */
1551 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001552 }
1553 /*
1554 * do not remove from the list until nobody holds it; walking the
1555 * list in do_sysctl() relies on that.
1556 */
1557 list_del_init(&p->ctl_entry);
1558}
1559
Al Virof7e6ced2008-07-15 01:44:23 -04001560void sysctl_head_get(struct ctl_table_header *head)
1561{
1562 spin_lock(&sysctl_lock);
1563 head->count++;
1564 spin_unlock(&sysctl_lock);
1565}
1566
1567void sysctl_head_put(struct ctl_table_header *head)
1568{
1569 spin_lock(&sysctl_lock);
1570 if (!--head->count)
1571 kfree(head);
1572 spin_unlock(&sysctl_lock);
1573}
1574
1575struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1576{
1577 if (!head)
1578 BUG();
1579 spin_lock(&sysctl_lock);
1580 if (!use_table(head))
1581 head = ERR_PTR(-ENOENT);
1582 spin_unlock(&sysctl_lock);
1583 return head;
1584}
1585
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001586void sysctl_head_finish(struct ctl_table_header *head)
1587{
1588 if (!head)
1589 return;
1590 spin_lock(&sysctl_lock);
1591 unuse_table(head);
1592 spin_unlock(&sysctl_lock);
1593}
1594
Al Viro73455092008-07-14 21:22:20 -04001595static struct ctl_table_set *
1596lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1597{
1598 struct ctl_table_set *set = &root->default_set;
1599 if (root->lookup)
1600 set = root->lookup(root, namespaces);
1601 return set;
1602}
1603
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001604static struct list_head *
1605lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001606{
Al Viro73455092008-07-14 21:22:20 -04001607 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1608 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001609}
1610
1611struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1612 struct ctl_table_header *prev)
1613{
1614 struct ctl_table_root *root;
1615 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001616 struct ctl_table_header *head;
1617 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001618
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001619 spin_lock(&sysctl_lock);
1620 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001621 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001622 tmp = &prev->ctl_entry;
1623 unuse_table(prev);
1624 goto next;
1625 }
1626 tmp = &root_table_header.ctl_entry;
1627 for (;;) {
1628 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1629
1630 if (!use_table(head))
1631 goto next;
1632 spin_unlock(&sysctl_lock);
1633 return head;
1634 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001635 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001636 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001637 header_list = lookup_header_list(root, namespaces);
1638 if (tmp != header_list)
1639 continue;
1640
1641 do {
1642 root = list_entry(root->root_list.next,
1643 struct ctl_table_root, root_list);
1644 if (root == &sysctl_table_root)
1645 goto out;
1646 header_list = lookup_header_list(root, namespaces);
1647 } while (list_empty(header_list));
1648 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001649 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001650out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001651 spin_unlock(&sysctl_lock);
1652 return NULL;
1653}
1654
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001655struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1656{
1657 return __sysctl_head_next(current->nsproxy, prev);
1658}
1659
1660void register_sysctl_root(struct ctl_table_root *root)
1661{
1662 spin_lock(&sysctl_lock);
1663 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1664 spin_unlock(&sysctl_lock);
1665}
1666
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001667#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001668/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001669static int do_sysctl_strategy(struct ctl_table_root *root,
1670 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001671 void __user *oldval, size_t __user *oldlenp,
1672 void __user *newval, size_t newlen)
1673{
1674 int op = 0, rc;
1675
1676 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001677 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001678 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001679 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001680 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001681 return -EPERM;
1682
1683 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001684 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001685 if (rc < 0)
1686 return rc;
1687 if (rc > 0)
1688 return 0;
1689 }
1690
1691 /* If there is no strategy routine, or if the strategy returns
1692 * zero, proceed with automatic r/w */
1693 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001694 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001695 if (rc < 0)
1696 return rc;
1697 }
1698 return 0;
1699}
1700
1701static int parse_table(int __user *name, int nlen,
1702 void __user *oldval, size_t __user *oldlenp,
1703 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001704 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001705 struct ctl_table *table)
1706{
1707 int n;
1708repeat:
1709 if (!nlen)
1710 return -ENOTDIR;
1711 if (get_user(n, name))
1712 return -EFAULT;
1713 for ( ; table->ctl_name || table->procname; table++) {
1714 if (!table->ctl_name)
1715 continue;
1716 if (n == table->ctl_name) {
1717 int error;
1718 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001719 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001720 return -EPERM;
1721 name++;
1722 nlen--;
1723 table = table->child;
1724 goto repeat;
1725 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001726 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001727 oldval, oldlenp,
1728 newval, newlen);
1729 return error;
1730 }
1731 }
1732 return -ENOTDIR;
1733}
1734
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1736 void __user *newval, size_t newlen)
1737{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001738 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001739 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1742 return -ENOTDIR;
1743 if (oldval) {
1744 int old_len;
1745 if (!oldlenp || get_user(old_len, oldlenp))
1746 return -EFAULT;
1747 }
Al Viro330d57f2005-11-04 10:18:40 +00001748
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001749 for (head = sysctl_head_next(NULL); head;
1750 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001751 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001752 newval, newlen,
1753 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001754 if (error != -ENOTDIR) {
1755 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001756 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001757 }
1758 }
Al Viro330d57f2005-11-04 10:18:40 +00001759 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760}
1761
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001762SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763{
1764 struct __sysctl_args tmp;
1765 int error;
1766
1767 if (copy_from_user(&tmp, args, sizeof(tmp)))
1768 return -EFAULT;
1769
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001770 error = deprecated_sysctl_warning(&tmp);
1771 if (error)
1772 goto out;
1773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 lock_kernel();
1775 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1776 tmp.newval, tmp.newlen);
1777 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001778out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 return error;
1780}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001781#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001784 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 * some sysctl variables are readonly even to root.
1786 */
1787
1788static int test_perm(int mode, int op)
1789{
David Howells76aac0e2008-11-14 10:39:12 +11001790 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 mode >>= 6;
1792 else if (in_egroup_p(0))
1793 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001794 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 return 0;
1796 return -EACCES;
1797}
1798
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001799int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800{
1801 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001802 int mode;
1803
Al Viroe6305c42008-07-15 21:03:57 -04001804 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 if (error)
1806 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001807
1808 if (root->permissions)
1809 mode = root->permissions(root, current->nsproxy, table);
1810 else
1811 mode = table->mode;
1812
1813 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814}
1815
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001816static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1817{
1818 for (; table->ctl_name || table->procname; table++) {
1819 table->parent = parent;
1820 if (table->child)
1821 sysctl_set_parent(table, table->child);
1822 }
1823}
1824
1825static __init int sysctl_init(void)
1826{
1827 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001828#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1829 {
1830 int err;
1831 err = sysctl_check_table(current->nsproxy, root_table);
1832 }
1833#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001834 return 0;
1835}
1836
1837core_initcall(sysctl_init);
1838
Al Virobfbcf032008-07-27 06:31:22 +01001839static struct ctl_table *is_branch_in(struct ctl_table *branch,
1840 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001841{
1842 struct ctl_table *p;
1843 const char *s = branch->procname;
1844
1845 /* branch should have named subdirectory as its first element */
1846 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001847 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001848
1849 /* ... and nothing else */
1850 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001851 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001852
1853 /* table should contain subdirectory with the same name */
1854 for (p = table; p->procname || p->ctl_name; p++) {
1855 if (!p->child)
1856 continue;
1857 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001858 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001859 }
Al Virobfbcf032008-07-27 06:31:22 +01001860 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001861}
1862
1863/* see if attaching q to p would be an improvement */
1864static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1865{
1866 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001867 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001868 int is_better = 0;
1869 int not_in_parent = !p->attached_by;
1870
Al Virobfbcf032008-07-27 06:31:22 +01001871 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001872 if (by == q->attached_by)
1873 is_better = 1;
1874 if (to == p->attached_by)
1875 not_in_parent = 1;
1876 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001877 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001878 }
1879
1880 if (is_better && not_in_parent) {
1881 q->attached_by = by;
1882 q->attached_to = to;
1883 q->parent = p;
1884 }
1885}
1886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001888 * __register_sysctl_paths - register a sysctl hierarchy
1889 * @root: List of sysctl headers to register on
1890 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001891 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 *
1894 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001895 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001897 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 *
1899 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1900 * must be unique within that level of sysctl
1901 *
1902 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1903 * enter a sysctl file
1904 *
1905 * data - a pointer to data for use by proc_handler
1906 *
1907 * maxlen - the maximum size in bytes of the data
1908 *
1909 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1910 *
1911 * child - a pointer to the child sysctl table if this entry is a directory, or
1912 * %NULL.
1913 *
1914 * proc_handler - the text handler routine (described below)
1915 *
1916 * strategy - the strategy routine (described below)
1917 *
1918 * de - for internal use by the sysctl routines
1919 *
1920 * extra1, extra2 - extra pointers usable by the proc handler routines
1921 *
1922 * Leaf nodes in the sysctl tree will be represented by a single file
1923 * under /proc; non-leaf nodes will be represented by directories.
1924 *
1925 * sysctl(2) can automatically manage read and write requests through
1926 * the sysctl table. The data and maxlen fields of the ctl_table
1927 * struct enable minimal validation of the values being written to be
1928 * performed, and the mode field allows minimal authentication.
1929 *
1930 * More sophisticated management can be enabled by the provision of a
1931 * strategy routine with the table entry. This will be called before
1932 * any automatic read or write of the data is performed.
1933 *
1934 * The strategy routine may return
1935 *
1936 * < 0 - Error occurred (error is passed to user process)
1937 *
1938 * 0 - OK - proceed with automatic read or write.
1939 *
1940 * > 0 - OK - read or write has been done by the strategy routine, so
1941 * return immediately.
1942 *
1943 * There must be a proc_handler routine for any terminal nodes
1944 * mirrored under /proc/sys (non-terminals are handled by a built-in
1945 * directory handler). Several default handlers are available to
1946 * cover common cases -
1947 *
1948 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1949 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1950 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1951 *
1952 * It is the handler's job to read the input buffer from user memory
1953 * and process it. The handler should return 0 on success.
1954 *
1955 * This routine returns %NULL on a failure to register, and a pointer
1956 * to the table header on success.
1957 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001958struct ctl_table_header *__register_sysctl_paths(
1959 struct ctl_table_root *root,
1960 struct nsproxy *namespaces,
1961 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001963 struct ctl_table_header *header;
1964 struct ctl_table *new, **prevp;
1965 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001966 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001967
1968 /* Count the path components */
1969 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1970 ;
1971
1972 /*
1973 * For each path component, allocate a 2-element ctl_table array.
1974 * The first array element will be filled with the sysctl entry
1975 * for this, the second will be the sentinel (ctl_name == 0).
1976 *
1977 * We allocate everything in one go so that we don't have to
1978 * worry about freeing additional memory in unregister_sysctl_table.
1979 */
1980 header = kzalloc(sizeof(struct ctl_table_header) +
1981 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1982 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001984
1985 new = (struct ctl_table *) (header + 1);
1986
1987 /* Now connect the dots */
1988 prevp = &header->ctl_table;
1989 for (n = 0; n < npath; ++n, ++path) {
1990 /* Copy the procname */
1991 new->procname = path->procname;
1992 new->ctl_name = path->ctl_name;
1993 new->mode = 0555;
1994
1995 *prevp = new;
1996 prevp = &new->child;
1997
1998 new += 2;
1999 }
2000 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002001 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002002
2003 INIT_LIST_HEAD(&header->ctl_entry);
2004 header->used = 0;
2005 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002006 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002007 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002008 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002009#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002010 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002011 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002012 return NULL;
2013 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002014#endif
Al Viro330d57f2005-11-04 10:18:40 +00002015 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002016 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002017 header->attached_by = header->ctl_table;
2018 header->attached_to = root_table;
2019 header->parent = &root_table_header;
2020 for (set = header->set; set; set = set->parent) {
2021 struct ctl_table_header *p;
2022 list_for_each_entry(p, &set->list, ctl_entry) {
2023 if (p->unregistering)
2024 continue;
2025 try_attach(p, header);
2026 }
2027 }
2028 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002029 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002030 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002031
2032 return header;
2033}
2034
2035/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002036 * register_sysctl_table_path - register a sysctl table hierarchy
2037 * @path: The path to the directory the sysctl table is in.
2038 * @table: the top-level table structure
2039 *
2040 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2041 * array. A completely 0 filled entry terminates the table.
2042 *
2043 * See __register_sysctl_paths for more details.
2044 */
2045struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2046 struct ctl_table *table)
2047{
2048 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2049 path, table);
2050}
2051
2052/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002053 * register_sysctl_table - register a sysctl table hierarchy
2054 * @table: the top-level table structure
2055 *
2056 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2057 * array. A completely 0 filled entry terminates the table.
2058 *
2059 * See register_sysctl_paths for more details.
2060 */
2061struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2062{
2063 static const struct ctl_path null_path[] = { {} };
2064
2065 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066}
2067
2068/**
2069 * unregister_sysctl_table - unregister a sysctl table hierarchy
2070 * @header: the header returned from register_sysctl_table
2071 *
2072 * Unregisters the sysctl table and all children. proc entries may not
2073 * actually be removed until they are no longer used by anyone.
2074 */
2075void unregister_sysctl_table(struct ctl_table_header * header)
2076{
Al Viro330d57f2005-11-04 10:18:40 +00002077 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002078
2079 if (header == NULL)
2080 return;
2081
Al Viro330d57f2005-11-04 10:18:40 +00002082 spin_lock(&sysctl_lock);
2083 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002084 if (!--header->parent->count) {
2085 WARN_ON(1);
2086 kfree(header->parent);
2087 }
Al Virof7e6ced2008-07-15 01:44:23 -04002088 if (!--header->count)
2089 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002090 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
Al Viro9043476f2008-07-15 08:54:06 -04002093int sysctl_is_seen(struct ctl_table_header *p)
2094{
2095 struct ctl_table_set *set = p->set;
2096 int res;
2097 spin_lock(&sysctl_lock);
2098 if (p->unregistering)
2099 res = 0;
2100 else if (!set->is_seen)
2101 res = 1;
2102 else
2103 res = set->is_seen(set);
2104 spin_unlock(&sysctl_lock);
2105 return res;
2106}
2107
Al Viro73455092008-07-14 21:22:20 -04002108void setup_sysctl_set(struct ctl_table_set *p,
2109 struct ctl_table_set *parent,
2110 int (*is_seen)(struct ctl_table_set *))
2111{
2112 INIT_LIST_HEAD(&p->list);
2113 p->parent = parent ? parent : &sysctl_table_root.default_set;
2114 p->is_seen = is_seen;
2115}
2116
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002117#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002118struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002119{
2120 return NULL;
2121}
2122
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002123struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2124 struct ctl_table *table)
2125{
2126 return NULL;
2127}
2128
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002129void unregister_sysctl_table(struct ctl_table_header * table)
2130{
2131}
2132
Al Viro73455092008-07-14 21:22:20 -04002133void setup_sysctl_set(struct ctl_table_set *p,
2134 struct ctl_table_set *parent,
2135 int (*is_seen)(struct ctl_table_set *))
2136{
2137}
2138
Al Virof7e6ced2008-07-15 01:44:23 -04002139void sysctl_head_put(struct ctl_table_header *head)
2140{
2141}
2142
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002143#endif /* CONFIG_SYSCTL */
2144
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145/*
2146 * /proc/sys support
2147 */
2148
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002149#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002151static int _proc_do_string(void* data, int maxlen, int write,
2152 struct file *filp, void __user *buffer,
2153 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002154{
2155 size_t len;
2156 char __user *p;
2157 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002158
2159 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002160 *lenp = 0;
2161 return 0;
2162 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002163
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002164 if (write) {
2165 len = 0;
2166 p = buffer;
2167 while (len < *lenp) {
2168 if (get_user(c, p++))
2169 return -EFAULT;
2170 if (c == 0 || c == '\n')
2171 break;
2172 len++;
2173 }
2174 if (len >= maxlen)
2175 len = maxlen-1;
2176 if(copy_from_user(data, buffer, len))
2177 return -EFAULT;
2178 ((char *) data)[len] = 0;
2179 *ppos += *lenp;
2180 } else {
2181 len = strlen(data);
2182 if (len > maxlen)
2183 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002184
2185 if (*ppos > len) {
2186 *lenp = 0;
2187 return 0;
2188 }
2189
2190 data += *ppos;
2191 len -= *ppos;
2192
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002193 if (len > *lenp)
2194 len = *lenp;
2195 if (len)
2196 if(copy_to_user(buffer, data, len))
2197 return -EFAULT;
2198 if (len < *lenp) {
2199 if(put_user('\n', ((char __user *) buffer) + len))
2200 return -EFAULT;
2201 len++;
2202 }
2203 *lenp = len;
2204 *ppos += len;
2205 }
2206 return 0;
2207}
2208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209/**
2210 * proc_dostring - read a string sysctl
2211 * @table: the sysctl table
2212 * @write: %TRUE if this is a write to the sysctl file
2213 * @filp: the file structure
2214 * @buffer: the user buffer
2215 * @lenp: the size of the user buffer
2216 * @ppos: file position
2217 *
2218 * Reads/writes a string from/to the user buffer. If the kernel
2219 * buffer provided is not large enough to hold the string, the
2220 * string is truncated. The copied string is %NULL-terminated.
2221 * If the string is being read by the user process, it is copied
2222 * and a newline '\n' is added. It is truncated if the buffer is
2223 * not large enough.
2224 *
2225 * Returns 0 on success.
2226 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002227int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 void __user *buffer, size_t *lenp, loff_t *ppos)
2229{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002230 return _proc_do_string(table->data, table->maxlen, write, filp,
2231 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232}
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
2235static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2236 int *valp,
2237 int write, void *data)
2238{
2239 if (write) {
2240 *valp = *negp ? -*lvalp : *lvalp;
2241 } else {
2242 int val = *valp;
2243 if (val < 0) {
2244 *negp = -1;
2245 *lvalp = (unsigned long)-val;
2246 } else {
2247 *negp = 0;
2248 *lvalp = (unsigned long)val;
2249 }
2250 }
2251 return 0;
2252}
2253
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002254static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002255 int write, struct file *filp, void __user *buffer,
2256 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2258 int write, void *data),
2259 void *data)
2260{
2261#define TMPBUFLEN 21
2262 int *i, vleft, first=1, neg, val;
2263 unsigned long lval;
2264 size_t left, len;
2265
2266 char buf[TMPBUFLEN], *p;
2267 char __user *s = buffer;
2268
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002269 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 (*ppos && !write)) {
2271 *lenp = 0;
2272 return 0;
2273 }
2274
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002275 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 vleft = table->maxlen / sizeof(*i);
2277 left = *lenp;
2278
2279 if (!conv)
2280 conv = do_proc_dointvec_conv;
2281
2282 for (; left && vleft--; i++, first=0) {
2283 if (write) {
2284 while (left) {
2285 char c;
2286 if (get_user(c, s))
2287 return -EFAULT;
2288 if (!isspace(c))
2289 break;
2290 left--;
2291 s++;
2292 }
2293 if (!left)
2294 break;
2295 neg = 0;
2296 len = left;
2297 if (len > sizeof(buf) - 1)
2298 len = sizeof(buf) - 1;
2299 if (copy_from_user(buf, s, len))
2300 return -EFAULT;
2301 buf[len] = 0;
2302 p = buf;
2303 if (*p == '-' && left > 1) {
2304 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002305 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 }
2307 if (*p < '0' || *p > '9')
2308 break;
2309
2310 lval = simple_strtoul(p, &p, 0);
2311
2312 len = p-buf;
2313 if ((len < left) && *p && !isspace(*p))
2314 break;
2315 if (neg)
2316 val = -val;
2317 s += len;
2318 left -= len;
2319
2320 if (conv(&neg, &lval, i, 1, data))
2321 break;
2322 } else {
2323 p = buf;
2324 if (!first)
2325 *p++ = '\t';
2326
2327 if (conv(&neg, &lval, i, 0, data))
2328 break;
2329
2330 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2331 len = strlen(buf);
2332 if (len > left)
2333 len = left;
2334 if(copy_to_user(s, buf, len))
2335 return -EFAULT;
2336 left -= len;
2337 s += len;
2338 }
2339 }
2340
2341 if (!write && !first && left) {
2342 if(put_user('\n', s))
2343 return -EFAULT;
2344 left--, s++;
2345 }
2346 if (write) {
2347 while (left) {
2348 char c;
2349 if (get_user(c, s++))
2350 return -EFAULT;
2351 if (!isspace(c))
2352 break;
2353 left--;
2354 }
2355 }
2356 if (write && first)
2357 return -EINVAL;
2358 *lenp -= left;
2359 *ppos += *lenp;
2360 return 0;
2361#undef TMPBUFLEN
2362}
2363
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002364static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002365 void __user *buffer, size_t *lenp, loff_t *ppos,
2366 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2367 int write, void *data),
2368 void *data)
2369{
2370 return __do_proc_dointvec(table->data, table, write, filp,
2371 buffer, lenp, ppos, conv, data);
2372}
2373
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374/**
2375 * proc_dointvec - read a vector of integers
2376 * @table: the sysctl table
2377 * @write: %TRUE if this is a write to the sysctl file
2378 * @filp: the file structure
2379 * @buffer: the user buffer
2380 * @lenp: the size of the user buffer
2381 * @ppos: file position
2382 *
2383 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2384 * values from/to the user buffer, treated as an ASCII string.
2385 *
2386 * Returns 0 on success.
2387 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002388int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 void __user *buffer, size_t *lenp, loff_t *ppos)
2390{
2391 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2392 NULL,NULL);
2393}
2394
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002395/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002396 * Taint values can only be increased
2397 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002398 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002399static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002400 void __user *buffer, size_t *lenp, loff_t *ppos)
2401{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002402 struct ctl_table t;
2403 unsigned long tmptaint = get_taint();
2404 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002405
Bastian Blank91fcd412007-04-23 14:41:14 -07002406 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002407 return -EPERM;
2408
Andi Kleen25ddbb12008-10-15 22:01:41 -07002409 t = *table;
2410 t.data = &tmptaint;
2411 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2412 if (err < 0)
2413 return err;
2414
2415 if (write) {
2416 /*
2417 * Poor man's atomic or. Not worth adding a primitive
2418 * to everyone's atomic.h for this
2419 */
2420 int i;
2421 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2422 if ((tmptaint >> i) & 1)
2423 add_taint(i);
2424 }
2425 }
2426
2427 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002428}
2429
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430struct do_proc_dointvec_minmax_conv_param {
2431 int *min;
2432 int *max;
2433};
2434
2435static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2436 int *valp,
2437 int write, void *data)
2438{
2439 struct do_proc_dointvec_minmax_conv_param *param = data;
2440 if (write) {
2441 int val = *negp ? -*lvalp : *lvalp;
2442 if ((param->min && *param->min > val) ||
2443 (param->max && *param->max < val))
2444 return -EINVAL;
2445 *valp = val;
2446 } else {
2447 int val = *valp;
2448 if (val < 0) {
2449 *negp = -1;
2450 *lvalp = (unsigned long)-val;
2451 } else {
2452 *negp = 0;
2453 *lvalp = (unsigned long)val;
2454 }
2455 }
2456 return 0;
2457}
2458
2459/**
2460 * proc_dointvec_minmax - read a vector of integers with min/max values
2461 * @table: the sysctl table
2462 * @write: %TRUE if this is a write to the sysctl file
2463 * @filp: the file structure
2464 * @buffer: the user buffer
2465 * @lenp: the size of the user buffer
2466 * @ppos: file position
2467 *
2468 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2469 * values from/to the user buffer, treated as an ASCII string.
2470 *
2471 * This routine will ensure the values are within the range specified by
2472 * table->extra1 (min) and table->extra2 (max).
2473 *
2474 * Returns 0 on success.
2475 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002476int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 void __user *buffer, size_t *lenp, loff_t *ppos)
2478{
2479 struct do_proc_dointvec_minmax_conv_param param = {
2480 .min = (int *) table->extra1,
2481 .max = (int *) table->extra2,
2482 };
2483 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2484 do_proc_dointvec_minmax_conv, &param);
2485}
2486
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002487static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 struct file *filp,
2489 void __user *buffer,
2490 size_t *lenp, loff_t *ppos,
2491 unsigned long convmul,
2492 unsigned long convdiv)
2493{
2494#define TMPBUFLEN 21
2495 unsigned long *i, *min, *max, val;
2496 int vleft, first=1, neg;
2497 size_t len, left;
2498 char buf[TMPBUFLEN], *p;
2499 char __user *s = buffer;
2500
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002501 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 (*ppos && !write)) {
2503 *lenp = 0;
2504 return 0;
2505 }
2506
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002507 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 min = (unsigned long *) table->extra1;
2509 max = (unsigned long *) table->extra2;
2510 vleft = table->maxlen / sizeof(unsigned long);
2511 left = *lenp;
2512
2513 for (; left && vleft--; i++, min++, max++, first=0) {
2514 if (write) {
2515 while (left) {
2516 char c;
2517 if (get_user(c, s))
2518 return -EFAULT;
2519 if (!isspace(c))
2520 break;
2521 left--;
2522 s++;
2523 }
2524 if (!left)
2525 break;
2526 neg = 0;
2527 len = left;
2528 if (len > TMPBUFLEN-1)
2529 len = TMPBUFLEN-1;
2530 if (copy_from_user(buf, s, len))
2531 return -EFAULT;
2532 buf[len] = 0;
2533 p = buf;
2534 if (*p == '-' && left > 1) {
2535 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002536 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 }
2538 if (*p < '0' || *p > '9')
2539 break;
2540 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2541 len = p-buf;
2542 if ((len < left) && *p && !isspace(*p))
2543 break;
2544 if (neg)
2545 val = -val;
2546 s += len;
2547 left -= len;
2548
2549 if(neg)
2550 continue;
2551 if ((min && val < *min) || (max && val > *max))
2552 continue;
2553 *i = val;
2554 } else {
2555 p = buf;
2556 if (!first)
2557 *p++ = '\t';
2558 sprintf(p, "%lu", convdiv * (*i) / convmul);
2559 len = strlen(buf);
2560 if (len > left)
2561 len = left;
2562 if(copy_to_user(s, buf, len))
2563 return -EFAULT;
2564 left -= len;
2565 s += len;
2566 }
2567 }
2568
2569 if (!write && !first && left) {
2570 if(put_user('\n', s))
2571 return -EFAULT;
2572 left--, s++;
2573 }
2574 if (write) {
2575 while (left) {
2576 char c;
2577 if (get_user(c, s++))
2578 return -EFAULT;
2579 if (!isspace(c))
2580 break;
2581 left--;
2582 }
2583 }
2584 if (write && first)
2585 return -EINVAL;
2586 *lenp -= left;
2587 *ppos += *lenp;
2588 return 0;
2589#undef TMPBUFLEN
2590}
2591
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002592static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002593 struct file *filp,
2594 void __user *buffer,
2595 size_t *lenp, loff_t *ppos,
2596 unsigned long convmul,
2597 unsigned long convdiv)
2598{
2599 return __do_proc_doulongvec_minmax(table->data, table, write,
2600 filp, buffer, lenp, ppos, convmul, convdiv);
2601}
2602
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603/**
2604 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
2607 * @filp: the file structure
2608 * @buffer: the user buffer
2609 * @lenp: the size of the user buffer
2610 * @ppos: file position
2611 *
2612 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2613 * values from/to the user buffer, treated as an ASCII string.
2614 *
2615 * This routine will ensure the values are within the range specified by
2616 * table->extra1 (min) and table->extra2 (max).
2617 *
2618 * Returns 0 on success.
2619 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002620int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 void __user *buffer, size_t *lenp, loff_t *ppos)
2622{
2623 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2624}
2625
2626/**
2627 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2628 * @table: the sysctl table
2629 * @write: %TRUE if this is a write to the sysctl file
2630 * @filp: the file structure
2631 * @buffer: the user buffer
2632 * @lenp: the size of the user buffer
2633 * @ppos: file position
2634 *
2635 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2636 * values from/to the user buffer, treated as an ASCII string. The values
2637 * are treated as milliseconds, and converted to jiffies when they are stored.
2638 *
2639 * This routine will ensure the values are within the range specified by
2640 * table->extra1 (min) and table->extra2 (max).
2641 *
2642 * Returns 0 on success.
2643 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002644int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 struct file *filp,
2646 void __user *buffer,
2647 size_t *lenp, loff_t *ppos)
2648{
2649 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2650 lenp, ppos, HZ, 1000l);
2651}
2652
2653
2654static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2655 int *valp,
2656 int write, void *data)
2657{
2658 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002659 if (*lvalp > LONG_MAX / HZ)
2660 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2662 } else {
2663 int val = *valp;
2664 unsigned long lval;
2665 if (val < 0) {
2666 *negp = -1;
2667 lval = (unsigned long)-val;
2668 } else {
2669 *negp = 0;
2670 lval = (unsigned long)val;
2671 }
2672 *lvalp = lval / HZ;
2673 }
2674 return 0;
2675}
2676
2677static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2678 int *valp,
2679 int write, void *data)
2680{
2681 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002682 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2683 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2685 } else {
2686 int val = *valp;
2687 unsigned long lval;
2688 if (val < 0) {
2689 *negp = -1;
2690 lval = (unsigned long)-val;
2691 } else {
2692 *negp = 0;
2693 lval = (unsigned long)val;
2694 }
2695 *lvalp = jiffies_to_clock_t(lval);
2696 }
2697 return 0;
2698}
2699
2700static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2701 int *valp,
2702 int write, void *data)
2703{
2704 if (write) {
2705 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2706 } else {
2707 int val = *valp;
2708 unsigned long lval;
2709 if (val < 0) {
2710 *negp = -1;
2711 lval = (unsigned long)-val;
2712 } else {
2713 *negp = 0;
2714 lval = (unsigned long)val;
2715 }
2716 *lvalp = jiffies_to_msecs(lval);
2717 }
2718 return 0;
2719}
2720
2721/**
2722 * proc_dointvec_jiffies - read a vector of integers as seconds
2723 * @table: the sysctl table
2724 * @write: %TRUE if this is a write to the sysctl file
2725 * @filp: the file structure
2726 * @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 int) integer
2731 * values from/to the user buffer, treated as an ASCII string.
2732 * The values read are assumed to be in seconds, and are converted into
2733 * jiffies.
2734 *
2735 * Returns 0 on success.
2736 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002737int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 void __user *buffer, size_t *lenp, loff_t *ppos)
2739{
2740 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2741 do_proc_dointvec_jiffies_conv,NULL);
2742}
2743
2744/**
2745 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2746 * @table: the sysctl table
2747 * @write: %TRUE if this is a write to the sysctl file
2748 * @filp: the file structure
2749 * @buffer: the user buffer
2750 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002751 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 *
2753 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2754 * values from/to the user buffer, treated as an ASCII string.
2755 * The values read are assumed to be in 1/USER_HZ seconds, and
2756 * are converted into jiffies.
2757 *
2758 * Returns 0 on success.
2759 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002760int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 void __user *buffer, size_t *lenp, loff_t *ppos)
2762{
2763 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2764 do_proc_dointvec_userhz_jiffies_conv,NULL);
2765}
2766
2767/**
2768 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2769 * @table: the sysctl table
2770 * @write: %TRUE if this is a write to the sysctl file
2771 * @filp: the file structure
2772 * @buffer: the user buffer
2773 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002774 * @ppos: file position
2775 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 *
2777 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2778 * values from/to the user buffer, treated as an ASCII string.
2779 * The values read are assumed to be in 1/1000 seconds, and
2780 * are converted into jiffies.
2781 *
2782 * Returns 0 on success.
2783 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002784int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 void __user *buffer, size_t *lenp, loff_t *ppos)
2786{
2787 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2788 do_proc_dointvec_ms_jiffies_conv, NULL);
2789}
2790
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002791static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002792 void __user *buffer, size_t *lenp, loff_t *ppos)
2793{
2794 struct pid *new_pid;
2795 pid_t tmp;
2796 int r;
2797
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002798 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002799
2800 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2801 lenp, ppos, NULL, NULL);
2802 if (r || !write)
2803 return r;
2804
2805 new_pid = find_get_pid(tmp);
2806 if (!new_pid)
2807 return -ESRCH;
2808
2809 put_pid(xchg(&cad_pid, new_pid));
2810 return 0;
2811}
2812
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813#else /* CONFIG_PROC_FS */
2814
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002815int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 void __user *buffer, size_t *lenp, loff_t *ppos)
2817{
2818 return -ENOSYS;
2819}
2820
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002821int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 void __user *buffer, size_t *lenp, loff_t *ppos)
2823{
2824 return -ENOSYS;
2825}
2826
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002827int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 void __user *buffer, size_t *lenp, loff_t *ppos)
2829{
2830 return -ENOSYS;
2831}
2832
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002833int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 void __user *buffer, size_t *lenp, loff_t *ppos)
2835{
2836 return -ENOSYS;
2837}
2838
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002839int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 void __user *buffer, size_t *lenp, loff_t *ppos)
2841{
2842 return -ENOSYS;
2843}
2844
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002845int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 void __user *buffer, size_t *lenp, loff_t *ppos)
2847{
2848 return -ENOSYS;
2849}
2850
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002851int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 void __user *buffer, size_t *lenp, loff_t *ppos)
2853{
2854 return -ENOSYS;
2855}
2856
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002857int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 struct file *filp,
2859 void __user *buffer,
2860 size_t *lenp, loff_t *ppos)
2861{
2862 return -ENOSYS;
2863}
2864
2865
2866#endif /* CONFIG_PROC_FS */
2867
2868
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002869#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870/*
2871 * General sysctl support routines
2872 */
2873
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002874/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002875int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002876 void __user *oldval, size_t __user *oldlenp,
2877 void __user *newval, size_t newlen)
2878{
2879 size_t len;
2880
2881 /* Get out of I don't have a variable */
2882 if (!table->data || !table->maxlen)
2883 return -ENOTDIR;
2884
2885 if (oldval && oldlenp) {
2886 if (get_user(len, oldlenp))
2887 return -EFAULT;
2888 if (len) {
2889 if (len > table->maxlen)
2890 len = table->maxlen;
2891 if (copy_to_user(oldval, table->data, len))
2892 return -EFAULT;
2893 if (put_user(len, oldlenp))
2894 return -EFAULT;
2895 }
2896 }
2897
2898 if (newval && newlen) {
2899 if (newlen > table->maxlen)
2900 newlen = table->maxlen;
2901
2902 if (copy_from_user(table->data, newval, newlen))
2903 return -EFAULT;
2904 }
2905 return 1;
2906}
2907
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002909int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002911 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 if (!table->data || !table->maxlen)
2914 return -ENOTDIR;
2915
2916 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002917 size_t bufsize;
2918 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002920 if (bufsize) {
2921 size_t len = strlen(table->data), copied;
2922
2923 /* This shouldn't trigger for a well-formed sysctl */
2924 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002926
2927 /* Copy up to a max of bufsize-1 bytes of the string */
2928 copied = (len >= bufsize) ? bufsize - 1 : len;
2929
2930 if (copy_to_user(oldval, table->data, copied) ||
2931 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002933 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 return -EFAULT;
2935 }
2936 }
2937 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002938 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 if (len > table->maxlen)
2940 len = table->maxlen;
2941 if(copy_from_user(table->data, newval, len))
2942 return -EFAULT;
2943 if (len == table->maxlen)
2944 len--;
2945 ((char *) table->data)[len] = 0;
2946 }
Yi Yang82c9df82005-12-30 16:37:10 +08002947 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948}
2949
2950/*
2951 * This function makes sure that all of the integers in the vector
2952 * are between the minimum and maximum values given in the arrays
2953 * table->extra1 and table->extra2, respectively.
2954 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002955int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002957 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958{
2959
2960 if (newval && newlen) {
2961 int __user *vec = (int __user *) newval;
2962 int *min = (int *) table->extra1;
2963 int *max = (int *) table->extra2;
2964 size_t length;
2965 int i;
2966
2967 if (newlen % sizeof(int) != 0)
2968 return -EINVAL;
2969
2970 if (!table->extra1 && !table->extra2)
2971 return 0;
2972
2973 if (newlen > table->maxlen)
2974 newlen = table->maxlen;
2975 length = newlen / sizeof(int);
2976
2977 for (i = 0; i < length; i++) {
2978 int value;
2979 if (get_user(value, vec + i))
2980 return -EFAULT;
2981 if (min && value < min[i])
2982 return -EINVAL;
2983 if (max && value > max[i])
2984 return -EINVAL;
2985 }
2986 }
2987 return 0;
2988}
2989
2990/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002991int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002993 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002995 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002997
2998 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003000 if (olen) {
3001 int val;
3002
3003 if (olen < sizeof(int))
3004 return -EINVAL;
3005
3006 val = *(int *)(table->data) / HZ;
3007 if (put_user(val, (int __user *)oldval))
3008 return -EFAULT;
3009 if (put_user(sizeof(int), oldlenp))
3010 return -EFAULT;
3011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 }
3013 if (newval && newlen) {
3014 int new;
3015 if (newlen != sizeof(int))
3016 return -EINVAL;
3017 if (get_user(new, (int __user *)newval))
3018 return -EFAULT;
3019 *(int *)(table->data) = new*HZ;
3020 }
3021 return 1;
3022}
3023
3024/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003025int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003027 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003029 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003031
3032 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003034 if (olen) {
3035 int val;
3036
3037 if (olen < sizeof(int))
3038 return -EINVAL;
3039
3040 val = jiffies_to_msecs(*(int *)(table->data));
3041 if (put_user(val, (int __user *)oldval))
3042 return -EFAULT;
3043 if (put_user(sizeof(int), oldlenp))
3044 return -EFAULT;
3045 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 }
3047 if (newval && newlen) {
3048 int new;
3049 if (newlen != sizeof(int))
3050 return -EINVAL;
3051 if (get_user(new, (int __user *)newval))
3052 return -EFAULT;
3053 *(int *)(table->data) = msecs_to_jiffies(new);
3054 }
3055 return 1;
3056}
3057
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003058
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003059
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003060#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061
3062
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003063SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003065 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003066 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003067
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003068 if (copy_from_user(&tmp, args, sizeof(tmp)))
3069 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003070
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003071 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003072
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003073 /* If no error reading the parameters then just -ENOSYS ... */
3074 if (!error)
3075 error = -ENOSYS;
3076
3077 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078}
3079
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003080int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003081 void __user *oldval, size_t __user *oldlenp,
3082 void __user *newval, size_t newlen)
3083{
3084 return -ENOSYS;
3085}
3086
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003087int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003089 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090{
3091 return -ENOSYS;
3092}
3093
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003094int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003096 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097{
3098 return -ENOSYS;
3099}
3100
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003101int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003103 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104{
3105 return -ENOSYS;
3106}
3107
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003108int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003110 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111{
3112 return -ENOSYS;
3113}
3114
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003115#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003117static int deprecated_sysctl_warning(struct __sysctl_args *args)
3118{
3119 static int msg_count;
3120 int name[CTL_MAXNAME];
3121 int i;
3122
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003123 /* Check args->nlen. */
3124 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3125 return -ENOTDIR;
3126
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003127 /* Read in the sysctl name for better debug message logging */
3128 for (i = 0; i < args->nlen; i++)
3129 if (get_user(name[i], args->name + i))
3130 return -EFAULT;
3131
3132 /* Ignore accesses to kernel.version */
3133 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3134 return 0;
3135
3136 if (msg_count < 5) {
3137 msg_count++;
3138 printk(KERN_INFO
3139 "warning: process `%s' used the deprecated sysctl "
3140 "system call with ", current->comm);
3141 for (i = 0; i < args->nlen; i++)
3142 printk("%d.", name[i]);
3143 printk("\n");
3144 }
3145 return 0;
3146}
3147
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148/*
3149 * No sense putting this after each symbol definition, twice,
3150 * exception granted :-)
3151 */
3152EXPORT_SYMBOL(proc_dointvec);
3153EXPORT_SYMBOL(proc_dointvec_jiffies);
3154EXPORT_SYMBOL(proc_dointvec_minmax);
3155EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3156EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3157EXPORT_SYMBOL(proc_dostring);
3158EXPORT_SYMBOL(proc_doulongvec_minmax);
3159EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3160EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003161EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162EXPORT_SYMBOL(sysctl_intvec);
3163EXPORT_SYMBOL(sysctl_jiffies);
3164EXPORT_SYMBOL(sysctl_ms_jiffies);
3165EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003166EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167EXPORT_SYMBOL(unregister_sysctl_table);