blob: 3cb1849f59895e9cb09f7b6cbc7f4371bb6bd7d5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Peter Zijlstra1ccd1542009-04-09 10:53:45 +020052#include <linux/perf_counter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <asm/uaccess.h>
55#include <asm/processor.h>
56
Andi Kleen29cbc782006-09-30 01:47:55 +020057#ifdef CONFIG_X86
58#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010059#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010060#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020061#endif
62
Eric W. Biederman7058cb02007-10-18 03:05:58 -070063static int deprecated_sysctl_warning(struct __sysctl_args *args);
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#if defined(CONFIG_SYSCTL)
66
67/* External variables not in a header file. */
68extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070069extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int sysctl_overcommit_memory;
71extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070072extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070073extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080074extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070077extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max;
80extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080082extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080083extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020084extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010085extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040086extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000087#ifndef CONFIG_MMU
88extern int sysctl_nr_trim_pages;
89#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070090#ifdef CONFIG_RCU_TORTURE_TEST
91extern int rcutorture_runnable;
92#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070094/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080095#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020097static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098#endif
99
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700101static int __maybe_unused one = 1;
102static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800103static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700104static int one_hundred = 100;
105
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700106/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
107static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110static int maxolduid = 65535;
111static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800112static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static int ngroups_max = NGROUPS_MAX;
115
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200116#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117extern char modprobe_path[];
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#ifdef CONFIG_CHR_DEV_SG
120extern int sg_big_buff;
121#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
David S. Miller72c57ed2008-09-11 23:29:54 -0700123#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700124#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#endif
126
David S. Miller08714202008-11-16 23:49:24 -0800127#ifdef CONFIG_SPARC64
128extern int sysctl_tsb_ratio;
129#endif
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#ifdef __hppa__
132extern int pwrsw_enabled;
133extern int unaligned_enabled;
134#endif
135
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800136#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef CONFIG_MATHEMU
138extern int sysctl_ieee_emulation_warnings;
139#endif
140extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700141extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef CONFIG_BSD_PROCESS_ACCT
145extern int acct_parm[];
146#endif
147
Jes Sorensend2b176e2006-02-28 09:42:23 -0800148#ifdef CONFIG_IA64
149extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800150extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800151#endif
152
Ingo Molnar23f78d42006-06-27 02:54:53 -0700153#ifdef CONFIG_RT_MUTEXES
154extern int max_lock_depth;
155#endif
156
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700159 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700160static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800161 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700162#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700163
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700164static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100165static struct ctl_table_root sysctl_table_root;
166static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100167 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400169 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100170 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400171 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100172};
173static struct ctl_table_root sysctl_table_root = {
174 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400175 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700178static struct ctl_table kern_table[];
179static struct ctl_table vm_table[];
180static struct ctl_table fs_table[];
181static struct ctl_table debug_table[];
182static struct ctl_table dev_table[];
183extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700184#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700185extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400186#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800187#ifdef CONFIG_EPOLL
188extern struct ctl_table epoll_table[];
189#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
192int sysctl_legacy_va_layout;
193#endif
194
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700195extern int prove_locking;
196extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/* The default sysctl tables: */
199
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700200static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 {
202 .ctl_name = CTL_KERN,
203 .procname = "kernel",
204 .mode = 0555,
205 .child = kern_table,
206 },
207 {
208 .ctl_name = CTL_VM,
209 .procname = "vm",
210 .mode = 0555,
211 .child = vm_table,
212 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .ctl_name = CTL_FS,
215 .procname = "fs",
216 .mode = 0555,
217 .child = fs_table,
218 },
219 {
220 .ctl_name = CTL_DEBUG,
221 .procname = "debug",
222 .mode = 0555,
223 .child = debug_table,
224 },
225 {
226 .ctl_name = CTL_DEV,
227 .procname = "dev",
228 .mode = 0555,
229 .child = dev_table,
230 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700231/*
232 * NOTE: do not add new entries to this table unless you have read
233 * Documentation/sysctl/ctl_unnumbered.txt
234 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 { .ctl_name = 0 }
236};
237
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100239static int min_sched_granularity_ns = 100000; /* 100 usecs */
240static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
241static int min_wakeup_granularity_ns; /* 0 usecs */
242static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243#endif
244
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700245static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246#ifdef CONFIG_SCHED_DEBUG
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100249 .procname = "sched_min_granularity_ns",
250 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200260 .procname = "sched_latency_ns",
261 .data = &sysctl_sched_latency,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100264 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200265 .strategy = &sysctl_intvec,
266 .extra1 = &min_sched_granularity_ns,
267 .extra2 = &max_sched_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200271 .procname = "sched_wakeup_granularity_ns",
272 .data = &sysctl_sched_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200282 .procname = "sched_shares_ratelimit",
283 .data = &sysctl_sched_shares_ratelimit,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
287 },
288 {
289 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200290 .procname = "sched_shares_thresh",
291 .data = &sysctl_sched_shares_thresh,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
296 .extra1 = &zero,
297 },
298 {
299 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200300 .procname = "sched_child_runs_first",
301 .data = &sysctl_sched_child_runs_first,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200306 {
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_features",
309 .data = &sysctl_sched_features,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
313 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200314 {
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100322 {
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
329 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200330#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200331 {
332 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100333 .procname = "sched_rt_period_us",
334 .data = &sysctl_sched_rt_period,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200337 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100338 },
339 {
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_rt_runtime_us",
342 .data = &sysctl_sched_rt_runtime,
343 .maxlen = sizeof(int),
344 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200345 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100346 },
347 {
348 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200349 .procname = "sched_compat_yield",
350 .data = &sysctl_sched_compat_yield,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = &proc_dointvec,
354 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700355#ifdef CONFIG_PROVE_LOCKING
356 {
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
364#endif
365#ifdef CONFIG_LOCK_STAT
366 {
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "lock_stat",
369 .data = &lock_stat,
370 .maxlen = sizeof(int),
371 .mode = 0644,
372 .proc_handler = &proc_dointvec,
373 },
374#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .ctl_name = KERN_PANIC,
377 .procname = "panic",
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383 {
384 .ctl_name = KERN_CORE_USES_PID,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
391 {
392 .ctl_name = KERN_CORE_PATTERN,
393 .procname = "core_pattern",
394 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700395 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 .mode = 0644,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
399 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800400#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700403 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800404 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700405 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800407#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100408#ifdef CONFIG_LATENCYTOP
409 {
410 .procname = "latencytop",
411 .data = &latencytop_enabled,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = &proc_dointvec,
415 },
416#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#ifdef CONFIG_BLK_DEV_INITRD
418 {
419 .ctl_name = KERN_REALROOTDEV,
420 .procname = "real-root-dev",
421 .data = &real_root_dev,
422 .maxlen = sizeof(int),
423 .mode = 0644,
424 .proc_handler = &proc_dointvec,
425 },
426#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700427 {
428 .ctl_name = CTL_UNNUMBERED,
429 .procname = "print-fatal-signals",
430 .data = &print_fatal_signals,
431 .maxlen = sizeof(int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700435#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 {
437 .ctl_name = KERN_SPARC_REBOOT,
438 .procname = "reboot-cmd",
439 .data = reboot_command,
440 .maxlen = 256,
441 .mode = 0644,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
444 },
445 {
446 .ctl_name = KERN_SPARC_STOP_A,
447 .procname = "stop-a",
448 .data = &stop_a_enabled,
449 .maxlen = sizeof (int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec,
452 },
453 {
454 .ctl_name = KERN_SPARC_SCONS_PWROFF,
455 .procname = "scons-poweroff",
456 .data = &scons_pwroff,
457 .maxlen = sizeof (int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
460 },
461#endif
David S. Miller08714202008-11-16 23:49:24 -0800462#ifdef CONFIG_SPARC64
463 {
464 .ctl_name = CTL_UNNUMBERED,
465 .procname = "tsb-ratio",
466 .data = &sysctl_tsb_ratio,
467 .maxlen = sizeof (int),
468 .mode = 0644,
469 .proc_handler = &proc_dointvec,
470 },
471#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#ifdef __hppa__
473 {
474 .ctl_name = KERN_HPPA_PWRSW,
475 .procname = "soft-power",
476 .data = &pwrsw_enabled,
477 .maxlen = sizeof (int),
478 .mode = 0644,
479 .proc_handler = &proc_dointvec,
480 },
481 {
482 .ctl_name = KERN_HPPA_UNALIGNED,
483 .procname = "unaligned-trap",
484 .data = &unaligned_enabled,
485 .maxlen = sizeof (int),
486 .mode = 0644,
487 .proc_handler = &proc_dointvec,
488 },
489#endif
490 {
491 .ctl_name = KERN_CTLALTDEL,
492 .procname = "ctrl-alt-del",
493 .data = &C_A_D,
494 .maxlen = sizeof(int),
495 .mode = 0644,
496 .proc_handler = &proc_dointvec,
497 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400498#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200499 {
500 .ctl_name = CTL_UNNUMBERED,
501 .procname = "ftrace_enabled",
502 .data = &ftrace_enabled,
503 .maxlen = sizeof(int),
504 .mode = 0644,
505 .proc_handler = &ftrace_enable_sysctl,
506 },
507#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500508#ifdef CONFIG_STACK_TRACER
509 {
510 .ctl_name = CTL_UNNUMBERED,
511 .procname = "stack_tracer_enabled",
512 .data = &stack_tracer_enabled,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = &stack_trace_sysctl,
516 },
517#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400518#ifdef CONFIG_TRACING
519 {
520 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100521 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400522 .data = &ftrace_dump_on_oops,
523 .maxlen = sizeof(int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec,
526 },
527#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200528#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 {
530 .ctl_name = KERN_MODPROBE,
531 .procname = "modprobe",
532 .data = &modprobe_path,
533 .maxlen = KMOD_PATH_LEN,
534 .mode = 0644,
535 .proc_handler = &proc_dostring,
536 .strategy = &sysctl_string,
537 },
538#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700539#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
541 .ctl_name = KERN_HOTPLUG,
542 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100543 .data = &uevent_helper,
544 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .mode = 0644,
546 .proc_handler = &proc_dostring,
547 .strategy = &sysctl_string,
548 },
549#endif
550#ifdef CONFIG_CHR_DEV_SG
551 {
552 .ctl_name = KERN_SG_BIG_BUFF,
553 .procname = "sg-big-buff",
554 .data = &sg_big_buff,
555 .maxlen = sizeof (int),
556 .mode = 0444,
557 .proc_handler = &proc_dointvec,
558 },
559#endif
560#ifdef CONFIG_BSD_PROCESS_ACCT
561 {
562 .ctl_name = KERN_ACCT,
563 .procname = "acct",
564 .data = &acct_parm,
565 .maxlen = 3*sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#ifdef CONFIG_MAGIC_SYSRQ
571 {
572 .ctl_name = KERN_SYSRQ,
573 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800574 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .maxlen = sizeof (int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
578 },
579#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700580#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700583 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 .maxlen = sizeof (int),
585 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700586 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 {
590 .ctl_name = KERN_MAX_THREADS,
591 .procname = "threads-max",
592 .data = &max_threads,
593 .maxlen = sizeof(int),
594 .mode = 0644,
595 .proc_handler = &proc_dointvec,
596 },
597 {
598 .ctl_name = KERN_RANDOM,
599 .procname = "random",
600 .mode = 0555,
601 .child = random_table,
602 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 {
604 .ctl_name = KERN_OVERFLOWUID,
605 .procname = "overflowuid",
606 .data = &overflowuid,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec_minmax,
610 .strategy = &sysctl_intvec,
611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
613 },
614 {
615 .ctl_name = KERN_OVERFLOWGID,
616 .procname = "overflowgid",
617 .data = &overflowgid,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec_minmax,
621 .strategy = &sysctl_intvec,
622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
624 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800625#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#ifdef CONFIG_MATHEMU
627 {
628 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
629 .procname = "ieee_emulation_warnings",
630 .data = &sysctl_ieee_emulation_warnings,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
634 },
635#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 {
637 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
638 .procname = "userprocess_debug",
639 .data = &sysctl_userprocess_debug,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec,
643 },
644#endif
645 {
646 .ctl_name = KERN_PIDMAX,
647 .procname = "pid_max",
648 .data = &pid_max,
649 .maxlen = sizeof (int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec_minmax,
652 .strategy = sysctl_intvec,
653 .extra1 = &pid_max_min,
654 .extra2 = &pid_max_max,
655 },
656 {
657 .ctl_name = KERN_PANIC_ON_OOPS,
658 .procname = "panic_on_oops",
659 .data = &panic_on_oops,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800664#if defined CONFIG_PRINTK
665 {
666 .ctl_name = KERN_PRINTK,
667 .procname = "printk",
668 .data = &console_loglevel,
669 .maxlen = 4*sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 {
674 .ctl_name = KERN_PRINTK_RATELIMIT,
675 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700676 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec_jiffies,
680 .strategy = &sysctl_jiffies,
681 },
682 {
683 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
684 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700685 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec,
689 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800690#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 {
692 .ctl_name = KERN_NGROUPS_MAX,
693 .procname = "ngroups_max",
694 .data = &ngroups_max,
695 .maxlen = sizeof (int),
696 .mode = 0444,
697 .proc_handler = &proc_dointvec,
698 },
699#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
700 {
701 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
702 .procname = "unknown_nmi_panic",
703 .data = &unknown_nmi_panic,
704 .maxlen = sizeof (int),
705 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200706 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
Don Zickus407984f2006-09-26 10:52:27 +0200708 {
Don Zickus407984f2006-09-26 10:52:27 +0200709 .procname = "nmi_watchdog",
710 .data = &nmi_watchdog_enabled,
711 .maxlen = sizeof (int),
712 .mode = 0644,
713 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 },
715#endif
716#if defined(CONFIG_X86)
717 {
Don Zickus8da5add2006-09-26 10:52:27 +0200718 .ctl_name = KERN_PANIC_ON_NMI,
719 .procname = "panic_on_unrecovered_nmi",
720 .data = &panic_on_unrecovered_nmi,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec,
724 },
725 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .ctl_name = KERN_BOOTLOADER_TYPE,
727 .procname = "bootloader_type",
728 .data = &bootloader_type,
729 .maxlen = sizeof (int),
730 .mode = 0444,
731 .proc_handler = &proc_dointvec,
732 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100733 {
734 .ctl_name = CTL_UNNUMBERED,
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
David Howells12e22c52009-04-03 16:42:35 +0100908#ifdef CONFIG_SLOW_WORK
909 {
910 .ctl_name = CTL_UNNUMBERED,
911 .procname = "slow-work",
912 .mode = 0555,
913 .child = slow_work_sysctls,
914 },
915#endif
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200916#ifdef CONFIG_PERF_COUNTERS
917 {
918 .ctl_name = CTL_UNNUMBERED,
919 .procname = "perf_counter_privileged",
920 .data = &sysctl_perf_counter_priv,
921 .maxlen = sizeof(sysctl_perf_counter_priv),
922 .mode = 0644,
923 .proc_handler = &proc_dointvec,
924 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200925 {
926 .ctl_name = CTL_UNNUMBERED,
927 .procname = "perf_counter_mlock_kb",
928 .data = &sysctl_perf_counter_mlock,
929 .maxlen = sizeof(sysctl_perf_counter_mlock),
930 .mode = 0644,
931 .proc_handler = &proc_dointvec,
932 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200933#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700934/*
935 * NOTE: do not add new entries to this table unless you have read
936 * Documentation/sysctl/ctl_unnumbered.txt
937 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 { .ctl_name = 0 }
939};
940
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700941static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 {
943 .ctl_name = VM_OVERCOMMIT_MEMORY,
944 .procname = "overcommit_memory",
945 .data = &sysctl_overcommit_memory,
946 .maxlen = sizeof(sysctl_overcommit_memory),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec,
949 },
950 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700951 .ctl_name = VM_PANIC_ON_OOM,
952 .procname = "panic_on_oom",
953 .data = &sysctl_panic_on_oom,
954 .maxlen = sizeof(sysctl_panic_on_oom),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec,
957 },
958 {
David Rientjesfe071d72007-10-16 23:25:56 -0700959 .ctl_name = CTL_UNNUMBERED,
960 .procname = "oom_kill_allocating_task",
961 .data = &sysctl_oom_kill_allocating_task,
962 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 },
966 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800967 .ctl_name = CTL_UNNUMBERED,
968 .procname = "oom_dump_tasks",
969 .data = &sysctl_oom_dump_tasks,
970 .maxlen = sizeof(sysctl_oom_dump_tasks),
971 .mode = 0644,
972 .proc_handler = &proc_dointvec,
973 },
974 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 .ctl_name = VM_OVERCOMMIT_RATIO,
976 .procname = "overcommit_ratio",
977 .data = &sysctl_overcommit_ratio,
978 .maxlen = sizeof(sysctl_overcommit_ratio),
979 .mode = 0644,
980 .proc_handler = &proc_dointvec,
981 },
982 {
983 .ctl_name = VM_PAGE_CLUSTER,
984 .procname = "page-cluster",
985 .data = &page_cluster,
986 .maxlen = sizeof(int),
987 .mode = 0644,
988 .proc_handler = &proc_dointvec,
989 },
990 {
991 .ctl_name = VM_DIRTY_BACKGROUND,
992 .procname = "dirty_background_ratio",
993 .data = &dirty_background_ratio,
994 .maxlen = sizeof(dirty_background_ratio),
995 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800996 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 .strategy = &sysctl_intvec,
998 .extra1 = &zero,
999 .extra2 = &one_hundred,
1000 },
1001 {
David Rientjes2da02992009-01-06 14:39:31 -08001002 .ctl_name = CTL_UNNUMBERED,
1003 .procname = "dirty_background_bytes",
1004 .data = &dirty_background_bytes,
1005 .maxlen = sizeof(dirty_background_bytes),
1006 .mode = 0644,
1007 .proc_handler = &dirty_background_bytes_handler,
1008 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001009 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001010 },
1011 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .ctl_name = VM_DIRTY_RATIO,
1013 .procname = "dirty_ratio",
1014 .data = &vm_dirty_ratio,
1015 .maxlen = sizeof(vm_dirty_ratio),
1016 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001017 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 .strategy = &sysctl_intvec,
1019 .extra1 = &zero,
1020 .extra2 = &one_hundred,
1021 },
1022 {
David Rientjes2da02992009-01-06 14:39:31 -08001023 .ctl_name = CTL_UNNUMBERED,
1024 .procname = "dirty_bytes",
1025 .data = &vm_dirty_bytes,
1026 .maxlen = sizeof(vm_dirty_bytes),
1027 .mode = 0644,
1028 .proc_handler = &dirty_bytes_handler,
1029 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001030 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001031 },
1032 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001034 .data = &dirty_writeback_interval,
1035 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .mode = 0644,
1037 .proc_handler = &dirty_writeback_centisecs_handler,
1038 },
1039 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001041 .data = &dirty_expire_interval,
1042 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001044 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 },
1046 {
1047 .ctl_name = VM_NR_PDFLUSH_THREADS,
1048 .procname = "nr_pdflush_threads",
1049 .data = &nr_pdflush_threads,
1050 .maxlen = sizeof nr_pdflush_threads,
1051 .mode = 0444 /* read-only*/,
1052 .proc_handler = &proc_dointvec,
1053 },
1054 {
1055 .ctl_name = VM_SWAPPINESS,
1056 .procname = "swappiness",
1057 .data = &vm_swappiness,
1058 .maxlen = sizeof(vm_swappiness),
1059 .mode = 0644,
1060 .proc_handler = &proc_dointvec_minmax,
1061 .strategy = &sysctl_intvec,
1062 .extra1 = &zero,
1063 .extra2 = &one_hundred,
1064 },
1065#ifdef CONFIG_HUGETLB_PAGE
1066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001068 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 .maxlen = sizeof(unsigned long),
1070 .mode = 0644,
1071 .proc_handler = &hugetlb_sysctl_handler,
1072 .extra1 = (void *)&hugetlb_zero,
1073 .extra2 = (void *)&hugetlb_infinity,
1074 },
1075 {
1076 .ctl_name = VM_HUGETLB_GROUP,
1077 .procname = "hugetlb_shm_group",
1078 .data = &sysctl_hugetlb_shm_group,
1079 .maxlen = sizeof(gid_t),
1080 .mode = 0644,
1081 .proc_handler = &proc_dointvec,
1082 },
Mel Gorman396faf02007-07-17 04:03:13 -07001083 {
1084 .ctl_name = CTL_UNNUMBERED,
1085 .procname = "hugepages_treat_as_movable",
1086 .data = &hugepages_treat_as_movable,
1087 .maxlen = sizeof(int),
1088 .mode = 0644,
1089 .proc_handler = &hugetlb_treat_movable_handler,
1090 },
Adam Litke54f9f802007-10-16 01:26:20 -07001091 {
1092 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001093 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001094 .data = NULL,
1095 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001096 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001097 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001098 .extra1 = (void *)&hugetlb_zero,
1099 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001100 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101#endif
1102 {
1103 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1104 .procname = "lowmem_reserve_ratio",
1105 .data = &sysctl_lowmem_reserve_ratio,
1106 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1107 .mode = 0644,
1108 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1109 .strategy = &sysctl_intvec,
1110 },
1111 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001112 .ctl_name = VM_DROP_PAGECACHE,
1113 .procname = "drop_caches",
1114 .data = &sysctl_drop_caches,
1115 .maxlen = sizeof(int),
1116 .mode = 0644,
1117 .proc_handler = drop_caches_sysctl_handler,
1118 .strategy = &sysctl_intvec,
1119 },
1120 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 .ctl_name = VM_MIN_FREE_KBYTES,
1122 .procname = "min_free_kbytes",
1123 .data = &min_free_kbytes,
1124 .maxlen = sizeof(min_free_kbytes),
1125 .mode = 0644,
1126 .proc_handler = &min_free_kbytes_sysctl_handler,
1127 .strategy = &sysctl_intvec,
1128 .extra1 = &zero,
1129 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001130 {
1131 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1132 .procname = "percpu_pagelist_fraction",
1133 .data = &percpu_pagelist_fraction,
1134 .maxlen = sizeof(percpu_pagelist_fraction),
1135 .mode = 0644,
1136 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1137 .strategy = &sysctl_intvec,
1138 .extra1 = &min_percpu_pagelist_fract,
1139 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140#ifdef CONFIG_MMU
1141 {
1142 .ctl_name = VM_MAX_MAP_COUNT,
1143 .procname = "max_map_count",
1144 .data = &sysctl_max_map_count,
1145 .maxlen = sizeof(sysctl_max_map_count),
1146 .mode = 0644,
1147 .proc_handler = &proc_dointvec
1148 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001149#else
1150 {
1151 .ctl_name = CTL_UNNUMBERED,
1152 .procname = "nr_trim_pages",
1153 .data = &sysctl_nr_trim_pages,
1154 .maxlen = sizeof(sysctl_nr_trim_pages),
1155 .mode = 0644,
1156 .proc_handler = &proc_dointvec_minmax,
1157 .strategy = &sysctl_intvec,
1158 .extra1 = &zero,
1159 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160#endif
1161 {
1162 .ctl_name = VM_LAPTOP_MODE,
1163 .procname = "laptop_mode",
1164 .data = &laptop_mode,
1165 .maxlen = sizeof(laptop_mode),
1166 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001167 .proc_handler = &proc_dointvec_jiffies,
1168 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 },
1170 {
1171 .ctl_name = VM_BLOCK_DUMP,
1172 .procname = "block_dump",
1173 .data = &block_dump,
1174 .maxlen = sizeof(block_dump),
1175 .mode = 0644,
1176 .proc_handler = &proc_dointvec,
1177 .strategy = &sysctl_intvec,
1178 .extra1 = &zero,
1179 },
1180 {
1181 .ctl_name = VM_VFS_CACHE_PRESSURE,
1182 .procname = "vfs_cache_pressure",
1183 .data = &sysctl_vfs_cache_pressure,
1184 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1185 .mode = 0644,
1186 .proc_handler = &proc_dointvec,
1187 .strategy = &sysctl_intvec,
1188 .extra1 = &zero,
1189 },
1190#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1191 {
1192 .ctl_name = VM_LEGACY_VA_LAYOUT,
1193 .procname = "legacy_va_layout",
1194 .data = &sysctl_legacy_va_layout,
1195 .maxlen = sizeof(sysctl_legacy_va_layout),
1196 .mode = 0644,
1197 .proc_handler = &proc_dointvec,
1198 .strategy = &sysctl_intvec,
1199 .extra1 = &zero,
1200 },
1201#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001202#ifdef CONFIG_NUMA
1203 {
1204 .ctl_name = VM_ZONE_RECLAIM_MODE,
1205 .procname = "zone_reclaim_mode",
1206 .data = &zone_reclaim_mode,
1207 .maxlen = sizeof(zone_reclaim_mode),
1208 .mode = 0644,
1209 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001210 .strategy = &sysctl_intvec,
1211 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001212 },
Christoph Lameter96146342006-07-03 00:24:13 -07001213 {
1214 .ctl_name = VM_MIN_UNMAPPED,
1215 .procname = "min_unmapped_ratio",
1216 .data = &sysctl_min_unmapped_ratio,
1217 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1218 .mode = 0644,
1219 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1220 .strategy = &sysctl_intvec,
1221 .extra1 = &zero,
1222 .extra2 = &one_hundred,
1223 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001224 {
1225 .ctl_name = VM_MIN_SLAB,
1226 .procname = "min_slab_ratio",
1227 .data = &sysctl_min_slab_ratio,
1228 .maxlen = sizeof(sysctl_min_slab_ratio),
1229 .mode = 0644,
1230 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1231 .strategy = &sysctl_intvec,
1232 .extra1 = &zero,
1233 .extra2 = &one_hundred,
1234 },
Christoph Lameter17436602006-01-18 17:42:32 -08001235#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001236#ifdef CONFIG_SMP
1237 {
1238 .ctl_name = CTL_UNNUMBERED,
1239 .procname = "stat_interval",
1240 .data = &sysctl_stat_interval,
1241 .maxlen = sizeof(sysctl_stat_interval),
1242 .mode = 0644,
1243 .proc_handler = &proc_dointvec_jiffies,
1244 .strategy = &sysctl_jiffies,
1245 },
1246#endif
Eric Parised032182007-06-28 15:55:21 -04001247#ifdef CONFIG_SECURITY
1248 {
1249 .ctl_name = CTL_UNNUMBERED,
1250 .procname = "mmap_min_addr",
1251 .data = &mmap_min_addr,
1252 .maxlen = sizeof(unsigned long),
1253 .mode = 0644,
1254 .proc_handler = &proc_doulongvec_minmax,
1255 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001256#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001257#ifdef CONFIG_NUMA
1258 {
1259 .ctl_name = CTL_UNNUMBERED,
1260 .procname = "numa_zonelist_order",
1261 .data = &numa_zonelist_order,
1262 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1263 .mode = 0644,
1264 .proc_handler = &numa_zonelist_order_handler,
1265 .strategy = &sysctl_string,
1266 },
1267#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001268#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001269 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001270 {
1271 .ctl_name = VM_VDSO_ENABLED,
1272 .procname = "vdso_enabled",
1273 .data = &vdso_enabled,
1274 .maxlen = sizeof(vdso_enabled),
1275 .mode = 0644,
1276 .proc_handler = &proc_dointvec,
1277 .strategy = &sysctl_intvec,
1278 .extra1 = &zero,
1279 },
1280#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001281#ifdef CONFIG_HIGHMEM
1282 {
1283 .ctl_name = CTL_UNNUMBERED,
1284 .procname = "highmem_is_dirtyable",
1285 .data = &vm_highmem_is_dirtyable,
1286 .maxlen = sizeof(vm_highmem_is_dirtyable),
1287 .mode = 0644,
1288 .proc_handler = &proc_dointvec_minmax,
1289 .strategy = &sysctl_intvec,
1290 .extra1 = &zero,
1291 .extra2 = &one,
1292 },
1293#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001294#ifdef CONFIG_UNEVICTABLE_LRU
1295 {
1296 .ctl_name = CTL_UNNUMBERED,
1297 .procname = "scan_unevictable_pages",
1298 .data = &scan_unevictable_pages,
1299 .maxlen = sizeof(scan_unevictable_pages),
1300 .mode = 0644,
1301 .proc_handler = &scan_unevictable_handler,
1302 },
1303#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001304/*
1305 * NOTE: do not add new entries to this table unless you have read
1306 * Documentation/sysctl/ctl_unnumbered.txt
1307 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 { .ctl_name = 0 }
1309};
1310
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001311#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001312static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001313 { .ctl_name = 0 }
1314};
1315#endif
1316
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001317static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 {
1319 .ctl_name = FS_NRINODE,
1320 .procname = "inode-nr",
1321 .data = &inodes_stat,
1322 .maxlen = 2*sizeof(int),
1323 .mode = 0444,
1324 .proc_handler = &proc_dointvec,
1325 },
1326 {
1327 .ctl_name = FS_STATINODE,
1328 .procname = "inode-state",
1329 .data = &inodes_stat,
1330 .maxlen = 7*sizeof(int),
1331 .mode = 0444,
1332 .proc_handler = &proc_dointvec,
1333 },
1334 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 .procname = "file-nr",
1336 .data = &files_stat,
1337 .maxlen = 3*sizeof(int),
1338 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001339 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 },
1341 {
1342 .ctl_name = FS_MAXFILE,
1343 .procname = "file-max",
1344 .data = &files_stat.max_files,
1345 .maxlen = sizeof(int),
1346 .mode = 0644,
1347 .proc_handler = &proc_dointvec,
1348 },
1349 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001350 .ctl_name = CTL_UNNUMBERED,
1351 .procname = "nr_open",
1352 .data = &sysctl_nr_open,
1353 .maxlen = sizeof(int),
1354 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001355 .proc_handler = &proc_dointvec_minmax,
1356 .extra1 = &sysctl_nr_open_min,
1357 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001358 },
1359 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 .ctl_name = FS_DENTRY,
1361 .procname = "dentry-state",
1362 .data = &dentry_stat,
1363 .maxlen = 6*sizeof(int),
1364 .mode = 0444,
1365 .proc_handler = &proc_dointvec,
1366 },
1367 {
1368 .ctl_name = FS_OVERFLOWUID,
1369 .procname = "overflowuid",
1370 .data = &fs_overflowuid,
1371 .maxlen = sizeof(int),
1372 .mode = 0644,
1373 .proc_handler = &proc_dointvec_minmax,
1374 .strategy = &sysctl_intvec,
1375 .extra1 = &minolduid,
1376 .extra2 = &maxolduid,
1377 },
1378 {
1379 .ctl_name = FS_OVERFLOWGID,
1380 .procname = "overflowgid",
1381 .data = &fs_overflowgid,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = &proc_dointvec_minmax,
1385 .strategy = &sysctl_intvec,
1386 .extra1 = &minolduid,
1387 .extra2 = &maxolduid,
1388 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001389#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 {
1391 .ctl_name = FS_LEASES,
1392 .procname = "leases-enable",
1393 .data = &leases_enable,
1394 .maxlen = sizeof(int),
1395 .mode = 0644,
1396 .proc_handler = &proc_dointvec,
1397 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001398#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399#ifdef CONFIG_DNOTIFY
1400 {
1401 .ctl_name = FS_DIR_NOTIFY,
1402 .procname = "dir-notify-enable",
1403 .data = &dir_notify_enable,
1404 .maxlen = sizeof(int),
1405 .mode = 0644,
1406 .proc_handler = &proc_dointvec,
1407 },
1408#endif
1409#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001410#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 {
1412 .ctl_name = FS_LEASE_TIME,
1413 .procname = "lease-break-time",
1414 .data = &lease_break_time,
1415 .maxlen = sizeof(int),
1416 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001417 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001419#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001420#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 .procname = "aio-nr",
1423 .data = &aio_nr,
1424 .maxlen = sizeof(aio_nr),
1425 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001426 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 },
1428 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 .procname = "aio-max-nr",
1430 .data = &aio_max_nr,
1431 .maxlen = sizeof(aio_max_nr),
1432 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001433 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001435#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001436#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001437 {
1438 .ctl_name = FS_INOTIFY,
1439 .procname = "inotify",
1440 .mode = 0555,
1441 .child = inotify_table,
1442 },
1443#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001444#ifdef CONFIG_EPOLL
1445 {
1446 .procname = "epoll",
1447 .mode = 0555,
1448 .child = epoll_table,
1449 },
1450#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001452 {
1453 .ctl_name = KERN_SETUID_DUMPABLE,
1454 .procname = "suid_dumpable",
1455 .data = &suid_dumpable,
1456 .maxlen = sizeof(int),
1457 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001458 .proc_handler = &proc_dointvec_minmax,
1459 .strategy = &sysctl_intvec,
1460 .extra1 = &zero,
1461 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001462 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001463#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1464 {
1465 .ctl_name = CTL_UNNUMBERED,
1466 .procname = "binfmt_misc",
1467 .mode = 0555,
1468 .child = binfmt_misc_table,
1469 },
1470#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001471/*
1472 * NOTE: do not add new entries to this table unless you have read
1473 * Documentation/sysctl/ctl_unnumbered.txt
1474 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 { .ctl_name = 0 }
1476};
1477
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001478static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001479#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001480 {
1481 .ctl_name = CTL_UNNUMBERED,
1482 .procname = "exception-trace",
1483 .data = &show_unhandled_signals,
1484 .maxlen = sizeof(int),
1485 .mode = 0644,
1486 .proc_handler = proc_dointvec
1487 },
1488#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 { .ctl_name = 0 }
1490};
1491
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001492static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001494};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Al Viro330d57f2005-11-04 10:18:40 +00001496static DEFINE_SPINLOCK(sysctl_lock);
1497
1498/* called under sysctl_lock */
1499static int use_table(struct ctl_table_header *p)
1500{
1501 if (unlikely(p->unregistering))
1502 return 0;
1503 p->used++;
1504 return 1;
1505}
1506
1507/* called under sysctl_lock */
1508static void unuse_table(struct ctl_table_header *p)
1509{
1510 if (!--p->used)
1511 if (unlikely(p->unregistering))
1512 complete(p->unregistering);
1513}
1514
1515/* called under sysctl_lock, will reacquire if has to wait */
1516static void start_unregistering(struct ctl_table_header *p)
1517{
1518 /*
1519 * if p->used is 0, nobody will ever touch that entry again;
1520 * we'll eliminate all paths to it before dropping sysctl_lock
1521 */
1522 if (unlikely(p->used)) {
1523 struct completion wait;
1524 init_completion(&wait);
1525 p->unregistering = &wait;
1526 spin_unlock(&sysctl_lock);
1527 wait_for_completion(&wait);
1528 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001529 } else {
1530 /* anything non-NULL; we'll never dereference it */
1531 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001532 }
1533 /*
1534 * do not remove from the list until nobody holds it; walking the
1535 * list in do_sysctl() relies on that.
1536 */
1537 list_del_init(&p->ctl_entry);
1538}
1539
Al Virof7e6ced2008-07-15 01:44:23 -04001540void sysctl_head_get(struct ctl_table_header *head)
1541{
1542 spin_lock(&sysctl_lock);
1543 head->count++;
1544 spin_unlock(&sysctl_lock);
1545}
1546
1547void sysctl_head_put(struct ctl_table_header *head)
1548{
1549 spin_lock(&sysctl_lock);
1550 if (!--head->count)
1551 kfree(head);
1552 spin_unlock(&sysctl_lock);
1553}
1554
1555struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1556{
1557 if (!head)
1558 BUG();
1559 spin_lock(&sysctl_lock);
1560 if (!use_table(head))
1561 head = ERR_PTR(-ENOENT);
1562 spin_unlock(&sysctl_lock);
1563 return head;
1564}
1565
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001566void sysctl_head_finish(struct ctl_table_header *head)
1567{
1568 if (!head)
1569 return;
1570 spin_lock(&sysctl_lock);
1571 unuse_table(head);
1572 spin_unlock(&sysctl_lock);
1573}
1574
Al Viro73455092008-07-14 21:22:20 -04001575static struct ctl_table_set *
1576lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1577{
1578 struct ctl_table_set *set = &root->default_set;
1579 if (root->lookup)
1580 set = root->lookup(root, namespaces);
1581 return set;
1582}
1583
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001584static struct list_head *
1585lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001586{
Al Viro73455092008-07-14 21:22:20 -04001587 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1588 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001589}
1590
1591struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1592 struct ctl_table_header *prev)
1593{
1594 struct ctl_table_root *root;
1595 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001596 struct ctl_table_header *head;
1597 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001598
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001599 spin_lock(&sysctl_lock);
1600 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001601 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001602 tmp = &prev->ctl_entry;
1603 unuse_table(prev);
1604 goto next;
1605 }
1606 tmp = &root_table_header.ctl_entry;
1607 for (;;) {
1608 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1609
1610 if (!use_table(head))
1611 goto next;
1612 spin_unlock(&sysctl_lock);
1613 return head;
1614 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001615 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001616 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001617 header_list = lookup_header_list(root, namespaces);
1618 if (tmp != header_list)
1619 continue;
1620
1621 do {
1622 root = list_entry(root->root_list.next,
1623 struct ctl_table_root, root_list);
1624 if (root == &sysctl_table_root)
1625 goto out;
1626 header_list = lookup_header_list(root, namespaces);
1627 } while (list_empty(header_list));
1628 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001629 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001630out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001631 spin_unlock(&sysctl_lock);
1632 return NULL;
1633}
1634
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001635struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1636{
1637 return __sysctl_head_next(current->nsproxy, prev);
1638}
1639
1640void register_sysctl_root(struct ctl_table_root *root)
1641{
1642 spin_lock(&sysctl_lock);
1643 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1644 spin_unlock(&sysctl_lock);
1645}
1646
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001647#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001648/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001649static int do_sysctl_strategy(struct ctl_table_root *root,
1650 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001651 void __user *oldval, size_t __user *oldlenp,
1652 void __user *newval, size_t newlen)
1653{
1654 int op = 0, rc;
1655
1656 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001657 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001658 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001659 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001660 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001661 return -EPERM;
1662
1663 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001664 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001665 if (rc < 0)
1666 return rc;
1667 if (rc > 0)
1668 return 0;
1669 }
1670
1671 /* If there is no strategy routine, or if the strategy returns
1672 * zero, proceed with automatic r/w */
1673 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001674 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001675 if (rc < 0)
1676 return rc;
1677 }
1678 return 0;
1679}
1680
1681static int parse_table(int __user *name, int nlen,
1682 void __user *oldval, size_t __user *oldlenp,
1683 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001684 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001685 struct ctl_table *table)
1686{
1687 int n;
1688repeat:
1689 if (!nlen)
1690 return -ENOTDIR;
1691 if (get_user(n, name))
1692 return -EFAULT;
1693 for ( ; table->ctl_name || table->procname; table++) {
1694 if (!table->ctl_name)
1695 continue;
1696 if (n == table->ctl_name) {
1697 int error;
1698 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001699 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001700 return -EPERM;
1701 name++;
1702 nlen--;
1703 table = table->child;
1704 goto repeat;
1705 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001706 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001707 oldval, oldlenp,
1708 newval, newlen);
1709 return error;
1710 }
1711 }
1712 return -ENOTDIR;
1713}
1714
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1716 void __user *newval, size_t newlen)
1717{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001718 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001719 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
1721 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1722 return -ENOTDIR;
1723 if (oldval) {
1724 int old_len;
1725 if (!oldlenp || get_user(old_len, oldlenp))
1726 return -EFAULT;
1727 }
Al Viro330d57f2005-11-04 10:18:40 +00001728
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001729 for (head = sysctl_head_next(NULL); head;
1730 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001731 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001732 newval, newlen,
1733 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001734 if (error != -ENOTDIR) {
1735 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001736 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001737 }
1738 }
Al Viro330d57f2005-11-04 10:18:40 +00001739 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740}
1741
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001742SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743{
1744 struct __sysctl_args tmp;
1745 int error;
1746
1747 if (copy_from_user(&tmp, args, sizeof(tmp)))
1748 return -EFAULT;
1749
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001750 error = deprecated_sysctl_warning(&tmp);
1751 if (error)
1752 goto out;
1753
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 lock_kernel();
1755 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1756 tmp.newval, tmp.newlen);
1757 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001758out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return error;
1760}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001761#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
1763/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001764 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 * some sysctl variables are readonly even to root.
1766 */
1767
1768static int test_perm(int mode, int op)
1769{
David Howells76aac0e2008-11-14 10:39:12 +11001770 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 mode >>= 6;
1772 else if (in_egroup_p(0))
1773 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001774 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 return 0;
1776 return -EACCES;
1777}
1778
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001779int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
1781 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001782 int mode;
1783
Al Viroe6305c42008-07-15 21:03:57 -04001784 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 if (error)
1786 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001787
1788 if (root->permissions)
1789 mode = root->permissions(root, current->nsproxy, table);
1790 else
1791 mode = table->mode;
1792
1793 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794}
1795
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001796static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1797{
1798 for (; table->ctl_name || table->procname; table++) {
1799 table->parent = parent;
1800 if (table->child)
1801 sysctl_set_parent(table, table->child);
1802 }
1803}
1804
1805static __init int sysctl_init(void)
1806{
1807 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001808#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1809 {
1810 int err;
1811 err = sysctl_check_table(current->nsproxy, root_table);
1812 }
1813#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001814 return 0;
1815}
1816
1817core_initcall(sysctl_init);
1818
Al Virobfbcf032008-07-27 06:31:22 +01001819static struct ctl_table *is_branch_in(struct ctl_table *branch,
1820 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001821{
1822 struct ctl_table *p;
1823 const char *s = branch->procname;
1824
1825 /* branch should have named subdirectory as its first element */
1826 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001827 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001828
1829 /* ... and nothing else */
1830 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001831 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001832
1833 /* table should contain subdirectory with the same name */
1834 for (p = table; p->procname || p->ctl_name; p++) {
1835 if (!p->child)
1836 continue;
1837 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001838 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001839 }
Al Virobfbcf032008-07-27 06:31:22 +01001840 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001841}
1842
1843/* see if attaching q to p would be an improvement */
1844static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1845{
1846 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001847 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001848 int is_better = 0;
1849 int not_in_parent = !p->attached_by;
1850
Al Virobfbcf032008-07-27 06:31:22 +01001851 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001852 if (by == q->attached_by)
1853 is_better = 1;
1854 if (to == p->attached_by)
1855 not_in_parent = 1;
1856 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001857 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001858 }
1859
1860 if (is_better && not_in_parent) {
1861 q->attached_by = by;
1862 q->attached_to = to;
1863 q->parent = p;
1864 }
1865}
1866
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001868 * __register_sysctl_paths - register a sysctl hierarchy
1869 * @root: List of sysctl headers to register on
1870 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001871 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 *
1874 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001875 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001877 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 *
1879 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1880 * must be unique within that level of sysctl
1881 *
1882 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1883 * enter a sysctl file
1884 *
1885 * data - a pointer to data for use by proc_handler
1886 *
1887 * maxlen - the maximum size in bytes of the data
1888 *
1889 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1890 *
1891 * child - a pointer to the child sysctl table if this entry is a directory, or
1892 * %NULL.
1893 *
1894 * proc_handler - the text handler routine (described below)
1895 *
1896 * strategy - the strategy routine (described below)
1897 *
1898 * de - for internal use by the sysctl routines
1899 *
1900 * extra1, extra2 - extra pointers usable by the proc handler routines
1901 *
1902 * Leaf nodes in the sysctl tree will be represented by a single file
1903 * under /proc; non-leaf nodes will be represented by directories.
1904 *
1905 * sysctl(2) can automatically manage read and write requests through
1906 * the sysctl table. The data and maxlen fields of the ctl_table
1907 * struct enable minimal validation of the values being written to be
1908 * performed, and the mode field allows minimal authentication.
1909 *
1910 * More sophisticated management can be enabled by the provision of a
1911 * strategy routine with the table entry. This will be called before
1912 * any automatic read or write of the data is performed.
1913 *
1914 * The strategy routine may return
1915 *
1916 * < 0 - Error occurred (error is passed to user process)
1917 *
1918 * 0 - OK - proceed with automatic read or write.
1919 *
1920 * > 0 - OK - read or write has been done by the strategy routine, so
1921 * return immediately.
1922 *
1923 * There must be a proc_handler routine for any terminal nodes
1924 * mirrored under /proc/sys (non-terminals are handled by a built-in
1925 * directory handler). Several default handlers are available to
1926 * cover common cases -
1927 *
1928 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1929 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1930 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1931 *
1932 * It is the handler's job to read the input buffer from user memory
1933 * and process it. The handler should return 0 on success.
1934 *
1935 * This routine returns %NULL on a failure to register, and a pointer
1936 * to the table header on success.
1937 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001938struct ctl_table_header *__register_sysctl_paths(
1939 struct ctl_table_root *root,
1940 struct nsproxy *namespaces,
1941 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001943 struct ctl_table_header *header;
1944 struct ctl_table *new, **prevp;
1945 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001946 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001947
1948 /* Count the path components */
1949 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1950 ;
1951
1952 /*
1953 * For each path component, allocate a 2-element ctl_table array.
1954 * The first array element will be filled with the sysctl entry
1955 * for this, the second will be the sentinel (ctl_name == 0).
1956 *
1957 * We allocate everything in one go so that we don't have to
1958 * worry about freeing additional memory in unregister_sysctl_table.
1959 */
1960 header = kzalloc(sizeof(struct ctl_table_header) +
1961 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1962 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001964
1965 new = (struct ctl_table *) (header + 1);
1966
1967 /* Now connect the dots */
1968 prevp = &header->ctl_table;
1969 for (n = 0; n < npath; ++n, ++path) {
1970 /* Copy the procname */
1971 new->procname = path->procname;
1972 new->ctl_name = path->ctl_name;
1973 new->mode = 0555;
1974
1975 *prevp = new;
1976 prevp = &new->child;
1977
1978 new += 2;
1979 }
1980 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001981 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001982
1983 INIT_LIST_HEAD(&header->ctl_entry);
1984 header->used = 0;
1985 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001986 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001987 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001988 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001989#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001990 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001991 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001992 return NULL;
1993 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001994#endif
Al Viro330d57f2005-11-04 10:18:40 +00001995 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001996 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001997 header->attached_by = header->ctl_table;
1998 header->attached_to = root_table;
1999 header->parent = &root_table_header;
2000 for (set = header->set; set; set = set->parent) {
2001 struct ctl_table_header *p;
2002 list_for_each_entry(p, &set->list, ctl_entry) {
2003 if (p->unregistering)
2004 continue;
2005 try_attach(p, header);
2006 }
2007 }
2008 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002009 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002010 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002011
2012 return header;
2013}
2014
2015/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002016 * register_sysctl_table_path - register a sysctl table hierarchy
2017 * @path: The path to the directory the sysctl table is in.
2018 * @table: the top-level table structure
2019 *
2020 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2021 * array. A completely 0 filled entry terminates the table.
2022 *
2023 * See __register_sysctl_paths for more details.
2024 */
2025struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2026 struct ctl_table *table)
2027{
2028 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2029 path, table);
2030}
2031
2032/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002033 * register_sysctl_table - register a sysctl table hierarchy
2034 * @table: the top-level table structure
2035 *
2036 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2037 * array. A completely 0 filled entry terminates the table.
2038 *
2039 * See register_sysctl_paths for more details.
2040 */
2041struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2042{
2043 static const struct ctl_path null_path[] = { {} };
2044
2045 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
2048/**
2049 * unregister_sysctl_table - unregister a sysctl table hierarchy
2050 * @header: the header returned from register_sysctl_table
2051 *
2052 * Unregisters the sysctl table and all children. proc entries may not
2053 * actually be removed until they are no longer used by anyone.
2054 */
2055void unregister_sysctl_table(struct ctl_table_header * header)
2056{
Al Viro330d57f2005-11-04 10:18:40 +00002057 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002058
2059 if (header == NULL)
2060 return;
2061
Al Viro330d57f2005-11-04 10:18:40 +00002062 spin_lock(&sysctl_lock);
2063 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002064 if (!--header->parent->count) {
2065 WARN_ON(1);
2066 kfree(header->parent);
2067 }
Al Virof7e6ced2008-07-15 01:44:23 -04002068 if (!--header->count)
2069 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002070 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071}
2072
Al Viro90434762008-07-15 08:54:06 -04002073int sysctl_is_seen(struct ctl_table_header *p)
2074{
2075 struct ctl_table_set *set = p->set;
2076 int res;
2077 spin_lock(&sysctl_lock);
2078 if (p->unregistering)
2079 res = 0;
2080 else if (!set->is_seen)
2081 res = 1;
2082 else
2083 res = set->is_seen(set);
2084 spin_unlock(&sysctl_lock);
2085 return res;
2086}
2087
Al Viro73455092008-07-14 21:22:20 -04002088void setup_sysctl_set(struct ctl_table_set *p,
2089 struct ctl_table_set *parent,
2090 int (*is_seen)(struct ctl_table_set *))
2091{
2092 INIT_LIST_HEAD(&p->list);
2093 p->parent = parent ? parent : &sysctl_table_root.default_set;
2094 p->is_seen = is_seen;
2095}
2096
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002097#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002098struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002099{
2100 return NULL;
2101}
2102
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002103struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2104 struct ctl_table *table)
2105{
2106 return NULL;
2107}
2108
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002109void unregister_sysctl_table(struct ctl_table_header * table)
2110{
2111}
2112
Al Viro73455092008-07-14 21:22:20 -04002113void setup_sysctl_set(struct ctl_table_set *p,
2114 struct ctl_table_set *parent,
2115 int (*is_seen)(struct ctl_table_set *))
2116{
2117}
2118
Al Virof7e6ced2008-07-15 01:44:23 -04002119void sysctl_head_put(struct ctl_table_header *head)
2120{
2121}
2122
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002123#endif /* CONFIG_SYSCTL */
2124
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125/*
2126 * /proc/sys support
2127 */
2128
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002129#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002131static int _proc_do_string(void* data, int maxlen, int write,
2132 struct file *filp, void __user *buffer,
2133 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002134{
2135 size_t len;
2136 char __user *p;
2137 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002138
2139 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002140 *lenp = 0;
2141 return 0;
2142 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002143
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002144 if (write) {
2145 len = 0;
2146 p = buffer;
2147 while (len < *lenp) {
2148 if (get_user(c, p++))
2149 return -EFAULT;
2150 if (c == 0 || c == '\n')
2151 break;
2152 len++;
2153 }
2154 if (len >= maxlen)
2155 len = maxlen-1;
2156 if(copy_from_user(data, buffer, len))
2157 return -EFAULT;
2158 ((char *) data)[len] = 0;
2159 *ppos += *lenp;
2160 } else {
2161 len = strlen(data);
2162 if (len > maxlen)
2163 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002164
2165 if (*ppos > len) {
2166 *lenp = 0;
2167 return 0;
2168 }
2169
2170 data += *ppos;
2171 len -= *ppos;
2172
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002173 if (len > *lenp)
2174 len = *lenp;
2175 if (len)
2176 if(copy_to_user(buffer, data, len))
2177 return -EFAULT;
2178 if (len < *lenp) {
2179 if(put_user('\n', ((char __user *) buffer) + len))
2180 return -EFAULT;
2181 len++;
2182 }
2183 *lenp = len;
2184 *ppos += len;
2185 }
2186 return 0;
2187}
2188
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189/**
2190 * proc_dostring - read a string sysctl
2191 * @table: the sysctl table
2192 * @write: %TRUE if this is a write to the sysctl file
2193 * @filp: the file structure
2194 * @buffer: the user buffer
2195 * @lenp: the size of the user buffer
2196 * @ppos: file position
2197 *
2198 * Reads/writes a string from/to the user buffer. If the kernel
2199 * buffer provided is not large enough to hold the string, the
2200 * string is truncated. The copied string is %NULL-terminated.
2201 * If the string is being read by the user process, it is copied
2202 * and a newline '\n' is added. It is truncated if the buffer is
2203 * not large enough.
2204 *
2205 * Returns 0 on success.
2206 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002207int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 void __user *buffer, size_t *lenp, loff_t *ppos)
2209{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002210 return _proc_do_string(table->data, table->maxlen, write, filp,
2211 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212}
2213
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
2215static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2216 int *valp,
2217 int write, void *data)
2218{
2219 if (write) {
2220 *valp = *negp ? -*lvalp : *lvalp;
2221 } else {
2222 int val = *valp;
2223 if (val < 0) {
2224 *negp = -1;
2225 *lvalp = (unsigned long)-val;
2226 } else {
2227 *negp = 0;
2228 *lvalp = (unsigned long)val;
2229 }
2230 }
2231 return 0;
2232}
2233
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002234static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002235 int write, struct file *filp, void __user *buffer,
2236 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2238 int write, void *data),
2239 void *data)
2240{
2241#define TMPBUFLEN 21
2242 int *i, vleft, first=1, neg, val;
2243 unsigned long lval;
2244 size_t left, len;
2245
2246 char buf[TMPBUFLEN], *p;
2247 char __user *s = buffer;
2248
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002249 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 (*ppos && !write)) {
2251 *lenp = 0;
2252 return 0;
2253 }
2254
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002255 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 vleft = table->maxlen / sizeof(*i);
2257 left = *lenp;
2258
2259 if (!conv)
2260 conv = do_proc_dointvec_conv;
2261
2262 for (; left && vleft--; i++, first=0) {
2263 if (write) {
2264 while (left) {
2265 char c;
2266 if (get_user(c, s))
2267 return -EFAULT;
2268 if (!isspace(c))
2269 break;
2270 left--;
2271 s++;
2272 }
2273 if (!left)
2274 break;
2275 neg = 0;
2276 len = left;
2277 if (len > sizeof(buf) - 1)
2278 len = sizeof(buf) - 1;
2279 if (copy_from_user(buf, s, len))
2280 return -EFAULT;
2281 buf[len] = 0;
2282 p = buf;
2283 if (*p == '-' && left > 1) {
2284 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002285 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 }
2287 if (*p < '0' || *p > '9')
2288 break;
2289
2290 lval = simple_strtoul(p, &p, 0);
2291
2292 len = p-buf;
2293 if ((len < left) && *p && !isspace(*p))
2294 break;
2295 if (neg)
2296 val = -val;
2297 s += len;
2298 left -= len;
2299
2300 if (conv(&neg, &lval, i, 1, data))
2301 break;
2302 } else {
2303 p = buf;
2304 if (!first)
2305 *p++ = '\t';
2306
2307 if (conv(&neg, &lval, i, 0, data))
2308 break;
2309
2310 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2311 len = strlen(buf);
2312 if (len > left)
2313 len = left;
2314 if(copy_to_user(s, buf, len))
2315 return -EFAULT;
2316 left -= len;
2317 s += len;
2318 }
2319 }
2320
2321 if (!write && !first && left) {
2322 if(put_user('\n', s))
2323 return -EFAULT;
2324 left--, s++;
2325 }
2326 if (write) {
2327 while (left) {
2328 char c;
2329 if (get_user(c, s++))
2330 return -EFAULT;
2331 if (!isspace(c))
2332 break;
2333 left--;
2334 }
2335 }
2336 if (write && first)
2337 return -EINVAL;
2338 *lenp -= left;
2339 *ppos += *lenp;
2340 return 0;
2341#undef TMPBUFLEN
2342}
2343
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002344static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002345 void __user *buffer, size_t *lenp, loff_t *ppos,
2346 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2347 int write, void *data),
2348 void *data)
2349{
2350 return __do_proc_dointvec(table->data, table, write, filp,
2351 buffer, lenp, ppos, conv, data);
2352}
2353
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354/**
2355 * proc_dointvec - read a vector of integers
2356 * @table: the sysctl table
2357 * @write: %TRUE if this is a write to the sysctl file
2358 * @filp: the file structure
2359 * @buffer: the user buffer
2360 * @lenp: the size of the user buffer
2361 * @ppos: file position
2362 *
2363 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2364 * values from/to the user buffer, treated as an ASCII string.
2365 *
2366 * Returns 0 on success.
2367 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002368int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 void __user *buffer, size_t *lenp, loff_t *ppos)
2370{
2371 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2372 NULL,NULL);
2373}
2374
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002375/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002376 * Taint values can only be increased
2377 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002378 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002379static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002380 void __user *buffer, size_t *lenp, loff_t *ppos)
2381{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002382 struct ctl_table t;
2383 unsigned long tmptaint = get_taint();
2384 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002385
Bastian Blank91fcd412007-04-23 14:41:14 -07002386 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002387 return -EPERM;
2388
Andi Kleen25ddbb12008-10-15 22:01:41 -07002389 t = *table;
2390 t.data = &tmptaint;
2391 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2392 if (err < 0)
2393 return err;
2394
2395 if (write) {
2396 /*
2397 * Poor man's atomic or. Not worth adding a primitive
2398 * to everyone's atomic.h for this
2399 */
2400 int i;
2401 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2402 if ((tmptaint >> i) & 1)
2403 add_taint(i);
2404 }
2405 }
2406
2407 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002408}
2409
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410struct do_proc_dointvec_minmax_conv_param {
2411 int *min;
2412 int *max;
2413};
2414
2415static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2416 int *valp,
2417 int write, void *data)
2418{
2419 struct do_proc_dointvec_minmax_conv_param *param = data;
2420 if (write) {
2421 int val = *negp ? -*lvalp : *lvalp;
2422 if ((param->min && *param->min > val) ||
2423 (param->max && *param->max < val))
2424 return -EINVAL;
2425 *valp = val;
2426 } else {
2427 int val = *valp;
2428 if (val < 0) {
2429 *negp = -1;
2430 *lvalp = (unsigned long)-val;
2431 } else {
2432 *negp = 0;
2433 *lvalp = (unsigned long)val;
2434 }
2435 }
2436 return 0;
2437}
2438
2439/**
2440 * proc_dointvec_minmax - read a vector of integers with min/max values
2441 * @table: the sysctl table
2442 * @write: %TRUE if this is a write to the sysctl file
2443 * @filp: the file structure
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2447 *
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2449 * values from/to the user buffer, treated as an ASCII string.
2450 *
2451 * This routine will ensure the values are within the range specified by
2452 * table->extra1 (min) and table->extra2 (max).
2453 *
2454 * Returns 0 on success.
2455 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002456int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 void __user *buffer, size_t *lenp, loff_t *ppos)
2458{
2459 struct do_proc_dointvec_minmax_conv_param param = {
2460 .min = (int *) table->extra1,
2461 .max = (int *) table->extra2,
2462 };
2463 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2464 do_proc_dointvec_minmax_conv, &param);
2465}
2466
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002467static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 struct file *filp,
2469 void __user *buffer,
2470 size_t *lenp, loff_t *ppos,
2471 unsigned long convmul,
2472 unsigned long convdiv)
2473{
2474#define TMPBUFLEN 21
2475 unsigned long *i, *min, *max, val;
2476 int vleft, first=1, neg;
2477 size_t len, left;
2478 char buf[TMPBUFLEN], *p;
2479 char __user *s = buffer;
2480
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002481 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 (*ppos && !write)) {
2483 *lenp = 0;
2484 return 0;
2485 }
2486
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002487 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 min = (unsigned long *) table->extra1;
2489 max = (unsigned long *) table->extra2;
2490 vleft = table->maxlen / sizeof(unsigned long);
2491 left = *lenp;
2492
2493 for (; left && vleft--; i++, min++, max++, first=0) {
2494 if (write) {
2495 while (left) {
2496 char c;
2497 if (get_user(c, s))
2498 return -EFAULT;
2499 if (!isspace(c))
2500 break;
2501 left--;
2502 s++;
2503 }
2504 if (!left)
2505 break;
2506 neg = 0;
2507 len = left;
2508 if (len > TMPBUFLEN-1)
2509 len = TMPBUFLEN-1;
2510 if (copy_from_user(buf, s, len))
2511 return -EFAULT;
2512 buf[len] = 0;
2513 p = buf;
2514 if (*p == '-' && left > 1) {
2515 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002516 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 }
2518 if (*p < '0' || *p > '9')
2519 break;
2520 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2521 len = p-buf;
2522 if ((len < left) && *p && !isspace(*p))
2523 break;
2524 if (neg)
2525 val = -val;
2526 s += len;
2527 left -= len;
2528
2529 if(neg)
2530 continue;
2531 if ((min && val < *min) || (max && val > *max))
2532 continue;
2533 *i = val;
2534 } else {
2535 p = buf;
2536 if (!first)
2537 *p++ = '\t';
2538 sprintf(p, "%lu", convdiv * (*i) / convmul);
2539 len = strlen(buf);
2540 if (len > left)
2541 len = left;
2542 if(copy_to_user(s, buf, len))
2543 return -EFAULT;
2544 left -= len;
2545 s += len;
2546 }
2547 }
2548
2549 if (!write && !first && left) {
2550 if(put_user('\n', s))
2551 return -EFAULT;
2552 left--, s++;
2553 }
2554 if (write) {
2555 while (left) {
2556 char c;
2557 if (get_user(c, s++))
2558 return -EFAULT;
2559 if (!isspace(c))
2560 break;
2561 left--;
2562 }
2563 }
2564 if (write && first)
2565 return -EINVAL;
2566 *lenp -= left;
2567 *ppos += *lenp;
2568 return 0;
2569#undef TMPBUFLEN
2570}
2571
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002572static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002573 struct file *filp,
2574 void __user *buffer,
2575 size_t *lenp, loff_t *ppos,
2576 unsigned long convmul,
2577 unsigned long convdiv)
2578{
2579 return __do_proc_doulongvec_minmax(table->data, table, write,
2580 filp, buffer, lenp, ppos, convmul, convdiv);
2581}
2582
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583/**
2584 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2585 * @table: the sysctl table
2586 * @write: %TRUE if this is a write to the sysctl file
2587 * @filp: the file structure
2588 * @buffer: the user buffer
2589 * @lenp: the size of the user buffer
2590 * @ppos: file position
2591 *
2592 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2593 * values from/to the user buffer, treated as an ASCII string.
2594 *
2595 * This routine will ensure the values are within the range specified by
2596 * table->extra1 (min) and table->extra2 (max).
2597 *
2598 * Returns 0 on success.
2599 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002600int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 void __user *buffer, size_t *lenp, loff_t *ppos)
2602{
2603 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2604}
2605
2606/**
2607 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2608 * @table: the sysctl table
2609 * @write: %TRUE if this is a write to the sysctl file
2610 * @filp: the file structure
2611 * @buffer: the user buffer
2612 * @lenp: the size of the user buffer
2613 * @ppos: file position
2614 *
2615 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2616 * values from/to the user buffer, treated as an ASCII string. The values
2617 * are treated as milliseconds, and converted to jiffies when they are stored.
2618 *
2619 * This routine will ensure the values are within the range specified by
2620 * table->extra1 (min) and table->extra2 (max).
2621 *
2622 * Returns 0 on success.
2623 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002624int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 struct file *filp,
2626 void __user *buffer,
2627 size_t *lenp, loff_t *ppos)
2628{
2629 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2630 lenp, ppos, HZ, 1000l);
2631}
2632
2633
2634static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2635 int *valp,
2636 int write, void *data)
2637{
2638 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002639 if (*lvalp > LONG_MAX / HZ)
2640 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2642 } else {
2643 int val = *valp;
2644 unsigned long lval;
2645 if (val < 0) {
2646 *negp = -1;
2647 lval = (unsigned long)-val;
2648 } else {
2649 *negp = 0;
2650 lval = (unsigned long)val;
2651 }
2652 *lvalp = lval / HZ;
2653 }
2654 return 0;
2655}
2656
2657static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2658 int *valp,
2659 int write, void *data)
2660{
2661 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002662 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2663 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2665 } else {
2666 int val = *valp;
2667 unsigned long lval;
2668 if (val < 0) {
2669 *negp = -1;
2670 lval = (unsigned long)-val;
2671 } else {
2672 *negp = 0;
2673 lval = (unsigned long)val;
2674 }
2675 *lvalp = jiffies_to_clock_t(lval);
2676 }
2677 return 0;
2678}
2679
2680static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2681 int *valp,
2682 int write, void *data)
2683{
2684 if (write) {
2685 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2686 } else {
2687 int val = *valp;
2688 unsigned long lval;
2689 if (val < 0) {
2690 *negp = -1;
2691 lval = (unsigned long)-val;
2692 } else {
2693 *negp = 0;
2694 lval = (unsigned long)val;
2695 }
2696 *lvalp = jiffies_to_msecs(lval);
2697 }
2698 return 0;
2699}
2700
2701/**
2702 * proc_dointvec_jiffies - read a vector of integers as seconds
2703 * @table: the sysctl table
2704 * @write: %TRUE if this is a write to the sysctl file
2705 * @filp: the file structure
2706 * @buffer: the user buffer
2707 * @lenp: the size of the user buffer
2708 * @ppos: file position
2709 *
2710 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2711 * values from/to the user buffer, treated as an ASCII string.
2712 * The values read are assumed to be in seconds, and are converted into
2713 * jiffies.
2714 *
2715 * Returns 0 on success.
2716 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002717int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 void __user *buffer, size_t *lenp, loff_t *ppos)
2719{
2720 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2721 do_proc_dointvec_jiffies_conv,NULL);
2722}
2723
2724/**
2725 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2726 * @table: the sysctl table
2727 * @write: %TRUE if this is a write to the sysctl file
2728 * @filp: the file structure
2729 * @buffer: the user buffer
2730 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002731 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 *
2733 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2734 * values from/to the user buffer, treated as an ASCII string.
2735 * The values read are assumed to be in 1/USER_HZ seconds, and
2736 * are converted into jiffies.
2737 *
2738 * Returns 0 on success.
2739 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002740int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 void __user *buffer, size_t *lenp, loff_t *ppos)
2742{
2743 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2744 do_proc_dointvec_userhz_jiffies_conv,NULL);
2745}
2746
2747/**
2748 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2749 * @table: the sysctl table
2750 * @write: %TRUE if this is a write to the sysctl file
2751 * @filp: the file structure
2752 * @buffer: the user buffer
2753 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002754 * @ppos: file position
2755 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 *
2757 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2758 * values from/to the user buffer, treated as an ASCII string.
2759 * The values read are assumed to be in 1/1000 seconds, and
2760 * are converted into jiffies.
2761 *
2762 * Returns 0 on success.
2763 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002764int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 void __user *buffer, size_t *lenp, loff_t *ppos)
2766{
2767 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2768 do_proc_dointvec_ms_jiffies_conv, NULL);
2769}
2770
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002771static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002772 void __user *buffer, size_t *lenp, loff_t *ppos)
2773{
2774 struct pid *new_pid;
2775 pid_t tmp;
2776 int r;
2777
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002778 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002779
2780 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2781 lenp, ppos, NULL, NULL);
2782 if (r || !write)
2783 return r;
2784
2785 new_pid = find_get_pid(tmp);
2786 if (!new_pid)
2787 return -ESRCH;
2788
2789 put_pid(xchg(&cad_pid, new_pid));
2790 return 0;
2791}
2792
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793#else /* CONFIG_PROC_FS */
2794
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002795int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 void __user *buffer, size_t *lenp, loff_t *ppos)
2797{
2798 return -ENOSYS;
2799}
2800
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002801int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 void __user *buffer, size_t *lenp, loff_t *ppos)
2803{
2804 return -ENOSYS;
2805}
2806
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002807int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 void __user *buffer, size_t *lenp, loff_t *ppos)
2809{
2810 return -ENOSYS;
2811}
2812
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002813int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 void __user *buffer, size_t *lenp, loff_t *ppos)
2815{
2816 return -ENOSYS;
2817}
2818
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002819int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 void __user *buffer, size_t *lenp, loff_t *ppos)
2821{
2822 return -ENOSYS;
2823}
2824
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002825int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 void __user *buffer, size_t *lenp, loff_t *ppos)
2827{
2828 return -ENOSYS;
2829}
2830
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002831int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 void __user *buffer, size_t *lenp, loff_t *ppos)
2833{
2834 return -ENOSYS;
2835}
2836
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002837int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 struct file *filp,
2839 void __user *buffer,
2840 size_t *lenp, loff_t *ppos)
2841{
2842 return -ENOSYS;
2843}
2844
2845
2846#endif /* CONFIG_PROC_FS */
2847
2848
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002849#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850/*
2851 * General sysctl support routines
2852 */
2853
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002854/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002855int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002856 void __user *oldval, size_t __user *oldlenp,
2857 void __user *newval, size_t newlen)
2858{
2859 size_t len;
2860
2861 /* Get out of I don't have a variable */
2862 if (!table->data || !table->maxlen)
2863 return -ENOTDIR;
2864
2865 if (oldval && oldlenp) {
2866 if (get_user(len, oldlenp))
2867 return -EFAULT;
2868 if (len) {
2869 if (len > table->maxlen)
2870 len = table->maxlen;
2871 if (copy_to_user(oldval, table->data, len))
2872 return -EFAULT;
2873 if (put_user(len, oldlenp))
2874 return -EFAULT;
2875 }
2876 }
2877
2878 if (newval && newlen) {
2879 if (newlen > table->maxlen)
2880 newlen = table->maxlen;
2881
2882 if (copy_from_user(table->data, newval, newlen))
2883 return -EFAULT;
2884 }
2885 return 1;
2886}
2887
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002889int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002891 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 if (!table->data || !table->maxlen)
2894 return -ENOTDIR;
2895
2896 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002897 size_t bufsize;
2898 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002900 if (bufsize) {
2901 size_t len = strlen(table->data), copied;
2902
2903 /* This shouldn't trigger for a well-formed sysctl */
2904 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002906
2907 /* Copy up to a max of bufsize-1 bytes of the string */
2908 copied = (len >= bufsize) ? bufsize - 1 : len;
2909
2910 if (copy_to_user(oldval, table->data, copied) ||
2911 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002913 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 return -EFAULT;
2915 }
2916 }
2917 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002918 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 if (len > table->maxlen)
2920 len = table->maxlen;
2921 if(copy_from_user(table->data, newval, len))
2922 return -EFAULT;
2923 if (len == table->maxlen)
2924 len--;
2925 ((char *) table->data)[len] = 0;
2926 }
Yi Yang82c9df82005-12-30 16:37:10 +08002927 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928}
2929
2930/*
2931 * This function makes sure that all of the integers in the vector
2932 * are between the minimum and maximum values given in the arrays
2933 * table->extra1 and table->extra2, respectively.
2934 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002935int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002937 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938{
2939
2940 if (newval && newlen) {
2941 int __user *vec = (int __user *) newval;
2942 int *min = (int *) table->extra1;
2943 int *max = (int *) table->extra2;
2944 size_t length;
2945 int i;
2946
2947 if (newlen % sizeof(int) != 0)
2948 return -EINVAL;
2949
2950 if (!table->extra1 && !table->extra2)
2951 return 0;
2952
2953 if (newlen > table->maxlen)
2954 newlen = table->maxlen;
2955 length = newlen / sizeof(int);
2956
2957 for (i = 0; i < length; i++) {
2958 int value;
2959 if (get_user(value, vec + i))
2960 return -EFAULT;
2961 if (min && value < min[i])
2962 return -EINVAL;
2963 if (max && value > max[i])
2964 return -EINVAL;
2965 }
2966 }
2967 return 0;
2968}
2969
2970/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002971int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002973 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002975 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002977
2978 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002980 if (olen) {
2981 int val;
2982
2983 if (olen < sizeof(int))
2984 return -EINVAL;
2985
2986 val = *(int *)(table->data) / HZ;
2987 if (put_user(val, (int __user *)oldval))
2988 return -EFAULT;
2989 if (put_user(sizeof(int), oldlenp))
2990 return -EFAULT;
2991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 }
2993 if (newval && newlen) {
2994 int new;
2995 if (newlen != sizeof(int))
2996 return -EINVAL;
2997 if (get_user(new, (int __user *)newval))
2998 return -EFAULT;
2999 *(int *)(table->data) = new*HZ;
3000 }
3001 return 1;
3002}
3003
3004/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003005int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003007 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003009 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003011
3012 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003014 if (olen) {
3015 int val;
3016
3017 if (olen < sizeof(int))
3018 return -EINVAL;
3019
3020 val = jiffies_to_msecs(*(int *)(table->data));
3021 if (put_user(val, (int __user *)oldval))
3022 return -EFAULT;
3023 if (put_user(sizeof(int), oldlenp))
3024 return -EFAULT;
3025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 }
3027 if (newval && newlen) {
3028 int new;
3029 if (newlen != sizeof(int))
3030 return -EINVAL;
3031 if (get_user(new, (int __user *)newval))
3032 return -EFAULT;
3033 *(int *)(table->data) = msecs_to_jiffies(new);
3034 }
3035 return 1;
3036}
3037
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003038
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003039
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003040#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041
3042
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003043SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003045 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003046 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003047
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003048 if (copy_from_user(&tmp, args, sizeof(tmp)))
3049 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003050
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003051 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003052
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003053 /* If no error reading the parameters then just -ENOSYS ... */
3054 if (!error)
3055 error = -ENOSYS;
3056
3057 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058}
3059
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003060int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003061 void __user *oldval, size_t __user *oldlenp,
3062 void __user *newval, size_t newlen)
3063{
3064 return -ENOSYS;
3065}
3066
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003067int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003069 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070{
3071 return -ENOSYS;
3072}
3073
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003074int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003076 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077{
3078 return -ENOSYS;
3079}
3080
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003081int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003083 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084{
3085 return -ENOSYS;
3086}
3087
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003088int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003090 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091{
3092 return -ENOSYS;
3093}
3094
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003095#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003097static int deprecated_sysctl_warning(struct __sysctl_args *args)
3098{
3099 static int msg_count;
3100 int name[CTL_MAXNAME];
3101 int i;
3102
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003103 /* Check args->nlen. */
3104 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3105 return -ENOTDIR;
3106
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003107 /* Read in the sysctl name for better debug message logging */
3108 for (i = 0; i < args->nlen; i++)
3109 if (get_user(name[i], args->name + i))
3110 return -EFAULT;
3111
3112 /* Ignore accesses to kernel.version */
3113 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3114 return 0;
3115
3116 if (msg_count < 5) {
3117 msg_count++;
3118 printk(KERN_INFO
3119 "warning: process `%s' used the deprecated sysctl "
3120 "system call with ", current->comm);
3121 for (i = 0; i < args->nlen; i++)
3122 printk("%d.", name[i]);
3123 printk("\n");
3124 }
3125 return 0;
3126}
3127
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128/*
3129 * No sense putting this after each symbol definition, twice,
3130 * exception granted :-)
3131 */
3132EXPORT_SYMBOL(proc_dointvec);
3133EXPORT_SYMBOL(proc_dointvec_jiffies);
3134EXPORT_SYMBOL(proc_dointvec_minmax);
3135EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3136EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3137EXPORT_SYMBOL(proc_dostring);
3138EXPORT_SYMBOL(proc_doulongvec_minmax);
3139EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3140EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003141EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142EXPORT_SYMBOL(sysctl_intvec);
3143EXPORT_SYMBOL(sysctl_jiffies);
3144EXPORT_SYMBOL(sysctl_ms_jiffies);
3145EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003146EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147EXPORT_SYMBOL(unregister_sysctl_table);