blob: 72eb1a41dcabef2a7d46ab7199cae10edcc3aa5c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/uaccess.h>
54#include <asm/processor.h>
55
Andi Kleen29cbc782006-09-30 01:47:55 +020056#ifdef CONFIG_X86
57#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010058#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010059#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020060#endif
61
Eric W. Biederman7058cb02007-10-18 03:05:58 -070062static int deprecated_sysctl_warning(struct __sysctl_args *args);
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#if defined(CONFIG_SYSCTL)
65
66/* External variables not in a header file. */
67extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070068extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int sysctl_overcommit_memory;
70extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070071extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070072extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080073extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070076extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int pid_max;
79extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080081extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080082extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020083extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000086#ifndef CONFIG_MMU
87extern int sysctl_nr_trim_pages;
88#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070089#ifdef CONFIG_RCU_TORTURE_TEST
90extern int rcutorture_runnable;
91#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070093/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080094#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020096static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097#endif
98
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700100static int __maybe_unused one = 1;
101static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800102static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103static int one_hundred = 100;
Peter W Morrealefafd6882009-04-06 19:00:29 -0700104static int one_thousand = 1000;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107static int maxolduid = 65535;
108static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111static int ngroups_max = NGROUPS_MAX;
112
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200113#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern char modprobe_path[];
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#ifdef CONFIG_CHR_DEV_SG
117extern int sg_big_buff;
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
David S. Miller72c57ed2008-09-11 23:29:54 -0700120#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700121#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#endif
123
David S. Miller08714202008-11-16 23:49:24 -0800124#ifdef CONFIG_SPARC64
125extern int sysctl_tsb_ratio;
126#endif
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef __hppa__
129extern int pwrsw_enabled;
130extern int unaligned_enabled;
131#endif
132
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800133#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef CONFIG_MATHEMU
135extern int sysctl_ieee_emulation_warnings;
136#endif
137extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700138extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#endif
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#ifdef CONFIG_BSD_PROCESS_ACCT
142extern int acct_parm[];
143#endif
144
Jes Sorensend2b176e2006-02-28 09:42:23 -0800145#ifdef CONFIG_IA64
146extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800147extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800148#endif
149
Ingo Molnar23f78d42006-06-27 02:54:53 -0700150#ifdef CONFIG_RT_MUTEXES
151extern int max_lock_depth;
152#endif
153
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700154#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700156 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700157static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800158 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700159#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700160
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700161static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100162static struct ctl_table_root sysctl_table_root;
163static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100164 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100165 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400166 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100167 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400168 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100169};
170static struct ctl_table_root sysctl_table_root = {
171 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400172 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100173};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700175static struct ctl_table kern_table[];
176static struct ctl_table vm_table[];
177static struct ctl_table fs_table[];
178static struct ctl_table debug_table[];
179static struct ctl_table dev_table[];
180extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700181#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700182extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400183#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800184#ifdef CONFIG_EPOLL
185extern struct ctl_table epoll_table[];
186#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
189int sysctl_legacy_va_layout;
190#endif
191
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700192extern int prove_locking;
193extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195/* The default sysctl tables: */
196
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700197static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 {
199 .ctl_name = CTL_KERN,
200 .procname = "kernel",
201 .mode = 0555,
202 .child = kern_table,
203 },
204 {
205 .ctl_name = CTL_VM,
206 .procname = "vm",
207 .mode = 0555,
208 .child = vm_table,
209 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 .ctl_name = CTL_FS,
212 .procname = "fs",
213 .mode = 0555,
214 .child = fs_table,
215 },
216 {
217 .ctl_name = CTL_DEBUG,
218 .procname = "debug",
219 .mode = 0555,
220 .child = debug_table,
221 },
222 {
223 .ctl_name = CTL_DEV,
224 .procname = "dev",
225 .mode = 0555,
226 .child = dev_table,
227 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700228/*
229 * NOTE: do not add new entries to this table unless you have read
230 * Documentation/sysctl/ctl_unnumbered.txt
231 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 { .ctl_name = 0 }
233};
234
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100236static int min_sched_granularity_ns = 100000; /* 100 usecs */
237static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
238static int min_wakeup_granularity_ns; /* 0 usecs */
239static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240#endif
241
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700242static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243#ifdef CONFIG_SCHED_DEBUG
244 {
245 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100246 .procname = "sched_min_granularity_ns",
247 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200248 .maxlen = sizeof(unsigned int),
249 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100250 .proc_handler = &sched_nr_latency_handler,
251 .strategy = &sysctl_intvec,
252 .extra1 = &min_sched_granularity_ns,
253 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200254 },
255 {
256 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200257 .procname = "sched_latency_ns",
258 .data = &sysctl_sched_latency,
259 .maxlen = sizeof(unsigned int),
260 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100261 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200262 .strategy = &sysctl_intvec,
263 .extra1 = &min_sched_granularity_ns,
264 .extra2 = &max_sched_granularity_ns,
265 },
266 {
267 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200268 .procname = "sched_wakeup_granularity_ns",
269 .data = &sysctl_sched_wakeup_granularity,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
272 .proc_handler = &proc_dointvec_minmax,
273 .strategy = &sysctl_intvec,
274 .extra1 = &min_wakeup_granularity_ns,
275 .extra2 = &max_wakeup_granularity_ns,
276 },
277 {
278 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200279 .procname = "sched_shares_ratelimit",
280 .data = &sysctl_sched_shares_ratelimit,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec,
284 },
285 {
286 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200287 .procname = "sched_shares_thresh",
288 .data = &sysctl_sched_shares_thresh,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = &proc_dointvec_minmax,
292 .strategy = &sysctl_intvec,
293 .extra1 = &zero,
294 },
295 {
296 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200297 .procname = "sched_child_runs_first",
298 .data = &sysctl_sched_child_runs_first,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
302 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200303 {
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_features",
306 .data = &sysctl_sched_features,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec,
310 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200311 {
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "sched_migration_cost",
314 .data = &sysctl_sched_migration_cost,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
317 .proc_handler = &proc_dointvec,
318 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100319 {
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "sched_nr_migrate",
322 .data = &sysctl_sched_nr_migrate,
323 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100324 .mode = 0644,
325 .proc_handler = &proc_dointvec,
326 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200327#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200328 {
329 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100330 .procname = "sched_rt_period_us",
331 .data = &sysctl_sched_rt_period,
332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200334 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100335 },
336 {
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "sched_rt_runtime_us",
339 .data = &sysctl_sched_rt_runtime,
340 .maxlen = sizeof(int),
341 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200342 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100343 },
344 {
345 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200346 .procname = "sched_compat_yield",
347 .data = &sysctl_sched_compat_yield,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
350 .proc_handler = &proc_dointvec,
351 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700352#ifdef CONFIG_PROVE_LOCKING
353 {
354 .ctl_name = CTL_UNNUMBERED,
355 .procname = "prove_locking",
356 .data = &prove_locking,
357 .maxlen = sizeof(int),
358 .mode = 0644,
359 .proc_handler = &proc_dointvec,
360 },
361#endif
362#ifdef CONFIG_LOCK_STAT
363 {
364 .ctl_name = CTL_UNNUMBERED,
365 .procname = "lock_stat",
366 .data = &lock_stat,
367 .maxlen = sizeof(int),
368 .mode = 0644,
369 .proc_handler = &proc_dointvec,
370 },
371#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200372 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 .ctl_name = KERN_PANIC,
374 .procname = "panic",
375 .data = &panic_timeout,
376 .maxlen = sizeof(int),
377 .mode = 0644,
378 .proc_handler = &proc_dointvec,
379 },
380 {
381 .ctl_name = KERN_CORE_USES_PID,
382 .procname = "core_uses_pid",
383 .data = &core_uses_pid,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = &proc_dointvec,
387 },
388 {
389 .ctl_name = KERN_CORE_PATTERN,
390 .procname = "core_pattern",
391 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700392 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 .mode = 0644,
394 .proc_handler = &proc_dostring,
395 .strategy = &sysctl_string,
396 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800397#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700400 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800401 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700402 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800404#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100405#ifdef CONFIG_LATENCYTOP
406 {
407 .procname = "latencytop",
408 .data = &latencytop_enabled,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
412 },
413#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414#ifdef CONFIG_BLK_DEV_INITRD
415 {
416 .ctl_name = KERN_REALROOTDEV,
417 .procname = "real-root-dev",
418 .data = &real_root_dev,
419 .maxlen = sizeof(int),
420 .mode = 0644,
421 .proc_handler = &proc_dointvec,
422 },
423#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700424 {
425 .ctl_name = CTL_UNNUMBERED,
426 .procname = "print-fatal-signals",
427 .data = &print_fatal_signals,
428 .maxlen = sizeof(int),
429 .mode = 0644,
430 .proc_handler = &proc_dointvec,
431 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700432#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 {
434 .ctl_name = KERN_SPARC_REBOOT,
435 .procname = "reboot-cmd",
436 .data = reboot_command,
437 .maxlen = 256,
438 .mode = 0644,
439 .proc_handler = &proc_dostring,
440 .strategy = &sysctl_string,
441 },
442 {
443 .ctl_name = KERN_SPARC_STOP_A,
444 .procname = "stop-a",
445 .data = &stop_a_enabled,
446 .maxlen = sizeof (int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450 {
451 .ctl_name = KERN_SPARC_SCONS_PWROFF,
452 .procname = "scons-poweroff",
453 .data = &scons_pwroff,
454 .maxlen = sizeof (int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458#endif
David S. Miller08714202008-11-16 23:49:24 -0800459#ifdef CONFIG_SPARC64
460 {
461 .ctl_name = CTL_UNNUMBERED,
462 .procname = "tsb-ratio",
463 .data = &sysctl_tsb_ratio,
464 .maxlen = sizeof (int),
465 .mode = 0644,
466 .proc_handler = &proc_dointvec,
467 },
468#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#ifdef __hppa__
470 {
471 .ctl_name = KERN_HPPA_PWRSW,
472 .procname = "soft-power",
473 .data = &pwrsw_enabled,
474 .maxlen = sizeof (int),
475 .mode = 0644,
476 .proc_handler = &proc_dointvec,
477 },
478 {
479 .ctl_name = KERN_HPPA_UNALIGNED,
480 .procname = "unaligned-trap",
481 .data = &unaligned_enabled,
482 .maxlen = sizeof (int),
483 .mode = 0644,
484 .proc_handler = &proc_dointvec,
485 },
486#endif
487 {
488 .ctl_name = KERN_CTLALTDEL,
489 .procname = "ctrl-alt-del",
490 .data = &C_A_D,
491 .maxlen = sizeof(int),
492 .mode = 0644,
493 .proc_handler = &proc_dointvec,
494 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400495#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200496 {
497 .ctl_name = CTL_UNNUMBERED,
498 .procname = "ftrace_enabled",
499 .data = &ftrace_enabled,
500 .maxlen = sizeof(int),
501 .mode = 0644,
502 .proc_handler = &ftrace_enable_sysctl,
503 },
504#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500505#ifdef CONFIG_STACK_TRACER
506 {
507 .ctl_name = CTL_UNNUMBERED,
508 .procname = "stack_tracer_enabled",
509 .data = &stack_tracer_enabled,
510 .maxlen = sizeof(int),
511 .mode = 0644,
512 .proc_handler = &stack_trace_sysctl,
513 },
514#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400515#ifdef CONFIG_TRACING
516 {
517 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100518 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400519 .data = &ftrace_dump_on_oops,
520 .maxlen = sizeof(int),
521 .mode = 0644,
522 .proc_handler = &proc_dointvec,
523 },
524#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200525#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 {
527 .ctl_name = KERN_MODPROBE,
528 .procname = "modprobe",
529 .data = &modprobe_path,
530 .maxlen = KMOD_PATH_LEN,
531 .mode = 0644,
532 .proc_handler = &proc_dostring,
533 .strategy = &sysctl_string,
534 },
535#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700536#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 {
538 .ctl_name = KERN_HOTPLUG,
539 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100540 .data = &uevent_helper,
541 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 .mode = 0644,
543 .proc_handler = &proc_dostring,
544 .strategy = &sysctl_string,
545 },
546#endif
547#ifdef CONFIG_CHR_DEV_SG
548 {
549 .ctl_name = KERN_SG_BIG_BUFF,
550 .procname = "sg-big-buff",
551 .data = &sg_big_buff,
552 .maxlen = sizeof (int),
553 .mode = 0444,
554 .proc_handler = &proc_dointvec,
555 },
556#endif
557#ifdef CONFIG_BSD_PROCESS_ACCT
558 {
559 .ctl_name = KERN_ACCT,
560 .procname = "acct",
561 .data = &acct_parm,
562 .maxlen = 3*sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
565 },
566#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#ifdef CONFIG_MAGIC_SYSRQ
568 {
569 .ctl_name = KERN_SYSRQ,
570 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800571 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .maxlen = sizeof (int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
575 },
576#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700577#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700580 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .maxlen = sizeof (int),
582 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700583 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 {
587 .ctl_name = KERN_MAX_THREADS,
588 .procname = "threads-max",
589 .data = &max_threads,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec,
593 },
594 {
595 .ctl_name = KERN_RANDOM,
596 .procname = "random",
597 .mode = 0555,
598 .child = random_table,
599 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 {
601 .ctl_name = KERN_OVERFLOWUID,
602 .procname = "overflowuid",
603 .data = &overflowuid,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec_minmax,
607 .strategy = &sysctl_intvec,
608 .extra1 = &minolduid,
609 .extra2 = &maxolduid,
610 },
611 {
612 .ctl_name = KERN_OVERFLOWGID,
613 .procname = "overflowgid",
614 .data = &overflowgid,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = &proc_dointvec_minmax,
618 .strategy = &sysctl_intvec,
619 .extra1 = &minolduid,
620 .extra2 = &maxolduid,
621 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800622#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#ifdef CONFIG_MATHEMU
624 {
625 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
626 .procname = "ieee_emulation_warnings",
627 .data = &sysctl_ieee_emulation_warnings,
628 .maxlen = sizeof(int),
629 .mode = 0644,
630 .proc_handler = &proc_dointvec,
631 },
632#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 {
634 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
635 .procname = "userprocess_debug",
636 .data = &sysctl_userprocess_debug,
637 .maxlen = sizeof(int),
638 .mode = 0644,
639 .proc_handler = &proc_dointvec,
640 },
641#endif
642 {
643 .ctl_name = KERN_PIDMAX,
644 .procname = "pid_max",
645 .data = &pid_max,
646 .maxlen = sizeof (int),
647 .mode = 0644,
648 .proc_handler = &proc_dointvec_minmax,
649 .strategy = sysctl_intvec,
650 .extra1 = &pid_max_min,
651 .extra2 = &pid_max_max,
652 },
653 {
654 .ctl_name = KERN_PANIC_ON_OOPS,
655 .procname = "panic_on_oops",
656 .data = &panic_on_oops,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 .proc_handler = &proc_dointvec,
660 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800661#if defined CONFIG_PRINTK
662 {
663 .ctl_name = KERN_PRINTK,
664 .procname = "printk",
665 .data = &console_loglevel,
666 .maxlen = 4*sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec,
669 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 {
671 .ctl_name = KERN_PRINTK_RATELIMIT,
672 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700673 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 .maxlen = sizeof(int),
675 .mode = 0644,
676 .proc_handler = &proc_dointvec_jiffies,
677 .strategy = &sysctl_jiffies,
678 },
679 {
680 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
681 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700682 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 .maxlen = sizeof(int),
684 .mode = 0644,
685 .proc_handler = &proc_dointvec,
686 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800687#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 {
689 .ctl_name = KERN_NGROUPS_MAX,
690 .procname = "ngroups_max",
691 .data = &ngroups_max,
692 .maxlen = sizeof (int),
693 .mode = 0444,
694 .proc_handler = &proc_dointvec,
695 },
696#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
697 {
698 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
699 .procname = "unknown_nmi_panic",
700 .data = &unknown_nmi_panic,
701 .maxlen = sizeof (int),
702 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200703 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 },
Don Zickus407984f2006-09-26 10:52:27 +0200705 {
Don Zickus407984f2006-09-26 10:52:27 +0200706 .procname = "nmi_watchdog",
707 .data = &nmi_watchdog_enabled,
708 .maxlen = sizeof (int),
709 .mode = 0644,
710 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 },
712#endif
713#if defined(CONFIG_X86)
714 {
Don Zickus8da5add2006-09-26 10:52:27 +0200715 .ctl_name = KERN_PANIC_ON_NMI,
716 .procname = "panic_on_unrecovered_nmi",
717 .data = &panic_on_unrecovered_nmi,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
721 },
722 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .ctl_name = KERN_BOOTLOADER_TYPE,
724 .procname = "bootloader_type",
725 .data = &bootloader_type,
726 .maxlen = sizeof (int),
727 .mode = 0444,
728 .proc_handler = &proc_dointvec,
729 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100730 {
731 .ctl_name = CTL_UNNUMBERED,
732 .procname = "kstack_depth_to_print",
733 .data = &kstack_depth_to_print,
734 .maxlen = sizeof(int),
735 .mode = 0644,
736 .proc_handler = &proc_dointvec,
737 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100738 {
739 .ctl_name = CTL_UNNUMBERED,
740 .procname = "io_delay_type",
741 .data = &io_delay_type,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = &proc_dointvec,
745 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800747#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 {
749 .ctl_name = KERN_RANDOMIZE,
750 .procname = "randomize_va_space",
751 .data = &randomize_va_space,
752 .maxlen = sizeof(int),
753 .mode = 0644,
754 .proc_handler = &proc_dointvec,
755 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800756#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800757#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700758 {
759 .ctl_name = KERN_SPIN_RETRY,
760 .procname = "spin_retry",
761 .data = &spin_retry,
762 .maxlen = sizeof (int),
763 .mode = 0644,
764 .proc_handler = &proc_dointvec,
765 },
766#endif
Len Brown673d5b42007-07-28 03:33:16 -0400767#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800768 {
Pavel Machekc255d842006-02-20 18:27:58 -0800769 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700770 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800771 .maxlen = sizeof (unsigned long),
772 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800773 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800774 },
775#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800776#ifdef CONFIG_IA64
777 {
778 .ctl_name = KERN_IA64_UNALIGNED,
779 .procname = "ignore-unaligned-usertrap",
780 .data = &no_unaligned_warning,
781 .maxlen = sizeof (int),
782 .mode = 0644,
783 .proc_handler = &proc_dointvec,
784 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800785 {
786 .ctl_name = CTL_UNNUMBERED,
787 .procname = "unaligned-dump-stack",
788 .data = &unaligned_dump_stack,
789 .maxlen = sizeof (int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
792 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800793#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700794#ifdef CONFIG_DETECT_SOFTLOCKUP
795 {
796 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200797 .procname = "softlockup_panic",
798 .data = &softlockup_panic,
799 .maxlen = sizeof(int),
800 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700801 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200802 .strategy = &sysctl_intvec,
803 .extra1 = &zero,
804 .extra2 = &one,
805 },
806 {
807 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700808 .procname = "softlockup_thresh",
809 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200810 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700811 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800812 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700813 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200814 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700815 .extra2 = &sixty,
816 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100817 {
818 .ctl_name = CTL_UNNUMBERED,
819 .procname = "hung_task_check_count",
820 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100821 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100822 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100823 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100824 .strategy = &sysctl_intvec,
825 },
826 {
827 .ctl_name = CTL_UNNUMBERED,
828 .procname = "hung_task_timeout_secs",
829 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100830 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100831 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100832 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100833 .strategy = &sysctl_intvec,
834 },
835 {
836 .ctl_name = CTL_UNNUMBERED,
837 .procname = "hung_task_warnings",
838 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100839 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100840 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100841 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100842 .strategy = &sysctl_intvec,
843 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700844#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200845#ifdef CONFIG_COMPAT
846 {
847 .ctl_name = KERN_COMPAT_LOG,
848 .procname = "compat-log",
849 .data = &compat_log,
850 .maxlen = sizeof (int),
851 .mode = 0644,
852 .proc_handler = &proc_dointvec,
853 },
854#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700855#ifdef CONFIG_RT_MUTEXES
856 {
857 .ctl_name = KERN_MAX_LOCK_DEPTH,
858 .procname = "max_lock_depth",
859 .data = &max_lock_depth,
860 .maxlen = sizeof(int),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec,
863 },
864#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700865 {
866 .ctl_name = CTL_UNNUMBERED,
867 .procname = "poweroff_cmd",
868 .data = &poweroff_cmd,
869 .maxlen = POWEROFF_CMD_PATH_LEN,
870 .mode = 0644,
871 .proc_handler = &proc_dostring,
872 .strategy = &sysctl_string,
873 },
David Howells0b77f5b2008-04-29 01:01:32 -0700874#ifdef CONFIG_KEYS
875 {
876 .ctl_name = CTL_UNNUMBERED,
877 .procname = "keys",
878 .mode = 0555,
879 .child = key_sysctls,
880 },
881#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700882#ifdef CONFIG_RCU_TORTURE_TEST
883 {
884 .ctl_name = CTL_UNNUMBERED,
885 .procname = "rcutorture_runnable",
886 .data = &rcutorture_runnable,
887 .maxlen = sizeof(int),
888 .mode = 0644,
889 .proc_handler = &proc_dointvec,
890 },
891#endif
Lee Schermerhornaf936a12008-10-18 20:26:53 -0700892#ifdef CONFIG_UNEVICTABLE_LRU
893 {
894 .ctl_name = CTL_UNNUMBERED,
895 .procname = "scan_unevictable_pages",
896 .data = &scan_unevictable_pages,
897 .maxlen = sizeof(scan_unevictable_pages),
898 .mode = 0644,
899 .proc_handler = &scan_unevictable_handler,
900 },
901#endif
David Howells12e22c52009-04-03 16:42:35 +0100902#ifdef CONFIG_SLOW_WORK
903 {
904 .ctl_name = CTL_UNNUMBERED,
905 .procname = "slow-work",
906 .mode = 0555,
907 .child = slow_work_sysctls,
908 },
909#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700910/*
911 * NOTE: do not add new entries to this table unless you have read
912 * Documentation/sysctl/ctl_unnumbered.txt
913 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 { .ctl_name = 0 }
915};
916
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700917static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 {
919 .ctl_name = VM_OVERCOMMIT_MEMORY,
920 .procname = "overcommit_memory",
921 .data = &sysctl_overcommit_memory,
922 .maxlen = sizeof(sysctl_overcommit_memory),
923 .mode = 0644,
924 .proc_handler = &proc_dointvec,
925 },
926 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700927 .ctl_name = VM_PANIC_ON_OOM,
928 .procname = "panic_on_oom",
929 .data = &sysctl_panic_on_oom,
930 .maxlen = sizeof(sysctl_panic_on_oom),
931 .mode = 0644,
932 .proc_handler = &proc_dointvec,
933 },
934 {
David Rientjesfe071d72007-10-16 23:25:56 -0700935 .ctl_name = CTL_UNNUMBERED,
936 .procname = "oom_kill_allocating_task",
937 .data = &sysctl_oom_kill_allocating_task,
938 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
939 .mode = 0644,
940 .proc_handler = &proc_dointvec,
941 },
942 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800943 .ctl_name = CTL_UNNUMBERED,
944 .procname = "oom_dump_tasks",
945 .data = &sysctl_oom_dump_tasks,
946 .maxlen = sizeof(sysctl_oom_dump_tasks),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec,
949 },
950 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 .ctl_name = VM_OVERCOMMIT_RATIO,
952 .procname = "overcommit_ratio",
953 .data = &sysctl_overcommit_ratio,
954 .maxlen = sizeof(sysctl_overcommit_ratio),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec,
957 },
958 {
959 .ctl_name = VM_PAGE_CLUSTER,
960 .procname = "page-cluster",
961 .data = &page_cluster,
962 .maxlen = sizeof(int),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 },
966 {
967 .ctl_name = VM_DIRTY_BACKGROUND,
968 .procname = "dirty_background_ratio",
969 .data = &dirty_background_ratio,
970 .maxlen = sizeof(dirty_background_ratio),
971 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800972 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 .strategy = &sysctl_intvec,
974 .extra1 = &zero,
975 .extra2 = &one_hundred,
976 },
977 {
David Rientjes2da02992009-01-06 14:39:31 -0800978 .ctl_name = CTL_UNNUMBERED,
979 .procname = "dirty_background_bytes",
980 .data = &dirty_background_bytes,
981 .maxlen = sizeof(dirty_background_bytes),
982 .mode = 0644,
983 .proc_handler = &dirty_background_bytes_handler,
984 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800985 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -0800986 },
987 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 .ctl_name = VM_DIRTY_RATIO,
989 .procname = "dirty_ratio",
990 .data = &vm_dirty_ratio,
991 .maxlen = sizeof(vm_dirty_ratio),
992 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700993 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 .strategy = &sysctl_intvec,
995 .extra1 = &zero,
996 .extra2 = &one_hundred,
997 },
998 {
David Rientjes2da02992009-01-06 14:39:31 -0800999 .ctl_name = CTL_UNNUMBERED,
1000 .procname = "dirty_bytes",
1001 .data = &vm_dirty_bytes,
1002 .maxlen = sizeof(vm_dirty_bytes),
1003 .mode = 0644,
1004 .proc_handler = &dirty_bytes_handler,
1005 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001006 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001007 },
1008 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001010 .data = &dirty_writeback_interval,
1011 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .mode = 0644,
1013 .proc_handler = &dirty_writeback_centisecs_handler,
1014 },
1015 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001017 .data = &dirty_expire_interval,
1018 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001020 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 },
1022 {
1023 .ctl_name = VM_NR_PDFLUSH_THREADS,
1024 .procname = "nr_pdflush_threads",
1025 .data = &nr_pdflush_threads,
1026 .maxlen = sizeof nr_pdflush_threads,
1027 .mode = 0444 /* read-only*/,
1028 .proc_handler = &proc_dointvec,
1029 },
1030 {
Peter W Morrealefafd6882009-04-06 19:00:29 -07001031 .ctl_name = CTL_UNNUMBERED,
1032 .procname = "nr_pdflush_threads_min",
1033 .data = &nr_pdflush_threads_min,
1034 .maxlen = sizeof nr_pdflush_threads_min,
1035 .mode = 0644 /* read-write */,
1036 .proc_handler = &proc_dointvec_minmax,
1037 .strategy = &sysctl_intvec,
1038 .extra1 = &one,
1039 .extra2 = &nr_pdflush_threads_max,
1040 },
1041 {
1042 .ctl_name = CTL_UNNUMBERED,
1043 .procname = "nr_pdflush_threads_max",
1044 .data = &nr_pdflush_threads_max,
1045 .maxlen = sizeof nr_pdflush_threads_max,
1046 .mode = 0644 /* read-write */,
1047 .proc_handler = &proc_dointvec_minmax,
1048 .strategy = &sysctl_intvec,
1049 .extra1 = &nr_pdflush_threads_min,
1050 .extra2 = &one_thousand,
1051 },
1052 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 .ctl_name = VM_SWAPPINESS,
1054 .procname = "swappiness",
1055 .data = &vm_swappiness,
1056 .maxlen = sizeof(vm_swappiness),
1057 .mode = 0644,
1058 .proc_handler = &proc_dointvec_minmax,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &zero,
1061 .extra2 = &one_hundred,
1062 },
1063#ifdef CONFIG_HUGETLB_PAGE
1064 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001066 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .maxlen = sizeof(unsigned long),
1068 .mode = 0644,
1069 .proc_handler = &hugetlb_sysctl_handler,
1070 .extra1 = (void *)&hugetlb_zero,
1071 .extra2 = (void *)&hugetlb_infinity,
1072 },
1073 {
1074 .ctl_name = VM_HUGETLB_GROUP,
1075 .procname = "hugetlb_shm_group",
1076 .data = &sysctl_hugetlb_shm_group,
1077 .maxlen = sizeof(gid_t),
1078 .mode = 0644,
1079 .proc_handler = &proc_dointvec,
1080 },
Mel Gorman396faf02007-07-17 04:03:13 -07001081 {
1082 .ctl_name = CTL_UNNUMBERED,
1083 .procname = "hugepages_treat_as_movable",
1084 .data = &hugepages_treat_as_movable,
1085 .maxlen = sizeof(int),
1086 .mode = 0644,
1087 .proc_handler = &hugetlb_treat_movable_handler,
1088 },
Adam Litke54f9f802007-10-16 01:26:20 -07001089 {
1090 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001091 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001092 .data = NULL,
1093 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001094 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001095 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001096 .extra1 = (void *)&hugetlb_zero,
1097 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001098 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099#endif
1100 {
1101 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1102 .procname = "lowmem_reserve_ratio",
1103 .data = &sysctl_lowmem_reserve_ratio,
1104 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1105 .mode = 0644,
1106 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1107 .strategy = &sysctl_intvec,
1108 },
1109 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001110 .ctl_name = VM_DROP_PAGECACHE,
1111 .procname = "drop_caches",
1112 .data = &sysctl_drop_caches,
1113 .maxlen = sizeof(int),
1114 .mode = 0644,
1115 .proc_handler = drop_caches_sysctl_handler,
1116 .strategy = &sysctl_intvec,
1117 },
1118 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 .ctl_name = VM_MIN_FREE_KBYTES,
1120 .procname = "min_free_kbytes",
1121 .data = &min_free_kbytes,
1122 .maxlen = sizeof(min_free_kbytes),
1123 .mode = 0644,
1124 .proc_handler = &min_free_kbytes_sysctl_handler,
1125 .strategy = &sysctl_intvec,
1126 .extra1 = &zero,
1127 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001128 {
1129 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1130 .procname = "percpu_pagelist_fraction",
1131 .data = &percpu_pagelist_fraction,
1132 .maxlen = sizeof(percpu_pagelist_fraction),
1133 .mode = 0644,
1134 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1135 .strategy = &sysctl_intvec,
1136 .extra1 = &min_percpu_pagelist_fract,
1137 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138#ifdef CONFIG_MMU
1139 {
1140 .ctl_name = VM_MAX_MAP_COUNT,
1141 .procname = "max_map_count",
1142 .data = &sysctl_max_map_count,
1143 .maxlen = sizeof(sysctl_max_map_count),
1144 .mode = 0644,
1145 .proc_handler = &proc_dointvec
1146 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001147#else
1148 {
1149 .ctl_name = CTL_UNNUMBERED,
1150 .procname = "nr_trim_pages",
1151 .data = &sysctl_nr_trim_pages,
1152 .maxlen = sizeof(sysctl_nr_trim_pages),
1153 .mode = 0644,
1154 .proc_handler = &proc_dointvec_minmax,
1155 .strategy = &sysctl_intvec,
1156 .extra1 = &zero,
1157 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158#endif
1159 {
1160 .ctl_name = VM_LAPTOP_MODE,
1161 .procname = "laptop_mode",
1162 .data = &laptop_mode,
1163 .maxlen = sizeof(laptop_mode),
1164 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001165 .proc_handler = &proc_dointvec_jiffies,
1166 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 },
1168 {
1169 .ctl_name = VM_BLOCK_DUMP,
1170 .procname = "block_dump",
1171 .data = &block_dump,
1172 .maxlen = sizeof(block_dump),
1173 .mode = 0644,
1174 .proc_handler = &proc_dointvec,
1175 .strategy = &sysctl_intvec,
1176 .extra1 = &zero,
1177 },
1178 {
1179 .ctl_name = VM_VFS_CACHE_PRESSURE,
1180 .procname = "vfs_cache_pressure",
1181 .data = &sysctl_vfs_cache_pressure,
1182 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1183 .mode = 0644,
1184 .proc_handler = &proc_dointvec,
1185 .strategy = &sysctl_intvec,
1186 .extra1 = &zero,
1187 },
1188#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1189 {
1190 .ctl_name = VM_LEGACY_VA_LAYOUT,
1191 .procname = "legacy_va_layout",
1192 .data = &sysctl_legacy_va_layout,
1193 .maxlen = sizeof(sysctl_legacy_va_layout),
1194 .mode = 0644,
1195 .proc_handler = &proc_dointvec,
1196 .strategy = &sysctl_intvec,
1197 .extra1 = &zero,
1198 },
1199#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001200#ifdef CONFIG_NUMA
1201 {
1202 .ctl_name = VM_ZONE_RECLAIM_MODE,
1203 .procname = "zone_reclaim_mode",
1204 .data = &zone_reclaim_mode,
1205 .maxlen = sizeof(zone_reclaim_mode),
1206 .mode = 0644,
1207 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001208 .strategy = &sysctl_intvec,
1209 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001210 },
Christoph Lameter96146342006-07-03 00:24:13 -07001211 {
1212 .ctl_name = VM_MIN_UNMAPPED,
1213 .procname = "min_unmapped_ratio",
1214 .data = &sysctl_min_unmapped_ratio,
1215 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1216 .mode = 0644,
1217 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1218 .strategy = &sysctl_intvec,
1219 .extra1 = &zero,
1220 .extra2 = &one_hundred,
1221 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001222 {
1223 .ctl_name = VM_MIN_SLAB,
1224 .procname = "min_slab_ratio",
1225 .data = &sysctl_min_slab_ratio,
1226 .maxlen = sizeof(sysctl_min_slab_ratio),
1227 .mode = 0644,
1228 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1229 .strategy = &sysctl_intvec,
1230 .extra1 = &zero,
1231 .extra2 = &one_hundred,
1232 },
Christoph Lameter17436602006-01-18 17:42:32 -08001233#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001234#ifdef CONFIG_SMP
1235 {
1236 .ctl_name = CTL_UNNUMBERED,
1237 .procname = "stat_interval",
1238 .data = &sysctl_stat_interval,
1239 .maxlen = sizeof(sysctl_stat_interval),
1240 .mode = 0644,
1241 .proc_handler = &proc_dointvec_jiffies,
1242 .strategy = &sysctl_jiffies,
1243 },
1244#endif
Eric Parised032182007-06-28 15:55:21 -04001245#ifdef CONFIG_SECURITY
1246 {
1247 .ctl_name = CTL_UNNUMBERED,
1248 .procname = "mmap_min_addr",
1249 .data = &mmap_min_addr,
1250 .maxlen = sizeof(unsigned long),
1251 .mode = 0644,
1252 .proc_handler = &proc_doulongvec_minmax,
1253 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001254#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001255#ifdef CONFIG_NUMA
1256 {
1257 .ctl_name = CTL_UNNUMBERED,
1258 .procname = "numa_zonelist_order",
1259 .data = &numa_zonelist_order,
1260 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1261 .mode = 0644,
1262 .proc_handler = &numa_zonelist_order_handler,
1263 .strategy = &sysctl_string,
1264 },
1265#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001266#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001267 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001268 {
1269 .ctl_name = VM_VDSO_ENABLED,
1270 .procname = "vdso_enabled",
1271 .data = &vdso_enabled,
1272 .maxlen = sizeof(vdso_enabled),
1273 .mode = 0644,
1274 .proc_handler = &proc_dointvec,
1275 .strategy = &sysctl_intvec,
1276 .extra1 = &zero,
1277 },
1278#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001279#ifdef CONFIG_HIGHMEM
1280 {
1281 .ctl_name = CTL_UNNUMBERED,
1282 .procname = "highmem_is_dirtyable",
1283 .data = &vm_highmem_is_dirtyable,
1284 .maxlen = sizeof(vm_highmem_is_dirtyable),
1285 .mode = 0644,
1286 .proc_handler = &proc_dointvec_minmax,
1287 .strategy = &sysctl_intvec,
1288 .extra1 = &zero,
1289 .extra2 = &one,
1290 },
1291#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001292/*
1293 * NOTE: do not add new entries to this table unless you have read
1294 * Documentation/sysctl/ctl_unnumbered.txt
1295 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 { .ctl_name = 0 }
1297};
1298
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001299#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001300static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001301 { .ctl_name = 0 }
1302};
1303#endif
1304
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001305static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 {
1307 .ctl_name = FS_NRINODE,
1308 .procname = "inode-nr",
1309 .data = &inodes_stat,
1310 .maxlen = 2*sizeof(int),
1311 .mode = 0444,
1312 .proc_handler = &proc_dointvec,
1313 },
1314 {
1315 .ctl_name = FS_STATINODE,
1316 .procname = "inode-state",
1317 .data = &inodes_stat,
1318 .maxlen = 7*sizeof(int),
1319 .mode = 0444,
1320 .proc_handler = &proc_dointvec,
1321 },
1322 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 .procname = "file-nr",
1324 .data = &files_stat,
1325 .maxlen = 3*sizeof(int),
1326 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001327 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 },
1329 {
1330 .ctl_name = FS_MAXFILE,
1331 .procname = "file-max",
1332 .data = &files_stat.max_files,
1333 .maxlen = sizeof(int),
1334 .mode = 0644,
1335 .proc_handler = &proc_dointvec,
1336 },
1337 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001338 .ctl_name = CTL_UNNUMBERED,
1339 .procname = "nr_open",
1340 .data = &sysctl_nr_open,
1341 .maxlen = sizeof(int),
1342 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001343 .proc_handler = &proc_dointvec_minmax,
1344 .extra1 = &sysctl_nr_open_min,
1345 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001346 },
1347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .ctl_name = FS_DENTRY,
1349 .procname = "dentry-state",
1350 .data = &dentry_stat,
1351 .maxlen = 6*sizeof(int),
1352 .mode = 0444,
1353 .proc_handler = &proc_dointvec,
1354 },
1355 {
1356 .ctl_name = FS_OVERFLOWUID,
1357 .procname = "overflowuid",
1358 .data = &fs_overflowuid,
1359 .maxlen = sizeof(int),
1360 .mode = 0644,
1361 .proc_handler = &proc_dointvec_minmax,
1362 .strategy = &sysctl_intvec,
1363 .extra1 = &minolduid,
1364 .extra2 = &maxolduid,
1365 },
1366 {
1367 .ctl_name = FS_OVERFLOWGID,
1368 .procname = "overflowgid",
1369 .data = &fs_overflowgid,
1370 .maxlen = sizeof(int),
1371 .mode = 0644,
1372 .proc_handler = &proc_dointvec_minmax,
1373 .strategy = &sysctl_intvec,
1374 .extra1 = &minolduid,
1375 .extra2 = &maxolduid,
1376 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001377#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 {
1379 .ctl_name = FS_LEASES,
1380 .procname = "leases-enable",
1381 .data = &leases_enable,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = &proc_dointvec,
1385 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001386#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387#ifdef CONFIG_DNOTIFY
1388 {
1389 .ctl_name = FS_DIR_NOTIFY,
1390 .procname = "dir-notify-enable",
1391 .data = &dir_notify_enable,
1392 .maxlen = sizeof(int),
1393 .mode = 0644,
1394 .proc_handler = &proc_dointvec,
1395 },
1396#endif
1397#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001398#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 {
1400 .ctl_name = FS_LEASE_TIME,
1401 .procname = "lease-break-time",
1402 .data = &lease_break_time,
1403 .maxlen = sizeof(int),
1404 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001405 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001407#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001408#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 .procname = "aio-nr",
1411 .data = &aio_nr,
1412 .maxlen = sizeof(aio_nr),
1413 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001414 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 },
1416 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 .procname = "aio-max-nr",
1418 .data = &aio_max_nr,
1419 .maxlen = sizeof(aio_max_nr),
1420 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001421 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001423#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001424#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001425 {
1426 .ctl_name = FS_INOTIFY,
1427 .procname = "inotify",
1428 .mode = 0555,
1429 .child = inotify_table,
1430 },
1431#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001432#ifdef CONFIG_EPOLL
1433 {
1434 .procname = "epoll",
1435 .mode = 0555,
1436 .child = epoll_table,
1437 },
1438#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001440 {
1441 .ctl_name = KERN_SETUID_DUMPABLE,
1442 .procname = "suid_dumpable",
1443 .data = &suid_dumpable,
1444 .maxlen = sizeof(int),
1445 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001446 .proc_handler = &proc_dointvec_minmax,
1447 .strategy = &sysctl_intvec,
1448 .extra1 = &zero,
1449 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001450 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001451#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1452 {
1453 .ctl_name = CTL_UNNUMBERED,
1454 .procname = "binfmt_misc",
1455 .mode = 0555,
1456 .child = binfmt_misc_table,
1457 },
1458#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001459/*
1460 * NOTE: do not add new entries to this table unless you have read
1461 * Documentation/sysctl/ctl_unnumbered.txt
1462 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 { .ctl_name = 0 }
1464};
1465
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001466static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001467#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001468 {
1469 .ctl_name = CTL_UNNUMBERED,
1470 .procname = "exception-trace",
1471 .data = &show_unhandled_signals,
1472 .maxlen = sizeof(int),
1473 .mode = 0644,
1474 .proc_handler = proc_dointvec
1475 },
1476#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 { .ctl_name = 0 }
1478};
1479
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001480static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001482};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Al Viro330d57f2005-11-04 10:18:40 +00001484static DEFINE_SPINLOCK(sysctl_lock);
1485
1486/* called under sysctl_lock */
1487static int use_table(struct ctl_table_header *p)
1488{
1489 if (unlikely(p->unregistering))
1490 return 0;
1491 p->used++;
1492 return 1;
1493}
1494
1495/* called under sysctl_lock */
1496static void unuse_table(struct ctl_table_header *p)
1497{
1498 if (!--p->used)
1499 if (unlikely(p->unregistering))
1500 complete(p->unregistering);
1501}
1502
1503/* called under sysctl_lock, will reacquire if has to wait */
1504static void start_unregistering(struct ctl_table_header *p)
1505{
1506 /*
1507 * if p->used is 0, nobody will ever touch that entry again;
1508 * we'll eliminate all paths to it before dropping sysctl_lock
1509 */
1510 if (unlikely(p->used)) {
1511 struct completion wait;
1512 init_completion(&wait);
1513 p->unregistering = &wait;
1514 spin_unlock(&sysctl_lock);
1515 wait_for_completion(&wait);
1516 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001517 } else {
1518 /* anything non-NULL; we'll never dereference it */
1519 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001520 }
1521 /*
1522 * do not remove from the list until nobody holds it; walking the
1523 * list in do_sysctl() relies on that.
1524 */
1525 list_del_init(&p->ctl_entry);
1526}
1527
Al Virof7e6ced2008-07-15 01:44:23 -04001528void sysctl_head_get(struct ctl_table_header *head)
1529{
1530 spin_lock(&sysctl_lock);
1531 head->count++;
1532 spin_unlock(&sysctl_lock);
1533}
1534
1535void sysctl_head_put(struct ctl_table_header *head)
1536{
1537 spin_lock(&sysctl_lock);
1538 if (!--head->count)
1539 kfree(head);
1540 spin_unlock(&sysctl_lock);
1541}
1542
1543struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1544{
1545 if (!head)
1546 BUG();
1547 spin_lock(&sysctl_lock);
1548 if (!use_table(head))
1549 head = ERR_PTR(-ENOENT);
1550 spin_unlock(&sysctl_lock);
1551 return head;
1552}
1553
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001554void sysctl_head_finish(struct ctl_table_header *head)
1555{
1556 if (!head)
1557 return;
1558 spin_lock(&sysctl_lock);
1559 unuse_table(head);
1560 spin_unlock(&sysctl_lock);
1561}
1562
Al Viro73455092008-07-14 21:22:20 -04001563static struct ctl_table_set *
1564lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1565{
1566 struct ctl_table_set *set = &root->default_set;
1567 if (root->lookup)
1568 set = root->lookup(root, namespaces);
1569 return set;
1570}
1571
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001572static struct list_head *
1573lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001574{
Al Viro73455092008-07-14 21:22:20 -04001575 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1576 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001577}
1578
1579struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1580 struct ctl_table_header *prev)
1581{
1582 struct ctl_table_root *root;
1583 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001584 struct ctl_table_header *head;
1585 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001586
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001587 spin_lock(&sysctl_lock);
1588 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001589 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001590 tmp = &prev->ctl_entry;
1591 unuse_table(prev);
1592 goto next;
1593 }
1594 tmp = &root_table_header.ctl_entry;
1595 for (;;) {
1596 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1597
1598 if (!use_table(head))
1599 goto next;
1600 spin_unlock(&sysctl_lock);
1601 return head;
1602 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001603 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001604 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001605 header_list = lookup_header_list(root, namespaces);
1606 if (tmp != header_list)
1607 continue;
1608
1609 do {
1610 root = list_entry(root->root_list.next,
1611 struct ctl_table_root, root_list);
1612 if (root == &sysctl_table_root)
1613 goto out;
1614 header_list = lookup_header_list(root, namespaces);
1615 } while (list_empty(header_list));
1616 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001617 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001618out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001619 spin_unlock(&sysctl_lock);
1620 return NULL;
1621}
1622
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001623struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1624{
1625 return __sysctl_head_next(current->nsproxy, prev);
1626}
1627
1628void register_sysctl_root(struct ctl_table_root *root)
1629{
1630 spin_lock(&sysctl_lock);
1631 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1632 spin_unlock(&sysctl_lock);
1633}
1634
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001635#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001636/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001637static int do_sysctl_strategy(struct ctl_table_root *root,
1638 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001639 void __user *oldval, size_t __user *oldlenp,
1640 void __user *newval, size_t newlen)
1641{
1642 int op = 0, rc;
1643
1644 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001645 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001646 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001647 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001648 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001649 return -EPERM;
1650
1651 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001652 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001653 if (rc < 0)
1654 return rc;
1655 if (rc > 0)
1656 return 0;
1657 }
1658
1659 /* If there is no strategy routine, or if the strategy returns
1660 * zero, proceed with automatic r/w */
1661 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001662 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001663 if (rc < 0)
1664 return rc;
1665 }
1666 return 0;
1667}
1668
1669static int parse_table(int __user *name, int nlen,
1670 void __user *oldval, size_t __user *oldlenp,
1671 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001672 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001673 struct ctl_table *table)
1674{
1675 int n;
1676repeat:
1677 if (!nlen)
1678 return -ENOTDIR;
1679 if (get_user(n, name))
1680 return -EFAULT;
1681 for ( ; table->ctl_name || table->procname; table++) {
1682 if (!table->ctl_name)
1683 continue;
1684 if (n == table->ctl_name) {
1685 int error;
1686 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001687 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001688 return -EPERM;
1689 name++;
1690 nlen--;
1691 table = table->child;
1692 goto repeat;
1693 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001694 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001695 oldval, oldlenp,
1696 newval, newlen);
1697 return error;
1698 }
1699 }
1700 return -ENOTDIR;
1701}
1702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1704 void __user *newval, size_t newlen)
1705{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001706 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001707 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1710 return -ENOTDIR;
1711 if (oldval) {
1712 int old_len;
1713 if (!oldlenp || get_user(old_len, oldlenp))
1714 return -EFAULT;
1715 }
Al Viro330d57f2005-11-04 10:18:40 +00001716
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001717 for (head = sysctl_head_next(NULL); head;
1718 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001719 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001720 newval, newlen,
1721 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001722 if (error != -ENOTDIR) {
1723 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001724 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001725 }
1726 }
Al Viro330d57f2005-11-04 10:18:40 +00001727 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728}
1729
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001730SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731{
1732 struct __sysctl_args tmp;
1733 int error;
1734
1735 if (copy_from_user(&tmp, args, sizeof(tmp)))
1736 return -EFAULT;
1737
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001738 error = deprecated_sysctl_warning(&tmp);
1739 if (error)
1740 goto out;
1741
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 lock_kernel();
1743 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1744 tmp.newval, tmp.newlen);
1745 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001746out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 return error;
1748}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001749#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
1751/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001752 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 * some sysctl variables are readonly even to root.
1754 */
1755
1756static int test_perm(int mode, int op)
1757{
David Howells76aac0e2008-11-14 10:39:12 +11001758 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 mode >>= 6;
1760 else if (in_egroup_p(0))
1761 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001762 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 return 0;
1764 return -EACCES;
1765}
1766
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001767int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768{
1769 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001770 int mode;
1771
Al Viroe6305c42008-07-15 21:03:57 -04001772 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 if (error)
1774 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001775
1776 if (root->permissions)
1777 mode = root->permissions(root, current->nsproxy, table);
1778 else
1779 mode = table->mode;
1780
1781 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782}
1783
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001784static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1785{
1786 for (; table->ctl_name || table->procname; table++) {
1787 table->parent = parent;
1788 if (table->child)
1789 sysctl_set_parent(table, table->child);
1790 }
1791}
1792
1793static __init int sysctl_init(void)
1794{
1795 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001796#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1797 {
1798 int err;
1799 err = sysctl_check_table(current->nsproxy, root_table);
1800 }
1801#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001802 return 0;
1803}
1804
1805core_initcall(sysctl_init);
1806
Al Virobfbcf032008-07-27 06:31:22 +01001807static struct ctl_table *is_branch_in(struct ctl_table *branch,
1808 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001809{
1810 struct ctl_table *p;
1811 const char *s = branch->procname;
1812
1813 /* branch should have named subdirectory as its first element */
1814 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001815 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001816
1817 /* ... and nothing else */
1818 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001819 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001820
1821 /* table should contain subdirectory with the same name */
1822 for (p = table; p->procname || p->ctl_name; p++) {
1823 if (!p->child)
1824 continue;
1825 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001826 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001827 }
Al Virobfbcf032008-07-27 06:31:22 +01001828 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001829}
1830
1831/* see if attaching q to p would be an improvement */
1832static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1833{
1834 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001835 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001836 int is_better = 0;
1837 int not_in_parent = !p->attached_by;
1838
Al Virobfbcf032008-07-27 06:31:22 +01001839 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001840 if (by == q->attached_by)
1841 is_better = 1;
1842 if (to == p->attached_by)
1843 not_in_parent = 1;
1844 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001845 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001846 }
1847
1848 if (is_better && not_in_parent) {
1849 q->attached_by = by;
1850 q->attached_to = to;
1851 q->parent = p;
1852 }
1853}
1854
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001856 * __register_sysctl_paths - register a sysctl hierarchy
1857 * @root: List of sysctl headers to register on
1858 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001859 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 *
1862 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001863 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001865 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 *
1867 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1868 * must be unique within that level of sysctl
1869 *
1870 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1871 * enter a sysctl file
1872 *
1873 * data - a pointer to data for use by proc_handler
1874 *
1875 * maxlen - the maximum size in bytes of the data
1876 *
1877 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1878 *
1879 * child - a pointer to the child sysctl table if this entry is a directory, or
1880 * %NULL.
1881 *
1882 * proc_handler - the text handler routine (described below)
1883 *
1884 * strategy - the strategy routine (described below)
1885 *
1886 * de - for internal use by the sysctl routines
1887 *
1888 * extra1, extra2 - extra pointers usable by the proc handler routines
1889 *
1890 * Leaf nodes in the sysctl tree will be represented by a single file
1891 * under /proc; non-leaf nodes will be represented by directories.
1892 *
1893 * sysctl(2) can automatically manage read and write requests through
1894 * the sysctl table. The data and maxlen fields of the ctl_table
1895 * struct enable minimal validation of the values being written to be
1896 * performed, and the mode field allows minimal authentication.
1897 *
1898 * More sophisticated management can be enabled by the provision of a
1899 * strategy routine with the table entry. This will be called before
1900 * any automatic read or write of the data is performed.
1901 *
1902 * The strategy routine may return
1903 *
1904 * < 0 - Error occurred (error is passed to user process)
1905 *
1906 * 0 - OK - proceed with automatic read or write.
1907 *
1908 * > 0 - OK - read or write has been done by the strategy routine, so
1909 * return immediately.
1910 *
1911 * There must be a proc_handler routine for any terminal nodes
1912 * mirrored under /proc/sys (non-terminals are handled by a built-in
1913 * directory handler). Several default handlers are available to
1914 * cover common cases -
1915 *
1916 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1917 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1918 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1919 *
1920 * It is the handler's job to read the input buffer from user memory
1921 * and process it. The handler should return 0 on success.
1922 *
1923 * This routine returns %NULL on a failure to register, and a pointer
1924 * to the table header on success.
1925 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001926struct ctl_table_header *__register_sysctl_paths(
1927 struct ctl_table_root *root,
1928 struct nsproxy *namespaces,
1929 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001931 struct ctl_table_header *header;
1932 struct ctl_table *new, **prevp;
1933 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001934 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001935
1936 /* Count the path components */
1937 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1938 ;
1939
1940 /*
1941 * For each path component, allocate a 2-element ctl_table array.
1942 * The first array element will be filled with the sysctl entry
1943 * for this, the second will be the sentinel (ctl_name == 0).
1944 *
1945 * We allocate everything in one go so that we don't have to
1946 * worry about freeing additional memory in unregister_sysctl_table.
1947 */
1948 header = kzalloc(sizeof(struct ctl_table_header) +
1949 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1950 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001952
1953 new = (struct ctl_table *) (header + 1);
1954
1955 /* Now connect the dots */
1956 prevp = &header->ctl_table;
1957 for (n = 0; n < npath; ++n, ++path) {
1958 /* Copy the procname */
1959 new->procname = path->procname;
1960 new->ctl_name = path->ctl_name;
1961 new->mode = 0555;
1962
1963 *prevp = new;
1964 prevp = &new->child;
1965
1966 new += 2;
1967 }
1968 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001969 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001970
1971 INIT_LIST_HEAD(&header->ctl_entry);
1972 header->used = 0;
1973 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001974 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001975 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001976 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001977#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001978 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001979 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001980 return NULL;
1981 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001982#endif
Al Viro330d57f2005-11-04 10:18:40 +00001983 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001984 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001985 header->attached_by = header->ctl_table;
1986 header->attached_to = root_table;
1987 header->parent = &root_table_header;
1988 for (set = header->set; set; set = set->parent) {
1989 struct ctl_table_header *p;
1990 list_for_each_entry(p, &set->list, ctl_entry) {
1991 if (p->unregistering)
1992 continue;
1993 try_attach(p, header);
1994 }
1995 }
1996 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001997 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001998 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001999
2000 return header;
2001}
2002
2003/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002004 * register_sysctl_table_path - register a sysctl table hierarchy
2005 * @path: The path to the directory the sysctl table is in.
2006 * @table: the top-level table structure
2007 *
2008 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2009 * array. A completely 0 filled entry terminates the table.
2010 *
2011 * See __register_sysctl_paths for more details.
2012 */
2013struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2014 struct ctl_table *table)
2015{
2016 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2017 path, table);
2018}
2019
2020/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002021 * register_sysctl_table - register a sysctl table hierarchy
2022 * @table: the top-level table structure
2023 *
2024 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2025 * array. A completely 0 filled entry terminates the table.
2026 *
2027 * See register_sysctl_paths for more details.
2028 */
2029struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2030{
2031 static const struct ctl_path null_path[] = { {} };
2032
2033 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034}
2035
2036/**
2037 * unregister_sysctl_table - unregister a sysctl table hierarchy
2038 * @header: the header returned from register_sysctl_table
2039 *
2040 * Unregisters the sysctl table and all children. proc entries may not
2041 * actually be removed until they are no longer used by anyone.
2042 */
2043void unregister_sysctl_table(struct ctl_table_header * header)
2044{
Al Viro330d57f2005-11-04 10:18:40 +00002045 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002046
2047 if (header == NULL)
2048 return;
2049
Al Viro330d57f2005-11-04 10:18:40 +00002050 spin_lock(&sysctl_lock);
2051 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002052 if (!--header->parent->count) {
2053 WARN_ON(1);
2054 kfree(header->parent);
2055 }
Al Virof7e6ced2008-07-15 01:44:23 -04002056 if (!--header->count)
2057 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002058 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
Al Viro90434762008-07-15 08:54:06 -04002061int sysctl_is_seen(struct ctl_table_header *p)
2062{
2063 struct ctl_table_set *set = p->set;
2064 int res;
2065 spin_lock(&sysctl_lock);
2066 if (p->unregistering)
2067 res = 0;
2068 else if (!set->is_seen)
2069 res = 1;
2070 else
2071 res = set->is_seen(set);
2072 spin_unlock(&sysctl_lock);
2073 return res;
2074}
2075
Al Viro73455092008-07-14 21:22:20 -04002076void setup_sysctl_set(struct ctl_table_set *p,
2077 struct ctl_table_set *parent,
2078 int (*is_seen)(struct ctl_table_set *))
2079{
2080 INIT_LIST_HEAD(&p->list);
2081 p->parent = parent ? parent : &sysctl_table_root.default_set;
2082 p->is_seen = is_seen;
2083}
2084
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002085#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002086struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002087{
2088 return NULL;
2089}
2090
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002091struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2092 struct ctl_table *table)
2093{
2094 return NULL;
2095}
2096
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002097void unregister_sysctl_table(struct ctl_table_header * table)
2098{
2099}
2100
Al Viro73455092008-07-14 21:22:20 -04002101void setup_sysctl_set(struct ctl_table_set *p,
2102 struct ctl_table_set *parent,
2103 int (*is_seen)(struct ctl_table_set *))
2104{
2105}
2106
Al Virof7e6ced2008-07-15 01:44:23 -04002107void sysctl_head_put(struct ctl_table_header *head)
2108{
2109}
2110
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002111#endif /* CONFIG_SYSCTL */
2112
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113/*
2114 * /proc/sys support
2115 */
2116
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002117#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002119static int _proc_do_string(void* data, int maxlen, int write,
2120 struct file *filp, void __user *buffer,
2121 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002122{
2123 size_t len;
2124 char __user *p;
2125 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002126
2127 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002128 *lenp = 0;
2129 return 0;
2130 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002131
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002132 if (write) {
2133 len = 0;
2134 p = buffer;
2135 while (len < *lenp) {
2136 if (get_user(c, p++))
2137 return -EFAULT;
2138 if (c == 0 || c == '\n')
2139 break;
2140 len++;
2141 }
2142 if (len >= maxlen)
2143 len = maxlen-1;
2144 if(copy_from_user(data, buffer, len))
2145 return -EFAULT;
2146 ((char *) data)[len] = 0;
2147 *ppos += *lenp;
2148 } else {
2149 len = strlen(data);
2150 if (len > maxlen)
2151 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002152
2153 if (*ppos > len) {
2154 *lenp = 0;
2155 return 0;
2156 }
2157
2158 data += *ppos;
2159 len -= *ppos;
2160
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002161 if (len > *lenp)
2162 len = *lenp;
2163 if (len)
2164 if(copy_to_user(buffer, data, len))
2165 return -EFAULT;
2166 if (len < *lenp) {
2167 if(put_user('\n', ((char __user *) buffer) + len))
2168 return -EFAULT;
2169 len++;
2170 }
2171 *lenp = len;
2172 *ppos += len;
2173 }
2174 return 0;
2175}
2176
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177/**
2178 * proc_dostring - read a string sysctl
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @filp: the file structure
2182 * @buffer: the user buffer
2183 * @lenp: the size of the user buffer
2184 * @ppos: file position
2185 *
2186 * Reads/writes a string from/to the user buffer. If the kernel
2187 * buffer provided is not large enough to hold the string, the
2188 * string is truncated. The copied string is %NULL-terminated.
2189 * If the string is being read by the user process, it is copied
2190 * and a newline '\n' is added. It is truncated if the buffer is
2191 * not large enough.
2192 *
2193 * Returns 0 on success.
2194 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002195int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 void __user *buffer, size_t *lenp, loff_t *ppos)
2197{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002198 return _proc_do_string(table->data, table->maxlen, write, filp,
2199 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
2203static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2204 int *valp,
2205 int write, void *data)
2206{
2207 if (write) {
2208 *valp = *negp ? -*lvalp : *lvalp;
2209 } else {
2210 int val = *valp;
2211 if (val < 0) {
2212 *negp = -1;
2213 *lvalp = (unsigned long)-val;
2214 } else {
2215 *negp = 0;
2216 *lvalp = (unsigned long)val;
2217 }
2218 }
2219 return 0;
2220}
2221
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002222static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002223 int write, struct file *filp, void __user *buffer,
2224 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2226 int write, void *data),
2227 void *data)
2228{
2229#define TMPBUFLEN 21
2230 int *i, vleft, first=1, neg, val;
2231 unsigned long lval;
2232 size_t left, len;
2233
2234 char buf[TMPBUFLEN], *p;
2235 char __user *s = buffer;
2236
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002237 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 (*ppos && !write)) {
2239 *lenp = 0;
2240 return 0;
2241 }
2242
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002243 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 vleft = table->maxlen / sizeof(*i);
2245 left = *lenp;
2246
2247 if (!conv)
2248 conv = do_proc_dointvec_conv;
2249
2250 for (; left && vleft--; i++, first=0) {
2251 if (write) {
2252 while (left) {
2253 char c;
2254 if (get_user(c, s))
2255 return -EFAULT;
2256 if (!isspace(c))
2257 break;
2258 left--;
2259 s++;
2260 }
2261 if (!left)
2262 break;
2263 neg = 0;
2264 len = left;
2265 if (len > sizeof(buf) - 1)
2266 len = sizeof(buf) - 1;
2267 if (copy_from_user(buf, s, len))
2268 return -EFAULT;
2269 buf[len] = 0;
2270 p = buf;
2271 if (*p == '-' && left > 1) {
2272 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002273 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 }
2275 if (*p < '0' || *p > '9')
2276 break;
2277
2278 lval = simple_strtoul(p, &p, 0);
2279
2280 len = p-buf;
2281 if ((len < left) && *p && !isspace(*p))
2282 break;
2283 if (neg)
2284 val = -val;
2285 s += len;
2286 left -= len;
2287
2288 if (conv(&neg, &lval, i, 1, data))
2289 break;
2290 } else {
2291 p = buf;
2292 if (!first)
2293 *p++ = '\t';
2294
2295 if (conv(&neg, &lval, i, 0, data))
2296 break;
2297
2298 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2299 len = strlen(buf);
2300 if (len > left)
2301 len = left;
2302 if(copy_to_user(s, buf, len))
2303 return -EFAULT;
2304 left -= len;
2305 s += len;
2306 }
2307 }
2308
2309 if (!write && !first && left) {
2310 if(put_user('\n', s))
2311 return -EFAULT;
2312 left--, s++;
2313 }
2314 if (write) {
2315 while (left) {
2316 char c;
2317 if (get_user(c, s++))
2318 return -EFAULT;
2319 if (!isspace(c))
2320 break;
2321 left--;
2322 }
2323 }
2324 if (write && first)
2325 return -EINVAL;
2326 *lenp -= left;
2327 *ppos += *lenp;
2328 return 0;
2329#undef TMPBUFLEN
2330}
2331
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002332static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002333 void __user *buffer, size_t *lenp, loff_t *ppos,
2334 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2335 int write, void *data),
2336 void *data)
2337{
2338 return __do_proc_dointvec(table->data, table, write, filp,
2339 buffer, lenp, ppos, conv, data);
2340}
2341
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342/**
2343 * proc_dointvec - read a vector of integers
2344 * @table: the sysctl table
2345 * @write: %TRUE if this is a write to the sysctl file
2346 * @filp: the file structure
2347 * @buffer: the user buffer
2348 * @lenp: the size of the user buffer
2349 * @ppos: file position
2350 *
2351 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2352 * values from/to the user buffer, treated as an ASCII string.
2353 *
2354 * Returns 0 on success.
2355 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002356int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 void __user *buffer, size_t *lenp, loff_t *ppos)
2358{
2359 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2360 NULL,NULL);
2361}
2362
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002363/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002364 * Taint values can only be increased
2365 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002366 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002367static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002368 void __user *buffer, size_t *lenp, loff_t *ppos)
2369{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002370 struct ctl_table t;
2371 unsigned long tmptaint = get_taint();
2372 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002373
Bastian Blank91fcd412007-04-23 14:41:14 -07002374 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002375 return -EPERM;
2376
Andi Kleen25ddbb12008-10-15 22:01:41 -07002377 t = *table;
2378 t.data = &tmptaint;
2379 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2380 if (err < 0)
2381 return err;
2382
2383 if (write) {
2384 /*
2385 * Poor man's atomic or. Not worth adding a primitive
2386 * to everyone's atomic.h for this
2387 */
2388 int i;
2389 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2390 if ((tmptaint >> i) & 1)
2391 add_taint(i);
2392 }
2393 }
2394
2395 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002396}
2397
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398struct do_proc_dointvec_minmax_conv_param {
2399 int *min;
2400 int *max;
2401};
2402
2403static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2404 int *valp,
2405 int write, void *data)
2406{
2407 struct do_proc_dointvec_minmax_conv_param *param = data;
2408 if (write) {
2409 int val = *negp ? -*lvalp : *lvalp;
2410 if ((param->min && *param->min > val) ||
2411 (param->max && *param->max < val))
2412 return -EINVAL;
2413 *valp = val;
2414 } else {
2415 int val = *valp;
2416 if (val < 0) {
2417 *negp = -1;
2418 *lvalp = (unsigned long)-val;
2419 } else {
2420 *negp = 0;
2421 *lvalp = (unsigned long)val;
2422 }
2423 }
2424 return 0;
2425}
2426
2427/**
2428 * proc_dointvec_minmax - read a vector of integers with min/max values
2429 * @table: the sysctl table
2430 * @write: %TRUE if this is a write to the sysctl file
2431 * @filp: the file structure
2432 * @buffer: the user buffer
2433 * @lenp: the size of the user buffer
2434 * @ppos: file position
2435 *
2436 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2437 * values from/to the user buffer, treated as an ASCII string.
2438 *
2439 * This routine will ensure the values are within the range specified by
2440 * table->extra1 (min) and table->extra2 (max).
2441 *
2442 * Returns 0 on success.
2443 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002444int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 void __user *buffer, size_t *lenp, loff_t *ppos)
2446{
2447 struct do_proc_dointvec_minmax_conv_param param = {
2448 .min = (int *) table->extra1,
2449 .max = (int *) table->extra2,
2450 };
2451 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2452 do_proc_dointvec_minmax_conv, &param);
2453}
2454
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002455static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 struct file *filp,
2457 void __user *buffer,
2458 size_t *lenp, loff_t *ppos,
2459 unsigned long convmul,
2460 unsigned long convdiv)
2461{
2462#define TMPBUFLEN 21
2463 unsigned long *i, *min, *max, val;
2464 int vleft, first=1, neg;
2465 size_t len, left;
2466 char buf[TMPBUFLEN], *p;
2467 char __user *s = buffer;
2468
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002469 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 (*ppos && !write)) {
2471 *lenp = 0;
2472 return 0;
2473 }
2474
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002475 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 min = (unsigned long *) table->extra1;
2477 max = (unsigned long *) table->extra2;
2478 vleft = table->maxlen / sizeof(unsigned long);
2479 left = *lenp;
2480
2481 for (; left && vleft--; i++, min++, max++, first=0) {
2482 if (write) {
2483 while (left) {
2484 char c;
2485 if (get_user(c, s))
2486 return -EFAULT;
2487 if (!isspace(c))
2488 break;
2489 left--;
2490 s++;
2491 }
2492 if (!left)
2493 break;
2494 neg = 0;
2495 len = left;
2496 if (len > TMPBUFLEN-1)
2497 len = TMPBUFLEN-1;
2498 if (copy_from_user(buf, s, len))
2499 return -EFAULT;
2500 buf[len] = 0;
2501 p = buf;
2502 if (*p == '-' && left > 1) {
2503 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002504 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 }
2506 if (*p < '0' || *p > '9')
2507 break;
2508 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2509 len = p-buf;
2510 if ((len < left) && *p && !isspace(*p))
2511 break;
2512 if (neg)
2513 val = -val;
2514 s += len;
2515 left -= len;
2516
2517 if(neg)
2518 continue;
2519 if ((min && val < *min) || (max && val > *max))
2520 continue;
2521 *i = val;
2522 } else {
2523 p = buf;
2524 if (!first)
2525 *p++ = '\t';
2526 sprintf(p, "%lu", convdiv * (*i) / convmul);
2527 len = strlen(buf);
2528 if (len > left)
2529 len = left;
2530 if(copy_to_user(s, buf, len))
2531 return -EFAULT;
2532 left -= len;
2533 s += len;
2534 }
2535 }
2536
2537 if (!write && !first && left) {
2538 if(put_user('\n', s))
2539 return -EFAULT;
2540 left--, s++;
2541 }
2542 if (write) {
2543 while (left) {
2544 char c;
2545 if (get_user(c, s++))
2546 return -EFAULT;
2547 if (!isspace(c))
2548 break;
2549 left--;
2550 }
2551 }
2552 if (write && first)
2553 return -EINVAL;
2554 *lenp -= left;
2555 *ppos += *lenp;
2556 return 0;
2557#undef TMPBUFLEN
2558}
2559
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002560static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002561 struct file *filp,
2562 void __user *buffer,
2563 size_t *lenp, loff_t *ppos,
2564 unsigned long convmul,
2565 unsigned long convdiv)
2566{
2567 return __do_proc_doulongvec_minmax(table->data, table, write,
2568 filp, buffer, lenp, ppos, convmul, convdiv);
2569}
2570
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571/**
2572 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2573 * @table: the sysctl table
2574 * @write: %TRUE if this is a write to the sysctl file
2575 * @filp: the file structure
2576 * @buffer: the user buffer
2577 * @lenp: the size of the user buffer
2578 * @ppos: file position
2579 *
2580 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2581 * values from/to the user buffer, treated as an ASCII string.
2582 *
2583 * This routine will ensure the values are within the range specified by
2584 * table->extra1 (min) and table->extra2 (max).
2585 *
2586 * Returns 0 on success.
2587 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002588int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 void __user *buffer, size_t *lenp, loff_t *ppos)
2590{
2591 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2592}
2593
2594/**
2595 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2596 * @table: the sysctl table
2597 * @write: %TRUE if this is a write to the sysctl file
2598 * @filp: the file structure
2599 * @buffer: the user buffer
2600 * @lenp: the size of the user buffer
2601 * @ppos: file position
2602 *
2603 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2604 * values from/to the user buffer, treated as an ASCII string. The values
2605 * are treated as milliseconds, and converted to jiffies when they are stored.
2606 *
2607 * This routine will ensure the values are within the range specified by
2608 * table->extra1 (min) and table->extra2 (max).
2609 *
2610 * Returns 0 on success.
2611 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002612int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 struct file *filp,
2614 void __user *buffer,
2615 size_t *lenp, loff_t *ppos)
2616{
2617 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2618 lenp, ppos, HZ, 1000l);
2619}
2620
2621
2622static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2623 int *valp,
2624 int write, void *data)
2625{
2626 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002627 if (*lvalp > LONG_MAX / HZ)
2628 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2630 } else {
2631 int val = *valp;
2632 unsigned long lval;
2633 if (val < 0) {
2634 *negp = -1;
2635 lval = (unsigned long)-val;
2636 } else {
2637 *negp = 0;
2638 lval = (unsigned long)val;
2639 }
2640 *lvalp = lval / HZ;
2641 }
2642 return 0;
2643}
2644
2645static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2646 int *valp,
2647 int write, void *data)
2648{
2649 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002650 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2651 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2653 } else {
2654 int val = *valp;
2655 unsigned long lval;
2656 if (val < 0) {
2657 *negp = -1;
2658 lval = (unsigned long)-val;
2659 } else {
2660 *negp = 0;
2661 lval = (unsigned long)val;
2662 }
2663 *lvalp = jiffies_to_clock_t(lval);
2664 }
2665 return 0;
2666}
2667
2668static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2669 int *valp,
2670 int write, void *data)
2671{
2672 if (write) {
2673 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2674 } else {
2675 int val = *valp;
2676 unsigned long lval;
2677 if (val < 0) {
2678 *negp = -1;
2679 lval = (unsigned long)-val;
2680 } else {
2681 *negp = 0;
2682 lval = (unsigned long)val;
2683 }
2684 *lvalp = jiffies_to_msecs(lval);
2685 }
2686 return 0;
2687}
2688
2689/**
2690 * proc_dointvec_jiffies - read a vector of integers as seconds
2691 * @table: the sysctl table
2692 * @write: %TRUE if this is a write to the sysctl file
2693 * @filp: the file structure
2694 * @buffer: the user buffer
2695 * @lenp: the size of the user buffer
2696 * @ppos: file position
2697 *
2698 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2699 * values from/to the user buffer, treated as an ASCII string.
2700 * The values read are assumed to be in seconds, and are converted into
2701 * jiffies.
2702 *
2703 * Returns 0 on success.
2704 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002705int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 void __user *buffer, size_t *lenp, loff_t *ppos)
2707{
2708 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2709 do_proc_dointvec_jiffies_conv,NULL);
2710}
2711
2712/**
2713 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2714 * @table: the sysctl table
2715 * @write: %TRUE if this is a write to the sysctl file
2716 * @filp: the file structure
2717 * @buffer: the user buffer
2718 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002719 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 *
2721 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2722 * values from/to the user buffer, treated as an ASCII string.
2723 * The values read are assumed to be in 1/USER_HZ seconds, and
2724 * are converted into jiffies.
2725 *
2726 * Returns 0 on success.
2727 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002728int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 void __user *buffer, size_t *lenp, loff_t *ppos)
2730{
2731 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2732 do_proc_dointvec_userhz_jiffies_conv,NULL);
2733}
2734
2735/**
2736 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2737 * @table: the sysctl table
2738 * @write: %TRUE if this is a write to the sysctl file
2739 * @filp: the file structure
2740 * @buffer: the user buffer
2741 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002742 * @ppos: file position
2743 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 *
2745 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2746 * values from/to the user buffer, treated as an ASCII string.
2747 * The values read are assumed to be in 1/1000 seconds, and
2748 * are converted into jiffies.
2749 *
2750 * Returns 0 on success.
2751 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002752int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 void __user *buffer, size_t *lenp, loff_t *ppos)
2754{
2755 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2756 do_proc_dointvec_ms_jiffies_conv, NULL);
2757}
2758
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002759static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002760 void __user *buffer, size_t *lenp, loff_t *ppos)
2761{
2762 struct pid *new_pid;
2763 pid_t tmp;
2764 int r;
2765
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002766 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002767
2768 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2769 lenp, ppos, NULL, NULL);
2770 if (r || !write)
2771 return r;
2772
2773 new_pid = find_get_pid(tmp);
2774 if (!new_pid)
2775 return -ESRCH;
2776
2777 put_pid(xchg(&cad_pid, new_pid));
2778 return 0;
2779}
2780
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781#else /* CONFIG_PROC_FS */
2782
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002783int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 void __user *buffer, size_t *lenp, loff_t *ppos)
2785{
2786 return -ENOSYS;
2787}
2788
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002789int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 void __user *buffer, size_t *lenp, loff_t *ppos)
2791{
2792 return -ENOSYS;
2793}
2794
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002795int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 void __user *buffer, size_t *lenp, loff_t *ppos)
2797{
2798 return -ENOSYS;
2799}
2800
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002801int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 void __user *buffer, size_t *lenp, loff_t *ppos)
2803{
2804 return -ENOSYS;
2805}
2806
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002807int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 void __user *buffer, size_t *lenp, loff_t *ppos)
2809{
2810 return -ENOSYS;
2811}
2812
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002813int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 void __user *buffer, size_t *lenp, loff_t *ppos)
2815{
2816 return -ENOSYS;
2817}
2818
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002819int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 void __user *buffer, size_t *lenp, loff_t *ppos)
2821{
2822 return -ENOSYS;
2823}
2824
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002825int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 struct file *filp,
2827 void __user *buffer,
2828 size_t *lenp, loff_t *ppos)
2829{
2830 return -ENOSYS;
2831}
2832
2833
2834#endif /* CONFIG_PROC_FS */
2835
2836
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002837#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838/*
2839 * General sysctl support routines
2840 */
2841
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002842/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002843int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002844 void __user *oldval, size_t __user *oldlenp,
2845 void __user *newval, size_t newlen)
2846{
2847 size_t len;
2848
2849 /* Get out of I don't have a variable */
2850 if (!table->data || !table->maxlen)
2851 return -ENOTDIR;
2852
2853 if (oldval && oldlenp) {
2854 if (get_user(len, oldlenp))
2855 return -EFAULT;
2856 if (len) {
2857 if (len > table->maxlen)
2858 len = table->maxlen;
2859 if (copy_to_user(oldval, table->data, len))
2860 return -EFAULT;
2861 if (put_user(len, oldlenp))
2862 return -EFAULT;
2863 }
2864 }
2865
2866 if (newval && newlen) {
2867 if (newlen > table->maxlen)
2868 newlen = table->maxlen;
2869
2870 if (copy_from_user(table->data, newval, newlen))
2871 return -EFAULT;
2872 }
2873 return 1;
2874}
2875
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002877int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002879 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 if (!table->data || !table->maxlen)
2882 return -ENOTDIR;
2883
2884 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002885 size_t bufsize;
2886 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002888 if (bufsize) {
2889 size_t len = strlen(table->data), copied;
2890
2891 /* This shouldn't trigger for a well-formed sysctl */
2892 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002894
2895 /* Copy up to a max of bufsize-1 bytes of the string */
2896 copied = (len >= bufsize) ? bufsize - 1 : len;
2897
2898 if (copy_to_user(oldval, table->data, copied) ||
2899 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002901 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 return -EFAULT;
2903 }
2904 }
2905 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002906 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 if (len > table->maxlen)
2908 len = table->maxlen;
2909 if(copy_from_user(table->data, newval, len))
2910 return -EFAULT;
2911 if (len == table->maxlen)
2912 len--;
2913 ((char *) table->data)[len] = 0;
2914 }
Yi Yang82c9df82005-12-30 16:37:10 +08002915 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916}
2917
2918/*
2919 * This function makes sure that all of the integers in the vector
2920 * are between the minimum and maximum values given in the arrays
2921 * table->extra1 and table->extra2, respectively.
2922 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002923int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002925 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926{
2927
2928 if (newval && newlen) {
2929 int __user *vec = (int __user *) newval;
2930 int *min = (int *) table->extra1;
2931 int *max = (int *) table->extra2;
2932 size_t length;
2933 int i;
2934
2935 if (newlen % sizeof(int) != 0)
2936 return -EINVAL;
2937
2938 if (!table->extra1 && !table->extra2)
2939 return 0;
2940
2941 if (newlen > table->maxlen)
2942 newlen = table->maxlen;
2943 length = newlen / sizeof(int);
2944
2945 for (i = 0; i < length; i++) {
2946 int value;
2947 if (get_user(value, vec + i))
2948 return -EFAULT;
2949 if (min && value < min[i])
2950 return -EINVAL;
2951 if (max && value > max[i])
2952 return -EINVAL;
2953 }
2954 }
2955 return 0;
2956}
2957
2958/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002959int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002961 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002963 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002965
2966 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002968 if (olen) {
2969 int val;
2970
2971 if (olen < sizeof(int))
2972 return -EINVAL;
2973
2974 val = *(int *)(table->data) / HZ;
2975 if (put_user(val, (int __user *)oldval))
2976 return -EFAULT;
2977 if (put_user(sizeof(int), oldlenp))
2978 return -EFAULT;
2979 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 }
2981 if (newval && newlen) {
2982 int new;
2983 if (newlen != sizeof(int))
2984 return -EINVAL;
2985 if (get_user(new, (int __user *)newval))
2986 return -EFAULT;
2987 *(int *)(table->data) = new*HZ;
2988 }
2989 return 1;
2990}
2991
2992/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002993int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002995 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002997 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002999
3000 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003002 if (olen) {
3003 int val;
3004
3005 if (olen < sizeof(int))
3006 return -EINVAL;
3007
3008 val = jiffies_to_msecs(*(int *)(table->data));
3009 if (put_user(val, (int __user *)oldval))
3010 return -EFAULT;
3011 if (put_user(sizeof(int), oldlenp))
3012 return -EFAULT;
3013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 }
3015 if (newval && newlen) {
3016 int new;
3017 if (newlen != sizeof(int))
3018 return -EINVAL;
3019 if (get_user(new, (int __user *)newval))
3020 return -EFAULT;
3021 *(int *)(table->data) = msecs_to_jiffies(new);
3022 }
3023 return 1;
3024}
3025
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003026
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003027
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003028#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
3030
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003031SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003033 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003034 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003035
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003036 if (copy_from_user(&tmp, args, sizeof(tmp)))
3037 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003038
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003039 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003040
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003041 /* If no error reading the parameters then just -ENOSYS ... */
3042 if (!error)
3043 error = -ENOSYS;
3044
3045 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046}
3047
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003048int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003049 void __user *oldval, size_t __user *oldlenp,
3050 void __user *newval, size_t newlen)
3051{
3052 return -ENOSYS;
3053}
3054
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003055int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003057 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058{
3059 return -ENOSYS;
3060}
3061
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003062int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003064 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065{
3066 return -ENOSYS;
3067}
3068
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003069int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003071 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072{
3073 return -ENOSYS;
3074}
3075
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003076int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003078 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079{
3080 return -ENOSYS;
3081}
3082
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003083#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003085static int deprecated_sysctl_warning(struct __sysctl_args *args)
3086{
3087 static int msg_count;
3088 int name[CTL_MAXNAME];
3089 int i;
3090
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003091 /* Check args->nlen. */
3092 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3093 return -ENOTDIR;
3094
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003095 /* Read in the sysctl name for better debug message logging */
3096 for (i = 0; i < args->nlen; i++)
3097 if (get_user(name[i], args->name + i))
3098 return -EFAULT;
3099
3100 /* Ignore accesses to kernel.version */
3101 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3102 return 0;
3103
3104 if (msg_count < 5) {
3105 msg_count++;
3106 printk(KERN_INFO
3107 "warning: process `%s' used the deprecated sysctl "
3108 "system call with ", current->comm);
3109 for (i = 0; i < args->nlen; i++)
3110 printk("%d.", name[i]);
3111 printk("\n");
3112 }
3113 return 0;
3114}
3115
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116/*
3117 * No sense putting this after each symbol definition, twice,
3118 * exception granted :-)
3119 */
3120EXPORT_SYMBOL(proc_dointvec);
3121EXPORT_SYMBOL(proc_dointvec_jiffies);
3122EXPORT_SYMBOL(proc_dointvec_minmax);
3123EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3124EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3125EXPORT_SYMBOL(proc_dostring);
3126EXPORT_SYMBOL(proc_doulongvec_minmax);
3127EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3128EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003129EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130EXPORT_SYMBOL(sysctl_intvec);
3131EXPORT_SYMBOL(sysctl_jiffies);
3132EXPORT_SYMBOL(sysctl_ms_jiffies);
3133EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003134EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135EXPORT_SYMBOL(unregister_sysctl_table);