blob: 6a463716ecbf6ccbf55b35c421303add04415306 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/uaccess.h>
54#include <asm/processor.h>
55
Andi Kleen29cbc782006-09-30 01:47:55 +020056#ifdef CONFIG_X86
57#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010058#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010059#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020060#endif
61
Eric W. Biederman7058cb02007-10-18 03:05:58 -070062static int deprecated_sysctl_warning(struct __sysctl_args *args);
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#if defined(CONFIG_SYSCTL)
65
66/* External variables not in a header file. */
67extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070068extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int sysctl_overcommit_memory;
70extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070071extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070072extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080073extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070076extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int pid_max;
79extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080081extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080082extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020083extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000086#ifndef CONFIG_MMU
87extern int sysctl_nr_trim_pages;
88#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070089#ifdef CONFIG_RCU_TORTURE_TEST
90extern int rcutorture_runnable;
91#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070093/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080094#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020096static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097#endif
98
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700100static int __maybe_unused one = 1;
101static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800102static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103static int one_hundred = 100;
104
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700105/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
106static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
109static int maxolduid = 65535;
110static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800111static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113static int ngroups_max = NGROUPS_MAX;
114
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200115#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116extern char modprobe_path[];
117#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#ifdef CONFIG_CHR_DEV_SG
119extern int sg_big_buff;
120#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
David S. Miller72c57ed2008-09-11 23:29:54 -0700122#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700123#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#endif
125
David S. Miller08714202008-11-16 23:49:24 -0800126#ifdef CONFIG_SPARC64
127extern int sysctl_tsb_ratio;
128#endif
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#ifdef __hppa__
131extern int pwrsw_enabled;
132extern int unaligned_enabled;
133#endif
134
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800135#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#ifdef CONFIG_MATHEMU
137extern int sysctl_ieee_emulation_warnings;
138#endif
139extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700140extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#ifdef CONFIG_BSD_PROCESS_ACCT
144extern int acct_parm[];
145#endif
146
Jes Sorensend2b176e2006-02-28 09:42:23 -0800147#ifdef CONFIG_IA64
148extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800149extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800150#endif
151
Ingo Molnar23f78d42006-06-27 02:54:53 -0700152#ifdef CONFIG_RT_MUTEXES
153extern int max_lock_depth;
154#endif
155
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700156#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700157static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700158 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700159static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800160 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700161#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700162
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700163static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100164static struct ctl_table_root sysctl_table_root;
165static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100166 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100167 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400168 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100169 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400170 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100171};
172static struct ctl_table_root sysctl_table_root = {
173 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400174 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100175};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700177static struct ctl_table kern_table[];
178static struct ctl_table vm_table[];
179static struct ctl_table fs_table[];
180static struct ctl_table debug_table[];
181static struct ctl_table dev_table[];
182extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700183#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700184extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400185#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800186#ifdef CONFIG_EPOLL
187extern struct ctl_table epoll_table[];
188#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
191int sysctl_legacy_va_layout;
192#endif
193
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700194extern int prove_locking;
195extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/* The default sysctl tables: */
198
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700199static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 {
201 .ctl_name = CTL_KERN,
202 .procname = "kernel",
203 .mode = 0555,
204 .child = kern_table,
205 },
206 {
207 .ctl_name = CTL_VM,
208 .procname = "vm",
209 .mode = 0555,
210 .child = vm_table,
211 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 .ctl_name = CTL_FS,
214 .procname = "fs",
215 .mode = 0555,
216 .child = fs_table,
217 },
218 {
219 .ctl_name = CTL_DEBUG,
220 .procname = "debug",
221 .mode = 0555,
222 .child = debug_table,
223 },
224 {
225 .ctl_name = CTL_DEV,
226 .procname = "dev",
227 .mode = 0555,
228 .child = dev_table,
229 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700230/*
231 * NOTE: do not add new entries to this table unless you have read
232 * Documentation/sysctl/ctl_unnumbered.txt
233 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 { .ctl_name = 0 }
235};
236
Ingo Molnar77e54a12007-07-09 18:52:00 +0200237#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100238static int min_sched_granularity_ns = 100000; /* 100 usecs */
239static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
240static int min_wakeup_granularity_ns; /* 0 usecs */
241static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200242#endif
243
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700244static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200245#ifdef CONFIG_SCHED_DEBUG
246 {
247 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100248 .procname = "sched_min_granularity_ns",
249 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200250 .maxlen = sizeof(unsigned int),
251 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100252 .proc_handler = &sched_nr_latency_handler,
253 .strategy = &sysctl_intvec,
254 .extra1 = &min_sched_granularity_ns,
255 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200256 },
257 {
258 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200259 .procname = "sched_latency_ns",
260 .data = &sysctl_sched_latency,
261 .maxlen = sizeof(unsigned int),
262 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100263 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200264 .strategy = &sysctl_intvec,
265 .extra1 = &min_sched_granularity_ns,
266 .extra2 = &max_sched_granularity_ns,
267 },
268 {
269 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200270 .procname = "sched_wakeup_granularity_ns",
271 .data = &sysctl_sched_wakeup_granularity,
272 .maxlen = sizeof(unsigned int),
273 .mode = 0644,
274 .proc_handler = &proc_dointvec_minmax,
275 .strategy = &sysctl_intvec,
276 .extra1 = &min_wakeup_granularity_ns,
277 .extra2 = &max_wakeup_granularity_ns,
278 },
279 {
280 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200281 .procname = "sched_shares_ratelimit",
282 .data = &sysctl_sched_shares_ratelimit,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
285 .proc_handler = &proc_dointvec,
286 },
287 {
288 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200289 .procname = "sched_shares_thresh",
290 .data = &sysctl_sched_shares_thresh,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
293 .proc_handler = &proc_dointvec_minmax,
294 .strategy = &sysctl_intvec,
295 .extra1 = &zero,
296 },
297 {
298 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299 .procname = "sched_child_runs_first",
300 .data = &sysctl_sched_child_runs_first,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
303 .proc_handler = &proc_dointvec,
304 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200305 {
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_features",
308 .data = &sysctl_sched_features,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
311 .proc_handler = &proc_dointvec,
312 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200313 {
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_migration_cost",
316 .data = &sysctl_sched_migration_cost,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
319 .proc_handler = &proc_dointvec,
320 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100321 {
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_nr_migrate",
324 .data = &sysctl_sched_nr_migrate,
325 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
328 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200329#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200330 {
331 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100332 .procname = "sched_rt_period_us",
333 .data = &sysctl_sched_rt_period,
334 .maxlen = sizeof(unsigned int),
335 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200336 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100337 },
338 {
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "sched_rt_runtime_us",
341 .data = &sysctl_sched_rt_runtime,
342 .maxlen = sizeof(int),
343 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200344 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100345 },
346 {
347 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200348 .procname = "sched_compat_yield",
349 .data = &sysctl_sched_compat_yield,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = &proc_dointvec,
353 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700354#ifdef CONFIG_PROVE_LOCKING
355 {
356 .ctl_name = CTL_UNNUMBERED,
357 .procname = "prove_locking",
358 .data = &prove_locking,
359 .maxlen = sizeof(int),
360 .mode = 0644,
361 .proc_handler = &proc_dointvec,
362 },
363#endif
364#ifdef CONFIG_LOCK_STAT
365 {
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "lock_stat",
368 .data = &lock_stat,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &proc_dointvec,
372 },
373#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 .ctl_name = KERN_PANIC,
376 .procname = "panic",
377 .data = &panic_timeout,
378 .maxlen = sizeof(int),
379 .mode = 0644,
380 .proc_handler = &proc_dointvec,
381 },
382 {
383 .ctl_name = KERN_CORE_USES_PID,
384 .procname = "core_uses_pid",
385 .data = &core_uses_pid,
386 .maxlen = sizeof(int),
387 .mode = 0644,
388 .proc_handler = &proc_dointvec,
389 },
390 {
391 .ctl_name = KERN_CORE_PATTERN,
392 .procname = "core_pattern",
393 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700394 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 .mode = 0644,
396 .proc_handler = &proc_dostring,
397 .strategy = &sysctl_string,
398 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800399#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700402 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800403 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700404 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800406#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100407#ifdef CONFIG_LATENCYTOP
408 {
409 .procname = "latencytop",
410 .data = &latencytop_enabled,
411 .maxlen = sizeof(int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
414 },
415#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#ifdef CONFIG_BLK_DEV_INITRD
417 {
418 .ctl_name = KERN_REALROOTDEV,
419 .procname = "real-root-dev",
420 .data = &real_root_dev,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = &proc_dointvec,
424 },
425#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700426 {
427 .ctl_name = CTL_UNNUMBERED,
428 .procname = "print-fatal-signals",
429 .data = &print_fatal_signals,
430 .maxlen = sizeof(int),
431 .mode = 0644,
432 .proc_handler = &proc_dointvec,
433 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700434#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 {
436 .ctl_name = KERN_SPARC_REBOOT,
437 .procname = "reboot-cmd",
438 .data = reboot_command,
439 .maxlen = 256,
440 .mode = 0644,
441 .proc_handler = &proc_dostring,
442 .strategy = &sysctl_string,
443 },
444 {
445 .ctl_name = KERN_SPARC_STOP_A,
446 .procname = "stop-a",
447 .data = &stop_a_enabled,
448 .maxlen = sizeof (int),
449 .mode = 0644,
450 .proc_handler = &proc_dointvec,
451 },
452 {
453 .ctl_name = KERN_SPARC_SCONS_PWROFF,
454 .procname = "scons-poweroff",
455 .data = &scons_pwroff,
456 .maxlen = sizeof (int),
457 .mode = 0644,
458 .proc_handler = &proc_dointvec,
459 },
460#endif
David S. Miller08714202008-11-16 23:49:24 -0800461#ifdef CONFIG_SPARC64
462 {
463 .ctl_name = CTL_UNNUMBERED,
464 .procname = "tsb-ratio",
465 .data = &sysctl_tsb_ratio,
466 .maxlen = sizeof (int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
469 },
470#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#ifdef __hppa__
472 {
473 .ctl_name = KERN_HPPA_PWRSW,
474 .procname = "soft-power",
475 .data = &pwrsw_enabled,
476 .maxlen = sizeof (int),
477 .mode = 0644,
478 .proc_handler = &proc_dointvec,
479 },
480 {
481 .ctl_name = KERN_HPPA_UNALIGNED,
482 .procname = "unaligned-trap",
483 .data = &unaligned_enabled,
484 .maxlen = sizeof (int),
485 .mode = 0644,
486 .proc_handler = &proc_dointvec,
487 },
488#endif
489 {
490 .ctl_name = KERN_CTLALTDEL,
491 .procname = "ctrl-alt-del",
492 .data = &C_A_D,
493 .maxlen = sizeof(int),
494 .mode = 0644,
495 .proc_handler = &proc_dointvec,
496 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400497#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200498 {
499 .ctl_name = CTL_UNNUMBERED,
500 .procname = "ftrace_enabled",
501 .data = &ftrace_enabled,
502 .maxlen = sizeof(int),
503 .mode = 0644,
504 .proc_handler = &ftrace_enable_sysctl,
505 },
506#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500507#ifdef CONFIG_STACK_TRACER
508 {
509 .ctl_name = CTL_UNNUMBERED,
510 .procname = "stack_tracer_enabled",
511 .data = &stack_tracer_enabled,
512 .maxlen = sizeof(int),
513 .mode = 0644,
514 .proc_handler = &stack_trace_sysctl,
515 },
516#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400517#ifdef CONFIG_TRACING
518 {
519 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100520 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400521 .data = &ftrace_dump_on_oops,
522 .maxlen = sizeof(int),
523 .mode = 0644,
524 .proc_handler = &proc_dointvec,
525 },
526#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200527#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 {
529 .ctl_name = KERN_MODPROBE,
530 .procname = "modprobe",
531 .data = &modprobe_path,
532 .maxlen = KMOD_PATH_LEN,
533 .mode = 0644,
534 .proc_handler = &proc_dostring,
535 .strategy = &sysctl_string,
536 },
537#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700538#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 {
540 .ctl_name = KERN_HOTPLUG,
541 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100542 .data = &uevent_helper,
543 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .mode = 0644,
545 .proc_handler = &proc_dostring,
546 .strategy = &sysctl_string,
547 },
548#endif
549#ifdef CONFIG_CHR_DEV_SG
550 {
551 .ctl_name = KERN_SG_BIG_BUFF,
552 .procname = "sg-big-buff",
553 .data = &sg_big_buff,
554 .maxlen = sizeof (int),
555 .mode = 0444,
556 .proc_handler = &proc_dointvec,
557 },
558#endif
559#ifdef CONFIG_BSD_PROCESS_ACCT
560 {
561 .ctl_name = KERN_ACCT,
562 .procname = "acct",
563 .data = &acct_parm,
564 .maxlen = 3*sizeof(int),
565 .mode = 0644,
566 .proc_handler = &proc_dointvec,
567 },
568#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#ifdef CONFIG_MAGIC_SYSRQ
570 {
571 .ctl_name = KERN_SYSRQ,
572 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800573 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .maxlen = sizeof (int),
575 .mode = 0644,
576 .proc_handler = &proc_dointvec,
577 },
578#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700579#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700582 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 .maxlen = sizeof (int),
584 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700585 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700587#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 {
589 .ctl_name = KERN_MAX_THREADS,
590 .procname = "threads-max",
591 .data = &max_threads,
592 .maxlen = sizeof(int),
593 .mode = 0644,
594 .proc_handler = &proc_dointvec,
595 },
596 {
597 .ctl_name = KERN_RANDOM,
598 .procname = "random",
599 .mode = 0555,
600 .child = random_table,
601 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 {
603 .ctl_name = KERN_OVERFLOWUID,
604 .procname = "overflowuid",
605 .data = &overflowuid,
606 .maxlen = sizeof(int),
607 .mode = 0644,
608 .proc_handler = &proc_dointvec_minmax,
609 .strategy = &sysctl_intvec,
610 .extra1 = &minolduid,
611 .extra2 = &maxolduid,
612 },
613 {
614 .ctl_name = KERN_OVERFLOWGID,
615 .procname = "overflowgid",
616 .data = &overflowgid,
617 .maxlen = sizeof(int),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec_minmax,
620 .strategy = &sysctl_intvec,
621 .extra1 = &minolduid,
622 .extra2 = &maxolduid,
623 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800624#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#ifdef CONFIG_MATHEMU
626 {
627 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
628 .procname = "ieee_emulation_warnings",
629 .data = &sysctl_ieee_emulation_warnings,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec,
633 },
634#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 {
636 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
637 .procname = "userprocess_debug",
638 .data = &sysctl_userprocess_debug,
639 .maxlen = sizeof(int),
640 .mode = 0644,
641 .proc_handler = &proc_dointvec,
642 },
643#endif
644 {
645 .ctl_name = KERN_PIDMAX,
646 .procname = "pid_max",
647 .data = &pid_max,
648 .maxlen = sizeof (int),
649 .mode = 0644,
650 .proc_handler = &proc_dointvec_minmax,
651 .strategy = sysctl_intvec,
652 .extra1 = &pid_max_min,
653 .extra2 = &pid_max_max,
654 },
655 {
656 .ctl_name = KERN_PANIC_ON_OOPS,
657 .procname = "panic_on_oops",
658 .data = &panic_on_oops,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = &proc_dointvec,
662 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800663#if defined CONFIG_PRINTK
664 {
665 .ctl_name = KERN_PRINTK,
666 .procname = "printk",
667 .data = &console_loglevel,
668 .maxlen = 4*sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
671 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 {
673 .ctl_name = KERN_PRINTK_RATELIMIT,
674 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700675 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .maxlen = sizeof(int),
677 .mode = 0644,
678 .proc_handler = &proc_dointvec_jiffies,
679 .strategy = &sysctl_jiffies,
680 },
681 {
682 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
683 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700684 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .maxlen = sizeof(int),
686 .mode = 0644,
687 .proc_handler = &proc_dointvec,
688 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800689#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 {
691 .ctl_name = KERN_NGROUPS_MAX,
692 .procname = "ngroups_max",
693 .data = &ngroups_max,
694 .maxlen = sizeof (int),
695 .mode = 0444,
696 .proc_handler = &proc_dointvec,
697 },
698#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
699 {
700 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
701 .procname = "unknown_nmi_panic",
702 .data = &unknown_nmi_panic,
703 .maxlen = sizeof (int),
704 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200705 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 },
Don Zickus407984f2006-09-26 10:52:27 +0200707 {
Don Zickus407984f2006-09-26 10:52:27 +0200708 .procname = "nmi_watchdog",
709 .data = &nmi_watchdog_enabled,
710 .maxlen = sizeof (int),
711 .mode = 0644,
712 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 },
714#endif
715#if defined(CONFIG_X86)
716 {
Don Zickus8da5adda2006-09-26 10:52:27 +0200717 .ctl_name = KERN_PANIC_ON_NMI,
718 .procname = "panic_on_unrecovered_nmi",
719 .data = &panic_on_unrecovered_nmi,
720 .maxlen = sizeof(int),
721 .mode = 0644,
722 .proc_handler = &proc_dointvec,
723 },
724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .ctl_name = KERN_BOOTLOADER_TYPE,
726 .procname = "bootloader_type",
727 .data = &bootloader_type,
728 .maxlen = sizeof (int),
729 .mode = 0444,
730 .proc_handler = &proc_dointvec,
731 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100732 {
733 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700734 .procname = "bootloader_version",
735 .data = &bootloader_version,
736 .maxlen = sizeof (int),
737 .mode = 0444,
738 .proc_handler = &proc_dointvec,
739 },
740 {
741 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100742 .procname = "kstack_depth_to_print",
743 .data = &kstack_depth_to_print,
744 .maxlen = sizeof(int),
745 .mode = 0644,
746 .proc_handler = &proc_dointvec,
747 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100748 {
749 .ctl_name = CTL_UNNUMBERED,
750 .procname = "io_delay_type",
751 .data = &io_delay_type,
752 .maxlen = sizeof(int),
753 .mode = 0644,
754 .proc_handler = &proc_dointvec,
755 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800757#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 {
759 .ctl_name = KERN_RANDOMIZE,
760 .procname = "randomize_va_space",
761 .data = &randomize_va_space,
762 .maxlen = sizeof(int),
763 .mode = 0644,
764 .proc_handler = &proc_dointvec,
765 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800766#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800767#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700768 {
769 .ctl_name = KERN_SPIN_RETRY,
770 .procname = "spin_retry",
771 .data = &spin_retry,
772 .maxlen = sizeof (int),
773 .mode = 0644,
774 .proc_handler = &proc_dointvec,
775 },
776#endif
Len Brown673d5b42007-07-28 03:33:16 -0400777#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800778 {
Pavel Machekc255d842006-02-20 18:27:58 -0800779 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700780 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800781 .maxlen = sizeof (unsigned long),
782 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800783 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800784 },
785#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800786#ifdef CONFIG_IA64
787 {
788 .ctl_name = KERN_IA64_UNALIGNED,
789 .procname = "ignore-unaligned-usertrap",
790 .data = &no_unaligned_warning,
791 .maxlen = sizeof (int),
792 .mode = 0644,
793 .proc_handler = &proc_dointvec,
794 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800795 {
796 .ctl_name = CTL_UNNUMBERED,
797 .procname = "unaligned-dump-stack",
798 .data = &unaligned_dump_stack,
799 .maxlen = sizeof (int),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800803#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700804#ifdef CONFIG_DETECT_SOFTLOCKUP
805 {
806 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200807 .procname = "softlockup_panic",
808 .data = &softlockup_panic,
809 .maxlen = sizeof(int),
810 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700811 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200812 .strategy = &sysctl_intvec,
813 .extra1 = &zero,
814 .extra2 = &one,
815 },
816 {
817 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700818 .procname = "softlockup_thresh",
819 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200820 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700821 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800822 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700823 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200824 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700825 .extra2 = &sixty,
826 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800827#endif
828#ifdef CONFIG_DETECT_HUNG_TASK
829 {
830 .ctl_name = CTL_UNNUMBERED,
831 .procname = "hung_task_panic",
832 .data = &sysctl_hung_task_panic,
833 .maxlen = sizeof(int),
834 .mode = 0644,
835 .proc_handler = &proc_dointvec_minmax,
836 .strategy = &sysctl_intvec,
837 .extra1 = &zero,
838 .extra2 = &one,
839 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100840 {
841 .ctl_name = CTL_UNNUMBERED,
842 .procname = "hung_task_check_count",
843 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100844 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100845 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100846 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100847 .strategy = &sysctl_intvec,
848 },
849 {
850 .ctl_name = CTL_UNNUMBERED,
851 .procname = "hung_task_timeout_secs",
852 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100853 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100854 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800855 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100856 .strategy = &sysctl_intvec,
857 },
858 {
859 .ctl_name = CTL_UNNUMBERED,
860 .procname = "hung_task_warnings",
861 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100862 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100863 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100864 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100865 .strategy = &sysctl_intvec,
866 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700867#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200868#ifdef CONFIG_COMPAT
869 {
870 .ctl_name = KERN_COMPAT_LOG,
871 .procname = "compat-log",
872 .data = &compat_log,
873 .maxlen = sizeof (int),
874 .mode = 0644,
875 .proc_handler = &proc_dointvec,
876 },
877#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700878#ifdef CONFIG_RT_MUTEXES
879 {
880 .ctl_name = KERN_MAX_LOCK_DEPTH,
881 .procname = "max_lock_depth",
882 .data = &max_lock_depth,
883 .maxlen = sizeof(int),
884 .mode = 0644,
885 .proc_handler = &proc_dointvec,
886 },
887#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700888 {
889 .ctl_name = CTL_UNNUMBERED,
890 .procname = "poweroff_cmd",
891 .data = &poweroff_cmd,
892 .maxlen = POWEROFF_CMD_PATH_LEN,
893 .mode = 0644,
894 .proc_handler = &proc_dostring,
895 .strategy = &sysctl_string,
896 },
David Howells0b77f5b2008-04-29 01:01:32 -0700897#ifdef CONFIG_KEYS
898 {
899 .ctl_name = CTL_UNNUMBERED,
900 .procname = "keys",
901 .mode = 0555,
902 .child = key_sysctls,
903 },
904#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700905#ifdef CONFIG_RCU_TORTURE_TEST
906 {
907 .ctl_name = CTL_UNNUMBERED,
908 .procname = "rcutorture_runnable",
909 .data = &rcutorture_runnable,
910 .maxlen = sizeof(int),
911 .mode = 0644,
912 .proc_handler = &proc_dointvec,
913 },
914#endif
David Howells12e22c52009-04-03 16:42:35 +0100915#ifdef CONFIG_SLOW_WORK
916 {
917 .ctl_name = CTL_UNNUMBERED,
918 .procname = "slow-work",
919 .mode = 0555,
920 .child = slow_work_sysctls,
921 },
922#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700923/*
924 * NOTE: do not add new entries to this table unless you have read
925 * Documentation/sysctl/ctl_unnumbered.txt
926 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 { .ctl_name = 0 }
928};
929
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700930static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 {
932 .ctl_name = VM_OVERCOMMIT_MEMORY,
933 .procname = "overcommit_memory",
934 .data = &sysctl_overcommit_memory,
935 .maxlen = sizeof(sysctl_overcommit_memory),
936 .mode = 0644,
937 .proc_handler = &proc_dointvec,
938 },
939 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700940 .ctl_name = VM_PANIC_ON_OOM,
941 .procname = "panic_on_oom",
942 .data = &sysctl_panic_on_oom,
943 .maxlen = sizeof(sysctl_panic_on_oom),
944 .mode = 0644,
945 .proc_handler = &proc_dointvec,
946 },
947 {
David Rientjesfe071d72007-10-16 23:25:56 -0700948 .ctl_name = CTL_UNNUMBERED,
949 .procname = "oom_kill_allocating_task",
950 .data = &sysctl_oom_kill_allocating_task,
951 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
952 .mode = 0644,
953 .proc_handler = &proc_dointvec,
954 },
955 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800956 .ctl_name = CTL_UNNUMBERED,
957 .procname = "oom_dump_tasks",
958 .data = &sysctl_oom_dump_tasks,
959 .maxlen = sizeof(sysctl_oom_dump_tasks),
960 .mode = 0644,
961 .proc_handler = &proc_dointvec,
962 },
963 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 .ctl_name = VM_OVERCOMMIT_RATIO,
965 .procname = "overcommit_ratio",
966 .data = &sysctl_overcommit_ratio,
967 .maxlen = sizeof(sysctl_overcommit_ratio),
968 .mode = 0644,
969 .proc_handler = &proc_dointvec,
970 },
971 {
972 .ctl_name = VM_PAGE_CLUSTER,
973 .procname = "page-cluster",
974 .data = &page_cluster,
975 .maxlen = sizeof(int),
976 .mode = 0644,
977 .proc_handler = &proc_dointvec,
978 },
979 {
980 .ctl_name = VM_DIRTY_BACKGROUND,
981 .procname = "dirty_background_ratio",
982 .data = &dirty_background_ratio,
983 .maxlen = sizeof(dirty_background_ratio),
984 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800985 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .strategy = &sysctl_intvec,
987 .extra1 = &zero,
988 .extra2 = &one_hundred,
989 },
990 {
David Rientjes2da02992009-01-06 14:39:31 -0800991 .ctl_name = CTL_UNNUMBERED,
992 .procname = "dirty_background_bytes",
993 .data = &dirty_background_bytes,
994 .maxlen = sizeof(dirty_background_bytes),
995 .mode = 0644,
996 .proc_handler = &dirty_background_bytes_handler,
997 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800998 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -0800999 },
1000 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 .ctl_name = VM_DIRTY_RATIO,
1002 .procname = "dirty_ratio",
1003 .data = &vm_dirty_ratio,
1004 .maxlen = sizeof(vm_dirty_ratio),
1005 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001006 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 .strategy = &sysctl_intvec,
1008 .extra1 = &zero,
1009 .extra2 = &one_hundred,
1010 },
1011 {
David Rientjes2da02992009-01-06 14:39:31 -08001012 .ctl_name = CTL_UNNUMBERED,
1013 .procname = "dirty_bytes",
1014 .data = &vm_dirty_bytes,
1015 .maxlen = sizeof(vm_dirty_bytes),
1016 .mode = 0644,
1017 .proc_handler = &dirty_bytes_handler,
1018 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001019 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001020 },
1021 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001023 .data = &dirty_writeback_interval,
1024 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 .mode = 0644,
1026 .proc_handler = &dirty_writeback_centisecs_handler,
1027 },
1028 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001030 .data = &dirty_expire_interval,
1031 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001033 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 },
1035 {
1036 .ctl_name = VM_NR_PDFLUSH_THREADS,
1037 .procname = "nr_pdflush_threads",
1038 .data = &nr_pdflush_threads,
1039 .maxlen = sizeof nr_pdflush_threads,
1040 .mode = 0444 /* read-only*/,
1041 .proc_handler = &proc_dointvec,
1042 },
1043 {
1044 .ctl_name = VM_SWAPPINESS,
1045 .procname = "swappiness",
1046 .data = &vm_swappiness,
1047 .maxlen = sizeof(vm_swappiness),
1048 .mode = 0644,
1049 .proc_handler = &proc_dointvec_minmax,
1050 .strategy = &sysctl_intvec,
1051 .extra1 = &zero,
1052 .extra2 = &one_hundred,
1053 },
1054#ifdef CONFIG_HUGETLB_PAGE
1055 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001057 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 .maxlen = sizeof(unsigned long),
1059 .mode = 0644,
1060 .proc_handler = &hugetlb_sysctl_handler,
1061 .extra1 = (void *)&hugetlb_zero,
1062 .extra2 = (void *)&hugetlb_infinity,
1063 },
1064 {
1065 .ctl_name = VM_HUGETLB_GROUP,
1066 .procname = "hugetlb_shm_group",
1067 .data = &sysctl_hugetlb_shm_group,
1068 .maxlen = sizeof(gid_t),
1069 .mode = 0644,
1070 .proc_handler = &proc_dointvec,
1071 },
Mel Gorman396faf02007-07-17 04:03:13 -07001072 {
1073 .ctl_name = CTL_UNNUMBERED,
1074 .procname = "hugepages_treat_as_movable",
1075 .data = &hugepages_treat_as_movable,
1076 .maxlen = sizeof(int),
1077 .mode = 0644,
1078 .proc_handler = &hugetlb_treat_movable_handler,
1079 },
Adam Litke54f9f802007-10-16 01:26:20 -07001080 {
1081 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001082 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001083 .data = NULL,
1084 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001085 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001086 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001087 .extra1 = (void *)&hugetlb_zero,
1088 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001089 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090#endif
1091 {
1092 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1093 .procname = "lowmem_reserve_ratio",
1094 .data = &sysctl_lowmem_reserve_ratio,
1095 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1096 .mode = 0644,
1097 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1098 .strategy = &sysctl_intvec,
1099 },
1100 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001101 .ctl_name = VM_DROP_PAGECACHE,
1102 .procname = "drop_caches",
1103 .data = &sysctl_drop_caches,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
1106 .proc_handler = drop_caches_sysctl_handler,
1107 .strategy = &sysctl_intvec,
1108 },
1109 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .ctl_name = VM_MIN_FREE_KBYTES,
1111 .procname = "min_free_kbytes",
1112 .data = &min_free_kbytes,
1113 .maxlen = sizeof(min_free_kbytes),
1114 .mode = 0644,
1115 .proc_handler = &min_free_kbytes_sysctl_handler,
1116 .strategy = &sysctl_intvec,
1117 .extra1 = &zero,
1118 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001119 {
1120 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1121 .procname = "percpu_pagelist_fraction",
1122 .data = &percpu_pagelist_fraction,
1123 .maxlen = sizeof(percpu_pagelist_fraction),
1124 .mode = 0644,
1125 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1126 .strategy = &sysctl_intvec,
1127 .extra1 = &min_percpu_pagelist_fract,
1128 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129#ifdef CONFIG_MMU
1130 {
1131 .ctl_name = VM_MAX_MAP_COUNT,
1132 .procname = "max_map_count",
1133 .data = &sysctl_max_map_count,
1134 .maxlen = sizeof(sysctl_max_map_count),
1135 .mode = 0644,
1136 .proc_handler = &proc_dointvec
1137 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001138#else
1139 {
1140 .ctl_name = CTL_UNNUMBERED,
1141 .procname = "nr_trim_pages",
1142 .data = &sysctl_nr_trim_pages,
1143 .maxlen = sizeof(sysctl_nr_trim_pages),
1144 .mode = 0644,
1145 .proc_handler = &proc_dointvec_minmax,
1146 .strategy = &sysctl_intvec,
1147 .extra1 = &zero,
1148 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149#endif
1150 {
1151 .ctl_name = VM_LAPTOP_MODE,
1152 .procname = "laptop_mode",
1153 .data = &laptop_mode,
1154 .maxlen = sizeof(laptop_mode),
1155 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001156 .proc_handler = &proc_dointvec_jiffies,
1157 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 },
1159 {
1160 .ctl_name = VM_BLOCK_DUMP,
1161 .procname = "block_dump",
1162 .data = &block_dump,
1163 .maxlen = sizeof(block_dump),
1164 .mode = 0644,
1165 .proc_handler = &proc_dointvec,
1166 .strategy = &sysctl_intvec,
1167 .extra1 = &zero,
1168 },
1169 {
1170 .ctl_name = VM_VFS_CACHE_PRESSURE,
1171 .procname = "vfs_cache_pressure",
1172 .data = &sysctl_vfs_cache_pressure,
1173 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1174 .mode = 0644,
1175 .proc_handler = &proc_dointvec,
1176 .strategy = &sysctl_intvec,
1177 .extra1 = &zero,
1178 },
1179#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1180 {
1181 .ctl_name = VM_LEGACY_VA_LAYOUT,
1182 .procname = "legacy_va_layout",
1183 .data = &sysctl_legacy_va_layout,
1184 .maxlen = sizeof(sysctl_legacy_va_layout),
1185 .mode = 0644,
1186 .proc_handler = &proc_dointvec,
1187 .strategy = &sysctl_intvec,
1188 .extra1 = &zero,
1189 },
1190#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001191#ifdef CONFIG_NUMA
1192 {
1193 .ctl_name = VM_ZONE_RECLAIM_MODE,
1194 .procname = "zone_reclaim_mode",
1195 .data = &zone_reclaim_mode,
1196 .maxlen = sizeof(zone_reclaim_mode),
1197 .mode = 0644,
1198 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001199 .strategy = &sysctl_intvec,
1200 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001201 },
Christoph Lameter96146342006-07-03 00:24:13 -07001202 {
1203 .ctl_name = VM_MIN_UNMAPPED,
1204 .procname = "min_unmapped_ratio",
1205 .data = &sysctl_min_unmapped_ratio,
1206 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1207 .mode = 0644,
1208 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1209 .strategy = &sysctl_intvec,
1210 .extra1 = &zero,
1211 .extra2 = &one_hundred,
1212 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001213 {
1214 .ctl_name = VM_MIN_SLAB,
1215 .procname = "min_slab_ratio",
1216 .data = &sysctl_min_slab_ratio,
1217 .maxlen = sizeof(sysctl_min_slab_ratio),
1218 .mode = 0644,
1219 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1220 .strategy = &sysctl_intvec,
1221 .extra1 = &zero,
1222 .extra2 = &one_hundred,
1223 },
Christoph Lameter17436602006-01-18 17:42:32 -08001224#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001225#ifdef CONFIG_SMP
1226 {
1227 .ctl_name = CTL_UNNUMBERED,
1228 .procname = "stat_interval",
1229 .data = &sysctl_stat_interval,
1230 .maxlen = sizeof(sysctl_stat_interval),
1231 .mode = 0644,
1232 .proc_handler = &proc_dointvec_jiffies,
1233 .strategy = &sysctl_jiffies,
1234 },
1235#endif
Eric Parised032182007-06-28 15:55:21 -04001236#ifdef CONFIG_SECURITY
1237 {
1238 .ctl_name = CTL_UNNUMBERED,
1239 .procname = "mmap_min_addr",
1240 .data = &mmap_min_addr,
1241 .maxlen = sizeof(unsigned long),
1242 .mode = 0644,
1243 .proc_handler = &proc_doulongvec_minmax,
1244 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001245#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001246#ifdef CONFIG_NUMA
1247 {
1248 .ctl_name = CTL_UNNUMBERED,
1249 .procname = "numa_zonelist_order",
1250 .data = &numa_zonelist_order,
1251 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1252 .mode = 0644,
1253 .proc_handler = &numa_zonelist_order_handler,
1254 .strategy = &sysctl_string,
1255 },
1256#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001257#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001258 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001259 {
1260 .ctl_name = VM_VDSO_ENABLED,
1261 .procname = "vdso_enabled",
1262 .data = &vdso_enabled,
1263 .maxlen = sizeof(vdso_enabled),
1264 .mode = 0644,
1265 .proc_handler = &proc_dointvec,
1266 .strategy = &sysctl_intvec,
1267 .extra1 = &zero,
1268 },
1269#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001270#ifdef CONFIG_HIGHMEM
1271 {
1272 .ctl_name = CTL_UNNUMBERED,
1273 .procname = "highmem_is_dirtyable",
1274 .data = &vm_highmem_is_dirtyable,
1275 .maxlen = sizeof(vm_highmem_is_dirtyable),
1276 .mode = 0644,
1277 .proc_handler = &proc_dointvec_minmax,
1278 .strategy = &sysctl_intvec,
1279 .extra1 = &zero,
1280 .extra2 = &one,
1281 },
1282#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001283#ifdef CONFIG_UNEVICTABLE_LRU
1284 {
1285 .ctl_name = CTL_UNNUMBERED,
1286 .procname = "scan_unevictable_pages",
1287 .data = &scan_unevictable_pages,
1288 .maxlen = sizeof(scan_unevictable_pages),
1289 .mode = 0644,
1290 .proc_handler = &scan_unevictable_handler,
1291 },
1292#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001293/*
1294 * NOTE: do not add new entries to this table unless you have read
1295 * Documentation/sysctl/ctl_unnumbered.txt
1296 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 { .ctl_name = 0 }
1298};
1299
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001300#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001301static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001302 { .ctl_name = 0 }
1303};
1304#endif
1305
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001306static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 {
1308 .ctl_name = FS_NRINODE,
1309 .procname = "inode-nr",
1310 .data = &inodes_stat,
1311 .maxlen = 2*sizeof(int),
1312 .mode = 0444,
1313 .proc_handler = &proc_dointvec,
1314 },
1315 {
1316 .ctl_name = FS_STATINODE,
1317 .procname = "inode-state",
1318 .data = &inodes_stat,
1319 .maxlen = 7*sizeof(int),
1320 .mode = 0444,
1321 .proc_handler = &proc_dointvec,
1322 },
1323 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 .procname = "file-nr",
1325 .data = &files_stat,
1326 .maxlen = 3*sizeof(int),
1327 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001328 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 },
1330 {
1331 .ctl_name = FS_MAXFILE,
1332 .procname = "file-max",
1333 .data = &files_stat.max_files,
1334 .maxlen = sizeof(int),
1335 .mode = 0644,
1336 .proc_handler = &proc_dointvec,
1337 },
1338 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001339 .ctl_name = CTL_UNNUMBERED,
1340 .procname = "nr_open",
1341 .data = &sysctl_nr_open,
1342 .maxlen = sizeof(int),
1343 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001344 .proc_handler = &proc_dointvec_minmax,
1345 .extra1 = &sysctl_nr_open_min,
1346 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001347 },
1348 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 .ctl_name = FS_DENTRY,
1350 .procname = "dentry-state",
1351 .data = &dentry_stat,
1352 .maxlen = 6*sizeof(int),
1353 .mode = 0444,
1354 .proc_handler = &proc_dointvec,
1355 },
1356 {
1357 .ctl_name = FS_OVERFLOWUID,
1358 .procname = "overflowuid",
1359 .data = &fs_overflowuid,
1360 .maxlen = sizeof(int),
1361 .mode = 0644,
1362 .proc_handler = &proc_dointvec_minmax,
1363 .strategy = &sysctl_intvec,
1364 .extra1 = &minolduid,
1365 .extra2 = &maxolduid,
1366 },
1367 {
1368 .ctl_name = FS_OVERFLOWGID,
1369 .procname = "overflowgid",
1370 .data = &fs_overflowgid,
1371 .maxlen = sizeof(int),
1372 .mode = 0644,
1373 .proc_handler = &proc_dointvec_minmax,
1374 .strategy = &sysctl_intvec,
1375 .extra1 = &minolduid,
1376 .extra2 = &maxolduid,
1377 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001378#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 {
1380 .ctl_name = FS_LEASES,
1381 .procname = "leases-enable",
1382 .data = &leases_enable,
1383 .maxlen = sizeof(int),
1384 .mode = 0644,
1385 .proc_handler = &proc_dointvec,
1386 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001387#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388#ifdef CONFIG_DNOTIFY
1389 {
1390 .ctl_name = FS_DIR_NOTIFY,
1391 .procname = "dir-notify-enable",
1392 .data = &dir_notify_enable,
1393 .maxlen = sizeof(int),
1394 .mode = 0644,
1395 .proc_handler = &proc_dointvec,
1396 },
1397#endif
1398#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001399#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 {
1401 .ctl_name = FS_LEASE_TIME,
1402 .procname = "lease-break-time",
1403 .data = &lease_break_time,
1404 .maxlen = sizeof(int),
1405 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001406 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001408#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001409#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 .procname = "aio-nr",
1412 .data = &aio_nr,
1413 .maxlen = sizeof(aio_nr),
1414 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001415 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 },
1417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "aio-max-nr",
1419 .data = &aio_max_nr,
1420 .maxlen = sizeof(aio_max_nr),
1421 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001422 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001424#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001425#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001426 {
1427 .ctl_name = FS_INOTIFY,
1428 .procname = "inotify",
1429 .mode = 0555,
1430 .child = inotify_table,
1431 },
1432#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001433#ifdef CONFIG_EPOLL
1434 {
1435 .procname = "epoll",
1436 .mode = 0555,
1437 .child = epoll_table,
1438 },
1439#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001441 {
1442 .ctl_name = KERN_SETUID_DUMPABLE,
1443 .procname = "suid_dumpable",
1444 .data = &suid_dumpable,
1445 .maxlen = sizeof(int),
1446 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001447 .proc_handler = &proc_dointvec_minmax,
1448 .strategy = &sysctl_intvec,
1449 .extra1 = &zero,
1450 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001451 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001452#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1453 {
1454 .ctl_name = CTL_UNNUMBERED,
1455 .procname = "binfmt_misc",
1456 .mode = 0555,
1457 .child = binfmt_misc_table,
1458 },
1459#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001460/*
1461 * NOTE: do not add new entries to this table unless you have read
1462 * Documentation/sysctl/ctl_unnumbered.txt
1463 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 { .ctl_name = 0 }
1465};
1466
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001467static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001468#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001469 {
1470 .ctl_name = CTL_UNNUMBERED,
1471 .procname = "exception-trace",
1472 .data = &show_unhandled_signals,
1473 .maxlen = sizeof(int),
1474 .mode = 0644,
1475 .proc_handler = proc_dointvec
1476 },
1477#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 { .ctl_name = 0 }
1479};
1480
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001481static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001483};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Al Viro330d57f2005-11-04 10:18:40 +00001485static DEFINE_SPINLOCK(sysctl_lock);
1486
1487/* called under sysctl_lock */
1488static int use_table(struct ctl_table_header *p)
1489{
1490 if (unlikely(p->unregistering))
1491 return 0;
1492 p->used++;
1493 return 1;
1494}
1495
1496/* called under sysctl_lock */
1497static void unuse_table(struct ctl_table_header *p)
1498{
1499 if (!--p->used)
1500 if (unlikely(p->unregistering))
1501 complete(p->unregistering);
1502}
1503
1504/* called under sysctl_lock, will reacquire if has to wait */
1505static void start_unregistering(struct ctl_table_header *p)
1506{
1507 /*
1508 * if p->used is 0, nobody will ever touch that entry again;
1509 * we'll eliminate all paths to it before dropping sysctl_lock
1510 */
1511 if (unlikely(p->used)) {
1512 struct completion wait;
1513 init_completion(&wait);
1514 p->unregistering = &wait;
1515 spin_unlock(&sysctl_lock);
1516 wait_for_completion(&wait);
1517 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001518 } else {
1519 /* anything non-NULL; we'll never dereference it */
1520 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001521 }
1522 /*
1523 * do not remove from the list until nobody holds it; walking the
1524 * list in do_sysctl() relies on that.
1525 */
1526 list_del_init(&p->ctl_entry);
1527}
1528
Al Virof7e6ced2008-07-15 01:44:23 -04001529void sysctl_head_get(struct ctl_table_header *head)
1530{
1531 spin_lock(&sysctl_lock);
1532 head->count++;
1533 spin_unlock(&sysctl_lock);
1534}
1535
1536void sysctl_head_put(struct ctl_table_header *head)
1537{
1538 spin_lock(&sysctl_lock);
1539 if (!--head->count)
1540 kfree(head);
1541 spin_unlock(&sysctl_lock);
1542}
1543
1544struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1545{
1546 if (!head)
1547 BUG();
1548 spin_lock(&sysctl_lock);
1549 if (!use_table(head))
1550 head = ERR_PTR(-ENOENT);
1551 spin_unlock(&sysctl_lock);
1552 return head;
1553}
1554
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001555void sysctl_head_finish(struct ctl_table_header *head)
1556{
1557 if (!head)
1558 return;
1559 spin_lock(&sysctl_lock);
1560 unuse_table(head);
1561 spin_unlock(&sysctl_lock);
1562}
1563
Al Viro73455092008-07-14 21:22:20 -04001564static struct ctl_table_set *
1565lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1566{
1567 struct ctl_table_set *set = &root->default_set;
1568 if (root->lookup)
1569 set = root->lookup(root, namespaces);
1570 return set;
1571}
1572
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001573static struct list_head *
1574lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001575{
Al Viro73455092008-07-14 21:22:20 -04001576 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1577 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001578}
1579
1580struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1581 struct ctl_table_header *prev)
1582{
1583 struct ctl_table_root *root;
1584 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001585 struct ctl_table_header *head;
1586 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001587
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001588 spin_lock(&sysctl_lock);
1589 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001590 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001591 tmp = &prev->ctl_entry;
1592 unuse_table(prev);
1593 goto next;
1594 }
1595 tmp = &root_table_header.ctl_entry;
1596 for (;;) {
1597 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1598
1599 if (!use_table(head))
1600 goto next;
1601 spin_unlock(&sysctl_lock);
1602 return head;
1603 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001604 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001605 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001606 header_list = lookup_header_list(root, namespaces);
1607 if (tmp != header_list)
1608 continue;
1609
1610 do {
1611 root = list_entry(root->root_list.next,
1612 struct ctl_table_root, root_list);
1613 if (root == &sysctl_table_root)
1614 goto out;
1615 header_list = lookup_header_list(root, namespaces);
1616 } while (list_empty(header_list));
1617 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001618 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001619out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001620 spin_unlock(&sysctl_lock);
1621 return NULL;
1622}
1623
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001624struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1625{
1626 return __sysctl_head_next(current->nsproxy, prev);
1627}
1628
1629void register_sysctl_root(struct ctl_table_root *root)
1630{
1631 spin_lock(&sysctl_lock);
1632 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1633 spin_unlock(&sysctl_lock);
1634}
1635
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001636#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001637/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001638static int do_sysctl_strategy(struct ctl_table_root *root,
1639 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001640 void __user *oldval, size_t __user *oldlenp,
1641 void __user *newval, size_t newlen)
1642{
1643 int op = 0, rc;
1644
1645 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001646 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001647 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001648 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001649 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001650 return -EPERM;
1651
1652 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001653 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001654 if (rc < 0)
1655 return rc;
1656 if (rc > 0)
1657 return 0;
1658 }
1659
1660 /* If there is no strategy routine, or if the strategy returns
1661 * zero, proceed with automatic r/w */
1662 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001663 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001664 if (rc < 0)
1665 return rc;
1666 }
1667 return 0;
1668}
1669
1670static int parse_table(int __user *name, int nlen,
1671 void __user *oldval, size_t __user *oldlenp,
1672 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001673 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001674 struct ctl_table *table)
1675{
1676 int n;
1677repeat:
1678 if (!nlen)
1679 return -ENOTDIR;
1680 if (get_user(n, name))
1681 return -EFAULT;
1682 for ( ; table->ctl_name || table->procname; table++) {
1683 if (!table->ctl_name)
1684 continue;
1685 if (n == table->ctl_name) {
1686 int error;
1687 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001688 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001689 return -EPERM;
1690 name++;
1691 nlen--;
1692 table = table->child;
1693 goto repeat;
1694 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001695 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001696 oldval, oldlenp,
1697 newval, newlen);
1698 return error;
1699 }
1700 }
1701 return -ENOTDIR;
1702}
1703
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1705 void __user *newval, size_t newlen)
1706{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001707 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001708 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1711 return -ENOTDIR;
1712 if (oldval) {
1713 int old_len;
1714 if (!oldlenp || get_user(old_len, oldlenp))
1715 return -EFAULT;
1716 }
Al Viro330d57f2005-11-04 10:18:40 +00001717
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001718 for (head = sysctl_head_next(NULL); head;
1719 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001720 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001721 newval, newlen,
1722 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001723 if (error != -ENOTDIR) {
1724 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001725 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001726 }
1727 }
Al Viro330d57f2005-11-04 10:18:40 +00001728 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729}
1730
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001731SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732{
1733 struct __sysctl_args tmp;
1734 int error;
1735
1736 if (copy_from_user(&tmp, args, sizeof(tmp)))
1737 return -EFAULT;
1738
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001739 error = deprecated_sysctl_warning(&tmp);
1740 if (error)
1741 goto out;
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 lock_kernel();
1744 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1745 tmp.newval, tmp.newlen);
1746 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001747out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 return error;
1749}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001750#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
1752/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001753 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 * some sysctl variables are readonly even to root.
1755 */
1756
1757static int test_perm(int mode, int op)
1758{
David Howells76aac0e2008-11-14 10:39:12 +11001759 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 mode >>= 6;
1761 else if (in_egroup_p(0))
1762 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001763 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 return 0;
1765 return -EACCES;
1766}
1767
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001768int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
1770 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001771 int mode;
1772
Al Viroe6305c42008-07-15 21:03:57 -04001773 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 if (error)
1775 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001776
1777 if (root->permissions)
1778 mode = root->permissions(root, current->nsproxy, table);
1779 else
1780 mode = table->mode;
1781
1782 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783}
1784
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001785static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1786{
1787 for (; table->ctl_name || table->procname; table++) {
1788 table->parent = parent;
1789 if (table->child)
1790 sysctl_set_parent(table, table->child);
1791 }
1792}
1793
1794static __init int sysctl_init(void)
1795{
1796 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001797#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1798 {
1799 int err;
1800 err = sysctl_check_table(current->nsproxy, root_table);
1801 }
1802#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001803 return 0;
1804}
1805
1806core_initcall(sysctl_init);
1807
Al Virobfbcf032008-07-27 06:31:22 +01001808static struct ctl_table *is_branch_in(struct ctl_table *branch,
1809 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001810{
1811 struct ctl_table *p;
1812 const char *s = branch->procname;
1813
1814 /* branch should have named subdirectory as its first element */
1815 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001816 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001817
1818 /* ... and nothing else */
1819 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001820 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001821
1822 /* table should contain subdirectory with the same name */
1823 for (p = table; p->procname || p->ctl_name; p++) {
1824 if (!p->child)
1825 continue;
1826 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001827 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001828 }
Al Virobfbcf032008-07-27 06:31:22 +01001829 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001830}
1831
1832/* see if attaching q to p would be an improvement */
1833static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1834{
1835 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001836 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001837 int is_better = 0;
1838 int not_in_parent = !p->attached_by;
1839
Al Virobfbcf032008-07-27 06:31:22 +01001840 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001841 if (by == q->attached_by)
1842 is_better = 1;
1843 if (to == p->attached_by)
1844 not_in_parent = 1;
1845 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001846 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001847 }
1848
1849 if (is_better && not_in_parent) {
1850 q->attached_by = by;
1851 q->attached_to = to;
1852 q->parent = p;
1853 }
1854}
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001857 * __register_sysctl_paths - register a sysctl hierarchy
1858 * @root: List of sysctl headers to register on
1859 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001860 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 *
1863 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001864 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001866 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 *
1868 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1869 * must be unique within that level of sysctl
1870 *
1871 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1872 * enter a sysctl file
1873 *
1874 * data - a pointer to data for use by proc_handler
1875 *
1876 * maxlen - the maximum size in bytes of the data
1877 *
1878 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1879 *
1880 * child - a pointer to the child sysctl table if this entry is a directory, or
1881 * %NULL.
1882 *
1883 * proc_handler - the text handler routine (described below)
1884 *
1885 * strategy - the strategy routine (described below)
1886 *
1887 * de - for internal use by the sysctl routines
1888 *
1889 * extra1, extra2 - extra pointers usable by the proc handler routines
1890 *
1891 * Leaf nodes in the sysctl tree will be represented by a single file
1892 * under /proc; non-leaf nodes will be represented by directories.
1893 *
1894 * sysctl(2) can automatically manage read and write requests through
1895 * the sysctl table. The data and maxlen fields of the ctl_table
1896 * struct enable minimal validation of the values being written to be
1897 * performed, and the mode field allows minimal authentication.
1898 *
1899 * More sophisticated management can be enabled by the provision of a
1900 * strategy routine with the table entry. This will be called before
1901 * any automatic read or write of the data is performed.
1902 *
1903 * The strategy routine may return
1904 *
1905 * < 0 - Error occurred (error is passed to user process)
1906 *
1907 * 0 - OK - proceed with automatic read or write.
1908 *
1909 * > 0 - OK - read or write has been done by the strategy routine, so
1910 * return immediately.
1911 *
1912 * There must be a proc_handler routine for any terminal nodes
1913 * mirrored under /proc/sys (non-terminals are handled by a built-in
1914 * directory handler). Several default handlers are available to
1915 * cover common cases -
1916 *
1917 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1918 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1919 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1920 *
1921 * It is the handler's job to read the input buffer from user memory
1922 * and process it. The handler should return 0 on success.
1923 *
1924 * This routine returns %NULL on a failure to register, and a pointer
1925 * to the table header on success.
1926 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001927struct ctl_table_header *__register_sysctl_paths(
1928 struct ctl_table_root *root,
1929 struct nsproxy *namespaces,
1930 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001932 struct ctl_table_header *header;
1933 struct ctl_table *new, **prevp;
1934 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001935 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001936
1937 /* Count the path components */
1938 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1939 ;
1940
1941 /*
1942 * For each path component, allocate a 2-element ctl_table array.
1943 * The first array element will be filled with the sysctl entry
1944 * for this, the second will be the sentinel (ctl_name == 0).
1945 *
1946 * We allocate everything in one go so that we don't have to
1947 * worry about freeing additional memory in unregister_sysctl_table.
1948 */
1949 header = kzalloc(sizeof(struct ctl_table_header) +
1950 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1951 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001953
1954 new = (struct ctl_table *) (header + 1);
1955
1956 /* Now connect the dots */
1957 prevp = &header->ctl_table;
1958 for (n = 0; n < npath; ++n, ++path) {
1959 /* Copy the procname */
1960 new->procname = path->procname;
1961 new->ctl_name = path->ctl_name;
1962 new->mode = 0555;
1963
1964 *prevp = new;
1965 prevp = &new->child;
1966
1967 new += 2;
1968 }
1969 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001970 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001971
1972 INIT_LIST_HEAD(&header->ctl_entry);
1973 header->used = 0;
1974 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001975 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001976 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001977 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001978#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001979 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001980 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001981 return NULL;
1982 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001983#endif
Al Viro330d57f2005-11-04 10:18:40 +00001984 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001985 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001986 header->attached_by = header->ctl_table;
1987 header->attached_to = root_table;
1988 header->parent = &root_table_header;
1989 for (set = header->set; set; set = set->parent) {
1990 struct ctl_table_header *p;
1991 list_for_each_entry(p, &set->list, ctl_entry) {
1992 if (p->unregistering)
1993 continue;
1994 try_attach(p, header);
1995 }
1996 }
1997 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001998 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001999 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002000
2001 return header;
2002}
2003
2004/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002005 * register_sysctl_table_path - register a sysctl table hierarchy
2006 * @path: The path to the directory the sysctl table is in.
2007 * @table: the top-level table structure
2008 *
2009 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2010 * array. A completely 0 filled entry terminates the table.
2011 *
2012 * See __register_sysctl_paths for more details.
2013 */
2014struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2015 struct ctl_table *table)
2016{
2017 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2018 path, table);
2019}
2020
2021/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002022 * register_sysctl_table - register a sysctl table hierarchy
2023 * @table: the top-level table structure
2024 *
2025 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2026 * array. A completely 0 filled entry terminates the table.
2027 *
2028 * See register_sysctl_paths for more details.
2029 */
2030struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2031{
2032 static const struct ctl_path null_path[] = { {} };
2033
2034 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035}
2036
2037/**
2038 * unregister_sysctl_table - unregister a sysctl table hierarchy
2039 * @header: the header returned from register_sysctl_table
2040 *
2041 * Unregisters the sysctl table and all children. proc entries may not
2042 * actually be removed until they are no longer used by anyone.
2043 */
2044void unregister_sysctl_table(struct ctl_table_header * header)
2045{
Al Viro330d57f2005-11-04 10:18:40 +00002046 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002047
2048 if (header == NULL)
2049 return;
2050
Al Viro330d57f2005-11-04 10:18:40 +00002051 spin_lock(&sysctl_lock);
2052 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002053 if (!--header->parent->count) {
2054 WARN_ON(1);
2055 kfree(header->parent);
2056 }
Al Virof7e6ced2008-07-15 01:44:23 -04002057 if (!--header->count)
2058 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002059 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
Al Viro90434762008-07-15 08:54:06 -04002062int sysctl_is_seen(struct ctl_table_header *p)
2063{
2064 struct ctl_table_set *set = p->set;
2065 int res;
2066 spin_lock(&sysctl_lock);
2067 if (p->unregistering)
2068 res = 0;
2069 else if (!set->is_seen)
2070 res = 1;
2071 else
2072 res = set->is_seen(set);
2073 spin_unlock(&sysctl_lock);
2074 return res;
2075}
2076
Al Viro73455092008-07-14 21:22:20 -04002077void setup_sysctl_set(struct ctl_table_set *p,
2078 struct ctl_table_set *parent,
2079 int (*is_seen)(struct ctl_table_set *))
2080{
2081 INIT_LIST_HEAD(&p->list);
2082 p->parent = parent ? parent : &sysctl_table_root.default_set;
2083 p->is_seen = is_seen;
2084}
2085
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002086#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002087struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002088{
2089 return NULL;
2090}
2091
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002092struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2093 struct ctl_table *table)
2094{
2095 return NULL;
2096}
2097
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002098void unregister_sysctl_table(struct ctl_table_header * table)
2099{
2100}
2101
Al Viro73455092008-07-14 21:22:20 -04002102void setup_sysctl_set(struct ctl_table_set *p,
2103 struct ctl_table_set *parent,
2104 int (*is_seen)(struct ctl_table_set *))
2105{
2106}
2107
Al Virof7e6ced2008-07-15 01:44:23 -04002108void sysctl_head_put(struct ctl_table_header *head)
2109{
2110}
2111
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002112#endif /* CONFIG_SYSCTL */
2113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114/*
2115 * /proc/sys support
2116 */
2117
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002118#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002120static int _proc_do_string(void* data, int maxlen, int write,
2121 struct file *filp, void __user *buffer,
2122 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002123{
2124 size_t len;
2125 char __user *p;
2126 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002127
2128 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002129 *lenp = 0;
2130 return 0;
2131 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002132
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002133 if (write) {
2134 len = 0;
2135 p = buffer;
2136 while (len < *lenp) {
2137 if (get_user(c, p++))
2138 return -EFAULT;
2139 if (c == 0 || c == '\n')
2140 break;
2141 len++;
2142 }
2143 if (len >= maxlen)
2144 len = maxlen-1;
2145 if(copy_from_user(data, buffer, len))
2146 return -EFAULT;
2147 ((char *) data)[len] = 0;
2148 *ppos += *lenp;
2149 } else {
2150 len = strlen(data);
2151 if (len > maxlen)
2152 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002153
2154 if (*ppos > len) {
2155 *lenp = 0;
2156 return 0;
2157 }
2158
2159 data += *ppos;
2160 len -= *ppos;
2161
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002162 if (len > *lenp)
2163 len = *lenp;
2164 if (len)
2165 if(copy_to_user(buffer, data, len))
2166 return -EFAULT;
2167 if (len < *lenp) {
2168 if(put_user('\n', ((char __user *) buffer) + len))
2169 return -EFAULT;
2170 len++;
2171 }
2172 *lenp = len;
2173 *ppos += len;
2174 }
2175 return 0;
2176}
2177
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178/**
2179 * proc_dostring - read a string sysctl
2180 * @table: the sysctl table
2181 * @write: %TRUE if this is a write to the sysctl file
2182 * @filp: the file structure
2183 * @buffer: the user buffer
2184 * @lenp: the size of the user buffer
2185 * @ppos: file position
2186 *
2187 * Reads/writes a string from/to the user buffer. If the kernel
2188 * buffer provided is not large enough to hold the string, the
2189 * string is truncated. The copied string is %NULL-terminated.
2190 * If the string is being read by the user process, it is copied
2191 * and a newline '\n' is added. It is truncated if the buffer is
2192 * not large enough.
2193 *
2194 * Returns 0 on success.
2195 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002196int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 void __user *buffer, size_t *lenp, loff_t *ppos)
2198{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002199 return _proc_do_string(table->data, table->maxlen, write, filp,
2200 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
2204static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2205 int *valp,
2206 int write, void *data)
2207{
2208 if (write) {
2209 *valp = *negp ? -*lvalp : *lvalp;
2210 } else {
2211 int val = *valp;
2212 if (val < 0) {
2213 *negp = -1;
2214 *lvalp = (unsigned long)-val;
2215 } else {
2216 *negp = 0;
2217 *lvalp = (unsigned long)val;
2218 }
2219 }
2220 return 0;
2221}
2222
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002223static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002224 int write, struct file *filp, void __user *buffer,
2225 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2227 int write, void *data),
2228 void *data)
2229{
2230#define TMPBUFLEN 21
2231 int *i, vleft, first=1, neg, val;
2232 unsigned long lval;
2233 size_t left, len;
2234
2235 char buf[TMPBUFLEN], *p;
2236 char __user *s = buffer;
2237
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002238 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 (*ppos && !write)) {
2240 *lenp = 0;
2241 return 0;
2242 }
2243
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002244 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 vleft = table->maxlen / sizeof(*i);
2246 left = *lenp;
2247
2248 if (!conv)
2249 conv = do_proc_dointvec_conv;
2250
2251 for (; left && vleft--; i++, first=0) {
2252 if (write) {
2253 while (left) {
2254 char c;
2255 if (get_user(c, s))
2256 return -EFAULT;
2257 if (!isspace(c))
2258 break;
2259 left--;
2260 s++;
2261 }
2262 if (!left)
2263 break;
2264 neg = 0;
2265 len = left;
2266 if (len > sizeof(buf) - 1)
2267 len = sizeof(buf) - 1;
2268 if (copy_from_user(buf, s, len))
2269 return -EFAULT;
2270 buf[len] = 0;
2271 p = buf;
2272 if (*p == '-' && left > 1) {
2273 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002274 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 }
2276 if (*p < '0' || *p > '9')
2277 break;
2278
2279 lval = simple_strtoul(p, &p, 0);
2280
2281 len = p-buf;
2282 if ((len < left) && *p && !isspace(*p))
2283 break;
2284 if (neg)
2285 val = -val;
2286 s += len;
2287 left -= len;
2288
2289 if (conv(&neg, &lval, i, 1, data))
2290 break;
2291 } else {
2292 p = buf;
2293 if (!first)
2294 *p++ = '\t';
2295
2296 if (conv(&neg, &lval, i, 0, data))
2297 break;
2298
2299 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2300 len = strlen(buf);
2301 if (len > left)
2302 len = left;
2303 if(copy_to_user(s, buf, len))
2304 return -EFAULT;
2305 left -= len;
2306 s += len;
2307 }
2308 }
2309
2310 if (!write && !first && left) {
2311 if(put_user('\n', s))
2312 return -EFAULT;
2313 left--, s++;
2314 }
2315 if (write) {
2316 while (left) {
2317 char c;
2318 if (get_user(c, s++))
2319 return -EFAULT;
2320 if (!isspace(c))
2321 break;
2322 left--;
2323 }
2324 }
2325 if (write && first)
2326 return -EINVAL;
2327 *lenp -= left;
2328 *ppos += *lenp;
2329 return 0;
2330#undef TMPBUFLEN
2331}
2332
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002333static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002334 void __user *buffer, size_t *lenp, loff_t *ppos,
2335 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2336 int write, void *data),
2337 void *data)
2338{
2339 return __do_proc_dointvec(table->data, table, write, filp,
2340 buffer, lenp, ppos, conv, data);
2341}
2342
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343/**
2344 * proc_dointvec - read a vector of integers
2345 * @table: the sysctl table
2346 * @write: %TRUE if this is a write to the sysctl file
2347 * @filp: the file structure
2348 * @buffer: the user buffer
2349 * @lenp: the size of the user buffer
2350 * @ppos: file position
2351 *
2352 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2353 * values from/to the user buffer, treated as an ASCII string.
2354 *
2355 * Returns 0 on success.
2356 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002357int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 void __user *buffer, size_t *lenp, loff_t *ppos)
2359{
2360 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2361 NULL,NULL);
2362}
2363
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002364/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002365 * Taint values can only be increased
2366 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002367 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002368static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002369 void __user *buffer, size_t *lenp, loff_t *ppos)
2370{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002371 struct ctl_table t;
2372 unsigned long tmptaint = get_taint();
2373 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002374
Bastian Blank91fcd412007-04-23 14:41:14 -07002375 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002376 return -EPERM;
2377
Andi Kleen25ddbb12008-10-15 22:01:41 -07002378 t = *table;
2379 t.data = &tmptaint;
2380 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2381 if (err < 0)
2382 return err;
2383
2384 if (write) {
2385 /*
2386 * Poor man's atomic or. Not worth adding a primitive
2387 * to everyone's atomic.h for this
2388 */
2389 int i;
2390 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2391 if ((tmptaint >> i) & 1)
2392 add_taint(i);
2393 }
2394 }
2395
2396 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002397}
2398
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399struct do_proc_dointvec_minmax_conv_param {
2400 int *min;
2401 int *max;
2402};
2403
2404static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2405 int *valp,
2406 int write, void *data)
2407{
2408 struct do_proc_dointvec_minmax_conv_param *param = data;
2409 if (write) {
2410 int val = *negp ? -*lvalp : *lvalp;
2411 if ((param->min && *param->min > val) ||
2412 (param->max && *param->max < val))
2413 return -EINVAL;
2414 *valp = val;
2415 } else {
2416 int val = *valp;
2417 if (val < 0) {
2418 *negp = -1;
2419 *lvalp = (unsigned long)-val;
2420 } else {
2421 *negp = 0;
2422 *lvalp = (unsigned long)val;
2423 }
2424 }
2425 return 0;
2426}
2427
2428/**
2429 * proc_dointvec_minmax - read a vector of integers with min/max values
2430 * @table: the sysctl table
2431 * @write: %TRUE if this is a write to the sysctl file
2432 * @filp: the file structure
2433 * @buffer: the user buffer
2434 * @lenp: the size of the user buffer
2435 * @ppos: file position
2436 *
2437 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2438 * values from/to the user buffer, treated as an ASCII string.
2439 *
2440 * This routine will ensure the values are within the range specified by
2441 * table->extra1 (min) and table->extra2 (max).
2442 *
2443 * Returns 0 on success.
2444 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002445int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 void __user *buffer, size_t *lenp, loff_t *ppos)
2447{
2448 struct do_proc_dointvec_minmax_conv_param param = {
2449 .min = (int *) table->extra1,
2450 .max = (int *) table->extra2,
2451 };
2452 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2453 do_proc_dointvec_minmax_conv, &param);
2454}
2455
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002456static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 struct file *filp,
2458 void __user *buffer,
2459 size_t *lenp, loff_t *ppos,
2460 unsigned long convmul,
2461 unsigned long convdiv)
2462{
2463#define TMPBUFLEN 21
2464 unsigned long *i, *min, *max, val;
2465 int vleft, first=1, neg;
2466 size_t len, left;
2467 char buf[TMPBUFLEN], *p;
2468 char __user *s = buffer;
2469
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002470 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 (*ppos && !write)) {
2472 *lenp = 0;
2473 return 0;
2474 }
2475
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002476 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 min = (unsigned long *) table->extra1;
2478 max = (unsigned long *) table->extra2;
2479 vleft = table->maxlen / sizeof(unsigned long);
2480 left = *lenp;
2481
2482 for (; left && vleft--; i++, min++, max++, first=0) {
2483 if (write) {
2484 while (left) {
2485 char c;
2486 if (get_user(c, s))
2487 return -EFAULT;
2488 if (!isspace(c))
2489 break;
2490 left--;
2491 s++;
2492 }
2493 if (!left)
2494 break;
2495 neg = 0;
2496 len = left;
2497 if (len > TMPBUFLEN-1)
2498 len = TMPBUFLEN-1;
2499 if (copy_from_user(buf, s, len))
2500 return -EFAULT;
2501 buf[len] = 0;
2502 p = buf;
2503 if (*p == '-' && left > 1) {
2504 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002505 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 }
2507 if (*p < '0' || *p > '9')
2508 break;
2509 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2510 len = p-buf;
2511 if ((len < left) && *p && !isspace(*p))
2512 break;
2513 if (neg)
2514 val = -val;
2515 s += len;
2516 left -= len;
2517
2518 if(neg)
2519 continue;
2520 if ((min && val < *min) || (max && val > *max))
2521 continue;
2522 *i = val;
2523 } else {
2524 p = buf;
2525 if (!first)
2526 *p++ = '\t';
2527 sprintf(p, "%lu", convdiv * (*i) / convmul);
2528 len = strlen(buf);
2529 if (len > left)
2530 len = left;
2531 if(copy_to_user(s, buf, len))
2532 return -EFAULT;
2533 left -= len;
2534 s += len;
2535 }
2536 }
2537
2538 if (!write && !first && left) {
2539 if(put_user('\n', s))
2540 return -EFAULT;
2541 left--, s++;
2542 }
2543 if (write) {
2544 while (left) {
2545 char c;
2546 if (get_user(c, s++))
2547 return -EFAULT;
2548 if (!isspace(c))
2549 break;
2550 left--;
2551 }
2552 }
2553 if (write && first)
2554 return -EINVAL;
2555 *lenp -= left;
2556 *ppos += *lenp;
2557 return 0;
2558#undef TMPBUFLEN
2559}
2560
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002561static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002562 struct file *filp,
2563 void __user *buffer,
2564 size_t *lenp, loff_t *ppos,
2565 unsigned long convmul,
2566 unsigned long convdiv)
2567{
2568 return __do_proc_doulongvec_minmax(table->data, table, write,
2569 filp, buffer, lenp, ppos, convmul, convdiv);
2570}
2571
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572/**
2573 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2574 * @table: the sysctl table
2575 * @write: %TRUE if this is a write to the sysctl file
2576 * @filp: the file structure
2577 * @buffer: the user buffer
2578 * @lenp: the size of the user buffer
2579 * @ppos: file position
2580 *
2581 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2582 * values from/to the user buffer, treated as an ASCII string.
2583 *
2584 * This routine will ensure the values are within the range specified by
2585 * table->extra1 (min) and table->extra2 (max).
2586 *
2587 * Returns 0 on success.
2588 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002589int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 void __user *buffer, size_t *lenp, loff_t *ppos)
2591{
2592 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2593}
2594
2595/**
2596 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2597 * @table: the sysctl table
2598 * @write: %TRUE if this is a write to the sysctl file
2599 * @filp: the file structure
2600 * @buffer: the user buffer
2601 * @lenp: the size of the user buffer
2602 * @ppos: file position
2603 *
2604 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2605 * values from/to the user buffer, treated as an ASCII string. The values
2606 * are treated as milliseconds, and converted to jiffies when they are stored.
2607 *
2608 * This routine will ensure the values are within the range specified by
2609 * table->extra1 (min) and table->extra2 (max).
2610 *
2611 * Returns 0 on success.
2612 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002613int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 struct file *filp,
2615 void __user *buffer,
2616 size_t *lenp, loff_t *ppos)
2617{
2618 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2619 lenp, ppos, HZ, 1000l);
2620}
2621
2622
2623static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2624 int *valp,
2625 int write, void *data)
2626{
2627 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002628 if (*lvalp > LONG_MAX / HZ)
2629 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2631 } else {
2632 int val = *valp;
2633 unsigned long lval;
2634 if (val < 0) {
2635 *negp = -1;
2636 lval = (unsigned long)-val;
2637 } else {
2638 *negp = 0;
2639 lval = (unsigned long)val;
2640 }
2641 *lvalp = lval / HZ;
2642 }
2643 return 0;
2644}
2645
2646static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2647 int *valp,
2648 int write, void *data)
2649{
2650 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002651 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2652 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2654 } else {
2655 int val = *valp;
2656 unsigned long lval;
2657 if (val < 0) {
2658 *negp = -1;
2659 lval = (unsigned long)-val;
2660 } else {
2661 *negp = 0;
2662 lval = (unsigned long)val;
2663 }
2664 *lvalp = jiffies_to_clock_t(lval);
2665 }
2666 return 0;
2667}
2668
2669static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2670 int *valp,
2671 int write, void *data)
2672{
2673 if (write) {
2674 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2675 } else {
2676 int val = *valp;
2677 unsigned long lval;
2678 if (val < 0) {
2679 *negp = -1;
2680 lval = (unsigned long)-val;
2681 } else {
2682 *negp = 0;
2683 lval = (unsigned long)val;
2684 }
2685 *lvalp = jiffies_to_msecs(lval);
2686 }
2687 return 0;
2688}
2689
2690/**
2691 * proc_dointvec_jiffies - read a vector of integers as seconds
2692 * @table: the sysctl table
2693 * @write: %TRUE if this is a write to the sysctl file
2694 * @filp: the file structure
2695 * @buffer: the user buffer
2696 * @lenp: the size of the user buffer
2697 * @ppos: file position
2698 *
2699 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2700 * values from/to the user buffer, treated as an ASCII string.
2701 * The values read are assumed to be in seconds, and are converted into
2702 * jiffies.
2703 *
2704 * Returns 0 on success.
2705 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002706int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 void __user *buffer, size_t *lenp, loff_t *ppos)
2708{
2709 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2710 do_proc_dointvec_jiffies_conv,NULL);
2711}
2712
2713/**
2714 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2715 * @table: the sysctl table
2716 * @write: %TRUE if this is a write to the sysctl file
2717 * @filp: the file structure
2718 * @buffer: the user buffer
2719 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002720 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 *
2722 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2723 * values from/to the user buffer, treated as an ASCII string.
2724 * The values read are assumed to be in 1/USER_HZ seconds, and
2725 * are converted into jiffies.
2726 *
2727 * Returns 0 on success.
2728 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002729int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 void __user *buffer, size_t *lenp, loff_t *ppos)
2731{
2732 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2733 do_proc_dointvec_userhz_jiffies_conv,NULL);
2734}
2735
2736/**
2737 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2738 * @table: the sysctl table
2739 * @write: %TRUE if this is a write to the sysctl file
2740 * @filp: the file structure
2741 * @buffer: the user buffer
2742 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002743 * @ppos: file position
2744 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 *
2746 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2747 * values from/to the user buffer, treated as an ASCII string.
2748 * The values read are assumed to be in 1/1000 seconds, and
2749 * are converted into jiffies.
2750 *
2751 * Returns 0 on success.
2752 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002753int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 void __user *buffer, size_t *lenp, loff_t *ppos)
2755{
2756 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2757 do_proc_dointvec_ms_jiffies_conv, NULL);
2758}
2759
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002760static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002761 void __user *buffer, size_t *lenp, loff_t *ppos)
2762{
2763 struct pid *new_pid;
2764 pid_t tmp;
2765 int r;
2766
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002767 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002768
2769 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2770 lenp, ppos, NULL, NULL);
2771 if (r || !write)
2772 return r;
2773
2774 new_pid = find_get_pid(tmp);
2775 if (!new_pid)
2776 return -ESRCH;
2777
2778 put_pid(xchg(&cad_pid, new_pid));
2779 return 0;
2780}
2781
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782#else /* CONFIG_PROC_FS */
2783
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002784int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 void __user *buffer, size_t *lenp, loff_t *ppos)
2786{
2787 return -ENOSYS;
2788}
2789
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002790int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 void __user *buffer, size_t *lenp, loff_t *ppos)
2792{
2793 return -ENOSYS;
2794}
2795
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002796int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 void __user *buffer, size_t *lenp, loff_t *ppos)
2798{
2799 return -ENOSYS;
2800}
2801
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002802int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 void __user *buffer, size_t *lenp, loff_t *ppos)
2804{
2805 return -ENOSYS;
2806}
2807
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002808int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 void __user *buffer, size_t *lenp, loff_t *ppos)
2810{
2811 return -ENOSYS;
2812}
2813
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002814int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 void __user *buffer, size_t *lenp, loff_t *ppos)
2816{
2817 return -ENOSYS;
2818}
2819
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002820int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 void __user *buffer, size_t *lenp, loff_t *ppos)
2822{
2823 return -ENOSYS;
2824}
2825
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002826int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 struct file *filp,
2828 void __user *buffer,
2829 size_t *lenp, loff_t *ppos)
2830{
2831 return -ENOSYS;
2832}
2833
2834
2835#endif /* CONFIG_PROC_FS */
2836
2837
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002838#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839/*
2840 * General sysctl support routines
2841 */
2842
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002843/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002844int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002845 void __user *oldval, size_t __user *oldlenp,
2846 void __user *newval, size_t newlen)
2847{
2848 size_t len;
2849
2850 /* Get out of I don't have a variable */
2851 if (!table->data || !table->maxlen)
2852 return -ENOTDIR;
2853
2854 if (oldval && oldlenp) {
2855 if (get_user(len, oldlenp))
2856 return -EFAULT;
2857 if (len) {
2858 if (len > table->maxlen)
2859 len = table->maxlen;
2860 if (copy_to_user(oldval, table->data, len))
2861 return -EFAULT;
2862 if (put_user(len, oldlenp))
2863 return -EFAULT;
2864 }
2865 }
2866
2867 if (newval && newlen) {
2868 if (newlen > table->maxlen)
2869 newlen = table->maxlen;
2870
2871 if (copy_from_user(table->data, newval, newlen))
2872 return -EFAULT;
2873 }
2874 return 1;
2875}
2876
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002878int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002880 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 if (!table->data || !table->maxlen)
2883 return -ENOTDIR;
2884
2885 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002886 size_t bufsize;
2887 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002889 if (bufsize) {
2890 size_t len = strlen(table->data), copied;
2891
2892 /* This shouldn't trigger for a well-formed sysctl */
2893 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002895
2896 /* Copy up to a max of bufsize-1 bytes of the string */
2897 copied = (len >= bufsize) ? bufsize - 1 : len;
2898
2899 if (copy_to_user(oldval, table->data, copied) ||
2900 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002902 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 return -EFAULT;
2904 }
2905 }
2906 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002907 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 if (len > table->maxlen)
2909 len = table->maxlen;
2910 if(copy_from_user(table->data, newval, len))
2911 return -EFAULT;
2912 if (len == table->maxlen)
2913 len--;
2914 ((char *) table->data)[len] = 0;
2915 }
Yi Yang82c9df82005-12-30 16:37:10 +08002916 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917}
2918
2919/*
2920 * This function makes sure that all of the integers in the vector
2921 * are between the minimum and maximum values given in the arrays
2922 * table->extra1 and table->extra2, respectively.
2923 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002924int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002926 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927{
2928
2929 if (newval && newlen) {
2930 int __user *vec = (int __user *) newval;
2931 int *min = (int *) table->extra1;
2932 int *max = (int *) table->extra2;
2933 size_t length;
2934 int i;
2935
2936 if (newlen % sizeof(int) != 0)
2937 return -EINVAL;
2938
2939 if (!table->extra1 && !table->extra2)
2940 return 0;
2941
2942 if (newlen > table->maxlen)
2943 newlen = table->maxlen;
2944 length = newlen / sizeof(int);
2945
2946 for (i = 0; i < length; i++) {
2947 int value;
2948 if (get_user(value, vec + i))
2949 return -EFAULT;
2950 if (min && value < min[i])
2951 return -EINVAL;
2952 if (max && value > max[i])
2953 return -EINVAL;
2954 }
2955 }
2956 return 0;
2957}
2958
2959/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002960int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002962 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002964 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002966
2967 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002969 if (olen) {
2970 int val;
2971
2972 if (olen < sizeof(int))
2973 return -EINVAL;
2974
2975 val = *(int *)(table->data) / HZ;
2976 if (put_user(val, (int __user *)oldval))
2977 return -EFAULT;
2978 if (put_user(sizeof(int), oldlenp))
2979 return -EFAULT;
2980 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 }
2982 if (newval && newlen) {
2983 int new;
2984 if (newlen != sizeof(int))
2985 return -EINVAL;
2986 if (get_user(new, (int __user *)newval))
2987 return -EFAULT;
2988 *(int *)(table->data) = new*HZ;
2989 }
2990 return 1;
2991}
2992
2993/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002994int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002996 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002998 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003000
3001 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003003 if (olen) {
3004 int val;
3005
3006 if (olen < sizeof(int))
3007 return -EINVAL;
3008
3009 val = jiffies_to_msecs(*(int *)(table->data));
3010 if (put_user(val, (int __user *)oldval))
3011 return -EFAULT;
3012 if (put_user(sizeof(int), oldlenp))
3013 return -EFAULT;
3014 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 }
3016 if (newval && newlen) {
3017 int new;
3018 if (newlen != sizeof(int))
3019 return -EINVAL;
3020 if (get_user(new, (int __user *)newval))
3021 return -EFAULT;
3022 *(int *)(table->data) = msecs_to_jiffies(new);
3023 }
3024 return 1;
3025}
3026
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003027
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003028
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003029#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030
3031
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003032SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003034 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003035 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003036
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003037 if (copy_from_user(&tmp, args, sizeof(tmp)))
3038 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003039
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003040 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003041
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003042 /* If no error reading the parameters then just -ENOSYS ... */
3043 if (!error)
3044 error = -ENOSYS;
3045
3046 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047}
3048
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003049int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003050 void __user *oldval, size_t __user *oldlenp,
3051 void __user *newval, size_t newlen)
3052{
3053 return -ENOSYS;
3054}
3055
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003056int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003058 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059{
3060 return -ENOSYS;
3061}
3062
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003063int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003065 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066{
3067 return -ENOSYS;
3068}
3069
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003070int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003072 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073{
3074 return -ENOSYS;
3075}
3076
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003077int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003079 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080{
3081 return -ENOSYS;
3082}
3083
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003084#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003086static int deprecated_sysctl_warning(struct __sysctl_args *args)
3087{
3088 static int msg_count;
3089 int name[CTL_MAXNAME];
3090 int i;
3091
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003092 /* Check args->nlen. */
3093 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3094 return -ENOTDIR;
3095
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003096 /* Read in the sysctl name for better debug message logging */
3097 for (i = 0; i < args->nlen; i++)
3098 if (get_user(name[i], args->name + i))
3099 return -EFAULT;
3100
3101 /* Ignore accesses to kernel.version */
3102 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3103 return 0;
3104
3105 if (msg_count < 5) {
3106 msg_count++;
3107 printk(KERN_INFO
3108 "warning: process `%s' used the deprecated sysctl "
3109 "system call with ", current->comm);
3110 for (i = 0; i < args->nlen; i++)
3111 printk("%d.", name[i]);
3112 printk("\n");
3113 }
3114 return 0;
3115}
3116
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117/*
3118 * No sense putting this after each symbol definition, twice,
3119 * exception granted :-)
3120 */
3121EXPORT_SYMBOL(proc_dointvec);
3122EXPORT_SYMBOL(proc_dointvec_jiffies);
3123EXPORT_SYMBOL(proc_dointvec_minmax);
3124EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3125EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3126EXPORT_SYMBOL(proc_dostring);
3127EXPORT_SYMBOL(proc_doulongvec_minmax);
3128EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3129EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003130EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131EXPORT_SYMBOL(sysctl_intvec);
3132EXPORT_SYMBOL(sysctl_jiffies);
3133EXPORT_SYMBOL(sysctl_ms_jiffies);
3134EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003135EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136EXPORT_SYMBOL(unregister_sysctl_table);