blob: 5e63de0f9ee23dfd6bd1262984e6bb783a128231 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
84static int maxolduid = 65535;
85static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080086static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88static int ngroups_max = NGROUPS_MAX;
89
90#ifdef CONFIG_KMOD
91extern char modprobe_path[];
92#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#ifdef CONFIG_CHR_DEV_SG
94extern int sg_big_buff;
95#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97#ifdef __sparc__
98extern char reboot_command [];
99extern int stop_a_enabled;
100extern int scons_pwroff;
101#endif
102
103#ifdef __hppa__
104extern int pwrsw_enabled;
105extern int unaligned_enabled;
106#endif
107
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800108#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#ifdef CONFIG_MATHEMU
110extern int sysctl_ieee_emulation_warnings;
111#endif
112extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700113extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif
115
116extern int sysctl_hz_timer;
117
118#ifdef CONFIG_BSD_PROCESS_ACCT
119extern int acct_parm[];
120#endif
121
Jes Sorensend2b176e2006-02-28 09:42:23 -0800122#ifdef CONFIG_IA64
123extern int no_unaligned_warning;
124#endif
125
Ingo Molnar23f78d42006-06-27 02:54:53 -0700126#ifdef CONFIG_RT_MUTEXES
127extern int max_lock_depth;
128#endif
129
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700130#ifdef CONFIG_SYSCTL_SYSCALL
131static int parse_table(int __user *, int, void __user *, size_t __user *,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800132 void __user *, size_t, ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700133#endif
134
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800135
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700136#ifdef CONFIG_PROC_SYSCTL
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700137static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
138 void __user *buffer, size_t *lenp, loff_t *ppos);
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800139static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
140 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700141#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static ctl_table root_table[];
144static struct ctl_table_header root_table_header =
145 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
146
147static ctl_table kern_table[];
148static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static ctl_table fs_table[];
150static ctl_table debug_table[];
151static ctl_table dev_table[];
152extern ctl_table random_table[];
153#ifdef CONFIG_UNIX98_PTYS
154extern ctl_table pty_table[];
155#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700156#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400157extern ctl_table inotify_table[];
158#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
161int sysctl_legacy_va_layout;
162#endif
163
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700164extern int prove_locking;
165extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/* The default sysctl tables: */
168
169static ctl_table root_table[] = {
170 {
171 .ctl_name = CTL_KERN,
172 .procname = "kernel",
173 .mode = 0555,
174 .child = kern_table,
175 },
176 {
177 .ctl_name = CTL_VM,
178 .procname = "vm",
179 .mode = 0555,
180 .child = vm_table,
181 },
182#ifdef CONFIG_NET
183 {
184 .ctl_name = CTL_NET,
185 .procname = "net",
186 .mode = 0555,
187 .child = net_table,
188 },
189#endif
190 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 .ctl_name = CTL_FS,
192 .procname = "fs",
193 .mode = 0555,
194 .child = fs_table,
195 },
196 {
197 .ctl_name = CTL_DEBUG,
198 .procname = "debug",
199 .mode = 0555,
200 .child = debug_table,
201 },
202 {
203 .ctl_name = CTL_DEV,
204 .procname = "dev",
205 .mode = 0555,
206 .child = dev_table,
207 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700208/*
209 * NOTE: do not add new entries to this table unless you have read
210 * Documentation/sysctl/ctl_unnumbered.txt
211 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 { .ctl_name = 0 }
213};
214
Ingo Molnar77e54a12007-07-09 18:52:00 +0200215#ifdef CONFIG_SCHED_DEBUG
216static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
217static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
218static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
219static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
220#endif
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200223#ifdef CONFIG_SCHED_DEBUG
224 {
225 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200226 .procname = "sched_nr_latency",
227 .data = &sysctl_sched_nr_latency,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200228 .maxlen = sizeof(unsigned int),
229 .mode = 0644,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200230 .proc_handler = &proc_dointvec,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200231 },
232 {
233 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200234 .procname = "sched_latency_ns",
235 .data = &sysctl_sched_latency,
236 .maxlen = sizeof(unsigned int),
237 .mode = 0644,
238 .proc_handler = &proc_dointvec_minmax,
239 .strategy = &sysctl_intvec,
240 .extra1 = &min_sched_granularity_ns,
241 .extra2 = &max_sched_granularity_ns,
242 },
243 {
244 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200245 .procname = "sched_wakeup_granularity_ns",
246 .data = &sysctl_sched_wakeup_granularity,
247 .maxlen = sizeof(unsigned int),
248 .mode = 0644,
249 .proc_handler = &proc_dointvec_minmax,
250 .strategy = &sysctl_intvec,
251 .extra1 = &min_wakeup_granularity_ns,
252 .extra2 = &max_wakeup_granularity_ns,
253 },
254 {
255 .ctl_name = CTL_UNNUMBERED,
256 .procname = "sched_batch_wakeup_granularity_ns",
257 .data = &sysctl_sched_batch_wakeup_granularity,
258 .maxlen = sizeof(unsigned int),
259 .mode = 0644,
260 .proc_handler = &proc_dointvec_minmax,
261 .strategy = &sysctl_intvec,
262 .extra1 = &min_wakeup_granularity_ns,
263 .extra2 = &max_wakeup_granularity_ns,
264 },
265 {
266 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200267 .procname = "sched_child_runs_first",
268 .data = &sysctl_sched_child_runs_first,
269 .maxlen = sizeof(unsigned int),
270 .mode = 0644,
271 .proc_handler = &proc_dointvec,
272 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200273 {
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_features",
276 .data = &sysctl_sched_features,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = &proc_dointvec,
280 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200281 {
282 .ctl_name = CTL_UNNUMBERED,
283 .procname = "sched_migration_cost",
284 .data = &sysctl_sched_migration_cost,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = &proc_dointvec,
288 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200289#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200290 {
291 .ctl_name = CTL_UNNUMBERED,
292 .procname = "sched_compat_yield",
293 .data = &sysctl_sched_compat_yield,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec,
297 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700298#ifdef CONFIG_PROVE_LOCKING
299 {
300 .ctl_name = CTL_UNNUMBERED,
301 .procname = "prove_locking",
302 .data = &prove_locking,
303 .maxlen = sizeof(int),
304 .mode = 0644,
305 .proc_handler = &proc_dointvec,
306 },
307#endif
308#ifdef CONFIG_LOCK_STAT
309 {
310 .ctl_name = CTL_UNNUMBERED,
311 .procname = "lock_stat",
312 .data = &lock_stat,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = &proc_dointvec,
316 },
317#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200318 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 .ctl_name = KERN_PANIC,
320 .procname = "panic",
321 .data = &panic_timeout,
322 .maxlen = sizeof(int),
323 .mode = 0644,
324 .proc_handler = &proc_dointvec,
325 },
326 {
327 .ctl_name = KERN_CORE_USES_PID,
328 .procname = "core_uses_pid",
329 .data = &core_uses_pid,
330 .maxlen = sizeof(int),
331 .mode = 0644,
332 .proc_handler = &proc_dointvec,
333 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700334#ifdef CONFIG_AUDITSYSCALL
335 {
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "audit_argv_kb",
338 .data = &audit_argv_kb,
339 .maxlen = sizeof(int),
340 .mode = 0644,
341 .proc_handler = &proc_dointvec,
342 },
343#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 {
345 .ctl_name = KERN_CORE_PATTERN,
346 .procname = "core_pattern",
347 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700348 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 .mode = 0644,
350 .proc_handler = &proc_dostring,
351 .strategy = &sysctl_string,
352 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800353#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 {
355 .ctl_name = KERN_TAINTED,
356 .procname = "tainted",
357 .data = &tainted,
358 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800359 .mode = 0644,
360 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800362#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 {
364 .ctl_name = KERN_CAP_BSET,
365 .procname = "cap-bound",
366 .data = &cap_bset,
367 .maxlen = sizeof(kernel_cap_t),
368 .mode = 0600,
369 .proc_handler = &proc_dointvec_bset,
370 },
371#ifdef CONFIG_BLK_DEV_INITRD
372 {
373 .ctl_name = KERN_REALROOTDEV,
374 .procname = "real-root-dev",
375 .data = &real_root_dev,
376 .maxlen = sizeof(int),
377 .mode = 0644,
378 .proc_handler = &proc_dointvec,
379 },
380#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700381 {
382 .ctl_name = CTL_UNNUMBERED,
383 .procname = "print-fatal-signals",
384 .data = &print_fatal_signals,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = &proc_dointvec,
388 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389#ifdef __sparc__
390 {
391 .ctl_name = KERN_SPARC_REBOOT,
392 .procname = "reboot-cmd",
393 .data = reboot_command,
394 .maxlen = 256,
395 .mode = 0644,
396 .proc_handler = &proc_dostring,
397 .strategy = &sysctl_string,
398 },
399 {
400 .ctl_name = KERN_SPARC_STOP_A,
401 .procname = "stop-a",
402 .data = &stop_a_enabled,
403 .maxlen = sizeof (int),
404 .mode = 0644,
405 .proc_handler = &proc_dointvec,
406 },
407 {
408 .ctl_name = KERN_SPARC_SCONS_PWROFF,
409 .procname = "scons-poweroff",
410 .data = &scons_pwroff,
411 .maxlen = sizeof (int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
414 },
415#endif
416#ifdef __hppa__
417 {
418 .ctl_name = KERN_HPPA_PWRSW,
419 .procname = "soft-power",
420 .data = &pwrsw_enabled,
421 .maxlen = sizeof (int),
422 .mode = 0644,
423 .proc_handler = &proc_dointvec,
424 },
425 {
426 .ctl_name = KERN_HPPA_UNALIGNED,
427 .procname = "unaligned-trap",
428 .data = &unaligned_enabled,
429 .maxlen = sizeof (int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
432 },
433#endif
434 {
435 .ctl_name = KERN_CTLALTDEL,
436 .procname = "ctrl-alt-del",
437 .data = &C_A_D,
438 .maxlen = sizeof(int),
439 .mode = 0644,
440 .proc_handler = &proc_dointvec,
441 },
442 {
443 .ctl_name = KERN_PRINTK,
444 .procname = "printk",
445 .data = &console_loglevel,
446 .maxlen = 4*sizeof(int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450#ifdef CONFIG_KMOD
451 {
452 .ctl_name = KERN_MODPROBE,
453 .procname = "modprobe",
454 .data = &modprobe_path,
455 .maxlen = KMOD_PATH_LEN,
456 .mode = 0644,
457 .proc_handler = &proc_dostring,
458 .strategy = &sysctl_string,
459 },
460#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700461#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 {
463 .ctl_name = KERN_HOTPLUG,
464 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100465 .data = &uevent_helper,
466 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 .mode = 0644,
468 .proc_handler = &proc_dostring,
469 .strategy = &sysctl_string,
470 },
471#endif
472#ifdef CONFIG_CHR_DEV_SG
473 {
474 .ctl_name = KERN_SG_BIG_BUFF,
475 .procname = "sg-big-buff",
476 .data = &sg_big_buff,
477 .maxlen = sizeof (int),
478 .mode = 0444,
479 .proc_handler = &proc_dointvec,
480 },
481#endif
482#ifdef CONFIG_BSD_PROCESS_ACCT
483 {
484 .ctl_name = KERN_ACCT,
485 .procname = "acct",
486 .data = &acct_parm,
487 .maxlen = 3*sizeof(int),
488 .mode = 0644,
489 .proc_handler = &proc_dointvec,
490 },
491#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492#ifdef CONFIG_MAGIC_SYSRQ
493 {
494 .ctl_name = KERN_SYSRQ,
495 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800496 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 .maxlen = sizeof (int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
500 },
501#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700502#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 {
504 .ctl_name = KERN_CADPID,
505 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700506 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .maxlen = sizeof (int),
508 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700509 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700511#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 {
513 .ctl_name = KERN_MAX_THREADS,
514 .procname = "threads-max",
515 .data = &max_threads,
516 .maxlen = sizeof(int),
517 .mode = 0644,
518 .proc_handler = &proc_dointvec,
519 },
520 {
521 .ctl_name = KERN_RANDOM,
522 .procname = "random",
523 .mode = 0555,
524 .child = random_table,
525 },
526#ifdef CONFIG_UNIX98_PTYS
527 {
528 .ctl_name = KERN_PTY,
529 .procname = "pty",
530 .mode = 0555,
531 .child = pty_table,
532 },
533#endif
534 {
535 .ctl_name = KERN_OVERFLOWUID,
536 .procname = "overflowuid",
537 .data = &overflowuid,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec_minmax,
541 .strategy = &sysctl_intvec,
542 .extra1 = &minolduid,
543 .extra2 = &maxolduid,
544 },
545 {
546 .ctl_name = KERN_OVERFLOWGID,
547 .procname = "overflowgid",
548 .data = &overflowgid,
549 .maxlen = sizeof(int),
550 .mode = 0644,
551 .proc_handler = &proc_dointvec_minmax,
552 .strategy = &sysctl_intvec,
553 .extra1 = &minolduid,
554 .extra2 = &maxolduid,
555 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800556#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#ifdef CONFIG_MATHEMU
558 {
559 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
560 .procname = "ieee_emulation_warnings",
561 .data = &sysctl_ieee_emulation_warnings,
562 .maxlen = sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
565 },
566#endif
567#ifdef CONFIG_NO_IDLE_HZ
568 {
569 .ctl_name = KERN_HZ_TIMER,
570 .procname = "hz_timer",
571 .data = &sysctl_hz_timer,
572 .maxlen = sizeof(int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
575 },
576#endif
577 {
578 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
579 .procname = "userprocess_debug",
580 .data = &sysctl_userprocess_debug,
581 .maxlen = sizeof(int),
582 .mode = 0644,
583 .proc_handler = &proc_dointvec,
584 },
585#endif
586 {
587 .ctl_name = KERN_PIDMAX,
588 .procname = "pid_max",
589 .data = &pid_max,
590 .maxlen = sizeof (int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec_minmax,
593 .strategy = sysctl_intvec,
594 .extra1 = &pid_max_min,
595 .extra2 = &pid_max_max,
596 },
597 {
598 .ctl_name = KERN_PANIC_ON_OOPS,
599 .procname = "panic_on_oops",
600 .data = &panic_on_oops,
601 .maxlen = sizeof(int),
602 .mode = 0644,
603 .proc_handler = &proc_dointvec,
604 },
605 {
606 .ctl_name = KERN_PRINTK_RATELIMIT,
607 .procname = "printk_ratelimit",
608 .data = &printk_ratelimit_jiffies,
609 .maxlen = sizeof(int),
610 .mode = 0644,
611 .proc_handler = &proc_dointvec_jiffies,
612 .strategy = &sysctl_jiffies,
613 },
614 {
615 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
616 .procname = "printk_ratelimit_burst",
617 .data = &printk_ratelimit_burst,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec,
621 },
622 {
623 .ctl_name = KERN_NGROUPS_MAX,
624 .procname = "ngroups_max",
625 .data = &ngroups_max,
626 .maxlen = sizeof (int),
627 .mode = 0444,
628 .proc_handler = &proc_dointvec,
629 },
630#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
631 {
632 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
633 .procname = "unknown_nmi_panic",
634 .data = &unknown_nmi_panic,
635 .maxlen = sizeof (int),
636 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200637 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 },
Don Zickus407984f2006-09-26 10:52:27 +0200639 {
640 .ctl_name = KERN_NMI_WATCHDOG,
641 .procname = "nmi_watchdog",
642 .data = &nmi_watchdog_enabled,
643 .maxlen = sizeof (int),
644 .mode = 0644,
645 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 },
647#endif
648#if defined(CONFIG_X86)
649 {
Don Zickus8da5add2006-09-26 10:52:27 +0200650 .ctl_name = KERN_PANIC_ON_NMI,
651 .procname = "panic_on_unrecovered_nmi",
652 .data = &panic_on_unrecovered_nmi,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec,
656 },
657 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .ctl_name = KERN_BOOTLOADER_TYPE,
659 .procname = "bootloader_type",
660 .data = &bootloader_type,
661 .maxlen = sizeof (int),
662 .mode = 0444,
663 .proc_handler = &proc_dointvec,
664 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100665 {
666 .ctl_name = CTL_UNNUMBERED,
667 .procname = "kstack_depth_to_print",
668 .data = &kstack_depth_to_print,
669 .maxlen = sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800674#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 {
676 .ctl_name = KERN_RANDOMIZE,
677 .procname = "randomize_va_space",
678 .data = &randomize_va_space,
679 .maxlen = sizeof(int),
680 .mode = 0644,
681 .proc_handler = &proc_dointvec,
682 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800683#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800684#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700685 {
686 .ctl_name = KERN_SPIN_RETRY,
687 .procname = "spin_retry",
688 .data = &spin_retry,
689 .maxlen = sizeof (int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec,
692 },
693#endif
Len Brown673d5b42007-07-28 03:33:16 -0400694#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800695 {
696 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
697 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700698 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800699 .maxlen = sizeof (unsigned long),
700 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800701 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800702 },
703#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800704#ifdef CONFIG_IA64
705 {
706 .ctl_name = KERN_IA64_UNALIGNED,
707 .procname = "ignore-unaligned-usertrap",
708 .data = &no_unaligned_warning,
709 .maxlen = sizeof (int),
710 .mode = 0644,
711 .proc_handler = &proc_dointvec,
712 },
713#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200714#ifdef CONFIG_COMPAT
715 {
716 .ctl_name = KERN_COMPAT_LOG,
717 .procname = "compat-log",
718 .data = &compat_log,
719 .maxlen = sizeof (int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
722 },
723#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700724#ifdef CONFIG_RT_MUTEXES
725 {
726 .ctl_name = KERN_MAX_LOCK_DEPTH,
727 .procname = "max_lock_depth",
728 .data = &max_lock_depth,
729 .maxlen = sizeof(int),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
732 },
733#endif
Kees Cook5096add2007-05-08 00:26:04 -0700734#ifdef CONFIG_PROC_FS
735 {
736 .ctl_name = CTL_UNNUMBERED,
737 .procname = "maps_protect",
738 .data = &maps_protect,
739 .maxlen = sizeof(int),
740 .mode = 0644,
741 .proc_handler = &proc_dointvec,
742 },
743#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700744 {
745 .ctl_name = CTL_UNNUMBERED,
746 .procname = "poweroff_cmd",
747 .data = &poweroff_cmd,
748 .maxlen = POWEROFF_CMD_PATH_LEN,
749 .mode = 0644,
750 .proc_handler = &proc_dostring,
751 .strategy = &sysctl_string,
752 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700753/*
754 * NOTE: do not add new entries to this table unless you have read
755 * Documentation/sysctl/ctl_unnumbered.txt
756 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 { .ctl_name = 0 }
758};
759
760/* Constants for minimum and maximum testing in vm_table.
761 We use these as one-element integer vectors. */
762static int zero;
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -0700763static int two = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764static int one_hundred = 100;
765
766
767static ctl_table vm_table[] = {
768 {
769 .ctl_name = VM_OVERCOMMIT_MEMORY,
770 .procname = "overcommit_memory",
771 .data = &sysctl_overcommit_memory,
772 .maxlen = sizeof(sysctl_overcommit_memory),
773 .mode = 0644,
774 .proc_handler = &proc_dointvec,
775 },
776 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700777 .ctl_name = VM_PANIC_ON_OOM,
778 .procname = "panic_on_oom",
779 .data = &sysctl_panic_on_oom,
780 .maxlen = sizeof(sysctl_panic_on_oom),
781 .mode = 0644,
782 .proc_handler = &proc_dointvec,
783 },
784 {
David Rientjesfe071d72007-10-16 23:25:56 -0700785 .ctl_name = CTL_UNNUMBERED,
786 .procname = "oom_kill_allocating_task",
787 .data = &sysctl_oom_kill_allocating_task,
788 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
789 .mode = 0644,
790 .proc_handler = &proc_dointvec,
791 },
792 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 .ctl_name = VM_OVERCOMMIT_RATIO,
794 .procname = "overcommit_ratio",
795 .data = &sysctl_overcommit_ratio,
796 .maxlen = sizeof(sysctl_overcommit_ratio),
797 .mode = 0644,
798 .proc_handler = &proc_dointvec,
799 },
800 {
801 .ctl_name = VM_PAGE_CLUSTER,
802 .procname = "page-cluster",
803 .data = &page_cluster,
804 .maxlen = sizeof(int),
805 .mode = 0644,
806 .proc_handler = &proc_dointvec,
807 },
808 {
809 .ctl_name = VM_DIRTY_BACKGROUND,
810 .procname = "dirty_background_ratio",
811 .data = &dirty_background_ratio,
812 .maxlen = sizeof(dirty_background_ratio),
813 .mode = 0644,
814 .proc_handler = &proc_dointvec_minmax,
815 .strategy = &sysctl_intvec,
816 .extra1 = &zero,
817 .extra2 = &one_hundred,
818 },
819 {
820 .ctl_name = VM_DIRTY_RATIO,
821 .procname = "dirty_ratio",
822 .data = &vm_dirty_ratio,
823 .maxlen = sizeof(vm_dirty_ratio),
824 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700825 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 .strategy = &sysctl_intvec,
827 .extra1 = &zero,
828 .extra2 = &one_hundred,
829 },
830 {
831 .ctl_name = VM_DIRTY_WB_CS,
832 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800833 .data = &dirty_writeback_interval,
834 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 .mode = 0644,
836 .proc_handler = &dirty_writeback_centisecs_handler,
837 },
838 {
839 .ctl_name = VM_DIRTY_EXPIRE_CS,
840 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800841 .data = &dirty_expire_interval,
842 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800844 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 },
846 {
847 .ctl_name = VM_NR_PDFLUSH_THREADS,
848 .procname = "nr_pdflush_threads",
849 .data = &nr_pdflush_threads,
850 .maxlen = sizeof nr_pdflush_threads,
851 .mode = 0444 /* read-only*/,
852 .proc_handler = &proc_dointvec,
853 },
854 {
855 .ctl_name = VM_SWAPPINESS,
856 .procname = "swappiness",
857 .data = &vm_swappiness,
858 .maxlen = sizeof(vm_swappiness),
859 .mode = 0644,
860 .proc_handler = &proc_dointvec_minmax,
861 .strategy = &sysctl_intvec,
862 .extra1 = &zero,
863 .extra2 = &one_hundred,
864 },
865#ifdef CONFIG_HUGETLB_PAGE
866 {
867 .ctl_name = VM_HUGETLB_PAGES,
868 .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)
1077static ctl_table binfmt_misc_table[] = {
1078 { .ctl_name = 0 }
1079};
1080#endif
1081
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082static ctl_table fs_table[] = {
1083 {
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 {
1100 .ctl_name = FS_NRFILE,
1101 .procname = "file-nr",
1102 .data = &files_stat,
1103 .maxlen = 3*sizeof(int),
1104 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001105 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 },
1107 {
1108 .ctl_name = FS_MAXFILE,
1109 .procname = "file-max",
1110 .data = &files_stat.max_files,
1111 .maxlen = sizeof(int),
1112 .mode = 0644,
1113 .proc_handler = &proc_dointvec,
1114 },
1115 {
1116 .ctl_name = FS_DENTRY,
1117 .procname = "dentry-state",
1118 .data = &dentry_stat,
1119 .maxlen = 6*sizeof(int),
1120 .mode = 0444,
1121 .proc_handler = &proc_dointvec,
1122 },
1123 {
1124 .ctl_name = FS_OVERFLOWUID,
1125 .procname = "overflowuid",
1126 .data = &fs_overflowuid,
1127 .maxlen = sizeof(int),
1128 .mode = 0644,
1129 .proc_handler = &proc_dointvec_minmax,
1130 .strategy = &sysctl_intvec,
1131 .extra1 = &minolduid,
1132 .extra2 = &maxolduid,
1133 },
1134 {
1135 .ctl_name = FS_OVERFLOWGID,
1136 .procname = "overflowgid",
1137 .data = &fs_overflowgid,
1138 .maxlen = sizeof(int),
1139 .mode = 0644,
1140 .proc_handler = &proc_dointvec_minmax,
1141 .strategy = &sysctl_intvec,
1142 .extra1 = &minolduid,
1143 .extra2 = &maxolduid,
1144 },
1145 {
1146 .ctl_name = FS_LEASES,
1147 .procname = "leases-enable",
1148 .data = &leases_enable,
1149 .maxlen = sizeof(int),
1150 .mode = 0644,
1151 .proc_handler = &proc_dointvec,
1152 },
1153#ifdef CONFIG_DNOTIFY
1154 {
1155 .ctl_name = FS_DIR_NOTIFY,
1156 .procname = "dir-notify-enable",
1157 .data = &dir_notify_enable,
1158 .maxlen = sizeof(int),
1159 .mode = 0644,
1160 .proc_handler = &proc_dointvec,
1161 },
1162#endif
1163#ifdef CONFIG_MMU
1164 {
1165 .ctl_name = FS_LEASE_TIME,
1166 .procname = "lease-break-time",
1167 .data = &lease_break_time,
1168 .maxlen = sizeof(int),
1169 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001170 .proc_handler = &proc_dointvec_minmax,
1171 .strategy = &sysctl_intvec,
1172 .extra1 = &zero,
1173 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 },
1175 {
1176 .ctl_name = FS_AIO_NR,
1177 .procname = "aio-nr",
1178 .data = &aio_nr,
1179 .maxlen = sizeof(aio_nr),
1180 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001181 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 },
1183 {
1184 .ctl_name = FS_AIO_MAX_NR,
1185 .procname = "aio-max-nr",
1186 .data = &aio_max_nr,
1187 .maxlen = sizeof(aio_max_nr),
1188 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001189 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001191#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001192 {
1193 .ctl_name = FS_INOTIFY,
1194 .procname = "inotify",
1195 .mode = 0555,
1196 .child = inotify_table,
1197 },
1198#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001200 {
1201 .ctl_name = KERN_SETUID_DUMPABLE,
1202 .procname = "suid_dumpable",
1203 .data = &suid_dumpable,
1204 .maxlen = sizeof(int),
1205 .mode = 0644,
1206 .proc_handler = &proc_dointvec,
1207 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001208#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1209 {
1210 .ctl_name = CTL_UNNUMBERED,
1211 .procname = "binfmt_misc",
1212 .mode = 0555,
1213 .child = binfmt_misc_table,
1214 },
1215#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001216/*
1217 * NOTE: do not add new entries to this table unless you have read
1218 * Documentation/sysctl/ctl_unnumbered.txt
1219 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 { .ctl_name = 0 }
1221};
1222
1223static ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001224#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001225 {
1226 .ctl_name = CTL_UNNUMBERED,
1227 .procname = "exception-trace",
1228 .data = &show_unhandled_signals,
1229 .maxlen = sizeof(int),
1230 .mode = 0644,
1231 .proc_handler = proc_dointvec
1232 },
1233#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 { .ctl_name = 0 }
1235};
1236
1237static ctl_table dev_table[] = {
1238 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001239};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Al Viro330d57f2005-11-04 10:18:40 +00001241static DEFINE_SPINLOCK(sysctl_lock);
1242
1243/* called under sysctl_lock */
1244static int use_table(struct ctl_table_header *p)
1245{
1246 if (unlikely(p->unregistering))
1247 return 0;
1248 p->used++;
1249 return 1;
1250}
1251
1252/* called under sysctl_lock */
1253static void unuse_table(struct ctl_table_header *p)
1254{
1255 if (!--p->used)
1256 if (unlikely(p->unregistering))
1257 complete(p->unregistering);
1258}
1259
1260/* called under sysctl_lock, will reacquire if has to wait */
1261static void start_unregistering(struct ctl_table_header *p)
1262{
1263 /*
1264 * if p->used is 0, nobody will ever touch that entry again;
1265 * we'll eliminate all paths to it before dropping sysctl_lock
1266 */
1267 if (unlikely(p->used)) {
1268 struct completion wait;
1269 init_completion(&wait);
1270 p->unregistering = &wait;
1271 spin_unlock(&sysctl_lock);
1272 wait_for_completion(&wait);
1273 spin_lock(&sysctl_lock);
1274 }
1275 /*
1276 * do not remove from the list until nobody holds it; walking the
1277 * list in do_sysctl() relies on that.
1278 */
1279 list_del_init(&p->ctl_entry);
1280}
1281
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001282void sysctl_head_finish(struct ctl_table_header *head)
1283{
1284 if (!head)
1285 return;
1286 spin_lock(&sysctl_lock);
1287 unuse_table(head);
1288 spin_unlock(&sysctl_lock);
1289}
1290
1291struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1292{
1293 struct ctl_table_header *head;
1294 struct list_head *tmp;
1295 spin_lock(&sysctl_lock);
1296 if (prev) {
1297 tmp = &prev->ctl_entry;
1298 unuse_table(prev);
1299 goto next;
1300 }
1301 tmp = &root_table_header.ctl_entry;
1302 for (;;) {
1303 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1304
1305 if (!use_table(head))
1306 goto next;
1307 spin_unlock(&sysctl_lock);
1308 return head;
1309 next:
1310 tmp = tmp->next;
1311 if (tmp == &root_table_header.ctl_entry)
1312 break;
1313 }
1314 spin_unlock(&sysctl_lock);
1315 return NULL;
1316}
1317
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001318#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1320 void __user *newval, size_t newlen)
1321{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001322 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001323 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1326 return -ENOTDIR;
1327 if (oldval) {
1328 int old_len;
1329 if (!oldlenp || get_user(old_len, oldlenp))
1330 return -EFAULT;
1331 }
Al Viro330d57f2005-11-04 10:18:40 +00001332
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001333 for (head = sysctl_head_next(NULL); head;
1334 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001335 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001336 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001337 if (error != -ENOTDIR) {
1338 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001339 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001340 }
1341 }
Al Viro330d57f2005-11-04 10:18:40 +00001342 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343}
1344
1345asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1346{
1347 struct __sysctl_args tmp;
1348 int error;
1349
1350 if (copy_from_user(&tmp, args, sizeof(tmp)))
1351 return -EFAULT;
1352
1353 lock_kernel();
1354 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1355 tmp.newval, tmp.newlen);
1356 unlock_kernel();
1357 return error;
1358}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001359#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001362 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 * some sysctl variables are readonly even to root.
1364 */
1365
1366static int test_perm(int mode, int op)
1367{
1368 if (!current->euid)
1369 mode >>= 6;
1370 else if (in_egroup_p(0))
1371 mode >>= 3;
1372 if ((mode & op & 0007) == op)
1373 return 0;
1374 return -EACCES;
1375}
1376
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001377int sysctl_perm(ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
1379 int error;
1380 error = security_sysctl(table, op);
1381 if (error)
1382 return error;
1383 return test_perm(table->mode, op);
1384}
1385
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001386#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387static int parse_table(int __user *name, int nlen,
1388 void __user *oldval, size_t __user *oldlenp,
1389 void __user *newval, size_t newlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001390 ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
1392 int n;
1393repeat:
1394 if (!nlen)
1395 return -ENOTDIR;
1396 if (get_user(n, name))
1397 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001398 for ( ; table->ctl_name || table->procname; table++) {
1399 if (!table->ctl_name)
1400 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001401 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 int error;
1403 if (table->child) {
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001404 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 name++;
1407 nlen--;
1408 table = table->child;
1409 goto repeat;
1410 }
1411 error = do_sysctl_strategy(table, name, nlen,
1412 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001413 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 return error;
1415 }
1416 }
1417 return -ENOTDIR;
1418}
1419
1420/* Perform the actual read/write of a sysctl table entry. */
1421int do_sysctl_strategy (ctl_table *table,
1422 int __user *name, int nlen,
1423 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001424 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
1426 int op = 0, rc;
1427 size_t len;
1428
1429 if (oldval)
1430 op |= 004;
1431 if (newval)
1432 op |= 002;
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001433 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 return -EPERM;
1435
1436 if (table->strategy) {
1437 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001438 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 if (rc < 0)
1440 return rc;
1441 if (rc > 0)
1442 return 0;
1443 }
1444
1445 /* If there is no strategy routine, or if the strategy returns
1446 * zero, proceed with automatic r/w */
1447 if (table->data && table->maxlen) {
1448 if (oldval && oldlenp) {
1449 if (get_user(len, oldlenp))
1450 return -EFAULT;
1451 if (len) {
1452 if (len > table->maxlen)
1453 len = table->maxlen;
1454 if(copy_to_user(oldval, table->data, len))
1455 return -EFAULT;
1456 if(put_user(len, oldlenp))
1457 return -EFAULT;
1458 }
1459 }
1460 if (newval && newlen) {
1461 len = newlen;
1462 if (len > table->maxlen)
1463 len = table->maxlen;
1464 if(copy_from_user(table->data, newval, len))
1465 return -EFAULT;
1466 }
1467 }
1468 return 0;
1469}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001470#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001472static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1473{
1474 for (; table->ctl_name || table->procname; table++) {
1475 table->parent = parent;
1476 if (table->child)
1477 sysctl_set_parent(table, table->child);
1478 }
1479}
1480
1481static __init int sysctl_init(void)
1482{
1483 sysctl_set_parent(NULL, root_table);
1484 return 0;
1485}
1486
1487core_initcall(sysctl_init);
1488
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489/**
1490 * register_sysctl_table - register a sysctl hierarchy
1491 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 *
1493 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1494 * array. An entry with a ctl_name of 0 terminates the table.
1495 *
1496 * The members of the &ctl_table structure are used as follows:
1497 *
1498 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1499 * must be unique within that level of sysctl
1500 *
1501 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1502 * enter a sysctl file
1503 *
1504 * data - a pointer to data for use by proc_handler
1505 *
1506 * maxlen - the maximum size in bytes of the data
1507 *
1508 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1509 *
1510 * child - a pointer to the child sysctl table if this entry is a directory, or
1511 * %NULL.
1512 *
1513 * proc_handler - the text handler routine (described below)
1514 *
1515 * strategy - the strategy routine (described below)
1516 *
1517 * de - for internal use by the sysctl routines
1518 *
1519 * extra1, extra2 - extra pointers usable by the proc handler routines
1520 *
1521 * Leaf nodes in the sysctl tree will be represented by a single file
1522 * under /proc; non-leaf nodes will be represented by directories.
1523 *
1524 * sysctl(2) can automatically manage read and write requests through
1525 * the sysctl table. The data and maxlen fields of the ctl_table
1526 * struct enable minimal validation of the values being written to be
1527 * performed, and the mode field allows minimal authentication.
1528 *
1529 * More sophisticated management can be enabled by the provision of a
1530 * strategy routine with the table entry. This will be called before
1531 * any automatic read or write of the data is performed.
1532 *
1533 * The strategy routine may return
1534 *
1535 * < 0 - Error occurred (error is passed to user process)
1536 *
1537 * 0 - OK - proceed with automatic read or write.
1538 *
1539 * > 0 - OK - read or write has been done by the strategy routine, so
1540 * return immediately.
1541 *
1542 * There must be a proc_handler routine for any terminal nodes
1543 * mirrored under /proc/sys (non-terminals are handled by a built-in
1544 * directory handler). Several default handlers are available to
1545 * cover common cases -
1546 *
1547 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1548 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1549 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1550 *
1551 * It is the handler's job to read the input buffer from user memory
1552 * and process it. The handler should return 0 on success.
1553 *
1554 * This routine returns %NULL on a failure to register, and a pointer
1555 * to the table header on success.
1556 */
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001557struct ctl_table_header *register_sysctl_table(ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
1559 struct ctl_table_header *tmp;
1560 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1561 if (!tmp)
1562 return NULL;
1563 tmp->ctl_table = table;
1564 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001565 tmp->used = 0;
1566 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001567 sysctl_set_parent(NULL, table);
Al Viro330d57f2005-11-04 10:18:40 +00001568 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001569 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001570 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 return tmp;
1572}
1573
1574/**
1575 * unregister_sysctl_table - unregister a sysctl table hierarchy
1576 * @header: the header returned from register_sysctl_table
1577 *
1578 * Unregisters the sysctl table and all children. proc entries may not
1579 * actually be removed until they are no longer used by anyone.
1580 */
1581void unregister_sysctl_table(struct ctl_table_header * header)
1582{
Al Viro330d57f2005-11-04 10:18:40 +00001583 might_sleep();
1584 spin_lock(&sysctl_lock);
1585 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001586 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 kfree(header);
1588}
1589
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001590#else /* !CONFIG_SYSCTL */
Adrian Bunk93a6fef2007-02-28 20:12:23 -08001591struct ctl_table_header *register_sysctl_table(ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001592{
1593 return NULL;
1594}
1595
1596void unregister_sysctl_table(struct ctl_table_header * table)
1597{
1598}
1599
1600#endif /* CONFIG_SYSCTL */
1601
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602/*
1603 * /proc/sys support
1604 */
1605
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001606#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001608static int _proc_do_string(void* data, int maxlen, int write,
1609 struct file *filp, void __user *buffer,
1610 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001611{
1612 size_t len;
1613 char __user *p;
1614 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001615
1616 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001617 *lenp = 0;
1618 return 0;
1619 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001620
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001621 if (write) {
1622 len = 0;
1623 p = buffer;
1624 while (len < *lenp) {
1625 if (get_user(c, p++))
1626 return -EFAULT;
1627 if (c == 0 || c == '\n')
1628 break;
1629 len++;
1630 }
1631 if (len >= maxlen)
1632 len = maxlen-1;
1633 if(copy_from_user(data, buffer, len))
1634 return -EFAULT;
1635 ((char *) data)[len] = 0;
1636 *ppos += *lenp;
1637 } else {
1638 len = strlen(data);
1639 if (len > maxlen)
1640 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001641
1642 if (*ppos > len) {
1643 *lenp = 0;
1644 return 0;
1645 }
1646
1647 data += *ppos;
1648 len -= *ppos;
1649
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001650 if (len > *lenp)
1651 len = *lenp;
1652 if (len)
1653 if(copy_to_user(buffer, data, len))
1654 return -EFAULT;
1655 if (len < *lenp) {
1656 if(put_user('\n', ((char __user *) buffer) + len))
1657 return -EFAULT;
1658 len++;
1659 }
1660 *lenp = len;
1661 *ppos += len;
1662 }
1663 return 0;
1664}
1665
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666/**
1667 * proc_dostring - read a string sysctl
1668 * @table: the sysctl table
1669 * @write: %TRUE if this is a write to the sysctl file
1670 * @filp: the file structure
1671 * @buffer: the user buffer
1672 * @lenp: the size of the user buffer
1673 * @ppos: file position
1674 *
1675 * Reads/writes a string from/to the user buffer. If the kernel
1676 * buffer provided is not large enough to hold the string, the
1677 * string is truncated. The copied string is %NULL-terminated.
1678 * If the string is being read by the user process, it is copied
1679 * and a newline '\n' is added. It is truncated if the buffer is
1680 * not large enough.
1681 *
1682 * Returns 0 on success.
1683 */
1684int proc_dostring(ctl_table *table, int write, struct file *filp,
1685 void __user *buffer, size_t *lenp, loff_t *ppos)
1686{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001687 return _proc_do_string(table->data, table->maxlen, write, filp,
1688 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689}
1690
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
1692static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1693 int *valp,
1694 int write, void *data)
1695{
1696 if (write) {
1697 *valp = *negp ? -*lvalp : *lvalp;
1698 } else {
1699 int val = *valp;
1700 if (val < 0) {
1701 *negp = -1;
1702 *lvalp = (unsigned long)-val;
1703 } else {
1704 *negp = 0;
1705 *lvalp = (unsigned long)val;
1706 }
1707 }
1708 return 0;
1709}
1710
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001711static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1712 int write, struct file *filp, void __user *buffer,
1713 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1715 int write, void *data),
1716 void *data)
1717{
1718#define TMPBUFLEN 21
1719 int *i, vleft, first=1, neg, val;
1720 unsigned long lval;
1721 size_t left, len;
1722
1723 char buf[TMPBUFLEN], *p;
1724 char __user *s = buffer;
1725
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001726 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 (*ppos && !write)) {
1728 *lenp = 0;
1729 return 0;
1730 }
1731
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001732 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 vleft = table->maxlen / sizeof(*i);
1734 left = *lenp;
1735
1736 if (!conv)
1737 conv = do_proc_dointvec_conv;
1738
1739 for (; left && vleft--; i++, first=0) {
1740 if (write) {
1741 while (left) {
1742 char c;
1743 if (get_user(c, s))
1744 return -EFAULT;
1745 if (!isspace(c))
1746 break;
1747 left--;
1748 s++;
1749 }
1750 if (!left)
1751 break;
1752 neg = 0;
1753 len = left;
1754 if (len > sizeof(buf) - 1)
1755 len = sizeof(buf) - 1;
1756 if (copy_from_user(buf, s, len))
1757 return -EFAULT;
1758 buf[len] = 0;
1759 p = buf;
1760 if (*p == '-' && left > 1) {
1761 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001762 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 }
1764 if (*p < '0' || *p > '9')
1765 break;
1766
1767 lval = simple_strtoul(p, &p, 0);
1768
1769 len = p-buf;
1770 if ((len < left) && *p && !isspace(*p))
1771 break;
1772 if (neg)
1773 val = -val;
1774 s += len;
1775 left -= len;
1776
1777 if (conv(&neg, &lval, i, 1, data))
1778 break;
1779 } else {
1780 p = buf;
1781 if (!first)
1782 *p++ = '\t';
1783
1784 if (conv(&neg, &lval, i, 0, data))
1785 break;
1786
1787 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1788 len = strlen(buf);
1789 if (len > left)
1790 len = left;
1791 if(copy_to_user(s, buf, len))
1792 return -EFAULT;
1793 left -= len;
1794 s += len;
1795 }
1796 }
1797
1798 if (!write && !first && left) {
1799 if(put_user('\n', s))
1800 return -EFAULT;
1801 left--, s++;
1802 }
1803 if (write) {
1804 while (left) {
1805 char c;
1806 if (get_user(c, s++))
1807 return -EFAULT;
1808 if (!isspace(c))
1809 break;
1810 left--;
1811 }
1812 }
1813 if (write && first)
1814 return -EINVAL;
1815 *lenp -= left;
1816 *ppos += *lenp;
1817 return 0;
1818#undef TMPBUFLEN
1819}
1820
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001821static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1822 void __user *buffer, size_t *lenp, loff_t *ppos,
1823 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1824 int write, void *data),
1825 void *data)
1826{
1827 return __do_proc_dointvec(table->data, table, write, filp,
1828 buffer, lenp, ppos, conv, data);
1829}
1830
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831/**
1832 * proc_dointvec - read a vector of integers
1833 * @table: the sysctl table
1834 * @write: %TRUE if this is a write to the sysctl file
1835 * @filp: the file structure
1836 * @buffer: the user buffer
1837 * @lenp: the size of the user buffer
1838 * @ppos: file position
1839 *
1840 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1841 * values from/to the user buffer, treated as an ASCII string.
1842 *
1843 * Returns 0 on success.
1844 */
1845int proc_dointvec(ctl_table *table, int write, struct file *filp,
1846 void __user *buffer, size_t *lenp, loff_t *ppos)
1847{
1848 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1849 NULL,NULL);
1850}
1851
1852#define OP_SET 0
1853#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001854#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
1856static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1857 int *valp,
1858 int write, void *data)
1859{
1860 int op = *(int *)data;
1861 if (write) {
1862 int val = *negp ? -*lvalp : *lvalp;
1863 switch(op) {
1864 case OP_SET: *valp = val; break;
1865 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001866 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 }
1868 } else {
1869 int val = *valp;
1870 if (val < 0) {
1871 *negp = -1;
1872 *lvalp = (unsigned long)-val;
1873 } else {
1874 *negp = 0;
1875 *lvalp = (unsigned long)val;
1876 }
1877 }
1878 return 0;
1879}
1880
1881/*
1882 * init may raise the set.
1883 */
1884
1885int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1886 void __user *buffer, size_t *lenp, loff_t *ppos)
1887{
1888 int op;
1889
Eric Paris6ff1b442007-02-10 01:43:19 -08001890 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 return -EPERM;
1892 }
1893
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001894 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1896 do_proc_dointvec_bset_conv,&op);
1897}
1898
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001899/*
1900 * Taint values can only be increased
1901 */
1902static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1903 void __user *buffer, size_t *lenp, loff_t *ppos)
1904{
1905 int op;
1906
Bastian Blank91fcd412007-04-23 14:41:14 -07001907 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001908 return -EPERM;
1909
1910 op = OP_OR;
1911 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1912 do_proc_dointvec_bset_conv,&op);
1913}
1914
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915struct do_proc_dointvec_minmax_conv_param {
1916 int *min;
1917 int *max;
1918};
1919
1920static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1921 int *valp,
1922 int write, void *data)
1923{
1924 struct do_proc_dointvec_minmax_conv_param *param = data;
1925 if (write) {
1926 int val = *negp ? -*lvalp : *lvalp;
1927 if ((param->min && *param->min > val) ||
1928 (param->max && *param->max < val))
1929 return -EINVAL;
1930 *valp = val;
1931 } else {
1932 int val = *valp;
1933 if (val < 0) {
1934 *negp = -1;
1935 *lvalp = (unsigned long)-val;
1936 } else {
1937 *negp = 0;
1938 *lvalp = (unsigned long)val;
1939 }
1940 }
1941 return 0;
1942}
1943
1944/**
1945 * proc_dointvec_minmax - read a vector of integers with min/max values
1946 * @table: the sysctl table
1947 * @write: %TRUE if this is a write to the sysctl file
1948 * @filp: the file structure
1949 * @buffer: the user buffer
1950 * @lenp: the size of the user buffer
1951 * @ppos: file position
1952 *
1953 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1954 * values from/to the user buffer, treated as an ASCII string.
1955 *
1956 * This routine will ensure the values are within the range specified by
1957 * table->extra1 (min) and table->extra2 (max).
1958 *
1959 * Returns 0 on success.
1960 */
1961int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1962 void __user *buffer, size_t *lenp, loff_t *ppos)
1963{
1964 struct do_proc_dointvec_minmax_conv_param param = {
1965 .min = (int *) table->extra1,
1966 .max = (int *) table->extra2,
1967 };
1968 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1969 do_proc_dointvec_minmax_conv, &param);
1970}
1971
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001972static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 struct file *filp,
1974 void __user *buffer,
1975 size_t *lenp, loff_t *ppos,
1976 unsigned long convmul,
1977 unsigned long convdiv)
1978{
1979#define TMPBUFLEN 21
1980 unsigned long *i, *min, *max, val;
1981 int vleft, first=1, neg;
1982 size_t len, left;
1983 char buf[TMPBUFLEN], *p;
1984 char __user *s = buffer;
1985
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001986 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 (*ppos && !write)) {
1988 *lenp = 0;
1989 return 0;
1990 }
1991
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001992 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 min = (unsigned long *) table->extra1;
1994 max = (unsigned long *) table->extra2;
1995 vleft = table->maxlen / sizeof(unsigned long);
1996 left = *lenp;
1997
1998 for (; left && vleft--; i++, min++, max++, first=0) {
1999 if (write) {
2000 while (left) {
2001 char c;
2002 if (get_user(c, s))
2003 return -EFAULT;
2004 if (!isspace(c))
2005 break;
2006 left--;
2007 s++;
2008 }
2009 if (!left)
2010 break;
2011 neg = 0;
2012 len = left;
2013 if (len > TMPBUFLEN-1)
2014 len = TMPBUFLEN-1;
2015 if (copy_from_user(buf, s, len))
2016 return -EFAULT;
2017 buf[len] = 0;
2018 p = buf;
2019 if (*p == '-' && left > 1) {
2020 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002021 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 }
2023 if (*p < '0' || *p > '9')
2024 break;
2025 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2026 len = p-buf;
2027 if ((len < left) && *p && !isspace(*p))
2028 break;
2029 if (neg)
2030 val = -val;
2031 s += len;
2032 left -= len;
2033
2034 if(neg)
2035 continue;
2036 if ((min && val < *min) || (max && val > *max))
2037 continue;
2038 *i = val;
2039 } else {
2040 p = buf;
2041 if (!first)
2042 *p++ = '\t';
2043 sprintf(p, "%lu", convdiv * (*i) / convmul);
2044 len = strlen(buf);
2045 if (len > left)
2046 len = left;
2047 if(copy_to_user(s, buf, len))
2048 return -EFAULT;
2049 left -= len;
2050 s += len;
2051 }
2052 }
2053
2054 if (!write && !first && left) {
2055 if(put_user('\n', s))
2056 return -EFAULT;
2057 left--, s++;
2058 }
2059 if (write) {
2060 while (left) {
2061 char c;
2062 if (get_user(c, s++))
2063 return -EFAULT;
2064 if (!isspace(c))
2065 break;
2066 left--;
2067 }
2068 }
2069 if (write && first)
2070 return -EINVAL;
2071 *lenp -= left;
2072 *ppos += *lenp;
2073 return 0;
2074#undef TMPBUFLEN
2075}
2076
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002077static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2078 struct file *filp,
2079 void __user *buffer,
2080 size_t *lenp, loff_t *ppos,
2081 unsigned long convmul,
2082 unsigned long convdiv)
2083{
2084 return __do_proc_doulongvec_minmax(table->data, table, write,
2085 filp, buffer, lenp, ppos, convmul, convdiv);
2086}
2087
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088/**
2089 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2090 * @table: the sysctl table
2091 * @write: %TRUE if this is a write to the sysctl file
2092 * @filp: the file structure
2093 * @buffer: the user buffer
2094 * @lenp: the size of the user buffer
2095 * @ppos: file position
2096 *
2097 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2098 * values from/to the user buffer, treated as an ASCII string.
2099 *
2100 * This routine will ensure the values are within the range specified by
2101 * table->extra1 (min) and table->extra2 (max).
2102 *
2103 * Returns 0 on success.
2104 */
2105int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2106 void __user *buffer, size_t *lenp, loff_t *ppos)
2107{
2108 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2109}
2110
2111/**
2112 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2113 * @table: the sysctl table
2114 * @write: %TRUE if this is a write to the sysctl file
2115 * @filp: the file structure
2116 * @buffer: the user buffer
2117 * @lenp: the size of the user buffer
2118 * @ppos: file position
2119 *
2120 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2121 * values from/to the user buffer, treated as an ASCII string. The values
2122 * are treated as milliseconds, and converted to jiffies when they are stored.
2123 *
2124 * This routine will ensure the values are within the range specified by
2125 * table->extra1 (min) and table->extra2 (max).
2126 *
2127 * Returns 0 on success.
2128 */
2129int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2130 struct file *filp,
2131 void __user *buffer,
2132 size_t *lenp, loff_t *ppos)
2133{
2134 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2135 lenp, ppos, HZ, 1000l);
2136}
2137
2138
2139static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2140 int *valp,
2141 int write, void *data)
2142{
2143 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002144 if (*lvalp > LONG_MAX / HZ)
2145 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2147 } else {
2148 int val = *valp;
2149 unsigned long lval;
2150 if (val < 0) {
2151 *negp = -1;
2152 lval = (unsigned long)-val;
2153 } else {
2154 *negp = 0;
2155 lval = (unsigned long)val;
2156 }
2157 *lvalp = lval / HZ;
2158 }
2159 return 0;
2160}
2161
2162static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2163 int *valp,
2164 int write, void *data)
2165{
2166 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002167 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2168 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2170 } else {
2171 int val = *valp;
2172 unsigned long lval;
2173 if (val < 0) {
2174 *negp = -1;
2175 lval = (unsigned long)-val;
2176 } else {
2177 *negp = 0;
2178 lval = (unsigned long)val;
2179 }
2180 *lvalp = jiffies_to_clock_t(lval);
2181 }
2182 return 0;
2183}
2184
2185static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2186 int *valp,
2187 int write, void *data)
2188{
2189 if (write) {
2190 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2191 } else {
2192 int val = *valp;
2193 unsigned long lval;
2194 if (val < 0) {
2195 *negp = -1;
2196 lval = (unsigned long)-val;
2197 } else {
2198 *negp = 0;
2199 lval = (unsigned long)val;
2200 }
2201 *lvalp = jiffies_to_msecs(lval);
2202 }
2203 return 0;
2204}
2205
2206/**
2207 * proc_dointvec_jiffies - read a vector of integers as seconds
2208 * @table: the sysctl table
2209 * @write: %TRUE if this is a write to the sysctl file
2210 * @filp: the file structure
2211 * @buffer: the user buffer
2212 * @lenp: the size of the user buffer
2213 * @ppos: file position
2214 *
2215 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2216 * values from/to the user buffer, treated as an ASCII string.
2217 * The values read are assumed to be in seconds, and are converted into
2218 * jiffies.
2219 *
2220 * Returns 0 on success.
2221 */
2222int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2223 void __user *buffer, size_t *lenp, loff_t *ppos)
2224{
2225 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2226 do_proc_dointvec_jiffies_conv,NULL);
2227}
2228
2229/**
2230 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2231 * @table: the sysctl table
2232 * @write: %TRUE if this is a write to the sysctl file
2233 * @filp: the file structure
2234 * @buffer: the user buffer
2235 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002236 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 *
2238 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2239 * values from/to the user buffer, treated as an ASCII string.
2240 * The values read are assumed to be in 1/USER_HZ seconds, and
2241 * are converted into jiffies.
2242 *
2243 * Returns 0 on success.
2244 */
2245int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2246 void __user *buffer, size_t *lenp, loff_t *ppos)
2247{
2248 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2249 do_proc_dointvec_userhz_jiffies_conv,NULL);
2250}
2251
2252/**
2253 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2254 * @table: the sysctl table
2255 * @write: %TRUE if this is a write to the sysctl file
2256 * @filp: the file structure
2257 * @buffer: the user buffer
2258 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002259 * @ppos: file position
2260 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 *
2262 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2263 * values from/to the user buffer, treated as an ASCII string.
2264 * The values read are assumed to be in 1/1000 seconds, and
2265 * are converted into jiffies.
2266 *
2267 * Returns 0 on success.
2268 */
2269int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2270 void __user *buffer, size_t *lenp, loff_t *ppos)
2271{
2272 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2273 do_proc_dointvec_ms_jiffies_conv, NULL);
2274}
2275
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002276static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2277 void __user *buffer, size_t *lenp, loff_t *ppos)
2278{
2279 struct pid *new_pid;
2280 pid_t tmp;
2281 int r;
2282
2283 tmp = pid_nr(cad_pid);
2284
2285 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2286 lenp, ppos, NULL, NULL);
2287 if (r || !write)
2288 return r;
2289
2290 new_pid = find_get_pid(tmp);
2291 if (!new_pid)
2292 return -ESRCH;
2293
2294 put_pid(xchg(&cad_pid, new_pid));
2295 return 0;
2296}
2297
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298#else /* CONFIG_PROC_FS */
2299
2300int proc_dostring(ctl_table *table, int write, struct file *filp,
2301 void __user *buffer, size_t *lenp, loff_t *ppos)
2302{
2303 return -ENOSYS;
2304}
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306int proc_dointvec(ctl_table *table, int write, struct file *filp,
2307 void __user *buffer, size_t *lenp, loff_t *ppos)
2308{
2309 return -ENOSYS;
2310}
2311
2312int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2313 void __user *buffer, size_t *lenp, loff_t *ppos)
2314{
2315 return -ENOSYS;
2316}
2317
2318int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2319 void __user *buffer, size_t *lenp, loff_t *ppos)
2320{
2321 return -ENOSYS;
2322}
2323
2324int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2325 void __user *buffer, size_t *lenp, loff_t *ppos)
2326{
2327 return -ENOSYS;
2328}
2329
2330int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2331 void __user *buffer, size_t *lenp, loff_t *ppos)
2332{
2333 return -ENOSYS;
2334}
2335
2336int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2337 void __user *buffer, size_t *lenp, loff_t *ppos)
2338{
2339 return -ENOSYS;
2340}
2341
2342int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2343 void __user *buffer, size_t *lenp, loff_t *ppos)
2344{
2345 return -ENOSYS;
2346}
2347
2348int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2349 struct file *filp,
2350 void __user *buffer,
2351 size_t *lenp, loff_t *ppos)
2352{
2353 return -ENOSYS;
2354}
2355
2356
2357#endif /* CONFIG_PROC_FS */
2358
2359
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002360#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361/*
2362 * General sysctl support routines
2363 */
2364
2365/* The generic string strategy routine: */
2366int sysctl_string(ctl_table *table, int __user *name, int nlen,
2367 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002368 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 if (!table->data || !table->maxlen)
2371 return -ENOTDIR;
2372
2373 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002374 size_t bufsize;
2375 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002377 if (bufsize) {
2378 size_t len = strlen(table->data), copied;
2379
2380 /* This shouldn't trigger for a well-formed sysctl */
2381 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002383
2384 /* Copy up to a max of bufsize-1 bytes of the string */
2385 copied = (len >= bufsize) ? bufsize - 1 : len;
2386
2387 if (copy_to_user(oldval, table->data, copied) ||
2388 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002390 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 return -EFAULT;
2392 }
2393 }
2394 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002395 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 if (len > table->maxlen)
2397 len = table->maxlen;
2398 if(copy_from_user(table->data, newval, len))
2399 return -EFAULT;
2400 if (len == table->maxlen)
2401 len--;
2402 ((char *) table->data)[len] = 0;
2403 }
Yi Yang82c9df82005-12-30 16:37:10 +08002404 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405}
2406
2407/*
2408 * This function makes sure that all of the integers in the vector
2409 * are between the minimum and maximum values given in the arrays
2410 * table->extra1 and table->extra2, respectively.
2411 */
2412int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2413 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002414 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415{
2416
2417 if (newval && newlen) {
2418 int __user *vec = (int __user *) newval;
2419 int *min = (int *) table->extra1;
2420 int *max = (int *) table->extra2;
2421 size_t length;
2422 int i;
2423
2424 if (newlen % sizeof(int) != 0)
2425 return -EINVAL;
2426
2427 if (!table->extra1 && !table->extra2)
2428 return 0;
2429
2430 if (newlen > table->maxlen)
2431 newlen = table->maxlen;
2432 length = newlen / sizeof(int);
2433
2434 for (i = 0; i < length; i++) {
2435 int value;
2436 if (get_user(value, vec + i))
2437 return -EFAULT;
2438 if (min && value < min[i])
2439 return -EINVAL;
2440 if (max && value > max[i])
2441 return -EINVAL;
2442 }
2443 }
2444 return 0;
2445}
2446
2447/* Strategy function to convert jiffies to seconds */
2448int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2449 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002450 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002452 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002454
2455 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002457 if (olen) {
2458 int val;
2459
2460 if (olen < sizeof(int))
2461 return -EINVAL;
2462
2463 val = *(int *)(table->data) / HZ;
2464 if (put_user(val, (int __user *)oldval))
2465 return -EFAULT;
2466 if (put_user(sizeof(int), oldlenp))
2467 return -EFAULT;
2468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 }
2470 if (newval && newlen) {
2471 int new;
2472 if (newlen != sizeof(int))
2473 return -EINVAL;
2474 if (get_user(new, (int __user *)newval))
2475 return -EFAULT;
2476 *(int *)(table->data) = new*HZ;
2477 }
2478 return 1;
2479}
2480
2481/* Strategy function to convert jiffies to seconds */
2482int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2483 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002484 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002486 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002488
2489 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002491 if (olen) {
2492 int val;
2493
2494 if (olen < sizeof(int))
2495 return -EINVAL;
2496
2497 val = jiffies_to_msecs(*(int *)(table->data));
2498 if (put_user(val, (int __user *)oldval))
2499 return -EFAULT;
2500 if (put_user(sizeof(int), oldlenp))
2501 return -EFAULT;
2502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 }
2504 if (newval && newlen) {
2505 int new;
2506 if (newlen != sizeof(int))
2507 return -EINVAL;
2508 if (get_user(new, (int __user *)newval))
2509 return -EFAULT;
2510 *(int *)(table->data) = msecs_to_jiffies(new);
2511 }
2512 return 1;
2513}
2514
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002515
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002516
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002517#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
2519
2520asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2521{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002522 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002523 struct __sysctl_args tmp;
2524 int name[CTL_MAXNAME];
2525 int i;
2526
2527 /* Read in the sysctl name for better debug message logging */
2528 if (copy_from_user(&tmp, args, sizeof(tmp)))
2529 return -EFAULT;
2530 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2531 return -ENOTDIR;
2532 for (i = 0; i < tmp.nlen; i++)
2533 if (get_user(name[i], tmp.name + i))
2534 return -EFAULT;
2535
2536 /* Ignore accesses to kernel.version */
2537 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2538 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002539
2540 if (msg_count < 5) {
2541 msg_count++;
2542 printk(KERN_INFO
2543 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002544 "system call with ", current->comm);
2545 for (i = 0; i < tmp.nlen; i++)
2546 printk("%d.", name[i]);
2547 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002548 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002549out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 return -ENOSYS;
2551}
2552
2553int sysctl_string(ctl_table *table, int __user *name, int nlen,
2554 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002555 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
2557 return -ENOSYS;
2558}
2559
2560int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2561 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002562 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563{
2564 return -ENOSYS;
2565}
2566
2567int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2568 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002569 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570{
2571 return -ENOSYS;
2572}
2573
2574int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2575 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002576 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577{
2578 return -ENOSYS;
2579}
2580
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002581#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
2583/*
2584 * No sense putting this after each symbol definition, twice,
2585 * exception granted :-)
2586 */
2587EXPORT_SYMBOL(proc_dointvec);
2588EXPORT_SYMBOL(proc_dointvec_jiffies);
2589EXPORT_SYMBOL(proc_dointvec_minmax);
2590EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2591EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2592EXPORT_SYMBOL(proc_dostring);
2593EXPORT_SYMBOL(proc_doulongvec_minmax);
2594EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2595EXPORT_SYMBOL(register_sysctl_table);
2596EXPORT_SYMBOL(sysctl_intvec);
2597EXPORT_SYMBOL(sysctl_jiffies);
2598EXPORT_SYMBOL(sysctl_ms_jiffies);
2599EXPORT_SYMBOL(sysctl_string);
2600EXPORT_SYMBOL(unregister_sysctl_table);