blob: e69179b1809ca31b9e302060baeba7d408193711 [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 },
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 { .ctl_name = 0 }
753};
754
755/* Constants for minimum and maximum testing in vm_table.
756 We use these as one-element integer vectors. */
757static int zero;
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -0700758static int two = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759static int one_hundred = 100;
760
761
762static ctl_table vm_table[] = {
763 {
764 .ctl_name = VM_OVERCOMMIT_MEMORY,
765 .procname = "overcommit_memory",
766 .data = &sysctl_overcommit_memory,
767 .maxlen = sizeof(sysctl_overcommit_memory),
768 .mode = 0644,
769 .proc_handler = &proc_dointvec,
770 },
771 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700772 .ctl_name = VM_PANIC_ON_OOM,
773 .procname = "panic_on_oom",
774 .data = &sysctl_panic_on_oom,
775 .maxlen = sizeof(sysctl_panic_on_oom),
776 .mode = 0644,
777 .proc_handler = &proc_dointvec,
778 },
779 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 .ctl_name = VM_OVERCOMMIT_RATIO,
781 .procname = "overcommit_ratio",
782 .data = &sysctl_overcommit_ratio,
783 .maxlen = sizeof(sysctl_overcommit_ratio),
784 .mode = 0644,
785 .proc_handler = &proc_dointvec,
786 },
787 {
788 .ctl_name = VM_PAGE_CLUSTER,
789 .procname = "page-cluster",
790 .data = &page_cluster,
791 .maxlen = sizeof(int),
792 .mode = 0644,
793 .proc_handler = &proc_dointvec,
794 },
795 {
796 .ctl_name = VM_DIRTY_BACKGROUND,
797 .procname = "dirty_background_ratio",
798 .data = &dirty_background_ratio,
799 .maxlen = sizeof(dirty_background_ratio),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec_minmax,
802 .strategy = &sysctl_intvec,
803 .extra1 = &zero,
804 .extra2 = &one_hundred,
805 },
806 {
807 .ctl_name = VM_DIRTY_RATIO,
808 .procname = "dirty_ratio",
809 .data = &vm_dirty_ratio,
810 .maxlen = sizeof(vm_dirty_ratio),
811 .mode = 0644,
812 .proc_handler = &proc_dointvec_minmax,
813 .strategy = &sysctl_intvec,
814 .extra1 = &zero,
815 .extra2 = &one_hundred,
816 },
817 {
818 .ctl_name = VM_DIRTY_WB_CS,
819 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800820 .data = &dirty_writeback_interval,
821 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 .mode = 0644,
823 .proc_handler = &dirty_writeback_centisecs_handler,
824 },
825 {
826 .ctl_name = VM_DIRTY_EXPIRE_CS,
827 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800828 .data = &dirty_expire_interval,
829 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800831 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 },
833 {
834 .ctl_name = VM_NR_PDFLUSH_THREADS,
835 .procname = "nr_pdflush_threads",
836 .data = &nr_pdflush_threads,
837 .maxlen = sizeof nr_pdflush_threads,
838 .mode = 0444 /* read-only*/,
839 .proc_handler = &proc_dointvec,
840 },
841 {
842 .ctl_name = VM_SWAPPINESS,
843 .procname = "swappiness",
844 .data = &vm_swappiness,
845 .maxlen = sizeof(vm_swappiness),
846 .mode = 0644,
847 .proc_handler = &proc_dointvec_minmax,
848 .strategy = &sysctl_intvec,
849 .extra1 = &zero,
850 .extra2 = &one_hundred,
851 },
852#ifdef CONFIG_HUGETLB_PAGE
853 {
854 .ctl_name = VM_HUGETLB_PAGES,
855 .procname = "nr_hugepages",
856 .data = &max_huge_pages,
857 .maxlen = sizeof(unsigned long),
858 .mode = 0644,
859 .proc_handler = &hugetlb_sysctl_handler,
860 .extra1 = (void *)&hugetlb_zero,
861 .extra2 = (void *)&hugetlb_infinity,
862 },
863 {
864 .ctl_name = VM_HUGETLB_GROUP,
865 .procname = "hugetlb_shm_group",
866 .data = &sysctl_hugetlb_shm_group,
867 .maxlen = sizeof(gid_t),
868 .mode = 0644,
869 .proc_handler = &proc_dointvec,
870 },
Mel Gorman396faf02007-07-17 04:03:13 -0700871 {
872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "hugepages_treat_as_movable",
874 .data = &hugepages_treat_as_movable,
875 .maxlen = sizeof(int),
876 .mode = 0644,
877 .proc_handler = &hugetlb_treat_movable_handler,
878 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879#endif
880 {
881 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
882 .procname = "lowmem_reserve_ratio",
883 .data = &sysctl_lowmem_reserve_ratio,
884 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
885 .mode = 0644,
886 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
887 .strategy = &sysctl_intvec,
888 },
889 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800890 .ctl_name = VM_DROP_PAGECACHE,
891 .procname = "drop_caches",
892 .data = &sysctl_drop_caches,
893 .maxlen = sizeof(int),
894 .mode = 0644,
895 .proc_handler = drop_caches_sysctl_handler,
896 .strategy = &sysctl_intvec,
897 },
898 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 .ctl_name = VM_MIN_FREE_KBYTES,
900 .procname = "min_free_kbytes",
901 .data = &min_free_kbytes,
902 .maxlen = sizeof(min_free_kbytes),
903 .mode = 0644,
904 .proc_handler = &min_free_kbytes_sysctl_handler,
905 .strategy = &sysctl_intvec,
906 .extra1 = &zero,
907 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800908 {
909 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
910 .procname = "percpu_pagelist_fraction",
911 .data = &percpu_pagelist_fraction,
912 .maxlen = sizeof(percpu_pagelist_fraction),
913 .mode = 0644,
914 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
915 .strategy = &sysctl_intvec,
916 .extra1 = &min_percpu_pagelist_fract,
917 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918#ifdef CONFIG_MMU
919 {
920 .ctl_name = VM_MAX_MAP_COUNT,
921 .procname = "max_map_count",
922 .data = &sysctl_max_map_count,
923 .maxlen = sizeof(sysctl_max_map_count),
924 .mode = 0644,
925 .proc_handler = &proc_dointvec
926 },
927#endif
928 {
929 .ctl_name = VM_LAPTOP_MODE,
930 .procname = "laptop_mode",
931 .data = &laptop_mode,
932 .maxlen = sizeof(laptop_mode),
933 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800934 .proc_handler = &proc_dointvec_jiffies,
935 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 },
937 {
938 .ctl_name = VM_BLOCK_DUMP,
939 .procname = "block_dump",
940 .data = &block_dump,
941 .maxlen = sizeof(block_dump),
942 .mode = 0644,
943 .proc_handler = &proc_dointvec,
944 .strategy = &sysctl_intvec,
945 .extra1 = &zero,
946 },
947 {
948 .ctl_name = VM_VFS_CACHE_PRESSURE,
949 .procname = "vfs_cache_pressure",
950 .data = &sysctl_vfs_cache_pressure,
951 .maxlen = sizeof(sysctl_vfs_cache_pressure),
952 .mode = 0644,
953 .proc_handler = &proc_dointvec,
954 .strategy = &sysctl_intvec,
955 .extra1 = &zero,
956 },
957#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
958 {
959 .ctl_name = VM_LEGACY_VA_LAYOUT,
960 .procname = "legacy_va_layout",
961 .data = &sysctl_legacy_va_layout,
962 .maxlen = sizeof(sysctl_legacy_va_layout),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 .strategy = &sysctl_intvec,
966 .extra1 = &zero,
967 },
968#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800969#ifdef CONFIG_NUMA
970 {
971 .ctl_name = VM_ZONE_RECLAIM_MODE,
972 .procname = "zone_reclaim_mode",
973 .data = &zone_reclaim_mode,
974 .maxlen = sizeof(zone_reclaim_mode),
975 .mode = 0644,
976 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -0800977 .strategy = &sysctl_intvec,
978 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -0800979 },
Christoph Lameter96146342006-07-03 00:24:13 -0700980 {
981 .ctl_name = VM_MIN_UNMAPPED,
982 .procname = "min_unmapped_ratio",
983 .data = &sysctl_min_unmapped_ratio,
984 .maxlen = sizeof(sysctl_min_unmapped_ratio),
985 .mode = 0644,
986 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
987 .strategy = &sysctl_intvec,
988 .extra1 = &zero,
989 .extra2 = &one_hundred,
990 },
Christoph Lameter0ff38492006-09-25 23:31:52 -0700991 {
992 .ctl_name = VM_MIN_SLAB,
993 .procname = "min_slab_ratio",
994 .data = &sysctl_min_slab_ratio,
995 .maxlen = sizeof(sysctl_min_slab_ratio),
996 .mode = 0644,
997 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
998 .strategy = &sysctl_intvec,
999 .extra1 = &zero,
1000 .extra2 = &one_hundred,
1001 },
Christoph Lameter17436602006-01-18 17:42:32 -08001002#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001003#ifdef CONFIG_SMP
1004 {
1005 .ctl_name = CTL_UNNUMBERED,
1006 .procname = "stat_interval",
1007 .data = &sysctl_stat_interval,
1008 .maxlen = sizeof(sysctl_stat_interval),
1009 .mode = 0644,
1010 .proc_handler = &proc_dointvec_jiffies,
1011 .strategy = &sysctl_jiffies,
1012 },
1013#endif
Eric Parised032182007-06-28 15:55:21 -04001014#ifdef CONFIG_SECURITY
1015 {
1016 .ctl_name = CTL_UNNUMBERED,
1017 .procname = "mmap_min_addr",
1018 .data = &mmap_min_addr,
1019 .maxlen = sizeof(unsigned long),
1020 .mode = 0644,
1021 .proc_handler = &proc_doulongvec_minmax,
1022 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001023#ifdef CONFIG_NUMA
1024 {
1025 .ctl_name = CTL_UNNUMBERED,
1026 .procname = "numa_zonelist_order",
1027 .data = &numa_zonelist_order,
1028 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1029 .mode = 0644,
1030 .proc_handler = &numa_zonelist_order_handler,
1031 .strategy = &sysctl_string,
1032 },
1033#endif
Eric Parised032182007-06-28 15:55:21 -04001034#endif
Paul Mundt5c36e652007-03-01 10:07:42 +09001035#if defined(CONFIG_X86_32) || \
1036 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001037 {
1038 .ctl_name = VM_VDSO_ENABLED,
1039 .procname = "vdso_enabled",
1040 .data = &vdso_enabled,
1041 .maxlen = sizeof(vdso_enabled),
1042 .mode = 0644,
1043 .proc_handler = &proc_dointvec,
1044 .strategy = &sysctl_intvec,
1045 .extra1 = &zero,
1046 },
1047#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001048/*
1049 * NOTE: do not add new entries to this table unless you have read
1050 * Documentation/sysctl/ctl_unnumbered.txt
1051 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 { .ctl_name = 0 }
1053};
1054
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001055#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1056static ctl_table binfmt_misc_table[] = {
1057 { .ctl_name = 0 }
1058};
1059#endif
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061static ctl_table fs_table[] = {
1062 {
1063 .ctl_name = FS_NRINODE,
1064 .procname = "inode-nr",
1065 .data = &inodes_stat,
1066 .maxlen = 2*sizeof(int),
1067 .mode = 0444,
1068 .proc_handler = &proc_dointvec,
1069 },
1070 {
1071 .ctl_name = FS_STATINODE,
1072 .procname = "inode-state",
1073 .data = &inodes_stat,
1074 .maxlen = 7*sizeof(int),
1075 .mode = 0444,
1076 .proc_handler = &proc_dointvec,
1077 },
1078 {
1079 .ctl_name = FS_NRFILE,
1080 .procname = "file-nr",
1081 .data = &files_stat,
1082 .maxlen = 3*sizeof(int),
1083 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001084 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 },
1086 {
1087 .ctl_name = FS_MAXFILE,
1088 .procname = "file-max",
1089 .data = &files_stat.max_files,
1090 .maxlen = sizeof(int),
1091 .mode = 0644,
1092 .proc_handler = &proc_dointvec,
1093 },
1094 {
1095 .ctl_name = FS_DENTRY,
1096 .procname = "dentry-state",
1097 .data = &dentry_stat,
1098 .maxlen = 6*sizeof(int),
1099 .mode = 0444,
1100 .proc_handler = &proc_dointvec,
1101 },
1102 {
1103 .ctl_name = FS_OVERFLOWUID,
1104 .procname = "overflowuid",
1105 .data = &fs_overflowuid,
1106 .maxlen = sizeof(int),
1107 .mode = 0644,
1108 .proc_handler = &proc_dointvec_minmax,
1109 .strategy = &sysctl_intvec,
1110 .extra1 = &minolduid,
1111 .extra2 = &maxolduid,
1112 },
1113 {
1114 .ctl_name = FS_OVERFLOWGID,
1115 .procname = "overflowgid",
1116 .data = &fs_overflowgid,
1117 .maxlen = sizeof(int),
1118 .mode = 0644,
1119 .proc_handler = &proc_dointvec_minmax,
1120 .strategy = &sysctl_intvec,
1121 .extra1 = &minolduid,
1122 .extra2 = &maxolduid,
1123 },
1124 {
1125 .ctl_name = FS_LEASES,
1126 .procname = "leases-enable",
1127 .data = &leases_enable,
1128 .maxlen = sizeof(int),
1129 .mode = 0644,
1130 .proc_handler = &proc_dointvec,
1131 },
1132#ifdef CONFIG_DNOTIFY
1133 {
1134 .ctl_name = FS_DIR_NOTIFY,
1135 .procname = "dir-notify-enable",
1136 .data = &dir_notify_enable,
1137 .maxlen = sizeof(int),
1138 .mode = 0644,
1139 .proc_handler = &proc_dointvec,
1140 },
1141#endif
1142#ifdef CONFIG_MMU
1143 {
1144 .ctl_name = FS_LEASE_TIME,
1145 .procname = "lease-break-time",
1146 .data = &lease_break_time,
1147 .maxlen = sizeof(int),
1148 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001149 .proc_handler = &proc_dointvec_minmax,
1150 .strategy = &sysctl_intvec,
1151 .extra1 = &zero,
1152 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 },
1154 {
1155 .ctl_name = FS_AIO_NR,
1156 .procname = "aio-nr",
1157 .data = &aio_nr,
1158 .maxlen = sizeof(aio_nr),
1159 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001160 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 },
1162 {
1163 .ctl_name = FS_AIO_MAX_NR,
1164 .procname = "aio-max-nr",
1165 .data = &aio_max_nr,
1166 .maxlen = sizeof(aio_max_nr),
1167 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001168 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001170#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001171 {
1172 .ctl_name = FS_INOTIFY,
1173 .procname = "inotify",
1174 .mode = 0555,
1175 .child = inotify_table,
1176 },
1177#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001179 {
1180 .ctl_name = KERN_SETUID_DUMPABLE,
1181 .procname = "suid_dumpable",
1182 .data = &suid_dumpable,
1183 .maxlen = sizeof(int),
1184 .mode = 0644,
1185 .proc_handler = &proc_dointvec,
1186 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001187#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1188 {
1189 .ctl_name = CTL_UNNUMBERED,
1190 .procname = "binfmt_misc",
1191 .mode = 0555,
1192 .child = binfmt_misc_table,
1193 },
1194#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001195/*
1196 * NOTE: do not add new entries to this table unless you have read
1197 * Documentation/sysctl/ctl_unnumbered.txt
1198 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 { .ctl_name = 0 }
1200};
1201
1202static ctl_table debug_table[] = {
1203 { .ctl_name = 0 }
1204};
1205
1206static ctl_table dev_table[] = {
1207 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001208};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Al Viro330d57f2005-11-04 10:18:40 +00001210static DEFINE_SPINLOCK(sysctl_lock);
1211
1212/* called under sysctl_lock */
1213static int use_table(struct ctl_table_header *p)
1214{
1215 if (unlikely(p->unregistering))
1216 return 0;
1217 p->used++;
1218 return 1;
1219}
1220
1221/* called under sysctl_lock */
1222static void unuse_table(struct ctl_table_header *p)
1223{
1224 if (!--p->used)
1225 if (unlikely(p->unregistering))
1226 complete(p->unregistering);
1227}
1228
1229/* called under sysctl_lock, will reacquire if has to wait */
1230static void start_unregistering(struct ctl_table_header *p)
1231{
1232 /*
1233 * if p->used is 0, nobody will ever touch that entry again;
1234 * we'll eliminate all paths to it before dropping sysctl_lock
1235 */
1236 if (unlikely(p->used)) {
1237 struct completion wait;
1238 init_completion(&wait);
1239 p->unregistering = &wait;
1240 spin_unlock(&sysctl_lock);
1241 wait_for_completion(&wait);
1242 spin_lock(&sysctl_lock);
1243 }
1244 /*
1245 * do not remove from the list until nobody holds it; walking the
1246 * list in do_sysctl() relies on that.
1247 */
1248 list_del_init(&p->ctl_entry);
1249}
1250
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001251void sysctl_head_finish(struct ctl_table_header *head)
1252{
1253 if (!head)
1254 return;
1255 spin_lock(&sysctl_lock);
1256 unuse_table(head);
1257 spin_unlock(&sysctl_lock);
1258}
1259
1260struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1261{
1262 struct ctl_table_header *head;
1263 struct list_head *tmp;
1264 spin_lock(&sysctl_lock);
1265 if (prev) {
1266 tmp = &prev->ctl_entry;
1267 unuse_table(prev);
1268 goto next;
1269 }
1270 tmp = &root_table_header.ctl_entry;
1271 for (;;) {
1272 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1273
1274 if (!use_table(head))
1275 goto next;
1276 spin_unlock(&sysctl_lock);
1277 return head;
1278 next:
1279 tmp = tmp->next;
1280 if (tmp == &root_table_header.ctl_entry)
1281 break;
1282 }
1283 spin_unlock(&sysctl_lock);
1284 return NULL;
1285}
1286
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001287#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1289 void __user *newval, size_t newlen)
1290{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001291 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001292 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1295 return -ENOTDIR;
1296 if (oldval) {
1297 int old_len;
1298 if (!oldlenp || get_user(old_len, oldlenp))
1299 return -EFAULT;
1300 }
Al Viro330d57f2005-11-04 10:18:40 +00001301
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001302 for (head = sysctl_head_next(NULL); head;
1303 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001304 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001305 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001306 if (error != -ENOTDIR) {
1307 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001308 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001309 }
1310 }
Al Viro330d57f2005-11-04 10:18:40 +00001311 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312}
1313
1314asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1315{
1316 struct __sysctl_args tmp;
1317 int error;
1318
1319 if (copy_from_user(&tmp, args, sizeof(tmp)))
1320 return -EFAULT;
1321
1322 lock_kernel();
1323 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1324 tmp.newval, tmp.newlen);
1325 unlock_kernel();
1326 return error;
1327}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001328#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329
1330/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001331 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 * some sysctl variables are readonly even to root.
1333 */
1334
1335static int test_perm(int mode, int op)
1336{
1337 if (!current->euid)
1338 mode >>= 6;
1339 else if (in_egroup_p(0))
1340 mode >>= 3;
1341 if ((mode & op & 0007) == op)
1342 return 0;
1343 return -EACCES;
1344}
1345
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001346int sysctl_perm(ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347{
1348 int error;
1349 error = security_sysctl(table, op);
1350 if (error)
1351 return error;
1352 return test_perm(table->mode, op);
1353}
1354
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001355#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356static int parse_table(int __user *name, int nlen,
1357 void __user *oldval, size_t __user *oldlenp,
1358 void __user *newval, size_t newlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001359 ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
1361 int n;
1362repeat:
1363 if (!nlen)
1364 return -ENOTDIR;
1365 if (get_user(n, name))
1366 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001367 for ( ; table->ctl_name || table->procname; table++) {
1368 if (!table->ctl_name)
1369 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001370 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 int error;
1372 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001373 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 name++;
1376 nlen--;
1377 table = table->child;
1378 goto repeat;
1379 }
1380 error = do_sysctl_strategy(table, name, nlen,
1381 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001382 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 return error;
1384 }
1385 }
1386 return -ENOTDIR;
1387}
1388
1389/* Perform the actual read/write of a sysctl table entry. */
1390int do_sysctl_strategy (ctl_table *table,
1391 int __user *name, int nlen,
1392 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001393 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394{
1395 int op = 0, rc;
1396 size_t len;
1397
1398 if (oldval)
1399 op |= 004;
1400 if (newval)
1401 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001402 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 return -EPERM;
1404
1405 if (table->strategy) {
1406 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001407 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 if (rc < 0)
1409 return rc;
1410 if (rc > 0)
1411 return 0;
1412 }
1413
1414 /* If there is no strategy routine, or if the strategy returns
1415 * zero, proceed with automatic r/w */
1416 if (table->data && table->maxlen) {
1417 if (oldval && oldlenp) {
1418 if (get_user(len, oldlenp))
1419 return -EFAULT;
1420 if (len) {
1421 if (len > table->maxlen)
1422 len = table->maxlen;
1423 if(copy_to_user(oldval, table->data, len))
1424 return -EFAULT;
1425 if(put_user(len, oldlenp))
1426 return -EFAULT;
1427 }
1428 }
1429 if (newval && newlen) {
1430 len = newlen;
1431 if (len > table->maxlen)
1432 len = table->maxlen;
1433 if(copy_from_user(table->data, newval, len))
1434 return -EFAULT;
1435 }
1436 }
1437 return 0;
1438}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001439#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001441static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1442{
1443 for (; table->ctl_name || table->procname; table++) {
1444 table->parent = parent;
1445 if (table->child)
1446 sysctl_set_parent(table, table->child);
1447 }
1448}
1449
1450static __init int sysctl_init(void)
1451{
1452 sysctl_set_parent(NULL, root_table);
1453 return 0;
1454}
1455
1456core_initcall(sysctl_init);
1457
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458/**
1459 * register_sysctl_table - register a sysctl hierarchy
1460 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 *
1462 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1463 * array. An entry with a ctl_name of 0 terminates the table.
1464 *
1465 * The members of the &ctl_table structure are used as follows:
1466 *
1467 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1468 * must be unique within that level of sysctl
1469 *
1470 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1471 * enter a sysctl file
1472 *
1473 * data - a pointer to data for use by proc_handler
1474 *
1475 * maxlen - the maximum size in bytes of the data
1476 *
1477 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1478 *
1479 * child - a pointer to the child sysctl table if this entry is a directory, or
1480 * %NULL.
1481 *
1482 * proc_handler - the text handler routine (described below)
1483 *
1484 * strategy - the strategy routine (described below)
1485 *
1486 * de - for internal use by the sysctl routines
1487 *
1488 * extra1, extra2 - extra pointers usable by the proc handler routines
1489 *
1490 * Leaf nodes in the sysctl tree will be represented by a single file
1491 * under /proc; non-leaf nodes will be represented by directories.
1492 *
1493 * sysctl(2) can automatically manage read and write requests through
1494 * the sysctl table. The data and maxlen fields of the ctl_table
1495 * struct enable minimal validation of the values being written to be
1496 * performed, and the mode field allows minimal authentication.
1497 *
1498 * More sophisticated management can be enabled by the provision of a
1499 * strategy routine with the table entry. This will be called before
1500 * any automatic read or write of the data is performed.
1501 *
1502 * The strategy routine may return
1503 *
1504 * < 0 - Error occurred (error is passed to user process)
1505 *
1506 * 0 - OK - proceed with automatic read or write.
1507 *
1508 * > 0 - OK - read or write has been done by the strategy routine, so
1509 * return immediately.
1510 *
1511 * There must be a proc_handler routine for any terminal nodes
1512 * mirrored under /proc/sys (non-terminals are handled by a built-in
1513 * directory handler). Several default handlers are available to
1514 * cover common cases -
1515 *
1516 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1517 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1518 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1519 *
1520 * It is the handler's job to read the input buffer from user memory
1521 * and process it. The handler should return 0 on success.
1522 *
1523 * This routine returns %NULL on a failure to register, and a pointer
1524 * to the table header on success.
1525 */
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001526struct ctl_table_header *register_sysctl_table(ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
1528 struct ctl_table_header *tmp;
1529 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1530 if (!tmp)
1531 return NULL;
1532 tmp->ctl_table = table;
1533 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001534 tmp->used = 0;
1535 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001536 sysctl_set_parent(NULL, table);
Al Viro330d57f2005-11-04 10:18:40 +00001537 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001538 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001539 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 return tmp;
1541}
1542
1543/**
1544 * unregister_sysctl_table - unregister a sysctl table hierarchy
1545 * @header: the header returned from register_sysctl_table
1546 *
1547 * Unregisters the sysctl table and all children. proc entries may not
1548 * actually be removed until they are no longer used by anyone.
1549 */
1550void unregister_sysctl_table(struct ctl_table_header * header)
1551{
Al Viro330d57f2005-11-04 10:18:40 +00001552 might_sleep();
1553 spin_lock(&sysctl_lock);
1554 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001555 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 kfree(header);
1557}
1558
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001559#else /* !CONFIG_SYSCTL */
Adrian Bunk93a6fef2007-02-28 20:12:23 -08001560struct ctl_table_header *register_sysctl_table(ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001561{
1562 return NULL;
1563}
1564
1565void unregister_sysctl_table(struct ctl_table_header * table)
1566{
1567}
1568
1569#endif /* CONFIG_SYSCTL */
1570
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571/*
1572 * /proc/sys support
1573 */
1574
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001575#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001577static int _proc_do_string(void* data, int maxlen, int write,
1578 struct file *filp, void __user *buffer,
1579 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001580{
1581 size_t len;
1582 char __user *p;
1583 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001584
1585 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001586 *lenp = 0;
1587 return 0;
1588 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001589
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001590 if (write) {
1591 len = 0;
1592 p = buffer;
1593 while (len < *lenp) {
1594 if (get_user(c, p++))
1595 return -EFAULT;
1596 if (c == 0 || c == '\n')
1597 break;
1598 len++;
1599 }
1600 if (len >= maxlen)
1601 len = maxlen-1;
1602 if(copy_from_user(data, buffer, len))
1603 return -EFAULT;
1604 ((char *) data)[len] = 0;
1605 *ppos += *lenp;
1606 } else {
1607 len = strlen(data);
1608 if (len > maxlen)
1609 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001610
1611 if (*ppos > len) {
1612 *lenp = 0;
1613 return 0;
1614 }
1615
1616 data += *ppos;
1617 len -= *ppos;
1618
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001619 if (len > *lenp)
1620 len = *lenp;
1621 if (len)
1622 if(copy_to_user(buffer, data, len))
1623 return -EFAULT;
1624 if (len < *lenp) {
1625 if(put_user('\n', ((char __user *) buffer) + len))
1626 return -EFAULT;
1627 len++;
1628 }
1629 *lenp = len;
1630 *ppos += len;
1631 }
1632 return 0;
1633}
1634
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635/**
1636 * proc_dostring - read a string sysctl
1637 * @table: the sysctl table
1638 * @write: %TRUE if this is a write to the sysctl file
1639 * @filp: the file structure
1640 * @buffer: the user buffer
1641 * @lenp: the size of the user buffer
1642 * @ppos: file position
1643 *
1644 * Reads/writes a string from/to the user buffer. If the kernel
1645 * buffer provided is not large enough to hold the string, the
1646 * string is truncated. The copied string is %NULL-terminated.
1647 * If the string is being read by the user process, it is copied
1648 * and a newline '\n' is added. It is truncated if the buffer is
1649 * not large enough.
1650 *
1651 * Returns 0 on success.
1652 */
1653int proc_dostring(ctl_table *table, int write, struct file *filp,
1654 void __user *buffer, size_t *lenp, loff_t *ppos)
1655{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001656 return _proc_do_string(table->data, table->maxlen, write, filp,
1657 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1662 int *valp,
1663 int write, void *data)
1664{
1665 if (write) {
1666 *valp = *negp ? -*lvalp : *lvalp;
1667 } else {
1668 int val = *valp;
1669 if (val < 0) {
1670 *negp = -1;
1671 *lvalp = (unsigned long)-val;
1672 } else {
1673 *negp = 0;
1674 *lvalp = (unsigned long)val;
1675 }
1676 }
1677 return 0;
1678}
1679
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001680static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1681 int write, struct file *filp, void __user *buffer,
1682 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1684 int write, void *data),
1685 void *data)
1686{
1687#define TMPBUFLEN 21
1688 int *i, vleft, first=1, neg, val;
1689 unsigned long lval;
1690 size_t left, len;
1691
1692 char buf[TMPBUFLEN], *p;
1693 char __user *s = buffer;
1694
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001695 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 (*ppos && !write)) {
1697 *lenp = 0;
1698 return 0;
1699 }
1700
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001701 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 vleft = table->maxlen / sizeof(*i);
1703 left = *lenp;
1704
1705 if (!conv)
1706 conv = do_proc_dointvec_conv;
1707
1708 for (; left && vleft--; i++, first=0) {
1709 if (write) {
1710 while (left) {
1711 char c;
1712 if (get_user(c, s))
1713 return -EFAULT;
1714 if (!isspace(c))
1715 break;
1716 left--;
1717 s++;
1718 }
1719 if (!left)
1720 break;
1721 neg = 0;
1722 len = left;
1723 if (len > sizeof(buf) - 1)
1724 len = sizeof(buf) - 1;
1725 if (copy_from_user(buf, s, len))
1726 return -EFAULT;
1727 buf[len] = 0;
1728 p = buf;
1729 if (*p == '-' && left > 1) {
1730 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001731 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 }
1733 if (*p < '0' || *p > '9')
1734 break;
1735
1736 lval = simple_strtoul(p, &p, 0);
1737
1738 len = p-buf;
1739 if ((len < left) && *p && !isspace(*p))
1740 break;
1741 if (neg)
1742 val = -val;
1743 s += len;
1744 left -= len;
1745
1746 if (conv(&neg, &lval, i, 1, data))
1747 break;
1748 } else {
1749 p = buf;
1750 if (!first)
1751 *p++ = '\t';
1752
1753 if (conv(&neg, &lval, i, 0, data))
1754 break;
1755
1756 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1757 len = strlen(buf);
1758 if (len > left)
1759 len = left;
1760 if(copy_to_user(s, buf, len))
1761 return -EFAULT;
1762 left -= len;
1763 s += len;
1764 }
1765 }
1766
1767 if (!write && !first && left) {
1768 if(put_user('\n', s))
1769 return -EFAULT;
1770 left--, s++;
1771 }
1772 if (write) {
1773 while (left) {
1774 char c;
1775 if (get_user(c, s++))
1776 return -EFAULT;
1777 if (!isspace(c))
1778 break;
1779 left--;
1780 }
1781 }
1782 if (write && first)
1783 return -EINVAL;
1784 *lenp -= left;
1785 *ppos += *lenp;
1786 return 0;
1787#undef TMPBUFLEN
1788}
1789
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001790static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1791 void __user *buffer, size_t *lenp, loff_t *ppos,
1792 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1793 int write, void *data),
1794 void *data)
1795{
1796 return __do_proc_dointvec(table->data, table, write, filp,
1797 buffer, lenp, ppos, conv, data);
1798}
1799
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800/**
1801 * proc_dointvec - read a vector of integers
1802 * @table: the sysctl table
1803 * @write: %TRUE if this is a write to the sysctl file
1804 * @filp: the file structure
1805 * @buffer: the user buffer
1806 * @lenp: the size of the user buffer
1807 * @ppos: file position
1808 *
1809 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1810 * values from/to the user buffer, treated as an ASCII string.
1811 *
1812 * Returns 0 on success.
1813 */
1814int proc_dointvec(ctl_table *table, int write, struct file *filp,
1815 void __user *buffer, size_t *lenp, loff_t *ppos)
1816{
1817 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1818 NULL,NULL);
1819}
1820
1821#define OP_SET 0
1822#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001823#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
1825static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1826 int *valp,
1827 int write, void *data)
1828{
1829 int op = *(int *)data;
1830 if (write) {
1831 int val = *negp ? -*lvalp : *lvalp;
1832 switch(op) {
1833 case OP_SET: *valp = val; break;
1834 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001835 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 }
1837 } else {
1838 int val = *valp;
1839 if (val < 0) {
1840 *negp = -1;
1841 *lvalp = (unsigned long)-val;
1842 } else {
1843 *negp = 0;
1844 *lvalp = (unsigned long)val;
1845 }
1846 }
1847 return 0;
1848}
1849
1850/*
1851 * init may raise the set.
1852 */
1853
1854int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1855 void __user *buffer, size_t *lenp, loff_t *ppos)
1856{
1857 int op;
1858
Eric Paris6ff1b442007-02-10 01:43:19 -08001859 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 return -EPERM;
1861 }
1862
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001863 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1865 do_proc_dointvec_bset_conv,&op);
1866}
1867
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001868/*
1869 * Taint values can only be increased
1870 */
1871static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1872 void __user *buffer, size_t *lenp, loff_t *ppos)
1873{
1874 int op;
1875
Bastian Blank91fcd412007-04-23 14:41:14 -07001876 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001877 return -EPERM;
1878
1879 op = OP_OR;
1880 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1881 do_proc_dointvec_bset_conv,&op);
1882}
1883
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884struct do_proc_dointvec_minmax_conv_param {
1885 int *min;
1886 int *max;
1887};
1888
1889static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1890 int *valp,
1891 int write, void *data)
1892{
1893 struct do_proc_dointvec_minmax_conv_param *param = data;
1894 if (write) {
1895 int val = *negp ? -*lvalp : *lvalp;
1896 if ((param->min && *param->min > val) ||
1897 (param->max && *param->max < val))
1898 return -EINVAL;
1899 *valp = val;
1900 } else {
1901 int val = *valp;
1902 if (val < 0) {
1903 *negp = -1;
1904 *lvalp = (unsigned long)-val;
1905 } else {
1906 *negp = 0;
1907 *lvalp = (unsigned long)val;
1908 }
1909 }
1910 return 0;
1911}
1912
1913/**
1914 * proc_dointvec_minmax - read a vector of integers with min/max values
1915 * @table: the sysctl table
1916 * @write: %TRUE if this is a write to the sysctl file
1917 * @filp: the file structure
1918 * @buffer: the user buffer
1919 * @lenp: the size of the user buffer
1920 * @ppos: file position
1921 *
1922 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1923 * values from/to the user buffer, treated as an ASCII string.
1924 *
1925 * This routine will ensure the values are within the range specified by
1926 * table->extra1 (min) and table->extra2 (max).
1927 *
1928 * Returns 0 on success.
1929 */
1930int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1931 void __user *buffer, size_t *lenp, loff_t *ppos)
1932{
1933 struct do_proc_dointvec_minmax_conv_param param = {
1934 .min = (int *) table->extra1,
1935 .max = (int *) table->extra2,
1936 };
1937 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1938 do_proc_dointvec_minmax_conv, &param);
1939}
1940
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001941static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 struct file *filp,
1943 void __user *buffer,
1944 size_t *lenp, loff_t *ppos,
1945 unsigned long convmul,
1946 unsigned long convdiv)
1947{
1948#define TMPBUFLEN 21
1949 unsigned long *i, *min, *max, val;
1950 int vleft, first=1, neg;
1951 size_t len, left;
1952 char buf[TMPBUFLEN], *p;
1953 char __user *s = buffer;
1954
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001955 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 (*ppos && !write)) {
1957 *lenp = 0;
1958 return 0;
1959 }
1960
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001961 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 min = (unsigned long *) table->extra1;
1963 max = (unsigned long *) table->extra2;
1964 vleft = table->maxlen / sizeof(unsigned long);
1965 left = *lenp;
1966
1967 for (; left && vleft--; i++, min++, max++, first=0) {
1968 if (write) {
1969 while (left) {
1970 char c;
1971 if (get_user(c, s))
1972 return -EFAULT;
1973 if (!isspace(c))
1974 break;
1975 left--;
1976 s++;
1977 }
1978 if (!left)
1979 break;
1980 neg = 0;
1981 len = left;
1982 if (len > TMPBUFLEN-1)
1983 len = TMPBUFLEN-1;
1984 if (copy_from_user(buf, s, len))
1985 return -EFAULT;
1986 buf[len] = 0;
1987 p = buf;
1988 if (*p == '-' && left > 1) {
1989 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001990 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 }
1992 if (*p < '0' || *p > '9')
1993 break;
1994 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1995 len = p-buf;
1996 if ((len < left) && *p && !isspace(*p))
1997 break;
1998 if (neg)
1999 val = -val;
2000 s += len;
2001 left -= len;
2002
2003 if(neg)
2004 continue;
2005 if ((min && val < *min) || (max && val > *max))
2006 continue;
2007 *i = val;
2008 } else {
2009 p = buf;
2010 if (!first)
2011 *p++ = '\t';
2012 sprintf(p, "%lu", convdiv * (*i) / convmul);
2013 len = strlen(buf);
2014 if (len > left)
2015 len = left;
2016 if(copy_to_user(s, buf, len))
2017 return -EFAULT;
2018 left -= len;
2019 s += len;
2020 }
2021 }
2022
2023 if (!write && !first && left) {
2024 if(put_user('\n', s))
2025 return -EFAULT;
2026 left--, s++;
2027 }
2028 if (write) {
2029 while (left) {
2030 char c;
2031 if (get_user(c, s++))
2032 return -EFAULT;
2033 if (!isspace(c))
2034 break;
2035 left--;
2036 }
2037 }
2038 if (write && first)
2039 return -EINVAL;
2040 *lenp -= left;
2041 *ppos += *lenp;
2042 return 0;
2043#undef TMPBUFLEN
2044}
2045
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002046static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2047 struct file *filp,
2048 void __user *buffer,
2049 size_t *lenp, loff_t *ppos,
2050 unsigned long convmul,
2051 unsigned long convdiv)
2052{
2053 return __do_proc_doulongvec_minmax(table->data, table, write,
2054 filp, buffer, lenp, ppos, convmul, convdiv);
2055}
2056
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057/**
2058 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2059 * @table: the sysctl table
2060 * @write: %TRUE if this is a write to the sysctl file
2061 * @filp: the file structure
2062 * @buffer: the user buffer
2063 * @lenp: the size of the user buffer
2064 * @ppos: file position
2065 *
2066 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2067 * values from/to the user buffer, treated as an ASCII string.
2068 *
2069 * This routine will ensure the values are within the range specified by
2070 * table->extra1 (min) and table->extra2 (max).
2071 *
2072 * Returns 0 on success.
2073 */
2074int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2075 void __user *buffer, size_t *lenp, loff_t *ppos)
2076{
2077 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2078}
2079
2080/**
2081 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2082 * @table: the sysctl table
2083 * @write: %TRUE if this is a write to the sysctl file
2084 * @filp: the file structure
2085 * @buffer: the user buffer
2086 * @lenp: the size of the user buffer
2087 * @ppos: file position
2088 *
2089 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2090 * values from/to the user buffer, treated as an ASCII string. The values
2091 * are treated as milliseconds, and converted to jiffies when they are stored.
2092 *
2093 * This routine will ensure the values are within the range specified by
2094 * table->extra1 (min) and table->extra2 (max).
2095 *
2096 * Returns 0 on success.
2097 */
2098int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2099 struct file *filp,
2100 void __user *buffer,
2101 size_t *lenp, loff_t *ppos)
2102{
2103 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2104 lenp, ppos, HZ, 1000l);
2105}
2106
2107
2108static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2109 int *valp,
2110 int write, void *data)
2111{
2112 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002113 if (*lvalp > LONG_MAX / HZ)
2114 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2116 } else {
2117 int val = *valp;
2118 unsigned long lval;
2119 if (val < 0) {
2120 *negp = -1;
2121 lval = (unsigned long)-val;
2122 } else {
2123 *negp = 0;
2124 lval = (unsigned long)val;
2125 }
2126 *lvalp = lval / HZ;
2127 }
2128 return 0;
2129}
2130
2131static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2132 int *valp,
2133 int write, void *data)
2134{
2135 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002136 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2137 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2139 } else {
2140 int val = *valp;
2141 unsigned long lval;
2142 if (val < 0) {
2143 *negp = -1;
2144 lval = (unsigned long)-val;
2145 } else {
2146 *negp = 0;
2147 lval = (unsigned long)val;
2148 }
2149 *lvalp = jiffies_to_clock_t(lval);
2150 }
2151 return 0;
2152}
2153
2154static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2155 int *valp,
2156 int write, void *data)
2157{
2158 if (write) {
2159 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2160 } else {
2161 int val = *valp;
2162 unsigned long lval;
2163 if (val < 0) {
2164 *negp = -1;
2165 lval = (unsigned long)-val;
2166 } else {
2167 *negp = 0;
2168 lval = (unsigned long)val;
2169 }
2170 *lvalp = jiffies_to_msecs(lval);
2171 }
2172 return 0;
2173}
2174
2175/**
2176 * proc_dointvec_jiffies - read a vector of integers as seconds
2177 * @table: the sysctl table
2178 * @write: %TRUE if this is a write to the sysctl file
2179 * @filp: the file structure
2180 * @buffer: the user buffer
2181 * @lenp: the size of the user buffer
2182 * @ppos: file position
2183 *
2184 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2185 * values from/to the user buffer, treated as an ASCII string.
2186 * The values read are assumed to be in seconds, and are converted into
2187 * jiffies.
2188 *
2189 * Returns 0 on success.
2190 */
2191int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2192 void __user *buffer, size_t *lenp, loff_t *ppos)
2193{
2194 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2195 do_proc_dointvec_jiffies_conv,NULL);
2196}
2197
2198/**
2199 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2200 * @table: the sysctl table
2201 * @write: %TRUE if this is a write to the sysctl file
2202 * @filp: the file structure
2203 * @buffer: the user buffer
2204 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002205 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 *
2207 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2208 * values from/to the user buffer, treated as an ASCII string.
2209 * The values read are assumed to be in 1/USER_HZ seconds, and
2210 * are converted into jiffies.
2211 *
2212 * Returns 0 on success.
2213 */
2214int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2215 void __user *buffer, size_t *lenp, loff_t *ppos)
2216{
2217 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2218 do_proc_dointvec_userhz_jiffies_conv,NULL);
2219}
2220
2221/**
2222 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2223 * @table: the sysctl table
2224 * @write: %TRUE if this is a write to the sysctl file
2225 * @filp: the file structure
2226 * @buffer: the user buffer
2227 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002228 * @ppos: file position
2229 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 *
2231 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2232 * values from/to the user buffer, treated as an ASCII string.
2233 * The values read are assumed to be in 1/1000 seconds, and
2234 * are converted into jiffies.
2235 *
2236 * Returns 0 on success.
2237 */
2238int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2239 void __user *buffer, size_t *lenp, loff_t *ppos)
2240{
2241 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2242 do_proc_dointvec_ms_jiffies_conv, NULL);
2243}
2244
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002245static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2246 void __user *buffer, size_t *lenp, loff_t *ppos)
2247{
2248 struct pid *new_pid;
2249 pid_t tmp;
2250 int r;
2251
2252 tmp = pid_nr(cad_pid);
2253
2254 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2255 lenp, ppos, NULL, NULL);
2256 if (r || !write)
2257 return r;
2258
2259 new_pid = find_get_pid(tmp);
2260 if (!new_pid)
2261 return -ESRCH;
2262
2263 put_pid(xchg(&cad_pid, new_pid));
2264 return 0;
2265}
2266
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267#else /* CONFIG_PROC_FS */
2268
2269int proc_dostring(ctl_table *table, int write, struct file *filp,
2270 void __user *buffer, size_t *lenp, loff_t *ppos)
2271{
2272 return -ENOSYS;
2273}
2274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275int proc_dointvec(ctl_table *table, int write, struct file *filp,
2276 void __user *buffer, size_t *lenp, loff_t *ppos)
2277{
2278 return -ENOSYS;
2279}
2280
2281int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2283{
2284 return -ENOSYS;
2285}
2286
2287int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2288 void __user *buffer, size_t *lenp, loff_t *ppos)
2289{
2290 return -ENOSYS;
2291}
2292
2293int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2295{
2296 return -ENOSYS;
2297}
2298
2299int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2300 void __user *buffer, size_t *lenp, loff_t *ppos)
2301{
2302 return -ENOSYS;
2303}
2304
2305int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2306 void __user *buffer, size_t *lenp, loff_t *ppos)
2307{
2308 return -ENOSYS;
2309}
2310
2311int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2312 void __user *buffer, size_t *lenp, loff_t *ppos)
2313{
2314 return -ENOSYS;
2315}
2316
2317int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2318 struct file *filp,
2319 void __user *buffer,
2320 size_t *lenp, loff_t *ppos)
2321{
2322 return -ENOSYS;
2323}
2324
2325
2326#endif /* CONFIG_PROC_FS */
2327
2328
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002329#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330/*
2331 * General sysctl support routines
2332 */
2333
2334/* The generic string strategy routine: */
2335int sysctl_string(ctl_table *table, int __user *name, int nlen,
2336 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002337 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 if (!table->data || !table->maxlen)
2340 return -ENOTDIR;
2341
2342 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002343 size_t bufsize;
2344 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002346 if (bufsize) {
2347 size_t len = strlen(table->data), copied;
2348
2349 /* This shouldn't trigger for a well-formed sysctl */
2350 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002352
2353 /* Copy up to a max of bufsize-1 bytes of the string */
2354 copied = (len >= bufsize) ? bufsize - 1 : len;
2355
2356 if (copy_to_user(oldval, table->data, copied) ||
2357 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002359 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 return -EFAULT;
2361 }
2362 }
2363 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002364 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 if (len > table->maxlen)
2366 len = table->maxlen;
2367 if(copy_from_user(table->data, newval, len))
2368 return -EFAULT;
2369 if (len == table->maxlen)
2370 len--;
2371 ((char *) table->data)[len] = 0;
2372 }
Yi Yang82c9df82005-12-30 16:37:10 +08002373 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374}
2375
2376/*
2377 * This function makes sure that all of the integers in the vector
2378 * are between the minimum and maximum values given in the arrays
2379 * table->extra1 and table->extra2, respectively.
2380 */
2381int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2382 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002383 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384{
2385
2386 if (newval && newlen) {
2387 int __user *vec = (int __user *) newval;
2388 int *min = (int *) table->extra1;
2389 int *max = (int *) table->extra2;
2390 size_t length;
2391 int i;
2392
2393 if (newlen % sizeof(int) != 0)
2394 return -EINVAL;
2395
2396 if (!table->extra1 && !table->extra2)
2397 return 0;
2398
2399 if (newlen > table->maxlen)
2400 newlen = table->maxlen;
2401 length = newlen / sizeof(int);
2402
2403 for (i = 0; i < length; i++) {
2404 int value;
2405 if (get_user(value, vec + i))
2406 return -EFAULT;
2407 if (min && value < min[i])
2408 return -EINVAL;
2409 if (max && value > max[i])
2410 return -EINVAL;
2411 }
2412 }
2413 return 0;
2414}
2415
2416/* Strategy function to convert jiffies to seconds */
2417int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2418 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002419 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002421 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002423
2424 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002426 if (olen) {
2427 int val;
2428
2429 if (olen < sizeof(int))
2430 return -EINVAL;
2431
2432 val = *(int *)(table->data) / HZ;
2433 if (put_user(val, (int __user *)oldval))
2434 return -EFAULT;
2435 if (put_user(sizeof(int), oldlenp))
2436 return -EFAULT;
2437 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 }
2439 if (newval && newlen) {
2440 int new;
2441 if (newlen != sizeof(int))
2442 return -EINVAL;
2443 if (get_user(new, (int __user *)newval))
2444 return -EFAULT;
2445 *(int *)(table->data) = new*HZ;
2446 }
2447 return 1;
2448}
2449
2450/* Strategy function to convert jiffies to seconds */
2451int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2452 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002453 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002455 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002457
2458 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002460 if (olen) {
2461 int val;
2462
2463 if (olen < sizeof(int))
2464 return -EINVAL;
2465
2466 val = jiffies_to_msecs(*(int *)(table->data));
2467 if (put_user(val, (int __user *)oldval))
2468 return -EFAULT;
2469 if (put_user(sizeof(int), oldlenp))
2470 return -EFAULT;
2471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 }
2473 if (newval && newlen) {
2474 int new;
2475 if (newlen != sizeof(int))
2476 return -EINVAL;
2477 if (get_user(new, (int __user *)newval))
2478 return -EFAULT;
2479 *(int *)(table->data) = msecs_to_jiffies(new);
2480 }
2481 return 1;
2482}
2483
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002484
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002485
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002486#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
2488
2489asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2490{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002491 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002492 struct __sysctl_args tmp;
2493 int name[CTL_MAXNAME];
2494 int i;
2495
2496 /* Read in the sysctl name for better debug message logging */
2497 if (copy_from_user(&tmp, args, sizeof(tmp)))
2498 return -EFAULT;
2499 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2500 return -ENOTDIR;
2501 for (i = 0; i < tmp.nlen; i++)
2502 if (get_user(name[i], tmp.name + i))
2503 return -EFAULT;
2504
2505 /* Ignore accesses to kernel.version */
2506 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2507 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002508
2509 if (msg_count < 5) {
2510 msg_count++;
2511 printk(KERN_INFO
2512 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002513 "system call with ", current->comm);
2514 for (i = 0; i < tmp.nlen; i++)
2515 printk("%d.", name[i]);
2516 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002517 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002518out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 return -ENOSYS;
2520}
2521
2522int sysctl_string(ctl_table *table, int __user *name, int nlen,
2523 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002524 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525{
2526 return -ENOSYS;
2527}
2528
2529int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2530 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002531 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532{
2533 return -ENOSYS;
2534}
2535
2536int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2537 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002538 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539{
2540 return -ENOSYS;
2541}
2542
2543int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2544 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002545 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546{
2547 return -ENOSYS;
2548}
2549
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002550#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551
2552/*
2553 * No sense putting this after each symbol definition, twice,
2554 * exception granted :-)
2555 */
2556EXPORT_SYMBOL(proc_dointvec);
2557EXPORT_SYMBOL(proc_dointvec_jiffies);
2558EXPORT_SYMBOL(proc_dointvec_minmax);
2559EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2560EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2561EXPORT_SYMBOL(proc_dostring);
2562EXPORT_SYMBOL(proc_doulongvec_minmax);
2563EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2564EXPORT_SYMBOL(register_sysctl_table);
2565EXPORT_SYMBOL(sysctl_intvec);
2566EXPORT_SYMBOL(sysctl_jiffies);
2567EXPORT_SYMBOL(sysctl_ms_jiffies);
2568EXPORT_SYMBOL(sysctl_string);
2569EXPORT_SYMBOL(unregister_sysctl_table);