blob: 6d2aeff92b3de7bc3090a1edfda60620ba1867d1 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include <asm/uaccess.h>
53#include <asm/processor.h>
54
Andi Kleen29cbc782006-09-30 01:47:55 +020055#ifdef CONFIG_X86
56#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010057#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010058#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020059#endif
60
Eric W. Biederman7058cb02007-10-18 03:05:58 -070061static int deprecated_sysctl_warning(struct __sysctl_args *args);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#if defined(CONFIG_SYSCTL)
64
65/* External variables not in a header file. */
66extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070067extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int sysctl_overcommit_memory;
69extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070070extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070071extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080072extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070075extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max;
78extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080080extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080081extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020082extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010083extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040084extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000085#ifndef CONFIG_MMU
86extern int sysctl_nr_trim_pages;
87#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070088#ifdef CONFIG_RCU_TORTURE_TEST
89extern int rcutorture_runnable;
90#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092/* Constants used for minimum and maximum */
Ingo Molnar9f8d9792009-02-12 13:10:17 +010093#if defined(CONFIG_DETECT_HUNG_TASK) || defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
94static int one = 1;
95#endif
Bron Gondwana195cf452008-02-04 22:29:20 -080096#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020098static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099#endif
100
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +0200101#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700102static int two = 2;
103#endif
104
105static int zero;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800106static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700107static int one_hundred = 100;
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110static int maxolduid = 65535;
111static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800112static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static int ngroups_max = NGROUPS_MAX;
115
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200116#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117extern char modprobe_path[];
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#ifdef CONFIG_CHR_DEV_SG
120extern int sg_big_buff;
121#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
David S. Miller72c57ed2008-09-11 23:29:54 -0700123#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700124#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#endif
126
David S. Miller08714202008-11-16 23:49:24 -0800127#ifdef CONFIG_SPARC64
128extern int sysctl_tsb_ratio;
129#endif
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#ifdef __hppa__
132extern int pwrsw_enabled;
133extern int unaligned_enabled;
134#endif
135
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800136#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef CONFIG_MATHEMU
138extern int sysctl_ieee_emulation_warnings;
139#endif
140extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700141extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef CONFIG_BSD_PROCESS_ACCT
145extern int acct_parm[];
146#endif
147
Jes Sorensend2b176e2006-02-28 09:42:23 -0800148#ifdef CONFIG_IA64
149extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800150extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800151#endif
152
Ingo Molnar23f78d42006-06-27 02:54:53 -0700153#ifdef CONFIG_RT_MUTEXES
154extern int max_lock_depth;
155#endif
156
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700159 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700160static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800161 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700162#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700163
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700164static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100165static struct ctl_table_root sysctl_table_root;
166static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100167 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400169 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100170 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400171 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100172};
173static struct ctl_table_root sysctl_table_root = {
174 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400175 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700178static struct ctl_table kern_table[];
179static struct ctl_table vm_table[];
180static struct ctl_table fs_table[];
181static struct ctl_table debug_table[];
182static struct ctl_table dev_table[];
183extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700184#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700185extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400186#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800187#ifdef CONFIG_EPOLL
188extern struct ctl_table epoll_table[];
189#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
192int sysctl_legacy_va_layout;
193#endif
194
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700195extern int prove_locking;
196extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/* The default sysctl tables: */
199
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700200static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 {
202 .ctl_name = CTL_KERN,
203 .procname = "kernel",
204 .mode = 0555,
205 .child = kern_table,
206 },
207 {
208 .ctl_name = CTL_VM,
209 .procname = "vm",
210 .mode = 0555,
211 .child = vm_table,
212 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .ctl_name = CTL_FS,
215 .procname = "fs",
216 .mode = 0555,
217 .child = fs_table,
218 },
219 {
220 .ctl_name = CTL_DEBUG,
221 .procname = "debug",
222 .mode = 0555,
223 .child = debug_table,
224 },
225 {
226 .ctl_name = CTL_DEV,
227 .procname = "dev",
228 .mode = 0555,
229 .child = dev_table,
230 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700231/*
232 * NOTE: do not add new entries to this table unless you have read
233 * Documentation/sysctl/ctl_unnumbered.txt
234 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 { .ctl_name = 0 }
236};
237
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100239static int min_sched_granularity_ns = 100000; /* 100 usecs */
240static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
241static int min_wakeup_granularity_ns; /* 0 usecs */
242static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243#endif
244
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700245static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246#ifdef CONFIG_SCHED_DEBUG
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100249 .procname = "sched_min_granularity_ns",
250 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200260 .procname = "sched_latency_ns",
261 .data = &sysctl_sched_latency,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100264 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200265 .strategy = &sysctl_intvec,
266 .extra1 = &min_sched_granularity_ns,
267 .extra2 = &max_sched_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200271 .procname = "sched_wakeup_granularity_ns",
272 .data = &sysctl_sched_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200282 .procname = "sched_shares_ratelimit",
283 .data = &sysctl_sched_shares_ratelimit,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
287 },
288 {
289 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200290 .procname = "sched_shares_thresh",
291 .data = &sysctl_sched_shares_thresh,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
296 .extra1 = &zero,
297 },
298 {
299 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200300 .procname = "sched_child_runs_first",
301 .data = &sysctl_sched_child_runs_first,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200306 {
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_features",
309 .data = &sysctl_sched_features,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
313 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200314 {
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100322 {
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
329 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200330#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200331 {
332 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100333 .procname = "sched_rt_period_us",
334 .data = &sysctl_sched_rt_period,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200337 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100338 },
339 {
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_rt_runtime_us",
342 .data = &sysctl_sched_rt_runtime,
343 .maxlen = sizeof(int),
344 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200345 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100346 },
347 {
348 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200349 .procname = "sched_compat_yield",
350 .data = &sysctl_sched_compat_yield,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = &proc_dointvec,
354 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700355#ifdef CONFIG_PROVE_LOCKING
356 {
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
364#endif
365#ifdef CONFIG_LOCK_STAT
366 {
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "lock_stat",
369 .data = &lock_stat,
370 .maxlen = sizeof(int),
371 .mode = 0644,
372 .proc_handler = &proc_dointvec,
373 },
374#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .ctl_name = KERN_PANIC,
377 .procname = "panic",
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383 {
384 .ctl_name = KERN_CORE_USES_PID,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
391 {
392 .ctl_name = KERN_CORE_PATTERN,
393 .procname = "core_pattern",
394 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700395 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 .mode = 0644,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
399 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800400#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700403 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800404 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700405 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800407#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100408#ifdef CONFIG_LATENCYTOP
409 {
410 .procname = "latencytop",
411 .data = &latencytop_enabled,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = &proc_dointvec,
415 },
416#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#ifdef CONFIG_BLK_DEV_INITRD
418 {
419 .ctl_name = KERN_REALROOTDEV,
420 .procname = "real-root-dev",
421 .data = &real_root_dev,
422 .maxlen = sizeof(int),
423 .mode = 0644,
424 .proc_handler = &proc_dointvec,
425 },
426#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700427 {
428 .ctl_name = CTL_UNNUMBERED,
429 .procname = "print-fatal-signals",
430 .data = &print_fatal_signals,
431 .maxlen = sizeof(int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700435#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 {
437 .ctl_name = KERN_SPARC_REBOOT,
438 .procname = "reboot-cmd",
439 .data = reboot_command,
440 .maxlen = 256,
441 .mode = 0644,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
444 },
445 {
446 .ctl_name = KERN_SPARC_STOP_A,
447 .procname = "stop-a",
448 .data = &stop_a_enabled,
449 .maxlen = sizeof (int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec,
452 },
453 {
454 .ctl_name = KERN_SPARC_SCONS_PWROFF,
455 .procname = "scons-poweroff",
456 .data = &scons_pwroff,
457 .maxlen = sizeof (int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
460 },
461#endif
David S. Miller08714202008-11-16 23:49:24 -0800462#ifdef CONFIG_SPARC64
463 {
464 .ctl_name = CTL_UNNUMBERED,
465 .procname = "tsb-ratio",
466 .data = &sysctl_tsb_ratio,
467 .maxlen = sizeof (int),
468 .mode = 0644,
469 .proc_handler = &proc_dointvec,
470 },
471#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#ifdef __hppa__
473 {
474 .ctl_name = KERN_HPPA_PWRSW,
475 .procname = "soft-power",
476 .data = &pwrsw_enabled,
477 .maxlen = sizeof (int),
478 .mode = 0644,
479 .proc_handler = &proc_dointvec,
480 },
481 {
482 .ctl_name = KERN_HPPA_UNALIGNED,
483 .procname = "unaligned-trap",
484 .data = &unaligned_enabled,
485 .maxlen = sizeof (int),
486 .mode = 0644,
487 .proc_handler = &proc_dointvec,
488 },
489#endif
490 {
491 .ctl_name = KERN_CTLALTDEL,
492 .procname = "ctrl-alt-del",
493 .data = &C_A_D,
494 .maxlen = sizeof(int),
495 .mode = 0644,
496 .proc_handler = &proc_dointvec,
497 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400498#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200499 {
500 .ctl_name = CTL_UNNUMBERED,
501 .procname = "ftrace_enabled",
502 .data = &ftrace_enabled,
503 .maxlen = sizeof(int),
504 .mode = 0644,
505 .proc_handler = &ftrace_enable_sysctl,
506 },
507#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500508#ifdef CONFIG_STACK_TRACER
509 {
510 .ctl_name = CTL_UNNUMBERED,
511 .procname = "stack_tracer_enabled",
512 .data = &stack_tracer_enabled,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = &stack_trace_sysctl,
516 },
517#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400518#ifdef CONFIG_TRACING
519 {
520 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100521 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400522 .data = &ftrace_dump_on_oops,
523 .maxlen = sizeof(int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec,
526 },
527#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200528#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 {
530 .ctl_name = KERN_MODPROBE,
531 .procname = "modprobe",
532 .data = &modprobe_path,
533 .maxlen = KMOD_PATH_LEN,
534 .mode = 0644,
535 .proc_handler = &proc_dostring,
536 .strategy = &sysctl_string,
537 },
538#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700539#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
541 .ctl_name = KERN_HOTPLUG,
542 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100543 .data = &uevent_helper,
544 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .mode = 0644,
546 .proc_handler = &proc_dostring,
547 .strategy = &sysctl_string,
548 },
549#endif
550#ifdef CONFIG_CHR_DEV_SG
551 {
552 .ctl_name = KERN_SG_BIG_BUFF,
553 .procname = "sg-big-buff",
554 .data = &sg_big_buff,
555 .maxlen = sizeof (int),
556 .mode = 0444,
557 .proc_handler = &proc_dointvec,
558 },
559#endif
560#ifdef CONFIG_BSD_PROCESS_ACCT
561 {
562 .ctl_name = KERN_ACCT,
563 .procname = "acct",
564 .data = &acct_parm,
565 .maxlen = 3*sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#ifdef CONFIG_MAGIC_SYSRQ
571 {
572 .ctl_name = KERN_SYSRQ,
573 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800574 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .maxlen = sizeof (int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
578 },
579#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700580#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700583 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 .maxlen = sizeof (int),
585 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700586 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 {
590 .ctl_name = KERN_MAX_THREADS,
591 .procname = "threads-max",
592 .data = &max_threads,
593 .maxlen = sizeof(int),
594 .mode = 0644,
595 .proc_handler = &proc_dointvec,
596 },
597 {
598 .ctl_name = KERN_RANDOM,
599 .procname = "random",
600 .mode = 0555,
601 .child = random_table,
602 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 {
604 .ctl_name = KERN_OVERFLOWUID,
605 .procname = "overflowuid",
606 .data = &overflowuid,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec_minmax,
610 .strategy = &sysctl_intvec,
611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
613 },
614 {
615 .ctl_name = KERN_OVERFLOWGID,
616 .procname = "overflowgid",
617 .data = &overflowgid,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec_minmax,
621 .strategy = &sysctl_intvec,
622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
624 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800625#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#ifdef CONFIG_MATHEMU
627 {
628 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
629 .procname = "ieee_emulation_warnings",
630 .data = &sysctl_ieee_emulation_warnings,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
634 },
635#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 {
637 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
638 .procname = "userprocess_debug",
639 .data = &sysctl_userprocess_debug,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec,
643 },
644#endif
645 {
646 .ctl_name = KERN_PIDMAX,
647 .procname = "pid_max",
648 .data = &pid_max,
649 .maxlen = sizeof (int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec_minmax,
652 .strategy = sysctl_intvec,
653 .extra1 = &pid_max_min,
654 .extra2 = &pid_max_max,
655 },
656 {
657 .ctl_name = KERN_PANIC_ON_OOPS,
658 .procname = "panic_on_oops",
659 .data = &panic_on_oops,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800664#if defined CONFIG_PRINTK
665 {
666 .ctl_name = KERN_PRINTK,
667 .procname = "printk",
668 .data = &console_loglevel,
669 .maxlen = 4*sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 {
674 .ctl_name = KERN_PRINTK_RATELIMIT,
675 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700676 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec_jiffies,
680 .strategy = &sysctl_jiffies,
681 },
682 {
683 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
684 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700685 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec,
689 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800690#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 {
692 .ctl_name = KERN_NGROUPS_MAX,
693 .procname = "ngroups_max",
694 .data = &ngroups_max,
695 .maxlen = sizeof (int),
696 .mode = 0444,
697 .proc_handler = &proc_dointvec,
698 },
699#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
700 {
701 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
702 .procname = "unknown_nmi_panic",
703 .data = &unknown_nmi_panic,
704 .maxlen = sizeof (int),
705 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200706 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
Don Zickus407984f2006-09-26 10:52:27 +0200708 {
Don Zickus407984f2006-09-26 10:52:27 +0200709 .procname = "nmi_watchdog",
710 .data = &nmi_watchdog_enabled,
711 .maxlen = sizeof (int),
712 .mode = 0644,
713 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 },
715#endif
716#if defined(CONFIG_X86)
717 {
Don Zickus8da5add2006-09-26 10:52:27 +0200718 .ctl_name = KERN_PANIC_ON_NMI,
719 .procname = "panic_on_unrecovered_nmi",
720 .data = &panic_on_unrecovered_nmi,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec,
724 },
725 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .ctl_name = KERN_BOOTLOADER_TYPE,
727 .procname = "bootloader_type",
728 .data = &bootloader_type,
729 .maxlen = sizeof (int),
730 .mode = 0444,
731 .proc_handler = &proc_dointvec,
732 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100733 {
734 .ctl_name = CTL_UNNUMBERED,
735 .procname = "kstack_depth_to_print",
736 .data = &kstack_depth_to_print,
737 .maxlen = sizeof(int),
738 .mode = 0644,
739 .proc_handler = &proc_dointvec,
740 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100741 {
742 .ctl_name = CTL_UNNUMBERED,
743 .procname = "io_delay_type",
744 .data = &io_delay_type,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
748 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800750#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 {
752 .ctl_name = KERN_RANDOMIZE,
753 .procname = "randomize_va_space",
754 .data = &randomize_va_space,
755 .maxlen = sizeof(int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
758 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800759#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800760#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700761 {
762 .ctl_name = KERN_SPIN_RETRY,
763 .procname = "spin_retry",
764 .data = &spin_retry,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
768 },
769#endif
Len Brown673d5b42007-07-28 03:33:16 -0400770#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800771 {
Pavel Machekc255d842006-02-20 18:27:58 -0800772 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700773 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800774 .maxlen = sizeof (unsigned long),
775 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800776 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800777 },
778#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800779#ifdef CONFIG_IA64
780 {
781 .ctl_name = KERN_IA64_UNALIGNED,
782 .procname = "ignore-unaligned-usertrap",
783 .data = &no_unaligned_warning,
784 .maxlen = sizeof (int),
785 .mode = 0644,
786 .proc_handler = &proc_dointvec,
787 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800788 {
789 .ctl_name = CTL_UNNUMBERED,
790 .procname = "unaligned-dump-stack",
791 .data = &unaligned_dump_stack,
792 .maxlen = sizeof (int),
793 .mode = 0644,
794 .proc_handler = &proc_dointvec,
795 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800796#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700797#ifdef CONFIG_DETECT_SOFTLOCKUP
798 {
799 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200800 .procname = "softlockup_panic",
801 .data = &softlockup_panic,
802 .maxlen = sizeof(int),
803 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700804 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200805 .strategy = &sysctl_intvec,
806 .extra1 = &zero,
807 .extra2 = &one,
808 },
809 {
810 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700811 .procname = "softlockup_thresh",
812 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200813 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700814 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800815 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700816 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200817 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700818 .extra2 = &sixty,
819 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800820#endif
821#ifdef CONFIG_DETECT_HUNG_TASK
822 {
823 .ctl_name = CTL_UNNUMBERED,
824 .procname = "hung_task_panic",
825 .data = &sysctl_hung_task_panic,
826 .maxlen = sizeof(int),
827 .mode = 0644,
828 .proc_handler = &proc_dointvec_minmax,
829 .strategy = &sysctl_intvec,
830 .extra1 = &zero,
831 .extra2 = &one,
832 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100833 {
834 .ctl_name = CTL_UNNUMBERED,
835 .procname = "hung_task_check_count",
836 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100837 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100838 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100839 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100840 .strategy = &sysctl_intvec,
841 },
842 {
843 .ctl_name = CTL_UNNUMBERED,
844 .procname = "hung_task_timeout_secs",
845 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100846 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100847 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800848 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100849 .strategy = &sysctl_intvec,
850 },
851 {
852 .ctl_name = CTL_UNNUMBERED,
853 .procname = "hung_task_warnings",
854 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100855 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100856 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100857 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100858 .strategy = &sysctl_intvec,
859 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700860#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200861#ifdef CONFIG_COMPAT
862 {
863 .ctl_name = KERN_COMPAT_LOG,
864 .procname = "compat-log",
865 .data = &compat_log,
866 .maxlen = sizeof (int),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec,
869 },
870#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700871#ifdef CONFIG_RT_MUTEXES
872 {
873 .ctl_name = KERN_MAX_LOCK_DEPTH,
874 .procname = "max_lock_depth",
875 .data = &max_lock_depth,
876 .maxlen = sizeof(int),
877 .mode = 0644,
878 .proc_handler = &proc_dointvec,
879 },
880#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700881 {
882 .ctl_name = CTL_UNNUMBERED,
883 .procname = "poweroff_cmd",
884 .data = &poweroff_cmd,
885 .maxlen = POWEROFF_CMD_PATH_LEN,
886 .mode = 0644,
887 .proc_handler = &proc_dostring,
888 .strategy = &sysctl_string,
889 },
David Howells0b77f5b2008-04-29 01:01:32 -0700890#ifdef CONFIG_KEYS
891 {
892 .ctl_name = CTL_UNNUMBERED,
893 .procname = "keys",
894 .mode = 0555,
895 .child = key_sysctls,
896 },
897#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700898#ifdef CONFIG_RCU_TORTURE_TEST
899 {
900 .ctl_name = CTL_UNNUMBERED,
901 .procname = "rcutorture_runnable",
902 .data = &rcutorture_runnable,
903 .maxlen = sizeof(int),
904 .mode = 0644,
905 .proc_handler = &proc_dointvec,
906 },
907#endif
Lee Schermerhornaf936a12008-10-18 20:26:53 -0700908#ifdef CONFIG_UNEVICTABLE_LRU
909 {
910 .ctl_name = CTL_UNNUMBERED,
911 .procname = "scan_unevictable_pages",
912 .data = &scan_unevictable_pages,
913 .maxlen = sizeof(scan_unevictable_pages),
914 .mode = 0644,
915 .proc_handler = &scan_unevictable_handler,
916 },
917#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700918/*
919 * NOTE: do not add new entries to this table unless you have read
920 * Documentation/sysctl/ctl_unnumbered.txt
921 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 { .ctl_name = 0 }
923};
924
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700925static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 {
927 .ctl_name = VM_OVERCOMMIT_MEMORY,
928 .procname = "overcommit_memory",
929 .data = &sysctl_overcommit_memory,
930 .maxlen = sizeof(sysctl_overcommit_memory),
931 .mode = 0644,
932 .proc_handler = &proc_dointvec,
933 },
934 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700935 .ctl_name = VM_PANIC_ON_OOM,
936 .procname = "panic_on_oom",
937 .data = &sysctl_panic_on_oom,
938 .maxlen = sizeof(sysctl_panic_on_oom),
939 .mode = 0644,
940 .proc_handler = &proc_dointvec,
941 },
942 {
David Rientjesfe071d72007-10-16 23:25:56 -0700943 .ctl_name = CTL_UNNUMBERED,
944 .procname = "oom_kill_allocating_task",
945 .data = &sysctl_oom_kill_allocating_task,
946 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec,
949 },
950 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800951 .ctl_name = CTL_UNNUMBERED,
952 .procname = "oom_dump_tasks",
953 .data = &sysctl_oom_dump_tasks,
954 .maxlen = sizeof(sysctl_oom_dump_tasks),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec,
957 },
958 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 .ctl_name = VM_OVERCOMMIT_RATIO,
960 .procname = "overcommit_ratio",
961 .data = &sysctl_overcommit_ratio,
962 .maxlen = sizeof(sysctl_overcommit_ratio),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 },
966 {
967 .ctl_name = VM_PAGE_CLUSTER,
968 .procname = "page-cluster",
969 .data = &page_cluster,
970 .maxlen = sizeof(int),
971 .mode = 0644,
972 .proc_handler = &proc_dointvec,
973 },
974 {
975 .ctl_name = VM_DIRTY_BACKGROUND,
976 .procname = "dirty_background_ratio",
977 .data = &dirty_background_ratio,
978 .maxlen = sizeof(dirty_background_ratio),
979 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800980 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 .strategy = &sysctl_intvec,
982 .extra1 = &zero,
983 .extra2 = &one_hundred,
984 },
985 {
David Rientjes2da02992009-01-06 14:39:31 -0800986 .ctl_name = CTL_UNNUMBERED,
987 .procname = "dirty_background_bytes",
988 .data = &dirty_background_bytes,
989 .maxlen = sizeof(dirty_background_bytes),
990 .mode = 0644,
991 .proc_handler = &dirty_background_bytes_handler,
992 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800993 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -0800994 },
995 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 .ctl_name = VM_DIRTY_RATIO,
997 .procname = "dirty_ratio",
998 .data = &vm_dirty_ratio,
999 .maxlen = sizeof(vm_dirty_ratio),
1000 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001001 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 .strategy = &sysctl_intvec,
1003 .extra1 = &zero,
1004 .extra2 = &one_hundred,
1005 },
1006 {
David Rientjes2da02992009-01-06 14:39:31 -08001007 .ctl_name = CTL_UNNUMBERED,
1008 .procname = "dirty_bytes",
1009 .data = &vm_dirty_bytes,
1010 .maxlen = sizeof(vm_dirty_bytes),
1011 .mode = 0644,
1012 .proc_handler = &dirty_bytes_handler,
1013 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001014 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001015 },
1016 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001018 .data = &dirty_writeback_interval,
1019 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 .mode = 0644,
1021 .proc_handler = &dirty_writeback_centisecs_handler,
1022 },
1023 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001025 .data = &dirty_expire_interval,
1026 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -08001028 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 },
1030 {
1031 .ctl_name = VM_NR_PDFLUSH_THREADS,
1032 .procname = "nr_pdflush_threads",
1033 .data = &nr_pdflush_threads,
1034 .maxlen = sizeof nr_pdflush_threads,
1035 .mode = 0444 /* read-only*/,
1036 .proc_handler = &proc_dointvec,
1037 },
1038 {
1039 .ctl_name = VM_SWAPPINESS,
1040 .procname = "swappiness",
1041 .data = &vm_swappiness,
1042 .maxlen = sizeof(vm_swappiness),
1043 .mode = 0644,
1044 .proc_handler = &proc_dointvec_minmax,
1045 .strategy = &sysctl_intvec,
1046 .extra1 = &zero,
1047 .extra2 = &one_hundred,
1048 },
1049#ifdef CONFIG_HUGETLB_PAGE
1050 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001052 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 .maxlen = sizeof(unsigned long),
1054 .mode = 0644,
1055 .proc_handler = &hugetlb_sysctl_handler,
1056 .extra1 = (void *)&hugetlb_zero,
1057 .extra2 = (void *)&hugetlb_infinity,
1058 },
1059 {
1060 .ctl_name = VM_HUGETLB_GROUP,
1061 .procname = "hugetlb_shm_group",
1062 .data = &sysctl_hugetlb_shm_group,
1063 .maxlen = sizeof(gid_t),
1064 .mode = 0644,
1065 .proc_handler = &proc_dointvec,
1066 },
Mel Gorman396faf02007-07-17 04:03:13 -07001067 {
1068 .ctl_name = CTL_UNNUMBERED,
1069 .procname = "hugepages_treat_as_movable",
1070 .data = &hugepages_treat_as_movable,
1071 .maxlen = sizeof(int),
1072 .mode = 0644,
1073 .proc_handler = &hugetlb_treat_movable_handler,
1074 },
Adam Litke54f9f802007-10-16 01:26:20 -07001075 {
1076 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001077 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001078 .data = NULL,
1079 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001080 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001081 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001082 .extra1 = (void *)&hugetlb_zero,
1083 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001084 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085#endif
1086 {
1087 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1088 .procname = "lowmem_reserve_ratio",
1089 .data = &sysctl_lowmem_reserve_ratio,
1090 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1091 .mode = 0644,
1092 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1093 .strategy = &sysctl_intvec,
1094 },
1095 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001096 .ctl_name = VM_DROP_PAGECACHE,
1097 .procname = "drop_caches",
1098 .data = &sysctl_drop_caches,
1099 .maxlen = sizeof(int),
1100 .mode = 0644,
1101 .proc_handler = drop_caches_sysctl_handler,
1102 .strategy = &sysctl_intvec,
1103 },
1104 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 .ctl_name = VM_MIN_FREE_KBYTES,
1106 .procname = "min_free_kbytes",
1107 .data = &min_free_kbytes,
1108 .maxlen = sizeof(min_free_kbytes),
1109 .mode = 0644,
1110 .proc_handler = &min_free_kbytes_sysctl_handler,
1111 .strategy = &sysctl_intvec,
1112 .extra1 = &zero,
1113 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001114 {
1115 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1116 .procname = "percpu_pagelist_fraction",
1117 .data = &percpu_pagelist_fraction,
1118 .maxlen = sizeof(percpu_pagelist_fraction),
1119 .mode = 0644,
1120 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1121 .strategy = &sysctl_intvec,
1122 .extra1 = &min_percpu_pagelist_fract,
1123 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124#ifdef CONFIG_MMU
1125 {
1126 .ctl_name = VM_MAX_MAP_COUNT,
1127 .procname = "max_map_count",
1128 .data = &sysctl_max_map_count,
1129 .maxlen = sizeof(sysctl_max_map_count),
1130 .mode = 0644,
1131 .proc_handler = &proc_dointvec
1132 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001133#else
1134 {
1135 .ctl_name = CTL_UNNUMBERED,
1136 .procname = "nr_trim_pages",
1137 .data = &sysctl_nr_trim_pages,
1138 .maxlen = sizeof(sysctl_nr_trim_pages),
1139 .mode = 0644,
1140 .proc_handler = &proc_dointvec_minmax,
1141 .strategy = &sysctl_intvec,
1142 .extra1 = &zero,
1143 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144#endif
1145 {
1146 .ctl_name = VM_LAPTOP_MODE,
1147 .procname = "laptop_mode",
1148 .data = &laptop_mode,
1149 .maxlen = sizeof(laptop_mode),
1150 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001151 .proc_handler = &proc_dointvec_jiffies,
1152 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 },
1154 {
1155 .ctl_name = VM_BLOCK_DUMP,
1156 .procname = "block_dump",
1157 .data = &block_dump,
1158 .maxlen = sizeof(block_dump),
1159 .mode = 0644,
1160 .proc_handler = &proc_dointvec,
1161 .strategy = &sysctl_intvec,
1162 .extra1 = &zero,
1163 },
1164 {
1165 .ctl_name = VM_VFS_CACHE_PRESSURE,
1166 .procname = "vfs_cache_pressure",
1167 .data = &sysctl_vfs_cache_pressure,
1168 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1169 .mode = 0644,
1170 .proc_handler = &proc_dointvec,
1171 .strategy = &sysctl_intvec,
1172 .extra1 = &zero,
1173 },
1174#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1175 {
1176 .ctl_name = VM_LEGACY_VA_LAYOUT,
1177 .procname = "legacy_va_layout",
1178 .data = &sysctl_legacy_va_layout,
1179 .maxlen = sizeof(sysctl_legacy_va_layout),
1180 .mode = 0644,
1181 .proc_handler = &proc_dointvec,
1182 .strategy = &sysctl_intvec,
1183 .extra1 = &zero,
1184 },
1185#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001186#ifdef CONFIG_NUMA
1187 {
1188 .ctl_name = VM_ZONE_RECLAIM_MODE,
1189 .procname = "zone_reclaim_mode",
1190 .data = &zone_reclaim_mode,
1191 .maxlen = sizeof(zone_reclaim_mode),
1192 .mode = 0644,
1193 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001194 .strategy = &sysctl_intvec,
1195 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001196 },
Christoph Lameter96146342006-07-03 00:24:13 -07001197 {
1198 .ctl_name = VM_MIN_UNMAPPED,
1199 .procname = "min_unmapped_ratio",
1200 .data = &sysctl_min_unmapped_ratio,
1201 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1202 .mode = 0644,
1203 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1204 .strategy = &sysctl_intvec,
1205 .extra1 = &zero,
1206 .extra2 = &one_hundred,
1207 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001208 {
1209 .ctl_name = VM_MIN_SLAB,
1210 .procname = "min_slab_ratio",
1211 .data = &sysctl_min_slab_ratio,
1212 .maxlen = sizeof(sysctl_min_slab_ratio),
1213 .mode = 0644,
1214 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1215 .strategy = &sysctl_intvec,
1216 .extra1 = &zero,
1217 .extra2 = &one_hundred,
1218 },
Christoph Lameter17436602006-01-18 17:42:32 -08001219#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001220#ifdef CONFIG_SMP
1221 {
1222 .ctl_name = CTL_UNNUMBERED,
1223 .procname = "stat_interval",
1224 .data = &sysctl_stat_interval,
1225 .maxlen = sizeof(sysctl_stat_interval),
1226 .mode = 0644,
1227 .proc_handler = &proc_dointvec_jiffies,
1228 .strategy = &sysctl_jiffies,
1229 },
1230#endif
Eric Parised032182007-06-28 15:55:21 -04001231#ifdef CONFIG_SECURITY
1232 {
1233 .ctl_name = CTL_UNNUMBERED,
1234 .procname = "mmap_min_addr",
1235 .data = &mmap_min_addr,
1236 .maxlen = sizeof(unsigned long),
1237 .mode = 0644,
1238 .proc_handler = &proc_doulongvec_minmax,
1239 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001240#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001241#ifdef CONFIG_NUMA
1242 {
1243 .ctl_name = CTL_UNNUMBERED,
1244 .procname = "numa_zonelist_order",
1245 .data = &numa_zonelist_order,
1246 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1247 .mode = 0644,
1248 .proc_handler = &numa_zonelist_order_handler,
1249 .strategy = &sysctl_string,
1250 },
1251#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001252#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001253 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001254 {
1255 .ctl_name = VM_VDSO_ENABLED,
1256 .procname = "vdso_enabled",
1257 .data = &vdso_enabled,
1258 .maxlen = sizeof(vdso_enabled),
1259 .mode = 0644,
1260 .proc_handler = &proc_dointvec,
1261 .strategy = &sysctl_intvec,
1262 .extra1 = &zero,
1263 },
1264#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001265#ifdef CONFIG_HIGHMEM
1266 {
1267 .ctl_name = CTL_UNNUMBERED,
1268 .procname = "highmem_is_dirtyable",
1269 .data = &vm_highmem_is_dirtyable,
1270 .maxlen = sizeof(vm_highmem_is_dirtyable),
1271 .mode = 0644,
1272 .proc_handler = &proc_dointvec_minmax,
1273 .strategy = &sysctl_intvec,
1274 .extra1 = &zero,
1275 .extra2 = &one,
1276 },
1277#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001278/*
1279 * NOTE: do not add new entries to this table unless you have read
1280 * Documentation/sysctl/ctl_unnumbered.txt
1281 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 { .ctl_name = 0 }
1283};
1284
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001285#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001286static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001287 { .ctl_name = 0 }
1288};
1289#endif
1290
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001291static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 {
1293 .ctl_name = FS_NRINODE,
1294 .procname = "inode-nr",
1295 .data = &inodes_stat,
1296 .maxlen = 2*sizeof(int),
1297 .mode = 0444,
1298 .proc_handler = &proc_dointvec,
1299 },
1300 {
1301 .ctl_name = FS_STATINODE,
1302 .procname = "inode-state",
1303 .data = &inodes_stat,
1304 .maxlen = 7*sizeof(int),
1305 .mode = 0444,
1306 .proc_handler = &proc_dointvec,
1307 },
1308 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 .procname = "file-nr",
1310 .data = &files_stat,
1311 .maxlen = 3*sizeof(int),
1312 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001313 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 },
1315 {
1316 .ctl_name = FS_MAXFILE,
1317 .procname = "file-max",
1318 .data = &files_stat.max_files,
1319 .maxlen = sizeof(int),
1320 .mode = 0644,
1321 .proc_handler = &proc_dointvec,
1322 },
1323 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001324 .ctl_name = CTL_UNNUMBERED,
1325 .procname = "nr_open",
1326 .data = &sysctl_nr_open,
1327 .maxlen = sizeof(int),
1328 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001329 .proc_handler = &proc_dointvec_minmax,
1330 .extra1 = &sysctl_nr_open_min,
1331 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001332 },
1333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 .ctl_name = FS_DENTRY,
1335 .procname = "dentry-state",
1336 .data = &dentry_stat,
1337 .maxlen = 6*sizeof(int),
1338 .mode = 0444,
1339 .proc_handler = &proc_dointvec,
1340 },
1341 {
1342 .ctl_name = FS_OVERFLOWUID,
1343 .procname = "overflowuid",
1344 .data = &fs_overflowuid,
1345 .maxlen = sizeof(int),
1346 .mode = 0644,
1347 .proc_handler = &proc_dointvec_minmax,
1348 .strategy = &sysctl_intvec,
1349 .extra1 = &minolduid,
1350 .extra2 = &maxolduid,
1351 },
1352 {
1353 .ctl_name = FS_OVERFLOWGID,
1354 .procname = "overflowgid",
1355 .data = &fs_overflowgid,
1356 .maxlen = sizeof(int),
1357 .mode = 0644,
1358 .proc_handler = &proc_dointvec_minmax,
1359 .strategy = &sysctl_intvec,
1360 .extra1 = &minolduid,
1361 .extra2 = &maxolduid,
1362 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001363#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 {
1365 .ctl_name = FS_LEASES,
1366 .procname = "leases-enable",
1367 .data = &leases_enable,
1368 .maxlen = sizeof(int),
1369 .mode = 0644,
1370 .proc_handler = &proc_dointvec,
1371 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001372#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373#ifdef CONFIG_DNOTIFY
1374 {
1375 .ctl_name = FS_DIR_NOTIFY,
1376 .procname = "dir-notify-enable",
1377 .data = &dir_notify_enable,
1378 .maxlen = sizeof(int),
1379 .mode = 0644,
1380 .proc_handler = &proc_dointvec,
1381 },
1382#endif
1383#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001384#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 {
1386 .ctl_name = FS_LEASE_TIME,
1387 .procname = "lease-break-time",
1388 .data = &lease_break_time,
1389 .maxlen = sizeof(int),
1390 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001391 .proc_handler = &proc_dointvec_minmax,
1392 .strategy = &sysctl_intvec,
1393 .extra1 = &zero,
1394 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001396#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001397#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "aio-nr",
1400 .data = &aio_nr,
1401 .maxlen = sizeof(aio_nr),
1402 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001403 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 },
1405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 .procname = "aio-max-nr",
1407 .data = &aio_max_nr,
1408 .maxlen = sizeof(aio_max_nr),
1409 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001410 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001412#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001413#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001414 {
1415 .ctl_name = FS_INOTIFY,
1416 .procname = "inotify",
1417 .mode = 0555,
1418 .child = inotify_table,
1419 },
1420#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001421#ifdef CONFIG_EPOLL
1422 {
1423 .procname = "epoll",
1424 .mode = 0555,
1425 .child = epoll_table,
1426 },
1427#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001429 {
1430 .ctl_name = KERN_SETUID_DUMPABLE,
1431 .procname = "suid_dumpable",
1432 .data = &suid_dumpable,
1433 .maxlen = sizeof(int),
1434 .mode = 0644,
1435 .proc_handler = &proc_dointvec,
1436 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001437#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1438 {
1439 .ctl_name = CTL_UNNUMBERED,
1440 .procname = "binfmt_misc",
1441 .mode = 0555,
1442 .child = binfmt_misc_table,
1443 },
1444#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001445/*
1446 * NOTE: do not add new entries to this table unless you have read
1447 * Documentation/sysctl/ctl_unnumbered.txt
1448 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 { .ctl_name = 0 }
1450};
1451
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001452static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001453#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001454 {
1455 .ctl_name = CTL_UNNUMBERED,
1456 .procname = "exception-trace",
1457 .data = &show_unhandled_signals,
1458 .maxlen = sizeof(int),
1459 .mode = 0644,
1460 .proc_handler = proc_dointvec
1461 },
1462#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 { .ctl_name = 0 }
1464};
1465
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001466static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001468};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
Al Viro330d57f2005-11-04 10:18:40 +00001470static DEFINE_SPINLOCK(sysctl_lock);
1471
1472/* called under sysctl_lock */
1473static int use_table(struct ctl_table_header *p)
1474{
1475 if (unlikely(p->unregistering))
1476 return 0;
1477 p->used++;
1478 return 1;
1479}
1480
1481/* called under sysctl_lock */
1482static void unuse_table(struct ctl_table_header *p)
1483{
1484 if (!--p->used)
1485 if (unlikely(p->unregistering))
1486 complete(p->unregistering);
1487}
1488
1489/* called under sysctl_lock, will reacquire if has to wait */
1490static void start_unregistering(struct ctl_table_header *p)
1491{
1492 /*
1493 * if p->used is 0, nobody will ever touch that entry again;
1494 * we'll eliminate all paths to it before dropping sysctl_lock
1495 */
1496 if (unlikely(p->used)) {
1497 struct completion wait;
1498 init_completion(&wait);
1499 p->unregistering = &wait;
1500 spin_unlock(&sysctl_lock);
1501 wait_for_completion(&wait);
1502 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001503 } else {
1504 /* anything non-NULL; we'll never dereference it */
1505 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001506 }
1507 /*
1508 * do not remove from the list until nobody holds it; walking the
1509 * list in do_sysctl() relies on that.
1510 */
1511 list_del_init(&p->ctl_entry);
1512}
1513
Al Virof7e6ced2008-07-15 01:44:23 -04001514void sysctl_head_get(struct ctl_table_header *head)
1515{
1516 spin_lock(&sysctl_lock);
1517 head->count++;
1518 spin_unlock(&sysctl_lock);
1519}
1520
1521void sysctl_head_put(struct ctl_table_header *head)
1522{
1523 spin_lock(&sysctl_lock);
1524 if (!--head->count)
1525 kfree(head);
1526 spin_unlock(&sysctl_lock);
1527}
1528
1529struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1530{
1531 if (!head)
1532 BUG();
1533 spin_lock(&sysctl_lock);
1534 if (!use_table(head))
1535 head = ERR_PTR(-ENOENT);
1536 spin_unlock(&sysctl_lock);
1537 return head;
1538}
1539
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001540void sysctl_head_finish(struct ctl_table_header *head)
1541{
1542 if (!head)
1543 return;
1544 spin_lock(&sysctl_lock);
1545 unuse_table(head);
1546 spin_unlock(&sysctl_lock);
1547}
1548
Al Viro73455092008-07-14 21:22:20 -04001549static struct ctl_table_set *
1550lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1551{
1552 struct ctl_table_set *set = &root->default_set;
1553 if (root->lookup)
1554 set = root->lookup(root, namespaces);
1555 return set;
1556}
1557
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001558static struct list_head *
1559lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001560{
Al Viro73455092008-07-14 21:22:20 -04001561 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1562 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001563}
1564
1565struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1566 struct ctl_table_header *prev)
1567{
1568 struct ctl_table_root *root;
1569 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001570 struct ctl_table_header *head;
1571 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001572
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001573 spin_lock(&sysctl_lock);
1574 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001575 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001576 tmp = &prev->ctl_entry;
1577 unuse_table(prev);
1578 goto next;
1579 }
1580 tmp = &root_table_header.ctl_entry;
1581 for (;;) {
1582 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1583
1584 if (!use_table(head))
1585 goto next;
1586 spin_unlock(&sysctl_lock);
1587 return head;
1588 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001589 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001590 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001591 header_list = lookup_header_list(root, namespaces);
1592 if (tmp != header_list)
1593 continue;
1594
1595 do {
1596 root = list_entry(root->root_list.next,
1597 struct ctl_table_root, root_list);
1598 if (root == &sysctl_table_root)
1599 goto out;
1600 header_list = lookup_header_list(root, namespaces);
1601 } while (list_empty(header_list));
1602 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001603 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001604out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001605 spin_unlock(&sysctl_lock);
1606 return NULL;
1607}
1608
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001609struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1610{
1611 return __sysctl_head_next(current->nsproxy, prev);
1612}
1613
1614void register_sysctl_root(struct ctl_table_root *root)
1615{
1616 spin_lock(&sysctl_lock);
1617 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1618 spin_unlock(&sysctl_lock);
1619}
1620
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001621#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001622/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001623static int do_sysctl_strategy(struct ctl_table_root *root,
1624 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001625 void __user *oldval, size_t __user *oldlenp,
1626 void __user *newval, size_t newlen)
1627{
1628 int op = 0, rc;
1629
1630 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001631 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001632 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001633 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001634 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001635 return -EPERM;
1636
1637 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001638 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001639 if (rc < 0)
1640 return rc;
1641 if (rc > 0)
1642 return 0;
1643 }
1644
1645 /* If there is no strategy routine, or if the strategy returns
1646 * zero, proceed with automatic r/w */
1647 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001648 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001649 if (rc < 0)
1650 return rc;
1651 }
1652 return 0;
1653}
1654
1655static int parse_table(int __user *name, int nlen,
1656 void __user *oldval, size_t __user *oldlenp,
1657 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001658 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001659 struct ctl_table *table)
1660{
1661 int n;
1662repeat:
1663 if (!nlen)
1664 return -ENOTDIR;
1665 if (get_user(n, name))
1666 return -EFAULT;
1667 for ( ; table->ctl_name || table->procname; table++) {
1668 if (!table->ctl_name)
1669 continue;
1670 if (n == table->ctl_name) {
1671 int error;
1672 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001673 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001674 return -EPERM;
1675 name++;
1676 nlen--;
1677 table = table->child;
1678 goto repeat;
1679 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001680 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001681 oldval, oldlenp,
1682 newval, newlen);
1683 return error;
1684 }
1685 }
1686 return -ENOTDIR;
1687}
1688
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1690 void __user *newval, size_t newlen)
1691{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001692 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001693 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
1695 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1696 return -ENOTDIR;
1697 if (oldval) {
1698 int old_len;
1699 if (!oldlenp || get_user(old_len, oldlenp))
1700 return -EFAULT;
1701 }
Al Viro330d57f2005-11-04 10:18:40 +00001702
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001703 for (head = sysctl_head_next(NULL); head;
1704 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001705 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001706 newval, newlen,
1707 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001708 if (error != -ENOTDIR) {
1709 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001710 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001711 }
1712 }
Al Viro330d57f2005-11-04 10:18:40 +00001713 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
1715
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001716SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
1718 struct __sysctl_args tmp;
1719 int error;
1720
1721 if (copy_from_user(&tmp, args, sizeof(tmp)))
1722 return -EFAULT;
1723
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001724 error = deprecated_sysctl_warning(&tmp);
1725 if (error)
1726 goto out;
1727
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 lock_kernel();
1729 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1730 tmp.newval, tmp.newlen);
1731 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001732out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 return error;
1734}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001735#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001738 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 * some sysctl variables are readonly even to root.
1740 */
1741
1742static int test_perm(int mode, int op)
1743{
David Howells76aac0e2008-11-14 10:39:12 +11001744 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 mode >>= 6;
1746 else if (in_egroup_p(0))
1747 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001748 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 return 0;
1750 return -EACCES;
1751}
1752
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001753int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754{
1755 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001756 int mode;
1757
Al Viroe6305c42008-07-15 21:03:57 -04001758 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 if (error)
1760 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001761
1762 if (root->permissions)
1763 mode = root->permissions(root, current->nsproxy, table);
1764 else
1765 mode = table->mode;
1766
1767 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001770static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1771{
1772 for (; table->ctl_name || table->procname; table++) {
1773 table->parent = parent;
1774 if (table->child)
1775 sysctl_set_parent(table, table->child);
1776 }
1777}
1778
1779static __init int sysctl_init(void)
1780{
1781 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001782#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1783 {
1784 int err;
1785 err = sysctl_check_table(current->nsproxy, root_table);
1786 }
1787#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001788 return 0;
1789}
1790
1791core_initcall(sysctl_init);
1792
Al Virobfbcf032008-07-27 06:31:22 +01001793static struct ctl_table *is_branch_in(struct ctl_table *branch,
1794 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001795{
1796 struct ctl_table *p;
1797 const char *s = branch->procname;
1798
1799 /* branch should have named subdirectory as its first element */
1800 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001801 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001802
1803 /* ... and nothing else */
1804 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001805 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001806
1807 /* table should contain subdirectory with the same name */
1808 for (p = table; p->procname || p->ctl_name; p++) {
1809 if (!p->child)
1810 continue;
1811 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001812 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001813 }
Al Virobfbcf032008-07-27 06:31:22 +01001814 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001815}
1816
1817/* see if attaching q to p would be an improvement */
1818static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1819{
1820 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001821 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001822 int is_better = 0;
1823 int not_in_parent = !p->attached_by;
1824
Al Virobfbcf032008-07-27 06:31:22 +01001825 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001826 if (by == q->attached_by)
1827 is_better = 1;
1828 if (to == p->attached_by)
1829 not_in_parent = 1;
1830 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001831 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001832 }
1833
1834 if (is_better && not_in_parent) {
1835 q->attached_by = by;
1836 q->attached_to = to;
1837 q->parent = p;
1838 }
1839}
1840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001842 * __register_sysctl_paths - register a sysctl hierarchy
1843 * @root: List of sysctl headers to register on
1844 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001845 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 *
1848 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001849 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001851 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 *
1853 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1854 * must be unique within that level of sysctl
1855 *
1856 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1857 * enter a sysctl file
1858 *
1859 * data - a pointer to data for use by proc_handler
1860 *
1861 * maxlen - the maximum size in bytes of the data
1862 *
1863 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1864 *
1865 * child - a pointer to the child sysctl table if this entry is a directory, or
1866 * %NULL.
1867 *
1868 * proc_handler - the text handler routine (described below)
1869 *
1870 * strategy - the strategy routine (described below)
1871 *
1872 * de - for internal use by the sysctl routines
1873 *
1874 * extra1, extra2 - extra pointers usable by the proc handler routines
1875 *
1876 * Leaf nodes in the sysctl tree will be represented by a single file
1877 * under /proc; non-leaf nodes will be represented by directories.
1878 *
1879 * sysctl(2) can automatically manage read and write requests through
1880 * the sysctl table. The data and maxlen fields of the ctl_table
1881 * struct enable minimal validation of the values being written to be
1882 * performed, and the mode field allows minimal authentication.
1883 *
1884 * More sophisticated management can be enabled by the provision of a
1885 * strategy routine with the table entry. This will be called before
1886 * any automatic read or write of the data is performed.
1887 *
1888 * The strategy routine may return
1889 *
1890 * < 0 - Error occurred (error is passed to user process)
1891 *
1892 * 0 - OK - proceed with automatic read or write.
1893 *
1894 * > 0 - OK - read or write has been done by the strategy routine, so
1895 * return immediately.
1896 *
1897 * There must be a proc_handler routine for any terminal nodes
1898 * mirrored under /proc/sys (non-terminals are handled by a built-in
1899 * directory handler). Several default handlers are available to
1900 * cover common cases -
1901 *
1902 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1903 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1904 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1905 *
1906 * It is the handler's job to read the input buffer from user memory
1907 * and process it. The handler should return 0 on success.
1908 *
1909 * This routine returns %NULL on a failure to register, and a pointer
1910 * to the table header on success.
1911 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001912struct ctl_table_header *__register_sysctl_paths(
1913 struct ctl_table_root *root,
1914 struct nsproxy *namespaces,
1915 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001917 struct ctl_table_header *header;
1918 struct ctl_table *new, **prevp;
1919 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001920 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001921
1922 /* Count the path components */
1923 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1924 ;
1925
1926 /*
1927 * For each path component, allocate a 2-element ctl_table array.
1928 * The first array element will be filled with the sysctl entry
1929 * for this, the second will be the sentinel (ctl_name == 0).
1930 *
1931 * We allocate everything in one go so that we don't have to
1932 * worry about freeing additional memory in unregister_sysctl_table.
1933 */
1934 header = kzalloc(sizeof(struct ctl_table_header) +
1935 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1936 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001938
1939 new = (struct ctl_table *) (header + 1);
1940
1941 /* Now connect the dots */
1942 prevp = &header->ctl_table;
1943 for (n = 0; n < npath; ++n, ++path) {
1944 /* Copy the procname */
1945 new->procname = path->procname;
1946 new->ctl_name = path->ctl_name;
1947 new->mode = 0555;
1948
1949 *prevp = new;
1950 prevp = &new->child;
1951
1952 new += 2;
1953 }
1954 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001955 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001956
1957 INIT_LIST_HEAD(&header->ctl_entry);
1958 header->used = 0;
1959 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001960 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001961 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001962 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001963#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001964 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001965 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001966 return NULL;
1967 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001968#endif
Al Viro330d57f2005-11-04 10:18:40 +00001969 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001970 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001971 header->attached_by = header->ctl_table;
1972 header->attached_to = root_table;
1973 header->parent = &root_table_header;
1974 for (set = header->set; set; set = set->parent) {
1975 struct ctl_table_header *p;
1976 list_for_each_entry(p, &set->list, ctl_entry) {
1977 if (p->unregistering)
1978 continue;
1979 try_attach(p, header);
1980 }
1981 }
1982 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001983 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001984 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001985
1986 return header;
1987}
1988
1989/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001990 * register_sysctl_table_path - register a sysctl table hierarchy
1991 * @path: The path to the directory the sysctl table is in.
1992 * @table: the top-level table structure
1993 *
1994 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1995 * array. A completely 0 filled entry terminates the table.
1996 *
1997 * See __register_sysctl_paths for more details.
1998 */
1999struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2000 struct ctl_table *table)
2001{
2002 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2003 path, table);
2004}
2005
2006/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002007 * register_sysctl_table - register a sysctl table hierarchy
2008 * @table: the top-level table structure
2009 *
2010 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2011 * array. A completely 0 filled entry terminates the table.
2012 *
2013 * See register_sysctl_paths for more details.
2014 */
2015struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2016{
2017 static const struct ctl_path null_path[] = { {} };
2018
2019 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020}
2021
2022/**
2023 * unregister_sysctl_table - unregister a sysctl table hierarchy
2024 * @header: the header returned from register_sysctl_table
2025 *
2026 * Unregisters the sysctl table and all children. proc entries may not
2027 * actually be removed until they are no longer used by anyone.
2028 */
2029void unregister_sysctl_table(struct ctl_table_header * header)
2030{
Al Viro330d57f2005-11-04 10:18:40 +00002031 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002032
2033 if (header == NULL)
2034 return;
2035
Al Viro330d57f2005-11-04 10:18:40 +00002036 spin_lock(&sysctl_lock);
2037 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002038 if (!--header->parent->count) {
2039 WARN_ON(1);
2040 kfree(header->parent);
2041 }
Al Virof7e6ced2008-07-15 01:44:23 -04002042 if (!--header->count)
2043 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002044 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
Al Viro90434762008-07-15 08:54:06 -04002047int sysctl_is_seen(struct ctl_table_header *p)
2048{
2049 struct ctl_table_set *set = p->set;
2050 int res;
2051 spin_lock(&sysctl_lock);
2052 if (p->unregistering)
2053 res = 0;
2054 else if (!set->is_seen)
2055 res = 1;
2056 else
2057 res = set->is_seen(set);
2058 spin_unlock(&sysctl_lock);
2059 return res;
2060}
2061
Al Viro73455092008-07-14 21:22:20 -04002062void setup_sysctl_set(struct ctl_table_set *p,
2063 struct ctl_table_set *parent,
2064 int (*is_seen)(struct ctl_table_set *))
2065{
2066 INIT_LIST_HEAD(&p->list);
2067 p->parent = parent ? parent : &sysctl_table_root.default_set;
2068 p->is_seen = is_seen;
2069}
2070
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002071#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002072struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002073{
2074 return NULL;
2075}
2076
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002077struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2078 struct ctl_table *table)
2079{
2080 return NULL;
2081}
2082
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002083void unregister_sysctl_table(struct ctl_table_header * table)
2084{
2085}
2086
Al Viro73455092008-07-14 21:22:20 -04002087void setup_sysctl_set(struct ctl_table_set *p,
2088 struct ctl_table_set *parent,
2089 int (*is_seen)(struct ctl_table_set *))
2090{
2091}
2092
Al Virof7e6ced2008-07-15 01:44:23 -04002093void sysctl_head_put(struct ctl_table_header *head)
2094{
2095}
2096
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002097#endif /* CONFIG_SYSCTL */
2098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099/*
2100 * /proc/sys support
2101 */
2102
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002103#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002105static int _proc_do_string(void* data, int maxlen, int write,
2106 struct file *filp, void __user *buffer,
2107 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002108{
2109 size_t len;
2110 char __user *p;
2111 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002112
2113 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002114 *lenp = 0;
2115 return 0;
2116 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002117
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002118 if (write) {
2119 len = 0;
2120 p = buffer;
2121 while (len < *lenp) {
2122 if (get_user(c, p++))
2123 return -EFAULT;
2124 if (c == 0 || c == '\n')
2125 break;
2126 len++;
2127 }
2128 if (len >= maxlen)
2129 len = maxlen-1;
2130 if(copy_from_user(data, buffer, len))
2131 return -EFAULT;
2132 ((char *) data)[len] = 0;
2133 *ppos += *lenp;
2134 } else {
2135 len = strlen(data);
2136 if (len > maxlen)
2137 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002138
2139 if (*ppos > len) {
2140 *lenp = 0;
2141 return 0;
2142 }
2143
2144 data += *ppos;
2145 len -= *ppos;
2146
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002147 if (len > *lenp)
2148 len = *lenp;
2149 if (len)
2150 if(copy_to_user(buffer, data, len))
2151 return -EFAULT;
2152 if (len < *lenp) {
2153 if(put_user('\n', ((char __user *) buffer) + len))
2154 return -EFAULT;
2155 len++;
2156 }
2157 *lenp = len;
2158 *ppos += len;
2159 }
2160 return 0;
2161}
2162
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163/**
2164 * proc_dostring - read a string sysctl
2165 * @table: the sysctl table
2166 * @write: %TRUE if this is a write to the sysctl file
2167 * @filp: the file structure
2168 * @buffer: the user buffer
2169 * @lenp: the size of the user buffer
2170 * @ppos: file position
2171 *
2172 * Reads/writes a string from/to the user buffer. If the kernel
2173 * buffer provided is not large enough to hold the string, the
2174 * string is truncated. The copied string is %NULL-terminated.
2175 * If the string is being read by the user process, it is copied
2176 * and a newline '\n' is added. It is truncated if the buffer is
2177 * not large enough.
2178 *
2179 * Returns 0 on success.
2180 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002181int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 void __user *buffer, size_t *lenp, loff_t *ppos)
2183{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002184 return _proc_do_string(table->data, table->maxlen, write, filp,
2185 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
2189static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2190 int *valp,
2191 int write, void *data)
2192{
2193 if (write) {
2194 *valp = *negp ? -*lvalp : *lvalp;
2195 } else {
2196 int val = *valp;
2197 if (val < 0) {
2198 *negp = -1;
2199 *lvalp = (unsigned long)-val;
2200 } else {
2201 *negp = 0;
2202 *lvalp = (unsigned long)val;
2203 }
2204 }
2205 return 0;
2206}
2207
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002208static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002209 int write, struct file *filp, void __user *buffer,
2210 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2212 int write, void *data),
2213 void *data)
2214{
2215#define TMPBUFLEN 21
2216 int *i, vleft, first=1, neg, val;
2217 unsigned long lval;
2218 size_t left, len;
2219
2220 char buf[TMPBUFLEN], *p;
2221 char __user *s = buffer;
2222
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002223 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 (*ppos && !write)) {
2225 *lenp = 0;
2226 return 0;
2227 }
2228
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002229 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 vleft = table->maxlen / sizeof(*i);
2231 left = *lenp;
2232
2233 if (!conv)
2234 conv = do_proc_dointvec_conv;
2235
2236 for (; left && vleft--; i++, first=0) {
2237 if (write) {
2238 while (left) {
2239 char c;
2240 if (get_user(c, s))
2241 return -EFAULT;
2242 if (!isspace(c))
2243 break;
2244 left--;
2245 s++;
2246 }
2247 if (!left)
2248 break;
2249 neg = 0;
2250 len = left;
2251 if (len > sizeof(buf) - 1)
2252 len = sizeof(buf) - 1;
2253 if (copy_from_user(buf, s, len))
2254 return -EFAULT;
2255 buf[len] = 0;
2256 p = buf;
2257 if (*p == '-' && left > 1) {
2258 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002259 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 }
2261 if (*p < '0' || *p > '9')
2262 break;
2263
2264 lval = simple_strtoul(p, &p, 0);
2265
2266 len = p-buf;
2267 if ((len < left) && *p && !isspace(*p))
2268 break;
2269 if (neg)
2270 val = -val;
2271 s += len;
2272 left -= len;
2273
2274 if (conv(&neg, &lval, i, 1, data))
2275 break;
2276 } else {
2277 p = buf;
2278 if (!first)
2279 *p++ = '\t';
2280
2281 if (conv(&neg, &lval, i, 0, data))
2282 break;
2283
2284 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2285 len = strlen(buf);
2286 if (len > left)
2287 len = left;
2288 if(copy_to_user(s, buf, len))
2289 return -EFAULT;
2290 left -= len;
2291 s += len;
2292 }
2293 }
2294
2295 if (!write && !first && left) {
2296 if(put_user('\n', s))
2297 return -EFAULT;
2298 left--, s++;
2299 }
2300 if (write) {
2301 while (left) {
2302 char c;
2303 if (get_user(c, s++))
2304 return -EFAULT;
2305 if (!isspace(c))
2306 break;
2307 left--;
2308 }
2309 }
2310 if (write && first)
2311 return -EINVAL;
2312 *lenp -= left;
2313 *ppos += *lenp;
2314 return 0;
2315#undef TMPBUFLEN
2316}
2317
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002318static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002319 void __user *buffer, size_t *lenp, loff_t *ppos,
2320 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2321 int write, void *data),
2322 void *data)
2323{
2324 return __do_proc_dointvec(table->data, table, write, filp,
2325 buffer, lenp, ppos, conv, data);
2326}
2327
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328/**
2329 * proc_dointvec - read a vector of integers
2330 * @table: the sysctl table
2331 * @write: %TRUE if this is a write to the sysctl file
2332 * @filp: the file structure
2333 * @buffer: the user buffer
2334 * @lenp: the size of the user buffer
2335 * @ppos: file position
2336 *
2337 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2338 * values from/to the user buffer, treated as an ASCII string.
2339 *
2340 * Returns 0 on success.
2341 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002342int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 void __user *buffer, size_t *lenp, loff_t *ppos)
2344{
2345 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2346 NULL,NULL);
2347}
2348
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002349/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002350 * Taint values can only be increased
2351 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002352 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002353static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002354 void __user *buffer, size_t *lenp, loff_t *ppos)
2355{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002356 struct ctl_table t;
2357 unsigned long tmptaint = get_taint();
2358 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002359
Bastian Blank91fcd412007-04-23 14:41:14 -07002360 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002361 return -EPERM;
2362
Andi Kleen25ddbb12008-10-15 22:01:41 -07002363 t = *table;
2364 t.data = &tmptaint;
2365 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2366 if (err < 0)
2367 return err;
2368
2369 if (write) {
2370 /*
2371 * Poor man's atomic or. Not worth adding a primitive
2372 * to everyone's atomic.h for this
2373 */
2374 int i;
2375 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2376 if ((tmptaint >> i) & 1)
2377 add_taint(i);
2378 }
2379 }
2380
2381 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002382}
2383
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384struct do_proc_dointvec_minmax_conv_param {
2385 int *min;
2386 int *max;
2387};
2388
2389static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2390 int *valp,
2391 int write, void *data)
2392{
2393 struct do_proc_dointvec_minmax_conv_param *param = data;
2394 if (write) {
2395 int val = *negp ? -*lvalp : *lvalp;
2396 if ((param->min && *param->min > val) ||
2397 (param->max && *param->max < val))
2398 return -EINVAL;
2399 *valp = val;
2400 } else {
2401 int val = *valp;
2402 if (val < 0) {
2403 *negp = -1;
2404 *lvalp = (unsigned long)-val;
2405 } else {
2406 *negp = 0;
2407 *lvalp = (unsigned long)val;
2408 }
2409 }
2410 return 0;
2411}
2412
2413/**
2414 * proc_dointvec_minmax - read a vector of integers with min/max values
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @filp: the file structure
2418 * @buffer: the user buffer
2419 * @lenp: the size of the user buffer
2420 * @ppos: file position
2421 *
2422 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2423 * values from/to the user buffer, treated as an ASCII string.
2424 *
2425 * This routine will ensure the values are within the range specified by
2426 * table->extra1 (min) and table->extra2 (max).
2427 *
2428 * Returns 0 on success.
2429 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002430int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 void __user *buffer, size_t *lenp, loff_t *ppos)
2432{
2433 struct do_proc_dointvec_minmax_conv_param param = {
2434 .min = (int *) table->extra1,
2435 .max = (int *) table->extra2,
2436 };
2437 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2438 do_proc_dointvec_minmax_conv, &param);
2439}
2440
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002441static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 struct file *filp,
2443 void __user *buffer,
2444 size_t *lenp, loff_t *ppos,
2445 unsigned long convmul,
2446 unsigned long convdiv)
2447{
2448#define TMPBUFLEN 21
2449 unsigned long *i, *min, *max, val;
2450 int vleft, first=1, neg;
2451 size_t len, left;
2452 char buf[TMPBUFLEN], *p;
2453 char __user *s = buffer;
2454
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002455 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 (*ppos && !write)) {
2457 *lenp = 0;
2458 return 0;
2459 }
2460
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002461 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 min = (unsigned long *) table->extra1;
2463 max = (unsigned long *) table->extra2;
2464 vleft = table->maxlen / sizeof(unsigned long);
2465 left = *lenp;
2466
2467 for (; left && vleft--; i++, min++, max++, first=0) {
2468 if (write) {
2469 while (left) {
2470 char c;
2471 if (get_user(c, s))
2472 return -EFAULT;
2473 if (!isspace(c))
2474 break;
2475 left--;
2476 s++;
2477 }
2478 if (!left)
2479 break;
2480 neg = 0;
2481 len = left;
2482 if (len > TMPBUFLEN-1)
2483 len = TMPBUFLEN-1;
2484 if (copy_from_user(buf, s, len))
2485 return -EFAULT;
2486 buf[len] = 0;
2487 p = buf;
2488 if (*p == '-' && left > 1) {
2489 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002490 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 }
2492 if (*p < '0' || *p > '9')
2493 break;
2494 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2495 len = p-buf;
2496 if ((len < left) && *p && !isspace(*p))
2497 break;
2498 if (neg)
2499 val = -val;
2500 s += len;
2501 left -= len;
2502
2503 if(neg)
2504 continue;
2505 if ((min && val < *min) || (max && val > *max))
2506 continue;
2507 *i = val;
2508 } else {
2509 p = buf;
2510 if (!first)
2511 *p++ = '\t';
2512 sprintf(p, "%lu", convdiv * (*i) / convmul);
2513 len = strlen(buf);
2514 if (len > left)
2515 len = left;
2516 if(copy_to_user(s, buf, len))
2517 return -EFAULT;
2518 left -= len;
2519 s += len;
2520 }
2521 }
2522
2523 if (!write && !first && left) {
2524 if(put_user('\n', s))
2525 return -EFAULT;
2526 left--, s++;
2527 }
2528 if (write) {
2529 while (left) {
2530 char c;
2531 if (get_user(c, s++))
2532 return -EFAULT;
2533 if (!isspace(c))
2534 break;
2535 left--;
2536 }
2537 }
2538 if (write && first)
2539 return -EINVAL;
2540 *lenp -= left;
2541 *ppos += *lenp;
2542 return 0;
2543#undef TMPBUFLEN
2544}
2545
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002546static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002547 struct file *filp,
2548 void __user *buffer,
2549 size_t *lenp, loff_t *ppos,
2550 unsigned long convmul,
2551 unsigned long convdiv)
2552{
2553 return __do_proc_doulongvec_minmax(table->data, table, write,
2554 filp, buffer, lenp, ppos, convmul, convdiv);
2555}
2556
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557/**
2558 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2559 * @table: the sysctl table
2560 * @write: %TRUE if this is a write to the sysctl file
2561 * @filp: the file structure
2562 * @buffer: the user buffer
2563 * @lenp: the size of the user buffer
2564 * @ppos: file position
2565 *
2566 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2567 * values from/to the user buffer, treated as an ASCII string.
2568 *
2569 * This routine will ensure the values are within the range specified by
2570 * table->extra1 (min) and table->extra2 (max).
2571 *
2572 * Returns 0 on success.
2573 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002574int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 void __user *buffer, size_t *lenp, loff_t *ppos)
2576{
2577 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2578}
2579
2580/**
2581 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2582 * @table: the sysctl table
2583 * @write: %TRUE if this is a write to the sysctl file
2584 * @filp: the file structure
2585 * @buffer: the user buffer
2586 * @lenp: the size of the user buffer
2587 * @ppos: file position
2588 *
2589 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2590 * values from/to the user buffer, treated as an ASCII string. The values
2591 * are treated as milliseconds, and converted to jiffies when they are stored.
2592 *
2593 * This routine will ensure the values are within the range specified by
2594 * table->extra1 (min) and table->extra2 (max).
2595 *
2596 * Returns 0 on success.
2597 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002598int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 struct file *filp,
2600 void __user *buffer,
2601 size_t *lenp, loff_t *ppos)
2602{
2603 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2604 lenp, ppos, HZ, 1000l);
2605}
2606
2607
2608static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2609 int *valp,
2610 int write, void *data)
2611{
2612 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002613 if (*lvalp > LONG_MAX / HZ)
2614 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2616 } else {
2617 int val = *valp;
2618 unsigned long lval;
2619 if (val < 0) {
2620 *negp = -1;
2621 lval = (unsigned long)-val;
2622 } else {
2623 *negp = 0;
2624 lval = (unsigned long)val;
2625 }
2626 *lvalp = lval / HZ;
2627 }
2628 return 0;
2629}
2630
2631static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2632 int *valp,
2633 int write, void *data)
2634{
2635 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002636 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2637 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2639 } else {
2640 int val = *valp;
2641 unsigned long lval;
2642 if (val < 0) {
2643 *negp = -1;
2644 lval = (unsigned long)-val;
2645 } else {
2646 *negp = 0;
2647 lval = (unsigned long)val;
2648 }
2649 *lvalp = jiffies_to_clock_t(lval);
2650 }
2651 return 0;
2652}
2653
2654static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2655 int *valp,
2656 int write, void *data)
2657{
2658 if (write) {
2659 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2660 } else {
2661 int val = *valp;
2662 unsigned long lval;
2663 if (val < 0) {
2664 *negp = -1;
2665 lval = (unsigned long)-val;
2666 } else {
2667 *negp = 0;
2668 lval = (unsigned long)val;
2669 }
2670 *lvalp = jiffies_to_msecs(lval);
2671 }
2672 return 0;
2673}
2674
2675/**
2676 * proc_dointvec_jiffies - read a vector of integers as seconds
2677 * @table: the sysctl table
2678 * @write: %TRUE if this is a write to the sysctl file
2679 * @filp: the file structure
2680 * @buffer: the user buffer
2681 * @lenp: the size of the user buffer
2682 * @ppos: file position
2683 *
2684 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2685 * values from/to the user buffer, treated as an ASCII string.
2686 * The values read are assumed to be in seconds, and are converted into
2687 * jiffies.
2688 *
2689 * Returns 0 on success.
2690 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002691int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 void __user *buffer, size_t *lenp, loff_t *ppos)
2693{
2694 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2695 do_proc_dointvec_jiffies_conv,NULL);
2696}
2697
2698/**
2699 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2700 * @table: the sysctl table
2701 * @write: %TRUE if this is a write to the sysctl file
2702 * @filp: the file structure
2703 * @buffer: the user buffer
2704 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002705 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 *
2707 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2708 * values from/to the user buffer, treated as an ASCII string.
2709 * The values read are assumed to be in 1/USER_HZ seconds, and
2710 * are converted into jiffies.
2711 *
2712 * Returns 0 on success.
2713 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002714int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 void __user *buffer, size_t *lenp, loff_t *ppos)
2716{
2717 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2718 do_proc_dointvec_userhz_jiffies_conv,NULL);
2719}
2720
2721/**
2722 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2723 * @table: the sysctl table
2724 * @write: %TRUE if this is a write to the sysctl file
2725 * @filp: the file structure
2726 * @buffer: the user buffer
2727 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002728 * @ppos: file position
2729 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 *
2731 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2732 * values from/to the user buffer, treated as an ASCII string.
2733 * The values read are assumed to be in 1/1000 seconds, and
2734 * are converted into jiffies.
2735 *
2736 * Returns 0 on success.
2737 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002738int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 void __user *buffer, size_t *lenp, loff_t *ppos)
2740{
2741 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2742 do_proc_dointvec_ms_jiffies_conv, NULL);
2743}
2744
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002745static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002746 void __user *buffer, size_t *lenp, loff_t *ppos)
2747{
2748 struct pid *new_pid;
2749 pid_t tmp;
2750 int r;
2751
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002752 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002753
2754 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2755 lenp, ppos, NULL, NULL);
2756 if (r || !write)
2757 return r;
2758
2759 new_pid = find_get_pid(tmp);
2760 if (!new_pid)
2761 return -ESRCH;
2762
2763 put_pid(xchg(&cad_pid, new_pid));
2764 return 0;
2765}
2766
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767#else /* CONFIG_PROC_FS */
2768
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002769int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 void __user *buffer, size_t *lenp, loff_t *ppos)
2771{
2772 return -ENOSYS;
2773}
2774
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002775int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 void __user *buffer, size_t *lenp, loff_t *ppos)
2777{
2778 return -ENOSYS;
2779}
2780
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002781int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 void __user *buffer, size_t *lenp, loff_t *ppos)
2783{
2784 return -ENOSYS;
2785}
2786
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002787int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 void __user *buffer, size_t *lenp, loff_t *ppos)
2789{
2790 return -ENOSYS;
2791}
2792
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002793int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 void __user *buffer, size_t *lenp, loff_t *ppos)
2795{
2796 return -ENOSYS;
2797}
2798
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002799int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 void __user *buffer, size_t *lenp, loff_t *ppos)
2801{
2802 return -ENOSYS;
2803}
2804
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002805int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 void __user *buffer, size_t *lenp, loff_t *ppos)
2807{
2808 return -ENOSYS;
2809}
2810
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002811int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 struct file *filp,
2813 void __user *buffer,
2814 size_t *lenp, loff_t *ppos)
2815{
2816 return -ENOSYS;
2817}
2818
2819
2820#endif /* CONFIG_PROC_FS */
2821
2822
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002823#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824/*
2825 * General sysctl support routines
2826 */
2827
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002828/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002829int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002830 void __user *oldval, size_t __user *oldlenp,
2831 void __user *newval, size_t newlen)
2832{
2833 size_t len;
2834
2835 /* Get out of I don't have a variable */
2836 if (!table->data || !table->maxlen)
2837 return -ENOTDIR;
2838
2839 if (oldval && oldlenp) {
2840 if (get_user(len, oldlenp))
2841 return -EFAULT;
2842 if (len) {
2843 if (len > table->maxlen)
2844 len = table->maxlen;
2845 if (copy_to_user(oldval, table->data, len))
2846 return -EFAULT;
2847 if (put_user(len, oldlenp))
2848 return -EFAULT;
2849 }
2850 }
2851
2852 if (newval && newlen) {
2853 if (newlen > table->maxlen)
2854 newlen = table->maxlen;
2855
2856 if (copy_from_user(table->data, newval, newlen))
2857 return -EFAULT;
2858 }
2859 return 1;
2860}
2861
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002863int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002865 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 if (!table->data || !table->maxlen)
2868 return -ENOTDIR;
2869
2870 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002871 size_t bufsize;
2872 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002874 if (bufsize) {
2875 size_t len = strlen(table->data), copied;
2876
2877 /* This shouldn't trigger for a well-formed sysctl */
2878 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002880
2881 /* Copy up to a max of bufsize-1 bytes of the string */
2882 copied = (len >= bufsize) ? bufsize - 1 : len;
2883
2884 if (copy_to_user(oldval, table->data, copied) ||
2885 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002887 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 return -EFAULT;
2889 }
2890 }
2891 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002892 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 if (len > table->maxlen)
2894 len = table->maxlen;
2895 if(copy_from_user(table->data, newval, len))
2896 return -EFAULT;
2897 if (len == table->maxlen)
2898 len--;
2899 ((char *) table->data)[len] = 0;
2900 }
Yi Yang82c9df82005-12-30 16:37:10 +08002901 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902}
2903
2904/*
2905 * This function makes sure that all of the integers in the vector
2906 * are between the minimum and maximum values given in the arrays
2907 * table->extra1 and table->extra2, respectively.
2908 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002909int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002911 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912{
2913
2914 if (newval && newlen) {
2915 int __user *vec = (int __user *) newval;
2916 int *min = (int *) table->extra1;
2917 int *max = (int *) table->extra2;
2918 size_t length;
2919 int i;
2920
2921 if (newlen % sizeof(int) != 0)
2922 return -EINVAL;
2923
2924 if (!table->extra1 && !table->extra2)
2925 return 0;
2926
2927 if (newlen > table->maxlen)
2928 newlen = table->maxlen;
2929 length = newlen / sizeof(int);
2930
2931 for (i = 0; i < length; i++) {
2932 int value;
2933 if (get_user(value, vec + i))
2934 return -EFAULT;
2935 if (min && value < min[i])
2936 return -EINVAL;
2937 if (max && value > max[i])
2938 return -EINVAL;
2939 }
2940 }
2941 return 0;
2942}
2943
2944/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002945int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002947 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002949 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002951
2952 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002954 if (olen) {
2955 int val;
2956
2957 if (olen < sizeof(int))
2958 return -EINVAL;
2959
2960 val = *(int *)(table->data) / HZ;
2961 if (put_user(val, (int __user *)oldval))
2962 return -EFAULT;
2963 if (put_user(sizeof(int), oldlenp))
2964 return -EFAULT;
2965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 }
2967 if (newval && newlen) {
2968 int new;
2969 if (newlen != sizeof(int))
2970 return -EINVAL;
2971 if (get_user(new, (int __user *)newval))
2972 return -EFAULT;
2973 *(int *)(table->data) = new*HZ;
2974 }
2975 return 1;
2976}
2977
2978/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002979int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002981 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002983 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002985
2986 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002988 if (olen) {
2989 int val;
2990
2991 if (olen < sizeof(int))
2992 return -EINVAL;
2993
2994 val = jiffies_to_msecs(*(int *)(table->data));
2995 if (put_user(val, (int __user *)oldval))
2996 return -EFAULT;
2997 if (put_user(sizeof(int), oldlenp))
2998 return -EFAULT;
2999 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 }
3001 if (newval && newlen) {
3002 int new;
3003 if (newlen != sizeof(int))
3004 return -EINVAL;
3005 if (get_user(new, (int __user *)newval))
3006 return -EFAULT;
3007 *(int *)(table->data) = msecs_to_jiffies(new);
3008 }
3009 return 1;
3010}
3011
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003012
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003013
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003014#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
3016
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003017SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003019 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003020 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003021
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003022 if (copy_from_user(&tmp, args, sizeof(tmp)))
3023 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003024
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003025 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003026
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003027 /* If no error reading the parameters then just -ENOSYS ... */
3028 if (!error)
3029 error = -ENOSYS;
3030
3031 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032}
3033
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003034int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003035 void __user *oldval, size_t __user *oldlenp,
3036 void __user *newval, size_t newlen)
3037{
3038 return -ENOSYS;
3039}
3040
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003041int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003043 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044{
3045 return -ENOSYS;
3046}
3047
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003048int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003050 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051{
3052 return -ENOSYS;
3053}
3054
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003055int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003057 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058{
3059 return -ENOSYS;
3060}
3061
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003062int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003064 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065{
3066 return -ENOSYS;
3067}
3068
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003069#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003071static int deprecated_sysctl_warning(struct __sysctl_args *args)
3072{
3073 static int msg_count;
3074 int name[CTL_MAXNAME];
3075 int i;
3076
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003077 /* Check args->nlen. */
3078 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3079 return -ENOTDIR;
3080
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003081 /* Read in the sysctl name for better debug message logging */
3082 for (i = 0; i < args->nlen; i++)
3083 if (get_user(name[i], args->name + i))
3084 return -EFAULT;
3085
3086 /* Ignore accesses to kernel.version */
3087 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3088 return 0;
3089
3090 if (msg_count < 5) {
3091 msg_count++;
3092 printk(KERN_INFO
3093 "warning: process `%s' used the deprecated sysctl "
3094 "system call with ", current->comm);
3095 for (i = 0; i < args->nlen; i++)
3096 printk("%d.", name[i]);
3097 printk("\n");
3098 }
3099 return 0;
3100}
3101
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102/*
3103 * No sense putting this after each symbol definition, twice,
3104 * exception granted :-)
3105 */
3106EXPORT_SYMBOL(proc_dointvec);
3107EXPORT_SYMBOL(proc_dointvec_jiffies);
3108EXPORT_SYMBOL(proc_dointvec_minmax);
3109EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3110EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3111EXPORT_SYMBOL(proc_dostring);
3112EXPORT_SYMBOL(proc_doulongvec_minmax);
3113EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3114EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003115EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116EXPORT_SYMBOL(sysctl_intvec);
3117EXPORT_SYMBOL(sysctl_jiffies);
3118EXPORT_SYMBOL(sysctl_ms_jiffies);
3119EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003120EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121EXPORT_SYMBOL(unregister_sysctl_table);