blob: ea78fa101ad6a4325209f6bd9b3c350298d1e4e2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/uaccess.h>
54#include <asm/processor.h>
55
Andi Kleen29cbc782006-09-30 01:47:55 +020056#ifdef CONFIG_X86
57#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010058#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010059#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020060#endif
61
Eric W. Biederman7058cb02007-10-18 03:05:58 -070062static int deprecated_sysctl_warning(struct __sysctl_args *args);
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#if defined(CONFIG_SYSCTL)
65
66/* External variables not in a header file. */
67extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070068extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int sysctl_overcommit_memory;
70extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070071extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070072extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080073extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070076extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int pid_max;
79extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080081extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080082extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020083extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000086#ifndef CONFIG_MMU
87extern int sysctl_nr_trim_pages;
88#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070089#ifdef CONFIG_RCU_TORTURE_TEST
90extern int rcutorture_runnable;
91#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070093/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080094#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020096static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097#endif
98
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700100static int __maybe_unused one = 1;
101static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800102static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103static int one_hundred = 100;
Peter W Morrealefafd6882009-04-06 19:00:29 -0700104static int one_thousand = 1000;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700105
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;
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110static int maxolduid = 65535;
111static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800112static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static int ngroups_max = NGROUPS_MAX;
115
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200116#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117extern char modprobe_path[];
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#ifdef CONFIG_CHR_DEV_SG
120extern int sg_big_buff;
121#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
David S. Miller72c57ed2008-09-11 23:29:54 -0700123#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700124#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#endif
126
David S. Miller08714202008-11-16 23:49:24 -0800127#ifdef CONFIG_SPARC64
128extern int sysctl_tsb_ratio;
129#endif
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#ifdef __hppa__
132extern int pwrsw_enabled;
133extern int unaligned_enabled;
134#endif
135
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800136#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef CONFIG_MATHEMU
138extern int sysctl_ieee_emulation_warnings;
139#endif
140extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700141extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#endif
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef CONFIG_BSD_PROCESS_ACCT
145extern int acct_parm[];
146#endif
147
Jes Sorensend2b176e2006-02-28 09:42:23 -0800148#ifdef CONFIG_IA64
149extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800150extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800151#endif
152
Ingo Molnar23f78d42006-06-27 02:54:53 -0700153#ifdef CONFIG_RT_MUTEXES
154extern int max_lock_depth;
155#endif
156
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700159 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700160static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800161 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700162#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700163
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700164static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100165static struct ctl_table_root sysctl_table_root;
166static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100167 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400169 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100170 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400171 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100172};
173static struct ctl_table_root sysctl_table_root = {
174 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400175 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100176};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700178static struct ctl_table kern_table[];
179static struct ctl_table vm_table[];
180static struct ctl_table fs_table[];
181static struct ctl_table debug_table[];
182static struct ctl_table dev_table[];
183extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700184#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700185extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400186#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800187#ifdef CONFIG_EPOLL
188extern struct ctl_table epoll_table[];
189#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
192int sysctl_legacy_va_layout;
193#endif
194
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700195extern int prove_locking;
196extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198/* The default sysctl tables: */
199
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700200static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 {
202 .ctl_name = CTL_KERN,
203 .procname = "kernel",
204 .mode = 0555,
205 .child = kern_table,
206 },
207 {
208 .ctl_name = CTL_VM,
209 .procname = "vm",
210 .mode = 0555,
211 .child = vm_table,
212 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 .ctl_name = CTL_FS,
215 .procname = "fs",
216 .mode = 0555,
217 .child = fs_table,
218 },
219 {
220 .ctl_name = CTL_DEBUG,
221 .procname = "debug",
222 .mode = 0555,
223 .child = debug_table,
224 },
225 {
226 .ctl_name = CTL_DEV,
227 .procname = "dev",
228 .mode = 0555,
229 .child = dev_table,
230 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700231/*
232 * NOTE: do not add new entries to this table unless you have read
233 * Documentation/sysctl/ctl_unnumbered.txt
234 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 { .ctl_name = 0 }
236};
237
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100239static int min_sched_granularity_ns = 100000; /* 100 usecs */
240static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
241static int min_wakeup_granularity_ns; /* 0 usecs */
242static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243#endif
244
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700245static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246#ifdef CONFIG_SCHED_DEBUG
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100249 .procname = "sched_min_granularity_ns",
250 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200260 .procname = "sched_latency_ns",
261 .data = &sysctl_sched_latency,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100264 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200265 .strategy = &sysctl_intvec,
266 .extra1 = &min_sched_granularity_ns,
267 .extra2 = &max_sched_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200271 .procname = "sched_wakeup_granularity_ns",
272 .data = &sysctl_sched_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200282 .procname = "sched_shares_ratelimit",
283 .data = &sysctl_sched_shares_ratelimit,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
287 },
288 {
289 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200290 .procname = "sched_shares_thresh",
291 .data = &sysctl_sched_shares_thresh,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
296 .extra1 = &zero,
297 },
298 {
299 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200300 .procname = "sched_child_runs_first",
301 .data = &sysctl_sched_child_runs_first,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200306 {
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_features",
309 .data = &sysctl_sched_features,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
313 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200314 {
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100322 {
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
329 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200330#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200331 {
332 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100333 .procname = "sched_rt_period_us",
334 .data = &sysctl_sched_rt_period,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200337 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100338 },
339 {
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_rt_runtime_us",
342 .data = &sysctl_sched_rt_runtime,
343 .maxlen = sizeof(int),
344 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200345 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100346 },
347 {
348 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200349 .procname = "sched_compat_yield",
350 .data = &sysctl_sched_compat_yield,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = &proc_dointvec,
354 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700355#ifdef CONFIG_PROVE_LOCKING
356 {
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
364#endif
365#ifdef CONFIG_LOCK_STAT
366 {
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "lock_stat",
369 .data = &lock_stat,
370 .maxlen = sizeof(int),
371 .mode = 0644,
372 .proc_handler = &proc_dointvec,
373 },
374#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .ctl_name = KERN_PANIC,
377 .procname = "panic",
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383 {
384 .ctl_name = KERN_CORE_USES_PID,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
391 {
392 .ctl_name = KERN_CORE_PATTERN,
393 .procname = "core_pattern",
394 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700395 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 .mode = 0644,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
399 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800400#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700403 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800404 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700405 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800407#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100408#ifdef CONFIG_LATENCYTOP
409 {
410 .procname = "latencytop",
411 .data = &latencytop_enabled,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = &proc_dointvec,
415 },
416#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#ifdef CONFIG_BLK_DEV_INITRD
418 {
419 .ctl_name = KERN_REALROOTDEV,
420 .procname = "real-root-dev",
421 .data = &real_root_dev,
422 .maxlen = sizeof(int),
423 .mode = 0644,
424 .proc_handler = &proc_dointvec,
425 },
426#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700427 {
428 .ctl_name = CTL_UNNUMBERED,
429 .procname = "print-fatal-signals",
430 .data = &print_fatal_signals,
431 .maxlen = sizeof(int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700435#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 {
437 .ctl_name = KERN_SPARC_REBOOT,
438 .procname = "reboot-cmd",
439 .data = reboot_command,
440 .maxlen = 256,
441 .mode = 0644,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
444 },
445 {
446 .ctl_name = KERN_SPARC_STOP_A,
447 .procname = "stop-a",
448 .data = &stop_a_enabled,
449 .maxlen = sizeof (int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec,
452 },
453 {
454 .ctl_name = KERN_SPARC_SCONS_PWROFF,
455 .procname = "scons-poweroff",
456 .data = &scons_pwroff,
457 .maxlen = sizeof (int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
460 },
461#endif
David S. Miller08714202008-11-16 23:49:24 -0800462#ifdef CONFIG_SPARC64
463 {
464 .ctl_name = CTL_UNNUMBERED,
465 .procname = "tsb-ratio",
466 .data = &sysctl_tsb_ratio,
467 .maxlen = sizeof (int),
468 .mode = 0644,
469 .proc_handler = &proc_dointvec,
470 },
471#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472#ifdef __hppa__
473 {
474 .ctl_name = KERN_HPPA_PWRSW,
475 .procname = "soft-power",
476 .data = &pwrsw_enabled,
477 .maxlen = sizeof (int),
478 .mode = 0644,
479 .proc_handler = &proc_dointvec,
480 },
481 {
482 .ctl_name = KERN_HPPA_UNALIGNED,
483 .procname = "unaligned-trap",
484 .data = &unaligned_enabled,
485 .maxlen = sizeof (int),
486 .mode = 0644,
487 .proc_handler = &proc_dointvec,
488 },
489#endif
490 {
491 .ctl_name = KERN_CTLALTDEL,
492 .procname = "ctrl-alt-del",
493 .data = &C_A_D,
494 .maxlen = sizeof(int),
495 .mode = 0644,
496 .proc_handler = &proc_dointvec,
497 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400498#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200499 {
500 .ctl_name = CTL_UNNUMBERED,
501 .procname = "ftrace_enabled",
502 .data = &ftrace_enabled,
503 .maxlen = sizeof(int),
504 .mode = 0644,
505 .proc_handler = &ftrace_enable_sysctl,
506 },
507#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500508#ifdef CONFIG_STACK_TRACER
509 {
510 .ctl_name = CTL_UNNUMBERED,
511 .procname = "stack_tracer_enabled",
512 .data = &stack_tracer_enabled,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = &stack_trace_sysctl,
516 },
517#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400518#ifdef CONFIG_TRACING
519 {
520 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100521 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400522 .data = &ftrace_dump_on_oops,
523 .maxlen = sizeof(int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec,
526 },
527#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200528#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 {
530 .ctl_name = KERN_MODPROBE,
531 .procname = "modprobe",
532 .data = &modprobe_path,
533 .maxlen = KMOD_PATH_LEN,
534 .mode = 0644,
535 .proc_handler = &proc_dostring,
536 .strategy = &sysctl_string,
537 },
538#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700539#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
541 .ctl_name = KERN_HOTPLUG,
542 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100543 .data = &uevent_helper,
544 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .mode = 0644,
546 .proc_handler = &proc_dostring,
547 .strategy = &sysctl_string,
548 },
549#endif
550#ifdef CONFIG_CHR_DEV_SG
551 {
552 .ctl_name = KERN_SG_BIG_BUFF,
553 .procname = "sg-big-buff",
554 .data = &sg_big_buff,
555 .maxlen = sizeof (int),
556 .mode = 0444,
557 .proc_handler = &proc_dointvec,
558 },
559#endif
560#ifdef CONFIG_BSD_PROCESS_ACCT
561 {
562 .ctl_name = KERN_ACCT,
563 .procname = "acct",
564 .data = &acct_parm,
565 .maxlen = 3*sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#ifdef CONFIG_MAGIC_SYSRQ
571 {
572 .ctl_name = KERN_SYSRQ,
573 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800574 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .maxlen = sizeof (int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
578 },
579#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700580#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700583 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 .maxlen = sizeof (int),
585 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700586 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 {
590 .ctl_name = KERN_MAX_THREADS,
591 .procname = "threads-max",
592 .data = &max_threads,
593 .maxlen = sizeof(int),
594 .mode = 0644,
595 .proc_handler = &proc_dointvec,
596 },
597 {
598 .ctl_name = KERN_RANDOM,
599 .procname = "random",
600 .mode = 0555,
601 .child = random_table,
602 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 {
604 .ctl_name = KERN_OVERFLOWUID,
605 .procname = "overflowuid",
606 .data = &overflowuid,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec_minmax,
610 .strategy = &sysctl_intvec,
611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
613 },
614 {
615 .ctl_name = KERN_OVERFLOWGID,
616 .procname = "overflowgid",
617 .data = &overflowgid,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec_minmax,
621 .strategy = &sysctl_intvec,
622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
624 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800625#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#ifdef CONFIG_MATHEMU
627 {
628 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
629 .procname = "ieee_emulation_warnings",
630 .data = &sysctl_ieee_emulation_warnings,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
634 },
635#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 {
637 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
638 .procname = "userprocess_debug",
639 .data = &sysctl_userprocess_debug,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec,
643 },
644#endif
645 {
646 .ctl_name = KERN_PIDMAX,
647 .procname = "pid_max",
648 .data = &pid_max,
649 .maxlen = sizeof (int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec_minmax,
652 .strategy = sysctl_intvec,
653 .extra1 = &pid_max_min,
654 .extra2 = &pid_max_max,
655 },
656 {
657 .ctl_name = KERN_PANIC_ON_OOPS,
658 .procname = "panic_on_oops",
659 .data = &panic_on_oops,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800664#if defined CONFIG_PRINTK
665 {
666 .ctl_name = KERN_PRINTK,
667 .procname = "printk",
668 .data = &console_loglevel,
669 .maxlen = 4*sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 {
674 .ctl_name = KERN_PRINTK_RATELIMIT,
675 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700676 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec_jiffies,
680 .strategy = &sysctl_jiffies,
681 },
682 {
683 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
684 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700685 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec,
689 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800690#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 {
692 .ctl_name = KERN_NGROUPS_MAX,
693 .procname = "ngroups_max",
694 .data = &ngroups_max,
695 .maxlen = sizeof (int),
696 .mode = 0444,
697 .proc_handler = &proc_dointvec,
698 },
699#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
700 {
701 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
702 .procname = "unknown_nmi_panic",
703 .data = &unknown_nmi_panic,
704 .maxlen = sizeof (int),
705 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200706 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
Don Zickus407984f2006-09-26 10:52:27 +0200708 {
Don Zickus407984f2006-09-26 10:52:27 +0200709 .procname = "nmi_watchdog",
710 .data = &nmi_watchdog_enabled,
711 .maxlen = sizeof (int),
712 .mode = 0644,
713 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 },
715#endif
716#if defined(CONFIG_X86)
717 {
Don Zickus8da5add2006-09-26 10:52:27 +0200718 .ctl_name = KERN_PANIC_ON_NMI,
719 .procname = "panic_on_unrecovered_nmi",
720 .data = &panic_on_unrecovered_nmi,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec,
724 },
725 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 .ctl_name = KERN_BOOTLOADER_TYPE,
727 .procname = "bootloader_type",
728 .data = &bootloader_type,
729 .maxlen = sizeof (int),
730 .mode = 0444,
731 .proc_handler = &proc_dointvec,
732 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100733 {
734 .ctl_name = CTL_UNNUMBERED,
735 .procname = "kstack_depth_to_print",
736 .data = &kstack_depth_to_print,
737 .maxlen = sizeof(int),
738 .mode = 0644,
739 .proc_handler = &proc_dointvec,
740 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100741 {
742 .ctl_name = CTL_UNNUMBERED,
743 .procname = "io_delay_type",
744 .data = &io_delay_type,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
748 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800750#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 {
752 .ctl_name = KERN_RANDOMIZE,
753 .procname = "randomize_va_space",
754 .data = &randomize_va_space,
755 .maxlen = sizeof(int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
758 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800759#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800760#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700761 {
762 .ctl_name = KERN_SPIN_RETRY,
763 .procname = "spin_retry",
764 .data = &spin_retry,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
768 },
769#endif
Len Brown673d5b42007-07-28 03:33:16 -0400770#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800771 {
Pavel Machekc255d842006-02-20 18:27:58 -0800772 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700773 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800774 .maxlen = sizeof (unsigned long),
775 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800776 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800777 },
778#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800779#ifdef CONFIG_IA64
780 {
781 .ctl_name = KERN_IA64_UNALIGNED,
782 .procname = "ignore-unaligned-usertrap",
783 .data = &no_unaligned_warning,
784 .maxlen = sizeof (int),
785 .mode = 0644,
786 .proc_handler = &proc_dointvec,
787 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800788 {
789 .ctl_name = CTL_UNNUMBERED,
790 .procname = "unaligned-dump-stack",
791 .data = &unaligned_dump_stack,
792 .maxlen = sizeof (int),
793 .mode = 0644,
794 .proc_handler = &proc_dointvec,
795 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800796#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700797#ifdef CONFIG_DETECT_SOFTLOCKUP
798 {
799 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200800 .procname = "softlockup_panic",
801 .data = &softlockup_panic,
802 .maxlen = sizeof(int),
803 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700804 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200805 .strategy = &sysctl_intvec,
806 .extra1 = &zero,
807 .extra2 = &one,
808 },
809 {
810 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700811 .procname = "softlockup_thresh",
812 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200813 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700814 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800815 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700816 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200817 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700818 .extra2 = &sixty,
819 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800820#endif
821#ifdef CONFIG_DETECT_HUNG_TASK
822 {
823 .ctl_name = CTL_UNNUMBERED,
824 .procname = "hung_task_panic",
825 .data = &sysctl_hung_task_panic,
826 .maxlen = sizeof(int),
827 .mode = 0644,
828 .proc_handler = &proc_dointvec_minmax,
829 .strategy = &sysctl_intvec,
830 .extra1 = &zero,
831 .extra2 = &one,
832 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100833 {
834 .ctl_name = CTL_UNNUMBERED,
835 .procname = "hung_task_check_count",
836 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100837 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100838 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100839 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100840 .strategy = &sysctl_intvec,
841 },
842 {
843 .ctl_name = CTL_UNNUMBERED,
844 .procname = "hung_task_timeout_secs",
845 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100846 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100847 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800848 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100849 .strategy = &sysctl_intvec,
850 },
851 {
852 .ctl_name = CTL_UNNUMBERED,
853 .procname = "hung_task_warnings",
854 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100855 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100856 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100857 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100858 .strategy = &sysctl_intvec,
859 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700860#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200861#ifdef CONFIG_COMPAT
862 {
863 .ctl_name = KERN_COMPAT_LOG,
864 .procname = "compat-log",
865 .data = &compat_log,
866 .maxlen = sizeof (int),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec,
869 },
870#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700871#ifdef CONFIG_RT_MUTEXES
872 {
873 .ctl_name = KERN_MAX_LOCK_DEPTH,
874 .procname = "max_lock_depth",
875 .data = &max_lock_depth,
876 .maxlen = sizeof(int),
877 .mode = 0644,
878 .proc_handler = &proc_dointvec,
879 },
880#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700881 {
882 .ctl_name = CTL_UNNUMBERED,
883 .procname = "poweroff_cmd",
884 .data = &poweroff_cmd,
885 .maxlen = POWEROFF_CMD_PATH_LEN,
886 .mode = 0644,
887 .proc_handler = &proc_dostring,
888 .strategy = &sysctl_string,
889 },
David Howells0b77f5b2008-04-29 01:01:32 -0700890#ifdef CONFIG_KEYS
891 {
892 .ctl_name = CTL_UNNUMBERED,
893 .procname = "keys",
894 .mode = 0555,
895 .child = key_sysctls,
896 },
897#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700898#ifdef CONFIG_RCU_TORTURE_TEST
899 {
900 .ctl_name = CTL_UNNUMBERED,
901 .procname = "rcutorture_runnable",
902 .data = &rcutorture_runnable,
903 .maxlen = sizeof(int),
904 .mode = 0644,
905 .proc_handler = &proc_dointvec,
906 },
907#endif
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
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700916/*
917 * NOTE: do not add new entries to this table unless you have read
918 * Documentation/sysctl/ctl_unnumbered.txt
919 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 { .ctl_name = 0 }
921};
922
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700923static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 {
925 .ctl_name = VM_OVERCOMMIT_MEMORY,
926 .procname = "overcommit_memory",
927 .data = &sysctl_overcommit_memory,
928 .maxlen = sizeof(sysctl_overcommit_memory),
929 .mode = 0644,
930 .proc_handler = &proc_dointvec,
931 },
932 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700933 .ctl_name = VM_PANIC_ON_OOM,
934 .procname = "panic_on_oom",
935 .data = &sysctl_panic_on_oom,
936 .maxlen = sizeof(sysctl_panic_on_oom),
937 .mode = 0644,
938 .proc_handler = &proc_dointvec,
939 },
940 {
David Rientjesfe071d72007-10-16 23:25:56 -0700941 .ctl_name = CTL_UNNUMBERED,
942 .procname = "oom_kill_allocating_task",
943 .data = &sysctl_oom_kill_allocating_task,
944 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
945 .mode = 0644,
946 .proc_handler = &proc_dointvec,
947 },
948 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800949 .ctl_name = CTL_UNNUMBERED,
950 .procname = "oom_dump_tasks",
951 .data = &sysctl_oom_dump_tasks,
952 .maxlen = sizeof(sysctl_oom_dump_tasks),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
955 },
956 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 .ctl_name = VM_OVERCOMMIT_RATIO,
958 .procname = "overcommit_ratio",
959 .data = &sysctl_overcommit_ratio,
960 .maxlen = sizeof(sysctl_overcommit_ratio),
961 .mode = 0644,
962 .proc_handler = &proc_dointvec,
963 },
964 {
965 .ctl_name = VM_PAGE_CLUSTER,
966 .procname = "page-cluster",
967 .data = &page_cluster,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = &proc_dointvec,
971 },
972 {
973 .ctl_name = VM_DIRTY_BACKGROUND,
974 .procname = "dirty_background_ratio",
975 .data = &dirty_background_ratio,
976 .maxlen = sizeof(dirty_background_ratio),
977 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800978 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 .strategy = &sysctl_intvec,
980 .extra1 = &zero,
981 .extra2 = &one_hundred,
982 },
983 {
David Rientjes2da02992009-01-06 14:39:31 -0800984 .ctl_name = CTL_UNNUMBERED,
985 .procname = "dirty_background_bytes",
986 .data = &dirty_background_bytes,
987 .maxlen = sizeof(dirty_background_bytes),
988 .mode = 0644,
989 .proc_handler = &dirty_background_bytes_handler,
990 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800991 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -0800992 },
993 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 .ctl_name = VM_DIRTY_RATIO,
995 .procname = "dirty_ratio",
996 .data = &vm_dirty_ratio,
997 .maxlen = sizeof(vm_dirty_ratio),
998 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700999 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 .strategy = &sysctl_intvec,
1001 .extra1 = &zero,
1002 .extra2 = &one_hundred,
1003 },
1004 {
David Rientjes2da02992009-01-06 14:39:31 -08001005 .ctl_name = CTL_UNNUMBERED,
1006 .procname = "dirty_bytes",
1007 .data = &vm_dirty_bytes,
1008 .maxlen = sizeof(vm_dirty_bytes),
1009 .mode = 0644,
1010 .proc_handler = &dirty_bytes_handler,
1011 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001012 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001013 },
1014 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001016 .data = &dirty_writeback_interval,
1017 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 .mode = 0644,
1019 .proc_handler = &dirty_writeback_centisecs_handler,
1020 },
1021 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001023 .data = &dirty_expire_interval,
1024 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001026 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 },
1028 {
1029 .ctl_name = VM_NR_PDFLUSH_THREADS,
1030 .procname = "nr_pdflush_threads",
1031 .data = &nr_pdflush_threads,
1032 .maxlen = sizeof nr_pdflush_threads,
1033 .mode = 0444 /* read-only*/,
1034 .proc_handler = &proc_dointvec,
1035 },
1036 {
Peter W Morrealefafd6882009-04-06 19:00:29 -07001037 .ctl_name = CTL_UNNUMBERED,
1038 .procname = "nr_pdflush_threads_min",
1039 .data = &nr_pdflush_threads_min,
1040 .maxlen = sizeof nr_pdflush_threads_min,
1041 .mode = 0644 /* read-write */,
1042 .proc_handler = &proc_dointvec_minmax,
1043 .strategy = &sysctl_intvec,
1044 .extra1 = &one,
1045 .extra2 = &nr_pdflush_threads_max,
1046 },
1047 {
1048 .ctl_name = CTL_UNNUMBERED,
1049 .procname = "nr_pdflush_threads_max",
1050 .data = &nr_pdflush_threads_max,
1051 .maxlen = sizeof nr_pdflush_threads_max,
1052 .mode = 0644 /* read-write */,
1053 .proc_handler = &proc_dointvec_minmax,
1054 .strategy = &sysctl_intvec,
1055 .extra1 = &nr_pdflush_threads_min,
1056 .extra2 = &one_thousand,
1057 },
1058 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 .ctl_name = VM_SWAPPINESS,
1060 .procname = "swappiness",
1061 .data = &vm_swappiness,
1062 .maxlen = sizeof(vm_swappiness),
1063 .mode = 0644,
1064 .proc_handler = &proc_dointvec_minmax,
1065 .strategy = &sysctl_intvec,
1066 .extra1 = &zero,
1067 .extra2 = &one_hundred,
1068 },
1069#ifdef CONFIG_HUGETLB_PAGE
1070 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001072 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 .maxlen = sizeof(unsigned long),
1074 .mode = 0644,
1075 .proc_handler = &hugetlb_sysctl_handler,
1076 .extra1 = (void *)&hugetlb_zero,
1077 .extra2 = (void *)&hugetlb_infinity,
1078 },
1079 {
1080 .ctl_name = VM_HUGETLB_GROUP,
1081 .procname = "hugetlb_shm_group",
1082 .data = &sysctl_hugetlb_shm_group,
1083 .maxlen = sizeof(gid_t),
1084 .mode = 0644,
1085 .proc_handler = &proc_dointvec,
1086 },
Mel Gorman396faf02007-07-17 04:03:13 -07001087 {
1088 .ctl_name = CTL_UNNUMBERED,
1089 .procname = "hugepages_treat_as_movable",
1090 .data = &hugepages_treat_as_movable,
1091 .maxlen = sizeof(int),
1092 .mode = 0644,
1093 .proc_handler = &hugetlb_treat_movable_handler,
1094 },
Adam Litke54f9f802007-10-16 01:26:20 -07001095 {
1096 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001097 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001098 .data = NULL,
1099 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001100 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001101 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001102 .extra1 = (void *)&hugetlb_zero,
1103 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001104 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105#endif
1106 {
1107 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1108 .procname = "lowmem_reserve_ratio",
1109 .data = &sysctl_lowmem_reserve_ratio,
1110 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1111 .mode = 0644,
1112 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1113 .strategy = &sysctl_intvec,
1114 },
1115 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001116 .ctl_name = VM_DROP_PAGECACHE,
1117 .procname = "drop_caches",
1118 .data = &sysctl_drop_caches,
1119 .maxlen = sizeof(int),
1120 .mode = 0644,
1121 .proc_handler = drop_caches_sysctl_handler,
1122 .strategy = &sysctl_intvec,
1123 },
1124 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 .ctl_name = VM_MIN_FREE_KBYTES,
1126 .procname = "min_free_kbytes",
1127 .data = &min_free_kbytes,
1128 .maxlen = sizeof(min_free_kbytes),
1129 .mode = 0644,
1130 .proc_handler = &min_free_kbytes_sysctl_handler,
1131 .strategy = &sysctl_intvec,
1132 .extra1 = &zero,
1133 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001134 {
1135 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1136 .procname = "percpu_pagelist_fraction",
1137 .data = &percpu_pagelist_fraction,
1138 .maxlen = sizeof(percpu_pagelist_fraction),
1139 .mode = 0644,
1140 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1141 .strategy = &sysctl_intvec,
1142 .extra1 = &min_percpu_pagelist_fract,
1143 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144#ifdef CONFIG_MMU
1145 {
1146 .ctl_name = VM_MAX_MAP_COUNT,
1147 .procname = "max_map_count",
1148 .data = &sysctl_max_map_count,
1149 .maxlen = sizeof(sysctl_max_map_count),
1150 .mode = 0644,
1151 .proc_handler = &proc_dointvec
1152 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001153#else
1154 {
1155 .ctl_name = CTL_UNNUMBERED,
1156 .procname = "nr_trim_pages",
1157 .data = &sysctl_nr_trim_pages,
1158 .maxlen = sizeof(sysctl_nr_trim_pages),
1159 .mode = 0644,
1160 .proc_handler = &proc_dointvec_minmax,
1161 .strategy = &sysctl_intvec,
1162 .extra1 = &zero,
1163 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164#endif
1165 {
1166 .ctl_name = VM_LAPTOP_MODE,
1167 .procname = "laptop_mode",
1168 .data = &laptop_mode,
1169 .maxlen = sizeof(laptop_mode),
1170 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001171 .proc_handler = &proc_dointvec_jiffies,
1172 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 },
1174 {
1175 .ctl_name = VM_BLOCK_DUMP,
1176 .procname = "block_dump",
1177 .data = &block_dump,
1178 .maxlen = sizeof(block_dump),
1179 .mode = 0644,
1180 .proc_handler = &proc_dointvec,
1181 .strategy = &sysctl_intvec,
1182 .extra1 = &zero,
1183 },
1184 {
1185 .ctl_name = VM_VFS_CACHE_PRESSURE,
1186 .procname = "vfs_cache_pressure",
1187 .data = &sysctl_vfs_cache_pressure,
1188 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1189 .mode = 0644,
1190 .proc_handler = &proc_dointvec,
1191 .strategy = &sysctl_intvec,
1192 .extra1 = &zero,
1193 },
1194#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1195 {
1196 .ctl_name = VM_LEGACY_VA_LAYOUT,
1197 .procname = "legacy_va_layout",
1198 .data = &sysctl_legacy_va_layout,
1199 .maxlen = sizeof(sysctl_legacy_va_layout),
1200 .mode = 0644,
1201 .proc_handler = &proc_dointvec,
1202 .strategy = &sysctl_intvec,
1203 .extra1 = &zero,
1204 },
1205#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001206#ifdef CONFIG_NUMA
1207 {
1208 .ctl_name = VM_ZONE_RECLAIM_MODE,
1209 .procname = "zone_reclaim_mode",
1210 .data = &zone_reclaim_mode,
1211 .maxlen = sizeof(zone_reclaim_mode),
1212 .mode = 0644,
1213 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001214 .strategy = &sysctl_intvec,
1215 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001216 },
Christoph Lameter96146342006-07-03 00:24:13 -07001217 {
1218 .ctl_name = VM_MIN_UNMAPPED,
1219 .procname = "min_unmapped_ratio",
1220 .data = &sysctl_min_unmapped_ratio,
1221 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1222 .mode = 0644,
1223 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1224 .strategy = &sysctl_intvec,
1225 .extra1 = &zero,
1226 .extra2 = &one_hundred,
1227 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001228 {
1229 .ctl_name = VM_MIN_SLAB,
1230 .procname = "min_slab_ratio",
1231 .data = &sysctl_min_slab_ratio,
1232 .maxlen = sizeof(sysctl_min_slab_ratio),
1233 .mode = 0644,
1234 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1235 .strategy = &sysctl_intvec,
1236 .extra1 = &zero,
1237 .extra2 = &one_hundred,
1238 },
Christoph Lameter17436602006-01-18 17:42:32 -08001239#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001240#ifdef CONFIG_SMP
1241 {
1242 .ctl_name = CTL_UNNUMBERED,
1243 .procname = "stat_interval",
1244 .data = &sysctl_stat_interval,
1245 .maxlen = sizeof(sysctl_stat_interval),
1246 .mode = 0644,
1247 .proc_handler = &proc_dointvec_jiffies,
1248 .strategy = &sysctl_jiffies,
1249 },
1250#endif
Eric Parised032182007-06-28 15:55:21 -04001251#ifdef CONFIG_SECURITY
1252 {
1253 .ctl_name = CTL_UNNUMBERED,
1254 .procname = "mmap_min_addr",
1255 .data = &mmap_min_addr,
1256 .maxlen = sizeof(unsigned long),
1257 .mode = 0644,
1258 .proc_handler = &proc_doulongvec_minmax,
1259 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001260#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001261#ifdef CONFIG_NUMA
1262 {
1263 .ctl_name = CTL_UNNUMBERED,
1264 .procname = "numa_zonelist_order",
1265 .data = &numa_zonelist_order,
1266 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1267 .mode = 0644,
1268 .proc_handler = &numa_zonelist_order_handler,
1269 .strategy = &sysctl_string,
1270 },
1271#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001272#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001273 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001274 {
1275 .ctl_name = VM_VDSO_ENABLED,
1276 .procname = "vdso_enabled",
1277 .data = &vdso_enabled,
1278 .maxlen = sizeof(vdso_enabled),
1279 .mode = 0644,
1280 .proc_handler = &proc_dointvec,
1281 .strategy = &sysctl_intvec,
1282 .extra1 = &zero,
1283 },
1284#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001285#ifdef CONFIG_HIGHMEM
1286 {
1287 .ctl_name = CTL_UNNUMBERED,
1288 .procname = "highmem_is_dirtyable",
1289 .data = &vm_highmem_is_dirtyable,
1290 .maxlen = sizeof(vm_highmem_is_dirtyable),
1291 .mode = 0644,
1292 .proc_handler = &proc_dointvec_minmax,
1293 .strategy = &sysctl_intvec,
1294 .extra1 = &zero,
1295 .extra2 = &one,
1296 },
1297#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001298#ifdef CONFIG_UNEVICTABLE_LRU
1299 {
1300 .ctl_name = CTL_UNNUMBERED,
1301 .procname = "scan_unevictable_pages",
1302 .data = &scan_unevictable_pages,
1303 .maxlen = sizeof(scan_unevictable_pages),
1304 .mode = 0644,
1305 .proc_handler = &scan_unevictable_handler,
1306 },
1307#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001308/*
1309 * NOTE: do not add new entries to this table unless you have read
1310 * Documentation/sysctl/ctl_unnumbered.txt
1311 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 { .ctl_name = 0 }
1313};
1314
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001315#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001316static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001317 { .ctl_name = 0 }
1318};
1319#endif
1320
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001321static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 {
1323 .ctl_name = FS_NRINODE,
1324 .procname = "inode-nr",
1325 .data = &inodes_stat,
1326 .maxlen = 2*sizeof(int),
1327 .mode = 0444,
1328 .proc_handler = &proc_dointvec,
1329 },
1330 {
1331 .ctl_name = FS_STATINODE,
1332 .procname = "inode-state",
1333 .data = &inodes_stat,
1334 .maxlen = 7*sizeof(int),
1335 .mode = 0444,
1336 .proc_handler = &proc_dointvec,
1337 },
1338 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 .procname = "file-nr",
1340 .data = &files_stat,
1341 .maxlen = 3*sizeof(int),
1342 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001343 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 },
1345 {
1346 .ctl_name = FS_MAXFILE,
1347 .procname = "file-max",
1348 .data = &files_stat.max_files,
1349 .maxlen = sizeof(int),
1350 .mode = 0644,
1351 .proc_handler = &proc_dointvec,
1352 },
1353 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001354 .ctl_name = CTL_UNNUMBERED,
1355 .procname = "nr_open",
1356 .data = &sysctl_nr_open,
1357 .maxlen = sizeof(int),
1358 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001359 .proc_handler = &proc_dointvec_minmax,
1360 .extra1 = &sysctl_nr_open_min,
1361 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001362 },
1363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .ctl_name = FS_DENTRY,
1365 .procname = "dentry-state",
1366 .data = &dentry_stat,
1367 .maxlen = 6*sizeof(int),
1368 .mode = 0444,
1369 .proc_handler = &proc_dointvec,
1370 },
1371 {
1372 .ctl_name = FS_OVERFLOWUID,
1373 .procname = "overflowuid",
1374 .data = &fs_overflowuid,
1375 .maxlen = sizeof(int),
1376 .mode = 0644,
1377 .proc_handler = &proc_dointvec_minmax,
1378 .strategy = &sysctl_intvec,
1379 .extra1 = &minolduid,
1380 .extra2 = &maxolduid,
1381 },
1382 {
1383 .ctl_name = FS_OVERFLOWGID,
1384 .procname = "overflowgid",
1385 .data = &fs_overflowgid,
1386 .maxlen = sizeof(int),
1387 .mode = 0644,
1388 .proc_handler = &proc_dointvec_minmax,
1389 .strategy = &sysctl_intvec,
1390 .extra1 = &minolduid,
1391 .extra2 = &maxolduid,
1392 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001393#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 {
1395 .ctl_name = FS_LEASES,
1396 .procname = "leases-enable",
1397 .data = &leases_enable,
1398 .maxlen = sizeof(int),
1399 .mode = 0644,
1400 .proc_handler = &proc_dointvec,
1401 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001402#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403#ifdef CONFIG_DNOTIFY
1404 {
1405 .ctl_name = FS_DIR_NOTIFY,
1406 .procname = "dir-notify-enable",
1407 .data = &dir_notify_enable,
1408 .maxlen = sizeof(int),
1409 .mode = 0644,
1410 .proc_handler = &proc_dointvec,
1411 },
1412#endif
1413#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001414#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 {
1416 .ctl_name = FS_LEASE_TIME,
1417 .procname = "lease-break-time",
1418 .data = &lease_break_time,
1419 .maxlen = sizeof(int),
1420 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001421 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001423#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001424#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 .procname = "aio-nr",
1427 .data = &aio_nr,
1428 .maxlen = sizeof(aio_nr),
1429 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001430 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 },
1432 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 .procname = "aio-max-nr",
1434 .data = &aio_max_nr,
1435 .maxlen = sizeof(aio_max_nr),
1436 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001437 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001439#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001440#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001441 {
1442 .ctl_name = FS_INOTIFY,
1443 .procname = "inotify",
1444 .mode = 0555,
1445 .child = inotify_table,
1446 },
1447#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001448#ifdef CONFIG_EPOLL
1449 {
1450 .procname = "epoll",
1451 .mode = 0555,
1452 .child = epoll_table,
1453 },
1454#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001456 {
1457 .ctl_name = KERN_SETUID_DUMPABLE,
1458 .procname = "suid_dumpable",
1459 .data = &suid_dumpable,
1460 .maxlen = sizeof(int),
1461 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001462 .proc_handler = &proc_dointvec_minmax,
1463 .strategy = &sysctl_intvec,
1464 .extra1 = &zero,
1465 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001466 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001467#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1468 {
1469 .ctl_name = CTL_UNNUMBERED,
1470 .procname = "binfmt_misc",
1471 .mode = 0555,
1472 .child = binfmt_misc_table,
1473 },
1474#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001475/*
1476 * NOTE: do not add new entries to this table unless you have read
1477 * Documentation/sysctl/ctl_unnumbered.txt
1478 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 { .ctl_name = 0 }
1480};
1481
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001482static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001483#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001484 {
1485 .ctl_name = CTL_UNNUMBERED,
1486 .procname = "exception-trace",
1487 .data = &show_unhandled_signals,
1488 .maxlen = sizeof(int),
1489 .mode = 0644,
1490 .proc_handler = proc_dointvec
1491 },
1492#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 { .ctl_name = 0 }
1494};
1495
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001496static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001498};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Al Viro330d57f2005-11-04 10:18:40 +00001500static DEFINE_SPINLOCK(sysctl_lock);
1501
1502/* called under sysctl_lock */
1503static int use_table(struct ctl_table_header *p)
1504{
1505 if (unlikely(p->unregistering))
1506 return 0;
1507 p->used++;
1508 return 1;
1509}
1510
1511/* called under sysctl_lock */
1512static void unuse_table(struct ctl_table_header *p)
1513{
1514 if (!--p->used)
1515 if (unlikely(p->unregistering))
1516 complete(p->unregistering);
1517}
1518
1519/* called under sysctl_lock, will reacquire if has to wait */
1520static void start_unregistering(struct ctl_table_header *p)
1521{
1522 /*
1523 * if p->used is 0, nobody will ever touch that entry again;
1524 * we'll eliminate all paths to it before dropping sysctl_lock
1525 */
1526 if (unlikely(p->used)) {
1527 struct completion wait;
1528 init_completion(&wait);
1529 p->unregistering = &wait;
1530 spin_unlock(&sysctl_lock);
1531 wait_for_completion(&wait);
1532 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001533 } else {
1534 /* anything non-NULL; we'll never dereference it */
1535 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001536 }
1537 /*
1538 * do not remove from the list until nobody holds it; walking the
1539 * list in do_sysctl() relies on that.
1540 */
1541 list_del_init(&p->ctl_entry);
1542}
1543
Al Virof7e6ced2008-07-15 01:44:23 -04001544void sysctl_head_get(struct ctl_table_header *head)
1545{
1546 spin_lock(&sysctl_lock);
1547 head->count++;
1548 spin_unlock(&sysctl_lock);
1549}
1550
1551void sysctl_head_put(struct ctl_table_header *head)
1552{
1553 spin_lock(&sysctl_lock);
1554 if (!--head->count)
1555 kfree(head);
1556 spin_unlock(&sysctl_lock);
1557}
1558
1559struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1560{
1561 if (!head)
1562 BUG();
1563 spin_lock(&sysctl_lock);
1564 if (!use_table(head))
1565 head = ERR_PTR(-ENOENT);
1566 spin_unlock(&sysctl_lock);
1567 return head;
1568}
1569
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001570void sysctl_head_finish(struct ctl_table_header *head)
1571{
1572 if (!head)
1573 return;
1574 spin_lock(&sysctl_lock);
1575 unuse_table(head);
1576 spin_unlock(&sysctl_lock);
1577}
1578
Al Viro73455092008-07-14 21:22:20 -04001579static struct ctl_table_set *
1580lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1581{
1582 struct ctl_table_set *set = &root->default_set;
1583 if (root->lookup)
1584 set = root->lookup(root, namespaces);
1585 return set;
1586}
1587
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001588static struct list_head *
1589lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001590{
Al Viro73455092008-07-14 21:22:20 -04001591 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1592 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001593}
1594
1595struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1596 struct ctl_table_header *prev)
1597{
1598 struct ctl_table_root *root;
1599 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001600 struct ctl_table_header *head;
1601 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001602
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001603 spin_lock(&sysctl_lock);
1604 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001605 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001606 tmp = &prev->ctl_entry;
1607 unuse_table(prev);
1608 goto next;
1609 }
1610 tmp = &root_table_header.ctl_entry;
1611 for (;;) {
1612 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1613
1614 if (!use_table(head))
1615 goto next;
1616 spin_unlock(&sysctl_lock);
1617 return head;
1618 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001619 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001620 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001621 header_list = lookup_header_list(root, namespaces);
1622 if (tmp != header_list)
1623 continue;
1624
1625 do {
1626 root = list_entry(root->root_list.next,
1627 struct ctl_table_root, root_list);
1628 if (root == &sysctl_table_root)
1629 goto out;
1630 header_list = lookup_header_list(root, namespaces);
1631 } while (list_empty(header_list));
1632 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001633 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001634out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001635 spin_unlock(&sysctl_lock);
1636 return NULL;
1637}
1638
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001639struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1640{
1641 return __sysctl_head_next(current->nsproxy, prev);
1642}
1643
1644void register_sysctl_root(struct ctl_table_root *root)
1645{
1646 spin_lock(&sysctl_lock);
1647 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1648 spin_unlock(&sysctl_lock);
1649}
1650
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001651#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001652/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001653static int do_sysctl_strategy(struct ctl_table_root *root,
1654 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001655 void __user *oldval, size_t __user *oldlenp,
1656 void __user *newval, size_t newlen)
1657{
1658 int op = 0, rc;
1659
1660 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001661 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001662 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001663 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001664 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001665 return -EPERM;
1666
1667 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001668 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001669 if (rc < 0)
1670 return rc;
1671 if (rc > 0)
1672 return 0;
1673 }
1674
1675 /* If there is no strategy routine, or if the strategy returns
1676 * zero, proceed with automatic r/w */
1677 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001678 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001679 if (rc < 0)
1680 return rc;
1681 }
1682 return 0;
1683}
1684
1685static int parse_table(int __user *name, int nlen,
1686 void __user *oldval, size_t __user *oldlenp,
1687 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001688 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001689 struct ctl_table *table)
1690{
1691 int n;
1692repeat:
1693 if (!nlen)
1694 return -ENOTDIR;
1695 if (get_user(n, name))
1696 return -EFAULT;
1697 for ( ; table->ctl_name || table->procname; table++) {
1698 if (!table->ctl_name)
1699 continue;
1700 if (n == table->ctl_name) {
1701 int error;
1702 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001703 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001704 return -EPERM;
1705 name++;
1706 nlen--;
1707 table = table->child;
1708 goto repeat;
1709 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001710 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001711 oldval, oldlenp,
1712 newval, newlen);
1713 return error;
1714 }
1715 }
1716 return -ENOTDIR;
1717}
1718
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1720 void __user *newval, size_t newlen)
1721{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001722 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001723 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1726 return -ENOTDIR;
1727 if (oldval) {
1728 int old_len;
1729 if (!oldlenp || get_user(old_len, oldlenp))
1730 return -EFAULT;
1731 }
Al Viro330d57f2005-11-04 10:18:40 +00001732
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001733 for (head = sysctl_head_next(NULL); head;
1734 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001735 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001736 newval, newlen,
1737 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001738 if (error != -ENOTDIR) {
1739 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001740 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001741 }
1742 }
Al Viro330d57f2005-11-04 10:18:40 +00001743 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744}
1745
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001746SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747{
1748 struct __sysctl_args tmp;
1749 int error;
1750
1751 if (copy_from_user(&tmp, args, sizeof(tmp)))
1752 return -EFAULT;
1753
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001754 error = deprecated_sysctl_warning(&tmp);
1755 if (error)
1756 goto out;
1757
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 lock_kernel();
1759 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1760 tmp.newval, tmp.newlen);
1761 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001762out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 return error;
1764}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001765#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
1767/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001768 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 * some sysctl variables are readonly even to root.
1770 */
1771
1772static int test_perm(int mode, int op)
1773{
David Howells76aac0e2008-11-14 10:39:12 +11001774 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 mode >>= 6;
1776 else if (in_egroup_p(0))
1777 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001778 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 return 0;
1780 return -EACCES;
1781}
1782
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001783int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
1785 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001786 int mode;
1787
Al Viroe6305c42008-07-15 21:03:57 -04001788 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 if (error)
1790 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001791
1792 if (root->permissions)
1793 mode = root->permissions(root, current->nsproxy, table);
1794 else
1795 mode = table->mode;
1796
1797 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798}
1799
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001800static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1801{
1802 for (; table->ctl_name || table->procname; table++) {
1803 table->parent = parent;
1804 if (table->child)
1805 sysctl_set_parent(table, table->child);
1806 }
1807}
1808
1809static __init int sysctl_init(void)
1810{
1811 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001812#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1813 {
1814 int err;
1815 err = sysctl_check_table(current->nsproxy, root_table);
1816 }
1817#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001818 return 0;
1819}
1820
1821core_initcall(sysctl_init);
1822
Al Virobfbcf032008-07-27 06:31:22 +01001823static struct ctl_table *is_branch_in(struct ctl_table *branch,
1824 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001825{
1826 struct ctl_table *p;
1827 const char *s = branch->procname;
1828
1829 /* branch should have named subdirectory as its first element */
1830 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001831 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001832
1833 /* ... and nothing else */
1834 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001835 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001836
1837 /* table should contain subdirectory with the same name */
1838 for (p = table; p->procname || p->ctl_name; p++) {
1839 if (!p->child)
1840 continue;
1841 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001842 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001843 }
Al Virobfbcf032008-07-27 06:31:22 +01001844 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001845}
1846
1847/* see if attaching q to p would be an improvement */
1848static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1849{
1850 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001851 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001852 int is_better = 0;
1853 int not_in_parent = !p->attached_by;
1854
Al Virobfbcf032008-07-27 06:31:22 +01001855 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001856 if (by == q->attached_by)
1857 is_better = 1;
1858 if (to == p->attached_by)
1859 not_in_parent = 1;
1860 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001861 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001862 }
1863
1864 if (is_better && not_in_parent) {
1865 q->attached_by = by;
1866 q->attached_to = to;
1867 q->parent = p;
1868 }
1869}
1870
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001872 * __register_sysctl_paths - register a sysctl hierarchy
1873 * @root: List of sysctl headers to register on
1874 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001875 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 *
1878 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001879 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001881 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 *
1883 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1884 * must be unique within that level of sysctl
1885 *
1886 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1887 * enter a sysctl file
1888 *
1889 * data - a pointer to data for use by proc_handler
1890 *
1891 * maxlen - the maximum size in bytes of the data
1892 *
1893 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1894 *
1895 * child - a pointer to the child sysctl table if this entry is a directory, or
1896 * %NULL.
1897 *
1898 * proc_handler - the text handler routine (described below)
1899 *
1900 * strategy - the strategy routine (described below)
1901 *
1902 * de - for internal use by the sysctl routines
1903 *
1904 * extra1, extra2 - extra pointers usable by the proc handler routines
1905 *
1906 * Leaf nodes in the sysctl tree will be represented by a single file
1907 * under /proc; non-leaf nodes will be represented by directories.
1908 *
1909 * sysctl(2) can automatically manage read and write requests through
1910 * the sysctl table. The data and maxlen fields of the ctl_table
1911 * struct enable minimal validation of the values being written to be
1912 * performed, and the mode field allows minimal authentication.
1913 *
1914 * More sophisticated management can be enabled by the provision of a
1915 * strategy routine with the table entry. This will be called before
1916 * any automatic read or write of the data is performed.
1917 *
1918 * The strategy routine may return
1919 *
1920 * < 0 - Error occurred (error is passed to user process)
1921 *
1922 * 0 - OK - proceed with automatic read or write.
1923 *
1924 * > 0 - OK - read or write has been done by the strategy routine, so
1925 * return immediately.
1926 *
1927 * There must be a proc_handler routine for any terminal nodes
1928 * mirrored under /proc/sys (non-terminals are handled by a built-in
1929 * directory handler). Several default handlers are available to
1930 * cover common cases -
1931 *
1932 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1933 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1934 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1935 *
1936 * It is the handler's job to read the input buffer from user memory
1937 * and process it. The handler should return 0 on success.
1938 *
1939 * This routine returns %NULL on a failure to register, and a pointer
1940 * to the table header on success.
1941 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001942struct ctl_table_header *__register_sysctl_paths(
1943 struct ctl_table_root *root,
1944 struct nsproxy *namespaces,
1945 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001947 struct ctl_table_header *header;
1948 struct ctl_table *new, **prevp;
1949 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001950 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001951
1952 /* Count the path components */
1953 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1954 ;
1955
1956 /*
1957 * For each path component, allocate a 2-element ctl_table array.
1958 * The first array element will be filled with the sysctl entry
1959 * for this, the second will be the sentinel (ctl_name == 0).
1960 *
1961 * We allocate everything in one go so that we don't have to
1962 * worry about freeing additional memory in unregister_sysctl_table.
1963 */
1964 header = kzalloc(sizeof(struct ctl_table_header) +
1965 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1966 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001968
1969 new = (struct ctl_table *) (header + 1);
1970
1971 /* Now connect the dots */
1972 prevp = &header->ctl_table;
1973 for (n = 0; n < npath; ++n, ++path) {
1974 /* Copy the procname */
1975 new->procname = path->procname;
1976 new->ctl_name = path->ctl_name;
1977 new->mode = 0555;
1978
1979 *prevp = new;
1980 prevp = &new->child;
1981
1982 new += 2;
1983 }
1984 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001985 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001986
1987 INIT_LIST_HEAD(&header->ctl_entry);
1988 header->used = 0;
1989 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001990 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001991 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001992 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001993#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001994 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001995 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001996 return NULL;
1997 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001998#endif
Al Viro330d57f2005-11-04 10:18:40 +00001999 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002000 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002001 header->attached_by = header->ctl_table;
2002 header->attached_to = root_table;
2003 header->parent = &root_table_header;
2004 for (set = header->set; set; set = set->parent) {
2005 struct ctl_table_header *p;
2006 list_for_each_entry(p, &set->list, ctl_entry) {
2007 if (p->unregistering)
2008 continue;
2009 try_attach(p, header);
2010 }
2011 }
2012 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002013 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002014 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002015
2016 return header;
2017}
2018
2019/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002020 * register_sysctl_table_path - register a sysctl table hierarchy
2021 * @path: The path to the directory the sysctl table is in.
2022 * @table: the top-level table structure
2023 *
2024 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2025 * array. A completely 0 filled entry terminates the table.
2026 *
2027 * See __register_sysctl_paths for more details.
2028 */
2029struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2030 struct ctl_table *table)
2031{
2032 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2033 path, table);
2034}
2035
2036/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002037 * register_sysctl_table - register a sysctl table hierarchy
2038 * @table: the top-level table structure
2039 *
2040 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2041 * array. A completely 0 filled entry terminates the table.
2042 *
2043 * See register_sysctl_paths for more details.
2044 */
2045struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2046{
2047 static const struct ctl_path null_path[] = { {} };
2048
2049 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050}
2051
2052/**
2053 * unregister_sysctl_table - unregister a sysctl table hierarchy
2054 * @header: the header returned from register_sysctl_table
2055 *
2056 * Unregisters the sysctl table and all children. proc entries may not
2057 * actually be removed until they are no longer used by anyone.
2058 */
2059void unregister_sysctl_table(struct ctl_table_header * header)
2060{
Al Viro330d57f2005-11-04 10:18:40 +00002061 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002062
2063 if (header == NULL)
2064 return;
2065
Al Viro330d57f2005-11-04 10:18:40 +00002066 spin_lock(&sysctl_lock);
2067 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002068 if (!--header->parent->count) {
2069 WARN_ON(1);
2070 kfree(header->parent);
2071 }
Al Virof7e6ced2008-07-15 01:44:23 -04002072 if (!--header->count)
2073 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002074 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075}
2076
Al Viro90434762008-07-15 08:54:06 -04002077int sysctl_is_seen(struct ctl_table_header *p)
2078{
2079 struct ctl_table_set *set = p->set;
2080 int res;
2081 spin_lock(&sysctl_lock);
2082 if (p->unregistering)
2083 res = 0;
2084 else if (!set->is_seen)
2085 res = 1;
2086 else
2087 res = set->is_seen(set);
2088 spin_unlock(&sysctl_lock);
2089 return res;
2090}
2091
Al Viro73455092008-07-14 21:22:20 -04002092void setup_sysctl_set(struct ctl_table_set *p,
2093 struct ctl_table_set *parent,
2094 int (*is_seen)(struct ctl_table_set *))
2095{
2096 INIT_LIST_HEAD(&p->list);
2097 p->parent = parent ? parent : &sysctl_table_root.default_set;
2098 p->is_seen = is_seen;
2099}
2100
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002101#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002102struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002103{
2104 return NULL;
2105}
2106
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002107struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2108 struct ctl_table *table)
2109{
2110 return NULL;
2111}
2112
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002113void unregister_sysctl_table(struct ctl_table_header * table)
2114{
2115}
2116
Al Viro73455092008-07-14 21:22:20 -04002117void setup_sysctl_set(struct ctl_table_set *p,
2118 struct ctl_table_set *parent,
2119 int (*is_seen)(struct ctl_table_set *))
2120{
2121}
2122
Al Virof7e6ced2008-07-15 01:44:23 -04002123void sysctl_head_put(struct ctl_table_header *head)
2124{
2125}
2126
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002127#endif /* CONFIG_SYSCTL */
2128
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129/*
2130 * /proc/sys support
2131 */
2132
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002133#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002135static int _proc_do_string(void* data, int maxlen, int write,
2136 struct file *filp, void __user *buffer,
2137 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002138{
2139 size_t len;
2140 char __user *p;
2141 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002142
2143 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002144 *lenp = 0;
2145 return 0;
2146 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002147
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002148 if (write) {
2149 len = 0;
2150 p = buffer;
2151 while (len < *lenp) {
2152 if (get_user(c, p++))
2153 return -EFAULT;
2154 if (c == 0 || c == '\n')
2155 break;
2156 len++;
2157 }
2158 if (len >= maxlen)
2159 len = maxlen-1;
2160 if(copy_from_user(data, buffer, len))
2161 return -EFAULT;
2162 ((char *) data)[len] = 0;
2163 *ppos += *lenp;
2164 } else {
2165 len = strlen(data);
2166 if (len > maxlen)
2167 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002168
2169 if (*ppos > len) {
2170 *lenp = 0;
2171 return 0;
2172 }
2173
2174 data += *ppos;
2175 len -= *ppos;
2176
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002177 if (len > *lenp)
2178 len = *lenp;
2179 if (len)
2180 if(copy_to_user(buffer, data, len))
2181 return -EFAULT;
2182 if (len < *lenp) {
2183 if(put_user('\n', ((char __user *) buffer) + len))
2184 return -EFAULT;
2185 len++;
2186 }
2187 *lenp = len;
2188 *ppos += len;
2189 }
2190 return 0;
2191}
2192
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193/**
2194 * proc_dostring - read a string sysctl
2195 * @table: the sysctl table
2196 * @write: %TRUE if this is a write to the sysctl file
2197 * @filp: the file structure
2198 * @buffer: the user buffer
2199 * @lenp: the size of the user buffer
2200 * @ppos: file position
2201 *
2202 * Reads/writes a string from/to the user buffer. If the kernel
2203 * buffer provided is not large enough to hold the string, the
2204 * string is truncated. The copied string is %NULL-terminated.
2205 * If the string is being read by the user process, it is copied
2206 * and a newline '\n' is added. It is truncated if the buffer is
2207 * not large enough.
2208 *
2209 * Returns 0 on success.
2210 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002211int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 void __user *buffer, size_t *lenp, loff_t *ppos)
2213{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002214 return _proc_do_string(table->data, table->maxlen, write, filp,
2215 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216}
2217
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
2219static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2220 int *valp,
2221 int write, void *data)
2222{
2223 if (write) {
2224 *valp = *negp ? -*lvalp : *lvalp;
2225 } else {
2226 int val = *valp;
2227 if (val < 0) {
2228 *negp = -1;
2229 *lvalp = (unsigned long)-val;
2230 } else {
2231 *negp = 0;
2232 *lvalp = (unsigned long)val;
2233 }
2234 }
2235 return 0;
2236}
2237
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002238static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002239 int write, struct file *filp, void __user *buffer,
2240 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2242 int write, void *data),
2243 void *data)
2244{
2245#define TMPBUFLEN 21
2246 int *i, vleft, first=1, neg, val;
2247 unsigned long lval;
2248 size_t left, len;
2249
2250 char buf[TMPBUFLEN], *p;
2251 char __user *s = buffer;
2252
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002253 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 (*ppos && !write)) {
2255 *lenp = 0;
2256 return 0;
2257 }
2258
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002259 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 vleft = table->maxlen / sizeof(*i);
2261 left = *lenp;
2262
2263 if (!conv)
2264 conv = do_proc_dointvec_conv;
2265
2266 for (; left && vleft--; i++, first=0) {
2267 if (write) {
2268 while (left) {
2269 char c;
2270 if (get_user(c, s))
2271 return -EFAULT;
2272 if (!isspace(c))
2273 break;
2274 left--;
2275 s++;
2276 }
2277 if (!left)
2278 break;
2279 neg = 0;
2280 len = left;
2281 if (len > sizeof(buf) - 1)
2282 len = sizeof(buf) - 1;
2283 if (copy_from_user(buf, s, len))
2284 return -EFAULT;
2285 buf[len] = 0;
2286 p = buf;
2287 if (*p == '-' && left > 1) {
2288 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002289 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 }
2291 if (*p < '0' || *p > '9')
2292 break;
2293
2294 lval = simple_strtoul(p, &p, 0);
2295
2296 len = p-buf;
2297 if ((len < left) && *p && !isspace(*p))
2298 break;
2299 if (neg)
2300 val = -val;
2301 s += len;
2302 left -= len;
2303
2304 if (conv(&neg, &lval, i, 1, data))
2305 break;
2306 } else {
2307 p = buf;
2308 if (!first)
2309 *p++ = '\t';
2310
2311 if (conv(&neg, &lval, i, 0, data))
2312 break;
2313
2314 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2315 len = strlen(buf);
2316 if (len > left)
2317 len = left;
2318 if(copy_to_user(s, buf, len))
2319 return -EFAULT;
2320 left -= len;
2321 s += len;
2322 }
2323 }
2324
2325 if (!write && !first && left) {
2326 if(put_user('\n', s))
2327 return -EFAULT;
2328 left--, s++;
2329 }
2330 if (write) {
2331 while (left) {
2332 char c;
2333 if (get_user(c, s++))
2334 return -EFAULT;
2335 if (!isspace(c))
2336 break;
2337 left--;
2338 }
2339 }
2340 if (write && first)
2341 return -EINVAL;
2342 *lenp -= left;
2343 *ppos += *lenp;
2344 return 0;
2345#undef TMPBUFLEN
2346}
2347
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002348static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002349 void __user *buffer, size_t *lenp, loff_t *ppos,
2350 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2351 int write, void *data),
2352 void *data)
2353{
2354 return __do_proc_dointvec(table->data, table, write, filp,
2355 buffer, lenp, ppos, conv, data);
2356}
2357
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358/**
2359 * proc_dointvec - read a vector of integers
2360 * @table: the sysctl table
2361 * @write: %TRUE if this is a write to the sysctl file
2362 * @filp: the file structure
2363 * @buffer: the user buffer
2364 * @lenp: the size of the user buffer
2365 * @ppos: file position
2366 *
2367 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2368 * values from/to the user buffer, treated as an ASCII string.
2369 *
2370 * Returns 0 on success.
2371 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002372int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 void __user *buffer, size_t *lenp, loff_t *ppos)
2374{
2375 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2376 NULL,NULL);
2377}
2378
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002379/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002380 * Taint values can only be increased
2381 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002382 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002383static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002384 void __user *buffer, size_t *lenp, loff_t *ppos)
2385{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002386 struct ctl_table t;
2387 unsigned long tmptaint = get_taint();
2388 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002389
Bastian Blank91fcd412007-04-23 14:41:14 -07002390 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002391 return -EPERM;
2392
Andi Kleen25ddbb12008-10-15 22:01:41 -07002393 t = *table;
2394 t.data = &tmptaint;
2395 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2396 if (err < 0)
2397 return err;
2398
2399 if (write) {
2400 /*
2401 * Poor man's atomic or. Not worth adding a primitive
2402 * to everyone's atomic.h for this
2403 */
2404 int i;
2405 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2406 if ((tmptaint >> i) & 1)
2407 add_taint(i);
2408 }
2409 }
2410
2411 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002412}
2413
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414struct do_proc_dointvec_minmax_conv_param {
2415 int *min;
2416 int *max;
2417};
2418
2419static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2420 int *valp,
2421 int write, void *data)
2422{
2423 struct do_proc_dointvec_minmax_conv_param *param = data;
2424 if (write) {
2425 int val = *negp ? -*lvalp : *lvalp;
2426 if ((param->min && *param->min > val) ||
2427 (param->max && *param->max < val))
2428 return -EINVAL;
2429 *valp = val;
2430 } else {
2431 int val = *valp;
2432 if (val < 0) {
2433 *negp = -1;
2434 *lvalp = (unsigned long)-val;
2435 } else {
2436 *negp = 0;
2437 *lvalp = (unsigned long)val;
2438 }
2439 }
2440 return 0;
2441}
2442
2443/**
2444 * proc_dointvec_minmax - read a vector of integers with min/max values
2445 * @table: the sysctl table
2446 * @write: %TRUE if this is a write to the sysctl file
2447 * @filp: the file structure
2448 * @buffer: the user buffer
2449 * @lenp: the size of the user buffer
2450 * @ppos: file position
2451 *
2452 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2453 * values from/to the user buffer, treated as an ASCII string.
2454 *
2455 * This routine will ensure the values are within the range specified by
2456 * table->extra1 (min) and table->extra2 (max).
2457 *
2458 * Returns 0 on success.
2459 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002460int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 void __user *buffer, size_t *lenp, loff_t *ppos)
2462{
2463 struct do_proc_dointvec_minmax_conv_param param = {
2464 .min = (int *) table->extra1,
2465 .max = (int *) table->extra2,
2466 };
2467 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2468 do_proc_dointvec_minmax_conv, &param);
2469}
2470
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002471static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 struct file *filp,
2473 void __user *buffer,
2474 size_t *lenp, loff_t *ppos,
2475 unsigned long convmul,
2476 unsigned long convdiv)
2477{
2478#define TMPBUFLEN 21
2479 unsigned long *i, *min, *max, val;
2480 int vleft, first=1, neg;
2481 size_t len, left;
2482 char buf[TMPBUFLEN], *p;
2483 char __user *s = buffer;
2484
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002485 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 (*ppos && !write)) {
2487 *lenp = 0;
2488 return 0;
2489 }
2490
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002491 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 min = (unsigned long *) table->extra1;
2493 max = (unsigned long *) table->extra2;
2494 vleft = table->maxlen / sizeof(unsigned long);
2495 left = *lenp;
2496
2497 for (; left && vleft--; i++, min++, max++, first=0) {
2498 if (write) {
2499 while (left) {
2500 char c;
2501 if (get_user(c, s))
2502 return -EFAULT;
2503 if (!isspace(c))
2504 break;
2505 left--;
2506 s++;
2507 }
2508 if (!left)
2509 break;
2510 neg = 0;
2511 len = left;
2512 if (len > TMPBUFLEN-1)
2513 len = TMPBUFLEN-1;
2514 if (copy_from_user(buf, s, len))
2515 return -EFAULT;
2516 buf[len] = 0;
2517 p = buf;
2518 if (*p == '-' && left > 1) {
2519 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002520 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 }
2522 if (*p < '0' || *p > '9')
2523 break;
2524 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2525 len = p-buf;
2526 if ((len < left) && *p && !isspace(*p))
2527 break;
2528 if (neg)
2529 val = -val;
2530 s += len;
2531 left -= len;
2532
2533 if(neg)
2534 continue;
2535 if ((min && val < *min) || (max && val > *max))
2536 continue;
2537 *i = val;
2538 } else {
2539 p = buf;
2540 if (!first)
2541 *p++ = '\t';
2542 sprintf(p, "%lu", convdiv * (*i) / convmul);
2543 len = strlen(buf);
2544 if (len > left)
2545 len = left;
2546 if(copy_to_user(s, buf, len))
2547 return -EFAULT;
2548 left -= len;
2549 s += len;
2550 }
2551 }
2552
2553 if (!write && !first && left) {
2554 if(put_user('\n', s))
2555 return -EFAULT;
2556 left--, s++;
2557 }
2558 if (write) {
2559 while (left) {
2560 char c;
2561 if (get_user(c, s++))
2562 return -EFAULT;
2563 if (!isspace(c))
2564 break;
2565 left--;
2566 }
2567 }
2568 if (write && first)
2569 return -EINVAL;
2570 *lenp -= left;
2571 *ppos += *lenp;
2572 return 0;
2573#undef TMPBUFLEN
2574}
2575
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002576static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002577 struct file *filp,
2578 void __user *buffer,
2579 size_t *lenp, loff_t *ppos,
2580 unsigned long convmul,
2581 unsigned long convdiv)
2582{
2583 return __do_proc_doulongvec_minmax(table->data, table, write,
2584 filp, buffer, lenp, ppos, convmul, convdiv);
2585}
2586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587/**
2588 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2589 * @table: the sysctl table
2590 * @write: %TRUE if this is a write to the sysctl file
2591 * @filp: the file structure
2592 * @buffer: the user buffer
2593 * @lenp: the size of the user buffer
2594 * @ppos: file position
2595 *
2596 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2597 * values from/to the user buffer, treated as an ASCII string.
2598 *
2599 * This routine will ensure the values are within the range specified by
2600 * table->extra1 (min) and table->extra2 (max).
2601 *
2602 * Returns 0 on success.
2603 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002604int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 void __user *buffer, size_t *lenp, loff_t *ppos)
2606{
2607 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2608}
2609
2610/**
2611 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2612 * @table: the sysctl table
2613 * @write: %TRUE if this is a write to the sysctl file
2614 * @filp: the file structure
2615 * @buffer: the user buffer
2616 * @lenp: the size of the user buffer
2617 * @ppos: file position
2618 *
2619 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2620 * values from/to the user buffer, treated as an ASCII string. The values
2621 * are treated as milliseconds, and converted to jiffies when they are stored.
2622 *
2623 * This routine will ensure the values are within the range specified by
2624 * table->extra1 (min) and table->extra2 (max).
2625 *
2626 * Returns 0 on success.
2627 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002628int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 struct file *filp,
2630 void __user *buffer,
2631 size_t *lenp, loff_t *ppos)
2632{
2633 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2634 lenp, ppos, HZ, 1000l);
2635}
2636
2637
2638static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2639 int *valp,
2640 int write, void *data)
2641{
2642 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002643 if (*lvalp > LONG_MAX / HZ)
2644 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2646 } else {
2647 int val = *valp;
2648 unsigned long lval;
2649 if (val < 0) {
2650 *negp = -1;
2651 lval = (unsigned long)-val;
2652 } else {
2653 *negp = 0;
2654 lval = (unsigned long)val;
2655 }
2656 *lvalp = lval / HZ;
2657 }
2658 return 0;
2659}
2660
2661static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2662 int *valp,
2663 int write, void *data)
2664{
2665 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002666 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2667 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2669 } else {
2670 int val = *valp;
2671 unsigned long lval;
2672 if (val < 0) {
2673 *negp = -1;
2674 lval = (unsigned long)-val;
2675 } else {
2676 *negp = 0;
2677 lval = (unsigned long)val;
2678 }
2679 *lvalp = jiffies_to_clock_t(lval);
2680 }
2681 return 0;
2682}
2683
2684static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2685 int *valp,
2686 int write, void *data)
2687{
2688 if (write) {
2689 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2690 } else {
2691 int val = *valp;
2692 unsigned long lval;
2693 if (val < 0) {
2694 *negp = -1;
2695 lval = (unsigned long)-val;
2696 } else {
2697 *negp = 0;
2698 lval = (unsigned long)val;
2699 }
2700 *lvalp = jiffies_to_msecs(lval);
2701 }
2702 return 0;
2703}
2704
2705/**
2706 * proc_dointvec_jiffies - read a vector of integers as seconds
2707 * @table: the sysctl table
2708 * @write: %TRUE if this is a write to the sysctl file
2709 * @filp: the file structure
2710 * @buffer: the user buffer
2711 * @lenp: the size of the user buffer
2712 * @ppos: file position
2713 *
2714 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2715 * values from/to the user buffer, treated as an ASCII string.
2716 * The values read are assumed to be in seconds, and are converted into
2717 * jiffies.
2718 *
2719 * Returns 0 on success.
2720 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002721int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 void __user *buffer, size_t *lenp, loff_t *ppos)
2723{
2724 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2725 do_proc_dointvec_jiffies_conv,NULL);
2726}
2727
2728/**
2729 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2730 * @table: the sysctl table
2731 * @write: %TRUE if this is a write to the sysctl file
2732 * @filp: the file structure
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002735 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 *
2737 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2738 * values from/to the user buffer, treated as an ASCII string.
2739 * The values read are assumed to be in 1/USER_HZ seconds, and
2740 * are converted into jiffies.
2741 *
2742 * Returns 0 on success.
2743 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002744int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 void __user *buffer, size_t *lenp, loff_t *ppos)
2746{
2747 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2748 do_proc_dointvec_userhz_jiffies_conv,NULL);
2749}
2750
2751/**
2752 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2753 * @table: the sysctl table
2754 * @write: %TRUE if this is a write to the sysctl file
2755 * @filp: the file structure
2756 * @buffer: the user buffer
2757 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002758 * @ppos: file position
2759 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 *
2761 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2762 * values from/to the user buffer, treated as an ASCII string.
2763 * The values read are assumed to be in 1/1000 seconds, and
2764 * are converted into jiffies.
2765 *
2766 * Returns 0 on success.
2767 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002768int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 void __user *buffer, size_t *lenp, loff_t *ppos)
2770{
2771 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2772 do_proc_dointvec_ms_jiffies_conv, NULL);
2773}
2774
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002775static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002776 void __user *buffer, size_t *lenp, loff_t *ppos)
2777{
2778 struct pid *new_pid;
2779 pid_t tmp;
2780 int r;
2781
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002782 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002783
2784 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2785 lenp, ppos, NULL, NULL);
2786 if (r || !write)
2787 return r;
2788
2789 new_pid = find_get_pid(tmp);
2790 if (!new_pid)
2791 return -ESRCH;
2792
2793 put_pid(xchg(&cad_pid, new_pid));
2794 return 0;
2795}
2796
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797#else /* CONFIG_PROC_FS */
2798
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002799int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 void __user *buffer, size_t *lenp, loff_t *ppos)
2801{
2802 return -ENOSYS;
2803}
2804
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002805int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 void __user *buffer, size_t *lenp, loff_t *ppos)
2807{
2808 return -ENOSYS;
2809}
2810
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002811int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 void __user *buffer, size_t *lenp, loff_t *ppos)
2813{
2814 return -ENOSYS;
2815}
2816
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002817int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 void __user *buffer, size_t *lenp, loff_t *ppos)
2819{
2820 return -ENOSYS;
2821}
2822
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002823int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 void __user *buffer, size_t *lenp, loff_t *ppos)
2825{
2826 return -ENOSYS;
2827}
2828
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002829int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 void __user *buffer, size_t *lenp, loff_t *ppos)
2831{
2832 return -ENOSYS;
2833}
2834
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002835int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 void __user *buffer, size_t *lenp, loff_t *ppos)
2837{
2838 return -ENOSYS;
2839}
2840
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002841int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 struct file *filp,
2843 void __user *buffer,
2844 size_t *lenp, loff_t *ppos)
2845{
2846 return -ENOSYS;
2847}
2848
2849
2850#endif /* CONFIG_PROC_FS */
2851
2852
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002853#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854/*
2855 * General sysctl support routines
2856 */
2857
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002858/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002859int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002860 void __user *oldval, size_t __user *oldlenp,
2861 void __user *newval, size_t newlen)
2862{
2863 size_t len;
2864
2865 /* Get out of I don't have a variable */
2866 if (!table->data || !table->maxlen)
2867 return -ENOTDIR;
2868
2869 if (oldval && oldlenp) {
2870 if (get_user(len, oldlenp))
2871 return -EFAULT;
2872 if (len) {
2873 if (len > table->maxlen)
2874 len = table->maxlen;
2875 if (copy_to_user(oldval, table->data, len))
2876 return -EFAULT;
2877 if (put_user(len, oldlenp))
2878 return -EFAULT;
2879 }
2880 }
2881
2882 if (newval && newlen) {
2883 if (newlen > table->maxlen)
2884 newlen = table->maxlen;
2885
2886 if (copy_from_user(table->data, newval, newlen))
2887 return -EFAULT;
2888 }
2889 return 1;
2890}
2891
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002893int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002895 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 if (!table->data || !table->maxlen)
2898 return -ENOTDIR;
2899
2900 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002901 size_t bufsize;
2902 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002904 if (bufsize) {
2905 size_t len = strlen(table->data), copied;
2906
2907 /* This shouldn't trigger for a well-formed sysctl */
2908 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002910
2911 /* Copy up to a max of bufsize-1 bytes of the string */
2912 copied = (len >= bufsize) ? bufsize - 1 : len;
2913
2914 if (copy_to_user(oldval, table->data, copied) ||
2915 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002917 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 return -EFAULT;
2919 }
2920 }
2921 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002922 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 if (len > table->maxlen)
2924 len = table->maxlen;
2925 if(copy_from_user(table->data, newval, len))
2926 return -EFAULT;
2927 if (len == table->maxlen)
2928 len--;
2929 ((char *) table->data)[len] = 0;
2930 }
Yi Yang82c9df82005-12-30 16:37:10 +08002931 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932}
2933
2934/*
2935 * This function makes sure that all of the integers in the vector
2936 * are between the minimum and maximum values given in the arrays
2937 * table->extra1 and table->extra2, respectively.
2938 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002939int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002941 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942{
2943
2944 if (newval && newlen) {
2945 int __user *vec = (int __user *) newval;
2946 int *min = (int *) table->extra1;
2947 int *max = (int *) table->extra2;
2948 size_t length;
2949 int i;
2950
2951 if (newlen % sizeof(int) != 0)
2952 return -EINVAL;
2953
2954 if (!table->extra1 && !table->extra2)
2955 return 0;
2956
2957 if (newlen > table->maxlen)
2958 newlen = table->maxlen;
2959 length = newlen / sizeof(int);
2960
2961 for (i = 0; i < length; i++) {
2962 int value;
2963 if (get_user(value, vec + i))
2964 return -EFAULT;
2965 if (min && value < min[i])
2966 return -EINVAL;
2967 if (max && value > max[i])
2968 return -EINVAL;
2969 }
2970 }
2971 return 0;
2972}
2973
2974/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002975int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002977 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002979 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002981
2982 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002984 if (olen) {
2985 int val;
2986
2987 if (olen < sizeof(int))
2988 return -EINVAL;
2989
2990 val = *(int *)(table->data) / HZ;
2991 if (put_user(val, (int __user *)oldval))
2992 return -EFAULT;
2993 if (put_user(sizeof(int), oldlenp))
2994 return -EFAULT;
2995 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 }
2997 if (newval && newlen) {
2998 int new;
2999 if (newlen != sizeof(int))
3000 return -EINVAL;
3001 if (get_user(new, (int __user *)newval))
3002 return -EFAULT;
3003 *(int *)(table->data) = new*HZ;
3004 }
3005 return 1;
3006}
3007
3008/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003009int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003011 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003013 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003015
3016 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003018 if (olen) {
3019 int val;
3020
3021 if (olen < sizeof(int))
3022 return -EINVAL;
3023
3024 val = jiffies_to_msecs(*(int *)(table->data));
3025 if (put_user(val, (int __user *)oldval))
3026 return -EFAULT;
3027 if (put_user(sizeof(int), oldlenp))
3028 return -EFAULT;
3029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 }
3031 if (newval && newlen) {
3032 int new;
3033 if (newlen != sizeof(int))
3034 return -EINVAL;
3035 if (get_user(new, (int __user *)newval))
3036 return -EFAULT;
3037 *(int *)(table->data) = msecs_to_jiffies(new);
3038 }
3039 return 1;
3040}
3041
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003042
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003043
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003044#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
3046
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003047SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003049 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003050 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003051
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003052 if (copy_from_user(&tmp, args, sizeof(tmp)))
3053 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003054
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003055 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003056
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003057 /* If no error reading the parameters then just -ENOSYS ... */
3058 if (!error)
3059 error = -ENOSYS;
3060
3061 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062}
3063
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003064int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003065 void __user *oldval, size_t __user *oldlenp,
3066 void __user *newval, size_t newlen)
3067{
3068 return -ENOSYS;
3069}
3070
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003071int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003073 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074{
3075 return -ENOSYS;
3076}
3077
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003078int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003080 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081{
3082 return -ENOSYS;
3083}
3084
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003085int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003087 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088{
3089 return -ENOSYS;
3090}
3091
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003092int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003094 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
3096 return -ENOSYS;
3097}
3098
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003099#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003101static int deprecated_sysctl_warning(struct __sysctl_args *args)
3102{
3103 static int msg_count;
3104 int name[CTL_MAXNAME];
3105 int i;
3106
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003107 /* Check args->nlen. */
3108 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3109 return -ENOTDIR;
3110
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003111 /* Read in the sysctl name for better debug message logging */
3112 for (i = 0; i < args->nlen; i++)
3113 if (get_user(name[i], args->name + i))
3114 return -EFAULT;
3115
3116 /* Ignore accesses to kernel.version */
3117 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3118 return 0;
3119
3120 if (msg_count < 5) {
3121 msg_count++;
3122 printk(KERN_INFO
3123 "warning: process `%s' used the deprecated sysctl "
3124 "system call with ", current->comm);
3125 for (i = 0; i < args->nlen; i++)
3126 printk("%d.", name[i]);
3127 printk("\n");
3128 }
3129 return 0;
3130}
3131
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132/*
3133 * No sense putting this after each symbol definition, twice,
3134 * exception granted :-)
3135 */
3136EXPORT_SYMBOL(proc_dointvec);
3137EXPORT_SYMBOL(proc_dointvec_jiffies);
3138EXPORT_SYMBOL(proc_dointvec_minmax);
3139EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3140EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3141EXPORT_SYMBOL(proc_dostring);
3142EXPORT_SYMBOL(proc_doulongvec_minmax);
3143EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3144EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003145EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146EXPORT_SYMBOL(sysctl_intvec);
3147EXPORT_SYMBOL(sysctl_jiffies);
3148EXPORT_SYMBOL(sysctl_ms_jiffies);
3149EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003150EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151EXPORT_SYMBOL(unregister_sysctl_table);