blob: c7150af631b59c3a64407924f34790d566825387 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Randy.Dunlapc59ede72006-01-11 12:17:46 -080027#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
40#include <linux/security.h>
41#include <linux/initrd.h>
42#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Pavel Machekc255d842006-02-20 18:27:58 -080046#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
Andi Kleen29cbc782006-09-30 01:47:55 +020053#ifdef CONFIG_X86
54#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010055#include <asm/stacktrace.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020056#endif
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#if defined(CONFIG_SYSCTL)
59
60/* External variables not in a header file. */
61extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070062extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063extern int sysctl_overcommit_memory;
64extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070065extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070066extern int sysctl_oom_kill_allocating_task;
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
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070083/* Constants used for minimum and maximum */
84#ifdef CONFIG_DETECT_SOFTLOCKUP
85static int one = 1;
86static int sixty = 60;
87#endif
88
89#ifdef CONFIG_MMU
90static int two = 2;
91#endif
92
93static int zero;
94static int one_hundred = 100;
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
97static int maxolduid = 65535;
98static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080099static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101static int ngroups_max = NGROUPS_MAX;
102
103#ifdef CONFIG_KMOD
104extern char modprobe_path[];
105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#ifdef CONFIG_CHR_DEV_SG
107extern int sg_big_buff;
108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110#ifdef __sparc__
111extern char reboot_command [];
112extern int stop_a_enabled;
113extern int scons_pwroff;
114#endif
115
116#ifdef __hppa__
117extern int pwrsw_enabled;
118extern int unaligned_enabled;
119#endif
120
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800121#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#ifdef CONFIG_MATHEMU
123extern int sysctl_ieee_emulation_warnings;
124#endif
125extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700126extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#endif
128
129extern int sysctl_hz_timer;
130
131#ifdef CONFIG_BSD_PROCESS_ACCT
132extern int acct_parm[];
133#endif
134
Jes Sorensend2b176e2006-02-28 09:42:23 -0800135#ifdef CONFIG_IA64
136extern int no_unaligned_warning;
137#endif
138
Ingo Molnar23f78d42006-06-27 02:54:53 -0700139#ifdef CONFIG_RT_MUTEXES
140extern int max_lock_depth;
141#endif
142
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700143#ifdef CONFIG_SYSCTL_SYSCALL
144static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700145 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700146#endif
147
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800148
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700149#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700150static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700151 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700152static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800153 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700154#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static struct ctl_table root_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157static struct ctl_table_header root_table_header =
158 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
159
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700160static struct ctl_table kern_table[];
161static struct ctl_table vm_table[];
162static struct ctl_table fs_table[];
163static struct ctl_table debug_table[];
164static struct ctl_table dev_table[];
165extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700166#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700167extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400168#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
171int sysctl_legacy_va_layout;
172#endif
173
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700174extern int prove_locking;
175extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/* The default sysctl tables: */
178
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700179static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 {
181 .ctl_name = CTL_KERN,
182 .procname = "kernel",
183 .mode = 0555,
184 .child = kern_table,
185 },
186 {
187 .ctl_name = CTL_VM,
188 .procname = "vm",
189 .mode = 0555,
190 .child = vm_table,
191 },
192#ifdef CONFIG_NET
193 {
194 .ctl_name = CTL_NET,
195 .procname = "net",
196 .mode = 0555,
197 .child = net_table,
198 },
199#endif
200 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 .ctl_name = CTL_FS,
202 .procname = "fs",
203 .mode = 0555,
204 .child = fs_table,
205 },
206 {
207 .ctl_name = CTL_DEBUG,
208 .procname = "debug",
209 .mode = 0555,
210 .child = debug_table,
211 },
212 {
213 .ctl_name = CTL_DEV,
214 .procname = "dev",
215 .mode = 0555,
216 .child = dev_table,
217 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700218/*
219 * NOTE: do not add new entries to this table unless you have read
220 * Documentation/sysctl/ctl_unnumbered.txt
221 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 { .ctl_name = 0 }
223};
224
Ingo Molnar77e54a12007-07-09 18:52:00 +0200225#ifdef CONFIG_SCHED_DEBUG
226static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
227static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
228static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
229static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
230#endif
231
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700232static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200233#ifdef CONFIG_SCHED_DEBUG
234 {
235 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200236 .procname = "sched_nr_latency",
237 .data = &sysctl_sched_nr_latency,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238 .maxlen = sizeof(unsigned int),
239 .mode = 0644,
Peter Zijlstra5f6d858e2007-10-15 17:00:12 +0200240 .proc_handler = &proc_dointvec,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200241 },
242 {
243 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200244 .procname = "sched_latency_ns",
245 .data = &sysctl_sched_latency,
246 .maxlen = sizeof(unsigned int),
247 .mode = 0644,
248 .proc_handler = &proc_dointvec_minmax,
249 .strategy = &sysctl_intvec,
250 .extra1 = &min_sched_granularity_ns,
251 .extra2 = &max_sched_granularity_ns,
252 },
253 {
254 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200255 .procname = "sched_wakeup_granularity_ns",
256 .data = &sysctl_sched_wakeup_granularity,
257 .maxlen = sizeof(unsigned int),
258 .mode = 0644,
259 .proc_handler = &proc_dointvec_minmax,
260 .strategy = &sysctl_intvec,
261 .extra1 = &min_wakeup_granularity_ns,
262 .extra2 = &max_wakeup_granularity_ns,
263 },
264 {
265 .ctl_name = CTL_UNNUMBERED,
266 .procname = "sched_batch_wakeup_granularity_ns",
267 .data = &sysctl_sched_batch_wakeup_granularity,
268 .maxlen = sizeof(unsigned int),
269 .mode = 0644,
270 .proc_handler = &proc_dointvec_minmax,
271 .strategy = &sysctl_intvec,
272 .extra1 = &min_wakeup_granularity_ns,
273 .extra2 = &max_wakeup_granularity_ns,
274 },
275 {
276 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200277 .procname = "sched_child_runs_first",
278 .data = &sysctl_sched_child_runs_first,
279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
281 .proc_handler = &proc_dointvec,
282 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200283 {
284 .ctl_name = CTL_UNNUMBERED,
285 .procname = "sched_features",
286 .data = &sysctl_sched_features,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
289 .proc_handler = &proc_dointvec,
290 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200291 {
292 .ctl_name = CTL_UNNUMBERED,
293 .procname = "sched_migration_cost",
294 .data = &sysctl_sched_migration_cost,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
297 .proc_handler = &proc_dointvec,
298 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200299#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200300 {
301 .ctl_name = CTL_UNNUMBERED,
302 .procname = "sched_compat_yield",
303 .data = &sysctl_sched_compat_yield,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = &proc_dointvec,
307 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700308#ifdef CONFIG_PROVE_LOCKING
309 {
310 .ctl_name = CTL_UNNUMBERED,
311 .procname = "prove_locking",
312 .data = &prove_locking,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = &proc_dointvec,
316 },
317#endif
318#ifdef CONFIG_LOCK_STAT
319 {
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "lock_stat",
322 .data = &lock_stat,
323 .maxlen = sizeof(int),
324 .mode = 0644,
325 .proc_handler = &proc_dointvec,
326 },
327#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200328 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 .ctl_name = KERN_PANIC,
330 .procname = "panic",
331 .data = &panic_timeout,
332 .maxlen = sizeof(int),
333 .mode = 0644,
334 .proc_handler = &proc_dointvec,
335 },
336 {
337 .ctl_name = KERN_CORE_USES_PID,
338 .procname = "core_uses_pid",
339 .data = &core_uses_pid,
340 .maxlen = sizeof(int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
343 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700344#ifdef CONFIG_AUDITSYSCALL
345 {
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "audit_argv_kb",
348 .data = &audit_argv_kb,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
352 },
353#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 {
355 .ctl_name = KERN_CORE_PATTERN,
356 .procname = "core_pattern",
357 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700358 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 .mode = 0644,
360 .proc_handler = &proc_dostring,
361 .strategy = &sysctl_string,
362 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800363#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 .procname = "tainted",
366 .data = &tainted,
367 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800368 .mode = 0644,
369 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800371#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 .procname = "cap-bound",
374 .data = &cap_bset,
375 .maxlen = sizeof(kernel_cap_t),
376 .mode = 0600,
377 .proc_handler = &proc_dointvec_bset,
378 },
379#ifdef CONFIG_BLK_DEV_INITRD
380 {
381 .ctl_name = KERN_REALROOTDEV,
382 .procname = "real-root-dev",
383 .data = &real_root_dev,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = &proc_dointvec,
387 },
388#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700389 {
390 .ctl_name = CTL_UNNUMBERED,
391 .procname = "print-fatal-signals",
392 .data = &print_fatal_signals,
393 .maxlen = sizeof(int),
394 .mode = 0644,
395 .proc_handler = &proc_dointvec,
396 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#ifdef __sparc__
398 {
399 .ctl_name = KERN_SPARC_REBOOT,
400 .procname = "reboot-cmd",
401 .data = reboot_command,
402 .maxlen = 256,
403 .mode = 0644,
404 .proc_handler = &proc_dostring,
405 .strategy = &sysctl_string,
406 },
407 {
408 .ctl_name = KERN_SPARC_STOP_A,
409 .procname = "stop-a",
410 .data = &stop_a_enabled,
411 .maxlen = sizeof (int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
414 },
415 {
416 .ctl_name = KERN_SPARC_SCONS_PWROFF,
417 .procname = "scons-poweroff",
418 .data = &scons_pwroff,
419 .maxlen = sizeof (int),
420 .mode = 0644,
421 .proc_handler = &proc_dointvec,
422 },
423#endif
424#ifdef __hppa__
425 {
426 .ctl_name = KERN_HPPA_PWRSW,
427 .procname = "soft-power",
428 .data = &pwrsw_enabled,
429 .maxlen = sizeof (int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
432 },
433 {
434 .ctl_name = KERN_HPPA_UNALIGNED,
435 .procname = "unaligned-trap",
436 .data = &unaligned_enabled,
437 .maxlen = sizeof (int),
438 .mode = 0644,
439 .proc_handler = &proc_dointvec,
440 },
441#endif
442 {
443 .ctl_name = KERN_CTLALTDEL,
444 .procname = "ctrl-alt-del",
445 .data = &C_A_D,
446 .maxlen = sizeof(int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450 {
451 .ctl_name = KERN_PRINTK,
452 .procname = "printk",
453 .data = &console_loglevel,
454 .maxlen = 4*sizeof(int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458#ifdef CONFIG_KMOD
459 {
460 .ctl_name = KERN_MODPROBE,
461 .procname = "modprobe",
462 .data = &modprobe_path,
463 .maxlen = KMOD_PATH_LEN,
464 .mode = 0644,
465 .proc_handler = &proc_dostring,
466 .strategy = &sysctl_string,
467 },
468#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700469#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 {
471 .ctl_name = KERN_HOTPLUG,
472 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100473 .data = &uevent_helper,
474 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .mode = 0644,
476 .proc_handler = &proc_dostring,
477 .strategy = &sysctl_string,
478 },
479#endif
480#ifdef CONFIG_CHR_DEV_SG
481 {
482 .ctl_name = KERN_SG_BIG_BUFF,
483 .procname = "sg-big-buff",
484 .data = &sg_big_buff,
485 .maxlen = sizeof (int),
486 .mode = 0444,
487 .proc_handler = &proc_dointvec,
488 },
489#endif
490#ifdef CONFIG_BSD_PROCESS_ACCT
491 {
492 .ctl_name = KERN_ACCT,
493 .procname = "acct",
494 .data = &acct_parm,
495 .maxlen = 3*sizeof(int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
498 },
499#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500#ifdef CONFIG_MAGIC_SYSRQ
501 {
502 .ctl_name = KERN_SYSRQ,
503 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800504 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .maxlen = sizeof (int),
506 .mode = 0644,
507 .proc_handler = &proc_dointvec,
508 },
509#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700510#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700513 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .maxlen = sizeof (int),
515 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700516 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700518#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 {
520 .ctl_name = KERN_MAX_THREADS,
521 .procname = "threads-max",
522 .data = &max_threads,
523 .maxlen = sizeof(int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec,
526 },
527 {
528 .ctl_name = KERN_RANDOM,
529 .procname = "random",
530 .mode = 0555,
531 .child = random_table,
532 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 {
534 .ctl_name = KERN_OVERFLOWUID,
535 .procname = "overflowuid",
536 .data = &overflowuid,
537 .maxlen = sizeof(int),
538 .mode = 0644,
539 .proc_handler = &proc_dointvec_minmax,
540 .strategy = &sysctl_intvec,
541 .extra1 = &minolduid,
542 .extra2 = &maxolduid,
543 },
544 {
545 .ctl_name = KERN_OVERFLOWGID,
546 .procname = "overflowgid",
547 .data = &overflowgid,
548 .maxlen = sizeof(int),
549 .mode = 0644,
550 .proc_handler = &proc_dointvec_minmax,
551 .strategy = &sysctl_intvec,
552 .extra1 = &minolduid,
553 .extra2 = &maxolduid,
554 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800555#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556#ifdef CONFIG_MATHEMU
557 {
558 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
559 .procname = "ieee_emulation_warnings",
560 .data = &sysctl_ieee_emulation_warnings,
561 .maxlen = sizeof(int),
562 .mode = 0644,
563 .proc_handler = &proc_dointvec,
564 },
565#endif
566#ifdef CONFIG_NO_IDLE_HZ
567 {
568 .ctl_name = KERN_HZ_TIMER,
569 .procname = "hz_timer",
570 .data = &sysctl_hz_timer,
571 .maxlen = sizeof(int),
572 .mode = 0644,
573 .proc_handler = &proc_dointvec,
574 },
575#endif
576 {
577 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
578 .procname = "userprocess_debug",
579 .data = &sysctl_userprocess_debug,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 .proc_handler = &proc_dointvec,
583 },
584#endif
585 {
586 .ctl_name = KERN_PIDMAX,
587 .procname = "pid_max",
588 .data = &pid_max,
589 .maxlen = sizeof (int),
590 .mode = 0644,
591 .proc_handler = &proc_dointvec_minmax,
592 .strategy = sysctl_intvec,
593 .extra1 = &pid_max_min,
594 .extra2 = &pid_max_max,
595 },
596 {
597 .ctl_name = KERN_PANIC_ON_OOPS,
598 .procname = "panic_on_oops",
599 .data = &panic_on_oops,
600 .maxlen = sizeof(int),
601 .mode = 0644,
602 .proc_handler = &proc_dointvec,
603 },
604 {
605 .ctl_name = KERN_PRINTK_RATELIMIT,
606 .procname = "printk_ratelimit",
607 .data = &printk_ratelimit_jiffies,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec_jiffies,
611 .strategy = &sysctl_jiffies,
612 },
613 {
614 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
615 .procname = "printk_ratelimit_burst",
616 .data = &printk_ratelimit_burst,
617 .maxlen = sizeof(int),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec,
620 },
621 {
622 .ctl_name = KERN_NGROUPS_MAX,
623 .procname = "ngroups_max",
624 .data = &ngroups_max,
625 .maxlen = sizeof (int),
626 .mode = 0444,
627 .proc_handler = &proc_dointvec,
628 },
629#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
630 {
631 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
632 .procname = "unknown_nmi_panic",
633 .data = &unknown_nmi_panic,
634 .maxlen = sizeof (int),
635 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200636 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 },
Don Zickus407984f2006-09-26 10:52:27 +0200638 {
Don Zickus407984f2006-09-26 10:52:27 +0200639 .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
Len Brown673d5b42007-07-28 03:33:16 -0400692#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800693 {
Pavel Machekc255d842006-02-20 18:27:58 -0800694 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700695 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800696 .maxlen = sizeof (unsigned long),
697 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800698 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800699 },
700#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800701#ifdef CONFIG_IA64
702 {
703 .ctl_name = KERN_IA64_UNALIGNED,
704 .procname = "ignore-unaligned-usertrap",
705 .data = &no_unaligned_warning,
706 .maxlen = sizeof (int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
709 },
710#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700711#ifdef CONFIG_DETECT_SOFTLOCKUP
712 {
713 .ctl_name = CTL_UNNUMBERED,
714 .procname = "softlockup_thresh",
715 .data = &softlockup_thresh,
716 .maxlen = sizeof(int),
717 .mode = 0644,
718 .proc_handler = &proc_dointvec_minmax,
719 .strategy = &sysctl_intvec,
720 .extra1 = &one,
721 .extra2 = &sixty,
722 },
723#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200724#ifdef CONFIG_COMPAT
725 {
726 .ctl_name = KERN_COMPAT_LOG,
727 .procname = "compat-log",
728 .data = &compat_log,
729 .maxlen = sizeof (int),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
732 },
733#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700734#ifdef CONFIG_RT_MUTEXES
735 {
736 .ctl_name = KERN_MAX_LOCK_DEPTH,
737 .procname = "max_lock_depth",
738 .data = &max_lock_depth,
739 .maxlen = sizeof(int),
740 .mode = 0644,
741 .proc_handler = &proc_dointvec,
742 },
743#endif
Kees Cook5096add2007-05-08 00:26:04 -0700744#ifdef CONFIG_PROC_FS
745 {
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "maps_protect",
748 .data = &maps_protect,
749 .maxlen = sizeof(int),
750 .mode = 0644,
751 .proc_handler = &proc_dointvec,
752 },
753#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700754 {
755 .ctl_name = CTL_UNNUMBERED,
756 .procname = "poweroff_cmd",
757 .data = &poweroff_cmd,
758 .maxlen = POWEROFF_CMD_PATH_LEN,
759 .mode = 0644,
760 .proc_handler = &proc_dostring,
761 .strategy = &sysctl_string,
762 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700763/*
764 * NOTE: do not add new entries to this table unless you have read
765 * Documentation/sysctl/ctl_unnumbered.txt
766 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 { .ctl_name = 0 }
768};
769
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700770static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 {
772 .ctl_name = VM_OVERCOMMIT_MEMORY,
773 .procname = "overcommit_memory",
774 .data = &sysctl_overcommit_memory,
775 .maxlen = sizeof(sysctl_overcommit_memory),
776 .mode = 0644,
777 .proc_handler = &proc_dointvec,
778 },
779 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700780 .ctl_name = VM_PANIC_ON_OOM,
781 .procname = "panic_on_oom",
782 .data = &sysctl_panic_on_oom,
783 .maxlen = sizeof(sysctl_panic_on_oom),
784 .mode = 0644,
785 .proc_handler = &proc_dointvec,
786 },
787 {
David Rientjesfe071d72007-10-16 23:25:56 -0700788 .ctl_name = CTL_UNNUMBERED,
789 .procname = "oom_kill_allocating_task",
790 .data = &sysctl_oom_kill_allocating_task,
791 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
792 .mode = 0644,
793 .proc_handler = &proc_dointvec,
794 },
795 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 .ctl_name = VM_OVERCOMMIT_RATIO,
797 .procname = "overcommit_ratio",
798 .data = &sysctl_overcommit_ratio,
799 .maxlen = sizeof(sysctl_overcommit_ratio),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
803 {
804 .ctl_name = VM_PAGE_CLUSTER,
805 .procname = "page-cluster",
806 .data = &page_cluster,
807 .maxlen = sizeof(int),
808 .mode = 0644,
809 .proc_handler = &proc_dointvec,
810 },
811 {
812 .ctl_name = VM_DIRTY_BACKGROUND,
813 .procname = "dirty_background_ratio",
814 .data = &dirty_background_ratio,
815 .maxlen = sizeof(dirty_background_ratio),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec_minmax,
818 .strategy = &sysctl_intvec,
819 .extra1 = &zero,
820 .extra2 = &one_hundred,
821 },
822 {
823 .ctl_name = VM_DIRTY_RATIO,
824 .procname = "dirty_ratio",
825 .data = &vm_dirty_ratio,
826 .maxlen = sizeof(vm_dirty_ratio),
827 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700828 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 .strategy = &sysctl_intvec,
830 .extra1 = &zero,
831 .extra2 = &one_hundred,
832 },
833 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800835 .data = &dirty_writeback_interval,
836 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 .mode = 0644,
838 .proc_handler = &dirty_writeback_centisecs_handler,
839 },
840 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800842 .data = &dirty_expire_interval,
843 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800845 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 },
847 {
848 .ctl_name = VM_NR_PDFLUSH_THREADS,
849 .procname = "nr_pdflush_threads",
850 .data = &nr_pdflush_threads,
851 .maxlen = sizeof nr_pdflush_threads,
852 .mode = 0444 /* read-only*/,
853 .proc_handler = &proc_dointvec,
854 },
855 {
856 .ctl_name = VM_SWAPPINESS,
857 .procname = "swappiness",
858 .data = &vm_swappiness,
859 .maxlen = sizeof(vm_swappiness),
860 .mode = 0644,
861 .proc_handler = &proc_dointvec_minmax,
862 .strategy = &sysctl_intvec,
863 .extra1 = &zero,
864 .extra2 = &one_hundred,
865 },
866#ifdef CONFIG_HUGETLB_PAGE
867 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 .procname = "nr_hugepages",
869 .data = &max_huge_pages,
870 .maxlen = sizeof(unsigned long),
871 .mode = 0644,
872 .proc_handler = &hugetlb_sysctl_handler,
873 .extra1 = (void *)&hugetlb_zero,
874 .extra2 = (void *)&hugetlb_infinity,
875 },
876 {
877 .ctl_name = VM_HUGETLB_GROUP,
878 .procname = "hugetlb_shm_group",
879 .data = &sysctl_hugetlb_shm_group,
880 .maxlen = sizeof(gid_t),
881 .mode = 0644,
882 .proc_handler = &proc_dointvec,
883 },
Mel Gorman396faf02007-07-17 04:03:13 -0700884 {
885 .ctl_name = CTL_UNNUMBERED,
886 .procname = "hugepages_treat_as_movable",
887 .data = &hugepages_treat_as_movable,
888 .maxlen = sizeof(int),
889 .mode = 0644,
890 .proc_handler = &hugetlb_treat_movable_handler,
891 },
Adam Litke54f9f802007-10-16 01:26:20 -0700892 {
893 .ctl_name = CTL_UNNUMBERED,
894 .procname = "hugetlb_dynamic_pool",
895 .data = &hugetlb_dynamic_pool,
896 .maxlen = sizeof(hugetlb_dynamic_pool),
897 .mode = 0644,
898 .proc_handler = &proc_dointvec,
899 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900#endif
901 {
902 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
903 .procname = "lowmem_reserve_ratio",
904 .data = &sysctl_lowmem_reserve_ratio,
905 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
906 .mode = 0644,
907 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
908 .strategy = &sysctl_intvec,
909 },
910 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800911 .ctl_name = VM_DROP_PAGECACHE,
912 .procname = "drop_caches",
913 .data = &sysctl_drop_caches,
914 .maxlen = sizeof(int),
915 .mode = 0644,
916 .proc_handler = drop_caches_sysctl_handler,
917 .strategy = &sysctl_intvec,
918 },
919 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 .ctl_name = VM_MIN_FREE_KBYTES,
921 .procname = "min_free_kbytes",
922 .data = &min_free_kbytes,
923 .maxlen = sizeof(min_free_kbytes),
924 .mode = 0644,
925 .proc_handler = &min_free_kbytes_sysctl_handler,
926 .strategy = &sysctl_intvec,
927 .extra1 = &zero,
928 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800929 {
930 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
931 .procname = "percpu_pagelist_fraction",
932 .data = &percpu_pagelist_fraction,
933 .maxlen = sizeof(percpu_pagelist_fraction),
934 .mode = 0644,
935 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
936 .strategy = &sysctl_intvec,
937 .extra1 = &min_percpu_pagelist_fract,
938 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939#ifdef CONFIG_MMU
940 {
941 .ctl_name = VM_MAX_MAP_COUNT,
942 .procname = "max_map_count",
943 .data = &sysctl_max_map_count,
944 .maxlen = sizeof(sysctl_max_map_count),
945 .mode = 0644,
946 .proc_handler = &proc_dointvec
947 },
948#endif
949 {
950 .ctl_name = VM_LAPTOP_MODE,
951 .procname = "laptop_mode",
952 .data = &laptop_mode,
953 .maxlen = sizeof(laptop_mode),
954 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800955 .proc_handler = &proc_dointvec_jiffies,
956 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 },
958 {
959 .ctl_name = VM_BLOCK_DUMP,
960 .procname = "block_dump",
961 .data = &block_dump,
962 .maxlen = sizeof(block_dump),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 .strategy = &sysctl_intvec,
966 .extra1 = &zero,
967 },
968 {
969 .ctl_name = VM_VFS_CACHE_PRESSURE,
970 .procname = "vfs_cache_pressure",
971 .data = &sysctl_vfs_cache_pressure,
972 .maxlen = sizeof(sysctl_vfs_cache_pressure),
973 .mode = 0644,
974 .proc_handler = &proc_dointvec,
975 .strategy = &sysctl_intvec,
976 .extra1 = &zero,
977 },
978#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
979 {
980 .ctl_name = VM_LEGACY_VA_LAYOUT,
981 .procname = "legacy_va_layout",
982 .data = &sysctl_legacy_va_layout,
983 .maxlen = sizeof(sysctl_legacy_va_layout),
984 .mode = 0644,
985 .proc_handler = &proc_dointvec,
986 .strategy = &sysctl_intvec,
987 .extra1 = &zero,
988 },
989#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800990#ifdef CONFIG_NUMA
991 {
992 .ctl_name = VM_ZONE_RECLAIM_MODE,
993 .procname = "zone_reclaim_mode",
994 .data = &zone_reclaim_mode,
995 .maxlen = sizeof(zone_reclaim_mode),
996 .mode = 0644,
997 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -0800998 .strategy = &sysctl_intvec,
999 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001000 },
Christoph Lameter96146342006-07-03 00:24:13 -07001001 {
1002 .ctl_name = VM_MIN_UNMAPPED,
1003 .procname = "min_unmapped_ratio",
1004 .data = &sysctl_min_unmapped_ratio,
1005 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1006 .mode = 0644,
1007 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1008 .strategy = &sysctl_intvec,
1009 .extra1 = &zero,
1010 .extra2 = &one_hundred,
1011 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001012 {
1013 .ctl_name = VM_MIN_SLAB,
1014 .procname = "min_slab_ratio",
1015 .data = &sysctl_min_slab_ratio,
1016 .maxlen = sizeof(sysctl_min_slab_ratio),
1017 .mode = 0644,
1018 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1019 .strategy = &sysctl_intvec,
1020 .extra1 = &zero,
1021 .extra2 = &one_hundred,
1022 },
Christoph Lameter17436602006-01-18 17:42:32 -08001023#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001024#ifdef CONFIG_SMP
1025 {
1026 .ctl_name = CTL_UNNUMBERED,
1027 .procname = "stat_interval",
1028 .data = &sysctl_stat_interval,
1029 .maxlen = sizeof(sysctl_stat_interval),
1030 .mode = 0644,
1031 .proc_handler = &proc_dointvec_jiffies,
1032 .strategy = &sysctl_jiffies,
1033 },
1034#endif
Eric Parised032182007-06-28 15:55:21 -04001035#ifdef CONFIG_SECURITY
1036 {
1037 .ctl_name = CTL_UNNUMBERED,
1038 .procname = "mmap_min_addr",
1039 .data = &mmap_min_addr,
1040 .maxlen = sizeof(unsigned long),
1041 .mode = 0644,
1042 .proc_handler = &proc_doulongvec_minmax,
1043 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001044#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001045#ifdef CONFIG_NUMA
1046 {
1047 .ctl_name = CTL_UNNUMBERED,
1048 .procname = "numa_zonelist_order",
1049 .data = &numa_zonelist_order,
1050 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1051 .mode = 0644,
1052 .proc_handler = &numa_zonelist_order_handler,
1053 .strategy = &sysctl_string,
1054 },
1055#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001056#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001057 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001058 {
1059 .ctl_name = VM_VDSO_ENABLED,
1060 .procname = "vdso_enabled",
1061 .data = &vdso_enabled,
1062 .maxlen = sizeof(vdso_enabled),
1063 .mode = 0644,
1064 .proc_handler = &proc_dointvec,
1065 .strategy = &sysctl_intvec,
1066 .extra1 = &zero,
1067 },
1068#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001069/*
1070 * NOTE: do not add new entries to this table unless you have read
1071 * Documentation/sysctl/ctl_unnumbered.txt
1072 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 { .ctl_name = 0 }
1074};
1075
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001076#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001077static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001078 { .ctl_name = 0 }
1079};
1080#endif
1081
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001082static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 {
1084 .ctl_name = FS_NRINODE,
1085 .procname = "inode-nr",
1086 .data = &inodes_stat,
1087 .maxlen = 2*sizeof(int),
1088 .mode = 0444,
1089 .proc_handler = &proc_dointvec,
1090 },
1091 {
1092 .ctl_name = FS_STATINODE,
1093 .procname = "inode-state",
1094 .data = &inodes_stat,
1095 .maxlen = 7*sizeof(int),
1096 .mode = 0444,
1097 .proc_handler = &proc_dointvec,
1098 },
1099 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 .procname = "file-nr",
1101 .data = &files_stat,
1102 .maxlen = 3*sizeof(int),
1103 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001104 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 },
1106 {
1107 .ctl_name = FS_MAXFILE,
1108 .procname = "file-max",
1109 .data = &files_stat.max_files,
1110 .maxlen = sizeof(int),
1111 .mode = 0644,
1112 .proc_handler = &proc_dointvec,
1113 },
1114 {
1115 .ctl_name = FS_DENTRY,
1116 .procname = "dentry-state",
1117 .data = &dentry_stat,
1118 .maxlen = 6*sizeof(int),
1119 .mode = 0444,
1120 .proc_handler = &proc_dointvec,
1121 },
1122 {
1123 .ctl_name = FS_OVERFLOWUID,
1124 .procname = "overflowuid",
1125 .data = &fs_overflowuid,
1126 .maxlen = sizeof(int),
1127 .mode = 0644,
1128 .proc_handler = &proc_dointvec_minmax,
1129 .strategy = &sysctl_intvec,
1130 .extra1 = &minolduid,
1131 .extra2 = &maxolduid,
1132 },
1133 {
1134 .ctl_name = FS_OVERFLOWGID,
1135 .procname = "overflowgid",
1136 .data = &fs_overflowgid,
1137 .maxlen = sizeof(int),
1138 .mode = 0644,
1139 .proc_handler = &proc_dointvec_minmax,
1140 .strategy = &sysctl_intvec,
1141 .extra1 = &minolduid,
1142 .extra2 = &maxolduid,
1143 },
1144 {
1145 .ctl_name = FS_LEASES,
1146 .procname = "leases-enable",
1147 .data = &leases_enable,
1148 .maxlen = sizeof(int),
1149 .mode = 0644,
1150 .proc_handler = &proc_dointvec,
1151 },
1152#ifdef CONFIG_DNOTIFY
1153 {
1154 .ctl_name = FS_DIR_NOTIFY,
1155 .procname = "dir-notify-enable",
1156 .data = &dir_notify_enable,
1157 .maxlen = sizeof(int),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec,
1160 },
1161#endif
1162#ifdef CONFIG_MMU
1163 {
1164 .ctl_name = FS_LEASE_TIME,
1165 .procname = "lease-break-time",
1166 .data = &lease_break_time,
1167 .maxlen = sizeof(int),
1168 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001169 .proc_handler = &proc_dointvec_minmax,
1170 .strategy = &sysctl_intvec,
1171 .extra1 = &zero,
1172 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 },
1174 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 .procname = "aio-nr",
1176 .data = &aio_nr,
1177 .maxlen = sizeof(aio_nr),
1178 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001179 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 },
1181 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 .procname = "aio-max-nr",
1183 .data = &aio_max_nr,
1184 .maxlen = sizeof(aio_max_nr),
1185 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001186 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001188#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001189 {
1190 .ctl_name = FS_INOTIFY,
1191 .procname = "inotify",
1192 .mode = 0555,
1193 .child = inotify_table,
1194 },
1195#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001197 {
1198 .ctl_name = KERN_SETUID_DUMPABLE,
1199 .procname = "suid_dumpable",
1200 .data = &suid_dumpable,
1201 .maxlen = sizeof(int),
1202 .mode = 0644,
1203 .proc_handler = &proc_dointvec,
1204 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001205#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1206 {
1207 .ctl_name = CTL_UNNUMBERED,
1208 .procname = "binfmt_misc",
1209 .mode = 0555,
1210 .child = binfmt_misc_table,
1211 },
1212#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001213/*
1214 * NOTE: do not add new entries to this table unless you have read
1215 * Documentation/sysctl/ctl_unnumbered.txt
1216 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 { .ctl_name = 0 }
1218};
1219
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001220static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001221#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001222 {
1223 .ctl_name = CTL_UNNUMBERED,
1224 .procname = "exception-trace",
1225 .data = &show_unhandled_signals,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = proc_dointvec
1229 },
1230#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 { .ctl_name = 0 }
1232};
1233
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001234static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001236};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Al Viro330d57f2005-11-04 10:18:40 +00001238static DEFINE_SPINLOCK(sysctl_lock);
1239
1240/* called under sysctl_lock */
1241static int use_table(struct ctl_table_header *p)
1242{
1243 if (unlikely(p->unregistering))
1244 return 0;
1245 p->used++;
1246 return 1;
1247}
1248
1249/* called under sysctl_lock */
1250static void unuse_table(struct ctl_table_header *p)
1251{
1252 if (!--p->used)
1253 if (unlikely(p->unregistering))
1254 complete(p->unregistering);
1255}
1256
1257/* called under sysctl_lock, will reacquire if has to wait */
1258static void start_unregistering(struct ctl_table_header *p)
1259{
1260 /*
1261 * if p->used is 0, nobody will ever touch that entry again;
1262 * we'll eliminate all paths to it before dropping sysctl_lock
1263 */
1264 if (unlikely(p->used)) {
1265 struct completion wait;
1266 init_completion(&wait);
1267 p->unregistering = &wait;
1268 spin_unlock(&sysctl_lock);
1269 wait_for_completion(&wait);
1270 spin_lock(&sysctl_lock);
1271 }
1272 /*
1273 * do not remove from the list until nobody holds it; walking the
1274 * list in do_sysctl() relies on that.
1275 */
1276 list_del_init(&p->ctl_entry);
1277}
1278
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001279void sysctl_head_finish(struct ctl_table_header *head)
1280{
1281 if (!head)
1282 return;
1283 spin_lock(&sysctl_lock);
1284 unuse_table(head);
1285 spin_unlock(&sysctl_lock);
1286}
1287
1288struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1289{
1290 struct ctl_table_header *head;
1291 struct list_head *tmp;
1292 spin_lock(&sysctl_lock);
1293 if (prev) {
1294 tmp = &prev->ctl_entry;
1295 unuse_table(prev);
1296 goto next;
1297 }
1298 tmp = &root_table_header.ctl_entry;
1299 for (;;) {
1300 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1301
1302 if (!use_table(head))
1303 goto next;
1304 spin_unlock(&sysctl_lock);
1305 return head;
1306 next:
1307 tmp = tmp->next;
1308 if (tmp == &root_table_header.ctl_entry)
1309 break;
1310 }
1311 spin_unlock(&sysctl_lock);
1312 return NULL;
1313}
1314
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001315#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1317 void __user *newval, size_t newlen)
1318{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001319 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001320 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1323 return -ENOTDIR;
1324 if (oldval) {
1325 int old_len;
1326 if (!oldlenp || get_user(old_len, oldlenp))
1327 return -EFAULT;
1328 }
Al Viro330d57f2005-11-04 10:18:40 +00001329
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001330 for (head = sysctl_head_next(NULL); head;
1331 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001332 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001333 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001334 if (error != -ENOTDIR) {
1335 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001336 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001337 }
1338 }
Al Viro330d57f2005-11-04 10:18:40 +00001339 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
1342asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1343{
1344 struct __sysctl_args tmp;
1345 int error;
1346
1347 if (copy_from_user(&tmp, args, sizeof(tmp)))
1348 return -EFAULT;
1349
1350 lock_kernel();
1351 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1352 tmp.newval, tmp.newlen);
1353 unlock_kernel();
1354 return error;
1355}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001356#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001359 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 * some sysctl variables are readonly even to root.
1361 */
1362
1363static int test_perm(int mode, int op)
1364{
1365 if (!current->euid)
1366 mode >>= 6;
1367 else if (in_egroup_p(0))
1368 mode >>= 3;
1369 if ((mode & op & 0007) == op)
1370 return 0;
1371 return -EACCES;
1372}
1373
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001374int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375{
1376 int error;
1377 error = security_sysctl(table, op);
1378 if (error)
1379 return error;
1380 return test_perm(table->mode, op);
1381}
1382
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001383#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384static int parse_table(int __user *name, int nlen,
1385 void __user *oldval, size_t __user *oldlenp,
1386 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001387 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388{
1389 int n;
1390repeat:
1391 if (!nlen)
1392 return -ENOTDIR;
1393 if (get_user(n, name))
1394 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001395 for ( ; table->ctl_name || table->procname; table++) {
1396 if (!table->ctl_name)
1397 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001398 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 int error;
1400 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001401 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 name++;
1404 nlen--;
1405 table = table->child;
1406 goto repeat;
1407 }
1408 error = do_sysctl_strategy(table, name, nlen,
1409 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001410 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 return error;
1412 }
1413 }
1414 return -ENOTDIR;
1415}
1416
1417/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001418int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 int __user *name, int nlen,
1420 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001421 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422{
1423 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 if (oldval)
1426 op |= 004;
1427 if (newval)
1428 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001429 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 return -EPERM;
1431
1432 if (table->strategy) {
1433 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001434 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 if (rc < 0)
1436 return rc;
1437 if (rc > 0)
1438 return 0;
1439 }
1440
1441 /* If there is no strategy routine, or if the strategy returns
1442 * zero, proceed with automatic r/w */
1443 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001444 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1445 newval, newlen);
1446 if (rc < 0)
1447 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 }
1449 return 0;
1450}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001451#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001453static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1454{
1455 for (; table->ctl_name || table->procname; table++) {
1456 table->parent = parent;
1457 if (table->child)
1458 sysctl_set_parent(table, table->child);
1459 }
1460}
1461
1462static __init int sysctl_init(void)
1463{
1464 sysctl_set_parent(NULL, root_table);
1465 return 0;
1466}
1467
1468core_initcall(sysctl_init);
1469
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470/**
1471 * register_sysctl_table - register a sysctl hierarchy
1472 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 *
1474 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1475 * array. An entry with a ctl_name of 0 terminates the table.
1476 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001477 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 *
1479 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1480 * must be unique within that level of sysctl
1481 *
1482 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1483 * enter a sysctl file
1484 *
1485 * data - a pointer to data for use by proc_handler
1486 *
1487 * maxlen - the maximum size in bytes of the data
1488 *
1489 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1490 *
1491 * child - a pointer to the child sysctl table if this entry is a directory, or
1492 * %NULL.
1493 *
1494 * proc_handler - the text handler routine (described below)
1495 *
1496 * strategy - the strategy routine (described below)
1497 *
1498 * de - for internal use by the sysctl routines
1499 *
1500 * extra1, extra2 - extra pointers usable by the proc handler routines
1501 *
1502 * Leaf nodes in the sysctl tree will be represented by a single file
1503 * under /proc; non-leaf nodes will be represented by directories.
1504 *
1505 * sysctl(2) can automatically manage read and write requests through
1506 * the sysctl table. The data and maxlen fields of the ctl_table
1507 * struct enable minimal validation of the values being written to be
1508 * performed, and the mode field allows minimal authentication.
1509 *
1510 * More sophisticated management can be enabled by the provision of a
1511 * strategy routine with the table entry. This will be called before
1512 * any automatic read or write of the data is performed.
1513 *
1514 * The strategy routine may return
1515 *
1516 * < 0 - Error occurred (error is passed to user process)
1517 *
1518 * 0 - OK - proceed with automatic read or write.
1519 *
1520 * > 0 - OK - read or write has been done by the strategy routine, so
1521 * return immediately.
1522 *
1523 * There must be a proc_handler routine for any terminal nodes
1524 * mirrored under /proc/sys (non-terminals are handled by a built-in
1525 * directory handler). Several default handlers are available to
1526 * cover common cases -
1527 *
1528 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1529 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1530 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1531 *
1532 * It is the handler's job to read the input buffer from user memory
1533 * and process it. The handler should return 0 on success.
1534 *
1535 * This routine returns %NULL on a failure to register, and a pointer
1536 * to the table header on success.
1537 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001538struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539{
1540 struct ctl_table_header *tmp;
1541 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1542 if (!tmp)
1543 return NULL;
1544 tmp->ctl_table = table;
1545 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001546 tmp->used = 0;
1547 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001548 sysctl_set_parent(NULL, table);
Al Viro330d57f2005-11-04 10:18:40 +00001549 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001550 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001551 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 return tmp;
1553}
1554
1555/**
1556 * unregister_sysctl_table - unregister a sysctl table hierarchy
1557 * @header: the header returned from register_sysctl_table
1558 *
1559 * Unregisters the sysctl table and all children. proc entries may not
1560 * actually be removed until they are no longer used by anyone.
1561 */
1562void unregister_sysctl_table(struct ctl_table_header * header)
1563{
Al Viro330d57f2005-11-04 10:18:40 +00001564 might_sleep();
1565 spin_lock(&sysctl_lock);
1566 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001567 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 kfree(header);
1569}
1570
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001571#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001572struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001573{
1574 return NULL;
1575}
1576
1577void unregister_sysctl_table(struct ctl_table_header * table)
1578{
1579}
1580
1581#endif /* CONFIG_SYSCTL */
1582
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583/*
1584 * /proc/sys support
1585 */
1586
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001587#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001589static int _proc_do_string(void* data, int maxlen, int write,
1590 struct file *filp, void __user *buffer,
1591 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001592{
1593 size_t len;
1594 char __user *p;
1595 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001596
1597 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001598 *lenp = 0;
1599 return 0;
1600 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001601
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001602 if (write) {
1603 len = 0;
1604 p = buffer;
1605 while (len < *lenp) {
1606 if (get_user(c, p++))
1607 return -EFAULT;
1608 if (c == 0 || c == '\n')
1609 break;
1610 len++;
1611 }
1612 if (len >= maxlen)
1613 len = maxlen-1;
1614 if(copy_from_user(data, buffer, len))
1615 return -EFAULT;
1616 ((char *) data)[len] = 0;
1617 *ppos += *lenp;
1618 } else {
1619 len = strlen(data);
1620 if (len > maxlen)
1621 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001622
1623 if (*ppos > len) {
1624 *lenp = 0;
1625 return 0;
1626 }
1627
1628 data += *ppos;
1629 len -= *ppos;
1630
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001631 if (len > *lenp)
1632 len = *lenp;
1633 if (len)
1634 if(copy_to_user(buffer, data, len))
1635 return -EFAULT;
1636 if (len < *lenp) {
1637 if(put_user('\n', ((char __user *) buffer) + len))
1638 return -EFAULT;
1639 len++;
1640 }
1641 *lenp = len;
1642 *ppos += len;
1643 }
1644 return 0;
1645}
1646
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647/**
1648 * proc_dostring - read a string sysctl
1649 * @table: the sysctl table
1650 * @write: %TRUE if this is a write to the sysctl file
1651 * @filp: the file structure
1652 * @buffer: the user buffer
1653 * @lenp: the size of the user buffer
1654 * @ppos: file position
1655 *
1656 * Reads/writes a string from/to the user buffer. If the kernel
1657 * buffer provided is not large enough to hold the string, the
1658 * string is truncated. The copied string is %NULL-terminated.
1659 * If the string is being read by the user process, it is copied
1660 * and a newline '\n' is added. It is truncated if the buffer is
1661 * not large enough.
1662 *
1663 * Returns 0 on success.
1664 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001665int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 void __user *buffer, size_t *lenp, loff_t *ppos)
1667{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001668 return _proc_do_string(table->data, table->maxlen, write, filp,
1669 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670}
1671
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1674 int *valp,
1675 int write, void *data)
1676{
1677 if (write) {
1678 *valp = *negp ? -*lvalp : *lvalp;
1679 } else {
1680 int val = *valp;
1681 if (val < 0) {
1682 *negp = -1;
1683 *lvalp = (unsigned long)-val;
1684 } else {
1685 *negp = 0;
1686 *lvalp = (unsigned long)val;
1687 }
1688 }
1689 return 0;
1690}
1691
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001692static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001693 int write, struct file *filp, void __user *buffer,
1694 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1696 int write, void *data),
1697 void *data)
1698{
1699#define TMPBUFLEN 21
1700 int *i, vleft, first=1, neg, val;
1701 unsigned long lval;
1702 size_t left, len;
1703
1704 char buf[TMPBUFLEN], *p;
1705 char __user *s = buffer;
1706
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001707 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 (*ppos && !write)) {
1709 *lenp = 0;
1710 return 0;
1711 }
1712
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001713 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 vleft = table->maxlen / sizeof(*i);
1715 left = *lenp;
1716
1717 if (!conv)
1718 conv = do_proc_dointvec_conv;
1719
1720 for (; left && vleft--; i++, first=0) {
1721 if (write) {
1722 while (left) {
1723 char c;
1724 if (get_user(c, s))
1725 return -EFAULT;
1726 if (!isspace(c))
1727 break;
1728 left--;
1729 s++;
1730 }
1731 if (!left)
1732 break;
1733 neg = 0;
1734 len = left;
1735 if (len > sizeof(buf) - 1)
1736 len = sizeof(buf) - 1;
1737 if (copy_from_user(buf, s, len))
1738 return -EFAULT;
1739 buf[len] = 0;
1740 p = buf;
1741 if (*p == '-' && left > 1) {
1742 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001743 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 }
1745 if (*p < '0' || *p > '9')
1746 break;
1747
1748 lval = simple_strtoul(p, &p, 0);
1749
1750 len = p-buf;
1751 if ((len < left) && *p && !isspace(*p))
1752 break;
1753 if (neg)
1754 val = -val;
1755 s += len;
1756 left -= len;
1757
1758 if (conv(&neg, &lval, i, 1, data))
1759 break;
1760 } else {
1761 p = buf;
1762 if (!first)
1763 *p++ = '\t';
1764
1765 if (conv(&neg, &lval, i, 0, data))
1766 break;
1767
1768 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1769 len = strlen(buf);
1770 if (len > left)
1771 len = left;
1772 if(copy_to_user(s, buf, len))
1773 return -EFAULT;
1774 left -= len;
1775 s += len;
1776 }
1777 }
1778
1779 if (!write && !first && left) {
1780 if(put_user('\n', s))
1781 return -EFAULT;
1782 left--, s++;
1783 }
1784 if (write) {
1785 while (left) {
1786 char c;
1787 if (get_user(c, s++))
1788 return -EFAULT;
1789 if (!isspace(c))
1790 break;
1791 left--;
1792 }
1793 }
1794 if (write && first)
1795 return -EINVAL;
1796 *lenp -= left;
1797 *ppos += *lenp;
1798 return 0;
1799#undef TMPBUFLEN
1800}
1801
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001802static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001803 void __user *buffer, size_t *lenp, loff_t *ppos,
1804 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1805 int write, void *data),
1806 void *data)
1807{
1808 return __do_proc_dointvec(table->data, table, write, filp,
1809 buffer, lenp, ppos, conv, data);
1810}
1811
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812/**
1813 * proc_dointvec - read a vector of integers
1814 * @table: the sysctl table
1815 * @write: %TRUE if this is a write to the sysctl file
1816 * @filp: the file structure
1817 * @buffer: the user buffer
1818 * @lenp: the size of the user buffer
1819 * @ppos: file position
1820 *
1821 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1822 * values from/to the user buffer, treated as an ASCII string.
1823 *
1824 * Returns 0 on success.
1825 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001826int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 void __user *buffer, size_t *lenp, loff_t *ppos)
1828{
1829 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1830 NULL,NULL);
1831}
1832
1833#define OP_SET 0
1834#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001835#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
1837static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1838 int *valp,
1839 int write, void *data)
1840{
1841 int op = *(int *)data;
1842 if (write) {
1843 int val = *negp ? -*lvalp : *lvalp;
1844 switch(op) {
1845 case OP_SET: *valp = val; break;
1846 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001847 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 }
1849 } else {
1850 int val = *valp;
1851 if (val < 0) {
1852 *negp = -1;
1853 *lvalp = (unsigned long)-val;
1854 } else {
1855 *negp = 0;
1856 *lvalp = (unsigned long)val;
1857 }
1858 }
1859 return 0;
1860}
1861
1862/*
1863 * init may raise the set.
1864 */
1865
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001866int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 void __user *buffer, size_t *lenp, loff_t *ppos)
1868{
1869 int op;
1870
Eric Paris6ff1b442007-02-10 01:43:19 -08001871 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 return -EPERM;
1873 }
1874
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001875 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1877 do_proc_dointvec_bset_conv,&op);
1878}
1879
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001880/*
1881 * Taint values can only be increased
1882 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001883static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001884 void __user *buffer, size_t *lenp, loff_t *ppos)
1885{
1886 int op;
1887
Bastian Blank91fcd412007-04-23 14:41:14 -07001888 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001889 return -EPERM;
1890
1891 op = OP_OR;
1892 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1893 do_proc_dointvec_bset_conv,&op);
1894}
1895
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896struct do_proc_dointvec_minmax_conv_param {
1897 int *min;
1898 int *max;
1899};
1900
1901static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1902 int *valp,
1903 int write, void *data)
1904{
1905 struct do_proc_dointvec_minmax_conv_param *param = data;
1906 if (write) {
1907 int val = *negp ? -*lvalp : *lvalp;
1908 if ((param->min && *param->min > val) ||
1909 (param->max && *param->max < val))
1910 return -EINVAL;
1911 *valp = val;
1912 } else {
1913 int val = *valp;
1914 if (val < 0) {
1915 *negp = -1;
1916 *lvalp = (unsigned long)-val;
1917 } else {
1918 *negp = 0;
1919 *lvalp = (unsigned long)val;
1920 }
1921 }
1922 return 0;
1923}
1924
1925/**
1926 * proc_dointvec_minmax - read a vector of integers with min/max values
1927 * @table: the sysctl table
1928 * @write: %TRUE if this is a write to the sysctl file
1929 * @filp: the file structure
1930 * @buffer: the user buffer
1931 * @lenp: the size of the user buffer
1932 * @ppos: file position
1933 *
1934 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1935 * values from/to the user buffer, treated as an ASCII string.
1936 *
1937 * This routine will ensure the values are within the range specified by
1938 * table->extra1 (min) and table->extra2 (max).
1939 *
1940 * Returns 0 on success.
1941 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001942int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 void __user *buffer, size_t *lenp, loff_t *ppos)
1944{
1945 struct do_proc_dointvec_minmax_conv_param param = {
1946 .min = (int *) table->extra1,
1947 .max = (int *) table->extra2,
1948 };
1949 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1950 do_proc_dointvec_minmax_conv, &param);
1951}
1952
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001953static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 struct file *filp,
1955 void __user *buffer,
1956 size_t *lenp, loff_t *ppos,
1957 unsigned long convmul,
1958 unsigned long convdiv)
1959{
1960#define TMPBUFLEN 21
1961 unsigned long *i, *min, *max, val;
1962 int vleft, first=1, neg;
1963 size_t len, left;
1964 char buf[TMPBUFLEN], *p;
1965 char __user *s = buffer;
1966
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001967 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 (*ppos && !write)) {
1969 *lenp = 0;
1970 return 0;
1971 }
1972
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001973 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 min = (unsigned long *) table->extra1;
1975 max = (unsigned long *) table->extra2;
1976 vleft = table->maxlen / sizeof(unsigned long);
1977 left = *lenp;
1978
1979 for (; left && vleft--; i++, min++, max++, first=0) {
1980 if (write) {
1981 while (left) {
1982 char c;
1983 if (get_user(c, s))
1984 return -EFAULT;
1985 if (!isspace(c))
1986 break;
1987 left--;
1988 s++;
1989 }
1990 if (!left)
1991 break;
1992 neg = 0;
1993 len = left;
1994 if (len > TMPBUFLEN-1)
1995 len = TMPBUFLEN-1;
1996 if (copy_from_user(buf, s, len))
1997 return -EFAULT;
1998 buf[len] = 0;
1999 p = buf;
2000 if (*p == '-' && left > 1) {
2001 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002002 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 }
2004 if (*p < '0' || *p > '9')
2005 break;
2006 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2007 len = p-buf;
2008 if ((len < left) && *p && !isspace(*p))
2009 break;
2010 if (neg)
2011 val = -val;
2012 s += len;
2013 left -= len;
2014
2015 if(neg)
2016 continue;
2017 if ((min && val < *min) || (max && val > *max))
2018 continue;
2019 *i = val;
2020 } else {
2021 p = buf;
2022 if (!first)
2023 *p++ = '\t';
2024 sprintf(p, "%lu", convdiv * (*i) / convmul);
2025 len = strlen(buf);
2026 if (len > left)
2027 len = left;
2028 if(copy_to_user(s, buf, len))
2029 return -EFAULT;
2030 left -= len;
2031 s += len;
2032 }
2033 }
2034
2035 if (!write && !first && left) {
2036 if(put_user('\n', s))
2037 return -EFAULT;
2038 left--, s++;
2039 }
2040 if (write) {
2041 while (left) {
2042 char c;
2043 if (get_user(c, s++))
2044 return -EFAULT;
2045 if (!isspace(c))
2046 break;
2047 left--;
2048 }
2049 }
2050 if (write && first)
2051 return -EINVAL;
2052 *lenp -= left;
2053 *ppos += *lenp;
2054 return 0;
2055#undef TMPBUFLEN
2056}
2057
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002058static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002059 struct file *filp,
2060 void __user *buffer,
2061 size_t *lenp, loff_t *ppos,
2062 unsigned long convmul,
2063 unsigned long convdiv)
2064{
2065 return __do_proc_doulongvec_minmax(table->data, table, write,
2066 filp, buffer, lenp, ppos, convmul, convdiv);
2067}
2068
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069/**
2070 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2071 * @table: the sysctl table
2072 * @write: %TRUE if this is a write to the sysctl file
2073 * @filp: the file structure
2074 * @buffer: the user buffer
2075 * @lenp: the size of the user buffer
2076 * @ppos: file position
2077 *
2078 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2079 * values from/to the user buffer, treated as an ASCII string.
2080 *
2081 * This routine will ensure the values are within the range specified by
2082 * table->extra1 (min) and table->extra2 (max).
2083 *
2084 * Returns 0 on success.
2085 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002086int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 void __user *buffer, size_t *lenp, loff_t *ppos)
2088{
2089 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2090}
2091
2092/**
2093 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2094 * @table: the sysctl table
2095 * @write: %TRUE if this is a write to the sysctl file
2096 * @filp: the file structure
2097 * @buffer: the user buffer
2098 * @lenp: the size of the user buffer
2099 * @ppos: file position
2100 *
2101 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2102 * values from/to the user buffer, treated as an ASCII string. The values
2103 * are treated as milliseconds, and converted to jiffies when they are stored.
2104 *
2105 * This routine will ensure the values are within the range specified by
2106 * table->extra1 (min) and table->extra2 (max).
2107 *
2108 * Returns 0 on success.
2109 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002110int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 struct file *filp,
2112 void __user *buffer,
2113 size_t *lenp, loff_t *ppos)
2114{
2115 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2116 lenp, ppos, HZ, 1000l);
2117}
2118
2119
2120static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2121 int *valp,
2122 int write, void *data)
2123{
2124 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002125 if (*lvalp > LONG_MAX / HZ)
2126 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2128 } else {
2129 int val = *valp;
2130 unsigned long lval;
2131 if (val < 0) {
2132 *negp = -1;
2133 lval = (unsigned long)-val;
2134 } else {
2135 *negp = 0;
2136 lval = (unsigned long)val;
2137 }
2138 *lvalp = lval / HZ;
2139 }
2140 return 0;
2141}
2142
2143static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2144 int *valp,
2145 int write, void *data)
2146{
2147 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002148 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2149 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2151 } else {
2152 int val = *valp;
2153 unsigned long lval;
2154 if (val < 0) {
2155 *negp = -1;
2156 lval = (unsigned long)-val;
2157 } else {
2158 *negp = 0;
2159 lval = (unsigned long)val;
2160 }
2161 *lvalp = jiffies_to_clock_t(lval);
2162 }
2163 return 0;
2164}
2165
2166static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2167 int *valp,
2168 int write, void *data)
2169{
2170 if (write) {
2171 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2172 } else {
2173 int val = *valp;
2174 unsigned long lval;
2175 if (val < 0) {
2176 *negp = -1;
2177 lval = (unsigned long)-val;
2178 } else {
2179 *negp = 0;
2180 lval = (unsigned long)val;
2181 }
2182 *lvalp = jiffies_to_msecs(lval);
2183 }
2184 return 0;
2185}
2186
2187/**
2188 * proc_dointvec_jiffies - read a vector of integers as seconds
2189 * @table: the sysctl table
2190 * @write: %TRUE if this is a write to the sysctl file
2191 * @filp: the file structure
2192 * @buffer: the user buffer
2193 * @lenp: the size of the user buffer
2194 * @ppos: file position
2195 *
2196 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2197 * values from/to the user buffer, treated as an ASCII string.
2198 * The values read are assumed to be in seconds, and are converted into
2199 * jiffies.
2200 *
2201 * Returns 0 on success.
2202 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002203int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 void __user *buffer, size_t *lenp, loff_t *ppos)
2205{
2206 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2207 do_proc_dointvec_jiffies_conv,NULL);
2208}
2209
2210/**
2211 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2212 * @table: the sysctl table
2213 * @write: %TRUE if this is a write to the sysctl file
2214 * @filp: the file structure
2215 * @buffer: the user buffer
2216 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002217 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 *
2219 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2220 * values from/to the user buffer, treated as an ASCII string.
2221 * The values read are assumed to be in 1/USER_HZ seconds, and
2222 * are converted into jiffies.
2223 *
2224 * Returns 0 on success.
2225 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002226int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 void __user *buffer, size_t *lenp, loff_t *ppos)
2228{
2229 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2230 do_proc_dointvec_userhz_jiffies_conv,NULL);
2231}
2232
2233/**
2234 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2235 * @table: the sysctl table
2236 * @write: %TRUE if this is a write to the sysctl file
2237 * @filp: the file structure
2238 * @buffer: the user buffer
2239 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002240 * @ppos: file position
2241 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 *
2243 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2244 * values from/to the user buffer, treated as an ASCII string.
2245 * The values read are assumed to be in 1/1000 seconds, and
2246 * are converted into jiffies.
2247 *
2248 * Returns 0 on success.
2249 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002250int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 void __user *buffer, size_t *lenp, loff_t *ppos)
2252{
2253 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2254 do_proc_dointvec_ms_jiffies_conv, NULL);
2255}
2256
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002257static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002258 void __user *buffer, size_t *lenp, loff_t *ppos)
2259{
2260 struct pid *new_pid;
2261 pid_t tmp;
2262 int r;
2263
2264 tmp = pid_nr(cad_pid);
2265
2266 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2267 lenp, ppos, NULL, NULL);
2268 if (r || !write)
2269 return r;
2270
2271 new_pid = find_get_pid(tmp);
2272 if (!new_pid)
2273 return -ESRCH;
2274
2275 put_pid(xchg(&cad_pid, new_pid));
2276 return 0;
2277}
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279#else /* CONFIG_PROC_FS */
2280
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002281int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 void __user *buffer, size_t *lenp, loff_t *ppos)
2283{
2284 return -ENOSYS;
2285}
2286
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002287int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 void __user *buffer, size_t *lenp, loff_t *ppos)
2289{
2290 return -ENOSYS;
2291}
2292
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002293int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 void __user *buffer, size_t *lenp, loff_t *ppos)
2295{
2296 return -ENOSYS;
2297}
2298
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002299int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 void __user *buffer, size_t *lenp, loff_t *ppos)
2301{
2302 return -ENOSYS;
2303}
2304
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002305int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 void __user *buffer, size_t *lenp, loff_t *ppos)
2307{
2308 return -ENOSYS;
2309}
2310
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002311int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 void __user *buffer, size_t *lenp, loff_t *ppos)
2313{
2314 return -ENOSYS;
2315}
2316
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002317int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 void __user *buffer, size_t *lenp, loff_t *ppos)
2319{
2320 return -ENOSYS;
2321}
2322
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002323int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 void __user *buffer, size_t *lenp, loff_t *ppos)
2325{
2326 return -ENOSYS;
2327}
2328
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002329int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 struct file *filp,
2331 void __user *buffer,
2332 size_t *lenp, loff_t *ppos)
2333{
2334 return -ENOSYS;
2335}
2336
2337
2338#endif /* CONFIG_PROC_FS */
2339
2340
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002341#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342/*
2343 * General sysctl support routines
2344 */
2345
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002346/* The generic sysctl data routine (used if no strategy routine supplied) */
2347int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2348 void __user *oldval, size_t __user *oldlenp,
2349 void __user *newval, size_t newlen)
2350{
2351 size_t len;
2352
2353 /* Get out of I don't have a variable */
2354 if (!table->data || !table->maxlen)
2355 return -ENOTDIR;
2356
2357 if (oldval && oldlenp) {
2358 if (get_user(len, oldlenp))
2359 return -EFAULT;
2360 if (len) {
2361 if (len > table->maxlen)
2362 len = table->maxlen;
2363 if (copy_to_user(oldval, table->data, len))
2364 return -EFAULT;
2365 if (put_user(len, oldlenp))
2366 return -EFAULT;
2367 }
2368 }
2369
2370 if (newval && newlen) {
2371 if (newlen > table->maxlen)
2372 newlen = table->maxlen;
2373
2374 if (copy_from_user(table->data, newval, newlen))
2375 return -EFAULT;
2376 }
2377 return 1;
2378}
2379
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002381int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 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{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 if (!table->data || !table->maxlen)
2386 return -ENOTDIR;
2387
2388 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002389 size_t bufsize;
2390 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002392 if (bufsize) {
2393 size_t len = strlen(table->data), copied;
2394
2395 /* This shouldn't trigger for a well-formed sysctl */
2396 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002398
2399 /* Copy up to a max of bufsize-1 bytes of the string */
2400 copied = (len >= bufsize) ? bufsize - 1 : len;
2401
2402 if (copy_to_user(oldval, table->data, copied) ||
2403 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002405 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 return -EFAULT;
2407 }
2408 }
2409 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002410 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 if (len > table->maxlen)
2412 len = table->maxlen;
2413 if(copy_from_user(table->data, newval, len))
2414 return -EFAULT;
2415 if (len == table->maxlen)
2416 len--;
2417 ((char *) table->data)[len] = 0;
2418 }
Yi Yang82c9df82005-12-30 16:37:10 +08002419 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420}
2421
2422/*
2423 * This function makes sure that all of the integers in the vector
2424 * are between the minimum and maximum values given in the arrays
2425 * table->extra1 and table->extra2, respectively.
2426 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002427int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002429 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430{
2431
2432 if (newval && newlen) {
2433 int __user *vec = (int __user *) newval;
2434 int *min = (int *) table->extra1;
2435 int *max = (int *) table->extra2;
2436 size_t length;
2437 int i;
2438
2439 if (newlen % sizeof(int) != 0)
2440 return -EINVAL;
2441
2442 if (!table->extra1 && !table->extra2)
2443 return 0;
2444
2445 if (newlen > table->maxlen)
2446 newlen = table->maxlen;
2447 length = newlen / sizeof(int);
2448
2449 for (i = 0; i < length; i++) {
2450 int value;
2451 if (get_user(value, vec + i))
2452 return -EFAULT;
2453 if (min && value < min[i])
2454 return -EINVAL;
2455 if (max && value > max[i])
2456 return -EINVAL;
2457 }
2458 }
2459 return 0;
2460}
2461
2462/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002463int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002465 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002467 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002469
2470 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002472 if (olen) {
2473 int val;
2474
2475 if (olen < sizeof(int))
2476 return -EINVAL;
2477
2478 val = *(int *)(table->data) / HZ;
2479 if (put_user(val, (int __user *)oldval))
2480 return -EFAULT;
2481 if (put_user(sizeof(int), oldlenp))
2482 return -EFAULT;
2483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 }
2485 if (newval && newlen) {
2486 int new;
2487 if (newlen != sizeof(int))
2488 return -EINVAL;
2489 if (get_user(new, (int __user *)newval))
2490 return -EFAULT;
2491 *(int *)(table->data) = new*HZ;
2492 }
2493 return 1;
2494}
2495
2496/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002497int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002499 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002501 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002503
2504 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002506 if (olen) {
2507 int val;
2508
2509 if (olen < sizeof(int))
2510 return -EINVAL;
2511
2512 val = jiffies_to_msecs(*(int *)(table->data));
2513 if (put_user(val, (int __user *)oldval))
2514 return -EFAULT;
2515 if (put_user(sizeof(int), oldlenp))
2516 return -EFAULT;
2517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 }
2519 if (newval && newlen) {
2520 int new;
2521 if (newlen != sizeof(int))
2522 return -EINVAL;
2523 if (get_user(new, (int __user *)newval))
2524 return -EFAULT;
2525 *(int *)(table->data) = msecs_to_jiffies(new);
2526 }
2527 return 1;
2528}
2529
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002530
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002531
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002532#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
2534
2535asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2536{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002537 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002538 struct __sysctl_args tmp;
2539 int name[CTL_MAXNAME];
2540 int i;
2541
2542 /* Read in the sysctl name for better debug message logging */
2543 if (copy_from_user(&tmp, args, sizeof(tmp)))
2544 return -EFAULT;
2545 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2546 return -ENOTDIR;
2547 for (i = 0; i < tmp.nlen; i++)
2548 if (get_user(name[i], tmp.name + i))
2549 return -EFAULT;
2550
2551 /* Ignore accesses to kernel.version */
2552 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2553 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002554
2555 if (msg_count < 5) {
2556 msg_count++;
2557 printk(KERN_INFO
2558 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002559 "system call with ", current->comm);
2560 for (i = 0; i < tmp.nlen; i++)
2561 printk("%d.", name[i]);
2562 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002563 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002564out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 return -ENOSYS;
2566}
2567
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002568int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2569 void __user *oldval, size_t __user *oldlenp,
2570 void __user *newval, size_t newlen)
2571{
2572 return -ENOSYS;
2573}
2574
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002575int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002577 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578{
2579 return -ENOSYS;
2580}
2581
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002582int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002584 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585{
2586 return -ENOSYS;
2587}
2588
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002589int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002591 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592{
2593 return -ENOSYS;
2594}
2595
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002596int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002598 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599{
2600 return -ENOSYS;
2601}
2602
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002603#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
2605/*
2606 * No sense putting this after each symbol definition, twice,
2607 * exception granted :-)
2608 */
2609EXPORT_SYMBOL(proc_dointvec);
2610EXPORT_SYMBOL(proc_dointvec_jiffies);
2611EXPORT_SYMBOL(proc_dointvec_minmax);
2612EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2613EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2614EXPORT_SYMBOL(proc_dostring);
2615EXPORT_SYMBOL(proc_doulongvec_minmax);
2616EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2617EXPORT_SYMBOL(register_sysctl_table);
2618EXPORT_SYMBOL(sysctl_intvec);
2619EXPORT_SYMBOL(sysctl_jiffies);
2620EXPORT_SYMBOL(sysctl_ms_jiffies);
2621EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002622EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623EXPORT_SYMBOL(unregister_sysctl_table);