blob: 3afbd25f43eb84da2278216e06004a6c560d6d10 [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),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100309 .mode = 0644,
310 .proc_handler = &proc_dointvec,
311 },
312 {
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "sched_rt_period_ms",
315 .data = &sysctl_sched_rt_period,
316 .maxlen = sizeof(unsigned int),
317 .mode = 0644,
318 .proc_handler = &proc_dointvec,
319 },
320 {
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_rt_ratio",
323 .data = &sysctl_sched_rt_ratio,
324 .maxlen = sizeof(unsigned int),
325 .mode = 0644,
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100326 .proc_handler = &proc_dointvec,
327 },
Srivatsa Vaddagiri6b2d7702008-01-25 21:08:00 +0100328#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
329 {
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "sched_min_bal_int_shares",
332 .data = &sysctl_sched_min_bal_int_shares,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
335 .proc_handler = &proc_dointvec,
336 },
337 {
338 .ctl_name = CTL_UNNUMBERED,
339 .procname = "sched_max_bal_int_shares",
340 .data = &sysctl_sched_max_bal_int_shares,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
343 .proc_handler = &proc_dointvec,
344 },
345#endif
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200346#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200347 {
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "sched_compat_yield",
350 .data = &sysctl_sched_compat_yield,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
353 .proc_handler = &proc_dointvec,
354 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700355#ifdef CONFIG_PROVE_LOCKING
356 {
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
364#endif
365#ifdef CONFIG_LOCK_STAT
366 {
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "lock_stat",
369 .data = &lock_stat,
370 .maxlen = sizeof(int),
371 .mode = 0644,
372 .proc_handler = &proc_dointvec,
373 },
374#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .ctl_name = KERN_PANIC,
377 .procname = "panic",
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383 {
384 .ctl_name = KERN_CORE_USES_PID,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700391#ifdef CONFIG_AUDITSYSCALL
392 {
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "audit_argv_kb",
395 .data = &audit_argv_kb,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
399 },
400#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 {
402 .ctl_name = KERN_CORE_PATTERN,
403 .procname = "core_pattern",
404 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700405 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .mode = 0644,
407 .proc_handler = &proc_dostring,
408 .strategy = &sysctl_string,
409 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800410#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .procname = "tainted",
413 .data = &tainted,
414 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800415 .mode = 0644,
416 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800418#endif
Andrew Morgan72c2d582007-10-18 03:05:59 -0700419#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .procname = "cap-bound",
422 .data = &cap_bset,
423 .maxlen = sizeof(kernel_cap_t),
424 .mode = 0600,
425 .proc_handler = &proc_dointvec_bset,
426 },
Andrew Morgan72c2d582007-10-18 03:05:59 -0700427#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#ifdef CONFIG_BLK_DEV_INITRD
429 {
430 .ctl_name = KERN_REALROOTDEV,
431 .procname = "real-root-dev",
432 .data = &real_root_dev,
433 .maxlen = sizeof(int),
434 .mode = 0644,
435 .proc_handler = &proc_dointvec,
436 },
437#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700438 {
439 .ctl_name = CTL_UNNUMBERED,
440 .procname = "print-fatal-signals",
441 .data = &print_fatal_signals,
442 .maxlen = sizeof(int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
445 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#ifdef __sparc__
447 {
448 .ctl_name = KERN_SPARC_REBOOT,
449 .procname = "reboot-cmd",
450 .data = reboot_command,
451 .maxlen = 256,
452 .mode = 0644,
453 .proc_handler = &proc_dostring,
454 .strategy = &sysctl_string,
455 },
456 {
457 .ctl_name = KERN_SPARC_STOP_A,
458 .procname = "stop-a",
459 .data = &stop_a_enabled,
460 .maxlen = sizeof (int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
463 },
464 {
465 .ctl_name = KERN_SPARC_SCONS_PWROFF,
466 .procname = "scons-poweroff",
467 .data = &scons_pwroff,
468 .maxlen = sizeof (int),
469 .mode = 0644,
470 .proc_handler = &proc_dointvec,
471 },
472#endif
473#ifdef __hppa__
474 {
475 .ctl_name = KERN_HPPA_PWRSW,
476 .procname = "soft-power",
477 .data = &pwrsw_enabled,
478 .maxlen = sizeof (int),
479 .mode = 0644,
480 .proc_handler = &proc_dointvec,
481 },
482 {
483 .ctl_name = KERN_HPPA_UNALIGNED,
484 .procname = "unaligned-trap",
485 .data = &unaligned_enabled,
486 .maxlen = sizeof (int),
487 .mode = 0644,
488 .proc_handler = &proc_dointvec,
489 },
490#endif
491 {
492 .ctl_name = KERN_CTLALTDEL,
493 .procname = "ctrl-alt-del",
494 .data = &C_A_D,
495 .maxlen = sizeof(int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
498 },
499 {
500 .ctl_name = KERN_PRINTK,
501 .procname = "printk",
502 .data = &console_loglevel,
503 .maxlen = 4*sizeof(int),
504 .mode = 0644,
505 .proc_handler = &proc_dointvec,
506 },
507#ifdef CONFIG_KMOD
508 {
509 .ctl_name = KERN_MODPROBE,
510 .procname = "modprobe",
511 .data = &modprobe_path,
512 .maxlen = KMOD_PATH_LEN,
513 .mode = 0644,
514 .proc_handler = &proc_dostring,
515 .strategy = &sysctl_string,
516 },
517#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700518#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 {
520 .ctl_name = KERN_HOTPLUG,
521 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100522 .data = &uevent_helper,
523 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 .mode = 0644,
525 .proc_handler = &proc_dostring,
526 .strategy = &sysctl_string,
527 },
528#endif
529#ifdef CONFIG_CHR_DEV_SG
530 {
531 .ctl_name = KERN_SG_BIG_BUFF,
532 .procname = "sg-big-buff",
533 .data = &sg_big_buff,
534 .maxlen = sizeof (int),
535 .mode = 0444,
536 .proc_handler = &proc_dointvec,
537 },
538#endif
539#ifdef CONFIG_BSD_PROCESS_ACCT
540 {
541 .ctl_name = KERN_ACCT,
542 .procname = "acct",
543 .data = &acct_parm,
544 .maxlen = 3*sizeof(int),
545 .mode = 0644,
546 .proc_handler = &proc_dointvec,
547 },
548#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#ifdef CONFIG_MAGIC_SYSRQ
550 {
551 .ctl_name = KERN_SYSRQ,
552 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800553 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 .maxlen = sizeof (int),
555 .mode = 0644,
556 .proc_handler = &proc_dointvec,
557 },
558#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700559#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700562 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 .maxlen = sizeof (int),
564 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700565 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700567#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 {
569 .ctl_name = KERN_MAX_THREADS,
570 .procname = "threads-max",
571 .data = &max_threads,
572 .maxlen = sizeof(int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
575 },
576 {
577 .ctl_name = KERN_RANDOM,
578 .procname = "random",
579 .mode = 0555,
580 .child = random_table,
581 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 {
583 .ctl_name = KERN_OVERFLOWUID,
584 .procname = "overflowuid",
585 .data = &overflowuid,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 .proc_handler = &proc_dointvec_minmax,
589 .strategy = &sysctl_intvec,
590 .extra1 = &minolduid,
591 .extra2 = &maxolduid,
592 },
593 {
594 .ctl_name = KERN_OVERFLOWGID,
595 .procname = "overflowgid",
596 .data = &overflowgid,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = &proc_dointvec_minmax,
600 .strategy = &sysctl_intvec,
601 .extra1 = &minolduid,
602 .extra2 = &maxolduid,
603 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800604#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#ifdef CONFIG_MATHEMU
606 {
607 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
608 .procname = "ieee_emulation_warnings",
609 .data = &sysctl_ieee_emulation_warnings,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = &proc_dointvec,
613 },
614#endif
615#ifdef CONFIG_NO_IDLE_HZ
616 {
617 .ctl_name = KERN_HZ_TIMER,
618 .procname = "hz_timer",
619 .data = &sysctl_hz_timer,
620 .maxlen = sizeof(int),
621 .mode = 0644,
622 .proc_handler = &proc_dointvec,
623 },
624#endif
625 {
626 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
627 .procname = "userprocess_debug",
628 .data = &sysctl_userprocess_debug,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = &proc_dointvec,
632 },
633#endif
634 {
635 .ctl_name = KERN_PIDMAX,
636 .procname = "pid_max",
637 .data = &pid_max,
638 .maxlen = sizeof (int),
639 .mode = 0644,
640 .proc_handler = &proc_dointvec_minmax,
641 .strategy = sysctl_intvec,
642 .extra1 = &pid_max_min,
643 .extra2 = &pid_max_max,
644 },
645 {
646 .ctl_name = KERN_PANIC_ON_OOPS,
647 .procname = "panic_on_oops",
648 .data = &panic_on_oops,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec,
652 },
653 {
654 .ctl_name = KERN_PRINTK_RATELIMIT,
655 .procname = "printk_ratelimit",
656 .data = &printk_ratelimit_jiffies,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 .proc_handler = &proc_dointvec_jiffies,
660 .strategy = &sysctl_jiffies,
661 },
662 {
663 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
664 .procname = "printk_ratelimit_burst",
665 .data = &printk_ratelimit_burst,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec,
669 },
670 {
671 .ctl_name = KERN_NGROUPS_MAX,
672 .procname = "ngroups_max",
673 .data = &ngroups_max,
674 .maxlen = sizeof (int),
675 .mode = 0444,
676 .proc_handler = &proc_dointvec,
677 },
678#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
679 {
680 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
681 .procname = "unknown_nmi_panic",
682 .data = &unknown_nmi_panic,
683 .maxlen = sizeof (int),
684 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200685 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 },
Don Zickus407984f2006-09-26 10:52:27 +0200687 {
Don Zickus407984f2006-09-26 10:52:27 +0200688 .procname = "nmi_watchdog",
689 .data = &nmi_watchdog_enabled,
690 .maxlen = sizeof (int),
691 .mode = 0644,
692 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 },
694#endif
695#if defined(CONFIG_X86)
696 {
Don Zickus8da5add2006-09-26 10:52:27 +0200697 .ctl_name = KERN_PANIC_ON_NMI,
698 .procname = "panic_on_unrecovered_nmi",
699 .data = &panic_on_unrecovered_nmi,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = &proc_dointvec,
703 },
704 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .ctl_name = KERN_BOOTLOADER_TYPE,
706 .procname = "bootloader_type",
707 .data = &bootloader_type,
708 .maxlen = sizeof (int),
709 .mode = 0444,
710 .proc_handler = &proc_dointvec,
711 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100712 {
713 .ctl_name = CTL_UNNUMBERED,
714 .procname = "kstack_depth_to_print",
715 .data = &kstack_depth_to_print,
716 .maxlen = sizeof(int),
717 .mode = 0644,
718 .proc_handler = &proc_dointvec,
719 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800721#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 {
723 .ctl_name = KERN_RANDOMIZE,
724 .procname = "randomize_va_space",
725 .data = &randomize_va_space,
726 .maxlen = sizeof(int),
727 .mode = 0644,
728 .proc_handler = &proc_dointvec,
729 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800730#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800731#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700732 {
733 .ctl_name = KERN_SPIN_RETRY,
734 .procname = "spin_retry",
735 .data = &spin_retry,
736 .maxlen = sizeof (int),
737 .mode = 0644,
738 .proc_handler = &proc_dointvec,
739 },
740#endif
Len Brown673d5b42007-07-28 03:33:16 -0400741#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800742 {
Pavel Machekc255d842006-02-20 18:27:58 -0800743 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700744 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800745 .maxlen = sizeof (unsigned long),
746 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800747 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800748 },
749#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800750#ifdef CONFIG_IA64
751 {
752 .ctl_name = KERN_IA64_UNALIGNED,
753 .procname = "ignore-unaligned-usertrap",
754 .data = &no_unaligned_warning,
755 .maxlen = sizeof (int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
758 },
759#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700760#ifdef CONFIG_DETECT_SOFTLOCKUP
761 {
762 .ctl_name = CTL_UNNUMBERED,
763 .procname = "softlockup_thresh",
764 .data = &softlockup_thresh,
765 .maxlen = sizeof(int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec_minmax,
768 .strategy = &sysctl_intvec,
769 .extra1 = &one,
770 .extra2 = &sixty,
771 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100772 {
773 .ctl_name = CTL_UNNUMBERED,
774 .procname = "hung_task_check_count",
775 .data = &sysctl_hung_task_check_count,
776 .maxlen = sizeof(int),
777 .mode = 0644,
778 .proc_handler = &proc_dointvec_minmax,
779 .strategy = &sysctl_intvec,
780 },
781 {
782 .ctl_name = CTL_UNNUMBERED,
783 .procname = "hung_task_timeout_secs",
784 .data = &sysctl_hung_task_timeout_secs,
785 .maxlen = sizeof(int),
786 .mode = 0644,
787 .proc_handler = &proc_dointvec_minmax,
788 .strategy = &sysctl_intvec,
789 },
790 {
791 .ctl_name = CTL_UNNUMBERED,
792 .procname = "hung_task_warnings",
793 .data = &sysctl_hung_task_warnings,
794 .maxlen = sizeof(int),
795 .mode = 0644,
796 .proc_handler = &proc_dointvec_minmax,
797 .strategy = &sysctl_intvec,
798 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700799#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200800#ifdef CONFIG_COMPAT
801 {
802 .ctl_name = KERN_COMPAT_LOG,
803 .procname = "compat-log",
804 .data = &compat_log,
805 .maxlen = sizeof (int),
806 .mode = 0644,
807 .proc_handler = &proc_dointvec,
808 },
809#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700810#ifdef CONFIG_RT_MUTEXES
811 {
812 .ctl_name = KERN_MAX_LOCK_DEPTH,
813 .procname = "max_lock_depth",
814 .data = &max_lock_depth,
815 .maxlen = sizeof(int),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec,
818 },
819#endif
Kees Cook5096add2007-05-08 00:26:04 -0700820#ifdef CONFIG_PROC_FS
821 {
822 .ctl_name = CTL_UNNUMBERED,
823 .procname = "maps_protect",
824 .data = &maps_protect,
825 .maxlen = sizeof(int),
826 .mode = 0644,
827 .proc_handler = &proc_dointvec,
828 },
829#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700830 {
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "poweroff_cmd",
833 .data = &poweroff_cmd,
834 .maxlen = POWEROFF_CMD_PATH_LEN,
835 .mode = 0644,
836 .proc_handler = &proc_dostring,
837 .strategy = &sysctl_string,
838 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700839/*
840 * NOTE: do not add new entries to this table unless you have read
841 * Documentation/sysctl/ctl_unnumbered.txt
842 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 { .ctl_name = 0 }
844};
845
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700846static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 {
848 .ctl_name = VM_OVERCOMMIT_MEMORY,
849 .procname = "overcommit_memory",
850 .data = &sysctl_overcommit_memory,
851 .maxlen = sizeof(sysctl_overcommit_memory),
852 .mode = 0644,
853 .proc_handler = &proc_dointvec,
854 },
855 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700856 .ctl_name = VM_PANIC_ON_OOM,
857 .procname = "panic_on_oom",
858 .data = &sysctl_panic_on_oom,
859 .maxlen = sizeof(sysctl_panic_on_oom),
860 .mode = 0644,
861 .proc_handler = &proc_dointvec,
862 },
863 {
David Rientjesfe071d72007-10-16 23:25:56 -0700864 .ctl_name = CTL_UNNUMBERED,
865 .procname = "oom_kill_allocating_task",
866 .data = &sysctl_oom_kill_allocating_task,
867 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
868 .mode = 0644,
869 .proc_handler = &proc_dointvec,
870 },
871 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 .ctl_name = VM_OVERCOMMIT_RATIO,
873 .procname = "overcommit_ratio",
874 .data = &sysctl_overcommit_ratio,
875 .maxlen = sizeof(sysctl_overcommit_ratio),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec,
878 },
879 {
880 .ctl_name = VM_PAGE_CLUSTER,
881 .procname = "page-cluster",
882 .data = &page_cluster,
883 .maxlen = sizeof(int),
884 .mode = 0644,
885 .proc_handler = &proc_dointvec,
886 },
887 {
888 .ctl_name = VM_DIRTY_BACKGROUND,
889 .procname = "dirty_background_ratio",
890 .data = &dirty_background_ratio,
891 .maxlen = sizeof(dirty_background_ratio),
892 .mode = 0644,
893 .proc_handler = &proc_dointvec_minmax,
894 .strategy = &sysctl_intvec,
895 .extra1 = &zero,
896 .extra2 = &one_hundred,
897 },
898 {
899 .ctl_name = VM_DIRTY_RATIO,
900 .procname = "dirty_ratio",
901 .data = &vm_dirty_ratio,
902 .maxlen = sizeof(vm_dirty_ratio),
903 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700904 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 .strategy = &sysctl_intvec,
906 .extra1 = &zero,
907 .extra2 = &one_hundred,
908 },
909 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800911 .data = &dirty_writeback_interval,
912 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 .mode = 0644,
914 .proc_handler = &dirty_writeback_centisecs_handler,
915 },
916 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800918 .data = &dirty_expire_interval,
919 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800921 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 },
923 {
924 .ctl_name = VM_NR_PDFLUSH_THREADS,
925 .procname = "nr_pdflush_threads",
926 .data = &nr_pdflush_threads,
927 .maxlen = sizeof nr_pdflush_threads,
928 .mode = 0444 /* read-only*/,
929 .proc_handler = &proc_dointvec,
930 },
931 {
932 .ctl_name = VM_SWAPPINESS,
933 .procname = "swappiness",
934 .data = &vm_swappiness,
935 .maxlen = sizeof(vm_swappiness),
936 .mode = 0644,
937 .proc_handler = &proc_dointvec_minmax,
938 .strategy = &sysctl_intvec,
939 .extra1 = &zero,
940 .extra2 = &one_hundred,
941 },
942#ifdef CONFIG_HUGETLB_PAGE
943 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 .procname = "nr_hugepages",
945 .data = &max_huge_pages,
946 .maxlen = sizeof(unsigned long),
947 .mode = 0644,
948 .proc_handler = &hugetlb_sysctl_handler,
949 .extra1 = (void *)&hugetlb_zero,
950 .extra2 = (void *)&hugetlb_infinity,
951 },
952 {
953 .ctl_name = VM_HUGETLB_GROUP,
954 .procname = "hugetlb_shm_group",
955 .data = &sysctl_hugetlb_shm_group,
956 .maxlen = sizeof(gid_t),
957 .mode = 0644,
958 .proc_handler = &proc_dointvec,
959 },
Mel Gorman396faf02007-07-17 04:03:13 -0700960 {
961 .ctl_name = CTL_UNNUMBERED,
962 .procname = "hugepages_treat_as_movable",
963 .data = &hugepages_treat_as_movable,
964 .maxlen = sizeof(int),
965 .mode = 0644,
966 .proc_handler = &hugetlb_treat_movable_handler,
967 },
Adam Litke54f9f802007-10-16 01:26:20 -0700968 {
969 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800970 .procname = "nr_overcommit_hugepages",
971 .data = &nr_overcommit_huge_pages,
972 .maxlen = sizeof(nr_overcommit_huge_pages),
973 .mode = 0644,
974 .proc_handler = &proc_doulongvec_minmax,
975 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976#endif
977 {
978 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
979 .procname = "lowmem_reserve_ratio",
980 .data = &sysctl_lowmem_reserve_ratio,
981 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
982 .mode = 0644,
983 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
984 .strategy = &sysctl_intvec,
985 },
986 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800987 .ctl_name = VM_DROP_PAGECACHE,
988 .procname = "drop_caches",
989 .data = &sysctl_drop_caches,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = drop_caches_sysctl_handler,
993 .strategy = &sysctl_intvec,
994 },
995 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 .ctl_name = VM_MIN_FREE_KBYTES,
997 .procname = "min_free_kbytes",
998 .data = &min_free_kbytes,
999 .maxlen = sizeof(min_free_kbytes),
1000 .mode = 0644,
1001 .proc_handler = &min_free_kbytes_sysctl_handler,
1002 .strategy = &sysctl_intvec,
1003 .extra1 = &zero,
1004 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001005 {
1006 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1007 .procname = "percpu_pagelist_fraction",
1008 .data = &percpu_pagelist_fraction,
1009 .maxlen = sizeof(percpu_pagelist_fraction),
1010 .mode = 0644,
1011 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1013 .extra1 = &min_percpu_pagelist_fract,
1014 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015#ifdef CONFIG_MMU
1016 {
1017 .ctl_name = VM_MAX_MAP_COUNT,
1018 .procname = "max_map_count",
1019 .data = &sysctl_max_map_count,
1020 .maxlen = sizeof(sysctl_max_map_count),
1021 .mode = 0644,
1022 .proc_handler = &proc_dointvec
1023 },
1024#endif
1025 {
1026 .ctl_name = VM_LAPTOP_MODE,
1027 .procname = "laptop_mode",
1028 .data = &laptop_mode,
1029 .maxlen = sizeof(laptop_mode),
1030 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001031 .proc_handler = &proc_dointvec_jiffies,
1032 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 },
1034 {
1035 .ctl_name = VM_BLOCK_DUMP,
1036 .procname = "block_dump",
1037 .data = &block_dump,
1038 .maxlen = sizeof(block_dump),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec,
1041 .strategy = &sysctl_intvec,
1042 .extra1 = &zero,
1043 },
1044 {
1045 .ctl_name = VM_VFS_CACHE_PRESSURE,
1046 .procname = "vfs_cache_pressure",
1047 .data = &sysctl_vfs_cache_pressure,
1048 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1049 .mode = 0644,
1050 .proc_handler = &proc_dointvec,
1051 .strategy = &sysctl_intvec,
1052 .extra1 = &zero,
1053 },
1054#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1055 {
1056 .ctl_name = VM_LEGACY_VA_LAYOUT,
1057 .procname = "legacy_va_layout",
1058 .data = &sysctl_legacy_va_layout,
1059 .maxlen = sizeof(sysctl_legacy_va_layout),
1060 .mode = 0644,
1061 .proc_handler = &proc_dointvec,
1062 .strategy = &sysctl_intvec,
1063 .extra1 = &zero,
1064 },
1065#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001066#ifdef CONFIG_NUMA
1067 {
1068 .ctl_name = VM_ZONE_RECLAIM_MODE,
1069 .procname = "zone_reclaim_mode",
1070 .data = &zone_reclaim_mode,
1071 .maxlen = sizeof(zone_reclaim_mode),
1072 .mode = 0644,
1073 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001074 .strategy = &sysctl_intvec,
1075 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001076 },
Christoph Lameter96146342006-07-03 00:24:13 -07001077 {
1078 .ctl_name = VM_MIN_UNMAPPED,
1079 .procname = "min_unmapped_ratio",
1080 .data = &sysctl_min_unmapped_ratio,
1081 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1082 .mode = 0644,
1083 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1084 .strategy = &sysctl_intvec,
1085 .extra1 = &zero,
1086 .extra2 = &one_hundred,
1087 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001088 {
1089 .ctl_name = VM_MIN_SLAB,
1090 .procname = "min_slab_ratio",
1091 .data = &sysctl_min_slab_ratio,
1092 .maxlen = sizeof(sysctl_min_slab_ratio),
1093 .mode = 0644,
1094 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1095 .strategy = &sysctl_intvec,
1096 .extra1 = &zero,
1097 .extra2 = &one_hundred,
1098 },
Christoph Lameter17436602006-01-18 17:42:32 -08001099#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001100#ifdef CONFIG_SMP
1101 {
1102 .ctl_name = CTL_UNNUMBERED,
1103 .procname = "stat_interval",
1104 .data = &sysctl_stat_interval,
1105 .maxlen = sizeof(sysctl_stat_interval),
1106 .mode = 0644,
1107 .proc_handler = &proc_dointvec_jiffies,
1108 .strategy = &sysctl_jiffies,
1109 },
1110#endif
Eric Parised032182007-06-28 15:55:21 -04001111#ifdef CONFIG_SECURITY
1112 {
1113 .ctl_name = CTL_UNNUMBERED,
1114 .procname = "mmap_min_addr",
1115 .data = &mmap_min_addr,
1116 .maxlen = sizeof(unsigned long),
1117 .mode = 0644,
1118 .proc_handler = &proc_doulongvec_minmax,
1119 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001120#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001121#ifdef CONFIG_NUMA
1122 {
1123 .ctl_name = CTL_UNNUMBERED,
1124 .procname = "numa_zonelist_order",
1125 .data = &numa_zonelist_order,
1126 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1127 .mode = 0644,
1128 .proc_handler = &numa_zonelist_order_handler,
1129 .strategy = &sysctl_string,
1130 },
1131#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001132#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001133 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001134 {
1135 .ctl_name = VM_VDSO_ENABLED,
1136 .procname = "vdso_enabled",
1137 .data = &vdso_enabled,
1138 .maxlen = sizeof(vdso_enabled),
1139 .mode = 0644,
1140 .proc_handler = &proc_dointvec,
1141 .strategy = &sysctl_intvec,
1142 .extra1 = &zero,
1143 },
1144#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001145/*
1146 * NOTE: do not add new entries to this table unless you have read
1147 * Documentation/sysctl/ctl_unnumbered.txt
1148 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 { .ctl_name = 0 }
1150};
1151
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001152#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001153static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001154 { .ctl_name = 0 }
1155};
1156#endif
1157
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001158static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 {
1160 .ctl_name = FS_NRINODE,
1161 .procname = "inode-nr",
1162 .data = &inodes_stat,
1163 .maxlen = 2*sizeof(int),
1164 .mode = 0444,
1165 .proc_handler = &proc_dointvec,
1166 },
1167 {
1168 .ctl_name = FS_STATINODE,
1169 .procname = "inode-state",
1170 .data = &inodes_stat,
1171 .maxlen = 7*sizeof(int),
1172 .mode = 0444,
1173 .proc_handler = &proc_dointvec,
1174 },
1175 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 .procname = "file-nr",
1177 .data = &files_stat,
1178 .maxlen = 3*sizeof(int),
1179 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001180 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 },
1182 {
1183 .ctl_name = FS_MAXFILE,
1184 .procname = "file-max",
1185 .data = &files_stat.max_files,
1186 .maxlen = sizeof(int),
1187 .mode = 0644,
1188 .proc_handler = &proc_dointvec,
1189 },
1190 {
1191 .ctl_name = FS_DENTRY,
1192 .procname = "dentry-state",
1193 .data = &dentry_stat,
1194 .maxlen = 6*sizeof(int),
1195 .mode = 0444,
1196 .proc_handler = &proc_dointvec,
1197 },
1198 {
1199 .ctl_name = FS_OVERFLOWUID,
1200 .procname = "overflowuid",
1201 .data = &fs_overflowuid,
1202 .maxlen = sizeof(int),
1203 .mode = 0644,
1204 .proc_handler = &proc_dointvec_minmax,
1205 .strategy = &sysctl_intvec,
1206 .extra1 = &minolduid,
1207 .extra2 = &maxolduid,
1208 },
1209 {
1210 .ctl_name = FS_OVERFLOWGID,
1211 .procname = "overflowgid",
1212 .data = &fs_overflowgid,
1213 .maxlen = sizeof(int),
1214 .mode = 0644,
1215 .proc_handler = &proc_dointvec_minmax,
1216 .strategy = &sysctl_intvec,
1217 .extra1 = &minolduid,
1218 .extra2 = &maxolduid,
1219 },
1220 {
1221 .ctl_name = FS_LEASES,
1222 .procname = "leases-enable",
1223 .data = &leases_enable,
1224 .maxlen = sizeof(int),
1225 .mode = 0644,
1226 .proc_handler = &proc_dointvec,
1227 },
1228#ifdef CONFIG_DNOTIFY
1229 {
1230 .ctl_name = FS_DIR_NOTIFY,
1231 .procname = "dir-notify-enable",
1232 .data = &dir_notify_enable,
1233 .maxlen = sizeof(int),
1234 .mode = 0644,
1235 .proc_handler = &proc_dointvec,
1236 },
1237#endif
1238#ifdef CONFIG_MMU
1239 {
1240 .ctl_name = FS_LEASE_TIME,
1241 .procname = "lease-break-time",
1242 .data = &lease_break_time,
1243 .maxlen = sizeof(int),
1244 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001245 .proc_handler = &proc_dointvec_minmax,
1246 .strategy = &sysctl_intvec,
1247 .extra1 = &zero,
1248 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 },
1250 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 .procname = "aio-nr",
1252 .data = &aio_nr,
1253 .maxlen = sizeof(aio_nr),
1254 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001255 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 },
1257 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 .procname = "aio-max-nr",
1259 .data = &aio_max_nr,
1260 .maxlen = sizeof(aio_max_nr),
1261 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001262 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001264#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001265 {
1266 .ctl_name = FS_INOTIFY,
1267 .procname = "inotify",
1268 .mode = 0555,
1269 .child = inotify_table,
1270 },
1271#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001273 {
1274 .ctl_name = KERN_SETUID_DUMPABLE,
1275 .procname = "suid_dumpable",
1276 .data = &suid_dumpable,
1277 .maxlen = sizeof(int),
1278 .mode = 0644,
1279 .proc_handler = &proc_dointvec,
1280 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001281#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1282 {
1283 .ctl_name = CTL_UNNUMBERED,
1284 .procname = "binfmt_misc",
1285 .mode = 0555,
1286 .child = binfmt_misc_table,
1287 },
1288#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001289/*
1290 * NOTE: do not add new entries to this table unless you have read
1291 * Documentation/sysctl/ctl_unnumbered.txt
1292 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 { .ctl_name = 0 }
1294};
1295
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001296static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001297#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001298 {
1299 .ctl_name = CTL_UNNUMBERED,
1300 .procname = "exception-trace",
1301 .data = &show_unhandled_signals,
1302 .maxlen = sizeof(int),
1303 .mode = 0644,
1304 .proc_handler = proc_dointvec
1305 },
1306#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 { .ctl_name = 0 }
1308};
1309
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001310static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001312};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Al Viro330d57f2005-11-04 10:18:40 +00001314static DEFINE_SPINLOCK(sysctl_lock);
1315
1316/* called under sysctl_lock */
1317static int use_table(struct ctl_table_header *p)
1318{
1319 if (unlikely(p->unregistering))
1320 return 0;
1321 p->used++;
1322 return 1;
1323}
1324
1325/* called under sysctl_lock */
1326static void unuse_table(struct ctl_table_header *p)
1327{
1328 if (!--p->used)
1329 if (unlikely(p->unregistering))
1330 complete(p->unregistering);
1331}
1332
1333/* called under sysctl_lock, will reacquire if has to wait */
1334static void start_unregistering(struct ctl_table_header *p)
1335{
1336 /*
1337 * if p->used is 0, nobody will ever touch that entry again;
1338 * we'll eliminate all paths to it before dropping sysctl_lock
1339 */
1340 if (unlikely(p->used)) {
1341 struct completion wait;
1342 init_completion(&wait);
1343 p->unregistering = &wait;
1344 spin_unlock(&sysctl_lock);
1345 wait_for_completion(&wait);
1346 spin_lock(&sysctl_lock);
1347 }
1348 /*
1349 * do not remove from the list until nobody holds it; walking the
1350 * list in do_sysctl() relies on that.
1351 */
1352 list_del_init(&p->ctl_entry);
1353}
1354
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001355void sysctl_head_finish(struct ctl_table_header *head)
1356{
1357 if (!head)
1358 return;
1359 spin_lock(&sysctl_lock);
1360 unuse_table(head);
1361 spin_unlock(&sysctl_lock);
1362}
1363
1364struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1365{
1366 struct ctl_table_header *head;
1367 struct list_head *tmp;
1368 spin_lock(&sysctl_lock);
1369 if (prev) {
1370 tmp = &prev->ctl_entry;
1371 unuse_table(prev);
1372 goto next;
1373 }
1374 tmp = &root_table_header.ctl_entry;
1375 for (;;) {
1376 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1377
1378 if (!use_table(head))
1379 goto next;
1380 spin_unlock(&sysctl_lock);
1381 return head;
1382 next:
1383 tmp = tmp->next;
1384 if (tmp == &root_table_header.ctl_entry)
1385 break;
1386 }
1387 spin_unlock(&sysctl_lock);
1388 return NULL;
1389}
1390
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001391#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1393 void __user *newval, size_t newlen)
1394{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001395 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001396 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1399 return -ENOTDIR;
1400 if (oldval) {
1401 int old_len;
1402 if (!oldlenp || get_user(old_len, oldlenp))
1403 return -EFAULT;
1404 }
Al Viro330d57f2005-11-04 10:18:40 +00001405
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001406 for (head = sysctl_head_next(NULL); head;
1407 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001408 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001409 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001410 if (error != -ENOTDIR) {
1411 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001412 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001413 }
1414 }
Al Viro330d57f2005-11-04 10:18:40 +00001415 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416}
1417
1418asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1419{
1420 struct __sysctl_args tmp;
1421 int error;
1422
1423 if (copy_from_user(&tmp, args, sizeof(tmp)))
1424 return -EFAULT;
1425
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001426 error = deprecated_sysctl_warning(&tmp);
1427 if (error)
1428 goto out;
1429
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 lock_kernel();
1431 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1432 tmp.newval, tmp.newlen);
1433 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001434out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return error;
1436}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001437#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
1439/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001440 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 * some sysctl variables are readonly even to root.
1442 */
1443
1444static int test_perm(int mode, int op)
1445{
1446 if (!current->euid)
1447 mode >>= 6;
1448 else if (in_egroup_p(0))
1449 mode >>= 3;
1450 if ((mode & op & 0007) == op)
1451 return 0;
1452 return -EACCES;
1453}
1454
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001455int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
1457 int error;
1458 error = security_sysctl(table, op);
1459 if (error)
1460 return error;
1461 return test_perm(table->mode, op);
1462}
1463
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001464#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465static int parse_table(int __user *name, int nlen,
1466 void __user *oldval, size_t __user *oldlenp,
1467 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001468 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469{
1470 int n;
1471repeat:
1472 if (!nlen)
1473 return -ENOTDIR;
1474 if (get_user(n, name))
1475 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001476 for ( ; table->ctl_name || table->procname; table++) {
1477 if (!table->ctl_name)
1478 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001479 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 int error;
1481 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001482 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 name++;
1485 nlen--;
1486 table = table->child;
1487 goto repeat;
1488 }
1489 error = do_sysctl_strategy(table, name, nlen,
1490 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001491 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 return error;
1493 }
1494 }
1495 return -ENOTDIR;
1496}
1497
1498/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001499int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 int __user *name, int nlen,
1501 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001502 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
1504 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 if (oldval)
1507 op |= 004;
1508 if (newval)
1509 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001510 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 return -EPERM;
1512
1513 if (table->strategy) {
1514 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001515 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 if (rc < 0)
1517 return rc;
1518 if (rc > 0)
1519 return 0;
1520 }
1521
1522 /* If there is no strategy routine, or if the strategy returns
1523 * zero, proceed with automatic r/w */
1524 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001525 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1526 newval, newlen);
1527 if (rc < 0)
1528 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 }
1530 return 0;
1531}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001532#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001534static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1535{
1536 for (; table->ctl_name || table->procname; table++) {
1537 table->parent = parent;
1538 if (table->child)
1539 sysctl_set_parent(table, table->child);
1540 }
1541}
1542
1543static __init int sysctl_init(void)
1544{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001545 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001546 sysctl_set_parent(NULL, root_table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001547 err = sysctl_check_table(root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001548 return 0;
1549}
1550
1551core_initcall(sysctl_init);
1552
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553/**
1554 * register_sysctl_table - register a sysctl hierarchy
1555 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 *
1557 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1558 * array. An entry with a ctl_name of 0 terminates the table.
1559 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001560 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 *
1562 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1563 * must be unique within that level of sysctl
1564 *
1565 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1566 * enter a sysctl file
1567 *
1568 * data - a pointer to data for use by proc_handler
1569 *
1570 * maxlen - the maximum size in bytes of the data
1571 *
1572 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1573 *
1574 * child - a pointer to the child sysctl table if this entry is a directory, or
1575 * %NULL.
1576 *
1577 * proc_handler - the text handler routine (described below)
1578 *
1579 * strategy - the strategy routine (described below)
1580 *
1581 * de - for internal use by the sysctl routines
1582 *
1583 * extra1, extra2 - extra pointers usable by the proc handler routines
1584 *
1585 * Leaf nodes in the sysctl tree will be represented by a single file
1586 * under /proc; non-leaf nodes will be represented by directories.
1587 *
1588 * sysctl(2) can automatically manage read and write requests through
1589 * the sysctl table. The data and maxlen fields of the ctl_table
1590 * struct enable minimal validation of the values being written to be
1591 * performed, and the mode field allows minimal authentication.
1592 *
1593 * More sophisticated management can be enabled by the provision of a
1594 * strategy routine with the table entry. This will be called before
1595 * any automatic read or write of the data is performed.
1596 *
1597 * The strategy routine may return
1598 *
1599 * < 0 - Error occurred (error is passed to user process)
1600 *
1601 * 0 - OK - proceed with automatic read or write.
1602 *
1603 * > 0 - OK - read or write has been done by the strategy routine, so
1604 * return immediately.
1605 *
1606 * There must be a proc_handler routine for any terminal nodes
1607 * mirrored under /proc/sys (non-terminals are handled by a built-in
1608 * directory handler). Several default handlers are available to
1609 * cover common cases -
1610 *
1611 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1612 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1613 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1614 *
1615 * It is the handler's job to read the input buffer from user memory
1616 * and process it. The handler should return 0 on success.
1617 *
1618 * This routine returns %NULL on a failure to register, and a pointer
1619 * to the table header on success.
1620 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001621struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
1623 struct ctl_table_header *tmp;
1624 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1625 if (!tmp)
1626 return NULL;
1627 tmp->ctl_table = table;
1628 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001629 tmp->used = 0;
1630 tmp->unregistering = NULL;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001631 sysctl_set_parent(NULL, table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001632 if (sysctl_check_table(tmp->ctl_table)) {
1633 kfree(tmp);
1634 return NULL;
1635 }
Al Viro330d57f2005-11-04 10:18:40 +00001636 spin_lock(&sysctl_lock);
Eric W. Biederman0b4d4142007-02-14 00:34:09 -08001637 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001638 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 return tmp;
1640}
1641
1642/**
1643 * unregister_sysctl_table - unregister a sysctl table hierarchy
1644 * @header: the header returned from register_sysctl_table
1645 *
1646 * Unregisters the sysctl table and all children. proc entries may not
1647 * actually be removed until they are no longer used by anyone.
1648 */
1649void unregister_sysctl_table(struct ctl_table_header * header)
1650{
Al Viro330d57f2005-11-04 10:18:40 +00001651 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001652
1653 if (header == NULL)
1654 return;
1655
Al Viro330d57f2005-11-04 10:18:40 +00001656 spin_lock(&sysctl_lock);
1657 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001658 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 kfree(header);
1660}
1661
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001662#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001663struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001664{
1665 return NULL;
1666}
1667
1668void unregister_sysctl_table(struct ctl_table_header * table)
1669{
1670}
1671
1672#endif /* CONFIG_SYSCTL */
1673
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674/*
1675 * /proc/sys support
1676 */
1677
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001678#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001680static int _proc_do_string(void* data, int maxlen, int write,
1681 struct file *filp, void __user *buffer,
1682 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001683{
1684 size_t len;
1685 char __user *p;
1686 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001687
1688 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001689 *lenp = 0;
1690 return 0;
1691 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001692
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001693 if (write) {
1694 len = 0;
1695 p = buffer;
1696 while (len < *lenp) {
1697 if (get_user(c, p++))
1698 return -EFAULT;
1699 if (c == 0 || c == '\n')
1700 break;
1701 len++;
1702 }
1703 if (len >= maxlen)
1704 len = maxlen-1;
1705 if(copy_from_user(data, buffer, len))
1706 return -EFAULT;
1707 ((char *) data)[len] = 0;
1708 *ppos += *lenp;
1709 } else {
1710 len = strlen(data);
1711 if (len > maxlen)
1712 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001713
1714 if (*ppos > len) {
1715 *lenp = 0;
1716 return 0;
1717 }
1718
1719 data += *ppos;
1720 len -= *ppos;
1721
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001722 if (len > *lenp)
1723 len = *lenp;
1724 if (len)
1725 if(copy_to_user(buffer, data, len))
1726 return -EFAULT;
1727 if (len < *lenp) {
1728 if(put_user('\n', ((char __user *) buffer) + len))
1729 return -EFAULT;
1730 len++;
1731 }
1732 *lenp = len;
1733 *ppos += len;
1734 }
1735 return 0;
1736}
1737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738/**
1739 * proc_dostring - read a string sysctl
1740 * @table: the sysctl table
1741 * @write: %TRUE if this is a write to the sysctl file
1742 * @filp: the file structure
1743 * @buffer: the user buffer
1744 * @lenp: the size of the user buffer
1745 * @ppos: file position
1746 *
1747 * Reads/writes a string from/to the user buffer. If the kernel
1748 * buffer provided is not large enough to hold the string, the
1749 * string is truncated. The copied string is %NULL-terminated.
1750 * If the string is being read by the user process, it is copied
1751 * and a newline '\n' is added. It is truncated if the buffer is
1752 * not large enough.
1753 *
1754 * Returns 0 on success.
1755 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001756int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 void __user *buffer, size_t *lenp, loff_t *ppos)
1758{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001759 return _proc_do_string(table->data, table->maxlen, write, filp,
1760 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
1764static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1765 int *valp,
1766 int write, void *data)
1767{
1768 if (write) {
1769 *valp = *negp ? -*lvalp : *lvalp;
1770 } else {
1771 int val = *valp;
1772 if (val < 0) {
1773 *negp = -1;
1774 *lvalp = (unsigned long)-val;
1775 } else {
1776 *negp = 0;
1777 *lvalp = (unsigned long)val;
1778 }
1779 }
1780 return 0;
1781}
1782
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001783static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001784 int write, struct file *filp, void __user *buffer,
1785 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1787 int write, void *data),
1788 void *data)
1789{
1790#define TMPBUFLEN 21
1791 int *i, vleft, first=1, neg, val;
1792 unsigned long lval;
1793 size_t left, len;
1794
1795 char buf[TMPBUFLEN], *p;
1796 char __user *s = buffer;
1797
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001798 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 (*ppos && !write)) {
1800 *lenp = 0;
1801 return 0;
1802 }
1803
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001804 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 vleft = table->maxlen / sizeof(*i);
1806 left = *lenp;
1807
1808 if (!conv)
1809 conv = do_proc_dointvec_conv;
1810
1811 for (; left && vleft--; i++, first=0) {
1812 if (write) {
1813 while (left) {
1814 char c;
1815 if (get_user(c, s))
1816 return -EFAULT;
1817 if (!isspace(c))
1818 break;
1819 left--;
1820 s++;
1821 }
1822 if (!left)
1823 break;
1824 neg = 0;
1825 len = left;
1826 if (len > sizeof(buf) - 1)
1827 len = sizeof(buf) - 1;
1828 if (copy_from_user(buf, s, len))
1829 return -EFAULT;
1830 buf[len] = 0;
1831 p = buf;
1832 if (*p == '-' && left > 1) {
1833 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001834 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 }
1836 if (*p < '0' || *p > '9')
1837 break;
1838
1839 lval = simple_strtoul(p, &p, 0);
1840
1841 len = p-buf;
1842 if ((len < left) && *p && !isspace(*p))
1843 break;
1844 if (neg)
1845 val = -val;
1846 s += len;
1847 left -= len;
1848
1849 if (conv(&neg, &lval, i, 1, data))
1850 break;
1851 } else {
1852 p = buf;
1853 if (!first)
1854 *p++ = '\t';
1855
1856 if (conv(&neg, &lval, i, 0, data))
1857 break;
1858
1859 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1860 len = strlen(buf);
1861 if (len > left)
1862 len = left;
1863 if(copy_to_user(s, buf, len))
1864 return -EFAULT;
1865 left -= len;
1866 s += len;
1867 }
1868 }
1869
1870 if (!write && !first && left) {
1871 if(put_user('\n', s))
1872 return -EFAULT;
1873 left--, s++;
1874 }
1875 if (write) {
1876 while (left) {
1877 char c;
1878 if (get_user(c, s++))
1879 return -EFAULT;
1880 if (!isspace(c))
1881 break;
1882 left--;
1883 }
1884 }
1885 if (write && first)
1886 return -EINVAL;
1887 *lenp -= left;
1888 *ppos += *lenp;
1889 return 0;
1890#undef TMPBUFLEN
1891}
1892
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001893static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001894 void __user *buffer, size_t *lenp, loff_t *ppos,
1895 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1896 int write, void *data),
1897 void *data)
1898{
1899 return __do_proc_dointvec(table->data, table, write, filp,
1900 buffer, lenp, ppos, conv, data);
1901}
1902
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903/**
1904 * proc_dointvec - read a vector of integers
1905 * @table: the sysctl table
1906 * @write: %TRUE if this is a write to the sysctl file
1907 * @filp: the file structure
1908 * @buffer: the user buffer
1909 * @lenp: the size of the user buffer
1910 * @ppos: file position
1911 *
1912 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1913 * values from/to the user buffer, treated as an ASCII string.
1914 *
1915 * Returns 0 on success.
1916 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001917int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 void __user *buffer, size_t *lenp, loff_t *ppos)
1919{
1920 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1921 NULL,NULL);
1922}
1923
1924#define OP_SET 0
1925#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001926#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
1928static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1929 int *valp,
1930 int write, void *data)
1931{
1932 int op = *(int *)data;
1933 if (write) {
1934 int val = *negp ? -*lvalp : *lvalp;
1935 switch(op) {
1936 case OP_SET: *valp = val; break;
1937 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001938 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 }
1940 } else {
1941 int val = *valp;
1942 if (val < 0) {
1943 *negp = -1;
1944 *lvalp = (unsigned long)-val;
1945 } else {
1946 *negp = 0;
1947 *lvalp = (unsigned long)val;
1948 }
1949 }
1950 return 0;
1951}
1952
Andrew Morgan72c2d582007-10-18 03:05:59 -07001953#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954/*
1955 * init may raise the set.
1956 */
Andrew Morgan72c2d582007-10-18 03:05:59 -07001957
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001958int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 void __user *buffer, size_t *lenp, loff_t *ppos)
1960{
1961 int op;
1962
Eric Paris6ff1b442007-02-10 01:43:19 -08001963 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 return -EPERM;
1965 }
1966
Serge E. Hallynb460cbc2007-10-18 23:39:52 -07001967 op = is_global_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1969 do_proc_dointvec_bset_conv,&op);
1970}
Andrew Morgan72c2d582007-10-18 03:05:59 -07001971#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001973/*
1974 * Taint values can only be increased
1975 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001976static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001977 void __user *buffer, size_t *lenp, loff_t *ppos)
1978{
1979 int op;
1980
Bastian Blank91fcd412007-04-23 14:41:14 -07001981 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001982 return -EPERM;
1983
1984 op = OP_OR;
1985 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1986 do_proc_dointvec_bset_conv,&op);
1987}
1988
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989struct do_proc_dointvec_minmax_conv_param {
1990 int *min;
1991 int *max;
1992};
1993
1994static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1995 int *valp,
1996 int write, void *data)
1997{
1998 struct do_proc_dointvec_minmax_conv_param *param = data;
1999 if (write) {
2000 int val = *negp ? -*lvalp : *lvalp;
2001 if ((param->min && *param->min > val) ||
2002 (param->max && *param->max < val))
2003 return -EINVAL;
2004 *valp = val;
2005 } else {
2006 int val = *valp;
2007 if (val < 0) {
2008 *negp = -1;
2009 *lvalp = (unsigned long)-val;
2010 } else {
2011 *negp = 0;
2012 *lvalp = (unsigned long)val;
2013 }
2014 }
2015 return 0;
2016}
2017
2018/**
2019 * proc_dointvec_minmax - read a vector of integers with min/max values
2020 * @table: the sysctl table
2021 * @write: %TRUE if this is a write to the sysctl file
2022 * @filp: the file structure
2023 * @buffer: the user buffer
2024 * @lenp: the size of the user buffer
2025 * @ppos: file position
2026 *
2027 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2028 * values from/to the user buffer, treated as an ASCII string.
2029 *
2030 * This routine will ensure the values are within the range specified by
2031 * table->extra1 (min) and table->extra2 (max).
2032 *
2033 * Returns 0 on success.
2034 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002035int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 void __user *buffer, size_t *lenp, loff_t *ppos)
2037{
2038 struct do_proc_dointvec_minmax_conv_param param = {
2039 .min = (int *) table->extra1,
2040 .max = (int *) table->extra2,
2041 };
2042 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2043 do_proc_dointvec_minmax_conv, &param);
2044}
2045
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002046static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 struct file *filp,
2048 void __user *buffer,
2049 size_t *lenp, loff_t *ppos,
2050 unsigned long convmul,
2051 unsigned long convdiv)
2052{
2053#define TMPBUFLEN 21
2054 unsigned long *i, *min, *max, val;
2055 int vleft, first=1, neg;
2056 size_t len, left;
2057 char buf[TMPBUFLEN], *p;
2058 char __user *s = buffer;
2059
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002060 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 (*ppos && !write)) {
2062 *lenp = 0;
2063 return 0;
2064 }
2065
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002066 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 min = (unsigned long *) table->extra1;
2068 max = (unsigned long *) table->extra2;
2069 vleft = table->maxlen / sizeof(unsigned long);
2070 left = *lenp;
2071
2072 for (; left && vleft--; i++, min++, max++, first=0) {
2073 if (write) {
2074 while (left) {
2075 char c;
2076 if (get_user(c, s))
2077 return -EFAULT;
2078 if (!isspace(c))
2079 break;
2080 left--;
2081 s++;
2082 }
2083 if (!left)
2084 break;
2085 neg = 0;
2086 len = left;
2087 if (len > TMPBUFLEN-1)
2088 len = TMPBUFLEN-1;
2089 if (copy_from_user(buf, s, len))
2090 return -EFAULT;
2091 buf[len] = 0;
2092 p = buf;
2093 if (*p == '-' && left > 1) {
2094 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002095 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 }
2097 if (*p < '0' || *p > '9')
2098 break;
2099 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2100 len = p-buf;
2101 if ((len < left) && *p && !isspace(*p))
2102 break;
2103 if (neg)
2104 val = -val;
2105 s += len;
2106 left -= len;
2107
2108 if(neg)
2109 continue;
2110 if ((min && val < *min) || (max && val > *max))
2111 continue;
2112 *i = val;
2113 } else {
2114 p = buf;
2115 if (!first)
2116 *p++ = '\t';
2117 sprintf(p, "%lu", convdiv * (*i) / convmul);
2118 len = strlen(buf);
2119 if (len > left)
2120 len = left;
2121 if(copy_to_user(s, buf, len))
2122 return -EFAULT;
2123 left -= len;
2124 s += len;
2125 }
2126 }
2127
2128 if (!write && !first && left) {
2129 if(put_user('\n', s))
2130 return -EFAULT;
2131 left--, s++;
2132 }
2133 if (write) {
2134 while (left) {
2135 char c;
2136 if (get_user(c, s++))
2137 return -EFAULT;
2138 if (!isspace(c))
2139 break;
2140 left--;
2141 }
2142 }
2143 if (write && first)
2144 return -EINVAL;
2145 *lenp -= left;
2146 *ppos += *lenp;
2147 return 0;
2148#undef TMPBUFLEN
2149}
2150
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002151static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002152 struct file *filp,
2153 void __user *buffer,
2154 size_t *lenp, loff_t *ppos,
2155 unsigned long convmul,
2156 unsigned long convdiv)
2157{
2158 return __do_proc_doulongvec_minmax(table->data, table, write,
2159 filp, buffer, lenp, ppos, convmul, convdiv);
2160}
2161
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162/**
2163 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2164 * @table: the sysctl table
2165 * @write: %TRUE if this is a write to the sysctl file
2166 * @filp: the file structure
2167 * @buffer: the user buffer
2168 * @lenp: the size of the user buffer
2169 * @ppos: file position
2170 *
2171 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2172 * values from/to the user buffer, treated as an ASCII string.
2173 *
2174 * This routine will ensure the values are within the range specified by
2175 * table->extra1 (min) and table->extra2 (max).
2176 *
2177 * Returns 0 on success.
2178 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002179int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 void __user *buffer, size_t *lenp, loff_t *ppos)
2181{
2182 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2183}
2184
2185/**
2186 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2187 * @table: the sysctl table
2188 * @write: %TRUE if this is a write to the sysctl file
2189 * @filp: the file structure
2190 * @buffer: the user buffer
2191 * @lenp: the size of the user buffer
2192 * @ppos: file position
2193 *
2194 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2195 * values from/to the user buffer, treated as an ASCII string. The values
2196 * are treated as milliseconds, and converted to jiffies when they are stored.
2197 *
2198 * This routine will ensure the values are within the range specified by
2199 * table->extra1 (min) and table->extra2 (max).
2200 *
2201 * Returns 0 on success.
2202 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002203int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 struct file *filp,
2205 void __user *buffer,
2206 size_t *lenp, loff_t *ppos)
2207{
2208 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2209 lenp, ppos, HZ, 1000l);
2210}
2211
2212
2213static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2214 int *valp,
2215 int write, void *data)
2216{
2217 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002218 if (*lvalp > LONG_MAX / HZ)
2219 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2221 } else {
2222 int val = *valp;
2223 unsigned long lval;
2224 if (val < 0) {
2225 *negp = -1;
2226 lval = (unsigned long)-val;
2227 } else {
2228 *negp = 0;
2229 lval = (unsigned long)val;
2230 }
2231 *lvalp = lval / HZ;
2232 }
2233 return 0;
2234}
2235
2236static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2237 int *valp,
2238 int write, void *data)
2239{
2240 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002241 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2242 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2244 } else {
2245 int val = *valp;
2246 unsigned long lval;
2247 if (val < 0) {
2248 *negp = -1;
2249 lval = (unsigned long)-val;
2250 } else {
2251 *negp = 0;
2252 lval = (unsigned long)val;
2253 }
2254 *lvalp = jiffies_to_clock_t(lval);
2255 }
2256 return 0;
2257}
2258
2259static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2260 int *valp,
2261 int write, void *data)
2262{
2263 if (write) {
2264 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2265 } else {
2266 int val = *valp;
2267 unsigned long lval;
2268 if (val < 0) {
2269 *negp = -1;
2270 lval = (unsigned long)-val;
2271 } else {
2272 *negp = 0;
2273 lval = (unsigned long)val;
2274 }
2275 *lvalp = jiffies_to_msecs(lval);
2276 }
2277 return 0;
2278}
2279
2280/**
2281 * proc_dointvec_jiffies - read a vector of integers as seconds
2282 * @table: the sysctl table
2283 * @write: %TRUE if this is a write to the sysctl file
2284 * @filp: the file structure
2285 * @buffer: the user buffer
2286 * @lenp: the size of the user buffer
2287 * @ppos: file position
2288 *
2289 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2290 * values from/to the user buffer, treated as an ASCII string.
2291 * The values read are assumed to be in seconds, and are converted into
2292 * jiffies.
2293 *
2294 * Returns 0 on success.
2295 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002296int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 void __user *buffer, size_t *lenp, loff_t *ppos)
2298{
2299 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2300 do_proc_dointvec_jiffies_conv,NULL);
2301}
2302
2303/**
2304 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2305 * @table: the sysctl table
2306 * @write: %TRUE if this is a write to the sysctl file
2307 * @filp: the file structure
2308 * @buffer: the user buffer
2309 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002310 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 *
2312 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2313 * values from/to the user buffer, treated as an ASCII string.
2314 * The values read are assumed to be in 1/USER_HZ seconds, and
2315 * are converted into jiffies.
2316 *
2317 * Returns 0 on success.
2318 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002319int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 void __user *buffer, size_t *lenp, loff_t *ppos)
2321{
2322 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2323 do_proc_dointvec_userhz_jiffies_conv,NULL);
2324}
2325
2326/**
2327 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2328 * @table: the sysctl table
2329 * @write: %TRUE if this is a write to the sysctl file
2330 * @filp: the file structure
2331 * @buffer: the user buffer
2332 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002333 * @ppos: file position
2334 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 *
2336 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2337 * values from/to the user buffer, treated as an ASCII string.
2338 * The values read are assumed to be in 1/1000 seconds, and
2339 * are converted into jiffies.
2340 *
2341 * Returns 0 on success.
2342 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002343int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 void __user *buffer, size_t *lenp, loff_t *ppos)
2345{
2346 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2347 do_proc_dointvec_ms_jiffies_conv, NULL);
2348}
2349
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002350static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002351 void __user *buffer, size_t *lenp, loff_t *ppos)
2352{
2353 struct pid *new_pid;
2354 pid_t tmp;
2355 int r;
2356
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002357 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002358
2359 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2360 lenp, ppos, NULL, NULL);
2361 if (r || !write)
2362 return r;
2363
2364 new_pid = find_get_pid(tmp);
2365 if (!new_pid)
2366 return -ESRCH;
2367
2368 put_pid(xchg(&cad_pid, new_pid));
2369 return 0;
2370}
2371
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372#else /* CONFIG_PROC_FS */
2373
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002374int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 void __user *buffer, size_t *lenp, loff_t *ppos)
2376{
2377 return -ENOSYS;
2378}
2379
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002380int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 void __user *buffer, size_t *lenp, loff_t *ppos)
2382{
2383 return -ENOSYS;
2384}
2385
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002386int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 void __user *buffer, size_t *lenp, loff_t *ppos)
2388{
2389 return -ENOSYS;
2390}
2391
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002392int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 void __user *buffer, size_t *lenp, loff_t *ppos)
2394{
2395 return -ENOSYS;
2396}
2397
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002398int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 void __user *buffer, size_t *lenp, loff_t *ppos)
2400{
2401 return -ENOSYS;
2402}
2403
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002404int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 void __user *buffer, size_t *lenp, loff_t *ppos)
2406{
2407 return -ENOSYS;
2408}
2409
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002410int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 void __user *buffer, size_t *lenp, loff_t *ppos)
2412{
2413 return -ENOSYS;
2414}
2415
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002416int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 void __user *buffer, size_t *lenp, loff_t *ppos)
2418{
2419 return -ENOSYS;
2420}
2421
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002422int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 struct file *filp,
2424 void __user *buffer,
2425 size_t *lenp, loff_t *ppos)
2426{
2427 return -ENOSYS;
2428}
2429
2430
2431#endif /* CONFIG_PROC_FS */
2432
2433
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002434#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435/*
2436 * General sysctl support routines
2437 */
2438
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002439/* The generic sysctl data routine (used if no strategy routine supplied) */
2440int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2441 void __user *oldval, size_t __user *oldlenp,
2442 void __user *newval, size_t newlen)
2443{
2444 size_t len;
2445
2446 /* Get out of I don't have a variable */
2447 if (!table->data || !table->maxlen)
2448 return -ENOTDIR;
2449
2450 if (oldval && oldlenp) {
2451 if (get_user(len, oldlenp))
2452 return -EFAULT;
2453 if (len) {
2454 if (len > table->maxlen)
2455 len = table->maxlen;
2456 if (copy_to_user(oldval, table->data, len))
2457 return -EFAULT;
2458 if (put_user(len, oldlenp))
2459 return -EFAULT;
2460 }
2461 }
2462
2463 if (newval && newlen) {
2464 if (newlen > table->maxlen)
2465 newlen = table->maxlen;
2466
2467 if (copy_from_user(table->data, newval, newlen))
2468 return -EFAULT;
2469 }
2470 return 1;
2471}
2472
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002474int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002476 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 if (!table->data || !table->maxlen)
2479 return -ENOTDIR;
2480
2481 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002482 size_t bufsize;
2483 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002485 if (bufsize) {
2486 size_t len = strlen(table->data), copied;
2487
2488 /* This shouldn't trigger for a well-formed sysctl */
2489 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002491
2492 /* Copy up to a max of bufsize-1 bytes of the string */
2493 copied = (len >= bufsize) ? bufsize - 1 : len;
2494
2495 if (copy_to_user(oldval, table->data, copied) ||
2496 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002498 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 return -EFAULT;
2500 }
2501 }
2502 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002503 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 if (len > table->maxlen)
2505 len = table->maxlen;
2506 if(copy_from_user(table->data, newval, len))
2507 return -EFAULT;
2508 if (len == table->maxlen)
2509 len--;
2510 ((char *) table->data)[len] = 0;
2511 }
Yi Yang82c9df82005-12-30 16:37:10 +08002512 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513}
2514
2515/*
2516 * This function makes sure that all of the integers in the vector
2517 * are between the minimum and maximum values given in the arrays
2518 * table->extra1 and table->extra2, respectively.
2519 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002520int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002522 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523{
2524
2525 if (newval && newlen) {
2526 int __user *vec = (int __user *) newval;
2527 int *min = (int *) table->extra1;
2528 int *max = (int *) table->extra2;
2529 size_t length;
2530 int i;
2531
2532 if (newlen % sizeof(int) != 0)
2533 return -EINVAL;
2534
2535 if (!table->extra1 && !table->extra2)
2536 return 0;
2537
2538 if (newlen > table->maxlen)
2539 newlen = table->maxlen;
2540 length = newlen / sizeof(int);
2541
2542 for (i = 0; i < length; i++) {
2543 int value;
2544 if (get_user(value, vec + i))
2545 return -EFAULT;
2546 if (min && value < min[i])
2547 return -EINVAL;
2548 if (max && value > max[i])
2549 return -EINVAL;
2550 }
2551 }
2552 return 0;
2553}
2554
2555/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002556int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002558 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002560 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002562
2563 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002565 if (olen) {
2566 int val;
2567
2568 if (olen < sizeof(int))
2569 return -EINVAL;
2570
2571 val = *(int *)(table->data) / HZ;
2572 if (put_user(val, (int __user *)oldval))
2573 return -EFAULT;
2574 if (put_user(sizeof(int), oldlenp))
2575 return -EFAULT;
2576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 }
2578 if (newval && newlen) {
2579 int new;
2580 if (newlen != sizeof(int))
2581 return -EINVAL;
2582 if (get_user(new, (int __user *)newval))
2583 return -EFAULT;
2584 *(int *)(table->data) = new*HZ;
2585 }
2586 return 1;
2587}
2588
2589/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002590int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002592 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002594 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002596
2597 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002599 if (olen) {
2600 int val;
2601
2602 if (olen < sizeof(int))
2603 return -EINVAL;
2604
2605 val = jiffies_to_msecs(*(int *)(table->data));
2606 if (put_user(val, (int __user *)oldval))
2607 return -EFAULT;
2608 if (put_user(sizeof(int), oldlenp))
2609 return -EFAULT;
2610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 }
2612 if (newval && newlen) {
2613 int new;
2614 if (newlen != sizeof(int))
2615 return -EINVAL;
2616 if (get_user(new, (int __user *)newval))
2617 return -EFAULT;
2618 *(int *)(table->data) = msecs_to_jiffies(new);
2619 }
2620 return 1;
2621}
2622
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002623
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002624
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002625#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
2627
2628asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2629{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002630 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002631 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002632
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002633 if (copy_from_user(&tmp, args, sizeof(tmp)))
2634 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002635
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002636 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002637
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002638 /* If no error reading the parameters then just -ENOSYS ... */
2639 if (!error)
2640 error = -ENOSYS;
2641
2642 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643}
2644
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002645int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2646 void __user *oldval, size_t __user *oldlenp,
2647 void __user *newval, size_t newlen)
2648{
2649 return -ENOSYS;
2650}
2651
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002652int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002654 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655{
2656 return -ENOSYS;
2657}
2658
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002659int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002661 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662{
2663 return -ENOSYS;
2664}
2665
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002666int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002668 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669{
2670 return -ENOSYS;
2671}
2672
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002673int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002675 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676{
2677 return -ENOSYS;
2678}
2679
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002680#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002682static int deprecated_sysctl_warning(struct __sysctl_args *args)
2683{
2684 static int msg_count;
2685 int name[CTL_MAXNAME];
2686 int i;
2687
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002688 /* Check args->nlen. */
2689 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2690 return -ENOTDIR;
2691
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002692 /* Read in the sysctl name for better debug message logging */
2693 for (i = 0; i < args->nlen; i++)
2694 if (get_user(name[i], args->name + i))
2695 return -EFAULT;
2696
2697 /* Ignore accesses to kernel.version */
2698 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2699 return 0;
2700
2701 if (msg_count < 5) {
2702 msg_count++;
2703 printk(KERN_INFO
2704 "warning: process `%s' used the deprecated sysctl "
2705 "system call with ", current->comm);
2706 for (i = 0; i < args->nlen; i++)
2707 printk("%d.", name[i]);
2708 printk("\n");
2709 }
2710 return 0;
2711}
2712
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713/*
2714 * No sense putting this after each symbol definition, twice,
2715 * exception granted :-)
2716 */
2717EXPORT_SYMBOL(proc_dointvec);
2718EXPORT_SYMBOL(proc_dointvec_jiffies);
2719EXPORT_SYMBOL(proc_dointvec_minmax);
2720EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2721EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2722EXPORT_SYMBOL(proc_dostring);
2723EXPORT_SYMBOL(proc_doulongvec_minmax);
2724EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2725EXPORT_SYMBOL(register_sysctl_table);
2726EXPORT_SYMBOL(sysctl_intvec);
2727EXPORT_SYMBOL(sysctl_jiffies);
2728EXPORT_SYMBOL(sysctl_ms_jiffies);
2729EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002730EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731EXPORT_SYMBOL(unregister_sysctl_table);