blob: a7e4eb0525b19e768cf6d729f0db3b07d5d35dd5 [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 Gondwana195cf452008-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;
105
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700106/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
107static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110static int maxolduid = 65535;
111static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800112static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static int ngroups_max = NGROUPS_MAX;
115
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200116#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117extern char modprobe_path[];
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#ifdef CONFIG_CHR_DEV_SG
120extern int sg_big_buff;
121#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
David S. Miller72c57ed2008-09-11 23:29:54 -0700123#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700124#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#endif
126
David S. Miller08714202008-11-16 23:49:24 -0800127#ifdef CONFIG_SPARC64
128extern int sysctl_tsb_ratio;
129#endif
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#ifdef __hppa__
132extern int pwrsw_enabled;
133extern int unaligned_enabled;
134#endif
135
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800136#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef CONFIG_MATHEMU
138extern int sysctl_ieee_emulation_warnings;
139#endif
140extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700141extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef CONFIG_BSD_PROCESS_ACCT
145extern int acct_parm[];
146#endif
147
Jes Sorensend2b176e2006-02-28 09:42:23 -0800148#ifdef CONFIG_IA64
149extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800150extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800151#endif
152
Ingo Molnar23f78d42006-06-27 02:54:53 -0700153#ifdef CONFIG_RT_MUTEXES
154extern int max_lock_depth;
155#endif
156
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700159 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700160static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800161 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700162#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700163
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700164static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100165static struct ctl_table_root sysctl_table_root;
166static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100167 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400169 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100170 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400171 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100172};
173static struct ctl_table_root sysctl_table_root = {
174 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400175 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700178static struct ctl_table kern_table[];
179static struct ctl_table vm_table[];
180static struct ctl_table fs_table[];
181static struct ctl_table debug_table[];
182static struct ctl_table dev_table[];
183extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700184#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700185extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400186#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800187#ifdef CONFIG_EPOLL
188extern struct ctl_table epoll_table[];
189#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
192int sysctl_legacy_va_layout;
193#endif
194
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700195extern int prove_locking;
196extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/* The default sysctl tables: */
199
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700200static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 {
202 .ctl_name = CTL_KERN,
203 .procname = "kernel",
204 .mode = 0555,
205 .child = kern_table,
206 },
207 {
208 .ctl_name = CTL_VM,
209 .procname = "vm",
210 .mode = 0555,
211 .child = vm_table,
212 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .ctl_name = CTL_FS,
215 .procname = "fs",
216 .mode = 0555,
217 .child = fs_table,
218 },
219 {
220 .ctl_name = CTL_DEBUG,
221 .procname = "debug",
222 .mode = 0555,
223 .child = debug_table,
224 },
225 {
226 .ctl_name = CTL_DEV,
227 .procname = "dev",
228 .mode = 0555,
229 .child = dev_table,
230 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700231/*
232 * NOTE: do not add new entries to this table unless you have read
233 * Documentation/sysctl/ctl_unnumbered.txt
234 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 { .ctl_name = 0 }
236};
237
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100239static int min_sched_granularity_ns = 100000; /* 100 usecs */
240static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
241static int min_wakeup_granularity_ns; /* 0 usecs */
242static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243#endif
244
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700245static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246#ifdef CONFIG_SCHED_DEBUG
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100249 .procname = "sched_min_granularity_ns",
250 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200260 .procname = "sched_latency_ns",
261 .data = &sysctl_sched_latency,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100264 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200265 .strategy = &sysctl_intvec,
266 .extra1 = &min_sched_granularity_ns,
267 .extra2 = &max_sched_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200271 .procname = "sched_wakeup_granularity_ns",
272 .data = &sysctl_sched_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200282 .procname = "sched_shares_ratelimit",
283 .data = &sysctl_sched_shares_ratelimit,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
287 },
288 {
289 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200290 .procname = "sched_shares_thresh",
291 .data = &sysctl_sched_shares_thresh,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
296 .extra1 = &zero,
297 },
298 {
299 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200300 .procname = "sched_child_runs_first",
301 .data = &sysctl_sched_child_runs_first,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200306 {
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_features",
309 .data = &sysctl_sched_features,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
313 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200314 {
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100322 {
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
329 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200330#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200331 {
332 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100333 .procname = "sched_rt_period_us",
334 .data = &sysctl_sched_rt_period,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200337 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100338 },
339 {
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_rt_runtime_us",
342 .data = &sysctl_sched_rt_runtime,
343 .maxlen = sizeof(int),
344 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200345 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100346 },
347 {
348 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200349 .procname = "sched_compat_yield",
350 .data = &sysctl_sched_compat_yield,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = &proc_dointvec,
354 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700355#ifdef CONFIG_PROVE_LOCKING
356 {
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
364#endif
365#ifdef CONFIG_LOCK_STAT
366 {
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "lock_stat",
369 .data = &lock_stat,
370 .maxlen = sizeof(int),
371 .mode = 0644,
372 .proc_handler = &proc_dointvec,
373 },
374#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .ctl_name = KERN_PANIC,
377 .procname = "panic",
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383 {
384 .ctl_name = KERN_CORE_USES_PID,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
391 {
392 .ctl_name = KERN_CORE_PATTERN,
393 .procname = "core_pattern",
394 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700395 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 .mode = 0644,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
399 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800400#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700403 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800404 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700405 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800407#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100408#ifdef CONFIG_LATENCYTOP
409 {
410 .procname = "latencytop",
411 .data = &latencytop_enabled,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = &proc_dointvec,
415 },
416#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#ifdef CONFIG_BLK_DEV_INITRD
418 {
419 .ctl_name = KERN_REALROOTDEV,
420 .procname = "real-root-dev",
421 .data = &real_root_dev,
422 .maxlen = sizeof(int),
423 .mode = 0644,
424 .proc_handler = &proc_dointvec,
425 },
426#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700427 {
428 .ctl_name = CTL_UNNUMBERED,
429 .procname = "print-fatal-signals",
430 .data = &print_fatal_signals,
431 .maxlen = sizeof(int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700435#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 {
437 .ctl_name = KERN_SPARC_REBOOT,
438 .procname = "reboot-cmd",
439 .data = reboot_command,
440 .maxlen = 256,
441 .mode = 0644,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
444 },
445 {
446 .ctl_name = KERN_SPARC_STOP_A,
447 .procname = "stop-a",
448 .data = &stop_a_enabled,
449 .maxlen = sizeof (int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec,
452 },
453 {
454 .ctl_name = KERN_SPARC_SCONS_PWROFF,
455 .procname = "scons-poweroff",
456 .data = &scons_pwroff,
457 .maxlen = sizeof (int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
460 },
461#endif
David S. Miller08714202008-11-16 23:49:24 -0800462#ifdef CONFIG_SPARC64
463 {
464 .ctl_name = CTL_UNNUMBERED,
465 .procname = "tsb-ratio",
466 .data = &sysctl_tsb_ratio,
467 .maxlen = sizeof (int),
468 .mode = 0644,
469 .proc_handler = &proc_dointvec,
470 },
471#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#ifdef __hppa__
473 {
474 .ctl_name = KERN_HPPA_PWRSW,
475 .procname = "soft-power",
476 .data = &pwrsw_enabled,
477 .maxlen = sizeof (int),
478 .mode = 0644,
479 .proc_handler = &proc_dointvec,
480 },
481 {
482 .ctl_name = KERN_HPPA_UNALIGNED,
483 .procname = "unaligned-trap",
484 .data = &unaligned_enabled,
485 .maxlen = sizeof (int),
486 .mode = 0644,
487 .proc_handler = &proc_dointvec,
488 },
489#endif
490 {
491 .ctl_name = KERN_CTLALTDEL,
492 .procname = "ctrl-alt-del",
493 .data = &C_A_D,
494 .maxlen = sizeof(int),
495 .mode = 0644,
496 .proc_handler = &proc_dointvec,
497 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400498#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200499 {
500 .ctl_name = CTL_UNNUMBERED,
501 .procname = "ftrace_enabled",
502 .data = &ftrace_enabled,
503 .maxlen = sizeof(int),
504 .mode = 0644,
505 .proc_handler = &ftrace_enable_sysctl,
506 },
507#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500508#ifdef CONFIG_STACK_TRACER
509 {
510 .ctl_name = CTL_UNNUMBERED,
511 .procname = "stack_tracer_enabled",
512 .data = &stack_tracer_enabled,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = &stack_trace_sysctl,
516 },
517#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400518#ifdef CONFIG_TRACING
519 {
520 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100521 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400522 .data = &ftrace_dump_on_oops,
523 .maxlen = sizeof(int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec,
526 },
527#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200528#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 {
530 .ctl_name = KERN_MODPROBE,
531 .procname = "modprobe",
532 .data = &modprobe_path,
533 .maxlen = KMOD_PATH_LEN,
534 .mode = 0644,
535 .proc_handler = &proc_dostring,
536 .strategy = &sysctl_string,
537 },
538#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700539#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
541 .ctl_name = KERN_HOTPLUG,
542 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100543 .data = &uevent_helper,
544 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .mode = 0644,
546 .proc_handler = &proc_dostring,
547 .strategy = &sysctl_string,
548 },
549#endif
550#ifdef CONFIG_CHR_DEV_SG
551 {
552 .ctl_name = KERN_SG_BIG_BUFF,
553 .procname = "sg-big-buff",
554 .data = &sg_big_buff,
555 .maxlen = sizeof (int),
556 .mode = 0444,
557 .proc_handler = &proc_dointvec,
558 },
559#endif
560#ifdef CONFIG_BSD_PROCESS_ACCT
561 {
562 .ctl_name = KERN_ACCT,
563 .procname = "acct",
564 .data = &acct_parm,
565 .maxlen = 3*sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#ifdef CONFIG_MAGIC_SYSRQ
571 {
572 .ctl_name = KERN_SYSRQ,
573 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800574 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .maxlen = sizeof (int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
578 },
579#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700580#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700583 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 .maxlen = sizeof (int),
585 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700586 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 {
590 .ctl_name = KERN_MAX_THREADS,
591 .procname = "threads-max",
592 .data = &max_threads,
593 .maxlen = sizeof(int),
594 .mode = 0644,
595 .proc_handler = &proc_dointvec,
596 },
597 {
598 .ctl_name = KERN_RANDOM,
599 .procname = "random",
600 .mode = 0555,
601 .child = random_table,
602 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 {
604 .ctl_name = KERN_OVERFLOWUID,
605 .procname = "overflowuid",
606 .data = &overflowuid,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec_minmax,
610 .strategy = &sysctl_intvec,
611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
613 },
614 {
615 .ctl_name = KERN_OVERFLOWGID,
616 .procname = "overflowgid",
617 .data = &overflowgid,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec_minmax,
621 .strategy = &sysctl_intvec,
622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
624 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800625#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#ifdef CONFIG_MATHEMU
627 {
628 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
629 .procname = "ieee_emulation_warnings",
630 .data = &sysctl_ieee_emulation_warnings,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
634 },
635#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 {
637 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
638 .procname = "userprocess_debug",
639 .data = &sysctl_userprocess_debug,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec,
643 },
644#endif
645 {
646 .ctl_name = KERN_PIDMAX,
647 .procname = "pid_max",
648 .data = &pid_max,
649 .maxlen = sizeof (int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec_minmax,
652 .strategy = sysctl_intvec,
653 .extra1 = &pid_max_min,
654 .extra2 = &pid_max_max,
655 },
656 {
657 .ctl_name = KERN_PANIC_ON_OOPS,
658 .procname = "panic_on_oops",
659 .data = &panic_on_oops,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800664#if defined CONFIG_PRINTK
665 {
666 .ctl_name = KERN_PRINTK,
667 .procname = "printk",
668 .data = &console_loglevel,
669 .maxlen = 4*sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 {
674 .ctl_name = KERN_PRINTK_RATELIMIT,
675 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700676 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec_jiffies,
680 .strategy = &sysctl_jiffies,
681 },
682 {
683 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
684 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700685 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec,
689 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800690#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 {
692 .ctl_name = KERN_NGROUPS_MAX,
693 .procname = "ngroups_max",
694 .data = &ngroups_max,
695 .maxlen = sizeof (int),
696 .mode = 0444,
697 .proc_handler = &proc_dointvec,
698 },
699#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
700 {
701 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
702 .procname = "unknown_nmi_panic",
703 .data = &unknown_nmi_panic,
704 .maxlen = sizeof (int),
705 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200706 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
Don Zickus407984f2006-09-26 10:52:27 +0200708 {
Don Zickus407984f2006-09-26 10:52:27 +0200709 .procname = "nmi_watchdog",
710 .data = &nmi_watchdog_enabled,
711 .maxlen = sizeof (int),
712 .mode = 0644,
713 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 },
715#endif
716#if defined(CONFIG_X86)
717 {
Don Zickus8da5add2006-09-26 10:52:27 +0200718 .ctl_name = KERN_PANIC_ON_NMI,
719 .procname = "panic_on_unrecovered_nmi",
720 .data = &panic_on_unrecovered_nmi,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec,
724 },
725 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .ctl_name = KERN_BOOTLOADER_TYPE,
727 .procname = "bootloader_type",
728 .data = &bootloader_type,
729 .maxlen = sizeof (int),
730 .mode = 0444,
731 .proc_handler = &proc_dointvec,
732 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100733 {
734 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700735 .procname = "bootloader_version",
736 .data = &bootloader_version,
737 .maxlen = sizeof (int),
738 .mode = 0444,
739 .proc_handler = &proc_dointvec,
740 },
741 {
742 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100743 .procname = "kstack_depth_to_print",
744 .data = &kstack_depth_to_print,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
748 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100749 {
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "io_delay_type",
752 .data = &io_delay_type,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = &proc_dointvec,
756 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800758#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 {
760 .ctl_name = KERN_RANDOMIZE,
761 .procname = "randomize_va_space",
762 .data = &randomize_va_space,
763 .maxlen = sizeof(int),
764 .mode = 0644,
765 .proc_handler = &proc_dointvec,
766 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800767#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800768#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700769 {
770 .ctl_name = KERN_SPIN_RETRY,
771 .procname = "spin_retry",
772 .data = &spin_retry,
773 .maxlen = sizeof (int),
774 .mode = 0644,
775 .proc_handler = &proc_dointvec,
776 },
777#endif
Len Brown673d5b42007-07-28 03:33:16 -0400778#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800779 {
Pavel Machekc255d842006-02-20 18:27:58 -0800780 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700781 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800782 .maxlen = sizeof (unsigned long),
783 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800784 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800785 },
786#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800787#ifdef CONFIG_IA64
788 {
789 .ctl_name = KERN_IA64_UNALIGNED,
790 .procname = "ignore-unaligned-usertrap",
791 .data = &no_unaligned_warning,
792 .maxlen = sizeof (int),
793 .mode = 0644,
794 .proc_handler = &proc_dointvec,
795 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800796 {
797 .ctl_name = CTL_UNNUMBERED,
798 .procname = "unaligned-dump-stack",
799 .data = &unaligned_dump_stack,
800 .maxlen = sizeof (int),
801 .mode = 0644,
802 .proc_handler = &proc_dointvec,
803 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800804#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700805#ifdef CONFIG_DETECT_SOFTLOCKUP
806 {
807 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200808 .procname = "softlockup_panic",
809 .data = &softlockup_panic,
810 .maxlen = sizeof(int),
811 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700812 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200813 .strategy = &sysctl_intvec,
814 .extra1 = &zero,
815 .extra2 = &one,
816 },
817 {
818 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700819 .procname = "softlockup_thresh",
820 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200821 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700822 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800823 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700824 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200825 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700826 .extra2 = &sixty,
827 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800828#endif
829#ifdef CONFIG_DETECT_HUNG_TASK
830 {
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "hung_task_panic",
833 .data = &sysctl_hung_task_panic,
834 .maxlen = sizeof(int),
835 .mode = 0644,
836 .proc_handler = &proc_dointvec_minmax,
837 .strategy = &sysctl_intvec,
838 .extra1 = &zero,
839 .extra2 = &one,
840 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100841 {
842 .ctl_name = CTL_UNNUMBERED,
843 .procname = "hung_task_check_count",
844 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100845 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100846 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100847 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100848 .strategy = &sysctl_intvec,
849 },
850 {
851 .ctl_name = CTL_UNNUMBERED,
852 .procname = "hung_task_timeout_secs",
853 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100854 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100855 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800856 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100857 .strategy = &sysctl_intvec,
858 },
859 {
860 .ctl_name = CTL_UNNUMBERED,
861 .procname = "hung_task_warnings",
862 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100863 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100864 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100865 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100866 .strategy = &sysctl_intvec,
867 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700868#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200869#ifdef CONFIG_COMPAT
870 {
871 .ctl_name = KERN_COMPAT_LOG,
872 .procname = "compat-log",
873 .data = &compat_log,
874 .maxlen = sizeof (int),
875 .mode = 0644,
876 .proc_handler = &proc_dointvec,
877 },
878#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700879#ifdef CONFIG_RT_MUTEXES
880 {
881 .ctl_name = KERN_MAX_LOCK_DEPTH,
882 .procname = "max_lock_depth",
883 .data = &max_lock_depth,
884 .maxlen = sizeof(int),
885 .mode = 0644,
886 .proc_handler = &proc_dointvec,
887 },
888#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700889 {
890 .ctl_name = CTL_UNNUMBERED,
891 .procname = "poweroff_cmd",
892 .data = &poweroff_cmd,
893 .maxlen = POWEROFF_CMD_PATH_LEN,
894 .mode = 0644,
895 .proc_handler = &proc_dostring,
896 .strategy = &sysctl_string,
897 },
David Howells0b77f5b2008-04-29 01:01:32 -0700898#ifdef CONFIG_KEYS
899 {
900 .ctl_name = CTL_UNNUMBERED,
901 .procname = "keys",
902 .mode = 0555,
903 .child = key_sysctls,
904 },
905#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700906#ifdef CONFIG_RCU_TORTURE_TEST
907 {
908 .ctl_name = CTL_UNNUMBERED,
909 .procname = "rcutorture_runnable",
910 .data = &rcutorture_runnable,
911 .maxlen = sizeof(int),
912 .mode = 0644,
913 .proc_handler = &proc_dointvec,
914 },
915#endif
David Howells12e22c52009-04-03 16:42:35 +0100916#ifdef CONFIG_SLOW_WORK
917 {
918 .ctl_name = CTL_UNNUMBERED,
919 .procname = "slow-work",
920 .mode = 0555,
921 .child = slow_work_sysctls,
922 },
923#endif
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200924#ifdef CONFIG_PERF_COUNTERS
925 {
926 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra07647712009-06-11 11:18:36 +0200927 .procname = "perf_counter_paranoid",
928 .data = &sysctl_perf_counter_paranoid,
929 .maxlen = sizeof(sysctl_perf_counter_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200930 .mode = 0644,
931 .proc_handler = &proc_dointvec,
932 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200933 {
934 .ctl_name = CTL_UNNUMBERED,
935 .procname = "perf_counter_mlock_kb",
936 .data = &sysctl_perf_counter_mlock,
937 .maxlen = sizeof(sysctl_perf_counter_mlock),
938 .mode = 0644,
939 .proc_handler = &proc_dointvec,
940 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200941 {
942 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstradf58ab22009-06-11 11:25:05 +0200943 .procname = "perf_counter_max_sample_rate",
944 .data = &sysctl_perf_counter_sample_rate,
945 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200946 .mode = 0644,
947 .proc_handler = &proc_dointvec,
948 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200949#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700950/*
951 * NOTE: do not add new entries to this table unless you have read
952 * Documentation/sysctl/ctl_unnumbered.txt
953 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 { .ctl_name = 0 }
955};
956
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700957static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 {
959 .ctl_name = VM_OVERCOMMIT_MEMORY,
960 .procname = "overcommit_memory",
961 .data = &sysctl_overcommit_memory,
962 .maxlen = sizeof(sysctl_overcommit_memory),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 },
966 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700967 .ctl_name = VM_PANIC_ON_OOM,
968 .procname = "panic_on_oom",
969 .data = &sysctl_panic_on_oom,
970 .maxlen = sizeof(sysctl_panic_on_oom),
971 .mode = 0644,
972 .proc_handler = &proc_dointvec,
973 },
974 {
David Rientjesfe071d72007-10-16 23:25:56 -0700975 .ctl_name = CTL_UNNUMBERED,
976 .procname = "oom_kill_allocating_task",
977 .data = &sysctl_oom_kill_allocating_task,
978 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
979 .mode = 0644,
980 .proc_handler = &proc_dointvec,
981 },
982 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800983 .ctl_name = CTL_UNNUMBERED,
984 .procname = "oom_dump_tasks",
985 .data = &sysctl_oom_dump_tasks,
986 .maxlen = sizeof(sysctl_oom_dump_tasks),
987 .mode = 0644,
988 .proc_handler = &proc_dointvec,
989 },
990 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 .ctl_name = VM_OVERCOMMIT_RATIO,
992 .procname = "overcommit_ratio",
993 .data = &sysctl_overcommit_ratio,
994 .maxlen = sizeof(sysctl_overcommit_ratio),
995 .mode = 0644,
996 .proc_handler = &proc_dointvec,
997 },
998 {
999 .ctl_name = VM_PAGE_CLUSTER,
1000 .procname = "page-cluster",
1001 .data = &page_cluster,
1002 .maxlen = sizeof(int),
1003 .mode = 0644,
1004 .proc_handler = &proc_dointvec,
1005 },
1006 {
1007 .ctl_name = VM_DIRTY_BACKGROUND,
1008 .procname = "dirty_background_ratio",
1009 .data = &dirty_background_ratio,
1010 .maxlen = sizeof(dirty_background_ratio),
1011 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001012 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 .strategy = &sysctl_intvec,
1014 .extra1 = &zero,
1015 .extra2 = &one_hundred,
1016 },
1017 {
David Rientjes2da02992009-01-06 14:39:31 -08001018 .ctl_name = CTL_UNNUMBERED,
1019 .procname = "dirty_background_bytes",
1020 .data = &dirty_background_bytes,
1021 .maxlen = sizeof(dirty_background_bytes),
1022 .mode = 0644,
1023 .proc_handler = &dirty_background_bytes_handler,
1024 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001025 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001026 },
1027 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 .ctl_name = VM_DIRTY_RATIO,
1029 .procname = "dirty_ratio",
1030 .data = &vm_dirty_ratio,
1031 .maxlen = sizeof(vm_dirty_ratio),
1032 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001033 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 .strategy = &sysctl_intvec,
1035 .extra1 = &zero,
1036 .extra2 = &one_hundred,
1037 },
1038 {
David Rientjes2da02992009-01-06 14:39:31 -08001039 .ctl_name = CTL_UNNUMBERED,
1040 .procname = "dirty_bytes",
1041 .data = &vm_dirty_bytes,
1042 .maxlen = sizeof(vm_dirty_bytes),
1043 .mode = 0644,
1044 .proc_handler = &dirty_bytes_handler,
1045 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001046 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001047 },
1048 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001050 .data = &dirty_writeback_interval,
1051 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .mode = 0644,
1053 .proc_handler = &dirty_writeback_centisecs_handler,
1054 },
1055 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001057 .data = &dirty_expire_interval,
1058 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001060 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 },
1062 {
1063 .ctl_name = VM_NR_PDFLUSH_THREADS,
1064 .procname = "nr_pdflush_threads",
1065 .data = &nr_pdflush_threads,
1066 .maxlen = sizeof nr_pdflush_threads,
1067 .mode = 0444 /* read-only*/,
1068 .proc_handler = &proc_dointvec,
1069 },
1070 {
1071 .ctl_name = VM_SWAPPINESS,
1072 .procname = "swappiness",
1073 .data = &vm_swappiness,
1074 .maxlen = sizeof(vm_swappiness),
1075 .mode = 0644,
1076 .proc_handler = &proc_dointvec_minmax,
1077 .strategy = &sysctl_intvec,
1078 .extra1 = &zero,
1079 .extra2 = &one_hundred,
1080 },
1081#ifdef CONFIG_HUGETLB_PAGE
1082 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001084 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 .maxlen = sizeof(unsigned long),
1086 .mode = 0644,
1087 .proc_handler = &hugetlb_sysctl_handler,
1088 .extra1 = (void *)&hugetlb_zero,
1089 .extra2 = (void *)&hugetlb_infinity,
1090 },
1091 {
1092 .ctl_name = VM_HUGETLB_GROUP,
1093 .procname = "hugetlb_shm_group",
1094 .data = &sysctl_hugetlb_shm_group,
1095 .maxlen = sizeof(gid_t),
1096 .mode = 0644,
1097 .proc_handler = &proc_dointvec,
1098 },
Mel Gorman396faf02007-07-17 04:03:13 -07001099 {
1100 .ctl_name = CTL_UNNUMBERED,
1101 .procname = "hugepages_treat_as_movable",
1102 .data = &hugepages_treat_as_movable,
1103 .maxlen = sizeof(int),
1104 .mode = 0644,
1105 .proc_handler = &hugetlb_treat_movable_handler,
1106 },
Adam Litke54f9f802007-10-16 01:26:20 -07001107 {
1108 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001109 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001110 .data = NULL,
1111 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001112 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001113 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001114 .extra1 = (void *)&hugetlb_zero,
1115 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001116 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117#endif
1118 {
1119 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1120 .procname = "lowmem_reserve_ratio",
1121 .data = &sysctl_lowmem_reserve_ratio,
1122 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1123 .mode = 0644,
1124 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1125 .strategy = &sysctl_intvec,
1126 },
1127 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001128 .ctl_name = VM_DROP_PAGECACHE,
1129 .procname = "drop_caches",
1130 .data = &sysctl_drop_caches,
1131 .maxlen = sizeof(int),
1132 .mode = 0644,
1133 .proc_handler = drop_caches_sysctl_handler,
1134 .strategy = &sysctl_intvec,
1135 },
1136 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 .ctl_name = VM_MIN_FREE_KBYTES,
1138 .procname = "min_free_kbytes",
1139 .data = &min_free_kbytes,
1140 .maxlen = sizeof(min_free_kbytes),
1141 .mode = 0644,
1142 .proc_handler = &min_free_kbytes_sysctl_handler,
1143 .strategy = &sysctl_intvec,
1144 .extra1 = &zero,
1145 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001146 {
1147 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1148 .procname = "percpu_pagelist_fraction",
1149 .data = &percpu_pagelist_fraction,
1150 .maxlen = sizeof(percpu_pagelist_fraction),
1151 .mode = 0644,
1152 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1153 .strategy = &sysctl_intvec,
1154 .extra1 = &min_percpu_pagelist_fract,
1155 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156#ifdef CONFIG_MMU
1157 {
1158 .ctl_name = VM_MAX_MAP_COUNT,
1159 .procname = "max_map_count",
1160 .data = &sysctl_max_map_count,
1161 .maxlen = sizeof(sysctl_max_map_count),
1162 .mode = 0644,
1163 .proc_handler = &proc_dointvec
1164 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001165#else
1166 {
1167 .ctl_name = CTL_UNNUMBERED,
1168 .procname = "nr_trim_pages",
1169 .data = &sysctl_nr_trim_pages,
1170 .maxlen = sizeof(sysctl_nr_trim_pages),
1171 .mode = 0644,
1172 .proc_handler = &proc_dointvec_minmax,
1173 .strategy = &sysctl_intvec,
1174 .extra1 = &zero,
1175 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176#endif
1177 {
1178 .ctl_name = VM_LAPTOP_MODE,
1179 .procname = "laptop_mode",
1180 .data = &laptop_mode,
1181 .maxlen = sizeof(laptop_mode),
1182 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001183 .proc_handler = &proc_dointvec_jiffies,
1184 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 },
1186 {
1187 .ctl_name = VM_BLOCK_DUMP,
1188 .procname = "block_dump",
1189 .data = &block_dump,
1190 .maxlen = sizeof(block_dump),
1191 .mode = 0644,
1192 .proc_handler = &proc_dointvec,
1193 .strategy = &sysctl_intvec,
1194 .extra1 = &zero,
1195 },
1196 {
1197 .ctl_name = VM_VFS_CACHE_PRESSURE,
1198 .procname = "vfs_cache_pressure",
1199 .data = &sysctl_vfs_cache_pressure,
1200 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1201 .mode = 0644,
1202 .proc_handler = &proc_dointvec,
1203 .strategy = &sysctl_intvec,
1204 .extra1 = &zero,
1205 },
1206#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1207 {
1208 .ctl_name = VM_LEGACY_VA_LAYOUT,
1209 .procname = "legacy_va_layout",
1210 .data = &sysctl_legacy_va_layout,
1211 .maxlen = sizeof(sysctl_legacy_va_layout),
1212 .mode = 0644,
1213 .proc_handler = &proc_dointvec,
1214 .strategy = &sysctl_intvec,
1215 .extra1 = &zero,
1216 },
1217#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001218#ifdef CONFIG_NUMA
1219 {
1220 .ctl_name = VM_ZONE_RECLAIM_MODE,
1221 .procname = "zone_reclaim_mode",
1222 .data = &zone_reclaim_mode,
1223 .maxlen = sizeof(zone_reclaim_mode),
1224 .mode = 0644,
1225 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001226 .strategy = &sysctl_intvec,
1227 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001228 },
Christoph Lameter96146342006-07-03 00:24:13 -07001229 {
1230 .ctl_name = VM_MIN_UNMAPPED,
1231 .procname = "min_unmapped_ratio",
1232 .data = &sysctl_min_unmapped_ratio,
1233 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1234 .mode = 0644,
1235 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1236 .strategy = &sysctl_intvec,
1237 .extra1 = &zero,
1238 .extra2 = &one_hundred,
1239 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001240 {
1241 .ctl_name = VM_MIN_SLAB,
1242 .procname = "min_slab_ratio",
1243 .data = &sysctl_min_slab_ratio,
1244 .maxlen = sizeof(sysctl_min_slab_ratio),
1245 .mode = 0644,
1246 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1247 .strategy = &sysctl_intvec,
1248 .extra1 = &zero,
1249 .extra2 = &one_hundred,
1250 },
Christoph Lameter17436602006-01-18 17:42:32 -08001251#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001252#ifdef CONFIG_SMP
1253 {
1254 .ctl_name = CTL_UNNUMBERED,
1255 .procname = "stat_interval",
1256 .data = &sysctl_stat_interval,
1257 .maxlen = sizeof(sysctl_stat_interval),
1258 .mode = 0644,
1259 .proc_handler = &proc_dointvec_jiffies,
1260 .strategy = &sysctl_jiffies,
1261 },
1262#endif
Eric Parised032182007-06-28 15:55:21 -04001263#ifdef CONFIG_SECURITY
1264 {
1265 .ctl_name = CTL_UNNUMBERED,
1266 .procname = "mmap_min_addr",
1267 .data = &mmap_min_addr,
1268 .maxlen = sizeof(unsigned long),
1269 .mode = 0644,
1270 .proc_handler = &proc_doulongvec_minmax,
1271 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001272#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001273#ifdef CONFIG_NUMA
1274 {
1275 .ctl_name = CTL_UNNUMBERED,
1276 .procname = "numa_zonelist_order",
1277 .data = &numa_zonelist_order,
1278 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1279 .mode = 0644,
1280 .proc_handler = &numa_zonelist_order_handler,
1281 .strategy = &sysctl_string,
1282 },
1283#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001284#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001285 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001286 {
1287 .ctl_name = VM_VDSO_ENABLED,
1288 .procname = "vdso_enabled",
1289 .data = &vdso_enabled,
1290 .maxlen = sizeof(vdso_enabled),
1291 .mode = 0644,
1292 .proc_handler = &proc_dointvec,
1293 .strategy = &sysctl_intvec,
1294 .extra1 = &zero,
1295 },
1296#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001297#ifdef CONFIG_HIGHMEM
1298 {
1299 .ctl_name = CTL_UNNUMBERED,
1300 .procname = "highmem_is_dirtyable",
1301 .data = &vm_highmem_is_dirtyable,
1302 .maxlen = sizeof(vm_highmem_is_dirtyable),
1303 .mode = 0644,
1304 .proc_handler = &proc_dointvec_minmax,
1305 .strategy = &sysctl_intvec,
1306 .extra1 = &zero,
1307 .extra2 = &one,
1308 },
1309#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001310#ifdef CONFIG_UNEVICTABLE_LRU
1311 {
1312 .ctl_name = CTL_UNNUMBERED,
1313 .procname = "scan_unevictable_pages",
1314 .data = &scan_unevictable_pages,
1315 .maxlen = sizeof(scan_unevictable_pages),
1316 .mode = 0644,
1317 .proc_handler = &scan_unevictable_handler,
1318 },
1319#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001320/*
1321 * NOTE: do not add new entries to this table unless you have read
1322 * Documentation/sysctl/ctl_unnumbered.txt
1323 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 { .ctl_name = 0 }
1325};
1326
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001327#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001328static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001329 { .ctl_name = 0 }
1330};
1331#endif
1332
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001333static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 {
1335 .ctl_name = FS_NRINODE,
1336 .procname = "inode-nr",
1337 .data = &inodes_stat,
1338 .maxlen = 2*sizeof(int),
1339 .mode = 0444,
1340 .proc_handler = &proc_dointvec,
1341 },
1342 {
1343 .ctl_name = FS_STATINODE,
1344 .procname = "inode-state",
1345 .data = &inodes_stat,
1346 .maxlen = 7*sizeof(int),
1347 .mode = 0444,
1348 .proc_handler = &proc_dointvec,
1349 },
1350 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 .procname = "file-nr",
1352 .data = &files_stat,
1353 .maxlen = 3*sizeof(int),
1354 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001355 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 },
1357 {
1358 .ctl_name = FS_MAXFILE,
1359 .procname = "file-max",
1360 .data = &files_stat.max_files,
1361 .maxlen = sizeof(int),
1362 .mode = 0644,
1363 .proc_handler = &proc_dointvec,
1364 },
1365 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001366 .ctl_name = CTL_UNNUMBERED,
1367 .procname = "nr_open",
1368 .data = &sysctl_nr_open,
1369 .maxlen = sizeof(int),
1370 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001371 .proc_handler = &proc_dointvec_minmax,
1372 .extra1 = &sysctl_nr_open_min,
1373 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001374 },
1375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .ctl_name = FS_DENTRY,
1377 .procname = "dentry-state",
1378 .data = &dentry_stat,
1379 .maxlen = 6*sizeof(int),
1380 .mode = 0444,
1381 .proc_handler = &proc_dointvec,
1382 },
1383 {
1384 .ctl_name = FS_OVERFLOWUID,
1385 .procname = "overflowuid",
1386 .data = &fs_overflowuid,
1387 .maxlen = sizeof(int),
1388 .mode = 0644,
1389 .proc_handler = &proc_dointvec_minmax,
1390 .strategy = &sysctl_intvec,
1391 .extra1 = &minolduid,
1392 .extra2 = &maxolduid,
1393 },
1394 {
1395 .ctl_name = FS_OVERFLOWGID,
1396 .procname = "overflowgid",
1397 .data = &fs_overflowgid,
1398 .maxlen = sizeof(int),
1399 .mode = 0644,
1400 .proc_handler = &proc_dointvec_minmax,
1401 .strategy = &sysctl_intvec,
1402 .extra1 = &minolduid,
1403 .extra2 = &maxolduid,
1404 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001405#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 {
1407 .ctl_name = FS_LEASES,
1408 .procname = "leases-enable",
1409 .data = &leases_enable,
1410 .maxlen = sizeof(int),
1411 .mode = 0644,
1412 .proc_handler = &proc_dointvec,
1413 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001414#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415#ifdef CONFIG_DNOTIFY
1416 {
1417 .ctl_name = FS_DIR_NOTIFY,
1418 .procname = "dir-notify-enable",
1419 .data = &dir_notify_enable,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
1422 .proc_handler = &proc_dointvec,
1423 },
1424#endif
1425#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001426#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 {
1428 .ctl_name = FS_LEASE_TIME,
1429 .procname = "lease-break-time",
1430 .data = &lease_break_time,
1431 .maxlen = sizeof(int),
1432 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001433 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001435#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001436#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 .procname = "aio-nr",
1439 .data = &aio_nr,
1440 .maxlen = sizeof(aio_nr),
1441 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001442 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 },
1444 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 .procname = "aio-max-nr",
1446 .data = &aio_max_nr,
1447 .maxlen = sizeof(aio_max_nr),
1448 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001449 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001451#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001452#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001453 {
1454 .ctl_name = FS_INOTIFY,
1455 .procname = "inotify",
1456 .mode = 0555,
1457 .child = inotify_table,
1458 },
1459#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001460#ifdef CONFIG_EPOLL
1461 {
1462 .procname = "epoll",
1463 .mode = 0555,
1464 .child = epoll_table,
1465 },
1466#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001468 {
1469 .ctl_name = KERN_SETUID_DUMPABLE,
1470 .procname = "suid_dumpable",
1471 .data = &suid_dumpable,
1472 .maxlen = sizeof(int),
1473 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001474 .proc_handler = &proc_dointvec_minmax,
1475 .strategy = &sysctl_intvec,
1476 .extra1 = &zero,
1477 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001478 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001479#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1480 {
1481 .ctl_name = CTL_UNNUMBERED,
1482 .procname = "binfmt_misc",
1483 .mode = 0555,
1484 .child = binfmt_misc_table,
1485 },
1486#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001487/*
1488 * NOTE: do not add new entries to this table unless you have read
1489 * Documentation/sysctl/ctl_unnumbered.txt
1490 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 { .ctl_name = 0 }
1492};
1493
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001494static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001495#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001496 {
1497 .ctl_name = CTL_UNNUMBERED,
1498 .procname = "exception-trace",
1499 .data = &show_unhandled_signals,
1500 .maxlen = sizeof(int),
1501 .mode = 0644,
1502 .proc_handler = proc_dointvec
1503 },
1504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 { .ctl_name = 0 }
1506};
1507
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001508static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001510};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
Al Viro330d57f2005-11-04 10:18:40 +00001512static DEFINE_SPINLOCK(sysctl_lock);
1513
1514/* called under sysctl_lock */
1515static int use_table(struct ctl_table_header *p)
1516{
1517 if (unlikely(p->unregistering))
1518 return 0;
1519 p->used++;
1520 return 1;
1521}
1522
1523/* called under sysctl_lock */
1524static void unuse_table(struct ctl_table_header *p)
1525{
1526 if (!--p->used)
1527 if (unlikely(p->unregistering))
1528 complete(p->unregistering);
1529}
1530
1531/* called under sysctl_lock, will reacquire if has to wait */
1532static void start_unregistering(struct ctl_table_header *p)
1533{
1534 /*
1535 * if p->used is 0, nobody will ever touch that entry again;
1536 * we'll eliminate all paths to it before dropping sysctl_lock
1537 */
1538 if (unlikely(p->used)) {
1539 struct completion wait;
1540 init_completion(&wait);
1541 p->unregistering = &wait;
1542 spin_unlock(&sysctl_lock);
1543 wait_for_completion(&wait);
1544 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001545 } else {
1546 /* anything non-NULL; we'll never dereference it */
1547 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001548 }
1549 /*
1550 * do not remove from the list until nobody holds it; walking the
1551 * list in do_sysctl() relies on that.
1552 */
1553 list_del_init(&p->ctl_entry);
1554}
1555
Al Virof7e6ced2008-07-15 01:44:23 -04001556void sysctl_head_get(struct ctl_table_header *head)
1557{
1558 spin_lock(&sysctl_lock);
1559 head->count++;
1560 spin_unlock(&sysctl_lock);
1561}
1562
1563void sysctl_head_put(struct ctl_table_header *head)
1564{
1565 spin_lock(&sysctl_lock);
1566 if (!--head->count)
1567 kfree(head);
1568 spin_unlock(&sysctl_lock);
1569}
1570
1571struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1572{
1573 if (!head)
1574 BUG();
1575 spin_lock(&sysctl_lock);
1576 if (!use_table(head))
1577 head = ERR_PTR(-ENOENT);
1578 spin_unlock(&sysctl_lock);
1579 return head;
1580}
1581
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001582void sysctl_head_finish(struct ctl_table_header *head)
1583{
1584 if (!head)
1585 return;
1586 spin_lock(&sysctl_lock);
1587 unuse_table(head);
1588 spin_unlock(&sysctl_lock);
1589}
1590
Al Viro73455092008-07-14 21:22:20 -04001591static struct ctl_table_set *
1592lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1593{
1594 struct ctl_table_set *set = &root->default_set;
1595 if (root->lookup)
1596 set = root->lookup(root, namespaces);
1597 return set;
1598}
1599
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001600static struct list_head *
1601lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001602{
Al Viro73455092008-07-14 21:22:20 -04001603 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1604 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001605}
1606
1607struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1608 struct ctl_table_header *prev)
1609{
1610 struct ctl_table_root *root;
1611 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001612 struct ctl_table_header *head;
1613 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001614
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001615 spin_lock(&sysctl_lock);
1616 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001617 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001618 tmp = &prev->ctl_entry;
1619 unuse_table(prev);
1620 goto next;
1621 }
1622 tmp = &root_table_header.ctl_entry;
1623 for (;;) {
1624 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1625
1626 if (!use_table(head))
1627 goto next;
1628 spin_unlock(&sysctl_lock);
1629 return head;
1630 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001631 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001632 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001633 header_list = lookup_header_list(root, namespaces);
1634 if (tmp != header_list)
1635 continue;
1636
1637 do {
1638 root = list_entry(root->root_list.next,
1639 struct ctl_table_root, root_list);
1640 if (root == &sysctl_table_root)
1641 goto out;
1642 header_list = lookup_header_list(root, namespaces);
1643 } while (list_empty(header_list));
1644 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001645 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001646out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001647 spin_unlock(&sysctl_lock);
1648 return NULL;
1649}
1650
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001651struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1652{
1653 return __sysctl_head_next(current->nsproxy, prev);
1654}
1655
1656void register_sysctl_root(struct ctl_table_root *root)
1657{
1658 spin_lock(&sysctl_lock);
1659 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1660 spin_unlock(&sysctl_lock);
1661}
1662
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001663#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001664/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001665static int do_sysctl_strategy(struct ctl_table_root *root,
1666 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001667 void __user *oldval, size_t __user *oldlenp,
1668 void __user *newval, size_t newlen)
1669{
1670 int op = 0, rc;
1671
1672 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001673 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001674 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001675 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001676 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001677 return -EPERM;
1678
1679 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001680 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001681 if (rc < 0)
1682 return rc;
1683 if (rc > 0)
1684 return 0;
1685 }
1686
1687 /* If there is no strategy routine, or if the strategy returns
1688 * zero, proceed with automatic r/w */
1689 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001690 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001691 if (rc < 0)
1692 return rc;
1693 }
1694 return 0;
1695}
1696
1697static int parse_table(int __user *name, int nlen,
1698 void __user *oldval, size_t __user *oldlenp,
1699 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001700 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001701 struct ctl_table *table)
1702{
1703 int n;
1704repeat:
1705 if (!nlen)
1706 return -ENOTDIR;
1707 if (get_user(n, name))
1708 return -EFAULT;
1709 for ( ; table->ctl_name || table->procname; table++) {
1710 if (!table->ctl_name)
1711 continue;
1712 if (n == table->ctl_name) {
1713 int error;
1714 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001715 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001716 return -EPERM;
1717 name++;
1718 nlen--;
1719 table = table->child;
1720 goto repeat;
1721 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001722 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001723 oldval, oldlenp,
1724 newval, newlen);
1725 return error;
1726 }
1727 }
1728 return -ENOTDIR;
1729}
1730
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1732 void __user *newval, size_t newlen)
1733{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001734 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001735 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1738 return -ENOTDIR;
1739 if (oldval) {
1740 int old_len;
1741 if (!oldlenp || get_user(old_len, oldlenp))
1742 return -EFAULT;
1743 }
Al Viro330d57f2005-11-04 10:18:40 +00001744
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001745 for (head = sysctl_head_next(NULL); head;
1746 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001747 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001748 newval, newlen,
1749 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001750 if (error != -ENOTDIR) {
1751 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001752 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001753 }
1754 }
Al Viro330d57f2005-11-04 10:18:40 +00001755 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756}
1757
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001758SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759{
1760 struct __sysctl_args tmp;
1761 int error;
1762
1763 if (copy_from_user(&tmp, args, sizeof(tmp)))
1764 return -EFAULT;
1765
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001766 error = deprecated_sysctl_warning(&tmp);
1767 if (error)
1768 goto out;
1769
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 lock_kernel();
1771 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1772 tmp.newval, tmp.newlen);
1773 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001774out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 return error;
1776}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001777#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
1779/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001780 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 * some sysctl variables are readonly even to root.
1782 */
1783
1784static int test_perm(int mode, int op)
1785{
David Howells76aac0e2008-11-14 10:39:12 +11001786 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 mode >>= 6;
1788 else if (in_egroup_p(0))
1789 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001790 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 return 0;
1792 return -EACCES;
1793}
1794
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001795int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796{
1797 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001798 int mode;
1799
Al Viroe6305c42008-07-15 21:03:57 -04001800 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 if (error)
1802 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001803
1804 if (root->permissions)
1805 mode = root->permissions(root, current->nsproxy, table);
1806 else
1807 mode = table->mode;
1808
1809 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810}
1811
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001812static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1813{
1814 for (; table->ctl_name || table->procname; table++) {
1815 table->parent = parent;
1816 if (table->child)
1817 sysctl_set_parent(table, table->child);
1818 }
1819}
1820
1821static __init int sysctl_init(void)
1822{
1823 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001824#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1825 {
1826 int err;
1827 err = sysctl_check_table(current->nsproxy, root_table);
1828 }
1829#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001830 return 0;
1831}
1832
1833core_initcall(sysctl_init);
1834
Al Virobfbcf032008-07-27 06:31:22 +01001835static struct ctl_table *is_branch_in(struct ctl_table *branch,
1836 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001837{
1838 struct ctl_table *p;
1839 const char *s = branch->procname;
1840
1841 /* branch should have named subdirectory as its first element */
1842 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001843 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001844
1845 /* ... and nothing else */
1846 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001847 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001848
1849 /* table should contain subdirectory with the same name */
1850 for (p = table; p->procname || p->ctl_name; p++) {
1851 if (!p->child)
1852 continue;
1853 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001854 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001855 }
Al Virobfbcf032008-07-27 06:31:22 +01001856 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001857}
1858
1859/* see if attaching q to p would be an improvement */
1860static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1861{
1862 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001863 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001864 int is_better = 0;
1865 int not_in_parent = !p->attached_by;
1866
Al Virobfbcf032008-07-27 06:31:22 +01001867 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001868 if (by == q->attached_by)
1869 is_better = 1;
1870 if (to == p->attached_by)
1871 not_in_parent = 1;
1872 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001873 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001874 }
1875
1876 if (is_better && not_in_parent) {
1877 q->attached_by = by;
1878 q->attached_to = to;
1879 q->parent = p;
1880 }
1881}
1882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001884 * __register_sysctl_paths - register a sysctl hierarchy
1885 * @root: List of sysctl headers to register on
1886 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001887 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 *
1890 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001891 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001893 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 *
1895 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1896 * must be unique within that level of sysctl
1897 *
1898 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1899 * enter a sysctl file
1900 *
1901 * data - a pointer to data for use by proc_handler
1902 *
1903 * maxlen - the maximum size in bytes of the data
1904 *
1905 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1906 *
1907 * child - a pointer to the child sysctl table if this entry is a directory, or
1908 * %NULL.
1909 *
1910 * proc_handler - the text handler routine (described below)
1911 *
1912 * strategy - the strategy routine (described below)
1913 *
1914 * de - for internal use by the sysctl routines
1915 *
1916 * extra1, extra2 - extra pointers usable by the proc handler routines
1917 *
1918 * Leaf nodes in the sysctl tree will be represented by a single file
1919 * under /proc; non-leaf nodes will be represented by directories.
1920 *
1921 * sysctl(2) can automatically manage read and write requests through
1922 * the sysctl table. The data and maxlen fields of the ctl_table
1923 * struct enable minimal validation of the values being written to be
1924 * performed, and the mode field allows minimal authentication.
1925 *
1926 * More sophisticated management can be enabled by the provision of a
1927 * strategy routine with the table entry. This will be called before
1928 * any automatic read or write of the data is performed.
1929 *
1930 * The strategy routine may return
1931 *
1932 * < 0 - Error occurred (error is passed to user process)
1933 *
1934 * 0 - OK - proceed with automatic read or write.
1935 *
1936 * > 0 - OK - read or write has been done by the strategy routine, so
1937 * return immediately.
1938 *
1939 * There must be a proc_handler routine for any terminal nodes
1940 * mirrored under /proc/sys (non-terminals are handled by a built-in
1941 * directory handler). Several default handlers are available to
1942 * cover common cases -
1943 *
1944 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1945 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1946 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1947 *
1948 * It is the handler's job to read the input buffer from user memory
1949 * and process it. The handler should return 0 on success.
1950 *
1951 * This routine returns %NULL on a failure to register, and a pointer
1952 * to the table header on success.
1953 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001954struct ctl_table_header *__register_sysctl_paths(
1955 struct ctl_table_root *root,
1956 struct nsproxy *namespaces,
1957 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001959 struct ctl_table_header *header;
1960 struct ctl_table *new, **prevp;
1961 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001962 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001963
1964 /* Count the path components */
1965 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1966 ;
1967
1968 /*
1969 * For each path component, allocate a 2-element ctl_table array.
1970 * The first array element will be filled with the sysctl entry
1971 * for this, the second will be the sentinel (ctl_name == 0).
1972 *
1973 * We allocate everything in one go so that we don't have to
1974 * worry about freeing additional memory in unregister_sysctl_table.
1975 */
1976 header = kzalloc(sizeof(struct ctl_table_header) +
1977 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1978 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001980
1981 new = (struct ctl_table *) (header + 1);
1982
1983 /* Now connect the dots */
1984 prevp = &header->ctl_table;
1985 for (n = 0; n < npath; ++n, ++path) {
1986 /* Copy the procname */
1987 new->procname = path->procname;
1988 new->ctl_name = path->ctl_name;
1989 new->mode = 0555;
1990
1991 *prevp = new;
1992 prevp = &new->child;
1993
1994 new += 2;
1995 }
1996 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001997 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001998
1999 INIT_LIST_HEAD(&header->ctl_entry);
2000 header->used = 0;
2001 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002002 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002003 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002004 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002005#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002006 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002007 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002008 return NULL;
2009 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002010#endif
Al Viro330d57f2005-11-04 10:18:40 +00002011 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002012 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002013 header->attached_by = header->ctl_table;
2014 header->attached_to = root_table;
2015 header->parent = &root_table_header;
2016 for (set = header->set; set; set = set->parent) {
2017 struct ctl_table_header *p;
2018 list_for_each_entry(p, &set->list, ctl_entry) {
2019 if (p->unregistering)
2020 continue;
2021 try_attach(p, header);
2022 }
2023 }
2024 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002025 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002026 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002027
2028 return header;
2029}
2030
2031/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002032 * register_sysctl_table_path - register a sysctl table hierarchy
2033 * @path: The path to the directory the sysctl table is in.
2034 * @table: the top-level table structure
2035 *
2036 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2037 * array. A completely 0 filled entry terminates the table.
2038 *
2039 * See __register_sysctl_paths for more details.
2040 */
2041struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2042 struct ctl_table *table)
2043{
2044 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2045 path, table);
2046}
2047
2048/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002049 * register_sysctl_table - register a sysctl table hierarchy
2050 * @table: the top-level table structure
2051 *
2052 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2053 * array. A completely 0 filled entry terminates the table.
2054 *
2055 * See register_sysctl_paths for more details.
2056 */
2057struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2058{
2059 static const struct ctl_path null_path[] = { {} };
2060
2061 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062}
2063
2064/**
2065 * unregister_sysctl_table - unregister a sysctl table hierarchy
2066 * @header: the header returned from register_sysctl_table
2067 *
2068 * Unregisters the sysctl table and all children. proc entries may not
2069 * actually be removed until they are no longer used by anyone.
2070 */
2071void unregister_sysctl_table(struct ctl_table_header * header)
2072{
Al Viro330d57f2005-11-04 10:18:40 +00002073 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002074
2075 if (header == NULL)
2076 return;
2077
Al Viro330d57f2005-11-04 10:18:40 +00002078 spin_lock(&sysctl_lock);
2079 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002080 if (!--header->parent->count) {
2081 WARN_ON(1);
2082 kfree(header->parent);
2083 }
Al Virof7e6ced2008-07-15 01:44:23 -04002084 if (!--header->count)
2085 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002086 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
Al Viro90434762008-07-15 08:54:06 -04002089int sysctl_is_seen(struct ctl_table_header *p)
2090{
2091 struct ctl_table_set *set = p->set;
2092 int res;
2093 spin_lock(&sysctl_lock);
2094 if (p->unregistering)
2095 res = 0;
2096 else if (!set->is_seen)
2097 res = 1;
2098 else
2099 res = set->is_seen(set);
2100 spin_unlock(&sysctl_lock);
2101 return res;
2102}
2103
Al Viro73455092008-07-14 21:22:20 -04002104void setup_sysctl_set(struct ctl_table_set *p,
2105 struct ctl_table_set *parent,
2106 int (*is_seen)(struct ctl_table_set *))
2107{
2108 INIT_LIST_HEAD(&p->list);
2109 p->parent = parent ? parent : &sysctl_table_root.default_set;
2110 p->is_seen = is_seen;
2111}
2112
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002113#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002114struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002115{
2116 return NULL;
2117}
2118
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002119struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2120 struct ctl_table *table)
2121{
2122 return NULL;
2123}
2124
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002125void unregister_sysctl_table(struct ctl_table_header * table)
2126{
2127}
2128
Al Viro73455092008-07-14 21:22:20 -04002129void setup_sysctl_set(struct ctl_table_set *p,
2130 struct ctl_table_set *parent,
2131 int (*is_seen)(struct ctl_table_set *))
2132{
2133}
2134
Al Virof7e6ced2008-07-15 01:44:23 -04002135void sysctl_head_put(struct ctl_table_header *head)
2136{
2137}
2138
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002139#endif /* CONFIG_SYSCTL */
2140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141/*
2142 * /proc/sys support
2143 */
2144
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002145#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002147static int _proc_do_string(void* data, int maxlen, int write,
2148 struct file *filp, void __user *buffer,
2149 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002150{
2151 size_t len;
2152 char __user *p;
2153 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002154
2155 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002156 *lenp = 0;
2157 return 0;
2158 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002159
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002160 if (write) {
2161 len = 0;
2162 p = buffer;
2163 while (len < *lenp) {
2164 if (get_user(c, p++))
2165 return -EFAULT;
2166 if (c == 0 || c == '\n')
2167 break;
2168 len++;
2169 }
2170 if (len >= maxlen)
2171 len = maxlen-1;
2172 if(copy_from_user(data, buffer, len))
2173 return -EFAULT;
2174 ((char *) data)[len] = 0;
2175 *ppos += *lenp;
2176 } else {
2177 len = strlen(data);
2178 if (len > maxlen)
2179 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002180
2181 if (*ppos > len) {
2182 *lenp = 0;
2183 return 0;
2184 }
2185
2186 data += *ppos;
2187 len -= *ppos;
2188
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002189 if (len > *lenp)
2190 len = *lenp;
2191 if (len)
2192 if(copy_to_user(buffer, data, len))
2193 return -EFAULT;
2194 if (len < *lenp) {
2195 if(put_user('\n', ((char __user *) buffer) + len))
2196 return -EFAULT;
2197 len++;
2198 }
2199 *lenp = len;
2200 *ppos += len;
2201 }
2202 return 0;
2203}
2204
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205/**
2206 * proc_dostring - read a string sysctl
2207 * @table: the sysctl table
2208 * @write: %TRUE if this is a write to the sysctl file
2209 * @filp: the file structure
2210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2213 *
2214 * Reads/writes a string from/to the user buffer. If the kernel
2215 * buffer provided is not large enough to hold the string, the
2216 * string is truncated. The copied string is %NULL-terminated.
2217 * If the string is being read by the user process, it is copied
2218 * and a newline '\n' is added. It is truncated if the buffer is
2219 * not large enough.
2220 *
2221 * Returns 0 on success.
2222 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002223int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 void __user *buffer, size_t *lenp, loff_t *ppos)
2225{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002226 return _proc_do_string(table->data, table->maxlen, write, filp,
2227 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228}
2229
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
2231static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2232 int *valp,
2233 int write, void *data)
2234{
2235 if (write) {
2236 *valp = *negp ? -*lvalp : *lvalp;
2237 } else {
2238 int val = *valp;
2239 if (val < 0) {
2240 *negp = -1;
2241 *lvalp = (unsigned long)-val;
2242 } else {
2243 *negp = 0;
2244 *lvalp = (unsigned long)val;
2245 }
2246 }
2247 return 0;
2248}
2249
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002250static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002251 int write, struct file *filp, void __user *buffer,
2252 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2254 int write, void *data),
2255 void *data)
2256{
2257#define TMPBUFLEN 21
2258 int *i, vleft, first=1, neg, val;
2259 unsigned long lval;
2260 size_t left, len;
2261
2262 char buf[TMPBUFLEN], *p;
2263 char __user *s = buffer;
2264
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002265 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 (*ppos && !write)) {
2267 *lenp = 0;
2268 return 0;
2269 }
2270
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002271 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 vleft = table->maxlen / sizeof(*i);
2273 left = *lenp;
2274
2275 if (!conv)
2276 conv = do_proc_dointvec_conv;
2277
2278 for (; left && vleft--; i++, first=0) {
2279 if (write) {
2280 while (left) {
2281 char c;
2282 if (get_user(c, s))
2283 return -EFAULT;
2284 if (!isspace(c))
2285 break;
2286 left--;
2287 s++;
2288 }
2289 if (!left)
2290 break;
2291 neg = 0;
2292 len = left;
2293 if (len > sizeof(buf) - 1)
2294 len = sizeof(buf) - 1;
2295 if (copy_from_user(buf, s, len))
2296 return -EFAULT;
2297 buf[len] = 0;
2298 p = buf;
2299 if (*p == '-' && left > 1) {
2300 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002301 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 }
2303 if (*p < '0' || *p > '9')
2304 break;
2305
2306 lval = simple_strtoul(p, &p, 0);
2307
2308 len = p-buf;
2309 if ((len < left) && *p && !isspace(*p))
2310 break;
2311 if (neg)
2312 val = -val;
2313 s += len;
2314 left -= len;
2315
2316 if (conv(&neg, &lval, i, 1, data))
2317 break;
2318 } else {
2319 p = buf;
2320 if (!first)
2321 *p++ = '\t';
2322
2323 if (conv(&neg, &lval, i, 0, data))
2324 break;
2325
2326 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2327 len = strlen(buf);
2328 if (len > left)
2329 len = left;
2330 if(copy_to_user(s, buf, len))
2331 return -EFAULT;
2332 left -= len;
2333 s += len;
2334 }
2335 }
2336
2337 if (!write && !first && left) {
2338 if(put_user('\n', s))
2339 return -EFAULT;
2340 left--, s++;
2341 }
2342 if (write) {
2343 while (left) {
2344 char c;
2345 if (get_user(c, s++))
2346 return -EFAULT;
2347 if (!isspace(c))
2348 break;
2349 left--;
2350 }
2351 }
2352 if (write && first)
2353 return -EINVAL;
2354 *lenp -= left;
2355 *ppos += *lenp;
2356 return 0;
2357#undef TMPBUFLEN
2358}
2359
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002360static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002361 void __user *buffer, size_t *lenp, loff_t *ppos,
2362 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2363 int write, void *data),
2364 void *data)
2365{
2366 return __do_proc_dointvec(table->data, table, write, filp,
2367 buffer, lenp, ppos, conv, data);
2368}
2369
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370/**
2371 * proc_dointvec - read a vector of integers
2372 * @table: the sysctl table
2373 * @write: %TRUE if this is a write to the sysctl file
2374 * @filp: the file structure
2375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: file position
2378 *
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2381 *
2382 * Returns 0 on success.
2383 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002384int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 void __user *buffer, size_t *lenp, loff_t *ppos)
2386{
2387 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2388 NULL,NULL);
2389}
2390
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002391/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002392 * Taint values can only be increased
2393 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002394 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002395static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002396 void __user *buffer, size_t *lenp, loff_t *ppos)
2397{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002398 struct ctl_table t;
2399 unsigned long tmptaint = get_taint();
2400 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002401
Bastian Blank91fcd412007-04-23 14:41:14 -07002402 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002403 return -EPERM;
2404
Andi Kleen25ddbb12008-10-15 22:01:41 -07002405 t = *table;
2406 t.data = &tmptaint;
2407 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2408 if (err < 0)
2409 return err;
2410
2411 if (write) {
2412 /*
2413 * Poor man's atomic or. Not worth adding a primitive
2414 * to everyone's atomic.h for this
2415 */
2416 int i;
2417 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2418 if ((tmptaint >> i) & 1)
2419 add_taint(i);
2420 }
2421 }
2422
2423 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002424}
2425
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426struct do_proc_dointvec_minmax_conv_param {
2427 int *min;
2428 int *max;
2429};
2430
2431static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2432 int *valp,
2433 int write, void *data)
2434{
2435 struct do_proc_dointvec_minmax_conv_param *param = data;
2436 if (write) {
2437 int val = *negp ? -*lvalp : *lvalp;
2438 if ((param->min && *param->min > val) ||
2439 (param->max && *param->max < val))
2440 return -EINVAL;
2441 *valp = val;
2442 } else {
2443 int val = *valp;
2444 if (val < 0) {
2445 *negp = -1;
2446 *lvalp = (unsigned long)-val;
2447 } else {
2448 *negp = 0;
2449 *lvalp = (unsigned long)val;
2450 }
2451 }
2452 return 0;
2453}
2454
2455/**
2456 * proc_dointvec_minmax - read a vector of integers with min/max values
2457 * @table: the sysctl table
2458 * @write: %TRUE if this is a write to the sysctl file
2459 * @filp: the file structure
2460 * @buffer: the user buffer
2461 * @lenp: the size of the user buffer
2462 * @ppos: file position
2463 *
2464 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2465 * values from/to the user buffer, treated as an ASCII string.
2466 *
2467 * This routine will ensure the values are within the range specified by
2468 * table->extra1 (min) and table->extra2 (max).
2469 *
2470 * Returns 0 on success.
2471 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002472int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 void __user *buffer, size_t *lenp, loff_t *ppos)
2474{
2475 struct do_proc_dointvec_minmax_conv_param param = {
2476 .min = (int *) table->extra1,
2477 .max = (int *) table->extra2,
2478 };
2479 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2480 do_proc_dointvec_minmax_conv, &param);
2481}
2482
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002483static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 struct file *filp,
2485 void __user *buffer,
2486 size_t *lenp, loff_t *ppos,
2487 unsigned long convmul,
2488 unsigned long convdiv)
2489{
2490#define TMPBUFLEN 21
2491 unsigned long *i, *min, *max, val;
2492 int vleft, first=1, neg;
2493 size_t len, left;
2494 char buf[TMPBUFLEN], *p;
2495 char __user *s = buffer;
2496
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002497 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 (*ppos && !write)) {
2499 *lenp = 0;
2500 return 0;
2501 }
2502
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002503 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 min = (unsigned long *) table->extra1;
2505 max = (unsigned long *) table->extra2;
2506 vleft = table->maxlen / sizeof(unsigned long);
2507 left = *lenp;
2508
2509 for (; left && vleft--; i++, min++, max++, first=0) {
2510 if (write) {
2511 while (left) {
2512 char c;
2513 if (get_user(c, s))
2514 return -EFAULT;
2515 if (!isspace(c))
2516 break;
2517 left--;
2518 s++;
2519 }
2520 if (!left)
2521 break;
2522 neg = 0;
2523 len = left;
2524 if (len > TMPBUFLEN-1)
2525 len = TMPBUFLEN-1;
2526 if (copy_from_user(buf, s, len))
2527 return -EFAULT;
2528 buf[len] = 0;
2529 p = buf;
2530 if (*p == '-' && left > 1) {
2531 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002532 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 }
2534 if (*p < '0' || *p > '9')
2535 break;
2536 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2537 len = p-buf;
2538 if ((len < left) && *p && !isspace(*p))
2539 break;
2540 if (neg)
2541 val = -val;
2542 s += len;
2543 left -= len;
2544
2545 if(neg)
2546 continue;
2547 if ((min && val < *min) || (max && val > *max))
2548 continue;
2549 *i = val;
2550 } else {
2551 p = buf;
2552 if (!first)
2553 *p++ = '\t';
2554 sprintf(p, "%lu", convdiv * (*i) / convmul);
2555 len = strlen(buf);
2556 if (len > left)
2557 len = left;
2558 if(copy_to_user(s, buf, len))
2559 return -EFAULT;
2560 left -= len;
2561 s += len;
2562 }
2563 }
2564
2565 if (!write && !first && left) {
2566 if(put_user('\n', s))
2567 return -EFAULT;
2568 left--, s++;
2569 }
2570 if (write) {
2571 while (left) {
2572 char c;
2573 if (get_user(c, s++))
2574 return -EFAULT;
2575 if (!isspace(c))
2576 break;
2577 left--;
2578 }
2579 }
2580 if (write && first)
2581 return -EINVAL;
2582 *lenp -= left;
2583 *ppos += *lenp;
2584 return 0;
2585#undef TMPBUFLEN
2586}
2587
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002588static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002589 struct file *filp,
2590 void __user *buffer,
2591 size_t *lenp, loff_t *ppos,
2592 unsigned long convmul,
2593 unsigned long convdiv)
2594{
2595 return __do_proc_doulongvec_minmax(table->data, table, write,
2596 filp, buffer, lenp, ppos, convmul, convdiv);
2597}
2598
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599/**
2600 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2601 * @table: the sysctl table
2602 * @write: %TRUE if this is a write to the sysctl file
2603 * @filp: the file structure
2604 * @buffer: the user buffer
2605 * @lenp: the size of the user buffer
2606 * @ppos: file position
2607 *
2608 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2609 * values from/to the user buffer, treated as an ASCII string.
2610 *
2611 * This routine will ensure the values are within the range specified by
2612 * table->extra1 (min) and table->extra2 (max).
2613 *
2614 * Returns 0 on success.
2615 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002616int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 void __user *buffer, size_t *lenp, loff_t *ppos)
2618{
2619 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2620}
2621
2622/**
2623 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2624 * @table: the sysctl table
2625 * @write: %TRUE if this is a write to the sysctl file
2626 * @filp: the file structure
2627 * @buffer: the user buffer
2628 * @lenp: the size of the user buffer
2629 * @ppos: file position
2630 *
2631 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2632 * values from/to the user buffer, treated as an ASCII string. The values
2633 * are treated as milliseconds, and converted to jiffies when they are stored.
2634 *
2635 * This routine will ensure the values are within the range specified by
2636 * table->extra1 (min) and table->extra2 (max).
2637 *
2638 * Returns 0 on success.
2639 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002640int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 struct file *filp,
2642 void __user *buffer,
2643 size_t *lenp, loff_t *ppos)
2644{
2645 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2646 lenp, ppos, HZ, 1000l);
2647}
2648
2649
2650static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2651 int *valp,
2652 int write, void *data)
2653{
2654 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002655 if (*lvalp > LONG_MAX / HZ)
2656 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2658 } else {
2659 int val = *valp;
2660 unsigned long lval;
2661 if (val < 0) {
2662 *negp = -1;
2663 lval = (unsigned long)-val;
2664 } else {
2665 *negp = 0;
2666 lval = (unsigned long)val;
2667 }
2668 *lvalp = lval / HZ;
2669 }
2670 return 0;
2671}
2672
2673static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2674 int *valp,
2675 int write, void *data)
2676{
2677 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002678 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2679 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2681 } else {
2682 int val = *valp;
2683 unsigned long lval;
2684 if (val < 0) {
2685 *negp = -1;
2686 lval = (unsigned long)-val;
2687 } else {
2688 *negp = 0;
2689 lval = (unsigned long)val;
2690 }
2691 *lvalp = jiffies_to_clock_t(lval);
2692 }
2693 return 0;
2694}
2695
2696static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2697 int *valp,
2698 int write, void *data)
2699{
2700 if (write) {
2701 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2702 } else {
2703 int val = *valp;
2704 unsigned long lval;
2705 if (val < 0) {
2706 *negp = -1;
2707 lval = (unsigned long)-val;
2708 } else {
2709 *negp = 0;
2710 lval = (unsigned long)val;
2711 }
2712 *lvalp = jiffies_to_msecs(lval);
2713 }
2714 return 0;
2715}
2716
2717/**
2718 * proc_dointvec_jiffies - read a vector of integers as seconds
2719 * @table: the sysctl table
2720 * @write: %TRUE if this is a write to the sysctl file
2721 * @filp: the file structure
2722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
2724 * @ppos: file position
2725 *
2726 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2727 * values from/to the user buffer, treated as an ASCII string.
2728 * The values read are assumed to be in seconds, and are converted into
2729 * jiffies.
2730 *
2731 * Returns 0 on success.
2732 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002733int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 void __user *buffer, size_t *lenp, loff_t *ppos)
2735{
2736 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2737 do_proc_dointvec_jiffies_conv,NULL);
2738}
2739
2740/**
2741 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @filp: the file structure
2745 * @buffer: the user buffer
2746 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002747 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 *
2749 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2750 * values from/to the user buffer, treated as an ASCII string.
2751 * The values read are assumed to be in 1/USER_HZ seconds, and
2752 * are converted into jiffies.
2753 *
2754 * Returns 0 on success.
2755 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002756int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 void __user *buffer, size_t *lenp, loff_t *ppos)
2758{
2759 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2760 do_proc_dointvec_userhz_jiffies_conv,NULL);
2761}
2762
2763/**
2764 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2765 * @table: the sysctl table
2766 * @write: %TRUE if this is a write to the sysctl file
2767 * @filp: the file structure
2768 * @buffer: the user buffer
2769 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002770 * @ppos: file position
2771 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 *
2773 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2774 * values from/to the user buffer, treated as an ASCII string.
2775 * The values read are assumed to be in 1/1000 seconds, and
2776 * are converted into jiffies.
2777 *
2778 * Returns 0 on success.
2779 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002780int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 void __user *buffer, size_t *lenp, loff_t *ppos)
2782{
2783 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2784 do_proc_dointvec_ms_jiffies_conv, NULL);
2785}
2786
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002787static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002788 void __user *buffer, size_t *lenp, loff_t *ppos)
2789{
2790 struct pid *new_pid;
2791 pid_t tmp;
2792 int r;
2793
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002794 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002795
2796 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2797 lenp, ppos, NULL, NULL);
2798 if (r || !write)
2799 return r;
2800
2801 new_pid = find_get_pid(tmp);
2802 if (!new_pid)
2803 return -ESRCH;
2804
2805 put_pid(xchg(&cad_pid, new_pid));
2806 return 0;
2807}
2808
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809#else /* CONFIG_PROC_FS */
2810
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002811int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 void __user *buffer, size_t *lenp, loff_t *ppos)
2813{
2814 return -ENOSYS;
2815}
2816
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002817int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 void __user *buffer, size_t *lenp, loff_t *ppos)
2819{
2820 return -ENOSYS;
2821}
2822
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002823int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 void __user *buffer, size_t *lenp, loff_t *ppos)
2825{
2826 return -ENOSYS;
2827}
2828
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002829int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 void __user *buffer, size_t *lenp, loff_t *ppos)
2831{
2832 return -ENOSYS;
2833}
2834
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002835int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 void __user *buffer, size_t *lenp, loff_t *ppos)
2837{
2838 return -ENOSYS;
2839}
2840
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002841int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 void __user *buffer, size_t *lenp, loff_t *ppos)
2843{
2844 return -ENOSYS;
2845}
2846
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002847int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 void __user *buffer, size_t *lenp, loff_t *ppos)
2849{
2850 return -ENOSYS;
2851}
2852
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002853int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 struct file *filp,
2855 void __user *buffer,
2856 size_t *lenp, loff_t *ppos)
2857{
2858 return -ENOSYS;
2859}
2860
2861
2862#endif /* CONFIG_PROC_FS */
2863
2864
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002865#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866/*
2867 * General sysctl support routines
2868 */
2869
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002870/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002871int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002872 void __user *oldval, size_t __user *oldlenp,
2873 void __user *newval, size_t newlen)
2874{
2875 size_t len;
2876
2877 /* Get out of I don't have a variable */
2878 if (!table->data || !table->maxlen)
2879 return -ENOTDIR;
2880
2881 if (oldval && oldlenp) {
2882 if (get_user(len, oldlenp))
2883 return -EFAULT;
2884 if (len) {
2885 if (len > table->maxlen)
2886 len = table->maxlen;
2887 if (copy_to_user(oldval, table->data, len))
2888 return -EFAULT;
2889 if (put_user(len, oldlenp))
2890 return -EFAULT;
2891 }
2892 }
2893
2894 if (newval && newlen) {
2895 if (newlen > table->maxlen)
2896 newlen = table->maxlen;
2897
2898 if (copy_from_user(table->data, newval, newlen))
2899 return -EFAULT;
2900 }
2901 return 1;
2902}
2903
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002905int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002907 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 if (!table->data || !table->maxlen)
2910 return -ENOTDIR;
2911
2912 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002913 size_t bufsize;
2914 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002916 if (bufsize) {
2917 size_t len = strlen(table->data), copied;
2918
2919 /* This shouldn't trigger for a well-formed sysctl */
2920 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002922
2923 /* Copy up to a max of bufsize-1 bytes of the string */
2924 copied = (len >= bufsize) ? bufsize - 1 : len;
2925
2926 if (copy_to_user(oldval, table->data, copied) ||
2927 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002929 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 return -EFAULT;
2931 }
2932 }
2933 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002934 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 if (len > table->maxlen)
2936 len = table->maxlen;
2937 if(copy_from_user(table->data, newval, len))
2938 return -EFAULT;
2939 if (len == table->maxlen)
2940 len--;
2941 ((char *) table->data)[len] = 0;
2942 }
Yi Yang82c9df82005-12-30 16:37:10 +08002943 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944}
2945
2946/*
2947 * This function makes sure that all of the integers in the vector
2948 * are between the minimum and maximum values given in the arrays
2949 * table->extra1 and table->extra2, respectively.
2950 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002951int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002953 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954{
2955
2956 if (newval && newlen) {
2957 int __user *vec = (int __user *) newval;
2958 int *min = (int *) table->extra1;
2959 int *max = (int *) table->extra2;
2960 size_t length;
2961 int i;
2962
2963 if (newlen % sizeof(int) != 0)
2964 return -EINVAL;
2965
2966 if (!table->extra1 && !table->extra2)
2967 return 0;
2968
2969 if (newlen > table->maxlen)
2970 newlen = table->maxlen;
2971 length = newlen / sizeof(int);
2972
2973 for (i = 0; i < length; i++) {
2974 int value;
2975 if (get_user(value, vec + i))
2976 return -EFAULT;
2977 if (min && value < min[i])
2978 return -EINVAL;
2979 if (max && value > max[i])
2980 return -EINVAL;
2981 }
2982 }
2983 return 0;
2984}
2985
2986/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002987int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002989 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002991 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002993
2994 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002996 if (olen) {
2997 int val;
2998
2999 if (olen < sizeof(int))
3000 return -EINVAL;
3001
3002 val = *(int *)(table->data) / HZ;
3003 if (put_user(val, (int __user *)oldval))
3004 return -EFAULT;
3005 if (put_user(sizeof(int), oldlenp))
3006 return -EFAULT;
3007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 }
3009 if (newval && newlen) {
3010 int new;
3011 if (newlen != sizeof(int))
3012 return -EINVAL;
3013 if (get_user(new, (int __user *)newval))
3014 return -EFAULT;
3015 *(int *)(table->data) = new*HZ;
3016 }
3017 return 1;
3018}
3019
3020/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003021int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003023 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003025 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003027
3028 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003030 if (olen) {
3031 int val;
3032
3033 if (olen < sizeof(int))
3034 return -EINVAL;
3035
3036 val = jiffies_to_msecs(*(int *)(table->data));
3037 if (put_user(val, (int __user *)oldval))
3038 return -EFAULT;
3039 if (put_user(sizeof(int), oldlenp))
3040 return -EFAULT;
3041 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 }
3043 if (newval && newlen) {
3044 int new;
3045 if (newlen != sizeof(int))
3046 return -EINVAL;
3047 if (get_user(new, (int __user *)newval))
3048 return -EFAULT;
3049 *(int *)(table->data) = msecs_to_jiffies(new);
3050 }
3051 return 1;
3052}
3053
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003054
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003055
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003056#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
3058
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003059SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003061 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003062 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003063
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003064 if (copy_from_user(&tmp, args, sizeof(tmp)))
3065 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003066
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003067 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003068
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003069 /* If no error reading the parameters then just -ENOSYS ... */
3070 if (!error)
3071 error = -ENOSYS;
3072
3073 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074}
3075
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003076int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003077 void __user *oldval, size_t __user *oldlenp,
3078 void __user *newval, size_t newlen)
3079{
3080 return -ENOSYS;
3081}
3082
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003083int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003085 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086{
3087 return -ENOSYS;
3088}
3089
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003090int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003092 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093{
3094 return -ENOSYS;
3095}
3096
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003097int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003099 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100{
3101 return -ENOSYS;
3102}
3103
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003104int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003106 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107{
3108 return -ENOSYS;
3109}
3110
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003111#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003113static int deprecated_sysctl_warning(struct __sysctl_args *args)
3114{
3115 static int msg_count;
3116 int name[CTL_MAXNAME];
3117 int i;
3118
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003119 /* Check args->nlen. */
3120 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3121 return -ENOTDIR;
3122
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003123 /* Read in the sysctl name for better debug message logging */
3124 for (i = 0; i < args->nlen; i++)
3125 if (get_user(name[i], args->name + i))
3126 return -EFAULT;
3127
3128 /* Ignore accesses to kernel.version */
3129 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3130 return 0;
3131
3132 if (msg_count < 5) {
3133 msg_count++;
3134 printk(KERN_INFO
3135 "warning: process `%s' used the deprecated sysctl "
3136 "system call with ", current->comm);
3137 for (i = 0; i < args->nlen; i++)
3138 printk("%d.", name[i]);
3139 printk("\n");
3140 }
3141 return 0;
3142}
3143
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144/*
3145 * No sense putting this after each symbol definition, twice,
3146 * exception granted :-)
3147 */
3148EXPORT_SYMBOL(proc_dointvec);
3149EXPORT_SYMBOL(proc_dointvec_jiffies);
3150EXPORT_SYMBOL(proc_dointvec_minmax);
3151EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3152EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3153EXPORT_SYMBOL(proc_dostring);
3154EXPORT_SYMBOL(proc_doulongvec_minmax);
3155EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3156EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003157EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158EXPORT_SYMBOL(sysctl_intvec);
3159EXPORT_SYMBOL(sysctl_jiffies);
3160EXPORT_SYMBOL(sysctl_ms_jiffies);
3161EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003162EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163EXPORT_SYMBOL(unregister_sysctl_table);