blob: 62e53a0de4a3055843b545749d6e0cc570fde0f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Randy.Dunlapc59ede72006-01-11 12:17:46 -080027#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
40#include <linux/security.h>
41#include <linux/initrd.h>
42#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Pavel Machekc255d842006-02-20 18:27:58 -080046#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
Andi Kleen29cbc782006-09-30 01:47:55 +020053#ifdef CONFIG_X86
54#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010055#include <asm/stacktrace.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020056#endif
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#if defined(CONFIG_SYSCTL)
59
60/* External variables not in a header file. */
61extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070062extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063extern int sysctl_overcommit_memory;
64extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070065extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070066extern int sysctl_oom_kill_allocating_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070069extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int pid_max;
72extern int min_free_kbytes;
73extern int printk_ratelimit_jiffies;
74extern int printk_ratelimit_burst;
75extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080076extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080077extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020078extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070079extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070080extern int sysctl_stat_interval;
Peter Zijlstrabdf4c482007-07-19 01:48:15 -070081extern int audit_argv_kb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070083/* Constants used for minimum and maximum */
84#ifdef CONFIG_DETECT_SOFTLOCKUP
85static int one = 1;
86static int sixty = 60;
87#endif
88
89#ifdef CONFIG_MMU
90static int two = 2;
91#endif
92
93static int zero;
94static int one_hundred = 100;
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
97static int maxolduid = 65535;
98static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080099static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101static int ngroups_max = NGROUPS_MAX;
102
103#ifdef CONFIG_KMOD
104extern char modprobe_path[];
105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#ifdef CONFIG_CHR_DEV_SG
107extern int sg_big_buff;
108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110#ifdef __sparc__
111extern char reboot_command [];
112extern int stop_a_enabled;
113extern int scons_pwroff;
114#endif
115
116#ifdef __hppa__
117extern int pwrsw_enabled;
118extern int unaligned_enabled;
119#endif
120
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800121#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#ifdef CONFIG_MATHEMU
123extern int sysctl_ieee_emulation_warnings;
124#endif
125extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700126extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#endif
128
129extern int sysctl_hz_timer;
130
131#ifdef CONFIG_BSD_PROCESS_ACCT
132extern int acct_parm[];
133#endif
134
Jes Sorensend2b176e2006-02-28 09:42:23 -0800135#ifdef CONFIG_IA64
136extern int no_unaligned_warning;
137#endif
138
Ingo Molnar23f78d42006-06-27 02:54:53 -0700139#ifdef CONFIG_RT_MUTEXES
140extern int max_lock_depth;
141#endif
142
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700143#ifdef CONFIG_SYSCTL_SYSCALL
144static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700145 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700146#endif
147
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800148
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700149#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700150static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700151 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700152static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800153 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700154#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static struct ctl_table root_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157static struct ctl_table_header root_table_header =
158 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
159
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700160static struct ctl_table kern_table[];
161static struct ctl_table vm_table[];
162static struct ctl_table fs_table[];
163static struct ctl_table debug_table[];
164static struct ctl_table dev_table[];
165extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700166#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700167extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400168#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
171int sysctl_legacy_va_layout;
172#endif
173
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700174extern int prove_locking;
175extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/* The default sysctl tables: */
178
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700179static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 {
181 .ctl_name = CTL_KERN,
182 .procname = "kernel",
183 .mode = 0555,
184 .child = kern_table,
185 },
186 {
187 .ctl_name = CTL_VM,
188 .procname = "vm",
189 .mode = 0555,
190 .child = vm_table,
191 },
192#ifdef CONFIG_NET
193 {
194 .ctl_name = CTL_NET,
195 .procname = "net",
196 .mode = 0555,
197 .child = net_table,
198 },
199#endif
200 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 .ctl_name = CTL_FS,
202 .procname = "fs",
203 .mode = 0555,
204 .child = fs_table,
205 },
206 {
207 .ctl_name = CTL_DEBUG,
208 .procname = "debug",
209 .mode = 0555,
210 .child = debug_table,
211 },
212 {
213 .ctl_name = CTL_DEV,
214 .procname = "dev",
215 .mode = 0555,
216 .child = dev_table,
217 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700218/*
219 * NOTE: do not add new entries to this table unless you have read
220 * Documentation/sysctl/ctl_unnumbered.txt
221 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 { .ctl_name = 0 }
223};
224
Ingo Molnar77e54a12007-07-09 18:52:00 +0200225#ifdef CONFIG_SCHED_DEBUG
226static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
227static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
228static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
229static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
230#endif
231
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700232static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200233#ifdef CONFIG_SCHED_DEBUG
234 {
235 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200236 .procname = "sched_nr_latency",
237 .data = &sysctl_sched_nr_latency,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238 .maxlen = sizeof(unsigned int),
239 .mode = 0644,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200240 .proc_handler = &proc_dointvec,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200241 },
242 {
243 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200244 .procname = "sched_latency_ns",
245 .data = &sysctl_sched_latency,
246 .maxlen = sizeof(unsigned int),
247 .mode = 0644,
248 .proc_handler = &proc_dointvec_minmax,
249 .strategy = &sysctl_intvec,
250 .extra1 = &min_sched_granularity_ns,
251 .extra2 = &max_sched_granularity_ns,
252 },
253 {
254 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200255 .procname = "sched_wakeup_granularity_ns",
256 .data = &sysctl_sched_wakeup_granularity,
257 .maxlen = sizeof(unsigned int),
258 .mode = 0644,
259 .proc_handler = &proc_dointvec_minmax,
260 .strategy = &sysctl_intvec,
261 .extra1 = &min_wakeup_granularity_ns,
262 .extra2 = &max_wakeup_granularity_ns,
263 },
264 {
265 .ctl_name = CTL_UNNUMBERED,
266 .procname = "sched_batch_wakeup_granularity_ns",
267 .data = &sysctl_sched_batch_wakeup_granularity,
268 .maxlen = sizeof(unsigned int),
269 .mode = 0644,
270 .proc_handler = &proc_dointvec_minmax,
271 .strategy = &sysctl_intvec,
272 .extra1 = &min_wakeup_granularity_ns,
273 .extra2 = &max_wakeup_granularity_ns,
274 },
275 {
276 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200277 .procname = "sched_child_runs_first",
278 .data = &sysctl_sched_child_runs_first,
279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
281 .proc_handler = &proc_dointvec,
282 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200283 {
284 .ctl_name = CTL_UNNUMBERED,
285 .procname = "sched_features",
286 .data = &sysctl_sched_features,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
289 .proc_handler = &proc_dointvec,
290 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200291 {
292 .ctl_name = CTL_UNNUMBERED,
293 .procname = "sched_migration_cost",
294 .data = &sysctl_sched_migration_cost,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
297 .proc_handler = &proc_dointvec,
298 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200299#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200300 {
301 .ctl_name = CTL_UNNUMBERED,
302 .procname = "sched_compat_yield",
303 .data = &sysctl_sched_compat_yield,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = &proc_dointvec,
307 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700308#ifdef CONFIG_PROVE_LOCKING
309 {
310 .ctl_name = CTL_UNNUMBERED,
311 .procname = "prove_locking",
312 .data = &prove_locking,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = &proc_dointvec,
316 },
317#endif
318#ifdef CONFIG_LOCK_STAT
319 {
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "lock_stat",
322 .data = &lock_stat,
323 .maxlen = sizeof(int),
324 .mode = 0644,
325 .proc_handler = &proc_dointvec,
326 },
327#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200328 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 .ctl_name = KERN_PANIC,
330 .procname = "panic",
331 .data = &panic_timeout,
332 .maxlen = sizeof(int),
333 .mode = 0644,
334 .proc_handler = &proc_dointvec,
335 },
336 {
337 .ctl_name = KERN_CORE_USES_PID,
338 .procname = "core_uses_pid",
339 .data = &core_uses_pid,
340 .maxlen = sizeof(int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
343 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700344#ifdef CONFIG_AUDITSYSCALL
345 {
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "audit_argv_kb",
348 .data = &audit_argv_kb,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
352 },
353#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 {
355 .ctl_name = KERN_CORE_PATTERN,
356 .procname = "core_pattern",
357 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700358 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 .mode = 0644,
360 .proc_handler = &proc_dostring,
361 .strategy = &sysctl_string,
362 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800363#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 .procname = "tainted",
366 .data = &tainted,
367 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800368 .mode = 0644,
369 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800371#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 .procname = "cap-bound",
374 .data = &cap_bset,
375 .maxlen = sizeof(kernel_cap_t),
376 .mode = 0600,
377 .proc_handler = &proc_dointvec_bset,
378 },
379#ifdef CONFIG_BLK_DEV_INITRD
380 {
381 .ctl_name = KERN_REALROOTDEV,
382 .procname = "real-root-dev",
383 .data = &real_root_dev,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = &proc_dointvec,
387 },
388#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700389 {
390 .ctl_name = CTL_UNNUMBERED,
391 .procname = "print-fatal-signals",
392 .data = &print_fatal_signals,
393 .maxlen = sizeof(int),
394 .mode = 0644,
395 .proc_handler = &proc_dointvec,
396 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#ifdef __sparc__
398 {
399 .ctl_name = KERN_SPARC_REBOOT,
400 .procname = "reboot-cmd",
401 .data = reboot_command,
402 .maxlen = 256,
403 .mode = 0644,
404 .proc_handler = &proc_dostring,
405 .strategy = &sysctl_string,
406 },
407 {
408 .ctl_name = KERN_SPARC_STOP_A,
409 .procname = "stop-a",
410 .data = &stop_a_enabled,
411 .maxlen = sizeof (int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
414 },
415 {
416 .ctl_name = KERN_SPARC_SCONS_PWROFF,
417 .procname = "scons-poweroff",
418 .data = &scons_pwroff,
419 .maxlen = sizeof (int),
420 .mode = 0644,
421 .proc_handler = &proc_dointvec,
422 },
423#endif
424#ifdef __hppa__
425 {
426 .ctl_name = KERN_HPPA_PWRSW,
427 .procname = "soft-power",
428 .data = &pwrsw_enabled,
429 .maxlen = sizeof (int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
432 },
433 {
434 .ctl_name = KERN_HPPA_UNALIGNED,
435 .procname = "unaligned-trap",
436 .data = &unaligned_enabled,
437 .maxlen = sizeof (int),
438 .mode = 0644,
439 .proc_handler = &proc_dointvec,
440 },
441#endif
442 {
443 .ctl_name = KERN_CTLALTDEL,
444 .procname = "ctrl-alt-del",
445 .data = &C_A_D,
446 .maxlen = sizeof(int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450 {
451 .ctl_name = KERN_PRINTK,
452 .procname = "printk",
453 .data = &console_loglevel,
454 .maxlen = 4*sizeof(int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458#ifdef CONFIG_KMOD
459 {
460 .ctl_name = KERN_MODPROBE,
461 .procname = "modprobe",
462 .data = &modprobe_path,
463 .maxlen = KMOD_PATH_LEN,
464 .mode = 0644,
465 .proc_handler = &proc_dostring,
466 .strategy = &sysctl_string,
467 },
468#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700469#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 {
471 .ctl_name = KERN_HOTPLUG,
472 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100473 .data = &uevent_helper,
474 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .mode = 0644,
476 .proc_handler = &proc_dostring,
477 .strategy = &sysctl_string,
478 },
479#endif
480#ifdef CONFIG_CHR_DEV_SG
481 {
482 .ctl_name = KERN_SG_BIG_BUFF,
483 .procname = "sg-big-buff",
484 .data = &sg_big_buff,
485 .maxlen = sizeof (int),
486 .mode = 0444,
487 .proc_handler = &proc_dointvec,
488 },
489#endif
490#ifdef CONFIG_BSD_PROCESS_ACCT
491 {
492 .ctl_name = KERN_ACCT,
493 .procname = "acct",
494 .data = &acct_parm,
495 .maxlen = 3*sizeof(int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
498 },
499#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#ifdef CONFIG_MAGIC_SYSRQ
501 {
502 .ctl_name = KERN_SYSRQ,
503 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800504 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .maxlen = sizeof (int),
506 .mode = 0644,
507 .proc_handler = &proc_dointvec,
508 },
509#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700510#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700513 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .maxlen = sizeof (int),
515 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700516 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700518#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 {
520 .ctl_name = KERN_MAX_THREADS,
521 .procname = "threads-max",
522 .data = &max_threads,
523 .maxlen = sizeof(int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec,
526 },
527 {
528 .ctl_name = KERN_RANDOM,
529 .procname = "random",
530 .mode = 0555,
531 .child = random_table,
532 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 {
534 .ctl_name = KERN_OVERFLOWUID,
535 .procname = "overflowuid",
536 .data = &overflowuid,
537 .maxlen = sizeof(int),
538 .mode = 0644,
539 .proc_handler = &proc_dointvec_minmax,
540 .strategy = &sysctl_intvec,
541 .extra1 = &minolduid,
542 .extra2 = &maxolduid,
543 },
544 {
545 .ctl_name = KERN_OVERFLOWGID,
546 .procname = "overflowgid",
547 .data = &overflowgid,
548 .maxlen = sizeof(int),
549 .mode = 0644,
550 .proc_handler = &proc_dointvec_minmax,
551 .strategy = &sysctl_intvec,
552 .extra1 = &minolduid,
553 .extra2 = &maxolduid,
554 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800555#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556#ifdef CONFIG_MATHEMU
557 {
558 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
559 .procname = "ieee_emulation_warnings",
560 .data = &sysctl_ieee_emulation_warnings,
561 .maxlen = sizeof(int),
562 .mode = 0644,
563 .proc_handler = &proc_dointvec,
564 },
565#endif
566#ifdef CONFIG_NO_IDLE_HZ
567 {
568 .ctl_name = KERN_HZ_TIMER,
569 .procname = "hz_timer",
570 .data = &sysctl_hz_timer,
571 .maxlen = sizeof(int),
572 .mode = 0644,
573 .proc_handler = &proc_dointvec,
574 },
575#endif
576 {
577 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
578 .procname = "userprocess_debug",
579 .data = &sysctl_userprocess_debug,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 .proc_handler = &proc_dointvec,
583 },
584#endif
585 {
586 .ctl_name = KERN_PIDMAX,
587 .procname = "pid_max",
588 .data = &pid_max,
589 .maxlen = sizeof (int),
590 .mode = 0644,
591 .proc_handler = &proc_dointvec_minmax,
592 .strategy = sysctl_intvec,
593 .extra1 = &pid_max_min,
594 .extra2 = &pid_max_max,
595 },
596 {
597 .ctl_name = KERN_PANIC_ON_OOPS,
598 .procname = "panic_on_oops",
599 .data = &panic_on_oops,
600 .maxlen = sizeof(int),
601 .mode = 0644,
602 .proc_handler = &proc_dointvec,
603 },
604 {
605 .ctl_name = KERN_PRINTK_RATELIMIT,
606 .procname = "printk_ratelimit",
607 .data = &printk_ratelimit_jiffies,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec_jiffies,
611 .strategy = &sysctl_jiffies,
612 },
613 {
614 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
615 .procname = "printk_ratelimit_burst",
616 .data = &printk_ratelimit_burst,
617 .maxlen = sizeof(int),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec,
620 },
621 {
622 .ctl_name = KERN_NGROUPS_MAX,
623 .procname = "ngroups_max",
624 .data = &ngroups_max,
625 .maxlen = sizeof (int),
626 .mode = 0444,
627 .proc_handler = &proc_dointvec,
628 },
629#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
630 {
631 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
632 .procname = "unknown_nmi_panic",
633 .data = &unknown_nmi_panic,
634 .maxlen = sizeof (int),
635 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200636 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 },
Don Zickus407984f2006-09-26 10:52:27 +0200638 {
Don Zickus407984f2006-09-26 10:52:27 +0200639 .procname = "nmi_watchdog",
640 .data = &nmi_watchdog_enabled,
641 .maxlen = sizeof (int),
642 .mode = 0644,
643 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 },
645#endif
646#if defined(CONFIG_X86)
647 {
Don Zickus8da5adda2006-09-26 10:52:27 +0200648 .ctl_name = KERN_PANIC_ON_NMI,
649 .procname = "panic_on_unrecovered_nmi",
650 .data = &panic_on_unrecovered_nmi,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec,
654 },
655 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 .ctl_name = KERN_BOOTLOADER_TYPE,
657 .procname = "bootloader_type",
658 .data = &bootloader_type,
659 .maxlen = sizeof (int),
660 .mode = 0444,
661 .proc_handler = &proc_dointvec,
662 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100663 {
664 .ctl_name = CTL_UNNUMBERED,
665 .procname = "kstack_depth_to_print",
666 .data = &kstack_depth_to_print,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = &proc_dointvec,
670 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800672#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 {
674 .ctl_name = KERN_RANDOMIZE,
675 .procname = "randomize_va_space",
676 .data = &randomize_va_space,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec,
680 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800681#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800682#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700683 {
684 .ctl_name = KERN_SPIN_RETRY,
685 .procname = "spin_retry",
686 .data = &spin_retry,
687 .maxlen = sizeof (int),
688 .mode = 0644,
689 .proc_handler = &proc_dointvec,
690 },
691#endif
Len Brown673d5b42007-07-28 03:33:16 -0400692#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800693 {
Pavel Machekc255d842006-02-20 18:27:58 -0800694 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700695 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800696 .maxlen = sizeof (unsigned long),
697 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800698 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800699 },
700#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800701#ifdef CONFIG_IA64
702 {
703 .ctl_name = KERN_IA64_UNALIGNED,
704 .procname = "ignore-unaligned-usertrap",
705 .data = &no_unaligned_warning,
706 .maxlen = sizeof (int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
709 },
710#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700711#ifdef CONFIG_DETECT_SOFTLOCKUP
712 {
713 .ctl_name = CTL_UNNUMBERED,
714 .procname = "softlockup_thresh",
715 .data = &softlockup_thresh,
716 .maxlen = sizeof(int),
717 .mode = 0644,
718 .proc_handler = &proc_dointvec_minmax,
719 .strategy = &sysctl_intvec,
720 .extra1 = &one,
721 .extra2 = &sixty,
722 },
723#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200724#ifdef CONFIG_COMPAT
725 {
726 .ctl_name = KERN_COMPAT_LOG,
727 .procname = "compat-log",
728 .data = &compat_log,
729 .maxlen = sizeof (int),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
732 },
733#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700734#ifdef CONFIG_RT_MUTEXES
735 {
736 .ctl_name = KERN_MAX_LOCK_DEPTH,
737 .procname = "max_lock_depth",
738 .data = &max_lock_depth,
739 .maxlen = sizeof(int),
740 .mode = 0644,
741 .proc_handler = &proc_dointvec,
742 },
743#endif
Kees Cook5096add2007-05-08 00:26:04 -0700744#ifdef CONFIG_PROC_FS
745 {
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "maps_protect",
748 .data = &maps_protect,
749 .maxlen = sizeof(int),
750 .mode = 0644,
751 .proc_handler = &proc_dointvec,
752 },
753#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700754 {
755 .ctl_name = CTL_UNNUMBERED,
756 .procname = "poweroff_cmd",
757 .data = &poweroff_cmd,
758 .maxlen = POWEROFF_CMD_PATH_LEN,
759 .mode = 0644,
760 .proc_handler = &proc_dostring,
761 .strategy = &sysctl_string,
762 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700763/*
764 * NOTE: do not add new entries to this table unless you have read
765 * Documentation/sysctl/ctl_unnumbered.txt
766 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 { .ctl_name = 0 }
768};
769
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700770static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 {
772 .ctl_name = VM_OVERCOMMIT_MEMORY,
773 .procname = "overcommit_memory",
774 .data = &sysctl_overcommit_memory,
775 .maxlen = sizeof(sysctl_overcommit_memory),
776 .mode = 0644,
777 .proc_handler = &proc_dointvec,
778 },
779 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700780 .ctl_name = VM_PANIC_ON_OOM,
781 .procname = "panic_on_oom",
782 .data = &sysctl_panic_on_oom,
783 .maxlen = sizeof(sysctl_panic_on_oom),
784 .mode = 0644,
785 .proc_handler = &proc_dointvec,
786 },
787 {
David Rientjesfe071d72007-10-16 23:25:56 -0700788 .ctl_name = CTL_UNNUMBERED,
789 .procname = "oom_kill_allocating_task",
790 .data = &sysctl_oom_kill_allocating_task,
791 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
792 .mode = 0644,
793 .proc_handler = &proc_dointvec,
794 },
795 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 .ctl_name = VM_OVERCOMMIT_RATIO,
797 .procname = "overcommit_ratio",
798 .data = &sysctl_overcommit_ratio,
799 .maxlen = sizeof(sysctl_overcommit_ratio),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
803 {
804 .ctl_name = VM_PAGE_CLUSTER,
805 .procname = "page-cluster",
806 .data = &page_cluster,
807 .maxlen = sizeof(int),
808 .mode = 0644,
809 .proc_handler = &proc_dointvec,
810 },
811 {
812 .ctl_name = VM_DIRTY_BACKGROUND,
813 .procname = "dirty_background_ratio",
814 .data = &dirty_background_ratio,
815 .maxlen = sizeof(dirty_background_ratio),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec_minmax,
818 .strategy = &sysctl_intvec,
819 .extra1 = &zero,
820 .extra2 = &one_hundred,
821 },
822 {
823 .ctl_name = VM_DIRTY_RATIO,
824 .procname = "dirty_ratio",
825 .data = &vm_dirty_ratio,
826 .maxlen = sizeof(vm_dirty_ratio),
827 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700828 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 .strategy = &sysctl_intvec,
830 .extra1 = &zero,
831 .extra2 = &one_hundred,
832 },
833 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800835 .data = &dirty_writeback_interval,
836 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 .mode = 0644,
838 .proc_handler = &dirty_writeback_centisecs_handler,
839 },
840 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800842 .data = &dirty_expire_interval,
843 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800845 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 },
847 {
848 .ctl_name = VM_NR_PDFLUSH_THREADS,
849 .procname = "nr_pdflush_threads",
850 .data = &nr_pdflush_threads,
851 .maxlen = sizeof nr_pdflush_threads,
852 .mode = 0444 /* read-only*/,
853 .proc_handler = &proc_dointvec,
854 },
855 {
856 .ctl_name = VM_SWAPPINESS,
857 .procname = "swappiness",
858 .data = &vm_swappiness,
859 .maxlen = sizeof(vm_swappiness),
860 .mode = 0644,
861 .proc_handler = &proc_dointvec_minmax,
862 .strategy = &sysctl_intvec,
863 .extra1 = &zero,
864 .extra2 = &one_hundred,
865 },
866#ifdef CONFIG_HUGETLB_PAGE
867 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 .procname = "nr_hugepages",
869 .data = &max_huge_pages,
870 .maxlen = sizeof(unsigned long),
871 .mode = 0644,
872 .proc_handler = &hugetlb_sysctl_handler,
873 .extra1 = (void *)&hugetlb_zero,
874 .extra2 = (void *)&hugetlb_infinity,
875 },
876 {
877 .ctl_name = VM_HUGETLB_GROUP,
878 .procname = "hugetlb_shm_group",
879 .data = &sysctl_hugetlb_shm_group,
880 .maxlen = sizeof(gid_t),
881 .mode = 0644,
882 .proc_handler = &proc_dointvec,
883 },
Mel Gorman396faf02007-07-17 04:03:13 -0700884 {
885 .ctl_name = CTL_UNNUMBERED,
886 .procname = "hugepages_treat_as_movable",
887 .data = &hugepages_treat_as_movable,
888 .maxlen = sizeof(int),
889 .mode = 0644,
890 .proc_handler = &hugetlb_treat_movable_handler,
891 },
Adam Litke54f9f802007-10-16 01:26:20 -0700892 {
893 .ctl_name = CTL_UNNUMBERED,
894 .procname = "hugetlb_dynamic_pool",
895 .data = &hugetlb_dynamic_pool,
896 .maxlen = sizeof(hugetlb_dynamic_pool),
897 .mode = 0644,
898 .proc_handler = &proc_dointvec,
899 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900#endif
901 {
902 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
903 .procname = "lowmem_reserve_ratio",
904 .data = &sysctl_lowmem_reserve_ratio,
905 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
906 .mode = 0644,
907 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
908 .strategy = &sysctl_intvec,
909 },
910 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800911 .ctl_name = VM_DROP_PAGECACHE,
912 .procname = "drop_caches",
913 .data = &sysctl_drop_caches,
914 .maxlen = sizeof(int),
915 .mode = 0644,
916 .proc_handler = drop_caches_sysctl_handler,
917 .strategy = &sysctl_intvec,
918 },
919 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 .ctl_name = VM_MIN_FREE_KBYTES,
921 .procname = "min_free_kbytes",
922 .data = &min_free_kbytes,
923 .maxlen = sizeof(min_free_kbytes),
924 .mode = 0644,
925 .proc_handler = &min_free_kbytes_sysctl_handler,
926 .strategy = &sysctl_intvec,
927 .extra1 = &zero,
928 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800929 {
930 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
931 .procname = "percpu_pagelist_fraction",
932 .data = &percpu_pagelist_fraction,
933 .maxlen = sizeof(percpu_pagelist_fraction),
934 .mode = 0644,
935 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
936 .strategy = &sysctl_intvec,
937 .extra1 = &min_percpu_pagelist_fract,
938 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939#ifdef CONFIG_MMU
940 {
941 .ctl_name = VM_MAX_MAP_COUNT,
942 .procname = "max_map_count",
943 .data = &sysctl_max_map_count,
944 .maxlen = sizeof(sysctl_max_map_count),
945 .mode = 0644,
946 .proc_handler = &proc_dointvec
947 },
948#endif
949 {
950 .ctl_name = VM_LAPTOP_MODE,
951 .procname = "laptop_mode",
952 .data = &laptop_mode,
953 .maxlen = sizeof(laptop_mode),
954 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800955 .proc_handler = &proc_dointvec_jiffies,
956 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 },
958 {
959 .ctl_name = VM_BLOCK_DUMP,
960 .procname = "block_dump",
961 .data = &block_dump,
962 .maxlen = sizeof(block_dump),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 .strategy = &sysctl_intvec,
966 .extra1 = &zero,
967 },
968 {
969 .ctl_name = VM_VFS_CACHE_PRESSURE,
970 .procname = "vfs_cache_pressure",
971 .data = &sysctl_vfs_cache_pressure,
972 .maxlen = sizeof(sysctl_vfs_cache_pressure),
973 .mode = 0644,
974 .proc_handler = &proc_dointvec,
975 .strategy = &sysctl_intvec,
976 .extra1 = &zero,
977 },
978#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
979 {
980 .ctl_name = VM_LEGACY_VA_LAYOUT,
981 .procname = "legacy_va_layout",
982 .data = &sysctl_legacy_va_layout,
983 .maxlen = sizeof(sysctl_legacy_va_layout),
984 .mode = 0644,
985 .proc_handler = &proc_dointvec,
986 .strategy = &sysctl_intvec,
987 .extra1 = &zero,
988 },
989#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800990#ifdef CONFIG_NUMA
991 {
992 .ctl_name = VM_ZONE_RECLAIM_MODE,
993 .procname = "zone_reclaim_mode",
994 .data = &zone_reclaim_mode,
995 .maxlen = sizeof(zone_reclaim_mode),
996 .mode = 0644,
997 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -0800998 .strategy = &sysctl_intvec,
999 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001000 },
Christoph Lameter96146342006-07-03 00:24:13 -07001001 {
1002 .ctl_name = VM_MIN_UNMAPPED,
1003 .procname = "min_unmapped_ratio",
1004 .data = &sysctl_min_unmapped_ratio,
1005 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1006 .mode = 0644,
1007 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1008 .strategy = &sysctl_intvec,
1009 .extra1 = &zero,
1010 .extra2 = &one_hundred,
1011 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001012 {
1013 .ctl_name = VM_MIN_SLAB,
1014 .procname = "min_slab_ratio",
1015 .data = &sysctl_min_slab_ratio,
1016 .maxlen = sizeof(sysctl_min_slab_ratio),
1017 .mode = 0644,
1018 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1019 .strategy = &sysctl_intvec,
1020 .extra1 = &zero,
1021 .extra2 = &one_hundred,
1022 },
Christoph Lameter17436602006-01-18 17:42:32 -08001023#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001024#ifdef CONFIG_SMP
1025 {
1026 .ctl_name = CTL_UNNUMBERED,
1027 .procname = "stat_interval",
1028 .data = &sysctl_stat_interval,
1029 .maxlen = sizeof(sysctl_stat_interval),
1030 .mode = 0644,
1031 .proc_handler = &proc_dointvec_jiffies,
1032 .strategy = &sysctl_jiffies,
1033 },
1034#endif
Eric Parised032182007-06-28 15:55:21 -04001035#ifdef CONFIG_SECURITY
1036 {
1037 .ctl_name = CTL_UNNUMBERED,
1038 .procname = "mmap_min_addr",
1039 .data = &mmap_min_addr,
1040 .maxlen = sizeof(unsigned long),
1041 .mode = 0644,
1042 .proc_handler = &proc_doulongvec_minmax,
1043 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001044#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001045#ifdef CONFIG_NUMA
1046 {
1047 .ctl_name = CTL_UNNUMBERED,
1048 .procname = "numa_zonelist_order",
1049 .data = &numa_zonelist_order,
1050 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1051 .mode = 0644,
1052 .proc_handler = &numa_zonelist_order_handler,
1053 .strategy = &sysctl_string,
1054 },
1055#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001056#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001057 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001058 {
1059 .ctl_name = VM_VDSO_ENABLED,
1060 .procname = "vdso_enabled",
1061 .data = &vdso_enabled,
1062 .maxlen = sizeof(vdso_enabled),
1063 .mode = 0644,
1064 .proc_handler = &proc_dointvec,
1065 .strategy = &sysctl_intvec,
1066 .extra1 = &zero,
1067 },
1068#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001069/*
1070 * NOTE: do not add new entries to this table unless you have read
1071 * Documentation/sysctl/ctl_unnumbered.txt
1072 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 { .ctl_name = 0 }
1074};
1075
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001076#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001077static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001078 { .ctl_name = 0 }
1079};
1080#endif
1081
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001082static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 {
1084 .ctl_name = FS_NRINODE,
1085 .procname = "inode-nr",
1086 .data = &inodes_stat,
1087 .maxlen = 2*sizeof(int),
1088 .mode = 0444,
1089 .proc_handler = &proc_dointvec,
1090 },
1091 {
1092 .ctl_name = FS_STATINODE,
1093 .procname = "inode-state",
1094 .data = &inodes_stat,
1095 .maxlen = 7*sizeof(int),
1096 .mode = 0444,
1097 .proc_handler = &proc_dointvec,
1098 },
1099 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 .procname = "file-nr",
1101 .data = &files_stat,
1102 .maxlen = 3*sizeof(int),
1103 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001104 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 },
1106 {
1107 .ctl_name = FS_MAXFILE,
1108 .procname = "file-max",
1109 .data = &files_stat.max_files,
1110 .maxlen = sizeof(int),
1111 .mode = 0644,
1112 .proc_handler = &proc_dointvec,
1113 },
1114 {
1115 .ctl_name = FS_DENTRY,
1116 .procname = "dentry-state",
1117 .data = &dentry_stat,
1118 .maxlen = 6*sizeof(int),
1119 .mode = 0444,
1120 .proc_handler = &proc_dointvec,
1121 },
1122 {
1123 .ctl_name = FS_OVERFLOWUID,
1124 .procname = "overflowuid",
1125 .data = &fs_overflowuid,
1126 .maxlen = sizeof(int),
1127 .mode = 0644,
1128 .proc_handler = &proc_dointvec_minmax,
1129 .strategy = &sysctl_intvec,
1130 .extra1 = &minolduid,
1131 .extra2 = &maxolduid,
1132 },
1133 {
1134 .ctl_name = FS_OVERFLOWGID,
1135 .procname = "overflowgid",
1136 .data = &fs_overflowgid,
1137 .maxlen = sizeof(int),
1138 .mode = 0644,
1139 .proc_handler = &proc_dointvec_minmax,
1140 .strategy = &sysctl_intvec,
1141 .extra1 = &minolduid,
1142 .extra2 = &maxolduid,
1143 },
1144 {
1145 .ctl_name = FS_LEASES,
1146 .procname = "leases-enable",
1147 .data = &leases_enable,
1148 .maxlen = sizeof(int),
1149 .mode = 0644,
1150 .proc_handler = &proc_dointvec,
1151 },
1152#ifdef CONFIG_DNOTIFY
1153 {
1154 .ctl_name = FS_DIR_NOTIFY,
1155 .procname = "dir-notify-enable",
1156 .data = &dir_notify_enable,
1157 .maxlen = sizeof(int),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec,
1160 },
1161#endif
1162#ifdef CONFIG_MMU
1163 {
1164 .ctl_name = FS_LEASE_TIME,
1165 .procname = "lease-break-time",
1166 .data = &lease_break_time,
1167 .maxlen = sizeof(int),
1168 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001169 .proc_handler = &proc_dointvec_minmax,
1170 .strategy = &sysctl_intvec,
1171 .extra1 = &zero,
1172 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 },
1174 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 .procname = "aio-nr",
1176 .data = &aio_nr,
1177 .maxlen = sizeof(aio_nr),
1178 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001179 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 },
1181 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 .procname = "aio-max-nr",
1183 .data = &aio_max_nr,
1184 .maxlen = sizeof(aio_max_nr),
1185 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001186 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001188#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001189 {
1190 .ctl_name = FS_INOTIFY,
1191 .procname = "inotify",
1192 .mode = 0555,
1193 .child = inotify_table,
1194 },
1195#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001197 {
1198 .ctl_name = KERN_SETUID_DUMPABLE,
1199 .procname = "suid_dumpable",
1200 .data = &suid_dumpable,
1201 .maxlen = sizeof(int),
1202 .mode = 0644,
1203 .proc_handler = &proc_dointvec,
1204 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001205#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1206 {
1207 .ctl_name = CTL_UNNUMBERED,
1208 .procname = "binfmt_misc",
1209 .mode = 0555,
1210 .child = binfmt_misc_table,
1211 },
1212#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001213/*
1214 * NOTE: do not add new entries to this table unless you have read
1215 * Documentation/sysctl/ctl_unnumbered.txt
1216 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 { .ctl_name = 0 }
1218};
1219
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001220static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001221#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001222 {
1223 .ctl_name = CTL_UNNUMBERED,
1224 .procname = "exception-trace",
1225 .data = &show_unhandled_signals,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = proc_dointvec
1229 },
1230#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 { .ctl_name = 0 }
1232};
1233
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001234static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001236};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Al Viro330d57f2005-11-04 10:18:40 +00001238static DEFINE_SPINLOCK(sysctl_lock);
1239
1240/* called under sysctl_lock */
1241static int use_table(struct ctl_table_header *p)
1242{
1243 if (unlikely(p->unregistering))
1244 return 0;
1245 p->used++;
1246 return 1;
1247}
1248
1249/* called under sysctl_lock */
1250static void unuse_table(struct ctl_table_header *p)
1251{
1252 if (!--p->used)
1253 if (unlikely(p->unregistering))
1254 complete(p->unregistering);
1255}
1256
1257/* called under sysctl_lock, will reacquire if has to wait */
1258static void start_unregistering(struct ctl_table_header *p)
1259{
1260 /*
1261 * if p->used is 0, nobody will ever touch that entry again;
1262 * we'll eliminate all paths to it before dropping sysctl_lock
1263 */
1264 if (unlikely(p->used)) {
1265 struct completion wait;
1266 init_completion(&wait);
1267 p->unregistering = &wait;
1268 spin_unlock(&sysctl_lock);
1269 wait_for_completion(&wait);
1270 spin_lock(&sysctl_lock);
1271 }
1272 /*
1273 * do not remove from the list until nobody holds it; walking the
1274 * list in do_sysctl() relies on that.
1275 */
1276 list_del_init(&p->ctl_entry);
1277}
1278
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001279void sysctl_head_finish(struct ctl_table_header *head)
1280{
1281 if (!head)
1282 return;
1283 spin_lock(&sysctl_lock);
1284 unuse_table(head);
1285 spin_unlock(&sysctl_lock);
1286}
1287
1288struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1289{
1290 struct ctl_table_header *head;
1291 struct list_head *tmp;
1292 spin_lock(&sysctl_lock);
1293 if (prev) {
1294 tmp = &prev->ctl_entry;
1295 unuse_table(prev);
1296 goto next;
1297 }
1298 tmp = &root_table_header.ctl_entry;
1299 for (;;) {
1300 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1301
1302 if (!use_table(head))
1303 goto next;
1304 spin_unlock(&sysctl_lock);
1305 return head;
1306 next:
1307 tmp = tmp->next;
1308 if (tmp == &root_table_header.ctl_entry)
1309 break;
1310 }
1311 spin_unlock(&sysctl_lock);
1312 return NULL;
1313}
1314
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001315#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1317 void __user *newval, size_t newlen)
1318{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001319 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001320 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1323 return -ENOTDIR;
1324 if (oldval) {
1325 int old_len;
1326 if (!oldlenp || get_user(old_len, oldlenp))
1327 return -EFAULT;
1328 }
Al Viro330d57f2005-11-04 10:18:40 +00001329
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001330 for (head = sysctl_head_next(NULL); head;
1331 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001332 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001333 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001334 if (error != -ENOTDIR) {
1335 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001336 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001337 }
1338 }
Al Viro330d57f2005-11-04 10:18:40 +00001339 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
1342asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1343{
1344 struct __sysctl_args tmp;
1345 int error;
1346
1347 if (copy_from_user(&tmp, args, sizeof(tmp)))
1348 return -EFAULT;
1349
1350 lock_kernel();
1351 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1352 tmp.newval, tmp.newlen);
1353 unlock_kernel();
1354 return error;
1355}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001356#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001359 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 * some sysctl variables are readonly even to root.
1361 */
1362
1363static int test_perm(int mode, int op)
1364{
1365 if (!current->euid)
1366 mode >>= 6;
1367 else if (in_egroup_p(0))
1368 mode >>= 3;
1369 if ((mode & op & 0007) == op)
1370 return 0;
1371 return -EACCES;
1372}
1373
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001374int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
1376 int error;
1377 error = security_sysctl(table, op);
1378 if (error)
1379 return error;
1380 return test_perm(table->mode, op);
1381}
1382
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001383#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384static int parse_table(int __user *name, int nlen,
1385 void __user *oldval, size_t __user *oldlenp,
1386 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001387 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388{
1389 int n;
1390repeat:
1391 if (!nlen)
1392 return -ENOTDIR;
1393 if (get_user(n, name))
1394 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001395 for ( ; table->ctl_name || table->procname; table++) {
1396 if (!table->ctl_name)
1397 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001398 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 int error;
1400 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001401 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 name++;
1404 nlen--;
1405 table = table->child;
1406 goto repeat;
1407 }
1408 error = do_sysctl_strategy(table, name, nlen,
1409 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001410 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 return error;
1412 }
1413 }
1414 return -ENOTDIR;
1415}
1416
1417/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001418int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 int __user *name, int nlen,
1420 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001421 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422{
1423 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 if (oldval)
1426 op |= 004;
1427 if (newval)
1428 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001429 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 return -EPERM;
1431
1432 if (table->strategy) {
1433 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001434 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 if (rc < 0)
1436 return rc;
1437 if (rc > 0)
1438 return 0;
1439 }
1440
1441 /* If there is no strategy routine, or if the strategy returns
1442 * zero, proceed with automatic r/w */
1443 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001444 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1445 newval, newlen);
1446 if (rc < 0)
1447 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 }
1449 return 0;
1450}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001451#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001453static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1454{
1455 for (; table->ctl_name || table->procname; table++) {
1456 table->parent = parent;
1457 if (table->child)
1458 sysctl_set_parent(table, table->child);
1459 }
1460}
1461
1462static __init int sysctl_init(void)
1463{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001464 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001465 sysctl_set_parent(NULL, root_table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001466 err = sysctl_check_table(root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001467 return 0;
1468}
1469
1470core_initcall(sysctl_init);
1471
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472/**
1473 * register_sysctl_table - register a sysctl hierarchy
1474 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 *
1476 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1477 * array. An entry with a ctl_name of 0 terminates the table.
1478 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001479 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 *
1481 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1482 * must be unique within that level of sysctl
1483 *
1484 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1485 * enter a sysctl file
1486 *
1487 * data - a pointer to data for use by proc_handler
1488 *
1489 * maxlen - the maximum size in bytes of the data
1490 *
1491 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1492 *
1493 * child - a pointer to the child sysctl table if this entry is a directory, or
1494 * %NULL.
1495 *
1496 * proc_handler - the text handler routine (described below)
1497 *
1498 * strategy - the strategy routine (described below)
1499 *
1500 * de - for internal use by the sysctl routines
1501 *
1502 * extra1, extra2 - extra pointers usable by the proc handler routines
1503 *
1504 * Leaf nodes in the sysctl tree will be represented by a single file
1505 * under /proc; non-leaf nodes will be represented by directories.
1506 *
1507 * sysctl(2) can automatically manage read and write requests through
1508 * the sysctl table. The data and maxlen fields of the ctl_table
1509 * struct enable minimal validation of the values being written to be
1510 * performed, and the mode field allows minimal authentication.
1511 *
1512 * More sophisticated management can be enabled by the provision of a
1513 * strategy routine with the table entry. This will be called before
1514 * any automatic read or write of the data is performed.
1515 *
1516 * The strategy routine may return
1517 *
1518 * < 0 - Error occurred (error is passed to user process)
1519 *
1520 * 0 - OK - proceed with automatic read or write.
1521 *
1522 * > 0 - OK - read or write has been done by the strategy routine, so
1523 * return immediately.
1524 *
1525 * There must be a proc_handler routine for any terminal nodes
1526 * mirrored under /proc/sys (non-terminals are handled by a built-in
1527 * directory handler). Several default handlers are available to
1528 * cover common cases -
1529 *
1530 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1531 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1532 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1533 *
1534 * It is the handler's job to read the input buffer from user memory
1535 * and process it. The handler should return 0 on success.
1536 *
1537 * This routine returns %NULL on a failure to register, and a pointer
1538 * to the table header on success.
1539 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001540struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
1542 struct ctl_table_header *tmp;
1543 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1544 if (!tmp)
1545 return NULL;
1546 tmp->ctl_table = table;
1547 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001548 tmp->used = 0;
1549 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001550 sysctl_set_parent(NULL, table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001551 if (sysctl_check_table(tmp->ctl_table)) {
1552 kfree(tmp);
1553 return NULL;
1554 }
Al Viro330d57f2005-11-04 10:18:40 +00001555 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001556 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001557 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 return tmp;
1559}
1560
1561/**
1562 * unregister_sysctl_table - unregister a sysctl table hierarchy
1563 * @header: the header returned from register_sysctl_table
1564 *
1565 * Unregisters the sysctl table and all children. proc entries may not
1566 * actually be removed until they are no longer used by anyone.
1567 */
1568void unregister_sysctl_table(struct ctl_table_header * header)
1569{
Al Viro330d57f2005-11-04 10:18:40 +00001570 might_sleep();
1571 spin_lock(&sysctl_lock);
1572 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001573 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 kfree(header);
1575}
1576
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001577#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001578struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001579{
1580 return NULL;
1581}
1582
1583void unregister_sysctl_table(struct ctl_table_header * table)
1584{
1585}
1586
1587#endif /* CONFIG_SYSCTL */
1588
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589/*
1590 * /proc/sys support
1591 */
1592
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001593#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001595static int _proc_do_string(void* data, int maxlen, int write,
1596 struct file *filp, void __user *buffer,
1597 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001598{
1599 size_t len;
1600 char __user *p;
1601 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001602
1603 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001604 *lenp = 0;
1605 return 0;
1606 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001607
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001608 if (write) {
1609 len = 0;
1610 p = buffer;
1611 while (len < *lenp) {
1612 if (get_user(c, p++))
1613 return -EFAULT;
1614 if (c == 0 || c == '\n')
1615 break;
1616 len++;
1617 }
1618 if (len >= maxlen)
1619 len = maxlen-1;
1620 if(copy_from_user(data, buffer, len))
1621 return -EFAULT;
1622 ((char *) data)[len] = 0;
1623 *ppos += *lenp;
1624 } else {
1625 len = strlen(data);
1626 if (len > maxlen)
1627 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001628
1629 if (*ppos > len) {
1630 *lenp = 0;
1631 return 0;
1632 }
1633
1634 data += *ppos;
1635 len -= *ppos;
1636
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001637 if (len > *lenp)
1638 len = *lenp;
1639 if (len)
1640 if(copy_to_user(buffer, data, len))
1641 return -EFAULT;
1642 if (len < *lenp) {
1643 if(put_user('\n', ((char __user *) buffer) + len))
1644 return -EFAULT;
1645 len++;
1646 }
1647 *lenp = len;
1648 *ppos += len;
1649 }
1650 return 0;
1651}
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653/**
1654 * proc_dostring - read a string sysctl
1655 * @table: the sysctl table
1656 * @write: %TRUE if this is a write to the sysctl file
1657 * @filp: the file structure
1658 * @buffer: the user buffer
1659 * @lenp: the size of the user buffer
1660 * @ppos: file position
1661 *
1662 * Reads/writes a string from/to the user buffer. If the kernel
1663 * buffer provided is not large enough to hold the string, the
1664 * string is truncated. The copied string is %NULL-terminated.
1665 * If the string is being read by the user process, it is copied
1666 * and a newline '\n' is added. It is truncated if the buffer is
1667 * not large enough.
1668 *
1669 * Returns 0 on success.
1670 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001671int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 void __user *buffer, size_t *lenp, loff_t *ppos)
1673{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001674 return _proc_do_string(table->data, table->maxlen, write, filp,
1675 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676}
1677
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1680 int *valp,
1681 int write, void *data)
1682{
1683 if (write) {
1684 *valp = *negp ? -*lvalp : *lvalp;
1685 } else {
1686 int val = *valp;
1687 if (val < 0) {
1688 *negp = -1;
1689 *lvalp = (unsigned long)-val;
1690 } else {
1691 *negp = 0;
1692 *lvalp = (unsigned long)val;
1693 }
1694 }
1695 return 0;
1696}
1697
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001698static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001699 int write, struct file *filp, void __user *buffer,
1700 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1702 int write, void *data),
1703 void *data)
1704{
1705#define TMPBUFLEN 21
1706 int *i, vleft, first=1, neg, val;
1707 unsigned long lval;
1708 size_t left, len;
1709
1710 char buf[TMPBUFLEN], *p;
1711 char __user *s = buffer;
1712
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001713 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 (*ppos && !write)) {
1715 *lenp = 0;
1716 return 0;
1717 }
1718
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001719 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 vleft = table->maxlen / sizeof(*i);
1721 left = *lenp;
1722
1723 if (!conv)
1724 conv = do_proc_dointvec_conv;
1725
1726 for (; left && vleft--; i++, first=0) {
1727 if (write) {
1728 while (left) {
1729 char c;
1730 if (get_user(c, s))
1731 return -EFAULT;
1732 if (!isspace(c))
1733 break;
1734 left--;
1735 s++;
1736 }
1737 if (!left)
1738 break;
1739 neg = 0;
1740 len = left;
1741 if (len > sizeof(buf) - 1)
1742 len = sizeof(buf) - 1;
1743 if (copy_from_user(buf, s, len))
1744 return -EFAULT;
1745 buf[len] = 0;
1746 p = buf;
1747 if (*p == '-' && left > 1) {
1748 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001749 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 }
1751 if (*p < '0' || *p > '9')
1752 break;
1753
1754 lval = simple_strtoul(p, &p, 0);
1755
1756 len = p-buf;
1757 if ((len < left) && *p && !isspace(*p))
1758 break;
1759 if (neg)
1760 val = -val;
1761 s += len;
1762 left -= len;
1763
1764 if (conv(&neg, &lval, i, 1, data))
1765 break;
1766 } else {
1767 p = buf;
1768 if (!first)
1769 *p++ = '\t';
1770
1771 if (conv(&neg, &lval, i, 0, data))
1772 break;
1773
1774 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1775 len = strlen(buf);
1776 if (len > left)
1777 len = left;
1778 if(copy_to_user(s, buf, len))
1779 return -EFAULT;
1780 left -= len;
1781 s += len;
1782 }
1783 }
1784
1785 if (!write && !first && left) {
1786 if(put_user('\n', s))
1787 return -EFAULT;
1788 left--, s++;
1789 }
1790 if (write) {
1791 while (left) {
1792 char c;
1793 if (get_user(c, s++))
1794 return -EFAULT;
1795 if (!isspace(c))
1796 break;
1797 left--;
1798 }
1799 }
1800 if (write && first)
1801 return -EINVAL;
1802 *lenp -= left;
1803 *ppos += *lenp;
1804 return 0;
1805#undef TMPBUFLEN
1806}
1807
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001808static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001809 void __user *buffer, size_t *lenp, loff_t *ppos,
1810 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1811 int write, void *data),
1812 void *data)
1813{
1814 return __do_proc_dointvec(table->data, table, write, filp,
1815 buffer, lenp, ppos, conv, data);
1816}
1817
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818/**
1819 * proc_dointvec - read a vector of integers
1820 * @table: the sysctl table
1821 * @write: %TRUE if this is a write to the sysctl file
1822 * @filp: the file structure
1823 * @buffer: the user buffer
1824 * @lenp: the size of the user buffer
1825 * @ppos: file position
1826 *
1827 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1828 * values from/to the user buffer, treated as an ASCII string.
1829 *
1830 * Returns 0 on success.
1831 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001832int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 void __user *buffer, size_t *lenp, loff_t *ppos)
1834{
1835 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1836 NULL,NULL);
1837}
1838
1839#define OP_SET 0
1840#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001841#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
1843static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1844 int *valp,
1845 int write, void *data)
1846{
1847 int op = *(int *)data;
1848 if (write) {
1849 int val = *negp ? -*lvalp : *lvalp;
1850 switch(op) {
1851 case OP_SET: *valp = val; break;
1852 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001853 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 }
1855 } else {
1856 int val = *valp;
1857 if (val < 0) {
1858 *negp = -1;
1859 *lvalp = (unsigned long)-val;
1860 } else {
1861 *negp = 0;
1862 *lvalp = (unsigned long)val;
1863 }
1864 }
1865 return 0;
1866}
1867
1868/*
1869 * init may raise the set.
1870 */
1871
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001872int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 void __user *buffer, size_t *lenp, loff_t *ppos)
1874{
1875 int op;
1876
Eric Paris6ff1b442007-02-10 01:43:19 -08001877 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 return -EPERM;
1879 }
1880
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001881 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1883 do_proc_dointvec_bset_conv,&op);
1884}
1885
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001886/*
1887 * Taint values can only be increased
1888 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001889static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001890 void __user *buffer, size_t *lenp, loff_t *ppos)
1891{
1892 int op;
1893
Bastian Blank91fcd412007-04-23 14:41:14 -07001894 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001895 return -EPERM;
1896
1897 op = OP_OR;
1898 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1899 do_proc_dointvec_bset_conv,&op);
1900}
1901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902struct do_proc_dointvec_minmax_conv_param {
1903 int *min;
1904 int *max;
1905};
1906
1907static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1908 int *valp,
1909 int write, void *data)
1910{
1911 struct do_proc_dointvec_minmax_conv_param *param = data;
1912 if (write) {
1913 int val = *negp ? -*lvalp : *lvalp;
1914 if ((param->min && *param->min > val) ||
1915 (param->max && *param->max < val))
1916 return -EINVAL;
1917 *valp = val;
1918 } else {
1919 int val = *valp;
1920 if (val < 0) {
1921 *negp = -1;
1922 *lvalp = (unsigned long)-val;
1923 } else {
1924 *negp = 0;
1925 *lvalp = (unsigned long)val;
1926 }
1927 }
1928 return 0;
1929}
1930
1931/**
1932 * proc_dointvec_minmax - read a vector of integers with min/max values
1933 * @table: the sysctl table
1934 * @write: %TRUE if this is a write to the sysctl file
1935 * @filp: the file structure
1936 * @buffer: the user buffer
1937 * @lenp: the size of the user buffer
1938 * @ppos: file position
1939 *
1940 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1941 * values from/to the user buffer, treated as an ASCII string.
1942 *
1943 * This routine will ensure the values are within the range specified by
1944 * table->extra1 (min) and table->extra2 (max).
1945 *
1946 * Returns 0 on success.
1947 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001948int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 void __user *buffer, size_t *lenp, loff_t *ppos)
1950{
1951 struct do_proc_dointvec_minmax_conv_param param = {
1952 .min = (int *) table->extra1,
1953 .max = (int *) table->extra2,
1954 };
1955 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1956 do_proc_dointvec_minmax_conv, &param);
1957}
1958
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001959static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 struct file *filp,
1961 void __user *buffer,
1962 size_t *lenp, loff_t *ppos,
1963 unsigned long convmul,
1964 unsigned long convdiv)
1965{
1966#define TMPBUFLEN 21
1967 unsigned long *i, *min, *max, val;
1968 int vleft, first=1, neg;
1969 size_t len, left;
1970 char buf[TMPBUFLEN], *p;
1971 char __user *s = buffer;
1972
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001973 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 (*ppos && !write)) {
1975 *lenp = 0;
1976 return 0;
1977 }
1978
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001979 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 min = (unsigned long *) table->extra1;
1981 max = (unsigned long *) table->extra2;
1982 vleft = table->maxlen / sizeof(unsigned long);
1983 left = *lenp;
1984
1985 for (; left && vleft--; i++, min++, max++, first=0) {
1986 if (write) {
1987 while (left) {
1988 char c;
1989 if (get_user(c, s))
1990 return -EFAULT;
1991 if (!isspace(c))
1992 break;
1993 left--;
1994 s++;
1995 }
1996 if (!left)
1997 break;
1998 neg = 0;
1999 len = left;
2000 if (len > TMPBUFLEN-1)
2001 len = TMPBUFLEN-1;
2002 if (copy_from_user(buf, s, len))
2003 return -EFAULT;
2004 buf[len] = 0;
2005 p = buf;
2006 if (*p == '-' && left > 1) {
2007 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002008 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
2010 if (*p < '0' || *p > '9')
2011 break;
2012 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2013 len = p-buf;
2014 if ((len < left) && *p && !isspace(*p))
2015 break;
2016 if (neg)
2017 val = -val;
2018 s += len;
2019 left -= len;
2020
2021 if(neg)
2022 continue;
2023 if ((min && val < *min) || (max && val > *max))
2024 continue;
2025 *i = val;
2026 } else {
2027 p = buf;
2028 if (!first)
2029 *p++ = '\t';
2030 sprintf(p, "%lu", convdiv * (*i) / convmul);
2031 len = strlen(buf);
2032 if (len > left)
2033 len = left;
2034 if(copy_to_user(s, buf, len))
2035 return -EFAULT;
2036 left -= len;
2037 s += len;
2038 }
2039 }
2040
2041 if (!write && !first && left) {
2042 if(put_user('\n', s))
2043 return -EFAULT;
2044 left--, s++;
2045 }
2046 if (write) {
2047 while (left) {
2048 char c;
2049 if (get_user(c, s++))
2050 return -EFAULT;
2051 if (!isspace(c))
2052 break;
2053 left--;
2054 }
2055 }
2056 if (write && first)
2057 return -EINVAL;
2058 *lenp -= left;
2059 *ppos += *lenp;
2060 return 0;
2061#undef TMPBUFLEN
2062}
2063
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002064static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002065 struct file *filp,
2066 void __user *buffer,
2067 size_t *lenp, loff_t *ppos,
2068 unsigned long convmul,
2069 unsigned long convdiv)
2070{
2071 return __do_proc_doulongvec_minmax(table->data, table, write,
2072 filp, buffer, lenp, ppos, convmul, convdiv);
2073}
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075/**
2076 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2077 * @table: the sysctl table
2078 * @write: %TRUE if this is a write to the sysctl file
2079 * @filp: the file structure
2080 * @buffer: the user buffer
2081 * @lenp: the size of the user buffer
2082 * @ppos: file position
2083 *
2084 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2085 * values from/to the user buffer, treated as an ASCII string.
2086 *
2087 * This routine will ensure the values are within the range specified by
2088 * table->extra1 (min) and table->extra2 (max).
2089 *
2090 * Returns 0 on success.
2091 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002092int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 void __user *buffer, size_t *lenp, loff_t *ppos)
2094{
2095 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2096}
2097
2098/**
2099 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2100 * @table: the sysctl table
2101 * @write: %TRUE if this is a write to the sysctl file
2102 * @filp: the file structure
2103 * @buffer: the user buffer
2104 * @lenp: the size of the user buffer
2105 * @ppos: file position
2106 *
2107 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2108 * values from/to the user buffer, treated as an ASCII string. The values
2109 * are treated as milliseconds, and converted to jiffies when they are stored.
2110 *
2111 * This routine will ensure the values are within the range specified by
2112 * table->extra1 (min) and table->extra2 (max).
2113 *
2114 * Returns 0 on success.
2115 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002116int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 struct file *filp,
2118 void __user *buffer,
2119 size_t *lenp, loff_t *ppos)
2120{
2121 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2122 lenp, ppos, HZ, 1000l);
2123}
2124
2125
2126static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2127 int *valp,
2128 int write, void *data)
2129{
2130 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002131 if (*lvalp > LONG_MAX / HZ)
2132 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2134 } else {
2135 int val = *valp;
2136 unsigned long lval;
2137 if (val < 0) {
2138 *negp = -1;
2139 lval = (unsigned long)-val;
2140 } else {
2141 *negp = 0;
2142 lval = (unsigned long)val;
2143 }
2144 *lvalp = lval / HZ;
2145 }
2146 return 0;
2147}
2148
2149static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2150 int *valp,
2151 int write, void *data)
2152{
2153 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002154 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2155 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2157 } else {
2158 int val = *valp;
2159 unsigned long lval;
2160 if (val < 0) {
2161 *negp = -1;
2162 lval = (unsigned long)-val;
2163 } else {
2164 *negp = 0;
2165 lval = (unsigned long)val;
2166 }
2167 *lvalp = jiffies_to_clock_t(lval);
2168 }
2169 return 0;
2170}
2171
2172static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2173 int *valp,
2174 int write, void *data)
2175{
2176 if (write) {
2177 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2178 } else {
2179 int val = *valp;
2180 unsigned long lval;
2181 if (val < 0) {
2182 *negp = -1;
2183 lval = (unsigned long)-val;
2184 } else {
2185 *negp = 0;
2186 lval = (unsigned long)val;
2187 }
2188 *lvalp = jiffies_to_msecs(lval);
2189 }
2190 return 0;
2191}
2192
2193/**
2194 * proc_dointvec_jiffies - read a vector of integers as seconds
2195 * @table: the sysctl table
2196 * @write: %TRUE if this is a write to the sysctl file
2197 * @filp: the file structure
2198 * @buffer: the user buffer
2199 * @lenp: the size of the user buffer
2200 * @ppos: file position
2201 *
2202 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2203 * values from/to the user buffer, treated as an ASCII string.
2204 * The values read are assumed to be in seconds, and are converted into
2205 * jiffies.
2206 *
2207 * Returns 0 on success.
2208 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002209int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 void __user *buffer, size_t *lenp, loff_t *ppos)
2211{
2212 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2213 do_proc_dointvec_jiffies_conv,NULL);
2214}
2215
2216/**
2217 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2218 * @table: the sysctl table
2219 * @write: %TRUE if this is a write to the sysctl file
2220 * @filp: the file structure
2221 * @buffer: the user buffer
2222 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002223 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 *
2225 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2226 * values from/to the user buffer, treated as an ASCII string.
2227 * The values read are assumed to be in 1/USER_HZ seconds, and
2228 * are converted into jiffies.
2229 *
2230 * Returns 0 on success.
2231 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002232int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 void __user *buffer, size_t *lenp, loff_t *ppos)
2234{
2235 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2236 do_proc_dointvec_userhz_jiffies_conv,NULL);
2237}
2238
2239/**
2240 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2241 * @table: the sysctl table
2242 * @write: %TRUE if this is a write to the sysctl file
2243 * @filp: the file structure
2244 * @buffer: the user buffer
2245 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002246 * @ppos: file position
2247 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 *
2249 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2250 * values from/to the user buffer, treated as an ASCII string.
2251 * The values read are assumed to be in 1/1000 seconds, and
2252 * are converted into jiffies.
2253 *
2254 * Returns 0 on success.
2255 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002256int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 void __user *buffer, size_t *lenp, loff_t *ppos)
2258{
2259 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2260 do_proc_dointvec_ms_jiffies_conv, NULL);
2261}
2262
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002263static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002264 void __user *buffer, size_t *lenp, loff_t *ppos)
2265{
2266 struct pid *new_pid;
2267 pid_t tmp;
2268 int r;
2269
2270 tmp = pid_nr(cad_pid);
2271
2272 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2273 lenp, ppos, NULL, NULL);
2274 if (r || !write)
2275 return r;
2276
2277 new_pid = find_get_pid(tmp);
2278 if (!new_pid)
2279 return -ESRCH;
2280
2281 put_pid(xchg(&cad_pid, new_pid));
2282 return 0;
2283}
2284
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285#else /* CONFIG_PROC_FS */
2286
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002287int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 void __user *buffer, size_t *lenp, loff_t *ppos)
2289{
2290 return -ENOSYS;
2291}
2292
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002293int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 void __user *buffer, size_t *lenp, loff_t *ppos)
2295{
2296 return -ENOSYS;
2297}
2298
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002299int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 void __user *buffer, size_t *lenp, loff_t *ppos)
2301{
2302 return -ENOSYS;
2303}
2304
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002305int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 void __user *buffer, size_t *lenp, loff_t *ppos)
2307{
2308 return -ENOSYS;
2309}
2310
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002311int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 void __user *buffer, size_t *lenp, loff_t *ppos)
2313{
2314 return -ENOSYS;
2315}
2316
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002317int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 void __user *buffer, size_t *lenp, loff_t *ppos)
2319{
2320 return -ENOSYS;
2321}
2322
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002323int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 void __user *buffer, size_t *lenp, loff_t *ppos)
2325{
2326 return -ENOSYS;
2327}
2328
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002329int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 void __user *buffer, size_t *lenp, loff_t *ppos)
2331{
2332 return -ENOSYS;
2333}
2334
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002335int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 struct file *filp,
2337 void __user *buffer,
2338 size_t *lenp, loff_t *ppos)
2339{
2340 return -ENOSYS;
2341}
2342
2343
2344#endif /* CONFIG_PROC_FS */
2345
2346
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002347#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348/*
2349 * General sysctl support routines
2350 */
2351
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002352/* The generic sysctl data routine (used if no strategy routine supplied) */
2353int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2354 void __user *oldval, size_t __user *oldlenp,
2355 void __user *newval, size_t newlen)
2356{
2357 size_t len;
2358
2359 /* Get out of I don't have a variable */
2360 if (!table->data || !table->maxlen)
2361 return -ENOTDIR;
2362
2363 if (oldval && oldlenp) {
2364 if (get_user(len, oldlenp))
2365 return -EFAULT;
2366 if (len) {
2367 if (len > table->maxlen)
2368 len = table->maxlen;
2369 if (copy_to_user(oldval, table->data, len))
2370 return -EFAULT;
2371 if (put_user(len, oldlenp))
2372 return -EFAULT;
2373 }
2374 }
2375
2376 if (newval && newlen) {
2377 if (newlen > table->maxlen)
2378 newlen = table->maxlen;
2379
2380 if (copy_from_user(table->data, newval, newlen))
2381 return -EFAULT;
2382 }
2383 return 1;
2384}
2385
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002387int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002389 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 if (!table->data || !table->maxlen)
2392 return -ENOTDIR;
2393
2394 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002395 size_t bufsize;
2396 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002398 if (bufsize) {
2399 size_t len = strlen(table->data), copied;
2400
2401 /* This shouldn't trigger for a well-formed sysctl */
2402 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002404
2405 /* Copy up to a max of bufsize-1 bytes of the string */
2406 copied = (len >= bufsize) ? bufsize - 1 : len;
2407
2408 if (copy_to_user(oldval, table->data, copied) ||
2409 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002411 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 return -EFAULT;
2413 }
2414 }
2415 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002416 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 if (len > table->maxlen)
2418 len = table->maxlen;
2419 if(copy_from_user(table->data, newval, len))
2420 return -EFAULT;
2421 if (len == table->maxlen)
2422 len--;
2423 ((char *) table->data)[len] = 0;
2424 }
Yi Yang82c9df82005-12-30 16:37:10 +08002425 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426}
2427
2428/*
2429 * This function makes sure that all of the integers in the vector
2430 * are between the minimum and maximum values given in the arrays
2431 * table->extra1 and table->extra2, respectively.
2432 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002433int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002435 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
2437
2438 if (newval && newlen) {
2439 int __user *vec = (int __user *) newval;
2440 int *min = (int *) table->extra1;
2441 int *max = (int *) table->extra2;
2442 size_t length;
2443 int i;
2444
2445 if (newlen % sizeof(int) != 0)
2446 return -EINVAL;
2447
2448 if (!table->extra1 && !table->extra2)
2449 return 0;
2450
2451 if (newlen > table->maxlen)
2452 newlen = table->maxlen;
2453 length = newlen / sizeof(int);
2454
2455 for (i = 0; i < length; i++) {
2456 int value;
2457 if (get_user(value, vec + i))
2458 return -EFAULT;
2459 if (min && value < min[i])
2460 return -EINVAL;
2461 if (max && value > max[i])
2462 return -EINVAL;
2463 }
2464 }
2465 return 0;
2466}
2467
2468/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002469int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002471 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002473 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002475
2476 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002478 if (olen) {
2479 int val;
2480
2481 if (olen < sizeof(int))
2482 return -EINVAL;
2483
2484 val = *(int *)(table->data) / HZ;
2485 if (put_user(val, (int __user *)oldval))
2486 return -EFAULT;
2487 if (put_user(sizeof(int), oldlenp))
2488 return -EFAULT;
2489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 }
2491 if (newval && newlen) {
2492 int new;
2493 if (newlen != sizeof(int))
2494 return -EINVAL;
2495 if (get_user(new, (int __user *)newval))
2496 return -EFAULT;
2497 *(int *)(table->data) = new*HZ;
2498 }
2499 return 1;
2500}
2501
2502/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002503int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002505 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002507 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002509
2510 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002512 if (olen) {
2513 int val;
2514
2515 if (olen < sizeof(int))
2516 return -EINVAL;
2517
2518 val = jiffies_to_msecs(*(int *)(table->data));
2519 if (put_user(val, (int __user *)oldval))
2520 return -EFAULT;
2521 if (put_user(sizeof(int), oldlenp))
2522 return -EFAULT;
2523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 }
2525 if (newval && newlen) {
2526 int new;
2527 if (newlen != sizeof(int))
2528 return -EINVAL;
2529 if (get_user(new, (int __user *)newval))
2530 return -EFAULT;
2531 *(int *)(table->data) = msecs_to_jiffies(new);
2532 }
2533 return 1;
2534}
2535
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002536
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002537
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002538#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539
2540
2541asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2542{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002543 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002544 struct __sysctl_args tmp;
2545 int name[CTL_MAXNAME];
2546 int i;
2547
2548 /* Read in the sysctl name for better debug message logging */
2549 if (copy_from_user(&tmp, args, sizeof(tmp)))
2550 return -EFAULT;
2551 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2552 return -ENOTDIR;
2553 for (i = 0; i < tmp.nlen; i++)
2554 if (get_user(name[i], tmp.name + i))
2555 return -EFAULT;
2556
2557 /* Ignore accesses to kernel.version */
2558 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2559 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002560
2561 if (msg_count < 5) {
2562 msg_count++;
2563 printk(KERN_INFO
2564 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002565 "system call with ", current->comm);
2566 for (i = 0; i < tmp.nlen; i++)
2567 printk("%d.", name[i]);
2568 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002569 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002570out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 return -ENOSYS;
2572}
2573
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002574int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2575 void __user *oldval, size_t __user *oldlenp,
2576 void __user *newval, size_t newlen)
2577{
2578 return -ENOSYS;
2579}
2580
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002581int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002583 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584{
2585 return -ENOSYS;
2586}
2587
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002588int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002590 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591{
2592 return -ENOSYS;
2593}
2594
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002595int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002597 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598{
2599 return -ENOSYS;
2600}
2601
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002602int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002604 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605{
2606 return -ENOSYS;
2607}
2608
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002609#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610
2611/*
2612 * No sense putting this after each symbol definition, twice,
2613 * exception granted :-)
2614 */
2615EXPORT_SYMBOL(proc_dointvec);
2616EXPORT_SYMBOL(proc_dointvec_jiffies);
2617EXPORT_SYMBOL(proc_dointvec_minmax);
2618EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2619EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2620EXPORT_SYMBOL(proc_dostring);
2621EXPORT_SYMBOL(proc_doulongvec_minmax);
2622EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2623EXPORT_SYMBOL(register_sysctl_table);
2624EXPORT_SYMBOL(sysctl_intvec);
2625EXPORT_SYMBOL(sysctl_jiffies);
2626EXPORT_SYMBOL(sysctl_ms_jiffies);
2627EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002628EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629EXPORT_SYMBOL(unregister_sysctl_table);