blob: b2a2d6889babc898794e7c7fb7907ef59a3b487b [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
41#include <linux/times.h>
42#include <linux/limits.h>
43#include <linux/dcache.h>
44#include <linux/syscalls.h>
Pavel Machekc255d842006-02-20 18:27:58 -080045#include <linux/nfs_fs.h>
46#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070047#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#include <asm/uaccess.h>
50#include <asm/processor.h>
51
Andi Kleen29cbc782006-09-30 01:47:55 +020052#ifdef CONFIG_X86
53#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010054#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010055#include <asm/io.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;
David Rientjesfef1bdd2008-02-07 00:14:07 -080069extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070072extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int pid_max;
75extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080077extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080078extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020079extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070080extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070081extern int sysctl_stat_interval;
Arjan van de Ven97455122008-01-25 21:08:34 +010082extern int latencytop_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070084/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080085#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070086static int one = 1;
Bron Gondwana195cf4532008-02-04 22:29:20 -080087#endif
88
89#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070090static int sixty = 60;
91#endif
92
93#ifdef CONFIG_MMU
94static int two = 2;
95#endif
96
97static int zero;
98static int one_hundred = 100;
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
101static int maxolduid = 65535;
102static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800103static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105static int ngroups_max = NGROUPS_MAX;
106
107#ifdef CONFIG_KMOD
108extern char modprobe_path[];
109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#ifdef CONFIG_CHR_DEV_SG
111extern int sg_big_buff;
112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114#ifdef __sparc__
115extern char reboot_command [];
116extern int stop_a_enabled;
117extern int scons_pwroff;
118#endif
119
120#ifdef __hppa__
121extern int pwrsw_enabled;
122extern int unaligned_enabled;
123#endif
124
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800125#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#ifdef CONFIG_MATHEMU
127extern int sysctl_ieee_emulation_warnings;
128#endif
129extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700130extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#endif
132
133extern int sysctl_hz_timer;
134
135#ifdef CONFIG_BSD_PROCESS_ACCT
136extern int acct_parm[];
137#endif
138
Jes Sorensend2b176e2006-02-28 09:42:23 -0800139#ifdef CONFIG_IA64
140extern int no_unaligned_warning;
141#endif
142
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700143#ifdef CONFIG_RT_MUTEXES
144extern int max_lock_depth;
145#endif
146
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700147#ifdef CONFIG_SYSCTL_SYSCALL
148static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700149 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700150#endif
151
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800152
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700153#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700154static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800157 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700158#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700159
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700160static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100161static struct ctl_table_root sysctl_table_root;
162static struct ctl_table_header root_table_header = {
163 .ctl_table = root_table,
164 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
165 .root = &sysctl_table_root,
166};
167static struct ctl_table_root sysctl_table_root = {
168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
169 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
170};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700172static struct ctl_table kern_table[];
173static struct ctl_table vm_table[];
174static struct ctl_table fs_table[];
175static struct ctl_table debug_table[];
176static struct ctl_table dev_table[];
177extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700178#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700179extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400180#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183int sysctl_legacy_va_layout;
184#endif
185
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700186extern int prove_locking;
187extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/* The default sysctl tables: */
190
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700191static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
195 .mode = 0555,
196 .child = kern_table,
197 },
198 {
199 .ctl_name = CTL_VM,
200 .procname = "vm",
201 .mode = 0555,
202 .child = vm_table,
203 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 .ctl_name = CTL_FS,
206 .procname = "fs",
207 .mode = 0555,
208 .child = fs_table,
209 },
210 {
211 .ctl_name = CTL_DEBUG,
212 .procname = "debug",
213 .mode = 0555,
214 .child = debug_table,
215 },
216 {
217 .ctl_name = CTL_DEV,
218 .procname = "dev",
219 .mode = 0555,
220 .child = dev_table,
221 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700222/*
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
225 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 { .ctl_name = 0 }
227};
228
Ingo Molnar77e54a12007-07-09 18:52:00 +0200229#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100230static int min_sched_granularity_ns = 100000; /* 100 usecs */
231static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
232static int min_wakeup_granularity_ns; /* 0 usecs */
233static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200234#endif
235
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700236static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200237#ifdef CONFIG_SCHED_DEBUG
238 {
239 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100240 .procname = "sched_min_granularity_ns",
241 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200242 .maxlen = sizeof(unsigned int),
243 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100244 .proc_handler = &sched_nr_latency_handler,
245 .strategy = &sysctl_intvec,
246 .extra1 = &min_sched_granularity_ns,
247 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200248 },
249 {
250 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200251 .procname = "sched_latency_ns",
252 .data = &sysctl_sched_latency,
253 .maxlen = sizeof(unsigned int),
254 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100255 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
259 },
260 {
261 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200262 .procname = "sched_wakeup_granularity_ns",
263 .data = &sysctl_sched_wakeup_granularity,
264 .maxlen = sizeof(unsigned int),
265 .mode = 0644,
266 .proc_handler = &proc_dointvec_minmax,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_wakeup_granularity_ns,
269 .extra2 = &max_wakeup_granularity_ns,
270 },
271 {
272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_batch_wakeup_granularity_ns",
274 .data = &sysctl_sched_batch_wakeup_granularity,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
277 .proc_handler = &proc_dointvec_minmax,
278 .strategy = &sysctl_intvec,
279 .extra1 = &min_wakeup_granularity_ns,
280 .extra2 = &max_wakeup_granularity_ns,
281 },
282 {
283 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200284 .procname = "sched_child_runs_first",
285 .data = &sysctl_sched_child_runs_first,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
288 .proc_handler = &proc_dointvec,
289 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200290 {
291 .ctl_name = CTL_UNNUMBERED,
292 .procname = "sched_features",
293 .data = &sysctl_sched_features,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec,
297 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200298 {
299 .ctl_name = CTL_UNNUMBERED,
300 .procname = "sched_migration_cost",
301 .data = &sysctl_sched_migration_cost,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100306 {
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_nr_migrate",
309 .data = &sysctl_sched_nr_migrate,
310 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
313 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200314#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200315 {
316 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100317 .procname = "sched_rt_period_us",
318 .data = &sysctl_sched_rt_period,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
321 .proc_handler = &proc_dointvec,
322 },
323 {
324 .ctl_name = CTL_UNNUMBERED,
325 .procname = "sched_rt_runtime_us",
326 .data = &sysctl_sched_rt_runtime,
327 .maxlen = sizeof(int),
328 .mode = 0644,
329 .proc_handler = &proc_dointvec,
330 },
331 {
332 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200333 .procname = "sched_compat_yield",
334 .data = &sysctl_sched_compat_yield,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
338 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700339#ifdef CONFIG_PROVE_LOCKING
340 {
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "prove_locking",
343 .data = &prove_locking,
344 .maxlen = sizeof(int),
345 .mode = 0644,
346 .proc_handler = &proc_dointvec,
347 },
348#endif
349#ifdef CONFIG_LOCK_STAT
350 {
351 .ctl_name = CTL_UNNUMBERED,
352 .procname = "lock_stat",
353 .data = &lock_stat,
354 .maxlen = sizeof(int),
355 .mode = 0644,
356 .proc_handler = &proc_dointvec,
357 },
358#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200359 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 .ctl_name = KERN_PANIC,
361 .procname = "panic",
362 .data = &panic_timeout,
363 .maxlen = sizeof(int),
364 .mode = 0644,
365 .proc_handler = &proc_dointvec,
366 },
367 {
368 .ctl_name = KERN_CORE_USES_PID,
369 .procname = "core_uses_pid",
370 .data = &core_uses_pid,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = &proc_dointvec,
374 },
375 {
376 .ctl_name = KERN_CORE_PATTERN,
377 .procname = "core_pattern",
378 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700379 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 .mode = 0644,
381 .proc_handler = &proc_dostring,
382 .strategy = &sysctl_string,
383 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800384#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 .procname = "tainted",
387 .data = &tainted,
388 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800389 .mode = 0644,
390 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800392#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100393#ifdef CONFIG_LATENCYTOP
394 {
395 .procname = "latencytop",
396 .data = &latencytop_enabled,
397 .maxlen = sizeof(int),
398 .mode = 0644,
399 .proc_handler = &proc_dointvec,
400 },
401#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#ifdef CONFIG_BLK_DEV_INITRD
403 {
404 .ctl_name = KERN_REALROOTDEV,
405 .procname = "real-root-dev",
406 .data = &real_root_dev,
407 .maxlen = sizeof(int),
408 .mode = 0644,
409 .proc_handler = &proc_dointvec,
410 },
411#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700412 {
413 .ctl_name = CTL_UNNUMBERED,
414 .procname = "print-fatal-signals",
415 .data = &print_fatal_signals,
416 .maxlen = sizeof(int),
417 .mode = 0644,
418 .proc_handler = &proc_dointvec,
419 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#ifdef __sparc__
421 {
422 .ctl_name = KERN_SPARC_REBOOT,
423 .procname = "reboot-cmd",
424 .data = reboot_command,
425 .maxlen = 256,
426 .mode = 0644,
427 .proc_handler = &proc_dostring,
428 .strategy = &sysctl_string,
429 },
430 {
431 .ctl_name = KERN_SPARC_STOP_A,
432 .procname = "stop-a",
433 .data = &stop_a_enabled,
434 .maxlen = sizeof (int),
435 .mode = 0644,
436 .proc_handler = &proc_dointvec,
437 },
438 {
439 .ctl_name = KERN_SPARC_SCONS_PWROFF,
440 .procname = "scons-poweroff",
441 .data = &scons_pwroff,
442 .maxlen = sizeof (int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
445 },
446#endif
447#ifdef __hppa__
448 {
449 .ctl_name = KERN_HPPA_PWRSW,
450 .procname = "soft-power",
451 .data = &pwrsw_enabled,
452 .maxlen = sizeof (int),
453 .mode = 0644,
454 .proc_handler = &proc_dointvec,
455 },
456 {
457 .ctl_name = KERN_HPPA_UNALIGNED,
458 .procname = "unaligned-trap",
459 .data = &unaligned_enabled,
460 .maxlen = sizeof (int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
463 },
464#endif
465 {
466 .ctl_name = KERN_CTLALTDEL,
467 .procname = "ctrl-alt-del",
468 .data = &C_A_D,
469 .maxlen = sizeof(int),
470 .mode = 0644,
471 .proc_handler = &proc_dointvec,
472 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#ifdef CONFIG_KMOD
474 {
475 .ctl_name = KERN_MODPROBE,
476 .procname = "modprobe",
477 .data = &modprobe_path,
478 .maxlen = KMOD_PATH_LEN,
479 .mode = 0644,
480 .proc_handler = &proc_dostring,
481 .strategy = &sysctl_string,
482 },
483#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700484#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 {
486 .ctl_name = KERN_HOTPLUG,
487 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100488 .data = &uevent_helper,
489 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 .mode = 0644,
491 .proc_handler = &proc_dostring,
492 .strategy = &sysctl_string,
493 },
494#endif
495#ifdef CONFIG_CHR_DEV_SG
496 {
497 .ctl_name = KERN_SG_BIG_BUFF,
498 .procname = "sg-big-buff",
499 .data = &sg_big_buff,
500 .maxlen = sizeof (int),
501 .mode = 0444,
502 .proc_handler = &proc_dointvec,
503 },
504#endif
505#ifdef CONFIG_BSD_PROCESS_ACCT
506 {
507 .ctl_name = KERN_ACCT,
508 .procname = "acct",
509 .data = &acct_parm,
510 .maxlen = 3*sizeof(int),
511 .mode = 0644,
512 .proc_handler = &proc_dointvec,
513 },
514#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515#ifdef CONFIG_MAGIC_SYSRQ
516 {
517 .ctl_name = KERN_SYSRQ,
518 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800519 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .maxlen = sizeof (int),
521 .mode = 0644,
522 .proc_handler = &proc_dointvec,
523 },
524#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700525#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700528 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 .maxlen = sizeof (int),
530 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700531 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700533#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 {
535 .ctl_name = KERN_MAX_THREADS,
536 .procname = "threads-max",
537 .data = &max_threads,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec,
541 },
542 {
543 .ctl_name = KERN_RANDOM,
544 .procname = "random",
545 .mode = 0555,
546 .child = random_table,
547 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 {
549 .ctl_name = KERN_OVERFLOWUID,
550 .procname = "overflowuid",
551 .data = &overflowuid,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 .proc_handler = &proc_dointvec_minmax,
555 .strategy = &sysctl_intvec,
556 .extra1 = &minolduid,
557 .extra2 = &maxolduid,
558 },
559 {
560 .ctl_name = KERN_OVERFLOWGID,
561 .procname = "overflowgid",
562 .data = &overflowgid,
563 .maxlen = sizeof(int),
564 .mode = 0644,
565 .proc_handler = &proc_dointvec_minmax,
566 .strategy = &sysctl_intvec,
567 .extra1 = &minolduid,
568 .extra2 = &maxolduid,
569 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800570#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#ifdef CONFIG_MATHEMU
572 {
573 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
574 .procname = "ieee_emulation_warnings",
575 .data = &sysctl_ieee_emulation_warnings,
576 .maxlen = sizeof(int),
577 .mode = 0644,
578 .proc_handler = &proc_dointvec,
579 },
580#endif
581#ifdef CONFIG_NO_IDLE_HZ
582 {
583 .ctl_name = KERN_HZ_TIMER,
584 .procname = "hz_timer",
585 .data = &sysctl_hz_timer,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 .proc_handler = &proc_dointvec,
589 },
590#endif
591 {
592 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
593 .procname = "userprocess_debug",
594 .data = &sysctl_userprocess_debug,
595 .maxlen = sizeof(int),
596 .mode = 0644,
597 .proc_handler = &proc_dointvec,
598 },
599#endif
600 {
601 .ctl_name = KERN_PIDMAX,
602 .procname = "pid_max",
603 .data = &pid_max,
604 .maxlen = sizeof (int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec_minmax,
607 .strategy = sysctl_intvec,
608 .extra1 = &pid_max_min,
609 .extra2 = &pid_max_max,
610 },
611 {
612 .ctl_name = KERN_PANIC_ON_OOPS,
613 .procname = "panic_on_oops",
614 .data = &panic_on_oops,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = &proc_dointvec,
618 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800619#if defined CONFIG_PRINTK
620 {
621 .ctl_name = KERN_PRINTK,
622 .procname = "printk",
623 .data = &console_loglevel,
624 .maxlen = 4*sizeof(int),
625 .mode = 0644,
626 .proc_handler = &proc_dointvec,
627 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 {
629 .ctl_name = KERN_PRINTK_RATELIMIT,
630 .procname = "printk_ratelimit",
631 .data = &printk_ratelimit_jiffies,
632 .maxlen = sizeof(int),
633 .mode = 0644,
634 .proc_handler = &proc_dointvec_jiffies,
635 .strategy = &sysctl_jiffies,
636 },
637 {
638 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
639 .procname = "printk_ratelimit_burst",
640 .data = &printk_ratelimit_burst,
641 .maxlen = sizeof(int),
642 .mode = 0644,
643 .proc_handler = &proc_dointvec,
644 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800645#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 {
647 .ctl_name = KERN_NGROUPS_MAX,
648 .procname = "ngroups_max",
649 .data = &ngroups_max,
650 .maxlen = sizeof (int),
651 .mode = 0444,
652 .proc_handler = &proc_dointvec,
653 },
654#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
655 {
656 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
657 .procname = "unknown_nmi_panic",
658 .data = &unknown_nmi_panic,
659 .maxlen = sizeof (int),
660 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200661 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 },
Don Zickus407984f2006-09-26 10:52:27 +0200663 {
Don Zickus407984f2006-09-26 10:52:27 +0200664 .procname = "nmi_watchdog",
665 .data = &nmi_watchdog_enabled,
666 .maxlen = sizeof (int),
667 .mode = 0644,
668 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 },
670#endif
671#if defined(CONFIG_X86)
672 {
Don Zickus8da5add2006-09-26 10:52:27 +0200673 .ctl_name = KERN_PANIC_ON_NMI,
674 .procname = "panic_on_unrecovered_nmi",
675 .data = &panic_on_unrecovered_nmi,
676 .maxlen = sizeof(int),
677 .mode = 0644,
678 .proc_handler = &proc_dointvec,
679 },
680 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 .ctl_name = KERN_BOOTLOADER_TYPE,
682 .procname = "bootloader_type",
683 .data = &bootloader_type,
684 .maxlen = sizeof (int),
685 .mode = 0444,
686 .proc_handler = &proc_dointvec,
687 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100688 {
689 .ctl_name = CTL_UNNUMBERED,
690 .procname = "kstack_depth_to_print",
691 .data = &kstack_depth_to_print,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 .proc_handler = &proc_dointvec,
695 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100696 {
697 .ctl_name = CTL_UNNUMBERED,
698 .procname = "io_delay_type",
699 .data = &io_delay_type,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = &proc_dointvec,
703 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800705#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 {
707 .ctl_name = KERN_RANDOMIZE,
708 .procname = "randomize_va_space",
709 .data = &randomize_va_space,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800714#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800715#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700716 {
717 .ctl_name = KERN_SPIN_RETRY,
718 .procname = "spin_retry",
719 .data = &spin_retry,
720 .maxlen = sizeof (int),
721 .mode = 0644,
722 .proc_handler = &proc_dointvec,
723 },
724#endif
Len Brown673d5b42007-07-28 03:33:16 -0400725#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800726 {
Pavel Machekc255d842006-02-20 18:27:58 -0800727 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700728 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800729 .maxlen = sizeof (unsigned long),
730 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800731 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800732 },
733#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800734#ifdef CONFIG_IA64
735 {
736 .ctl_name = KERN_IA64_UNALIGNED,
737 .procname = "ignore-unaligned-usertrap",
738 .data = &no_unaligned_warning,
739 .maxlen = sizeof (int),
740 .mode = 0644,
741 .proc_handler = &proc_dointvec,
742 },
743#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700744#ifdef CONFIG_DETECT_SOFTLOCKUP
745 {
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "softlockup_thresh",
748 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100749 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700750 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100751 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700752 .strategy = &sysctl_intvec,
753 .extra1 = &one,
754 .extra2 = &sixty,
755 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100756 {
757 .ctl_name = CTL_UNNUMBERED,
758 .procname = "hung_task_check_count",
759 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100760 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100761 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100762 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100763 .strategy = &sysctl_intvec,
764 },
765 {
766 .ctl_name = CTL_UNNUMBERED,
767 .procname = "hung_task_timeout_secs",
768 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100769 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100770 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100771 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100772 .strategy = &sysctl_intvec,
773 },
774 {
775 .ctl_name = CTL_UNNUMBERED,
776 .procname = "hung_task_warnings",
777 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100778 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100779 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100780 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100781 .strategy = &sysctl_intvec,
782 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700783#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200784#ifdef CONFIG_COMPAT
785 {
786 .ctl_name = KERN_COMPAT_LOG,
787 .procname = "compat-log",
788 .data = &compat_log,
789 .maxlen = sizeof (int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
792 },
793#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700794#ifdef CONFIG_RT_MUTEXES
795 {
796 .ctl_name = KERN_MAX_LOCK_DEPTH,
797 .procname = "max_lock_depth",
798 .data = &max_lock_depth,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
803#endif
Kees Cook5096add2007-05-08 00:26:04 -0700804#ifdef CONFIG_PROC_FS
805 {
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "maps_protect",
808 .data = &maps_protect,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = &proc_dointvec,
812 },
813#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700814 {
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "poweroff_cmd",
817 .data = &poweroff_cmd,
818 .maxlen = POWEROFF_CMD_PATH_LEN,
819 .mode = 0644,
820 .proc_handler = &proc_dostring,
821 .strategy = &sysctl_string,
822 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700823/*
824 * NOTE: do not add new entries to this table unless you have read
825 * Documentation/sysctl/ctl_unnumbered.txt
826 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 { .ctl_name = 0 }
828};
829
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700830static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 {
832 .ctl_name = VM_OVERCOMMIT_MEMORY,
833 .procname = "overcommit_memory",
834 .data = &sysctl_overcommit_memory,
835 .maxlen = sizeof(sysctl_overcommit_memory),
836 .mode = 0644,
837 .proc_handler = &proc_dointvec,
838 },
839 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700840 .ctl_name = VM_PANIC_ON_OOM,
841 .procname = "panic_on_oom",
842 .data = &sysctl_panic_on_oom,
843 .maxlen = sizeof(sysctl_panic_on_oom),
844 .mode = 0644,
845 .proc_handler = &proc_dointvec,
846 },
847 {
David Rientjesfe071d72007-10-16 23:25:56 -0700848 .ctl_name = CTL_UNNUMBERED,
849 .procname = "oom_kill_allocating_task",
850 .data = &sysctl_oom_kill_allocating_task,
851 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
852 .mode = 0644,
853 .proc_handler = &proc_dointvec,
854 },
855 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800856 .ctl_name = CTL_UNNUMBERED,
857 .procname = "oom_dump_tasks",
858 .data = &sysctl_oom_dump_tasks,
859 .maxlen = sizeof(sysctl_oom_dump_tasks),
860 .mode = 0644,
861 .proc_handler = &proc_dointvec,
862 },
863 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 .ctl_name = VM_OVERCOMMIT_RATIO,
865 .procname = "overcommit_ratio",
866 .data = &sysctl_overcommit_ratio,
867 .maxlen = sizeof(sysctl_overcommit_ratio),
868 .mode = 0644,
869 .proc_handler = &proc_dointvec,
870 },
871 {
872 .ctl_name = VM_PAGE_CLUSTER,
873 .procname = "page-cluster",
874 .data = &page_cluster,
875 .maxlen = sizeof(int),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec,
878 },
879 {
880 .ctl_name = VM_DIRTY_BACKGROUND,
881 .procname = "dirty_background_ratio",
882 .data = &dirty_background_ratio,
883 .maxlen = sizeof(dirty_background_ratio),
884 .mode = 0644,
885 .proc_handler = &proc_dointvec_minmax,
886 .strategy = &sysctl_intvec,
887 .extra1 = &zero,
888 .extra2 = &one_hundred,
889 },
890 {
891 .ctl_name = VM_DIRTY_RATIO,
892 .procname = "dirty_ratio",
893 .data = &vm_dirty_ratio,
894 .maxlen = sizeof(vm_dirty_ratio),
895 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700896 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 .strategy = &sysctl_intvec,
898 .extra1 = &zero,
899 .extra2 = &one_hundred,
900 },
901 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800903 .data = &dirty_writeback_interval,
904 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 .mode = 0644,
906 .proc_handler = &dirty_writeback_centisecs_handler,
907 },
908 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800910 .data = &dirty_expire_interval,
911 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800913 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 },
915 {
916 .ctl_name = VM_NR_PDFLUSH_THREADS,
917 .procname = "nr_pdflush_threads",
918 .data = &nr_pdflush_threads,
919 .maxlen = sizeof nr_pdflush_threads,
920 .mode = 0444 /* read-only*/,
921 .proc_handler = &proc_dointvec,
922 },
923 {
924 .ctl_name = VM_SWAPPINESS,
925 .procname = "swappiness",
926 .data = &vm_swappiness,
927 .maxlen = sizeof(vm_swappiness),
928 .mode = 0644,
929 .proc_handler = &proc_dointvec_minmax,
930 .strategy = &sysctl_intvec,
931 .extra1 = &zero,
932 .extra2 = &one_hundred,
933 },
934#ifdef CONFIG_HUGETLB_PAGE
935 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 .procname = "nr_hugepages",
937 .data = &max_huge_pages,
938 .maxlen = sizeof(unsigned long),
939 .mode = 0644,
940 .proc_handler = &hugetlb_sysctl_handler,
941 .extra1 = (void *)&hugetlb_zero,
942 .extra2 = (void *)&hugetlb_infinity,
943 },
944 {
945 .ctl_name = VM_HUGETLB_GROUP,
946 .procname = "hugetlb_shm_group",
947 .data = &sysctl_hugetlb_shm_group,
948 .maxlen = sizeof(gid_t),
949 .mode = 0644,
950 .proc_handler = &proc_dointvec,
951 },
Mel Gorman396faf02007-07-17 04:03:13 -0700952 {
953 .ctl_name = CTL_UNNUMBERED,
954 .procname = "hugepages_treat_as_movable",
955 .data = &hugepages_treat_as_movable,
956 .maxlen = sizeof(int),
957 .mode = 0644,
958 .proc_handler = &hugetlb_treat_movable_handler,
959 },
Adam Litke54f9f802007-10-16 01:26:20 -0700960 {
961 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800962 .procname = "nr_overcommit_hugepages",
Nishanth Aravamudan064d9ef2008-02-13 15:03:19 -0800963 .data = &sysctl_overcommit_huge_pages,
964 .maxlen = sizeof(sysctl_overcommit_huge_pages),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800965 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800966 .proc_handler = &hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800967 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968#endif
969 {
970 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
971 .procname = "lowmem_reserve_ratio",
972 .data = &sysctl_lowmem_reserve_ratio,
973 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
974 .mode = 0644,
975 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
976 .strategy = &sysctl_intvec,
977 },
978 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800979 .ctl_name = VM_DROP_PAGECACHE,
980 .procname = "drop_caches",
981 .data = &sysctl_drop_caches,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = drop_caches_sysctl_handler,
985 .strategy = &sysctl_intvec,
986 },
987 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 .ctl_name = VM_MIN_FREE_KBYTES,
989 .procname = "min_free_kbytes",
990 .data = &min_free_kbytes,
991 .maxlen = sizeof(min_free_kbytes),
992 .mode = 0644,
993 .proc_handler = &min_free_kbytes_sysctl_handler,
994 .strategy = &sysctl_intvec,
995 .extra1 = &zero,
996 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800997 {
998 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
999 .procname = "percpu_pagelist_fraction",
1000 .data = &percpu_pagelist_fraction,
1001 .maxlen = sizeof(percpu_pagelist_fraction),
1002 .mode = 0644,
1003 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1004 .strategy = &sysctl_intvec,
1005 .extra1 = &min_percpu_pagelist_fract,
1006 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007#ifdef CONFIG_MMU
1008 {
1009 .ctl_name = VM_MAX_MAP_COUNT,
1010 .procname = "max_map_count",
1011 .data = &sysctl_max_map_count,
1012 .maxlen = sizeof(sysctl_max_map_count),
1013 .mode = 0644,
1014 .proc_handler = &proc_dointvec
1015 },
1016#endif
1017 {
1018 .ctl_name = VM_LAPTOP_MODE,
1019 .procname = "laptop_mode",
1020 .data = &laptop_mode,
1021 .maxlen = sizeof(laptop_mode),
1022 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001023 .proc_handler = &proc_dointvec_jiffies,
1024 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 },
1026 {
1027 .ctl_name = VM_BLOCK_DUMP,
1028 .procname = "block_dump",
1029 .data = &block_dump,
1030 .maxlen = sizeof(block_dump),
1031 .mode = 0644,
1032 .proc_handler = &proc_dointvec,
1033 .strategy = &sysctl_intvec,
1034 .extra1 = &zero,
1035 },
1036 {
1037 .ctl_name = VM_VFS_CACHE_PRESSURE,
1038 .procname = "vfs_cache_pressure",
1039 .data = &sysctl_vfs_cache_pressure,
1040 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1041 .mode = 0644,
1042 .proc_handler = &proc_dointvec,
1043 .strategy = &sysctl_intvec,
1044 .extra1 = &zero,
1045 },
1046#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1047 {
1048 .ctl_name = VM_LEGACY_VA_LAYOUT,
1049 .procname = "legacy_va_layout",
1050 .data = &sysctl_legacy_va_layout,
1051 .maxlen = sizeof(sysctl_legacy_va_layout),
1052 .mode = 0644,
1053 .proc_handler = &proc_dointvec,
1054 .strategy = &sysctl_intvec,
1055 .extra1 = &zero,
1056 },
1057#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001058#ifdef CONFIG_NUMA
1059 {
1060 .ctl_name = VM_ZONE_RECLAIM_MODE,
1061 .procname = "zone_reclaim_mode",
1062 .data = &zone_reclaim_mode,
1063 .maxlen = sizeof(zone_reclaim_mode),
1064 .mode = 0644,
1065 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001066 .strategy = &sysctl_intvec,
1067 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001068 },
Christoph Lameter96146342006-07-03 00:24:13 -07001069 {
1070 .ctl_name = VM_MIN_UNMAPPED,
1071 .procname = "min_unmapped_ratio",
1072 .data = &sysctl_min_unmapped_ratio,
1073 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1074 .mode = 0644,
1075 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1076 .strategy = &sysctl_intvec,
1077 .extra1 = &zero,
1078 .extra2 = &one_hundred,
1079 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001080 {
1081 .ctl_name = VM_MIN_SLAB,
1082 .procname = "min_slab_ratio",
1083 .data = &sysctl_min_slab_ratio,
1084 .maxlen = sizeof(sysctl_min_slab_ratio),
1085 .mode = 0644,
1086 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1087 .strategy = &sysctl_intvec,
1088 .extra1 = &zero,
1089 .extra2 = &one_hundred,
1090 },
Christoph Lameter17436602006-01-18 17:42:32 -08001091#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001092#ifdef CONFIG_SMP
1093 {
1094 .ctl_name = CTL_UNNUMBERED,
1095 .procname = "stat_interval",
1096 .data = &sysctl_stat_interval,
1097 .maxlen = sizeof(sysctl_stat_interval),
1098 .mode = 0644,
1099 .proc_handler = &proc_dointvec_jiffies,
1100 .strategy = &sysctl_jiffies,
1101 },
1102#endif
Eric Parised032182007-06-28 15:55:21 -04001103#ifdef CONFIG_SECURITY
1104 {
1105 .ctl_name = CTL_UNNUMBERED,
1106 .procname = "mmap_min_addr",
1107 .data = &mmap_min_addr,
1108 .maxlen = sizeof(unsigned long),
1109 .mode = 0644,
1110 .proc_handler = &proc_doulongvec_minmax,
1111 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001112#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001113#ifdef CONFIG_NUMA
1114 {
1115 .ctl_name = CTL_UNNUMBERED,
1116 .procname = "numa_zonelist_order",
1117 .data = &numa_zonelist_order,
1118 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1119 .mode = 0644,
1120 .proc_handler = &numa_zonelist_order_handler,
1121 .strategy = &sysctl_string,
1122 },
1123#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001124#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001125 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001126 {
1127 .ctl_name = VM_VDSO_ENABLED,
1128 .procname = "vdso_enabled",
1129 .data = &vdso_enabled,
1130 .maxlen = sizeof(vdso_enabled),
1131 .mode = 0644,
1132 .proc_handler = &proc_dointvec,
1133 .strategy = &sysctl_intvec,
1134 .extra1 = &zero,
1135 },
1136#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001137#ifdef CONFIG_HIGHMEM
1138 {
1139 .ctl_name = CTL_UNNUMBERED,
1140 .procname = "highmem_is_dirtyable",
1141 .data = &vm_highmem_is_dirtyable,
1142 .maxlen = sizeof(vm_highmem_is_dirtyable),
1143 .mode = 0644,
1144 .proc_handler = &proc_dointvec_minmax,
1145 .strategy = &sysctl_intvec,
1146 .extra1 = &zero,
1147 .extra2 = &one,
1148 },
1149#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001150/*
1151 * NOTE: do not add new entries to this table unless you have read
1152 * Documentation/sysctl/ctl_unnumbered.txt
1153 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 { .ctl_name = 0 }
1155};
1156
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001157#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001158static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001159 { .ctl_name = 0 }
1160};
1161#endif
1162
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001163static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 {
1165 .ctl_name = FS_NRINODE,
1166 .procname = "inode-nr",
1167 .data = &inodes_stat,
1168 .maxlen = 2*sizeof(int),
1169 .mode = 0444,
1170 .proc_handler = &proc_dointvec,
1171 },
1172 {
1173 .ctl_name = FS_STATINODE,
1174 .procname = "inode-state",
1175 .data = &inodes_stat,
1176 .maxlen = 7*sizeof(int),
1177 .mode = 0444,
1178 .proc_handler = &proc_dointvec,
1179 },
1180 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 .procname = "file-nr",
1182 .data = &files_stat,
1183 .maxlen = 3*sizeof(int),
1184 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001185 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 },
1187 {
1188 .ctl_name = FS_MAXFILE,
1189 .procname = "file-max",
1190 .data = &files_stat.max_files,
1191 .maxlen = sizeof(int),
1192 .mode = 0644,
1193 .proc_handler = &proc_dointvec,
1194 },
1195 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001196 .ctl_name = CTL_UNNUMBERED,
1197 .procname = "nr_open",
1198 .data = &sysctl_nr_open,
1199 .maxlen = sizeof(int),
1200 .mode = 0644,
1201 .proc_handler = &proc_dointvec,
1202 },
1203 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 .ctl_name = FS_DENTRY,
1205 .procname = "dentry-state",
1206 .data = &dentry_stat,
1207 .maxlen = 6*sizeof(int),
1208 .mode = 0444,
1209 .proc_handler = &proc_dointvec,
1210 },
1211 {
1212 .ctl_name = FS_OVERFLOWUID,
1213 .procname = "overflowuid",
1214 .data = &fs_overflowuid,
1215 .maxlen = sizeof(int),
1216 .mode = 0644,
1217 .proc_handler = &proc_dointvec_minmax,
1218 .strategy = &sysctl_intvec,
1219 .extra1 = &minolduid,
1220 .extra2 = &maxolduid,
1221 },
1222 {
1223 .ctl_name = FS_OVERFLOWGID,
1224 .procname = "overflowgid",
1225 .data = &fs_overflowgid,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = &proc_dointvec_minmax,
1229 .strategy = &sysctl_intvec,
1230 .extra1 = &minolduid,
1231 .extra2 = &maxolduid,
1232 },
1233 {
1234 .ctl_name = FS_LEASES,
1235 .procname = "leases-enable",
1236 .data = &leases_enable,
1237 .maxlen = sizeof(int),
1238 .mode = 0644,
1239 .proc_handler = &proc_dointvec,
1240 },
1241#ifdef CONFIG_DNOTIFY
1242 {
1243 .ctl_name = FS_DIR_NOTIFY,
1244 .procname = "dir-notify-enable",
1245 .data = &dir_notify_enable,
1246 .maxlen = sizeof(int),
1247 .mode = 0644,
1248 .proc_handler = &proc_dointvec,
1249 },
1250#endif
1251#ifdef CONFIG_MMU
1252 {
1253 .ctl_name = FS_LEASE_TIME,
1254 .procname = "lease-break-time",
1255 .data = &lease_break_time,
1256 .maxlen = sizeof(int),
1257 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001258 .proc_handler = &proc_dointvec_minmax,
1259 .strategy = &sysctl_intvec,
1260 .extra1 = &zero,
1261 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 },
1263 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 .procname = "aio-nr",
1265 .data = &aio_nr,
1266 .maxlen = sizeof(aio_nr),
1267 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001268 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 },
1270 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 .procname = "aio-max-nr",
1272 .data = &aio_max_nr,
1273 .maxlen = sizeof(aio_max_nr),
1274 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001275 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001277#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001278 {
1279 .ctl_name = FS_INOTIFY,
1280 .procname = "inotify",
1281 .mode = 0555,
1282 .child = inotify_table,
1283 },
1284#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001286 {
1287 .ctl_name = KERN_SETUID_DUMPABLE,
1288 .procname = "suid_dumpable",
1289 .data = &suid_dumpable,
1290 .maxlen = sizeof(int),
1291 .mode = 0644,
1292 .proc_handler = &proc_dointvec,
1293 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001294#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1295 {
1296 .ctl_name = CTL_UNNUMBERED,
1297 .procname = "binfmt_misc",
1298 .mode = 0555,
1299 .child = binfmt_misc_table,
1300 },
1301#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001302/*
1303 * NOTE: do not add new entries to this table unless you have read
1304 * Documentation/sysctl/ctl_unnumbered.txt
1305 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 { .ctl_name = 0 }
1307};
1308
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001309static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001310#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001311 {
1312 .ctl_name = CTL_UNNUMBERED,
1313 .procname = "exception-trace",
1314 .data = &show_unhandled_signals,
1315 .maxlen = sizeof(int),
1316 .mode = 0644,
1317 .proc_handler = proc_dointvec
1318 },
1319#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 { .ctl_name = 0 }
1321};
1322
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001323static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001325};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Al Viro330d57f2005-11-04 10:18:40 +00001327static DEFINE_SPINLOCK(sysctl_lock);
1328
1329/* called under sysctl_lock */
1330static int use_table(struct ctl_table_header *p)
1331{
1332 if (unlikely(p->unregistering))
1333 return 0;
1334 p->used++;
1335 return 1;
1336}
1337
1338/* called under sysctl_lock */
1339static void unuse_table(struct ctl_table_header *p)
1340{
1341 if (!--p->used)
1342 if (unlikely(p->unregistering))
1343 complete(p->unregistering);
1344}
1345
1346/* called under sysctl_lock, will reacquire if has to wait */
1347static void start_unregistering(struct ctl_table_header *p)
1348{
1349 /*
1350 * if p->used is 0, nobody will ever touch that entry again;
1351 * we'll eliminate all paths to it before dropping sysctl_lock
1352 */
1353 if (unlikely(p->used)) {
1354 struct completion wait;
1355 init_completion(&wait);
1356 p->unregistering = &wait;
1357 spin_unlock(&sysctl_lock);
1358 wait_for_completion(&wait);
1359 spin_lock(&sysctl_lock);
1360 }
1361 /*
1362 * do not remove from the list until nobody holds it; walking the
1363 * list in do_sysctl() relies on that.
1364 */
1365 list_del_init(&p->ctl_entry);
1366}
1367
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001368void sysctl_head_finish(struct ctl_table_header *head)
1369{
1370 if (!head)
1371 return;
1372 spin_lock(&sysctl_lock);
1373 unuse_table(head);
1374 spin_unlock(&sysctl_lock);
1375}
1376
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001377static struct list_head *
1378lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001379{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001380 struct list_head *header_list;
1381 header_list = &root->header_list;
1382 if (root->lookup)
1383 header_list = root->lookup(root, namespaces);
1384 return header_list;
1385}
1386
1387struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1388 struct ctl_table_header *prev)
1389{
1390 struct ctl_table_root *root;
1391 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001392 struct ctl_table_header *head;
1393 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001394
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001395 spin_lock(&sysctl_lock);
1396 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001397 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001398 tmp = &prev->ctl_entry;
1399 unuse_table(prev);
1400 goto next;
1401 }
1402 tmp = &root_table_header.ctl_entry;
1403 for (;;) {
1404 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1405
1406 if (!use_table(head))
1407 goto next;
1408 spin_unlock(&sysctl_lock);
1409 return head;
1410 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001411 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001412 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001413 header_list = lookup_header_list(root, namespaces);
1414 if (tmp != header_list)
1415 continue;
1416
1417 do {
1418 root = list_entry(root->root_list.next,
1419 struct ctl_table_root, root_list);
1420 if (root == &sysctl_table_root)
1421 goto out;
1422 header_list = lookup_header_list(root, namespaces);
1423 } while (list_empty(header_list));
1424 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001425 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001426out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001427 spin_unlock(&sysctl_lock);
1428 return NULL;
1429}
1430
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001431struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1432{
1433 return __sysctl_head_next(current->nsproxy, prev);
1434}
1435
1436void register_sysctl_root(struct ctl_table_root *root)
1437{
1438 spin_lock(&sysctl_lock);
1439 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1440 spin_unlock(&sysctl_lock);
1441}
1442
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001443#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1445 void __user *newval, size_t newlen)
1446{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001447 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001448 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1451 return -ENOTDIR;
1452 if (oldval) {
1453 int old_len;
1454 if (!oldlenp || get_user(old_len, oldlenp))
1455 return -EFAULT;
1456 }
Al Viro330d57f2005-11-04 10:18:40 +00001457
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001458 for (head = sysctl_head_next(NULL); head;
1459 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001460 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001461 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001462 if (error != -ENOTDIR) {
1463 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001464 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001465 }
1466 }
Al Viro330d57f2005-11-04 10:18:40 +00001467 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468}
1469
1470asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1471{
1472 struct __sysctl_args tmp;
1473 int error;
1474
1475 if (copy_from_user(&tmp, args, sizeof(tmp)))
1476 return -EFAULT;
1477
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001478 error = deprecated_sysctl_warning(&tmp);
1479 if (error)
1480 goto out;
1481
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 lock_kernel();
1483 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1484 tmp.newval, tmp.newlen);
1485 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001486out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 return error;
1488}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001489#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
1491/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001492 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 * some sysctl variables are readonly even to root.
1494 */
1495
1496static int test_perm(int mode, int op)
1497{
1498 if (!current->euid)
1499 mode >>= 6;
1500 else if (in_egroup_p(0))
1501 mode >>= 3;
1502 if ((mode & op & 0007) == op)
1503 return 0;
1504 return -EACCES;
1505}
1506
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001507int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
1509 int error;
1510 error = security_sysctl(table, op);
1511 if (error)
1512 return error;
1513 return test_perm(table->mode, op);
1514}
1515
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001516#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517static int parse_table(int __user *name, int nlen,
1518 void __user *oldval, size_t __user *oldlenp,
1519 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001520 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
1522 int n;
1523repeat:
1524 if (!nlen)
1525 return -ENOTDIR;
1526 if (get_user(n, name))
1527 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001528 for ( ; table->ctl_name || table->procname; table++) {
1529 if (!table->ctl_name)
1530 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001531 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 int error;
1533 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001534 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 name++;
1537 nlen--;
1538 table = table->child;
1539 goto repeat;
1540 }
1541 error = do_sysctl_strategy(table, name, nlen,
1542 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001543 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 return error;
1545 }
1546 }
1547 return -ENOTDIR;
1548}
1549
1550/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001551int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 int __user *name, int nlen,
1553 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001554 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
1556 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 if (oldval)
1559 op |= 004;
1560 if (newval)
1561 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001562 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 return -EPERM;
1564
1565 if (table->strategy) {
1566 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001567 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 if (rc < 0)
1569 return rc;
1570 if (rc > 0)
1571 return 0;
1572 }
1573
1574 /* If there is no strategy routine, or if the strategy returns
1575 * zero, proceed with automatic r/w */
1576 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001577 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1578 newval, newlen);
1579 if (rc < 0)
1580 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
1582 return 0;
1583}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001584#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001586static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1587{
1588 for (; table->ctl_name || table->procname; table++) {
1589 table->parent = parent;
1590 if (table->child)
1591 sysctl_set_parent(table, table->child);
1592 }
1593}
1594
1595static __init int sysctl_init(void)
1596{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001597 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001598 sysctl_set_parent(NULL, root_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001599 err = sysctl_check_table(current->nsproxy, root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001600 return 0;
1601}
1602
1603core_initcall(sysctl_init);
1604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001606 * __register_sysctl_paths - register a sysctl hierarchy
1607 * @root: List of sysctl headers to register on
1608 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001609 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 *
1612 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001613 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001615 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 *
1617 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1618 * must be unique within that level of sysctl
1619 *
1620 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1621 * enter a sysctl file
1622 *
1623 * data - a pointer to data for use by proc_handler
1624 *
1625 * maxlen - the maximum size in bytes of the data
1626 *
1627 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1628 *
1629 * child - a pointer to the child sysctl table if this entry is a directory, or
1630 * %NULL.
1631 *
1632 * proc_handler - the text handler routine (described below)
1633 *
1634 * strategy - the strategy routine (described below)
1635 *
1636 * de - for internal use by the sysctl routines
1637 *
1638 * extra1, extra2 - extra pointers usable by the proc handler routines
1639 *
1640 * Leaf nodes in the sysctl tree will be represented by a single file
1641 * under /proc; non-leaf nodes will be represented by directories.
1642 *
1643 * sysctl(2) can automatically manage read and write requests through
1644 * the sysctl table. The data and maxlen fields of the ctl_table
1645 * struct enable minimal validation of the values being written to be
1646 * performed, and the mode field allows minimal authentication.
1647 *
1648 * More sophisticated management can be enabled by the provision of a
1649 * strategy routine with the table entry. This will be called before
1650 * any automatic read or write of the data is performed.
1651 *
1652 * The strategy routine may return
1653 *
1654 * < 0 - Error occurred (error is passed to user process)
1655 *
1656 * 0 - OK - proceed with automatic read or write.
1657 *
1658 * > 0 - OK - read or write has been done by the strategy routine, so
1659 * return immediately.
1660 *
1661 * There must be a proc_handler routine for any terminal nodes
1662 * mirrored under /proc/sys (non-terminals are handled by a built-in
1663 * directory handler). Several default handlers are available to
1664 * cover common cases -
1665 *
1666 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1667 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1668 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1669 *
1670 * It is the handler's job to read the input buffer from user memory
1671 * and process it. The handler should return 0 on success.
1672 *
1673 * This routine returns %NULL on a failure to register, and a pointer
1674 * to the table header on success.
1675 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001676struct ctl_table_header *__register_sysctl_paths(
1677 struct ctl_table_root *root,
1678 struct nsproxy *namespaces,
1679 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001681 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001682 struct ctl_table_header *header;
1683 struct ctl_table *new, **prevp;
1684 unsigned int n, npath;
1685
1686 /* Count the path components */
1687 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1688 ;
1689
1690 /*
1691 * For each path component, allocate a 2-element ctl_table array.
1692 * The first array element will be filled with the sysctl entry
1693 * for this, the second will be the sentinel (ctl_name == 0).
1694 *
1695 * We allocate everything in one go so that we don't have to
1696 * worry about freeing additional memory in unregister_sysctl_table.
1697 */
1698 header = kzalloc(sizeof(struct ctl_table_header) +
1699 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1700 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001702
1703 new = (struct ctl_table *) (header + 1);
1704
1705 /* Now connect the dots */
1706 prevp = &header->ctl_table;
1707 for (n = 0; n < npath; ++n, ++path) {
1708 /* Copy the procname */
1709 new->procname = path->procname;
1710 new->ctl_name = path->ctl_name;
1711 new->mode = 0555;
1712
1713 *prevp = new;
1714 prevp = &new->child;
1715
1716 new += 2;
1717 }
1718 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001719 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001720
1721 INIT_LIST_HEAD(&header->ctl_entry);
1722 header->used = 0;
1723 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001724 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001725 sysctl_set_parent(NULL, header->ctl_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001726 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001727 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001728 return NULL;
1729 }
Al Viro330d57f2005-11-04 10:18:40 +00001730 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001731 header_list = lookup_header_list(root, namespaces);
1732 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001733 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001734
1735 return header;
1736}
1737
1738/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001739 * register_sysctl_table_path - register a sysctl table hierarchy
1740 * @path: The path to the directory the sysctl table is in.
1741 * @table: the top-level table structure
1742 *
1743 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1744 * array. A completely 0 filled entry terminates the table.
1745 *
1746 * See __register_sysctl_paths for more details.
1747 */
1748struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1749 struct ctl_table *table)
1750{
1751 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1752 path, table);
1753}
1754
1755/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001756 * register_sysctl_table - register a sysctl table hierarchy
1757 * @table: the top-level table structure
1758 *
1759 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1760 * array. A completely 0 filled entry terminates the table.
1761 *
1762 * See register_sysctl_paths for more details.
1763 */
1764struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1765{
1766 static const struct ctl_path null_path[] = { {} };
1767
1768 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769}
1770
1771/**
1772 * unregister_sysctl_table - unregister a sysctl table hierarchy
1773 * @header: the header returned from register_sysctl_table
1774 *
1775 * Unregisters the sysctl table and all children. proc entries may not
1776 * actually be removed until they are no longer used by anyone.
1777 */
1778void unregister_sysctl_table(struct ctl_table_header * header)
1779{
Al Viro330d57f2005-11-04 10:18:40 +00001780 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001781
1782 if (header == NULL)
1783 return;
1784
Al Viro330d57f2005-11-04 10:18:40 +00001785 spin_lock(&sysctl_lock);
1786 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001787 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 kfree(header);
1789}
1790
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001791#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001792struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001793{
1794 return NULL;
1795}
1796
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001797struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1798 struct ctl_table *table)
1799{
1800 return NULL;
1801}
1802
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001803void unregister_sysctl_table(struct ctl_table_header * table)
1804{
1805}
1806
1807#endif /* CONFIG_SYSCTL */
1808
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809/*
1810 * /proc/sys support
1811 */
1812
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001813#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001815static int _proc_do_string(void* data, int maxlen, int write,
1816 struct file *filp, void __user *buffer,
1817 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001818{
1819 size_t len;
1820 char __user *p;
1821 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001822
1823 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001824 *lenp = 0;
1825 return 0;
1826 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001827
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001828 if (write) {
1829 len = 0;
1830 p = buffer;
1831 while (len < *lenp) {
1832 if (get_user(c, p++))
1833 return -EFAULT;
1834 if (c == 0 || c == '\n')
1835 break;
1836 len++;
1837 }
1838 if (len >= maxlen)
1839 len = maxlen-1;
1840 if(copy_from_user(data, buffer, len))
1841 return -EFAULT;
1842 ((char *) data)[len] = 0;
1843 *ppos += *lenp;
1844 } else {
1845 len = strlen(data);
1846 if (len > maxlen)
1847 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001848
1849 if (*ppos > len) {
1850 *lenp = 0;
1851 return 0;
1852 }
1853
1854 data += *ppos;
1855 len -= *ppos;
1856
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001857 if (len > *lenp)
1858 len = *lenp;
1859 if (len)
1860 if(copy_to_user(buffer, data, len))
1861 return -EFAULT;
1862 if (len < *lenp) {
1863 if(put_user('\n', ((char __user *) buffer) + len))
1864 return -EFAULT;
1865 len++;
1866 }
1867 *lenp = len;
1868 *ppos += len;
1869 }
1870 return 0;
1871}
1872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873/**
1874 * proc_dostring - read a string sysctl
1875 * @table: the sysctl table
1876 * @write: %TRUE if this is a write to the sysctl file
1877 * @filp: the file structure
1878 * @buffer: the user buffer
1879 * @lenp: the size of the user buffer
1880 * @ppos: file position
1881 *
1882 * Reads/writes a string from/to the user buffer. If the kernel
1883 * buffer provided is not large enough to hold the string, the
1884 * string is truncated. The copied string is %NULL-terminated.
1885 * If the string is being read by the user process, it is copied
1886 * and a newline '\n' is added. It is truncated if the buffer is
1887 * not large enough.
1888 *
1889 * Returns 0 on success.
1890 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001891int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 void __user *buffer, size_t *lenp, loff_t *ppos)
1893{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001894 return _proc_do_string(table->data, table->maxlen, write, filp,
1895 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896}
1897
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1900 int *valp,
1901 int write, void *data)
1902{
1903 if (write) {
1904 *valp = *negp ? -*lvalp : *lvalp;
1905 } else {
1906 int val = *valp;
1907 if (val < 0) {
1908 *negp = -1;
1909 *lvalp = (unsigned long)-val;
1910 } else {
1911 *negp = 0;
1912 *lvalp = (unsigned long)val;
1913 }
1914 }
1915 return 0;
1916}
1917
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001918static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001919 int write, struct file *filp, void __user *buffer,
1920 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1922 int write, void *data),
1923 void *data)
1924{
1925#define TMPBUFLEN 21
1926 int *i, vleft, first=1, neg, val;
1927 unsigned long lval;
1928 size_t left, len;
1929
1930 char buf[TMPBUFLEN], *p;
1931 char __user *s = buffer;
1932
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001933 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 (*ppos && !write)) {
1935 *lenp = 0;
1936 return 0;
1937 }
1938
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001939 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 vleft = table->maxlen / sizeof(*i);
1941 left = *lenp;
1942
1943 if (!conv)
1944 conv = do_proc_dointvec_conv;
1945
1946 for (; left && vleft--; i++, first=0) {
1947 if (write) {
1948 while (left) {
1949 char c;
1950 if (get_user(c, s))
1951 return -EFAULT;
1952 if (!isspace(c))
1953 break;
1954 left--;
1955 s++;
1956 }
1957 if (!left)
1958 break;
1959 neg = 0;
1960 len = left;
1961 if (len > sizeof(buf) - 1)
1962 len = sizeof(buf) - 1;
1963 if (copy_from_user(buf, s, len))
1964 return -EFAULT;
1965 buf[len] = 0;
1966 p = buf;
1967 if (*p == '-' && left > 1) {
1968 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001969 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 }
1971 if (*p < '0' || *p > '9')
1972 break;
1973
1974 lval = simple_strtoul(p, &p, 0);
1975
1976 len = p-buf;
1977 if ((len < left) && *p && !isspace(*p))
1978 break;
1979 if (neg)
1980 val = -val;
1981 s += len;
1982 left -= len;
1983
1984 if (conv(&neg, &lval, i, 1, data))
1985 break;
1986 } else {
1987 p = buf;
1988 if (!first)
1989 *p++ = '\t';
1990
1991 if (conv(&neg, &lval, i, 0, data))
1992 break;
1993
1994 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1995 len = strlen(buf);
1996 if (len > left)
1997 len = left;
1998 if(copy_to_user(s, buf, len))
1999 return -EFAULT;
2000 left -= len;
2001 s += len;
2002 }
2003 }
2004
2005 if (!write && !first && left) {
2006 if(put_user('\n', s))
2007 return -EFAULT;
2008 left--, s++;
2009 }
2010 if (write) {
2011 while (left) {
2012 char c;
2013 if (get_user(c, s++))
2014 return -EFAULT;
2015 if (!isspace(c))
2016 break;
2017 left--;
2018 }
2019 }
2020 if (write && first)
2021 return -EINVAL;
2022 *lenp -= left;
2023 *ppos += *lenp;
2024 return 0;
2025#undef TMPBUFLEN
2026}
2027
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002028static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002029 void __user *buffer, size_t *lenp, loff_t *ppos,
2030 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2031 int write, void *data),
2032 void *data)
2033{
2034 return __do_proc_dointvec(table->data, table, write, filp,
2035 buffer, lenp, ppos, conv, data);
2036}
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038/**
2039 * proc_dointvec - read a vector of integers
2040 * @table: the sysctl table
2041 * @write: %TRUE if this is a write to the sysctl file
2042 * @filp: the file structure
2043 * @buffer: the user buffer
2044 * @lenp: the size of the user buffer
2045 * @ppos: file position
2046 *
2047 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2048 * values from/to the user buffer, treated as an ASCII string.
2049 *
2050 * Returns 0 on success.
2051 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002052int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 void __user *buffer, size_t *lenp, loff_t *ppos)
2054{
2055 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2056 NULL,NULL);
2057}
2058
2059#define OP_SET 0
2060#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002061#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
2063static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2064 int *valp,
2065 int write, void *data)
2066{
2067 int op = *(int *)data;
2068 if (write) {
2069 int val = *negp ? -*lvalp : *lvalp;
2070 switch(op) {
2071 case OP_SET: *valp = val; break;
2072 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002073 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 }
2075 } else {
2076 int val = *valp;
2077 if (val < 0) {
2078 *negp = -1;
2079 *lvalp = (unsigned long)-val;
2080 } else {
2081 *negp = 0;
2082 *lvalp = (unsigned long)val;
2083 }
2084 }
2085 return 0;
2086}
2087
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002088/*
2089 * Taint values can only be increased
2090 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002091static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002092 void __user *buffer, size_t *lenp, loff_t *ppos)
2093{
2094 int op;
2095
Bastian Blank91fcd412007-04-23 14:41:14 -07002096 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002097 return -EPERM;
2098
2099 op = OP_OR;
2100 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2101 do_proc_dointvec_bset_conv,&op);
2102}
2103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104struct do_proc_dointvec_minmax_conv_param {
2105 int *min;
2106 int *max;
2107};
2108
2109static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2110 int *valp,
2111 int write, void *data)
2112{
2113 struct do_proc_dointvec_minmax_conv_param *param = data;
2114 if (write) {
2115 int val = *negp ? -*lvalp : *lvalp;
2116 if ((param->min && *param->min > val) ||
2117 (param->max && *param->max < val))
2118 return -EINVAL;
2119 *valp = val;
2120 } else {
2121 int val = *valp;
2122 if (val < 0) {
2123 *negp = -1;
2124 *lvalp = (unsigned long)-val;
2125 } else {
2126 *negp = 0;
2127 *lvalp = (unsigned long)val;
2128 }
2129 }
2130 return 0;
2131}
2132
2133/**
2134 * proc_dointvec_minmax - read a vector of integers with min/max values
2135 * @table: the sysctl table
2136 * @write: %TRUE if this is a write to the sysctl file
2137 * @filp: the file structure
2138 * @buffer: the user buffer
2139 * @lenp: the size of the user buffer
2140 * @ppos: file position
2141 *
2142 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2143 * values from/to the user buffer, treated as an ASCII string.
2144 *
2145 * This routine will ensure the values are within the range specified by
2146 * table->extra1 (min) and table->extra2 (max).
2147 *
2148 * Returns 0 on success.
2149 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002150int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 void __user *buffer, size_t *lenp, loff_t *ppos)
2152{
2153 struct do_proc_dointvec_minmax_conv_param param = {
2154 .min = (int *) table->extra1,
2155 .max = (int *) table->extra2,
2156 };
2157 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2158 do_proc_dointvec_minmax_conv, &param);
2159}
2160
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002161static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 struct file *filp,
2163 void __user *buffer,
2164 size_t *lenp, loff_t *ppos,
2165 unsigned long convmul,
2166 unsigned long convdiv)
2167{
2168#define TMPBUFLEN 21
2169 unsigned long *i, *min, *max, val;
2170 int vleft, first=1, neg;
2171 size_t len, left;
2172 char buf[TMPBUFLEN], *p;
2173 char __user *s = buffer;
2174
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002175 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 (*ppos && !write)) {
2177 *lenp = 0;
2178 return 0;
2179 }
2180
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002181 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 min = (unsigned long *) table->extra1;
2183 max = (unsigned long *) table->extra2;
2184 vleft = table->maxlen / sizeof(unsigned long);
2185 left = *lenp;
2186
2187 for (; left && vleft--; i++, min++, max++, first=0) {
2188 if (write) {
2189 while (left) {
2190 char c;
2191 if (get_user(c, s))
2192 return -EFAULT;
2193 if (!isspace(c))
2194 break;
2195 left--;
2196 s++;
2197 }
2198 if (!left)
2199 break;
2200 neg = 0;
2201 len = left;
2202 if (len > TMPBUFLEN-1)
2203 len = TMPBUFLEN-1;
2204 if (copy_from_user(buf, s, len))
2205 return -EFAULT;
2206 buf[len] = 0;
2207 p = buf;
2208 if (*p == '-' && left > 1) {
2209 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002210 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 }
2212 if (*p < '0' || *p > '9')
2213 break;
2214 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2215 len = p-buf;
2216 if ((len < left) && *p && !isspace(*p))
2217 break;
2218 if (neg)
2219 val = -val;
2220 s += len;
2221 left -= len;
2222
2223 if(neg)
2224 continue;
2225 if ((min && val < *min) || (max && val > *max))
2226 continue;
2227 *i = val;
2228 } else {
2229 p = buf;
2230 if (!first)
2231 *p++ = '\t';
2232 sprintf(p, "%lu", convdiv * (*i) / convmul);
2233 len = strlen(buf);
2234 if (len > left)
2235 len = left;
2236 if(copy_to_user(s, buf, len))
2237 return -EFAULT;
2238 left -= len;
2239 s += len;
2240 }
2241 }
2242
2243 if (!write && !first && left) {
2244 if(put_user('\n', s))
2245 return -EFAULT;
2246 left--, s++;
2247 }
2248 if (write) {
2249 while (left) {
2250 char c;
2251 if (get_user(c, s++))
2252 return -EFAULT;
2253 if (!isspace(c))
2254 break;
2255 left--;
2256 }
2257 }
2258 if (write && first)
2259 return -EINVAL;
2260 *lenp -= left;
2261 *ppos += *lenp;
2262 return 0;
2263#undef TMPBUFLEN
2264}
2265
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002266static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002267 struct file *filp,
2268 void __user *buffer,
2269 size_t *lenp, loff_t *ppos,
2270 unsigned long convmul,
2271 unsigned long convdiv)
2272{
2273 return __do_proc_doulongvec_minmax(table->data, table, write,
2274 filp, buffer, lenp, ppos, convmul, convdiv);
2275}
2276
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277/**
2278 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
2281 * @filp: the file structure
2282 * @buffer: the user buffer
2283 * @lenp: the size of the user buffer
2284 * @ppos: file position
2285 *
2286 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2287 * values from/to the user buffer, treated as an ASCII string.
2288 *
2289 * This routine will ensure the values are within the range specified by
2290 * table->extra1 (min) and table->extra2 (max).
2291 *
2292 * Returns 0 on success.
2293 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002294int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 void __user *buffer, size_t *lenp, loff_t *ppos)
2296{
2297 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2298}
2299
2300/**
2301 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2302 * @table: the sysctl table
2303 * @write: %TRUE if this is a write to the sysctl file
2304 * @filp: the file structure
2305 * @buffer: the user buffer
2306 * @lenp: the size of the user buffer
2307 * @ppos: file position
2308 *
2309 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2310 * values from/to the user buffer, treated as an ASCII string. The values
2311 * are treated as milliseconds, and converted to jiffies when they are stored.
2312 *
2313 * This routine will ensure the values are within the range specified by
2314 * table->extra1 (min) and table->extra2 (max).
2315 *
2316 * Returns 0 on success.
2317 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002318int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 struct file *filp,
2320 void __user *buffer,
2321 size_t *lenp, loff_t *ppos)
2322{
2323 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2324 lenp, ppos, HZ, 1000l);
2325}
2326
2327
2328static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2329 int *valp,
2330 int write, void *data)
2331{
2332 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002333 if (*lvalp > LONG_MAX / HZ)
2334 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2336 } else {
2337 int val = *valp;
2338 unsigned long lval;
2339 if (val < 0) {
2340 *negp = -1;
2341 lval = (unsigned long)-val;
2342 } else {
2343 *negp = 0;
2344 lval = (unsigned long)val;
2345 }
2346 *lvalp = lval / HZ;
2347 }
2348 return 0;
2349}
2350
2351static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2352 int *valp,
2353 int write, void *data)
2354{
2355 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002356 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2357 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2359 } else {
2360 int val = *valp;
2361 unsigned long lval;
2362 if (val < 0) {
2363 *negp = -1;
2364 lval = (unsigned long)-val;
2365 } else {
2366 *negp = 0;
2367 lval = (unsigned long)val;
2368 }
2369 *lvalp = jiffies_to_clock_t(lval);
2370 }
2371 return 0;
2372}
2373
2374static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2375 int *valp,
2376 int write, void *data)
2377{
2378 if (write) {
2379 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2380 } else {
2381 int val = *valp;
2382 unsigned long lval;
2383 if (val < 0) {
2384 *negp = -1;
2385 lval = (unsigned long)-val;
2386 } else {
2387 *negp = 0;
2388 lval = (unsigned long)val;
2389 }
2390 *lvalp = jiffies_to_msecs(lval);
2391 }
2392 return 0;
2393}
2394
2395/**
2396 * proc_dointvec_jiffies - read a vector of integers as seconds
2397 * @table: the sysctl table
2398 * @write: %TRUE if this is a write to the sysctl file
2399 * @filp: the file structure
2400 * @buffer: the user buffer
2401 * @lenp: the size of the user buffer
2402 * @ppos: file position
2403 *
2404 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2405 * values from/to the user buffer, treated as an ASCII string.
2406 * The values read are assumed to be in seconds, and are converted into
2407 * jiffies.
2408 *
2409 * Returns 0 on success.
2410 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002411int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 void __user *buffer, size_t *lenp, loff_t *ppos)
2413{
2414 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2415 do_proc_dointvec_jiffies_conv,NULL);
2416}
2417
2418/**
2419 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2420 * @table: the sysctl table
2421 * @write: %TRUE if this is a write to the sysctl file
2422 * @filp: the file structure
2423 * @buffer: the user buffer
2424 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002425 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 *
2427 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2428 * values from/to the user buffer, treated as an ASCII string.
2429 * The values read are assumed to be in 1/USER_HZ seconds, and
2430 * are converted into jiffies.
2431 *
2432 * Returns 0 on success.
2433 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002434int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 void __user *buffer, size_t *lenp, loff_t *ppos)
2436{
2437 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2438 do_proc_dointvec_userhz_jiffies_conv,NULL);
2439}
2440
2441/**
2442 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2443 * @table: the sysctl table
2444 * @write: %TRUE if this is a write to the sysctl file
2445 * @filp: the file structure
2446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002448 * @ppos: file position
2449 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 *
2451 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2452 * values from/to the user buffer, treated as an ASCII string.
2453 * The values read are assumed to be in 1/1000 seconds, and
2454 * are converted into jiffies.
2455 *
2456 * Returns 0 on success.
2457 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002458int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 void __user *buffer, size_t *lenp, loff_t *ppos)
2460{
2461 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2462 do_proc_dointvec_ms_jiffies_conv, NULL);
2463}
2464
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002465static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002466 void __user *buffer, size_t *lenp, loff_t *ppos)
2467{
2468 struct pid *new_pid;
2469 pid_t tmp;
2470 int r;
2471
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002472 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002473
2474 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2475 lenp, ppos, NULL, NULL);
2476 if (r || !write)
2477 return r;
2478
2479 new_pid = find_get_pid(tmp);
2480 if (!new_pid)
2481 return -ESRCH;
2482
2483 put_pid(xchg(&cad_pid, new_pid));
2484 return 0;
2485}
2486
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487#else /* CONFIG_PROC_FS */
2488
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002489int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 void __user *buffer, size_t *lenp, loff_t *ppos)
2491{
2492 return -ENOSYS;
2493}
2494
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002495int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 void __user *buffer, size_t *lenp, loff_t *ppos)
2497{
2498 return -ENOSYS;
2499}
2500
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002501int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 void __user *buffer, size_t *lenp, loff_t *ppos)
2503{
2504 return -ENOSYS;
2505}
2506
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002507int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 void __user *buffer, size_t *lenp, loff_t *ppos)
2509{
2510 return -ENOSYS;
2511}
2512
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002513int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 void __user *buffer, size_t *lenp, loff_t *ppos)
2515{
2516 return -ENOSYS;
2517}
2518
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002519int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 void __user *buffer, size_t *lenp, loff_t *ppos)
2521{
2522 return -ENOSYS;
2523}
2524
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002525int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 void __user *buffer, size_t *lenp, loff_t *ppos)
2527{
2528 return -ENOSYS;
2529}
2530
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002531int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 struct file *filp,
2533 void __user *buffer,
2534 size_t *lenp, loff_t *ppos)
2535{
2536 return -ENOSYS;
2537}
2538
2539
2540#endif /* CONFIG_PROC_FS */
2541
2542
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002543#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544/*
2545 * General sysctl support routines
2546 */
2547
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002548/* The generic sysctl data routine (used if no strategy routine supplied) */
2549int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2550 void __user *oldval, size_t __user *oldlenp,
2551 void __user *newval, size_t newlen)
2552{
2553 size_t len;
2554
2555 /* Get out of I don't have a variable */
2556 if (!table->data || !table->maxlen)
2557 return -ENOTDIR;
2558
2559 if (oldval && oldlenp) {
2560 if (get_user(len, oldlenp))
2561 return -EFAULT;
2562 if (len) {
2563 if (len > table->maxlen)
2564 len = table->maxlen;
2565 if (copy_to_user(oldval, table->data, len))
2566 return -EFAULT;
2567 if (put_user(len, oldlenp))
2568 return -EFAULT;
2569 }
2570 }
2571
2572 if (newval && newlen) {
2573 if (newlen > table->maxlen)
2574 newlen = table->maxlen;
2575
2576 if (copy_from_user(table->data, newval, newlen))
2577 return -EFAULT;
2578 }
2579 return 1;
2580}
2581
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002583int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002585 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 if (!table->data || !table->maxlen)
2588 return -ENOTDIR;
2589
2590 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002591 size_t bufsize;
2592 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002594 if (bufsize) {
2595 size_t len = strlen(table->data), copied;
2596
2597 /* This shouldn't trigger for a well-formed sysctl */
2598 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002600
2601 /* Copy up to a max of bufsize-1 bytes of the string */
2602 copied = (len >= bufsize) ? bufsize - 1 : len;
2603
2604 if (copy_to_user(oldval, table->data, copied) ||
2605 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002607 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 return -EFAULT;
2609 }
2610 }
2611 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002612 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 if (len > table->maxlen)
2614 len = table->maxlen;
2615 if(copy_from_user(table->data, newval, len))
2616 return -EFAULT;
2617 if (len == table->maxlen)
2618 len--;
2619 ((char *) table->data)[len] = 0;
2620 }
Yi Yang82c9df82005-12-30 16:37:10 +08002621 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622}
2623
2624/*
2625 * This function makes sure that all of the integers in the vector
2626 * are between the minimum and maximum values given in the arrays
2627 * table->extra1 and table->extra2, respectively.
2628 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002629int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002631 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632{
2633
2634 if (newval && newlen) {
2635 int __user *vec = (int __user *) newval;
2636 int *min = (int *) table->extra1;
2637 int *max = (int *) table->extra2;
2638 size_t length;
2639 int i;
2640
2641 if (newlen % sizeof(int) != 0)
2642 return -EINVAL;
2643
2644 if (!table->extra1 && !table->extra2)
2645 return 0;
2646
2647 if (newlen > table->maxlen)
2648 newlen = table->maxlen;
2649 length = newlen / sizeof(int);
2650
2651 for (i = 0; i < length; i++) {
2652 int value;
2653 if (get_user(value, vec + i))
2654 return -EFAULT;
2655 if (min && value < min[i])
2656 return -EINVAL;
2657 if (max && value > max[i])
2658 return -EINVAL;
2659 }
2660 }
2661 return 0;
2662}
2663
2664/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002665int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002667 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002669 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002671
2672 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002674 if (olen) {
2675 int val;
2676
2677 if (olen < sizeof(int))
2678 return -EINVAL;
2679
2680 val = *(int *)(table->data) / HZ;
2681 if (put_user(val, (int __user *)oldval))
2682 return -EFAULT;
2683 if (put_user(sizeof(int), oldlenp))
2684 return -EFAULT;
2685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 }
2687 if (newval && newlen) {
2688 int new;
2689 if (newlen != sizeof(int))
2690 return -EINVAL;
2691 if (get_user(new, (int __user *)newval))
2692 return -EFAULT;
2693 *(int *)(table->data) = new*HZ;
2694 }
2695 return 1;
2696}
2697
2698/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002699int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002701 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002703 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002705
2706 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002708 if (olen) {
2709 int val;
2710
2711 if (olen < sizeof(int))
2712 return -EINVAL;
2713
2714 val = jiffies_to_msecs(*(int *)(table->data));
2715 if (put_user(val, (int __user *)oldval))
2716 return -EFAULT;
2717 if (put_user(sizeof(int), oldlenp))
2718 return -EFAULT;
2719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 }
2721 if (newval && newlen) {
2722 int new;
2723 if (newlen != sizeof(int))
2724 return -EINVAL;
2725 if (get_user(new, (int __user *)newval))
2726 return -EFAULT;
2727 *(int *)(table->data) = msecs_to_jiffies(new);
2728 }
2729 return 1;
2730}
2731
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002732
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002733
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002734#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
2736
2737asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2738{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002739 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002740 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002741
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002742 if (copy_from_user(&tmp, args, sizeof(tmp)))
2743 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002744
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002745 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002746
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002747 /* If no error reading the parameters then just -ENOSYS ... */
2748 if (!error)
2749 error = -ENOSYS;
2750
2751 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752}
2753
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002754int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2755 void __user *oldval, size_t __user *oldlenp,
2756 void __user *newval, size_t newlen)
2757{
2758 return -ENOSYS;
2759}
2760
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002761int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002763 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764{
2765 return -ENOSYS;
2766}
2767
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002768int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002770 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771{
2772 return -ENOSYS;
2773}
2774
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002775int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002777 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778{
2779 return -ENOSYS;
2780}
2781
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002782int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002784 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785{
2786 return -ENOSYS;
2787}
2788
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002789#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002791static int deprecated_sysctl_warning(struct __sysctl_args *args)
2792{
2793 static int msg_count;
2794 int name[CTL_MAXNAME];
2795 int i;
2796
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002797 /* Check args->nlen. */
2798 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2799 return -ENOTDIR;
2800
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002801 /* Read in the sysctl name for better debug message logging */
2802 for (i = 0; i < args->nlen; i++)
2803 if (get_user(name[i], args->name + i))
2804 return -EFAULT;
2805
2806 /* Ignore accesses to kernel.version */
2807 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2808 return 0;
2809
2810 if (msg_count < 5) {
2811 msg_count++;
2812 printk(KERN_INFO
2813 "warning: process `%s' used the deprecated sysctl "
2814 "system call with ", current->comm);
2815 for (i = 0; i < args->nlen; i++)
2816 printk("%d.", name[i]);
2817 printk("\n");
2818 }
2819 return 0;
2820}
2821
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822/*
2823 * No sense putting this after each symbol definition, twice,
2824 * exception granted :-)
2825 */
2826EXPORT_SYMBOL(proc_dointvec);
2827EXPORT_SYMBOL(proc_dointvec_jiffies);
2828EXPORT_SYMBOL(proc_dointvec_minmax);
2829EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2830EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2831EXPORT_SYMBOL(proc_dostring);
2832EXPORT_SYMBOL(proc_doulongvec_minmax);
2833EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2834EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002835EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836EXPORT_SYMBOL(sysctl_intvec);
2837EXPORT_SYMBOL(sysctl_jiffies);
2838EXPORT_SYMBOL(sysctl_ms_jiffies);
2839EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002840EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841EXPORT_SYMBOL(unregister_sysctl_table);