blob: 230ca4eb57fea7c14e584ceb295c1178420d2bdf [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070068extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int pid_max;
71extern int min_free_kbytes;
72extern int printk_ratelimit_jiffies;
73extern int printk_ratelimit_burst;
74extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080075extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080076extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020077extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070078extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070079extern int sysctl_stat_interval;
Peter Zijlstrabdf4c482007-07-19 01:48:15 -070080extern int audit_argv_kb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83static int maxolduid = 65535;
84static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080085static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87static int ngroups_max = NGROUPS_MAX;
88
89#ifdef CONFIG_KMOD
90extern char modprobe_path[];
91#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#ifdef CONFIG_CHR_DEV_SG
93extern int sg_big_buff;
94#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96#ifdef __sparc__
97extern char reboot_command [];
98extern int stop_a_enabled;
99extern int scons_pwroff;
100#endif
101
102#ifdef __hppa__
103extern int pwrsw_enabled;
104extern int unaligned_enabled;
105#endif
106
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800107#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#ifdef CONFIG_MATHEMU
109extern int sysctl_ieee_emulation_warnings;
110#endif
111extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700112extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#endif
114
115extern int sysctl_hz_timer;
116
117#ifdef CONFIG_BSD_PROCESS_ACCT
118extern int acct_parm[];
119#endif
120
Jes Sorensend2b176e2006-02-28 09:42:23 -0800121#ifdef CONFIG_IA64
122extern int no_unaligned_warning;
123#endif
124
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700125#ifdef CONFIG_RT_MUTEXES
126extern int max_lock_depth;
127#endif
128
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700129#ifdef CONFIG_SYSCTL_SYSCALL
130static int parse_table(int __user *, int, void __user *, size_t __user *,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800131 void __user *, size_t, ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700132#endif
133
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800134
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700135#ifdef CONFIG_PROC_SYSCTL
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700136static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
137 void __user *buffer, size_t *lenp, loff_t *ppos);
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800138static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
139 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700140#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142static ctl_table root_table[];
143static struct ctl_table_header root_table_header =
144 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
145
146static ctl_table kern_table[];
147static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static ctl_table fs_table[];
149static ctl_table debug_table[];
150static ctl_table dev_table[];
151extern ctl_table random_table[];
152#ifdef CONFIG_UNIX98_PTYS
153extern ctl_table pty_table[];
154#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700155#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400156extern ctl_table inotify_table[];
157#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160int sysctl_legacy_va_layout;
161#endif
162
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700163extern int prove_locking;
164extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/* The default sysctl tables: */
167
168static ctl_table root_table[] = {
169 {
170 .ctl_name = CTL_KERN,
171 .procname = "kernel",
172 .mode = 0555,
173 .child = kern_table,
174 },
175 {
176 .ctl_name = CTL_VM,
177 .procname = "vm",
178 .mode = 0555,
179 .child = vm_table,
180 },
181#ifdef CONFIG_NET
182 {
183 .ctl_name = CTL_NET,
184 .procname = "net",
185 .mode = 0555,
186 .child = net_table,
187 },
188#endif
189 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 .ctl_name = CTL_FS,
191 .procname = "fs",
192 .mode = 0555,
193 .child = fs_table,
194 },
195 {
196 .ctl_name = CTL_DEBUG,
197 .procname = "debug",
198 .mode = 0555,
199 .child = debug_table,
200 },
201 {
202 .ctl_name = CTL_DEV,
203 .procname = "dev",
204 .mode = 0555,
205 .child = dev_table,
206 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700207/*
208 * NOTE: do not add new entries to this table unless you have read
209 * Documentation/sysctl/ctl_unnumbered.txt
210 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 { .ctl_name = 0 }
212};
213
Ingo Molnar77e54a12007-07-09 18:52:00 +0200214#ifdef CONFIG_SCHED_DEBUG
215static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
216static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
217static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
218static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
219#endif
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221static ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200222#ifdef CONFIG_SCHED_DEBUG
223 {
224 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200225 .procname = "sched_nr_latency",
226 .data = &sysctl_sched_nr_latency,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200227 .maxlen = sizeof(unsigned int),
228 .mode = 0644,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200229 .proc_handler = &proc_dointvec,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200230 },
231 {
232 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200233 .procname = "sched_latency_ns",
234 .data = &sysctl_sched_latency,
235 .maxlen = sizeof(unsigned int),
236 .mode = 0644,
237 .proc_handler = &proc_dointvec_minmax,
238 .strategy = &sysctl_intvec,
239 .extra1 = &min_sched_granularity_ns,
240 .extra2 = &max_sched_granularity_ns,
241 },
242 {
243 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244 .procname = "sched_wakeup_granularity_ns",
245 .data = &sysctl_sched_wakeup_granularity,
246 .maxlen = sizeof(unsigned int),
247 .mode = 0644,
248 .proc_handler = &proc_dointvec_minmax,
249 .strategy = &sysctl_intvec,
250 .extra1 = &min_wakeup_granularity_ns,
251 .extra2 = &max_wakeup_granularity_ns,
252 },
253 {
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "sched_batch_wakeup_granularity_ns",
256 .data = &sysctl_sched_batch_wakeup_granularity,
257 .maxlen = sizeof(unsigned int),
258 .mode = 0644,
259 .proc_handler = &proc_dointvec_minmax,
260 .strategy = &sysctl_intvec,
261 .extra1 = &min_wakeup_granularity_ns,
262 .extra2 = &max_wakeup_granularity_ns,
263 },
264 {
265 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200266 .procname = "sched_child_runs_first",
267 .data = &sysctl_sched_child_runs_first,
268 .maxlen = sizeof(unsigned int),
269 .mode = 0644,
270 .proc_handler = &proc_dointvec,
271 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200272 {
273 .ctl_name = CTL_UNNUMBERED,
274 .procname = "sched_features",
275 .data = &sysctl_sched_features,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
278 .proc_handler = &proc_dointvec,
279 },
280#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200281 {
282 .ctl_name = CTL_UNNUMBERED,
283 .procname = "sched_compat_yield",
284 .data = &sysctl_sched_compat_yield,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = &proc_dointvec,
288 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700289#ifdef CONFIG_PROVE_LOCKING
290 {
291 .ctl_name = CTL_UNNUMBERED,
292 .procname = "prove_locking",
293 .data = &prove_locking,
294 .maxlen = sizeof(int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec,
297 },
298#endif
299#ifdef CONFIG_LOCK_STAT
300 {
301 .ctl_name = CTL_UNNUMBERED,
302 .procname = "lock_stat",
303 .data = &lock_stat,
304 .maxlen = sizeof(int),
305 .mode = 0644,
306 .proc_handler = &proc_dointvec,
307 },
308#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200309 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 .ctl_name = KERN_PANIC,
311 .procname = "panic",
312 .data = &panic_timeout,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = &proc_dointvec,
316 },
317 {
318 .ctl_name = KERN_CORE_USES_PID,
319 .procname = "core_uses_pid",
320 .data = &core_uses_pid,
321 .maxlen = sizeof(int),
322 .mode = 0644,
323 .proc_handler = &proc_dointvec,
324 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700325#ifdef CONFIG_AUDITSYSCALL
326 {
327 .ctl_name = CTL_UNNUMBERED,
328 .procname = "audit_argv_kb",
329 .data = &audit_argv_kb,
330 .maxlen = sizeof(int),
331 .mode = 0644,
332 .proc_handler = &proc_dointvec,
333 },
334#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 {
336 .ctl_name = KERN_CORE_PATTERN,
337 .procname = "core_pattern",
338 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700339 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 .mode = 0644,
341 .proc_handler = &proc_dostring,
342 .strategy = &sysctl_string,
343 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800344#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 {
346 .ctl_name = KERN_TAINTED,
347 .procname = "tainted",
348 .data = &tainted,
349 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800350 .mode = 0644,
351 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800353#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 {
355 .ctl_name = KERN_CAP_BSET,
356 .procname = "cap-bound",
357 .data = &cap_bset,
358 .maxlen = sizeof(kernel_cap_t),
359 .mode = 0600,
360 .proc_handler = &proc_dointvec_bset,
361 },
362#ifdef CONFIG_BLK_DEV_INITRD
363 {
364 .ctl_name = KERN_REALROOTDEV,
365 .procname = "real-root-dev",
366 .data = &real_root_dev,
367 .maxlen = sizeof(int),
368 .mode = 0644,
369 .proc_handler = &proc_dointvec,
370 },
371#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700372 {
373 .ctl_name = CTL_UNNUMBERED,
374 .procname = "print-fatal-signals",
375 .data = &print_fatal_signals,
376 .maxlen = sizeof(int),
377 .mode = 0644,
378 .proc_handler = &proc_dointvec,
379 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#ifdef __sparc__
381 {
382 .ctl_name = KERN_SPARC_REBOOT,
383 .procname = "reboot-cmd",
384 .data = reboot_command,
385 .maxlen = 256,
386 .mode = 0644,
387 .proc_handler = &proc_dostring,
388 .strategy = &sysctl_string,
389 },
390 {
391 .ctl_name = KERN_SPARC_STOP_A,
392 .procname = "stop-a",
393 .data = &stop_a_enabled,
394 .maxlen = sizeof (int),
395 .mode = 0644,
396 .proc_handler = &proc_dointvec,
397 },
398 {
399 .ctl_name = KERN_SPARC_SCONS_PWROFF,
400 .procname = "scons-poweroff",
401 .data = &scons_pwroff,
402 .maxlen = sizeof (int),
403 .mode = 0644,
404 .proc_handler = &proc_dointvec,
405 },
406#endif
407#ifdef __hppa__
408 {
409 .ctl_name = KERN_HPPA_PWRSW,
410 .procname = "soft-power",
411 .data = &pwrsw_enabled,
412 .maxlen = sizeof (int),
413 .mode = 0644,
414 .proc_handler = &proc_dointvec,
415 },
416 {
417 .ctl_name = KERN_HPPA_UNALIGNED,
418 .procname = "unaligned-trap",
419 .data = &unaligned_enabled,
420 .maxlen = sizeof (int),
421 .mode = 0644,
422 .proc_handler = &proc_dointvec,
423 },
424#endif
425 {
426 .ctl_name = KERN_CTLALTDEL,
427 .procname = "ctrl-alt-del",
428 .data = &C_A_D,
429 .maxlen = sizeof(int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
432 },
433 {
434 .ctl_name = KERN_PRINTK,
435 .procname = "printk",
436 .data = &console_loglevel,
437 .maxlen = 4*sizeof(int),
438 .mode = 0644,
439 .proc_handler = &proc_dointvec,
440 },
441#ifdef CONFIG_KMOD
442 {
443 .ctl_name = KERN_MODPROBE,
444 .procname = "modprobe",
445 .data = &modprobe_path,
446 .maxlen = KMOD_PATH_LEN,
447 .mode = 0644,
448 .proc_handler = &proc_dostring,
449 .strategy = &sysctl_string,
450 },
451#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700452#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 {
454 .ctl_name = KERN_HOTPLUG,
455 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100456 .data = &uevent_helper,
457 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 .mode = 0644,
459 .proc_handler = &proc_dostring,
460 .strategy = &sysctl_string,
461 },
462#endif
463#ifdef CONFIG_CHR_DEV_SG
464 {
465 .ctl_name = KERN_SG_BIG_BUFF,
466 .procname = "sg-big-buff",
467 .data = &sg_big_buff,
468 .maxlen = sizeof (int),
469 .mode = 0444,
470 .proc_handler = &proc_dointvec,
471 },
472#endif
473#ifdef CONFIG_BSD_PROCESS_ACCT
474 {
475 .ctl_name = KERN_ACCT,
476 .procname = "acct",
477 .data = &acct_parm,
478 .maxlen = 3*sizeof(int),
479 .mode = 0644,
480 .proc_handler = &proc_dointvec,
481 },
482#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483#ifdef CONFIG_MAGIC_SYSRQ
484 {
485 .ctl_name = KERN_SYSRQ,
486 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800487 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 .maxlen = sizeof (int),
489 .mode = 0644,
490 .proc_handler = &proc_dointvec,
491 },
492#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700493#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 {
495 .ctl_name = KERN_CADPID,
496 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700497 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .maxlen = sizeof (int),
499 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700500 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700502#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 {
504 .ctl_name = KERN_MAX_THREADS,
505 .procname = "threads-max",
506 .data = &max_threads,
507 .maxlen = sizeof(int),
508 .mode = 0644,
509 .proc_handler = &proc_dointvec,
510 },
511 {
512 .ctl_name = KERN_RANDOM,
513 .procname = "random",
514 .mode = 0555,
515 .child = random_table,
516 },
517#ifdef CONFIG_UNIX98_PTYS
518 {
519 .ctl_name = KERN_PTY,
520 .procname = "pty",
521 .mode = 0555,
522 .child = pty_table,
523 },
524#endif
525 {
526 .ctl_name = KERN_OVERFLOWUID,
527 .procname = "overflowuid",
528 .data = &overflowuid,
529 .maxlen = sizeof(int),
530 .mode = 0644,
531 .proc_handler = &proc_dointvec_minmax,
532 .strategy = &sysctl_intvec,
533 .extra1 = &minolduid,
534 .extra2 = &maxolduid,
535 },
536 {
537 .ctl_name = KERN_OVERFLOWGID,
538 .procname = "overflowgid",
539 .data = &overflowgid,
540 .maxlen = sizeof(int),
541 .mode = 0644,
542 .proc_handler = &proc_dointvec_minmax,
543 .strategy = &sysctl_intvec,
544 .extra1 = &minolduid,
545 .extra2 = &maxolduid,
546 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800547#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548#ifdef CONFIG_MATHEMU
549 {
550 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
551 .procname = "ieee_emulation_warnings",
552 .data = &sysctl_ieee_emulation_warnings,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 .proc_handler = &proc_dointvec,
556 },
557#endif
558#ifdef CONFIG_NO_IDLE_HZ
559 {
560 .ctl_name = KERN_HZ_TIMER,
561 .procname = "hz_timer",
562 .data = &sysctl_hz_timer,
563 .maxlen = sizeof(int),
564 .mode = 0644,
565 .proc_handler = &proc_dointvec,
566 },
567#endif
568 {
569 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
570 .procname = "userprocess_debug",
571 .data = &sysctl_userprocess_debug,
572 .maxlen = sizeof(int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
575 },
576#endif
577 {
578 .ctl_name = KERN_PIDMAX,
579 .procname = "pid_max",
580 .data = &pid_max,
581 .maxlen = sizeof (int),
582 .mode = 0644,
583 .proc_handler = &proc_dointvec_minmax,
584 .strategy = sysctl_intvec,
585 .extra1 = &pid_max_min,
586 .extra2 = &pid_max_max,
587 },
588 {
589 .ctl_name = KERN_PANIC_ON_OOPS,
590 .procname = "panic_on_oops",
591 .data = &panic_on_oops,
592 .maxlen = sizeof(int),
593 .mode = 0644,
594 .proc_handler = &proc_dointvec,
595 },
596 {
597 .ctl_name = KERN_PRINTK_RATELIMIT,
598 .procname = "printk_ratelimit",
599 .data = &printk_ratelimit_jiffies,
600 .maxlen = sizeof(int),
601 .mode = 0644,
602 .proc_handler = &proc_dointvec_jiffies,
603 .strategy = &sysctl_jiffies,
604 },
605 {
606 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
607 .procname = "printk_ratelimit_burst",
608 .data = &printk_ratelimit_burst,
609 .maxlen = sizeof(int),
610 .mode = 0644,
611 .proc_handler = &proc_dointvec,
612 },
613 {
614 .ctl_name = KERN_NGROUPS_MAX,
615 .procname = "ngroups_max",
616 .data = &ngroups_max,
617 .maxlen = sizeof (int),
618 .mode = 0444,
619 .proc_handler = &proc_dointvec,
620 },
621#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
622 {
623 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
624 .procname = "unknown_nmi_panic",
625 .data = &unknown_nmi_panic,
626 .maxlen = sizeof (int),
627 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200628 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 },
Don Zickus407984f2006-09-26 10:52:27 +0200630 {
631 .ctl_name = KERN_NMI_WATCHDOG,
632 .procname = "nmi_watchdog",
633 .data = &nmi_watchdog_enabled,
634 .maxlen = sizeof (int),
635 .mode = 0644,
636 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 },
638#endif
639#if defined(CONFIG_X86)
640 {
Don Zickus8da5add2006-09-26 10:52:27 +0200641 .ctl_name = KERN_PANIC_ON_NMI,
642 .procname = "panic_on_unrecovered_nmi",
643 .data = &panic_on_unrecovered_nmi,
644 .maxlen = sizeof(int),
645 .mode = 0644,
646 .proc_handler = &proc_dointvec,
647 },
648 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .ctl_name = KERN_BOOTLOADER_TYPE,
650 .procname = "bootloader_type",
651 .data = &bootloader_type,
652 .maxlen = sizeof (int),
653 .mode = 0444,
654 .proc_handler = &proc_dointvec,
655 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100656 {
657 .ctl_name = CTL_UNNUMBERED,
658 .procname = "kstack_depth_to_print",
659 .data = &kstack_depth_to_print,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800665#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 {
667 .ctl_name = KERN_RANDOMIZE,
668 .procname = "randomize_va_space",
669 .data = &randomize_va_space,
670 .maxlen = sizeof(int),
671 .mode = 0644,
672 .proc_handler = &proc_dointvec,
673 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800674#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800675#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700676 {
677 .ctl_name = KERN_SPIN_RETRY,
678 .procname = "spin_retry",
679 .data = &spin_retry,
680 .maxlen = sizeof (int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
683 },
684#endif
Len Brown673d5b42007-07-28 03:33:16 -0400685#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800686 {
687 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
688 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700689 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800690 .maxlen = sizeof (unsigned long),
691 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800692 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800693 },
694#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800695#ifdef CONFIG_IA64
696 {
697 .ctl_name = KERN_IA64_UNALIGNED,
698 .procname = "ignore-unaligned-usertrap",
699 .data = &no_unaligned_warning,
700 .maxlen = sizeof (int),
701 .mode = 0644,
702 .proc_handler = &proc_dointvec,
703 },
704#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200705#ifdef CONFIG_COMPAT
706 {
707 .ctl_name = KERN_COMPAT_LOG,
708 .procname = "compat-log",
709 .data = &compat_log,
710 .maxlen = sizeof (int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
714#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700715#ifdef CONFIG_RT_MUTEXES
716 {
717 .ctl_name = KERN_MAX_LOCK_DEPTH,
718 .procname = "max_lock_depth",
719 .data = &max_lock_depth,
720 .maxlen = sizeof(int),
721 .mode = 0644,
722 .proc_handler = &proc_dointvec,
723 },
724#endif
Kees Cook5096add2007-05-08 00:26:04 -0700725#ifdef CONFIG_PROC_FS
726 {
727 .ctl_name = CTL_UNNUMBERED,
728 .procname = "maps_protect",
729 .data = &maps_protect,
730 .maxlen = sizeof(int),
731 .mode = 0644,
732 .proc_handler = &proc_dointvec,
733 },
734#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700735 {
736 .ctl_name = CTL_UNNUMBERED,
737 .procname = "poweroff_cmd",
738 .data = &poweroff_cmd,
739 .maxlen = POWEROFF_CMD_PATH_LEN,
740 .mode = 0644,
741 .proc_handler = &proc_dostring,
742 .strategy = &sysctl_string,
743 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700744/*
745 * NOTE: do not add new entries to this table unless you have read
746 * Documentation/sysctl/ctl_unnumbered.txt
747 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 { .ctl_name = 0 }
749};
750
751/* Constants for minimum and maximum testing in vm_table.
752 We use these as one-element integer vectors. */
753static int zero;
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -0700754static int two = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755static int one_hundred = 100;
756
757
758static ctl_table vm_table[] = {
759 {
760 .ctl_name = VM_OVERCOMMIT_MEMORY,
761 .procname = "overcommit_memory",
762 .data = &sysctl_overcommit_memory,
763 .maxlen = sizeof(sysctl_overcommit_memory),
764 .mode = 0644,
765 .proc_handler = &proc_dointvec,
766 },
767 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700768 .ctl_name = VM_PANIC_ON_OOM,
769 .procname = "panic_on_oom",
770 .data = &sysctl_panic_on_oom,
771 .maxlen = sizeof(sysctl_panic_on_oom),
772 .mode = 0644,
773 .proc_handler = &proc_dointvec,
774 },
775 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 .ctl_name = VM_OVERCOMMIT_RATIO,
777 .procname = "overcommit_ratio",
778 .data = &sysctl_overcommit_ratio,
779 .maxlen = sizeof(sysctl_overcommit_ratio),
780 .mode = 0644,
781 .proc_handler = &proc_dointvec,
782 },
783 {
784 .ctl_name = VM_PAGE_CLUSTER,
785 .procname = "page-cluster",
786 .data = &page_cluster,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = &proc_dointvec,
790 },
791 {
792 .ctl_name = VM_DIRTY_BACKGROUND,
793 .procname = "dirty_background_ratio",
794 .data = &dirty_background_ratio,
795 .maxlen = sizeof(dirty_background_ratio),
796 .mode = 0644,
797 .proc_handler = &proc_dointvec_minmax,
798 .strategy = &sysctl_intvec,
799 .extra1 = &zero,
800 .extra2 = &one_hundred,
801 },
802 {
803 .ctl_name = VM_DIRTY_RATIO,
804 .procname = "dirty_ratio",
805 .data = &vm_dirty_ratio,
806 .maxlen = sizeof(vm_dirty_ratio),
807 .mode = 0644,
808 .proc_handler = &proc_dointvec_minmax,
809 .strategy = &sysctl_intvec,
810 .extra1 = &zero,
811 .extra2 = &one_hundred,
812 },
813 {
814 .ctl_name = VM_DIRTY_WB_CS,
815 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800816 .data = &dirty_writeback_interval,
817 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 .mode = 0644,
819 .proc_handler = &dirty_writeback_centisecs_handler,
820 },
821 {
822 .ctl_name = VM_DIRTY_EXPIRE_CS,
823 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800824 .data = &dirty_expire_interval,
825 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800827 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 },
829 {
830 .ctl_name = VM_NR_PDFLUSH_THREADS,
831 .procname = "nr_pdflush_threads",
832 .data = &nr_pdflush_threads,
833 .maxlen = sizeof nr_pdflush_threads,
834 .mode = 0444 /* read-only*/,
835 .proc_handler = &proc_dointvec,
836 },
837 {
838 .ctl_name = VM_SWAPPINESS,
839 .procname = "swappiness",
840 .data = &vm_swappiness,
841 .maxlen = sizeof(vm_swappiness),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec_minmax,
844 .strategy = &sysctl_intvec,
845 .extra1 = &zero,
846 .extra2 = &one_hundred,
847 },
848#ifdef CONFIG_HUGETLB_PAGE
849 {
850 .ctl_name = VM_HUGETLB_PAGES,
851 .procname = "nr_hugepages",
852 .data = &max_huge_pages,
853 .maxlen = sizeof(unsigned long),
854 .mode = 0644,
855 .proc_handler = &hugetlb_sysctl_handler,
856 .extra1 = (void *)&hugetlb_zero,
857 .extra2 = (void *)&hugetlb_infinity,
858 },
859 {
860 .ctl_name = VM_HUGETLB_GROUP,
861 .procname = "hugetlb_shm_group",
862 .data = &sysctl_hugetlb_shm_group,
863 .maxlen = sizeof(gid_t),
864 .mode = 0644,
865 .proc_handler = &proc_dointvec,
866 },
Mel Gorman396faf02007-07-17 04:03:13 -0700867 {
868 .ctl_name = CTL_UNNUMBERED,
869 .procname = "hugepages_treat_as_movable",
870 .data = &hugepages_treat_as_movable,
871 .maxlen = sizeof(int),
872 .mode = 0644,
873 .proc_handler = &hugetlb_treat_movable_handler,
874 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875#endif
876 {
877 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
878 .procname = "lowmem_reserve_ratio",
879 .data = &sysctl_lowmem_reserve_ratio,
880 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
881 .mode = 0644,
882 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
883 .strategy = &sysctl_intvec,
884 },
885 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800886 .ctl_name = VM_DROP_PAGECACHE,
887 .procname = "drop_caches",
888 .data = &sysctl_drop_caches,
889 .maxlen = sizeof(int),
890 .mode = 0644,
891 .proc_handler = drop_caches_sysctl_handler,
892 .strategy = &sysctl_intvec,
893 },
894 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 .ctl_name = VM_MIN_FREE_KBYTES,
896 .procname = "min_free_kbytes",
897 .data = &min_free_kbytes,
898 .maxlen = sizeof(min_free_kbytes),
899 .mode = 0644,
900 .proc_handler = &min_free_kbytes_sysctl_handler,
901 .strategy = &sysctl_intvec,
902 .extra1 = &zero,
903 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800904 {
905 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
906 .procname = "percpu_pagelist_fraction",
907 .data = &percpu_pagelist_fraction,
908 .maxlen = sizeof(percpu_pagelist_fraction),
909 .mode = 0644,
910 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
911 .strategy = &sysctl_intvec,
912 .extra1 = &min_percpu_pagelist_fract,
913 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914#ifdef CONFIG_MMU
915 {
916 .ctl_name = VM_MAX_MAP_COUNT,
917 .procname = "max_map_count",
918 .data = &sysctl_max_map_count,
919 .maxlen = sizeof(sysctl_max_map_count),
920 .mode = 0644,
921 .proc_handler = &proc_dointvec
922 },
923#endif
924 {
925 .ctl_name = VM_LAPTOP_MODE,
926 .procname = "laptop_mode",
927 .data = &laptop_mode,
928 .maxlen = sizeof(laptop_mode),
929 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800930 .proc_handler = &proc_dointvec_jiffies,
931 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 },
933 {
934 .ctl_name = VM_BLOCK_DUMP,
935 .procname = "block_dump",
936 .data = &block_dump,
937 .maxlen = sizeof(block_dump),
938 .mode = 0644,
939 .proc_handler = &proc_dointvec,
940 .strategy = &sysctl_intvec,
941 .extra1 = &zero,
942 },
943 {
944 .ctl_name = VM_VFS_CACHE_PRESSURE,
945 .procname = "vfs_cache_pressure",
946 .data = &sysctl_vfs_cache_pressure,
947 .maxlen = sizeof(sysctl_vfs_cache_pressure),
948 .mode = 0644,
949 .proc_handler = &proc_dointvec,
950 .strategy = &sysctl_intvec,
951 .extra1 = &zero,
952 },
953#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
954 {
955 .ctl_name = VM_LEGACY_VA_LAYOUT,
956 .procname = "legacy_va_layout",
957 .data = &sysctl_legacy_va_layout,
958 .maxlen = sizeof(sysctl_legacy_va_layout),
959 .mode = 0644,
960 .proc_handler = &proc_dointvec,
961 .strategy = &sysctl_intvec,
962 .extra1 = &zero,
963 },
964#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800965#ifdef CONFIG_NUMA
966 {
967 .ctl_name = VM_ZONE_RECLAIM_MODE,
968 .procname = "zone_reclaim_mode",
969 .data = &zone_reclaim_mode,
970 .maxlen = sizeof(zone_reclaim_mode),
971 .mode = 0644,
972 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -0800973 .strategy = &sysctl_intvec,
974 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -0800975 },
Christoph Lameter96146342006-07-03 00:24:13 -0700976 {
977 .ctl_name = VM_MIN_UNMAPPED,
978 .procname = "min_unmapped_ratio",
979 .data = &sysctl_min_unmapped_ratio,
980 .maxlen = sizeof(sysctl_min_unmapped_ratio),
981 .mode = 0644,
982 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
983 .strategy = &sysctl_intvec,
984 .extra1 = &zero,
985 .extra2 = &one_hundred,
986 },
Christoph Lameter0ff38492006-09-25 23:31:52 -0700987 {
988 .ctl_name = VM_MIN_SLAB,
989 .procname = "min_slab_ratio",
990 .data = &sysctl_min_slab_ratio,
991 .maxlen = sizeof(sysctl_min_slab_ratio),
992 .mode = 0644,
993 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
994 .strategy = &sysctl_intvec,
995 .extra1 = &zero,
996 .extra2 = &one_hundred,
997 },
Christoph Lameter17436602006-01-18 17:42:32 -0800998#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -0700999#ifdef CONFIG_SMP
1000 {
1001 .ctl_name = CTL_UNNUMBERED,
1002 .procname = "stat_interval",
1003 .data = &sysctl_stat_interval,
1004 .maxlen = sizeof(sysctl_stat_interval),
1005 .mode = 0644,
1006 .proc_handler = &proc_dointvec_jiffies,
1007 .strategy = &sysctl_jiffies,
1008 },
1009#endif
Eric Parised032182007-06-28 15:55:21 -04001010#ifdef CONFIG_SECURITY
1011 {
1012 .ctl_name = CTL_UNNUMBERED,
1013 .procname = "mmap_min_addr",
1014 .data = &mmap_min_addr,
1015 .maxlen = sizeof(unsigned long),
1016 .mode = 0644,
1017 .proc_handler = &proc_doulongvec_minmax,
1018 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001019#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001020#ifdef CONFIG_NUMA
1021 {
1022 .ctl_name = CTL_UNNUMBERED,
1023 .procname = "numa_zonelist_order",
1024 .data = &numa_zonelist_order,
1025 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1026 .mode = 0644,
1027 .proc_handler = &numa_zonelist_order_handler,
1028 .strategy = &sysctl_string,
1029 },
1030#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001031#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001032 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001033 {
1034 .ctl_name = VM_VDSO_ENABLED,
1035 .procname = "vdso_enabled",
1036 .data = &vdso_enabled,
1037 .maxlen = sizeof(vdso_enabled),
1038 .mode = 0644,
1039 .proc_handler = &proc_dointvec,
1040 .strategy = &sysctl_intvec,
1041 .extra1 = &zero,
1042 },
1043#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001044/*
1045 * NOTE: do not add new entries to this table unless you have read
1046 * Documentation/sysctl/ctl_unnumbered.txt
1047 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 { .ctl_name = 0 }
1049};
1050
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001051#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1052static ctl_table binfmt_misc_table[] = {
1053 { .ctl_name = 0 }
1054};
1055#endif
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057static ctl_table fs_table[] = {
1058 {
1059 .ctl_name = FS_NRINODE,
1060 .procname = "inode-nr",
1061 .data = &inodes_stat,
1062 .maxlen = 2*sizeof(int),
1063 .mode = 0444,
1064 .proc_handler = &proc_dointvec,
1065 },
1066 {
1067 .ctl_name = FS_STATINODE,
1068 .procname = "inode-state",
1069 .data = &inodes_stat,
1070 .maxlen = 7*sizeof(int),
1071 .mode = 0444,
1072 .proc_handler = &proc_dointvec,
1073 },
1074 {
1075 .ctl_name = FS_NRFILE,
1076 .procname = "file-nr",
1077 .data = &files_stat,
1078 .maxlen = 3*sizeof(int),
1079 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001080 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 },
1082 {
1083 .ctl_name = FS_MAXFILE,
1084 .procname = "file-max",
1085 .data = &files_stat.max_files,
1086 .maxlen = sizeof(int),
1087 .mode = 0644,
1088 .proc_handler = &proc_dointvec,
1089 },
1090 {
1091 .ctl_name = FS_DENTRY,
1092 .procname = "dentry-state",
1093 .data = &dentry_stat,
1094 .maxlen = 6*sizeof(int),
1095 .mode = 0444,
1096 .proc_handler = &proc_dointvec,
1097 },
1098 {
1099 .ctl_name = FS_OVERFLOWUID,
1100 .procname = "overflowuid",
1101 .data = &fs_overflowuid,
1102 .maxlen = sizeof(int),
1103 .mode = 0644,
1104 .proc_handler = &proc_dointvec_minmax,
1105 .strategy = &sysctl_intvec,
1106 .extra1 = &minolduid,
1107 .extra2 = &maxolduid,
1108 },
1109 {
1110 .ctl_name = FS_OVERFLOWGID,
1111 .procname = "overflowgid",
1112 .data = &fs_overflowgid,
1113 .maxlen = sizeof(int),
1114 .mode = 0644,
1115 .proc_handler = &proc_dointvec_minmax,
1116 .strategy = &sysctl_intvec,
1117 .extra1 = &minolduid,
1118 .extra2 = &maxolduid,
1119 },
1120 {
1121 .ctl_name = FS_LEASES,
1122 .procname = "leases-enable",
1123 .data = &leases_enable,
1124 .maxlen = sizeof(int),
1125 .mode = 0644,
1126 .proc_handler = &proc_dointvec,
1127 },
1128#ifdef CONFIG_DNOTIFY
1129 {
1130 .ctl_name = FS_DIR_NOTIFY,
1131 .procname = "dir-notify-enable",
1132 .data = &dir_notify_enable,
1133 .maxlen = sizeof(int),
1134 .mode = 0644,
1135 .proc_handler = &proc_dointvec,
1136 },
1137#endif
1138#ifdef CONFIG_MMU
1139 {
1140 .ctl_name = FS_LEASE_TIME,
1141 .procname = "lease-break-time",
1142 .data = &lease_break_time,
1143 .maxlen = sizeof(int),
1144 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001145 .proc_handler = &proc_dointvec_minmax,
1146 .strategy = &sysctl_intvec,
1147 .extra1 = &zero,
1148 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 },
1150 {
1151 .ctl_name = FS_AIO_NR,
1152 .procname = "aio-nr",
1153 .data = &aio_nr,
1154 .maxlen = sizeof(aio_nr),
1155 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001156 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 },
1158 {
1159 .ctl_name = FS_AIO_MAX_NR,
1160 .procname = "aio-max-nr",
1161 .data = &aio_max_nr,
1162 .maxlen = sizeof(aio_max_nr),
1163 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001164 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001166#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001167 {
1168 .ctl_name = FS_INOTIFY,
1169 .procname = "inotify",
1170 .mode = 0555,
1171 .child = inotify_table,
1172 },
1173#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001175 {
1176 .ctl_name = KERN_SETUID_DUMPABLE,
1177 .procname = "suid_dumpable",
1178 .data = &suid_dumpable,
1179 .maxlen = sizeof(int),
1180 .mode = 0644,
1181 .proc_handler = &proc_dointvec,
1182 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001183#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1184 {
1185 .ctl_name = CTL_UNNUMBERED,
1186 .procname = "binfmt_misc",
1187 .mode = 0555,
1188 .child = binfmt_misc_table,
1189 },
1190#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001191/*
1192 * NOTE: do not add new entries to this table unless you have read
1193 * Documentation/sysctl/ctl_unnumbered.txt
1194 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 { .ctl_name = 0 }
1196};
1197
1198static ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001199#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001200 {
1201 .ctl_name = CTL_UNNUMBERED,
1202 .procname = "exception-trace",
1203 .data = &show_unhandled_signals,
1204 .maxlen = sizeof(int),
1205 .mode = 0644,
1206 .proc_handler = proc_dointvec
1207 },
1208#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 { .ctl_name = 0 }
1210};
1211
1212static ctl_table dev_table[] = {
1213 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001214};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Al Viro330d57f2005-11-04 10:18:40 +00001216static DEFINE_SPINLOCK(sysctl_lock);
1217
1218/* called under sysctl_lock */
1219static int use_table(struct ctl_table_header *p)
1220{
1221 if (unlikely(p->unregistering))
1222 return 0;
1223 p->used++;
1224 return 1;
1225}
1226
1227/* called under sysctl_lock */
1228static void unuse_table(struct ctl_table_header *p)
1229{
1230 if (!--p->used)
1231 if (unlikely(p->unregistering))
1232 complete(p->unregistering);
1233}
1234
1235/* called under sysctl_lock, will reacquire if has to wait */
1236static void start_unregistering(struct ctl_table_header *p)
1237{
1238 /*
1239 * if p->used is 0, nobody will ever touch that entry again;
1240 * we'll eliminate all paths to it before dropping sysctl_lock
1241 */
1242 if (unlikely(p->used)) {
1243 struct completion wait;
1244 init_completion(&wait);
1245 p->unregistering = &wait;
1246 spin_unlock(&sysctl_lock);
1247 wait_for_completion(&wait);
1248 spin_lock(&sysctl_lock);
1249 }
1250 /*
1251 * do not remove from the list until nobody holds it; walking the
1252 * list in do_sysctl() relies on that.
1253 */
1254 list_del_init(&p->ctl_entry);
1255}
1256
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001257void sysctl_head_finish(struct ctl_table_header *head)
1258{
1259 if (!head)
1260 return;
1261 spin_lock(&sysctl_lock);
1262 unuse_table(head);
1263 spin_unlock(&sysctl_lock);
1264}
1265
1266struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1267{
1268 struct ctl_table_header *head;
1269 struct list_head *tmp;
1270 spin_lock(&sysctl_lock);
1271 if (prev) {
1272 tmp = &prev->ctl_entry;
1273 unuse_table(prev);
1274 goto next;
1275 }
1276 tmp = &root_table_header.ctl_entry;
1277 for (;;) {
1278 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1279
1280 if (!use_table(head))
1281 goto next;
1282 spin_unlock(&sysctl_lock);
1283 return head;
1284 next:
1285 tmp = tmp->next;
1286 if (tmp == &root_table_header.ctl_entry)
1287 break;
1288 }
1289 spin_unlock(&sysctl_lock);
1290 return NULL;
1291}
1292
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001293#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1295 void __user *newval, size_t newlen)
1296{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001297 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001298 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
1300 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1301 return -ENOTDIR;
1302 if (oldval) {
1303 int old_len;
1304 if (!oldlenp || get_user(old_len, oldlenp))
1305 return -EFAULT;
1306 }
Al Viro330d57f2005-11-04 10:18:40 +00001307
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001308 for (head = sysctl_head_next(NULL); head;
1309 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001310 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001311 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001312 if (error != -ENOTDIR) {
1313 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001314 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001315 }
1316 }
Al Viro330d57f2005-11-04 10:18:40 +00001317 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
1319
1320asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1321{
1322 struct __sysctl_args tmp;
1323 int error;
1324
1325 if (copy_from_user(&tmp, args, sizeof(tmp)))
1326 return -EFAULT;
1327
1328 lock_kernel();
1329 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1330 tmp.newval, tmp.newlen);
1331 unlock_kernel();
1332 return error;
1333}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001334#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
1336/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001337 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 * some sysctl variables are readonly even to root.
1339 */
1340
1341static int test_perm(int mode, int op)
1342{
1343 if (!current->euid)
1344 mode >>= 6;
1345 else if (in_egroup_p(0))
1346 mode >>= 3;
1347 if ((mode & op & 0007) == op)
1348 return 0;
1349 return -EACCES;
1350}
1351
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001352int sysctl_perm(ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
1354 int error;
1355 error = security_sysctl(table, op);
1356 if (error)
1357 return error;
1358 return test_perm(table->mode, op);
1359}
1360
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001361#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362static int parse_table(int __user *name, int nlen,
1363 void __user *oldval, size_t __user *oldlenp,
1364 void __user *newval, size_t newlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001365 ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
1367 int n;
1368repeat:
1369 if (!nlen)
1370 return -ENOTDIR;
1371 if (get_user(n, name))
1372 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001373 for ( ; table->ctl_name || table->procname; table++) {
1374 if (!table->ctl_name)
1375 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001376 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 int error;
1378 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001379 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 name++;
1382 nlen--;
1383 table = table->child;
1384 goto repeat;
1385 }
1386 error = do_sysctl_strategy(table, name, nlen,
1387 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001388 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 return error;
1390 }
1391 }
1392 return -ENOTDIR;
1393}
1394
1395/* Perform the actual read/write of a sysctl table entry. */
1396int do_sysctl_strategy (ctl_table *table,
1397 int __user *name, int nlen,
1398 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001399 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400{
1401 int op = 0, rc;
1402 size_t len;
1403
1404 if (oldval)
1405 op |= 004;
1406 if (newval)
1407 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001408 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 return -EPERM;
1410
1411 if (table->strategy) {
1412 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001413 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 if (rc < 0)
1415 return rc;
1416 if (rc > 0)
1417 return 0;
1418 }
1419
1420 /* If there is no strategy routine, or if the strategy returns
1421 * zero, proceed with automatic r/w */
1422 if (table->data && table->maxlen) {
1423 if (oldval && oldlenp) {
1424 if (get_user(len, oldlenp))
1425 return -EFAULT;
1426 if (len) {
1427 if (len > table->maxlen)
1428 len = table->maxlen;
1429 if(copy_to_user(oldval, table->data, len))
1430 return -EFAULT;
1431 if(put_user(len, oldlenp))
1432 return -EFAULT;
1433 }
1434 }
1435 if (newval && newlen) {
1436 len = newlen;
1437 if (len > table->maxlen)
1438 len = table->maxlen;
1439 if(copy_from_user(table->data, newval, len))
1440 return -EFAULT;
1441 }
1442 }
1443 return 0;
1444}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001445#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001447static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1448{
1449 for (; table->ctl_name || table->procname; table++) {
1450 table->parent = parent;
1451 if (table->child)
1452 sysctl_set_parent(table, table->child);
1453 }
1454}
1455
1456static __init int sysctl_init(void)
1457{
1458 sysctl_set_parent(NULL, root_table);
1459 return 0;
1460}
1461
1462core_initcall(sysctl_init);
1463
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464/**
1465 * register_sysctl_table - register a sysctl hierarchy
1466 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 *
1468 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1469 * array. An entry with a ctl_name of 0 terminates the table.
1470 *
1471 * The members of the &ctl_table structure are used as follows:
1472 *
1473 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1474 * must be unique within that level of sysctl
1475 *
1476 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1477 * enter a sysctl file
1478 *
1479 * data - a pointer to data for use by proc_handler
1480 *
1481 * maxlen - the maximum size in bytes of the data
1482 *
1483 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1484 *
1485 * child - a pointer to the child sysctl table if this entry is a directory, or
1486 * %NULL.
1487 *
1488 * proc_handler - the text handler routine (described below)
1489 *
1490 * strategy - the strategy routine (described below)
1491 *
1492 * de - for internal use by the sysctl routines
1493 *
1494 * extra1, extra2 - extra pointers usable by the proc handler routines
1495 *
1496 * Leaf nodes in the sysctl tree will be represented by a single file
1497 * under /proc; non-leaf nodes will be represented by directories.
1498 *
1499 * sysctl(2) can automatically manage read and write requests through
1500 * the sysctl table. The data and maxlen fields of the ctl_table
1501 * struct enable minimal validation of the values being written to be
1502 * performed, and the mode field allows minimal authentication.
1503 *
1504 * More sophisticated management can be enabled by the provision of a
1505 * strategy routine with the table entry. This will be called before
1506 * any automatic read or write of the data is performed.
1507 *
1508 * The strategy routine may return
1509 *
1510 * < 0 - Error occurred (error is passed to user process)
1511 *
1512 * 0 - OK - proceed with automatic read or write.
1513 *
1514 * > 0 - OK - read or write has been done by the strategy routine, so
1515 * return immediately.
1516 *
1517 * There must be a proc_handler routine for any terminal nodes
1518 * mirrored under /proc/sys (non-terminals are handled by a built-in
1519 * directory handler). Several default handlers are available to
1520 * cover common cases -
1521 *
1522 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1523 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1524 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1525 *
1526 * It is the handler's job to read the input buffer from user memory
1527 * and process it. The handler should return 0 on success.
1528 *
1529 * This routine returns %NULL on a failure to register, and a pointer
1530 * to the table header on success.
1531 */
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001532struct ctl_table_header *register_sysctl_table(ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533{
1534 struct ctl_table_header *tmp;
1535 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1536 if (!tmp)
1537 return NULL;
1538 tmp->ctl_table = table;
1539 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001540 tmp->used = 0;
1541 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001542 sysctl_set_parent(NULL, table);
Al Viro330d57f2005-11-04 10:18:40 +00001543 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001544 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001545 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 return tmp;
1547}
1548
1549/**
1550 * unregister_sysctl_table - unregister a sysctl table hierarchy
1551 * @header: the header returned from register_sysctl_table
1552 *
1553 * Unregisters the sysctl table and all children. proc entries may not
1554 * actually be removed until they are no longer used by anyone.
1555 */
1556void unregister_sysctl_table(struct ctl_table_header * header)
1557{
Al Viro330d57f2005-11-04 10:18:40 +00001558 might_sleep();
1559 spin_lock(&sysctl_lock);
1560 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001561 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 kfree(header);
1563}
1564
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001565#else /* !CONFIG_SYSCTL */
Adrian Bunk93a6fef2007-02-28 20:12:23 -08001566struct ctl_table_header *register_sysctl_table(ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001567{
1568 return NULL;
1569}
1570
1571void unregister_sysctl_table(struct ctl_table_header * table)
1572{
1573}
1574
1575#endif /* CONFIG_SYSCTL */
1576
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577/*
1578 * /proc/sys support
1579 */
1580
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001581#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001583static int _proc_do_string(void* data, int maxlen, int write,
1584 struct file *filp, void __user *buffer,
1585 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001586{
1587 size_t len;
1588 char __user *p;
1589 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001590
1591 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001592 *lenp = 0;
1593 return 0;
1594 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001595
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001596 if (write) {
1597 len = 0;
1598 p = buffer;
1599 while (len < *lenp) {
1600 if (get_user(c, p++))
1601 return -EFAULT;
1602 if (c == 0 || c == '\n')
1603 break;
1604 len++;
1605 }
1606 if (len >= maxlen)
1607 len = maxlen-1;
1608 if(copy_from_user(data, buffer, len))
1609 return -EFAULT;
1610 ((char *) data)[len] = 0;
1611 *ppos += *lenp;
1612 } else {
1613 len = strlen(data);
1614 if (len > maxlen)
1615 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001616
1617 if (*ppos > len) {
1618 *lenp = 0;
1619 return 0;
1620 }
1621
1622 data += *ppos;
1623 len -= *ppos;
1624
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001625 if (len > *lenp)
1626 len = *lenp;
1627 if (len)
1628 if(copy_to_user(buffer, data, len))
1629 return -EFAULT;
1630 if (len < *lenp) {
1631 if(put_user('\n', ((char __user *) buffer) + len))
1632 return -EFAULT;
1633 len++;
1634 }
1635 *lenp = len;
1636 *ppos += len;
1637 }
1638 return 0;
1639}
1640
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641/**
1642 * proc_dostring - read a string sysctl
1643 * @table: the sysctl table
1644 * @write: %TRUE if this is a write to the sysctl file
1645 * @filp: the file structure
1646 * @buffer: the user buffer
1647 * @lenp: the size of the user buffer
1648 * @ppos: file position
1649 *
1650 * Reads/writes a string from/to the user buffer. If the kernel
1651 * buffer provided is not large enough to hold the string, the
1652 * string is truncated. The copied string is %NULL-terminated.
1653 * If the string is being read by the user process, it is copied
1654 * and a newline '\n' is added. It is truncated if the buffer is
1655 * not large enough.
1656 *
1657 * Returns 0 on success.
1658 */
1659int proc_dostring(ctl_table *table, int write, struct file *filp,
1660 void __user *buffer, size_t *lenp, loff_t *ppos)
1661{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001662 return _proc_do_string(table->data, table->maxlen, write, filp,
1663 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664}
1665
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1668 int *valp,
1669 int write, void *data)
1670{
1671 if (write) {
1672 *valp = *negp ? -*lvalp : *lvalp;
1673 } else {
1674 int val = *valp;
1675 if (val < 0) {
1676 *negp = -1;
1677 *lvalp = (unsigned long)-val;
1678 } else {
1679 *negp = 0;
1680 *lvalp = (unsigned long)val;
1681 }
1682 }
1683 return 0;
1684}
1685
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001686static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1687 int write, struct file *filp, void __user *buffer,
1688 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1690 int write, void *data),
1691 void *data)
1692{
1693#define TMPBUFLEN 21
1694 int *i, vleft, first=1, neg, val;
1695 unsigned long lval;
1696 size_t left, len;
1697
1698 char buf[TMPBUFLEN], *p;
1699 char __user *s = buffer;
1700
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001701 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 (*ppos && !write)) {
1703 *lenp = 0;
1704 return 0;
1705 }
1706
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001707 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 vleft = table->maxlen / sizeof(*i);
1709 left = *lenp;
1710
1711 if (!conv)
1712 conv = do_proc_dointvec_conv;
1713
1714 for (; left && vleft--; i++, first=0) {
1715 if (write) {
1716 while (left) {
1717 char c;
1718 if (get_user(c, s))
1719 return -EFAULT;
1720 if (!isspace(c))
1721 break;
1722 left--;
1723 s++;
1724 }
1725 if (!left)
1726 break;
1727 neg = 0;
1728 len = left;
1729 if (len > sizeof(buf) - 1)
1730 len = sizeof(buf) - 1;
1731 if (copy_from_user(buf, s, len))
1732 return -EFAULT;
1733 buf[len] = 0;
1734 p = buf;
1735 if (*p == '-' && left > 1) {
1736 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001737 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 }
1739 if (*p < '0' || *p > '9')
1740 break;
1741
1742 lval = simple_strtoul(p, &p, 0);
1743
1744 len = p-buf;
1745 if ((len < left) && *p && !isspace(*p))
1746 break;
1747 if (neg)
1748 val = -val;
1749 s += len;
1750 left -= len;
1751
1752 if (conv(&neg, &lval, i, 1, data))
1753 break;
1754 } else {
1755 p = buf;
1756 if (!first)
1757 *p++ = '\t';
1758
1759 if (conv(&neg, &lval, i, 0, data))
1760 break;
1761
1762 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1763 len = strlen(buf);
1764 if (len > left)
1765 len = left;
1766 if(copy_to_user(s, buf, len))
1767 return -EFAULT;
1768 left -= len;
1769 s += len;
1770 }
1771 }
1772
1773 if (!write && !first && left) {
1774 if(put_user('\n', s))
1775 return -EFAULT;
1776 left--, s++;
1777 }
1778 if (write) {
1779 while (left) {
1780 char c;
1781 if (get_user(c, s++))
1782 return -EFAULT;
1783 if (!isspace(c))
1784 break;
1785 left--;
1786 }
1787 }
1788 if (write && first)
1789 return -EINVAL;
1790 *lenp -= left;
1791 *ppos += *lenp;
1792 return 0;
1793#undef TMPBUFLEN
1794}
1795
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001796static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1797 void __user *buffer, size_t *lenp, loff_t *ppos,
1798 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1799 int write, void *data),
1800 void *data)
1801{
1802 return __do_proc_dointvec(table->data, table, write, filp,
1803 buffer, lenp, ppos, conv, data);
1804}
1805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806/**
1807 * proc_dointvec - read a vector of integers
1808 * @table: the sysctl table
1809 * @write: %TRUE if this is a write to the sysctl file
1810 * @filp: the file structure
1811 * @buffer: the user buffer
1812 * @lenp: the size of the user buffer
1813 * @ppos: file position
1814 *
1815 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1816 * values from/to the user buffer, treated as an ASCII string.
1817 *
1818 * Returns 0 on success.
1819 */
1820int proc_dointvec(ctl_table *table, int write, struct file *filp,
1821 void __user *buffer, size_t *lenp, loff_t *ppos)
1822{
1823 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1824 NULL,NULL);
1825}
1826
1827#define OP_SET 0
1828#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001829#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
1831static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1832 int *valp,
1833 int write, void *data)
1834{
1835 int op = *(int *)data;
1836 if (write) {
1837 int val = *negp ? -*lvalp : *lvalp;
1838 switch(op) {
1839 case OP_SET: *valp = val; break;
1840 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001841 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 }
1843 } else {
1844 int val = *valp;
1845 if (val < 0) {
1846 *negp = -1;
1847 *lvalp = (unsigned long)-val;
1848 } else {
1849 *negp = 0;
1850 *lvalp = (unsigned long)val;
1851 }
1852 }
1853 return 0;
1854}
1855
1856/*
1857 * init may raise the set.
1858 */
1859
1860int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1861 void __user *buffer, size_t *lenp, loff_t *ppos)
1862{
1863 int op;
1864
Eric Paris6ff1b442007-02-10 01:43:19 -08001865 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 return -EPERM;
1867 }
1868
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001869 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1871 do_proc_dointvec_bset_conv,&op);
1872}
1873
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001874/*
1875 * Taint values can only be increased
1876 */
1877static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1878 void __user *buffer, size_t *lenp, loff_t *ppos)
1879{
1880 int op;
1881
Bastian Blank91fcd412007-04-23 14:41:14 -07001882 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001883 return -EPERM;
1884
1885 op = OP_OR;
1886 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1887 do_proc_dointvec_bset_conv,&op);
1888}
1889
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890struct do_proc_dointvec_minmax_conv_param {
1891 int *min;
1892 int *max;
1893};
1894
1895static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1896 int *valp,
1897 int write, void *data)
1898{
1899 struct do_proc_dointvec_minmax_conv_param *param = data;
1900 if (write) {
1901 int val = *negp ? -*lvalp : *lvalp;
1902 if ((param->min && *param->min > val) ||
1903 (param->max && *param->max < val))
1904 return -EINVAL;
1905 *valp = val;
1906 } else {
1907 int val = *valp;
1908 if (val < 0) {
1909 *negp = -1;
1910 *lvalp = (unsigned long)-val;
1911 } else {
1912 *negp = 0;
1913 *lvalp = (unsigned long)val;
1914 }
1915 }
1916 return 0;
1917}
1918
1919/**
1920 * proc_dointvec_minmax - read a vector of integers with min/max values
1921 * @table: the sysctl table
1922 * @write: %TRUE if this is a write to the sysctl file
1923 * @filp: the file structure
1924 * @buffer: the user buffer
1925 * @lenp: the size of the user buffer
1926 * @ppos: file position
1927 *
1928 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1929 * values from/to the user buffer, treated as an ASCII string.
1930 *
1931 * This routine will ensure the values are within the range specified by
1932 * table->extra1 (min) and table->extra2 (max).
1933 *
1934 * Returns 0 on success.
1935 */
1936int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1937 void __user *buffer, size_t *lenp, loff_t *ppos)
1938{
1939 struct do_proc_dointvec_minmax_conv_param param = {
1940 .min = (int *) table->extra1,
1941 .max = (int *) table->extra2,
1942 };
1943 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1944 do_proc_dointvec_minmax_conv, &param);
1945}
1946
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001947static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 struct file *filp,
1949 void __user *buffer,
1950 size_t *lenp, loff_t *ppos,
1951 unsigned long convmul,
1952 unsigned long convdiv)
1953{
1954#define TMPBUFLEN 21
1955 unsigned long *i, *min, *max, val;
1956 int vleft, first=1, neg;
1957 size_t len, left;
1958 char buf[TMPBUFLEN], *p;
1959 char __user *s = buffer;
1960
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001961 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 (*ppos && !write)) {
1963 *lenp = 0;
1964 return 0;
1965 }
1966
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001967 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 min = (unsigned long *) table->extra1;
1969 max = (unsigned long *) table->extra2;
1970 vleft = table->maxlen / sizeof(unsigned long);
1971 left = *lenp;
1972
1973 for (; left && vleft--; i++, min++, max++, first=0) {
1974 if (write) {
1975 while (left) {
1976 char c;
1977 if (get_user(c, s))
1978 return -EFAULT;
1979 if (!isspace(c))
1980 break;
1981 left--;
1982 s++;
1983 }
1984 if (!left)
1985 break;
1986 neg = 0;
1987 len = left;
1988 if (len > TMPBUFLEN-1)
1989 len = TMPBUFLEN-1;
1990 if (copy_from_user(buf, s, len))
1991 return -EFAULT;
1992 buf[len] = 0;
1993 p = buf;
1994 if (*p == '-' && left > 1) {
1995 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001996 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 }
1998 if (*p < '0' || *p > '9')
1999 break;
2000 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2001 len = p-buf;
2002 if ((len < left) && *p && !isspace(*p))
2003 break;
2004 if (neg)
2005 val = -val;
2006 s += len;
2007 left -= len;
2008
2009 if(neg)
2010 continue;
2011 if ((min && val < *min) || (max && val > *max))
2012 continue;
2013 *i = val;
2014 } else {
2015 p = buf;
2016 if (!first)
2017 *p++ = '\t';
2018 sprintf(p, "%lu", convdiv * (*i) / convmul);
2019 len = strlen(buf);
2020 if (len > left)
2021 len = left;
2022 if(copy_to_user(s, buf, len))
2023 return -EFAULT;
2024 left -= len;
2025 s += len;
2026 }
2027 }
2028
2029 if (!write && !first && left) {
2030 if(put_user('\n', s))
2031 return -EFAULT;
2032 left--, s++;
2033 }
2034 if (write) {
2035 while (left) {
2036 char c;
2037 if (get_user(c, s++))
2038 return -EFAULT;
2039 if (!isspace(c))
2040 break;
2041 left--;
2042 }
2043 }
2044 if (write && first)
2045 return -EINVAL;
2046 *lenp -= left;
2047 *ppos += *lenp;
2048 return 0;
2049#undef TMPBUFLEN
2050}
2051
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002052static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2053 struct file *filp,
2054 void __user *buffer,
2055 size_t *lenp, loff_t *ppos,
2056 unsigned long convmul,
2057 unsigned long convdiv)
2058{
2059 return __do_proc_doulongvec_minmax(table->data, table, write,
2060 filp, buffer, lenp, ppos, convmul, convdiv);
2061}
2062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063/**
2064 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2065 * @table: the sysctl table
2066 * @write: %TRUE if this is a write to the sysctl file
2067 * @filp: the file structure
2068 * @buffer: the user buffer
2069 * @lenp: the size of the user buffer
2070 * @ppos: file position
2071 *
2072 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2073 * values from/to the user buffer, treated as an ASCII string.
2074 *
2075 * This routine will ensure the values are within the range specified by
2076 * table->extra1 (min) and table->extra2 (max).
2077 *
2078 * Returns 0 on success.
2079 */
2080int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2081 void __user *buffer, size_t *lenp, loff_t *ppos)
2082{
2083 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2084}
2085
2086/**
2087 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2088 * @table: the sysctl table
2089 * @write: %TRUE if this is a write to the sysctl file
2090 * @filp: the file structure
2091 * @buffer: the user buffer
2092 * @lenp: the size of the user buffer
2093 * @ppos: file position
2094 *
2095 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2096 * values from/to the user buffer, treated as an ASCII string. The values
2097 * are treated as milliseconds, and converted to jiffies when they are stored.
2098 *
2099 * This routine will ensure the values are within the range specified by
2100 * table->extra1 (min) and table->extra2 (max).
2101 *
2102 * Returns 0 on success.
2103 */
2104int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2105 struct file *filp,
2106 void __user *buffer,
2107 size_t *lenp, loff_t *ppos)
2108{
2109 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2110 lenp, ppos, HZ, 1000l);
2111}
2112
2113
2114static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2115 int *valp,
2116 int write, void *data)
2117{
2118 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002119 if (*lvalp > LONG_MAX / HZ)
2120 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2122 } else {
2123 int val = *valp;
2124 unsigned long lval;
2125 if (val < 0) {
2126 *negp = -1;
2127 lval = (unsigned long)-val;
2128 } else {
2129 *negp = 0;
2130 lval = (unsigned long)val;
2131 }
2132 *lvalp = lval / HZ;
2133 }
2134 return 0;
2135}
2136
2137static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2138 int *valp,
2139 int write, void *data)
2140{
2141 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002142 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2143 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2145 } else {
2146 int val = *valp;
2147 unsigned long lval;
2148 if (val < 0) {
2149 *negp = -1;
2150 lval = (unsigned long)-val;
2151 } else {
2152 *negp = 0;
2153 lval = (unsigned long)val;
2154 }
2155 *lvalp = jiffies_to_clock_t(lval);
2156 }
2157 return 0;
2158}
2159
2160static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2161 int *valp,
2162 int write, void *data)
2163{
2164 if (write) {
2165 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
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 = jiffies_to_msecs(lval);
2177 }
2178 return 0;
2179}
2180
2181/**
2182 * proc_dointvec_jiffies - read a vector of integers as seconds
2183 * @table: the sysctl table
2184 * @write: %TRUE if this is a write to the sysctl file
2185 * @filp: the file structure
2186 * @buffer: the user buffer
2187 * @lenp: the size of the user buffer
2188 * @ppos: file position
2189 *
2190 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2191 * values from/to the user buffer, treated as an ASCII string.
2192 * The values read are assumed to be in seconds, and are converted into
2193 * jiffies.
2194 *
2195 * Returns 0 on success.
2196 */
2197int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2198 void __user *buffer, size_t *lenp, loff_t *ppos)
2199{
2200 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2201 do_proc_dointvec_jiffies_conv,NULL);
2202}
2203
2204/**
2205 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2206 * @table: the sysctl table
2207 * @write: %TRUE if this is a write to the sysctl file
2208 * @filp: the file structure
2209 * @buffer: the user buffer
2210 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002211 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 *
2213 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2214 * values from/to the user buffer, treated as an ASCII string.
2215 * The values read are assumed to be in 1/USER_HZ seconds, and
2216 * are converted into jiffies.
2217 *
2218 * Returns 0 on success.
2219 */
2220int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2221 void __user *buffer, size_t *lenp, loff_t *ppos)
2222{
2223 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2224 do_proc_dointvec_userhz_jiffies_conv,NULL);
2225}
2226
2227/**
2228 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @filp: the file structure
2232 * @buffer: the user buffer
2233 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002234 * @ppos: file position
2235 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 *
2237 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2238 * values from/to the user buffer, treated as an ASCII string.
2239 * The values read are assumed to be in 1/1000 seconds, and
2240 * are converted into jiffies.
2241 *
2242 * Returns 0 on success.
2243 */
2244int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2245 void __user *buffer, size_t *lenp, loff_t *ppos)
2246{
2247 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2248 do_proc_dointvec_ms_jiffies_conv, NULL);
2249}
2250
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002251static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2252 void __user *buffer, size_t *lenp, loff_t *ppos)
2253{
2254 struct pid *new_pid;
2255 pid_t tmp;
2256 int r;
2257
2258 tmp = pid_nr(cad_pid);
2259
2260 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2261 lenp, ppos, NULL, NULL);
2262 if (r || !write)
2263 return r;
2264
2265 new_pid = find_get_pid(tmp);
2266 if (!new_pid)
2267 return -ESRCH;
2268
2269 put_pid(xchg(&cad_pid, new_pid));
2270 return 0;
2271}
2272
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273#else /* CONFIG_PROC_FS */
2274
2275int proc_dostring(ctl_table *table, int write, struct file *filp,
2276 void __user *buffer, size_t *lenp, loff_t *ppos)
2277{
2278 return -ENOSYS;
2279}
2280
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281int proc_dointvec(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2283{
2284 return -ENOSYS;
2285}
2286
2287int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2288 void __user *buffer, size_t *lenp, loff_t *ppos)
2289{
2290 return -ENOSYS;
2291}
2292
2293int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2295{
2296 return -ENOSYS;
2297}
2298
2299int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2300 void __user *buffer, size_t *lenp, loff_t *ppos)
2301{
2302 return -ENOSYS;
2303}
2304
2305int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2306 void __user *buffer, size_t *lenp, loff_t *ppos)
2307{
2308 return -ENOSYS;
2309}
2310
2311int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2312 void __user *buffer, size_t *lenp, loff_t *ppos)
2313{
2314 return -ENOSYS;
2315}
2316
2317int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2318 void __user *buffer, size_t *lenp, loff_t *ppos)
2319{
2320 return -ENOSYS;
2321}
2322
2323int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2324 struct file *filp,
2325 void __user *buffer,
2326 size_t *lenp, loff_t *ppos)
2327{
2328 return -ENOSYS;
2329}
2330
2331
2332#endif /* CONFIG_PROC_FS */
2333
2334
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002335#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336/*
2337 * General sysctl support routines
2338 */
2339
2340/* The generic string strategy routine: */
2341int sysctl_string(ctl_table *table, int __user *name, int nlen,
2342 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002343 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 if (!table->data || !table->maxlen)
2346 return -ENOTDIR;
2347
2348 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002349 size_t bufsize;
2350 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002352 if (bufsize) {
2353 size_t len = strlen(table->data), copied;
2354
2355 /* This shouldn't trigger for a well-formed sysctl */
2356 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002358
2359 /* Copy up to a max of bufsize-1 bytes of the string */
2360 copied = (len >= bufsize) ? bufsize - 1 : len;
2361
2362 if (copy_to_user(oldval, table->data, copied) ||
2363 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002365 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 return -EFAULT;
2367 }
2368 }
2369 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002370 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 if (len > table->maxlen)
2372 len = table->maxlen;
2373 if(copy_from_user(table->data, newval, len))
2374 return -EFAULT;
2375 if (len == table->maxlen)
2376 len--;
2377 ((char *) table->data)[len] = 0;
2378 }
Yi Yang82c9df82005-12-30 16:37:10 +08002379 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380}
2381
2382/*
2383 * This function makes sure that all of the integers in the vector
2384 * are between the minimum and maximum values given in the arrays
2385 * table->extra1 and table->extra2, respectively.
2386 */
2387int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2388 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002389 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390{
2391
2392 if (newval && newlen) {
2393 int __user *vec = (int __user *) newval;
2394 int *min = (int *) table->extra1;
2395 int *max = (int *) table->extra2;
2396 size_t length;
2397 int i;
2398
2399 if (newlen % sizeof(int) != 0)
2400 return -EINVAL;
2401
2402 if (!table->extra1 && !table->extra2)
2403 return 0;
2404
2405 if (newlen > table->maxlen)
2406 newlen = table->maxlen;
2407 length = newlen / sizeof(int);
2408
2409 for (i = 0; i < length; i++) {
2410 int value;
2411 if (get_user(value, vec + i))
2412 return -EFAULT;
2413 if (min && value < min[i])
2414 return -EINVAL;
2415 if (max && value > max[i])
2416 return -EINVAL;
2417 }
2418 }
2419 return 0;
2420}
2421
2422/* Strategy function to convert jiffies to seconds */
2423int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2424 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002425 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002427 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002429
2430 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002432 if (olen) {
2433 int val;
2434
2435 if (olen < sizeof(int))
2436 return -EINVAL;
2437
2438 val = *(int *)(table->data) / HZ;
2439 if (put_user(val, (int __user *)oldval))
2440 return -EFAULT;
2441 if (put_user(sizeof(int), oldlenp))
2442 return -EFAULT;
2443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 }
2445 if (newval && newlen) {
2446 int new;
2447 if (newlen != sizeof(int))
2448 return -EINVAL;
2449 if (get_user(new, (int __user *)newval))
2450 return -EFAULT;
2451 *(int *)(table->data) = new*HZ;
2452 }
2453 return 1;
2454}
2455
2456/* Strategy function to convert jiffies to seconds */
2457int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2458 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002459 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002461 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002463
2464 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002466 if (olen) {
2467 int val;
2468
2469 if (olen < sizeof(int))
2470 return -EINVAL;
2471
2472 val = jiffies_to_msecs(*(int *)(table->data));
2473 if (put_user(val, (int __user *)oldval))
2474 return -EFAULT;
2475 if (put_user(sizeof(int), oldlenp))
2476 return -EFAULT;
2477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 }
2479 if (newval && newlen) {
2480 int new;
2481 if (newlen != sizeof(int))
2482 return -EINVAL;
2483 if (get_user(new, (int __user *)newval))
2484 return -EFAULT;
2485 *(int *)(table->data) = msecs_to_jiffies(new);
2486 }
2487 return 1;
2488}
2489
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002490
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002491
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002492#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
2494
2495asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2496{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002497 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002498 struct __sysctl_args tmp;
2499 int name[CTL_MAXNAME];
2500 int i;
2501
2502 /* Read in the sysctl name for better debug message logging */
2503 if (copy_from_user(&tmp, args, sizeof(tmp)))
2504 return -EFAULT;
2505 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2506 return -ENOTDIR;
2507 for (i = 0; i < tmp.nlen; i++)
2508 if (get_user(name[i], tmp.name + i))
2509 return -EFAULT;
2510
2511 /* Ignore accesses to kernel.version */
2512 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2513 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002514
2515 if (msg_count < 5) {
2516 msg_count++;
2517 printk(KERN_INFO
2518 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002519 "system call with ", current->comm);
2520 for (i = 0; i < tmp.nlen; i++)
2521 printk("%d.", name[i]);
2522 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002523 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002524out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 return -ENOSYS;
2526}
2527
2528int sysctl_string(ctl_table *table, int __user *name, int nlen,
2529 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002530 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531{
2532 return -ENOSYS;
2533}
2534
2535int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2536 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002537 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538{
2539 return -ENOSYS;
2540}
2541
2542int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2543 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002544 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545{
2546 return -ENOSYS;
2547}
2548
2549int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2550 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002551 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
2553 return -ENOSYS;
2554}
2555
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002556#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557
2558/*
2559 * No sense putting this after each symbol definition, twice,
2560 * exception granted :-)
2561 */
2562EXPORT_SYMBOL(proc_dointvec);
2563EXPORT_SYMBOL(proc_dointvec_jiffies);
2564EXPORT_SYMBOL(proc_dointvec_minmax);
2565EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2566EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2567EXPORT_SYMBOL(proc_dostring);
2568EXPORT_SYMBOL(proc_doulongvec_minmax);
2569EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2570EXPORT_SYMBOL(register_sysctl_table);
2571EXPORT_SYMBOL(sysctl_intvec);
2572EXPORT_SYMBOL(sysctl_jiffies);
2573EXPORT_SYMBOL(sysctl_ms_jiffies);
2574EXPORT_SYMBOL(sysctl_string);
2575EXPORT_SYMBOL(unregister_sysctl_table);