blob: c7314f95264763d10d5b0417aa29cf41ed26fd36 [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,
Ingo Molnar172ac3d2007-08-25 18:41:53 +0200225 .procname = "sched_min_granularity_ns",
226 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200227 .maxlen = sizeof(unsigned int),
228 .mode = 0644,
229 .proc_handler = &proc_dointvec_minmax,
230 .strategy = &sysctl_intvec,
231 .extra1 = &min_sched_granularity_ns,
232 .extra2 = &max_sched_granularity_ns,
233 },
234 {
235 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200236 .procname = "sched_latency_ns",
237 .data = &sysctl_sched_latency,
238 .maxlen = sizeof(unsigned int),
239 .mode = 0644,
240 .proc_handler = &proc_dointvec_minmax,
241 .strategy = &sysctl_intvec,
242 .extra1 = &min_sched_granularity_ns,
243 .extra2 = &max_sched_granularity_ns,
244 },
245 {
246 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200247 .procname = "sched_wakeup_granularity_ns",
248 .data = &sysctl_sched_wakeup_granularity,
249 .maxlen = sizeof(unsigned int),
250 .mode = 0644,
251 .proc_handler = &proc_dointvec_minmax,
252 .strategy = &sysctl_intvec,
253 .extra1 = &min_wakeup_granularity_ns,
254 .extra2 = &max_wakeup_granularity_ns,
255 },
256 {
257 .ctl_name = CTL_UNNUMBERED,
258 .procname = "sched_batch_wakeup_granularity_ns",
259 .data = &sysctl_sched_batch_wakeup_granularity,
260 .maxlen = sizeof(unsigned int),
261 .mode = 0644,
262 .proc_handler = &proc_dointvec_minmax,
263 .strategy = &sysctl_intvec,
264 .extra1 = &min_wakeup_granularity_ns,
265 .extra2 = &max_wakeup_granularity_ns,
266 },
267 {
268 .ctl_name = CTL_UNNUMBERED,
269 .procname = "sched_stat_granularity_ns",
270 .data = &sysctl_sched_stat_granularity,
271 .maxlen = sizeof(unsigned int),
272 .mode = 0644,
273 .proc_handler = &proc_dointvec_minmax,
274 .strategy = &sysctl_intvec,
275 .extra1 = &min_wakeup_granularity_ns,
276 .extra2 = &max_wakeup_granularity_ns,
277 },
278 {
279 .ctl_name = CTL_UNNUMBERED,
280 .procname = "sched_runtime_limit_ns",
281 .data = &sysctl_sched_runtime_limit,
282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
284 .proc_handler = &proc_dointvec_minmax,
285 .strategy = &sysctl_intvec,
286 .extra1 = &min_sched_granularity_ns,
287 .extra2 = &max_sched_granularity_ns,
288 },
289 {
290 .ctl_name = CTL_UNNUMBERED,
291 .procname = "sched_child_runs_first",
292 .data = &sysctl_sched_child_runs_first,
293 .maxlen = sizeof(unsigned int),
294 .mode = 0644,
295 .proc_handler = &proc_dointvec,
296 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200297 {
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_features",
300 .data = &sysctl_sched_features,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
303 .proc_handler = &proc_dointvec,
304 },
305#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200306 {
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_compat_yield",
309 .data = &sysctl_sched_compat_yield,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
313 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700314#ifdef CONFIG_PROVE_LOCKING
315 {
316 .ctl_name = CTL_UNNUMBERED,
317 .procname = "prove_locking",
318 .data = &prove_locking,
319 .maxlen = sizeof(int),
320 .mode = 0644,
321 .proc_handler = &proc_dointvec,
322 },
323#endif
324#ifdef CONFIG_LOCK_STAT
325 {
326 .ctl_name = CTL_UNNUMBERED,
327 .procname = "lock_stat",
328 .data = &lock_stat,
329 .maxlen = sizeof(int),
330 .mode = 0644,
331 .proc_handler = &proc_dointvec,
332 },
333#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200334 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 .ctl_name = KERN_PANIC,
336 .procname = "panic",
337 .data = &panic_timeout,
338 .maxlen = sizeof(int),
339 .mode = 0644,
340 .proc_handler = &proc_dointvec,
341 },
342 {
343 .ctl_name = KERN_CORE_USES_PID,
344 .procname = "core_uses_pid",
345 .data = &core_uses_pid,
346 .maxlen = sizeof(int),
347 .mode = 0644,
348 .proc_handler = &proc_dointvec,
349 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700350#ifdef CONFIG_AUDITSYSCALL
351 {
352 .ctl_name = CTL_UNNUMBERED,
353 .procname = "audit_argv_kb",
354 .data = &audit_argv_kb,
355 .maxlen = sizeof(int),
356 .mode = 0644,
357 .proc_handler = &proc_dointvec,
358 },
359#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 {
361 .ctl_name = KERN_CORE_PATTERN,
362 .procname = "core_pattern",
363 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700364 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 .mode = 0644,
366 .proc_handler = &proc_dostring,
367 .strategy = &sysctl_string,
368 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800369#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 {
371 .ctl_name = KERN_TAINTED,
372 .procname = "tainted",
373 .data = &tainted,
374 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800375 .mode = 0644,
376 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800378#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 {
380 .ctl_name = KERN_CAP_BSET,
381 .procname = "cap-bound",
382 .data = &cap_bset,
383 .maxlen = sizeof(kernel_cap_t),
384 .mode = 0600,
385 .proc_handler = &proc_dointvec_bset,
386 },
387#ifdef CONFIG_BLK_DEV_INITRD
388 {
389 .ctl_name = KERN_REALROOTDEV,
390 .procname = "real-root-dev",
391 .data = &real_root_dev,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = &proc_dointvec,
395 },
396#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700397 {
398 .ctl_name = CTL_UNNUMBERED,
399 .procname = "print-fatal-signals",
400 .data = &print_fatal_signals,
401 .maxlen = sizeof(int),
402 .mode = 0644,
403 .proc_handler = &proc_dointvec,
404 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405#ifdef __sparc__
406 {
407 .ctl_name = KERN_SPARC_REBOOT,
408 .procname = "reboot-cmd",
409 .data = reboot_command,
410 .maxlen = 256,
411 .mode = 0644,
412 .proc_handler = &proc_dostring,
413 .strategy = &sysctl_string,
414 },
415 {
416 .ctl_name = KERN_SPARC_STOP_A,
417 .procname = "stop-a",
418 .data = &stop_a_enabled,
419 .maxlen = sizeof (int),
420 .mode = 0644,
421 .proc_handler = &proc_dointvec,
422 },
423 {
424 .ctl_name = KERN_SPARC_SCONS_PWROFF,
425 .procname = "scons-poweroff",
426 .data = &scons_pwroff,
427 .maxlen = sizeof (int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
431#endif
432#ifdef __hppa__
433 {
434 .ctl_name = KERN_HPPA_PWRSW,
435 .procname = "soft-power",
436 .data = &pwrsw_enabled,
437 .maxlen = sizeof (int),
438 .mode = 0644,
439 .proc_handler = &proc_dointvec,
440 },
441 {
442 .ctl_name = KERN_HPPA_UNALIGNED,
443 .procname = "unaligned-trap",
444 .data = &unaligned_enabled,
445 .maxlen = sizeof (int),
446 .mode = 0644,
447 .proc_handler = &proc_dointvec,
448 },
449#endif
450 {
451 .ctl_name = KERN_CTLALTDEL,
452 .procname = "ctrl-alt-del",
453 .data = &C_A_D,
454 .maxlen = sizeof(int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458 {
459 .ctl_name = KERN_PRINTK,
460 .procname = "printk",
461 .data = &console_loglevel,
462 .maxlen = 4*sizeof(int),
463 .mode = 0644,
464 .proc_handler = &proc_dointvec,
465 },
466#ifdef CONFIG_KMOD
467 {
468 .ctl_name = KERN_MODPROBE,
469 .procname = "modprobe",
470 .data = &modprobe_path,
471 .maxlen = KMOD_PATH_LEN,
472 .mode = 0644,
473 .proc_handler = &proc_dostring,
474 .strategy = &sysctl_string,
475 },
476#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700477#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 {
479 .ctl_name = KERN_HOTPLUG,
480 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100481 .data = &uevent_helper,
482 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .mode = 0644,
484 .proc_handler = &proc_dostring,
485 .strategy = &sysctl_string,
486 },
487#endif
488#ifdef CONFIG_CHR_DEV_SG
489 {
490 .ctl_name = KERN_SG_BIG_BUFF,
491 .procname = "sg-big-buff",
492 .data = &sg_big_buff,
493 .maxlen = sizeof (int),
494 .mode = 0444,
495 .proc_handler = &proc_dointvec,
496 },
497#endif
498#ifdef CONFIG_BSD_PROCESS_ACCT
499 {
500 .ctl_name = KERN_ACCT,
501 .procname = "acct",
502 .data = &acct_parm,
503 .maxlen = 3*sizeof(int),
504 .mode = 0644,
505 .proc_handler = &proc_dointvec,
506 },
507#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508#ifdef CONFIG_MAGIC_SYSRQ
509 {
510 .ctl_name = KERN_SYSRQ,
511 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800512 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 .maxlen = sizeof (int),
514 .mode = 0644,
515 .proc_handler = &proc_dointvec,
516 },
517#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700518#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 {
520 .ctl_name = KERN_CADPID,
521 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700522 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 .maxlen = sizeof (int),
524 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700525 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700527#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 {
529 .ctl_name = KERN_MAX_THREADS,
530 .procname = "threads-max",
531 .data = &max_threads,
532 .maxlen = sizeof(int),
533 .mode = 0644,
534 .proc_handler = &proc_dointvec,
535 },
536 {
537 .ctl_name = KERN_RANDOM,
538 .procname = "random",
539 .mode = 0555,
540 .child = random_table,
541 },
542#ifdef CONFIG_UNIX98_PTYS
543 {
544 .ctl_name = KERN_PTY,
545 .procname = "pty",
546 .mode = 0555,
547 .child = pty_table,
548 },
549#endif
550 {
551 .ctl_name = KERN_OVERFLOWUID,
552 .procname = "overflowuid",
553 .data = &overflowuid,
554 .maxlen = sizeof(int),
555 .mode = 0644,
556 .proc_handler = &proc_dointvec_minmax,
557 .strategy = &sysctl_intvec,
558 .extra1 = &minolduid,
559 .extra2 = &maxolduid,
560 },
561 {
562 .ctl_name = KERN_OVERFLOWGID,
563 .procname = "overflowgid",
564 .data = &overflowgid,
565 .maxlen = sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec_minmax,
568 .strategy = &sysctl_intvec,
569 .extra1 = &minolduid,
570 .extra2 = &maxolduid,
571 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800572#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#ifdef CONFIG_MATHEMU
574 {
575 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
576 .procname = "ieee_emulation_warnings",
577 .data = &sysctl_ieee_emulation_warnings,
578 .maxlen = sizeof(int),
579 .mode = 0644,
580 .proc_handler = &proc_dointvec,
581 },
582#endif
583#ifdef CONFIG_NO_IDLE_HZ
584 {
585 .ctl_name = KERN_HZ_TIMER,
586 .procname = "hz_timer",
587 .data = &sysctl_hz_timer,
588 .maxlen = sizeof(int),
589 .mode = 0644,
590 .proc_handler = &proc_dointvec,
591 },
592#endif
593 {
594 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
595 .procname = "userprocess_debug",
596 .data = &sysctl_userprocess_debug,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = &proc_dointvec,
600 },
601#endif
602 {
603 .ctl_name = KERN_PIDMAX,
604 .procname = "pid_max",
605 .data = &pid_max,
606 .maxlen = sizeof (int),
607 .mode = 0644,
608 .proc_handler = &proc_dointvec_minmax,
609 .strategy = sysctl_intvec,
610 .extra1 = &pid_max_min,
611 .extra2 = &pid_max_max,
612 },
613 {
614 .ctl_name = KERN_PANIC_ON_OOPS,
615 .procname = "panic_on_oops",
616 .data = &panic_on_oops,
617 .maxlen = sizeof(int),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec,
620 },
621 {
622 .ctl_name = KERN_PRINTK_RATELIMIT,
623 .procname = "printk_ratelimit",
624 .data = &printk_ratelimit_jiffies,
625 .maxlen = sizeof(int),
626 .mode = 0644,
627 .proc_handler = &proc_dointvec_jiffies,
628 .strategy = &sysctl_jiffies,
629 },
630 {
631 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
632 .procname = "printk_ratelimit_burst",
633 .data = &printk_ratelimit_burst,
634 .maxlen = sizeof(int),
635 .mode = 0644,
636 .proc_handler = &proc_dointvec,
637 },
638 {
639 .ctl_name = KERN_NGROUPS_MAX,
640 .procname = "ngroups_max",
641 .data = &ngroups_max,
642 .maxlen = sizeof (int),
643 .mode = 0444,
644 .proc_handler = &proc_dointvec,
645 },
646#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
647 {
648 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
649 .procname = "unknown_nmi_panic",
650 .data = &unknown_nmi_panic,
651 .maxlen = sizeof (int),
652 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200653 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 },
Don Zickus407984f2006-09-26 10:52:27 +0200655 {
656 .ctl_name = KERN_NMI_WATCHDOG,
657 .procname = "nmi_watchdog",
658 .data = &nmi_watchdog_enabled,
659 .maxlen = sizeof (int),
660 .mode = 0644,
661 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 },
663#endif
664#if defined(CONFIG_X86)
665 {
Don Zickus8da5add2006-09-26 10:52:27 +0200666 .ctl_name = KERN_PANIC_ON_NMI,
667 .procname = "panic_on_unrecovered_nmi",
668 .data = &panic_on_unrecovered_nmi,
669 .maxlen = sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
672 },
673 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 .ctl_name = KERN_BOOTLOADER_TYPE,
675 .procname = "bootloader_type",
676 .data = &bootloader_type,
677 .maxlen = sizeof (int),
678 .mode = 0444,
679 .proc_handler = &proc_dointvec,
680 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100681 {
682 .ctl_name = CTL_UNNUMBERED,
683 .procname = "kstack_depth_to_print",
684 .data = &kstack_depth_to_print,
685 .maxlen = sizeof(int),
686 .mode = 0644,
687 .proc_handler = &proc_dointvec,
688 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800690#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 {
692 .ctl_name = KERN_RANDOMIZE,
693 .procname = "randomize_va_space",
694 .data = &randomize_va_space,
695 .maxlen = sizeof(int),
696 .mode = 0644,
697 .proc_handler = &proc_dointvec,
698 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800699#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800700#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700701 {
702 .ctl_name = KERN_SPIN_RETRY,
703 .procname = "spin_retry",
704 .data = &spin_retry,
705 .maxlen = sizeof (int),
706 .mode = 0644,
707 .proc_handler = &proc_dointvec,
708 },
709#endif
Len Brown673d5b42007-07-28 03:33:16 -0400710#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800711 {
712 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
713 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700714 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800715 .maxlen = sizeof (unsigned long),
716 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800717 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800718 },
719#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800720#ifdef CONFIG_IA64
721 {
722 .ctl_name = KERN_IA64_UNALIGNED,
723 .procname = "ignore-unaligned-usertrap",
724 .data = &no_unaligned_warning,
725 .maxlen = sizeof (int),
726 .mode = 0644,
727 .proc_handler = &proc_dointvec,
728 },
729#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200730#ifdef CONFIG_COMPAT
731 {
732 .ctl_name = KERN_COMPAT_LOG,
733 .procname = "compat-log",
734 .data = &compat_log,
735 .maxlen = sizeof (int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
738 },
739#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700740#ifdef CONFIG_RT_MUTEXES
741 {
742 .ctl_name = KERN_MAX_LOCK_DEPTH,
743 .procname = "max_lock_depth",
744 .data = &max_lock_depth,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
748 },
749#endif
Kees Cook5096add2007-05-08 00:26:04 -0700750#ifdef CONFIG_PROC_FS
751 {
752 .ctl_name = CTL_UNNUMBERED,
753 .procname = "maps_protect",
754 .data = &maps_protect,
755 .maxlen = sizeof(int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
758 },
759#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700760 {
761 .ctl_name = CTL_UNNUMBERED,
762 .procname = "poweroff_cmd",
763 .data = &poweroff_cmd,
764 .maxlen = POWEROFF_CMD_PATH_LEN,
765 .mode = 0644,
766 .proc_handler = &proc_dostring,
767 .strategy = &sysctl_string,
768 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700769/*
770 * NOTE: do not add new entries to this table unless you have read
771 * Documentation/sysctl/ctl_unnumbered.txt
772 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 { .ctl_name = 0 }
774};
775
776/* Constants for minimum and maximum testing in vm_table.
777 We use these as one-element integer vectors. */
778static int zero;
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -0700779static int two = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780static int one_hundred = 100;
781
782
783static ctl_table vm_table[] = {
784 {
785 .ctl_name = VM_OVERCOMMIT_MEMORY,
786 .procname = "overcommit_memory",
787 .data = &sysctl_overcommit_memory,
788 .maxlen = sizeof(sysctl_overcommit_memory),
789 .mode = 0644,
790 .proc_handler = &proc_dointvec,
791 },
792 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700793 .ctl_name = VM_PANIC_ON_OOM,
794 .procname = "panic_on_oom",
795 .data = &sysctl_panic_on_oom,
796 .maxlen = sizeof(sysctl_panic_on_oom),
797 .mode = 0644,
798 .proc_handler = &proc_dointvec,
799 },
800 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 .ctl_name = VM_OVERCOMMIT_RATIO,
802 .procname = "overcommit_ratio",
803 .data = &sysctl_overcommit_ratio,
804 .maxlen = sizeof(sysctl_overcommit_ratio),
805 .mode = 0644,
806 .proc_handler = &proc_dointvec,
807 },
808 {
809 .ctl_name = VM_PAGE_CLUSTER,
810 .procname = "page-cluster",
811 .data = &page_cluster,
812 .maxlen = sizeof(int),
813 .mode = 0644,
814 .proc_handler = &proc_dointvec,
815 },
816 {
817 .ctl_name = VM_DIRTY_BACKGROUND,
818 .procname = "dirty_background_ratio",
819 .data = &dirty_background_ratio,
820 .maxlen = sizeof(dirty_background_ratio),
821 .mode = 0644,
822 .proc_handler = &proc_dointvec_minmax,
823 .strategy = &sysctl_intvec,
824 .extra1 = &zero,
825 .extra2 = &one_hundred,
826 },
827 {
828 .ctl_name = VM_DIRTY_RATIO,
829 .procname = "dirty_ratio",
830 .data = &vm_dirty_ratio,
831 .maxlen = sizeof(vm_dirty_ratio),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec_minmax,
834 .strategy = &sysctl_intvec,
835 .extra1 = &zero,
836 .extra2 = &one_hundred,
837 },
838 {
839 .ctl_name = VM_DIRTY_WB_CS,
840 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800841 .data = &dirty_writeback_interval,
842 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 .mode = 0644,
844 .proc_handler = &dirty_writeback_centisecs_handler,
845 },
846 {
847 .ctl_name = VM_DIRTY_EXPIRE_CS,
848 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800849 .data = &dirty_expire_interval,
850 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800852 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 },
854 {
855 .ctl_name = VM_NR_PDFLUSH_THREADS,
856 .procname = "nr_pdflush_threads",
857 .data = &nr_pdflush_threads,
858 .maxlen = sizeof nr_pdflush_threads,
859 .mode = 0444 /* read-only*/,
860 .proc_handler = &proc_dointvec,
861 },
862 {
863 .ctl_name = VM_SWAPPINESS,
864 .procname = "swappiness",
865 .data = &vm_swappiness,
866 .maxlen = sizeof(vm_swappiness),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec_minmax,
869 .strategy = &sysctl_intvec,
870 .extra1 = &zero,
871 .extra2 = &one_hundred,
872 },
873#ifdef CONFIG_HUGETLB_PAGE
874 {
875 .ctl_name = VM_HUGETLB_PAGES,
876 .procname = "nr_hugepages",
877 .data = &max_huge_pages,
878 .maxlen = sizeof(unsigned long),
879 .mode = 0644,
880 .proc_handler = &hugetlb_sysctl_handler,
881 .extra1 = (void *)&hugetlb_zero,
882 .extra2 = (void *)&hugetlb_infinity,
883 },
884 {
885 .ctl_name = VM_HUGETLB_GROUP,
886 .procname = "hugetlb_shm_group",
887 .data = &sysctl_hugetlb_shm_group,
888 .maxlen = sizeof(gid_t),
889 .mode = 0644,
890 .proc_handler = &proc_dointvec,
891 },
Mel Gorman396faf02007-07-17 04:03:13 -0700892 {
893 .ctl_name = CTL_UNNUMBERED,
894 .procname = "hugepages_treat_as_movable",
895 .data = &hugepages_treat_as_movable,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = &hugetlb_treat_movable_handler,
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
Paul Mundt5c36e652007-03-01 10:07:42 +09001056#if defined(CONFIG_X86_32) || \
1057 (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. Biederman1ff007e2007-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. Biederman1ff007e2007-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. Biederman1ff007e2007-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. Biederman1ff007e2007-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);