blob: dde3d53e8adc0fd8aabbf871d0b5c6751dfb9907 [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 Molnar23f78d4a2006-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 *,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800145 void __user *, size_t, 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
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700150static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
151 void __user *buffer, size_t *lenp, loff_t *ppos);
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800152static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
153 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static ctl_table root_table[];
157static struct ctl_table_header root_table_header =
158 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
159
160static ctl_table kern_table[];
161static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162static ctl_table fs_table[];
163static ctl_table debug_table[];
164static ctl_table dev_table[];
165extern ctl_table random_table[];
166#ifdef CONFIG_UNIX98_PTYS
167extern ctl_table pty_table[];
168#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700169#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400170extern ctl_table inotify_table[];
171#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
174int sysctl_legacy_va_layout;
175#endif
176
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700177extern int prove_locking;
178extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/* The default sysctl tables: */
181
182static ctl_table root_table[] = {
183 {
184 .ctl_name = CTL_KERN,
185 .procname = "kernel",
186 .mode = 0555,
187 .child = kern_table,
188 },
189 {
190 .ctl_name = CTL_VM,
191 .procname = "vm",
192 .mode = 0555,
193 .child = vm_table,
194 },
195#ifdef CONFIG_NET
196 {
197 .ctl_name = CTL_NET,
198 .procname = "net",
199 .mode = 0555,
200 .child = net_table,
201 },
202#endif
203 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 .ctl_name = CTL_FS,
205 .procname = "fs",
206 .mode = 0555,
207 .child = fs_table,
208 },
209 {
210 .ctl_name = CTL_DEBUG,
211 .procname = "debug",
212 .mode = 0555,
213 .child = debug_table,
214 },
215 {
216 .ctl_name = CTL_DEV,
217 .procname = "dev",
218 .mode = 0555,
219 .child = dev_table,
220 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700221/*
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
224 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 { .ctl_name = 0 }
226};
227
Ingo Molnar77e54a12007-07-09 18:52:00 +0200228#ifdef CONFIG_SCHED_DEBUG
229static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
230static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
231static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
232static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
233#endif
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235static ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200236#ifdef CONFIG_SCHED_DEBUG
237 {
238 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200239 .procname = "sched_nr_latency",
240 .data = &sysctl_sched_nr_latency,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200241 .maxlen = sizeof(unsigned int),
242 .mode = 0644,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200243 .proc_handler = &proc_dointvec,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244 },
245 {
246 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200247 .procname = "sched_latency_ns",
248 .data = &sysctl_sched_latency,
249 .maxlen = sizeof(unsigned int),
250 .mode = 0644,
251 .proc_handler = &proc_dointvec_minmax,
252 .strategy = &sysctl_intvec,
253 .extra1 = &min_sched_granularity_ns,
254 .extra2 = &max_sched_granularity_ns,
255 },
256 {
257 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200258 .procname = "sched_wakeup_granularity_ns",
259 .data = &sysctl_sched_wakeup_granularity,
260 .maxlen = sizeof(unsigned int),
261 .mode = 0644,
262 .proc_handler = &proc_dointvec_minmax,
263 .strategy = &sysctl_intvec,
264 .extra1 = &min_wakeup_granularity_ns,
265 .extra2 = &max_wakeup_granularity_ns,
266 },
267 {
268 .ctl_name = CTL_UNNUMBERED,
269 .procname = "sched_batch_wakeup_granularity_ns",
270 .data = &sysctl_sched_batch_wakeup_granularity,
271 .maxlen = sizeof(unsigned int),
272 .mode = 0644,
273 .proc_handler = &proc_dointvec_minmax,
274 .strategy = &sysctl_intvec,
275 .extra1 = &min_wakeup_granularity_ns,
276 .extra2 = &max_wakeup_granularity_ns,
277 },
278 {
279 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200280 .procname = "sched_child_runs_first",
281 .data = &sysctl_sched_child_runs_first,
282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
284 .proc_handler = &proc_dointvec,
285 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200286 {
287 .ctl_name = CTL_UNNUMBERED,
288 .procname = "sched_features",
289 .data = &sysctl_sched_features,
290 .maxlen = sizeof(unsigned int),
291 .mode = 0644,
292 .proc_handler = &proc_dointvec,
293 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200294 {
295 .ctl_name = CTL_UNNUMBERED,
296 .procname = "sched_migration_cost",
297 .data = &sysctl_sched_migration_cost,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
300 .proc_handler = &proc_dointvec,
301 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200302#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200303 {
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_compat_yield",
306 .data = &sysctl_sched_compat_yield,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec,
310 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700311#ifdef CONFIG_PROVE_LOCKING
312 {
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "prove_locking",
315 .data = &prove_locking,
316 .maxlen = sizeof(int),
317 .mode = 0644,
318 .proc_handler = &proc_dointvec,
319 },
320#endif
321#ifdef CONFIG_LOCK_STAT
322 {
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "lock_stat",
325 .data = &lock_stat,
326 .maxlen = sizeof(int),
327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
329 },
330#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200331 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 .ctl_name = KERN_PANIC,
333 .procname = "panic",
334 .data = &panic_timeout,
335 .maxlen = sizeof(int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
338 },
339 {
340 .ctl_name = KERN_CORE_USES_PID,
341 .procname = "core_uses_pid",
342 .data = &core_uses_pid,
343 .maxlen = sizeof(int),
344 .mode = 0644,
345 .proc_handler = &proc_dointvec,
346 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700347#ifdef CONFIG_AUDITSYSCALL
348 {
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "audit_argv_kb",
351 .data = &audit_argv_kb,
352 .maxlen = sizeof(int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
355 },
356#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 {
358 .ctl_name = KERN_CORE_PATTERN,
359 .procname = "core_pattern",
360 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700361 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 .mode = 0644,
363 .proc_handler = &proc_dostring,
364 .strategy = &sysctl_string,
365 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800366#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 {
368 .ctl_name = KERN_TAINTED,
369 .procname = "tainted",
370 .data = &tainted,
371 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800372 .mode = 0644,
373 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800375#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 {
377 .ctl_name = KERN_CAP_BSET,
378 .procname = "cap-bound",
379 .data = &cap_bset,
380 .maxlen = sizeof(kernel_cap_t),
381 .mode = 0600,
382 .proc_handler = &proc_dointvec_bset,
383 },
384#ifdef CONFIG_BLK_DEV_INITRD
385 {
386 .ctl_name = KERN_REALROOTDEV,
387 .procname = "real-root-dev",
388 .data = &real_root_dev,
389 .maxlen = sizeof(int),
390 .mode = 0644,
391 .proc_handler = &proc_dointvec,
392 },
393#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700394 {
395 .ctl_name = CTL_UNNUMBERED,
396 .procname = "print-fatal-signals",
397 .data = &print_fatal_signals,
398 .maxlen = sizeof(int),
399 .mode = 0644,
400 .proc_handler = &proc_dointvec,
401 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#ifdef __sparc__
403 {
404 .ctl_name = KERN_SPARC_REBOOT,
405 .procname = "reboot-cmd",
406 .data = reboot_command,
407 .maxlen = 256,
408 .mode = 0644,
409 .proc_handler = &proc_dostring,
410 .strategy = &sysctl_string,
411 },
412 {
413 .ctl_name = KERN_SPARC_STOP_A,
414 .procname = "stop-a",
415 .data = &stop_a_enabled,
416 .maxlen = sizeof (int),
417 .mode = 0644,
418 .proc_handler = &proc_dointvec,
419 },
420 {
421 .ctl_name = KERN_SPARC_SCONS_PWROFF,
422 .procname = "scons-poweroff",
423 .data = &scons_pwroff,
424 .maxlen = sizeof (int),
425 .mode = 0644,
426 .proc_handler = &proc_dointvec,
427 },
428#endif
429#ifdef __hppa__
430 {
431 .ctl_name = KERN_HPPA_PWRSW,
432 .procname = "soft-power",
433 .data = &pwrsw_enabled,
434 .maxlen = sizeof (int),
435 .mode = 0644,
436 .proc_handler = &proc_dointvec,
437 },
438 {
439 .ctl_name = KERN_HPPA_UNALIGNED,
440 .procname = "unaligned-trap",
441 .data = &unaligned_enabled,
442 .maxlen = sizeof (int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
445 },
446#endif
447 {
448 .ctl_name = KERN_CTLALTDEL,
449 .procname = "ctrl-alt-del",
450 .data = &C_A_D,
451 .maxlen = sizeof(int),
452 .mode = 0644,
453 .proc_handler = &proc_dointvec,
454 },
455 {
456 .ctl_name = KERN_PRINTK,
457 .procname = "printk",
458 .data = &console_loglevel,
459 .maxlen = 4*sizeof(int),
460 .mode = 0644,
461 .proc_handler = &proc_dointvec,
462 },
463#ifdef CONFIG_KMOD
464 {
465 .ctl_name = KERN_MODPROBE,
466 .procname = "modprobe",
467 .data = &modprobe_path,
468 .maxlen = KMOD_PATH_LEN,
469 .mode = 0644,
470 .proc_handler = &proc_dostring,
471 .strategy = &sysctl_string,
472 },
473#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700474#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 {
476 .ctl_name = KERN_HOTPLUG,
477 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100478 .data = &uevent_helper,
479 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .mode = 0644,
481 .proc_handler = &proc_dostring,
482 .strategy = &sysctl_string,
483 },
484#endif
485#ifdef CONFIG_CHR_DEV_SG
486 {
487 .ctl_name = KERN_SG_BIG_BUFF,
488 .procname = "sg-big-buff",
489 .data = &sg_big_buff,
490 .maxlen = sizeof (int),
491 .mode = 0444,
492 .proc_handler = &proc_dointvec,
493 },
494#endif
495#ifdef CONFIG_BSD_PROCESS_ACCT
496 {
497 .ctl_name = KERN_ACCT,
498 .procname = "acct",
499 .data = &acct_parm,
500 .maxlen = 3*sizeof(int),
501 .mode = 0644,
502 .proc_handler = &proc_dointvec,
503 },
504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#ifdef CONFIG_MAGIC_SYSRQ
506 {
507 .ctl_name = KERN_SYSRQ,
508 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800509 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 .maxlen = sizeof (int),
511 .mode = 0644,
512 .proc_handler = &proc_dointvec,
513 },
514#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700515#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 {
517 .ctl_name = KERN_CADPID,
518 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700519 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .maxlen = sizeof (int),
521 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700522 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700524#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 {
526 .ctl_name = KERN_MAX_THREADS,
527 .procname = "threads-max",
528 .data = &max_threads,
529 .maxlen = sizeof(int),
530 .mode = 0644,
531 .proc_handler = &proc_dointvec,
532 },
533 {
534 .ctl_name = KERN_RANDOM,
535 .procname = "random",
536 .mode = 0555,
537 .child = random_table,
538 },
539#ifdef CONFIG_UNIX98_PTYS
540 {
541 .ctl_name = KERN_PTY,
542 .procname = "pty",
543 .mode = 0555,
544 .child = pty_table,
545 },
546#endif
547 {
548 .ctl_name = KERN_OVERFLOWUID,
549 .procname = "overflowuid",
550 .data = &overflowuid,
551 .maxlen = sizeof(int),
552 .mode = 0644,
553 .proc_handler = &proc_dointvec_minmax,
554 .strategy = &sysctl_intvec,
555 .extra1 = &minolduid,
556 .extra2 = &maxolduid,
557 },
558 {
559 .ctl_name = KERN_OVERFLOWGID,
560 .procname = "overflowgid",
561 .data = &overflowgid,
562 .maxlen = sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec_minmax,
565 .strategy = &sysctl_intvec,
566 .extra1 = &minolduid,
567 .extra2 = &maxolduid,
568 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800569#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#ifdef CONFIG_MATHEMU
571 {
572 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
573 .procname = "ieee_emulation_warnings",
574 .data = &sysctl_ieee_emulation_warnings,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
578 },
579#endif
580#ifdef CONFIG_NO_IDLE_HZ
581 {
582 .ctl_name = KERN_HZ_TIMER,
583 .procname = "hz_timer",
584 .data = &sysctl_hz_timer,
585 .maxlen = sizeof(int),
586 .mode = 0644,
587 .proc_handler = &proc_dointvec,
588 },
589#endif
590 {
591 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
592 .procname = "userprocess_debug",
593 .data = &sysctl_userprocess_debug,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec,
597 },
598#endif
599 {
600 .ctl_name = KERN_PIDMAX,
601 .procname = "pid_max",
602 .data = &pid_max,
603 .maxlen = sizeof (int),
604 .mode = 0644,
605 .proc_handler = &proc_dointvec_minmax,
606 .strategy = sysctl_intvec,
607 .extra1 = &pid_max_min,
608 .extra2 = &pid_max_max,
609 },
610 {
611 .ctl_name = KERN_PANIC_ON_OOPS,
612 .procname = "panic_on_oops",
613 .data = &panic_on_oops,
614 .maxlen = sizeof(int),
615 .mode = 0644,
616 .proc_handler = &proc_dointvec,
617 },
618 {
619 .ctl_name = KERN_PRINTK_RATELIMIT,
620 .procname = "printk_ratelimit",
621 .data = &printk_ratelimit_jiffies,
622 .maxlen = sizeof(int),
623 .mode = 0644,
624 .proc_handler = &proc_dointvec_jiffies,
625 .strategy = &sysctl_jiffies,
626 },
627 {
628 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
629 .procname = "printk_ratelimit_burst",
630 .data = &printk_ratelimit_burst,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
634 },
635 {
636 .ctl_name = KERN_NGROUPS_MAX,
637 .procname = "ngroups_max",
638 .data = &ngroups_max,
639 .maxlen = sizeof (int),
640 .mode = 0444,
641 .proc_handler = &proc_dointvec,
642 },
643#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
644 {
645 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
646 .procname = "unknown_nmi_panic",
647 .data = &unknown_nmi_panic,
648 .maxlen = sizeof (int),
649 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200650 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 },
Don Zickus407984f2006-09-26 10:52:27 +0200652 {
653 .ctl_name = KERN_NMI_WATCHDOG,
654 .procname = "nmi_watchdog",
655 .data = &nmi_watchdog_enabled,
656 .maxlen = sizeof (int),
657 .mode = 0644,
658 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 },
660#endif
661#if defined(CONFIG_X86)
662 {
Don Zickus8da5add2006-09-26 10:52:27 +0200663 .ctl_name = KERN_PANIC_ON_NMI,
664 .procname = "panic_on_unrecovered_nmi",
665 .data = &panic_on_unrecovered_nmi,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec,
669 },
670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .ctl_name = KERN_BOOTLOADER_TYPE,
672 .procname = "bootloader_type",
673 .data = &bootloader_type,
674 .maxlen = sizeof (int),
675 .mode = 0444,
676 .proc_handler = &proc_dointvec,
677 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100678 {
679 .ctl_name = CTL_UNNUMBERED,
680 .procname = "kstack_depth_to_print",
681 .data = &kstack_depth_to_print,
682 .maxlen = sizeof(int),
683 .mode = 0644,
684 .proc_handler = &proc_dointvec,
685 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800687#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 {
689 .ctl_name = KERN_RANDOMIZE,
690 .procname = "randomize_va_space",
691 .data = &randomize_va_space,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 .proc_handler = &proc_dointvec,
695 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800696#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800697#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700698 {
699 .ctl_name = KERN_SPIN_RETRY,
700 .procname = "spin_retry",
701 .data = &spin_retry,
702 .maxlen = sizeof (int),
703 .mode = 0644,
704 .proc_handler = &proc_dointvec,
705 },
706#endif
Len Brown673d5b42007-07-28 03:33:16 -0400707#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800708 {
709 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
710 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700711 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800712 .maxlen = sizeof (unsigned long),
713 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800714 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800715 },
716#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800717#ifdef CONFIG_IA64
718 {
719 .ctl_name = KERN_IA64_UNALIGNED,
720 .procname = "ignore-unaligned-usertrap",
721 .data = &no_unaligned_warning,
722 .maxlen = sizeof (int),
723 .mode = 0644,
724 .proc_handler = &proc_dointvec,
725 },
726#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700727#ifdef CONFIG_DETECT_SOFTLOCKUP
728 {
729 .ctl_name = CTL_UNNUMBERED,
730 .procname = "softlockup_thresh",
731 .data = &softlockup_thresh,
732 .maxlen = sizeof(int),
733 .mode = 0644,
734 .proc_handler = &proc_dointvec_minmax,
735 .strategy = &sysctl_intvec,
736 .extra1 = &one,
737 .extra2 = &sixty,
738 },
739#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200740#ifdef CONFIG_COMPAT
741 {
742 .ctl_name = KERN_COMPAT_LOG,
743 .procname = "compat-log",
744 .data = &compat_log,
745 .maxlen = sizeof (int),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
748 },
749#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700750#ifdef CONFIG_RT_MUTEXES
751 {
752 .ctl_name = KERN_MAX_LOCK_DEPTH,
753 .procname = "max_lock_depth",
754 .data = &max_lock_depth,
755 .maxlen = sizeof(int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
758 },
759#endif
Kees Cook5096add2007-05-08 00:26:04 -0700760#ifdef CONFIG_PROC_FS
761 {
762 .ctl_name = CTL_UNNUMBERED,
763 .procname = "maps_protect",
764 .data = &maps_protect,
765 .maxlen = sizeof(int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
768 },
769#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700770 {
771 .ctl_name = CTL_UNNUMBERED,
772 .procname = "poweroff_cmd",
773 .data = &poweroff_cmd,
774 .maxlen = POWEROFF_CMD_PATH_LEN,
775 .mode = 0644,
776 .proc_handler = &proc_dostring,
777 .strategy = &sysctl_string,
778 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700779/*
780 * NOTE: do not add new entries to this table unless you have read
781 * Documentation/sysctl/ctl_unnumbered.txt
782 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 { .ctl_name = 0 }
784};
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786static ctl_table vm_table[] = {
787 {
788 .ctl_name = VM_OVERCOMMIT_MEMORY,
789 .procname = "overcommit_memory",
790 .data = &sysctl_overcommit_memory,
791 .maxlen = sizeof(sysctl_overcommit_memory),
792 .mode = 0644,
793 .proc_handler = &proc_dointvec,
794 },
795 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700796 .ctl_name = VM_PANIC_ON_OOM,
797 .procname = "panic_on_oom",
798 .data = &sysctl_panic_on_oom,
799 .maxlen = sizeof(sysctl_panic_on_oom),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
803 {
David Rientjesfe071d72007-10-16 23:25:56 -0700804 .ctl_name = CTL_UNNUMBERED,
805 .procname = "oom_kill_allocating_task",
806 .data = &sysctl_oom_kill_allocating_task,
807 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
808 .mode = 0644,
809 .proc_handler = &proc_dointvec,
810 },
811 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 .ctl_name = VM_OVERCOMMIT_RATIO,
813 .procname = "overcommit_ratio",
814 .data = &sysctl_overcommit_ratio,
815 .maxlen = sizeof(sysctl_overcommit_ratio),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec,
818 },
819 {
820 .ctl_name = VM_PAGE_CLUSTER,
821 .procname = "page-cluster",
822 .data = &page_cluster,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec,
826 },
827 {
828 .ctl_name = VM_DIRTY_BACKGROUND,
829 .procname = "dirty_background_ratio",
830 .data = &dirty_background_ratio,
831 .maxlen = sizeof(dirty_background_ratio),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec_minmax,
834 .strategy = &sysctl_intvec,
835 .extra1 = &zero,
836 .extra2 = &one_hundred,
837 },
838 {
839 .ctl_name = VM_DIRTY_RATIO,
840 .procname = "dirty_ratio",
841 .data = &vm_dirty_ratio,
842 .maxlen = sizeof(vm_dirty_ratio),
843 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700844 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 .strategy = &sysctl_intvec,
846 .extra1 = &zero,
847 .extra2 = &one_hundred,
848 },
849 {
850 .ctl_name = VM_DIRTY_WB_CS,
851 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800852 .data = &dirty_writeback_interval,
853 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 .mode = 0644,
855 .proc_handler = &dirty_writeback_centisecs_handler,
856 },
857 {
858 .ctl_name = VM_DIRTY_EXPIRE_CS,
859 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800860 .data = &dirty_expire_interval,
861 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800863 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 },
865 {
866 .ctl_name = VM_NR_PDFLUSH_THREADS,
867 .procname = "nr_pdflush_threads",
868 .data = &nr_pdflush_threads,
869 .maxlen = sizeof nr_pdflush_threads,
870 .mode = 0444 /* read-only*/,
871 .proc_handler = &proc_dointvec,
872 },
873 {
874 .ctl_name = VM_SWAPPINESS,
875 .procname = "swappiness",
876 .data = &vm_swappiness,
877 .maxlen = sizeof(vm_swappiness),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec_minmax,
880 .strategy = &sysctl_intvec,
881 .extra1 = &zero,
882 .extra2 = &one_hundred,
883 },
884#ifdef CONFIG_HUGETLB_PAGE
885 {
886 .ctl_name = VM_HUGETLB_PAGES,
887 .procname = "nr_hugepages",
888 .data = &max_huge_pages,
889 .maxlen = sizeof(unsigned long),
890 .mode = 0644,
891 .proc_handler = &hugetlb_sysctl_handler,
892 .extra1 = (void *)&hugetlb_zero,
893 .extra2 = (void *)&hugetlb_infinity,
894 },
895 {
896 .ctl_name = VM_HUGETLB_GROUP,
897 .procname = "hugetlb_shm_group",
898 .data = &sysctl_hugetlb_shm_group,
899 .maxlen = sizeof(gid_t),
900 .mode = 0644,
901 .proc_handler = &proc_dointvec,
902 },
Mel Gorman396faf02007-07-17 04:03:13 -0700903 {
904 .ctl_name = CTL_UNNUMBERED,
905 .procname = "hugepages_treat_as_movable",
906 .data = &hugepages_treat_as_movable,
907 .maxlen = sizeof(int),
908 .mode = 0644,
909 .proc_handler = &hugetlb_treat_movable_handler,
910 },
Adam Litke54f9f802007-10-16 01:26:20 -0700911 {
912 .ctl_name = CTL_UNNUMBERED,
913 .procname = "hugetlb_dynamic_pool",
914 .data = &hugetlb_dynamic_pool,
915 .maxlen = sizeof(hugetlb_dynamic_pool),
916 .mode = 0644,
917 .proc_handler = &proc_dointvec,
918 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919#endif
920 {
921 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
922 .procname = "lowmem_reserve_ratio",
923 .data = &sysctl_lowmem_reserve_ratio,
924 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
925 .mode = 0644,
926 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
927 .strategy = &sysctl_intvec,
928 },
929 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800930 .ctl_name = VM_DROP_PAGECACHE,
931 .procname = "drop_caches",
932 .data = &sysctl_drop_caches,
933 .maxlen = sizeof(int),
934 .mode = 0644,
935 .proc_handler = drop_caches_sysctl_handler,
936 .strategy = &sysctl_intvec,
937 },
938 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 .ctl_name = VM_MIN_FREE_KBYTES,
940 .procname = "min_free_kbytes",
941 .data = &min_free_kbytes,
942 .maxlen = sizeof(min_free_kbytes),
943 .mode = 0644,
944 .proc_handler = &min_free_kbytes_sysctl_handler,
945 .strategy = &sysctl_intvec,
946 .extra1 = &zero,
947 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800948 {
949 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
950 .procname = "percpu_pagelist_fraction",
951 .data = &percpu_pagelist_fraction,
952 .maxlen = sizeof(percpu_pagelist_fraction),
953 .mode = 0644,
954 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
955 .strategy = &sysctl_intvec,
956 .extra1 = &min_percpu_pagelist_fract,
957 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958#ifdef CONFIG_MMU
959 {
960 .ctl_name = VM_MAX_MAP_COUNT,
961 .procname = "max_map_count",
962 .data = &sysctl_max_map_count,
963 .maxlen = sizeof(sysctl_max_map_count),
964 .mode = 0644,
965 .proc_handler = &proc_dointvec
966 },
967#endif
968 {
969 .ctl_name = VM_LAPTOP_MODE,
970 .procname = "laptop_mode",
971 .data = &laptop_mode,
972 .maxlen = sizeof(laptop_mode),
973 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800974 .proc_handler = &proc_dointvec_jiffies,
975 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 },
977 {
978 .ctl_name = VM_BLOCK_DUMP,
979 .procname = "block_dump",
980 .data = &block_dump,
981 .maxlen = sizeof(block_dump),
982 .mode = 0644,
983 .proc_handler = &proc_dointvec,
984 .strategy = &sysctl_intvec,
985 .extra1 = &zero,
986 },
987 {
988 .ctl_name = VM_VFS_CACHE_PRESSURE,
989 .procname = "vfs_cache_pressure",
990 .data = &sysctl_vfs_cache_pressure,
991 .maxlen = sizeof(sysctl_vfs_cache_pressure),
992 .mode = 0644,
993 .proc_handler = &proc_dointvec,
994 .strategy = &sysctl_intvec,
995 .extra1 = &zero,
996 },
997#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
998 {
999 .ctl_name = VM_LEGACY_VA_LAYOUT,
1000 .procname = "legacy_va_layout",
1001 .data = &sysctl_legacy_va_layout,
1002 .maxlen = sizeof(sysctl_legacy_va_layout),
1003 .mode = 0644,
1004 .proc_handler = &proc_dointvec,
1005 .strategy = &sysctl_intvec,
1006 .extra1 = &zero,
1007 },
1008#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001009#ifdef CONFIG_NUMA
1010 {
1011 .ctl_name = VM_ZONE_RECLAIM_MODE,
1012 .procname = "zone_reclaim_mode",
1013 .data = &zone_reclaim_mode,
1014 .maxlen = sizeof(zone_reclaim_mode),
1015 .mode = 0644,
1016 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001017 .strategy = &sysctl_intvec,
1018 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001019 },
Christoph Lameter96146342006-07-03 00:24:13 -07001020 {
1021 .ctl_name = VM_MIN_UNMAPPED,
1022 .procname = "min_unmapped_ratio",
1023 .data = &sysctl_min_unmapped_ratio,
1024 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1025 .mode = 0644,
1026 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1027 .strategy = &sysctl_intvec,
1028 .extra1 = &zero,
1029 .extra2 = &one_hundred,
1030 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001031 {
1032 .ctl_name = VM_MIN_SLAB,
1033 .procname = "min_slab_ratio",
1034 .data = &sysctl_min_slab_ratio,
1035 .maxlen = sizeof(sysctl_min_slab_ratio),
1036 .mode = 0644,
1037 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1038 .strategy = &sysctl_intvec,
1039 .extra1 = &zero,
1040 .extra2 = &one_hundred,
1041 },
Christoph Lameter17436602006-01-18 17:42:32 -08001042#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001043#ifdef CONFIG_SMP
1044 {
1045 .ctl_name = CTL_UNNUMBERED,
1046 .procname = "stat_interval",
1047 .data = &sysctl_stat_interval,
1048 .maxlen = sizeof(sysctl_stat_interval),
1049 .mode = 0644,
1050 .proc_handler = &proc_dointvec_jiffies,
1051 .strategy = &sysctl_jiffies,
1052 },
1053#endif
Eric Parised032182007-06-28 15:55:21 -04001054#ifdef CONFIG_SECURITY
1055 {
1056 .ctl_name = CTL_UNNUMBERED,
1057 .procname = "mmap_min_addr",
1058 .data = &mmap_min_addr,
1059 .maxlen = sizeof(unsigned long),
1060 .mode = 0644,
1061 .proc_handler = &proc_doulongvec_minmax,
1062 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001063#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001064#ifdef CONFIG_NUMA
1065 {
1066 .ctl_name = CTL_UNNUMBERED,
1067 .procname = "numa_zonelist_order",
1068 .data = &numa_zonelist_order,
1069 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1070 .mode = 0644,
1071 .proc_handler = &numa_zonelist_order_handler,
1072 .strategy = &sysctl_string,
1073 },
1074#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001075#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001076 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001077 {
1078 .ctl_name = VM_VDSO_ENABLED,
1079 .procname = "vdso_enabled",
1080 .data = &vdso_enabled,
1081 .maxlen = sizeof(vdso_enabled),
1082 .mode = 0644,
1083 .proc_handler = &proc_dointvec,
1084 .strategy = &sysctl_intvec,
1085 .extra1 = &zero,
1086 },
1087#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001088/*
1089 * NOTE: do not add new entries to this table unless you have read
1090 * Documentation/sysctl/ctl_unnumbered.txt
1091 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 { .ctl_name = 0 }
1093};
1094
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001095#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1096static ctl_table binfmt_misc_table[] = {
1097 { .ctl_name = 0 }
1098};
1099#endif
1100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101static ctl_table fs_table[] = {
1102 {
1103 .ctl_name = FS_NRINODE,
1104 .procname = "inode-nr",
1105 .data = &inodes_stat,
1106 .maxlen = 2*sizeof(int),
1107 .mode = 0444,
1108 .proc_handler = &proc_dointvec,
1109 },
1110 {
1111 .ctl_name = FS_STATINODE,
1112 .procname = "inode-state",
1113 .data = &inodes_stat,
1114 .maxlen = 7*sizeof(int),
1115 .mode = 0444,
1116 .proc_handler = &proc_dointvec,
1117 },
1118 {
1119 .ctl_name = FS_NRFILE,
1120 .procname = "file-nr",
1121 .data = &files_stat,
1122 .maxlen = 3*sizeof(int),
1123 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001124 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 },
1126 {
1127 .ctl_name = FS_MAXFILE,
1128 .procname = "file-max",
1129 .data = &files_stat.max_files,
1130 .maxlen = sizeof(int),
1131 .mode = 0644,
1132 .proc_handler = &proc_dointvec,
1133 },
1134 {
1135 .ctl_name = FS_DENTRY,
1136 .procname = "dentry-state",
1137 .data = &dentry_stat,
1138 .maxlen = 6*sizeof(int),
1139 .mode = 0444,
1140 .proc_handler = &proc_dointvec,
1141 },
1142 {
1143 .ctl_name = FS_OVERFLOWUID,
1144 .procname = "overflowuid",
1145 .data = &fs_overflowuid,
1146 .maxlen = sizeof(int),
1147 .mode = 0644,
1148 .proc_handler = &proc_dointvec_minmax,
1149 .strategy = &sysctl_intvec,
1150 .extra1 = &minolduid,
1151 .extra2 = &maxolduid,
1152 },
1153 {
1154 .ctl_name = FS_OVERFLOWGID,
1155 .procname = "overflowgid",
1156 .data = &fs_overflowgid,
1157 .maxlen = sizeof(int),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec_minmax,
1160 .strategy = &sysctl_intvec,
1161 .extra1 = &minolduid,
1162 .extra2 = &maxolduid,
1163 },
1164 {
1165 .ctl_name = FS_LEASES,
1166 .procname = "leases-enable",
1167 .data = &leases_enable,
1168 .maxlen = sizeof(int),
1169 .mode = 0644,
1170 .proc_handler = &proc_dointvec,
1171 },
1172#ifdef CONFIG_DNOTIFY
1173 {
1174 .ctl_name = FS_DIR_NOTIFY,
1175 .procname = "dir-notify-enable",
1176 .data = &dir_notify_enable,
1177 .maxlen = sizeof(int),
1178 .mode = 0644,
1179 .proc_handler = &proc_dointvec,
1180 },
1181#endif
1182#ifdef CONFIG_MMU
1183 {
1184 .ctl_name = FS_LEASE_TIME,
1185 .procname = "lease-break-time",
1186 .data = &lease_break_time,
1187 .maxlen = sizeof(int),
1188 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001189 .proc_handler = &proc_dointvec_minmax,
1190 .strategy = &sysctl_intvec,
1191 .extra1 = &zero,
1192 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 },
1194 {
1195 .ctl_name = FS_AIO_NR,
1196 .procname = "aio-nr",
1197 .data = &aio_nr,
1198 .maxlen = sizeof(aio_nr),
1199 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001200 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 },
1202 {
1203 .ctl_name = FS_AIO_MAX_NR,
1204 .procname = "aio-max-nr",
1205 .data = &aio_max_nr,
1206 .maxlen = sizeof(aio_max_nr),
1207 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001208 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001210#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001211 {
1212 .ctl_name = FS_INOTIFY,
1213 .procname = "inotify",
1214 .mode = 0555,
1215 .child = inotify_table,
1216 },
1217#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001219 {
1220 .ctl_name = KERN_SETUID_DUMPABLE,
1221 .procname = "suid_dumpable",
1222 .data = &suid_dumpable,
1223 .maxlen = sizeof(int),
1224 .mode = 0644,
1225 .proc_handler = &proc_dointvec,
1226 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001227#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1228 {
1229 .ctl_name = CTL_UNNUMBERED,
1230 .procname = "binfmt_misc",
1231 .mode = 0555,
1232 .child = binfmt_misc_table,
1233 },
1234#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001235/*
1236 * NOTE: do not add new entries to this table unless you have read
1237 * Documentation/sysctl/ctl_unnumbered.txt
1238 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 { .ctl_name = 0 }
1240};
1241
1242static ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001243#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001244 {
1245 .ctl_name = CTL_UNNUMBERED,
1246 .procname = "exception-trace",
1247 .data = &show_unhandled_signals,
1248 .maxlen = sizeof(int),
1249 .mode = 0644,
1250 .proc_handler = proc_dointvec
1251 },
1252#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 { .ctl_name = 0 }
1254};
1255
1256static ctl_table dev_table[] = {
1257 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001258};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259
Al Viro330d57f2005-11-04 10:18:40 +00001260static DEFINE_SPINLOCK(sysctl_lock);
1261
1262/* called under sysctl_lock */
1263static int use_table(struct ctl_table_header *p)
1264{
1265 if (unlikely(p->unregistering))
1266 return 0;
1267 p->used++;
1268 return 1;
1269}
1270
1271/* called under sysctl_lock */
1272static void unuse_table(struct ctl_table_header *p)
1273{
1274 if (!--p->used)
1275 if (unlikely(p->unregistering))
1276 complete(p->unregistering);
1277}
1278
1279/* called under sysctl_lock, will reacquire if has to wait */
1280static void start_unregistering(struct ctl_table_header *p)
1281{
1282 /*
1283 * if p->used is 0, nobody will ever touch that entry again;
1284 * we'll eliminate all paths to it before dropping sysctl_lock
1285 */
1286 if (unlikely(p->used)) {
1287 struct completion wait;
1288 init_completion(&wait);
1289 p->unregistering = &wait;
1290 spin_unlock(&sysctl_lock);
1291 wait_for_completion(&wait);
1292 spin_lock(&sysctl_lock);
1293 }
1294 /*
1295 * do not remove from the list until nobody holds it; walking the
1296 * list in do_sysctl() relies on that.
1297 */
1298 list_del_init(&p->ctl_entry);
1299}
1300
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001301void sysctl_head_finish(struct ctl_table_header *head)
1302{
1303 if (!head)
1304 return;
1305 spin_lock(&sysctl_lock);
1306 unuse_table(head);
1307 spin_unlock(&sysctl_lock);
1308}
1309
1310struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1311{
1312 struct ctl_table_header *head;
1313 struct list_head *tmp;
1314 spin_lock(&sysctl_lock);
1315 if (prev) {
1316 tmp = &prev->ctl_entry;
1317 unuse_table(prev);
1318 goto next;
1319 }
1320 tmp = &root_table_header.ctl_entry;
1321 for (;;) {
1322 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1323
1324 if (!use_table(head))
1325 goto next;
1326 spin_unlock(&sysctl_lock);
1327 return head;
1328 next:
1329 tmp = tmp->next;
1330 if (tmp == &root_table_header.ctl_entry)
1331 break;
1332 }
1333 spin_unlock(&sysctl_lock);
1334 return NULL;
1335}
1336
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001337#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1339 void __user *newval, size_t newlen)
1340{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001341 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001342 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1345 return -ENOTDIR;
1346 if (oldval) {
1347 int old_len;
1348 if (!oldlenp || get_user(old_len, oldlenp))
1349 return -EFAULT;
1350 }
Al Viro330d57f2005-11-04 10:18:40 +00001351
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001352 for (head = sysctl_head_next(NULL); head;
1353 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001354 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001355 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001356 if (error != -ENOTDIR) {
1357 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001358 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001359 }
1360 }
Al Viro330d57f2005-11-04 10:18:40 +00001361 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362}
1363
1364asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1365{
1366 struct __sysctl_args tmp;
1367 int error;
1368
1369 if (copy_from_user(&tmp, args, sizeof(tmp)))
1370 return -EFAULT;
1371
1372 lock_kernel();
1373 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1374 tmp.newval, tmp.newlen);
1375 unlock_kernel();
1376 return error;
1377}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001378#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
1380/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001381 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 * some sysctl variables are readonly even to root.
1383 */
1384
1385static int test_perm(int mode, int op)
1386{
1387 if (!current->euid)
1388 mode >>= 6;
1389 else if (in_egroup_p(0))
1390 mode >>= 3;
1391 if ((mode & op & 0007) == op)
1392 return 0;
1393 return -EACCES;
1394}
1395
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001396int sysctl_perm(ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397{
1398 int error;
1399 error = security_sysctl(table, op);
1400 if (error)
1401 return error;
1402 return test_perm(table->mode, op);
1403}
1404
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001405#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406static int parse_table(int __user *name, int nlen,
1407 void __user *oldval, size_t __user *oldlenp,
1408 void __user *newval, size_t newlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001409 ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
1411 int n;
1412repeat:
1413 if (!nlen)
1414 return -ENOTDIR;
1415 if (get_user(n, name))
1416 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001417 for ( ; table->ctl_name || table->procname; table++) {
1418 if (!table->ctl_name)
1419 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001420 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 int error;
1422 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001423 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 name++;
1426 nlen--;
1427 table = table->child;
1428 goto repeat;
1429 }
1430 error = do_sysctl_strategy(table, name, nlen,
1431 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001432 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 return error;
1434 }
1435 }
1436 return -ENOTDIR;
1437}
1438
1439/* Perform the actual read/write of a sysctl table entry. */
1440int do_sysctl_strategy (ctl_table *table,
1441 int __user *name, int nlen,
1442 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001443 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
1445 int op = 0, rc;
1446 size_t len;
1447
1448 if (oldval)
1449 op |= 004;
1450 if (newval)
1451 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001452 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 return -EPERM;
1454
1455 if (table->strategy) {
1456 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001457 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 if (rc < 0)
1459 return rc;
1460 if (rc > 0)
1461 return 0;
1462 }
1463
1464 /* If there is no strategy routine, or if the strategy returns
1465 * zero, proceed with automatic r/w */
1466 if (table->data && table->maxlen) {
1467 if (oldval && oldlenp) {
1468 if (get_user(len, oldlenp))
1469 return -EFAULT;
1470 if (len) {
1471 if (len > table->maxlen)
1472 len = table->maxlen;
1473 if(copy_to_user(oldval, table->data, len))
1474 return -EFAULT;
1475 if(put_user(len, oldlenp))
1476 return -EFAULT;
1477 }
1478 }
1479 if (newval && newlen) {
1480 len = newlen;
1481 if (len > table->maxlen)
1482 len = table->maxlen;
1483 if(copy_from_user(table->data, newval, len))
1484 return -EFAULT;
1485 }
1486 }
1487 return 0;
1488}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001489#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001491static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1492{
1493 for (; table->ctl_name || table->procname; table++) {
1494 table->parent = parent;
1495 if (table->child)
1496 sysctl_set_parent(table, table->child);
1497 }
1498}
1499
1500static __init int sysctl_init(void)
1501{
1502 sysctl_set_parent(NULL, root_table);
1503 return 0;
1504}
1505
1506core_initcall(sysctl_init);
1507
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508/**
1509 * register_sysctl_table - register a sysctl hierarchy
1510 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 *
1512 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1513 * array. An entry with a ctl_name of 0 terminates the table.
1514 *
1515 * The members of the &ctl_table structure are used as follows:
1516 *
1517 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1518 * must be unique within that level of sysctl
1519 *
1520 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1521 * enter a sysctl file
1522 *
1523 * data - a pointer to data for use by proc_handler
1524 *
1525 * maxlen - the maximum size in bytes of the data
1526 *
1527 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1528 *
1529 * child - a pointer to the child sysctl table if this entry is a directory, or
1530 * %NULL.
1531 *
1532 * proc_handler - the text handler routine (described below)
1533 *
1534 * strategy - the strategy routine (described below)
1535 *
1536 * de - for internal use by the sysctl routines
1537 *
1538 * extra1, extra2 - extra pointers usable by the proc handler routines
1539 *
1540 * Leaf nodes in the sysctl tree will be represented by a single file
1541 * under /proc; non-leaf nodes will be represented by directories.
1542 *
1543 * sysctl(2) can automatically manage read and write requests through
1544 * the sysctl table. The data and maxlen fields of the ctl_table
1545 * struct enable minimal validation of the values being written to be
1546 * performed, and the mode field allows minimal authentication.
1547 *
1548 * More sophisticated management can be enabled by the provision of a
1549 * strategy routine with the table entry. This will be called before
1550 * any automatic read or write of the data is performed.
1551 *
1552 * The strategy routine may return
1553 *
1554 * < 0 - Error occurred (error is passed to user process)
1555 *
1556 * 0 - OK - proceed with automatic read or write.
1557 *
1558 * > 0 - OK - read or write has been done by the strategy routine, so
1559 * return immediately.
1560 *
1561 * There must be a proc_handler routine for any terminal nodes
1562 * mirrored under /proc/sys (non-terminals are handled by a built-in
1563 * directory handler). Several default handlers are available to
1564 * cover common cases -
1565 *
1566 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1567 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1568 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1569 *
1570 * It is the handler's job to read the input buffer from user memory
1571 * and process it. The handler should return 0 on success.
1572 *
1573 * This routine returns %NULL on a failure to register, and a pointer
1574 * to the table header on success.
1575 */
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001576struct ctl_table_header *register_sysctl_table(ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577{
1578 struct ctl_table_header *tmp;
1579 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1580 if (!tmp)
1581 return NULL;
1582 tmp->ctl_table = table;
1583 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001584 tmp->used = 0;
1585 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001586 sysctl_set_parent(NULL, table);
Al Viro330d57f2005-11-04 10:18:40 +00001587 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001588 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001589 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 return tmp;
1591}
1592
1593/**
1594 * unregister_sysctl_table - unregister a sysctl table hierarchy
1595 * @header: the header returned from register_sysctl_table
1596 *
1597 * Unregisters the sysctl table and all children. proc entries may not
1598 * actually be removed until they are no longer used by anyone.
1599 */
1600void unregister_sysctl_table(struct ctl_table_header * header)
1601{
Al Viro330d57f2005-11-04 10:18:40 +00001602 might_sleep();
1603 spin_lock(&sysctl_lock);
1604 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001605 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 kfree(header);
1607}
1608
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001609#else /* !CONFIG_SYSCTL */
Adrian Bunk93a6fef2007-02-28 20:12:23 -08001610struct ctl_table_header *register_sysctl_table(ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001611{
1612 return NULL;
1613}
1614
1615void unregister_sysctl_table(struct ctl_table_header * table)
1616{
1617}
1618
1619#endif /* CONFIG_SYSCTL */
1620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621/*
1622 * /proc/sys support
1623 */
1624
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001625#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001627static int _proc_do_string(void* data, int maxlen, int write,
1628 struct file *filp, void __user *buffer,
1629 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001630{
1631 size_t len;
1632 char __user *p;
1633 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001634
1635 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001636 *lenp = 0;
1637 return 0;
1638 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001639
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001640 if (write) {
1641 len = 0;
1642 p = buffer;
1643 while (len < *lenp) {
1644 if (get_user(c, p++))
1645 return -EFAULT;
1646 if (c == 0 || c == '\n')
1647 break;
1648 len++;
1649 }
1650 if (len >= maxlen)
1651 len = maxlen-1;
1652 if(copy_from_user(data, buffer, len))
1653 return -EFAULT;
1654 ((char *) data)[len] = 0;
1655 *ppos += *lenp;
1656 } else {
1657 len = strlen(data);
1658 if (len > maxlen)
1659 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001660
1661 if (*ppos > len) {
1662 *lenp = 0;
1663 return 0;
1664 }
1665
1666 data += *ppos;
1667 len -= *ppos;
1668
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001669 if (len > *lenp)
1670 len = *lenp;
1671 if (len)
1672 if(copy_to_user(buffer, data, len))
1673 return -EFAULT;
1674 if (len < *lenp) {
1675 if(put_user('\n', ((char __user *) buffer) + len))
1676 return -EFAULT;
1677 len++;
1678 }
1679 *lenp = len;
1680 *ppos += len;
1681 }
1682 return 0;
1683}
1684
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685/**
1686 * proc_dostring - read a string sysctl
1687 * @table: the sysctl table
1688 * @write: %TRUE if this is a write to the sysctl file
1689 * @filp: the file structure
1690 * @buffer: the user buffer
1691 * @lenp: the size of the user buffer
1692 * @ppos: file position
1693 *
1694 * Reads/writes a string from/to the user buffer. If the kernel
1695 * buffer provided is not large enough to hold the string, the
1696 * string is truncated. The copied string is %NULL-terminated.
1697 * If the string is being read by the user process, it is copied
1698 * and a newline '\n' is added. It is truncated if the buffer is
1699 * not large enough.
1700 *
1701 * Returns 0 on success.
1702 */
1703int proc_dostring(ctl_table *table, int write, struct file *filp,
1704 void __user *buffer, size_t *lenp, loff_t *ppos)
1705{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001706 return _proc_do_string(table->data, table->maxlen, write, filp,
1707 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708}
1709
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
1711static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1712 int *valp,
1713 int write, void *data)
1714{
1715 if (write) {
1716 *valp = *negp ? -*lvalp : *lvalp;
1717 } else {
1718 int val = *valp;
1719 if (val < 0) {
1720 *negp = -1;
1721 *lvalp = (unsigned long)-val;
1722 } else {
1723 *negp = 0;
1724 *lvalp = (unsigned long)val;
1725 }
1726 }
1727 return 0;
1728}
1729
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001730static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1731 int write, struct file *filp, void __user *buffer,
1732 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1734 int write, void *data),
1735 void *data)
1736{
1737#define TMPBUFLEN 21
1738 int *i, vleft, first=1, neg, val;
1739 unsigned long lval;
1740 size_t left, len;
1741
1742 char buf[TMPBUFLEN], *p;
1743 char __user *s = buffer;
1744
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001745 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 (*ppos && !write)) {
1747 *lenp = 0;
1748 return 0;
1749 }
1750
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001751 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 vleft = table->maxlen / sizeof(*i);
1753 left = *lenp;
1754
1755 if (!conv)
1756 conv = do_proc_dointvec_conv;
1757
1758 for (; left && vleft--; i++, first=0) {
1759 if (write) {
1760 while (left) {
1761 char c;
1762 if (get_user(c, s))
1763 return -EFAULT;
1764 if (!isspace(c))
1765 break;
1766 left--;
1767 s++;
1768 }
1769 if (!left)
1770 break;
1771 neg = 0;
1772 len = left;
1773 if (len > sizeof(buf) - 1)
1774 len = sizeof(buf) - 1;
1775 if (copy_from_user(buf, s, len))
1776 return -EFAULT;
1777 buf[len] = 0;
1778 p = buf;
1779 if (*p == '-' && left > 1) {
1780 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001781 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 }
1783 if (*p < '0' || *p > '9')
1784 break;
1785
1786 lval = simple_strtoul(p, &p, 0);
1787
1788 len = p-buf;
1789 if ((len < left) && *p && !isspace(*p))
1790 break;
1791 if (neg)
1792 val = -val;
1793 s += len;
1794 left -= len;
1795
1796 if (conv(&neg, &lval, i, 1, data))
1797 break;
1798 } else {
1799 p = buf;
1800 if (!first)
1801 *p++ = '\t';
1802
1803 if (conv(&neg, &lval, i, 0, data))
1804 break;
1805
1806 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1807 len = strlen(buf);
1808 if (len > left)
1809 len = left;
1810 if(copy_to_user(s, buf, len))
1811 return -EFAULT;
1812 left -= len;
1813 s += len;
1814 }
1815 }
1816
1817 if (!write && !first && left) {
1818 if(put_user('\n', s))
1819 return -EFAULT;
1820 left--, s++;
1821 }
1822 if (write) {
1823 while (left) {
1824 char c;
1825 if (get_user(c, s++))
1826 return -EFAULT;
1827 if (!isspace(c))
1828 break;
1829 left--;
1830 }
1831 }
1832 if (write && first)
1833 return -EINVAL;
1834 *lenp -= left;
1835 *ppos += *lenp;
1836 return 0;
1837#undef TMPBUFLEN
1838}
1839
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001840static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1841 void __user *buffer, size_t *lenp, loff_t *ppos,
1842 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1843 int write, void *data),
1844 void *data)
1845{
1846 return __do_proc_dointvec(table->data, table, write, filp,
1847 buffer, lenp, ppos, conv, data);
1848}
1849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850/**
1851 * proc_dointvec - read a vector of integers
1852 * @table: the sysctl table
1853 * @write: %TRUE if this is a write to the sysctl file
1854 * @filp: the file structure
1855 * @buffer: the user buffer
1856 * @lenp: the size of the user buffer
1857 * @ppos: file position
1858 *
1859 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1860 * values from/to the user buffer, treated as an ASCII string.
1861 *
1862 * Returns 0 on success.
1863 */
1864int proc_dointvec(ctl_table *table, int write, struct file *filp,
1865 void __user *buffer, size_t *lenp, loff_t *ppos)
1866{
1867 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1868 NULL,NULL);
1869}
1870
1871#define OP_SET 0
1872#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001873#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
1875static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1876 int *valp,
1877 int write, void *data)
1878{
1879 int op = *(int *)data;
1880 if (write) {
1881 int val = *negp ? -*lvalp : *lvalp;
1882 switch(op) {
1883 case OP_SET: *valp = val; break;
1884 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001885 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 }
1887 } else {
1888 int val = *valp;
1889 if (val < 0) {
1890 *negp = -1;
1891 *lvalp = (unsigned long)-val;
1892 } else {
1893 *negp = 0;
1894 *lvalp = (unsigned long)val;
1895 }
1896 }
1897 return 0;
1898}
1899
1900/*
1901 * init may raise the set.
1902 */
1903
1904int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1905 void __user *buffer, size_t *lenp, loff_t *ppos)
1906{
1907 int op;
1908
Eric Paris6ff1b442007-02-10 01:43:19 -08001909 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 return -EPERM;
1911 }
1912
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001913 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1915 do_proc_dointvec_bset_conv,&op);
1916}
1917
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001918/*
1919 * Taint values can only be increased
1920 */
1921static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1922 void __user *buffer, size_t *lenp, loff_t *ppos)
1923{
1924 int op;
1925
Bastian Blank91fcd412007-04-23 14:41:14 -07001926 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001927 return -EPERM;
1928
1929 op = OP_OR;
1930 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1931 do_proc_dointvec_bset_conv,&op);
1932}
1933
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934struct do_proc_dointvec_minmax_conv_param {
1935 int *min;
1936 int *max;
1937};
1938
1939static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1940 int *valp,
1941 int write, void *data)
1942{
1943 struct do_proc_dointvec_minmax_conv_param *param = data;
1944 if (write) {
1945 int val = *negp ? -*lvalp : *lvalp;
1946 if ((param->min && *param->min > val) ||
1947 (param->max && *param->max < val))
1948 return -EINVAL;
1949 *valp = val;
1950 } else {
1951 int val = *valp;
1952 if (val < 0) {
1953 *negp = -1;
1954 *lvalp = (unsigned long)-val;
1955 } else {
1956 *negp = 0;
1957 *lvalp = (unsigned long)val;
1958 }
1959 }
1960 return 0;
1961}
1962
1963/**
1964 * proc_dointvec_minmax - read a vector of integers with min/max values
1965 * @table: the sysctl table
1966 * @write: %TRUE if this is a write to the sysctl file
1967 * @filp: the file structure
1968 * @buffer: the user buffer
1969 * @lenp: the size of the user buffer
1970 * @ppos: file position
1971 *
1972 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1973 * values from/to the user buffer, treated as an ASCII string.
1974 *
1975 * This routine will ensure the values are within the range specified by
1976 * table->extra1 (min) and table->extra2 (max).
1977 *
1978 * Returns 0 on success.
1979 */
1980int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1981 void __user *buffer, size_t *lenp, loff_t *ppos)
1982{
1983 struct do_proc_dointvec_minmax_conv_param param = {
1984 .min = (int *) table->extra1,
1985 .max = (int *) table->extra2,
1986 };
1987 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1988 do_proc_dointvec_minmax_conv, &param);
1989}
1990
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001991static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 struct file *filp,
1993 void __user *buffer,
1994 size_t *lenp, loff_t *ppos,
1995 unsigned long convmul,
1996 unsigned long convdiv)
1997{
1998#define TMPBUFLEN 21
1999 unsigned long *i, *min, *max, val;
2000 int vleft, first=1, neg;
2001 size_t len, left;
2002 char buf[TMPBUFLEN], *p;
2003 char __user *s = buffer;
2004
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002005 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 (*ppos && !write)) {
2007 *lenp = 0;
2008 return 0;
2009 }
2010
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002011 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 min = (unsigned long *) table->extra1;
2013 max = (unsigned long *) table->extra2;
2014 vleft = table->maxlen / sizeof(unsigned long);
2015 left = *lenp;
2016
2017 for (; left && vleft--; i++, min++, max++, first=0) {
2018 if (write) {
2019 while (left) {
2020 char c;
2021 if (get_user(c, s))
2022 return -EFAULT;
2023 if (!isspace(c))
2024 break;
2025 left--;
2026 s++;
2027 }
2028 if (!left)
2029 break;
2030 neg = 0;
2031 len = left;
2032 if (len > TMPBUFLEN-1)
2033 len = TMPBUFLEN-1;
2034 if (copy_from_user(buf, s, len))
2035 return -EFAULT;
2036 buf[len] = 0;
2037 p = buf;
2038 if (*p == '-' && left > 1) {
2039 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002040 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 }
2042 if (*p < '0' || *p > '9')
2043 break;
2044 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2045 len = p-buf;
2046 if ((len < left) && *p && !isspace(*p))
2047 break;
2048 if (neg)
2049 val = -val;
2050 s += len;
2051 left -= len;
2052
2053 if(neg)
2054 continue;
2055 if ((min && val < *min) || (max && val > *max))
2056 continue;
2057 *i = val;
2058 } else {
2059 p = buf;
2060 if (!first)
2061 *p++ = '\t';
2062 sprintf(p, "%lu", convdiv * (*i) / convmul);
2063 len = strlen(buf);
2064 if (len > left)
2065 len = left;
2066 if(copy_to_user(s, buf, len))
2067 return -EFAULT;
2068 left -= len;
2069 s += len;
2070 }
2071 }
2072
2073 if (!write && !first && left) {
2074 if(put_user('\n', s))
2075 return -EFAULT;
2076 left--, s++;
2077 }
2078 if (write) {
2079 while (left) {
2080 char c;
2081 if (get_user(c, s++))
2082 return -EFAULT;
2083 if (!isspace(c))
2084 break;
2085 left--;
2086 }
2087 }
2088 if (write && first)
2089 return -EINVAL;
2090 *lenp -= left;
2091 *ppos += *lenp;
2092 return 0;
2093#undef TMPBUFLEN
2094}
2095
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002096static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2097 struct file *filp,
2098 void __user *buffer,
2099 size_t *lenp, loff_t *ppos,
2100 unsigned long convmul,
2101 unsigned long convdiv)
2102{
2103 return __do_proc_doulongvec_minmax(table->data, table, write,
2104 filp, buffer, lenp, ppos, convmul, convdiv);
2105}
2106
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107/**
2108 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2109 * @table: the sysctl table
2110 * @write: %TRUE if this is a write to the sysctl file
2111 * @filp: the file structure
2112 * @buffer: the user buffer
2113 * @lenp: the size of the user buffer
2114 * @ppos: file position
2115 *
2116 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2117 * values from/to the user buffer, treated as an ASCII string.
2118 *
2119 * This routine will ensure the values are within the range specified by
2120 * table->extra1 (min) and table->extra2 (max).
2121 *
2122 * Returns 0 on success.
2123 */
2124int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2125 void __user *buffer, size_t *lenp, loff_t *ppos)
2126{
2127 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2128}
2129
2130/**
2131 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2132 * @table: the sysctl table
2133 * @write: %TRUE if this is a write to the sysctl file
2134 * @filp: the file structure
2135 * @buffer: the user buffer
2136 * @lenp: the size of the user buffer
2137 * @ppos: file position
2138 *
2139 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2140 * values from/to the user buffer, treated as an ASCII string. The values
2141 * are treated as milliseconds, and converted to jiffies when they are stored.
2142 *
2143 * This routine will ensure the values are within the range specified by
2144 * table->extra1 (min) and table->extra2 (max).
2145 *
2146 * Returns 0 on success.
2147 */
2148int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2149 struct file *filp,
2150 void __user *buffer,
2151 size_t *lenp, loff_t *ppos)
2152{
2153 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2154 lenp, ppos, HZ, 1000l);
2155}
2156
2157
2158static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2159 int *valp,
2160 int write, void *data)
2161{
2162 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002163 if (*lvalp > LONG_MAX / HZ)
2164 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2166 } else {
2167 int val = *valp;
2168 unsigned long lval;
2169 if (val < 0) {
2170 *negp = -1;
2171 lval = (unsigned long)-val;
2172 } else {
2173 *negp = 0;
2174 lval = (unsigned long)val;
2175 }
2176 *lvalp = lval / HZ;
2177 }
2178 return 0;
2179}
2180
2181static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2182 int *valp,
2183 int write, void *data)
2184{
2185 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002186 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2187 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2189 } else {
2190 int val = *valp;
2191 unsigned long lval;
2192 if (val < 0) {
2193 *negp = -1;
2194 lval = (unsigned long)-val;
2195 } else {
2196 *negp = 0;
2197 lval = (unsigned long)val;
2198 }
2199 *lvalp = jiffies_to_clock_t(lval);
2200 }
2201 return 0;
2202}
2203
2204static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2205 int *valp,
2206 int write, void *data)
2207{
2208 if (write) {
2209 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2210 } else {
2211 int val = *valp;
2212 unsigned long lval;
2213 if (val < 0) {
2214 *negp = -1;
2215 lval = (unsigned long)-val;
2216 } else {
2217 *negp = 0;
2218 lval = (unsigned long)val;
2219 }
2220 *lvalp = jiffies_to_msecs(lval);
2221 }
2222 return 0;
2223}
2224
2225/**
2226 * proc_dointvec_jiffies - read a vector of integers as seconds
2227 * @table: the sysctl table
2228 * @write: %TRUE if this is a write to the sysctl file
2229 * @filp: the file structure
2230 * @buffer: the user buffer
2231 * @lenp: the size of the user buffer
2232 * @ppos: file position
2233 *
2234 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2235 * values from/to the user buffer, treated as an ASCII string.
2236 * The values read are assumed to be in seconds, and are converted into
2237 * jiffies.
2238 *
2239 * Returns 0 on success.
2240 */
2241int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2242 void __user *buffer, size_t *lenp, loff_t *ppos)
2243{
2244 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2245 do_proc_dointvec_jiffies_conv,NULL);
2246}
2247
2248/**
2249 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2250 * @table: the sysctl table
2251 * @write: %TRUE if this is a write to the sysctl file
2252 * @filp: the file structure
2253 * @buffer: the user buffer
2254 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002255 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 *
2257 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2258 * values from/to the user buffer, treated as an ASCII string.
2259 * The values read are assumed to be in 1/USER_HZ seconds, and
2260 * are converted into jiffies.
2261 *
2262 * Returns 0 on success.
2263 */
2264int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2265 void __user *buffer, size_t *lenp, loff_t *ppos)
2266{
2267 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2268 do_proc_dointvec_userhz_jiffies_conv,NULL);
2269}
2270
2271/**
2272 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2273 * @table: the sysctl table
2274 * @write: %TRUE if this is a write to the sysctl file
2275 * @filp: the file structure
2276 * @buffer: the user buffer
2277 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002278 * @ppos: file position
2279 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 *
2281 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2282 * values from/to the user buffer, treated as an ASCII string.
2283 * The values read are assumed to be in 1/1000 seconds, and
2284 * are converted into jiffies.
2285 *
2286 * Returns 0 on success.
2287 */
2288int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2289 void __user *buffer, size_t *lenp, loff_t *ppos)
2290{
2291 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2292 do_proc_dointvec_ms_jiffies_conv, NULL);
2293}
2294
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002295static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2296 void __user *buffer, size_t *lenp, loff_t *ppos)
2297{
2298 struct pid *new_pid;
2299 pid_t tmp;
2300 int r;
2301
2302 tmp = pid_nr(cad_pid);
2303
2304 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2305 lenp, ppos, NULL, NULL);
2306 if (r || !write)
2307 return r;
2308
2309 new_pid = find_get_pid(tmp);
2310 if (!new_pid)
2311 return -ESRCH;
2312
2313 put_pid(xchg(&cad_pid, new_pid));
2314 return 0;
2315}
2316
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317#else /* CONFIG_PROC_FS */
2318
2319int proc_dostring(ctl_table *table, int write, struct file *filp,
2320 void __user *buffer, size_t *lenp, loff_t *ppos)
2321{
2322 return -ENOSYS;
2323}
2324
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325int proc_dointvec(ctl_table *table, int write, struct file *filp,
2326 void __user *buffer, size_t *lenp, loff_t *ppos)
2327{
2328 return -ENOSYS;
2329}
2330
2331int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2332 void __user *buffer, size_t *lenp, loff_t *ppos)
2333{
2334 return -ENOSYS;
2335}
2336
2337int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2339{
2340 return -ENOSYS;
2341}
2342
2343int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2344 void __user *buffer, size_t *lenp, loff_t *ppos)
2345{
2346 return -ENOSYS;
2347}
2348
2349int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2350 void __user *buffer, size_t *lenp, loff_t *ppos)
2351{
2352 return -ENOSYS;
2353}
2354
2355int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2356 void __user *buffer, size_t *lenp, loff_t *ppos)
2357{
2358 return -ENOSYS;
2359}
2360
2361int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2362 void __user *buffer, size_t *lenp, loff_t *ppos)
2363{
2364 return -ENOSYS;
2365}
2366
2367int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2368 struct file *filp,
2369 void __user *buffer,
2370 size_t *lenp, loff_t *ppos)
2371{
2372 return -ENOSYS;
2373}
2374
2375
2376#endif /* CONFIG_PROC_FS */
2377
2378
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002379#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380/*
2381 * General sysctl support routines
2382 */
2383
2384/* The generic string strategy routine: */
2385int sysctl_string(ctl_table *table, int __user *name, int nlen,
2386 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002387 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 if (!table->data || !table->maxlen)
2390 return -ENOTDIR;
2391
2392 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002393 size_t bufsize;
2394 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002396 if (bufsize) {
2397 size_t len = strlen(table->data), copied;
2398
2399 /* This shouldn't trigger for a well-formed sysctl */
2400 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002402
2403 /* Copy up to a max of bufsize-1 bytes of the string */
2404 copied = (len >= bufsize) ? bufsize - 1 : len;
2405
2406 if (copy_to_user(oldval, table->data, copied) ||
2407 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002409 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 return -EFAULT;
2411 }
2412 }
2413 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002414 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 if (len > table->maxlen)
2416 len = table->maxlen;
2417 if(copy_from_user(table->data, newval, len))
2418 return -EFAULT;
2419 if (len == table->maxlen)
2420 len--;
2421 ((char *) table->data)[len] = 0;
2422 }
Yi Yang82c9df82005-12-30 16:37:10 +08002423 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424}
2425
2426/*
2427 * This function makes sure that all of the integers in the vector
2428 * are between the minimum and maximum values given in the arrays
2429 * table->extra1 and table->extra2, respectively.
2430 */
2431int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2432 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002433 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434{
2435
2436 if (newval && newlen) {
2437 int __user *vec = (int __user *) newval;
2438 int *min = (int *) table->extra1;
2439 int *max = (int *) table->extra2;
2440 size_t length;
2441 int i;
2442
2443 if (newlen % sizeof(int) != 0)
2444 return -EINVAL;
2445
2446 if (!table->extra1 && !table->extra2)
2447 return 0;
2448
2449 if (newlen > table->maxlen)
2450 newlen = table->maxlen;
2451 length = newlen / sizeof(int);
2452
2453 for (i = 0; i < length; i++) {
2454 int value;
2455 if (get_user(value, vec + i))
2456 return -EFAULT;
2457 if (min && value < min[i])
2458 return -EINVAL;
2459 if (max && value > max[i])
2460 return -EINVAL;
2461 }
2462 }
2463 return 0;
2464}
2465
2466/* Strategy function to convert jiffies to seconds */
2467int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2468 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002469 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002471 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002473
2474 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002476 if (olen) {
2477 int val;
2478
2479 if (olen < sizeof(int))
2480 return -EINVAL;
2481
2482 val = *(int *)(table->data) / HZ;
2483 if (put_user(val, (int __user *)oldval))
2484 return -EFAULT;
2485 if (put_user(sizeof(int), oldlenp))
2486 return -EFAULT;
2487 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 }
2489 if (newval && newlen) {
2490 int new;
2491 if (newlen != sizeof(int))
2492 return -EINVAL;
2493 if (get_user(new, (int __user *)newval))
2494 return -EFAULT;
2495 *(int *)(table->data) = new*HZ;
2496 }
2497 return 1;
2498}
2499
2500/* Strategy function to convert jiffies to seconds */
2501int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2502 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002503 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002505 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002507
2508 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002510 if (olen) {
2511 int val;
2512
2513 if (olen < sizeof(int))
2514 return -EINVAL;
2515
2516 val = jiffies_to_msecs(*(int *)(table->data));
2517 if (put_user(val, (int __user *)oldval))
2518 return -EFAULT;
2519 if (put_user(sizeof(int), oldlenp))
2520 return -EFAULT;
2521 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 }
2523 if (newval && newlen) {
2524 int new;
2525 if (newlen != sizeof(int))
2526 return -EINVAL;
2527 if (get_user(new, (int __user *)newval))
2528 return -EFAULT;
2529 *(int *)(table->data) = msecs_to_jiffies(new);
2530 }
2531 return 1;
2532}
2533
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002534
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002535
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002536#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537
2538
2539asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2540{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002541 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002542 struct __sysctl_args tmp;
2543 int name[CTL_MAXNAME];
2544 int i;
2545
2546 /* Read in the sysctl name for better debug message logging */
2547 if (copy_from_user(&tmp, args, sizeof(tmp)))
2548 return -EFAULT;
2549 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2550 return -ENOTDIR;
2551 for (i = 0; i < tmp.nlen; i++)
2552 if (get_user(name[i], tmp.name + i))
2553 return -EFAULT;
2554
2555 /* Ignore accesses to kernel.version */
2556 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2557 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002558
2559 if (msg_count < 5) {
2560 msg_count++;
2561 printk(KERN_INFO
2562 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002563 "system call with ", current->comm);
2564 for (i = 0; i < tmp.nlen; i++)
2565 printk("%d.", name[i]);
2566 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002567 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002568out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 return -ENOSYS;
2570}
2571
2572int sysctl_string(ctl_table *table, int __user *name, int nlen,
2573 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002574 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575{
2576 return -ENOSYS;
2577}
2578
2579int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2580 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
2586int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2587 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
2593int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2594 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002595 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596{
2597 return -ENOSYS;
2598}
2599
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002600#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601
2602/*
2603 * No sense putting this after each symbol definition, twice,
2604 * exception granted :-)
2605 */
2606EXPORT_SYMBOL(proc_dointvec);
2607EXPORT_SYMBOL(proc_dointvec_jiffies);
2608EXPORT_SYMBOL(proc_dointvec_minmax);
2609EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2610EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2611EXPORT_SYMBOL(proc_dostring);
2612EXPORT_SYMBOL(proc_doulongvec_minmax);
2613EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2614EXPORT_SYMBOL(register_sysctl_table);
2615EXPORT_SYMBOL(sysctl_intvec);
2616EXPORT_SYMBOL(sysctl_jiffies);
2617EXPORT_SYMBOL(sysctl_ms_jiffies);
2618EXPORT_SYMBOL(sysctl_string);
2619EXPORT_SYMBOL(unregister_sysctl_table);