blob: ddebf3f2affe937d8a9ccb694de85dc9d567f1fb [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
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700164extern int prove_locking;
165extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167/* The default sysctl tables: */
168
169static ctl_table root_table[] = {
170 {
171 .ctl_name = CTL_KERN,
172 .procname = "kernel",
173 .mode = 0555,
174 .child = kern_table,
175 },
176 {
177 .ctl_name = CTL_VM,
178 .procname = "vm",
179 .mode = 0555,
180 .child = vm_table,
181 },
182#ifdef CONFIG_NET
183 {
184 .ctl_name = CTL_NET,
185 .procname = "net",
186 .mode = 0555,
187 .child = net_table,
188 },
189#endif
190 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 .ctl_name = CTL_FS,
192 .procname = "fs",
193 .mode = 0555,
194 .child = fs_table,
195 },
196 {
197 .ctl_name = CTL_DEBUG,
198 .procname = "debug",
199 .mode = 0555,
200 .child = debug_table,
201 },
202 {
203 .ctl_name = CTL_DEV,
204 .procname = "dev",
205 .mode = 0555,
206 .child = dev_table,
207 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700208/*
209 * NOTE: do not add new entries to this table unless you have read
210 * Documentation/sysctl/ctl_unnumbered.txt
211 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 { .ctl_name = 0 }
213};
214
Ingo Molnar77e54a12007-07-09 18:52:00 +0200215#ifdef CONFIG_SCHED_DEBUG
216static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
217static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
218static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
219static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
220#endif
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222static ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200223#ifdef CONFIG_SCHED_DEBUG
224 {
225 .ctl_name = CTL_UNNUMBERED,
226 .procname = "sched_granularity_ns",
227 .data = &sysctl_sched_granularity,
228 .maxlen = sizeof(unsigned int),
229 .mode = 0644,
230 .proc_handler = &proc_dointvec_minmax,
231 .strategy = &sysctl_intvec,
232 .extra1 = &min_sched_granularity_ns,
233 .extra2 = &max_sched_granularity_ns,
234 },
235 {
236 .ctl_name = CTL_UNNUMBERED,
237 .procname = "sched_wakeup_granularity_ns",
238 .data = &sysctl_sched_wakeup_granularity,
239 .maxlen = sizeof(unsigned int),
240 .mode = 0644,
241 .proc_handler = &proc_dointvec_minmax,
242 .strategy = &sysctl_intvec,
243 .extra1 = &min_wakeup_granularity_ns,
244 .extra2 = &max_wakeup_granularity_ns,
245 },
246 {
247 .ctl_name = CTL_UNNUMBERED,
248 .procname = "sched_batch_wakeup_granularity_ns",
249 .data = &sysctl_sched_batch_wakeup_granularity,
250 .maxlen = sizeof(unsigned int),
251 .mode = 0644,
252 .proc_handler = &proc_dointvec_minmax,
253 .strategy = &sysctl_intvec,
254 .extra1 = &min_wakeup_granularity_ns,
255 .extra2 = &max_wakeup_granularity_ns,
256 },
257 {
258 .ctl_name = CTL_UNNUMBERED,
259 .procname = "sched_stat_granularity_ns",
260 .data = &sysctl_sched_stat_granularity,
261 .maxlen = sizeof(unsigned int),
262 .mode = 0644,
263 .proc_handler = &proc_dointvec_minmax,
264 .strategy = &sysctl_intvec,
265 .extra1 = &min_wakeup_granularity_ns,
266 .extra2 = &max_wakeup_granularity_ns,
267 },
268 {
269 .ctl_name = CTL_UNNUMBERED,
270 .procname = "sched_runtime_limit_ns",
271 .data = &sysctl_sched_runtime_limit,
272 .maxlen = sizeof(unsigned int),
273 .mode = 0644,
274 .proc_handler = &proc_dointvec_minmax,
275 .strategy = &sysctl_intvec,
276 .extra1 = &min_sched_granularity_ns,
277 .extra2 = &max_sched_granularity_ns,
278 },
279 {
280 .ctl_name = CTL_UNNUMBERED,
281 .procname = "sched_child_runs_first",
282 .data = &sysctl_sched_child_runs_first,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
285 .proc_handler = &proc_dointvec,
286 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700287#ifdef CONFIG_PROVE_LOCKING
288 {
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "prove_locking",
291 .data = &prove_locking,
292 .maxlen = sizeof(int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec,
295 },
296#endif
297#ifdef CONFIG_LOCK_STAT
298 {
299 .ctl_name = CTL_UNNUMBERED,
300 .procname = "lock_stat",
301 .data = &lock_stat,
302 .maxlen = sizeof(int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
306#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200307 {
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "sched_features",
310 .data = &sysctl_sched_features,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = &proc_dointvec,
314 },
315#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 .ctl_name = KERN_PANIC,
318 .procname = "panic",
319 .data = &panic_timeout,
320 .maxlen = sizeof(int),
321 .mode = 0644,
322 .proc_handler = &proc_dointvec,
323 },
324 {
325 .ctl_name = KERN_CORE_USES_PID,
326 .procname = "core_uses_pid",
327 .data = &core_uses_pid,
328 .maxlen = sizeof(int),
329 .mode = 0644,
330 .proc_handler = &proc_dointvec,
331 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700332#ifdef CONFIG_AUDITSYSCALL
333 {
334 .ctl_name = CTL_UNNUMBERED,
335 .procname = "audit_argv_kb",
336 .data = &audit_argv_kb,
337 .maxlen = sizeof(int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 {
343 .ctl_name = KERN_CORE_PATTERN,
344 .procname = "core_pattern",
345 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700346 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 .mode = 0644,
348 .proc_handler = &proc_dostring,
349 .strategy = &sysctl_string,
350 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800351#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 {
353 .ctl_name = KERN_TAINTED,
354 .procname = "tainted",
355 .data = &tainted,
356 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800357 .mode = 0644,
358 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800360#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 {
362 .ctl_name = KERN_CAP_BSET,
363 .procname = "cap-bound",
364 .data = &cap_bset,
365 .maxlen = sizeof(kernel_cap_t),
366 .mode = 0600,
367 .proc_handler = &proc_dointvec_bset,
368 },
369#ifdef CONFIG_BLK_DEV_INITRD
370 {
371 .ctl_name = KERN_REALROOTDEV,
372 .procname = "real-root-dev",
373 .data = &real_root_dev,
374 .maxlen = sizeof(int),
375 .mode = 0644,
376 .proc_handler = &proc_dointvec,
377 },
378#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700379 {
380 .ctl_name = CTL_UNNUMBERED,
381 .procname = "print-fatal-signals",
382 .data = &print_fatal_signals,
383 .maxlen = sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
386 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387#ifdef __sparc__
388 {
389 .ctl_name = KERN_SPARC_REBOOT,
390 .procname = "reboot-cmd",
391 .data = reboot_command,
392 .maxlen = 256,
393 .mode = 0644,
394 .proc_handler = &proc_dostring,
395 .strategy = &sysctl_string,
396 },
397 {
398 .ctl_name = KERN_SPARC_STOP_A,
399 .procname = "stop-a",
400 .data = &stop_a_enabled,
401 .maxlen = sizeof (int),
402 .mode = 0644,
403 .proc_handler = &proc_dointvec,
404 },
405 {
406 .ctl_name = KERN_SPARC_SCONS_PWROFF,
407 .procname = "scons-poweroff",
408 .data = &scons_pwroff,
409 .maxlen = sizeof (int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
412 },
413#endif
414#ifdef __hppa__
415 {
416 .ctl_name = KERN_HPPA_PWRSW,
417 .procname = "soft-power",
418 .data = &pwrsw_enabled,
419 .maxlen = sizeof (int),
420 .mode = 0644,
421 .proc_handler = &proc_dointvec,
422 },
423 {
424 .ctl_name = KERN_HPPA_UNALIGNED,
425 .procname = "unaligned-trap",
426 .data = &unaligned_enabled,
427 .maxlen = sizeof (int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
431#endif
432 {
433 .ctl_name = KERN_CTLALTDEL,
434 .procname = "ctrl-alt-del",
435 .data = &C_A_D,
436 .maxlen = sizeof(int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
439 },
440 {
441 .ctl_name = KERN_PRINTK,
442 .procname = "printk",
443 .data = &console_loglevel,
444 .maxlen = 4*sizeof(int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
447 },
448#ifdef CONFIG_KMOD
449 {
450 .ctl_name = KERN_MODPROBE,
451 .procname = "modprobe",
452 .data = &modprobe_path,
453 .maxlen = KMOD_PATH_LEN,
454 .mode = 0644,
455 .proc_handler = &proc_dostring,
456 .strategy = &sysctl_string,
457 },
458#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700459#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 {
461 .ctl_name = KERN_HOTPLUG,
462 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100463 .data = &uevent_helper,
464 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .mode = 0644,
466 .proc_handler = &proc_dostring,
467 .strategy = &sysctl_string,
468 },
469#endif
470#ifdef CONFIG_CHR_DEV_SG
471 {
472 .ctl_name = KERN_SG_BIG_BUFF,
473 .procname = "sg-big-buff",
474 .data = &sg_big_buff,
475 .maxlen = sizeof (int),
476 .mode = 0444,
477 .proc_handler = &proc_dointvec,
478 },
479#endif
480#ifdef CONFIG_BSD_PROCESS_ACCT
481 {
482 .ctl_name = KERN_ACCT,
483 .procname = "acct",
484 .data = &acct_parm,
485 .maxlen = 3*sizeof(int),
486 .mode = 0644,
487 .proc_handler = &proc_dointvec,
488 },
489#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490#ifdef CONFIG_MAGIC_SYSRQ
491 {
492 .ctl_name = KERN_SYSRQ,
493 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800494 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .maxlen = sizeof (int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
498 },
499#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700500#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 {
502 .ctl_name = KERN_CADPID,
503 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700504 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .maxlen = sizeof (int),
506 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700507 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700509#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 {
511 .ctl_name = KERN_MAX_THREADS,
512 .procname = "threads-max",
513 .data = &max_threads,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = &proc_dointvec,
517 },
518 {
519 .ctl_name = KERN_RANDOM,
520 .procname = "random",
521 .mode = 0555,
522 .child = random_table,
523 },
524#ifdef CONFIG_UNIX98_PTYS
525 {
526 .ctl_name = KERN_PTY,
527 .procname = "pty",
528 .mode = 0555,
529 .child = pty_table,
530 },
531#endif
532 {
533 .ctl_name = KERN_OVERFLOWUID,
534 .procname = "overflowuid",
535 .data = &overflowuid,
536 .maxlen = sizeof(int),
537 .mode = 0644,
538 .proc_handler = &proc_dointvec_minmax,
539 .strategy = &sysctl_intvec,
540 .extra1 = &minolduid,
541 .extra2 = &maxolduid,
542 },
543 {
544 .ctl_name = KERN_OVERFLOWGID,
545 .procname = "overflowgid",
546 .data = &overflowgid,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = &proc_dointvec_minmax,
550 .strategy = &sysctl_intvec,
551 .extra1 = &minolduid,
552 .extra2 = &maxolduid,
553 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800554#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555#ifdef CONFIG_MATHEMU
556 {
557 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
558 .procname = "ieee_emulation_warnings",
559 .data = &sysctl_ieee_emulation_warnings,
560 .maxlen = sizeof(int),
561 .mode = 0644,
562 .proc_handler = &proc_dointvec,
563 },
564#endif
565#ifdef CONFIG_NO_IDLE_HZ
566 {
567 .ctl_name = KERN_HZ_TIMER,
568 .procname = "hz_timer",
569 .data = &sysctl_hz_timer,
570 .maxlen = sizeof(int),
571 .mode = 0644,
572 .proc_handler = &proc_dointvec,
573 },
574#endif
575 {
576 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
577 .procname = "userprocess_debug",
578 .data = &sysctl_userprocess_debug,
579 .maxlen = sizeof(int),
580 .mode = 0644,
581 .proc_handler = &proc_dointvec,
582 },
583#endif
584 {
585 .ctl_name = KERN_PIDMAX,
586 .procname = "pid_max",
587 .data = &pid_max,
588 .maxlen = sizeof (int),
589 .mode = 0644,
590 .proc_handler = &proc_dointvec_minmax,
591 .strategy = sysctl_intvec,
592 .extra1 = &pid_max_min,
593 .extra2 = &pid_max_max,
594 },
595 {
596 .ctl_name = KERN_PANIC_ON_OOPS,
597 .procname = "panic_on_oops",
598 .data = &panic_on_oops,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec,
602 },
603 {
604 .ctl_name = KERN_PRINTK_RATELIMIT,
605 .procname = "printk_ratelimit",
606 .data = &printk_ratelimit_jiffies,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec_jiffies,
610 .strategy = &sysctl_jiffies,
611 },
612 {
613 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
614 .procname = "printk_ratelimit_burst",
615 .data = &printk_ratelimit_burst,
616 .maxlen = sizeof(int),
617 .mode = 0644,
618 .proc_handler = &proc_dointvec,
619 },
620 {
621 .ctl_name = KERN_NGROUPS_MAX,
622 .procname = "ngroups_max",
623 .data = &ngroups_max,
624 .maxlen = sizeof (int),
625 .mode = 0444,
626 .proc_handler = &proc_dointvec,
627 },
628#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
629 {
630 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
631 .procname = "unknown_nmi_panic",
632 .data = &unknown_nmi_panic,
633 .maxlen = sizeof (int),
634 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200635 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 },
Don Zickus407984f2006-09-26 10:52:27 +0200637 {
638 .ctl_name = KERN_NMI_WATCHDOG,
639 .procname = "nmi_watchdog",
640 .data = &nmi_watchdog_enabled,
641 .maxlen = sizeof (int),
642 .mode = 0644,
643 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 },
645#endif
646#if defined(CONFIG_X86)
647 {
Don Zickus8da5add2006-09-26 10:52:27 +0200648 .ctl_name = KERN_PANIC_ON_NMI,
649 .procname = "panic_on_unrecovered_nmi",
650 .data = &panic_on_unrecovered_nmi,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec,
654 },
655 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 .ctl_name = KERN_BOOTLOADER_TYPE,
657 .procname = "bootloader_type",
658 .data = &bootloader_type,
659 .maxlen = sizeof (int),
660 .mode = 0444,
661 .proc_handler = &proc_dointvec,
662 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100663 {
664 .ctl_name = CTL_UNNUMBERED,
665 .procname = "kstack_depth_to_print",
666 .data = &kstack_depth_to_print,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = &proc_dointvec,
670 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800672#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 {
674 .ctl_name = KERN_RANDOMIZE,
675 .procname = "randomize_va_space",
676 .data = &randomize_va_space,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec,
680 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800681#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800682#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700683 {
684 .ctl_name = KERN_SPIN_RETRY,
685 .procname = "spin_retry",
686 .data = &spin_retry,
687 .maxlen = sizeof (int),
688 .mode = 0644,
689 .proc_handler = &proc_dointvec,
690 },
691#endif
Pavel Machekc255d842006-02-20 18:27:58 -0800692#ifdef CONFIG_ACPI_SLEEP
693 {
694 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
695 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700696 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800697 .maxlen = sizeof (unsigned long),
698 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800699 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800700 },
701#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800702#ifdef CONFIG_IA64
703 {
704 .ctl_name = KERN_IA64_UNALIGNED,
705 .procname = "ignore-unaligned-usertrap",
706 .data = &no_unaligned_warning,
707 .maxlen = sizeof (int),
708 .mode = 0644,
709 .proc_handler = &proc_dointvec,
710 },
711#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200712#ifdef CONFIG_COMPAT
713 {
714 .ctl_name = KERN_COMPAT_LOG,
715 .procname = "compat-log",
716 .data = &compat_log,
717 .maxlen = sizeof (int),
718 .mode = 0644,
719 .proc_handler = &proc_dointvec,
720 },
721#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700722#ifdef CONFIG_RT_MUTEXES
723 {
724 .ctl_name = KERN_MAX_LOCK_DEPTH,
725 .procname = "max_lock_depth",
726 .data = &max_lock_depth,
727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = &proc_dointvec,
730 },
731#endif
Kees Cook5096add2007-05-08 00:26:04 -0700732#ifdef CONFIG_PROC_FS
733 {
734 .ctl_name = CTL_UNNUMBERED,
735 .procname = "maps_protect",
736 .data = &maps_protect,
737 .maxlen = sizeof(int),
738 .mode = 0644,
739 .proc_handler = &proc_dointvec,
740 },
741#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700742 {
743 .ctl_name = CTL_UNNUMBERED,
744 .procname = "poweroff_cmd",
745 .data = &poweroff_cmd,
746 .maxlen = POWEROFF_CMD_PATH_LEN,
747 .mode = 0644,
748 .proc_handler = &proc_dostring,
749 .strategy = &sysctl_string,
750 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700751/*
752 * NOTE: do not add new entries to this table unless you have read
753 * Documentation/sysctl/ctl_unnumbered.txt
754 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 { .ctl_name = 0 }
756};
757
758/* Constants for minimum and maximum testing in vm_table.
759 We use these as one-element integer vectors. */
760static int zero;
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -0700761static int two = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762static int one_hundred = 100;
763
764
765static ctl_table vm_table[] = {
766 {
767 .ctl_name = VM_OVERCOMMIT_MEMORY,
768 .procname = "overcommit_memory",
769 .data = &sysctl_overcommit_memory,
770 .maxlen = sizeof(sysctl_overcommit_memory),
771 .mode = 0644,
772 .proc_handler = &proc_dointvec,
773 },
774 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700775 .ctl_name = VM_PANIC_ON_OOM,
776 .procname = "panic_on_oom",
777 .data = &sysctl_panic_on_oom,
778 .maxlen = sizeof(sysctl_panic_on_oom),
779 .mode = 0644,
780 .proc_handler = &proc_dointvec,
781 },
782 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 .ctl_name = VM_OVERCOMMIT_RATIO,
784 .procname = "overcommit_ratio",
785 .data = &sysctl_overcommit_ratio,
786 .maxlen = sizeof(sysctl_overcommit_ratio),
787 .mode = 0644,
788 .proc_handler = &proc_dointvec,
789 },
790 {
791 .ctl_name = VM_PAGE_CLUSTER,
792 .procname = "page-cluster",
793 .data = &page_cluster,
794 .maxlen = sizeof(int),
795 .mode = 0644,
796 .proc_handler = &proc_dointvec,
797 },
798 {
799 .ctl_name = VM_DIRTY_BACKGROUND,
800 .procname = "dirty_background_ratio",
801 .data = &dirty_background_ratio,
802 .maxlen = sizeof(dirty_background_ratio),
803 .mode = 0644,
804 .proc_handler = &proc_dointvec_minmax,
805 .strategy = &sysctl_intvec,
806 .extra1 = &zero,
807 .extra2 = &one_hundred,
808 },
809 {
810 .ctl_name = VM_DIRTY_RATIO,
811 .procname = "dirty_ratio",
812 .data = &vm_dirty_ratio,
813 .maxlen = sizeof(vm_dirty_ratio),
814 .mode = 0644,
815 .proc_handler = &proc_dointvec_minmax,
816 .strategy = &sysctl_intvec,
817 .extra1 = &zero,
818 .extra2 = &one_hundred,
819 },
820 {
821 .ctl_name = VM_DIRTY_WB_CS,
822 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800823 .data = &dirty_writeback_interval,
824 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 .mode = 0644,
826 .proc_handler = &dirty_writeback_centisecs_handler,
827 },
828 {
829 .ctl_name = VM_DIRTY_EXPIRE_CS,
830 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800831 .data = &dirty_expire_interval,
832 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800834 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 },
836 {
837 .ctl_name = VM_NR_PDFLUSH_THREADS,
838 .procname = "nr_pdflush_threads",
839 .data = &nr_pdflush_threads,
840 .maxlen = sizeof nr_pdflush_threads,
841 .mode = 0444 /* read-only*/,
842 .proc_handler = &proc_dointvec,
843 },
844 {
845 .ctl_name = VM_SWAPPINESS,
846 .procname = "swappiness",
847 .data = &vm_swappiness,
848 .maxlen = sizeof(vm_swappiness),
849 .mode = 0644,
850 .proc_handler = &proc_dointvec_minmax,
851 .strategy = &sysctl_intvec,
852 .extra1 = &zero,
853 .extra2 = &one_hundred,
854 },
855#ifdef CONFIG_HUGETLB_PAGE
856 {
857 .ctl_name = VM_HUGETLB_PAGES,
858 .procname = "nr_hugepages",
859 .data = &max_huge_pages,
860 .maxlen = sizeof(unsigned long),
861 .mode = 0644,
862 .proc_handler = &hugetlb_sysctl_handler,
863 .extra1 = (void *)&hugetlb_zero,
864 .extra2 = (void *)&hugetlb_infinity,
865 },
866 {
867 .ctl_name = VM_HUGETLB_GROUP,
868 .procname = "hugetlb_shm_group",
869 .data = &sysctl_hugetlb_shm_group,
870 .maxlen = sizeof(gid_t),
871 .mode = 0644,
872 .proc_handler = &proc_dointvec,
873 },
Mel Gorman396faf02007-07-17 04:03:13 -0700874 {
875 .ctl_name = CTL_UNNUMBERED,
876 .procname = "hugepages_treat_as_movable",
877 .data = &hugepages_treat_as_movable,
878 .maxlen = sizeof(int),
879 .mode = 0644,
880 .proc_handler = &hugetlb_treat_movable_handler,
881 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882#endif
883 {
884 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
885 .procname = "lowmem_reserve_ratio",
886 .data = &sysctl_lowmem_reserve_ratio,
887 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
888 .mode = 0644,
889 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
890 .strategy = &sysctl_intvec,
891 },
892 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800893 .ctl_name = VM_DROP_PAGECACHE,
894 .procname = "drop_caches",
895 .data = &sysctl_drop_caches,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = drop_caches_sysctl_handler,
899 .strategy = &sysctl_intvec,
900 },
901 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 .ctl_name = VM_MIN_FREE_KBYTES,
903 .procname = "min_free_kbytes",
904 .data = &min_free_kbytes,
905 .maxlen = sizeof(min_free_kbytes),
906 .mode = 0644,
907 .proc_handler = &min_free_kbytes_sysctl_handler,
908 .strategy = &sysctl_intvec,
909 .extra1 = &zero,
910 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800911 {
912 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
913 .procname = "percpu_pagelist_fraction",
914 .data = &percpu_pagelist_fraction,
915 .maxlen = sizeof(percpu_pagelist_fraction),
916 .mode = 0644,
917 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
918 .strategy = &sysctl_intvec,
919 .extra1 = &min_percpu_pagelist_fract,
920 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921#ifdef CONFIG_MMU
922 {
923 .ctl_name = VM_MAX_MAP_COUNT,
924 .procname = "max_map_count",
925 .data = &sysctl_max_map_count,
926 .maxlen = sizeof(sysctl_max_map_count),
927 .mode = 0644,
928 .proc_handler = &proc_dointvec
929 },
930#endif
931 {
932 .ctl_name = VM_LAPTOP_MODE,
933 .procname = "laptop_mode",
934 .data = &laptop_mode,
935 .maxlen = sizeof(laptop_mode),
936 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800937 .proc_handler = &proc_dointvec_jiffies,
938 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 },
940 {
941 .ctl_name = VM_BLOCK_DUMP,
942 .procname = "block_dump",
943 .data = &block_dump,
944 .maxlen = sizeof(block_dump),
945 .mode = 0644,
946 .proc_handler = &proc_dointvec,
947 .strategy = &sysctl_intvec,
948 .extra1 = &zero,
949 },
950 {
951 .ctl_name = VM_VFS_CACHE_PRESSURE,
952 .procname = "vfs_cache_pressure",
953 .data = &sysctl_vfs_cache_pressure,
954 .maxlen = sizeof(sysctl_vfs_cache_pressure),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec,
957 .strategy = &sysctl_intvec,
958 .extra1 = &zero,
959 },
960#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
961 {
962 .ctl_name = VM_LEGACY_VA_LAYOUT,
963 .procname = "legacy_va_layout",
964 .data = &sysctl_legacy_va_layout,
965 .maxlen = sizeof(sysctl_legacy_va_layout),
966 .mode = 0644,
967 .proc_handler = &proc_dointvec,
968 .strategy = &sysctl_intvec,
969 .extra1 = &zero,
970 },
971#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800972#ifdef CONFIG_NUMA
973 {
974 .ctl_name = VM_ZONE_RECLAIM_MODE,
975 .procname = "zone_reclaim_mode",
976 .data = &zone_reclaim_mode,
977 .maxlen = sizeof(zone_reclaim_mode),
978 .mode = 0644,
979 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -0800980 .strategy = &sysctl_intvec,
981 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -0800982 },
Christoph Lameter96146342006-07-03 00:24:13 -0700983 {
984 .ctl_name = VM_MIN_UNMAPPED,
985 .procname = "min_unmapped_ratio",
986 .data = &sysctl_min_unmapped_ratio,
987 .maxlen = sizeof(sysctl_min_unmapped_ratio),
988 .mode = 0644,
989 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
990 .strategy = &sysctl_intvec,
991 .extra1 = &zero,
992 .extra2 = &one_hundred,
993 },
Christoph Lameter0ff38492006-09-25 23:31:52 -0700994 {
995 .ctl_name = VM_MIN_SLAB,
996 .procname = "min_slab_ratio",
997 .data = &sysctl_min_slab_ratio,
998 .maxlen = sizeof(sysctl_min_slab_ratio),
999 .mode = 0644,
1000 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1001 .strategy = &sysctl_intvec,
1002 .extra1 = &zero,
1003 .extra2 = &one_hundred,
1004 },
Christoph Lameter17436602006-01-18 17:42:32 -08001005#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001006#ifdef CONFIG_SMP
1007 {
1008 .ctl_name = CTL_UNNUMBERED,
1009 .procname = "stat_interval",
1010 .data = &sysctl_stat_interval,
1011 .maxlen = sizeof(sysctl_stat_interval),
1012 .mode = 0644,
1013 .proc_handler = &proc_dointvec_jiffies,
1014 .strategy = &sysctl_jiffies,
1015 },
1016#endif
Eric Parised032182007-06-28 15:55:21 -04001017#ifdef CONFIG_SECURITY
1018 {
1019 .ctl_name = CTL_UNNUMBERED,
1020 .procname = "mmap_min_addr",
1021 .data = &mmap_min_addr,
1022 .maxlen = sizeof(unsigned long),
1023 .mode = 0644,
1024 .proc_handler = &proc_doulongvec_minmax,
1025 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001026#ifdef CONFIG_NUMA
1027 {
1028 .ctl_name = CTL_UNNUMBERED,
1029 .procname = "numa_zonelist_order",
1030 .data = &numa_zonelist_order,
1031 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1032 .mode = 0644,
1033 .proc_handler = &numa_zonelist_order_handler,
1034 .strategy = &sysctl_string,
1035 },
1036#endif
Eric Parised032182007-06-28 15:55:21 -04001037#endif
Paul Mundt5c36e652007-03-01 10:07:42 +09001038#if defined(CONFIG_X86_32) || \
1039 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001040 {
1041 .ctl_name = VM_VDSO_ENABLED,
1042 .procname = "vdso_enabled",
1043 .data = &vdso_enabled,
1044 .maxlen = sizeof(vdso_enabled),
1045 .mode = 0644,
1046 .proc_handler = &proc_dointvec,
1047 .strategy = &sysctl_intvec,
1048 .extra1 = &zero,
1049 },
1050#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001051/*
1052 * NOTE: do not add new entries to this table unless you have read
1053 * Documentation/sysctl/ctl_unnumbered.txt
1054 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 { .ctl_name = 0 }
1056};
1057
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001058#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1059static ctl_table binfmt_misc_table[] = {
1060 { .ctl_name = 0 }
1061};
1062#endif
1063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064static ctl_table fs_table[] = {
1065 {
1066 .ctl_name = FS_NRINODE,
1067 .procname = "inode-nr",
1068 .data = &inodes_stat,
1069 .maxlen = 2*sizeof(int),
1070 .mode = 0444,
1071 .proc_handler = &proc_dointvec,
1072 },
1073 {
1074 .ctl_name = FS_STATINODE,
1075 .procname = "inode-state",
1076 .data = &inodes_stat,
1077 .maxlen = 7*sizeof(int),
1078 .mode = 0444,
1079 .proc_handler = &proc_dointvec,
1080 },
1081 {
1082 .ctl_name = FS_NRFILE,
1083 .procname = "file-nr",
1084 .data = &files_stat,
1085 .maxlen = 3*sizeof(int),
1086 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001087 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 },
1089 {
1090 .ctl_name = FS_MAXFILE,
1091 .procname = "file-max",
1092 .data = &files_stat.max_files,
1093 .maxlen = sizeof(int),
1094 .mode = 0644,
1095 .proc_handler = &proc_dointvec,
1096 },
1097 {
1098 .ctl_name = FS_DENTRY,
1099 .procname = "dentry-state",
1100 .data = &dentry_stat,
1101 .maxlen = 6*sizeof(int),
1102 .mode = 0444,
1103 .proc_handler = &proc_dointvec,
1104 },
1105 {
1106 .ctl_name = FS_OVERFLOWUID,
1107 .procname = "overflowuid",
1108 .data = &fs_overflowuid,
1109 .maxlen = sizeof(int),
1110 .mode = 0644,
1111 .proc_handler = &proc_dointvec_minmax,
1112 .strategy = &sysctl_intvec,
1113 .extra1 = &minolduid,
1114 .extra2 = &maxolduid,
1115 },
1116 {
1117 .ctl_name = FS_OVERFLOWGID,
1118 .procname = "overflowgid",
1119 .data = &fs_overflowgid,
1120 .maxlen = sizeof(int),
1121 .mode = 0644,
1122 .proc_handler = &proc_dointvec_minmax,
1123 .strategy = &sysctl_intvec,
1124 .extra1 = &minolduid,
1125 .extra2 = &maxolduid,
1126 },
1127 {
1128 .ctl_name = FS_LEASES,
1129 .procname = "leases-enable",
1130 .data = &leases_enable,
1131 .maxlen = sizeof(int),
1132 .mode = 0644,
1133 .proc_handler = &proc_dointvec,
1134 },
1135#ifdef CONFIG_DNOTIFY
1136 {
1137 .ctl_name = FS_DIR_NOTIFY,
1138 .procname = "dir-notify-enable",
1139 .data = &dir_notify_enable,
1140 .maxlen = sizeof(int),
1141 .mode = 0644,
1142 .proc_handler = &proc_dointvec,
1143 },
1144#endif
1145#ifdef CONFIG_MMU
1146 {
1147 .ctl_name = FS_LEASE_TIME,
1148 .procname = "lease-break-time",
1149 .data = &lease_break_time,
1150 .maxlen = sizeof(int),
1151 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001152 .proc_handler = &proc_dointvec_minmax,
1153 .strategy = &sysctl_intvec,
1154 .extra1 = &zero,
1155 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 },
1157 {
1158 .ctl_name = FS_AIO_NR,
1159 .procname = "aio-nr",
1160 .data = &aio_nr,
1161 .maxlen = sizeof(aio_nr),
1162 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001163 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 },
1165 {
1166 .ctl_name = FS_AIO_MAX_NR,
1167 .procname = "aio-max-nr",
1168 .data = &aio_max_nr,
1169 .maxlen = sizeof(aio_max_nr),
1170 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001171 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001173#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001174 {
1175 .ctl_name = FS_INOTIFY,
1176 .procname = "inotify",
1177 .mode = 0555,
1178 .child = inotify_table,
1179 },
1180#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001182 {
1183 .ctl_name = KERN_SETUID_DUMPABLE,
1184 .procname = "suid_dumpable",
1185 .data = &suid_dumpable,
1186 .maxlen = sizeof(int),
1187 .mode = 0644,
1188 .proc_handler = &proc_dointvec,
1189 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001190#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1191 {
1192 .ctl_name = CTL_UNNUMBERED,
1193 .procname = "binfmt_misc",
1194 .mode = 0555,
1195 .child = binfmt_misc_table,
1196 },
1197#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001198/*
1199 * NOTE: do not add new entries to this table unless you have read
1200 * Documentation/sysctl/ctl_unnumbered.txt
1201 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 { .ctl_name = 0 }
1203};
1204
1205static ctl_table debug_table[] = {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001206#ifdef CONFIG_X86
1207 {
1208 .ctl_name = CTL_UNNUMBERED,
1209 .procname = "exception-trace",
1210 .data = &show_unhandled_signals,
1211 .maxlen = sizeof(int),
1212 .mode = 0644,
1213 .proc_handler = proc_dointvec
1214 },
1215#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 { .ctl_name = 0 }
1217};
1218
1219static ctl_table dev_table[] = {
1220 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001221};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
Al Viro330d57f2005-11-04 10:18:40 +00001223static DEFINE_SPINLOCK(sysctl_lock);
1224
1225/* called under sysctl_lock */
1226static int use_table(struct ctl_table_header *p)
1227{
1228 if (unlikely(p->unregistering))
1229 return 0;
1230 p->used++;
1231 return 1;
1232}
1233
1234/* called under sysctl_lock */
1235static void unuse_table(struct ctl_table_header *p)
1236{
1237 if (!--p->used)
1238 if (unlikely(p->unregistering))
1239 complete(p->unregistering);
1240}
1241
1242/* called under sysctl_lock, will reacquire if has to wait */
1243static void start_unregistering(struct ctl_table_header *p)
1244{
1245 /*
1246 * if p->used is 0, nobody will ever touch that entry again;
1247 * we'll eliminate all paths to it before dropping sysctl_lock
1248 */
1249 if (unlikely(p->used)) {
1250 struct completion wait;
1251 init_completion(&wait);
1252 p->unregistering = &wait;
1253 spin_unlock(&sysctl_lock);
1254 wait_for_completion(&wait);
1255 spin_lock(&sysctl_lock);
1256 }
1257 /*
1258 * do not remove from the list until nobody holds it; walking the
1259 * list in do_sysctl() relies on that.
1260 */
1261 list_del_init(&p->ctl_entry);
1262}
1263
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001264void sysctl_head_finish(struct ctl_table_header *head)
1265{
1266 if (!head)
1267 return;
1268 spin_lock(&sysctl_lock);
1269 unuse_table(head);
1270 spin_unlock(&sysctl_lock);
1271}
1272
1273struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1274{
1275 struct ctl_table_header *head;
1276 struct list_head *tmp;
1277 spin_lock(&sysctl_lock);
1278 if (prev) {
1279 tmp = &prev->ctl_entry;
1280 unuse_table(prev);
1281 goto next;
1282 }
1283 tmp = &root_table_header.ctl_entry;
1284 for (;;) {
1285 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1286
1287 if (!use_table(head))
1288 goto next;
1289 spin_unlock(&sysctl_lock);
1290 return head;
1291 next:
1292 tmp = tmp->next;
1293 if (tmp == &root_table_header.ctl_entry)
1294 break;
1295 }
1296 spin_unlock(&sysctl_lock);
1297 return NULL;
1298}
1299
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001300#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1302 void __user *newval, size_t newlen)
1303{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001304 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001305 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1308 return -ENOTDIR;
1309 if (oldval) {
1310 int old_len;
1311 if (!oldlenp || get_user(old_len, oldlenp))
1312 return -EFAULT;
1313 }
Al Viro330d57f2005-11-04 10:18:40 +00001314
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001315 for (head = sysctl_head_next(NULL); head;
1316 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001317 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001318 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001319 if (error != -ENOTDIR) {
1320 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001321 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001322 }
1323 }
Al Viro330d57f2005-11-04 10:18:40 +00001324 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325}
1326
1327asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1328{
1329 struct __sysctl_args tmp;
1330 int error;
1331
1332 if (copy_from_user(&tmp, args, sizeof(tmp)))
1333 return -EFAULT;
1334
1335 lock_kernel();
1336 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1337 tmp.newval, tmp.newlen);
1338 unlock_kernel();
1339 return error;
1340}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001341#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001344 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 * some sysctl variables are readonly even to root.
1346 */
1347
1348static int test_perm(int mode, int op)
1349{
1350 if (!current->euid)
1351 mode >>= 6;
1352 else if (in_egroup_p(0))
1353 mode >>= 3;
1354 if ((mode & op & 0007) == op)
1355 return 0;
1356 return -EACCES;
1357}
1358
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001359int sysctl_perm(ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
1361 int error;
1362 error = security_sysctl(table, op);
1363 if (error)
1364 return error;
1365 return test_perm(table->mode, op);
1366}
1367
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001368#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369static int parse_table(int __user *name, int nlen,
1370 void __user *oldval, size_t __user *oldlenp,
1371 void __user *newval, size_t newlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001372 ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373{
1374 int n;
1375repeat:
1376 if (!nlen)
1377 return -ENOTDIR;
1378 if (get_user(n, name))
1379 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001380 for ( ; table->ctl_name || table->procname; table++) {
1381 if (!table->ctl_name)
1382 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001383 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 int error;
1385 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001386 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 name++;
1389 nlen--;
1390 table = table->child;
1391 goto repeat;
1392 }
1393 error = do_sysctl_strategy(table, name, nlen,
1394 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001395 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 return error;
1397 }
1398 }
1399 return -ENOTDIR;
1400}
1401
1402/* Perform the actual read/write of a sysctl table entry. */
1403int do_sysctl_strategy (ctl_table *table,
1404 int __user *name, int nlen,
1405 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001406 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
1408 int op = 0, rc;
1409 size_t len;
1410
1411 if (oldval)
1412 op |= 004;
1413 if (newval)
1414 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001415 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 return -EPERM;
1417
1418 if (table->strategy) {
1419 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001420 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 if (rc < 0)
1422 return rc;
1423 if (rc > 0)
1424 return 0;
1425 }
1426
1427 /* If there is no strategy routine, or if the strategy returns
1428 * zero, proceed with automatic r/w */
1429 if (table->data && table->maxlen) {
1430 if (oldval && oldlenp) {
1431 if (get_user(len, oldlenp))
1432 return -EFAULT;
1433 if (len) {
1434 if (len > table->maxlen)
1435 len = table->maxlen;
1436 if(copy_to_user(oldval, table->data, len))
1437 return -EFAULT;
1438 if(put_user(len, oldlenp))
1439 return -EFAULT;
1440 }
1441 }
1442 if (newval && newlen) {
1443 len = newlen;
1444 if (len > table->maxlen)
1445 len = table->maxlen;
1446 if(copy_from_user(table->data, newval, len))
1447 return -EFAULT;
1448 }
1449 }
1450 return 0;
1451}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001452#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001454static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1455{
1456 for (; table->ctl_name || table->procname; table++) {
1457 table->parent = parent;
1458 if (table->child)
1459 sysctl_set_parent(table, table->child);
1460 }
1461}
1462
1463static __init int sysctl_init(void)
1464{
1465 sysctl_set_parent(NULL, root_table);
1466 return 0;
1467}
1468
1469core_initcall(sysctl_init);
1470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471/**
1472 * register_sysctl_table - register a sysctl hierarchy
1473 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 *
1475 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1476 * array. An entry with a ctl_name of 0 terminates the table.
1477 *
1478 * The members of the &ctl_table structure are used as follows:
1479 *
1480 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1481 * must be unique within that level of sysctl
1482 *
1483 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1484 * enter a sysctl file
1485 *
1486 * data - a pointer to data for use by proc_handler
1487 *
1488 * maxlen - the maximum size in bytes of the data
1489 *
1490 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1491 *
1492 * child - a pointer to the child sysctl table if this entry is a directory, or
1493 * %NULL.
1494 *
1495 * proc_handler - the text handler routine (described below)
1496 *
1497 * strategy - the strategy routine (described below)
1498 *
1499 * de - for internal use by the sysctl routines
1500 *
1501 * extra1, extra2 - extra pointers usable by the proc handler routines
1502 *
1503 * Leaf nodes in the sysctl tree will be represented by a single file
1504 * under /proc; non-leaf nodes will be represented by directories.
1505 *
1506 * sysctl(2) can automatically manage read and write requests through
1507 * the sysctl table. The data and maxlen fields of the ctl_table
1508 * struct enable minimal validation of the values being written to be
1509 * performed, and the mode field allows minimal authentication.
1510 *
1511 * More sophisticated management can be enabled by the provision of a
1512 * strategy routine with the table entry. This will be called before
1513 * any automatic read or write of the data is performed.
1514 *
1515 * The strategy routine may return
1516 *
1517 * < 0 - Error occurred (error is passed to user process)
1518 *
1519 * 0 - OK - proceed with automatic read or write.
1520 *
1521 * > 0 - OK - read or write has been done by the strategy routine, so
1522 * return immediately.
1523 *
1524 * There must be a proc_handler routine for any terminal nodes
1525 * mirrored under /proc/sys (non-terminals are handled by a built-in
1526 * directory handler). Several default handlers are available to
1527 * cover common cases -
1528 *
1529 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1530 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1531 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1532 *
1533 * It is the handler's job to read the input buffer from user memory
1534 * and process it. The handler should return 0 on success.
1535 *
1536 * This routine returns %NULL on a failure to register, and a pointer
1537 * to the table header on success.
1538 */
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001539struct ctl_table_header *register_sysctl_table(ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540{
1541 struct ctl_table_header *tmp;
1542 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1543 if (!tmp)
1544 return NULL;
1545 tmp->ctl_table = table;
1546 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001547 tmp->used = 0;
1548 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001549 sysctl_set_parent(NULL, table);
Al Viro330d57f2005-11-04 10:18:40 +00001550 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001551 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001552 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 return tmp;
1554}
1555
1556/**
1557 * unregister_sysctl_table - unregister a sysctl table hierarchy
1558 * @header: the header returned from register_sysctl_table
1559 *
1560 * Unregisters the sysctl table and all children. proc entries may not
1561 * actually be removed until they are no longer used by anyone.
1562 */
1563void unregister_sysctl_table(struct ctl_table_header * header)
1564{
Al Viro330d57f2005-11-04 10:18:40 +00001565 might_sleep();
1566 spin_lock(&sysctl_lock);
1567 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001568 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 kfree(header);
1570}
1571
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001572#else /* !CONFIG_SYSCTL */
Adrian Bunk93a6fef2007-02-28 20:12:23 -08001573struct ctl_table_header *register_sysctl_table(ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001574{
1575 return NULL;
1576}
1577
1578void unregister_sysctl_table(struct ctl_table_header * table)
1579{
1580}
1581
1582#endif /* CONFIG_SYSCTL */
1583
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584/*
1585 * /proc/sys support
1586 */
1587
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001588#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001590static int _proc_do_string(void* data, int maxlen, int write,
1591 struct file *filp, void __user *buffer,
1592 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001593{
1594 size_t len;
1595 char __user *p;
1596 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001597
1598 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001599 *lenp = 0;
1600 return 0;
1601 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001602
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001603 if (write) {
1604 len = 0;
1605 p = buffer;
1606 while (len < *lenp) {
1607 if (get_user(c, p++))
1608 return -EFAULT;
1609 if (c == 0 || c == '\n')
1610 break;
1611 len++;
1612 }
1613 if (len >= maxlen)
1614 len = maxlen-1;
1615 if(copy_from_user(data, buffer, len))
1616 return -EFAULT;
1617 ((char *) data)[len] = 0;
1618 *ppos += *lenp;
1619 } else {
1620 len = strlen(data);
1621 if (len > maxlen)
1622 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001623
1624 if (*ppos > len) {
1625 *lenp = 0;
1626 return 0;
1627 }
1628
1629 data += *ppos;
1630 len -= *ppos;
1631
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001632 if (len > *lenp)
1633 len = *lenp;
1634 if (len)
1635 if(copy_to_user(buffer, data, len))
1636 return -EFAULT;
1637 if (len < *lenp) {
1638 if(put_user('\n', ((char __user *) buffer) + len))
1639 return -EFAULT;
1640 len++;
1641 }
1642 *lenp = len;
1643 *ppos += len;
1644 }
1645 return 0;
1646}
1647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648/**
1649 * proc_dostring - read a string sysctl
1650 * @table: the sysctl table
1651 * @write: %TRUE if this is a write to the sysctl file
1652 * @filp: the file structure
1653 * @buffer: the user buffer
1654 * @lenp: the size of the user buffer
1655 * @ppos: file position
1656 *
1657 * Reads/writes a string from/to the user buffer. If the kernel
1658 * buffer provided is not large enough to hold the string, the
1659 * string is truncated. The copied string is %NULL-terminated.
1660 * If the string is being read by the user process, it is copied
1661 * and a newline '\n' is added. It is truncated if the buffer is
1662 * not large enough.
1663 *
1664 * Returns 0 on success.
1665 */
1666int proc_dostring(ctl_table *table, int write, struct file *filp,
1667 void __user *buffer, size_t *lenp, loff_t *ppos)
1668{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001669 return _proc_do_string(table->data, table->maxlen, write, filp,
1670 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671}
1672
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
1674static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1675 int *valp,
1676 int write, void *data)
1677{
1678 if (write) {
1679 *valp = *negp ? -*lvalp : *lvalp;
1680 } else {
1681 int val = *valp;
1682 if (val < 0) {
1683 *negp = -1;
1684 *lvalp = (unsigned long)-val;
1685 } else {
1686 *negp = 0;
1687 *lvalp = (unsigned long)val;
1688 }
1689 }
1690 return 0;
1691}
1692
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001693static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1694 int write, struct file *filp, void __user *buffer,
1695 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1697 int write, void *data),
1698 void *data)
1699{
1700#define TMPBUFLEN 21
1701 int *i, vleft, first=1, neg, val;
1702 unsigned long lval;
1703 size_t left, len;
1704
1705 char buf[TMPBUFLEN], *p;
1706 char __user *s = buffer;
1707
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001708 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 (*ppos && !write)) {
1710 *lenp = 0;
1711 return 0;
1712 }
1713
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001714 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 vleft = table->maxlen / sizeof(*i);
1716 left = *lenp;
1717
1718 if (!conv)
1719 conv = do_proc_dointvec_conv;
1720
1721 for (; left && vleft--; i++, first=0) {
1722 if (write) {
1723 while (left) {
1724 char c;
1725 if (get_user(c, s))
1726 return -EFAULT;
1727 if (!isspace(c))
1728 break;
1729 left--;
1730 s++;
1731 }
1732 if (!left)
1733 break;
1734 neg = 0;
1735 len = left;
1736 if (len > sizeof(buf) - 1)
1737 len = sizeof(buf) - 1;
1738 if (copy_from_user(buf, s, len))
1739 return -EFAULT;
1740 buf[len] = 0;
1741 p = buf;
1742 if (*p == '-' && left > 1) {
1743 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001744 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 }
1746 if (*p < '0' || *p > '9')
1747 break;
1748
1749 lval = simple_strtoul(p, &p, 0);
1750
1751 len = p-buf;
1752 if ((len < left) && *p && !isspace(*p))
1753 break;
1754 if (neg)
1755 val = -val;
1756 s += len;
1757 left -= len;
1758
1759 if (conv(&neg, &lval, i, 1, data))
1760 break;
1761 } else {
1762 p = buf;
1763 if (!first)
1764 *p++ = '\t';
1765
1766 if (conv(&neg, &lval, i, 0, data))
1767 break;
1768
1769 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1770 len = strlen(buf);
1771 if (len > left)
1772 len = left;
1773 if(copy_to_user(s, buf, len))
1774 return -EFAULT;
1775 left -= len;
1776 s += len;
1777 }
1778 }
1779
1780 if (!write && !first && left) {
1781 if(put_user('\n', s))
1782 return -EFAULT;
1783 left--, s++;
1784 }
1785 if (write) {
1786 while (left) {
1787 char c;
1788 if (get_user(c, s++))
1789 return -EFAULT;
1790 if (!isspace(c))
1791 break;
1792 left--;
1793 }
1794 }
1795 if (write && first)
1796 return -EINVAL;
1797 *lenp -= left;
1798 *ppos += *lenp;
1799 return 0;
1800#undef TMPBUFLEN
1801}
1802
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001803static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1804 void __user *buffer, size_t *lenp, loff_t *ppos,
1805 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1806 int write, void *data),
1807 void *data)
1808{
1809 return __do_proc_dointvec(table->data, table, write, filp,
1810 buffer, lenp, ppos, conv, data);
1811}
1812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813/**
1814 * proc_dointvec - read a vector of integers
1815 * @table: the sysctl table
1816 * @write: %TRUE if this is a write to the sysctl file
1817 * @filp: the file structure
1818 * @buffer: the user buffer
1819 * @lenp: the size of the user buffer
1820 * @ppos: file position
1821 *
1822 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1823 * values from/to the user buffer, treated as an ASCII string.
1824 *
1825 * Returns 0 on success.
1826 */
1827int proc_dointvec(ctl_table *table, int write, struct file *filp,
1828 void __user *buffer, size_t *lenp, loff_t *ppos)
1829{
1830 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1831 NULL,NULL);
1832}
1833
1834#define OP_SET 0
1835#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001836#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
1838static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1839 int *valp,
1840 int write, void *data)
1841{
1842 int op = *(int *)data;
1843 if (write) {
1844 int val = *negp ? -*lvalp : *lvalp;
1845 switch(op) {
1846 case OP_SET: *valp = val; break;
1847 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001848 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 }
1850 } else {
1851 int val = *valp;
1852 if (val < 0) {
1853 *negp = -1;
1854 *lvalp = (unsigned long)-val;
1855 } else {
1856 *negp = 0;
1857 *lvalp = (unsigned long)val;
1858 }
1859 }
1860 return 0;
1861}
1862
1863/*
1864 * init may raise the set.
1865 */
1866
1867int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1868 void __user *buffer, size_t *lenp, loff_t *ppos)
1869{
1870 int op;
1871
Eric Paris6ff1b442007-02-10 01:43:19 -08001872 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 return -EPERM;
1874 }
1875
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001876 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1878 do_proc_dointvec_bset_conv,&op);
1879}
1880
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001881/*
1882 * Taint values can only be increased
1883 */
1884static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1885 void __user *buffer, size_t *lenp, loff_t *ppos)
1886{
1887 int op;
1888
Bastian Blank91fcd412007-04-23 14:41:14 -07001889 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001890 return -EPERM;
1891
1892 op = OP_OR;
1893 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1894 do_proc_dointvec_bset_conv,&op);
1895}
1896
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897struct do_proc_dointvec_minmax_conv_param {
1898 int *min;
1899 int *max;
1900};
1901
1902static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1903 int *valp,
1904 int write, void *data)
1905{
1906 struct do_proc_dointvec_minmax_conv_param *param = data;
1907 if (write) {
1908 int val = *negp ? -*lvalp : *lvalp;
1909 if ((param->min && *param->min > val) ||
1910 (param->max && *param->max < val))
1911 return -EINVAL;
1912 *valp = val;
1913 } else {
1914 int val = *valp;
1915 if (val < 0) {
1916 *negp = -1;
1917 *lvalp = (unsigned long)-val;
1918 } else {
1919 *negp = 0;
1920 *lvalp = (unsigned long)val;
1921 }
1922 }
1923 return 0;
1924}
1925
1926/**
1927 * proc_dointvec_minmax - read a vector of integers with min/max values
1928 * @table: the sysctl table
1929 * @write: %TRUE if this is a write to the sysctl file
1930 * @filp: the file structure
1931 * @buffer: the user buffer
1932 * @lenp: the size of the user buffer
1933 * @ppos: file position
1934 *
1935 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1936 * values from/to the user buffer, treated as an ASCII string.
1937 *
1938 * This routine will ensure the values are within the range specified by
1939 * table->extra1 (min) and table->extra2 (max).
1940 *
1941 * Returns 0 on success.
1942 */
1943int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1944 void __user *buffer, size_t *lenp, loff_t *ppos)
1945{
1946 struct do_proc_dointvec_minmax_conv_param param = {
1947 .min = (int *) table->extra1,
1948 .max = (int *) table->extra2,
1949 };
1950 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1951 do_proc_dointvec_minmax_conv, &param);
1952}
1953
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001954static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 struct file *filp,
1956 void __user *buffer,
1957 size_t *lenp, loff_t *ppos,
1958 unsigned long convmul,
1959 unsigned long convdiv)
1960{
1961#define TMPBUFLEN 21
1962 unsigned long *i, *min, *max, val;
1963 int vleft, first=1, neg;
1964 size_t len, left;
1965 char buf[TMPBUFLEN], *p;
1966 char __user *s = buffer;
1967
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001968 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 (*ppos && !write)) {
1970 *lenp = 0;
1971 return 0;
1972 }
1973
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001974 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 min = (unsigned long *) table->extra1;
1976 max = (unsigned long *) table->extra2;
1977 vleft = table->maxlen / sizeof(unsigned long);
1978 left = *lenp;
1979
1980 for (; left && vleft--; i++, min++, max++, first=0) {
1981 if (write) {
1982 while (left) {
1983 char c;
1984 if (get_user(c, s))
1985 return -EFAULT;
1986 if (!isspace(c))
1987 break;
1988 left--;
1989 s++;
1990 }
1991 if (!left)
1992 break;
1993 neg = 0;
1994 len = left;
1995 if (len > TMPBUFLEN-1)
1996 len = TMPBUFLEN-1;
1997 if (copy_from_user(buf, s, len))
1998 return -EFAULT;
1999 buf[len] = 0;
2000 p = buf;
2001 if (*p == '-' && left > 1) {
2002 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002003 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 }
2005 if (*p < '0' || *p > '9')
2006 break;
2007 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2008 len = p-buf;
2009 if ((len < left) && *p && !isspace(*p))
2010 break;
2011 if (neg)
2012 val = -val;
2013 s += len;
2014 left -= len;
2015
2016 if(neg)
2017 continue;
2018 if ((min && val < *min) || (max && val > *max))
2019 continue;
2020 *i = val;
2021 } else {
2022 p = buf;
2023 if (!first)
2024 *p++ = '\t';
2025 sprintf(p, "%lu", convdiv * (*i) / convmul);
2026 len = strlen(buf);
2027 if (len > left)
2028 len = left;
2029 if(copy_to_user(s, buf, len))
2030 return -EFAULT;
2031 left -= len;
2032 s += len;
2033 }
2034 }
2035
2036 if (!write && !first && left) {
2037 if(put_user('\n', s))
2038 return -EFAULT;
2039 left--, s++;
2040 }
2041 if (write) {
2042 while (left) {
2043 char c;
2044 if (get_user(c, s++))
2045 return -EFAULT;
2046 if (!isspace(c))
2047 break;
2048 left--;
2049 }
2050 }
2051 if (write && first)
2052 return -EINVAL;
2053 *lenp -= left;
2054 *ppos += *lenp;
2055 return 0;
2056#undef TMPBUFLEN
2057}
2058
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002059static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2060 struct file *filp,
2061 void __user *buffer,
2062 size_t *lenp, loff_t *ppos,
2063 unsigned long convmul,
2064 unsigned long convdiv)
2065{
2066 return __do_proc_doulongvec_minmax(table->data, table, write,
2067 filp, buffer, lenp, ppos, convmul, convdiv);
2068}
2069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070/**
2071 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2072 * @table: the sysctl table
2073 * @write: %TRUE if this is a write to the sysctl file
2074 * @filp: the file structure
2075 * @buffer: the user buffer
2076 * @lenp: the size of the user buffer
2077 * @ppos: file position
2078 *
2079 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2080 * values from/to the user buffer, treated as an ASCII string.
2081 *
2082 * This routine will ensure the values are within the range specified by
2083 * table->extra1 (min) and table->extra2 (max).
2084 *
2085 * Returns 0 on success.
2086 */
2087int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2088 void __user *buffer, size_t *lenp, loff_t *ppos)
2089{
2090 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2091}
2092
2093/**
2094 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2095 * @table: the sysctl table
2096 * @write: %TRUE if this is a write to the sysctl file
2097 * @filp: the file structure
2098 * @buffer: the user buffer
2099 * @lenp: the size of the user buffer
2100 * @ppos: file position
2101 *
2102 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2103 * values from/to the user buffer, treated as an ASCII string. The values
2104 * are treated as milliseconds, and converted to jiffies when they are stored.
2105 *
2106 * This routine will ensure the values are within the range specified by
2107 * table->extra1 (min) and table->extra2 (max).
2108 *
2109 * Returns 0 on success.
2110 */
2111int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2112 struct file *filp,
2113 void __user *buffer,
2114 size_t *lenp, loff_t *ppos)
2115{
2116 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2117 lenp, ppos, HZ, 1000l);
2118}
2119
2120
2121static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2122 int *valp,
2123 int write, void *data)
2124{
2125 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002126 if (*lvalp > LONG_MAX / HZ)
2127 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2129 } else {
2130 int val = *valp;
2131 unsigned long lval;
2132 if (val < 0) {
2133 *negp = -1;
2134 lval = (unsigned long)-val;
2135 } else {
2136 *negp = 0;
2137 lval = (unsigned long)val;
2138 }
2139 *lvalp = lval / HZ;
2140 }
2141 return 0;
2142}
2143
2144static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2145 int *valp,
2146 int write, void *data)
2147{
2148 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002149 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2150 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2152 } else {
2153 int val = *valp;
2154 unsigned long lval;
2155 if (val < 0) {
2156 *negp = -1;
2157 lval = (unsigned long)-val;
2158 } else {
2159 *negp = 0;
2160 lval = (unsigned long)val;
2161 }
2162 *lvalp = jiffies_to_clock_t(lval);
2163 }
2164 return 0;
2165}
2166
2167static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2168 int *valp,
2169 int write, void *data)
2170{
2171 if (write) {
2172 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2173 } else {
2174 int val = *valp;
2175 unsigned long lval;
2176 if (val < 0) {
2177 *negp = -1;
2178 lval = (unsigned long)-val;
2179 } else {
2180 *negp = 0;
2181 lval = (unsigned long)val;
2182 }
2183 *lvalp = jiffies_to_msecs(lval);
2184 }
2185 return 0;
2186}
2187
2188/**
2189 * proc_dointvec_jiffies - read a vector of integers as seconds
2190 * @table: the sysctl table
2191 * @write: %TRUE if this is a write to the sysctl file
2192 * @filp: the file structure
2193 * @buffer: the user buffer
2194 * @lenp: the size of the user buffer
2195 * @ppos: file position
2196 *
2197 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2198 * values from/to the user buffer, treated as an ASCII string.
2199 * The values read are assumed to be in seconds, and are converted into
2200 * jiffies.
2201 *
2202 * Returns 0 on success.
2203 */
2204int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2205 void __user *buffer, size_t *lenp, loff_t *ppos)
2206{
2207 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2208 do_proc_dointvec_jiffies_conv,NULL);
2209}
2210
2211/**
2212 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2213 * @table: the sysctl table
2214 * @write: %TRUE if this is a write to the sysctl file
2215 * @filp: the file structure
2216 * @buffer: the user buffer
2217 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002218 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 *
2220 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2221 * values from/to the user buffer, treated as an ASCII string.
2222 * The values read are assumed to be in 1/USER_HZ seconds, and
2223 * are converted into jiffies.
2224 *
2225 * Returns 0 on success.
2226 */
2227int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2228 void __user *buffer, size_t *lenp, loff_t *ppos)
2229{
2230 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2231 do_proc_dointvec_userhz_jiffies_conv,NULL);
2232}
2233
2234/**
2235 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2236 * @table: the sysctl table
2237 * @write: %TRUE if this is a write to the sysctl file
2238 * @filp: the file structure
2239 * @buffer: the user buffer
2240 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002241 * @ppos: file position
2242 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 *
2244 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2245 * values from/to the user buffer, treated as an ASCII string.
2246 * The values read are assumed to be in 1/1000 seconds, and
2247 * are converted into jiffies.
2248 *
2249 * Returns 0 on success.
2250 */
2251int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2252 void __user *buffer, size_t *lenp, loff_t *ppos)
2253{
2254 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2255 do_proc_dointvec_ms_jiffies_conv, NULL);
2256}
2257
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002258static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2259 void __user *buffer, size_t *lenp, loff_t *ppos)
2260{
2261 struct pid *new_pid;
2262 pid_t tmp;
2263 int r;
2264
2265 tmp = pid_nr(cad_pid);
2266
2267 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2268 lenp, ppos, NULL, NULL);
2269 if (r || !write)
2270 return r;
2271
2272 new_pid = find_get_pid(tmp);
2273 if (!new_pid)
2274 return -ESRCH;
2275
2276 put_pid(xchg(&cad_pid, new_pid));
2277 return 0;
2278}
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280#else /* CONFIG_PROC_FS */
2281
2282int proc_dostring(ctl_table *table, int write, struct file *filp,
2283 void __user *buffer, size_t *lenp, loff_t *ppos)
2284{
2285 return -ENOSYS;
2286}
2287
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288int proc_dointvec(ctl_table *table, int write, struct file *filp,
2289 void __user *buffer, size_t *lenp, loff_t *ppos)
2290{
2291 return -ENOSYS;
2292}
2293
2294int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2295 void __user *buffer, size_t *lenp, loff_t *ppos)
2296{
2297 return -ENOSYS;
2298}
2299
2300int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2301 void __user *buffer, size_t *lenp, loff_t *ppos)
2302{
2303 return -ENOSYS;
2304}
2305
2306int proc_dointvec_jiffies(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_userhz_jiffies(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_ms_jiffies(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_doulongvec_minmax(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_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2331 struct file *filp,
2332 void __user *buffer,
2333 size_t *lenp, loff_t *ppos)
2334{
2335 return -ENOSYS;
2336}
2337
2338
2339#endif /* CONFIG_PROC_FS */
2340
2341
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002342#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343/*
2344 * General sysctl support routines
2345 */
2346
2347/* The generic string strategy routine: */
2348int sysctl_string(ctl_table *table, int __user *name, int nlen,
2349 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002350 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 if (!table->data || !table->maxlen)
2353 return -ENOTDIR;
2354
2355 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002356 size_t bufsize;
2357 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002359 if (bufsize) {
2360 size_t len = strlen(table->data), copied;
2361
2362 /* This shouldn't trigger for a well-formed sysctl */
2363 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002365
2366 /* Copy up to a max of bufsize-1 bytes of the string */
2367 copied = (len >= bufsize) ? bufsize - 1 : len;
2368
2369 if (copy_to_user(oldval, table->data, copied) ||
2370 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002372 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 return -EFAULT;
2374 }
2375 }
2376 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002377 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 if (len > table->maxlen)
2379 len = table->maxlen;
2380 if(copy_from_user(table->data, newval, len))
2381 return -EFAULT;
2382 if (len == table->maxlen)
2383 len--;
2384 ((char *) table->data)[len] = 0;
2385 }
Yi Yang82c9df82005-12-30 16:37:10 +08002386 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387}
2388
2389/*
2390 * This function makes sure that all of the integers in the vector
2391 * are between the minimum and maximum values given in the arrays
2392 * table->extra1 and table->extra2, respectively.
2393 */
2394int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2395 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002396 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
2398
2399 if (newval && newlen) {
2400 int __user *vec = (int __user *) newval;
2401 int *min = (int *) table->extra1;
2402 int *max = (int *) table->extra2;
2403 size_t length;
2404 int i;
2405
2406 if (newlen % sizeof(int) != 0)
2407 return -EINVAL;
2408
2409 if (!table->extra1 && !table->extra2)
2410 return 0;
2411
2412 if (newlen > table->maxlen)
2413 newlen = table->maxlen;
2414 length = newlen / sizeof(int);
2415
2416 for (i = 0; i < length; i++) {
2417 int value;
2418 if (get_user(value, vec + i))
2419 return -EFAULT;
2420 if (min && value < min[i])
2421 return -EINVAL;
2422 if (max && value > max[i])
2423 return -EINVAL;
2424 }
2425 }
2426 return 0;
2427}
2428
2429/* Strategy function to convert jiffies to seconds */
2430int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2431 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002432 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002434 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002436
2437 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002439 if (olen) {
2440 int val;
2441
2442 if (olen < sizeof(int))
2443 return -EINVAL;
2444
2445 val = *(int *)(table->data) / HZ;
2446 if (put_user(val, (int __user *)oldval))
2447 return -EFAULT;
2448 if (put_user(sizeof(int), oldlenp))
2449 return -EFAULT;
2450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 }
2452 if (newval && newlen) {
2453 int new;
2454 if (newlen != sizeof(int))
2455 return -EINVAL;
2456 if (get_user(new, (int __user *)newval))
2457 return -EFAULT;
2458 *(int *)(table->data) = new*HZ;
2459 }
2460 return 1;
2461}
2462
2463/* Strategy function to convert jiffies to seconds */
2464int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2465 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002466 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002468 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002470
2471 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002473 if (olen) {
2474 int val;
2475
2476 if (olen < sizeof(int))
2477 return -EINVAL;
2478
2479 val = jiffies_to_msecs(*(int *)(table->data));
2480 if (put_user(val, (int __user *)oldval))
2481 return -EFAULT;
2482 if (put_user(sizeof(int), oldlenp))
2483 return -EFAULT;
2484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 }
2486 if (newval && newlen) {
2487 int new;
2488 if (newlen != sizeof(int))
2489 return -EINVAL;
2490 if (get_user(new, (int __user *)newval))
2491 return -EFAULT;
2492 *(int *)(table->data) = msecs_to_jiffies(new);
2493 }
2494 return 1;
2495}
2496
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002497
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002498
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002499#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500
2501
2502asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2503{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002504 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002505 struct __sysctl_args tmp;
2506 int name[CTL_MAXNAME];
2507 int i;
2508
2509 /* Read in the sysctl name for better debug message logging */
2510 if (copy_from_user(&tmp, args, sizeof(tmp)))
2511 return -EFAULT;
2512 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2513 return -ENOTDIR;
2514 for (i = 0; i < tmp.nlen; i++)
2515 if (get_user(name[i], tmp.name + i))
2516 return -EFAULT;
2517
2518 /* Ignore accesses to kernel.version */
2519 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2520 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002521
2522 if (msg_count < 5) {
2523 msg_count++;
2524 printk(KERN_INFO
2525 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002526 "system call with ", current->comm);
2527 for (i = 0; i < tmp.nlen; i++)
2528 printk("%d.", name[i]);
2529 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002530 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002531out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 return -ENOSYS;
2533}
2534
2535int sysctl_string(ctl_table *table, int __user *name, int nlen,
2536 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002537 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538{
2539 return -ENOSYS;
2540}
2541
2542int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2543 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002544 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545{
2546 return -ENOSYS;
2547}
2548
2549int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2550 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002551 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
2553 return -ENOSYS;
2554}
2555
2556int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2557 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002558 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559{
2560 return -ENOSYS;
2561}
2562
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002563#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
2565/*
2566 * No sense putting this after each symbol definition, twice,
2567 * exception granted :-)
2568 */
2569EXPORT_SYMBOL(proc_dointvec);
2570EXPORT_SYMBOL(proc_dointvec_jiffies);
2571EXPORT_SYMBOL(proc_dointvec_minmax);
2572EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2573EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2574EXPORT_SYMBOL(proc_dostring);
2575EXPORT_SYMBOL(proc_doulongvec_minmax);
2576EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2577EXPORT_SYMBOL(register_sysctl_table);
2578EXPORT_SYMBOL(sysctl_intvec);
2579EXPORT_SYMBOL(sysctl_jiffies);
2580EXPORT_SYMBOL(sysctl_ms_jiffies);
2581EXPORT_SYMBOL(sysctl_string);
2582EXPORT_SYMBOL(unregister_sysctl_table);