blob: 6e3b63c06856d89b10b161dc1bc1c309d02ff911 [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 Molnar23f78d42006-06-27 02:54:53 -0700141#ifdef CONFIG_RT_MUTEXES
142extern int max_lock_depth;
143#endif
144
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700145#ifdef CONFIG_SYSCTL_SYSCALL
146static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700147 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700148#endif
149
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800150
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700151#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700152static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700153 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700154static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800155 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700156#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700157
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static struct ctl_table root_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static struct ctl_table_header root_table_header =
160 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
161
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700162static struct ctl_table kern_table[];
163static struct ctl_table vm_table[];
164static struct ctl_table fs_table[];
165static struct ctl_table debug_table[];
166static struct ctl_table dev_table[];
167extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700168#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700169extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400170#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
173int sysctl_legacy_va_layout;
174#endif
175
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700176extern int prove_locking;
177extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179/* The default sysctl tables: */
180
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700181static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 {
183 .ctl_name = CTL_KERN,
184 .procname = "kernel",
185 .mode = 0555,
186 .child = kern_table,
187 },
188 {
189 .ctl_name = CTL_VM,
190 .procname = "vm",
191 .mode = 0555,
192 .child = vm_table,
193 },
194#ifdef CONFIG_NET
195 {
196 .ctl_name = CTL_NET,
197 .procname = "net",
198 .mode = 0555,
199 .child = net_table,
200 },
201#endif
202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
207 },
208 {
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
213 },
214 {
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
219 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700220/*
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 { .ctl_name = 0 }
225};
226
Ingo Molnar77e54a12007-07-09 18:52:00 +0200227#ifdef CONFIG_SCHED_DEBUG
228static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
229static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
230static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
231static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
232#endif
233
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700234static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#ifdef CONFIG_SCHED_DEBUG
236 {
237 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240 .maxlen = sizeof(unsigned int),
241 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246 },
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_batch_wakeup_granularity_ns",
272 .data = &sysctl_sched_batch_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
287 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200288 {
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_features",
291 .data = &sysctl_sched_features,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec,
295 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200296 {
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_migration_cost",
299 .data = &sysctl_sched_migration_cost,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
302 .proc_handler = &proc_dointvec,
303 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200304#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200305 {
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_compat_yield",
308 .data = &sysctl_sched_compat_yield,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
311 .proc_handler = &proc_dointvec,
312 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700313#ifdef CONFIG_PROVE_LOCKING
314 {
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "prove_locking",
317 .data = &prove_locking,
318 .maxlen = sizeof(int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
322#endif
323#ifdef CONFIG_LOCK_STAT
324 {
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "lock_stat",
327 .data = &lock_stat,
328 .maxlen = sizeof(int),
329 .mode = 0644,
330 .proc_handler = &proc_dointvec,
331 },
332#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 .ctl_name = KERN_PANIC,
335 .procname = "panic",
336 .data = &panic_timeout,
337 .maxlen = sizeof(int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341 {
342 .ctl_name = KERN_CORE_USES_PID,
343 .procname = "core_uses_pid",
344 .data = &core_uses_pid,
345 .maxlen = sizeof(int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
348 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700349#ifdef CONFIG_AUDITSYSCALL
350 {
351 .ctl_name = CTL_UNNUMBERED,
352 .procname = "audit_argv_kb",
353 .data = &audit_argv_kb,
354 .maxlen = sizeof(int),
355 .mode = 0644,
356 .proc_handler = &proc_dointvec,
357 },
358#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 {
360 .ctl_name = KERN_CORE_PATTERN,
361 .procname = "core_pattern",
362 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700363 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 .mode = 0644,
365 .proc_handler = &proc_dostring,
366 .strategy = &sysctl_string,
367 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800368#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 .procname = "tainted",
371 .data = &tainted,
372 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800373 .mode = 0644,
374 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800376#endif
Andrew Morgan72c2d582007-10-18 03:05:59 -0700377#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 .procname = "cap-bound",
380 .data = &cap_bset,
381 .maxlen = sizeof(kernel_cap_t),
382 .mode = 0600,
383 .proc_handler = &proc_dointvec_bset,
384 },
Andrew Morgan72c2d582007-10-18 03:05:59 -0700385#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386#ifdef CONFIG_BLK_DEV_INITRD
387 {
388 .ctl_name = KERN_REALROOTDEV,
389 .procname = "real-root-dev",
390 .data = &real_root_dev,
391 .maxlen = sizeof(int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
394 },
395#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700396 {
397 .ctl_name = CTL_UNNUMBERED,
398 .procname = "print-fatal-signals",
399 .data = &print_fatal_signals,
400 .maxlen = sizeof(int),
401 .mode = 0644,
402 .proc_handler = &proc_dointvec,
403 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#ifdef __sparc__
405 {
406 .ctl_name = KERN_SPARC_REBOOT,
407 .procname = "reboot-cmd",
408 .data = reboot_command,
409 .maxlen = 256,
410 .mode = 0644,
411 .proc_handler = &proc_dostring,
412 .strategy = &sysctl_string,
413 },
414 {
415 .ctl_name = KERN_SPARC_STOP_A,
416 .procname = "stop-a",
417 .data = &stop_a_enabled,
418 .maxlen = sizeof (int),
419 .mode = 0644,
420 .proc_handler = &proc_dointvec,
421 },
422 {
423 .ctl_name = KERN_SPARC_SCONS_PWROFF,
424 .procname = "scons-poweroff",
425 .data = &scons_pwroff,
426 .maxlen = sizeof (int),
427 .mode = 0644,
428 .proc_handler = &proc_dointvec,
429 },
430#endif
431#ifdef __hppa__
432 {
433 .ctl_name = KERN_HPPA_PWRSW,
434 .procname = "soft-power",
435 .data = &pwrsw_enabled,
436 .maxlen = sizeof (int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
439 },
440 {
441 .ctl_name = KERN_HPPA_UNALIGNED,
442 .procname = "unaligned-trap",
443 .data = &unaligned_enabled,
444 .maxlen = sizeof (int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
447 },
448#endif
449 {
450 .ctl_name = KERN_CTLALTDEL,
451 .procname = "ctrl-alt-del",
452 .data = &C_A_D,
453 .maxlen = sizeof(int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
456 },
457 {
458 .ctl_name = KERN_PRINTK,
459 .procname = "printk",
460 .data = &console_loglevel,
461 .maxlen = 4*sizeof(int),
462 .mode = 0644,
463 .proc_handler = &proc_dointvec,
464 },
465#ifdef CONFIG_KMOD
466 {
467 .ctl_name = KERN_MODPROBE,
468 .procname = "modprobe",
469 .data = &modprobe_path,
470 .maxlen = KMOD_PATH_LEN,
471 .mode = 0644,
472 .proc_handler = &proc_dostring,
473 .strategy = &sysctl_string,
474 },
475#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700476#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 {
478 .ctl_name = KERN_HOTPLUG,
479 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100480 .data = &uevent_helper,
481 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 .mode = 0644,
483 .proc_handler = &proc_dostring,
484 .strategy = &sysctl_string,
485 },
486#endif
487#ifdef CONFIG_CHR_DEV_SG
488 {
489 .ctl_name = KERN_SG_BIG_BUFF,
490 .procname = "sg-big-buff",
491 .data = &sg_big_buff,
492 .maxlen = sizeof (int),
493 .mode = 0444,
494 .proc_handler = &proc_dointvec,
495 },
496#endif
497#ifdef CONFIG_BSD_PROCESS_ACCT
498 {
499 .ctl_name = KERN_ACCT,
500 .procname = "acct",
501 .data = &acct_parm,
502 .maxlen = 3*sizeof(int),
503 .mode = 0644,
504 .proc_handler = &proc_dointvec,
505 },
506#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#ifdef CONFIG_MAGIC_SYSRQ
508 {
509 .ctl_name = KERN_SYSRQ,
510 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800511 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 .maxlen = sizeof (int),
513 .mode = 0644,
514 .proc_handler = &proc_dointvec,
515 },
516#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700517#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700520 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 .maxlen = sizeof (int),
522 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700523 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700525#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 {
527 .ctl_name = KERN_MAX_THREADS,
528 .procname = "threads-max",
529 .data = &max_threads,
530 .maxlen = sizeof(int),
531 .mode = 0644,
532 .proc_handler = &proc_dointvec,
533 },
534 {
535 .ctl_name = KERN_RANDOM,
536 .procname = "random",
537 .mode = 0555,
538 .child = random_table,
539 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
541 .ctl_name = KERN_OVERFLOWUID,
542 .procname = "overflowuid",
543 .data = &overflowuid,
544 .maxlen = sizeof(int),
545 .mode = 0644,
546 .proc_handler = &proc_dointvec_minmax,
547 .strategy = &sysctl_intvec,
548 .extra1 = &minolduid,
549 .extra2 = &maxolduid,
550 },
551 {
552 .ctl_name = KERN_OVERFLOWGID,
553 .procname = "overflowgid",
554 .data = &overflowgid,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 .proc_handler = &proc_dointvec_minmax,
558 .strategy = &sysctl_intvec,
559 .extra1 = &minolduid,
560 .extra2 = &maxolduid,
561 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800562#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#ifdef CONFIG_MATHEMU
564 {
565 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
566 .procname = "ieee_emulation_warnings",
567 .data = &sysctl_ieee_emulation_warnings,
568 .maxlen = sizeof(int),
569 .mode = 0644,
570 .proc_handler = &proc_dointvec,
571 },
572#endif
573#ifdef CONFIG_NO_IDLE_HZ
574 {
575 .ctl_name = KERN_HZ_TIMER,
576 .procname = "hz_timer",
577 .data = &sysctl_hz_timer,
578 .maxlen = sizeof(int),
579 .mode = 0644,
580 .proc_handler = &proc_dointvec,
581 },
582#endif
583 {
584 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
585 .procname = "userprocess_debug",
586 .data = &sysctl_userprocess_debug,
587 .maxlen = sizeof(int),
588 .mode = 0644,
589 .proc_handler = &proc_dointvec,
590 },
591#endif
592 {
593 .ctl_name = KERN_PIDMAX,
594 .procname = "pid_max",
595 .data = &pid_max,
596 .maxlen = sizeof (int),
597 .mode = 0644,
598 .proc_handler = &proc_dointvec_minmax,
599 .strategy = sysctl_intvec,
600 .extra1 = &pid_max_min,
601 .extra2 = &pid_max_max,
602 },
603 {
604 .ctl_name = KERN_PANIC_ON_OOPS,
605 .procname = "panic_on_oops",
606 .data = &panic_on_oops,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec,
610 },
611 {
612 .ctl_name = KERN_PRINTK_RATELIMIT,
613 .procname = "printk_ratelimit",
614 .data = &printk_ratelimit_jiffies,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = &proc_dointvec_jiffies,
618 .strategy = &sysctl_jiffies,
619 },
620 {
621 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
622 .procname = "printk_ratelimit_burst",
623 .data = &printk_ratelimit_burst,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = &proc_dointvec,
627 },
628 {
629 .ctl_name = KERN_NGROUPS_MAX,
630 .procname = "ngroups_max",
631 .data = &ngroups_max,
632 .maxlen = sizeof (int),
633 .mode = 0444,
634 .proc_handler = &proc_dointvec,
635 },
636#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
637 {
638 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
639 .procname = "unknown_nmi_panic",
640 .data = &unknown_nmi_panic,
641 .maxlen = sizeof (int),
642 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200643 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 },
Don Zickus407984f2006-09-26 10:52:27 +0200645 {
Don Zickus407984f2006-09-26 10:52:27 +0200646 .procname = "nmi_watchdog",
647 .data = &nmi_watchdog_enabled,
648 .maxlen = sizeof (int),
649 .mode = 0644,
650 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 },
652#endif
653#if defined(CONFIG_X86)
654 {
Don Zickus8da5adda2006-09-26 10:52:27 +0200655 .ctl_name = KERN_PANIC_ON_NMI,
656 .procname = "panic_on_unrecovered_nmi",
657 .data = &panic_on_unrecovered_nmi,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 .proc_handler = &proc_dointvec,
661 },
662 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 .ctl_name = KERN_BOOTLOADER_TYPE,
664 .procname = "bootloader_type",
665 .data = &bootloader_type,
666 .maxlen = sizeof (int),
667 .mode = 0444,
668 .proc_handler = &proc_dointvec,
669 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100670 {
671 .ctl_name = CTL_UNNUMBERED,
672 .procname = "kstack_depth_to_print",
673 .data = &kstack_depth_to_print,
674 .maxlen = sizeof(int),
675 .mode = 0644,
676 .proc_handler = &proc_dointvec,
677 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800679#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 {
681 .ctl_name = KERN_RANDOMIZE,
682 .procname = "randomize_va_space",
683 .data = &randomize_va_space,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec,
687 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800688#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800689#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700690 {
691 .ctl_name = KERN_SPIN_RETRY,
692 .procname = "spin_retry",
693 .data = &spin_retry,
694 .maxlen = sizeof (int),
695 .mode = 0644,
696 .proc_handler = &proc_dointvec,
697 },
698#endif
Len Brown673d5b42007-07-28 03:33:16 -0400699#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800700 {
Pavel Machekc255d842006-02-20 18:27:58 -0800701 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700702 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800703 .maxlen = sizeof (unsigned long),
704 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800705 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800706 },
707#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800708#ifdef CONFIG_IA64
709 {
710 .ctl_name = KERN_IA64_UNALIGNED,
711 .procname = "ignore-unaligned-usertrap",
712 .data = &no_unaligned_warning,
713 .maxlen = sizeof (int),
714 .mode = 0644,
715 .proc_handler = &proc_dointvec,
716 },
717#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700718#ifdef CONFIG_DETECT_SOFTLOCKUP
719 {
720 .ctl_name = CTL_UNNUMBERED,
721 .procname = "softlockup_thresh",
722 .data = &softlockup_thresh,
723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = &proc_dointvec_minmax,
726 .strategy = &sysctl_intvec,
727 .extra1 = &one,
728 .extra2 = &sixty,
729 },
730#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200731#ifdef CONFIG_COMPAT
732 {
733 .ctl_name = KERN_COMPAT_LOG,
734 .procname = "compat-log",
735 .data = &compat_log,
736 .maxlen = sizeof (int),
737 .mode = 0644,
738 .proc_handler = &proc_dointvec,
739 },
740#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700741#ifdef CONFIG_RT_MUTEXES
742 {
743 .ctl_name = KERN_MAX_LOCK_DEPTH,
744 .procname = "max_lock_depth",
745 .data = &max_lock_depth,
746 .maxlen = sizeof(int),
747 .mode = 0644,
748 .proc_handler = &proc_dointvec,
749 },
750#endif
Kees Cook5096add2007-05-08 00:26:04 -0700751#ifdef CONFIG_PROC_FS
752 {
753 .ctl_name = CTL_UNNUMBERED,
754 .procname = "maps_protect",
755 .data = &maps_protect,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = &proc_dointvec,
759 },
760#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700761 {
762 .ctl_name = CTL_UNNUMBERED,
763 .procname = "poweroff_cmd",
764 .data = &poweroff_cmd,
765 .maxlen = POWEROFF_CMD_PATH_LEN,
766 .mode = 0644,
767 .proc_handler = &proc_dostring,
768 .strategy = &sysctl_string,
769 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700770/*
771 * NOTE: do not add new entries to this table unless you have read
772 * Documentation/sysctl/ctl_unnumbered.txt
773 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 { .ctl_name = 0 }
775};
776
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700777static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 {
779 .ctl_name = VM_OVERCOMMIT_MEMORY,
780 .procname = "overcommit_memory",
781 .data = &sysctl_overcommit_memory,
782 .maxlen = sizeof(sysctl_overcommit_memory),
783 .mode = 0644,
784 .proc_handler = &proc_dointvec,
785 },
786 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700787 .ctl_name = VM_PANIC_ON_OOM,
788 .procname = "panic_on_oom",
789 .data = &sysctl_panic_on_oom,
790 .maxlen = sizeof(sysctl_panic_on_oom),
791 .mode = 0644,
792 .proc_handler = &proc_dointvec,
793 },
794 {
David Rientjesfe071d72007-10-16 23:25:56 -0700795 .ctl_name = CTL_UNNUMBERED,
796 .procname = "oom_kill_allocating_task",
797 .data = &sysctl_oom_kill_allocating_task,
798 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
799 .mode = 0644,
800 .proc_handler = &proc_dointvec,
801 },
802 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 .ctl_name = VM_OVERCOMMIT_RATIO,
804 .procname = "overcommit_ratio",
805 .data = &sysctl_overcommit_ratio,
806 .maxlen = sizeof(sysctl_overcommit_ratio),
807 .mode = 0644,
808 .proc_handler = &proc_dointvec,
809 },
810 {
811 .ctl_name = VM_PAGE_CLUSTER,
812 .procname = "page-cluster",
813 .data = &page_cluster,
814 .maxlen = sizeof(int),
815 .mode = 0644,
816 .proc_handler = &proc_dointvec,
817 },
818 {
819 .ctl_name = VM_DIRTY_BACKGROUND,
820 .procname = "dirty_background_ratio",
821 .data = &dirty_background_ratio,
822 .maxlen = sizeof(dirty_background_ratio),
823 .mode = 0644,
824 .proc_handler = &proc_dointvec_minmax,
825 .strategy = &sysctl_intvec,
826 .extra1 = &zero,
827 .extra2 = &one_hundred,
828 },
829 {
830 .ctl_name = VM_DIRTY_RATIO,
831 .procname = "dirty_ratio",
832 .data = &vm_dirty_ratio,
833 .maxlen = sizeof(vm_dirty_ratio),
834 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700835 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 .strategy = &sysctl_intvec,
837 .extra1 = &zero,
838 .extra2 = &one_hundred,
839 },
840 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800842 .data = &dirty_writeback_interval,
843 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 .mode = 0644,
845 .proc_handler = &dirty_writeback_centisecs_handler,
846 },
847 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800849 .data = &dirty_expire_interval,
850 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800852 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 },
854 {
855 .ctl_name = VM_NR_PDFLUSH_THREADS,
856 .procname = "nr_pdflush_threads",
857 .data = &nr_pdflush_threads,
858 .maxlen = sizeof nr_pdflush_threads,
859 .mode = 0444 /* read-only*/,
860 .proc_handler = &proc_dointvec,
861 },
862 {
863 .ctl_name = VM_SWAPPINESS,
864 .procname = "swappiness",
865 .data = &vm_swappiness,
866 .maxlen = sizeof(vm_swappiness),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec_minmax,
869 .strategy = &sysctl_intvec,
870 .extra1 = &zero,
871 .extra2 = &one_hundred,
872 },
873#ifdef CONFIG_HUGETLB_PAGE
874 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 .procname = "nr_hugepages",
876 .data = &max_huge_pages,
877 .maxlen = sizeof(unsigned long),
878 .mode = 0644,
879 .proc_handler = &hugetlb_sysctl_handler,
880 .extra1 = (void *)&hugetlb_zero,
881 .extra2 = (void *)&hugetlb_infinity,
882 },
883 {
884 .ctl_name = VM_HUGETLB_GROUP,
885 .procname = "hugetlb_shm_group",
886 .data = &sysctl_hugetlb_shm_group,
887 .maxlen = sizeof(gid_t),
888 .mode = 0644,
889 .proc_handler = &proc_dointvec,
890 },
Mel Gorman396faf02007-07-17 04:03:13 -0700891 {
892 .ctl_name = CTL_UNNUMBERED,
893 .procname = "hugepages_treat_as_movable",
894 .data = &hugepages_treat_as_movable,
895 .maxlen = sizeof(int),
896 .mode = 0644,
897 .proc_handler = &hugetlb_treat_movable_handler,
898 },
Adam Litke54f9f802007-10-16 01:26:20 -0700899 {
900 .ctl_name = CTL_UNNUMBERED,
901 .procname = "hugetlb_dynamic_pool",
902 .data = &hugetlb_dynamic_pool,
903 .maxlen = sizeof(hugetlb_dynamic_pool),
904 .mode = 0644,
905 .proc_handler = &proc_dointvec,
906 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907#endif
908 {
909 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
910 .procname = "lowmem_reserve_ratio",
911 .data = &sysctl_lowmem_reserve_ratio,
912 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
913 .mode = 0644,
914 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
915 .strategy = &sysctl_intvec,
916 },
917 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800918 .ctl_name = VM_DROP_PAGECACHE,
919 .procname = "drop_caches",
920 .data = &sysctl_drop_caches,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = drop_caches_sysctl_handler,
924 .strategy = &sysctl_intvec,
925 },
926 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 .ctl_name = VM_MIN_FREE_KBYTES,
928 .procname = "min_free_kbytes",
929 .data = &min_free_kbytes,
930 .maxlen = sizeof(min_free_kbytes),
931 .mode = 0644,
932 .proc_handler = &min_free_kbytes_sysctl_handler,
933 .strategy = &sysctl_intvec,
934 .extra1 = &zero,
935 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800936 {
937 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
938 .procname = "percpu_pagelist_fraction",
939 .data = &percpu_pagelist_fraction,
940 .maxlen = sizeof(percpu_pagelist_fraction),
941 .mode = 0644,
942 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
943 .strategy = &sysctl_intvec,
944 .extra1 = &min_percpu_pagelist_fract,
945 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946#ifdef CONFIG_MMU
947 {
948 .ctl_name = VM_MAX_MAP_COUNT,
949 .procname = "max_map_count",
950 .data = &sysctl_max_map_count,
951 .maxlen = sizeof(sysctl_max_map_count),
952 .mode = 0644,
953 .proc_handler = &proc_dointvec
954 },
955#endif
956 {
957 .ctl_name = VM_LAPTOP_MODE,
958 .procname = "laptop_mode",
959 .data = &laptop_mode,
960 .maxlen = sizeof(laptop_mode),
961 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800962 .proc_handler = &proc_dointvec_jiffies,
963 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 },
965 {
966 .ctl_name = VM_BLOCK_DUMP,
967 .procname = "block_dump",
968 .data = &block_dump,
969 .maxlen = sizeof(block_dump),
970 .mode = 0644,
971 .proc_handler = &proc_dointvec,
972 .strategy = &sysctl_intvec,
973 .extra1 = &zero,
974 },
975 {
976 .ctl_name = VM_VFS_CACHE_PRESSURE,
977 .procname = "vfs_cache_pressure",
978 .data = &sysctl_vfs_cache_pressure,
979 .maxlen = sizeof(sysctl_vfs_cache_pressure),
980 .mode = 0644,
981 .proc_handler = &proc_dointvec,
982 .strategy = &sysctl_intvec,
983 .extra1 = &zero,
984 },
985#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
986 {
987 .ctl_name = VM_LEGACY_VA_LAYOUT,
988 .procname = "legacy_va_layout",
989 .data = &sysctl_legacy_va_layout,
990 .maxlen = sizeof(sysctl_legacy_va_layout),
991 .mode = 0644,
992 .proc_handler = &proc_dointvec,
993 .strategy = &sysctl_intvec,
994 .extra1 = &zero,
995 },
996#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800997#ifdef CONFIG_NUMA
998 {
999 .ctl_name = VM_ZONE_RECLAIM_MODE,
1000 .procname = "zone_reclaim_mode",
1001 .data = &zone_reclaim_mode,
1002 .maxlen = sizeof(zone_reclaim_mode),
1003 .mode = 0644,
1004 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001005 .strategy = &sysctl_intvec,
1006 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001007 },
Christoph Lameter96146342006-07-03 00:24:13 -07001008 {
1009 .ctl_name = VM_MIN_UNMAPPED,
1010 .procname = "min_unmapped_ratio",
1011 .data = &sysctl_min_unmapped_ratio,
1012 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1013 .mode = 0644,
1014 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1015 .strategy = &sysctl_intvec,
1016 .extra1 = &zero,
1017 .extra2 = &one_hundred,
1018 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001019 {
1020 .ctl_name = VM_MIN_SLAB,
1021 .procname = "min_slab_ratio",
1022 .data = &sysctl_min_slab_ratio,
1023 .maxlen = sizeof(sysctl_min_slab_ratio),
1024 .mode = 0644,
1025 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1026 .strategy = &sysctl_intvec,
1027 .extra1 = &zero,
1028 .extra2 = &one_hundred,
1029 },
Christoph Lameter17436602006-01-18 17:42:32 -08001030#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001031#ifdef CONFIG_SMP
1032 {
1033 .ctl_name = CTL_UNNUMBERED,
1034 .procname = "stat_interval",
1035 .data = &sysctl_stat_interval,
1036 .maxlen = sizeof(sysctl_stat_interval),
1037 .mode = 0644,
1038 .proc_handler = &proc_dointvec_jiffies,
1039 .strategy = &sysctl_jiffies,
1040 },
1041#endif
Eric Parised032182007-06-28 15:55:21 -04001042#ifdef CONFIG_SECURITY
1043 {
1044 .ctl_name = CTL_UNNUMBERED,
1045 .procname = "mmap_min_addr",
1046 .data = &mmap_min_addr,
1047 .maxlen = sizeof(unsigned long),
1048 .mode = 0644,
1049 .proc_handler = &proc_doulongvec_minmax,
1050 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001051#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001052#ifdef CONFIG_NUMA
1053 {
1054 .ctl_name = CTL_UNNUMBERED,
1055 .procname = "numa_zonelist_order",
1056 .data = &numa_zonelist_order,
1057 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1058 .mode = 0644,
1059 .proc_handler = &numa_zonelist_order_handler,
1060 .strategy = &sysctl_string,
1061 },
1062#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001063#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001064 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001065 {
1066 .ctl_name = VM_VDSO_ENABLED,
1067 .procname = "vdso_enabled",
1068 .data = &vdso_enabled,
1069 .maxlen = sizeof(vdso_enabled),
1070 .mode = 0644,
1071 .proc_handler = &proc_dointvec,
1072 .strategy = &sysctl_intvec,
1073 .extra1 = &zero,
1074 },
1075#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001076/*
1077 * NOTE: do not add new entries to this table unless you have read
1078 * Documentation/sysctl/ctl_unnumbered.txt
1079 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 { .ctl_name = 0 }
1081};
1082
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001083#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001084static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001085 { .ctl_name = 0 }
1086};
1087#endif
1088
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001089static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 {
1091 .ctl_name = FS_NRINODE,
1092 .procname = "inode-nr",
1093 .data = &inodes_stat,
1094 .maxlen = 2*sizeof(int),
1095 .mode = 0444,
1096 .proc_handler = &proc_dointvec,
1097 },
1098 {
1099 .ctl_name = FS_STATINODE,
1100 .procname = "inode-state",
1101 .data = &inodes_stat,
1102 .maxlen = 7*sizeof(int),
1103 .mode = 0444,
1104 .proc_handler = &proc_dointvec,
1105 },
1106 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 .procname = "file-nr",
1108 .data = &files_stat,
1109 .maxlen = 3*sizeof(int),
1110 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001111 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 },
1113 {
1114 .ctl_name = FS_MAXFILE,
1115 .procname = "file-max",
1116 .data = &files_stat.max_files,
1117 .maxlen = sizeof(int),
1118 .mode = 0644,
1119 .proc_handler = &proc_dointvec,
1120 },
1121 {
1122 .ctl_name = FS_DENTRY,
1123 .procname = "dentry-state",
1124 .data = &dentry_stat,
1125 .maxlen = 6*sizeof(int),
1126 .mode = 0444,
1127 .proc_handler = &proc_dointvec,
1128 },
1129 {
1130 .ctl_name = FS_OVERFLOWUID,
1131 .procname = "overflowuid",
1132 .data = &fs_overflowuid,
1133 .maxlen = sizeof(int),
1134 .mode = 0644,
1135 .proc_handler = &proc_dointvec_minmax,
1136 .strategy = &sysctl_intvec,
1137 .extra1 = &minolduid,
1138 .extra2 = &maxolduid,
1139 },
1140 {
1141 .ctl_name = FS_OVERFLOWGID,
1142 .procname = "overflowgid",
1143 .data = &fs_overflowgid,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = &proc_dointvec_minmax,
1147 .strategy = &sysctl_intvec,
1148 .extra1 = &minolduid,
1149 .extra2 = &maxolduid,
1150 },
1151 {
1152 .ctl_name = FS_LEASES,
1153 .procname = "leases-enable",
1154 .data = &leases_enable,
1155 .maxlen = sizeof(int),
1156 .mode = 0644,
1157 .proc_handler = &proc_dointvec,
1158 },
1159#ifdef CONFIG_DNOTIFY
1160 {
1161 .ctl_name = FS_DIR_NOTIFY,
1162 .procname = "dir-notify-enable",
1163 .data = &dir_notify_enable,
1164 .maxlen = sizeof(int),
1165 .mode = 0644,
1166 .proc_handler = &proc_dointvec,
1167 },
1168#endif
1169#ifdef CONFIG_MMU
1170 {
1171 .ctl_name = FS_LEASE_TIME,
1172 .procname = "lease-break-time",
1173 .data = &lease_break_time,
1174 .maxlen = sizeof(int),
1175 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001176 .proc_handler = &proc_dointvec_minmax,
1177 .strategy = &sysctl_intvec,
1178 .extra1 = &zero,
1179 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 },
1181 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 .procname = "aio-nr",
1183 .data = &aio_nr,
1184 .maxlen = sizeof(aio_nr),
1185 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001186 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 },
1188 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 .procname = "aio-max-nr",
1190 .data = &aio_max_nr,
1191 .maxlen = sizeof(aio_max_nr),
1192 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001193 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001195#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001196 {
1197 .ctl_name = FS_INOTIFY,
1198 .procname = "inotify",
1199 .mode = 0555,
1200 .child = inotify_table,
1201 },
1202#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001204 {
1205 .ctl_name = KERN_SETUID_DUMPABLE,
1206 .procname = "suid_dumpable",
1207 .data = &suid_dumpable,
1208 .maxlen = sizeof(int),
1209 .mode = 0644,
1210 .proc_handler = &proc_dointvec,
1211 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001212#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1213 {
1214 .ctl_name = CTL_UNNUMBERED,
1215 .procname = "binfmt_misc",
1216 .mode = 0555,
1217 .child = binfmt_misc_table,
1218 },
1219#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001220/*
1221 * NOTE: do not add new entries to this table unless you have read
1222 * Documentation/sysctl/ctl_unnumbered.txt
1223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 { .ctl_name = 0 }
1225};
1226
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001227static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001228#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001229 {
1230 .ctl_name = CTL_UNNUMBERED,
1231 .procname = "exception-trace",
1232 .data = &show_unhandled_signals,
1233 .maxlen = sizeof(int),
1234 .mode = 0644,
1235 .proc_handler = proc_dointvec
1236 },
1237#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 { .ctl_name = 0 }
1239};
1240
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001241static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001243};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Al Viro330d57f2005-11-04 10:18:40 +00001245static DEFINE_SPINLOCK(sysctl_lock);
1246
1247/* called under sysctl_lock */
1248static int use_table(struct ctl_table_header *p)
1249{
1250 if (unlikely(p->unregistering))
1251 return 0;
1252 p->used++;
1253 return 1;
1254}
1255
1256/* called under sysctl_lock */
1257static void unuse_table(struct ctl_table_header *p)
1258{
1259 if (!--p->used)
1260 if (unlikely(p->unregistering))
1261 complete(p->unregistering);
1262}
1263
1264/* called under sysctl_lock, will reacquire if has to wait */
1265static void start_unregistering(struct ctl_table_header *p)
1266{
1267 /*
1268 * if p->used is 0, nobody will ever touch that entry again;
1269 * we'll eliminate all paths to it before dropping sysctl_lock
1270 */
1271 if (unlikely(p->used)) {
1272 struct completion wait;
1273 init_completion(&wait);
1274 p->unregistering = &wait;
1275 spin_unlock(&sysctl_lock);
1276 wait_for_completion(&wait);
1277 spin_lock(&sysctl_lock);
1278 }
1279 /*
1280 * do not remove from the list until nobody holds it; walking the
1281 * list in do_sysctl() relies on that.
1282 */
1283 list_del_init(&p->ctl_entry);
1284}
1285
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001286void sysctl_head_finish(struct ctl_table_header *head)
1287{
1288 if (!head)
1289 return;
1290 spin_lock(&sysctl_lock);
1291 unuse_table(head);
1292 spin_unlock(&sysctl_lock);
1293}
1294
1295struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1296{
1297 struct ctl_table_header *head;
1298 struct list_head *tmp;
1299 spin_lock(&sysctl_lock);
1300 if (prev) {
1301 tmp = &prev->ctl_entry;
1302 unuse_table(prev);
1303 goto next;
1304 }
1305 tmp = &root_table_header.ctl_entry;
1306 for (;;) {
1307 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1308
1309 if (!use_table(head))
1310 goto next;
1311 spin_unlock(&sysctl_lock);
1312 return head;
1313 next:
1314 tmp = tmp->next;
1315 if (tmp == &root_table_header.ctl_entry)
1316 break;
1317 }
1318 spin_unlock(&sysctl_lock);
1319 return NULL;
1320}
1321
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001322#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1324 void __user *newval, size_t newlen)
1325{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001326 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001327 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
1329 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1330 return -ENOTDIR;
1331 if (oldval) {
1332 int old_len;
1333 if (!oldlenp || get_user(old_len, oldlenp))
1334 return -EFAULT;
1335 }
Al Viro330d57f2005-11-04 10:18:40 +00001336
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001337 for (head = sysctl_head_next(NULL); head;
1338 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001339 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001340 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001341 if (error != -ENOTDIR) {
1342 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001343 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001344 }
1345 }
Al Viro330d57f2005-11-04 10:18:40 +00001346 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
1349asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1350{
1351 struct __sysctl_args tmp;
1352 int error;
1353
1354 if (copy_from_user(&tmp, args, sizeof(tmp)))
1355 return -EFAULT;
1356
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001357 error = deprecated_sysctl_warning(&tmp);
1358 if (error)
1359 goto out;
1360
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 lock_kernel();
1362 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1363 tmp.newval, tmp.newlen);
1364 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001365out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 return error;
1367}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001368#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
1370/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001371 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 * some sysctl variables are readonly even to root.
1373 */
1374
1375static int test_perm(int mode, int op)
1376{
1377 if (!current->euid)
1378 mode >>= 6;
1379 else if (in_egroup_p(0))
1380 mode >>= 3;
1381 if ((mode & op & 0007) == op)
1382 return 0;
1383 return -EACCES;
1384}
1385
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001386int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
1388 int error;
1389 error = security_sysctl(table, op);
1390 if (error)
1391 return error;
1392 return test_perm(table->mode, op);
1393}
1394
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001395#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396static int parse_table(int __user *name, int nlen,
1397 void __user *oldval, size_t __user *oldlenp,
1398 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001399 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400{
1401 int n;
1402repeat:
1403 if (!nlen)
1404 return -ENOTDIR;
1405 if (get_user(n, name))
1406 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001407 for ( ; table->ctl_name || table->procname; table++) {
1408 if (!table->ctl_name)
1409 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001410 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 int error;
1412 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001413 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 name++;
1416 nlen--;
1417 table = table->child;
1418 goto repeat;
1419 }
1420 error = do_sysctl_strategy(table, name, nlen,
1421 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001422 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 return error;
1424 }
1425 }
1426 return -ENOTDIR;
1427}
1428
1429/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001430int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 int __user *name, int nlen,
1432 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001433 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434{
1435 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
1437 if (oldval)
1438 op |= 004;
1439 if (newval)
1440 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001441 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 return -EPERM;
1443
1444 if (table->strategy) {
1445 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001446 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 if (rc < 0)
1448 return rc;
1449 if (rc > 0)
1450 return 0;
1451 }
1452
1453 /* If there is no strategy routine, or if the strategy returns
1454 * zero, proceed with automatic r/w */
1455 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001456 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1457 newval, newlen);
1458 if (rc < 0)
1459 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 }
1461 return 0;
1462}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001463#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001465static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1466{
1467 for (; table->ctl_name || table->procname; table++) {
1468 table->parent = parent;
1469 if (table->child)
1470 sysctl_set_parent(table, table->child);
1471 }
1472}
1473
1474static __init int sysctl_init(void)
1475{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001476 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001477 sysctl_set_parent(NULL, root_table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001478 err = sysctl_check_table(root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001479 return 0;
1480}
1481
1482core_initcall(sysctl_init);
1483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484/**
1485 * register_sysctl_table - register a sysctl hierarchy
1486 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 *
1488 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1489 * array. An entry with a ctl_name of 0 terminates the table.
1490 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001491 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 *
1493 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1494 * must be unique within that level of sysctl
1495 *
1496 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1497 * enter a sysctl file
1498 *
1499 * data - a pointer to data for use by proc_handler
1500 *
1501 * maxlen - the maximum size in bytes of the data
1502 *
1503 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1504 *
1505 * child - a pointer to the child sysctl table if this entry is a directory, or
1506 * %NULL.
1507 *
1508 * proc_handler - the text handler routine (described below)
1509 *
1510 * strategy - the strategy routine (described below)
1511 *
1512 * de - for internal use by the sysctl routines
1513 *
1514 * extra1, extra2 - extra pointers usable by the proc handler routines
1515 *
1516 * Leaf nodes in the sysctl tree will be represented by a single file
1517 * under /proc; non-leaf nodes will be represented by directories.
1518 *
1519 * sysctl(2) can automatically manage read and write requests through
1520 * the sysctl table. The data and maxlen fields of the ctl_table
1521 * struct enable minimal validation of the values being written to be
1522 * performed, and the mode field allows minimal authentication.
1523 *
1524 * More sophisticated management can be enabled by the provision of a
1525 * strategy routine with the table entry. This will be called before
1526 * any automatic read or write of the data is performed.
1527 *
1528 * The strategy routine may return
1529 *
1530 * < 0 - Error occurred (error is passed to user process)
1531 *
1532 * 0 - OK - proceed with automatic read or write.
1533 *
1534 * > 0 - OK - read or write has been done by the strategy routine, so
1535 * return immediately.
1536 *
1537 * There must be a proc_handler routine for any terminal nodes
1538 * mirrored under /proc/sys (non-terminals are handled by a built-in
1539 * directory handler). Several default handlers are available to
1540 * cover common cases -
1541 *
1542 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1543 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1544 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1545 *
1546 * It is the handler's job to read the input buffer from user memory
1547 * and process it. The handler should return 0 on success.
1548 *
1549 * This routine returns %NULL on a failure to register, and a pointer
1550 * to the table header on success.
1551 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001552struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553{
1554 struct ctl_table_header *tmp;
1555 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1556 if (!tmp)
1557 return NULL;
1558 tmp->ctl_table = table;
1559 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001560 tmp->used = 0;
1561 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001562 sysctl_set_parent(NULL, table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001563 if (sysctl_check_table(tmp->ctl_table)) {
1564 kfree(tmp);
1565 return NULL;
1566 }
Al Viro330d57f2005-11-04 10:18:40 +00001567 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001568 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001569 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 return tmp;
1571}
1572
1573/**
1574 * unregister_sysctl_table - unregister a sysctl table hierarchy
1575 * @header: the header returned from register_sysctl_table
1576 *
1577 * Unregisters the sysctl table and all children. proc entries may not
1578 * actually be removed until they are no longer used by anyone.
1579 */
1580void unregister_sysctl_table(struct ctl_table_header * header)
1581{
Al Viro330d57f2005-11-04 10:18:40 +00001582 might_sleep();
1583 spin_lock(&sysctl_lock);
1584 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001585 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 kfree(header);
1587}
1588
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001589#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001590struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001591{
1592 return NULL;
1593}
1594
1595void unregister_sysctl_table(struct ctl_table_header * table)
1596{
1597}
1598
1599#endif /* CONFIG_SYSCTL */
1600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601/*
1602 * /proc/sys support
1603 */
1604
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001605#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001607static int _proc_do_string(void* data, int maxlen, int write,
1608 struct file *filp, void __user *buffer,
1609 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001610{
1611 size_t len;
1612 char __user *p;
1613 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001614
1615 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001616 *lenp = 0;
1617 return 0;
1618 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001619
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001620 if (write) {
1621 len = 0;
1622 p = buffer;
1623 while (len < *lenp) {
1624 if (get_user(c, p++))
1625 return -EFAULT;
1626 if (c == 0 || c == '\n')
1627 break;
1628 len++;
1629 }
1630 if (len >= maxlen)
1631 len = maxlen-1;
1632 if(copy_from_user(data, buffer, len))
1633 return -EFAULT;
1634 ((char *) data)[len] = 0;
1635 *ppos += *lenp;
1636 } else {
1637 len = strlen(data);
1638 if (len > maxlen)
1639 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001640
1641 if (*ppos > len) {
1642 *lenp = 0;
1643 return 0;
1644 }
1645
1646 data += *ppos;
1647 len -= *ppos;
1648
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001649 if (len > *lenp)
1650 len = *lenp;
1651 if (len)
1652 if(copy_to_user(buffer, data, len))
1653 return -EFAULT;
1654 if (len < *lenp) {
1655 if(put_user('\n', ((char __user *) buffer) + len))
1656 return -EFAULT;
1657 len++;
1658 }
1659 *lenp = len;
1660 *ppos += len;
1661 }
1662 return 0;
1663}
1664
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665/**
1666 * proc_dostring - read a string sysctl
1667 * @table: the sysctl table
1668 * @write: %TRUE if this is a write to the sysctl file
1669 * @filp: the file structure
1670 * @buffer: the user buffer
1671 * @lenp: the size of the user buffer
1672 * @ppos: file position
1673 *
1674 * Reads/writes a string from/to the user buffer. If the kernel
1675 * buffer provided is not large enough to hold the string, the
1676 * string is truncated. The copied string is %NULL-terminated.
1677 * If the string is being read by the user process, it is copied
1678 * and a newline '\n' is added. It is truncated if the buffer is
1679 * not large enough.
1680 *
1681 * Returns 0 on success.
1682 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001683int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 void __user *buffer, size_t *lenp, loff_t *ppos)
1685{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001686 return _proc_do_string(table->data, table->maxlen, write, filp,
1687 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
1691static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1692 int *valp,
1693 int write, void *data)
1694{
1695 if (write) {
1696 *valp = *negp ? -*lvalp : *lvalp;
1697 } else {
1698 int val = *valp;
1699 if (val < 0) {
1700 *negp = -1;
1701 *lvalp = (unsigned long)-val;
1702 } else {
1703 *negp = 0;
1704 *lvalp = (unsigned long)val;
1705 }
1706 }
1707 return 0;
1708}
1709
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001710static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001711 int write, struct file *filp, void __user *buffer,
1712 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1714 int write, void *data),
1715 void *data)
1716{
1717#define TMPBUFLEN 21
1718 int *i, vleft, first=1, neg, val;
1719 unsigned long lval;
1720 size_t left, len;
1721
1722 char buf[TMPBUFLEN], *p;
1723 char __user *s = buffer;
1724
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001725 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 (*ppos && !write)) {
1727 *lenp = 0;
1728 return 0;
1729 }
1730
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001731 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 vleft = table->maxlen / sizeof(*i);
1733 left = *lenp;
1734
1735 if (!conv)
1736 conv = do_proc_dointvec_conv;
1737
1738 for (; left && vleft--; i++, first=0) {
1739 if (write) {
1740 while (left) {
1741 char c;
1742 if (get_user(c, s))
1743 return -EFAULT;
1744 if (!isspace(c))
1745 break;
1746 left--;
1747 s++;
1748 }
1749 if (!left)
1750 break;
1751 neg = 0;
1752 len = left;
1753 if (len > sizeof(buf) - 1)
1754 len = sizeof(buf) - 1;
1755 if (copy_from_user(buf, s, len))
1756 return -EFAULT;
1757 buf[len] = 0;
1758 p = buf;
1759 if (*p == '-' && left > 1) {
1760 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001761 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 }
1763 if (*p < '0' || *p > '9')
1764 break;
1765
1766 lval = simple_strtoul(p, &p, 0);
1767
1768 len = p-buf;
1769 if ((len < left) && *p && !isspace(*p))
1770 break;
1771 if (neg)
1772 val = -val;
1773 s += len;
1774 left -= len;
1775
1776 if (conv(&neg, &lval, i, 1, data))
1777 break;
1778 } else {
1779 p = buf;
1780 if (!first)
1781 *p++ = '\t';
1782
1783 if (conv(&neg, &lval, i, 0, data))
1784 break;
1785
1786 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1787 len = strlen(buf);
1788 if (len > left)
1789 len = left;
1790 if(copy_to_user(s, buf, len))
1791 return -EFAULT;
1792 left -= len;
1793 s += len;
1794 }
1795 }
1796
1797 if (!write && !first && left) {
1798 if(put_user('\n', s))
1799 return -EFAULT;
1800 left--, s++;
1801 }
1802 if (write) {
1803 while (left) {
1804 char c;
1805 if (get_user(c, s++))
1806 return -EFAULT;
1807 if (!isspace(c))
1808 break;
1809 left--;
1810 }
1811 }
1812 if (write && first)
1813 return -EINVAL;
1814 *lenp -= left;
1815 *ppos += *lenp;
1816 return 0;
1817#undef TMPBUFLEN
1818}
1819
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001820static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001821 void __user *buffer, size_t *lenp, loff_t *ppos,
1822 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1823 int write, void *data),
1824 void *data)
1825{
1826 return __do_proc_dointvec(table->data, table, write, filp,
1827 buffer, lenp, ppos, conv, data);
1828}
1829
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830/**
1831 * proc_dointvec - read a vector of integers
1832 * @table: the sysctl table
1833 * @write: %TRUE if this is a write to the sysctl file
1834 * @filp: the file structure
1835 * @buffer: the user buffer
1836 * @lenp: the size of the user buffer
1837 * @ppos: file position
1838 *
1839 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1840 * values from/to the user buffer, treated as an ASCII string.
1841 *
1842 * Returns 0 on success.
1843 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001844int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 void __user *buffer, size_t *lenp, loff_t *ppos)
1846{
1847 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1848 NULL,NULL);
1849}
1850
1851#define OP_SET 0
1852#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001853#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
1855static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1856 int *valp,
1857 int write, void *data)
1858{
1859 int op = *(int *)data;
1860 if (write) {
1861 int val = *negp ? -*lvalp : *lvalp;
1862 switch(op) {
1863 case OP_SET: *valp = val; break;
1864 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001865 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 }
1867 } else {
1868 int val = *valp;
1869 if (val < 0) {
1870 *negp = -1;
1871 *lvalp = (unsigned long)-val;
1872 } else {
1873 *negp = 0;
1874 *lvalp = (unsigned long)val;
1875 }
1876 }
1877 return 0;
1878}
1879
Andrew Morgan72c2d582007-10-18 03:05:59 -07001880#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881/*
1882 * init may raise the set.
1883 */
Andrew Morgan72c2d582007-10-18 03:05:59 -07001884
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001885int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 void __user *buffer, size_t *lenp, loff_t *ppos)
1887{
1888 int op;
1889
Eric Paris6ff1b442007-02-10 01:43:19 -08001890 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 return -EPERM;
1892 }
1893
Serge E. Hallynb460cbc2007-10-18 23:39:52 -07001894 op = is_global_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1896 do_proc_dointvec_bset_conv,&op);
1897}
Andrew Morgan72c2d582007-10-18 03:05:59 -07001898#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001900/*
1901 * Taint values can only be increased
1902 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001903static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001904 void __user *buffer, size_t *lenp, loff_t *ppos)
1905{
1906 int op;
1907
Bastian Blank91fcd412007-04-23 14:41:14 -07001908 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001909 return -EPERM;
1910
1911 op = OP_OR;
1912 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1913 do_proc_dointvec_bset_conv,&op);
1914}
1915
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916struct do_proc_dointvec_minmax_conv_param {
1917 int *min;
1918 int *max;
1919};
1920
1921static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1922 int *valp,
1923 int write, void *data)
1924{
1925 struct do_proc_dointvec_minmax_conv_param *param = data;
1926 if (write) {
1927 int val = *negp ? -*lvalp : *lvalp;
1928 if ((param->min && *param->min > val) ||
1929 (param->max && *param->max < val))
1930 return -EINVAL;
1931 *valp = val;
1932 } else {
1933 int val = *valp;
1934 if (val < 0) {
1935 *negp = -1;
1936 *lvalp = (unsigned long)-val;
1937 } else {
1938 *negp = 0;
1939 *lvalp = (unsigned long)val;
1940 }
1941 }
1942 return 0;
1943}
1944
1945/**
1946 * proc_dointvec_minmax - read a vector of integers with min/max values
1947 * @table: the sysctl table
1948 * @write: %TRUE if this is a write to the sysctl file
1949 * @filp: the file structure
1950 * @buffer: the user buffer
1951 * @lenp: the size of the user buffer
1952 * @ppos: file position
1953 *
1954 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1955 * values from/to the user buffer, treated as an ASCII string.
1956 *
1957 * This routine will ensure the values are within the range specified by
1958 * table->extra1 (min) and table->extra2 (max).
1959 *
1960 * Returns 0 on success.
1961 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001962int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 void __user *buffer, size_t *lenp, loff_t *ppos)
1964{
1965 struct do_proc_dointvec_minmax_conv_param param = {
1966 .min = (int *) table->extra1,
1967 .max = (int *) table->extra2,
1968 };
1969 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1970 do_proc_dointvec_minmax_conv, &param);
1971}
1972
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001973static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 struct file *filp,
1975 void __user *buffer,
1976 size_t *lenp, loff_t *ppos,
1977 unsigned long convmul,
1978 unsigned long convdiv)
1979{
1980#define TMPBUFLEN 21
1981 unsigned long *i, *min, *max, val;
1982 int vleft, first=1, neg;
1983 size_t len, left;
1984 char buf[TMPBUFLEN], *p;
1985 char __user *s = buffer;
1986
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001987 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 (*ppos && !write)) {
1989 *lenp = 0;
1990 return 0;
1991 }
1992
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001993 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 min = (unsigned long *) table->extra1;
1995 max = (unsigned long *) table->extra2;
1996 vleft = table->maxlen / sizeof(unsigned long);
1997 left = *lenp;
1998
1999 for (; left && vleft--; i++, min++, max++, first=0) {
2000 if (write) {
2001 while (left) {
2002 char c;
2003 if (get_user(c, s))
2004 return -EFAULT;
2005 if (!isspace(c))
2006 break;
2007 left--;
2008 s++;
2009 }
2010 if (!left)
2011 break;
2012 neg = 0;
2013 len = left;
2014 if (len > TMPBUFLEN-1)
2015 len = TMPBUFLEN-1;
2016 if (copy_from_user(buf, s, len))
2017 return -EFAULT;
2018 buf[len] = 0;
2019 p = buf;
2020 if (*p == '-' && left > 1) {
2021 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002022 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 }
2024 if (*p < '0' || *p > '9')
2025 break;
2026 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2027 len = p-buf;
2028 if ((len < left) && *p && !isspace(*p))
2029 break;
2030 if (neg)
2031 val = -val;
2032 s += len;
2033 left -= len;
2034
2035 if(neg)
2036 continue;
2037 if ((min && val < *min) || (max && val > *max))
2038 continue;
2039 *i = val;
2040 } else {
2041 p = buf;
2042 if (!first)
2043 *p++ = '\t';
2044 sprintf(p, "%lu", convdiv * (*i) / convmul);
2045 len = strlen(buf);
2046 if (len > left)
2047 len = left;
2048 if(copy_to_user(s, buf, len))
2049 return -EFAULT;
2050 left -= len;
2051 s += len;
2052 }
2053 }
2054
2055 if (!write && !first && left) {
2056 if(put_user('\n', s))
2057 return -EFAULT;
2058 left--, s++;
2059 }
2060 if (write) {
2061 while (left) {
2062 char c;
2063 if (get_user(c, s++))
2064 return -EFAULT;
2065 if (!isspace(c))
2066 break;
2067 left--;
2068 }
2069 }
2070 if (write && first)
2071 return -EINVAL;
2072 *lenp -= left;
2073 *ppos += *lenp;
2074 return 0;
2075#undef TMPBUFLEN
2076}
2077
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002078static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002079 struct file *filp,
2080 void __user *buffer,
2081 size_t *lenp, loff_t *ppos,
2082 unsigned long convmul,
2083 unsigned long convdiv)
2084{
2085 return __do_proc_doulongvec_minmax(table->data, table, write,
2086 filp, buffer, lenp, ppos, convmul, convdiv);
2087}
2088
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089/**
2090 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2091 * @table: the sysctl table
2092 * @write: %TRUE if this is a write to the sysctl file
2093 * @filp: the file structure
2094 * @buffer: the user buffer
2095 * @lenp: the size of the user buffer
2096 * @ppos: file position
2097 *
2098 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2099 * values from/to the user buffer, treated as an ASCII string.
2100 *
2101 * This routine will ensure the values are within the range specified by
2102 * table->extra1 (min) and table->extra2 (max).
2103 *
2104 * Returns 0 on success.
2105 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002106int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 void __user *buffer, size_t *lenp, loff_t *ppos)
2108{
2109 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2110}
2111
2112/**
2113 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2114 * @table: the sysctl table
2115 * @write: %TRUE if this is a write to the sysctl file
2116 * @filp: the file structure
2117 * @buffer: the user buffer
2118 * @lenp: the size of the user buffer
2119 * @ppos: file position
2120 *
2121 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2122 * values from/to the user buffer, treated as an ASCII string. The values
2123 * are treated as milliseconds, and converted to jiffies when they are stored.
2124 *
2125 * This routine will ensure the values are within the range specified by
2126 * table->extra1 (min) and table->extra2 (max).
2127 *
2128 * Returns 0 on success.
2129 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002130int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct file *filp,
2132 void __user *buffer,
2133 size_t *lenp, loff_t *ppos)
2134{
2135 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2136 lenp, ppos, HZ, 1000l);
2137}
2138
2139
2140static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2141 int *valp,
2142 int write, void *data)
2143{
2144 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002145 if (*lvalp > LONG_MAX / HZ)
2146 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2148 } else {
2149 int val = *valp;
2150 unsigned long lval;
2151 if (val < 0) {
2152 *negp = -1;
2153 lval = (unsigned long)-val;
2154 } else {
2155 *negp = 0;
2156 lval = (unsigned long)val;
2157 }
2158 *lvalp = lval / HZ;
2159 }
2160 return 0;
2161}
2162
2163static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2164 int *valp,
2165 int write, void *data)
2166{
2167 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002168 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2169 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2171 } else {
2172 int val = *valp;
2173 unsigned long lval;
2174 if (val < 0) {
2175 *negp = -1;
2176 lval = (unsigned long)-val;
2177 } else {
2178 *negp = 0;
2179 lval = (unsigned long)val;
2180 }
2181 *lvalp = jiffies_to_clock_t(lval);
2182 }
2183 return 0;
2184}
2185
2186static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2187 int *valp,
2188 int write, void *data)
2189{
2190 if (write) {
2191 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2192 } else {
2193 int val = *valp;
2194 unsigned long lval;
2195 if (val < 0) {
2196 *negp = -1;
2197 lval = (unsigned long)-val;
2198 } else {
2199 *negp = 0;
2200 lval = (unsigned long)val;
2201 }
2202 *lvalp = jiffies_to_msecs(lval);
2203 }
2204 return 0;
2205}
2206
2207/**
2208 * proc_dointvec_jiffies - read a vector of integers as seconds
2209 * @table: the sysctl table
2210 * @write: %TRUE if this is a write to the sysctl file
2211 * @filp: the file structure
2212 * @buffer: the user buffer
2213 * @lenp: the size of the user buffer
2214 * @ppos: file position
2215 *
2216 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2217 * values from/to the user buffer, treated as an ASCII string.
2218 * The values read are assumed to be in seconds, and are converted into
2219 * jiffies.
2220 *
2221 * Returns 0 on success.
2222 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002223int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 void __user *buffer, size_t *lenp, loff_t *ppos)
2225{
2226 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2227 do_proc_dointvec_jiffies_conv,NULL);
2228}
2229
2230/**
2231 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2232 * @table: the sysctl table
2233 * @write: %TRUE if this is a write to the sysctl file
2234 * @filp: the file structure
2235 * @buffer: the user buffer
2236 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002237 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 *
2239 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2240 * values from/to the user buffer, treated as an ASCII string.
2241 * The values read are assumed to be in 1/USER_HZ seconds, and
2242 * are converted into jiffies.
2243 *
2244 * Returns 0 on success.
2245 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002246int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 void __user *buffer, size_t *lenp, loff_t *ppos)
2248{
2249 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2250 do_proc_dointvec_userhz_jiffies_conv,NULL);
2251}
2252
2253/**
2254 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2255 * @table: the sysctl table
2256 * @write: %TRUE if this is a write to the sysctl file
2257 * @filp: the file structure
2258 * @buffer: the user buffer
2259 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002260 * @ppos: file position
2261 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 *
2263 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2264 * values from/to the user buffer, treated as an ASCII string.
2265 * The values read are assumed to be in 1/1000 seconds, and
2266 * are converted into jiffies.
2267 *
2268 * Returns 0 on success.
2269 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002270int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 void __user *buffer, size_t *lenp, loff_t *ppos)
2272{
2273 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2274 do_proc_dointvec_ms_jiffies_conv, NULL);
2275}
2276
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002277static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002278 void __user *buffer, size_t *lenp, loff_t *ppos)
2279{
2280 struct pid *new_pid;
2281 pid_t tmp;
2282 int r;
2283
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002284 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002285
2286 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2287 lenp, ppos, NULL, NULL);
2288 if (r || !write)
2289 return r;
2290
2291 new_pid = find_get_pid(tmp);
2292 if (!new_pid)
2293 return -ESRCH;
2294
2295 put_pid(xchg(&cad_pid, new_pid));
2296 return 0;
2297}
2298
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299#else /* CONFIG_PROC_FS */
2300
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002301int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 void __user *buffer, size_t *lenp, loff_t *ppos)
2303{
2304 return -ENOSYS;
2305}
2306
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002307int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 void __user *buffer, size_t *lenp, loff_t *ppos)
2309{
2310 return -ENOSYS;
2311}
2312
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002313int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 void __user *buffer, size_t *lenp, loff_t *ppos)
2315{
2316 return -ENOSYS;
2317}
2318
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002319int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 void __user *buffer, size_t *lenp, loff_t *ppos)
2321{
2322 return -ENOSYS;
2323}
2324
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002325int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 void __user *buffer, size_t *lenp, loff_t *ppos)
2327{
2328 return -ENOSYS;
2329}
2330
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002331int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 void __user *buffer, size_t *lenp, loff_t *ppos)
2333{
2334 return -ENOSYS;
2335}
2336
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002337int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 void __user *buffer, size_t *lenp, loff_t *ppos)
2339{
2340 return -ENOSYS;
2341}
2342
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002343int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 void __user *buffer, size_t *lenp, loff_t *ppos)
2345{
2346 return -ENOSYS;
2347}
2348
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002349int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 struct file *filp,
2351 void __user *buffer,
2352 size_t *lenp, loff_t *ppos)
2353{
2354 return -ENOSYS;
2355}
2356
2357
2358#endif /* CONFIG_PROC_FS */
2359
2360
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002361#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362/*
2363 * General sysctl support routines
2364 */
2365
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002366/* The generic sysctl data routine (used if no strategy routine supplied) */
2367int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2368 void __user *oldval, size_t __user *oldlenp,
2369 void __user *newval, size_t newlen)
2370{
2371 size_t len;
2372
2373 /* Get out of I don't have a variable */
2374 if (!table->data || !table->maxlen)
2375 return -ENOTDIR;
2376
2377 if (oldval && oldlenp) {
2378 if (get_user(len, oldlenp))
2379 return -EFAULT;
2380 if (len) {
2381 if (len > table->maxlen)
2382 len = table->maxlen;
2383 if (copy_to_user(oldval, table->data, len))
2384 return -EFAULT;
2385 if (put_user(len, oldlenp))
2386 return -EFAULT;
2387 }
2388 }
2389
2390 if (newval && newlen) {
2391 if (newlen > table->maxlen)
2392 newlen = table->maxlen;
2393
2394 if (copy_from_user(table->data, newval, newlen))
2395 return -EFAULT;
2396 }
2397 return 1;
2398}
2399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002401int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002403 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 if (!table->data || !table->maxlen)
2406 return -ENOTDIR;
2407
2408 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002409 size_t bufsize;
2410 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002412 if (bufsize) {
2413 size_t len = strlen(table->data), copied;
2414
2415 /* This shouldn't trigger for a well-formed sysctl */
2416 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002418
2419 /* Copy up to a max of bufsize-1 bytes of the string */
2420 copied = (len >= bufsize) ? bufsize - 1 : len;
2421
2422 if (copy_to_user(oldval, table->data, copied) ||
2423 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002425 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 return -EFAULT;
2427 }
2428 }
2429 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002430 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 if (len > table->maxlen)
2432 len = table->maxlen;
2433 if(copy_from_user(table->data, newval, len))
2434 return -EFAULT;
2435 if (len == table->maxlen)
2436 len--;
2437 ((char *) table->data)[len] = 0;
2438 }
Yi Yang82c9df82005-12-30 16:37:10 +08002439 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440}
2441
2442/*
2443 * This function makes sure that all of the integers in the vector
2444 * are between the minimum and maximum values given in the arrays
2445 * table->extra1 and table->extra2, respectively.
2446 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002447int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002449 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450{
2451
2452 if (newval && newlen) {
2453 int __user *vec = (int __user *) newval;
2454 int *min = (int *) table->extra1;
2455 int *max = (int *) table->extra2;
2456 size_t length;
2457 int i;
2458
2459 if (newlen % sizeof(int) != 0)
2460 return -EINVAL;
2461
2462 if (!table->extra1 && !table->extra2)
2463 return 0;
2464
2465 if (newlen > table->maxlen)
2466 newlen = table->maxlen;
2467 length = newlen / sizeof(int);
2468
2469 for (i = 0; i < length; i++) {
2470 int value;
2471 if (get_user(value, vec + i))
2472 return -EFAULT;
2473 if (min && value < min[i])
2474 return -EINVAL;
2475 if (max && value > max[i])
2476 return -EINVAL;
2477 }
2478 }
2479 return 0;
2480}
2481
2482/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002483int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002485 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002487 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002489
2490 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002492 if (olen) {
2493 int val;
2494
2495 if (olen < sizeof(int))
2496 return -EINVAL;
2497
2498 val = *(int *)(table->data) / HZ;
2499 if (put_user(val, (int __user *)oldval))
2500 return -EFAULT;
2501 if (put_user(sizeof(int), oldlenp))
2502 return -EFAULT;
2503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 }
2505 if (newval && newlen) {
2506 int new;
2507 if (newlen != sizeof(int))
2508 return -EINVAL;
2509 if (get_user(new, (int __user *)newval))
2510 return -EFAULT;
2511 *(int *)(table->data) = new*HZ;
2512 }
2513 return 1;
2514}
2515
2516/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002517int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002519 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002521 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002523
2524 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002526 if (olen) {
2527 int val;
2528
2529 if (olen < sizeof(int))
2530 return -EINVAL;
2531
2532 val = jiffies_to_msecs(*(int *)(table->data));
2533 if (put_user(val, (int __user *)oldval))
2534 return -EFAULT;
2535 if (put_user(sizeof(int), oldlenp))
2536 return -EFAULT;
2537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 }
2539 if (newval && newlen) {
2540 int new;
2541 if (newlen != sizeof(int))
2542 return -EINVAL;
2543 if (get_user(new, (int __user *)newval))
2544 return -EFAULT;
2545 *(int *)(table->data) = msecs_to_jiffies(new);
2546 }
2547 return 1;
2548}
2549
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002550
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002551
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002552#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554
2555asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2556{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002557 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002558 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002559
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002560 if (copy_from_user(&tmp, args, sizeof(tmp)))
2561 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002562
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002563 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002564
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002565 /* If no error reading the parameters then just -ENOSYS ... */
2566 if (!error)
2567 error = -ENOSYS;
2568
2569 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570}
2571
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002572int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2573 void __user *oldval, size_t __user *oldlenp,
2574 void __user *newval, size_t newlen)
2575{
2576 return -ENOSYS;
2577}
2578
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002579int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002581 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582{
2583 return -ENOSYS;
2584}
2585
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002586int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002588 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589{
2590 return -ENOSYS;
2591}
2592
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002593int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002595 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596{
2597 return -ENOSYS;
2598}
2599
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002600int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002602 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
2604 return -ENOSYS;
2605}
2606
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002607#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002609static int deprecated_sysctl_warning(struct __sysctl_args *args)
2610{
2611 static int msg_count;
2612 int name[CTL_MAXNAME];
2613 int i;
2614
2615 /* Read in the sysctl name for better debug message logging */
2616 for (i = 0; i < args->nlen; i++)
2617 if (get_user(name[i], args->name + i))
2618 return -EFAULT;
2619
2620 /* Ignore accesses to kernel.version */
2621 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2622 return 0;
2623
2624 if (msg_count < 5) {
2625 msg_count++;
2626 printk(KERN_INFO
2627 "warning: process `%s' used the deprecated sysctl "
2628 "system call with ", current->comm);
2629 for (i = 0; i < args->nlen; i++)
2630 printk("%d.", name[i]);
2631 printk("\n");
2632 }
2633 return 0;
2634}
2635
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636/*
2637 * No sense putting this after each symbol definition, twice,
2638 * exception granted :-)
2639 */
2640EXPORT_SYMBOL(proc_dointvec);
2641EXPORT_SYMBOL(proc_dointvec_jiffies);
2642EXPORT_SYMBOL(proc_dointvec_minmax);
2643EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2644EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2645EXPORT_SYMBOL(proc_dostring);
2646EXPORT_SYMBOL(proc_doulongvec_minmax);
2647EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2648EXPORT_SYMBOL(register_sysctl_table);
2649EXPORT_SYMBOL(sysctl_intvec);
2650EXPORT_SYMBOL(sysctl_jiffies);
2651EXPORT_SYMBOL(sysctl_ms_jiffies);
2652EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002653EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654EXPORT_SYMBOL(unregister_sysctl_table);