blob: 3b4efbe2644572a32576b1a591f003e9869699f0 [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>
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 Molnar23f78d4a2006-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
Andrew Morgan72c2d582007-10-18 03:05:59 -0700374#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .procname = "cap-bound",
377 .data = &cap_bset,
378 .maxlen = sizeof(kernel_cap_t),
379 .mode = 0600,
380 .proc_handler = &proc_dointvec_bset,
381 },
Andrew Morgan72c2d582007-10-18 03:05:59 -0700382#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#ifdef CONFIG_BLK_DEV_INITRD
384 {
385 .ctl_name = KERN_REALROOTDEV,
386 .procname = "real-root-dev",
387 .data = &real_root_dev,
388 .maxlen = sizeof(int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
391 },
392#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700393 {
394 .ctl_name = CTL_UNNUMBERED,
395 .procname = "print-fatal-signals",
396 .data = &print_fatal_signals,
397 .maxlen = sizeof(int),
398 .mode = 0644,
399 .proc_handler = &proc_dointvec,
400 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401#ifdef __sparc__
402 {
403 .ctl_name = KERN_SPARC_REBOOT,
404 .procname = "reboot-cmd",
405 .data = reboot_command,
406 .maxlen = 256,
407 .mode = 0644,
408 .proc_handler = &proc_dostring,
409 .strategy = &sysctl_string,
410 },
411 {
412 .ctl_name = KERN_SPARC_STOP_A,
413 .procname = "stop-a",
414 .data = &stop_a_enabled,
415 .maxlen = sizeof (int),
416 .mode = 0644,
417 .proc_handler = &proc_dointvec,
418 },
419 {
420 .ctl_name = KERN_SPARC_SCONS_PWROFF,
421 .procname = "scons-poweroff",
422 .data = &scons_pwroff,
423 .maxlen = sizeof (int),
424 .mode = 0644,
425 .proc_handler = &proc_dointvec,
426 },
427#endif
428#ifdef __hppa__
429 {
430 .ctl_name = KERN_HPPA_PWRSW,
431 .procname = "soft-power",
432 .data = &pwrsw_enabled,
433 .maxlen = sizeof (int),
434 .mode = 0644,
435 .proc_handler = &proc_dointvec,
436 },
437 {
438 .ctl_name = KERN_HPPA_UNALIGNED,
439 .procname = "unaligned-trap",
440 .data = &unaligned_enabled,
441 .maxlen = sizeof (int),
442 .mode = 0644,
443 .proc_handler = &proc_dointvec,
444 },
445#endif
446 {
447 .ctl_name = KERN_CTLALTDEL,
448 .procname = "ctrl-alt-del",
449 .data = &C_A_D,
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
453 },
454 {
455 .ctl_name = KERN_PRINTK,
456 .procname = "printk",
457 .data = &console_loglevel,
458 .maxlen = 4*sizeof(int),
459 .mode = 0644,
460 .proc_handler = &proc_dointvec,
461 },
462#ifdef CONFIG_KMOD
463 {
464 .ctl_name = KERN_MODPROBE,
465 .procname = "modprobe",
466 .data = &modprobe_path,
467 .maxlen = KMOD_PATH_LEN,
468 .mode = 0644,
469 .proc_handler = &proc_dostring,
470 .strategy = &sysctl_string,
471 },
472#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700473#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 {
475 .ctl_name = KERN_HOTPLUG,
476 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100477 .data = &uevent_helper,
478 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 .mode = 0644,
480 .proc_handler = &proc_dostring,
481 .strategy = &sysctl_string,
482 },
483#endif
484#ifdef CONFIG_CHR_DEV_SG
485 {
486 .ctl_name = KERN_SG_BIG_BUFF,
487 .procname = "sg-big-buff",
488 .data = &sg_big_buff,
489 .maxlen = sizeof (int),
490 .mode = 0444,
491 .proc_handler = &proc_dointvec,
492 },
493#endif
494#ifdef CONFIG_BSD_PROCESS_ACCT
495 {
496 .ctl_name = KERN_ACCT,
497 .procname = "acct",
498 .data = &acct_parm,
499 .maxlen = 3*sizeof(int),
500 .mode = 0644,
501 .proc_handler = &proc_dointvec,
502 },
503#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504#ifdef CONFIG_MAGIC_SYSRQ
505 {
506 .ctl_name = KERN_SYSRQ,
507 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800508 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .maxlen = sizeof (int),
510 .mode = 0644,
511 .proc_handler = &proc_dointvec,
512 },
513#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700514#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700517 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .maxlen = sizeof (int),
519 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700520 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700522#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 {
524 .ctl_name = KERN_MAX_THREADS,
525 .procname = "threads-max",
526 .data = &max_threads,
527 .maxlen = sizeof(int),
528 .mode = 0644,
529 .proc_handler = &proc_dointvec,
530 },
531 {
532 .ctl_name = KERN_RANDOM,
533 .procname = "random",
534 .mode = 0555,
535 .child = random_table,
536 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 {
538 .ctl_name = KERN_OVERFLOWUID,
539 .procname = "overflowuid",
540 .data = &overflowuid,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = &proc_dointvec_minmax,
544 .strategy = &sysctl_intvec,
545 .extra1 = &minolduid,
546 .extra2 = &maxolduid,
547 },
548 {
549 .ctl_name = KERN_OVERFLOWGID,
550 .procname = "overflowgid",
551 .data = &overflowgid,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 .proc_handler = &proc_dointvec_minmax,
555 .strategy = &sysctl_intvec,
556 .extra1 = &minolduid,
557 .extra2 = &maxolduid,
558 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800559#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#ifdef CONFIG_MATHEMU
561 {
562 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
563 .procname = "ieee_emulation_warnings",
564 .data = &sysctl_ieee_emulation_warnings,
565 .maxlen = sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569#endif
570#ifdef CONFIG_NO_IDLE_HZ
571 {
572 .ctl_name = KERN_HZ_TIMER,
573 .procname = "hz_timer",
574 .data = &sysctl_hz_timer,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
578 },
579#endif
580 {
581 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
582 .procname = "userprocess_debug",
583 .data = &sysctl_userprocess_debug,
584 .maxlen = sizeof(int),
585 .mode = 0644,
586 .proc_handler = &proc_dointvec,
587 },
588#endif
589 {
590 .ctl_name = KERN_PIDMAX,
591 .procname = "pid_max",
592 .data = &pid_max,
593 .maxlen = sizeof (int),
594 .mode = 0644,
595 .proc_handler = &proc_dointvec_minmax,
596 .strategy = sysctl_intvec,
597 .extra1 = &pid_max_min,
598 .extra2 = &pid_max_max,
599 },
600 {
601 .ctl_name = KERN_PANIC_ON_OOPS,
602 .procname = "panic_on_oops",
603 .data = &panic_on_oops,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec,
607 },
608 {
609 .ctl_name = KERN_PRINTK_RATELIMIT,
610 .procname = "printk_ratelimit",
611 .data = &printk_ratelimit_jiffies,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec_jiffies,
615 .strategy = &sysctl_jiffies,
616 },
617 {
618 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
619 .procname = "printk_ratelimit_burst",
620 .data = &printk_ratelimit_burst,
621 .maxlen = sizeof(int),
622 .mode = 0644,
623 .proc_handler = &proc_dointvec,
624 },
625 {
626 .ctl_name = KERN_NGROUPS_MAX,
627 .procname = "ngroups_max",
628 .data = &ngroups_max,
629 .maxlen = sizeof (int),
630 .mode = 0444,
631 .proc_handler = &proc_dointvec,
632 },
633#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
634 {
635 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
636 .procname = "unknown_nmi_panic",
637 .data = &unknown_nmi_panic,
638 .maxlen = sizeof (int),
639 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200640 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 },
Don Zickus407984f2006-09-26 10:52:27 +0200642 {
Don Zickus407984f2006-09-26 10:52:27 +0200643 .procname = "nmi_watchdog",
644 .data = &nmi_watchdog_enabled,
645 .maxlen = sizeof (int),
646 .mode = 0644,
647 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 },
649#endif
650#if defined(CONFIG_X86)
651 {
Don Zickus8da5add2006-09-26 10:52:27 +0200652 .ctl_name = KERN_PANIC_ON_NMI,
653 .procname = "panic_on_unrecovered_nmi",
654 .data = &panic_on_unrecovered_nmi,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = &proc_dointvec,
658 },
659 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 .ctl_name = KERN_BOOTLOADER_TYPE,
661 .procname = "bootloader_type",
662 .data = &bootloader_type,
663 .maxlen = sizeof (int),
664 .mode = 0444,
665 .proc_handler = &proc_dointvec,
666 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100667 {
668 .ctl_name = CTL_UNNUMBERED,
669 .procname = "kstack_depth_to_print",
670 .data = &kstack_depth_to_print,
671 .maxlen = sizeof(int),
672 .mode = 0644,
673 .proc_handler = &proc_dointvec,
674 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800676#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 {
678 .ctl_name = KERN_RANDOMIZE,
679 .procname = "randomize_va_space",
680 .data = &randomize_va_space,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 .proc_handler = &proc_dointvec,
684 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800685#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800686#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700687 {
688 .ctl_name = KERN_SPIN_RETRY,
689 .procname = "spin_retry",
690 .data = &spin_retry,
691 .maxlen = sizeof (int),
692 .mode = 0644,
693 .proc_handler = &proc_dointvec,
694 },
695#endif
Len Brown673d5b42007-07-28 03:33:16 -0400696#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800697 {
Pavel Machekc255d842006-02-20 18:27:58 -0800698 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700699 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800700 .maxlen = sizeof (unsigned long),
701 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800702 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800703 },
704#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800705#ifdef CONFIG_IA64
706 {
707 .ctl_name = KERN_IA64_UNALIGNED,
708 .procname = "ignore-unaligned-usertrap",
709 .data = &no_unaligned_warning,
710 .maxlen = sizeof (int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
714#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700715#ifdef CONFIG_DETECT_SOFTLOCKUP
716 {
717 .ctl_name = CTL_UNNUMBERED,
718 .procname = "softlockup_thresh",
719 .data = &softlockup_thresh,
720 .maxlen = sizeof(int),
721 .mode = 0644,
722 .proc_handler = &proc_dointvec_minmax,
723 .strategy = &sysctl_intvec,
724 .extra1 = &one,
725 .extra2 = &sixty,
726 },
727#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200728#ifdef CONFIG_COMPAT
729 {
730 .ctl_name = KERN_COMPAT_LOG,
731 .procname = "compat-log",
732 .data = &compat_log,
733 .maxlen = sizeof (int),
734 .mode = 0644,
735 .proc_handler = &proc_dointvec,
736 },
737#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700738#ifdef CONFIG_RT_MUTEXES
739 {
740 .ctl_name = KERN_MAX_LOCK_DEPTH,
741 .procname = "max_lock_depth",
742 .data = &max_lock_depth,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = &proc_dointvec,
746 },
747#endif
Kees Cook5096add2007-05-08 00:26:04 -0700748#ifdef CONFIG_PROC_FS
749 {
750 .ctl_name = CTL_UNNUMBERED,
751 .procname = "maps_protect",
752 .data = &maps_protect,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = &proc_dointvec,
756 },
757#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700758 {
759 .ctl_name = CTL_UNNUMBERED,
760 .procname = "poweroff_cmd",
761 .data = &poweroff_cmd,
762 .maxlen = POWEROFF_CMD_PATH_LEN,
763 .mode = 0644,
764 .proc_handler = &proc_dostring,
765 .strategy = &sysctl_string,
766 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700767/*
768 * NOTE: do not add new entries to this table unless you have read
769 * Documentation/sysctl/ctl_unnumbered.txt
770 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 { .ctl_name = 0 }
772};
773
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700774static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 {
776 .ctl_name = VM_OVERCOMMIT_MEMORY,
777 .procname = "overcommit_memory",
778 .data = &sysctl_overcommit_memory,
779 .maxlen = sizeof(sysctl_overcommit_memory),
780 .mode = 0644,
781 .proc_handler = &proc_dointvec,
782 },
783 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700784 .ctl_name = VM_PANIC_ON_OOM,
785 .procname = "panic_on_oom",
786 .data = &sysctl_panic_on_oom,
787 .maxlen = sizeof(sysctl_panic_on_oom),
788 .mode = 0644,
789 .proc_handler = &proc_dointvec,
790 },
791 {
David Rientjesfe071d72007-10-16 23:25:56 -0700792 .ctl_name = CTL_UNNUMBERED,
793 .procname = "oom_kill_allocating_task",
794 .data = &sysctl_oom_kill_allocating_task,
795 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
796 .mode = 0644,
797 .proc_handler = &proc_dointvec,
798 },
799 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 .ctl_name = VM_OVERCOMMIT_RATIO,
801 .procname = "overcommit_ratio",
802 .data = &sysctl_overcommit_ratio,
803 .maxlen = sizeof(sysctl_overcommit_ratio),
804 .mode = 0644,
805 .proc_handler = &proc_dointvec,
806 },
807 {
808 .ctl_name = VM_PAGE_CLUSTER,
809 .procname = "page-cluster",
810 .data = &page_cluster,
811 .maxlen = sizeof(int),
812 .mode = 0644,
813 .proc_handler = &proc_dointvec,
814 },
815 {
816 .ctl_name = VM_DIRTY_BACKGROUND,
817 .procname = "dirty_background_ratio",
818 .data = &dirty_background_ratio,
819 .maxlen = sizeof(dirty_background_ratio),
820 .mode = 0644,
821 .proc_handler = &proc_dointvec_minmax,
822 .strategy = &sysctl_intvec,
823 .extra1 = &zero,
824 .extra2 = &one_hundred,
825 },
826 {
827 .ctl_name = VM_DIRTY_RATIO,
828 .procname = "dirty_ratio",
829 .data = &vm_dirty_ratio,
830 .maxlen = sizeof(vm_dirty_ratio),
831 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700832 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 .strategy = &sysctl_intvec,
834 .extra1 = &zero,
835 .extra2 = &one_hundred,
836 },
837 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800839 .data = &dirty_writeback_interval,
840 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 .mode = 0644,
842 .proc_handler = &dirty_writeback_centisecs_handler,
843 },
844 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800846 .data = &dirty_expire_interval,
847 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800849 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 },
851 {
852 .ctl_name = VM_NR_PDFLUSH_THREADS,
853 .procname = "nr_pdflush_threads",
854 .data = &nr_pdflush_threads,
855 .maxlen = sizeof nr_pdflush_threads,
856 .mode = 0444 /* read-only*/,
857 .proc_handler = &proc_dointvec,
858 },
859 {
860 .ctl_name = VM_SWAPPINESS,
861 .procname = "swappiness",
862 .data = &vm_swappiness,
863 .maxlen = sizeof(vm_swappiness),
864 .mode = 0644,
865 .proc_handler = &proc_dointvec_minmax,
866 .strategy = &sysctl_intvec,
867 .extra1 = &zero,
868 .extra2 = &one_hundred,
869 },
870#ifdef CONFIG_HUGETLB_PAGE
871 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 .procname = "nr_hugepages",
873 .data = &max_huge_pages,
874 .maxlen = sizeof(unsigned long),
875 .mode = 0644,
876 .proc_handler = &hugetlb_sysctl_handler,
877 .extra1 = (void *)&hugetlb_zero,
878 .extra2 = (void *)&hugetlb_infinity,
879 },
880 {
881 .ctl_name = VM_HUGETLB_GROUP,
882 .procname = "hugetlb_shm_group",
883 .data = &sysctl_hugetlb_shm_group,
884 .maxlen = sizeof(gid_t),
885 .mode = 0644,
886 .proc_handler = &proc_dointvec,
887 },
Mel Gorman396faf02007-07-17 04:03:13 -0700888 {
889 .ctl_name = CTL_UNNUMBERED,
890 .procname = "hugepages_treat_as_movable",
891 .data = &hugepages_treat_as_movable,
892 .maxlen = sizeof(int),
893 .mode = 0644,
894 .proc_handler = &hugetlb_treat_movable_handler,
895 },
Adam Litke54f9f802007-10-16 01:26:20 -0700896 {
897 .ctl_name = CTL_UNNUMBERED,
898 .procname = "hugetlb_dynamic_pool",
899 .data = &hugetlb_dynamic_pool,
900 .maxlen = sizeof(hugetlb_dynamic_pool),
901 .mode = 0644,
902 .proc_handler = &proc_dointvec,
903 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904#endif
905 {
906 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
907 .procname = "lowmem_reserve_ratio",
908 .data = &sysctl_lowmem_reserve_ratio,
909 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
910 .mode = 0644,
911 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
912 .strategy = &sysctl_intvec,
913 },
914 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800915 .ctl_name = VM_DROP_PAGECACHE,
916 .procname = "drop_caches",
917 .data = &sysctl_drop_caches,
918 .maxlen = sizeof(int),
919 .mode = 0644,
920 .proc_handler = drop_caches_sysctl_handler,
921 .strategy = &sysctl_intvec,
922 },
923 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 .ctl_name = VM_MIN_FREE_KBYTES,
925 .procname = "min_free_kbytes",
926 .data = &min_free_kbytes,
927 .maxlen = sizeof(min_free_kbytes),
928 .mode = 0644,
929 .proc_handler = &min_free_kbytes_sysctl_handler,
930 .strategy = &sysctl_intvec,
931 .extra1 = &zero,
932 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800933 {
934 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
935 .procname = "percpu_pagelist_fraction",
936 .data = &percpu_pagelist_fraction,
937 .maxlen = sizeof(percpu_pagelist_fraction),
938 .mode = 0644,
939 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
940 .strategy = &sysctl_intvec,
941 .extra1 = &min_percpu_pagelist_fract,
942 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943#ifdef CONFIG_MMU
944 {
945 .ctl_name = VM_MAX_MAP_COUNT,
946 .procname = "max_map_count",
947 .data = &sysctl_max_map_count,
948 .maxlen = sizeof(sysctl_max_map_count),
949 .mode = 0644,
950 .proc_handler = &proc_dointvec
951 },
952#endif
953 {
954 .ctl_name = VM_LAPTOP_MODE,
955 .procname = "laptop_mode",
956 .data = &laptop_mode,
957 .maxlen = sizeof(laptop_mode),
958 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800959 .proc_handler = &proc_dointvec_jiffies,
960 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 },
962 {
963 .ctl_name = VM_BLOCK_DUMP,
964 .procname = "block_dump",
965 .data = &block_dump,
966 .maxlen = sizeof(block_dump),
967 .mode = 0644,
968 .proc_handler = &proc_dointvec,
969 .strategy = &sysctl_intvec,
970 .extra1 = &zero,
971 },
972 {
973 .ctl_name = VM_VFS_CACHE_PRESSURE,
974 .procname = "vfs_cache_pressure",
975 .data = &sysctl_vfs_cache_pressure,
976 .maxlen = sizeof(sysctl_vfs_cache_pressure),
977 .mode = 0644,
978 .proc_handler = &proc_dointvec,
979 .strategy = &sysctl_intvec,
980 .extra1 = &zero,
981 },
982#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
983 {
984 .ctl_name = VM_LEGACY_VA_LAYOUT,
985 .procname = "legacy_va_layout",
986 .data = &sysctl_legacy_va_layout,
987 .maxlen = sizeof(sysctl_legacy_va_layout),
988 .mode = 0644,
989 .proc_handler = &proc_dointvec,
990 .strategy = &sysctl_intvec,
991 .extra1 = &zero,
992 },
993#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800994#ifdef CONFIG_NUMA
995 {
996 .ctl_name = VM_ZONE_RECLAIM_MODE,
997 .procname = "zone_reclaim_mode",
998 .data = &zone_reclaim_mode,
999 .maxlen = sizeof(zone_reclaim_mode),
1000 .mode = 0644,
1001 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001002 .strategy = &sysctl_intvec,
1003 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001004 },
Christoph Lameter96146342006-07-03 00:24:13 -07001005 {
1006 .ctl_name = VM_MIN_UNMAPPED,
1007 .procname = "min_unmapped_ratio",
1008 .data = &sysctl_min_unmapped_ratio,
1009 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1010 .mode = 0644,
1011 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1013 .extra1 = &zero,
1014 .extra2 = &one_hundred,
1015 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001016 {
1017 .ctl_name = VM_MIN_SLAB,
1018 .procname = "min_slab_ratio",
1019 .data = &sysctl_min_slab_ratio,
1020 .maxlen = sizeof(sysctl_min_slab_ratio),
1021 .mode = 0644,
1022 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1023 .strategy = &sysctl_intvec,
1024 .extra1 = &zero,
1025 .extra2 = &one_hundred,
1026 },
Christoph Lameter17436602006-01-18 17:42:32 -08001027#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001028#ifdef CONFIG_SMP
1029 {
1030 .ctl_name = CTL_UNNUMBERED,
1031 .procname = "stat_interval",
1032 .data = &sysctl_stat_interval,
1033 .maxlen = sizeof(sysctl_stat_interval),
1034 .mode = 0644,
1035 .proc_handler = &proc_dointvec_jiffies,
1036 .strategy = &sysctl_jiffies,
1037 },
1038#endif
Eric Parised032182007-06-28 15:55:21 -04001039#ifdef CONFIG_SECURITY
1040 {
1041 .ctl_name = CTL_UNNUMBERED,
1042 .procname = "mmap_min_addr",
1043 .data = &mmap_min_addr,
1044 .maxlen = sizeof(unsigned long),
1045 .mode = 0644,
1046 .proc_handler = &proc_doulongvec_minmax,
1047 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001048#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001049#ifdef CONFIG_NUMA
1050 {
1051 .ctl_name = CTL_UNNUMBERED,
1052 .procname = "numa_zonelist_order",
1053 .data = &numa_zonelist_order,
1054 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1055 .mode = 0644,
1056 .proc_handler = &numa_zonelist_order_handler,
1057 .strategy = &sysctl_string,
1058 },
1059#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001060#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001061 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001062 {
1063 .ctl_name = VM_VDSO_ENABLED,
1064 .procname = "vdso_enabled",
1065 .data = &vdso_enabled,
1066 .maxlen = sizeof(vdso_enabled),
1067 .mode = 0644,
1068 .proc_handler = &proc_dointvec,
1069 .strategy = &sysctl_intvec,
1070 .extra1 = &zero,
1071 },
1072#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001073/*
1074 * NOTE: do not add new entries to this table unless you have read
1075 * Documentation/sysctl/ctl_unnumbered.txt
1076 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 { .ctl_name = 0 }
1078};
1079
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001080#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001081static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001082 { .ctl_name = 0 }
1083};
1084#endif
1085
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001086static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 {
1088 .ctl_name = FS_NRINODE,
1089 .procname = "inode-nr",
1090 .data = &inodes_stat,
1091 .maxlen = 2*sizeof(int),
1092 .mode = 0444,
1093 .proc_handler = &proc_dointvec,
1094 },
1095 {
1096 .ctl_name = FS_STATINODE,
1097 .procname = "inode-state",
1098 .data = &inodes_stat,
1099 .maxlen = 7*sizeof(int),
1100 .mode = 0444,
1101 .proc_handler = &proc_dointvec,
1102 },
1103 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 .procname = "file-nr",
1105 .data = &files_stat,
1106 .maxlen = 3*sizeof(int),
1107 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001108 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 },
1110 {
1111 .ctl_name = FS_MAXFILE,
1112 .procname = "file-max",
1113 .data = &files_stat.max_files,
1114 .maxlen = sizeof(int),
1115 .mode = 0644,
1116 .proc_handler = &proc_dointvec,
1117 },
1118 {
1119 .ctl_name = FS_DENTRY,
1120 .procname = "dentry-state",
1121 .data = &dentry_stat,
1122 .maxlen = 6*sizeof(int),
1123 .mode = 0444,
1124 .proc_handler = &proc_dointvec,
1125 },
1126 {
1127 .ctl_name = FS_OVERFLOWUID,
1128 .procname = "overflowuid",
1129 .data = &fs_overflowuid,
1130 .maxlen = sizeof(int),
1131 .mode = 0644,
1132 .proc_handler = &proc_dointvec_minmax,
1133 .strategy = &sysctl_intvec,
1134 .extra1 = &minolduid,
1135 .extra2 = &maxolduid,
1136 },
1137 {
1138 .ctl_name = FS_OVERFLOWGID,
1139 .procname = "overflowgid",
1140 .data = &fs_overflowgid,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
1143 .proc_handler = &proc_dointvec_minmax,
1144 .strategy = &sysctl_intvec,
1145 .extra1 = &minolduid,
1146 .extra2 = &maxolduid,
1147 },
1148 {
1149 .ctl_name = FS_LEASES,
1150 .procname = "leases-enable",
1151 .data = &leases_enable,
1152 .maxlen = sizeof(int),
1153 .mode = 0644,
1154 .proc_handler = &proc_dointvec,
1155 },
1156#ifdef CONFIG_DNOTIFY
1157 {
1158 .ctl_name = FS_DIR_NOTIFY,
1159 .procname = "dir-notify-enable",
1160 .data = &dir_notify_enable,
1161 .maxlen = sizeof(int),
1162 .mode = 0644,
1163 .proc_handler = &proc_dointvec,
1164 },
1165#endif
1166#ifdef CONFIG_MMU
1167 {
1168 .ctl_name = FS_LEASE_TIME,
1169 .procname = "lease-break-time",
1170 .data = &lease_break_time,
1171 .maxlen = sizeof(int),
1172 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001173 .proc_handler = &proc_dointvec_minmax,
1174 .strategy = &sysctl_intvec,
1175 .extra1 = &zero,
1176 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 },
1178 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 .procname = "aio-nr",
1180 .data = &aio_nr,
1181 .maxlen = sizeof(aio_nr),
1182 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001183 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 },
1185 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 .procname = "aio-max-nr",
1187 .data = &aio_max_nr,
1188 .maxlen = sizeof(aio_max_nr),
1189 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001190 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001192#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001193 {
1194 .ctl_name = FS_INOTIFY,
1195 .procname = "inotify",
1196 .mode = 0555,
1197 .child = inotify_table,
1198 },
1199#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001201 {
1202 .ctl_name = KERN_SETUID_DUMPABLE,
1203 .procname = "suid_dumpable",
1204 .data = &suid_dumpable,
1205 .maxlen = sizeof(int),
1206 .mode = 0644,
1207 .proc_handler = &proc_dointvec,
1208 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001209#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1210 {
1211 .ctl_name = CTL_UNNUMBERED,
1212 .procname = "binfmt_misc",
1213 .mode = 0555,
1214 .child = binfmt_misc_table,
1215 },
1216#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001217/*
1218 * NOTE: do not add new entries to this table unless you have read
1219 * Documentation/sysctl/ctl_unnumbered.txt
1220 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 { .ctl_name = 0 }
1222};
1223
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001224static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001225#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001226 {
1227 .ctl_name = CTL_UNNUMBERED,
1228 .procname = "exception-trace",
1229 .data = &show_unhandled_signals,
1230 .maxlen = sizeof(int),
1231 .mode = 0644,
1232 .proc_handler = proc_dointvec
1233 },
1234#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 { .ctl_name = 0 }
1236};
1237
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001238static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001240};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Al Viro330d57f2005-11-04 10:18:40 +00001242static DEFINE_SPINLOCK(sysctl_lock);
1243
1244/* called under sysctl_lock */
1245static int use_table(struct ctl_table_header *p)
1246{
1247 if (unlikely(p->unregistering))
1248 return 0;
1249 p->used++;
1250 return 1;
1251}
1252
1253/* called under sysctl_lock */
1254static void unuse_table(struct ctl_table_header *p)
1255{
1256 if (!--p->used)
1257 if (unlikely(p->unregistering))
1258 complete(p->unregistering);
1259}
1260
1261/* called under sysctl_lock, will reacquire if has to wait */
1262static void start_unregistering(struct ctl_table_header *p)
1263{
1264 /*
1265 * if p->used is 0, nobody will ever touch that entry again;
1266 * we'll eliminate all paths to it before dropping sysctl_lock
1267 */
1268 if (unlikely(p->used)) {
1269 struct completion wait;
1270 init_completion(&wait);
1271 p->unregistering = &wait;
1272 spin_unlock(&sysctl_lock);
1273 wait_for_completion(&wait);
1274 spin_lock(&sysctl_lock);
1275 }
1276 /*
1277 * do not remove from the list until nobody holds it; walking the
1278 * list in do_sysctl() relies on that.
1279 */
1280 list_del_init(&p->ctl_entry);
1281}
1282
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001283void sysctl_head_finish(struct ctl_table_header *head)
1284{
1285 if (!head)
1286 return;
1287 spin_lock(&sysctl_lock);
1288 unuse_table(head);
1289 spin_unlock(&sysctl_lock);
1290}
1291
1292struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1293{
1294 struct ctl_table_header *head;
1295 struct list_head *tmp;
1296 spin_lock(&sysctl_lock);
1297 if (prev) {
1298 tmp = &prev->ctl_entry;
1299 unuse_table(prev);
1300 goto next;
1301 }
1302 tmp = &root_table_header.ctl_entry;
1303 for (;;) {
1304 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1305
1306 if (!use_table(head))
1307 goto next;
1308 spin_unlock(&sysctl_lock);
1309 return head;
1310 next:
1311 tmp = tmp->next;
1312 if (tmp == &root_table_header.ctl_entry)
1313 break;
1314 }
1315 spin_unlock(&sysctl_lock);
1316 return NULL;
1317}
1318
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001319#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1321 void __user *newval, size_t newlen)
1322{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001323 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001324 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
1326 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1327 return -ENOTDIR;
1328 if (oldval) {
1329 int old_len;
1330 if (!oldlenp || get_user(old_len, oldlenp))
1331 return -EFAULT;
1332 }
Al Viro330d57f2005-11-04 10:18:40 +00001333
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001334 for (head = sysctl_head_next(NULL); head;
1335 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001336 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001337 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001338 if (error != -ENOTDIR) {
1339 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001340 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001341 }
1342 }
Al Viro330d57f2005-11-04 10:18:40 +00001343 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344}
1345
1346asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1347{
1348 struct __sysctl_args tmp;
1349 int error;
1350
1351 if (copy_from_user(&tmp, args, sizeof(tmp)))
1352 return -EFAULT;
1353
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001354 error = deprecated_sysctl_warning(&tmp);
1355 if (error)
1356 goto out;
1357
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 lock_kernel();
1359 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1360 tmp.newval, tmp.newlen);
1361 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001362out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 return error;
1364}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001365#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001368 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 * some sysctl variables are readonly even to root.
1370 */
1371
1372static int test_perm(int mode, int op)
1373{
1374 if (!current->euid)
1375 mode >>= 6;
1376 else if (in_egroup_p(0))
1377 mode >>= 3;
1378 if ((mode & op & 0007) == op)
1379 return 0;
1380 return -EACCES;
1381}
1382
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001383int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384{
1385 int error;
1386 error = security_sysctl(table, op);
1387 if (error)
1388 return error;
1389 return test_perm(table->mode, op);
1390}
1391
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001392#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393static int parse_table(int __user *name, int nlen,
1394 void __user *oldval, size_t __user *oldlenp,
1395 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001396 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397{
1398 int n;
1399repeat:
1400 if (!nlen)
1401 return -ENOTDIR;
1402 if (get_user(n, name))
1403 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001404 for ( ; table->ctl_name || table->procname; table++) {
1405 if (!table->ctl_name)
1406 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001407 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 int error;
1409 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001410 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 name++;
1413 nlen--;
1414 table = table->child;
1415 goto repeat;
1416 }
1417 error = do_sysctl_strategy(table, name, nlen,
1418 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001419 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 return error;
1421 }
1422 }
1423 return -ENOTDIR;
1424}
1425
1426/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001427int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 int __user *name, int nlen,
1429 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001430 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
1432 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 if (oldval)
1435 op |= 004;
1436 if (newval)
1437 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001438 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 return -EPERM;
1440
1441 if (table->strategy) {
1442 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001443 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 if (rc < 0)
1445 return rc;
1446 if (rc > 0)
1447 return 0;
1448 }
1449
1450 /* If there is no strategy routine, or if the strategy returns
1451 * zero, proceed with automatic r/w */
1452 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001453 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1454 newval, newlen);
1455 if (rc < 0)
1456 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 }
1458 return 0;
1459}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001460#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001462static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1463{
1464 for (; table->ctl_name || table->procname; table++) {
1465 table->parent = parent;
1466 if (table->child)
1467 sysctl_set_parent(table, table->child);
1468 }
1469}
1470
1471static __init int sysctl_init(void)
1472{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001473 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001474 sysctl_set_parent(NULL, root_table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001475 err = sysctl_check_table(root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001476 return 0;
1477}
1478
1479core_initcall(sysctl_init);
1480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481/**
1482 * register_sysctl_table - register a sysctl hierarchy
1483 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 *
1485 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1486 * array. An entry with a ctl_name of 0 terminates the table.
1487 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001488 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 *
1490 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1491 * must be unique within that level of sysctl
1492 *
1493 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1494 * enter a sysctl file
1495 *
1496 * data - a pointer to data for use by proc_handler
1497 *
1498 * maxlen - the maximum size in bytes of the data
1499 *
1500 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1501 *
1502 * child - a pointer to the child sysctl table if this entry is a directory, or
1503 * %NULL.
1504 *
1505 * proc_handler - the text handler routine (described below)
1506 *
1507 * strategy - the strategy routine (described below)
1508 *
1509 * de - for internal use by the sysctl routines
1510 *
1511 * extra1, extra2 - extra pointers usable by the proc handler routines
1512 *
1513 * Leaf nodes in the sysctl tree will be represented by a single file
1514 * under /proc; non-leaf nodes will be represented by directories.
1515 *
1516 * sysctl(2) can automatically manage read and write requests through
1517 * the sysctl table. The data and maxlen fields of the ctl_table
1518 * struct enable minimal validation of the values being written to be
1519 * performed, and the mode field allows minimal authentication.
1520 *
1521 * More sophisticated management can be enabled by the provision of a
1522 * strategy routine with the table entry. This will be called before
1523 * any automatic read or write of the data is performed.
1524 *
1525 * The strategy routine may return
1526 *
1527 * < 0 - Error occurred (error is passed to user process)
1528 *
1529 * 0 - OK - proceed with automatic read or write.
1530 *
1531 * > 0 - OK - read or write has been done by the strategy routine, so
1532 * return immediately.
1533 *
1534 * There must be a proc_handler routine for any terminal nodes
1535 * mirrored under /proc/sys (non-terminals are handled by a built-in
1536 * directory handler). Several default handlers are available to
1537 * cover common cases -
1538 *
1539 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1540 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1541 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1542 *
1543 * It is the handler's job to read the input buffer from user memory
1544 * and process it. The handler should return 0 on success.
1545 *
1546 * This routine returns %NULL on a failure to register, and a pointer
1547 * to the table header on success.
1548 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001549struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
1551 struct ctl_table_header *tmp;
1552 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1553 if (!tmp)
1554 return NULL;
1555 tmp->ctl_table = table;
1556 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001557 tmp->used = 0;
1558 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001559 sysctl_set_parent(NULL, table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001560 if (sysctl_check_table(tmp->ctl_table)) {
1561 kfree(tmp);
1562 return NULL;
1563 }
Al Viro330d57f2005-11-04 10:18:40 +00001564 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001565 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001566 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 return tmp;
1568}
1569
1570/**
1571 * unregister_sysctl_table - unregister a sysctl table hierarchy
1572 * @header: the header returned from register_sysctl_table
1573 *
1574 * Unregisters the sysctl table and all children. proc entries may not
1575 * actually be removed until they are no longer used by anyone.
1576 */
1577void unregister_sysctl_table(struct ctl_table_header * header)
1578{
Al Viro330d57f2005-11-04 10:18:40 +00001579 might_sleep();
1580 spin_lock(&sysctl_lock);
1581 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001582 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 kfree(header);
1584}
1585
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001586#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001587struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001588{
1589 return NULL;
1590}
1591
1592void unregister_sysctl_table(struct ctl_table_header * table)
1593{
1594}
1595
1596#endif /* CONFIG_SYSCTL */
1597
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598/*
1599 * /proc/sys support
1600 */
1601
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001602#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001604static int _proc_do_string(void* data, int maxlen, int write,
1605 struct file *filp, void __user *buffer,
1606 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001607{
1608 size_t len;
1609 char __user *p;
1610 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001611
1612 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001613 *lenp = 0;
1614 return 0;
1615 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001616
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001617 if (write) {
1618 len = 0;
1619 p = buffer;
1620 while (len < *lenp) {
1621 if (get_user(c, p++))
1622 return -EFAULT;
1623 if (c == 0 || c == '\n')
1624 break;
1625 len++;
1626 }
1627 if (len >= maxlen)
1628 len = maxlen-1;
1629 if(copy_from_user(data, buffer, len))
1630 return -EFAULT;
1631 ((char *) data)[len] = 0;
1632 *ppos += *lenp;
1633 } else {
1634 len = strlen(data);
1635 if (len > maxlen)
1636 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001637
1638 if (*ppos > len) {
1639 *lenp = 0;
1640 return 0;
1641 }
1642
1643 data += *ppos;
1644 len -= *ppos;
1645
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001646 if (len > *lenp)
1647 len = *lenp;
1648 if (len)
1649 if(copy_to_user(buffer, data, len))
1650 return -EFAULT;
1651 if (len < *lenp) {
1652 if(put_user('\n', ((char __user *) buffer) + len))
1653 return -EFAULT;
1654 len++;
1655 }
1656 *lenp = len;
1657 *ppos += len;
1658 }
1659 return 0;
1660}
1661
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662/**
1663 * proc_dostring - read a string sysctl
1664 * @table: the sysctl table
1665 * @write: %TRUE if this is a write to the sysctl file
1666 * @filp: the file structure
1667 * @buffer: the user buffer
1668 * @lenp: the size of the user buffer
1669 * @ppos: file position
1670 *
1671 * Reads/writes a string from/to the user buffer. If the kernel
1672 * buffer provided is not large enough to hold the string, the
1673 * string is truncated. The copied string is %NULL-terminated.
1674 * If the string is being read by the user process, it is copied
1675 * and a newline '\n' is added. It is truncated if the buffer is
1676 * not large enough.
1677 *
1678 * Returns 0 on success.
1679 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001680int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 void __user *buffer, size_t *lenp, loff_t *ppos)
1682{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001683 return _proc_do_string(table->data, table->maxlen, write, filp,
1684 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685}
1686
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
1688static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1689 int *valp,
1690 int write, void *data)
1691{
1692 if (write) {
1693 *valp = *negp ? -*lvalp : *lvalp;
1694 } else {
1695 int val = *valp;
1696 if (val < 0) {
1697 *negp = -1;
1698 *lvalp = (unsigned long)-val;
1699 } else {
1700 *negp = 0;
1701 *lvalp = (unsigned long)val;
1702 }
1703 }
1704 return 0;
1705}
1706
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001707static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001708 int write, struct file *filp, void __user *buffer,
1709 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1711 int write, void *data),
1712 void *data)
1713{
1714#define TMPBUFLEN 21
1715 int *i, vleft, first=1, neg, val;
1716 unsigned long lval;
1717 size_t left, len;
1718
1719 char buf[TMPBUFLEN], *p;
1720 char __user *s = buffer;
1721
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001722 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 (*ppos && !write)) {
1724 *lenp = 0;
1725 return 0;
1726 }
1727
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001728 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 vleft = table->maxlen / sizeof(*i);
1730 left = *lenp;
1731
1732 if (!conv)
1733 conv = do_proc_dointvec_conv;
1734
1735 for (; left && vleft--; i++, first=0) {
1736 if (write) {
1737 while (left) {
1738 char c;
1739 if (get_user(c, s))
1740 return -EFAULT;
1741 if (!isspace(c))
1742 break;
1743 left--;
1744 s++;
1745 }
1746 if (!left)
1747 break;
1748 neg = 0;
1749 len = left;
1750 if (len > sizeof(buf) - 1)
1751 len = sizeof(buf) - 1;
1752 if (copy_from_user(buf, s, len))
1753 return -EFAULT;
1754 buf[len] = 0;
1755 p = buf;
1756 if (*p == '-' && left > 1) {
1757 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001758 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 }
1760 if (*p < '0' || *p > '9')
1761 break;
1762
1763 lval = simple_strtoul(p, &p, 0);
1764
1765 len = p-buf;
1766 if ((len < left) && *p && !isspace(*p))
1767 break;
1768 if (neg)
1769 val = -val;
1770 s += len;
1771 left -= len;
1772
1773 if (conv(&neg, &lval, i, 1, data))
1774 break;
1775 } else {
1776 p = buf;
1777 if (!first)
1778 *p++ = '\t';
1779
1780 if (conv(&neg, &lval, i, 0, data))
1781 break;
1782
1783 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1784 len = strlen(buf);
1785 if (len > left)
1786 len = left;
1787 if(copy_to_user(s, buf, len))
1788 return -EFAULT;
1789 left -= len;
1790 s += len;
1791 }
1792 }
1793
1794 if (!write && !first && left) {
1795 if(put_user('\n', s))
1796 return -EFAULT;
1797 left--, s++;
1798 }
1799 if (write) {
1800 while (left) {
1801 char c;
1802 if (get_user(c, s++))
1803 return -EFAULT;
1804 if (!isspace(c))
1805 break;
1806 left--;
1807 }
1808 }
1809 if (write && first)
1810 return -EINVAL;
1811 *lenp -= left;
1812 *ppos += *lenp;
1813 return 0;
1814#undef TMPBUFLEN
1815}
1816
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001817static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001818 void __user *buffer, size_t *lenp, loff_t *ppos,
1819 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1820 int write, void *data),
1821 void *data)
1822{
1823 return __do_proc_dointvec(table->data, table, write, filp,
1824 buffer, lenp, ppos, conv, data);
1825}
1826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827/**
1828 * proc_dointvec - read a vector of integers
1829 * @table: the sysctl table
1830 * @write: %TRUE if this is a write to the sysctl file
1831 * @filp: the file structure
1832 * @buffer: the user buffer
1833 * @lenp: the size of the user buffer
1834 * @ppos: file position
1835 *
1836 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1837 * values from/to the user buffer, treated as an ASCII string.
1838 *
1839 * Returns 0 on success.
1840 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001841int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 void __user *buffer, size_t *lenp, loff_t *ppos)
1843{
1844 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1845 NULL,NULL);
1846}
1847
1848#define OP_SET 0
1849#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001850#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
1852static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1853 int *valp,
1854 int write, void *data)
1855{
1856 int op = *(int *)data;
1857 if (write) {
1858 int val = *negp ? -*lvalp : *lvalp;
1859 switch(op) {
1860 case OP_SET: *valp = val; break;
1861 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001862 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 }
1864 } else {
1865 int val = *valp;
1866 if (val < 0) {
1867 *negp = -1;
1868 *lvalp = (unsigned long)-val;
1869 } else {
1870 *negp = 0;
1871 *lvalp = (unsigned long)val;
1872 }
1873 }
1874 return 0;
1875}
1876
Andrew Morgan72c2d582007-10-18 03:05:59 -07001877#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878/*
1879 * init may raise the set.
1880 */
Andrew Morgan72c2d582007-10-18 03:05:59 -07001881
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001882int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 void __user *buffer, size_t *lenp, loff_t *ppos)
1884{
1885 int op;
1886
Eric Paris6ff1b442007-02-10 01:43:19 -08001887 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 return -EPERM;
1889 }
1890
Serge E. Hallynb460cbc2007-10-18 23:39:52 -07001891 op = is_global_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1893 do_proc_dointvec_bset_conv,&op);
1894}
Andrew Morgan72c2d582007-10-18 03:05:59 -07001895#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001897/*
1898 * Taint values can only be increased
1899 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001900static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001901 void __user *buffer, size_t *lenp, loff_t *ppos)
1902{
1903 int op;
1904
Bastian Blank91fcd412007-04-23 14:41:14 -07001905 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001906 return -EPERM;
1907
1908 op = OP_OR;
1909 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1910 do_proc_dointvec_bset_conv,&op);
1911}
1912
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913struct do_proc_dointvec_minmax_conv_param {
1914 int *min;
1915 int *max;
1916};
1917
1918static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1919 int *valp,
1920 int write, void *data)
1921{
1922 struct do_proc_dointvec_minmax_conv_param *param = data;
1923 if (write) {
1924 int val = *negp ? -*lvalp : *lvalp;
1925 if ((param->min && *param->min > val) ||
1926 (param->max && *param->max < val))
1927 return -EINVAL;
1928 *valp = val;
1929 } else {
1930 int val = *valp;
1931 if (val < 0) {
1932 *negp = -1;
1933 *lvalp = (unsigned long)-val;
1934 } else {
1935 *negp = 0;
1936 *lvalp = (unsigned long)val;
1937 }
1938 }
1939 return 0;
1940}
1941
1942/**
1943 * proc_dointvec_minmax - read a vector of integers with min/max values
1944 * @table: the sysctl table
1945 * @write: %TRUE if this is a write to the sysctl file
1946 * @filp: the file structure
1947 * @buffer: the user buffer
1948 * @lenp: the size of the user buffer
1949 * @ppos: file position
1950 *
1951 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1952 * values from/to the user buffer, treated as an ASCII string.
1953 *
1954 * This routine will ensure the values are within the range specified by
1955 * table->extra1 (min) and table->extra2 (max).
1956 *
1957 * Returns 0 on success.
1958 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001959int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 void __user *buffer, size_t *lenp, loff_t *ppos)
1961{
1962 struct do_proc_dointvec_minmax_conv_param param = {
1963 .min = (int *) table->extra1,
1964 .max = (int *) table->extra2,
1965 };
1966 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1967 do_proc_dointvec_minmax_conv, &param);
1968}
1969
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001970static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 struct file *filp,
1972 void __user *buffer,
1973 size_t *lenp, loff_t *ppos,
1974 unsigned long convmul,
1975 unsigned long convdiv)
1976{
1977#define TMPBUFLEN 21
1978 unsigned long *i, *min, *max, val;
1979 int vleft, first=1, neg;
1980 size_t len, left;
1981 char buf[TMPBUFLEN], *p;
1982 char __user *s = buffer;
1983
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001984 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 (*ppos && !write)) {
1986 *lenp = 0;
1987 return 0;
1988 }
1989
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001990 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 min = (unsigned long *) table->extra1;
1992 max = (unsigned long *) table->extra2;
1993 vleft = table->maxlen / sizeof(unsigned long);
1994 left = *lenp;
1995
1996 for (; left && vleft--; i++, min++, max++, first=0) {
1997 if (write) {
1998 while (left) {
1999 char c;
2000 if (get_user(c, s))
2001 return -EFAULT;
2002 if (!isspace(c))
2003 break;
2004 left--;
2005 s++;
2006 }
2007 if (!left)
2008 break;
2009 neg = 0;
2010 len = left;
2011 if (len > TMPBUFLEN-1)
2012 len = TMPBUFLEN-1;
2013 if (copy_from_user(buf, s, len))
2014 return -EFAULT;
2015 buf[len] = 0;
2016 p = buf;
2017 if (*p == '-' && left > 1) {
2018 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002019 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 }
2021 if (*p < '0' || *p > '9')
2022 break;
2023 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2024 len = p-buf;
2025 if ((len < left) && *p && !isspace(*p))
2026 break;
2027 if (neg)
2028 val = -val;
2029 s += len;
2030 left -= len;
2031
2032 if(neg)
2033 continue;
2034 if ((min && val < *min) || (max && val > *max))
2035 continue;
2036 *i = val;
2037 } else {
2038 p = buf;
2039 if (!first)
2040 *p++ = '\t';
2041 sprintf(p, "%lu", convdiv * (*i) / convmul);
2042 len = strlen(buf);
2043 if (len > left)
2044 len = left;
2045 if(copy_to_user(s, buf, len))
2046 return -EFAULT;
2047 left -= len;
2048 s += len;
2049 }
2050 }
2051
2052 if (!write && !first && left) {
2053 if(put_user('\n', s))
2054 return -EFAULT;
2055 left--, s++;
2056 }
2057 if (write) {
2058 while (left) {
2059 char c;
2060 if (get_user(c, s++))
2061 return -EFAULT;
2062 if (!isspace(c))
2063 break;
2064 left--;
2065 }
2066 }
2067 if (write && first)
2068 return -EINVAL;
2069 *lenp -= left;
2070 *ppos += *lenp;
2071 return 0;
2072#undef TMPBUFLEN
2073}
2074
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002075static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002076 struct file *filp,
2077 void __user *buffer,
2078 size_t *lenp, loff_t *ppos,
2079 unsigned long convmul,
2080 unsigned long convdiv)
2081{
2082 return __do_proc_doulongvec_minmax(table->data, table, write,
2083 filp, buffer, lenp, ppos, convmul, convdiv);
2084}
2085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086/**
2087 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2088 * @table: the sysctl table
2089 * @write: %TRUE if this is a write to the sysctl file
2090 * @filp: the file structure
2091 * @buffer: the user buffer
2092 * @lenp: the size of the user buffer
2093 * @ppos: file position
2094 *
2095 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2096 * values from/to the user buffer, treated as an ASCII string.
2097 *
2098 * This routine will ensure the values are within the range specified by
2099 * table->extra1 (min) and table->extra2 (max).
2100 *
2101 * Returns 0 on success.
2102 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002103int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 void __user *buffer, size_t *lenp, loff_t *ppos)
2105{
2106 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2107}
2108
2109/**
2110 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2111 * @table: the sysctl table
2112 * @write: %TRUE if this is a write to the sysctl file
2113 * @filp: the file structure
2114 * @buffer: the user buffer
2115 * @lenp: the size of the user buffer
2116 * @ppos: file position
2117 *
2118 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2119 * values from/to the user buffer, treated as an ASCII string. The values
2120 * are treated as milliseconds, and converted to jiffies when they are stored.
2121 *
2122 * This routine will ensure the values are within the range specified by
2123 * table->extra1 (min) and table->extra2 (max).
2124 *
2125 * Returns 0 on success.
2126 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002127int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 struct file *filp,
2129 void __user *buffer,
2130 size_t *lenp, loff_t *ppos)
2131{
2132 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2133 lenp, ppos, HZ, 1000l);
2134}
2135
2136
2137static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2138 int *valp,
2139 int write, void *data)
2140{
2141 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002142 if (*lvalp > LONG_MAX / HZ)
2143 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2145 } else {
2146 int val = *valp;
2147 unsigned long lval;
2148 if (val < 0) {
2149 *negp = -1;
2150 lval = (unsigned long)-val;
2151 } else {
2152 *negp = 0;
2153 lval = (unsigned long)val;
2154 }
2155 *lvalp = lval / HZ;
2156 }
2157 return 0;
2158}
2159
2160static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2161 int *valp,
2162 int write, void *data)
2163{
2164 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002165 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2166 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2168 } else {
2169 int val = *valp;
2170 unsigned long lval;
2171 if (val < 0) {
2172 *negp = -1;
2173 lval = (unsigned long)-val;
2174 } else {
2175 *negp = 0;
2176 lval = (unsigned long)val;
2177 }
2178 *lvalp = jiffies_to_clock_t(lval);
2179 }
2180 return 0;
2181}
2182
2183static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2184 int *valp,
2185 int write, void *data)
2186{
2187 if (write) {
2188 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2189 } else {
2190 int val = *valp;
2191 unsigned long lval;
2192 if (val < 0) {
2193 *negp = -1;
2194 lval = (unsigned long)-val;
2195 } else {
2196 *negp = 0;
2197 lval = (unsigned long)val;
2198 }
2199 *lvalp = jiffies_to_msecs(lval);
2200 }
2201 return 0;
2202}
2203
2204/**
2205 * proc_dointvec_jiffies - read a vector of integers as seconds
2206 * @table: the sysctl table
2207 * @write: %TRUE if this is a write to the sysctl file
2208 * @filp: the file structure
2209 * @buffer: the user buffer
2210 * @lenp: the size of the user buffer
2211 * @ppos: file position
2212 *
2213 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2214 * values from/to the user buffer, treated as an ASCII string.
2215 * The values read are assumed to be in seconds, and are converted into
2216 * jiffies.
2217 *
2218 * Returns 0 on success.
2219 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002220int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 void __user *buffer, size_t *lenp, loff_t *ppos)
2222{
2223 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2224 do_proc_dointvec_jiffies_conv,NULL);
2225}
2226
2227/**
2228 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @filp: the file structure
2232 * @buffer: the user buffer
2233 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002234 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 *
2236 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2237 * values from/to the user buffer, treated as an ASCII string.
2238 * The values read are assumed to be in 1/USER_HZ seconds, and
2239 * are converted into jiffies.
2240 *
2241 * Returns 0 on success.
2242 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002243int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 void __user *buffer, size_t *lenp, loff_t *ppos)
2245{
2246 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2247 do_proc_dointvec_userhz_jiffies_conv,NULL);
2248}
2249
2250/**
2251 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2252 * @table: the sysctl table
2253 * @write: %TRUE if this is a write to the sysctl file
2254 * @filp: the file structure
2255 * @buffer: the user buffer
2256 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002257 * @ppos: file position
2258 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 *
2260 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2261 * values from/to the user buffer, treated as an ASCII string.
2262 * The values read are assumed to be in 1/1000 seconds, and
2263 * are converted into jiffies.
2264 *
2265 * Returns 0 on success.
2266 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002267int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 void __user *buffer, size_t *lenp, loff_t *ppos)
2269{
2270 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2271 do_proc_dointvec_ms_jiffies_conv, NULL);
2272}
2273
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002274static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002275 void __user *buffer, size_t *lenp, loff_t *ppos)
2276{
2277 struct pid *new_pid;
2278 pid_t tmp;
2279 int r;
2280
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002281 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002282
2283 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2284 lenp, ppos, NULL, NULL);
2285 if (r || !write)
2286 return r;
2287
2288 new_pid = find_get_pid(tmp);
2289 if (!new_pid)
2290 return -ESRCH;
2291
2292 put_pid(xchg(&cad_pid, new_pid));
2293 return 0;
2294}
2295
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296#else /* CONFIG_PROC_FS */
2297
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002298int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 void __user *buffer, size_t *lenp, loff_t *ppos)
2300{
2301 return -ENOSYS;
2302}
2303
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002304int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 void __user *buffer, size_t *lenp, loff_t *ppos)
2306{
2307 return -ENOSYS;
2308}
2309
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002310int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 void __user *buffer, size_t *lenp, loff_t *ppos)
2312{
2313 return -ENOSYS;
2314}
2315
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002316int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 void __user *buffer, size_t *lenp, loff_t *ppos)
2318{
2319 return -ENOSYS;
2320}
2321
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002322int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 void __user *buffer, size_t *lenp, loff_t *ppos)
2324{
2325 return -ENOSYS;
2326}
2327
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002328int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 void __user *buffer, size_t *lenp, loff_t *ppos)
2330{
2331 return -ENOSYS;
2332}
2333
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002334int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 void __user *buffer, size_t *lenp, loff_t *ppos)
2336{
2337 return -ENOSYS;
2338}
2339
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002340int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 void __user *buffer, size_t *lenp, loff_t *ppos)
2342{
2343 return -ENOSYS;
2344}
2345
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002346int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 struct file *filp,
2348 void __user *buffer,
2349 size_t *lenp, loff_t *ppos)
2350{
2351 return -ENOSYS;
2352}
2353
2354
2355#endif /* CONFIG_PROC_FS */
2356
2357
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002358#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359/*
2360 * General sysctl support routines
2361 */
2362
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002363/* The generic sysctl data routine (used if no strategy routine supplied) */
2364int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2365 void __user *oldval, size_t __user *oldlenp,
2366 void __user *newval, size_t newlen)
2367{
2368 size_t len;
2369
2370 /* Get out of I don't have a variable */
2371 if (!table->data || !table->maxlen)
2372 return -ENOTDIR;
2373
2374 if (oldval && oldlenp) {
2375 if (get_user(len, oldlenp))
2376 return -EFAULT;
2377 if (len) {
2378 if (len > table->maxlen)
2379 len = table->maxlen;
2380 if (copy_to_user(oldval, table->data, len))
2381 return -EFAULT;
2382 if (put_user(len, oldlenp))
2383 return -EFAULT;
2384 }
2385 }
2386
2387 if (newval && newlen) {
2388 if (newlen > table->maxlen)
2389 newlen = table->maxlen;
2390
2391 if (copy_from_user(table->data, newval, newlen))
2392 return -EFAULT;
2393 }
2394 return 1;
2395}
2396
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002398int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002400 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 if (!table->data || !table->maxlen)
2403 return -ENOTDIR;
2404
2405 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002406 size_t bufsize;
2407 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002409 if (bufsize) {
2410 size_t len = strlen(table->data), copied;
2411
2412 /* This shouldn't trigger for a well-formed sysctl */
2413 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002415
2416 /* Copy up to a max of bufsize-1 bytes of the string */
2417 copied = (len >= bufsize) ? bufsize - 1 : len;
2418
2419 if (copy_to_user(oldval, table->data, copied) ||
2420 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002422 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 return -EFAULT;
2424 }
2425 }
2426 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002427 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 if (len > table->maxlen)
2429 len = table->maxlen;
2430 if(copy_from_user(table->data, newval, len))
2431 return -EFAULT;
2432 if (len == table->maxlen)
2433 len--;
2434 ((char *) table->data)[len] = 0;
2435 }
Yi Yang82c9df82005-12-30 16:37:10 +08002436 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437}
2438
2439/*
2440 * This function makes sure that all of the integers in the vector
2441 * are between the minimum and maximum values given in the arrays
2442 * table->extra1 and table->extra2, respectively.
2443 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002444int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002446 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447{
2448
2449 if (newval && newlen) {
2450 int __user *vec = (int __user *) newval;
2451 int *min = (int *) table->extra1;
2452 int *max = (int *) table->extra2;
2453 size_t length;
2454 int i;
2455
2456 if (newlen % sizeof(int) != 0)
2457 return -EINVAL;
2458
2459 if (!table->extra1 && !table->extra2)
2460 return 0;
2461
2462 if (newlen > table->maxlen)
2463 newlen = table->maxlen;
2464 length = newlen / sizeof(int);
2465
2466 for (i = 0; i < length; i++) {
2467 int value;
2468 if (get_user(value, vec + i))
2469 return -EFAULT;
2470 if (min && value < min[i])
2471 return -EINVAL;
2472 if (max && value > max[i])
2473 return -EINVAL;
2474 }
2475 }
2476 return 0;
2477}
2478
2479/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002480int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002482 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002484 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002486
2487 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002489 if (olen) {
2490 int val;
2491
2492 if (olen < sizeof(int))
2493 return -EINVAL;
2494
2495 val = *(int *)(table->data) / HZ;
2496 if (put_user(val, (int __user *)oldval))
2497 return -EFAULT;
2498 if (put_user(sizeof(int), oldlenp))
2499 return -EFAULT;
2500 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 }
2502 if (newval && newlen) {
2503 int new;
2504 if (newlen != sizeof(int))
2505 return -EINVAL;
2506 if (get_user(new, (int __user *)newval))
2507 return -EFAULT;
2508 *(int *)(table->data) = new*HZ;
2509 }
2510 return 1;
2511}
2512
2513/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002514int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002516 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002518 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002520
2521 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002523 if (olen) {
2524 int val;
2525
2526 if (olen < sizeof(int))
2527 return -EINVAL;
2528
2529 val = jiffies_to_msecs(*(int *)(table->data));
2530 if (put_user(val, (int __user *)oldval))
2531 return -EFAULT;
2532 if (put_user(sizeof(int), oldlenp))
2533 return -EFAULT;
2534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 }
2536 if (newval && newlen) {
2537 int new;
2538 if (newlen != sizeof(int))
2539 return -EINVAL;
2540 if (get_user(new, (int __user *)newval))
2541 return -EFAULT;
2542 *(int *)(table->data) = msecs_to_jiffies(new);
2543 }
2544 return 1;
2545}
2546
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002547
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002548
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002549#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550
2551
2552asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2553{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002554 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002555 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002556
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002557 if (copy_from_user(&tmp, args, sizeof(tmp)))
2558 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002559
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002560 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002561
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002562 /* If no error reading the parameters then just -ENOSYS ... */
2563 if (!error)
2564 error = -ENOSYS;
2565
2566 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567}
2568
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002569int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2570 void __user *oldval, size_t __user *oldlenp,
2571 void __user *newval, size_t newlen)
2572{
2573 return -ENOSYS;
2574}
2575
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002576int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002578 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579{
2580 return -ENOSYS;
2581}
2582
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002583int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002585 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586{
2587 return -ENOSYS;
2588}
2589
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002590int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002592 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593{
2594 return -ENOSYS;
2595}
2596
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002597int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002599 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
2601 return -ENOSYS;
2602}
2603
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002604#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002606static int deprecated_sysctl_warning(struct __sysctl_args *args)
2607{
2608 static int msg_count;
2609 int name[CTL_MAXNAME];
2610 int i;
2611
2612 /* Read in the sysctl name for better debug message logging */
2613 for (i = 0; i < args->nlen; i++)
2614 if (get_user(name[i], args->name + i))
2615 return -EFAULT;
2616
2617 /* Ignore accesses to kernel.version */
2618 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2619 return 0;
2620
2621 if (msg_count < 5) {
2622 msg_count++;
2623 printk(KERN_INFO
2624 "warning: process `%s' used the deprecated sysctl "
2625 "system call with ", current->comm);
2626 for (i = 0; i < args->nlen; i++)
2627 printk("%d.", name[i]);
2628 printk("\n");
2629 }
2630 return 0;
2631}
2632
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633/*
2634 * No sense putting this after each symbol definition, twice,
2635 * exception granted :-)
2636 */
2637EXPORT_SYMBOL(proc_dointvec);
2638EXPORT_SYMBOL(proc_dointvec_jiffies);
2639EXPORT_SYMBOL(proc_dointvec_minmax);
2640EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2641EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2642EXPORT_SYMBOL(proc_dostring);
2643EXPORT_SYMBOL(proc_doulongvec_minmax);
2644EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2645EXPORT_SYMBOL(register_sysctl_table);
2646EXPORT_SYMBOL(sysctl_intvec);
2647EXPORT_SYMBOL(sysctl_jiffies);
2648EXPORT_SYMBOL(sysctl_ms_jiffies);
2649EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002650EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651EXPORT_SYMBOL(unregister_sysctl_table);