blob: c25e67e19af7b402ee57201f6f41491933feca78 [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>
Randy.Dunlapc59ede72006-01-11 12:17:46 -080027#include <linux/capability.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>
40#include <linux/security.h>
41#include <linux/initrd.h>
42#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Pavel Machekc255d842006-02-20 18:27:58 -080046#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
Andi Kleen29cbc782006-09-30 01:47:55 +020053#ifdef CONFIG_X86
54#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010055#include <asm/stacktrace.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020056#endif
57
Eric W. Biederman7058cb02007-10-18 03:05:58 -070058static int deprecated_sysctl_warning(struct __sysctl_args *args);
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#if defined(CONFIG_SYSCTL)
61
62/* External variables not in a header file. */
63extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070064extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065extern int sysctl_overcommit_memory;
66extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070067extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070068extern int sysctl_oom_kill_allocating_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070071extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int pid_max;
74extern int min_free_kbytes;
75extern int printk_ratelimit_jiffies;
76extern int printk_ratelimit_burst;
77extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080078extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080079extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020080extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070081extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070082extern int sysctl_stat_interval;
Peter Zijlstrabdf4c482007-07-19 01:48:15 -070083extern int audit_argv_kb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070085/* Constants used for minimum and maximum */
86#ifdef CONFIG_DETECT_SOFTLOCKUP
87static int one = 1;
88static int sixty = 60;
89#endif
90
91#ifdef CONFIG_MMU
92static int two = 2;
93#endif
94
95static int zero;
96static int one_hundred = 100;
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
99static int maxolduid = 65535;
100static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800101static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103static int ngroups_max = NGROUPS_MAX;
104
105#ifdef CONFIG_KMOD
106extern char modprobe_path[];
107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#ifdef CONFIG_CHR_DEV_SG
109extern int sg_big_buff;
110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112#ifdef __sparc__
113extern char reboot_command [];
114extern int stop_a_enabled;
115extern int scons_pwroff;
116#endif
117
118#ifdef __hppa__
119extern int pwrsw_enabled;
120extern int unaligned_enabled;
121#endif
122
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800123#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#ifdef CONFIG_MATHEMU
125extern int sysctl_ieee_emulation_warnings;
126#endif
127extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700128extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#endif
130
131extern int sysctl_hz_timer;
132
133#ifdef CONFIG_BSD_PROCESS_ACCT
134extern int acct_parm[];
135#endif
136
Jes Sorensend2b176e2006-02-28 09:42:23 -0800137#ifdef CONFIG_IA64
138extern int no_unaligned_warning;
139#endif
140
Ingo Molnar23f78d42006-06-27 02:54:53 -0700141#ifdef CONFIG_RT_MUTEXES
142extern int max_lock_depth;
143#endif
144
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700145#ifdef CONFIG_SYSCTL_SYSCALL
146static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700147 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700148#endif
149
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800150
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700151#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700152static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700153 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700154static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800155 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700156#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700157
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static struct ctl_table root_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static struct ctl_table_header root_table_header =
160 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
161
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700162static struct ctl_table kern_table[];
163static struct ctl_table vm_table[];
164static struct ctl_table fs_table[];
165static struct ctl_table debug_table[];
166static struct ctl_table dev_table[];
167extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700168#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700169extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400170#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
173int sysctl_legacy_va_layout;
174#endif
175
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700176extern int prove_locking;
177extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179/* The default sysctl tables: */
180
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700181static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 {
183 .ctl_name = CTL_KERN,
184 .procname = "kernel",
185 .mode = 0555,
186 .child = kern_table,
187 },
188 {
189 .ctl_name = CTL_VM,
190 .procname = "vm",
191 .mode = 0555,
192 .child = vm_table,
193 },
194#ifdef CONFIG_NET
195 {
196 .ctl_name = CTL_NET,
197 .procname = "net",
198 .mode = 0555,
199 .child = net_table,
200 },
201#endif
202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
207 },
208 {
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
213 },
214 {
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
219 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700220/*
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 { .ctl_name = 0 }
225};
226
Ingo Molnar77e54a12007-07-09 18:52:00 +0200227#ifdef CONFIG_SCHED_DEBUG
228static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
229static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
230static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
231static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
232#endif
233
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700234static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#ifdef CONFIG_SCHED_DEBUG
236 {
237 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200238 .procname = "sched_nr_latency",
239 .data = &sysctl_sched_nr_latency,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240 .maxlen = sizeof(unsigned int),
241 .mode = 0644,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200242 .proc_handler = &proc_dointvec,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243 },
244 {
245 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200246 .procname = "sched_latency_ns",
247 .data = &sysctl_sched_latency,
248 .maxlen = sizeof(unsigned int),
249 .mode = 0644,
250 .proc_handler = &proc_dointvec_minmax,
251 .strategy = &sysctl_intvec,
252 .extra1 = &min_sched_granularity_ns,
253 .extra2 = &max_sched_granularity_ns,
254 },
255 {
256 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200257 .procname = "sched_wakeup_granularity_ns",
258 .data = &sysctl_sched_wakeup_granularity,
259 .maxlen = sizeof(unsigned int),
260 .mode = 0644,
261 .proc_handler = &proc_dointvec_minmax,
262 .strategy = &sysctl_intvec,
263 .extra1 = &min_wakeup_granularity_ns,
264 .extra2 = &max_wakeup_granularity_ns,
265 },
266 {
267 .ctl_name = CTL_UNNUMBERED,
268 .procname = "sched_batch_wakeup_granularity_ns",
269 .data = &sysctl_sched_batch_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,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200279 .procname = "sched_child_runs_first",
280 .data = &sysctl_sched_child_runs_first,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec,
284 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200285 {
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_features",
288 .data = &sysctl_sched_features,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = &proc_dointvec,
292 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200293 {
294 .ctl_name = CTL_UNNUMBERED,
295 .procname = "sched_migration_cost",
296 .data = &sysctl_sched_migration_cost,
297 .maxlen = sizeof(unsigned int),
298 .mode = 0644,
299 .proc_handler = &proc_dointvec,
300 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200301#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200302 {
303 .ctl_name = CTL_UNNUMBERED,
304 .procname = "sched_compat_yield",
305 .data = &sysctl_sched_compat_yield,
306 .maxlen = sizeof(unsigned int),
307 .mode = 0644,
308 .proc_handler = &proc_dointvec,
309 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700310#ifdef CONFIG_PROVE_LOCKING
311 {
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "prove_locking",
314 .data = &prove_locking,
315 .maxlen = sizeof(int),
316 .mode = 0644,
317 .proc_handler = &proc_dointvec,
318 },
319#endif
320#ifdef CONFIG_LOCK_STAT
321 {
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "lock_stat",
324 .data = &lock_stat,
325 .maxlen = sizeof(int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
328 },
329#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200330 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 .ctl_name = KERN_PANIC,
332 .procname = "panic",
333 .data = &panic_timeout,
334 .maxlen = sizeof(int),
335 .mode = 0644,
336 .proc_handler = &proc_dointvec,
337 },
338 {
339 .ctl_name = KERN_CORE_USES_PID,
340 .procname = "core_uses_pid",
341 .data = &core_uses_pid,
342 .maxlen = sizeof(int),
343 .mode = 0644,
344 .proc_handler = &proc_dointvec,
345 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700346#ifdef CONFIG_AUDITSYSCALL
347 {
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "audit_argv_kb",
350 .data = &audit_argv_kb,
351 .maxlen = sizeof(int),
352 .mode = 0644,
353 .proc_handler = &proc_dointvec,
354 },
355#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 {
357 .ctl_name = KERN_CORE_PATTERN,
358 .procname = "core_pattern",
359 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700360 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 .mode = 0644,
362 .proc_handler = &proc_dostring,
363 .strategy = &sysctl_string,
364 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800365#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 .procname = "tainted",
368 .data = &tainted,
369 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800370 .mode = 0644,
371 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800373#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 .procname = "cap-bound",
376 .data = &cap_bset,
377 .maxlen = sizeof(kernel_cap_t),
378 .mode = 0600,
379 .proc_handler = &proc_dointvec_bset,
380 },
381#ifdef CONFIG_BLK_DEV_INITRD
382 {
383 .ctl_name = KERN_REALROOTDEV,
384 .procname = "real-root-dev",
385 .data = &real_root_dev,
386 .maxlen = sizeof(int),
387 .mode = 0644,
388 .proc_handler = &proc_dointvec,
389 },
390#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700391 {
392 .ctl_name = CTL_UNNUMBERED,
393 .procname = "print-fatal-signals",
394 .data = &print_fatal_signals,
395 .maxlen = sizeof(int),
396 .mode = 0644,
397 .proc_handler = &proc_dointvec,
398 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#ifdef __sparc__
400 {
401 .ctl_name = KERN_SPARC_REBOOT,
402 .procname = "reboot-cmd",
403 .data = reboot_command,
404 .maxlen = 256,
405 .mode = 0644,
406 .proc_handler = &proc_dostring,
407 .strategy = &sysctl_string,
408 },
409 {
410 .ctl_name = KERN_SPARC_STOP_A,
411 .procname = "stop-a",
412 .data = &stop_a_enabled,
413 .maxlen = sizeof (int),
414 .mode = 0644,
415 .proc_handler = &proc_dointvec,
416 },
417 {
418 .ctl_name = KERN_SPARC_SCONS_PWROFF,
419 .procname = "scons-poweroff",
420 .data = &scons_pwroff,
421 .maxlen = sizeof (int),
422 .mode = 0644,
423 .proc_handler = &proc_dointvec,
424 },
425#endif
426#ifdef __hppa__
427 {
428 .ctl_name = KERN_HPPA_PWRSW,
429 .procname = "soft-power",
430 .data = &pwrsw_enabled,
431 .maxlen = sizeof (int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
435 {
436 .ctl_name = KERN_HPPA_UNALIGNED,
437 .procname = "unaligned-trap",
438 .data = &unaligned_enabled,
439 .maxlen = sizeof (int),
440 .mode = 0644,
441 .proc_handler = &proc_dointvec,
442 },
443#endif
444 {
445 .ctl_name = KERN_CTLALTDEL,
446 .procname = "ctrl-alt-del",
447 .data = &C_A_D,
448 .maxlen = sizeof(int),
449 .mode = 0644,
450 .proc_handler = &proc_dointvec,
451 },
452 {
453 .ctl_name = KERN_PRINTK,
454 .procname = "printk",
455 .data = &console_loglevel,
456 .maxlen = 4*sizeof(int),
457 .mode = 0644,
458 .proc_handler = &proc_dointvec,
459 },
460#ifdef CONFIG_KMOD
461 {
462 .ctl_name = KERN_MODPROBE,
463 .procname = "modprobe",
464 .data = &modprobe_path,
465 .maxlen = KMOD_PATH_LEN,
466 .mode = 0644,
467 .proc_handler = &proc_dostring,
468 .strategy = &sysctl_string,
469 },
470#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700471#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 {
473 .ctl_name = KERN_HOTPLUG,
474 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100475 .data = &uevent_helper,
476 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .mode = 0644,
478 .proc_handler = &proc_dostring,
479 .strategy = &sysctl_string,
480 },
481#endif
482#ifdef CONFIG_CHR_DEV_SG
483 {
484 .ctl_name = KERN_SG_BIG_BUFF,
485 .procname = "sg-big-buff",
486 .data = &sg_big_buff,
487 .maxlen = sizeof (int),
488 .mode = 0444,
489 .proc_handler = &proc_dointvec,
490 },
491#endif
492#ifdef CONFIG_BSD_PROCESS_ACCT
493 {
494 .ctl_name = KERN_ACCT,
495 .procname = "acct",
496 .data = &acct_parm,
497 .maxlen = 3*sizeof(int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
500 },
501#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502#ifdef CONFIG_MAGIC_SYSRQ
503 {
504 .ctl_name = KERN_SYSRQ,
505 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800506 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .maxlen = sizeof (int),
508 .mode = 0644,
509 .proc_handler = &proc_dointvec,
510 },
511#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700512#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700515 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 .maxlen = sizeof (int),
517 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700518 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700520#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 {
522 .ctl_name = KERN_MAX_THREADS,
523 .procname = "threads-max",
524 .data = &max_threads,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = &proc_dointvec,
528 },
529 {
530 .ctl_name = KERN_RANDOM,
531 .procname = "random",
532 .mode = 0555,
533 .child = random_table,
534 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 {
536 .ctl_name = KERN_OVERFLOWUID,
537 .procname = "overflowuid",
538 .data = &overflowuid,
539 .maxlen = sizeof(int),
540 .mode = 0644,
541 .proc_handler = &proc_dointvec_minmax,
542 .strategy = &sysctl_intvec,
543 .extra1 = &minolduid,
544 .extra2 = &maxolduid,
545 },
546 {
547 .ctl_name = KERN_OVERFLOWGID,
548 .procname = "overflowgid",
549 .data = &overflowgid,
550 .maxlen = sizeof(int),
551 .mode = 0644,
552 .proc_handler = &proc_dointvec_minmax,
553 .strategy = &sysctl_intvec,
554 .extra1 = &minolduid,
555 .extra2 = &maxolduid,
556 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800557#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#ifdef CONFIG_MATHEMU
559 {
560 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
561 .procname = "ieee_emulation_warnings",
562 .data = &sysctl_ieee_emulation_warnings,
563 .maxlen = sizeof(int),
564 .mode = 0644,
565 .proc_handler = &proc_dointvec,
566 },
567#endif
568#ifdef CONFIG_NO_IDLE_HZ
569 {
570 .ctl_name = KERN_HZ_TIMER,
571 .procname = "hz_timer",
572 .data = &sysctl_hz_timer,
573 .maxlen = sizeof(int),
574 .mode = 0644,
575 .proc_handler = &proc_dointvec,
576 },
577#endif
578 {
579 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
580 .procname = "userprocess_debug",
581 .data = &sysctl_userprocess_debug,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = &proc_dointvec,
585 },
586#endif
587 {
588 .ctl_name = KERN_PIDMAX,
589 .procname = "pid_max",
590 .data = &pid_max,
591 .maxlen = sizeof (int),
592 .mode = 0644,
593 .proc_handler = &proc_dointvec_minmax,
594 .strategy = sysctl_intvec,
595 .extra1 = &pid_max_min,
596 .extra2 = &pid_max_max,
597 },
598 {
599 .ctl_name = KERN_PANIC_ON_OOPS,
600 .procname = "panic_on_oops",
601 .data = &panic_on_oops,
602 .maxlen = sizeof(int),
603 .mode = 0644,
604 .proc_handler = &proc_dointvec,
605 },
606 {
607 .ctl_name = KERN_PRINTK_RATELIMIT,
608 .procname = "printk_ratelimit",
609 .data = &printk_ratelimit_jiffies,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = &proc_dointvec_jiffies,
613 .strategy = &sysctl_jiffies,
614 },
615 {
616 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
617 .procname = "printk_ratelimit_burst",
618 .data = &printk_ratelimit_burst,
619 .maxlen = sizeof(int),
620 .mode = 0644,
621 .proc_handler = &proc_dointvec,
622 },
623 {
624 .ctl_name = KERN_NGROUPS_MAX,
625 .procname = "ngroups_max",
626 .data = &ngroups_max,
627 .maxlen = sizeof (int),
628 .mode = 0444,
629 .proc_handler = &proc_dointvec,
630 },
631#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
632 {
633 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
634 .procname = "unknown_nmi_panic",
635 .data = &unknown_nmi_panic,
636 .maxlen = sizeof (int),
637 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200638 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 },
Don Zickus407984f2006-09-26 10:52:27 +0200640 {
Don Zickus407984f2006-09-26 10:52:27 +0200641 .procname = "nmi_watchdog",
642 .data = &nmi_watchdog_enabled,
643 .maxlen = sizeof (int),
644 .mode = 0644,
645 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 },
647#endif
648#if defined(CONFIG_X86)
649 {
Don Zickus8da5add2006-09-26 10:52:27 +0200650 .ctl_name = KERN_PANIC_ON_NMI,
651 .procname = "panic_on_unrecovered_nmi",
652 .data = &panic_on_unrecovered_nmi,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec,
656 },
657 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .ctl_name = KERN_BOOTLOADER_TYPE,
659 .procname = "bootloader_type",
660 .data = &bootloader_type,
661 .maxlen = sizeof (int),
662 .mode = 0444,
663 .proc_handler = &proc_dointvec,
664 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100665 {
666 .ctl_name = CTL_UNNUMBERED,
667 .procname = "kstack_depth_to_print",
668 .data = &kstack_depth_to_print,
669 .maxlen = sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800674#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 {
676 .ctl_name = KERN_RANDOMIZE,
677 .procname = "randomize_va_space",
678 .data = &randomize_va_space,
679 .maxlen = sizeof(int),
680 .mode = 0644,
681 .proc_handler = &proc_dointvec,
682 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800683#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800684#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700685 {
686 .ctl_name = KERN_SPIN_RETRY,
687 .procname = "spin_retry",
688 .data = &spin_retry,
689 .maxlen = sizeof (int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec,
692 },
693#endif
Len Brown673d5b42007-07-28 03:33:16 -0400694#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800695 {
Pavel Machekc255d842006-02-20 18:27:58 -0800696 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700697 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800698 .maxlen = sizeof (unsigned long),
699 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800700 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800701 },
702#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800703#ifdef CONFIG_IA64
704 {
705 .ctl_name = KERN_IA64_UNALIGNED,
706 .procname = "ignore-unaligned-usertrap",
707 .data = &no_unaligned_warning,
708 .maxlen = sizeof (int),
709 .mode = 0644,
710 .proc_handler = &proc_dointvec,
711 },
712#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700713#ifdef CONFIG_DETECT_SOFTLOCKUP
714 {
715 .ctl_name = CTL_UNNUMBERED,
716 .procname = "softlockup_thresh",
717 .data = &softlockup_thresh,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec_minmax,
721 .strategy = &sysctl_intvec,
722 .extra1 = &one,
723 .extra2 = &sixty,
724 },
725#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200726#ifdef CONFIG_COMPAT
727 {
728 .ctl_name = KERN_COMPAT_LOG,
729 .procname = "compat-log",
730 .data = &compat_log,
731 .maxlen = sizeof (int),
732 .mode = 0644,
733 .proc_handler = &proc_dointvec,
734 },
735#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700736#ifdef CONFIG_RT_MUTEXES
737 {
738 .ctl_name = KERN_MAX_LOCK_DEPTH,
739 .procname = "max_lock_depth",
740 .data = &max_lock_depth,
741 .maxlen = sizeof(int),
742 .mode = 0644,
743 .proc_handler = &proc_dointvec,
744 },
745#endif
Kees Cook5096add2007-05-08 00:26:04 -0700746#ifdef CONFIG_PROC_FS
747 {
748 .ctl_name = CTL_UNNUMBERED,
749 .procname = "maps_protect",
750 .data = &maps_protect,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = &proc_dointvec,
754 },
755#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700756 {
757 .ctl_name = CTL_UNNUMBERED,
758 .procname = "poweroff_cmd",
759 .data = &poweroff_cmd,
760 .maxlen = POWEROFF_CMD_PATH_LEN,
761 .mode = 0644,
762 .proc_handler = &proc_dostring,
763 .strategy = &sysctl_string,
764 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700765/*
766 * NOTE: do not add new entries to this table unless you have read
767 * Documentation/sysctl/ctl_unnumbered.txt
768 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 { .ctl_name = 0 }
770};
771
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700772static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 {
774 .ctl_name = VM_OVERCOMMIT_MEMORY,
775 .procname = "overcommit_memory",
776 .data = &sysctl_overcommit_memory,
777 .maxlen = sizeof(sysctl_overcommit_memory),
778 .mode = 0644,
779 .proc_handler = &proc_dointvec,
780 },
781 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700782 .ctl_name = VM_PANIC_ON_OOM,
783 .procname = "panic_on_oom",
784 .data = &sysctl_panic_on_oom,
785 .maxlen = sizeof(sysctl_panic_on_oom),
786 .mode = 0644,
787 .proc_handler = &proc_dointvec,
788 },
789 {
David Rientjesfe071d72007-10-16 23:25:56 -0700790 .ctl_name = CTL_UNNUMBERED,
791 .procname = "oom_kill_allocating_task",
792 .data = &sysctl_oom_kill_allocating_task,
793 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
794 .mode = 0644,
795 .proc_handler = &proc_dointvec,
796 },
797 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 .ctl_name = VM_OVERCOMMIT_RATIO,
799 .procname = "overcommit_ratio",
800 .data = &sysctl_overcommit_ratio,
801 .maxlen = sizeof(sysctl_overcommit_ratio),
802 .mode = 0644,
803 .proc_handler = &proc_dointvec,
804 },
805 {
806 .ctl_name = VM_PAGE_CLUSTER,
807 .procname = "page-cluster",
808 .data = &page_cluster,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = &proc_dointvec,
812 },
813 {
814 .ctl_name = VM_DIRTY_BACKGROUND,
815 .procname = "dirty_background_ratio",
816 .data = &dirty_background_ratio,
817 .maxlen = sizeof(dirty_background_ratio),
818 .mode = 0644,
819 .proc_handler = &proc_dointvec_minmax,
820 .strategy = &sysctl_intvec,
821 .extra1 = &zero,
822 .extra2 = &one_hundred,
823 },
824 {
825 .ctl_name = VM_DIRTY_RATIO,
826 .procname = "dirty_ratio",
827 .data = &vm_dirty_ratio,
828 .maxlen = sizeof(vm_dirty_ratio),
829 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700830 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 .strategy = &sysctl_intvec,
832 .extra1 = &zero,
833 .extra2 = &one_hundred,
834 },
835 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800837 .data = &dirty_writeback_interval,
838 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 .mode = 0644,
840 .proc_handler = &dirty_writeback_centisecs_handler,
841 },
842 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800844 .data = &dirty_expire_interval,
845 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800847 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 },
849 {
850 .ctl_name = VM_NR_PDFLUSH_THREADS,
851 .procname = "nr_pdflush_threads",
852 .data = &nr_pdflush_threads,
853 .maxlen = sizeof nr_pdflush_threads,
854 .mode = 0444 /* read-only*/,
855 .proc_handler = &proc_dointvec,
856 },
857 {
858 .ctl_name = VM_SWAPPINESS,
859 .procname = "swappiness",
860 .data = &vm_swappiness,
861 .maxlen = sizeof(vm_swappiness),
862 .mode = 0644,
863 .proc_handler = &proc_dointvec_minmax,
864 .strategy = &sysctl_intvec,
865 .extra1 = &zero,
866 .extra2 = &one_hundred,
867 },
868#ifdef CONFIG_HUGETLB_PAGE
869 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 .procname = "nr_hugepages",
871 .data = &max_huge_pages,
872 .maxlen = sizeof(unsigned long),
873 .mode = 0644,
874 .proc_handler = &hugetlb_sysctl_handler,
875 .extra1 = (void *)&hugetlb_zero,
876 .extra2 = (void *)&hugetlb_infinity,
877 },
878 {
879 .ctl_name = VM_HUGETLB_GROUP,
880 .procname = "hugetlb_shm_group",
881 .data = &sysctl_hugetlb_shm_group,
882 .maxlen = sizeof(gid_t),
883 .mode = 0644,
884 .proc_handler = &proc_dointvec,
885 },
Mel Gorman396faf02007-07-17 04:03:13 -0700886 {
887 .ctl_name = CTL_UNNUMBERED,
888 .procname = "hugepages_treat_as_movable",
889 .data = &hugepages_treat_as_movable,
890 .maxlen = sizeof(int),
891 .mode = 0644,
892 .proc_handler = &hugetlb_treat_movable_handler,
893 },
Adam Litke54f9f802007-10-16 01:26:20 -0700894 {
895 .ctl_name = CTL_UNNUMBERED,
896 .procname = "hugetlb_dynamic_pool",
897 .data = &hugetlb_dynamic_pool,
898 .maxlen = sizeof(hugetlb_dynamic_pool),
899 .mode = 0644,
900 .proc_handler = &proc_dointvec,
901 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902#endif
903 {
904 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
905 .procname = "lowmem_reserve_ratio",
906 .data = &sysctl_lowmem_reserve_ratio,
907 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
908 .mode = 0644,
909 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
910 .strategy = &sysctl_intvec,
911 },
912 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800913 .ctl_name = VM_DROP_PAGECACHE,
914 .procname = "drop_caches",
915 .data = &sysctl_drop_caches,
916 .maxlen = sizeof(int),
917 .mode = 0644,
918 .proc_handler = drop_caches_sysctl_handler,
919 .strategy = &sysctl_intvec,
920 },
921 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 .ctl_name = VM_MIN_FREE_KBYTES,
923 .procname = "min_free_kbytes",
924 .data = &min_free_kbytes,
925 .maxlen = sizeof(min_free_kbytes),
926 .mode = 0644,
927 .proc_handler = &min_free_kbytes_sysctl_handler,
928 .strategy = &sysctl_intvec,
929 .extra1 = &zero,
930 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800931 {
932 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
933 .procname = "percpu_pagelist_fraction",
934 .data = &percpu_pagelist_fraction,
935 .maxlen = sizeof(percpu_pagelist_fraction),
936 .mode = 0644,
937 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
938 .strategy = &sysctl_intvec,
939 .extra1 = &min_percpu_pagelist_fract,
940 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941#ifdef CONFIG_MMU
942 {
943 .ctl_name = VM_MAX_MAP_COUNT,
944 .procname = "max_map_count",
945 .data = &sysctl_max_map_count,
946 .maxlen = sizeof(sysctl_max_map_count),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec
949 },
950#endif
951 {
952 .ctl_name = VM_LAPTOP_MODE,
953 .procname = "laptop_mode",
954 .data = &laptop_mode,
955 .maxlen = sizeof(laptop_mode),
956 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800957 .proc_handler = &proc_dointvec_jiffies,
958 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 },
960 {
961 .ctl_name = VM_BLOCK_DUMP,
962 .procname = "block_dump",
963 .data = &block_dump,
964 .maxlen = sizeof(block_dump),
965 .mode = 0644,
966 .proc_handler = &proc_dointvec,
967 .strategy = &sysctl_intvec,
968 .extra1 = &zero,
969 },
970 {
971 .ctl_name = VM_VFS_CACHE_PRESSURE,
972 .procname = "vfs_cache_pressure",
973 .data = &sysctl_vfs_cache_pressure,
974 .maxlen = sizeof(sysctl_vfs_cache_pressure),
975 .mode = 0644,
976 .proc_handler = &proc_dointvec,
977 .strategy = &sysctl_intvec,
978 .extra1 = &zero,
979 },
980#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
981 {
982 .ctl_name = VM_LEGACY_VA_LAYOUT,
983 .procname = "legacy_va_layout",
984 .data = &sysctl_legacy_va_layout,
985 .maxlen = sizeof(sysctl_legacy_va_layout),
986 .mode = 0644,
987 .proc_handler = &proc_dointvec,
988 .strategy = &sysctl_intvec,
989 .extra1 = &zero,
990 },
991#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800992#ifdef CONFIG_NUMA
993 {
994 .ctl_name = VM_ZONE_RECLAIM_MODE,
995 .procname = "zone_reclaim_mode",
996 .data = &zone_reclaim_mode,
997 .maxlen = sizeof(zone_reclaim_mode),
998 .mode = 0644,
999 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001000 .strategy = &sysctl_intvec,
1001 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001002 },
Christoph Lameter96146342006-07-03 00:24:13 -07001003 {
1004 .ctl_name = VM_MIN_UNMAPPED,
1005 .procname = "min_unmapped_ratio",
1006 .data = &sysctl_min_unmapped_ratio,
1007 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1008 .mode = 0644,
1009 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1010 .strategy = &sysctl_intvec,
1011 .extra1 = &zero,
1012 .extra2 = &one_hundred,
1013 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001014 {
1015 .ctl_name = VM_MIN_SLAB,
1016 .procname = "min_slab_ratio",
1017 .data = &sysctl_min_slab_ratio,
1018 .maxlen = sizeof(sysctl_min_slab_ratio),
1019 .mode = 0644,
1020 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1021 .strategy = &sysctl_intvec,
1022 .extra1 = &zero,
1023 .extra2 = &one_hundred,
1024 },
Christoph Lameter17436602006-01-18 17:42:32 -08001025#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001026#ifdef CONFIG_SMP
1027 {
1028 .ctl_name = CTL_UNNUMBERED,
1029 .procname = "stat_interval",
1030 .data = &sysctl_stat_interval,
1031 .maxlen = sizeof(sysctl_stat_interval),
1032 .mode = 0644,
1033 .proc_handler = &proc_dointvec_jiffies,
1034 .strategy = &sysctl_jiffies,
1035 },
1036#endif
Eric Parised032182007-06-28 15:55:21 -04001037#ifdef CONFIG_SECURITY
1038 {
1039 .ctl_name = CTL_UNNUMBERED,
1040 .procname = "mmap_min_addr",
1041 .data = &mmap_min_addr,
1042 .maxlen = sizeof(unsigned long),
1043 .mode = 0644,
1044 .proc_handler = &proc_doulongvec_minmax,
1045 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001046#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001047#ifdef CONFIG_NUMA
1048 {
1049 .ctl_name = CTL_UNNUMBERED,
1050 .procname = "numa_zonelist_order",
1051 .data = &numa_zonelist_order,
1052 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1053 .mode = 0644,
1054 .proc_handler = &numa_zonelist_order_handler,
1055 .strategy = &sysctl_string,
1056 },
1057#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001058#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001059 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001060 {
1061 .ctl_name = VM_VDSO_ENABLED,
1062 .procname = "vdso_enabled",
1063 .data = &vdso_enabled,
1064 .maxlen = sizeof(vdso_enabled),
1065 .mode = 0644,
1066 .proc_handler = &proc_dointvec,
1067 .strategy = &sysctl_intvec,
1068 .extra1 = &zero,
1069 },
1070#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001071/*
1072 * NOTE: do not add new entries to this table unless you have read
1073 * Documentation/sysctl/ctl_unnumbered.txt
1074 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 { .ctl_name = 0 }
1076};
1077
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001078#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001079static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001080 { .ctl_name = 0 }
1081};
1082#endif
1083
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001084static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 {
1086 .ctl_name = FS_NRINODE,
1087 .procname = "inode-nr",
1088 .data = &inodes_stat,
1089 .maxlen = 2*sizeof(int),
1090 .mode = 0444,
1091 .proc_handler = &proc_dointvec,
1092 },
1093 {
1094 .ctl_name = FS_STATINODE,
1095 .procname = "inode-state",
1096 .data = &inodes_stat,
1097 .maxlen = 7*sizeof(int),
1098 .mode = 0444,
1099 .proc_handler = &proc_dointvec,
1100 },
1101 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 .procname = "file-nr",
1103 .data = &files_stat,
1104 .maxlen = 3*sizeof(int),
1105 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001106 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 },
1108 {
1109 .ctl_name = FS_MAXFILE,
1110 .procname = "file-max",
1111 .data = &files_stat.max_files,
1112 .maxlen = sizeof(int),
1113 .mode = 0644,
1114 .proc_handler = &proc_dointvec,
1115 },
1116 {
1117 .ctl_name = FS_DENTRY,
1118 .procname = "dentry-state",
1119 .data = &dentry_stat,
1120 .maxlen = 6*sizeof(int),
1121 .mode = 0444,
1122 .proc_handler = &proc_dointvec,
1123 },
1124 {
1125 .ctl_name = FS_OVERFLOWUID,
1126 .procname = "overflowuid",
1127 .data = &fs_overflowuid,
1128 .maxlen = sizeof(int),
1129 .mode = 0644,
1130 .proc_handler = &proc_dointvec_minmax,
1131 .strategy = &sysctl_intvec,
1132 .extra1 = &minolduid,
1133 .extra2 = &maxolduid,
1134 },
1135 {
1136 .ctl_name = FS_OVERFLOWGID,
1137 .procname = "overflowgid",
1138 .data = &fs_overflowgid,
1139 .maxlen = sizeof(int),
1140 .mode = 0644,
1141 .proc_handler = &proc_dointvec_minmax,
1142 .strategy = &sysctl_intvec,
1143 .extra1 = &minolduid,
1144 .extra2 = &maxolduid,
1145 },
1146 {
1147 .ctl_name = FS_LEASES,
1148 .procname = "leases-enable",
1149 .data = &leases_enable,
1150 .maxlen = sizeof(int),
1151 .mode = 0644,
1152 .proc_handler = &proc_dointvec,
1153 },
1154#ifdef CONFIG_DNOTIFY
1155 {
1156 .ctl_name = FS_DIR_NOTIFY,
1157 .procname = "dir-notify-enable",
1158 .data = &dir_notify_enable,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = &proc_dointvec,
1162 },
1163#endif
1164#ifdef CONFIG_MMU
1165 {
1166 .ctl_name = FS_LEASE_TIME,
1167 .procname = "lease-break-time",
1168 .data = &lease_break_time,
1169 .maxlen = sizeof(int),
1170 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001171 .proc_handler = &proc_dointvec_minmax,
1172 .strategy = &sysctl_intvec,
1173 .extra1 = &zero,
1174 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 },
1176 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 .procname = "aio-nr",
1178 .data = &aio_nr,
1179 .maxlen = sizeof(aio_nr),
1180 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001181 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 },
1183 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 .procname = "aio-max-nr",
1185 .data = &aio_max_nr,
1186 .maxlen = sizeof(aio_max_nr),
1187 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001188 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001190#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001191 {
1192 .ctl_name = FS_INOTIFY,
1193 .procname = "inotify",
1194 .mode = 0555,
1195 .child = inotify_table,
1196 },
1197#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001199 {
1200 .ctl_name = KERN_SETUID_DUMPABLE,
1201 .procname = "suid_dumpable",
1202 .data = &suid_dumpable,
1203 .maxlen = sizeof(int),
1204 .mode = 0644,
1205 .proc_handler = &proc_dointvec,
1206 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001207#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1208 {
1209 .ctl_name = CTL_UNNUMBERED,
1210 .procname = "binfmt_misc",
1211 .mode = 0555,
1212 .child = binfmt_misc_table,
1213 },
1214#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001215/*
1216 * NOTE: do not add new entries to this table unless you have read
1217 * Documentation/sysctl/ctl_unnumbered.txt
1218 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 { .ctl_name = 0 }
1220};
1221
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001222static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001223#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001224 {
1225 .ctl_name = CTL_UNNUMBERED,
1226 .procname = "exception-trace",
1227 .data = &show_unhandled_signals,
1228 .maxlen = sizeof(int),
1229 .mode = 0644,
1230 .proc_handler = proc_dointvec
1231 },
1232#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 { .ctl_name = 0 }
1234};
1235
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001236static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001238};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Al Viro330d57f2005-11-04 10:18:40 +00001240static DEFINE_SPINLOCK(sysctl_lock);
1241
1242/* called under sysctl_lock */
1243static int use_table(struct ctl_table_header *p)
1244{
1245 if (unlikely(p->unregistering))
1246 return 0;
1247 p->used++;
1248 return 1;
1249}
1250
1251/* called under sysctl_lock */
1252static void unuse_table(struct ctl_table_header *p)
1253{
1254 if (!--p->used)
1255 if (unlikely(p->unregistering))
1256 complete(p->unregistering);
1257}
1258
1259/* called under sysctl_lock, will reacquire if has to wait */
1260static void start_unregistering(struct ctl_table_header *p)
1261{
1262 /*
1263 * if p->used is 0, nobody will ever touch that entry again;
1264 * we'll eliminate all paths to it before dropping sysctl_lock
1265 */
1266 if (unlikely(p->used)) {
1267 struct completion wait;
1268 init_completion(&wait);
1269 p->unregistering = &wait;
1270 spin_unlock(&sysctl_lock);
1271 wait_for_completion(&wait);
1272 spin_lock(&sysctl_lock);
1273 }
1274 /*
1275 * do not remove from the list until nobody holds it; walking the
1276 * list in do_sysctl() relies on that.
1277 */
1278 list_del_init(&p->ctl_entry);
1279}
1280
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001281void sysctl_head_finish(struct ctl_table_header *head)
1282{
1283 if (!head)
1284 return;
1285 spin_lock(&sysctl_lock);
1286 unuse_table(head);
1287 spin_unlock(&sysctl_lock);
1288}
1289
1290struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1291{
1292 struct ctl_table_header *head;
1293 struct list_head *tmp;
1294 spin_lock(&sysctl_lock);
1295 if (prev) {
1296 tmp = &prev->ctl_entry;
1297 unuse_table(prev);
1298 goto next;
1299 }
1300 tmp = &root_table_header.ctl_entry;
1301 for (;;) {
1302 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1303
1304 if (!use_table(head))
1305 goto next;
1306 spin_unlock(&sysctl_lock);
1307 return head;
1308 next:
1309 tmp = tmp->next;
1310 if (tmp == &root_table_header.ctl_entry)
1311 break;
1312 }
1313 spin_unlock(&sysctl_lock);
1314 return NULL;
1315}
1316
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001317#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1319 void __user *newval, size_t newlen)
1320{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001321 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001322 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
1324 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1325 return -ENOTDIR;
1326 if (oldval) {
1327 int old_len;
1328 if (!oldlenp || get_user(old_len, oldlenp))
1329 return -EFAULT;
1330 }
Al Viro330d57f2005-11-04 10:18:40 +00001331
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001332 for (head = sysctl_head_next(NULL); head;
1333 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001334 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001335 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001336 if (error != -ENOTDIR) {
1337 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001338 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001339 }
1340 }
Al Viro330d57f2005-11-04 10:18:40 +00001341 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343
1344asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1345{
1346 struct __sysctl_args tmp;
1347 int error;
1348
1349 if (copy_from_user(&tmp, args, sizeof(tmp)))
1350 return -EFAULT;
1351
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001352 error = deprecated_sysctl_warning(&tmp);
1353 if (error)
1354 goto out;
1355
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 lock_kernel();
1357 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1358 tmp.newval, tmp.newlen);
1359 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001360out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 return error;
1362}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001363#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001366 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 * some sysctl variables are readonly even to root.
1368 */
1369
1370static int test_perm(int mode, int op)
1371{
1372 if (!current->euid)
1373 mode >>= 6;
1374 else if (in_egroup_p(0))
1375 mode >>= 3;
1376 if ((mode & op & 0007) == op)
1377 return 0;
1378 return -EACCES;
1379}
1380
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001381int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382{
1383 int error;
1384 error = security_sysctl(table, op);
1385 if (error)
1386 return error;
1387 return test_perm(table->mode, op);
1388}
1389
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001390#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391static int parse_table(int __user *name, int nlen,
1392 void __user *oldval, size_t __user *oldlenp,
1393 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001394 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395{
1396 int n;
1397repeat:
1398 if (!nlen)
1399 return -ENOTDIR;
1400 if (get_user(n, name))
1401 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001402 for ( ; table->ctl_name || table->procname; table++) {
1403 if (!table->ctl_name)
1404 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001405 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 int error;
1407 if (table->child) {
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001408 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 name++;
1411 nlen--;
1412 table = table->child;
1413 goto repeat;
1414 }
1415 error = do_sysctl_strategy(table, name, nlen,
1416 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001417 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 return error;
1419 }
1420 }
1421 return -ENOTDIR;
1422}
1423
1424/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001425int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 int __user *name, int nlen,
1427 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001428 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429{
1430 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432 if (oldval)
1433 op |= 004;
1434 if (newval)
1435 op |= 002;
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001436 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 return -EPERM;
1438
1439 if (table->strategy) {
1440 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001441 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 if (rc < 0)
1443 return rc;
1444 if (rc > 0)
1445 return 0;
1446 }
1447
1448 /* If there is no strategy routine, or if the strategy returns
1449 * zero, proceed with automatic r/w */
1450 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001451 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1452 newval, newlen);
1453 if (rc < 0)
1454 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 }
1456 return 0;
1457}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001458#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001460static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1461{
1462 for (; table->ctl_name || table->procname; table++) {
1463 table->parent = parent;
1464 if (table->child)
1465 sysctl_set_parent(table, table->child);
1466 }
1467}
1468
1469static __init int sysctl_init(void)
1470{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001471 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001472 sysctl_set_parent(NULL, root_table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001473 err = sysctl_check_table(root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001474 return 0;
1475}
1476
1477core_initcall(sysctl_init);
1478
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479/**
1480 * register_sysctl_table - register a sysctl hierarchy
1481 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 *
1483 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1484 * array. An entry with a ctl_name of 0 terminates the table.
1485 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001486 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 *
1488 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1489 * must be unique within that level of sysctl
1490 *
1491 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1492 * enter a sysctl file
1493 *
1494 * data - a pointer to data for use by proc_handler
1495 *
1496 * maxlen - the maximum size in bytes of the data
1497 *
1498 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1499 *
1500 * child - a pointer to the child sysctl table if this entry is a directory, or
1501 * %NULL.
1502 *
1503 * proc_handler - the text handler routine (described below)
1504 *
1505 * strategy - the strategy routine (described below)
1506 *
1507 * de - for internal use by the sysctl routines
1508 *
1509 * extra1, extra2 - extra pointers usable by the proc handler routines
1510 *
1511 * Leaf nodes in the sysctl tree will be represented by a single file
1512 * under /proc; non-leaf nodes will be represented by directories.
1513 *
1514 * sysctl(2) can automatically manage read and write requests through
1515 * the sysctl table. The data and maxlen fields of the ctl_table
1516 * struct enable minimal validation of the values being written to be
1517 * performed, and the mode field allows minimal authentication.
1518 *
1519 * More sophisticated management can be enabled by the provision of a
1520 * strategy routine with the table entry. This will be called before
1521 * any automatic read or write of the data is performed.
1522 *
1523 * The strategy routine may return
1524 *
1525 * < 0 - Error occurred (error is passed to user process)
1526 *
1527 * 0 - OK - proceed with automatic read or write.
1528 *
1529 * > 0 - OK - read or write has been done by the strategy routine, so
1530 * return immediately.
1531 *
1532 * There must be a proc_handler routine for any terminal nodes
1533 * mirrored under /proc/sys (non-terminals are handled by a built-in
1534 * directory handler). Several default handlers are available to
1535 * cover common cases -
1536 *
1537 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1538 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1539 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1540 *
1541 * It is the handler's job to read the input buffer from user memory
1542 * and process it. The handler should return 0 on success.
1543 *
1544 * This routine returns %NULL on a failure to register, and a pointer
1545 * to the table header on success.
1546 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001547struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
1549 struct ctl_table_header *tmp;
1550 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1551 if (!tmp)
1552 return NULL;
1553 tmp->ctl_table = table;
1554 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001555 tmp->used = 0;
1556 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001557 sysctl_set_parent(NULL, table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001558 if (sysctl_check_table(tmp->ctl_table)) {
1559 kfree(tmp);
1560 return NULL;
1561 }
Al Viro330d57f2005-11-04 10:18:40 +00001562 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001563 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001564 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 return tmp;
1566}
1567
1568/**
1569 * unregister_sysctl_table - unregister a sysctl table hierarchy
1570 * @header: the header returned from register_sysctl_table
1571 *
1572 * Unregisters the sysctl table and all children. proc entries may not
1573 * actually be removed until they are no longer used by anyone.
1574 */
1575void unregister_sysctl_table(struct ctl_table_header * header)
1576{
Al Viro330d57f2005-11-04 10:18:40 +00001577 might_sleep();
1578 spin_lock(&sysctl_lock);
1579 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001580 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 kfree(header);
1582}
1583
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001584#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001585struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001586{
1587 return NULL;
1588}
1589
1590void unregister_sysctl_table(struct ctl_table_header * table)
1591{
1592}
1593
1594#endif /* CONFIG_SYSCTL */
1595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596/*
1597 * /proc/sys support
1598 */
1599
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001600#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001602static int _proc_do_string(void* data, int maxlen, int write,
1603 struct file *filp, void __user *buffer,
1604 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001605{
1606 size_t len;
1607 char __user *p;
1608 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001609
1610 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001611 *lenp = 0;
1612 return 0;
1613 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001614
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001615 if (write) {
1616 len = 0;
1617 p = buffer;
1618 while (len < *lenp) {
1619 if (get_user(c, p++))
1620 return -EFAULT;
1621 if (c == 0 || c == '\n')
1622 break;
1623 len++;
1624 }
1625 if (len >= maxlen)
1626 len = maxlen-1;
1627 if(copy_from_user(data, buffer, len))
1628 return -EFAULT;
1629 ((char *) data)[len] = 0;
1630 *ppos += *lenp;
1631 } else {
1632 len = strlen(data);
1633 if (len > maxlen)
1634 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001635
1636 if (*ppos > len) {
1637 *lenp = 0;
1638 return 0;
1639 }
1640
1641 data += *ppos;
1642 len -= *ppos;
1643
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001644 if (len > *lenp)
1645 len = *lenp;
1646 if (len)
1647 if(copy_to_user(buffer, data, len))
1648 return -EFAULT;
1649 if (len < *lenp) {
1650 if(put_user('\n', ((char __user *) buffer) + len))
1651 return -EFAULT;
1652 len++;
1653 }
1654 *lenp = len;
1655 *ppos += len;
1656 }
1657 return 0;
1658}
1659
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660/**
1661 * proc_dostring - read a string sysctl
1662 * @table: the sysctl table
1663 * @write: %TRUE if this is a write to the sysctl file
1664 * @filp: the file structure
1665 * @buffer: the user buffer
1666 * @lenp: the size of the user buffer
1667 * @ppos: file position
1668 *
1669 * Reads/writes a string from/to the user buffer. If the kernel
1670 * buffer provided is not large enough to hold the string, the
1671 * string is truncated. The copied string is %NULL-terminated.
1672 * If the string is being read by the user process, it is copied
1673 * and a newline '\n' is added. It is truncated if the buffer is
1674 * not large enough.
1675 *
1676 * Returns 0 on success.
1677 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001678int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 void __user *buffer, size_t *lenp, loff_t *ppos)
1680{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001681 return _proc_do_string(table->data, table->maxlen, write, filp,
1682 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683}
1684
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1687 int *valp,
1688 int write, void *data)
1689{
1690 if (write) {
1691 *valp = *negp ? -*lvalp : *lvalp;
1692 } else {
1693 int val = *valp;
1694 if (val < 0) {
1695 *negp = -1;
1696 *lvalp = (unsigned long)-val;
1697 } else {
1698 *negp = 0;
1699 *lvalp = (unsigned long)val;
1700 }
1701 }
1702 return 0;
1703}
1704
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001705static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001706 int write, struct file *filp, void __user *buffer,
1707 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1709 int write, void *data),
1710 void *data)
1711{
1712#define TMPBUFLEN 21
1713 int *i, vleft, first=1, neg, val;
1714 unsigned long lval;
1715 size_t left, len;
1716
1717 char buf[TMPBUFLEN], *p;
1718 char __user *s = buffer;
1719
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001720 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 (*ppos && !write)) {
1722 *lenp = 0;
1723 return 0;
1724 }
1725
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001726 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 vleft = table->maxlen / sizeof(*i);
1728 left = *lenp;
1729
1730 if (!conv)
1731 conv = do_proc_dointvec_conv;
1732
1733 for (; left && vleft--; i++, first=0) {
1734 if (write) {
1735 while (left) {
1736 char c;
1737 if (get_user(c, s))
1738 return -EFAULT;
1739 if (!isspace(c))
1740 break;
1741 left--;
1742 s++;
1743 }
1744 if (!left)
1745 break;
1746 neg = 0;
1747 len = left;
1748 if (len > sizeof(buf) - 1)
1749 len = sizeof(buf) - 1;
1750 if (copy_from_user(buf, s, len))
1751 return -EFAULT;
1752 buf[len] = 0;
1753 p = buf;
1754 if (*p == '-' && left > 1) {
1755 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001756 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 }
1758 if (*p < '0' || *p > '9')
1759 break;
1760
1761 lval = simple_strtoul(p, &p, 0);
1762
1763 len = p-buf;
1764 if ((len < left) && *p && !isspace(*p))
1765 break;
1766 if (neg)
1767 val = -val;
1768 s += len;
1769 left -= len;
1770
1771 if (conv(&neg, &lval, i, 1, data))
1772 break;
1773 } else {
1774 p = buf;
1775 if (!first)
1776 *p++ = '\t';
1777
1778 if (conv(&neg, &lval, i, 0, data))
1779 break;
1780
1781 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1782 len = strlen(buf);
1783 if (len > left)
1784 len = left;
1785 if(copy_to_user(s, buf, len))
1786 return -EFAULT;
1787 left -= len;
1788 s += len;
1789 }
1790 }
1791
1792 if (!write && !first && left) {
1793 if(put_user('\n', s))
1794 return -EFAULT;
1795 left--, s++;
1796 }
1797 if (write) {
1798 while (left) {
1799 char c;
1800 if (get_user(c, s++))
1801 return -EFAULT;
1802 if (!isspace(c))
1803 break;
1804 left--;
1805 }
1806 }
1807 if (write && first)
1808 return -EINVAL;
1809 *lenp -= left;
1810 *ppos += *lenp;
1811 return 0;
1812#undef TMPBUFLEN
1813}
1814
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001815static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001816 void __user *buffer, size_t *lenp, loff_t *ppos,
1817 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1818 int write, void *data),
1819 void *data)
1820{
1821 return __do_proc_dointvec(table->data, table, write, filp,
1822 buffer, lenp, ppos, conv, data);
1823}
1824
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825/**
1826 * proc_dointvec - read a vector of integers
1827 * @table: the sysctl table
1828 * @write: %TRUE if this is a write to the sysctl file
1829 * @filp: the file structure
1830 * @buffer: the user buffer
1831 * @lenp: the size of the user buffer
1832 * @ppos: file position
1833 *
1834 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1835 * values from/to the user buffer, treated as an ASCII string.
1836 *
1837 * Returns 0 on success.
1838 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001839int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 void __user *buffer, size_t *lenp, loff_t *ppos)
1841{
1842 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1843 NULL,NULL);
1844}
1845
1846#define OP_SET 0
1847#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001848#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
1850static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1851 int *valp,
1852 int write, void *data)
1853{
1854 int op = *(int *)data;
1855 if (write) {
1856 int val = *negp ? -*lvalp : *lvalp;
1857 switch(op) {
1858 case OP_SET: *valp = val; break;
1859 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001860 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 }
1862 } else {
1863 int val = *valp;
1864 if (val < 0) {
1865 *negp = -1;
1866 *lvalp = (unsigned long)-val;
1867 } else {
1868 *negp = 0;
1869 *lvalp = (unsigned long)val;
1870 }
1871 }
1872 return 0;
1873}
1874
1875/*
1876 * init may raise the set.
1877 */
1878
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001879int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 void __user *buffer, size_t *lenp, loff_t *ppos)
1881{
1882 int op;
1883
Eric Paris6ff1b442007-02-10 01:43:19 -08001884 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 return -EPERM;
1886 }
1887
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001888 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1890 do_proc_dointvec_bset_conv,&op);
1891}
1892
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001893/*
1894 * Taint values can only be increased
1895 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001896static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001897 void __user *buffer, size_t *lenp, loff_t *ppos)
1898{
1899 int op;
1900
Bastian Blank91fcd412007-04-23 14:41:14 -07001901 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001902 return -EPERM;
1903
1904 op = OP_OR;
1905 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1906 do_proc_dointvec_bset_conv,&op);
1907}
1908
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909struct do_proc_dointvec_minmax_conv_param {
1910 int *min;
1911 int *max;
1912};
1913
1914static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1915 int *valp,
1916 int write, void *data)
1917{
1918 struct do_proc_dointvec_minmax_conv_param *param = data;
1919 if (write) {
1920 int val = *negp ? -*lvalp : *lvalp;
1921 if ((param->min && *param->min > val) ||
1922 (param->max && *param->max < val))
1923 return -EINVAL;
1924 *valp = val;
1925 } else {
1926 int val = *valp;
1927 if (val < 0) {
1928 *negp = -1;
1929 *lvalp = (unsigned long)-val;
1930 } else {
1931 *negp = 0;
1932 *lvalp = (unsigned long)val;
1933 }
1934 }
1935 return 0;
1936}
1937
1938/**
1939 * proc_dointvec_minmax - read a vector of integers with min/max values
1940 * @table: the sysctl table
1941 * @write: %TRUE if this is a write to the sysctl file
1942 * @filp: the file structure
1943 * @buffer: the user buffer
1944 * @lenp: the size of the user buffer
1945 * @ppos: file position
1946 *
1947 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1948 * values from/to the user buffer, treated as an ASCII string.
1949 *
1950 * This routine will ensure the values are within the range specified by
1951 * table->extra1 (min) and table->extra2 (max).
1952 *
1953 * Returns 0 on success.
1954 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001955int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 void __user *buffer, size_t *lenp, loff_t *ppos)
1957{
1958 struct do_proc_dointvec_minmax_conv_param param = {
1959 .min = (int *) table->extra1,
1960 .max = (int *) table->extra2,
1961 };
1962 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1963 do_proc_dointvec_minmax_conv, &param);
1964}
1965
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001966static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 struct file *filp,
1968 void __user *buffer,
1969 size_t *lenp, loff_t *ppos,
1970 unsigned long convmul,
1971 unsigned long convdiv)
1972{
1973#define TMPBUFLEN 21
1974 unsigned long *i, *min, *max, val;
1975 int vleft, first=1, neg;
1976 size_t len, left;
1977 char buf[TMPBUFLEN], *p;
1978 char __user *s = buffer;
1979
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001980 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 (*ppos && !write)) {
1982 *lenp = 0;
1983 return 0;
1984 }
1985
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001986 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 min = (unsigned long *) table->extra1;
1988 max = (unsigned long *) table->extra2;
1989 vleft = table->maxlen / sizeof(unsigned long);
1990 left = *lenp;
1991
1992 for (; left && vleft--; i++, min++, max++, first=0) {
1993 if (write) {
1994 while (left) {
1995 char c;
1996 if (get_user(c, s))
1997 return -EFAULT;
1998 if (!isspace(c))
1999 break;
2000 left--;
2001 s++;
2002 }
2003 if (!left)
2004 break;
2005 neg = 0;
2006 len = left;
2007 if (len > TMPBUFLEN-1)
2008 len = TMPBUFLEN-1;
2009 if (copy_from_user(buf, s, len))
2010 return -EFAULT;
2011 buf[len] = 0;
2012 p = buf;
2013 if (*p == '-' && left > 1) {
2014 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002015 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 }
2017 if (*p < '0' || *p > '9')
2018 break;
2019 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2020 len = p-buf;
2021 if ((len < left) && *p && !isspace(*p))
2022 break;
2023 if (neg)
2024 val = -val;
2025 s += len;
2026 left -= len;
2027
2028 if(neg)
2029 continue;
2030 if ((min && val < *min) || (max && val > *max))
2031 continue;
2032 *i = val;
2033 } else {
2034 p = buf;
2035 if (!first)
2036 *p++ = '\t';
2037 sprintf(p, "%lu", convdiv * (*i) / convmul);
2038 len = strlen(buf);
2039 if (len > left)
2040 len = left;
2041 if(copy_to_user(s, buf, len))
2042 return -EFAULT;
2043 left -= len;
2044 s += len;
2045 }
2046 }
2047
2048 if (!write && !first && left) {
2049 if(put_user('\n', s))
2050 return -EFAULT;
2051 left--, s++;
2052 }
2053 if (write) {
2054 while (left) {
2055 char c;
2056 if (get_user(c, s++))
2057 return -EFAULT;
2058 if (!isspace(c))
2059 break;
2060 left--;
2061 }
2062 }
2063 if (write && first)
2064 return -EINVAL;
2065 *lenp -= left;
2066 *ppos += *lenp;
2067 return 0;
2068#undef TMPBUFLEN
2069}
2070
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002071static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002072 struct file *filp,
2073 void __user *buffer,
2074 size_t *lenp, loff_t *ppos,
2075 unsigned long convmul,
2076 unsigned long convdiv)
2077{
2078 return __do_proc_doulongvec_minmax(table->data, table, write,
2079 filp, buffer, lenp, ppos, convmul, convdiv);
2080}
2081
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082/**
2083 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2084 * @table: the sysctl table
2085 * @write: %TRUE if this is a write to the sysctl file
2086 * @filp: the file structure
2087 * @buffer: the user buffer
2088 * @lenp: the size of the user buffer
2089 * @ppos: file position
2090 *
2091 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2092 * values from/to the user buffer, treated as an ASCII string.
2093 *
2094 * This routine will ensure the values are within the range specified by
2095 * table->extra1 (min) and table->extra2 (max).
2096 *
2097 * Returns 0 on success.
2098 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002099int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 void __user *buffer, size_t *lenp, loff_t *ppos)
2101{
2102 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2103}
2104
2105/**
2106 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2107 * @table: the sysctl table
2108 * @write: %TRUE if this is a write to the sysctl file
2109 * @filp: the file structure
2110 * @buffer: the user buffer
2111 * @lenp: the size of the user buffer
2112 * @ppos: file position
2113 *
2114 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2115 * values from/to the user buffer, treated as an ASCII string. The values
2116 * are treated as milliseconds, and converted to jiffies when they are stored.
2117 *
2118 * This routine will ensure the values are within the range specified by
2119 * table->extra1 (min) and table->extra2 (max).
2120 *
2121 * Returns 0 on success.
2122 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002123int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 struct file *filp,
2125 void __user *buffer,
2126 size_t *lenp, loff_t *ppos)
2127{
2128 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2129 lenp, ppos, HZ, 1000l);
2130}
2131
2132
2133static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2134 int *valp,
2135 int write, void *data)
2136{
2137 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002138 if (*lvalp > LONG_MAX / HZ)
2139 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2141 } else {
2142 int val = *valp;
2143 unsigned long lval;
2144 if (val < 0) {
2145 *negp = -1;
2146 lval = (unsigned long)-val;
2147 } else {
2148 *negp = 0;
2149 lval = (unsigned long)val;
2150 }
2151 *lvalp = lval / HZ;
2152 }
2153 return 0;
2154}
2155
2156static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2157 int *valp,
2158 int write, void *data)
2159{
2160 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002161 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2162 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2164 } else {
2165 int val = *valp;
2166 unsigned long lval;
2167 if (val < 0) {
2168 *negp = -1;
2169 lval = (unsigned long)-val;
2170 } else {
2171 *negp = 0;
2172 lval = (unsigned long)val;
2173 }
2174 *lvalp = jiffies_to_clock_t(lval);
2175 }
2176 return 0;
2177}
2178
2179static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2180 int *valp,
2181 int write, void *data)
2182{
2183 if (write) {
2184 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2185 } else {
2186 int val = *valp;
2187 unsigned long lval;
2188 if (val < 0) {
2189 *negp = -1;
2190 lval = (unsigned long)-val;
2191 } else {
2192 *negp = 0;
2193 lval = (unsigned long)val;
2194 }
2195 *lvalp = jiffies_to_msecs(lval);
2196 }
2197 return 0;
2198}
2199
2200/**
2201 * proc_dointvec_jiffies - read a vector of integers as seconds
2202 * @table: the sysctl table
2203 * @write: %TRUE if this is a write to the sysctl file
2204 * @filp: the file structure
2205 * @buffer: the user buffer
2206 * @lenp: the size of the user buffer
2207 * @ppos: file position
2208 *
2209 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2210 * values from/to the user buffer, treated as an ASCII string.
2211 * The values read are assumed to be in seconds, and are converted into
2212 * jiffies.
2213 *
2214 * Returns 0 on success.
2215 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002216int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 void __user *buffer, size_t *lenp, loff_t *ppos)
2218{
2219 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2220 do_proc_dointvec_jiffies_conv,NULL);
2221}
2222
2223/**
2224 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2225 * @table: the sysctl table
2226 * @write: %TRUE if this is a write to the sysctl file
2227 * @filp: the file structure
2228 * @buffer: the user buffer
2229 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002230 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 *
2232 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2233 * values from/to the user buffer, treated as an ASCII string.
2234 * The values read are assumed to be in 1/USER_HZ seconds, and
2235 * are converted into jiffies.
2236 *
2237 * Returns 0 on success.
2238 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002239int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 void __user *buffer, size_t *lenp, loff_t *ppos)
2241{
2242 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2243 do_proc_dointvec_userhz_jiffies_conv,NULL);
2244}
2245
2246/**
2247 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2248 * @table: the sysctl table
2249 * @write: %TRUE if this is a write to the sysctl file
2250 * @filp: the file structure
2251 * @buffer: the user buffer
2252 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002253 * @ppos: file position
2254 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 *
2256 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2257 * values from/to the user buffer, treated as an ASCII string.
2258 * The values read are assumed to be in 1/1000 seconds, and
2259 * are converted into jiffies.
2260 *
2261 * Returns 0 on success.
2262 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002263int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 void __user *buffer, size_t *lenp, loff_t *ppos)
2265{
2266 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2267 do_proc_dointvec_ms_jiffies_conv, NULL);
2268}
2269
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002270static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002271 void __user *buffer, size_t *lenp, loff_t *ppos)
2272{
2273 struct pid *new_pid;
2274 pid_t tmp;
2275 int r;
2276
2277 tmp = pid_nr(cad_pid);
2278
2279 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2280 lenp, ppos, NULL, NULL);
2281 if (r || !write)
2282 return r;
2283
2284 new_pid = find_get_pid(tmp);
2285 if (!new_pid)
2286 return -ESRCH;
2287
2288 put_pid(xchg(&cad_pid, new_pid));
2289 return 0;
2290}
2291
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292#else /* CONFIG_PROC_FS */
2293
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002294int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 void __user *buffer, size_t *lenp, loff_t *ppos)
2296{
2297 return -ENOSYS;
2298}
2299
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002300int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 void __user *buffer, size_t *lenp, loff_t *ppos)
2302{
2303 return -ENOSYS;
2304}
2305
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002306int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 void __user *buffer, size_t *lenp, loff_t *ppos)
2308{
2309 return -ENOSYS;
2310}
2311
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002312int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 void __user *buffer, size_t *lenp, loff_t *ppos)
2314{
2315 return -ENOSYS;
2316}
2317
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002318int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 void __user *buffer, size_t *lenp, loff_t *ppos)
2320{
2321 return -ENOSYS;
2322}
2323
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002324int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 void __user *buffer, size_t *lenp, loff_t *ppos)
2326{
2327 return -ENOSYS;
2328}
2329
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002330int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 void __user *buffer, size_t *lenp, loff_t *ppos)
2332{
2333 return -ENOSYS;
2334}
2335
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002336int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 void __user *buffer, size_t *lenp, loff_t *ppos)
2338{
2339 return -ENOSYS;
2340}
2341
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002342int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 struct file *filp,
2344 void __user *buffer,
2345 size_t *lenp, loff_t *ppos)
2346{
2347 return -ENOSYS;
2348}
2349
2350
2351#endif /* CONFIG_PROC_FS */
2352
2353
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002354#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355/*
2356 * General sysctl support routines
2357 */
2358
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002359/* The generic sysctl data routine (used if no strategy routine supplied) */
2360int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2361 void __user *oldval, size_t __user *oldlenp,
2362 void __user *newval, size_t newlen)
2363{
2364 size_t len;
2365
2366 /* Get out of I don't have a variable */
2367 if (!table->data || !table->maxlen)
2368 return -ENOTDIR;
2369
2370 if (oldval && oldlenp) {
2371 if (get_user(len, oldlenp))
2372 return -EFAULT;
2373 if (len) {
2374 if (len > table->maxlen)
2375 len = table->maxlen;
2376 if (copy_to_user(oldval, table->data, len))
2377 return -EFAULT;
2378 if (put_user(len, oldlenp))
2379 return -EFAULT;
2380 }
2381 }
2382
2383 if (newval && newlen) {
2384 if (newlen > table->maxlen)
2385 newlen = table->maxlen;
2386
2387 if (copy_from_user(table->data, newval, newlen))
2388 return -EFAULT;
2389 }
2390 return 1;
2391}
2392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002394int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002396 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 if (!table->data || !table->maxlen)
2399 return -ENOTDIR;
2400
2401 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002402 size_t bufsize;
2403 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002405 if (bufsize) {
2406 size_t len = strlen(table->data), copied;
2407
2408 /* This shouldn't trigger for a well-formed sysctl */
2409 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002411
2412 /* Copy up to a max of bufsize-1 bytes of the string */
2413 copied = (len >= bufsize) ? bufsize - 1 : len;
2414
2415 if (copy_to_user(oldval, table->data, copied) ||
2416 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002418 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 return -EFAULT;
2420 }
2421 }
2422 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002423 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 if (len > table->maxlen)
2425 len = table->maxlen;
2426 if(copy_from_user(table->data, newval, len))
2427 return -EFAULT;
2428 if (len == table->maxlen)
2429 len--;
2430 ((char *) table->data)[len] = 0;
2431 }
Yi Yang82c9df82005-12-30 16:37:10 +08002432 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433}
2434
2435/*
2436 * This function makes sure that all of the integers in the vector
2437 * are between the minimum and maximum values given in the arrays
2438 * table->extra1 and table->extra2, respectively.
2439 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002440int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002442 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443{
2444
2445 if (newval && newlen) {
2446 int __user *vec = (int __user *) newval;
2447 int *min = (int *) table->extra1;
2448 int *max = (int *) table->extra2;
2449 size_t length;
2450 int i;
2451
2452 if (newlen % sizeof(int) != 0)
2453 return -EINVAL;
2454
2455 if (!table->extra1 && !table->extra2)
2456 return 0;
2457
2458 if (newlen > table->maxlen)
2459 newlen = table->maxlen;
2460 length = newlen / sizeof(int);
2461
2462 for (i = 0; i < length; i++) {
2463 int value;
2464 if (get_user(value, vec + i))
2465 return -EFAULT;
2466 if (min && value < min[i])
2467 return -EINVAL;
2468 if (max && value > max[i])
2469 return -EINVAL;
2470 }
2471 }
2472 return 0;
2473}
2474
2475/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002476int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002478 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002480 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002482
2483 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002485 if (olen) {
2486 int val;
2487
2488 if (olen < sizeof(int))
2489 return -EINVAL;
2490
2491 val = *(int *)(table->data) / HZ;
2492 if (put_user(val, (int __user *)oldval))
2493 return -EFAULT;
2494 if (put_user(sizeof(int), oldlenp))
2495 return -EFAULT;
2496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 }
2498 if (newval && newlen) {
2499 int new;
2500 if (newlen != sizeof(int))
2501 return -EINVAL;
2502 if (get_user(new, (int __user *)newval))
2503 return -EFAULT;
2504 *(int *)(table->data) = new*HZ;
2505 }
2506 return 1;
2507}
2508
2509/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002510int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002512 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002514 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002516
2517 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002519 if (olen) {
2520 int val;
2521
2522 if (olen < sizeof(int))
2523 return -EINVAL;
2524
2525 val = jiffies_to_msecs(*(int *)(table->data));
2526 if (put_user(val, (int __user *)oldval))
2527 return -EFAULT;
2528 if (put_user(sizeof(int), oldlenp))
2529 return -EFAULT;
2530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 }
2532 if (newval && newlen) {
2533 int new;
2534 if (newlen != sizeof(int))
2535 return -EINVAL;
2536 if (get_user(new, (int __user *)newval))
2537 return -EFAULT;
2538 *(int *)(table->data) = msecs_to_jiffies(new);
2539 }
2540 return 1;
2541}
2542
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002543
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002544
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002545#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
2547
2548asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2549{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002550 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002551 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002552
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002553 if (copy_from_user(&tmp, args, sizeof(tmp)))
2554 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002555
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002556 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002557
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002558 /* If no error reading the parameters then just -ENOSYS ... */
2559 if (!error)
2560 error = -ENOSYS;
2561
2562 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563}
2564
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002565int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2566 void __user *oldval, size_t __user *oldlenp,
2567 void __user *newval, size_t newlen)
2568{
2569 return -ENOSYS;
2570}
2571
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002572int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002574 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
2576 return -ENOSYS;
2577}
2578
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002579int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002581 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582{
2583 return -ENOSYS;
2584}
2585
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002586int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002588 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589{
2590 return -ENOSYS;
2591}
2592
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002593int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002595 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596{
2597 return -ENOSYS;
2598}
2599
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002600#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002602static int deprecated_sysctl_warning(struct __sysctl_args *args)
2603{
2604 static int msg_count;
2605 int name[CTL_MAXNAME];
2606 int i;
2607
2608 /* Read in the sysctl name for better debug message logging */
2609 for (i = 0; i < args->nlen; i++)
2610 if (get_user(name[i], args->name + i))
2611 return -EFAULT;
2612
2613 /* Ignore accesses to kernel.version */
2614 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2615 return 0;
2616
2617 if (msg_count < 5) {
2618 msg_count++;
2619 printk(KERN_INFO
2620 "warning: process `%s' used the deprecated sysctl "
2621 "system call with ", current->comm);
2622 for (i = 0; i < args->nlen; i++)
2623 printk("%d.", name[i]);
2624 printk("\n");
2625 }
2626 return 0;
2627}
2628
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629/*
2630 * No sense putting this after each symbol definition, twice,
2631 * exception granted :-)
2632 */
2633EXPORT_SYMBOL(proc_dointvec);
2634EXPORT_SYMBOL(proc_dointvec_jiffies);
2635EXPORT_SYMBOL(proc_dointvec_minmax);
2636EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2637EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2638EXPORT_SYMBOL(proc_dostring);
2639EXPORT_SYMBOL(proc_doulongvec_minmax);
2640EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2641EXPORT_SYMBOL(register_sysctl_table);
2642EXPORT_SYMBOL(sysctl_intvec);
2643EXPORT_SYMBOL(sysctl_jiffies);
2644EXPORT_SYMBOL(sysctl_ms_jiffies);
2645EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002646EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647EXPORT_SYMBOL(unregister_sysctl_table);