blob: 149581fb48ab048b66a04105bad71dfcf66bfe29 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/uaccess.h>
54#include <asm/processor.h>
55
Andi Kleen29cbc782006-09-30 01:47:55 +020056#ifdef CONFIG_X86
57#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010058#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010059#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020060#endif
61
Eric W. Biederman7058cb02007-10-18 03:05:58 -070062static int deprecated_sysctl_warning(struct __sysctl_args *args);
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#if defined(CONFIG_SYSCTL)
65
66/* External variables not in a header file. */
67extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070068extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int sysctl_overcommit_memory;
70extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070071extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070072extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080073extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070076extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int pid_max;
79extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080081extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080082extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020083extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000086#ifndef CONFIG_MMU
87extern int sysctl_nr_trim_pages;
88#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070089#ifdef CONFIG_RCU_TORTURE_TEST
90extern int rcutorture_runnable;
91#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070093/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080094#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020096static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097#endif
98
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700100static int __maybe_unused one = 1;
101static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800102static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103static int one_hundred = 100;
104
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700105/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
106static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
109static int maxolduid = 65535;
110static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800111static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113static int ngroups_max = NGROUPS_MAX;
114
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200115#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700117extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#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 },
Kees Cook3d433212009-04-02 15:49:29 -0700538 {
539 .ctl_name = CTL_UNNUMBERED,
540 .procname = "modules_disabled",
541 .data = &modules_disabled,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 /* only handle a transition from default "0" to "1" */
545 .proc_handler = &proc_dointvec_minmax,
546 .extra1 = &one,
547 .extra2 = &one,
548 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700550#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 {
552 .ctl_name = KERN_HOTPLUG,
553 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100554 .data = &uevent_helper,
555 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 .mode = 0644,
557 .proc_handler = &proc_dostring,
558 .strategy = &sysctl_string,
559 },
560#endif
561#ifdef CONFIG_CHR_DEV_SG
562 {
563 .ctl_name = KERN_SG_BIG_BUFF,
564 .procname = "sg-big-buff",
565 .data = &sg_big_buff,
566 .maxlen = sizeof (int),
567 .mode = 0444,
568 .proc_handler = &proc_dointvec,
569 },
570#endif
571#ifdef CONFIG_BSD_PROCESS_ACCT
572 {
573 .ctl_name = KERN_ACCT,
574 .procname = "acct",
575 .data = &acct_parm,
576 .maxlen = 3*sizeof(int),
577 .mode = 0644,
578 .proc_handler = &proc_dointvec,
579 },
580#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#ifdef CONFIG_MAGIC_SYSRQ
582 {
583 .ctl_name = KERN_SYSRQ,
584 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800585 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 .maxlen = sizeof (int),
587 .mode = 0644,
588 .proc_handler = &proc_dointvec,
589 },
590#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700591#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700594 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .maxlen = sizeof (int),
596 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700597 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700599#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 {
601 .ctl_name = KERN_MAX_THREADS,
602 .procname = "threads-max",
603 .data = &max_threads,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec,
607 },
608 {
609 .ctl_name = KERN_RANDOM,
610 .procname = "random",
611 .mode = 0555,
612 .child = random_table,
613 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 {
615 .ctl_name = KERN_OVERFLOWUID,
616 .procname = "overflowuid",
617 .data = &overflowuid,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec_minmax,
621 .strategy = &sysctl_intvec,
622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
624 },
625 {
626 .ctl_name = KERN_OVERFLOWGID,
627 .procname = "overflowgid",
628 .data = &overflowgid,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = &proc_dointvec_minmax,
632 .strategy = &sysctl_intvec,
633 .extra1 = &minolduid,
634 .extra2 = &maxolduid,
635 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800636#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637#ifdef CONFIG_MATHEMU
638 {
639 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
640 .procname = "ieee_emulation_warnings",
641 .data = &sysctl_ieee_emulation_warnings,
642 .maxlen = sizeof(int),
643 .mode = 0644,
644 .proc_handler = &proc_dointvec,
645 },
646#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 {
648 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
649 .procname = "userprocess_debug",
650 .data = &sysctl_userprocess_debug,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec,
654 },
655#endif
656 {
657 .ctl_name = KERN_PIDMAX,
658 .procname = "pid_max",
659 .data = &pid_max,
660 .maxlen = sizeof (int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec_minmax,
663 .strategy = sysctl_intvec,
664 .extra1 = &pid_max_min,
665 .extra2 = &pid_max_max,
666 },
667 {
668 .ctl_name = KERN_PANIC_ON_OOPS,
669 .procname = "panic_on_oops",
670 .data = &panic_on_oops,
671 .maxlen = sizeof(int),
672 .mode = 0644,
673 .proc_handler = &proc_dointvec,
674 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800675#if defined CONFIG_PRINTK
676 {
677 .ctl_name = KERN_PRINTK,
678 .procname = "printk",
679 .data = &console_loglevel,
680 .maxlen = 4*sizeof(int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
683 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 {
685 .ctl_name = KERN_PRINTK_RATELIMIT,
686 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700687 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .maxlen = sizeof(int),
689 .mode = 0644,
690 .proc_handler = &proc_dointvec_jiffies,
691 .strategy = &sysctl_jiffies,
692 },
693 {
694 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
695 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700696 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec,
700 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800701#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 {
703 .ctl_name = KERN_NGROUPS_MAX,
704 .procname = "ngroups_max",
705 .data = &ngroups_max,
706 .maxlen = sizeof (int),
707 .mode = 0444,
708 .proc_handler = &proc_dointvec,
709 },
710#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
711 {
712 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
713 .procname = "unknown_nmi_panic",
714 .data = &unknown_nmi_panic,
715 .maxlen = sizeof (int),
716 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200717 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 },
Don Zickus407984f2006-09-26 10:52:27 +0200719 {
Don Zickus407984f2006-09-26 10:52:27 +0200720 .procname = "nmi_watchdog",
721 .data = &nmi_watchdog_enabled,
722 .maxlen = sizeof (int),
723 .mode = 0644,
724 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 },
726#endif
727#if defined(CONFIG_X86)
728 {
Don Zickus8da5add2006-09-26 10:52:27 +0200729 .ctl_name = KERN_PANIC_ON_NMI,
730 .procname = "panic_on_unrecovered_nmi",
731 .data = &panic_on_unrecovered_nmi,
732 .maxlen = sizeof(int),
733 .mode = 0644,
734 .proc_handler = &proc_dointvec,
735 },
736 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 .ctl_name = KERN_BOOTLOADER_TYPE,
738 .procname = "bootloader_type",
739 .data = &bootloader_type,
740 .maxlen = sizeof (int),
741 .mode = 0444,
742 .proc_handler = &proc_dointvec,
743 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100744 {
745 .ctl_name = CTL_UNNUMBERED,
746 .procname = "kstack_depth_to_print",
747 .data = &kstack_depth_to_print,
748 .maxlen = sizeof(int),
749 .mode = 0644,
750 .proc_handler = &proc_dointvec,
751 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100752 {
753 .ctl_name = CTL_UNNUMBERED,
754 .procname = "io_delay_type",
755 .data = &io_delay_type,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = &proc_dointvec,
759 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800761#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 {
763 .ctl_name = KERN_RANDOMIZE,
764 .procname = "randomize_va_space",
765 .data = &randomize_va_space,
766 .maxlen = sizeof(int),
767 .mode = 0644,
768 .proc_handler = &proc_dointvec,
769 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800770#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800771#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700772 {
773 .ctl_name = KERN_SPIN_RETRY,
774 .procname = "spin_retry",
775 .data = &spin_retry,
776 .maxlen = sizeof (int),
777 .mode = 0644,
778 .proc_handler = &proc_dointvec,
779 },
780#endif
Len Brown673d5b42007-07-28 03:33:16 -0400781#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800782 {
Pavel Machekc255d842006-02-20 18:27:58 -0800783 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700784 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800785 .maxlen = sizeof (unsigned long),
786 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800787 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800788 },
789#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800790#ifdef CONFIG_IA64
791 {
792 .ctl_name = KERN_IA64_UNALIGNED,
793 .procname = "ignore-unaligned-usertrap",
794 .data = &no_unaligned_warning,
795 .maxlen = sizeof (int),
796 .mode = 0644,
797 .proc_handler = &proc_dointvec,
798 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800799 {
800 .ctl_name = CTL_UNNUMBERED,
801 .procname = "unaligned-dump-stack",
802 .data = &unaligned_dump_stack,
803 .maxlen = sizeof (int),
804 .mode = 0644,
805 .proc_handler = &proc_dointvec,
806 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800807#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700808#ifdef CONFIG_DETECT_SOFTLOCKUP
809 {
810 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200811 .procname = "softlockup_panic",
812 .data = &softlockup_panic,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700815 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200816 .strategy = &sysctl_intvec,
817 .extra1 = &zero,
818 .extra2 = &one,
819 },
820 {
821 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700822 .procname = "softlockup_thresh",
823 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200824 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700825 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800826 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700827 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200828 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700829 .extra2 = &sixty,
830 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800831#endif
832#ifdef CONFIG_DETECT_HUNG_TASK
833 {
834 .ctl_name = CTL_UNNUMBERED,
835 .procname = "hung_task_panic",
836 .data = &sysctl_hung_task_panic,
837 .maxlen = sizeof(int),
838 .mode = 0644,
839 .proc_handler = &proc_dointvec_minmax,
840 .strategy = &sysctl_intvec,
841 .extra1 = &zero,
842 .extra2 = &one,
843 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100844 {
845 .ctl_name = CTL_UNNUMBERED,
846 .procname = "hung_task_check_count",
847 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100848 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100849 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100850 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100851 .strategy = &sysctl_intvec,
852 },
853 {
854 .ctl_name = CTL_UNNUMBERED,
855 .procname = "hung_task_timeout_secs",
856 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100857 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100858 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800859 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100860 .strategy = &sysctl_intvec,
861 },
862 {
863 .ctl_name = CTL_UNNUMBERED,
864 .procname = "hung_task_warnings",
865 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100866 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100867 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100868 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100869 .strategy = &sysctl_intvec,
870 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700871#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200872#ifdef CONFIG_COMPAT
873 {
874 .ctl_name = KERN_COMPAT_LOG,
875 .procname = "compat-log",
876 .data = &compat_log,
877 .maxlen = sizeof (int),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec,
880 },
881#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700882#ifdef CONFIG_RT_MUTEXES
883 {
884 .ctl_name = KERN_MAX_LOCK_DEPTH,
885 .procname = "max_lock_depth",
886 .data = &max_lock_depth,
887 .maxlen = sizeof(int),
888 .mode = 0644,
889 .proc_handler = &proc_dointvec,
890 },
891#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700892 {
893 .ctl_name = CTL_UNNUMBERED,
894 .procname = "poweroff_cmd",
895 .data = &poweroff_cmd,
896 .maxlen = POWEROFF_CMD_PATH_LEN,
897 .mode = 0644,
898 .proc_handler = &proc_dostring,
899 .strategy = &sysctl_string,
900 },
David Howells0b77f5b2008-04-29 01:01:32 -0700901#ifdef CONFIG_KEYS
902 {
903 .ctl_name = CTL_UNNUMBERED,
904 .procname = "keys",
905 .mode = 0555,
906 .child = key_sysctls,
907 },
908#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700909#ifdef CONFIG_RCU_TORTURE_TEST
910 {
911 .ctl_name = CTL_UNNUMBERED,
912 .procname = "rcutorture_runnable",
913 .data = &rcutorture_runnable,
914 .maxlen = sizeof(int),
915 .mode = 0644,
916 .proc_handler = &proc_dointvec,
917 },
918#endif
David Howells12e22c52009-04-03 16:42:35 +0100919#ifdef CONFIG_SLOW_WORK
Lee Schermerhornaf936a12008-10-18 20:26:53 -0700920 {
921 .ctl_name = CTL_UNNUMBERED,
David Howells12e22c52009-04-03 16:42:35 +0100922 .procname = "slow-work",
923 .mode = 0555,
924 .child = slow_work_sysctls,
Lee Schermerhornaf936a12008-10-18 20:26:53 -0700925 },
926#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700927/*
928 * NOTE: do not add new entries to this table unless you have read
929 * Documentation/sysctl/ctl_unnumbered.txt
930 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 { .ctl_name = 0 }
932};
933
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700934static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 {
936 .ctl_name = VM_OVERCOMMIT_MEMORY,
937 .procname = "overcommit_memory",
938 .data = &sysctl_overcommit_memory,
939 .maxlen = sizeof(sysctl_overcommit_memory),
940 .mode = 0644,
941 .proc_handler = &proc_dointvec,
942 },
943 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700944 .ctl_name = VM_PANIC_ON_OOM,
945 .procname = "panic_on_oom",
946 .data = &sysctl_panic_on_oom,
947 .maxlen = sizeof(sysctl_panic_on_oom),
948 .mode = 0644,
949 .proc_handler = &proc_dointvec,
950 },
951 {
David Rientjesfe071d72007-10-16 23:25:56 -0700952 .ctl_name = CTL_UNNUMBERED,
953 .procname = "oom_kill_allocating_task",
954 .data = &sysctl_oom_kill_allocating_task,
955 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
956 .mode = 0644,
957 .proc_handler = &proc_dointvec,
958 },
959 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800960 .ctl_name = CTL_UNNUMBERED,
961 .procname = "oom_dump_tasks",
962 .data = &sysctl_oom_dump_tasks,
963 .maxlen = sizeof(sysctl_oom_dump_tasks),
964 .mode = 0644,
965 .proc_handler = &proc_dointvec,
966 },
967 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 .ctl_name = VM_OVERCOMMIT_RATIO,
969 .procname = "overcommit_ratio",
970 .data = &sysctl_overcommit_ratio,
971 .maxlen = sizeof(sysctl_overcommit_ratio),
972 .mode = 0644,
973 .proc_handler = &proc_dointvec,
974 },
975 {
976 .ctl_name = VM_PAGE_CLUSTER,
977 .procname = "page-cluster",
978 .data = &page_cluster,
979 .maxlen = sizeof(int),
980 .mode = 0644,
981 .proc_handler = &proc_dointvec,
982 },
983 {
984 .ctl_name = VM_DIRTY_BACKGROUND,
985 .procname = "dirty_background_ratio",
986 .data = &dirty_background_ratio,
987 .maxlen = sizeof(dirty_background_ratio),
988 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800989 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 .strategy = &sysctl_intvec,
991 .extra1 = &zero,
992 .extra2 = &one_hundred,
993 },
994 {
David Rientjes2da02992009-01-06 14:39:31 -0800995 .ctl_name = CTL_UNNUMBERED,
996 .procname = "dirty_background_bytes",
997 .data = &dirty_background_bytes,
998 .maxlen = sizeof(dirty_background_bytes),
999 .mode = 0644,
1000 .proc_handler = &dirty_background_bytes_handler,
1001 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001002 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001003 },
1004 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 .ctl_name = VM_DIRTY_RATIO,
1006 .procname = "dirty_ratio",
1007 .data = &vm_dirty_ratio,
1008 .maxlen = sizeof(vm_dirty_ratio),
1009 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001010 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 .strategy = &sysctl_intvec,
1012 .extra1 = &zero,
1013 .extra2 = &one_hundred,
1014 },
1015 {
David Rientjes2da02992009-01-06 14:39:31 -08001016 .ctl_name = CTL_UNNUMBERED,
1017 .procname = "dirty_bytes",
1018 .data = &vm_dirty_bytes,
1019 .maxlen = sizeof(vm_dirty_bytes),
1020 .mode = 0644,
1021 .proc_handler = &dirty_bytes_handler,
1022 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001023 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001024 },
1025 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001027 .data = &dirty_writeback_interval,
1028 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 .mode = 0644,
1030 .proc_handler = &dirty_writeback_centisecs_handler,
1031 },
1032 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001034 .data = &dirty_expire_interval,
1035 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001037 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 },
1039 {
1040 .ctl_name = VM_NR_PDFLUSH_THREADS,
1041 .procname = "nr_pdflush_threads",
1042 .data = &nr_pdflush_threads,
1043 .maxlen = sizeof nr_pdflush_threads,
1044 .mode = 0444 /* read-only*/,
1045 .proc_handler = &proc_dointvec,
1046 },
1047 {
1048 .ctl_name = VM_SWAPPINESS,
1049 .procname = "swappiness",
1050 .data = &vm_swappiness,
1051 .maxlen = sizeof(vm_swappiness),
1052 .mode = 0644,
1053 .proc_handler = &proc_dointvec_minmax,
1054 .strategy = &sysctl_intvec,
1055 .extra1 = &zero,
1056 .extra2 = &one_hundred,
1057 },
1058#ifdef CONFIG_HUGETLB_PAGE
1059 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001061 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 .maxlen = sizeof(unsigned long),
1063 .mode = 0644,
1064 .proc_handler = &hugetlb_sysctl_handler,
1065 .extra1 = (void *)&hugetlb_zero,
1066 .extra2 = (void *)&hugetlb_infinity,
1067 },
1068 {
1069 .ctl_name = VM_HUGETLB_GROUP,
1070 .procname = "hugetlb_shm_group",
1071 .data = &sysctl_hugetlb_shm_group,
1072 .maxlen = sizeof(gid_t),
1073 .mode = 0644,
1074 .proc_handler = &proc_dointvec,
1075 },
Mel Gorman396faf02007-07-17 04:03:13 -07001076 {
1077 .ctl_name = CTL_UNNUMBERED,
1078 .procname = "hugepages_treat_as_movable",
1079 .data = &hugepages_treat_as_movable,
1080 .maxlen = sizeof(int),
1081 .mode = 0644,
1082 .proc_handler = &hugetlb_treat_movable_handler,
1083 },
Adam Litke54f9f802007-10-16 01:26:20 -07001084 {
1085 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001086 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001087 .data = NULL,
1088 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001089 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001090 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001091 .extra1 = (void *)&hugetlb_zero,
1092 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001093 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094#endif
1095 {
1096 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1097 .procname = "lowmem_reserve_ratio",
1098 .data = &sysctl_lowmem_reserve_ratio,
1099 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1100 .mode = 0644,
1101 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1102 .strategy = &sysctl_intvec,
1103 },
1104 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001105 .ctl_name = VM_DROP_PAGECACHE,
1106 .procname = "drop_caches",
1107 .data = &sysctl_drop_caches,
1108 .maxlen = sizeof(int),
1109 .mode = 0644,
1110 .proc_handler = drop_caches_sysctl_handler,
1111 .strategy = &sysctl_intvec,
1112 },
1113 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 .ctl_name = VM_MIN_FREE_KBYTES,
1115 .procname = "min_free_kbytes",
1116 .data = &min_free_kbytes,
1117 .maxlen = sizeof(min_free_kbytes),
1118 .mode = 0644,
1119 .proc_handler = &min_free_kbytes_sysctl_handler,
1120 .strategy = &sysctl_intvec,
1121 .extra1 = &zero,
1122 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001123 {
1124 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1125 .procname = "percpu_pagelist_fraction",
1126 .data = &percpu_pagelist_fraction,
1127 .maxlen = sizeof(percpu_pagelist_fraction),
1128 .mode = 0644,
1129 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1130 .strategy = &sysctl_intvec,
1131 .extra1 = &min_percpu_pagelist_fract,
1132 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133#ifdef CONFIG_MMU
1134 {
1135 .ctl_name = VM_MAX_MAP_COUNT,
1136 .procname = "max_map_count",
1137 .data = &sysctl_max_map_count,
1138 .maxlen = sizeof(sysctl_max_map_count),
1139 .mode = 0644,
1140 .proc_handler = &proc_dointvec
1141 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001142#else
1143 {
1144 .ctl_name = CTL_UNNUMBERED,
1145 .procname = "nr_trim_pages",
1146 .data = &sysctl_nr_trim_pages,
1147 .maxlen = sizeof(sysctl_nr_trim_pages),
1148 .mode = 0644,
1149 .proc_handler = &proc_dointvec_minmax,
1150 .strategy = &sysctl_intvec,
1151 .extra1 = &zero,
1152 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153#endif
1154 {
1155 .ctl_name = VM_LAPTOP_MODE,
1156 .procname = "laptop_mode",
1157 .data = &laptop_mode,
1158 .maxlen = sizeof(laptop_mode),
1159 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001160 .proc_handler = &proc_dointvec_jiffies,
1161 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 },
1163 {
1164 .ctl_name = VM_BLOCK_DUMP,
1165 .procname = "block_dump",
1166 .data = &block_dump,
1167 .maxlen = sizeof(block_dump),
1168 .mode = 0644,
1169 .proc_handler = &proc_dointvec,
1170 .strategy = &sysctl_intvec,
1171 .extra1 = &zero,
1172 },
1173 {
1174 .ctl_name = VM_VFS_CACHE_PRESSURE,
1175 .procname = "vfs_cache_pressure",
1176 .data = &sysctl_vfs_cache_pressure,
1177 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1178 .mode = 0644,
1179 .proc_handler = &proc_dointvec,
1180 .strategy = &sysctl_intvec,
1181 .extra1 = &zero,
1182 },
1183#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1184 {
1185 .ctl_name = VM_LEGACY_VA_LAYOUT,
1186 .procname = "legacy_va_layout",
1187 .data = &sysctl_legacy_va_layout,
1188 .maxlen = sizeof(sysctl_legacy_va_layout),
1189 .mode = 0644,
1190 .proc_handler = &proc_dointvec,
1191 .strategy = &sysctl_intvec,
1192 .extra1 = &zero,
1193 },
1194#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001195#ifdef CONFIG_NUMA
1196 {
1197 .ctl_name = VM_ZONE_RECLAIM_MODE,
1198 .procname = "zone_reclaim_mode",
1199 .data = &zone_reclaim_mode,
1200 .maxlen = sizeof(zone_reclaim_mode),
1201 .mode = 0644,
1202 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001203 .strategy = &sysctl_intvec,
1204 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001205 },
Christoph Lameter96146342006-07-03 00:24:13 -07001206 {
1207 .ctl_name = VM_MIN_UNMAPPED,
1208 .procname = "min_unmapped_ratio",
1209 .data = &sysctl_min_unmapped_ratio,
1210 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1211 .mode = 0644,
1212 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1213 .strategy = &sysctl_intvec,
1214 .extra1 = &zero,
1215 .extra2 = &one_hundred,
1216 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001217 {
1218 .ctl_name = VM_MIN_SLAB,
1219 .procname = "min_slab_ratio",
1220 .data = &sysctl_min_slab_ratio,
1221 .maxlen = sizeof(sysctl_min_slab_ratio),
1222 .mode = 0644,
1223 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1224 .strategy = &sysctl_intvec,
1225 .extra1 = &zero,
1226 .extra2 = &one_hundred,
1227 },
Christoph Lameter17436602006-01-18 17:42:32 -08001228#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001229#ifdef CONFIG_SMP
1230 {
1231 .ctl_name = CTL_UNNUMBERED,
1232 .procname = "stat_interval",
1233 .data = &sysctl_stat_interval,
1234 .maxlen = sizeof(sysctl_stat_interval),
1235 .mode = 0644,
1236 .proc_handler = &proc_dointvec_jiffies,
1237 .strategy = &sysctl_jiffies,
1238 },
1239#endif
Eric Parised032182007-06-28 15:55:21 -04001240#ifdef CONFIG_SECURITY
1241 {
1242 .ctl_name = CTL_UNNUMBERED,
1243 .procname = "mmap_min_addr",
1244 .data = &mmap_min_addr,
1245 .maxlen = sizeof(unsigned long),
1246 .mode = 0644,
1247 .proc_handler = &proc_doulongvec_minmax,
1248 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001249#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001250#ifdef CONFIG_NUMA
1251 {
1252 .ctl_name = CTL_UNNUMBERED,
1253 .procname = "numa_zonelist_order",
1254 .data = &numa_zonelist_order,
1255 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1256 .mode = 0644,
1257 .proc_handler = &numa_zonelist_order_handler,
1258 .strategy = &sysctl_string,
1259 },
1260#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001261#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001262 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001263 {
1264 .ctl_name = VM_VDSO_ENABLED,
1265 .procname = "vdso_enabled",
1266 .data = &vdso_enabled,
1267 .maxlen = sizeof(vdso_enabled),
1268 .mode = 0644,
1269 .proc_handler = &proc_dointvec,
1270 .strategy = &sysctl_intvec,
1271 .extra1 = &zero,
1272 },
1273#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001274#ifdef CONFIG_HIGHMEM
1275 {
1276 .ctl_name = CTL_UNNUMBERED,
1277 .procname = "highmem_is_dirtyable",
1278 .data = &vm_highmem_is_dirtyable,
1279 .maxlen = sizeof(vm_highmem_is_dirtyable),
1280 .mode = 0644,
1281 .proc_handler = &proc_dointvec_minmax,
1282 .strategy = &sysctl_intvec,
1283 .extra1 = &zero,
1284 .extra2 = &one,
1285 },
1286#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001287#ifdef CONFIG_UNEVICTABLE_LRU
1288 {
1289 .ctl_name = CTL_UNNUMBERED,
1290 .procname = "scan_unevictable_pages",
1291 .data = &scan_unevictable_pages,
1292 .maxlen = sizeof(scan_unevictable_pages),
1293 .mode = 0644,
1294 .proc_handler = &scan_unevictable_handler,
1295 },
1296#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001297/*
1298 * NOTE: do not add new entries to this table unless you have read
1299 * Documentation/sysctl/ctl_unnumbered.txt
1300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 { .ctl_name = 0 }
1302};
1303
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001304#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001305static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001306 { .ctl_name = 0 }
1307};
1308#endif
1309
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001310static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 {
1312 .ctl_name = FS_NRINODE,
1313 .procname = "inode-nr",
1314 .data = &inodes_stat,
1315 .maxlen = 2*sizeof(int),
1316 .mode = 0444,
1317 .proc_handler = &proc_dointvec,
1318 },
1319 {
1320 .ctl_name = FS_STATINODE,
1321 .procname = "inode-state",
1322 .data = &inodes_stat,
1323 .maxlen = 7*sizeof(int),
1324 .mode = 0444,
1325 .proc_handler = &proc_dointvec,
1326 },
1327 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 .procname = "file-nr",
1329 .data = &files_stat,
1330 .maxlen = 3*sizeof(int),
1331 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001332 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 },
1334 {
1335 .ctl_name = FS_MAXFILE,
1336 .procname = "file-max",
1337 .data = &files_stat.max_files,
1338 .maxlen = sizeof(int),
1339 .mode = 0644,
1340 .proc_handler = &proc_dointvec,
1341 },
1342 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001343 .ctl_name = CTL_UNNUMBERED,
1344 .procname = "nr_open",
1345 .data = &sysctl_nr_open,
1346 .maxlen = sizeof(int),
1347 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001348 .proc_handler = &proc_dointvec_minmax,
1349 .extra1 = &sysctl_nr_open_min,
1350 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001351 },
1352 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 .ctl_name = FS_DENTRY,
1354 .procname = "dentry-state",
1355 .data = &dentry_stat,
1356 .maxlen = 6*sizeof(int),
1357 .mode = 0444,
1358 .proc_handler = &proc_dointvec,
1359 },
1360 {
1361 .ctl_name = FS_OVERFLOWUID,
1362 .procname = "overflowuid",
1363 .data = &fs_overflowuid,
1364 .maxlen = sizeof(int),
1365 .mode = 0644,
1366 .proc_handler = &proc_dointvec_minmax,
1367 .strategy = &sysctl_intvec,
1368 .extra1 = &minolduid,
1369 .extra2 = &maxolduid,
1370 },
1371 {
1372 .ctl_name = FS_OVERFLOWGID,
1373 .procname = "overflowgid",
1374 .data = &fs_overflowgid,
1375 .maxlen = sizeof(int),
1376 .mode = 0644,
1377 .proc_handler = &proc_dointvec_minmax,
1378 .strategy = &sysctl_intvec,
1379 .extra1 = &minolduid,
1380 .extra2 = &maxolduid,
1381 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001382#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 {
1384 .ctl_name = FS_LEASES,
1385 .procname = "leases-enable",
1386 .data = &leases_enable,
1387 .maxlen = sizeof(int),
1388 .mode = 0644,
1389 .proc_handler = &proc_dointvec,
1390 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001391#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392#ifdef CONFIG_DNOTIFY
1393 {
1394 .ctl_name = FS_DIR_NOTIFY,
1395 .procname = "dir-notify-enable",
1396 .data = &dir_notify_enable,
1397 .maxlen = sizeof(int),
1398 .mode = 0644,
1399 .proc_handler = &proc_dointvec,
1400 },
1401#endif
1402#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001403#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 {
1405 .ctl_name = FS_LEASE_TIME,
1406 .procname = "lease-break-time",
1407 .data = &lease_break_time,
1408 .maxlen = sizeof(int),
1409 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001410 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001412#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001413#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 .procname = "aio-nr",
1416 .data = &aio_nr,
1417 .maxlen = sizeof(aio_nr),
1418 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001419 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 },
1421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 .procname = "aio-max-nr",
1423 .data = &aio_max_nr,
1424 .maxlen = sizeof(aio_max_nr),
1425 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001426 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001428#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001429#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001430 {
1431 .ctl_name = FS_INOTIFY,
1432 .procname = "inotify",
1433 .mode = 0555,
1434 .child = inotify_table,
1435 },
1436#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001437#ifdef CONFIG_EPOLL
1438 {
1439 .procname = "epoll",
1440 .mode = 0555,
1441 .child = epoll_table,
1442 },
1443#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001445 {
1446 .ctl_name = KERN_SETUID_DUMPABLE,
1447 .procname = "suid_dumpable",
1448 .data = &suid_dumpable,
1449 .maxlen = sizeof(int),
1450 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001451 .proc_handler = &proc_dointvec_minmax,
1452 .strategy = &sysctl_intvec,
1453 .extra1 = &zero,
1454 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001455 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001456#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1457 {
1458 .ctl_name = CTL_UNNUMBERED,
1459 .procname = "binfmt_misc",
1460 .mode = 0555,
1461 .child = binfmt_misc_table,
1462 },
1463#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001464/*
1465 * NOTE: do not add new entries to this table unless you have read
1466 * Documentation/sysctl/ctl_unnumbered.txt
1467 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 { .ctl_name = 0 }
1469};
1470
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001471static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001472#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001473 {
1474 .ctl_name = CTL_UNNUMBERED,
1475 .procname = "exception-trace",
1476 .data = &show_unhandled_signals,
1477 .maxlen = sizeof(int),
1478 .mode = 0644,
1479 .proc_handler = proc_dointvec
1480 },
1481#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 { .ctl_name = 0 }
1483};
1484
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001485static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001487};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Al Viro330d57f2005-11-04 10:18:40 +00001489static DEFINE_SPINLOCK(sysctl_lock);
1490
1491/* called under sysctl_lock */
1492static int use_table(struct ctl_table_header *p)
1493{
1494 if (unlikely(p->unregistering))
1495 return 0;
1496 p->used++;
1497 return 1;
1498}
1499
1500/* called under sysctl_lock */
1501static void unuse_table(struct ctl_table_header *p)
1502{
1503 if (!--p->used)
1504 if (unlikely(p->unregistering))
1505 complete(p->unregistering);
1506}
1507
1508/* called under sysctl_lock, will reacquire if has to wait */
1509static void start_unregistering(struct ctl_table_header *p)
1510{
1511 /*
1512 * if p->used is 0, nobody will ever touch that entry again;
1513 * we'll eliminate all paths to it before dropping sysctl_lock
1514 */
1515 if (unlikely(p->used)) {
1516 struct completion wait;
1517 init_completion(&wait);
1518 p->unregistering = &wait;
1519 spin_unlock(&sysctl_lock);
1520 wait_for_completion(&wait);
1521 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001522 } else {
1523 /* anything non-NULL; we'll never dereference it */
1524 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001525 }
1526 /*
1527 * do not remove from the list until nobody holds it; walking the
1528 * list in do_sysctl() relies on that.
1529 */
1530 list_del_init(&p->ctl_entry);
1531}
1532
Al Virof7e6ced2008-07-15 01:44:23 -04001533void sysctl_head_get(struct ctl_table_header *head)
1534{
1535 spin_lock(&sysctl_lock);
1536 head->count++;
1537 spin_unlock(&sysctl_lock);
1538}
1539
1540void sysctl_head_put(struct ctl_table_header *head)
1541{
1542 spin_lock(&sysctl_lock);
1543 if (!--head->count)
1544 kfree(head);
1545 spin_unlock(&sysctl_lock);
1546}
1547
1548struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1549{
1550 if (!head)
1551 BUG();
1552 spin_lock(&sysctl_lock);
1553 if (!use_table(head))
1554 head = ERR_PTR(-ENOENT);
1555 spin_unlock(&sysctl_lock);
1556 return head;
1557}
1558
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001559void sysctl_head_finish(struct ctl_table_header *head)
1560{
1561 if (!head)
1562 return;
1563 spin_lock(&sysctl_lock);
1564 unuse_table(head);
1565 spin_unlock(&sysctl_lock);
1566}
1567
Al Viro73455092008-07-14 21:22:20 -04001568static struct ctl_table_set *
1569lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1570{
1571 struct ctl_table_set *set = &root->default_set;
1572 if (root->lookup)
1573 set = root->lookup(root, namespaces);
1574 return set;
1575}
1576
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001577static struct list_head *
1578lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001579{
Al Viro73455092008-07-14 21:22:20 -04001580 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1581 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001582}
1583
1584struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1585 struct ctl_table_header *prev)
1586{
1587 struct ctl_table_root *root;
1588 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001589 struct ctl_table_header *head;
1590 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001591
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001592 spin_lock(&sysctl_lock);
1593 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001594 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001595 tmp = &prev->ctl_entry;
1596 unuse_table(prev);
1597 goto next;
1598 }
1599 tmp = &root_table_header.ctl_entry;
1600 for (;;) {
1601 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1602
1603 if (!use_table(head))
1604 goto next;
1605 spin_unlock(&sysctl_lock);
1606 return head;
1607 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001608 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001609 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001610 header_list = lookup_header_list(root, namespaces);
1611 if (tmp != header_list)
1612 continue;
1613
1614 do {
1615 root = list_entry(root->root_list.next,
1616 struct ctl_table_root, root_list);
1617 if (root == &sysctl_table_root)
1618 goto out;
1619 header_list = lookup_header_list(root, namespaces);
1620 } while (list_empty(header_list));
1621 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001622 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001623out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001624 spin_unlock(&sysctl_lock);
1625 return NULL;
1626}
1627
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001628struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1629{
1630 return __sysctl_head_next(current->nsproxy, prev);
1631}
1632
1633void register_sysctl_root(struct ctl_table_root *root)
1634{
1635 spin_lock(&sysctl_lock);
1636 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1637 spin_unlock(&sysctl_lock);
1638}
1639
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001640#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001641/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001642static int do_sysctl_strategy(struct ctl_table_root *root,
1643 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001644 void __user *oldval, size_t __user *oldlenp,
1645 void __user *newval, size_t newlen)
1646{
1647 int op = 0, rc;
1648
1649 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001650 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001651 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001652 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001653 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001654 return -EPERM;
1655
1656 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001657 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001658 if (rc < 0)
1659 return rc;
1660 if (rc > 0)
1661 return 0;
1662 }
1663
1664 /* If there is no strategy routine, or if the strategy returns
1665 * zero, proceed with automatic r/w */
1666 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001667 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001668 if (rc < 0)
1669 return rc;
1670 }
1671 return 0;
1672}
1673
1674static int parse_table(int __user *name, int nlen,
1675 void __user *oldval, size_t __user *oldlenp,
1676 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001677 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001678 struct ctl_table *table)
1679{
1680 int n;
1681repeat:
1682 if (!nlen)
1683 return -ENOTDIR;
1684 if (get_user(n, name))
1685 return -EFAULT;
1686 for ( ; table->ctl_name || table->procname; table++) {
1687 if (!table->ctl_name)
1688 continue;
1689 if (n == table->ctl_name) {
1690 int error;
1691 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001692 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001693 return -EPERM;
1694 name++;
1695 nlen--;
1696 table = table->child;
1697 goto repeat;
1698 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001699 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001700 oldval, oldlenp,
1701 newval, newlen);
1702 return error;
1703 }
1704 }
1705 return -ENOTDIR;
1706}
1707
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1709 void __user *newval, size_t newlen)
1710{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001711 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001712 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
1714 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1715 return -ENOTDIR;
1716 if (oldval) {
1717 int old_len;
1718 if (!oldlenp || get_user(old_len, oldlenp))
1719 return -EFAULT;
1720 }
Al Viro330d57f2005-11-04 10:18:40 +00001721
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001722 for (head = sysctl_head_next(NULL); head;
1723 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001724 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001725 newval, newlen,
1726 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001727 if (error != -ENOTDIR) {
1728 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001729 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001730 }
1731 }
Al Viro330d57f2005-11-04 10:18:40 +00001732 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733}
1734
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001735SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
1737 struct __sysctl_args tmp;
1738 int error;
1739
1740 if (copy_from_user(&tmp, args, sizeof(tmp)))
1741 return -EFAULT;
1742
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001743 error = deprecated_sysctl_warning(&tmp);
1744 if (error)
1745 goto out;
1746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 lock_kernel();
1748 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1749 tmp.newval, tmp.newlen);
1750 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001751out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 return error;
1753}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001754#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001757 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 * some sysctl variables are readonly even to root.
1759 */
1760
1761static int test_perm(int mode, int op)
1762{
David Howells76aac0e2008-11-14 10:39:12 +11001763 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 mode >>= 6;
1765 else if (in_egroup_p(0))
1766 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001767 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 return 0;
1769 return -EACCES;
1770}
1771
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001772int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
1774 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001775 int mode;
1776
Al Viroe6305c42008-07-15 21:03:57 -04001777 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 if (error)
1779 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001780
1781 if (root->permissions)
1782 mode = root->permissions(root, current->nsproxy, table);
1783 else
1784 mode = table->mode;
1785
1786 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787}
1788
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001789static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1790{
1791 for (; table->ctl_name || table->procname; table++) {
1792 table->parent = parent;
1793 if (table->child)
1794 sysctl_set_parent(table, table->child);
1795 }
1796}
1797
1798static __init int sysctl_init(void)
1799{
1800 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001801#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1802 {
1803 int err;
1804 err = sysctl_check_table(current->nsproxy, root_table);
1805 }
1806#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001807 return 0;
1808}
1809
1810core_initcall(sysctl_init);
1811
Al Virobfbcf032008-07-27 06:31:22 +01001812static struct ctl_table *is_branch_in(struct ctl_table *branch,
1813 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001814{
1815 struct ctl_table *p;
1816 const char *s = branch->procname;
1817
1818 /* branch should have named subdirectory as its first element */
1819 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001820 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001821
1822 /* ... and nothing else */
1823 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001824 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001825
1826 /* table should contain subdirectory with the same name */
1827 for (p = table; p->procname || p->ctl_name; p++) {
1828 if (!p->child)
1829 continue;
1830 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001831 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001832 }
Al Virobfbcf032008-07-27 06:31:22 +01001833 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001834}
1835
1836/* see if attaching q to p would be an improvement */
1837static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1838{
1839 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001840 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001841 int is_better = 0;
1842 int not_in_parent = !p->attached_by;
1843
Al Virobfbcf032008-07-27 06:31:22 +01001844 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001845 if (by == q->attached_by)
1846 is_better = 1;
1847 if (to == p->attached_by)
1848 not_in_parent = 1;
1849 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001850 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001851 }
1852
1853 if (is_better && not_in_parent) {
1854 q->attached_by = by;
1855 q->attached_to = to;
1856 q->parent = p;
1857 }
1858}
1859
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001861 * __register_sysctl_paths - register a sysctl hierarchy
1862 * @root: List of sysctl headers to register on
1863 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001864 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 *
1867 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001868 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001870 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 *
1872 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1873 * must be unique within that level of sysctl
1874 *
1875 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1876 * enter a sysctl file
1877 *
1878 * data - a pointer to data for use by proc_handler
1879 *
1880 * maxlen - the maximum size in bytes of the data
1881 *
1882 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1883 *
1884 * child - a pointer to the child sysctl table if this entry is a directory, or
1885 * %NULL.
1886 *
1887 * proc_handler - the text handler routine (described below)
1888 *
1889 * strategy - the strategy routine (described below)
1890 *
1891 * de - for internal use by the sysctl routines
1892 *
1893 * extra1, extra2 - extra pointers usable by the proc handler routines
1894 *
1895 * Leaf nodes in the sysctl tree will be represented by a single file
1896 * under /proc; non-leaf nodes will be represented by directories.
1897 *
1898 * sysctl(2) can automatically manage read and write requests through
1899 * the sysctl table. The data and maxlen fields of the ctl_table
1900 * struct enable minimal validation of the values being written to be
1901 * performed, and the mode field allows minimal authentication.
1902 *
1903 * More sophisticated management can be enabled by the provision of a
1904 * strategy routine with the table entry. This will be called before
1905 * any automatic read or write of the data is performed.
1906 *
1907 * The strategy routine may return
1908 *
1909 * < 0 - Error occurred (error is passed to user process)
1910 *
1911 * 0 - OK - proceed with automatic read or write.
1912 *
1913 * > 0 - OK - read or write has been done by the strategy routine, so
1914 * return immediately.
1915 *
1916 * There must be a proc_handler routine for any terminal nodes
1917 * mirrored under /proc/sys (non-terminals are handled by a built-in
1918 * directory handler). Several default handlers are available to
1919 * cover common cases -
1920 *
1921 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1922 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1923 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1924 *
1925 * It is the handler's job to read the input buffer from user memory
1926 * and process it. The handler should return 0 on success.
1927 *
1928 * This routine returns %NULL on a failure to register, and a pointer
1929 * to the table header on success.
1930 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001931struct ctl_table_header *__register_sysctl_paths(
1932 struct ctl_table_root *root,
1933 struct nsproxy *namespaces,
1934 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001936 struct ctl_table_header *header;
1937 struct ctl_table *new, **prevp;
1938 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001939 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001940
1941 /* Count the path components */
1942 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1943 ;
1944
1945 /*
1946 * For each path component, allocate a 2-element ctl_table array.
1947 * The first array element will be filled with the sysctl entry
1948 * for this, the second will be the sentinel (ctl_name == 0).
1949 *
1950 * We allocate everything in one go so that we don't have to
1951 * worry about freeing additional memory in unregister_sysctl_table.
1952 */
1953 header = kzalloc(sizeof(struct ctl_table_header) +
1954 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1955 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001957
1958 new = (struct ctl_table *) (header + 1);
1959
1960 /* Now connect the dots */
1961 prevp = &header->ctl_table;
1962 for (n = 0; n < npath; ++n, ++path) {
1963 /* Copy the procname */
1964 new->procname = path->procname;
1965 new->ctl_name = path->ctl_name;
1966 new->mode = 0555;
1967
1968 *prevp = new;
1969 prevp = &new->child;
1970
1971 new += 2;
1972 }
1973 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001974 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001975
1976 INIT_LIST_HEAD(&header->ctl_entry);
1977 header->used = 0;
1978 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001979 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001980 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001981 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001982#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001983 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001984 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001985 return NULL;
1986 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001987#endif
Al Viro330d57f2005-11-04 10:18:40 +00001988 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001989 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001990 header->attached_by = header->ctl_table;
1991 header->attached_to = root_table;
1992 header->parent = &root_table_header;
1993 for (set = header->set; set; set = set->parent) {
1994 struct ctl_table_header *p;
1995 list_for_each_entry(p, &set->list, ctl_entry) {
1996 if (p->unregistering)
1997 continue;
1998 try_attach(p, header);
1999 }
2000 }
2001 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002002 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002003 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002004
2005 return header;
2006}
2007
2008/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002009 * register_sysctl_table_path - register a sysctl table hierarchy
2010 * @path: The path to the directory the sysctl table is in.
2011 * @table: the top-level table structure
2012 *
2013 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2014 * array. A completely 0 filled entry terminates the table.
2015 *
2016 * See __register_sysctl_paths for more details.
2017 */
2018struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2019 struct ctl_table *table)
2020{
2021 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2022 path, table);
2023}
2024
2025/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002026 * register_sysctl_table - register a sysctl table hierarchy
2027 * @table: the top-level table structure
2028 *
2029 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2030 * array. A completely 0 filled entry terminates the table.
2031 *
2032 * See register_sysctl_paths for more details.
2033 */
2034struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2035{
2036 static const struct ctl_path null_path[] = { {} };
2037
2038 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039}
2040
2041/**
2042 * unregister_sysctl_table - unregister a sysctl table hierarchy
2043 * @header: the header returned from register_sysctl_table
2044 *
2045 * Unregisters the sysctl table and all children. proc entries may not
2046 * actually be removed until they are no longer used by anyone.
2047 */
2048void unregister_sysctl_table(struct ctl_table_header * header)
2049{
Al Viro330d57f2005-11-04 10:18:40 +00002050 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002051
2052 if (header == NULL)
2053 return;
2054
Al Viro330d57f2005-11-04 10:18:40 +00002055 spin_lock(&sysctl_lock);
2056 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002057 if (!--header->parent->count) {
2058 WARN_ON(1);
2059 kfree(header->parent);
2060 }
Al Virof7e6ced2008-07-15 01:44:23 -04002061 if (!--header->count)
2062 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002063 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064}
2065
Al Viro90434762008-07-15 08:54:06 -04002066int sysctl_is_seen(struct ctl_table_header *p)
2067{
2068 struct ctl_table_set *set = p->set;
2069 int res;
2070 spin_lock(&sysctl_lock);
2071 if (p->unregistering)
2072 res = 0;
2073 else if (!set->is_seen)
2074 res = 1;
2075 else
2076 res = set->is_seen(set);
2077 spin_unlock(&sysctl_lock);
2078 return res;
2079}
2080
Al Viro73455092008-07-14 21:22:20 -04002081void setup_sysctl_set(struct ctl_table_set *p,
2082 struct ctl_table_set *parent,
2083 int (*is_seen)(struct ctl_table_set *))
2084{
2085 INIT_LIST_HEAD(&p->list);
2086 p->parent = parent ? parent : &sysctl_table_root.default_set;
2087 p->is_seen = is_seen;
2088}
2089
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002090#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002091struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002092{
2093 return NULL;
2094}
2095
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002096struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2097 struct ctl_table *table)
2098{
2099 return NULL;
2100}
2101
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002102void unregister_sysctl_table(struct ctl_table_header * table)
2103{
2104}
2105
Al Viro73455092008-07-14 21:22:20 -04002106void setup_sysctl_set(struct ctl_table_set *p,
2107 struct ctl_table_set *parent,
2108 int (*is_seen)(struct ctl_table_set *))
2109{
2110}
2111
Al Virof7e6ced2008-07-15 01:44:23 -04002112void sysctl_head_put(struct ctl_table_header *head)
2113{
2114}
2115
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002116#endif /* CONFIG_SYSCTL */
2117
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118/*
2119 * /proc/sys support
2120 */
2121
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002122#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002124static int _proc_do_string(void* data, int maxlen, int write,
2125 struct file *filp, void __user *buffer,
2126 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002127{
2128 size_t len;
2129 char __user *p;
2130 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002131
2132 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002133 *lenp = 0;
2134 return 0;
2135 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002136
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002137 if (write) {
2138 len = 0;
2139 p = buffer;
2140 while (len < *lenp) {
2141 if (get_user(c, p++))
2142 return -EFAULT;
2143 if (c == 0 || c == '\n')
2144 break;
2145 len++;
2146 }
2147 if (len >= maxlen)
2148 len = maxlen-1;
2149 if(copy_from_user(data, buffer, len))
2150 return -EFAULT;
2151 ((char *) data)[len] = 0;
2152 *ppos += *lenp;
2153 } else {
2154 len = strlen(data);
2155 if (len > maxlen)
2156 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002157
2158 if (*ppos > len) {
2159 *lenp = 0;
2160 return 0;
2161 }
2162
2163 data += *ppos;
2164 len -= *ppos;
2165
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002166 if (len > *lenp)
2167 len = *lenp;
2168 if (len)
2169 if(copy_to_user(buffer, data, len))
2170 return -EFAULT;
2171 if (len < *lenp) {
2172 if(put_user('\n', ((char __user *) buffer) + len))
2173 return -EFAULT;
2174 len++;
2175 }
2176 *lenp = len;
2177 *ppos += len;
2178 }
2179 return 0;
2180}
2181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182/**
2183 * proc_dostring - read a string sysctl
2184 * @table: the sysctl table
2185 * @write: %TRUE if this is a write to the sysctl file
2186 * @filp: the file structure
2187 * @buffer: the user buffer
2188 * @lenp: the size of the user buffer
2189 * @ppos: file position
2190 *
2191 * Reads/writes a string from/to the user buffer. If the kernel
2192 * buffer provided is not large enough to hold the string, the
2193 * string is truncated. The copied string is %NULL-terminated.
2194 * If the string is being read by the user process, it is copied
2195 * and a newline '\n' is added. It is truncated if the buffer is
2196 * not large enough.
2197 *
2198 * Returns 0 on success.
2199 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002200int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 void __user *buffer, size_t *lenp, loff_t *ppos)
2202{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002203 return _proc_do_string(table->data, table->maxlen, write, filp,
2204 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205}
2206
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
2208static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2209 int *valp,
2210 int write, void *data)
2211{
2212 if (write) {
2213 *valp = *negp ? -*lvalp : *lvalp;
2214 } else {
2215 int val = *valp;
2216 if (val < 0) {
2217 *negp = -1;
2218 *lvalp = (unsigned long)-val;
2219 } else {
2220 *negp = 0;
2221 *lvalp = (unsigned long)val;
2222 }
2223 }
2224 return 0;
2225}
2226
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002227static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002228 int write, struct file *filp, void __user *buffer,
2229 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2231 int write, void *data),
2232 void *data)
2233{
2234#define TMPBUFLEN 21
2235 int *i, vleft, first=1, neg, val;
2236 unsigned long lval;
2237 size_t left, len;
2238
2239 char buf[TMPBUFLEN], *p;
2240 char __user *s = buffer;
2241
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002242 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 (*ppos && !write)) {
2244 *lenp = 0;
2245 return 0;
2246 }
2247
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002248 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 vleft = table->maxlen / sizeof(*i);
2250 left = *lenp;
2251
2252 if (!conv)
2253 conv = do_proc_dointvec_conv;
2254
2255 for (; left && vleft--; i++, first=0) {
2256 if (write) {
2257 while (left) {
2258 char c;
2259 if (get_user(c, s))
2260 return -EFAULT;
2261 if (!isspace(c))
2262 break;
2263 left--;
2264 s++;
2265 }
2266 if (!left)
2267 break;
2268 neg = 0;
2269 len = left;
2270 if (len > sizeof(buf) - 1)
2271 len = sizeof(buf) - 1;
2272 if (copy_from_user(buf, s, len))
2273 return -EFAULT;
2274 buf[len] = 0;
2275 p = buf;
2276 if (*p == '-' && left > 1) {
2277 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002278 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 }
2280 if (*p < '0' || *p > '9')
2281 break;
2282
2283 lval = simple_strtoul(p, &p, 0);
2284
2285 len = p-buf;
2286 if ((len < left) && *p && !isspace(*p))
2287 break;
2288 if (neg)
2289 val = -val;
2290 s += len;
2291 left -= len;
2292
2293 if (conv(&neg, &lval, i, 1, data))
2294 break;
2295 } else {
2296 p = buf;
2297 if (!first)
2298 *p++ = '\t';
2299
2300 if (conv(&neg, &lval, i, 0, data))
2301 break;
2302
2303 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2304 len = strlen(buf);
2305 if (len > left)
2306 len = left;
2307 if(copy_to_user(s, buf, len))
2308 return -EFAULT;
2309 left -= len;
2310 s += len;
2311 }
2312 }
2313
2314 if (!write && !first && left) {
2315 if(put_user('\n', s))
2316 return -EFAULT;
2317 left--, s++;
2318 }
2319 if (write) {
2320 while (left) {
2321 char c;
2322 if (get_user(c, s++))
2323 return -EFAULT;
2324 if (!isspace(c))
2325 break;
2326 left--;
2327 }
2328 }
2329 if (write && first)
2330 return -EINVAL;
2331 *lenp -= left;
2332 *ppos += *lenp;
2333 return 0;
2334#undef TMPBUFLEN
2335}
2336
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002337static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002338 void __user *buffer, size_t *lenp, loff_t *ppos,
2339 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2340 int write, void *data),
2341 void *data)
2342{
2343 return __do_proc_dointvec(table->data, table, write, filp,
2344 buffer, lenp, ppos, conv, data);
2345}
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347/**
2348 * proc_dointvec - read a vector of integers
2349 * @table: the sysctl table
2350 * @write: %TRUE if this is a write to the sysctl file
2351 * @filp: the file structure
2352 * @buffer: the user buffer
2353 * @lenp: the size of the user buffer
2354 * @ppos: file position
2355 *
2356 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2357 * values from/to the user buffer, treated as an ASCII string.
2358 *
2359 * Returns 0 on success.
2360 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002361int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 void __user *buffer, size_t *lenp, loff_t *ppos)
2363{
2364 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2365 NULL,NULL);
2366}
2367
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002368/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002369 * Taint values can only be increased
2370 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002371 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002372static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002373 void __user *buffer, size_t *lenp, loff_t *ppos)
2374{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002375 struct ctl_table t;
2376 unsigned long tmptaint = get_taint();
2377 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002378
Bastian Blank91fcd412007-04-23 14:41:14 -07002379 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002380 return -EPERM;
2381
Andi Kleen25ddbb12008-10-15 22:01:41 -07002382 t = *table;
2383 t.data = &tmptaint;
2384 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2385 if (err < 0)
2386 return err;
2387
2388 if (write) {
2389 /*
2390 * Poor man's atomic or. Not worth adding a primitive
2391 * to everyone's atomic.h for this
2392 */
2393 int i;
2394 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2395 if ((tmptaint >> i) & 1)
2396 add_taint(i);
2397 }
2398 }
2399
2400 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002401}
2402
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403struct do_proc_dointvec_minmax_conv_param {
2404 int *min;
2405 int *max;
2406};
2407
2408static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2409 int *valp,
2410 int write, void *data)
2411{
2412 struct do_proc_dointvec_minmax_conv_param *param = data;
2413 if (write) {
2414 int val = *negp ? -*lvalp : *lvalp;
2415 if ((param->min && *param->min > val) ||
2416 (param->max && *param->max < val))
2417 return -EINVAL;
2418 *valp = val;
2419 } else {
2420 int val = *valp;
2421 if (val < 0) {
2422 *negp = -1;
2423 *lvalp = (unsigned long)-val;
2424 } else {
2425 *negp = 0;
2426 *lvalp = (unsigned long)val;
2427 }
2428 }
2429 return 0;
2430}
2431
2432/**
2433 * proc_dointvec_minmax - read a vector of integers with min/max values
2434 * @table: the sysctl table
2435 * @write: %TRUE if this is a write to the sysctl file
2436 * @filp: the file structure
2437 * @buffer: the user buffer
2438 * @lenp: the size of the user buffer
2439 * @ppos: file position
2440 *
2441 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2442 * values from/to the user buffer, treated as an ASCII string.
2443 *
2444 * This routine will ensure the values are within the range specified by
2445 * table->extra1 (min) and table->extra2 (max).
2446 *
2447 * Returns 0 on success.
2448 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002449int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 void __user *buffer, size_t *lenp, loff_t *ppos)
2451{
2452 struct do_proc_dointvec_minmax_conv_param param = {
2453 .min = (int *) table->extra1,
2454 .max = (int *) table->extra2,
2455 };
2456 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2457 do_proc_dointvec_minmax_conv, &param);
2458}
2459
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002460static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 struct file *filp,
2462 void __user *buffer,
2463 size_t *lenp, loff_t *ppos,
2464 unsigned long convmul,
2465 unsigned long convdiv)
2466{
2467#define TMPBUFLEN 21
2468 unsigned long *i, *min, *max, val;
2469 int vleft, first=1, neg;
2470 size_t len, left;
2471 char buf[TMPBUFLEN], *p;
2472 char __user *s = buffer;
2473
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002474 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 (*ppos && !write)) {
2476 *lenp = 0;
2477 return 0;
2478 }
2479
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002480 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 min = (unsigned long *) table->extra1;
2482 max = (unsigned long *) table->extra2;
2483 vleft = table->maxlen / sizeof(unsigned long);
2484 left = *lenp;
2485
2486 for (; left && vleft--; i++, min++, max++, first=0) {
2487 if (write) {
2488 while (left) {
2489 char c;
2490 if (get_user(c, s))
2491 return -EFAULT;
2492 if (!isspace(c))
2493 break;
2494 left--;
2495 s++;
2496 }
2497 if (!left)
2498 break;
2499 neg = 0;
2500 len = left;
2501 if (len > TMPBUFLEN-1)
2502 len = TMPBUFLEN-1;
2503 if (copy_from_user(buf, s, len))
2504 return -EFAULT;
2505 buf[len] = 0;
2506 p = buf;
2507 if (*p == '-' && left > 1) {
2508 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002509 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 }
2511 if (*p < '0' || *p > '9')
2512 break;
2513 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2514 len = p-buf;
2515 if ((len < left) && *p && !isspace(*p))
2516 break;
2517 if (neg)
2518 val = -val;
2519 s += len;
2520 left -= len;
2521
2522 if(neg)
2523 continue;
2524 if ((min && val < *min) || (max && val > *max))
2525 continue;
2526 *i = val;
2527 } else {
2528 p = buf;
2529 if (!first)
2530 *p++ = '\t';
2531 sprintf(p, "%lu", convdiv * (*i) / convmul);
2532 len = strlen(buf);
2533 if (len > left)
2534 len = left;
2535 if(copy_to_user(s, buf, len))
2536 return -EFAULT;
2537 left -= len;
2538 s += len;
2539 }
2540 }
2541
2542 if (!write && !first && left) {
2543 if(put_user('\n', s))
2544 return -EFAULT;
2545 left--, s++;
2546 }
2547 if (write) {
2548 while (left) {
2549 char c;
2550 if (get_user(c, s++))
2551 return -EFAULT;
2552 if (!isspace(c))
2553 break;
2554 left--;
2555 }
2556 }
2557 if (write && first)
2558 return -EINVAL;
2559 *lenp -= left;
2560 *ppos += *lenp;
2561 return 0;
2562#undef TMPBUFLEN
2563}
2564
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002565static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002566 struct file *filp,
2567 void __user *buffer,
2568 size_t *lenp, loff_t *ppos,
2569 unsigned long convmul,
2570 unsigned long convdiv)
2571{
2572 return __do_proc_doulongvec_minmax(table->data, table, write,
2573 filp, buffer, lenp, ppos, convmul, convdiv);
2574}
2575
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576/**
2577 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2578 * @table: the sysctl table
2579 * @write: %TRUE if this is a write to the sysctl file
2580 * @filp: the file structure
2581 * @buffer: the user buffer
2582 * @lenp: the size of the user buffer
2583 * @ppos: file position
2584 *
2585 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2586 * values from/to the user buffer, treated as an ASCII string.
2587 *
2588 * This routine will ensure the values are within the range specified by
2589 * table->extra1 (min) and table->extra2 (max).
2590 *
2591 * Returns 0 on success.
2592 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002593int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 void __user *buffer, size_t *lenp, loff_t *ppos)
2595{
2596 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2597}
2598
2599/**
2600 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values 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. The values
2610 * are treated as milliseconds, and converted to jiffies when they are stored.
2611 *
2612 * This routine will ensure the values are within the range specified by
2613 * table->extra1 (min) and table->extra2 (max).
2614 *
2615 * Returns 0 on success.
2616 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002617int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 struct file *filp,
2619 void __user *buffer,
2620 size_t *lenp, loff_t *ppos)
2621{
2622 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2623 lenp, ppos, HZ, 1000l);
2624}
2625
2626
2627static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2628 int *valp,
2629 int write, void *data)
2630{
2631 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002632 if (*lvalp > LONG_MAX / HZ)
2633 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2635 } else {
2636 int val = *valp;
2637 unsigned long lval;
2638 if (val < 0) {
2639 *negp = -1;
2640 lval = (unsigned long)-val;
2641 } else {
2642 *negp = 0;
2643 lval = (unsigned long)val;
2644 }
2645 *lvalp = lval / HZ;
2646 }
2647 return 0;
2648}
2649
2650static int do_proc_dointvec_userhz_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 (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2656 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
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 = jiffies_to_clock_t(lval);
2669 }
2670 return 0;
2671}
2672
2673static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2674 int *valp,
2675 int write, void *data)
2676{
2677 if (write) {
2678 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2679 } else {
2680 int val = *valp;
2681 unsigned long lval;
2682 if (val < 0) {
2683 *negp = -1;
2684 lval = (unsigned long)-val;
2685 } else {
2686 *negp = 0;
2687 lval = (unsigned long)val;
2688 }
2689 *lvalp = jiffies_to_msecs(lval);
2690 }
2691 return 0;
2692}
2693
2694/**
2695 * proc_dointvec_jiffies - read a vector of integers as seconds
2696 * @table: the sysctl table
2697 * @write: %TRUE if this is a write to the sysctl file
2698 * @filp: the file structure
2699 * @buffer: the user buffer
2700 * @lenp: the size of the user buffer
2701 * @ppos: file position
2702 *
2703 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2704 * values from/to the user buffer, treated as an ASCII string.
2705 * The values read are assumed to be in seconds, and are converted into
2706 * jiffies.
2707 *
2708 * Returns 0 on success.
2709 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002710int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 void __user *buffer, size_t *lenp, loff_t *ppos)
2712{
2713 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2714 do_proc_dointvec_jiffies_conv,NULL);
2715}
2716
2717/**
2718 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2719 * @table: the sysctl table
2720 * @write: %TRUE if this is a write to the sysctl file
2721 * @filp: the file structure
2722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002724 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 *
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 1/USER_HZ seconds, and
2729 * are converted into jiffies.
2730 *
2731 * Returns 0 on success.
2732 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002733int proc_dointvec_userhz_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_userhz_jiffies_conv,NULL);
2738}
2739
2740/**
2741 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
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
Martin Waitz67be2dd2005-05-01 08:59:26 -07002747 * @ppos: file position
2748 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 *
2750 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2751 * values from/to the user buffer, treated as an ASCII string.
2752 * The values read are assumed to be in 1/1000 seconds, and
2753 * are converted into jiffies.
2754 *
2755 * Returns 0 on success.
2756 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002757int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 void __user *buffer, size_t *lenp, loff_t *ppos)
2759{
2760 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2761 do_proc_dointvec_ms_jiffies_conv, NULL);
2762}
2763
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002764static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002765 void __user *buffer, size_t *lenp, loff_t *ppos)
2766{
2767 struct pid *new_pid;
2768 pid_t tmp;
2769 int r;
2770
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002771 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002772
2773 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2774 lenp, ppos, NULL, NULL);
2775 if (r || !write)
2776 return r;
2777
2778 new_pid = find_get_pid(tmp);
2779 if (!new_pid)
2780 return -ESRCH;
2781
2782 put_pid(xchg(&cad_pid, new_pid));
2783 return 0;
2784}
2785
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786#else /* CONFIG_PROC_FS */
2787
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002788int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 void __user *buffer, size_t *lenp, loff_t *ppos)
2790{
2791 return -ENOSYS;
2792}
2793
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002794int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 void __user *buffer, size_t *lenp, loff_t *ppos)
2796{
2797 return -ENOSYS;
2798}
2799
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002800int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 void __user *buffer, size_t *lenp, loff_t *ppos)
2802{
2803 return -ENOSYS;
2804}
2805
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002806int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 void __user *buffer, size_t *lenp, loff_t *ppos)
2808{
2809 return -ENOSYS;
2810}
2811
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002812int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 void __user *buffer, size_t *lenp, loff_t *ppos)
2814{
2815 return -ENOSYS;
2816}
2817
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002818int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 void __user *buffer, size_t *lenp, loff_t *ppos)
2820{
2821 return -ENOSYS;
2822}
2823
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002824int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 void __user *buffer, size_t *lenp, loff_t *ppos)
2826{
2827 return -ENOSYS;
2828}
2829
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002830int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 struct file *filp,
2832 void __user *buffer,
2833 size_t *lenp, loff_t *ppos)
2834{
2835 return -ENOSYS;
2836}
2837
2838
2839#endif /* CONFIG_PROC_FS */
2840
2841
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002842#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843/*
2844 * General sysctl support routines
2845 */
2846
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002847/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002848int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002849 void __user *oldval, size_t __user *oldlenp,
2850 void __user *newval, size_t newlen)
2851{
2852 size_t len;
2853
2854 /* Get out of I don't have a variable */
2855 if (!table->data || !table->maxlen)
2856 return -ENOTDIR;
2857
2858 if (oldval && oldlenp) {
2859 if (get_user(len, oldlenp))
2860 return -EFAULT;
2861 if (len) {
2862 if (len > table->maxlen)
2863 len = table->maxlen;
2864 if (copy_to_user(oldval, table->data, len))
2865 return -EFAULT;
2866 if (put_user(len, oldlenp))
2867 return -EFAULT;
2868 }
2869 }
2870
2871 if (newval && newlen) {
2872 if (newlen > table->maxlen)
2873 newlen = table->maxlen;
2874
2875 if (copy_from_user(table->data, newval, newlen))
2876 return -EFAULT;
2877 }
2878 return 1;
2879}
2880
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002882int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002884 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 if (!table->data || !table->maxlen)
2887 return -ENOTDIR;
2888
2889 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002890 size_t bufsize;
2891 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002893 if (bufsize) {
2894 size_t len = strlen(table->data), copied;
2895
2896 /* This shouldn't trigger for a well-formed sysctl */
2897 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002899
2900 /* Copy up to a max of bufsize-1 bytes of the string */
2901 copied = (len >= bufsize) ? bufsize - 1 : len;
2902
2903 if (copy_to_user(oldval, table->data, copied) ||
2904 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002906 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 return -EFAULT;
2908 }
2909 }
2910 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002911 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 if (len > table->maxlen)
2913 len = table->maxlen;
2914 if(copy_from_user(table->data, newval, len))
2915 return -EFAULT;
2916 if (len == table->maxlen)
2917 len--;
2918 ((char *) table->data)[len] = 0;
2919 }
Yi Yang82c9df82005-12-30 16:37:10 +08002920 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921}
2922
2923/*
2924 * This function makes sure that all of the integers in the vector
2925 * are between the minimum and maximum values given in the arrays
2926 * table->extra1 and table->extra2, respectively.
2927 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002928int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002930 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931{
2932
2933 if (newval && newlen) {
2934 int __user *vec = (int __user *) newval;
2935 int *min = (int *) table->extra1;
2936 int *max = (int *) table->extra2;
2937 size_t length;
2938 int i;
2939
2940 if (newlen % sizeof(int) != 0)
2941 return -EINVAL;
2942
2943 if (!table->extra1 && !table->extra2)
2944 return 0;
2945
2946 if (newlen > table->maxlen)
2947 newlen = table->maxlen;
2948 length = newlen / sizeof(int);
2949
2950 for (i = 0; i < length; i++) {
2951 int value;
2952 if (get_user(value, vec + i))
2953 return -EFAULT;
2954 if (min && value < min[i])
2955 return -EINVAL;
2956 if (max && value > max[i])
2957 return -EINVAL;
2958 }
2959 }
2960 return 0;
2961}
2962
2963/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002964int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002966 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002968 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002970
2971 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002973 if (olen) {
2974 int val;
2975
2976 if (olen < sizeof(int))
2977 return -EINVAL;
2978
2979 val = *(int *)(table->data) / HZ;
2980 if (put_user(val, (int __user *)oldval))
2981 return -EFAULT;
2982 if (put_user(sizeof(int), oldlenp))
2983 return -EFAULT;
2984 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 }
2986 if (newval && newlen) {
2987 int new;
2988 if (newlen != sizeof(int))
2989 return -EINVAL;
2990 if (get_user(new, (int __user *)newval))
2991 return -EFAULT;
2992 *(int *)(table->data) = new*HZ;
2993 }
2994 return 1;
2995}
2996
2997/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002998int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003000 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003002 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003004
3005 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003007 if (olen) {
3008 int val;
3009
3010 if (olen < sizeof(int))
3011 return -EINVAL;
3012
3013 val = jiffies_to_msecs(*(int *)(table->data));
3014 if (put_user(val, (int __user *)oldval))
3015 return -EFAULT;
3016 if (put_user(sizeof(int), oldlenp))
3017 return -EFAULT;
3018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 }
3020 if (newval && newlen) {
3021 int new;
3022 if (newlen != sizeof(int))
3023 return -EINVAL;
3024 if (get_user(new, (int __user *)newval))
3025 return -EFAULT;
3026 *(int *)(table->data) = msecs_to_jiffies(new);
3027 }
3028 return 1;
3029}
3030
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003031
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003032
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003033#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034
3035
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003036SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003038 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003039 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003040
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003041 if (copy_from_user(&tmp, args, sizeof(tmp)))
3042 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003043
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003044 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003045
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003046 /* If no error reading the parameters then just -ENOSYS ... */
3047 if (!error)
3048 error = -ENOSYS;
3049
3050 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051}
3052
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003053int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003054 void __user *oldval, size_t __user *oldlenp,
3055 void __user *newval, size_t newlen)
3056{
3057 return -ENOSYS;
3058}
3059
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003060int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003062 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063{
3064 return -ENOSYS;
3065}
3066
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003067int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003069 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070{
3071 return -ENOSYS;
3072}
3073
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003074int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003076 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077{
3078 return -ENOSYS;
3079}
3080
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003081int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003083 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084{
3085 return -ENOSYS;
3086}
3087
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003088#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003090static int deprecated_sysctl_warning(struct __sysctl_args *args)
3091{
3092 static int msg_count;
3093 int name[CTL_MAXNAME];
3094 int i;
3095
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003096 /* Check args->nlen. */
3097 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3098 return -ENOTDIR;
3099
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003100 /* Read in the sysctl name for better debug message logging */
3101 for (i = 0; i < args->nlen; i++)
3102 if (get_user(name[i], args->name + i))
3103 return -EFAULT;
3104
3105 /* Ignore accesses to kernel.version */
3106 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3107 return 0;
3108
3109 if (msg_count < 5) {
3110 msg_count++;
3111 printk(KERN_INFO
3112 "warning: process `%s' used the deprecated sysctl "
3113 "system call with ", current->comm);
3114 for (i = 0; i < args->nlen; i++)
3115 printk("%d.", name[i]);
3116 printk("\n");
3117 }
3118 return 0;
3119}
3120
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121/*
3122 * No sense putting this after each symbol definition, twice,
3123 * exception granted :-)
3124 */
3125EXPORT_SYMBOL(proc_dointvec);
3126EXPORT_SYMBOL(proc_dointvec_jiffies);
3127EXPORT_SYMBOL(proc_dointvec_minmax);
3128EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3129EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3130EXPORT_SYMBOL(proc_dostring);
3131EXPORT_SYMBOL(proc_doulongvec_minmax);
3132EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3133EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003134EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135EXPORT_SYMBOL(sysctl_intvec);
3136EXPORT_SYMBOL(sysctl_jiffies);
3137EXPORT_SYMBOL(sysctl_ms_jiffies);
3138EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003139EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140EXPORT_SYMBOL(unregister_sysctl_table);