blob: 2aaa3f98185d12efe58a589f48017f83f488cb53 [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>
30#include <linux/capability.h>
31#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
40#include <linux/hugetlb.h>
41#include <linux/security.h>
42#include <linux/initrd.h>
43#include <linux/times.h>
44#include <linux/limits.h>
45#include <linux/dcache.h>
46#include <linux/syscalls.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51#include <asm/uaccess.h>
52#include <asm/processor.h>
53
Andi Kleen29cbc782006-09-30 01:47:55 +020054#ifdef CONFIG_X86
55#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010056#include <asm/stacktrace.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020057#endif
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#if defined(CONFIG_SYSCTL)
60
61/* External variables not in a header file. */
62extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070063extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064extern int sysctl_overcommit_memory;
65extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070066extern int sysctl_panic_on_oom;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070069extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int pid_max;
72extern int min_free_kbytes;
73extern int printk_ratelimit_jiffies;
74extern int printk_ratelimit_burst;
75extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080076extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080077extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020078extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070079extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070080extern int sysctl_stat_interval;
Peter Zijlstrabdf4c482007-07-19 01:48:15 -070081extern int audit_argv_kb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
84static int maxolduid = 65535;
85static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080086static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88static int ngroups_max = NGROUPS_MAX;
89
90#ifdef CONFIG_KMOD
91extern char modprobe_path[];
92#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#ifdef CONFIG_CHR_DEV_SG
94extern int sg_big_buff;
95#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97#ifdef __sparc__
98extern char reboot_command [];
99extern int stop_a_enabled;
100extern int scons_pwroff;
101#endif
102
103#ifdef __hppa__
104extern int pwrsw_enabled;
105extern int unaligned_enabled;
106#endif
107
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800108#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#ifdef CONFIG_MATHEMU
110extern int sysctl_ieee_emulation_warnings;
111#endif
112extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700113extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif
115
116extern int sysctl_hz_timer;
117
118#ifdef CONFIG_BSD_PROCESS_ACCT
119extern int acct_parm[];
120#endif
121
Jes Sorensend2b176e2006-02-28 09:42:23 -0800122#ifdef CONFIG_IA64
123extern int no_unaligned_warning;
124#endif
125
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700126#ifdef CONFIG_RT_MUTEXES
127extern int max_lock_depth;
128#endif
129
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700130#ifdef CONFIG_SYSCTL_SYSCALL
131static int parse_table(int __user *, int, void __user *, size_t __user *,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800132 void __user *, size_t, ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700133#endif
134
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800135
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700136#ifdef CONFIG_PROC_SYSCTL
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700137static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
138 void __user *buffer, size_t *lenp, loff_t *ppos);
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800139static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
140 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700141#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static ctl_table root_table[];
144static struct ctl_table_header root_table_header =
145 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
146
147static ctl_table kern_table[];
148static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static ctl_table fs_table[];
150static ctl_table debug_table[];
151static ctl_table dev_table[];
152extern ctl_table random_table[];
153#ifdef CONFIG_UNIX98_PTYS
154extern ctl_table pty_table[];
155#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700156#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400157extern ctl_table inotify_table[];
158#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
161int sysctl_legacy_va_layout;
162#endif
163
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165/* The default sysctl tables: */
166
167static ctl_table root_table[] = {
168 {
169 .ctl_name = CTL_KERN,
170 .procname = "kernel",
171 .mode = 0555,
172 .child = kern_table,
173 },
174 {
175 .ctl_name = CTL_VM,
176 .procname = "vm",
177 .mode = 0555,
178 .child = vm_table,
179 },
180#ifdef CONFIG_NET
181 {
182 .ctl_name = CTL_NET,
183 .procname = "net",
184 .mode = 0555,
185 .child = net_table,
186 },
187#endif
188 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 .ctl_name = CTL_FS,
190 .procname = "fs",
191 .mode = 0555,
192 .child = fs_table,
193 },
194 {
195 .ctl_name = CTL_DEBUG,
196 .procname = "debug",
197 .mode = 0555,
198 .child = debug_table,
199 },
200 {
201 .ctl_name = CTL_DEV,
202 .procname = "dev",
203 .mode = 0555,
204 .child = dev_table,
205 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700206/*
207 * NOTE: do not add new entries to this table unless you have read
208 * Documentation/sysctl/ctl_unnumbered.txt
209 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 { .ctl_name = 0 }
211};
212
Ingo Molnar77e54a12007-07-09 18:52:00 +0200213#ifdef CONFIG_SCHED_DEBUG
214static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
215static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
216static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
217static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
218#endif
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220static ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200221#ifdef CONFIG_SCHED_DEBUG
222 {
223 .ctl_name = CTL_UNNUMBERED,
224 .procname = "sched_granularity_ns",
225 .data = &sysctl_sched_granularity,
226 .maxlen = sizeof(unsigned int),
227 .mode = 0644,
228 .proc_handler = &proc_dointvec_minmax,
229 .strategy = &sysctl_intvec,
230 .extra1 = &min_sched_granularity_ns,
231 .extra2 = &max_sched_granularity_ns,
232 },
233 {
234 .ctl_name = CTL_UNNUMBERED,
235 .procname = "sched_wakeup_granularity_ns",
236 .data = &sysctl_sched_wakeup_granularity,
237 .maxlen = sizeof(unsigned int),
238 .mode = 0644,
239 .proc_handler = &proc_dointvec_minmax,
240 .strategy = &sysctl_intvec,
241 .extra1 = &min_wakeup_granularity_ns,
242 .extra2 = &max_wakeup_granularity_ns,
243 },
244 {
245 .ctl_name = CTL_UNNUMBERED,
246 .procname = "sched_batch_wakeup_granularity_ns",
247 .data = &sysctl_sched_batch_wakeup_granularity,
248 .maxlen = sizeof(unsigned int),
249 .mode = 0644,
250 .proc_handler = &proc_dointvec_minmax,
251 .strategy = &sysctl_intvec,
252 .extra1 = &min_wakeup_granularity_ns,
253 .extra2 = &max_wakeup_granularity_ns,
254 },
255 {
256 .ctl_name = CTL_UNNUMBERED,
257 .procname = "sched_stat_granularity_ns",
258 .data = &sysctl_sched_stat_granularity,
259 .maxlen = sizeof(unsigned int),
260 .mode = 0644,
261 .proc_handler = &proc_dointvec_minmax,
262 .strategy = &sysctl_intvec,
263 .extra1 = &min_wakeup_granularity_ns,
264 .extra2 = &max_wakeup_granularity_ns,
265 },
266 {
267 .ctl_name = CTL_UNNUMBERED,
268 .procname = "sched_runtime_limit_ns",
269 .data = &sysctl_sched_runtime_limit,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
272 .proc_handler = &proc_dointvec_minmax,
273 .strategy = &sysctl_intvec,
274 .extra1 = &min_sched_granularity_ns,
275 .extra2 = &max_sched_granularity_ns,
276 },
277 {
278 .ctl_name = CTL_UNNUMBERED,
279 .procname = "sched_child_runs_first",
280 .data = &sysctl_sched_child_runs_first,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec,
284 },
285 {
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_features",
288 .data = &sysctl_sched_features,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = &proc_dointvec,
292 },
293#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 .ctl_name = KERN_PANIC,
296 .procname = "panic",
297 .data = &panic_timeout,
298 .maxlen = sizeof(int),
299 .mode = 0644,
300 .proc_handler = &proc_dointvec,
301 },
302 {
303 .ctl_name = KERN_CORE_USES_PID,
304 .procname = "core_uses_pid",
305 .data = &core_uses_pid,
306 .maxlen = sizeof(int),
307 .mode = 0644,
308 .proc_handler = &proc_dointvec,
309 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700310#ifdef CONFIG_AUDITSYSCALL
311 {
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "audit_argv_kb",
314 .data = &audit_argv_kb,
315 .maxlen = sizeof(int),
316 .mode = 0644,
317 .proc_handler = &proc_dointvec,
318 },
319#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 {
321 .ctl_name = KERN_CORE_PATTERN,
322 .procname = "core_pattern",
323 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700324 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 .mode = 0644,
326 .proc_handler = &proc_dostring,
327 .strategy = &sysctl_string,
328 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800329#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 {
331 .ctl_name = KERN_TAINTED,
332 .procname = "tainted",
333 .data = &tainted,
334 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800335 .mode = 0644,
336 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800338#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 {
340 .ctl_name = KERN_CAP_BSET,
341 .procname = "cap-bound",
342 .data = &cap_bset,
343 .maxlen = sizeof(kernel_cap_t),
344 .mode = 0600,
345 .proc_handler = &proc_dointvec_bset,
346 },
347#ifdef CONFIG_BLK_DEV_INITRD
348 {
349 .ctl_name = KERN_REALROOTDEV,
350 .procname = "real-root-dev",
351 .data = &real_root_dev,
352 .maxlen = sizeof(int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
355 },
356#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700357 {
358 .ctl_name = CTL_UNNUMBERED,
359 .procname = "print-fatal-signals",
360 .data = &print_fatal_signals,
361 .maxlen = sizeof(int),
362 .mode = 0644,
363 .proc_handler = &proc_dointvec,
364 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#ifdef __sparc__
366 {
367 .ctl_name = KERN_SPARC_REBOOT,
368 .procname = "reboot-cmd",
369 .data = reboot_command,
370 .maxlen = 256,
371 .mode = 0644,
372 .proc_handler = &proc_dostring,
373 .strategy = &sysctl_string,
374 },
375 {
376 .ctl_name = KERN_SPARC_STOP_A,
377 .procname = "stop-a",
378 .data = &stop_a_enabled,
379 .maxlen = sizeof (int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383 {
384 .ctl_name = KERN_SPARC_SCONS_PWROFF,
385 .procname = "scons-poweroff",
386 .data = &scons_pwroff,
387 .maxlen = sizeof (int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
391#endif
392#ifdef __hppa__
393 {
394 .ctl_name = KERN_HPPA_PWRSW,
395 .procname = "soft-power",
396 .data = &pwrsw_enabled,
397 .maxlen = sizeof (int),
398 .mode = 0644,
399 .proc_handler = &proc_dointvec,
400 },
401 {
402 .ctl_name = KERN_HPPA_UNALIGNED,
403 .procname = "unaligned-trap",
404 .data = &unaligned_enabled,
405 .maxlen = sizeof (int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec,
408 },
409#endif
410 {
411 .ctl_name = KERN_CTLALTDEL,
412 .procname = "ctrl-alt-del",
413 .data = &C_A_D,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
417 },
418 {
419 .ctl_name = KERN_PRINTK,
420 .procname = "printk",
421 .data = &console_loglevel,
422 .maxlen = 4*sizeof(int),
423 .mode = 0644,
424 .proc_handler = &proc_dointvec,
425 },
426#ifdef CONFIG_KMOD
427 {
428 .ctl_name = KERN_MODPROBE,
429 .procname = "modprobe",
430 .data = &modprobe_path,
431 .maxlen = KMOD_PATH_LEN,
432 .mode = 0644,
433 .proc_handler = &proc_dostring,
434 .strategy = &sysctl_string,
435 },
436#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700437#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 {
439 .ctl_name = KERN_HOTPLUG,
440 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100441 .data = &uevent_helper,
442 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 .mode = 0644,
444 .proc_handler = &proc_dostring,
445 .strategy = &sysctl_string,
446 },
447#endif
448#ifdef CONFIG_CHR_DEV_SG
449 {
450 .ctl_name = KERN_SG_BIG_BUFF,
451 .procname = "sg-big-buff",
452 .data = &sg_big_buff,
453 .maxlen = sizeof (int),
454 .mode = 0444,
455 .proc_handler = &proc_dointvec,
456 },
457#endif
458#ifdef CONFIG_BSD_PROCESS_ACCT
459 {
460 .ctl_name = KERN_ACCT,
461 .procname = "acct",
462 .data = &acct_parm,
463 .maxlen = 3*sizeof(int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
466 },
467#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#ifdef CONFIG_MAGIC_SYSRQ
469 {
470 .ctl_name = KERN_SYSRQ,
471 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800472 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .maxlen = sizeof (int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec,
476 },
477#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700478#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 {
480 .ctl_name = KERN_CADPID,
481 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700482 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .maxlen = sizeof (int),
484 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700485 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700487#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 {
489 .ctl_name = KERN_MAX_THREADS,
490 .procname = "threads-max",
491 .data = &max_threads,
492 .maxlen = sizeof(int),
493 .mode = 0644,
494 .proc_handler = &proc_dointvec,
495 },
496 {
497 .ctl_name = KERN_RANDOM,
498 .procname = "random",
499 .mode = 0555,
500 .child = random_table,
501 },
502#ifdef CONFIG_UNIX98_PTYS
503 {
504 .ctl_name = KERN_PTY,
505 .procname = "pty",
506 .mode = 0555,
507 .child = pty_table,
508 },
509#endif
510 {
511 .ctl_name = KERN_OVERFLOWUID,
512 .procname = "overflowuid",
513 .data = &overflowuid,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = &proc_dointvec_minmax,
517 .strategy = &sysctl_intvec,
518 .extra1 = &minolduid,
519 .extra2 = &maxolduid,
520 },
521 {
522 .ctl_name = KERN_OVERFLOWGID,
523 .procname = "overflowgid",
524 .data = &overflowgid,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = &proc_dointvec_minmax,
528 .strategy = &sysctl_intvec,
529 .extra1 = &minolduid,
530 .extra2 = &maxolduid,
531 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800532#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#ifdef CONFIG_MATHEMU
534 {
535 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
536 .procname = "ieee_emulation_warnings",
537 .data = &sysctl_ieee_emulation_warnings,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec,
541 },
542#endif
543#ifdef CONFIG_NO_IDLE_HZ
544 {
545 .ctl_name = KERN_HZ_TIMER,
546 .procname = "hz_timer",
547 .data = &sysctl_hz_timer,
548 .maxlen = sizeof(int),
549 .mode = 0644,
550 .proc_handler = &proc_dointvec,
551 },
552#endif
553 {
554 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
555 .procname = "userprocess_debug",
556 .data = &sysctl_userprocess_debug,
557 .maxlen = sizeof(int),
558 .mode = 0644,
559 .proc_handler = &proc_dointvec,
560 },
561#endif
562 {
563 .ctl_name = KERN_PIDMAX,
564 .procname = "pid_max",
565 .data = &pid_max,
566 .maxlen = sizeof (int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec_minmax,
569 .strategy = sysctl_intvec,
570 .extra1 = &pid_max_min,
571 .extra2 = &pid_max_max,
572 },
573 {
574 .ctl_name = KERN_PANIC_ON_OOPS,
575 .procname = "panic_on_oops",
576 .data = &panic_on_oops,
577 .maxlen = sizeof(int),
578 .mode = 0644,
579 .proc_handler = &proc_dointvec,
580 },
581 {
582 .ctl_name = KERN_PRINTK_RATELIMIT,
583 .procname = "printk_ratelimit",
584 .data = &printk_ratelimit_jiffies,
585 .maxlen = sizeof(int),
586 .mode = 0644,
587 .proc_handler = &proc_dointvec_jiffies,
588 .strategy = &sysctl_jiffies,
589 },
590 {
591 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
592 .procname = "printk_ratelimit_burst",
593 .data = &printk_ratelimit_burst,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec,
597 },
598 {
599 .ctl_name = KERN_NGROUPS_MAX,
600 .procname = "ngroups_max",
601 .data = &ngroups_max,
602 .maxlen = sizeof (int),
603 .mode = 0444,
604 .proc_handler = &proc_dointvec,
605 },
606#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
607 {
608 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
609 .procname = "unknown_nmi_panic",
610 .data = &unknown_nmi_panic,
611 .maxlen = sizeof (int),
612 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200613 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 },
Don Zickus407984f2006-09-26 10:52:27 +0200615 {
616 .ctl_name = KERN_NMI_WATCHDOG,
617 .procname = "nmi_watchdog",
618 .data = &nmi_watchdog_enabled,
619 .maxlen = sizeof (int),
620 .mode = 0644,
621 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 },
623#endif
624#if defined(CONFIG_X86)
625 {
Don Zickus8da5add2006-09-26 10:52:27 +0200626 .ctl_name = KERN_PANIC_ON_NMI,
627 .procname = "panic_on_unrecovered_nmi",
628 .data = &panic_on_unrecovered_nmi,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = &proc_dointvec,
632 },
633 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 .ctl_name = KERN_BOOTLOADER_TYPE,
635 .procname = "bootloader_type",
636 .data = &bootloader_type,
637 .maxlen = sizeof (int),
638 .mode = 0444,
639 .proc_handler = &proc_dointvec,
640 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100641 {
642 .ctl_name = CTL_UNNUMBERED,
643 .procname = "kstack_depth_to_print",
644 .data = &kstack_depth_to_print,
645 .maxlen = sizeof(int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
648 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800650#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 {
652 .ctl_name = KERN_RANDOMIZE,
653 .procname = "randomize_va_space",
654 .data = &randomize_va_space,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = &proc_dointvec,
658 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800659#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800660#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700661 {
662 .ctl_name = KERN_SPIN_RETRY,
663 .procname = "spin_retry",
664 .data = &spin_retry,
665 .maxlen = sizeof (int),
666 .mode = 0644,
667 .proc_handler = &proc_dointvec,
668 },
669#endif
Pavel Machekc255d842006-02-20 18:27:58 -0800670#ifdef CONFIG_ACPI_SLEEP
671 {
672 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
673 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700674 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800675 .maxlen = sizeof (unsigned long),
676 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800677 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800678 },
679#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800680#ifdef CONFIG_IA64
681 {
682 .ctl_name = KERN_IA64_UNALIGNED,
683 .procname = "ignore-unaligned-usertrap",
684 .data = &no_unaligned_warning,
685 .maxlen = sizeof (int),
686 .mode = 0644,
687 .proc_handler = &proc_dointvec,
688 },
689#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200690#ifdef CONFIG_COMPAT
691 {
692 .ctl_name = KERN_COMPAT_LOG,
693 .procname = "compat-log",
694 .data = &compat_log,
695 .maxlen = sizeof (int),
696 .mode = 0644,
697 .proc_handler = &proc_dointvec,
698 },
699#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700700#ifdef CONFIG_RT_MUTEXES
701 {
702 .ctl_name = KERN_MAX_LOCK_DEPTH,
703 .procname = "max_lock_depth",
704 .data = &max_lock_depth,
705 .maxlen = sizeof(int),
706 .mode = 0644,
707 .proc_handler = &proc_dointvec,
708 },
709#endif
Kees Cook5096add2007-05-08 00:26:04 -0700710#ifdef CONFIG_PROC_FS
711 {
712 .ctl_name = CTL_UNNUMBERED,
713 .procname = "maps_protect",
714 .data = &maps_protect,
715 .maxlen = sizeof(int),
716 .mode = 0644,
717 .proc_handler = &proc_dointvec,
718 },
719#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700720 {
721 .ctl_name = CTL_UNNUMBERED,
722 .procname = "poweroff_cmd",
723 .data = &poweroff_cmd,
724 .maxlen = POWEROFF_CMD_PATH_LEN,
725 .mode = 0644,
726 .proc_handler = &proc_dostring,
727 .strategy = &sysctl_string,
728 },
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 { .ctl_name = 0 }
731};
732
733/* Constants for minimum and maximum testing in vm_table.
734 We use these as one-element integer vectors. */
735static int zero;
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -0700736static int two = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737static int one_hundred = 100;
738
739
740static ctl_table vm_table[] = {
741 {
742 .ctl_name = VM_OVERCOMMIT_MEMORY,
743 .procname = "overcommit_memory",
744 .data = &sysctl_overcommit_memory,
745 .maxlen = sizeof(sysctl_overcommit_memory),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
748 },
749 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700750 .ctl_name = VM_PANIC_ON_OOM,
751 .procname = "panic_on_oom",
752 .data = &sysctl_panic_on_oom,
753 .maxlen = sizeof(sysctl_panic_on_oom),
754 .mode = 0644,
755 .proc_handler = &proc_dointvec,
756 },
757 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .ctl_name = VM_OVERCOMMIT_RATIO,
759 .procname = "overcommit_ratio",
760 .data = &sysctl_overcommit_ratio,
761 .maxlen = sizeof(sysctl_overcommit_ratio),
762 .mode = 0644,
763 .proc_handler = &proc_dointvec,
764 },
765 {
766 .ctl_name = VM_PAGE_CLUSTER,
767 .procname = "page-cluster",
768 .data = &page_cluster,
769 .maxlen = sizeof(int),
770 .mode = 0644,
771 .proc_handler = &proc_dointvec,
772 },
773 {
774 .ctl_name = VM_DIRTY_BACKGROUND,
775 .procname = "dirty_background_ratio",
776 .data = &dirty_background_ratio,
777 .maxlen = sizeof(dirty_background_ratio),
778 .mode = 0644,
779 .proc_handler = &proc_dointvec_minmax,
780 .strategy = &sysctl_intvec,
781 .extra1 = &zero,
782 .extra2 = &one_hundred,
783 },
784 {
785 .ctl_name = VM_DIRTY_RATIO,
786 .procname = "dirty_ratio",
787 .data = &vm_dirty_ratio,
788 .maxlen = sizeof(vm_dirty_ratio),
789 .mode = 0644,
790 .proc_handler = &proc_dointvec_minmax,
791 .strategy = &sysctl_intvec,
792 .extra1 = &zero,
793 .extra2 = &one_hundred,
794 },
795 {
796 .ctl_name = VM_DIRTY_WB_CS,
797 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800798 .data = &dirty_writeback_interval,
799 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 .mode = 0644,
801 .proc_handler = &dirty_writeback_centisecs_handler,
802 },
803 {
804 .ctl_name = VM_DIRTY_EXPIRE_CS,
805 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800806 .data = &dirty_expire_interval,
807 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800809 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 },
811 {
812 .ctl_name = VM_NR_PDFLUSH_THREADS,
813 .procname = "nr_pdflush_threads",
814 .data = &nr_pdflush_threads,
815 .maxlen = sizeof nr_pdflush_threads,
816 .mode = 0444 /* read-only*/,
817 .proc_handler = &proc_dointvec,
818 },
819 {
820 .ctl_name = VM_SWAPPINESS,
821 .procname = "swappiness",
822 .data = &vm_swappiness,
823 .maxlen = sizeof(vm_swappiness),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec_minmax,
826 .strategy = &sysctl_intvec,
827 .extra1 = &zero,
828 .extra2 = &one_hundred,
829 },
830#ifdef CONFIG_HUGETLB_PAGE
831 {
832 .ctl_name = VM_HUGETLB_PAGES,
833 .procname = "nr_hugepages",
834 .data = &max_huge_pages,
835 .maxlen = sizeof(unsigned long),
836 .mode = 0644,
837 .proc_handler = &hugetlb_sysctl_handler,
838 .extra1 = (void *)&hugetlb_zero,
839 .extra2 = (void *)&hugetlb_infinity,
840 },
841 {
842 .ctl_name = VM_HUGETLB_GROUP,
843 .procname = "hugetlb_shm_group",
844 .data = &sysctl_hugetlb_shm_group,
845 .maxlen = sizeof(gid_t),
846 .mode = 0644,
847 .proc_handler = &proc_dointvec,
848 },
Mel Gorman396faf02007-07-17 04:03:13 -0700849 {
850 .ctl_name = CTL_UNNUMBERED,
851 .procname = "hugepages_treat_as_movable",
852 .data = &hugepages_treat_as_movable,
853 .maxlen = sizeof(int),
854 .mode = 0644,
855 .proc_handler = &hugetlb_treat_movable_handler,
856 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857#endif
858 {
859 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
860 .procname = "lowmem_reserve_ratio",
861 .data = &sysctl_lowmem_reserve_ratio,
862 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
863 .mode = 0644,
864 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
865 .strategy = &sysctl_intvec,
866 },
867 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800868 .ctl_name = VM_DROP_PAGECACHE,
869 .procname = "drop_caches",
870 .data = &sysctl_drop_caches,
871 .maxlen = sizeof(int),
872 .mode = 0644,
873 .proc_handler = drop_caches_sysctl_handler,
874 .strategy = &sysctl_intvec,
875 },
876 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 .ctl_name = VM_MIN_FREE_KBYTES,
878 .procname = "min_free_kbytes",
879 .data = &min_free_kbytes,
880 .maxlen = sizeof(min_free_kbytes),
881 .mode = 0644,
882 .proc_handler = &min_free_kbytes_sysctl_handler,
883 .strategy = &sysctl_intvec,
884 .extra1 = &zero,
885 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800886 {
887 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
888 .procname = "percpu_pagelist_fraction",
889 .data = &percpu_pagelist_fraction,
890 .maxlen = sizeof(percpu_pagelist_fraction),
891 .mode = 0644,
892 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
893 .strategy = &sysctl_intvec,
894 .extra1 = &min_percpu_pagelist_fract,
895 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896#ifdef CONFIG_MMU
897 {
898 .ctl_name = VM_MAX_MAP_COUNT,
899 .procname = "max_map_count",
900 .data = &sysctl_max_map_count,
901 .maxlen = sizeof(sysctl_max_map_count),
902 .mode = 0644,
903 .proc_handler = &proc_dointvec
904 },
905#endif
906 {
907 .ctl_name = VM_LAPTOP_MODE,
908 .procname = "laptop_mode",
909 .data = &laptop_mode,
910 .maxlen = sizeof(laptop_mode),
911 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800912 .proc_handler = &proc_dointvec_jiffies,
913 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 },
915 {
916 .ctl_name = VM_BLOCK_DUMP,
917 .procname = "block_dump",
918 .data = &block_dump,
919 .maxlen = sizeof(block_dump),
920 .mode = 0644,
921 .proc_handler = &proc_dointvec,
922 .strategy = &sysctl_intvec,
923 .extra1 = &zero,
924 },
925 {
926 .ctl_name = VM_VFS_CACHE_PRESSURE,
927 .procname = "vfs_cache_pressure",
928 .data = &sysctl_vfs_cache_pressure,
929 .maxlen = sizeof(sysctl_vfs_cache_pressure),
930 .mode = 0644,
931 .proc_handler = &proc_dointvec,
932 .strategy = &sysctl_intvec,
933 .extra1 = &zero,
934 },
935#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
936 {
937 .ctl_name = VM_LEGACY_VA_LAYOUT,
938 .procname = "legacy_va_layout",
939 .data = &sysctl_legacy_va_layout,
940 .maxlen = sizeof(sysctl_legacy_va_layout),
941 .mode = 0644,
942 .proc_handler = &proc_dointvec,
943 .strategy = &sysctl_intvec,
944 .extra1 = &zero,
945 },
946#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800947#ifdef CONFIG_NUMA
948 {
949 .ctl_name = VM_ZONE_RECLAIM_MODE,
950 .procname = "zone_reclaim_mode",
951 .data = &zone_reclaim_mode,
952 .maxlen = sizeof(zone_reclaim_mode),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -0800955 .strategy = &sysctl_intvec,
956 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -0800957 },
Christoph Lameter96146342006-07-03 00:24:13 -0700958 {
959 .ctl_name = VM_MIN_UNMAPPED,
960 .procname = "min_unmapped_ratio",
961 .data = &sysctl_min_unmapped_ratio,
962 .maxlen = sizeof(sysctl_min_unmapped_ratio),
963 .mode = 0644,
964 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
965 .strategy = &sysctl_intvec,
966 .extra1 = &zero,
967 .extra2 = &one_hundred,
968 },
Christoph Lameter0ff38492006-09-25 23:31:52 -0700969 {
970 .ctl_name = VM_MIN_SLAB,
971 .procname = "min_slab_ratio",
972 .data = &sysctl_min_slab_ratio,
973 .maxlen = sizeof(sysctl_min_slab_ratio),
974 .mode = 0644,
975 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
976 .strategy = &sysctl_intvec,
977 .extra1 = &zero,
978 .extra2 = &one_hundred,
979 },
Christoph Lameter17436602006-01-18 17:42:32 -0800980#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -0700981#ifdef CONFIG_SMP
982 {
983 .ctl_name = CTL_UNNUMBERED,
984 .procname = "stat_interval",
985 .data = &sysctl_stat_interval,
986 .maxlen = sizeof(sysctl_stat_interval),
987 .mode = 0644,
988 .proc_handler = &proc_dointvec_jiffies,
989 .strategy = &sysctl_jiffies,
990 },
991#endif
Eric Parised032182007-06-28 15:55:21 -0400992#ifdef CONFIG_SECURITY
993 {
994 .ctl_name = CTL_UNNUMBERED,
995 .procname = "mmap_min_addr",
996 .data = &mmap_min_addr,
997 .maxlen = sizeof(unsigned long),
998 .mode = 0644,
999 .proc_handler = &proc_doulongvec_minmax,
1000 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001001#ifdef CONFIG_NUMA
1002 {
1003 .ctl_name = CTL_UNNUMBERED,
1004 .procname = "numa_zonelist_order",
1005 .data = &numa_zonelist_order,
1006 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1007 .mode = 0644,
1008 .proc_handler = &numa_zonelist_order_handler,
1009 .strategy = &sysctl_string,
1010 },
1011#endif
Eric Parised032182007-06-28 15:55:21 -04001012#endif
Paul Mundt5c36e652007-03-01 10:07:42 +09001013#if defined(CONFIG_X86_32) || \
1014 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001015 {
1016 .ctl_name = VM_VDSO_ENABLED,
1017 .procname = "vdso_enabled",
1018 .data = &vdso_enabled,
1019 .maxlen = sizeof(vdso_enabled),
1020 .mode = 0644,
1021 .proc_handler = &proc_dointvec,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &zero,
1024 },
1025#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001026/*
1027 * NOTE: do not add new entries to this table unless you have read
1028 * Documentation/sysctl/ctl_unnumbered.txt
1029 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 { .ctl_name = 0 }
1031};
1032
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001033#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1034static ctl_table binfmt_misc_table[] = {
1035 { .ctl_name = 0 }
1036};
1037#endif
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039static ctl_table fs_table[] = {
1040 {
1041 .ctl_name = FS_NRINODE,
1042 .procname = "inode-nr",
1043 .data = &inodes_stat,
1044 .maxlen = 2*sizeof(int),
1045 .mode = 0444,
1046 .proc_handler = &proc_dointvec,
1047 },
1048 {
1049 .ctl_name = FS_STATINODE,
1050 .procname = "inode-state",
1051 .data = &inodes_stat,
1052 .maxlen = 7*sizeof(int),
1053 .mode = 0444,
1054 .proc_handler = &proc_dointvec,
1055 },
1056 {
1057 .ctl_name = FS_NRFILE,
1058 .procname = "file-nr",
1059 .data = &files_stat,
1060 .maxlen = 3*sizeof(int),
1061 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001062 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 },
1064 {
1065 .ctl_name = FS_MAXFILE,
1066 .procname = "file-max",
1067 .data = &files_stat.max_files,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
1070 .proc_handler = &proc_dointvec,
1071 },
1072 {
1073 .ctl_name = FS_DENTRY,
1074 .procname = "dentry-state",
1075 .data = &dentry_stat,
1076 .maxlen = 6*sizeof(int),
1077 .mode = 0444,
1078 .proc_handler = &proc_dointvec,
1079 },
1080 {
1081 .ctl_name = FS_OVERFLOWUID,
1082 .procname = "overflowuid",
1083 .data = &fs_overflowuid,
1084 .maxlen = sizeof(int),
1085 .mode = 0644,
1086 .proc_handler = &proc_dointvec_minmax,
1087 .strategy = &sysctl_intvec,
1088 .extra1 = &minolduid,
1089 .extra2 = &maxolduid,
1090 },
1091 {
1092 .ctl_name = FS_OVERFLOWGID,
1093 .procname = "overflowgid",
1094 .data = &fs_overflowgid,
1095 .maxlen = sizeof(int),
1096 .mode = 0644,
1097 .proc_handler = &proc_dointvec_minmax,
1098 .strategy = &sysctl_intvec,
1099 .extra1 = &minolduid,
1100 .extra2 = &maxolduid,
1101 },
1102 {
1103 .ctl_name = FS_LEASES,
1104 .procname = "leases-enable",
1105 .data = &leases_enable,
1106 .maxlen = sizeof(int),
1107 .mode = 0644,
1108 .proc_handler = &proc_dointvec,
1109 },
1110#ifdef CONFIG_DNOTIFY
1111 {
1112 .ctl_name = FS_DIR_NOTIFY,
1113 .procname = "dir-notify-enable",
1114 .data = &dir_notify_enable,
1115 .maxlen = sizeof(int),
1116 .mode = 0644,
1117 .proc_handler = &proc_dointvec,
1118 },
1119#endif
1120#ifdef CONFIG_MMU
1121 {
1122 .ctl_name = FS_LEASE_TIME,
1123 .procname = "lease-break-time",
1124 .data = &lease_break_time,
1125 .maxlen = sizeof(int),
1126 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001127 .proc_handler = &proc_dointvec_minmax,
1128 .strategy = &sysctl_intvec,
1129 .extra1 = &zero,
1130 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 },
1132 {
1133 .ctl_name = FS_AIO_NR,
1134 .procname = "aio-nr",
1135 .data = &aio_nr,
1136 .maxlen = sizeof(aio_nr),
1137 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001138 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 },
1140 {
1141 .ctl_name = FS_AIO_MAX_NR,
1142 .procname = "aio-max-nr",
1143 .data = &aio_max_nr,
1144 .maxlen = sizeof(aio_max_nr),
1145 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001146 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001148#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001149 {
1150 .ctl_name = FS_INOTIFY,
1151 .procname = "inotify",
1152 .mode = 0555,
1153 .child = inotify_table,
1154 },
1155#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001157 {
1158 .ctl_name = KERN_SETUID_DUMPABLE,
1159 .procname = "suid_dumpable",
1160 .data = &suid_dumpable,
1161 .maxlen = sizeof(int),
1162 .mode = 0644,
1163 .proc_handler = &proc_dointvec,
1164 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001165#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1166 {
1167 .ctl_name = CTL_UNNUMBERED,
1168 .procname = "binfmt_misc",
1169 .mode = 0555,
1170 .child = binfmt_misc_table,
1171 },
1172#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001173/*
1174 * NOTE: do not add new entries to this table unless you have read
1175 * Documentation/sysctl/ctl_unnumbered.txt
1176 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 { .ctl_name = 0 }
1178};
1179
1180static ctl_table debug_table[] = {
1181 { .ctl_name = 0 }
1182};
1183
1184static ctl_table dev_table[] = {
1185 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001186};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
Al Viro330d57f2005-11-04 10:18:40 +00001188static DEFINE_SPINLOCK(sysctl_lock);
1189
1190/* called under sysctl_lock */
1191static int use_table(struct ctl_table_header *p)
1192{
1193 if (unlikely(p->unregistering))
1194 return 0;
1195 p->used++;
1196 return 1;
1197}
1198
1199/* called under sysctl_lock */
1200static void unuse_table(struct ctl_table_header *p)
1201{
1202 if (!--p->used)
1203 if (unlikely(p->unregistering))
1204 complete(p->unregistering);
1205}
1206
1207/* called under sysctl_lock, will reacquire if has to wait */
1208static void start_unregistering(struct ctl_table_header *p)
1209{
1210 /*
1211 * if p->used is 0, nobody will ever touch that entry again;
1212 * we'll eliminate all paths to it before dropping sysctl_lock
1213 */
1214 if (unlikely(p->used)) {
1215 struct completion wait;
1216 init_completion(&wait);
1217 p->unregistering = &wait;
1218 spin_unlock(&sysctl_lock);
1219 wait_for_completion(&wait);
1220 spin_lock(&sysctl_lock);
1221 }
1222 /*
1223 * do not remove from the list until nobody holds it; walking the
1224 * list in do_sysctl() relies on that.
1225 */
1226 list_del_init(&p->ctl_entry);
1227}
1228
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001229void sysctl_head_finish(struct ctl_table_header *head)
1230{
1231 if (!head)
1232 return;
1233 spin_lock(&sysctl_lock);
1234 unuse_table(head);
1235 spin_unlock(&sysctl_lock);
1236}
1237
1238struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1239{
1240 struct ctl_table_header *head;
1241 struct list_head *tmp;
1242 spin_lock(&sysctl_lock);
1243 if (prev) {
1244 tmp = &prev->ctl_entry;
1245 unuse_table(prev);
1246 goto next;
1247 }
1248 tmp = &root_table_header.ctl_entry;
1249 for (;;) {
1250 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1251
1252 if (!use_table(head))
1253 goto next;
1254 spin_unlock(&sysctl_lock);
1255 return head;
1256 next:
1257 tmp = tmp->next;
1258 if (tmp == &root_table_header.ctl_entry)
1259 break;
1260 }
1261 spin_unlock(&sysctl_lock);
1262 return NULL;
1263}
1264
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001265#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1267 void __user *newval, size_t newlen)
1268{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001269 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001270 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1273 return -ENOTDIR;
1274 if (oldval) {
1275 int old_len;
1276 if (!oldlenp || get_user(old_len, oldlenp))
1277 return -EFAULT;
1278 }
Al Viro330d57f2005-11-04 10:18:40 +00001279
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001280 for (head = sysctl_head_next(NULL); head;
1281 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001282 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001283 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001284 if (error != -ENOTDIR) {
1285 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001286 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001287 }
1288 }
Al Viro330d57f2005-11-04 10:18:40 +00001289 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290}
1291
1292asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1293{
1294 struct __sysctl_args tmp;
1295 int error;
1296
1297 if (copy_from_user(&tmp, args, sizeof(tmp)))
1298 return -EFAULT;
1299
1300 lock_kernel();
1301 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1302 tmp.newval, tmp.newlen);
1303 unlock_kernel();
1304 return error;
1305}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001306#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
1308/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001309 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 * some sysctl variables are readonly even to root.
1311 */
1312
1313static int test_perm(int mode, int op)
1314{
1315 if (!current->euid)
1316 mode >>= 6;
1317 else if (in_egroup_p(0))
1318 mode >>= 3;
1319 if ((mode & op & 0007) == op)
1320 return 0;
1321 return -EACCES;
1322}
1323
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001324int sysctl_perm(ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
1326 int error;
1327 error = security_sysctl(table, op);
1328 if (error)
1329 return error;
1330 return test_perm(table->mode, op);
1331}
1332
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001333#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334static int parse_table(int __user *name, int nlen,
1335 void __user *oldval, size_t __user *oldlenp,
1336 void __user *newval, size_t newlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001337 ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
1339 int n;
1340repeat:
1341 if (!nlen)
1342 return -ENOTDIR;
1343 if (get_user(n, name))
1344 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001345 for ( ; table->ctl_name || table->procname; table++) {
1346 if (!table->ctl_name)
1347 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001348 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 int error;
1350 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001351 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 name++;
1354 nlen--;
1355 table = table->child;
1356 goto repeat;
1357 }
1358 error = do_sysctl_strategy(table, name, nlen,
1359 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001360 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 return error;
1362 }
1363 }
1364 return -ENOTDIR;
1365}
1366
1367/* Perform the actual read/write of a sysctl table entry. */
1368int do_sysctl_strategy (ctl_table *table,
1369 int __user *name, int nlen,
1370 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001371 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372{
1373 int op = 0, rc;
1374 size_t len;
1375
1376 if (oldval)
1377 op |= 004;
1378 if (newval)
1379 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001380 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 return -EPERM;
1382
1383 if (table->strategy) {
1384 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001385 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 if (rc < 0)
1387 return rc;
1388 if (rc > 0)
1389 return 0;
1390 }
1391
1392 /* If there is no strategy routine, or if the strategy returns
1393 * zero, proceed with automatic r/w */
1394 if (table->data && table->maxlen) {
1395 if (oldval && oldlenp) {
1396 if (get_user(len, oldlenp))
1397 return -EFAULT;
1398 if (len) {
1399 if (len > table->maxlen)
1400 len = table->maxlen;
1401 if(copy_to_user(oldval, table->data, len))
1402 return -EFAULT;
1403 if(put_user(len, oldlenp))
1404 return -EFAULT;
1405 }
1406 }
1407 if (newval && newlen) {
1408 len = newlen;
1409 if (len > table->maxlen)
1410 len = table->maxlen;
1411 if(copy_from_user(table->data, newval, len))
1412 return -EFAULT;
1413 }
1414 }
1415 return 0;
1416}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001417#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001419static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1420{
1421 for (; table->ctl_name || table->procname; table++) {
1422 table->parent = parent;
1423 if (table->child)
1424 sysctl_set_parent(table, table->child);
1425 }
1426}
1427
1428static __init int sysctl_init(void)
1429{
1430 sysctl_set_parent(NULL, root_table);
1431 return 0;
1432}
1433
1434core_initcall(sysctl_init);
1435
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436/**
1437 * register_sysctl_table - register a sysctl hierarchy
1438 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 *
1440 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1441 * array. An entry with a ctl_name of 0 terminates the table.
1442 *
1443 * The members of the &ctl_table structure are used as follows:
1444 *
1445 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1446 * must be unique within that level of sysctl
1447 *
1448 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1449 * enter a sysctl file
1450 *
1451 * data - a pointer to data for use by proc_handler
1452 *
1453 * maxlen - the maximum size in bytes of the data
1454 *
1455 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1456 *
1457 * child - a pointer to the child sysctl table if this entry is a directory, or
1458 * %NULL.
1459 *
1460 * proc_handler - the text handler routine (described below)
1461 *
1462 * strategy - the strategy routine (described below)
1463 *
1464 * de - for internal use by the sysctl routines
1465 *
1466 * extra1, extra2 - extra pointers usable by the proc handler routines
1467 *
1468 * Leaf nodes in the sysctl tree will be represented by a single file
1469 * under /proc; non-leaf nodes will be represented by directories.
1470 *
1471 * sysctl(2) can automatically manage read and write requests through
1472 * the sysctl table. The data and maxlen fields of the ctl_table
1473 * struct enable minimal validation of the values being written to be
1474 * performed, and the mode field allows minimal authentication.
1475 *
1476 * More sophisticated management can be enabled by the provision of a
1477 * strategy routine with the table entry. This will be called before
1478 * any automatic read or write of the data is performed.
1479 *
1480 * The strategy routine may return
1481 *
1482 * < 0 - Error occurred (error is passed to user process)
1483 *
1484 * 0 - OK - proceed with automatic read or write.
1485 *
1486 * > 0 - OK - read or write has been done by the strategy routine, so
1487 * return immediately.
1488 *
1489 * There must be a proc_handler routine for any terminal nodes
1490 * mirrored under /proc/sys (non-terminals are handled by a built-in
1491 * directory handler). Several default handlers are available to
1492 * cover common cases -
1493 *
1494 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1495 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1496 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1497 *
1498 * It is the handler's job to read the input buffer from user memory
1499 * and process it. The handler should return 0 on success.
1500 *
1501 * This routine returns %NULL on a failure to register, and a pointer
1502 * to the table header on success.
1503 */
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001504struct ctl_table_header *register_sysctl_table(ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505{
1506 struct ctl_table_header *tmp;
1507 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1508 if (!tmp)
1509 return NULL;
1510 tmp->ctl_table = table;
1511 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001512 tmp->used = 0;
1513 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001514 sysctl_set_parent(NULL, table);
Al Viro330d57f2005-11-04 10:18:40 +00001515 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001516 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001517 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 return tmp;
1519}
1520
1521/**
1522 * unregister_sysctl_table - unregister a sysctl table hierarchy
1523 * @header: the header returned from register_sysctl_table
1524 *
1525 * Unregisters the sysctl table and all children. proc entries may not
1526 * actually be removed until they are no longer used by anyone.
1527 */
1528void unregister_sysctl_table(struct ctl_table_header * header)
1529{
Al Viro330d57f2005-11-04 10:18:40 +00001530 might_sleep();
1531 spin_lock(&sysctl_lock);
1532 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001533 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 kfree(header);
1535}
1536
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001537#else /* !CONFIG_SYSCTL */
Adrian Bunk93a6fef2007-02-28 20:12:23 -08001538struct ctl_table_header *register_sysctl_table(ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001539{
1540 return NULL;
1541}
1542
1543void unregister_sysctl_table(struct ctl_table_header * table)
1544{
1545}
1546
1547#endif /* CONFIG_SYSCTL */
1548
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549/*
1550 * /proc/sys support
1551 */
1552
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001553#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001555static int _proc_do_string(void* data, int maxlen, int write,
1556 struct file *filp, void __user *buffer,
1557 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001558{
1559 size_t len;
1560 char __user *p;
1561 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001562
1563 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001564 *lenp = 0;
1565 return 0;
1566 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001567
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001568 if (write) {
1569 len = 0;
1570 p = buffer;
1571 while (len < *lenp) {
1572 if (get_user(c, p++))
1573 return -EFAULT;
1574 if (c == 0 || c == '\n')
1575 break;
1576 len++;
1577 }
1578 if (len >= maxlen)
1579 len = maxlen-1;
1580 if(copy_from_user(data, buffer, len))
1581 return -EFAULT;
1582 ((char *) data)[len] = 0;
1583 *ppos += *lenp;
1584 } else {
1585 len = strlen(data);
1586 if (len > maxlen)
1587 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001588
1589 if (*ppos > len) {
1590 *lenp = 0;
1591 return 0;
1592 }
1593
1594 data += *ppos;
1595 len -= *ppos;
1596
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001597 if (len > *lenp)
1598 len = *lenp;
1599 if (len)
1600 if(copy_to_user(buffer, data, len))
1601 return -EFAULT;
1602 if (len < *lenp) {
1603 if(put_user('\n', ((char __user *) buffer) + len))
1604 return -EFAULT;
1605 len++;
1606 }
1607 *lenp = len;
1608 *ppos += len;
1609 }
1610 return 0;
1611}
1612
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613/**
1614 * proc_dostring - read a string sysctl
1615 * @table: the sysctl table
1616 * @write: %TRUE if this is a write to the sysctl file
1617 * @filp: the file structure
1618 * @buffer: the user buffer
1619 * @lenp: the size of the user buffer
1620 * @ppos: file position
1621 *
1622 * Reads/writes a string from/to the user buffer. If the kernel
1623 * buffer provided is not large enough to hold the string, the
1624 * string is truncated. The copied string is %NULL-terminated.
1625 * If the string is being read by the user process, it is copied
1626 * and a newline '\n' is added. It is truncated if the buffer is
1627 * not large enough.
1628 *
1629 * Returns 0 on success.
1630 */
1631int proc_dostring(ctl_table *table, int write, struct file *filp,
1632 void __user *buffer, size_t *lenp, loff_t *ppos)
1633{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001634 return _proc_do_string(table->data, table->maxlen, write, filp,
1635 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636}
1637
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638
1639static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1640 int *valp,
1641 int write, void *data)
1642{
1643 if (write) {
1644 *valp = *negp ? -*lvalp : *lvalp;
1645 } else {
1646 int val = *valp;
1647 if (val < 0) {
1648 *negp = -1;
1649 *lvalp = (unsigned long)-val;
1650 } else {
1651 *negp = 0;
1652 *lvalp = (unsigned long)val;
1653 }
1654 }
1655 return 0;
1656}
1657
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001658static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1659 int write, struct file *filp, void __user *buffer,
1660 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1662 int write, void *data),
1663 void *data)
1664{
1665#define TMPBUFLEN 21
1666 int *i, vleft, first=1, neg, val;
1667 unsigned long lval;
1668 size_t left, len;
1669
1670 char buf[TMPBUFLEN], *p;
1671 char __user *s = buffer;
1672
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001673 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 (*ppos && !write)) {
1675 *lenp = 0;
1676 return 0;
1677 }
1678
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001679 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 vleft = table->maxlen / sizeof(*i);
1681 left = *lenp;
1682
1683 if (!conv)
1684 conv = do_proc_dointvec_conv;
1685
1686 for (; left && vleft--; i++, first=0) {
1687 if (write) {
1688 while (left) {
1689 char c;
1690 if (get_user(c, s))
1691 return -EFAULT;
1692 if (!isspace(c))
1693 break;
1694 left--;
1695 s++;
1696 }
1697 if (!left)
1698 break;
1699 neg = 0;
1700 len = left;
1701 if (len > sizeof(buf) - 1)
1702 len = sizeof(buf) - 1;
1703 if (copy_from_user(buf, s, len))
1704 return -EFAULT;
1705 buf[len] = 0;
1706 p = buf;
1707 if (*p == '-' && left > 1) {
1708 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001709 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 }
1711 if (*p < '0' || *p > '9')
1712 break;
1713
1714 lval = simple_strtoul(p, &p, 0);
1715
1716 len = p-buf;
1717 if ((len < left) && *p && !isspace(*p))
1718 break;
1719 if (neg)
1720 val = -val;
1721 s += len;
1722 left -= len;
1723
1724 if (conv(&neg, &lval, i, 1, data))
1725 break;
1726 } else {
1727 p = buf;
1728 if (!first)
1729 *p++ = '\t';
1730
1731 if (conv(&neg, &lval, i, 0, data))
1732 break;
1733
1734 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1735 len = strlen(buf);
1736 if (len > left)
1737 len = left;
1738 if(copy_to_user(s, buf, len))
1739 return -EFAULT;
1740 left -= len;
1741 s += len;
1742 }
1743 }
1744
1745 if (!write && !first && left) {
1746 if(put_user('\n', s))
1747 return -EFAULT;
1748 left--, s++;
1749 }
1750 if (write) {
1751 while (left) {
1752 char c;
1753 if (get_user(c, s++))
1754 return -EFAULT;
1755 if (!isspace(c))
1756 break;
1757 left--;
1758 }
1759 }
1760 if (write && first)
1761 return -EINVAL;
1762 *lenp -= left;
1763 *ppos += *lenp;
1764 return 0;
1765#undef TMPBUFLEN
1766}
1767
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001768static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1769 void __user *buffer, size_t *lenp, loff_t *ppos,
1770 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1771 int write, void *data),
1772 void *data)
1773{
1774 return __do_proc_dointvec(table->data, table, write, filp,
1775 buffer, lenp, ppos, conv, data);
1776}
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778/**
1779 * proc_dointvec - read a vector of integers
1780 * @table: the sysctl table
1781 * @write: %TRUE if this is a write to the sysctl file
1782 * @filp: the file structure
1783 * @buffer: the user buffer
1784 * @lenp: the size of the user buffer
1785 * @ppos: file position
1786 *
1787 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1788 * values from/to the user buffer, treated as an ASCII string.
1789 *
1790 * Returns 0 on success.
1791 */
1792int proc_dointvec(ctl_table *table, int write, struct file *filp,
1793 void __user *buffer, size_t *lenp, loff_t *ppos)
1794{
1795 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1796 NULL,NULL);
1797}
1798
1799#define OP_SET 0
1800#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001801#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
1803static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1804 int *valp,
1805 int write, void *data)
1806{
1807 int op = *(int *)data;
1808 if (write) {
1809 int val = *negp ? -*lvalp : *lvalp;
1810 switch(op) {
1811 case OP_SET: *valp = val; break;
1812 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001813 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 }
1815 } else {
1816 int val = *valp;
1817 if (val < 0) {
1818 *negp = -1;
1819 *lvalp = (unsigned long)-val;
1820 } else {
1821 *negp = 0;
1822 *lvalp = (unsigned long)val;
1823 }
1824 }
1825 return 0;
1826}
1827
1828/*
1829 * init may raise the set.
1830 */
1831
1832int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1833 void __user *buffer, size_t *lenp, loff_t *ppos)
1834{
1835 int op;
1836
Eric Paris6ff1b442007-02-10 01:43:19 -08001837 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 return -EPERM;
1839 }
1840
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001841 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1843 do_proc_dointvec_bset_conv,&op);
1844}
1845
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001846/*
1847 * Taint values can only be increased
1848 */
1849static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1850 void __user *buffer, size_t *lenp, loff_t *ppos)
1851{
1852 int op;
1853
Bastian Blank91fcd412007-04-23 14:41:14 -07001854 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001855 return -EPERM;
1856
1857 op = OP_OR;
1858 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1859 do_proc_dointvec_bset_conv,&op);
1860}
1861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862struct do_proc_dointvec_minmax_conv_param {
1863 int *min;
1864 int *max;
1865};
1866
1867static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1868 int *valp,
1869 int write, void *data)
1870{
1871 struct do_proc_dointvec_minmax_conv_param *param = data;
1872 if (write) {
1873 int val = *negp ? -*lvalp : *lvalp;
1874 if ((param->min && *param->min > val) ||
1875 (param->max && *param->max < val))
1876 return -EINVAL;
1877 *valp = val;
1878 } else {
1879 int val = *valp;
1880 if (val < 0) {
1881 *negp = -1;
1882 *lvalp = (unsigned long)-val;
1883 } else {
1884 *negp = 0;
1885 *lvalp = (unsigned long)val;
1886 }
1887 }
1888 return 0;
1889}
1890
1891/**
1892 * proc_dointvec_minmax - read a vector of integers with min/max values
1893 * @table: the sysctl table
1894 * @write: %TRUE if this is a write to the sysctl file
1895 * @filp: the file structure
1896 * @buffer: the user buffer
1897 * @lenp: the size of the user buffer
1898 * @ppos: file position
1899 *
1900 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1901 * values from/to the user buffer, treated as an ASCII string.
1902 *
1903 * This routine will ensure the values are within the range specified by
1904 * table->extra1 (min) and table->extra2 (max).
1905 *
1906 * Returns 0 on success.
1907 */
1908int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1909 void __user *buffer, size_t *lenp, loff_t *ppos)
1910{
1911 struct do_proc_dointvec_minmax_conv_param param = {
1912 .min = (int *) table->extra1,
1913 .max = (int *) table->extra2,
1914 };
1915 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1916 do_proc_dointvec_minmax_conv, &param);
1917}
1918
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001919static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 struct file *filp,
1921 void __user *buffer,
1922 size_t *lenp, loff_t *ppos,
1923 unsigned long convmul,
1924 unsigned long convdiv)
1925{
1926#define TMPBUFLEN 21
1927 unsigned long *i, *min, *max, val;
1928 int vleft, first=1, neg;
1929 size_t len, left;
1930 char buf[TMPBUFLEN], *p;
1931 char __user *s = buffer;
1932
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001933 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 (*ppos && !write)) {
1935 *lenp = 0;
1936 return 0;
1937 }
1938
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001939 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 min = (unsigned long *) table->extra1;
1941 max = (unsigned long *) table->extra2;
1942 vleft = table->maxlen / sizeof(unsigned long);
1943 left = *lenp;
1944
1945 for (; left && vleft--; i++, min++, max++, first=0) {
1946 if (write) {
1947 while (left) {
1948 char c;
1949 if (get_user(c, s))
1950 return -EFAULT;
1951 if (!isspace(c))
1952 break;
1953 left--;
1954 s++;
1955 }
1956 if (!left)
1957 break;
1958 neg = 0;
1959 len = left;
1960 if (len > TMPBUFLEN-1)
1961 len = TMPBUFLEN-1;
1962 if (copy_from_user(buf, s, len))
1963 return -EFAULT;
1964 buf[len] = 0;
1965 p = buf;
1966 if (*p == '-' && left > 1) {
1967 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001968 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 }
1970 if (*p < '0' || *p > '9')
1971 break;
1972 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1973 len = p-buf;
1974 if ((len < left) && *p && !isspace(*p))
1975 break;
1976 if (neg)
1977 val = -val;
1978 s += len;
1979 left -= len;
1980
1981 if(neg)
1982 continue;
1983 if ((min && val < *min) || (max && val > *max))
1984 continue;
1985 *i = val;
1986 } else {
1987 p = buf;
1988 if (!first)
1989 *p++ = '\t';
1990 sprintf(p, "%lu", convdiv * (*i) / convmul);
1991 len = strlen(buf);
1992 if (len > left)
1993 len = left;
1994 if(copy_to_user(s, buf, len))
1995 return -EFAULT;
1996 left -= len;
1997 s += len;
1998 }
1999 }
2000
2001 if (!write && !first && left) {
2002 if(put_user('\n', s))
2003 return -EFAULT;
2004 left--, s++;
2005 }
2006 if (write) {
2007 while (left) {
2008 char c;
2009 if (get_user(c, s++))
2010 return -EFAULT;
2011 if (!isspace(c))
2012 break;
2013 left--;
2014 }
2015 }
2016 if (write && first)
2017 return -EINVAL;
2018 *lenp -= left;
2019 *ppos += *lenp;
2020 return 0;
2021#undef TMPBUFLEN
2022}
2023
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002024static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2025 struct file *filp,
2026 void __user *buffer,
2027 size_t *lenp, loff_t *ppos,
2028 unsigned long convmul,
2029 unsigned long convdiv)
2030{
2031 return __do_proc_doulongvec_minmax(table->data, table, write,
2032 filp, buffer, lenp, ppos, convmul, convdiv);
2033}
2034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035/**
2036 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2037 * @table: the sysctl table
2038 * @write: %TRUE if this is a write to the sysctl file
2039 * @filp: the file structure
2040 * @buffer: the user buffer
2041 * @lenp: the size of the user buffer
2042 * @ppos: file position
2043 *
2044 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2045 * values from/to the user buffer, treated as an ASCII string.
2046 *
2047 * This routine will ensure the values are within the range specified by
2048 * table->extra1 (min) and table->extra2 (max).
2049 *
2050 * Returns 0 on success.
2051 */
2052int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2053 void __user *buffer, size_t *lenp, loff_t *ppos)
2054{
2055 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2056}
2057
2058/**
2059 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2060 * @table: the sysctl table
2061 * @write: %TRUE if this is a write to the sysctl file
2062 * @filp: the file structure
2063 * @buffer: the user buffer
2064 * @lenp: the size of the user buffer
2065 * @ppos: file position
2066 *
2067 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2068 * values from/to the user buffer, treated as an ASCII string. The values
2069 * are treated as milliseconds, and converted to jiffies when they are stored.
2070 *
2071 * This routine will ensure the values are within the range specified by
2072 * table->extra1 (min) and table->extra2 (max).
2073 *
2074 * Returns 0 on success.
2075 */
2076int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2077 struct file *filp,
2078 void __user *buffer,
2079 size_t *lenp, loff_t *ppos)
2080{
2081 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2082 lenp, ppos, HZ, 1000l);
2083}
2084
2085
2086static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2087 int *valp,
2088 int write, void *data)
2089{
2090 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002091 if (*lvalp > LONG_MAX / HZ)
2092 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2094 } else {
2095 int val = *valp;
2096 unsigned long lval;
2097 if (val < 0) {
2098 *negp = -1;
2099 lval = (unsigned long)-val;
2100 } else {
2101 *negp = 0;
2102 lval = (unsigned long)val;
2103 }
2104 *lvalp = lval / HZ;
2105 }
2106 return 0;
2107}
2108
2109static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2110 int *valp,
2111 int write, void *data)
2112{
2113 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002114 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2115 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2117 } else {
2118 int val = *valp;
2119 unsigned long lval;
2120 if (val < 0) {
2121 *negp = -1;
2122 lval = (unsigned long)-val;
2123 } else {
2124 *negp = 0;
2125 lval = (unsigned long)val;
2126 }
2127 *lvalp = jiffies_to_clock_t(lval);
2128 }
2129 return 0;
2130}
2131
2132static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2133 int *valp,
2134 int write, void *data)
2135{
2136 if (write) {
2137 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2138 } else {
2139 int val = *valp;
2140 unsigned long lval;
2141 if (val < 0) {
2142 *negp = -1;
2143 lval = (unsigned long)-val;
2144 } else {
2145 *negp = 0;
2146 lval = (unsigned long)val;
2147 }
2148 *lvalp = jiffies_to_msecs(lval);
2149 }
2150 return 0;
2151}
2152
2153/**
2154 * proc_dointvec_jiffies - read a vector of integers as seconds
2155 * @table: the sysctl table
2156 * @write: %TRUE if this is a write to the sysctl file
2157 * @filp: the file structure
2158 * @buffer: the user buffer
2159 * @lenp: the size of the user buffer
2160 * @ppos: file position
2161 *
2162 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2163 * values from/to the user buffer, treated as an ASCII string.
2164 * The values read are assumed to be in seconds, and are converted into
2165 * jiffies.
2166 *
2167 * Returns 0 on success.
2168 */
2169int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2170 void __user *buffer, size_t *lenp, loff_t *ppos)
2171{
2172 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2173 do_proc_dointvec_jiffies_conv,NULL);
2174}
2175
2176/**
2177 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2178 * @table: the sysctl table
2179 * @write: %TRUE if this is a write to the sysctl file
2180 * @filp: the file structure
2181 * @buffer: the user buffer
2182 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002183 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 *
2185 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2186 * values from/to the user buffer, treated as an ASCII string.
2187 * The values read are assumed to be in 1/USER_HZ seconds, and
2188 * are converted into jiffies.
2189 *
2190 * Returns 0 on success.
2191 */
2192int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2193 void __user *buffer, size_t *lenp, loff_t *ppos)
2194{
2195 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2196 do_proc_dointvec_userhz_jiffies_conv,NULL);
2197}
2198
2199/**
2200 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2201 * @table: the sysctl table
2202 * @write: %TRUE if this is a write to the sysctl file
2203 * @filp: the file structure
2204 * @buffer: the user buffer
2205 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002206 * @ppos: file position
2207 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 *
2209 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2210 * values from/to the user buffer, treated as an ASCII string.
2211 * The values read are assumed to be in 1/1000 seconds, and
2212 * are converted into jiffies.
2213 *
2214 * Returns 0 on success.
2215 */
2216int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2217 void __user *buffer, size_t *lenp, loff_t *ppos)
2218{
2219 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2220 do_proc_dointvec_ms_jiffies_conv, NULL);
2221}
2222
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002223static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2225{
2226 struct pid *new_pid;
2227 pid_t tmp;
2228 int r;
2229
2230 tmp = pid_nr(cad_pid);
2231
2232 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2233 lenp, ppos, NULL, NULL);
2234 if (r || !write)
2235 return r;
2236
2237 new_pid = find_get_pid(tmp);
2238 if (!new_pid)
2239 return -ESRCH;
2240
2241 put_pid(xchg(&cad_pid, new_pid));
2242 return 0;
2243}
2244
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245#else /* CONFIG_PROC_FS */
2246
2247int proc_dostring(ctl_table *table, int write, struct file *filp,
2248 void __user *buffer, size_t *lenp, loff_t *ppos)
2249{
2250 return -ENOSYS;
2251}
2252
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253int proc_dointvec(ctl_table *table, int write, struct file *filp,
2254 void __user *buffer, size_t *lenp, loff_t *ppos)
2255{
2256 return -ENOSYS;
2257}
2258
2259int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2260 void __user *buffer, size_t *lenp, loff_t *ppos)
2261{
2262 return -ENOSYS;
2263}
2264
2265int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2266 void __user *buffer, size_t *lenp, loff_t *ppos)
2267{
2268 return -ENOSYS;
2269}
2270
2271int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2272 void __user *buffer, size_t *lenp, loff_t *ppos)
2273{
2274 return -ENOSYS;
2275}
2276
2277int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2278 void __user *buffer, size_t *lenp, loff_t *ppos)
2279{
2280 return -ENOSYS;
2281}
2282
2283int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2284 void __user *buffer, size_t *lenp, loff_t *ppos)
2285{
2286 return -ENOSYS;
2287}
2288
2289int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2290 void __user *buffer, size_t *lenp, loff_t *ppos)
2291{
2292 return -ENOSYS;
2293}
2294
2295int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2296 struct file *filp,
2297 void __user *buffer,
2298 size_t *lenp, loff_t *ppos)
2299{
2300 return -ENOSYS;
2301}
2302
2303
2304#endif /* CONFIG_PROC_FS */
2305
2306
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002307#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308/*
2309 * General sysctl support routines
2310 */
2311
2312/* The generic string strategy routine: */
2313int sysctl_string(ctl_table *table, int __user *name, int nlen,
2314 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002315 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 if (!table->data || !table->maxlen)
2318 return -ENOTDIR;
2319
2320 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002321 size_t bufsize;
2322 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002324 if (bufsize) {
2325 size_t len = strlen(table->data), copied;
2326
2327 /* This shouldn't trigger for a well-formed sysctl */
2328 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002330
2331 /* Copy up to a max of bufsize-1 bytes of the string */
2332 copied = (len >= bufsize) ? bufsize - 1 : len;
2333
2334 if (copy_to_user(oldval, table->data, copied) ||
2335 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002337 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 return -EFAULT;
2339 }
2340 }
2341 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002342 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 if (len > table->maxlen)
2344 len = table->maxlen;
2345 if(copy_from_user(table->data, newval, len))
2346 return -EFAULT;
2347 if (len == table->maxlen)
2348 len--;
2349 ((char *) table->data)[len] = 0;
2350 }
Yi Yang82c9df82005-12-30 16:37:10 +08002351 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352}
2353
2354/*
2355 * This function makes sure that all of the integers in the vector
2356 * are between the minimum and maximum values given in the arrays
2357 * table->extra1 and table->extra2, respectively.
2358 */
2359int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2360 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002361 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362{
2363
2364 if (newval && newlen) {
2365 int __user *vec = (int __user *) newval;
2366 int *min = (int *) table->extra1;
2367 int *max = (int *) table->extra2;
2368 size_t length;
2369 int i;
2370
2371 if (newlen % sizeof(int) != 0)
2372 return -EINVAL;
2373
2374 if (!table->extra1 && !table->extra2)
2375 return 0;
2376
2377 if (newlen > table->maxlen)
2378 newlen = table->maxlen;
2379 length = newlen / sizeof(int);
2380
2381 for (i = 0; i < length; i++) {
2382 int value;
2383 if (get_user(value, vec + i))
2384 return -EFAULT;
2385 if (min && value < min[i])
2386 return -EINVAL;
2387 if (max && value > max[i])
2388 return -EINVAL;
2389 }
2390 }
2391 return 0;
2392}
2393
2394/* Strategy function to convert jiffies to seconds */
2395int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2396 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002397 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002399 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002401
2402 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002404 if (olen) {
2405 int val;
2406
2407 if (olen < sizeof(int))
2408 return -EINVAL;
2409
2410 val = *(int *)(table->data) / HZ;
2411 if (put_user(val, (int __user *)oldval))
2412 return -EFAULT;
2413 if (put_user(sizeof(int), oldlenp))
2414 return -EFAULT;
2415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 }
2417 if (newval && newlen) {
2418 int new;
2419 if (newlen != sizeof(int))
2420 return -EINVAL;
2421 if (get_user(new, (int __user *)newval))
2422 return -EFAULT;
2423 *(int *)(table->data) = new*HZ;
2424 }
2425 return 1;
2426}
2427
2428/* Strategy function to convert jiffies to seconds */
2429int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2430 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002431 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002433 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002435
2436 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002438 if (olen) {
2439 int val;
2440
2441 if (olen < sizeof(int))
2442 return -EINVAL;
2443
2444 val = jiffies_to_msecs(*(int *)(table->data));
2445 if (put_user(val, (int __user *)oldval))
2446 return -EFAULT;
2447 if (put_user(sizeof(int), oldlenp))
2448 return -EFAULT;
2449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 }
2451 if (newval && newlen) {
2452 int new;
2453 if (newlen != sizeof(int))
2454 return -EINVAL;
2455 if (get_user(new, (int __user *)newval))
2456 return -EFAULT;
2457 *(int *)(table->data) = msecs_to_jiffies(new);
2458 }
2459 return 1;
2460}
2461
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002462
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002463
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002464#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465
2466
2467asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2468{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002469 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002470 struct __sysctl_args tmp;
2471 int name[CTL_MAXNAME];
2472 int i;
2473
2474 /* Read in the sysctl name for better debug message logging */
2475 if (copy_from_user(&tmp, args, sizeof(tmp)))
2476 return -EFAULT;
2477 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2478 return -ENOTDIR;
2479 for (i = 0; i < tmp.nlen; i++)
2480 if (get_user(name[i], tmp.name + i))
2481 return -EFAULT;
2482
2483 /* Ignore accesses to kernel.version */
2484 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2485 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002486
2487 if (msg_count < 5) {
2488 msg_count++;
2489 printk(KERN_INFO
2490 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002491 "system call with ", current->comm);
2492 for (i = 0; i < tmp.nlen; i++)
2493 printk("%d.", name[i]);
2494 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002495 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002496out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 return -ENOSYS;
2498}
2499
2500int sysctl_string(ctl_table *table, int __user *name, int nlen,
2501 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002502 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503{
2504 return -ENOSYS;
2505}
2506
2507int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2508 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002509 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510{
2511 return -ENOSYS;
2512}
2513
2514int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2515 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002516 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517{
2518 return -ENOSYS;
2519}
2520
2521int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2522 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002523 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524{
2525 return -ENOSYS;
2526}
2527
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002528#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529
2530/*
2531 * No sense putting this after each symbol definition, twice,
2532 * exception granted :-)
2533 */
2534EXPORT_SYMBOL(proc_dointvec);
2535EXPORT_SYMBOL(proc_dointvec_jiffies);
2536EXPORT_SYMBOL(proc_dointvec_minmax);
2537EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2538EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2539EXPORT_SYMBOL(proc_dostring);
2540EXPORT_SYMBOL(proc_doulongvec_minmax);
2541EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2542EXPORT_SYMBOL(register_sysctl_table);
2543EXPORT_SYMBOL(sysctl_intvec);
2544EXPORT_SYMBOL(sysctl_jiffies);
2545EXPORT_SYMBOL(sysctl_ms_jiffies);
2546EXPORT_SYMBOL(sysctl_string);
2547EXPORT_SYMBOL(unregister_sysctl_table);