blob: 31c19a79738d0fc73ef418126c8a4789e364b70d [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>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Pavel Machekc255d842006-02-20 18:27:58 -080046#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
Andi Kleen29cbc782006-09-30 01:47:55 +020053#ifdef CONFIG_X86
54#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010055#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010056#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020057#endif
58
Eric W. Biederman7058cb02007-10-18 03:05:58 -070059static int deprecated_sysctl_warning(struct __sysctl_args *args);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#if defined(CONFIG_SYSCTL)
62
63/* External variables not in a header file. */
64extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070065extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern int sysctl_overcommit_memory;
67extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070068extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070069extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080070extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070073extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int pid_max;
76extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080078extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080079extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020080extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070081extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070082extern int sysctl_stat_interval;
Arjan van de Ven97455122008-01-25 21:08:34 +010083extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040084extern int sysctl_nr_open_min, sysctl_nr_open_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070086/* Constants used for minimum and maximum */
Dimitri Sivanich9383d962008-05-12 21:21:14 +020087#ifdef CONFIG_HIGHMEM
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070088static int one = 1;
Bron Gondwana195cf452008-02-04 22:29:20 -080089#endif
90
91#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020093static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070094#endif
95
96#ifdef CONFIG_MMU
97static int two = 2;
98#endif
99
100static int zero;
101static int one_hundred = 100;
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
104static int maxolduid = 65535;
105static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800106static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108static int ngroups_max = NGROUPS_MAX;
109
110#ifdef CONFIG_KMOD
111extern char modprobe_path[];
112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#ifdef CONFIG_CHR_DEV_SG
114extern int sg_big_buff;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117#ifdef __sparc__
118extern char reboot_command [];
119extern int stop_a_enabled;
120extern int scons_pwroff;
121#endif
122
123#ifdef __hppa__
124extern int pwrsw_enabled;
125extern int unaligned_enabled;
126#endif
127
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800128#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#ifdef CONFIG_MATHEMU
130extern int sysctl_ieee_emulation_warnings;
131#endif
132extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700133extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
136extern int sysctl_hz_timer;
137
138#ifdef CONFIG_BSD_PROCESS_ACCT
139extern int acct_parm[];
140#endif
141
Jes Sorensend2b176e2006-02-28 09:42:23 -0800142#ifdef CONFIG_IA64
143extern int no_unaligned_warning;
144#endif
145
Ingo Molnar23f78d42006-06-27 02:54:53 -0700146#ifdef CONFIG_RT_MUTEXES
147extern int max_lock_depth;
148#endif
149
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700150#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700151static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700152 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700153static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800154 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700155#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700156
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700157static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100158static struct ctl_table_root sysctl_table_root;
159static struct ctl_table_header root_table_header = {
160 .ctl_table = root_table,
161 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
162 .root = &sysctl_table_root,
163};
164static struct ctl_table_root sysctl_table_root = {
165 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
166 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
167};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700169static struct ctl_table kern_table[];
170static struct ctl_table vm_table[];
171static struct ctl_table fs_table[];
172static struct ctl_table debug_table[];
173static struct ctl_table dev_table[];
174extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700175#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700176extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400177#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
180int sysctl_legacy_va_layout;
181#endif
182
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700183extern int prove_locking;
184extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/* The default sysctl tables: */
187
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700188static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 {
190 .ctl_name = CTL_KERN,
191 .procname = "kernel",
192 .mode = 0555,
193 .child = kern_table,
194 },
195 {
196 .ctl_name = CTL_VM,
197 .procname = "vm",
198 .mode = 0555,
199 .child = vm_table,
200 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 .ctl_name = CTL_FS,
203 .procname = "fs",
204 .mode = 0555,
205 .child = fs_table,
206 },
207 {
208 .ctl_name = CTL_DEBUG,
209 .procname = "debug",
210 .mode = 0555,
211 .child = debug_table,
212 },
213 {
214 .ctl_name = CTL_DEV,
215 .procname = "dev",
216 .mode = 0555,
217 .child = dev_table,
218 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700219/*
220 * NOTE: do not add new entries to this table unless you have read
221 * Documentation/sysctl/ctl_unnumbered.txt
222 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 { .ctl_name = 0 }
224};
225
Ingo Molnar77e54a12007-07-09 18:52:00 +0200226#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100227static int min_sched_granularity_ns = 100000; /* 100 usecs */
228static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
229static int min_wakeup_granularity_ns; /* 0 usecs */
230static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200231#endif
232
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700233static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200234#ifdef CONFIG_SCHED_DEBUG
235 {
236 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100237 .procname = "sched_min_granularity_ns",
238 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200239 .maxlen = sizeof(unsigned int),
240 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100241 .proc_handler = &sched_nr_latency_handler,
242 .strategy = &sysctl_intvec,
243 .extra1 = &min_sched_granularity_ns,
244 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200245 },
246 {
247 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200248 .procname = "sched_latency_ns",
249 .data = &sysctl_sched_latency,
250 .maxlen = sizeof(unsigned int),
251 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100252 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200253 .strategy = &sysctl_intvec,
254 .extra1 = &min_sched_granularity_ns,
255 .extra2 = &max_sched_granularity_ns,
256 },
257 {
258 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200259 .procname = "sched_wakeup_granularity_ns",
260 .data = &sysctl_sched_wakeup_granularity,
261 .maxlen = sizeof(unsigned int),
262 .mode = 0644,
263 .proc_handler = &proc_dointvec_minmax,
264 .strategy = &sysctl_intvec,
265 .extra1 = &min_wakeup_granularity_ns,
266 .extra2 = &max_wakeup_granularity_ns,
267 },
268 {
269 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200270 .procname = "sched_child_runs_first",
271 .data = &sysctl_sched_child_runs_first,
272 .maxlen = sizeof(unsigned int),
273 .mode = 0644,
274 .proc_handler = &proc_dointvec,
275 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200276 {
277 .ctl_name = CTL_UNNUMBERED,
278 .procname = "sched_features",
279 .data = &sysctl_sched_features,
280 .maxlen = sizeof(unsigned int),
281 .mode = 0644,
282 .proc_handler = &proc_dointvec,
283 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200284 {
285 .ctl_name = CTL_UNNUMBERED,
286 .procname = "sched_migration_cost",
287 .data = &sysctl_sched_migration_cost,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec,
291 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100292 {
293 .ctl_name = CTL_UNNUMBERED,
294 .procname = "sched_nr_migrate",
295 .data = &sysctl_sched_nr_migrate,
296 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100297 .mode = 0644,
298 .proc_handler = &proc_dointvec,
299 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200300#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200301 {
302 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100303 .procname = "sched_rt_period_us",
304 .data = &sysctl_sched_rt_period,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200307 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100308 },
309 {
310 .ctl_name = CTL_UNNUMBERED,
311 .procname = "sched_rt_runtime_us",
312 .data = &sysctl_sched_rt_runtime,
313 .maxlen = sizeof(int),
314 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200315 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100316 },
317 {
318 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200319 .procname = "sched_compat_yield",
320 .data = &sysctl_sched_compat_yield,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
323 .proc_handler = &proc_dointvec,
324 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700325#ifdef CONFIG_PROVE_LOCKING
326 {
327 .ctl_name = CTL_UNNUMBERED,
328 .procname = "prove_locking",
329 .data = &prove_locking,
330 .maxlen = sizeof(int),
331 .mode = 0644,
332 .proc_handler = &proc_dointvec,
333 },
334#endif
335#ifdef CONFIG_LOCK_STAT
336 {
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "lock_stat",
339 .data = &lock_stat,
340 .maxlen = sizeof(int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
343 },
344#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200345 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 .ctl_name = KERN_PANIC,
347 .procname = "panic",
348 .data = &panic_timeout,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
352 },
353 {
354 .ctl_name = KERN_CORE_USES_PID,
355 .procname = "core_uses_pid",
356 .data = &core_uses_pid,
357 .maxlen = sizeof(int),
358 .mode = 0644,
359 .proc_handler = &proc_dointvec,
360 },
361 {
362 .ctl_name = KERN_CORE_PATTERN,
363 .procname = "core_pattern",
364 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700365 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 .mode = 0644,
367 .proc_handler = &proc_dostring,
368 .strategy = &sysctl_string,
369 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800370#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 .procname = "tainted",
373 .data = &tainted,
374 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800375 .mode = 0644,
376 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800378#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100379#ifdef CONFIG_LATENCYTOP
380 {
381 .procname = "latencytop",
382 .data = &latencytop_enabled,
383 .maxlen = sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
386 },
387#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388#ifdef CONFIG_BLK_DEV_INITRD
389 {
390 .ctl_name = KERN_REALROOTDEV,
391 .procname = "real-root-dev",
392 .data = &real_root_dev,
393 .maxlen = sizeof(int),
394 .mode = 0644,
395 .proc_handler = &proc_dointvec,
396 },
397#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700398 {
399 .ctl_name = CTL_UNNUMBERED,
400 .procname = "print-fatal-signals",
401 .data = &print_fatal_signals,
402 .maxlen = sizeof(int),
403 .mode = 0644,
404 .proc_handler = &proc_dointvec,
405 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#ifdef __sparc__
407 {
408 .ctl_name = KERN_SPARC_REBOOT,
409 .procname = "reboot-cmd",
410 .data = reboot_command,
411 .maxlen = 256,
412 .mode = 0644,
413 .proc_handler = &proc_dostring,
414 .strategy = &sysctl_string,
415 },
416 {
417 .ctl_name = KERN_SPARC_STOP_A,
418 .procname = "stop-a",
419 .data = &stop_a_enabled,
420 .maxlen = sizeof (int),
421 .mode = 0644,
422 .proc_handler = &proc_dointvec,
423 },
424 {
425 .ctl_name = KERN_SPARC_SCONS_PWROFF,
426 .procname = "scons-poweroff",
427 .data = &scons_pwroff,
428 .maxlen = sizeof (int),
429 .mode = 0644,
430 .proc_handler = &proc_dointvec,
431 },
432#endif
433#ifdef __hppa__
434 {
435 .ctl_name = KERN_HPPA_PWRSW,
436 .procname = "soft-power",
437 .data = &pwrsw_enabled,
438 .maxlen = sizeof (int),
439 .mode = 0644,
440 .proc_handler = &proc_dointvec,
441 },
442 {
443 .ctl_name = KERN_HPPA_UNALIGNED,
444 .procname = "unaligned-trap",
445 .data = &unaligned_enabled,
446 .maxlen = sizeof (int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450#endif
451 {
452 .ctl_name = KERN_CTLALTDEL,
453 .procname = "ctrl-alt-del",
454 .data = &C_A_D,
455 .maxlen = sizeof(int),
456 .mode = 0644,
457 .proc_handler = &proc_dointvec,
458 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#ifdef CONFIG_KMOD
460 {
461 .ctl_name = KERN_MODPROBE,
462 .procname = "modprobe",
463 .data = &modprobe_path,
464 .maxlen = KMOD_PATH_LEN,
465 .mode = 0644,
466 .proc_handler = &proc_dostring,
467 .strategy = &sysctl_string,
468 },
469#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700470#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 {
472 .ctl_name = KERN_HOTPLUG,
473 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100474 .data = &uevent_helper,
475 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 .mode = 0644,
477 .proc_handler = &proc_dostring,
478 .strategy = &sysctl_string,
479 },
480#endif
481#ifdef CONFIG_CHR_DEV_SG
482 {
483 .ctl_name = KERN_SG_BIG_BUFF,
484 .procname = "sg-big-buff",
485 .data = &sg_big_buff,
486 .maxlen = sizeof (int),
487 .mode = 0444,
488 .proc_handler = &proc_dointvec,
489 },
490#endif
491#ifdef CONFIG_BSD_PROCESS_ACCT
492 {
493 .ctl_name = KERN_ACCT,
494 .procname = "acct",
495 .data = &acct_parm,
496 .maxlen = 3*sizeof(int),
497 .mode = 0644,
498 .proc_handler = &proc_dointvec,
499 },
500#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501#ifdef CONFIG_MAGIC_SYSRQ
502 {
503 .ctl_name = KERN_SYSRQ,
504 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800505 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 .maxlen = sizeof (int),
507 .mode = 0644,
508 .proc_handler = &proc_dointvec,
509 },
510#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700511#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700514 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 .maxlen = sizeof (int),
516 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700517 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700519#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 {
521 .ctl_name = KERN_MAX_THREADS,
522 .procname = "threads-max",
523 .data = &max_threads,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = &proc_dointvec,
527 },
528 {
529 .ctl_name = KERN_RANDOM,
530 .procname = "random",
531 .mode = 0555,
532 .child = random_table,
533 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 {
535 .ctl_name = KERN_OVERFLOWUID,
536 .procname = "overflowuid",
537 .data = &overflowuid,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec_minmax,
541 .strategy = &sysctl_intvec,
542 .extra1 = &minolduid,
543 .extra2 = &maxolduid,
544 },
545 {
546 .ctl_name = KERN_OVERFLOWGID,
547 .procname = "overflowgid",
548 .data = &overflowgid,
549 .maxlen = sizeof(int),
550 .mode = 0644,
551 .proc_handler = &proc_dointvec_minmax,
552 .strategy = &sysctl_intvec,
553 .extra1 = &minolduid,
554 .extra2 = &maxolduid,
555 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800556#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#ifdef CONFIG_MATHEMU
558 {
559 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
560 .procname = "ieee_emulation_warnings",
561 .data = &sysctl_ieee_emulation_warnings,
562 .maxlen = sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
565 },
566#endif
567#ifdef CONFIG_NO_IDLE_HZ
568 {
569 .ctl_name = KERN_HZ_TIMER,
570 .procname = "hz_timer",
571 .data = &sysctl_hz_timer,
572 .maxlen = sizeof(int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
575 },
576#endif
577 {
578 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
579 .procname = "userprocess_debug",
580 .data = &sysctl_userprocess_debug,
581 .maxlen = sizeof(int),
582 .mode = 0644,
583 .proc_handler = &proc_dointvec,
584 },
585#endif
586 {
587 .ctl_name = KERN_PIDMAX,
588 .procname = "pid_max",
589 .data = &pid_max,
590 .maxlen = sizeof (int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec_minmax,
593 .strategy = sysctl_intvec,
594 .extra1 = &pid_max_min,
595 .extra2 = &pid_max_max,
596 },
597 {
598 .ctl_name = KERN_PANIC_ON_OOPS,
599 .procname = "panic_on_oops",
600 .data = &panic_on_oops,
601 .maxlen = sizeof(int),
602 .mode = 0644,
603 .proc_handler = &proc_dointvec,
604 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800605#if defined CONFIG_PRINTK
606 {
607 .ctl_name = KERN_PRINTK,
608 .procname = "printk",
609 .data = &console_loglevel,
610 .maxlen = 4*sizeof(int),
611 .mode = 0644,
612 .proc_handler = &proc_dointvec,
613 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 {
615 .ctl_name = KERN_PRINTK_RATELIMIT,
616 .procname = "printk_ratelimit",
617 .data = &printk_ratelimit_jiffies,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec_jiffies,
621 .strategy = &sysctl_jiffies,
622 },
623 {
624 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
625 .procname = "printk_ratelimit_burst",
626 .data = &printk_ratelimit_burst,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = &proc_dointvec,
630 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800631#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 {
633 .ctl_name = KERN_NGROUPS_MAX,
634 .procname = "ngroups_max",
635 .data = &ngroups_max,
636 .maxlen = sizeof (int),
637 .mode = 0444,
638 .proc_handler = &proc_dointvec,
639 },
640#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
641 {
642 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
643 .procname = "unknown_nmi_panic",
644 .data = &unknown_nmi_panic,
645 .maxlen = sizeof (int),
646 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200647 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 },
Don Zickus407984f2006-09-26 10:52:27 +0200649 {
Don Zickus407984f2006-09-26 10:52:27 +0200650 .procname = "nmi_watchdog",
651 .data = &nmi_watchdog_enabled,
652 .maxlen = sizeof (int),
653 .mode = 0644,
654 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 },
656#endif
657#if defined(CONFIG_X86)
658 {
Don Zickus8da5add2006-09-26 10:52:27 +0200659 .ctl_name = KERN_PANIC_ON_NMI,
660 .procname = "panic_on_unrecovered_nmi",
661 .data = &panic_on_unrecovered_nmi,
662 .maxlen = sizeof(int),
663 .mode = 0644,
664 .proc_handler = &proc_dointvec,
665 },
666 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 .ctl_name = KERN_BOOTLOADER_TYPE,
668 .procname = "bootloader_type",
669 .data = &bootloader_type,
670 .maxlen = sizeof (int),
671 .mode = 0444,
672 .proc_handler = &proc_dointvec,
673 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100674 {
675 .ctl_name = CTL_UNNUMBERED,
676 .procname = "kstack_depth_to_print",
677 .data = &kstack_depth_to_print,
678 .maxlen = sizeof(int),
679 .mode = 0644,
680 .proc_handler = &proc_dointvec,
681 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100682 {
683 .ctl_name = CTL_UNNUMBERED,
684 .procname = "io_delay_type",
685 .data = &io_delay_type,
686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec,
689 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800691#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 {
693 .ctl_name = KERN_RANDOMIZE,
694 .procname = "randomize_va_space",
695 .data = &randomize_va_space,
696 .maxlen = sizeof(int),
697 .mode = 0644,
698 .proc_handler = &proc_dointvec,
699 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800700#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800701#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700702 {
703 .ctl_name = KERN_SPIN_RETRY,
704 .procname = "spin_retry",
705 .data = &spin_retry,
706 .maxlen = sizeof (int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
709 },
710#endif
Len Brown673d5b42007-07-28 03:33:16 -0400711#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800712 {
Pavel Machekc255d842006-02-20 18:27:58 -0800713 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700714 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800715 .maxlen = sizeof (unsigned long),
716 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800717 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800718 },
719#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800720#ifdef CONFIG_IA64
721 {
722 .ctl_name = KERN_IA64_UNALIGNED,
723 .procname = "ignore-unaligned-usertrap",
724 .data = &no_unaligned_warning,
725 .maxlen = sizeof (int),
726 .mode = 0644,
727 .proc_handler = &proc_dointvec,
728 },
729#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700730#ifdef CONFIG_DETECT_SOFTLOCKUP
731 {
732 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200733 .procname = "softlockup_panic",
734 .data = &softlockup_panic,
735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = &proc_doulongvec_minmax,
738 .strategy = &sysctl_intvec,
739 .extra1 = &zero,
740 .extra2 = &one,
741 },
742 {
743 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700744 .procname = "softlockup_thresh",
745 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200746 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700747 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200748 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700749 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200750 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700751 .extra2 = &sixty,
752 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100753 {
754 .ctl_name = CTL_UNNUMBERED,
755 .procname = "hung_task_check_count",
756 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100757 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100758 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100759 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100760 .strategy = &sysctl_intvec,
761 },
762 {
763 .ctl_name = CTL_UNNUMBERED,
764 .procname = "hung_task_timeout_secs",
765 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100766 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100767 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100768 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100769 .strategy = &sysctl_intvec,
770 },
771 {
772 .ctl_name = CTL_UNNUMBERED,
773 .procname = "hung_task_warnings",
774 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100775 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100776 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100777 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100778 .strategy = &sysctl_intvec,
779 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700780#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200781#ifdef CONFIG_COMPAT
782 {
783 .ctl_name = KERN_COMPAT_LOG,
784 .procname = "compat-log",
785 .data = &compat_log,
786 .maxlen = sizeof (int),
787 .mode = 0644,
788 .proc_handler = &proc_dointvec,
789 },
790#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700791#ifdef CONFIG_RT_MUTEXES
792 {
793 .ctl_name = KERN_MAX_LOCK_DEPTH,
794 .procname = "max_lock_depth",
795 .data = &max_lock_depth,
796 .maxlen = sizeof(int),
797 .mode = 0644,
798 .proc_handler = &proc_dointvec,
799 },
800#endif
Kees Cook5096add2007-05-08 00:26:04 -0700801#ifdef CONFIG_PROC_FS
802 {
803 .ctl_name = CTL_UNNUMBERED,
804 .procname = "maps_protect",
805 .data = &maps_protect,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = &proc_dointvec,
809 },
810#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700811 {
812 .ctl_name = CTL_UNNUMBERED,
813 .procname = "poweroff_cmd",
814 .data = &poweroff_cmd,
815 .maxlen = POWEROFF_CMD_PATH_LEN,
816 .mode = 0644,
817 .proc_handler = &proc_dostring,
818 .strategy = &sysctl_string,
819 },
David Howells0b77f5b2008-04-29 01:01:32 -0700820#ifdef CONFIG_KEYS
821 {
822 .ctl_name = CTL_UNNUMBERED,
823 .procname = "keys",
824 .mode = 0555,
825 .child = key_sysctls,
826 },
827#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700828/*
829 * NOTE: do not add new entries to this table unless you have read
830 * Documentation/sysctl/ctl_unnumbered.txt
831 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 { .ctl_name = 0 }
833};
834
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700835static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 {
837 .ctl_name = VM_OVERCOMMIT_MEMORY,
838 .procname = "overcommit_memory",
839 .data = &sysctl_overcommit_memory,
840 .maxlen = sizeof(sysctl_overcommit_memory),
841 .mode = 0644,
842 .proc_handler = &proc_dointvec,
843 },
844 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700845 .ctl_name = VM_PANIC_ON_OOM,
846 .procname = "panic_on_oom",
847 .data = &sysctl_panic_on_oom,
848 .maxlen = sizeof(sysctl_panic_on_oom),
849 .mode = 0644,
850 .proc_handler = &proc_dointvec,
851 },
852 {
David Rientjesfe071d72007-10-16 23:25:56 -0700853 .ctl_name = CTL_UNNUMBERED,
854 .procname = "oom_kill_allocating_task",
855 .data = &sysctl_oom_kill_allocating_task,
856 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
857 .mode = 0644,
858 .proc_handler = &proc_dointvec,
859 },
860 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800861 .ctl_name = CTL_UNNUMBERED,
862 .procname = "oom_dump_tasks",
863 .data = &sysctl_oom_dump_tasks,
864 .maxlen = sizeof(sysctl_oom_dump_tasks),
865 .mode = 0644,
866 .proc_handler = &proc_dointvec,
867 },
868 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 .ctl_name = VM_OVERCOMMIT_RATIO,
870 .procname = "overcommit_ratio",
871 .data = &sysctl_overcommit_ratio,
872 .maxlen = sizeof(sysctl_overcommit_ratio),
873 .mode = 0644,
874 .proc_handler = &proc_dointvec,
875 },
876 {
877 .ctl_name = VM_PAGE_CLUSTER,
878 .procname = "page-cluster",
879 .data = &page_cluster,
880 .maxlen = sizeof(int),
881 .mode = 0644,
882 .proc_handler = &proc_dointvec,
883 },
884 {
885 .ctl_name = VM_DIRTY_BACKGROUND,
886 .procname = "dirty_background_ratio",
887 .data = &dirty_background_ratio,
888 .maxlen = sizeof(dirty_background_ratio),
889 .mode = 0644,
890 .proc_handler = &proc_dointvec_minmax,
891 .strategy = &sysctl_intvec,
892 .extra1 = &zero,
893 .extra2 = &one_hundred,
894 },
895 {
896 .ctl_name = VM_DIRTY_RATIO,
897 .procname = "dirty_ratio",
898 .data = &vm_dirty_ratio,
899 .maxlen = sizeof(vm_dirty_ratio),
900 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700901 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 .strategy = &sysctl_intvec,
903 .extra1 = &zero,
904 .extra2 = &one_hundred,
905 },
906 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800908 .data = &dirty_writeback_interval,
909 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .mode = 0644,
911 .proc_handler = &dirty_writeback_centisecs_handler,
912 },
913 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800915 .data = &dirty_expire_interval,
916 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800918 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 },
920 {
921 .ctl_name = VM_NR_PDFLUSH_THREADS,
922 .procname = "nr_pdflush_threads",
923 .data = &nr_pdflush_threads,
924 .maxlen = sizeof nr_pdflush_threads,
925 .mode = 0444 /* read-only*/,
926 .proc_handler = &proc_dointvec,
927 },
928 {
929 .ctl_name = VM_SWAPPINESS,
930 .procname = "swappiness",
931 .data = &vm_swappiness,
932 .maxlen = sizeof(vm_swappiness),
933 .mode = 0644,
934 .proc_handler = &proc_dointvec_minmax,
935 .strategy = &sysctl_intvec,
936 .extra1 = &zero,
937 .extra2 = &one_hundred,
938 },
939#ifdef CONFIG_HUGETLB_PAGE
940 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 .procname = "nr_hugepages",
942 .data = &max_huge_pages,
943 .maxlen = sizeof(unsigned long),
944 .mode = 0644,
945 .proc_handler = &hugetlb_sysctl_handler,
946 .extra1 = (void *)&hugetlb_zero,
947 .extra2 = (void *)&hugetlb_infinity,
948 },
949 {
950 .ctl_name = VM_HUGETLB_GROUP,
951 .procname = "hugetlb_shm_group",
952 .data = &sysctl_hugetlb_shm_group,
953 .maxlen = sizeof(gid_t),
954 .mode = 0644,
955 .proc_handler = &proc_dointvec,
956 },
Mel Gorman396faf02007-07-17 04:03:13 -0700957 {
958 .ctl_name = CTL_UNNUMBERED,
959 .procname = "hugepages_treat_as_movable",
960 .data = &hugepages_treat_as_movable,
961 .maxlen = sizeof(int),
962 .mode = 0644,
963 .proc_handler = &hugetlb_treat_movable_handler,
964 },
Adam Litke54f9f802007-10-16 01:26:20 -0700965 {
966 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800967 .procname = "nr_overcommit_hugepages",
Nishanth Aravamudan064d9ef2008-02-13 15:03:19 -0800968 .data = &sysctl_overcommit_huge_pages,
969 .maxlen = sizeof(sysctl_overcommit_huge_pages),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800970 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800971 .proc_handler = &hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800972 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973#endif
974 {
975 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
976 .procname = "lowmem_reserve_ratio",
977 .data = &sysctl_lowmem_reserve_ratio,
978 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
979 .mode = 0644,
980 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
981 .strategy = &sysctl_intvec,
982 },
983 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800984 .ctl_name = VM_DROP_PAGECACHE,
985 .procname = "drop_caches",
986 .data = &sysctl_drop_caches,
987 .maxlen = sizeof(int),
988 .mode = 0644,
989 .proc_handler = drop_caches_sysctl_handler,
990 .strategy = &sysctl_intvec,
991 },
992 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 .ctl_name = VM_MIN_FREE_KBYTES,
994 .procname = "min_free_kbytes",
995 .data = &min_free_kbytes,
996 .maxlen = sizeof(min_free_kbytes),
997 .mode = 0644,
998 .proc_handler = &min_free_kbytes_sysctl_handler,
999 .strategy = &sysctl_intvec,
1000 .extra1 = &zero,
1001 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001002 {
1003 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1004 .procname = "percpu_pagelist_fraction",
1005 .data = &percpu_pagelist_fraction,
1006 .maxlen = sizeof(percpu_pagelist_fraction),
1007 .mode = 0644,
1008 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1009 .strategy = &sysctl_intvec,
1010 .extra1 = &min_percpu_pagelist_fract,
1011 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012#ifdef CONFIG_MMU
1013 {
1014 .ctl_name = VM_MAX_MAP_COUNT,
1015 .procname = "max_map_count",
1016 .data = &sysctl_max_map_count,
1017 .maxlen = sizeof(sysctl_max_map_count),
1018 .mode = 0644,
1019 .proc_handler = &proc_dointvec
1020 },
1021#endif
1022 {
1023 .ctl_name = VM_LAPTOP_MODE,
1024 .procname = "laptop_mode",
1025 .data = &laptop_mode,
1026 .maxlen = sizeof(laptop_mode),
1027 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001028 .proc_handler = &proc_dointvec_jiffies,
1029 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 },
1031 {
1032 .ctl_name = VM_BLOCK_DUMP,
1033 .procname = "block_dump",
1034 .data = &block_dump,
1035 .maxlen = sizeof(block_dump),
1036 .mode = 0644,
1037 .proc_handler = &proc_dointvec,
1038 .strategy = &sysctl_intvec,
1039 .extra1 = &zero,
1040 },
1041 {
1042 .ctl_name = VM_VFS_CACHE_PRESSURE,
1043 .procname = "vfs_cache_pressure",
1044 .data = &sysctl_vfs_cache_pressure,
1045 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1046 .mode = 0644,
1047 .proc_handler = &proc_dointvec,
1048 .strategy = &sysctl_intvec,
1049 .extra1 = &zero,
1050 },
1051#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1052 {
1053 .ctl_name = VM_LEGACY_VA_LAYOUT,
1054 .procname = "legacy_va_layout",
1055 .data = &sysctl_legacy_va_layout,
1056 .maxlen = sizeof(sysctl_legacy_va_layout),
1057 .mode = 0644,
1058 .proc_handler = &proc_dointvec,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &zero,
1061 },
1062#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001063#ifdef CONFIG_NUMA
1064 {
1065 .ctl_name = VM_ZONE_RECLAIM_MODE,
1066 .procname = "zone_reclaim_mode",
1067 .data = &zone_reclaim_mode,
1068 .maxlen = sizeof(zone_reclaim_mode),
1069 .mode = 0644,
1070 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001071 .strategy = &sysctl_intvec,
1072 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001073 },
Christoph Lameter96146342006-07-03 00:24:13 -07001074 {
1075 .ctl_name = VM_MIN_UNMAPPED,
1076 .procname = "min_unmapped_ratio",
1077 .data = &sysctl_min_unmapped_ratio,
1078 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1079 .mode = 0644,
1080 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1081 .strategy = &sysctl_intvec,
1082 .extra1 = &zero,
1083 .extra2 = &one_hundred,
1084 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001085 {
1086 .ctl_name = VM_MIN_SLAB,
1087 .procname = "min_slab_ratio",
1088 .data = &sysctl_min_slab_ratio,
1089 .maxlen = sizeof(sysctl_min_slab_ratio),
1090 .mode = 0644,
1091 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1092 .strategy = &sysctl_intvec,
1093 .extra1 = &zero,
1094 .extra2 = &one_hundred,
1095 },
Christoph Lameter17436602006-01-18 17:42:32 -08001096#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001097#ifdef CONFIG_SMP
1098 {
1099 .ctl_name = CTL_UNNUMBERED,
1100 .procname = "stat_interval",
1101 .data = &sysctl_stat_interval,
1102 .maxlen = sizeof(sysctl_stat_interval),
1103 .mode = 0644,
1104 .proc_handler = &proc_dointvec_jiffies,
1105 .strategy = &sysctl_jiffies,
1106 },
1107#endif
Eric Parised032182007-06-28 15:55:21 -04001108#ifdef CONFIG_SECURITY
1109 {
1110 .ctl_name = CTL_UNNUMBERED,
1111 .procname = "mmap_min_addr",
1112 .data = &mmap_min_addr,
1113 .maxlen = sizeof(unsigned long),
1114 .mode = 0644,
1115 .proc_handler = &proc_doulongvec_minmax,
1116 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001117#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001118#ifdef CONFIG_NUMA
1119 {
1120 .ctl_name = CTL_UNNUMBERED,
1121 .procname = "numa_zonelist_order",
1122 .data = &numa_zonelist_order,
1123 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1124 .mode = 0644,
1125 .proc_handler = &numa_zonelist_order_handler,
1126 .strategy = &sysctl_string,
1127 },
1128#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001129#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001130 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001131 {
1132 .ctl_name = VM_VDSO_ENABLED,
1133 .procname = "vdso_enabled",
1134 .data = &vdso_enabled,
1135 .maxlen = sizeof(vdso_enabled),
1136 .mode = 0644,
1137 .proc_handler = &proc_dointvec,
1138 .strategy = &sysctl_intvec,
1139 .extra1 = &zero,
1140 },
1141#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001142#ifdef CONFIG_HIGHMEM
1143 {
1144 .ctl_name = CTL_UNNUMBERED,
1145 .procname = "highmem_is_dirtyable",
1146 .data = &vm_highmem_is_dirtyable,
1147 .maxlen = sizeof(vm_highmem_is_dirtyable),
1148 .mode = 0644,
1149 .proc_handler = &proc_dointvec_minmax,
1150 .strategy = &sysctl_intvec,
1151 .extra1 = &zero,
1152 .extra2 = &one,
1153 },
1154#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001155/*
1156 * NOTE: do not add new entries to this table unless you have read
1157 * Documentation/sysctl/ctl_unnumbered.txt
1158 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 { .ctl_name = 0 }
1160};
1161
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001162#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001163static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001164 { .ctl_name = 0 }
1165};
1166#endif
1167
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001168static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 {
1170 .ctl_name = FS_NRINODE,
1171 .procname = "inode-nr",
1172 .data = &inodes_stat,
1173 .maxlen = 2*sizeof(int),
1174 .mode = 0444,
1175 .proc_handler = &proc_dointvec,
1176 },
1177 {
1178 .ctl_name = FS_STATINODE,
1179 .procname = "inode-state",
1180 .data = &inodes_stat,
1181 .maxlen = 7*sizeof(int),
1182 .mode = 0444,
1183 .proc_handler = &proc_dointvec,
1184 },
1185 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 .procname = "file-nr",
1187 .data = &files_stat,
1188 .maxlen = 3*sizeof(int),
1189 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001190 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 },
1192 {
1193 .ctl_name = FS_MAXFILE,
1194 .procname = "file-max",
1195 .data = &files_stat.max_files,
1196 .maxlen = sizeof(int),
1197 .mode = 0644,
1198 .proc_handler = &proc_dointvec,
1199 },
1200 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001201 .ctl_name = CTL_UNNUMBERED,
1202 .procname = "nr_open",
1203 .data = &sysctl_nr_open,
1204 .maxlen = sizeof(int),
1205 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001206 .proc_handler = &proc_dointvec_minmax,
1207 .extra1 = &sysctl_nr_open_min,
1208 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001209 },
1210 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 .ctl_name = FS_DENTRY,
1212 .procname = "dentry-state",
1213 .data = &dentry_stat,
1214 .maxlen = 6*sizeof(int),
1215 .mode = 0444,
1216 .proc_handler = &proc_dointvec,
1217 },
1218 {
1219 .ctl_name = FS_OVERFLOWUID,
1220 .procname = "overflowuid",
1221 .data = &fs_overflowuid,
1222 .maxlen = sizeof(int),
1223 .mode = 0644,
1224 .proc_handler = &proc_dointvec_minmax,
1225 .strategy = &sysctl_intvec,
1226 .extra1 = &minolduid,
1227 .extra2 = &maxolduid,
1228 },
1229 {
1230 .ctl_name = FS_OVERFLOWGID,
1231 .procname = "overflowgid",
1232 .data = &fs_overflowgid,
1233 .maxlen = sizeof(int),
1234 .mode = 0644,
1235 .proc_handler = &proc_dointvec_minmax,
1236 .strategy = &sysctl_intvec,
1237 .extra1 = &minolduid,
1238 .extra2 = &maxolduid,
1239 },
1240 {
1241 .ctl_name = FS_LEASES,
1242 .procname = "leases-enable",
1243 .data = &leases_enable,
1244 .maxlen = sizeof(int),
1245 .mode = 0644,
1246 .proc_handler = &proc_dointvec,
1247 },
1248#ifdef CONFIG_DNOTIFY
1249 {
1250 .ctl_name = FS_DIR_NOTIFY,
1251 .procname = "dir-notify-enable",
1252 .data = &dir_notify_enable,
1253 .maxlen = sizeof(int),
1254 .mode = 0644,
1255 .proc_handler = &proc_dointvec,
1256 },
1257#endif
1258#ifdef CONFIG_MMU
1259 {
1260 .ctl_name = FS_LEASE_TIME,
1261 .procname = "lease-break-time",
1262 .data = &lease_break_time,
1263 .maxlen = sizeof(int),
1264 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001265 .proc_handler = &proc_dointvec_minmax,
1266 .strategy = &sysctl_intvec,
1267 .extra1 = &zero,
1268 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 },
1270 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 .procname = "aio-nr",
1272 .data = &aio_nr,
1273 .maxlen = sizeof(aio_nr),
1274 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001275 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 },
1277 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 .procname = "aio-max-nr",
1279 .data = &aio_max_nr,
1280 .maxlen = sizeof(aio_max_nr),
1281 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001282 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001284#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001285 {
1286 .ctl_name = FS_INOTIFY,
1287 .procname = "inotify",
1288 .mode = 0555,
1289 .child = inotify_table,
1290 },
1291#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001293 {
1294 .ctl_name = KERN_SETUID_DUMPABLE,
1295 .procname = "suid_dumpable",
1296 .data = &suid_dumpable,
1297 .maxlen = sizeof(int),
1298 .mode = 0644,
1299 .proc_handler = &proc_dointvec,
1300 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001301#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1302 {
1303 .ctl_name = CTL_UNNUMBERED,
1304 .procname = "binfmt_misc",
1305 .mode = 0555,
1306 .child = binfmt_misc_table,
1307 },
1308#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001309/*
1310 * NOTE: do not add new entries to this table unless you have read
1311 * Documentation/sysctl/ctl_unnumbered.txt
1312 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 { .ctl_name = 0 }
1314};
1315
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001316static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001317#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001318 {
1319 .ctl_name = CTL_UNNUMBERED,
1320 .procname = "exception-trace",
1321 .data = &show_unhandled_signals,
1322 .maxlen = sizeof(int),
1323 .mode = 0644,
1324 .proc_handler = proc_dointvec
1325 },
1326#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 { .ctl_name = 0 }
1328};
1329
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001330static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001332};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Al Viro330d57f2005-11-04 10:18:40 +00001334static DEFINE_SPINLOCK(sysctl_lock);
1335
1336/* called under sysctl_lock */
1337static int use_table(struct ctl_table_header *p)
1338{
1339 if (unlikely(p->unregistering))
1340 return 0;
1341 p->used++;
1342 return 1;
1343}
1344
1345/* called under sysctl_lock */
1346static void unuse_table(struct ctl_table_header *p)
1347{
1348 if (!--p->used)
1349 if (unlikely(p->unregistering))
1350 complete(p->unregistering);
1351}
1352
1353/* called under sysctl_lock, will reacquire if has to wait */
1354static void start_unregistering(struct ctl_table_header *p)
1355{
1356 /*
1357 * if p->used is 0, nobody will ever touch that entry again;
1358 * we'll eliminate all paths to it before dropping sysctl_lock
1359 */
1360 if (unlikely(p->used)) {
1361 struct completion wait;
1362 init_completion(&wait);
1363 p->unregistering = &wait;
1364 spin_unlock(&sysctl_lock);
1365 wait_for_completion(&wait);
1366 spin_lock(&sysctl_lock);
1367 }
1368 /*
1369 * do not remove from the list until nobody holds it; walking the
1370 * list in do_sysctl() relies on that.
1371 */
1372 list_del_init(&p->ctl_entry);
1373}
1374
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001375void sysctl_head_finish(struct ctl_table_header *head)
1376{
1377 if (!head)
1378 return;
1379 spin_lock(&sysctl_lock);
1380 unuse_table(head);
1381 spin_unlock(&sysctl_lock);
1382}
1383
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001384static struct list_head *
1385lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001386{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001387 struct list_head *header_list;
1388 header_list = &root->header_list;
1389 if (root->lookup)
1390 header_list = root->lookup(root, namespaces);
1391 return header_list;
1392}
1393
1394struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1395 struct ctl_table_header *prev)
1396{
1397 struct ctl_table_root *root;
1398 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001399 struct ctl_table_header *head;
1400 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001401
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001402 spin_lock(&sysctl_lock);
1403 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001404 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001405 tmp = &prev->ctl_entry;
1406 unuse_table(prev);
1407 goto next;
1408 }
1409 tmp = &root_table_header.ctl_entry;
1410 for (;;) {
1411 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1412
1413 if (!use_table(head))
1414 goto next;
1415 spin_unlock(&sysctl_lock);
1416 return head;
1417 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001418 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001419 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001420 header_list = lookup_header_list(root, namespaces);
1421 if (tmp != header_list)
1422 continue;
1423
1424 do {
1425 root = list_entry(root->root_list.next,
1426 struct ctl_table_root, root_list);
1427 if (root == &sysctl_table_root)
1428 goto out;
1429 header_list = lookup_header_list(root, namespaces);
1430 } while (list_empty(header_list));
1431 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001432 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001433out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001434 spin_unlock(&sysctl_lock);
1435 return NULL;
1436}
1437
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001438struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1439{
1440 return __sysctl_head_next(current->nsproxy, prev);
1441}
1442
1443void register_sysctl_root(struct ctl_table_root *root)
1444{
1445 spin_lock(&sysctl_lock);
1446 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1447 spin_unlock(&sysctl_lock);
1448}
1449
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001450#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001451/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001452static int do_sysctl_strategy(struct ctl_table_root *root,
1453 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001454 int __user *name, int nlen,
1455 void __user *oldval, size_t __user *oldlenp,
1456 void __user *newval, size_t newlen)
1457{
1458 int op = 0, rc;
1459
1460 if (oldval)
1461 op |= 004;
1462 if (newval)
1463 op |= 002;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001464 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001465 return -EPERM;
1466
1467 if (table->strategy) {
1468 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1469 newval, newlen);
1470 if (rc < 0)
1471 return rc;
1472 if (rc > 0)
1473 return 0;
1474 }
1475
1476 /* If there is no strategy routine, or if the strategy returns
1477 * zero, proceed with automatic r/w */
1478 if (table->data && table->maxlen) {
1479 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1480 newval, newlen);
1481 if (rc < 0)
1482 return rc;
1483 }
1484 return 0;
1485}
1486
1487static int parse_table(int __user *name, int nlen,
1488 void __user *oldval, size_t __user *oldlenp,
1489 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001490 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001491 struct ctl_table *table)
1492{
1493 int n;
1494repeat:
1495 if (!nlen)
1496 return -ENOTDIR;
1497 if (get_user(n, name))
1498 return -EFAULT;
1499 for ( ; table->ctl_name || table->procname; table++) {
1500 if (!table->ctl_name)
1501 continue;
1502 if (n == table->ctl_name) {
1503 int error;
1504 if (table->child) {
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001505 if (sysctl_perm(root, table, 001))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001506 return -EPERM;
1507 name++;
1508 nlen--;
1509 table = table->child;
1510 goto repeat;
1511 }
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001512 error = do_sysctl_strategy(root, table, name, nlen,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001513 oldval, oldlenp,
1514 newval, newlen);
1515 return error;
1516 }
1517 }
1518 return -ENOTDIR;
1519}
1520
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1522 void __user *newval, size_t newlen)
1523{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001524 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001525 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1528 return -ENOTDIR;
1529 if (oldval) {
1530 int old_len;
1531 if (!oldlenp || get_user(old_len, oldlenp))
1532 return -EFAULT;
1533 }
Al Viro330d57f2005-11-04 10:18:40 +00001534
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001535 for (head = sysctl_head_next(NULL); head;
1536 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001537 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001538 newval, newlen,
1539 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001540 if (error != -ENOTDIR) {
1541 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001542 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001543 }
1544 }
Al Viro330d57f2005-11-04 10:18:40 +00001545 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
1548asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1549{
1550 struct __sysctl_args tmp;
1551 int error;
1552
1553 if (copy_from_user(&tmp, args, sizeof(tmp)))
1554 return -EFAULT;
1555
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001556 error = deprecated_sysctl_warning(&tmp);
1557 if (error)
1558 goto out;
1559
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 lock_kernel();
1561 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1562 tmp.newval, tmp.newlen);
1563 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001564out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 return error;
1566}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001567#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001570 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 * some sysctl variables are readonly even to root.
1572 */
1573
1574static int test_perm(int mode, int op)
1575{
1576 if (!current->euid)
1577 mode >>= 6;
1578 else if (in_egroup_p(0))
1579 mode >>= 3;
1580 if ((mode & op & 0007) == op)
1581 return 0;
1582 return -EACCES;
1583}
1584
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001585int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586{
1587 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001588 int mode;
1589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 error = security_sysctl(table, op);
1591 if (error)
1592 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001593
1594 if (root->permissions)
1595 mode = root->permissions(root, current->nsproxy, table);
1596 else
1597 mode = table->mode;
1598
1599 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001602static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1603{
1604 for (; table->ctl_name || table->procname; table++) {
1605 table->parent = parent;
1606 if (table->child)
1607 sysctl_set_parent(table, table->child);
1608 }
1609}
1610
1611static __init int sysctl_init(void)
1612{
1613 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001614#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1615 {
1616 int err;
1617 err = sysctl_check_table(current->nsproxy, root_table);
1618 }
1619#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001620 return 0;
1621}
1622
1623core_initcall(sysctl_init);
1624
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001626 * __register_sysctl_paths - register a sysctl hierarchy
1627 * @root: List of sysctl headers to register on
1628 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001629 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 *
1632 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001633 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001635 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 *
1637 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1638 * must be unique within that level of sysctl
1639 *
1640 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1641 * enter a sysctl file
1642 *
1643 * data - a pointer to data for use by proc_handler
1644 *
1645 * maxlen - the maximum size in bytes of the data
1646 *
1647 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1648 *
1649 * child - a pointer to the child sysctl table if this entry is a directory, or
1650 * %NULL.
1651 *
1652 * proc_handler - the text handler routine (described below)
1653 *
1654 * strategy - the strategy routine (described below)
1655 *
1656 * de - for internal use by the sysctl routines
1657 *
1658 * extra1, extra2 - extra pointers usable by the proc handler routines
1659 *
1660 * Leaf nodes in the sysctl tree will be represented by a single file
1661 * under /proc; non-leaf nodes will be represented by directories.
1662 *
1663 * sysctl(2) can automatically manage read and write requests through
1664 * the sysctl table. The data and maxlen fields of the ctl_table
1665 * struct enable minimal validation of the values being written to be
1666 * performed, and the mode field allows minimal authentication.
1667 *
1668 * More sophisticated management can be enabled by the provision of a
1669 * strategy routine with the table entry. This will be called before
1670 * any automatic read or write of the data is performed.
1671 *
1672 * The strategy routine may return
1673 *
1674 * < 0 - Error occurred (error is passed to user process)
1675 *
1676 * 0 - OK - proceed with automatic read or write.
1677 *
1678 * > 0 - OK - read or write has been done by the strategy routine, so
1679 * return immediately.
1680 *
1681 * There must be a proc_handler routine for any terminal nodes
1682 * mirrored under /proc/sys (non-terminals are handled by a built-in
1683 * directory handler). Several default handlers are available to
1684 * cover common cases -
1685 *
1686 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1687 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1688 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1689 *
1690 * It is the handler's job to read the input buffer from user memory
1691 * and process it. The handler should return 0 on success.
1692 *
1693 * This routine returns %NULL on a failure to register, and a pointer
1694 * to the table header on success.
1695 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001696struct ctl_table_header *__register_sysctl_paths(
1697 struct ctl_table_root *root,
1698 struct nsproxy *namespaces,
1699 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001701 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001702 struct ctl_table_header *header;
1703 struct ctl_table *new, **prevp;
1704 unsigned int n, npath;
1705
1706 /* Count the path components */
1707 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1708 ;
1709
1710 /*
1711 * For each path component, allocate a 2-element ctl_table array.
1712 * The first array element will be filled with the sysctl entry
1713 * for this, the second will be the sentinel (ctl_name == 0).
1714 *
1715 * We allocate everything in one go so that we don't have to
1716 * worry about freeing additional memory in unregister_sysctl_table.
1717 */
1718 header = kzalloc(sizeof(struct ctl_table_header) +
1719 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1720 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001722
1723 new = (struct ctl_table *) (header + 1);
1724
1725 /* Now connect the dots */
1726 prevp = &header->ctl_table;
1727 for (n = 0; n < npath; ++n, ++path) {
1728 /* Copy the procname */
1729 new->procname = path->procname;
1730 new->ctl_name = path->ctl_name;
1731 new->mode = 0555;
1732
1733 *prevp = new;
1734 prevp = &new->child;
1735
1736 new += 2;
1737 }
1738 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001739 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001740
1741 INIT_LIST_HEAD(&header->ctl_entry);
1742 header->used = 0;
1743 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001744 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001745 sysctl_set_parent(NULL, header->ctl_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001746#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001747 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001748 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001749 return NULL;
1750 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001751#endif
Al Viro330d57f2005-11-04 10:18:40 +00001752 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001753 header_list = lookup_header_list(root, namespaces);
1754 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001755 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001756
1757 return header;
1758}
1759
1760/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001761 * register_sysctl_table_path - register a sysctl table hierarchy
1762 * @path: The path to the directory the sysctl table is in.
1763 * @table: the top-level table structure
1764 *
1765 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1766 * array. A completely 0 filled entry terminates the table.
1767 *
1768 * See __register_sysctl_paths for more details.
1769 */
1770struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1771 struct ctl_table *table)
1772{
1773 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1774 path, table);
1775}
1776
1777/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001778 * register_sysctl_table - register a sysctl table hierarchy
1779 * @table: the top-level table structure
1780 *
1781 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1782 * array. A completely 0 filled entry terminates the table.
1783 *
1784 * See register_sysctl_paths for more details.
1785 */
1786struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1787{
1788 static const struct ctl_path null_path[] = { {} };
1789
1790 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791}
1792
1793/**
1794 * unregister_sysctl_table - unregister a sysctl table hierarchy
1795 * @header: the header returned from register_sysctl_table
1796 *
1797 * Unregisters the sysctl table and all children. proc entries may not
1798 * actually be removed until they are no longer used by anyone.
1799 */
1800void unregister_sysctl_table(struct ctl_table_header * header)
1801{
Al Viro330d57f2005-11-04 10:18:40 +00001802 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001803
1804 if (header == NULL)
1805 return;
1806
Al Viro330d57f2005-11-04 10:18:40 +00001807 spin_lock(&sysctl_lock);
1808 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001809 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 kfree(header);
1811}
1812
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001813#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001814struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001815{
1816 return NULL;
1817}
1818
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001819struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1820 struct ctl_table *table)
1821{
1822 return NULL;
1823}
1824
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001825void unregister_sysctl_table(struct ctl_table_header * table)
1826{
1827}
1828
1829#endif /* CONFIG_SYSCTL */
1830
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831/*
1832 * /proc/sys support
1833 */
1834
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001835#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001837static int _proc_do_string(void* data, int maxlen, int write,
1838 struct file *filp, void __user *buffer,
1839 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001840{
1841 size_t len;
1842 char __user *p;
1843 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001844
1845 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001846 *lenp = 0;
1847 return 0;
1848 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001849
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001850 if (write) {
1851 len = 0;
1852 p = buffer;
1853 while (len < *lenp) {
1854 if (get_user(c, p++))
1855 return -EFAULT;
1856 if (c == 0 || c == '\n')
1857 break;
1858 len++;
1859 }
1860 if (len >= maxlen)
1861 len = maxlen-1;
1862 if(copy_from_user(data, buffer, len))
1863 return -EFAULT;
1864 ((char *) data)[len] = 0;
1865 *ppos += *lenp;
1866 } else {
1867 len = strlen(data);
1868 if (len > maxlen)
1869 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001870
1871 if (*ppos > len) {
1872 *lenp = 0;
1873 return 0;
1874 }
1875
1876 data += *ppos;
1877 len -= *ppos;
1878
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001879 if (len > *lenp)
1880 len = *lenp;
1881 if (len)
1882 if(copy_to_user(buffer, data, len))
1883 return -EFAULT;
1884 if (len < *lenp) {
1885 if(put_user('\n', ((char __user *) buffer) + len))
1886 return -EFAULT;
1887 len++;
1888 }
1889 *lenp = len;
1890 *ppos += len;
1891 }
1892 return 0;
1893}
1894
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895/**
1896 * proc_dostring - read a string sysctl
1897 * @table: the sysctl table
1898 * @write: %TRUE if this is a write to the sysctl file
1899 * @filp: the file structure
1900 * @buffer: the user buffer
1901 * @lenp: the size of the user buffer
1902 * @ppos: file position
1903 *
1904 * Reads/writes a string from/to the user buffer. If the kernel
1905 * buffer provided is not large enough to hold the string, the
1906 * string is truncated. The copied string is %NULL-terminated.
1907 * If the string is being read by the user process, it is copied
1908 * and a newline '\n' is added. It is truncated if the buffer is
1909 * not large enough.
1910 *
1911 * Returns 0 on success.
1912 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001913int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 void __user *buffer, size_t *lenp, loff_t *ppos)
1915{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001916 return _proc_do_string(table->data, table->maxlen, write, filp,
1917 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918}
1919
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
1921static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1922 int *valp,
1923 int write, void *data)
1924{
1925 if (write) {
1926 *valp = *negp ? -*lvalp : *lvalp;
1927 } else {
1928 int val = *valp;
1929 if (val < 0) {
1930 *negp = -1;
1931 *lvalp = (unsigned long)-val;
1932 } else {
1933 *negp = 0;
1934 *lvalp = (unsigned long)val;
1935 }
1936 }
1937 return 0;
1938}
1939
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001940static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001941 int write, struct file *filp, void __user *buffer,
1942 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1944 int write, void *data),
1945 void *data)
1946{
1947#define TMPBUFLEN 21
1948 int *i, vleft, first=1, neg, val;
1949 unsigned long lval;
1950 size_t left, len;
1951
1952 char buf[TMPBUFLEN], *p;
1953 char __user *s = buffer;
1954
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001955 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 (*ppos && !write)) {
1957 *lenp = 0;
1958 return 0;
1959 }
1960
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001961 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 vleft = table->maxlen / sizeof(*i);
1963 left = *lenp;
1964
1965 if (!conv)
1966 conv = do_proc_dointvec_conv;
1967
1968 for (; left && vleft--; i++, first=0) {
1969 if (write) {
1970 while (left) {
1971 char c;
1972 if (get_user(c, s))
1973 return -EFAULT;
1974 if (!isspace(c))
1975 break;
1976 left--;
1977 s++;
1978 }
1979 if (!left)
1980 break;
1981 neg = 0;
1982 len = left;
1983 if (len > sizeof(buf) - 1)
1984 len = sizeof(buf) - 1;
1985 if (copy_from_user(buf, s, len))
1986 return -EFAULT;
1987 buf[len] = 0;
1988 p = buf;
1989 if (*p == '-' && left > 1) {
1990 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001991 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 }
1993 if (*p < '0' || *p > '9')
1994 break;
1995
1996 lval = simple_strtoul(p, &p, 0);
1997
1998 len = p-buf;
1999 if ((len < left) && *p && !isspace(*p))
2000 break;
2001 if (neg)
2002 val = -val;
2003 s += len;
2004 left -= len;
2005
2006 if (conv(&neg, &lval, i, 1, data))
2007 break;
2008 } else {
2009 p = buf;
2010 if (!first)
2011 *p++ = '\t';
2012
2013 if (conv(&neg, &lval, i, 0, data))
2014 break;
2015
2016 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2017 len = strlen(buf);
2018 if (len > left)
2019 len = left;
2020 if(copy_to_user(s, buf, len))
2021 return -EFAULT;
2022 left -= len;
2023 s += len;
2024 }
2025 }
2026
2027 if (!write && !first && left) {
2028 if(put_user('\n', s))
2029 return -EFAULT;
2030 left--, s++;
2031 }
2032 if (write) {
2033 while (left) {
2034 char c;
2035 if (get_user(c, s++))
2036 return -EFAULT;
2037 if (!isspace(c))
2038 break;
2039 left--;
2040 }
2041 }
2042 if (write && first)
2043 return -EINVAL;
2044 *lenp -= left;
2045 *ppos += *lenp;
2046 return 0;
2047#undef TMPBUFLEN
2048}
2049
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002050static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002051 void __user *buffer, size_t *lenp, loff_t *ppos,
2052 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2053 int write, void *data),
2054 void *data)
2055{
2056 return __do_proc_dointvec(table->data, table, write, filp,
2057 buffer, lenp, ppos, conv, data);
2058}
2059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060/**
2061 * proc_dointvec - read a vector of integers
2062 * @table: the sysctl table
2063 * @write: %TRUE if this is a write to the sysctl file
2064 * @filp: the file structure
2065 * @buffer: the user buffer
2066 * @lenp: the size of the user buffer
2067 * @ppos: file position
2068 *
2069 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2070 * values from/to the user buffer, treated as an ASCII string.
2071 *
2072 * Returns 0 on success.
2073 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002074int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 void __user *buffer, size_t *lenp, loff_t *ppos)
2076{
2077 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2078 NULL,NULL);
2079}
2080
2081#define OP_SET 0
2082#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002083#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2086 int *valp,
2087 int write, void *data)
2088{
2089 int op = *(int *)data;
2090 if (write) {
2091 int val = *negp ? -*lvalp : *lvalp;
2092 switch(op) {
2093 case OP_SET: *valp = val; break;
2094 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002095 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 }
2097 } else {
2098 int val = *valp;
2099 if (val < 0) {
2100 *negp = -1;
2101 *lvalp = (unsigned long)-val;
2102 } else {
2103 *negp = 0;
2104 *lvalp = (unsigned long)val;
2105 }
2106 }
2107 return 0;
2108}
2109
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002110/*
2111 * Taint values can only be increased
2112 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002113static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002114 void __user *buffer, size_t *lenp, loff_t *ppos)
2115{
2116 int op;
2117
Bastian Blank91fcd412007-04-23 14:41:14 -07002118 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002119 return -EPERM;
2120
2121 op = OP_OR;
2122 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2123 do_proc_dointvec_bset_conv,&op);
2124}
2125
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126struct do_proc_dointvec_minmax_conv_param {
2127 int *min;
2128 int *max;
2129};
2130
2131static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2132 int *valp,
2133 int write, void *data)
2134{
2135 struct do_proc_dointvec_minmax_conv_param *param = data;
2136 if (write) {
2137 int val = *negp ? -*lvalp : *lvalp;
2138 if ((param->min && *param->min > val) ||
2139 (param->max && *param->max < val))
2140 return -EINVAL;
2141 *valp = val;
2142 } else {
2143 int val = *valp;
2144 if (val < 0) {
2145 *negp = -1;
2146 *lvalp = (unsigned long)-val;
2147 } else {
2148 *negp = 0;
2149 *lvalp = (unsigned long)val;
2150 }
2151 }
2152 return 0;
2153}
2154
2155/**
2156 * proc_dointvec_minmax - read a vector of integers with min/max values
2157 * @table: the sysctl table
2158 * @write: %TRUE if this is a write to the sysctl file
2159 * @filp: the file structure
2160 * @buffer: the user buffer
2161 * @lenp: the size of the user buffer
2162 * @ppos: file position
2163 *
2164 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2165 * values from/to the user buffer, treated as an ASCII string.
2166 *
2167 * This routine will ensure the values are within the range specified by
2168 * table->extra1 (min) and table->extra2 (max).
2169 *
2170 * Returns 0 on success.
2171 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002172int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 void __user *buffer, size_t *lenp, loff_t *ppos)
2174{
2175 struct do_proc_dointvec_minmax_conv_param param = {
2176 .min = (int *) table->extra1,
2177 .max = (int *) table->extra2,
2178 };
2179 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2180 do_proc_dointvec_minmax_conv, &param);
2181}
2182
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002183static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 struct file *filp,
2185 void __user *buffer,
2186 size_t *lenp, loff_t *ppos,
2187 unsigned long convmul,
2188 unsigned long convdiv)
2189{
2190#define TMPBUFLEN 21
2191 unsigned long *i, *min, *max, val;
2192 int vleft, first=1, neg;
2193 size_t len, left;
2194 char buf[TMPBUFLEN], *p;
2195 char __user *s = buffer;
2196
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002197 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 (*ppos && !write)) {
2199 *lenp = 0;
2200 return 0;
2201 }
2202
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002203 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 min = (unsigned long *) table->extra1;
2205 max = (unsigned long *) table->extra2;
2206 vleft = table->maxlen / sizeof(unsigned long);
2207 left = *lenp;
2208
2209 for (; left && vleft--; i++, min++, max++, first=0) {
2210 if (write) {
2211 while (left) {
2212 char c;
2213 if (get_user(c, s))
2214 return -EFAULT;
2215 if (!isspace(c))
2216 break;
2217 left--;
2218 s++;
2219 }
2220 if (!left)
2221 break;
2222 neg = 0;
2223 len = left;
2224 if (len > TMPBUFLEN-1)
2225 len = TMPBUFLEN-1;
2226 if (copy_from_user(buf, s, len))
2227 return -EFAULT;
2228 buf[len] = 0;
2229 p = buf;
2230 if (*p == '-' && left > 1) {
2231 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002232 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 }
2234 if (*p < '0' || *p > '9')
2235 break;
2236 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2237 len = p-buf;
2238 if ((len < left) && *p && !isspace(*p))
2239 break;
2240 if (neg)
2241 val = -val;
2242 s += len;
2243 left -= len;
2244
2245 if(neg)
2246 continue;
2247 if ((min && val < *min) || (max && val > *max))
2248 continue;
2249 *i = val;
2250 } else {
2251 p = buf;
2252 if (!first)
2253 *p++ = '\t';
2254 sprintf(p, "%lu", convdiv * (*i) / convmul);
2255 len = strlen(buf);
2256 if (len > left)
2257 len = left;
2258 if(copy_to_user(s, buf, len))
2259 return -EFAULT;
2260 left -= len;
2261 s += len;
2262 }
2263 }
2264
2265 if (!write && !first && left) {
2266 if(put_user('\n', s))
2267 return -EFAULT;
2268 left--, s++;
2269 }
2270 if (write) {
2271 while (left) {
2272 char c;
2273 if (get_user(c, s++))
2274 return -EFAULT;
2275 if (!isspace(c))
2276 break;
2277 left--;
2278 }
2279 }
2280 if (write && first)
2281 return -EINVAL;
2282 *lenp -= left;
2283 *ppos += *lenp;
2284 return 0;
2285#undef TMPBUFLEN
2286}
2287
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002288static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002289 struct file *filp,
2290 void __user *buffer,
2291 size_t *lenp, loff_t *ppos,
2292 unsigned long convmul,
2293 unsigned long convdiv)
2294{
2295 return __do_proc_doulongvec_minmax(table->data, table, write,
2296 filp, buffer, lenp, ppos, convmul, convdiv);
2297}
2298
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299/**
2300 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2301 * @table: the sysctl table
2302 * @write: %TRUE if this is a write to the sysctl file
2303 * @filp: the file structure
2304 * @buffer: the user buffer
2305 * @lenp: the size of the user buffer
2306 * @ppos: file position
2307 *
2308 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2309 * values from/to the user buffer, treated as an ASCII string.
2310 *
2311 * This routine will ensure the values are within the range specified by
2312 * table->extra1 (min) and table->extra2 (max).
2313 *
2314 * Returns 0 on success.
2315 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002316int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 void __user *buffer, size_t *lenp, loff_t *ppos)
2318{
2319 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2320}
2321
2322/**
2323 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2324 * @table: the sysctl table
2325 * @write: %TRUE if this is a write to the sysctl file
2326 * @filp: the file structure
2327 * @buffer: the user buffer
2328 * @lenp: the size of the user buffer
2329 * @ppos: file position
2330 *
2331 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2332 * values from/to the user buffer, treated as an ASCII string. The values
2333 * are treated as milliseconds, and converted to jiffies when they are stored.
2334 *
2335 * This routine will ensure the values are within the range specified by
2336 * table->extra1 (min) and table->extra2 (max).
2337 *
2338 * Returns 0 on success.
2339 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002340int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 struct file *filp,
2342 void __user *buffer,
2343 size_t *lenp, loff_t *ppos)
2344{
2345 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2346 lenp, ppos, HZ, 1000l);
2347}
2348
2349
2350static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2351 int *valp,
2352 int write, void *data)
2353{
2354 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002355 if (*lvalp > LONG_MAX / HZ)
2356 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2358 } else {
2359 int val = *valp;
2360 unsigned long lval;
2361 if (val < 0) {
2362 *negp = -1;
2363 lval = (unsigned long)-val;
2364 } else {
2365 *negp = 0;
2366 lval = (unsigned long)val;
2367 }
2368 *lvalp = lval / HZ;
2369 }
2370 return 0;
2371}
2372
2373static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2374 int *valp,
2375 int write, void *data)
2376{
2377 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002378 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2379 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2381 } else {
2382 int val = *valp;
2383 unsigned long lval;
2384 if (val < 0) {
2385 *negp = -1;
2386 lval = (unsigned long)-val;
2387 } else {
2388 *negp = 0;
2389 lval = (unsigned long)val;
2390 }
2391 *lvalp = jiffies_to_clock_t(lval);
2392 }
2393 return 0;
2394}
2395
2396static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2397 int *valp,
2398 int write, void *data)
2399{
2400 if (write) {
2401 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2402 } else {
2403 int val = *valp;
2404 unsigned long lval;
2405 if (val < 0) {
2406 *negp = -1;
2407 lval = (unsigned long)-val;
2408 } else {
2409 *negp = 0;
2410 lval = (unsigned long)val;
2411 }
2412 *lvalp = jiffies_to_msecs(lval);
2413 }
2414 return 0;
2415}
2416
2417/**
2418 * proc_dointvec_jiffies - read a vector of integers as seconds
2419 * @table: the sysctl table
2420 * @write: %TRUE if this is a write to the sysctl file
2421 * @filp: the file structure
2422 * @buffer: the user buffer
2423 * @lenp: the size of the user buffer
2424 * @ppos: file position
2425 *
2426 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2427 * values from/to the user buffer, treated as an ASCII string.
2428 * The values read are assumed to be in seconds, and are converted into
2429 * jiffies.
2430 *
2431 * Returns 0 on success.
2432 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002433int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 void __user *buffer, size_t *lenp, loff_t *ppos)
2435{
2436 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2437 do_proc_dointvec_jiffies_conv,NULL);
2438}
2439
2440/**
2441 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @filp: the file structure
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002447 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 *
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2451 * The values read are assumed to be in 1/USER_HZ seconds, and
2452 * are converted into jiffies.
2453 *
2454 * Returns 0 on success.
2455 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002456int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 void __user *buffer, size_t *lenp, loff_t *ppos)
2458{
2459 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2460 do_proc_dointvec_userhz_jiffies_conv,NULL);
2461}
2462
2463/**
2464 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2465 * @table: the sysctl table
2466 * @write: %TRUE if this is a write to the sysctl file
2467 * @filp: the file structure
2468 * @buffer: the user buffer
2469 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002470 * @ppos: file position
2471 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 *
2473 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2474 * values from/to the user buffer, treated as an ASCII string.
2475 * The values read are assumed to be in 1/1000 seconds, and
2476 * are converted into jiffies.
2477 *
2478 * Returns 0 on success.
2479 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002480int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 void __user *buffer, size_t *lenp, loff_t *ppos)
2482{
2483 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2484 do_proc_dointvec_ms_jiffies_conv, NULL);
2485}
2486
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002487static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002488 void __user *buffer, size_t *lenp, loff_t *ppos)
2489{
2490 struct pid *new_pid;
2491 pid_t tmp;
2492 int r;
2493
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002494 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002495
2496 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2497 lenp, ppos, NULL, NULL);
2498 if (r || !write)
2499 return r;
2500
2501 new_pid = find_get_pid(tmp);
2502 if (!new_pid)
2503 return -ESRCH;
2504
2505 put_pid(xchg(&cad_pid, new_pid));
2506 return 0;
2507}
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509#else /* CONFIG_PROC_FS */
2510
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002511int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 void __user *buffer, size_t *lenp, loff_t *ppos)
2513{
2514 return -ENOSYS;
2515}
2516
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002517int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 void __user *buffer, size_t *lenp, loff_t *ppos)
2519{
2520 return -ENOSYS;
2521}
2522
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002523int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 void __user *buffer, size_t *lenp, loff_t *ppos)
2525{
2526 return -ENOSYS;
2527}
2528
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002529int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 void __user *buffer, size_t *lenp, loff_t *ppos)
2531{
2532 return -ENOSYS;
2533}
2534
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002535int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 void __user *buffer, size_t *lenp, loff_t *ppos)
2537{
2538 return -ENOSYS;
2539}
2540
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002541int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 void __user *buffer, size_t *lenp, loff_t *ppos)
2543{
2544 return -ENOSYS;
2545}
2546
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002547int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 void __user *buffer, size_t *lenp, loff_t *ppos)
2549{
2550 return -ENOSYS;
2551}
2552
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002553int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 struct file *filp,
2555 void __user *buffer,
2556 size_t *lenp, loff_t *ppos)
2557{
2558 return -ENOSYS;
2559}
2560
2561
2562#endif /* CONFIG_PROC_FS */
2563
2564
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002565#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566/*
2567 * General sysctl support routines
2568 */
2569
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002570/* The generic sysctl data routine (used if no strategy routine supplied) */
2571int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2572 void __user *oldval, size_t __user *oldlenp,
2573 void __user *newval, size_t newlen)
2574{
2575 size_t len;
2576
2577 /* Get out of I don't have a variable */
2578 if (!table->data || !table->maxlen)
2579 return -ENOTDIR;
2580
2581 if (oldval && oldlenp) {
2582 if (get_user(len, oldlenp))
2583 return -EFAULT;
2584 if (len) {
2585 if (len > table->maxlen)
2586 len = table->maxlen;
2587 if (copy_to_user(oldval, table->data, len))
2588 return -EFAULT;
2589 if (put_user(len, oldlenp))
2590 return -EFAULT;
2591 }
2592 }
2593
2594 if (newval && newlen) {
2595 if (newlen > table->maxlen)
2596 newlen = table->maxlen;
2597
2598 if (copy_from_user(table->data, newval, newlen))
2599 return -EFAULT;
2600 }
2601 return 1;
2602}
2603
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002605int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002607 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 if (!table->data || !table->maxlen)
2610 return -ENOTDIR;
2611
2612 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002613 size_t bufsize;
2614 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002616 if (bufsize) {
2617 size_t len = strlen(table->data), copied;
2618
2619 /* This shouldn't trigger for a well-formed sysctl */
2620 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002622
2623 /* Copy up to a max of bufsize-1 bytes of the string */
2624 copied = (len >= bufsize) ? bufsize - 1 : len;
2625
2626 if (copy_to_user(oldval, table->data, copied) ||
2627 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002629 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 return -EFAULT;
2631 }
2632 }
2633 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002634 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 if (len > table->maxlen)
2636 len = table->maxlen;
2637 if(copy_from_user(table->data, newval, len))
2638 return -EFAULT;
2639 if (len == table->maxlen)
2640 len--;
2641 ((char *) table->data)[len] = 0;
2642 }
Yi Yang82c9df82005-12-30 16:37:10 +08002643 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644}
2645
2646/*
2647 * This function makes sure that all of the integers in the vector
2648 * are between the minimum and maximum values given in the arrays
2649 * table->extra1 and table->extra2, respectively.
2650 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002651int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002653 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654{
2655
2656 if (newval && newlen) {
2657 int __user *vec = (int __user *) newval;
2658 int *min = (int *) table->extra1;
2659 int *max = (int *) table->extra2;
2660 size_t length;
2661 int i;
2662
2663 if (newlen % sizeof(int) != 0)
2664 return -EINVAL;
2665
2666 if (!table->extra1 && !table->extra2)
2667 return 0;
2668
2669 if (newlen > table->maxlen)
2670 newlen = table->maxlen;
2671 length = newlen / sizeof(int);
2672
2673 for (i = 0; i < length; i++) {
2674 int value;
2675 if (get_user(value, vec + i))
2676 return -EFAULT;
2677 if (min && value < min[i])
2678 return -EINVAL;
2679 if (max && value > max[i])
2680 return -EINVAL;
2681 }
2682 }
2683 return 0;
2684}
2685
2686/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002687int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002689 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002691 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002693
2694 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002696 if (olen) {
2697 int val;
2698
2699 if (olen < sizeof(int))
2700 return -EINVAL;
2701
2702 val = *(int *)(table->data) / HZ;
2703 if (put_user(val, (int __user *)oldval))
2704 return -EFAULT;
2705 if (put_user(sizeof(int), oldlenp))
2706 return -EFAULT;
2707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 }
2709 if (newval && newlen) {
2710 int new;
2711 if (newlen != sizeof(int))
2712 return -EINVAL;
2713 if (get_user(new, (int __user *)newval))
2714 return -EFAULT;
2715 *(int *)(table->data) = new*HZ;
2716 }
2717 return 1;
2718}
2719
2720/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002721int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002723 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002725 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002727
2728 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002730 if (olen) {
2731 int val;
2732
2733 if (olen < sizeof(int))
2734 return -EINVAL;
2735
2736 val = jiffies_to_msecs(*(int *)(table->data));
2737 if (put_user(val, (int __user *)oldval))
2738 return -EFAULT;
2739 if (put_user(sizeof(int), oldlenp))
2740 return -EFAULT;
2741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 }
2743 if (newval && newlen) {
2744 int new;
2745 if (newlen != sizeof(int))
2746 return -EINVAL;
2747 if (get_user(new, (int __user *)newval))
2748 return -EFAULT;
2749 *(int *)(table->data) = msecs_to_jiffies(new);
2750 }
2751 return 1;
2752}
2753
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002754
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002755
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002756#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
2758
2759asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2760{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002761 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002762 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002763
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002764 if (copy_from_user(&tmp, args, sizeof(tmp)))
2765 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002766
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002767 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002768
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002769 /* If no error reading the parameters then just -ENOSYS ... */
2770 if (!error)
2771 error = -ENOSYS;
2772
2773 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774}
2775
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002776int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2777 void __user *oldval, size_t __user *oldlenp,
2778 void __user *newval, size_t newlen)
2779{
2780 return -ENOSYS;
2781}
2782
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002783int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002785 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786{
2787 return -ENOSYS;
2788}
2789
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002790int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002792 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793{
2794 return -ENOSYS;
2795}
2796
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002797int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002799 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800{
2801 return -ENOSYS;
2802}
2803
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002804int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002806 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807{
2808 return -ENOSYS;
2809}
2810
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002811#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002813static int deprecated_sysctl_warning(struct __sysctl_args *args)
2814{
2815 static int msg_count;
2816 int name[CTL_MAXNAME];
2817 int i;
2818
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002819 /* Check args->nlen. */
2820 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2821 return -ENOTDIR;
2822
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002823 /* Read in the sysctl name for better debug message logging */
2824 for (i = 0; i < args->nlen; i++)
2825 if (get_user(name[i], args->name + i))
2826 return -EFAULT;
2827
2828 /* Ignore accesses to kernel.version */
2829 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2830 return 0;
2831
2832 if (msg_count < 5) {
2833 msg_count++;
2834 printk(KERN_INFO
2835 "warning: process `%s' used the deprecated sysctl "
2836 "system call with ", current->comm);
2837 for (i = 0; i < args->nlen; i++)
2838 printk("%d.", name[i]);
2839 printk("\n");
2840 }
2841 return 0;
2842}
2843
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844/*
2845 * No sense putting this after each symbol definition, twice,
2846 * exception granted :-)
2847 */
2848EXPORT_SYMBOL(proc_dointvec);
2849EXPORT_SYMBOL(proc_dointvec_jiffies);
2850EXPORT_SYMBOL(proc_dointvec_minmax);
2851EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2852EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2853EXPORT_SYMBOL(proc_dostring);
2854EXPORT_SYMBOL(proc_doulongvec_minmax);
2855EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2856EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002857EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858EXPORT_SYMBOL(sysctl_intvec);
2859EXPORT_SYMBOL(sysctl_jiffies);
2860EXPORT_SYMBOL(sysctl_ms_jiffies);
2861EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002862EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863EXPORT_SYMBOL(unregister_sysctl_table);