blob: 96f31c1bc4f0ad3223b92d64a6bfd9a6f22c1eb0 [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>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.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
Eric W. Biederman7058cb02007-10-18 03:05:58 -070058static int deprecated_sysctl_warning(struct __sysctl_args *args);
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#if defined(CONFIG_SYSCTL)
61
62/* External variables not in a header file. */
63extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070064extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065extern int sysctl_overcommit_memory;
66extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070067extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070068extern int sysctl_oom_kill_allocating_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070071extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int pid_max;
74extern int min_free_kbytes;
75extern int printk_ratelimit_jiffies;
76extern int printk_ratelimit_burst;
77extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080078extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080079extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020080extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070081extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070082extern int sysctl_stat_interval;
Peter Zijlstrabdf4c482007-07-19 01:48:15 -070083extern int audit_argv_kb;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070085/* Constants used for minimum and maximum */
86#ifdef CONFIG_DETECT_SOFTLOCKUP
87static int one = 1;
88static int sixty = 60;
89#endif
90
91#ifdef CONFIG_MMU
92static int two = 2;
93#endif
94
95static int zero;
96static int one_hundred = 100;
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
99static int maxolduid = 65535;
100static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800101static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103static int ngroups_max = NGROUPS_MAX;
104
105#ifdef CONFIG_KMOD
106extern char modprobe_path[];
107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#ifdef CONFIG_CHR_DEV_SG
109extern int sg_big_buff;
110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112#ifdef __sparc__
113extern char reboot_command [];
114extern int stop_a_enabled;
115extern int scons_pwroff;
116#endif
117
118#ifdef __hppa__
119extern int pwrsw_enabled;
120extern int unaligned_enabled;
121#endif
122
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800123#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#ifdef CONFIG_MATHEMU
125extern int sysctl_ieee_emulation_warnings;
126#endif
127extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700128extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#endif
130
131extern int sysctl_hz_timer;
132
133#ifdef CONFIG_BSD_PROCESS_ACCT
134extern int acct_parm[];
135#endif
136
Jes Sorensend2b176e2006-02-28 09:42:23 -0800137#ifdef CONFIG_IA64
138extern int no_unaligned_warning;
139#endif
140
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700141#ifdef CONFIG_RT_MUTEXES
142extern int max_lock_depth;
143#endif
144
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700145#ifdef CONFIG_SYSCTL_SYSCALL
146static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700147 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700148#endif
149
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800150
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700151#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700152static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700153 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700154static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800155 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700156#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700157
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static struct ctl_table root_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static struct ctl_table_header root_table_header =
160 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
161
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700162static struct ctl_table kern_table[];
163static struct ctl_table vm_table[];
164static struct ctl_table fs_table[];
165static struct ctl_table debug_table[];
166static struct ctl_table dev_table[];
167extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700168#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700169extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400170#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
173int sysctl_legacy_va_layout;
174#endif
175
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700176extern int prove_locking;
177extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179/* The default sysctl tables: */
180
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700181static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 {
183 .ctl_name = CTL_KERN,
184 .procname = "kernel",
185 .mode = 0555,
186 .child = kern_table,
187 },
188 {
189 .ctl_name = CTL_VM,
190 .procname = "vm",
191 .mode = 0555,
192 .child = vm_table,
193 },
194#ifdef CONFIG_NET
195 {
196 .ctl_name = CTL_NET,
197 .procname = "net",
198 .mode = 0555,
199 .child = net_table,
200 },
201#endif
202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
207 },
208 {
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
213 },
214 {
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
219 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700220/*
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 { .ctl_name = 0 }
225};
226
Ingo Molnar77e54a12007-07-09 18:52:00 +0200227#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100228static int min_sched_granularity_ns = 100000; /* 100 usecs */
229static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230static int min_wakeup_granularity_ns; /* 0 usecs */
231static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200232#endif
233
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700234static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#ifdef CONFIG_SCHED_DEBUG
236 {
237 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240 .maxlen = sizeof(unsigned int),
241 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246 },
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_batch_wakeup_granularity_ns",
272 .data = &sysctl_sched_batch_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
287 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200288 {
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_features",
291 .data = &sysctl_sched_features,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec,
295 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200296 {
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_migration_cost",
299 .data = &sysctl_sched_migration_cost,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
302 .proc_handler = &proc_dointvec,
303 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100304 {
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_nr_migrate",
307 .data = &sysctl_sched_nr_migrate,
308 .maxlen = sizeof(unsigned int),
309 .mode = 644,
310 .proc_handler = &proc_dointvec,
311 },
Srivatsa Vaddagiri6b2d7702008-01-25 21:08:00 +0100312#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
313 {
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_min_bal_int_shares",
316 .data = &sysctl_sched_min_bal_int_shares,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
319 .proc_handler = &proc_dointvec,
320 },
321 {
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_max_bal_int_shares",
324 .data = &sysctl_sched_max_bal_int_shares,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
328 },
329#endif
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200330#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200331 {
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_compat_yield",
334 .data = &sysctl_sched_compat_yield,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
338 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700339#ifdef CONFIG_PROVE_LOCKING
340 {
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "prove_locking",
343 .data = &prove_locking,
344 .maxlen = sizeof(int),
345 .mode = 0644,
346 .proc_handler = &proc_dointvec,
347 },
348#endif
349#ifdef CONFIG_LOCK_STAT
350 {
351 .ctl_name = CTL_UNNUMBERED,
352 .procname = "lock_stat",
353 .data = &lock_stat,
354 .maxlen = sizeof(int),
355 .mode = 0644,
356 .proc_handler = &proc_dointvec,
357 },
358#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200359 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 .ctl_name = KERN_PANIC,
361 .procname = "panic",
362 .data = &panic_timeout,
363 .maxlen = sizeof(int),
364 .mode = 0644,
365 .proc_handler = &proc_dointvec,
366 },
367 {
368 .ctl_name = KERN_CORE_USES_PID,
369 .procname = "core_uses_pid",
370 .data = &core_uses_pid,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = &proc_dointvec,
374 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700375#ifdef CONFIG_AUDITSYSCALL
376 {
377 .ctl_name = CTL_UNNUMBERED,
378 .procname = "audit_argv_kb",
379 .data = &audit_argv_kb,
380 .maxlen = sizeof(int),
381 .mode = 0644,
382 .proc_handler = &proc_dointvec,
383 },
384#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 {
386 .ctl_name = KERN_CORE_PATTERN,
387 .procname = "core_pattern",
388 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700389 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 .mode = 0644,
391 .proc_handler = &proc_dostring,
392 .strategy = &sysctl_string,
393 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800394#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 .procname = "tainted",
397 .data = &tainted,
398 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800399 .mode = 0644,
400 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800402#endif
Andrew Morgan72c2d582007-10-18 03:05:59 -0700403#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 .procname = "cap-bound",
406 .data = &cap_bset,
407 .maxlen = sizeof(kernel_cap_t),
408 .mode = 0600,
409 .proc_handler = &proc_dointvec_bset,
410 },
Andrew Morgan72c2d582007-10-18 03:05:59 -0700411#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412#ifdef CONFIG_BLK_DEV_INITRD
413 {
414 .ctl_name = KERN_REALROOTDEV,
415 .procname = "real-root-dev",
416 .data = &real_root_dev,
417 .maxlen = sizeof(int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
420 },
421#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700422 {
423 .ctl_name = CTL_UNNUMBERED,
424 .procname = "print-fatal-signals",
425 .data = &print_fatal_signals,
426 .maxlen = sizeof(int),
427 .mode = 0644,
428 .proc_handler = &proc_dointvec,
429 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430#ifdef __sparc__
431 {
432 .ctl_name = KERN_SPARC_REBOOT,
433 .procname = "reboot-cmd",
434 .data = reboot_command,
435 .maxlen = 256,
436 .mode = 0644,
437 .proc_handler = &proc_dostring,
438 .strategy = &sysctl_string,
439 },
440 {
441 .ctl_name = KERN_SPARC_STOP_A,
442 .procname = "stop-a",
443 .data = &stop_a_enabled,
444 .maxlen = sizeof (int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
447 },
448 {
449 .ctl_name = KERN_SPARC_SCONS_PWROFF,
450 .procname = "scons-poweroff",
451 .data = &scons_pwroff,
452 .maxlen = sizeof (int),
453 .mode = 0644,
454 .proc_handler = &proc_dointvec,
455 },
456#endif
457#ifdef __hppa__
458 {
459 .ctl_name = KERN_HPPA_PWRSW,
460 .procname = "soft-power",
461 .data = &pwrsw_enabled,
462 .maxlen = sizeof (int),
463 .mode = 0644,
464 .proc_handler = &proc_dointvec,
465 },
466 {
467 .ctl_name = KERN_HPPA_UNALIGNED,
468 .procname = "unaligned-trap",
469 .data = &unaligned_enabled,
470 .maxlen = sizeof (int),
471 .mode = 0644,
472 .proc_handler = &proc_dointvec,
473 },
474#endif
475 {
476 .ctl_name = KERN_CTLALTDEL,
477 .procname = "ctrl-alt-del",
478 .data = &C_A_D,
479 .maxlen = sizeof(int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
482 },
483 {
484 .ctl_name = KERN_PRINTK,
485 .procname = "printk",
486 .data = &console_loglevel,
487 .maxlen = 4*sizeof(int),
488 .mode = 0644,
489 .proc_handler = &proc_dointvec,
490 },
491#ifdef CONFIG_KMOD
492 {
493 .ctl_name = KERN_MODPROBE,
494 .procname = "modprobe",
495 .data = &modprobe_path,
496 .maxlen = KMOD_PATH_LEN,
497 .mode = 0644,
498 .proc_handler = &proc_dostring,
499 .strategy = &sysctl_string,
500 },
501#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700502#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 {
504 .ctl_name = KERN_HOTPLUG,
505 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100506 .data = &uevent_helper,
507 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .mode = 0644,
509 .proc_handler = &proc_dostring,
510 .strategy = &sysctl_string,
511 },
512#endif
513#ifdef CONFIG_CHR_DEV_SG
514 {
515 .ctl_name = KERN_SG_BIG_BUFF,
516 .procname = "sg-big-buff",
517 .data = &sg_big_buff,
518 .maxlen = sizeof (int),
519 .mode = 0444,
520 .proc_handler = &proc_dointvec,
521 },
522#endif
523#ifdef CONFIG_BSD_PROCESS_ACCT
524 {
525 .ctl_name = KERN_ACCT,
526 .procname = "acct",
527 .data = &acct_parm,
528 .maxlen = 3*sizeof(int),
529 .mode = 0644,
530 .proc_handler = &proc_dointvec,
531 },
532#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533#ifdef CONFIG_MAGIC_SYSRQ
534 {
535 .ctl_name = KERN_SYSRQ,
536 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800537 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 .maxlen = sizeof (int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec,
541 },
542#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700543#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700546 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 .maxlen = sizeof (int),
548 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700549 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700551#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 {
553 .ctl_name = KERN_MAX_THREADS,
554 .procname = "threads-max",
555 .data = &max_threads,
556 .maxlen = sizeof(int),
557 .mode = 0644,
558 .proc_handler = &proc_dointvec,
559 },
560 {
561 .ctl_name = KERN_RANDOM,
562 .procname = "random",
563 .mode = 0555,
564 .child = random_table,
565 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 {
567 .ctl_name = KERN_OVERFLOWUID,
568 .procname = "overflowuid",
569 .data = &overflowuid,
570 .maxlen = sizeof(int),
571 .mode = 0644,
572 .proc_handler = &proc_dointvec_minmax,
573 .strategy = &sysctl_intvec,
574 .extra1 = &minolduid,
575 .extra2 = &maxolduid,
576 },
577 {
578 .ctl_name = KERN_OVERFLOWGID,
579 .procname = "overflowgid",
580 .data = &overflowgid,
581 .maxlen = sizeof(int),
582 .mode = 0644,
583 .proc_handler = &proc_dointvec_minmax,
584 .strategy = &sysctl_intvec,
585 .extra1 = &minolduid,
586 .extra2 = &maxolduid,
587 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800588#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#ifdef CONFIG_MATHEMU
590 {
591 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
592 .procname = "ieee_emulation_warnings",
593 .data = &sysctl_ieee_emulation_warnings,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec,
597 },
598#endif
599#ifdef CONFIG_NO_IDLE_HZ
600 {
601 .ctl_name = KERN_HZ_TIMER,
602 .procname = "hz_timer",
603 .data = &sysctl_hz_timer,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec,
607 },
608#endif
609 {
610 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
611 .procname = "userprocess_debug",
612 .data = &sysctl_userprocess_debug,
613 .maxlen = sizeof(int),
614 .mode = 0644,
615 .proc_handler = &proc_dointvec,
616 },
617#endif
618 {
619 .ctl_name = KERN_PIDMAX,
620 .procname = "pid_max",
621 .data = &pid_max,
622 .maxlen = sizeof (int),
623 .mode = 0644,
624 .proc_handler = &proc_dointvec_minmax,
625 .strategy = sysctl_intvec,
626 .extra1 = &pid_max_min,
627 .extra2 = &pid_max_max,
628 },
629 {
630 .ctl_name = KERN_PANIC_ON_OOPS,
631 .procname = "panic_on_oops",
632 .data = &panic_on_oops,
633 .maxlen = sizeof(int),
634 .mode = 0644,
635 .proc_handler = &proc_dointvec,
636 },
637 {
638 .ctl_name = KERN_PRINTK_RATELIMIT,
639 .procname = "printk_ratelimit",
640 .data = &printk_ratelimit_jiffies,
641 .maxlen = sizeof(int),
642 .mode = 0644,
643 .proc_handler = &proc_dointvec_jiffies,
644 .strategy = &sysctl_jiffies,
645 },
646 {
647 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
648 .procname = "printk_ratelimit_burst",
649 .data = &printk_ratelimit_burst,
650 .maxlen = sizeof(int),
651 .mode = 0644,
652 .proc_handler = &proc_dointvec,
653 },
654 {
655 .ctl_name = KERN_NGROUPS_MAX,
656 .procname = "ngroups_max",
657 .data = &ngroups_max,
658 .maxlen = sizeof (int),
659 .mode = 0444,
660 .proc_handler = &proc_dointvec,
661 },
662#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
663 {
664 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
665 .procname = "unknown_nmi_panic",
666 .data = &unknown_nmi_panic,
667 .maxlen = sizeof (int),
668 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200669 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 },
Don Zickus407984f2006-09-26 10:52:27 +0200671 {
Don Zickus407984f2006-09-26 10:52:27 +0200672 .procname = "nmi_watchdog",
673 .data = &nmi_watchdog_enabled,
674 .maxlen = sizeof (int),
675 .mode = 0644,
676 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 },
678#endif
679#if defined(CONFIG_X86)
680 {
Don Zickus8da5add2006-09-26 10:52:27 +0200681 .ctl_name = KERN_PANIC_ON_NMI,
682 .procname = "panic_on_unrecovered_nmi",
683 .data = &panic_on_unrecovered_nmi,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec,
687 },
688 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .ctl_name = KERN_BOOTLOADER_TYPE,
690 .procname = "bootloader_type",
691 .data = &bootloader_type,
692 .maxlen = sizeof (int),
693 .mode = 0444,
694 .proc_handler = &proc_dointvec,
695 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100696 {
697 .ctl_name = CTL_UNNUMBERED,
698 .procname = "kstack_depth_to_print",
699 .data = &kstack_depth_to_print,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = &proc_dointvec,
703 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800705#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 {
707 .ctl_name = KERN_RANDOMIZE,
708 .procname = "randomize_va_space",
709 .data = &randomize_va_space,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800714#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800715#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700716 {
717 .ctl_name = KERN_SPIN_RETRY,
718 .procname = "spin_retry",
719 .data = &spin_retry,
720 .maxlen = sizeof (int),
721 .mode = 0644,
722 .proc_handler = &proc_dointvec,
723 },
724#endif
Len Brown673d5b42007-07-28 03:33:16 -0400725#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800726 {
Pavel Machekc255d842006-02-20 18:27:58 -0800727 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700728 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800729 .maxlen = sizeof (unsigned long),
730 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800731 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800732 },
733#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800734#ifdef CONFIG_IA64
735 {
736 .ctl_name = KERN_IA64_UNALIGNED,
737 .procname = "ignore-unaligned-usertrap",
738 .data = &no_unaligned_warning,
739 .maxlen = sizeof (int),
740 .mode = 0644,
741 .proc_handler = &proc_dointvec,
742 },
743#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700744#ifdef CONFIG_DETECT_SOFTLOCKUP
745 {
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "softlockup_thresh",
748 .data = &softlockup_thresh,
749 .maxlen = sizeof(int),
750 .mode = 0644,
751 .proc_handler = &proc_dointvec_minmax,
752 .strategy = &sysctl_intvec,
753 .extra1 = &one,
754 .extra2 = &sixty,
755 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100756 {
757 .ctl_name = CTL_UNNUMBERED,
758 .procname = "hung_task_check_count",
759 .data = &sysctl_hung_task_check_count,
760 .maxlen = sizeof(int),
761 .mode = 0644,
762 .proc_handler = &proc_dointvec_minmax,
763 .strategy = &sysctl_intvec,
764 },
765 {
766 .ctl_name = CTL_UNNUMBERED,
767 .procname = "hung_task_timeout_secs",
768 .data = &sysctl_hung_task_timeout_secs,
769 .maxlen = sizeof(int),
770 .mode = 0644,
771 .proc_handler = &proc_dointvec_minmax,
772 .strategy = &sysctl_intvec,
773 },
774 {
775 .ctl_name = CTL_UNNUMBERED,
776 .procname = "hung_task_warnings",
777 .data = &sysctl_hung_task_warnings,
778 .maxlen = sizeof(int),
779 .mode = 0644,
780 .proc_handler = &proc_dointvec_minmax,
781 .strategy = &sysctl_intvec,
782 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700783#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200784#ifdef CONFIG_COMPAT
785 {
786 .ctl_name = KERN_COMPAT_LOG,
787 .procname = "compat-log",
788 .data = &compat_log,
789 .maxlen = sizeof (int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
792 },
793#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700794#ifdef CONFIG_RT_MUTEXES
795 {
796 .ctl_name = KERN_MAX_LOCK_DEPTH,
797 .procname = "max_lock_depth",
798 .data = &max_lock_depth,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
803#endif
Kees Cook5096add2007-05-08 00:26:04 -0700804#ifdef CONFIG_PROC_FS
805 {
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "maps_protect",
808 .data = &maps_protect,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = &proc_dointvec,
812 },
813#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700814 {
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "poweroff_cmd",
817 .data = &poweroff_cmd,
818 .maxlen = POWEROFF_CMD_PATH_LEN,
819 .mode = 0644,
820 .proc_handler = &proc_dostring,
821 .strategy = &sysctl_string,
822 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700823/*
824 * NOTE: do not add new entries to this table unless you have read
825 * Documentation/sysctl/ctl_unnumbered.txt
826 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 { .ctl_name = 0 }
828};
829
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700830static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 {
832 .ctl_name = VM_OVERCOMMIT_MEMORY,
833 .procname = "overcommit_memory",
834 .data = &sysctl_overcommit_memory,
835 .maxlen = sizeof(sysctl_overcommit_memory),
836 .mode = 0644,
837 .proc_handler = &proc_dointvec,
838 },
839 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700840 .ctl_name = VM_PANIC_ON_OOM,
841 .procname = "panic_on_oom",
842 .data = &sysctl_panic_on_oom,
843 .maxlen = sizeof(sysctl_panic_on_oom),
844 .mode = 0644,
845 .proc_handler = &proc_dointvec,
846 },
847 {
David Rientjesfe071d72007-10-16 23:25:56 -0700848 .ctl_name = CTL_UNNUMBERED,
849 .procname = "oom_kill_allocating_task",
850 .data = &sysctl_oom_kill_allocating_task,
851 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
852 .mode = 0644,
853 .proc_handler = &proc_dointvec,
854 },
855 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 .ctl_name = VM_OVERCOMMIT_RATIO,
857 .procname = "overcommit_ratio",
858 .data = &sysctl_overcommit_ratio,
859 .maxlen = sizeof(sysctl_overcommit_ratio),
860 .mode = 0644,
861 .proc_handler = &proc_dointvec,
862 },
863 {
864 .ctl_name = VM_PAGE_CLUSTER,
865 .procname = "page-cluster",
866 .data = &page_cluster,
867 .maxlen = sizeof(int),
868 .mode = 0644,
869 .proc_handler = &proc_dointvec,
870 },
871 {
872 .ctl_name = VM_DIRTY_BACKGROUND,
873 .procname = "dirty_background_ratio",
874 .data = &dirty_background_ratio,
875 .maxlen = sizeof(dirty_background_ratio),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec_minmax,
878 .strategy = &sysctl_intvec,
879 .extra1 = &zero,
880 .extra2 = &one_hundred,
881 },
882 {
883 .ctl_name = VM_DIRTY_RATIO,
884 .procname = "dirty_ratio",
885 .data = &vm_dirty_ratio,
886 .maxlen = sizeof(vm_dirty_ratio),
887 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700888 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 .strategy = &sysctl_intvec,
890 .extra1 = &zero,
891 .extra2 = &one_hundred,
892 },
893 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800895 .data = &dirty_writeback_interval,
896 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 .mode = 0644,
898 .proc_handler = &dirty_writeback_centisecs_handler,
899 },
900 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800902 .data = &dirty_expire_interval,
903 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800905 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 },
907 {
908 .ctl_name = VM_NR_PDFLUSH_THREADS,
909 .procname = "nr_pdflush_threads",
910 .data = &nr_pdflush_threads,
911 .maxlen = sizeof nr_pdflush_threads,
912 .mode = 0444 /* read-only*/,
913 .proc_handler = &proc_dointvec,
914 },
915 {
916 .ctl_name = VM_SWAPPINESS,
917 .procname = "swappiness",
918 .data = &vm_swappiness,
919 .maxlen = sizeof(vm_swappiness),
920 .mode = 0644,
921 .proc_handler = &proc_dointvec_minmax,
922 .strategy = &sysctl_intvec,
923 .extra1 = &zero,
924 .extra2 = &one_hundred,
925 },
926#ifdef CONFIG_HUGETLB_PAGE
927 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 .procname = "nr_hugepages",
929 .data = &max_huge_pages,
930 .maxlen = sizeof(unsigned long),
931 .mode = 0644,
932 .proc_handler = &hugetlb_sysctl_handler,
933 .extra1 = (void *)&hugetlb_zero,
934 .extra2 = (void *)&hugetlb_infinity,
935 },
936 {
937 .ctl_name = VM_HUGETLB_GROUP,
938 .procname = "hugetlb_shm_group",
939 .data = &sysctl_hugetlb_shm_group,
940 .maxlen = sizeof(gid_t),
941 .mode = 0644,
942 .proc_handler = &proc_dointvec,
943 },
Mel Gorman396faf02007-07-17 04:03:13 -0700944 {
945 .ctl_name = CTL_UNNUMBERED,
946 .procname = "hugepages_treat_as_movable",
947 .data = &hugepages_treat_as_movable,
948 .maxlen = sizeof(int),
949 .mode = 0644,
950 .proc_handler = &hugetlb_treat_movable_handler,
951 },
Adam Litke54f9f802007-10-16 01:26:20 -0700952 {
953 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800954 .procname = "nr_overcommit_hugepages",
955 .data = &nr_overcommit_huge_pages,
956 .maxlen = sizeof(nr_overcommit_huge_pages),
957 .mode = 0644,
958 .proc_handler = &proc_doulongvec_minmax,
959 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960#endif
961 {
962 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
963 .procname = "lowmem_reserve_ratio",
964 .data = &sysctl_lowmem_reserve_ratio,
965 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
966 .mode = 0644,
967 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
968 .strategy = &sysctl_intvec,
969 },
970 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800971 .ctl_name = VM_DROP_PAGECACHE,
972 .procname = "drop_caches",
973 .data = &sysctl_drop_caches,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = drop_caches_sysctl_handler,
977 .strategy = &sysctl_intvec,
978 },
979 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 .ctl_name = VM_MIN_FREE_KBYTES,
981 .procname = "min_free_kbytes",
982 .data = &min_free_kbytes,
983 .maxlen = sizeof(min_free_kbytes),
984 .mode = 0644,
985 .proc_handler = &min_free_kbytes_sysctl_handler,
986 .strategy = &sysctl_intvec,
987 .extra1 = &zero,
988 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800989 {
990 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
991 .procname = "percpu_pagelist_fraction",
992 .data = &percpu_pagelist_fraction,
993 .maxlen = sizeof(percpu_pagelist_fraction),
994 .mode = 0644,
995 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
996 .strategy = &sysctl_intvec,
997 .extra1 = &min_percpu_pagelist_fract,
998 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999#ifdef CONFIG_MMU
1000 {
1001 .ctl_name = VM_MAX_MAP_COUNT,
1002 .procname = "max_map_count",
1003 .data = &sysctl_max_map_count,
1004 .maxlen = sizeof(sysctl_max_map_count),
1005 .mode = 0644,
1006 .proc_handler = &proc_dointvec
1007 },
1008#endif
1009 {
1010 .ctl_name = VM_LAPTOP_MODE,
1011 .procname = "laptop_mode",
1012 .data = &laptop_mode,
1013 .maxlen = sizeof(laptop_mode),
1014 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001015 .proc_handler = &proc_dointvec_jiffies,
1016 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 },
1018 {
1019 .ctl_name = VM_BLOCK_DUMP,
1020 .procname = "block_dump",
1021 .data = &block_dump,
1022 .maxlen = sizeof(block_dump),
1023 .mode = 0644,
1024 .proc_handler = &proc_dointvec,
1025 .strategy = &sysctl_intvec,
1026 .extra1 = &zero,
1027 },
1028 {
1029 .ctl_name = VM_VFS_CACHE_PRESSURE,
1030 .procname = "vfs_cache_pressure",
1031 .data = &sysctl_vfs_cache_pressure,
1032 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1033 .mode = 0644,
1034 .proc_handler = &proc_dointvec,
1035 .strategy = &sysctl_intvec,
1036 .extra1 = &zero,
1037 },
1038#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1039 {
1040 .ctl_name = VM_LEGACY_VA_LAYOUT,
1041 .procname = "legacy_va_layout",
1042 .data = &sysctl_legacy_va_layout,
1043 .maxlen = sizeof(sysctl_legacy_va_layout),
1044 .mode = 0644,
1045 .proc_handler = &proc_dointvec,
1046 .strategy = &sysctl_intvec,
1047 .extra1 = &zero,
1048 },
1049#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001050#ifdef CONFIG_NUMA
1051 {
1052 .ctl_name = VM_ZONE_RECLAIM_MODE,
1053 .procname = "zone_reclaim_mode",
1054 .data = &zone_reclaim_mode,
1055 .maxlen = sizeof(zone_reclaim_mode),
1056 .mode = 0644,
1057 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001058 .strategy = &sysctl_intvec,
1059 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001060 },
Christoph Lameter96146342006-07-03 00:24:13 -07001061 {
1062 .ctl_name = VM_MIN_UNMAPPED,
1063 .procname = "min_unmapped_ratio",
1064 .data = &sysctl_min_unmapped_ratio,
1065 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1066 .mode = 0644,
1067 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1068 .strategy = &sysctl_intvec,
1069 .extra1 = &zero,
1070 .extra2 = &one_hundred,
1071 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001072 {
1073 .ctl_name = VM_MIN_SLAB,
1074 .procname = "min_slab_ratio",
1075 .data = &sysctl_min_slab_ratio,
1076 .maxlen = sizeof(sysctl_min_slab_ratio),
1077 .mode = 0644,
1078 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1079 .strategy = &sysctl_intvec,
1080 .extra1 = &zero,
1081 .extra2 = &one_hundred,
1082 },
Christoph Lameter17436602006-01-18 17:42:32 -08001083#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001084#ifdef CONFIG_SMP
1085 {
1086 .ctl_name = CTL_UNNUMBERED,
1087 .procname = "stat_interval",
1088 .data = &sysctl_stat_interval,
1089 .maxlen = sizeof(sysctl_stat_interval),
1090 .mode = 0644,
1091 .proc_handler = &proc_dointvec_jiffies,
1092 .strategy = &sysctl_jiffies,
1093 },
1094#endif
Eric Parised032182007-06-28 15:55:21 -04001095#ifdef CONFIG_SECURITY
1096 {
1097 .ctl_name = CTL_UNNUMBERED,
1098 .procname = "mmap_min_addr",
1099 .data = &mmap_min_addr,
1100 .maxlen = sizeof(unsigned long),
1101 .mode = 0644,
1102 .proc_handler = &proc_doulongvec_minmax,
1103 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001104#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001105#ifdef CONFIG_NUMA
1106 {
1107 .ctl_name = CTL_UNNUMBERED,
1108 .procname = "numa_zonelist_order",
1109 .data = &numa_zonelist_order,
1110 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1111 .mode = 0644,
1112 .proc_handler = &numa_zonelist_order_handler,
1113 .strategy = &sysctl_string,
1114 },
1115#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001116#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001117 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001118 {
1119 .ctl_name = VM_VDSO_ENABLED,
1120 .procname = "vdso_enabled",
1121 .data = &vdso_enabled,
1122 .maxlen = sizeof(vdso_enabled),
1123 .mode = 0644,
1124 .proc_handler = &proc_dointvec,
1125 .strategy = &sysctl_intvec,
1126 .extra1 = &zero,
1127 },
1128#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001129/*
1130 * NOTE: do not add new entries to this table unless you have read
1131 * Documentation/sysctl/ctl_unnumbered.txt
1132 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 { .ctl_name = 0 }
1134};
1135
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001136#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001137static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001138 { .ctl_name = 0 }
1139};
1140#endif
1141
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001142static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 {
1144 .ctl_name = FS_NRINODE,
1145 .procname = "inode-nr",
1146 .data = &inodes_stat,
1147 .maxlen = 2*sizeof(int),
1148 .mode = 0444,
1149 .proc_handler = &proc_dointvec,
1150 },
1151 {
1152 .ctl_name = FS_STATINODE,
1153 .procname = "inode-state",
1154 .data = &inodes_stat,
1155 .maxlen = 7*sizeof(int),
1156 .mode = 0444,
1157 .proc_handler = &proc_dointvec,
1158 },
1159 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 .procname = "file-nr",
1161 .data = &files_stat,
1162 .maxlen = 3*sizeof(int),
1163 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001164 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 },
1166 {
1167 .ctl_name = FS_MAXFILE,
1168 .procname = "file-max",
1169 .data = &files_stat.max_files,
1170 .maxlen = sizeof(int),
1171 .mode = 0644,
1172 .proc_handler = &proc_dointvec,
1173 },
1174 {
1175 .ctl_name = FS_DENTRY,
1176 .procname = "dentry-state",
1177 .data = &dentry_stat,
1178 .maxlen = 6*sizeof(int),
1179 .mode = 0444,
1180 .proc_handler = &proc_dointvec,
1181 },
1182 {
1183 .ctl_name = FS_OVERFLOWUID,
1184 .procname = "overflowuid",
1185 .data = &fs_overflowuid,
1186 .maxlen = sizeof(int),
1187 .mode = 0644,
1188 .proc_handler = &proc_dointvec_minmax,
1189 .strategy = &sysctl_intvec,
1190 .extra1 = &minolduid,
1191 .extra2 = &maxolduid,
1192 },
1193 {
1194 .ctl_name = FS_OVERFLOWGID,
1195 .procname = "overflowgid",
1196 .data = &fs_overflowgid,
1197 .maxlen = sizeof(int),
1198 .mode = 0644,
1199 .proc_handler = &proc_dointvec_minmax,
1200 .strategy = &sysctl_intvec,
1201 .extra1 = &minolduid,
1202 .extra2 = &maxolduid,
1203 },
1204 {
1205 .ctl_name = FS_LEASES,
1206 .procname = "leases-enable",
1207 .data = &leases_enable,
1208 .maxlen = sizeof(int),
1209 .mode = 0644,
1210 .proc_handler = &proc_dointvec,
1211 },
1212#ifdef CONFIG_DNOTIFY
1213 {
1214 .ctl_name = FS_DIR_NOTIFY,
1215 .procname = "dir-notify-enable",
1216 .data = &dir_notify_enable,
1217 .maxlen = sizeof(int),
1218 .mode = 0644,
1219 .proc_handler = &proc_dointvec,
1220 },
1221#endif
1222#ifdef CONFIG_MMU
1223 {
1224 .ctl_name = FS_LEASE_TIME,
1225 .procname = "lease-break-time",
1226 .data = &lease_break_time,
1227 .maxlen = sizeof(int),
1228 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001229 .proc_handler = &proc_dointvec_minmax,
1230 .strategy = &sysctl_intvec,
1231 .extra1 = &zero,
1232 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 },
1234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 .procname = "aio-nr",
1236 .data = &aio_nr,
1237 .maxlen = sizeof(aio_nr),
1238 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001239 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 },
1241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 .procname = "aio-max-nr",
1243 .data = &aio_max_nr,
1244 .maxlen = sizeof(aio_max_nr),
1245 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001246 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001248#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001249 {
1250 .ctl_name = FS_INOTIFY,
1251 .procname = "inotify",
1252 .mode = 0555,
1253 .child = inotify_table,
1254 },
1255#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001257 {
1258 .ctl_name = KERN_SETUID_DUMPABLE,
1259 .procname = "suid_dumpable",
1260 .data = &suid_dumpable,
1261 .maxlen = sizeof(int),
1262 .mode = 0644,
1263 .proc_handler = &proc_dointvec,
1264 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001265#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1266 {
1267 .ctl_name = CTL_UNNUMBERED,
1268 .procname = "binfmt_misc",
1269 .mode = 0555,
1270 .child = binfmt_misc_table,
1271 },
1272#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001273/*
1274 * NOTE: do not add new entries to this table unless you have read
1275 * Documentation/sysctl/ctl_unnumbered.txt
1276 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 { .ctl_name = 0 }
1278};
1279
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001280static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001281#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001282 {
1283 .ctl_name = CTL_UNNUMBERED,
1284 .procname = "exception-trace",
1285 .data = &show_unhandled_signals,
1286 .maxlen = sizeof(int),
1287 .mode = 0644,
1288 .proc_handler = proc_dointvec
1289 },
1290#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 { .ctl_name = 0 }
1292};
1293
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001294static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001296};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Al Viro330d57f2005-11-04 10:18:40 +00001298static DEFINE_SPINLOCK(sysctl_lock);
1299
1300/* called under sysctl_lock */
1301static int use_table(struct ctl_table_header *p)
1302{
1303 if (unlikely(p->unregistering))
1304 return 0;
1305 p->used++;
1306 return 1;
1307}
1308
1309/* called under sysctl_lock */
1310static void unuse_table(struct ctl_table_header *p)
1311{
1312 if (!--p->used)
1313 if (unlikely(p->unregistering))
1314 complete(p->unregistering);
1315}
1316
1317/* called under sysctl_lock, will reacquire if has to wait */
1318static void start_unregistering(struct ctl_table_header *p)
1319{
1320 /*
1321 * if p->used is 0, nobody will ever touch that entry again;
1322 * we'll eliminate all paths to it before dropping sysctl_lock
1323 */
1324 if (unlikely(p->used)) {
1325 struct completion wait;
1326 init_completion(&wait);
1327 p->unregistering = &wait;
1328 spin_unlock(&sysctl_lock);
1329 wait_for_completion(&wait);
1330 spin_lock(&sysctl_lock);
1331 }
1332 /*
1333 * do not remove from the list until nobody holds it; walking the
1334 * list in do_sysctl() relies on that.
1335 */
1336 list_del_init(&p->ctl_entry);
1337}
1338
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001339void sysctl_head_finish(struct ctl_table_header *head)
1340{
1341 if (!head)
1342 return;
1343 spin_lock(&sysctl_lock);
1344 unuse_table(head);
1345 spin_unlock(&sysctl_lock);
1346}
1347
1348struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1349{
1350 struct ctl_table_header *head;
1351 struct list_head *tmp;
1352 spin_lock(&sysctl_lock);
1353 if (prev) {
1354 tmp = &prev->ctl_entry;
1355 unuse_table(prev);
1356 goto next;
1357 }
1358 tmp = &root_table_header.ctl_entry;
1359 for (;;) {
1360 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1361
1362 if (!use_table(head))
1363 goto next;
1364 spin_unlock(&sysctl_lock);
1365 return head;
1366 next:
1367 tmp = tmp->next;
1368 if (tmp == &root_table_header.ctl_entry)
1369 break;
1370 }
1371 spin_unlock(&sysctl_lock);
1372 return NULL;
1373}
1374
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001375#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1377 void __user *newval, size_t newlen)
1378{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001379 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001380 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1383 return -ENOTDIR;
1384 if (oldval) {
1385 int old_len;
1386 if (!oldlenp || get_user(old_len, oldlenp))
1387 return -EFAULT;
1388 }
Al Viro330d57f2005-11-04 10:18:40 +00001389
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001390 for (head = sysctl_head_next(NULL); head;
1391 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001392 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001393 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001394 if (error != -ENOTDIR) {
1395 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001396 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001397 }
1398 }
Al Viro330d57f2005-11-04 10:18:40 +00001399 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400}
1401
1402asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1403{
1404 struct __sysctl_args tmp;
1405 int error;
1406
1407 if (copy_from_user(&tmp, args, sizeof(tmp)))
1408 return -EFAULT;
1409
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001410 error = deprecated_sysctl_warning(&tmp);
1411 if (error)
1412 goto out;
1413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 lock_kernel();
1415 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1416 tmp.newval, tmp.newlen);
1417 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001418out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 return error;
1420}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001421#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
1423/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001424 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 * some sysctl variables are readonly even to root.
1426 */
1427
1428static int test_perm(int mode, int op)
1429{
1430 if (!current->euid)
1431 mode >>= 6;
1432 else if (in_egroup_p(0))
1433 mode >>= 3;
1434 if ((mode & op & 0007) == op)
1435 return 0;
1436 return -EACCES;
1437}
1438
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001439int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440{
1441 int error;
1442 error = security_sysctl(table, op);
1443 if (error)
1444 return error;
1445 return test_perm(table->mode, op);
1446}
1447
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001448#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449static int parse_table(int __user *name, int nlen,
1450 void __user *oldval, size_t __user *oldlenp,
1451 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001452 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
1454 int n;
1455repeat:
1456 if (!nlen)
1457 return -ENOTDIR;
1458 if (get_user(n, name))
1459 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001460 for ( ; table->ctl_name || table->procname; table++) {
1461 if (!table->ctl_name)
1462 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001463 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 int error;
1465 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001466 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 name++;
1469 nlen--;
1470 table = table->child;
1471 goto repeat;
1472 }
1473 error = do_sysctl_strategy(table, name, nlen,
1474 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001475 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 return error;
1477 }
1478 }
1479 return -ENOTDIR;
1480}
1481
1482/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001483int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 int __user *name, int nlen,
1485 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001486 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
1488 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
1490 if (oldval)
1491 op |= 004;
1492 if (newval)
1493 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001494 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 return -EPERM;
1496
1497 if (table->strategy) {
1498 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001499 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 if (rc < 0)
1501 return rc;
1502 if (rc > 0)
1503 return 0;
1504 }
1505
1506 /* If there is no strategy routine, or if the strategy returns
1507 * zero, proceed with automatic r/w */
1508 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001509 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1510 newval, newlen);
1511 if (rc < 0)
1512 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 }
1514 return 0;
1515}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001516#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001518static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1519{
1520 for (; table->ctl_name || table->procname; table++) {
1521 table->parent = parent;
1522 if (table->child)
1523 sysctl_set_parent(table, table->child);
1524 }
1525}
1526
1527static __init int sysctl_init(void)
1528{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001529 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001530 sysctl_set_parent(NULL, root_table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001531 err = sysctl_check_table(root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001532 return 0;
1533}
1534
1535core_initcall(sysctl_init);
1536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537/**
1538 * register_sysctl_table - register a sysctl hierarchy
1539 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 *
1541 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1542 * array. An entry with a ctl_name of 0 terminates the table.
1543 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001544 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 *
1546 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1547 * must be unique within that level of sysctl
1548 *
1549 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1550 * enter a sysctl file
1551 *
1552 * data - a pointer to data for use by proc_handler
1553 *
1554 * maxlen - the maximum size in bytes of the data
1555 *
1556 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1557 *
1558 * child - a pointer to the child sysctl table if this entry is a directory, or
1559 * %NULL.
1560 *
1561 * proc_handler - the text handler routine (described below)
1562 *
1563 * strategy - the strategy routine (described below)
1564 *
1565 * de - for internal use by the sysctl routines
1566 *
1567 * extra1, extra2 - extra pointers usable by the proc handler routines
1568 *
1569 * Leaf nodes in the sysctl tree will be represented by a single file
1570 * under /proc; non-leaf nodes will be represented by directories.
1571 *
1572 * sysctl(2) can automatically manage read and write requests through
1573 * the sysctl table. The data and maxlen fields of the ctl_table
1574 * struct enable minimal validation of the values being written to be
1575 * performed, and the mode field allows minimal authentication.
1576 *
1577 * More sophisticated management can be enabled by the provision of a
1578 * strategy routine with the table entry. This will be called before
1579 * any automatic read or write of the data is performed.
1580 *
1581 * The strategy routine may return
1582 *
1583 * < 0 - Error occurred (error is passed to user process)
1584 *
1585 * 0 - OK - proceed with automatic read or write.
1586 *
1587 * > 0 - OK - read or write has been done by the strategy routine, so
1588 * return immediately.
1589 *
1590 * There must be a proc_handler routine for any terminal nodes
1591 * mirrored under /proc/sys (non-terminals are handled by a built-in
1592 * directory handler). Several default handlers are available to
1593 * cover common cases -
1594 *
1595 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1596 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1597 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1598 *
1599 * It is the handler's job to read the input buffer from user memory
1600 * and process it. The handler should return 0 on success.
1601 *
1602 * This routine returns %NULL on a failure to register, and a pointer
1603 * to the table header on success.
1604 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001605struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
1607 struct ctl_table_header *tmp;
1608 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1609 if (!tmp)
1610 return NULL;
1611 tmp->ctl_table = table;
1612 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001613 tmp->used = 0;
1614 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001615 sysctl_set_parent(NULL, table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001616 if (sysctl_check_table(tmp->ctl_table)) {
1617 kfree(tmp);
1618 return NULL;
1619 }
Al Viro330d57f2005-11-04 10:18:40 +00001620 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001621 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001622 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 return tmp;
1624}
1625
1626/**
1627 * unregister_sysctl_table - unregister a sysctl table hierarchy
1628 * @header: the header returned from register_sysctl_table
1629 *
1630 * Unregisters the sysctl table and all children. proc entries may not
1631 * actually be removed until they are no longer used by anyone.
1632 */
1633void unregister_sysctl_table(struct ctl_table_header * header)
1634{
Al Viro330d57f2005-11-04 10:18:40 +00001635 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001636
1637 if (header == NULL)
1638 return;
1639
Al Viro330d57f2005-11-04 10:18:40 +00001640 spin_lock(&sysctl_lock);
1641 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001642 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 kfree(header);
1644}
1645
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001646#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001647struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001648{
1649 return NULL;
1650}
1651
1652void unregister_sysctl_table(struct ctl_table_header * table)
1653{
1654}
1655
1656#endif /* CONFIG_SYSCTL */
1657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658/*
1659 * /proc/sys support
1660 */
1661
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001662#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001664static int _proc_do_string(void* data, int maxlen, int write,
1665 struct file *filp, void __user *buffer,
1666 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001667{
1668 size_t len;
1669 char __user *p;
1670 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001671
1672 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001673 *lenp = 0;
1674 return 0;
1675 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001676
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001677 if (write) {
1678 len = 0;
1679 p = buffer;
1680 while (len < *lenp) {
1681 if (get_user(c, p++))
1682 return -EFAULT;
1683 if (c == 0 || c == '\n')
1684 break;
1685 len++;
1686 }
1687 if (len >= maxlen)
1688 len = maxlen-1;
1689 if(copy_from_user(data, buffer, len))
1690 return -EFAULT;
1691 ((char *) data)[len] = 0;
1692 *ppos += *lenp;
1693 } else {
1694 len = strlen(data);
1695 if (len > maxlen)
1696 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001697
1698 if (*ppos > len) {
1699 *lenp = 0;
1700 return 0;
1701 }
1702
1703 data += *ppos;
1704 len -= *ppos;
1705
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001706 if (len > *lenp)
1707 len = *lenp;
1708 if (len)
1709 if(copy_to_user(buffer, data, len))
1710 return -EFAULT;
1711 if (len < *lenp) {
1712 if(put_user('\n', ((char __user *) buffer) + len))
1713 return -EFAULT;
1714 len++;
1715 }
1716 *lenp = len;
1717 *ppos += len;
1718 }
1719 return 0;
1720}
1721
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722/**
1723 * proc_dostring - read a string sysctl
1724 * @table: the sysctl table
1725 * @write: %TRUE if this is a write to the sysctl file
1726 * @filp: the file structure
1727 * @buffer: the user buffer
1728 * @lenp: the size of the user buffer
1729 * @ppos: file position
1730 *
1731 * Reads/writes a string from/to the user buffer. If the kernel
1732 * buffer provided is not large enough to hold the string, the
1733 * string is truncated. The copied string is %NULL-terminated.
1734 * If the string is being read by the user process, it is copied
1735 * and a newline '\n' is added. It is truncated if the buffer is
1736 * not large enough.
1737 *
1738 * Returns 0 on success.
1739 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001740int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 void __user *buffer, size_t *lenp, loff_t *ppos)
1742{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001743 return _proc_do_string(table->data, table->maxlen, write, filp,
1744 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745}
1746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
1748static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1749 int *valp,
1750 int write, void *data)
1751{
1752 if (write) {
1753 *valp = *negp ? -*lvalp : *lvalp;
1754 } else {
1755 int val = *valp;
1756 if (val < 0) {
1757 *negp = -1;
1758 *lvalp = (unsigned long)-val;
1759 } else {
1760 *negp = 0;
1761 *lvalp = (unsigned long)val;
1762 }
1763 }
1764 return 0;
1765}
1766
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001767static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001768 int write, struct file *filp, void __user *buffer,
1769 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1771 int write, void *data),
1772 void *data)
1773{
1774#define TMPBUFLEN 21
1775 int *i, vleft, first=1, neg, val;
1776 unsigned long lval;
1777 size_t left, len;
1778
1779 char buf[TMPBUFLEN], *p;
1780 char __user *s = buffer;
1781
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001782 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 (*ppos && !write)) {
1784 *lenp = 0;
1785 return 0;
1786 }
1787
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001788 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 vleft = table->maxlen / sizeof(*i);
1790 left = *lenp;
1791
1792 if (!conv)
1793 conv = do_proc_dointvec_conv;
1794
1795 for (; left && vleft--; i++, first=0) {
1796 if (write) {
1797 while (left) {
1798 char c;
1799 if (get_user(c, s))
1800 return -EFAULT;
1801 if (!isspace(c))
1802 break;
1803 left--;
1804 s++;
1805 }
1806 if (!left)
1807 break;
1808 neg = 0;
1809 len = left;
1810 if (len > sizeof(buf) - 1)
1811 len = sizeof(buf) - 1;
1812 if (copy_from_user(buf, s, len))
1813 return -EFAULT;
1814 buf[len] = 0;
1815 p = buf;
1816 if (*p == '-' && left > 1) {
1817 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001818 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 }
1820 if (*p < '0' || *p > '9')
1821 break;
1822
1823 lval = simple_strtoul(p, &p, 0);
1824
1825 len = p-buf;
1826 if ((len < left) && *p && !isspace(*p))
1827 break;
1828 if (neg)
1829 val = -val;
1830 s += len;
1831 left -= len;
1832
1833 if (conv(&neg, &lval, i, 1, data))
1834 break;
1835 } else {
1836 p = buf;
1837 if (!first)
1838 *p++ = '\t';
1839
1840 if (conv(&neg, &lval, i, 0, data))
1841 break;
1842
1843 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1844 len = strlen(buf);
1845 if (len > left)
1846 len = left;
1847 if(copy_to_user(s, buf, len))
1848 return -EFAULT;
1849 left -= len;
1850 s += len;
1851 }
1852 }
1853
1854 if (!write && !first && left) {
1855 if(put_user('\n', s))
1856 return -EFAULT;
1857 left--, s++;
1858 }
1859 if (write) {
1860 while (left) {
1861 char c;
1862 if (get_user(c, s++))
1863 return -EFAULT;
1864 if (!isspace(c))
1865 break;
1866 left--;
1867 }
1868 }
1869 if (write && first)
1870 return -EINVAL;
1871 *lenp -= left;
1872 *ppos += *lenp;
1873 return 0;
1874#undef TMPBUFLEN
1875}
1876
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001877static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001878 void __user *buffer, size_t *lenp, loff_t *ppos,
1879 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1880 int write, void *data),
1881 void *data)
1882{
1883 return __do_proc_dointvec(table->data, table, write, filp,
1884 buffer, lenp, ppos, conv, data);
1885}
1886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887/**
1888 * proc_dointvec - read a vector of integers
1889 * @table: the sysctl table
1890 * @write: %TRUE if this is a write to the sysctl file
1891 * @filp: the file structure
1892 * @buffer: the user buffer
1893 * @lenp: the size of the user buffer
1894 * @ppos: file position
1895 *
1896 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1897 * values from/to the user buffer, treated as an ASCII string.
1898 *
1899 * Returns 0 on success.
1900 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001901int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 void __user *buffer, size_t *lenp, loff_t *ppos)
1903{
1904 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1905 NULL,NULL);
1906}
1907
1908#define OP_SET 0
1909#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001910#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911
1912static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1913 int *valp,
1914 int write, void *data)
1915{
1916 int op = *(int *)data;
1917 if (write) {
1918 int val = *negp ? -*lvalp : *lvalp;
1919 switch(op) {
1920 case OP_SET: *valp = val; break;
1921 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001922 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 }
1924 } else {
1925 int val = *valp;
1926 if (val < 0) {
1927 *negp = -1;
1928 *lvalp = (unsigned long)-val;
1929 } else {
1930 *negp = 0;
1931 *lvalp = (unsigned long)val;
1932 }
1933 }
1934 return 0;
1935}
1936
Andrew Morgan72c2d582007-10-18 03:05:59 -07001937#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938/*
1939 * init may raise the set.
1940 */
Andrew Morgan72c2d582007-10-18 03:05:59 -07001941
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001942int proc_dointvec_bset(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 int op;
1946
Eric Paris6ff1b442007-02-10 01:43:19 -08001947 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 return -EPERM;
1949 }
1950
Serge E. Hallynb460cbc2007-10-18 23:39:52 -07001951 op = is_global_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1953 do_proc_dointvec_bset_conv,&op);
1954}
Andrew Morgan72c2d582007-10-18 03:05:59 -07001955#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001957/*
1958 * Taint values can only be increased
1959 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001960static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001961 void __user *buffer, size_t *lenp, loff_t *ppos)
1962{
1963 int op;
1964
Bastian Blank91fcd412007-04-23 14:41:14 -07001965 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001966 return -EPERM;
1967
1968 op = OP_OR;
1969 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1970 do_proc_dointvec_bset_conv,&op);
1971}
1972
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973struct do_proc_dointvec_minmax_conv_param {
1974 int *min;
1975 int *max;
1976};
1977
1978static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1979 int *valp,
1980 int write, void *data)
1981{
1982 struct do_proc_dointvec_minmax_conv_param *param = data;
1983 if (write) {
1984 int val = *negp ? -*lvalp : *lvalp;
1985 if ((param->min && *param->min > val) ||
1986 (param->max && *param->max < val))
1987 return -EINVAL;
1988 *valp = val;
1989 } else {
1990 int val = *valp;
1991 if (val < 0) {
1992 *negp = -1;
1993 *lvalp = (unsigned long)-val;
1994 } else {
1995 *negp = 0;
1996 *lvalp = (unsigned long)val;
1997 }
1998 }
1999 return 0;
2000}
2001
2002/**
2003 * proc_dointvec_minmax - read a vector of integers with min/max values
2004 * @table: the sysctl table
2005 * @write: %TRUE if this is a write to the sysctl file
2006 * @filp: the file structure
2007 * @buffer: the user buffer
2008 * @lenp: the size of the user buffer
2009 * @ppos: file position
2010 *
2011 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2012 * values from/to the user buffer, treated as an ASCII string.
2013 *
2014 * This routine will ensure the values are within the range specified by
2015 * table->extra1 (min) and table->extra2 (max).
2016 *
2017 * Returns 0 on success.
2018 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002019int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 void __user *buffer, size_t *lenp, loff_t *ppos)
2021{
2022 struct do_proc_dointvec_minmax_conv_param param = {
2023 .min = (int *) table->extra1,
2024 .max = (int *) table->extra2,
2025 };
2026 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2027 do_proc_dointvec_minmax_conv, &param);
2028}
2029
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002030static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 struct file *filp,
2032 void __user *buffer,
2033 size_t *lenp, loff_t *ppos,
2034 unsigned long convmul,
2035 unsigned long convdiv)
2036{
2037#define TMPBUFLEN 21
2038 unsigned long *i, *min, *max, val;
2039 int vleft, first=1, neg;
2040 size_t len, left;
2041 char buf[TMPBUFLEN], *p;
2042 char __user *s = buffer;
2043
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002044 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 (*ppos && !write)) {
2046 *lenp = 0;
2047 return 0;
2048 }
2049
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002050 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 min = (unsigned long *) table->extra1;
2052 max = (unsigned long *) table->extra2;
2053 vleft = table->maxlen / sizeof(unsigned long);
2054 left = *lenp;
2055
2056 for (; left && vleft--; i++, min++, max++, first=0) {
2057 if (write) {
2058 while (left) {
2059 char c;
2060 if (get_user(c, s))
2061 return -EFAULT;
2062 if (!isspace(c))
2063 break;
2064 left--;
2065 s++;
2066 }
2067 if (!left)
2068 break;
2069 neg = 0;
2070 len = left;
2071 if (len > TMPBUFLEN-1)
2072 len = TMPBUFLEN-1;
2073 if (copy_from_user(buf, s, len))
2074 return -EFAULT;
2075 buf[len] = 0;
2076 p = buf;
2077 if (*p == '-' && left > 1) {
2078 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002079 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
2081 if (*p < '0' || *p > '9')
2082 break;
2083 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2084 len = p-buf;
2085 if ((len < left) && *p && !isspace(*p))
2086 break;
2087 if (neg)
2088 val = -val;
2089 s += len;
2090 left -= len;
2091
2092 if(neg)
2093 continue;
2094 if ((min && val < *min) || (max && val > *max))
2095 continue;
2096 *i = val;
2097 } else {
2098 p = buf;
2099 if (!first)
2100 *p++ = '\t';
2101 sprintf(p, "%lu", convdiv * (*i) / convmul);
2102 len = strlen(buf);
2103 if (len > left)
2104 len = left;
2105 if(copy_to_user(s, buf, len))
2106 return -EFAULT;
2107 left -= len;
2108 s += len;
2109 }
2110 }
2111
2112 if (!write && !first && left) {
2113 if(put_user('\n', s))
2114 return -EFAULT;
2115 left--, s++;
2116 }
2117 if (write) {
2118 while (left) {
2119 char c;
2120 if (get_user(c, s++))
2121 return -EFAULT;
2122 if (!isspace(c))
2123 break;
2124 left--;
2125 }
2126 }
2127 if (write && first)
2128 return -EINVAL;
2129 *lenp -= left;
2130 *ppos += *lenp;
2131 return 0;
2132#undef TMPBUFLEN
2133}
2134
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002135static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002136 struct file *filp,
2137 void __user *buffer,
2138 size_t *lenp, loff_t *ppos,
2139 unsigned long convmul,
2140 unsigned long convdiv)
2141{
2142 return __do_proc_doulongvec_minmax(table->data, table, write,
2143 filp, buffer, lenp, ppos, convmul, convdiv);
2144}
2145
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146/**
2147 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2148 * @table: the sysctl table
2149 * @write: %TRUE if this is a write to the sysctl file
2150 * @filp: the file structure
2151 * @buffer: the user buffer
2152 * @lenp: the size of the user buffer
2153 * @ppos: file position
2154 *
2155 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2156 * values from/to the user buffer, treated as an ASCII string.
2157 *
2158 * This routine will ensure the values are within the range specified by
2159 * table->extra1 (min) and table->extra2 (max).
2160 *
2161 * Returns 0 on success.
2162 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002163int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 void __user *buffer, size_t *lenp, loff_t *ppos)
2165{
2166 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2167}
2168
2169/**
2170 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2171 * @table: the sysctl table
2172 * @write: %TRUE if this is a write to the sysctl file
2173 * @filp: the file structure
2174 * @buffer: the user buffer
2175 * @lenp: the size of the user buffer
2176 * @ppos: file position
2177 *
2178 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2179 * values from/to the user buffer, treated as an ASCII string. The values
2180 * are treated as milliseconds, and converted to jiffies when they are stored.
2181 *
2182 * This routine will ensure the values are within the range specified by
2183 * table->extra1 (min) and table->extra2 (max).
2184 *
2185 * Returns 0 on success.
2186 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002187int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 struct file *filp,
2189 void __user *buffer,
2190 size_t *lenp, loff_t *ppos)
2191{
2192 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2193 lenp, ppos, HZ, 1000l);
2194}
2195
2196
2197static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2198 int *valp,
2199 int write, void *data)
2200{
2201 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002202 if (*lvalp > LONG_MAX / HZ)
2203 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2205 } else {
2206 int val = *valp;
2207 unsigned long lval;
2208 if (val < 0) {
2209 *negp = -1;
2210 lval = (unsigned long)-val;
2211 } else {
2212 *negp = 0;
2213 lval = (unsigned long)val;
2214 }
2215 *lvalp = lval / HZ;
2216 }
2217 return 0;
2218}
2219
2220static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2221 int *valp,
2222 int write, void *data)
2223{
2224 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002225 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2226 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2228 } else {
2229 int val = *valp;
2230 unsigned long lval;
2231 if (val < 0) {
2232 *negp = -1;
2233 lval = (unsigned long)-val;
2234 } else {
2235 *negp = 0;
2236 lval = (unsigned long)val;
2237 }
2238 *lvalp = jiffies_to_clock_t(lval);
2239 }
2240 return 0;
2241}
2242
2243static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2244 int *valp,
2245 int write, void *data)
2246{
2247 if (write) {
2248 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2249 } else {
2250 int val = *valp;
2251 unsigned long lval;
2252 if (val < 0) {
2253 *negp = -1;
2254 lval = (unsigned long)-val;
2255 } else {
2256 *negp = 0;
2257 lval = (unsigned long)val;
2258 }
2259 *lvalp = jiffies_to_msecs(lval);
2260 }
2261 return 0;
2262}
2263
2264/**
2265 * proc_dointvec_jiffies - read a vector of integers as seconds
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
2268 * @filp: the file structure
2269 * @buffer: the user buffer
2270 * @lenp: the size of the user buffer
2271 * @ppos: file position
2272 *
2273 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2274 * values from/to the user buffer, treated as an ASCII string.
2275 * The values read are assumed to be in seconds, and are converted into
2276 * jiffies.
2277 *
2278 * Returns 0 on success.
2279 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002280int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 void __user *buffer, size_t *lenp, loff_t *ppos)
2282{
2283 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2284 do_proc_dointvec_jiffies_conv,NULL);
2285}
2286
2287/**
2288 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2289 * @table: the sysctl table
2290 * @write: %TRUE if this is a write to the sysctl file
2291 * @filp: the file structure
2292 * @buffer: the user buffer
2293 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002294 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 *
2296 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2297 * values from/to the user buffer, treated as an ASCII string.
2298 * The values read are assumed to be in 1/USER_HZ seconds, and
2299 * are converted into jiffies.
2300 *
2301 * Returns 0 on success.
2302 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002303int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 void __user *buffer, size_t *lenp, loff_t *ppos)
2305{
2306 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2307 do_proc_dointvec_userhz_jiffies_conv,NULL);
2308}
2309
2310/**
2311 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2312 * @table: the sysctl table
2313 * @write: %TRUE if this is a write to the sysctl file
2314 * @filp: the file structure
2315 * @buffer: the user buffer
2316 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002317 * @ppos: file position
2318 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 *
2320 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2321 * values from/to the user buffer, treated as an ASCII string.
2322 * The values read are assumed to be in 1/1000 seconds, and
2323 * are converted into jiffies.
2324 *
2325 * Returns 0 on success.
2326 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002327int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 void __user *buffer, size_t *lenp, loff_t *ppos)
2329{
2330 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2331 do_proc_dointvec_ms_jiffies_conv, NULL);
2332}
2333
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002334static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002335 void __user *buffer, size_t *lenp, loff_t *ppos)
2336{
2337 struct pid *new_pid;
2338 pid_t tmp;
2339 int r;
2340
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002341 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002342
2343 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2344 lenp, ppos, NULL, NULL);
2345 if (r || !write)
2346 return r;
2347
2348 new_pid = find_get_pid(tmp);
2349 if (!new_pid)
2350 return -ESRCH;
2351
2352 put_pid(xchg(&cad_pid, new_pid));
2353 return 0;
2354}
2355
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356#else /* CONFIG_PROC_FS */
2357
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002358int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 void __user *buffer, size_t *lenp, loff_t *ppos)
2360{
2361 return -ENOSYS;
2362}
2363
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002364int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 void __user *buffer, size_t *lenp, loff_t *ppos)
2366{
2367 return -ENOSYS;
2368}
2369
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002370int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 void __user *buffer, size_t *lenp, loff_t *ppos)
2372{
2373 return -ENOSYS;
2374}
2375
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002376int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 void __user *buffer, size_t *lenp, loff_t *ppos)
2378{
2379 return -ENOSYS;
2380}
2381
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002382int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 void __user *buffer, size_t *lenp, loff_t *ppos)
2384{
2385 return -ENOSYS;
2386}
2387
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002388int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 void __user *buffer, size_t *lenp, loff_t *ppos)
2390{
2391 return -ENOSYS;
2392}
2393
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002394int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 void __user *buffer, size_t *lenp, loff_t *ppos)
2396{
2397 return -ENOSYS;
2398}
2399
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002400int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 void __user *buffer, size_t *lenp, loff_t *ppos)
2402{
2403 return -ENOSYS;
2404}
2405
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002406int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 struct file *filp,
2408 void __user *buffer,
2409 size_t *lenp, loff_t *ppos)
2410{
2411 return -ENOSYS;
2412}
2413
2414
2415#endif /* CONFIG_PROC_FS */
2416
2417
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002418#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419/*
2420 * General sysctl support routines
2421 */
2422
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002423/* The generic sysctl data routine (used if no strategy routine supplied) */
2424int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2425 void __user *oldval, size_t __user *oldlenp,
2426 void __user *newval, size_t newlen)
2427{
2428 size_t len;
2429
2430 /* Get out of I don't have a variable */
2431 if (!table->data || !table->maxlen)
2432 return -ENOTDIR;
2433
2434 if (oldval && oldlenp) {
2435 if (get_user(len, oldlenp))
2436 return -EFAULT;
2437 if (len) {
2438 if (len > table->maxlen)
2439 len = table->maxlen;
2440 if (copy_to_user(oldval, table->data, len))
2441 return -EFAULT;
2442 if (put_user(len, oldlenp))
2443 return -EFAULT;
2444 }
2445 }
2446
2447 if (newval && newlen) {
2448 if (newlen > table->maxlen)
2449 newlen = table->maxlen;
2450
2451 if (copy_from_user(table->data, newval, newlen))
2452 return -EFAULT;
2453 }
2454 return 1;
2455}
2456
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002458int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002460 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 if (!table->data || !table->maxlen)
2463 return -ENOTDIR;
2464
2465 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002466 size_t bufsize;
2467 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002469 if (bufsize) {
2470 size_t len = strlen(table->data), copied;
2471
2472 /* This shouldn't trigger for a well-formed sysctl */
2473 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002475
2476 /* Copy up to a max of bufsize-1 bytes of the string */
2477 copied = (len >= bufsize) ? bufsize - 1 : len;
2478
2479 if (copy_to_user(oldval, table->data, copied) ||
2480 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002482 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 return -EFAULT;
2484 }
2485 }
2486 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002487 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 if (len > table->maxlen)
2489 len = table->maxlen;
2490 if(copy_from_user(table->data, newval, len))
2491 return -EFAULT;
2492 if (len == table->maxlen)
2493 len--;
2494 ((char *) table->data)[len] = 0;
2495 }
Yi Yang82c9df82005-12-30 16:37:10 +08002496 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497}
2498
2499/*
2500 * This function makes sure that all of the integers in the vector
2501 * are between the minimum and maximum values given in the arrays
2502 * table->extra1 and table->extra2, respectively.
2503 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002504int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002506 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507{
2508
2509 if (newval && newlen) {
2510 int __user *vec = (int __user *) newval;
2511 int *min = (int *) table->extra1;
2512 int *max = (int *) table->extra2;
2513 size_t length;
2514 int i;
2515
2516 if (newlen % sizeof(int) != 0)
2517 return -EINVAL;
2518
2519 if (!table->extra1 && !table->extra2)
2520 return 0;
2521
2522 if (newlen > table->maxlen)
2523 newlen = table->maxlen;
2524 length = newlen / sizeof(int);
2525
2526 for (i = 0; i < length; i++) {
2527 int value;
2528 if (get_user(value, vec + i))
2529 return -EFAULT;
2530 if (min && value < min[i])
2531 return -EINVAL;
2532 if (max && value > max[i])
2533 return -EINVAL;
2534 }
2535 }
2536 return 0;
2537}
2538
2539/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002540int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002542 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002544 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002546
2547 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002549 if (olen) {
2550 int val;
2551
2552 if (olen < sizeof(int))
2553 return -EINVAL;
2554
2555 val = *(int *)(table->data) / HZ;
2556 if (put_user(val, (int __user *)oldval))
2557 return -EFAULT;
2558 if (put_user(sizeof(int), oldlenp))
2559 return -EFAULT;
2560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 }
2562 if (newval && newlen) {
2563 int new;
2564 if (newlen != sizeof(int))
2565 return -EINVAL;
2566 if (get_user(new, (int __user *)newval))
2567 return -EFAULT;
2568 *(int *)(table->data) = new*HZ;
2569 }
2570 return 1;
2571}
2572
2573/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002574int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002576 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002578 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002580
2581 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002583 if (olen) {
2584 int val;
2585
2586 if (olen < sizeof(int))
2587 return -EINVAL;
2588
2589 val = jiffies_to_msecs(*(int *)(table->data));
2590 if (put_user(val, (int __user *)oldval))
2591 return -EFAULT;
2592 if (put_user(sizeof(int), oldlenp))
2593 return -EFAULT;
2594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 }
2596 if (newval && newlen) {
2597 int new;
2598 if (newlen != sizeof(int))
2599 return -EINVAL;
2600 if (get_user(new, (int __user *)newval))
2601 return -EFAULT;
2602 *(int *)(table->data) = msecs_to_jiffies(new);
2603 }
2604 return 1;
2605}
2606
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002607
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002608
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002609#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610
2611
2612asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2613{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002614 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002615 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002616
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002617 if (copy_from_user(&tmp, args, sizeof(tmp)))
2618 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002619
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002620 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002621
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002622 /* If no error reading the parameters then just -ENOSYS ... */
2623 if (!error)
2624 error = -ENOSYS;
2625
2626 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627}
2628
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002629int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2630 void __user *oldval, size_t __user *oldlenp,
2631 void __user *newval, size_t newlen)
2632{
2633 return -ENOSYS;
2634}
2635
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002636int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002638 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639{
2640 return -ENOSYS;
2641}
2642
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002643int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002645 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646{
2647 return -ENOSYS;
2648}
2649
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002650int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002652 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653{
2654 return -ENOSYS;
2655}
2656
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002657int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002659 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660{
2661 return -ENOSYS;
2662}
2663
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002664#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002666static int deprecated_sysctl_warning(struct __sysctl_args *args)
2667{
2668 static int msg_count;
2669 int name[CTL_MAXNAME];
2670 int i;
2671
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002672 /* Check args->nlen. */
2673 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2674 return -ENOTDIR;
2675
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002676 /* Read in the sysctl name for better debug message logging */
2677 for (i = 0; i < args->nlen; i++)
2678 if (get_user(name[i], args->name + i))
2679 return -EFAULT;
2680
2681 /* Ignore accesses to kernel.version */
2682 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2683 return 0;
2684
2685 if (msg_count < 5) {
2686 msg_count++;
2687 printk(KERN_INFO
2688 "warning: process `%s' used the deprecated sysctl "
2689 "system call with ", current->comm);
2690 for (i = 0; i < args->nlen; i++)
2691 printk("%d.", name[i]);
2692 printk("\n");
2693 }
2694 return 0;
2695}
2696
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697/*
2698 * No sense putting this after each symbol definition, twice,
2699 * exception granted :-)
2700 */
2701EXPORT_SYMBOL(proc_dointvec);
2702EXPORT_SYMBOL(proc_dointvec_jiffies);
2703EXPORT_SYMBOL(proc_dointvec_minmax);
2704EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2705EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2706EXPORT_SYMBOL(proc_dostring);
2707EXPORT_SYMBOL(proc_doulongvec_minmax);
2708EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2709EXPORT_SYMBOL(register_sysctl_table);
2710EXPORT_SYMBOL(sysctl_intvec);
2711EXPORT_SYMBOL(sysctl_jiffies);
2712EXPORT_SYMBOL(sysctl_ms_jiffies);
2713EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002714EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715EXPORT_SYMBOL(unregister_sysctl_table);