blob: da5152088cc385808a7dd77a01f3e45b6d122d5c [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>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include <asm/uaccess.h>
53#include <asm/processor.h>
54
Andi Kleen29cbc782006-09-30 01:47:55 +020055#ifdef CONFIG_X86
56#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010057#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010058#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020059#endif
60
Eric W. Biederman7058cb02007-10-18 03:05:58 -070061static int deprecated_sysctl_warning(struct __sysctl_args *args);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#if defined(CONFIG_SYSCTL)
64
65/* External variables not in a header file. */
66extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070067extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int sysctl_overcommit_memory;
69extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070070extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070071extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080072extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070075extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max;
78extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080080extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080081extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020082extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070083extern int maps_protect;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070086#ifdef CONFIG_RCU_TORTURE_TEST
87extern int rcutorture_runnable;
88#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070090/* Constants used for minimum and maximum */
Ingo Molnar1c4cd6d2008-05-12 21:21:14 +020091#if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092static int one = 1;
Bron Gondwana195cf4532008-02-04 22:29:20 -080093#endif
94
95#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020097static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098#endif
99
100#ifdef CONFIG_MMU
101static int two = 2;
102#endif
103
104static int zero;
105static int one_hundred = 100;
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108static int maxolduid = 65535;
109static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112static int ngroups_max = NGROUPS_MAX;
113
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200114#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115extern char modprobe_path[];
116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#ifdef CONFIG_CHR_DEV_SG
118extern int sg_big_buff;
119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
David S. Miller72c57ed2008-09-11 23:29:54 -0700121#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700122#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#endif
124
125#ifdef __hppa__
126extern int pwrsw_enabled;
127extern int unaligned_enabled;
128#endif
129
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800130#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#ifdef CONFIG_MATHEMU
132extern int sysctl_ieee_emulation_warnings;
133#endif
134extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700135extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#endif
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#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 Molnar23f78d4a2006-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,
Al Viro73455092008-07-14 21:22:20 -0400161 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100162 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400163 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100164};
165static struct ctl_table_root sysctl_table_root = {
166 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400167 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700170static struct ctl_table kern_table[];
171static struct ctl_table vm_table[];
172static struct ctl_table fs_table[];
173static struct ctl_table debug_table[];
174static struct ctl_table dev_table[];
175extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700176#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700177extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400178#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
181int sysctl_legacy_va_layout;
182#endif
183
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700184extern int prove_locking;
185extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/* The default sysctl tables: */
188
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700189static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 {
191 .ctl_name = CTL_KERN,
192 .procname = "kernel",
193 .mode = 0555,
194 .child = kern_table,
195 },
196 {
197 .ctl_name = CTL_VM,
198 .procname = "vm",
199 .mode = 0555,
200 .child = vm_table,
201 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
207 },
208 {
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
213 },
214 {
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
219 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700220/*
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 { .ctl_name = 0 }
225};
226
Ingo Molnar77e54a12007-07-09 18:52:00 +0200227#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100228static int min_sched_granularity_ns = 100000; /* 100 usecs */
229static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230static int min_wakeup_granularity_ns; /* 0 usecs */
231static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200232#endif
233
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700234static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#ifdef CONFIG_SCHED_DEBUG
236 {
237 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240 .maxlen = sizeof(unsigned int),
241 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246 },
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200271 .procname = "sched_shares_ratelimit",
272 .data = &sysctl_sched_shares_ratelimit,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec,
276 },
277 {
278 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200279 .procname = "sched_child_runs_first",
280 .data = &sysctl_sched_child_runs_first,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec,
284 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200285 {
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_features",
288 .data = &sysctl_sched_features,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = &proc_dointvec,
292 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200293 {
294 .ctl_name = CTL_UNNUMBERED,
295 .procname = "sched_migration_cost",
296 .data = &sysctl_sched_migration_cost,
297 .maxlen = sizeof(unsigned int),
298 .mode = 0644,
299 .proc_handler = &proc_dointvec,
300 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100301 {
302 .ctl_name = CTL_UNNUMBERED,
303 .procname = "sched_nr_migrate",
304 .data = &sysctl_sched_nr_migrate,
305 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100306 .mode = 0644,
307 .proc_handler = &proc_dointvec,
308 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200309#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200310 {
311 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100312 .procname = "sched_rt_period_us",
313 .data = &sysctl_sched_rt_period,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200316 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100317 },
318 {
319 .ctl_name = CTL_UNNUMBERED,
320 .procname = "sched_rt_runtime_us",
321 .data = &sysctl_sched_rt_runtime,
322 .maxlen = sizeof(int),
323 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200324 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100325 },
326 {
327 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200328 .procname = "sched_compat_yield",
329 .data = &sysctl_sched_compat_yield,
330 .maxlen = sizeof(unsigned int),
331 .mode = 0644,
332 .proc_handler = &proc_dointvec,
333 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700334#ifdef CONFIG_PROVE_LOCKING
335 {
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "prove_locking",
338 .data = &prove_locking,
339 .maxlen = sizeof(int),
340 .mode = 0644,
341 .proc_handler = &proc_dointvec,
342 },
343#endif
344#ifdef CONFIG_LOCK_STAT
345 {
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "lock_stat",
348 .data = &lock_stat,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
352 },
353#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 .ctl_name = KERN_PANIC,
356 .procname = "panic",
357 .data = &panic_timeout,
358 .maxlen = sizeof(int),
359 .mode = 0644,
360 .proc_handler = &proc_dointvec,
361 },
362 {
363 .ctl_name = KERN_CORE_USES_PID,
364 .procname = "core_uses_pid",
365 .data = &core_uses_pid,
366 .maxlen = sizeof(int),
367 .mode = 0644,
368 .proc_handler = &proc_dointvec,
369 },
370 {
371 .ctl_name = KERN_CORE_PATTERN,
372 .procname = "core_pattern",
373 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700374 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 .mode = 0644,
376 .proc_handler = &proc_dostring,
377 .strategy = &sysctl_string,
378 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800379#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 .procname = "tainted",
382 .data = &tainted,
383 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800384 .mode = 0644,
385 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800387#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100388#ifdef CONFIG_LATENCYTOP
389 {
390 .procname = "latencytop",
391 .data = &latencytop_enabled,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = &proc_dointvec,
395 },
396#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397#ifdef CONFIG_BLK_DEV_INITRD
398 {
399 .ctl_name = KERN_REALROOTDEV,
400 .procname = "real-root-dev",
401 .data = &real_root_dev,
402 .maxlen = sizeof(int),
403 .mode = 0644,
404 .proc_handler = &proc_dointvec,
405 },
406#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700407 {
408 .ctl_name = CTL_UNNUMBERED,
409 .procname = "print-fatal-signals",
410 .data = &print_fatal_signals,
411 .maxlen = sizeof(int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
414 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700415#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 {
417 .ctl_name = KERN_SPARC_REBOOT,
418 .procname = "reboot-cmd",
419 .data = reboot_command,
420 .maxlen = 256,
421 .mode = 0644,
422 .proc_handler = &proc_dostring,
423 .strategy = &sysctl_string,
424 },
425 {
426 .ctl_name = KERN_SPARC_STOP_A,
427 .procname = "stop-a",
428 .data = &stop_a_enabled,
429 .maxlen = sizeof (int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
432 },
433 {
434 .ctl_name = KERN_SPARC_SCONS_PWROFF,
435 .procname = "scons-poweroff",
436 .data = &scons_pwroff,
437 .maxlen = sizeof (int),
438 .mode = 0644,
439 .proc_handler = &proc_dointvec,
440 },
441#endif
442#ifdef __hppa__
443 {
444 .ctl_name = KERN_HPPA_PWRSW,
445 .procname = "soft-power",
446 .data = &pwrsw_enabled,
447 .maxlen = sizeof (int),
448 .mode = 0644,
449 .proc_handler = &proc_dointvec,
450 },
451 {
452 .ctl_name = KERN_HPPA_UNALIGNED,
453 .procname = "unaligned-trap",
454 .data = &unaligned_enabled,
455 .maxlen = sizeof (int),
456 .mode = 0644,
457 .proc_handler = &proc_dointvec,
458 },
459#endif
460 {
461 .ctl_name = KERN_CTLALTDEL,
462 .procname = "ctrl-alt-del",
463 .data = &C_A_D,
464 .maxlen = sizeof(int),
465 .mode = 0644,
466 .proc_handler = &proc_dointvec,
467 },
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200468#ifdef CONFIG_FTRACE
469 {
470 .ctl_name = CTL_UNNUMBERED,
471 .procname = "ftrace_enabled",
472 .data = &ftrace_enabled,
473 .maxlen = sizeof(int),
474 .mode = 0644,
475 .proc_handler = &ftrace_enable_sysctl,
476 },
477#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200478#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 {
480 .ctl_name = KERN_MODPROBE,
481 .procname = "modprobe",
482 .data = &modprobe_path,
483 .maxlen = KMOD_PATH_LEN,
484 .mode = 0644,
485 .proc_handler = &proc_dostring,
486 .strategy = &sysctl_string,
487 },
488#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700489#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 {
491 .ctl_name = KERN_HOTPLUG,
492 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100493 .data = &uevent_helper,
494 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .mode = 0644,
496 .proc_handler = &proc_dostring,
497 .strategy = &sysctl_string,
498 },
499#endif
500#ifdef CONFIG_CHR_DEV_SG
501 {
502 .ctl_name = KERN_SG_BIG_BUFF,
503 .procname = "sg-big-buff",
504 .data = &sg_big_buff,
505 .maxlen = sizeof (int),
506 .mode = 0444,
507 .proc_handler = &proc_dointvec,
508 },
509#endif
510#ifdef CONFIG_BSD_PROCESS_ACCT
511 {
512 .ctl_name = KERN_ACCT,
513 .procname = "acct",
514 .data = &acct_parm,
515 .maxlen = 3*sizeof(int),
516 .mode = 0644,
517 .proc_handler = &proc_dointvec,
518 },
519#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#ifdef CONFIG_MAGIC_SYSRQ
521 {
522 .ctl_name = KERN_SYSRQ,
523 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800524 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 .maxlen = sizeof (int),
526 .mode = 0644,
527 .proc_handler = &proc_dointvec,
528 },
529#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700530#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700533 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 .maxlen = sizeof (int),
535 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700536 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700538#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 {
540 .ctl_name = KERN_MAX_THREADS,
541 .procname = "threads-max",
542 .data = &max_threads,
543 .maxlen = sizeof(int),
544 .mode = 0644,
545 .proc_handler = &proc_dointvec,
546 },
547 {
548 .ctl_name = KERN_RANDOM,
549 .procname = "random",
550 .mode = 0555,
551 .child = random_table,
552 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 {
554 .ctl_name = KERN_OVERFLOWUID,
555 .procname = "overflowuid",
556 .data = &overflowuid,
557 .maxlen = sizeof(int),
558 .mode = 0644,
559 .proc_handler = &proc_dointvec_minmax,
560 .strategy = &sysctl_intvec,
561 .extra1 = &minolduid,
562 .extra2 = &maxolduid,
563 },
564 {
565 .ctl_name = KERN_OVERFLOWGID,
566 .procname = "overflowgid",
567 .data = &overflowgid,
568 .maxlen = sizeof(int),
569 .mode = 0644,
570 .proc_handler = &proc_dointvec_minmax,
571 .strategy = &sysctl_intvec,
572 .extra1 = &minolduid,
573 .extra2 = &maxolduid,
574 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800575#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576#ifdef CONFIG_MATHEMU
577 {
578 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
579 .procname = "ieee_emulation_warnings",
580 .data = &sysctl_ieee_emulation_warnings,
581 .maxlen = sizeof(int),
582 .mode = 0644,
583 .proc_handler = &proc_dointvec,
584 },
585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 {
587 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
588 .procname = "userprocess_debug",
589 .data = &sysctl_userprocess_debug,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec,
593 },
594#endif
595 {
596 .ctl_name = KERN_PIDMAX,
597 .procname = "pid_max",
598 .data = &pid_max,
599 .maxlen = sizeof (int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec_minmax,
602 .strategy = sysctl_intvec,
603 .extra1 = &pid_max_min,
604 .extra2 = &pid_max_max,
605 },
606 {
607 .ctl_name = KERN_PANIC_ON_OOPS,
608 .procname = "panic_on_oops",
609 .data = &panic_on_oops,
610 .maxlen = sizeof(int),
611 .mode = 0644,
612 .proc_handler = &proc_dointvec,
613 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800614#if defined CONFIG_PRINTK
615 {
616 .ctl_name = KERN_PRINTK,
617 .procname = "printk",
618 .data = &console_loglevel,
619 .maxlen = 4*sizeof(int),
620 .mode = 0644,
621 .proc_handler = &proc_dointvec,
622 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 {
624 .ctl_name = KERN_PRINTK_RATELIMIT,
625 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700626 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = &proc_dointvec_jiffies,
630 .strategy = &sysctl_jiffies,
631 },
632 {
633 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
634 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700635 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec,
639 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800640#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 {
642 .ctl_name = KERN_NGROUPS_MAX,
643 .procname = "ngroups_max",
644 .data = &ngroups_max,
645 .maxlen = sizeof (int),
646 .mode = 0444,
647 .proc_handler = &proc_dointvec,
648 },
649#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
650 {
651 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
652 .procname = "unknown_nmi_panic",
653 .data = &unknown_nmi_panic,
654 .maxlen = sizeof (int),
655 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200656 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 },
Don Zickus407984f2006-09-26 10:52:27 +0200658 {
Don Zickus407984f2006-09-26 10:52:27 +0200659 .procname = "nmi_watchdog",
660 .data = &nmi_watchdog_enabled,
661 .maxlen = sizeof (int),
662 .mode = 0644,
663 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 },
665#endif
666#if defined(CONFIG_X86)
667 {
Don Zickus8da5add2006-09-26 10:52:27 +0200668 .ctl_name = KERN_PANIC_ON_NMI,
669 .procname = "panic_on_unrecovered_nmi",
670 .data = &panic_on_unrecovered_nmi,
671 .maxlen = sizeof(int),
672 .mode = 0644,
673 .proc_handler = &proc_dointvec,
674 },
675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .ctl_name = KERN_BOOTLOADER_TYPE,
677 .procname = "bootloader_type",
678 .data = &bootloader_type,
679 .maxlen = sizeof (int),
680 .mode = 0444,
681 .proc_handler = &proc_dointvec,
682 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100683 {
684 .ctl_name = CTL_UNNUMBERED,
685 .procname = "kstack_depth_to_print",
686 .data = &kstack_depth_to_print,
687 .maxlen = sizeof(int),
688 .mode = 0644,
689 .proc_handler = &proc_dointvec,
690 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100691 {
692 .ctl_name = CTL_UNNUMBERED,
693 .procname = "io_delay_type",
694 .data = &io_delay_type,
695 .maxlen = sizeof(int),
696 .mode = 0644,
697 .proc_handler = &proc_dointvec,
698 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800700#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
702 .ctl_name = KERN_RANDOMIZE,
703 .procname = "randomize_va_space",
704 .data = &randomize_va_space,
705 .maxlen = sizeof(int),
706 .mode = 0644,
707 .proc_handler = &proc_dointvec,
708 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800709#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800710#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700711 {
712 .ctl_name = KERN_SPIN_RETRY,
713 .procname = "spin_retry",
714 .data = &spin_retry,
715 .maxlen = sizeof (int),
716 .mode = 0644,
717 .proc_handler = &proc_dointvec,
718 },
719#endif
Len Brown673d5b42007-07-28 03:33:16 -0400720#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800721 {
Pavel Machekc255d842006-02-20 18:27:58 -0800722 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700723 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800724 .maxlen = sizeof (unsigned long),
725 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800726 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800727 },
728#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800729#ifdef CONFIG_IA64
730 {
731 .ctl_name = KERN_IA64_UNALIGNED,
732 .procname = "ignore-unaligned-usertrap",
733 .data = &no_unaligned_warning,
734 .maxlen = sizeof (int),
735 .mode = 0644,
736 .proc_handler = &proc_dointvec,
737 },
738#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700739#ifdef CONFIG_DETECT_SOFTLOCKUP
740 {
741 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200742 .procname = "softlockup_panic",
743 .data = &softlockup_panic,
744 .maxlen = sizeof(int),
745 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700746 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200747 .strategy = &sysctl_intvec,
748 .extra1 = &zero,
749 .extra2 = &one,
750 },
751 {
752 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700753 .procname = "softlockup_thresh",
754 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200755 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700756 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200757 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700758 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200759 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700760 .extra2 = &sixty,
761 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100762 {
763 .ctl_name = CTL_UNNUMBERED,
764 .procname = "hung_task_check_count",
765 .data = &sysctl_hung_task_check_count,
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_timeout_secs",
774 .data = &sysctl_hung_task_timeout_secs,
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 },
780 {
781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "hung_task_warnings",
783 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100784 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100785 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100786 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100787 .strategy = &sysctl_intvec,
788 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700789#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200790#ifdef CONFIG_COMPAT
791 {
792 .ctl_name = KERN_COMPAT_LOG,
793 .procname = "compat-log",
794 .data = &compat_log,
795 .maxlen = sizeof (int),
796 .mode = 0644,
797 .proc_handler = &proc_dointvec,
798 },
799#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700800#ifdef CONFIG_RT_MUTEXES
801 {
802 .ctl_name = KERN_MAX_LOCK_DEPTH,
803 .procname = "max_lock_depth",
804 .data = &max_lock_depth,
805 .maxlen = sizeof(int),
806 .mode = 0644,
807 .proc_handler = &proc_dointvec,
808 },
809#endif
Kees Cook5096add2007-05-08 00:26:04 -0700810#ifdef CONFIG_PROC_FS
811 {
812 .ctl_name = CTL_UNNUMBERED,
813 .procname = "maps_protect",
814 .data = &maps_protect,
815 .maxlen = sizeof(int),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec,
818 },
819#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700820 {
821 .ctl_name = CTL_UNNUMBERED,
822 .procname = "poweroff_cmd",
823 .data = &poweroff_cmd,
824 .maxlen = POWEROFF_CMD_PATH_LEN,
825 .mode = 0644,
826 .proc_handler = &proc_dostring,
827 .strategy = &sysctl_string,
828 },
David Howells0b77f5b2008-04-29 01:01:32 -0700829#ifdef CONFIG_KEYS
830 {
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "keys",
833 .mode = 0555,
834 .child = key_sysctls,
835 },
836#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700837#ifdef CONFIG_RCU_TORTURE_TEST
838 {
839 .ctl_name = CTL_UNNUMBERED,
840 .procname = "rcutorture_runnable",
841 .data = &rcutorture_runnable,
842 .maxlen = sizeof(int),
843 .mode = 0644,
844 .proc_handler = &proc_dointvec,
845 },
846#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700847/*
848 * NOTE: do not add new entries to this table unless you have read
849 * Documentation/sysctl/ctl_unnumbered.txt
850 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 { .ctl_name = 0 }
852};
853
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700854static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 {
856 .ctl_name = VM_OVERCOMMIT_MEMORY,
857 .procname = "overcommit_memory",
858 .data = &sysctl_overcommit_memory,
859 .maxlen = sizeof(sysctl_overcommit_memory),
860 .mode = 0644,
861 .proc_handler = &proc_dointvec,
862 },
863 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700864 .ctl_name = VM_PANIC_ON_OOM,
865 .procname = "panic_on_oom",
866 .data = &sysctl_panic_on_oom,
867 .maxlen = sizeof(sysctl_panic_on_oom),
868 .mode = 0644,
869 .proc_handler = &proc_dointvec,
870 },
871 {
David Rientjesfe071d72007-10-16 23:25:56 -0700872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "oom_kill_allocating_task",
874 .data = &sysctl_oom_kill_allocating_task,
875 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec,
878 },
879 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800880 .ctl_name = CTL_UNNUMBERED,
881 .procname = "oom_dump_tasks",
882 .data = &sysctl_oom_dump_tasks,
883 .maxlen = sizeof(sysctl_oom_dump_tasks),
884 .mode = 0644,
885 .proc_handler = &proc_dointvec,
886 },
887 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 .ctl_name = VM_OVERCOMMIT_RATIO,
889 .procname = "overcommit_ratio",
890 .data = &sysctl_overcommit_ratio,
891 .maxlen = sizeof(sysctl_overcommit_ratio),
892 .mode = 0644,
893 .proc_handler = &proc_dointvec,
894 },
895 {
896 .ctl_name = VM_PAGE_CLUSTER,
897 .procname = "page-cluster",
898 .data = &page_cluster,
899 .maxlen = sizeof(int),
900 .mode = 0644,
901 .proc_handler = &proc_dointvec,
902 },
903 {
904 .ctl_name = VM_DIRTY_BACKGROUND,
905 .procname = "dirty_background_ratio",
906 .data = &dirty_background_ratio,
907 .maxlen = sizeof(dirty_background_ratio),
908 .mode = 0644,
909 .proc_handler = &proc_dointvec_minmax,
910 .strategy = &sysctl_intvec,
911 .extra1 = &zero,
912 .extra2 = &one_hundred,
913 },
914 {
915 .ctl_name = VM_DIRTY_RATIO,
916 .procname = "dirty_ratio",
917 .data = &vm_dirty_ratio,
918 .maxlen = sizeof(vm_dirty_ratio),
919 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700920 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 .strategy = &sysctl_intvec,
922 .extra1 = &zero,
923 .extra2 = &one_hundred,
924 },
925 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800927 .data = &dirty_writeback_interval,
928 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 .mode = 0644,
930 .proc_handler = &dirty_writeback_centisecs_handler,
931 },
932 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800934 .data = &dirty_expire_interval,
935 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800937 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 },
939 {
940 .ctl_name = VM_NR_PDFLUSH_THREADS,
941 .procname = "nr_pdflush_threads",
942 .data = &nr_pdflush_threads,
943 .maxlen = sizeof nr_pdflush_threads,
944 .mode = 0444 /* read-only*/,
945 .proc_handler = &proc_dointvec,
946 },
947 {
948 .ctl_name = VM_SWAPPINESS,
949 .procname = "swappiness",
950 .data = &vm_swappiness,
951 .maxlen = sizeof(vm_swappiness),
952 .mode = 0644,
953 .proc_handler = &proc_dointvec_minmax,
954 .strategy = &sysctl_intvec,
955 .extra1 = &zero,
956 .extra2 = &one_hundred,
957 },
958#ifdef CONFIG_HUGETLB_PAGE
959 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700961 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 .maxlen = sizeof(unsigned long),
963 .mode = 0644,
964 .proc_handler = &hugetlb_sysctl_handler,
965 .extra1 = (void *)&hugetlb_zero,
966 .extra2 = (void *)&hugetlb_infinity,
967 },
968 {
969 .ctl_name = VM_HUGETLB_GROUP,
970 .procname = "hugetlb_shm_group",
971 .data = &sysctl_hugetlb_shm_group,
972 .maxlen = sizeof(gid_t),
973 .mode = 0644,
974 .proc_handler = &proc_dointvec,
975 },
Mel Gorman396faf02007-07-17 04:03:13 -0700976 {
977 .ctl_name = CTL_UNNUMBERED,
978 .procname = "hugepages_treat_as_movable",
979 .data = &hugepages_treat_as_movable,
980 .maxlen = sizeof(int),
981 .mode = 0644,
982 .proc_handler = &hugetlb_treat_movable_handler,
983 },
Adam Litke54f9f802007-10-16 01:26:20 -0700984 {
985 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800986 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700987 .data = NULL,
988 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800989 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800990 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -0700991 .extra1 = (void *)&hugetlb_zero,
992 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800993 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994#endif
995 {
996 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
997 .procname = "lowmem_reserve_ratio",
998 .data = &sysctl_lowmem_reserve_ratio,
999 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1000 .mode = 0644,
1001 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1002 .strategy = &sysctl_intvec,
1003 },
1004 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001005 .ctl_name = VM_DROP_PAGECACHE,
1006 .procname = "drop_caches",
1007 .data = &sysctl_drop_caches,
1008 .maxlen = sizeof(int),
1009 .mode = 0644,
1010 .proc_handler = drop_caches_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1012 },
1013 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 .ctl_name = VM_MIN_FREE_KBYTES,
1015 .procname = "min_free_kbytes",
1016 .data = &min_free_kbytes,
1017 .maxlen = sizeof(min_free_kbytes),
1018 .mode = 0644,
1019 .proc_handler = &min_free_kbytes_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1021 .extra1 = &zero,
1022 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001023 {
1024 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1025 .procname = "percpu_pagelist_fraction",
1026 .data = &percpu_pagelist_fraction,
1027 .maxlen = sizeof(percpu_pagelist_fraction),
1028 .mode = 0644,
1029 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1030 .strategy = &sysctl_intvec,
1031 .extra1 = &min_percpu_pagelist_fract,
1032 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033#ifdef CONFIG_MMU
1034 {
1035 .ctl_name = VM_MAX_MAP_COUNT,
1036 .procname = "max_map_count",
1037 .data = &sysctl_max_map_count,
1038 .maxlen = sizeof(sysctl_max_map_count),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec
1041 },
1042#endif
1043 {
1044 .ctl_name = VM_LAPTOP_MODE,
1045 .procname = "laptop_mode",
1046 .data = &laptop_mode,
1047 .maxlen = sizeof(laptop_mode),
1048 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001049 .proc_handler = &proc_dointvec_jiffies,
1050 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 },
1052 {
1053 .ctl_name = VM_BLOCK_DUMP,
1054 .procname = "block_dump",
1055 .data = &block_dump,
1056 .maxlen = sizeof(block_dump),
1057 .mode = 0644,
1058 .proc_handler = &proc_dointvec,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &zero,
1061 },
1062 {
1063 .ctl_name = VM_VFS_CACHE_PRESSURE,
1064 .procname = "vfs_cache_pressure",
1065 .data = &sysctl_vfs_cache_pressure,
1066 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1067 .mode = 0644,
1068 .proc_handler = &proc_dointvec,
1069 .strategy = &sysctl_intvec,
1070 .extra1 = &zero,
1071 },
1072#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1073 {
1074 .ctl_name = VM_LEGACY_VA_LAYOUT,
1075 .procname = "legacy_va_layout",
1076 .data = &sysctl_legacy_va_layout,
1077 .maxlen = sizeof(sysctl_legacy_va_layout),
1078 .mode = 0644,
1079 .proc_handler = &proc_dointvec,
1080 .strategy = &sysctl_intvec,
1081 .extra1 = &zero,
1082 },
1083#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001084#ifdef CONFIG_NUMA
1085 {
1086 .ctl_name = VM_ZONE_RECLAIM_MODE,
1087 .procname = "zone_reclaim_mode",
1088 .data = &zone_reclaim_mode,
1089 .maxlen = sizeof(zone_reclaim_mode),
1090 .mode = 0644,
1091 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001092 .strategy = &sysctl_intvec,
1093 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001094 },
Christoph Lameter96146342006-07-03 00:24:13 -07001095 {
1096 .ctl_name = VM_MIN_UNMAPPED,
1097 .procname = "min_unmapped_ratio",
1098 .data = &sysctl_min_unmapped_ratio,
1099 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1100 .mode = 0644,
1101 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1102 .strategy = &sysctl_intvec,
1103 .extra1 = &zero,
1104 .extra2 = &one_hundred,
1105 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001106 {
1107 .ctl_name = VM_MIN_SLAB,
1108 .procname = "min_slab_ratio",
1109 .data = &sysctl_min_slab_ratio,
1110 .maxlen = sizeof(sysctl_min_slab_ratio),
1111 .mode = 0644,
1112 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1113 .strategy = &sysctl_intvec,
1114 .extra1 = &zero,
1115 .extra2 = &one_hundred,
1116 },
Christoph Lameter17436602006-01-18 17:42:32 -08001117#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001118#ifdef CONFIG_SMP
1119 {
1120 .ctl_name = CTL_UNNUMBERED,
1121 .procname = "stat_interval",
1122 .data = &sysctl_stat_interval,
1123 .maxlen = sizeof(sysctl_stat_interval),
1124 .mode = 0644,
1125 .proc_handler = &proc_dointvec_jiffies,
1126 .strategy = &sysctl_jiffies,
1127 },
1128#endif
Eric Parised032182007-06-28 15:55:21 -04001129#ifdef CONFIG_SECURITY
1130 {
1131 .ctl_name = CTL_UNNUMBERED,
1132 .procname = "mmap_min_addr",
1133 .data = &mmap_min_addr,
1134 .maxlen = sizeof(unsigned long),
1135 .mode = 0644,
1136 .proc_handler = &proc_doulongvec_minmax,
1137 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001138#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001139#ifdef CONFIG_NUMA
1140 {
1141 .ctl_name = CTL_UNNUMBERED,
1142 .procname = "numa_zonelist_order",
1143 .data = &numa_zonelist_order,
1144 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1145 .mode = 0644,
1146 .proc_handler = &numa_zonelist_order_handler,
1147 .strategy = &sysctl_string,
1148 },
1149#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001150#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001151 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001152 {
1153 .ctl_name = VM_VDSO_ENABLED,
1154 .procname = "vdso_enabled",
1155 .data = &vdso_enabled,
1156 .maxlen = sizeof(vdso_enabled),
1157 .mode = 0644,
1158 .proc_handler = &proc_dointvec,
1159 .strategy = &sysctl_intvec,
1160 .extra1 = &zero,
1161 },
1162#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001163#ifdef CONFIG_HIGHMEM
1164 {
1165 .ctl_name = CTL_UNNUMBERED,
1166 .procname = "highmem_is_dirtyable",
1167 .data = &vm_highmem_is_dirtyable,
1168 .maxlen = sizeof(vm_highmem_is_dirtyable),
1169 .mode = 0644,
1170 .proc_handler = &proc_dointvec_minmax,
1171 .strategy = &sysctl_intvec,
1172 .extra1 = &zero,
1173 .extra2 = &one,
1174 },
1175#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001176/*
1177 * NOTE: do not add new entries to this table unless you have read
1178 * Documentation/sysctl/ctl_unnumbered.txt
1179 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 { .ctl_name = 0 }
1181};
1182
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001183#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001184static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001185 { .ctl_name = 0 }
1186};
1187#endif
1188
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001189static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 {
1191 .ctl_name = FS_NRINODE,
1192 .procname = "inode-nr",
1193 .data = &inodes_stat,
1194 .maxlen = 2*sizeof(int),
1195 .mode = 0444,
1196 .proc_handler = &proc_dointvec,
1197 },
1198 {
1199 .ctl_name = FS_STATINODE,
1200 .procname = "inode-state",
1201 .data = &inodes_stat,
1202 .maxlen = 7*sizeof(int),
1203 .mode = 0444,
1204 .proc_handler = &proc_dointvec,
1205 },
1206 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 .procname = "file-nr",
1208 .data = &files_stat,
1209 .maxlen = 3*sizeof(int),
1210 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001211 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 },
1213 {
1214 .ctl_name = FS_MAXFILE,
1215 .procname = "file-max",
1216 .data = &files_stat.max_files,
1217 .maxlen = sizeof(int),
1218 .mode = 0644,
1219 .proc_handler = &proc_dointvec,
1220 },
1221 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001222 .ctl_name = CTL_UNNUMBERED,
1223 .procname = "nr_open",
1224 .data = &sysctl_nr_open,
1225 .maxlen = sizeof(int),
1226 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001227 .proc_handler = &proc_dointvec_minmax,
1228 .extra1 = &sysctl_nr_open_min,
1229 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001230 },
1231 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 .ctl_name = FS_DENTRY,
1233 .procname = "dentry-state",
1234 .data = &dentry_stat,
1235 .maxlen = 6*sizeof(int),
1236 .mode = 0444,
1237 .proc_handler = &proc_dointvec,
1238 },
1239 {
1240 .ctl_name = FS_OVERFLOWUID,
1241 .procname = "overflowuid",
1242 .data = &fs_overflowuid,
1243 .maxlen = sizeof(int),
1244 .mode = 0644,
1245 .proc_handler = &proc_dointvec_minmax,
1246 .strategy = &sysctl_intvec,
1247 .extra1 = &minolduid,
1248 .extra2 = &maxolduid,
1249 },
1250 {
1251 .ctl_name = FS_OVERFLOWGID,
1252 .procname = "overflowgid",
1253 .data = &fs_overflowgid,
1254 .maxlen = sizeof(int),
1255 .mode = 0644,
1256 .proc_handler = &proc_dointvec_minmax,
1257 .strategy = &sysctl_intvec,
1258 .extra1 = &minolduid,
1259 .extra2 = &maxolduid,
1260 },
1261 {
1262 .ctl_name = FS_LEASES,
1263 .procname = "leases-enable",
1264 .data = &leases_enable,
1265 .maxlen = sizeof(int),
1266 .mode = 0644,
1267 .proc_handler = &proc_dointvec,
1268 },
1269#ifdef CONFIG_DNOTIFY
1270 {
1271 .ctl_name = FS_DIR_NOTIFY,
1272 .procname = "dir-notify-enable",
1273 .data = &dir_notify_enable,
1274 .maxlen = sizeof(int),
1275 .mode = 0644,
1276 .proc_handler = &proc_dointvec,
1277 },
1278#endif
1279#ifdef CONFIG_MMU
1280 {
1281 .ctl_name = FS_LEASE_TIME,
1282 .procname = "lease-break-time",
1283 .data = &lease_break_time,
1284 .maxlen = sizeof(int),
1285 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001286 .proc_handler = &proc_dointvec_minmax,
1287 .strategy = &sysctl_intvec,
1288 .extra1 = &zero,
1289 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 },
1291 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 .procname = "aio-nr",
1293 .data = &aio_nr,
1294 .maxlen = sizeof(aio_nr),
1295 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001296 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 },
1298 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 .procname = "aio-max-nr",
1300 .data = &aio_max_nr,
1301 .maxlen = sizeof(aio_max_nr),
1302 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001303 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001305#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001306 {
1307 .ctl_name = FS_INOTIFY,
1308 .procname = "inotify",
1309 .mode = 0555,
1310 .child = inotify_table,
1311 },
1312#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001314 {
1315 .ctl_name = KERN_SETUID_DUMPABLE,
1316 .procname = "suid_dumpable",
1317 .data = &suid_dumpable,
1318 .maxlen = sizeof(int),
1319 .mode = 0644,
1320 .proc_handler = &proc_dointvec,
1321 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001322#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1323 {
1324 .ctl_name = CTL_UNNUMBERED,
1325 .procname = "binfmt_misc",
1326 .mode = 0555,
1327 .child = binfmt_misc_table,
1328 },
1329#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001330/*
1331 * NOTE: do not add new entries to this table unless you have read
1332 * Documentation/sysctl/ctl_unnumbered.txt
1333 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 { .ctl_name = 0 }
1335};
1336
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001337static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001338#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001339 {
1340 .ctl_name = CTL_UNNUMBERED,
1341 .procname = "exception-trace",
1342 .data = &show_unhandled_signals,
1343 .maxlen = sizeof(int),
1344 .mode = 0644,
1345 .proc_handler = proc_dointvec
1346 },
1347#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 { .ctl_name = 0 }
1349};
1350
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001351static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001353};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Al Viro330d57f2005-11-04 10:18:40 +00001355static DEFINE_SPINLOCK(sysctl_lock);
1356
1357/* called under sysctl_lock */
1358static int use_table(struct ctl_table_header *p)
1359{
1360 if (unlikely(p->unregistering))
1361 return 0;
1362 p->used++;
1363 return 1;
1364}
1365
1366/* called under sysctl_lock */
1367static void unuse_table(struct ctl_table_header *p)
1368{
1369 if (!--p->used)
1370 if (unlikely(p->unregistering))
1371 complete(p->unregistering);
1372}
1373
1374/* called under sysctl_lock, will reacquire if has to wait */
1375static void start_unregistering(struct ctl_table_header *p)
1376{
1377 /*
1378 * if p->used is 0, nobody will ever touch that entry again;
1379 * we'll eliminate all paths to it before dropping sysctl_lock
1380 */
1381 if (unlikely(p->used)) {
1382 struct completion wait;
1383 init_completion(&wait);
1384 p->unregistering = &wait;
1385 spin_unlock(&sysctl_lock);
1386 wait_for_completion(&wait);
1387 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001388 } else {
1389 /* anything non-NULL; we'll never dereference it */
1390 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001391 }
1392 /*
1393 * do not remove from the list until nobody holds it; walking the
1394 * list in do_sysctl() relies on that.
1395 */
1396 list_del_init(&p->ctl_entry);
1397}
1398
Al Virof7e6ced2008-07-15 01:44:23 -04001399void sysctl_head_get(struct ctl_table_header *head)
1400{
1401 spin_lock(&sysctl_lock);
1402 head->count++;
1403 spin_unlock(&sysctl_lock);
1404}
1405
1406void sysctl_head_put(struct ctl_table_header *head)
1407{
1408 spin_lock(&sysctl_lock);
1409 if (!--head->count)
1410 kfree(head);
1411 spin_unlock(&sysctl_lock);
1412}
1413
1414struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1415{
1416 if (!head)
1417 BUG();
1418 spin_lock(&sysctl_lock);
1419 if (!use_table(head))
1420 head = ERR_PTR(-ENOENT);
1421 spin_unlock(&sysctl_lock);
1422 return head;
1423}
1424
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001425void sysctl_head_finish(struct ctl_table_header *head)
1426{
1427 if (!head)
1428 return;
1429 spin_lock(&sysctl_lock);
1430 unuse_table(head);
1431 spin_unlock(&sysctl_lock);
1432}
1433
Al Viro73455092008-07-14 21:22:20 -04001434static struct ctl_table_set *
1435lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1436{
1437 struct ctl_table_set *set = &root->default_set;
1438 if (root->lookup)
1439 set = root->lookup(root, namespaces);
1440 return set;
1441}
1442
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001443static struct list_head *
1444lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001445{
Al Viro73455092008-07-14 21:22:20 -04001446 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1447 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001448}
1449
1450struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1451 struct ctl_table_header *prev)
1452{
1453 struct ctl_table_root *root;
1454 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001455 struct ctl_table_header *head;
1456 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001457
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001458 spin_lock(&sysctl_lock);
1459 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001460 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001461 tmp = &prev->ctl_entry;
1462 unuse_table(prev);
1463 goto next;
1464 }
1465 tmp = &root_table_header.ctl_entry;
1466 for (;;) {
1467 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1468
1469 if (!use_table(head))
1470 goto next;
1471 spin_unlock(&sysctl_lock);
1472 return head;
1473 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001474 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001475 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001476 header_list = lookup_header_list(root, namespaces);
1477 if (tmp != header_list)
1478 continue;
1479
1480 do {
1481 root = list_entry(root->root_list.next,
1482 struct ctl_table_root, root_list);
1483 if (root == &sysctl_table_root)
1484 goto out;
1485 header_list = lookup_header_list(root, namespaces);
1486 } while (list_empty(header_list));
1487 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001488 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001489out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001490 spin_unlock(&sysctl_lock);
1491 return NULL;
1492}
1493
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001494struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1495{
1496 return __sysctl_head_next(current->nsproxy, prev);
1497}
1498
1499void register_sysctl_root(struct ctl_table_root *root)
1500{
1501 spin_lock(&sysctl_lock);
1502 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1503 spin_unlock(&sysctl_lock);
1504}
1505
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001506#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001507/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001508static int do_sysctl_strategy(struct ctl_table_root *root,
1509 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001510 int __user *name, int nlen,
1511 void __user *oldval, size_t __user *oldlenp,
1512 void __user *newval, size_t newlen)
1513{
1514 int op = 0, rc;
1515
1516 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001517 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001518 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001519 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001520 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001521 return -EPERM;
1522
1523 if (table->strategy) {
1524 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1525 newval, newlen);
1526 if (rc < 0)
1527 return rc;
1528 if (rc > 0)
1529 return 0;
1530 }
1531
1532 /* If there is no strategy routine, or if the strategy returns
1533 * zero, proceed with automatic r/w */
1534 if (table->data && table->maxlen) {
1535 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1536 newval, newlen);
1537 if (rc < 0)
1538 return rc;
1539 }
1540 return 0;
1541}
1542
1543static int parse_table(int __user *name, int nlen,
1544 void __user *oldval, size_t __user *oldlenp,
1545 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001546 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001547 struct ctl_table *table)
1548{
1549 int n;
1550repeat:
1551 if (!nlen)
1552 return -ENOTDIR;
1553 if (get_user(n, name))
1554 return -EFAULT;
1555 for ( ; table->ctl_name || table->procname; table++) {
1556 if (!table->ctl_name)
1557 continue;
1558 if (n == table->ctl_name) {
1559 int error;
1560 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001561 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001562 return -EPERM;
1563 name++;
1564 nlen--;
1565 table = table->child;
1566 goto repeat;
1567 }
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001568 error = do_sysctl_strategy(root, table, name, nlen,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001569 oldval, oldlenp,
1570 newval, newlen);
1571 return error;
1572 }
1573 }
1574 return -ENOTDIR;
1575}
1576
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1578 void __user *newval, size_t newlen)
1579{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001580 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001581 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
1583 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1584 return -ENOTDIR;
1585 if (oldval) {
1586 int old_len;
1587 if (!oldlenp || get_user(old_len, oldlenp))
1588 return -EFAULT;
1589 }
Al Viro330d57f2005-11-04 10:18:40 +00001590
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001591 for (head = sysctl_head_next(NULL); head;
1592 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001593 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001594 newval, newlen,
1595 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001596 if (error != -ENOTDIR) {
1597 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001598 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001599 }
1600 }
Al Viro330d57f2005-11-04 10:18:40 +00001601 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602}
1603
1604asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1605{
1606 struct __sysctl_args tmp;
1607 int error;
1608
1609 if (copy_from_user(&tmp, args, sizeof(tmp)))
1610 return -EFAULT;
1611
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001612 error = deprecated_sysctl_warning(&tmp);
1613 if (error)
1614 goto out;
1615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 lock_kernel();
1617 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1618 tmp.newval, tmp.newlen);
1619 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001620out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 return error;
1622}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001623#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001626 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 * some sysctl variables are readonly even to root.
1628 */
1629
1630static int test_perm(int mode, int op)
1631{
1632 if (!current->euid)
1633 mode >>= 6;
1634 else if (in_egroup_p(0))
1635 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001636 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 return 0;
1638 return -EACCES;
1639}
1640
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001641int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
1643 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001644 int mode;
1645
Al Viroe6305c42008-07-15 21:03:57 -04001646 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 if (error)
1648 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001649
1650 if (root->permissions)
1651 mode = root->permissions(root, current->nsproxy, table);
1652 else
1653 mode = table->mode;
1654
1655 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656}
1657
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001658static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1659{
1660 for (; table->ctl_name || table->procname; table++) {
1661 table->parent = parent;
1662 if (table->child)
1663 sysctl_set_parent(table, table->child);
1664 }
1665}
1666
1667static __init int sysctl_init(void)
1668{
1669 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001670#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1671 {
1672 int err;
1673 err = sysctl_check_table(current->nsproxy, root_table);
1674 }
1675#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001676 return 0;
1677}
1678
1679core_initcall(sysctl_init);
1680
Al Virobfbcf032008-07-27 06:31:22 +01001681static struct ctl_table *is_branch_in(struct ctl_table *branch,
1682 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001683{
1684 struct ctl_table *p;
1685 const char *s = branch->procname;
1686
1687 /* branch should have named subdirectory as its first element */
1688 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001689 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001690
1691 /* ... and nothing else */
1692 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001693 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001694
1695 /* table should contain subdirectory with the same name */
1696 for (p = table; p->procname || p->ctl_name; p++) {
1697 if (!p->child)
1698 continue;
1699 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001700 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001701 }
Al Virobfbcf032008-07-27 06:31:22 +01001702 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001703}
1704
1705/* see if attaching q to p would be an improvement */
1706static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1707{
1708 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001709 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001710 int is_better = 0;
1711 int not_in_parent = !p->attached_by;
1712
Al Virobfbcf032008-07-27 06:31:22 +01001713 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001714 if (by == q->attached_by)
1715 is_better = 1;
1716 if (to == p->attached_by)
1717 not_in_parent = 1;
1718 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001719 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001720 }
1721
1722 if (is_better && not_in_parent) {
1723 q->attached_by = by;
1724 q->attached_to = to;
1725 q->parent = p;
1726 }
1727}
1728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001730 * __register_sysctl_paths - register a sysctl hierarchy
1731 * @root: List of sysctl headers to register on
1732 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001733 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 *
1736 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001737 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001739 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 *
1741 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1742 * must be unique within that level of sysctl
1743 *
1744 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1745 * enter a sysctl file
1746 *
1747 * data - a pointer to data for use by proc_handler
1748 *
1749 * maxlen - the maximum size in bytes of the data
1750 *
1751 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1752 *
1753 * child - a pointer to the child sysctl table if this entry is a directory, or
1754 * %NULL.
1755 *
1756 * proc_handler - the text handler routine (described below)
1757 *
1758 * strategy - the strategy routine (described below)
1759 *
1760 * de - for internal use by the sysctl routines
1761 *
1762 * extra1, extra2 - extra pointers usable by the proc handler routines
1763 *
1764 * Leaf nodes in the sysctl tree will be represented by a single file
1765 * under /proc; non-leaf nodes will be represented by directories.
1766 *
1767 * sysctl(2) can automatically manage read and write requests through
1768 * the sysctl table. The data and maxlen fields of the ctl_table
1769 * struct enable minimal validation of the values being written to be
1770 * performed, and the mode field allows minimal authentication.
1771 *
1772 * More sophisticated management can be enabled by the provision of a
1773 * strategy routine with the table entry. This will be called before
1774 * any automatic read or write of the data is performed.
1775 *
1776 * The strategy routine may return
1777 *
1778 * < 0 - Error occurred (error is passed to user process)
1779 *
1780 * 0 - OK - proceed with automatic read or write.
1781 *
1782 * > 0 - OK - read or write has been done by the strategy routine, so
1783 * return immediately.
1784 *
1785 * There must be a proc_handler routine for any terminal nodes
1786 * mirrored under /proc/sys (non-terminals are handled by a built-in
1787 * directory handler). Several default handlers are available to
1788 * cover common cases -
1789 *
1790 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1791 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1792 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1793 *
1794 * It is the handler's job to read the input buffer from user memory
1795 * and process it. The handler should return 0 on success.
1796 *
1797 * This routine returns %NULL on a failure to register, and a pointer
1798 * to the table header on success.
1799 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001800struct ctl_table_header *__register_sysctl_paths(
1801 struct ctl_table_root *root,
1802 struct nsproxy *namespaces,
1803 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001805 struct ctl_table_header *header;
1806 struct ctl_table *new, **prevp;
1807 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001808 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001809
1810 /* Count the path components */
1811 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1812 ;
1813
1814 /*
1815 * For each path component, allocate a 2-element ctl_table array.
1816 * The first array element will be filled with the sysctl entry
1817 * for this, the second will be the sentinel (ctl_name == 0).
1818 *
1819 * We allocate everything in one go so that we don't have to
1820 * worry about freeing additional memory in unregister_sysctl_table.
1821 */
1822 header = kzalloc(sizeof(struct ctl_table_header) +
1823 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1824 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001826
1827 new = (struct ctl_table *) (header + 1);
1828
1829 /* Now connect the dots */
1830 prevp = &header->ctl_table;
1831 for (n = 0; n < npath; ++n, ++path) {
1832 /* Copy the procname */
1833 new->procname = path->procname;
1834 new->ctl_name = path->ctl_name;
1835 new->mode = 0555;
1836
1837 *prevp = new;
1838 prevp = &new->child;
1839
1840 new += 2;
1841 }
1842 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001843 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001844
1845 INIT_LIST_HEAD(&header->ctl_entry);
1846 header->used = 0;
1847 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001848 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001849 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001850 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001851#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001852 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001853 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001854 return NULL;
1855 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001856#endif
Al Viro330d57f2005-11-04 10:18:40 +00001857 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001858 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001859 header->attached_by = header->ctl_table;
1860 header->attached_to = root_table;
1861 header->parent = &root_table_header;
1862 for (set = header->set; set; set = set->parent) {
1863 struct ctl_table_header *p;
1864 list_for_each_entry(p, &set->list, ctl_entry) {
1865 if (p->unregistering)
1866 continue;
1867 try_attach(p, header);
1868 }
1869 }
1870 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001871 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001872 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001873
1874 return header;
1875}
1876
1877/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001878 * register_sysctl_table_path - register a sysctl table hierarchy
1879 * @path: The path to the directory the sysctl table is in.
1880 * @table: the top-level table structure
1881 *
1882 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1883 * array. A completely 0 filled entry terminates the table.
1884 *
1885 * See __register_sysctl_paths for more details.
1886 */
1887struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1888 struct ctl_table *table)
1889{
1890 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1891 path, table);
1892}
1893
1894/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001895 * register_sysctl_table - register a sysctl table hierarchy
1896 * @table: the top-level table structure
1897 *
1898 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1899 * array. A completely 0 filled entry terminates the table.
1900 *
1901 * See register_sysctl_paths for more details.
1902 */
1903struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1904{
1905 static const struct ctl_path null_path[] = { {} };
1906
1907 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908}
1909
1910/**
1911 * unregister_sysctl_table - unregister a sysctl table hierarchy
1912 * @header: the header returned from register_sysctl_table
1913 *
1914 * Unregisters the sysctl table and all children. proc entries may not
1915 * actually be removed until they are no longer used by anyone.
1916 */
1917void unregister_sysctl_table(struct ctl_table_header * header)
1918{
Al Viro330d57f2005-11-04 10:18:40 +00001919 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001920
1921 if (header == NULL)
1922 return;
1923
Al Viro330d57f2005-11-04 10:18:40 +00001924 spin_lock(&sysctl_lock);
1925 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001926 if (!--header->parent->count) {
1927 WARN_ON(1);
1928 kfree(header->parent);
1929 }
Al Virof7e6ced2008-07-15 01:44:23 -04001930 if (!--header->count)
1931 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001932 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
Al Viro9043476f2008-07-15 08:54:06 -04001935int sysctl_is_seen(struct ctl_table_header *p)
1936{
1937 struct ctl_table_set *set = p->set;
1938 int res;
1939 spin_lock(&sysctl_lock);
1940 if (p->unregistering)
1941 res = 0;
1942 else if (!set->is_seen)
1943 res = 1;
1944 else
1945 res = set->is_seen(set);
1946 spin_unlock(&sysctl_lock);
1947 return res;
1948}
1949
Al Viro73455092008-07-14 21:22:20 -04001950void setup_sysctl_set(struct ctl_table_set *p,
1951 struct ctl_table_set *parent,
1952 int (*is_seen)(struct ctl_table_set *))
1953{
1954 INIT_LIST_HEAD(&p->list);
1955 p->parent = parent ? parent : &sysctl_table_root.default_set;
1956 p->is_seen = is_seen;
1957}
1958
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001959#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001960struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001961{
1962 return NULL;
1963}
1964
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001965struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1966 struct ctl_table *table)
1967{
1968 return NULL;
1969}
1970
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001971void unregister_sysctl_table(struct ctl_table_header * table)
1972{
1973}
1974
Al Viro73455092008-07-14 21:22:20 -04001975void setup_sysctl_set(struct ctl_table_set *p,
1976 struct ctl_table_set *parent,
1977 int (*is_seen)(struct ctl_table_set *))
1978{
1979}
1980
Al Virof7e6ced2008-07-15 01:44:23 -04001981void sysctl_head_put(struct ctl_table_header *head)
1982{
1983}
1984
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001985#endif /* CONFIG_SYSCTL */
1986
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987/*
1988 * /proc/sys support
1989 */
1990
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001991#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001993static int _proc_do_string(void* data, int maxlen, int write,
1994 struct file *filp, void __user *buffer,
1995 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001996{
1997 size_t len;
1998 char __user *p;
1999 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002000
2001 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002002 *lenp = 0;
2003 return 0;
2004 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002005
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002006 if (write) {
2007 len = 0;
2008 p = buffer;
2009 while (len < *lenp) {
2010 if (get_user(c, p++))
2011 return -EFAULT;
2012 if (c == 0 || c == '\n')
2013 break;
2014 len++;
2015 }
2016 if (len >= maxlen)
2017 len = maxlen-1;
2018 if(copy_from_user(data, buffer, len))
2019 return -EFAULT;
2020 ((char *) data)[len] = 0;
2021 *ppos += *lenp;
2022 } else {
2023 len = strlen(data);
2024 if (len > maxlen)
2025 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002026
2027 if (*ppos > len) {
2028 *lenp = 0;
2029 return 0;
2030 }
2031
2032 data += *ppos;
2033 len -= *ppos;
2034
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002035 if (len > *lenp)
2036 len = *lenp;
2037 if (len)
2038 if(copy_to_user(buffer, data, len))
2039 return -EFAULT;
2040 if (len < *lenp) {
2041 if(put_user('\n', ((char __user *) buffer) + len))
2042 return -EFAULT;
2043 len++;
2044 }
2045 *lenp = len;
2046 *ppos += len;
2047 }
2048 return 0;
2049}
2050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051/**
2052 * proc_dostring - read a string sysctl
2053 * @table: the sysctl table
2054 * @write: %TRUE if this is a write to the sysctl file
2055 * @filp: the file structure
2056 * @buffer: the user buffer
2057 * @lenp: the size of the user buffer
2058 * @ppos: file position
2059 *
2060 * Reads/writes a string from/to the user buffer. If the kernel
2061 * buffer provided is not large enough to hold the string, the
2062 * string is truncated. The copied string is %NULL-terminated.
2063 * If the string is being read by the user process, it is copied
2064 * and a newline '\n' is added. It is truncated if the buffer is
2065 * not large enough.
2066 *
2067 * Returns 0 on success.
2068 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002069int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 void __user *buffer, size_t *lenp, loff_t *ppos)
2071{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002072 return _proc_do_string(table->data, table->maxlen, write, filp,
2073 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074}
2075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2078 int *valp,
2079 int write, void *data)
2080{
2081 if (write) {
2082 *valp = *negp ? -*lvalp : *lvalp;
2083 } else {
2084 int val = *valp;
2085 if (val < 0) {
2086 *negp = -1;
2087 *lvalp = (unsigned long)-val;
2088 } else {
2089 *negp = 0;
2090 *lvalp = (unsigned long)val;
2091 }
2092 }
2093 return 0;
2094}
2095
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002096static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002097 int write, struct file *filp, void __user *buffer,
2098 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2100 int write, void *data),
2101 void *data)
2102{
2103#define TMPBUFLEN 21
2104 int *i, vleft, first=1, neg, val;
2105 unsigned long lval;
2106 size_t left, len;
2107
2108 char buf[TMPBUFLEN], *p;
2109 char __user *s = buffer;
2110
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002111 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 (*ppos && !write)) {
2113 *lenp = 0;
2114 return 0;
2115 }
2116
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002117 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 vleft = table->maxlen / sizeof(*i);
2119 left = *lenp;
2120
2121 if (!conv)
2122 conv = do_proc_dointvec_conv;
2123
2124 for (; left && vleft--; i++, first=0) {
2125 if (write) {
2126 while (left) {
2127 char c;
2128 if (get_user(c, s))
2129 return -EFAULT;
2130 if (!isspace(c))
2131 break;
2132 left--;
2133 s++;
2134 }
2135 if (!left)
2136 break;
2137 neg = 0;
2138 len = left;
2139 if (len > sizeof(buf) - 1)
2140 len = sizeof(buf) - 1;
2141 if (copy_from_user(buf, s, len))
2142 return -EFAULT;
2143 buf[len] = 0;
2144 p = buf;
2145 if (*p == '-' && left > 1) {
2146 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002147 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 }
2149 if (*p < '0' || *p > '9')
2150 break;
2151
2152 lval = simple_strtoul(p, &p, 0);
2153
2154 len = p-buf;
2155 if ((len < left) && *p && !isspace(*p))
2156 break;
2157 if (neg)
2158 val = -val;
2159 s += len;
2160 left -= len;
2161
2162 if (conv(&neg, &lval, i, 1, data))
2163 break;
2164 } else {
2165 p = buf;
2166 if (!first)
2167 *p++ = '\t';
2168
2169 if (conv(&neg, &lval, i, 0, data))
2170 break;
2171
2172 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2173 len = strlen(buf);
2174 if (len > left)
2175 len = left;
2176 if(copy_to_user(s, buf, len))
2177 return -EFAULT;
2178 left -= len;
2179 s += len;
2180 }
2181 }
2182
2183 if (!write && !first && left) {
2184 if(put_user('\n', s))
2185 return -EFAULT;
2186 left--, s++;
2187 }
2188 if (write) {
2189 while (left) {
2190 char c;
2191 if (get_user(c, s++))
2192 return -EFAULT;
2193 if (!isspace(c))
2194 break;
2195 left--;
2196 }
2197 }
2198 if (write && first)
2199 return -EINVAL;
2200 *lenp -= left;
2201 *ppos += *lenp;
2202 return 0;
2203#undef TMPBUFLEN
2204}
2205
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002206static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002207 void __user *buffer, size_t *lenp, loff_t *ppos,
2208 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2209 int write, void *data),
2210 void *data)
2211{
2212 return __do_proc_dointvec(table->data, table, write, filp,
2213 buffer, lenp, ppos, conv, data);
2214}
2215
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216/**
2217 * proc_dointvec - read a vector of integers
2218 * @table: the sysctl table
2219 * @write: %TRUE if this is a write to the sysctl file
2220 * @filp: the file structure
2221 * @buffer: the user buffer
2222 * @lenp: the size of the user buffer
2223 * @ppos: file position
2224 *
2225 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2226 * values from/to the user buffer, treated as an ASCII string.
2227 *
2228 * Returns 0 on success.
2229 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002230int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 void __user *buffer, size_t *lenp, loff_t *ppos)
2232{
2233 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2234 NULL,NULL);
2235}
2236
2237#define OP_SET 0
2238#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002239#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
2241static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2242 int *valp,
2243 int write, void *data)
2244{
2245 int op = *(int *)data;
2246 if (write) {
2247 int val = *negp ? -*lvalp : *lvalp;
2248 switch(op) {
2249 case OP_SET: *valp = val; break;
2250 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002251 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 }
2253 } else {
2254 int val = *valp;
2255 if (val < 0) {
2256 *negp = -1;
2257 *lvalp = (unsigned long)-val;
2258 } else {
2259 *negp = 0;
2260 *lvalp = (unsigned long)val;
2261 }
2262 }
2263 return 0;
2264}
2265
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002266/*
2267 * Taint values can only be increased
2268 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002269static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002270 void __user *buffer, size_t *lenp, loff_t *ppos)
2271{
2272 int op;
2273
Bastian Blank91fcd412007-04-23 14:41:14 -07002274 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002275 return -EPERM;
2276
2277 op = OP_OR;
2278 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2279 do_proc_dointvec_bset_conv,&op);
2280}
2281
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282struct do_proc_dointvec_minmax_conv_param {
2283 int *min;
2284 int *max;
2285};
2286
2287static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2288 int *valp,
2289 int write, void *data)
2290{
2291 struct do_proc_dointvec_minmax_conv_param *param = data;
2292 if (write) {
2293 int val = *negp ? -*lvalp : *lvalp;
2294 if ((param->min && *param->min > val) ||
2295 (param->max && *param->max < val))
2296 return -EINVAL;
2297 *valp = val;
2298 } else {
2299 int val = *valp;
2300 if (val < 0) {
2301 *negp = -1;
2302 *lvalp = (unsigned long)-val;
2303 } else {
2304 *negp = 0;
2305 *lvalp = (unsigned long)val;
2306 }
2307 }
2308 return 0;
2309}
2310
2311/**
2312 * proc_dointvec_minmax - read a vector of integers with min/max values
2313 * @table: the sysctl table
2314 * @write: %TRUE if this is a write to the sysctl file
2315 * @filp: the file structure
2316 * @buffer: the user buffer
2317 * @lenp: the size of the user buffer
2318 * @ppos: file position
2319 *
2320 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2321 * values from/to the user buffer, treated as an ASCII string.
2322 *
2323 * This routine will ensure the values are within the range specified by
2324 * table->extra1 (min) and table->extra2 (max).
2325 *
2326 * Returns 0 on success.
2327 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002328int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 void __user *buffer, size_t *lenp, loff_t *ppos)
2330{
2331 struct do_proc_dointvec_minmax_conv_param param = {
2332 .min = (int *) table->extra1,
2333 .max = (int *) table->extra2,
2334 };
2335 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2336 do_proc_dointvec_minmax_conv, &param);
2337}
2338
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002339static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 struct file *filp,
2341 void __user *buffer,
2342 size_t *lenp, loff_t *ppos,
2343 unsigned long convmul,
2344 unsigned long convdiv)
2345{
2346#define TMPBUFLEN 21
2347 unsigned long *i, *min, *max, val;
2348 int vleft, first=1, neg;
2349 size_t len, left;
2350 char buf[TMPBUFLEN], *p;
2351 char __user *s = buffer;
2352
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002353 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 (*ppos && !write)) {
2355 *lenp = 0;
2356 return 0;
2357 }
2358
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002359 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 min = (unsigned long *) table->extra1;
2361 max = (unsigned long *) table->extra2;
2362 vleft = table->maxlen / sizeof(unsigned long);
2363 left = *lenp;
2364
2365 for (; left && vleft--; i++, min++, max++, first=0) {
2366 if (write) {
2367 while (left) {
2368 char c;
2369 if (get_user(c, s))
2370 return -EFAULT;
2371 if (!isspace(c))
2372 break;
2373 left--;
2374 s++;
2375 }
2376 if (!left)
2377 break;
2378 neg = 0;
2379 len = left;
2380 if (len > TMPBUFLEN-1)
2381 len = TMPBUFLEN-1;
2382 if (copy_from_user(buf, s, len))
2383 return -EFAULT;
2384 buf[len] = 0;
2385 p = buf;
2386 if (*p == '-' && left > 1) {
2387 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002388 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 }
2390 if (*p < '0' || *p > '9')
2391 break;
2392 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2393 len = p-buf;
2394 if ((len < left) && *p && !isspace(*p))
2395 break;
2396 if (neg)
2397 val = -val;
2398 s += len;
2399 left -= len;
2400
2401 if(neg)
2402 continue;
2403 if ((min && val < *min) || (max && val > *max))
2404 continue;
2405 *i = val;
2406 } else {
2407 p = buf;
2408 if (!first)
2409 *p++ = '\t';
2410 sprintf(p, "%lu", convdiv * (*i) / convmul);
2411 len = strlen(buf);
2412 if (len > left)
2413 len = left;
2414 if(copy_to_user(s, buf, len))
2415 return -EFAULT;
2416 left -= len;
2417 s += len;
2418 }
2419 }
2420
2421 if (!write && !first && left) {
2422 if(put_user('\n', s))
2423 return -EFAULT;
2424 left--, s++;
2425 }
2426 if (write) {
2427 while (left) {
2428 char c;
2429 if (get_user(c, s++))
2430 return -EFAULT;
2431 if (!isspace(c))
2432 break;
2433 left--;
2434 }
2435 }
2436 if (write && first)
2437 return -EINVAL;
2438 *lenp -= left;
2439 *ppos += *lenp;
2440 return 0;
2441#undef TMPBUFLEN
2442}
2443
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002444static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002445 struct file *filp,
2446 void __user *buffer,
2447 size_t *lenp, loff_t *ppos,
2448 unsigned long convmul,
2449 unsigned long convdiv)
2450{
2451 return __do_proc_doulongvec_minmax(table->data, table, write,
2452 filp, buffer, lenp, ppos, convmul, convdiv);
2453}
2454
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455/**
2456 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2457 * @table: the sysctl table
2458 * @write: %TRUE if this is a write to the sysctl file
2459 * @filp: the file structure
2460 * @buffer: the user buffer
2461 * @lenp: the size of the user buffer
2462 * @ppos: file position
2463 *
2464 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2465 * values from/to the user buffer, treated as an ASCII string.
2466 *
2467 * This routine will ensure the values are within the range specified by
2468 * table->extra1 (min) and table->extra2 (max).
2469 *
2470 * Returns 0 on success.
2471 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002472int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 void __user *buffer, size_t *lenp, loff_t *ppos)
2474{
2475 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2476}
2477
2478/**
2479 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2480 * @table: the sysctl table
2481 * @write: %TRUE if this is a write to the sysctl file
2482 * @filp: the file structure
2483 * @buffer: the user buffer
2484 * @lenp: the size of the user buffer
2485 * @ppos: file position
2486 *
2487 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2488 * values from/to the user buffer, treated as an ASCII string. The values
2489 * are treated as milliseconds, and converted to jiffies when they are stored.
2490 *
2491 * This routine will ensure the values are within the range specified by
2492 * table->extra1 (min) and table->extra2 (max).
2493 *
2494 * Returns 0 on success.
2495 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002496int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 struct file *filp,
2498 void __user *buffer,
2499 size_t *lenp, loff_t *ppos)
2500{
2501 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2502 lenp, ppos, HZ, 1000l);
2503}
2504
2505
2506static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2507 int *valp,
2508 int write, void *data)
2509{
2510 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002511 if (*lvalp > LONG_MAX / HZ)
2512 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2514 } else {
2515 int val = *valp;
2516 unsigned long lval;
2517 if (val < 0) {
2518 *negp = -1;
2519 lval = (unsigned long)-val;
2520 } else {
2521 *negp = 0;
2522 lval = (unsigned long)val;
2523 }
2524 *lvalp = lval / HZ;
2525 }
2526 return 0;
2527}
2528
2529static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2530 int *valp,
2531 int write, void *data)
2532{
2533 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002534 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2535 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2537 } else {
2538 int val = *valp;
2539 unsigned long lval;
2540 if (val < 0) {
2541 *negp = -1;
2542 lval = (unsigned long)-val;
2543 } else {
2544 *negp = 0;
2545 lval = (unsigned long)val;
2546 }
2547 *lvalp = jiffies_to_clock_t(lval);
2548 }
2549 return 0;
2550}
2551
2552static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2553 int *valp,
2554 int write, void *data)
2555{
2556 if (write) {
2557 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2558 } else {
2559 int val = *valp;
2560 unsigned long lval;
2561 if (val < 0) {
2562 *negp = -1;
2563 lval = (unsigned long)-val;
2564 } else {
2565 *negp = 0;
2566 lval = (unsigned long)val;
2567 }
2568 *lvalp = jiffies_to_msecs(lval);
2569 }
2570 return 0;
2571}
2572
2573/**
2574 * proc_dointvec_jiffies - read a vector of integers as seconds
2575 * @table: the sysctl table
2576 * @write: %TRUE if this is a write to the sysctl file
2577 * @filp: the file structure
2578 * @buffer: the user buffer
2579 * @lenp: the size of the user buffer
2580 * @ppos: file position
2581 *
2582 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2583 * values from/to the user buffer, treated as an ASCII string.
2584 * The values read are assumed to be in seconds, and are converted into
2585 * jiffies.
2586 *
2587 * Returns 0 on success.
2588 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002589int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 void __user *buffer, size_t *lenp, loff_t *ppos)
2591{
2592 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2593 do_proc_dointvec_jiffies_conv,NULL);
2594}
2595
2596/**
2597 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2598 * @table: the sysctl table
2599 * @write: %TRUE if this is a write to the sysctl file
2600 * @filp: the file structure
2601 * @buffer: the user buffer
2602 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002603 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 *
2605 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2606 * values from/to the user buffer, treated as an ASCII string.
2607 * The values read are assumed to be in 1/USER_HZ seconds, and
2608 * are converted into jiffies.
2609 *
2610 * Returns 0 on success.
2611 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002612int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 void __user *buffer, size_t *lenp, loff_t *ppos)
2614{
2615 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2616 do_proc_dointvec_userhz_jiffies_conv,NULL);
2617}
2618
2619/**
2620 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2621 * @table: the sysctl table
2622 * @write: %TRUE if this is a write to the sysctl file
2623 * @filp: the file structure
2624 * @buffer: the user buffer
2625 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002626 * @ppos: file position
2627 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 *
2629 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2630 * values from/to the user buffer, treated as an ASCII string.
2631 * The values read are assumed to be in 1/1000 seconds, and
2632 * are converted into jiffies.
2633 *
2634 * Returns 0 on success.
2635 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002636int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 void __user *buffer, size_t *lenp, loff_t *ppos)
2638{
2639 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2640 do_proc_dointvec_ms_jiffies_conv, NULL);
2641}
2642
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002643static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002644 void __user *buffer, size_t *lenp, loff_t *ppos)
2645{
2646 struct pid *new_pid;
2647 pid_t tmp;
2648 int r;
2649
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002650 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002651
2652 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2653 lenp, ppos, NULL, NULL);
2654 if (r || !write)
2655 return r;
2656
2657 new_pid = find_get_pid(tmp);
2658 if (!new_pid)
2659 return -ESRCH;
2660
2661 put_pid(xchg(&cad_pid, new_pid));
2662 return 0;
2663}
2664
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665#else /* CONFIG_PROC_FS */
2666
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002667int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 void __user *buffer, size_t *lenp, loff_t *ppos)
2669{
2670 return -ENOSYS;
2671}
2672
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002673int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 void __user *buffer, size_t *lenp, loff_t *ppos)
2675{
2676 return -ENOSYS;
2677}
2678
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002679int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 void __user *buffer, size_t *lenp, loff_t *ppos)
2681{
2682 return -ENOSYS;
2683}
2684
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002685int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 void __user *buffer, size_t *lenp, loff_t *ppos)
2687{
2688 return -ENOSYS;
2689}
2690
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002691int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 void __user *buffer, size_t *lenp, loff_t *ppos)
2693{
2694 return -ENOSYS;
2695}
2696
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002697int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 void __user *buffer, size_t *lenp, loff_t *ppos)
2699{
2700 return -ENOSYS;
2701}
2702
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002703int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 void __user *buffer, size_t *lenp, loff_t *ppos)
2705{
2706 return -ENOSYS;
2707}
2708
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002709int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 struct file *filp,
2711 void __user *buffer,
2712 size_t *lenp, loff_t *ppos)
2713{
2714 return -ENOSYS;
2715}
2716
2717
2718#endif /* CONFIG_PROC_FS */
2719
2720
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002721#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722/*
2723 * General sysctl support routines
2724 */
2725
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002726/* The generic sysctl data routine (used if no strategy routine supplied) */
2727int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2728 void __user *oldval, size_t __user *oldlenp,
2729 void __user *newval, size_t newlen)
2730{
2731 size_t len;
2732
2733 /* Get out of I don't have a variable */
2734 if (!table->data || !table->maxlen)
2735 return -ENOTDIR;
2736
2737 if (oldval && oldlenp) {
2738 if (get_user(len, oldlenp))
2739 return -EFAULT;
2740 if (len) {
2741 if (len > table->maxlen)
2742 len = table->maxlen;
2743 if (copy_to_user(oldval, table->data, len))
2744 return -EFAULT;
2745 if (put_user(len, oldlenp))
2746 return -EFAULT;
2747 }
2748 }
2749
2750 if (newval && newlen) {
2751 if (newlen > table->maxlen)
2752 newlen = table->maxlen;
2753
2754 if (copy_from_user(table->data, newval, newlen))
2755 return -EFAULT;
2756 }
2757 return 1;
2758}
2759
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002761int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002763 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 if (!table->data || !table->maxlen)
2766 return -ENOTDIR;
2767
2768 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002769 size_t bufsize;
2770 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002772 if (bufsize) {
2773 size_t len = strlen(table->data), copied;
2774
2775 /* This shouldn't trigger for a well-formed sysctl */
2776 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002778
2779 /* Copy up to a max of bufsize-1 bytes of the string */
2780 copied = (len >= bufsize) ? bufsize - 1 : len;
2781
2782 if (copy_to_user(oldval, table->data, copied) ||
2783 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002785 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 return -EFAULT;
2787 }
2788 }
2789 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002790 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 if (len > table->maxlen)
2792 len = table->maxlen;
2793 if(copy_from_user(table->data, newval, len))
2794 return -EFAULT;
2795 if (len == table->maxlen)
2796 len--;
2797 ((char *) table->data)[len] = 0;
2798 }
Yi Yang82c9df82005-12-30 16:37:10 +08002799 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800}
2801
2802/*
2803 * This function makes sure that all of the integers in the vector
2804 * are between the minimum and maximum values given in the arrays
2805 * table->extra1 and table->extra2, respectively.
2806 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002807int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002809 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810{
2811
2812 if (newval && newlen) {
2813 int __user *vec = (int __user *) newval;
2814 int *min = (int *) table->extra1;
2815 int *max = (int *) table->extra2;
2816 size_t length;
2817 int i;
2818
2819 if (newlen % sizeof(int) != 0)
2820 return -EINVAL;
2821
2822 if (!table->extra1 && !table->extra2)
2823 return 0;
2824
2825 if (newlen > table->maxlen)
2826 newlen = table->maxlen;
2827 length = newlen / sizeof(int);
2828
2829 for (i = 0; i < length; i++) {
2830 int value;
2831 if (get_user(value, vec + i))
2832 return -EFAULT;
2833 if (min && value < min[i])
2834 return -EINVAL;
2835 if (max && value > max[i])
2836 return -EINVAL;
2837 }
2838 }
2839 return 0;
2840}
2841
2842/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002843int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002845 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002847 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002849
2850 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002852 if (olen) {
2853 int val;
2854
2855 if (olen < sizeof(int))
2856 return -EINVAL;
2857
2858 val = *(int *)(table->data) / HZ;
2859 if (put_user(val, (int __user *)oldval))
2860 return -EFAULT;
2861 if (put_user(sizeof(int), oldlenp))
2862 return -EFAULT;
2863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 }
2865 if (newval && newlen) {
2866 int new;
2867 if (newlen != sizeof(int))
2868 return -EINVAL;
2869 if (get_user(new, (int __user *)newval))
2870 return -EFAULT;
2871 *(int *)(table->data) = new*HZ;
2872 }
2873 return 1;
2874}
2875
2876/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002877int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002879 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002881 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002883
2884 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002886 if (olen) {
2887 int val;
2888
2889 if (olen < sizeof(int))
2890 return -EINVAL;
2891
2892 val = jiffies_to_msecs(*(int *)(table->data));
2893 if (put_user(val, (int __user *)oldval))
2894 return -EFAULT;
2895 if (put_user(sizeof(int), oldlenp))
2896 return -EFAULT;
2897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 }
2899 if (newval && newlen) {
2900 int new;
2901 if (newlen != sizeof(int))
2902 return -EINVAL;
2903 if (get_user(new, (int __user *)newval))
2904 return -EFAULT;
2905 *(int *)(table->data) = msecs_to_jiffies(new);
2906 }
2907 return 1;
2908}
2909
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002910
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002911
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002912#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913
2914
2915asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2916{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002917 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002918 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002919
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002920 if (copy_from_user(&tmp, args, sizeof(tmp)))
2921 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002922
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002923 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002924
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002925 /* If no error reading the parameters then just -ENOSYS ... */
2926 if (!error)
2927 error = -ENOSYS;
2928
2929 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930}
2931
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002932int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2933 void __user *oldval, size_t __user *oldlenp,
2934 void __user *newval, size_t newlen)
2935{
2936 return -ENOSYS;
2937}
2938
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002939int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002941 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942{
2943 return -ENOSYS;
2944}
2945
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002946int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002948 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949{
2950 return -ENOSYS;
2951}
2952
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002953int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002955 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956{
2957 return -ENOSYS;
2958}
2959
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002960int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002962 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963{
2964 return -ENOSYS;
2965}
2966
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002967#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002969static int deprecated_sysctl_warning(struct __sysctl_args *args)
2970{
2971 static int msg_count;
2972 int name[CTL_MAXNAME];
2973 int i;
2974
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002975 /* Check args->nlen. */
2976 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2977 return -ENOTDIR;
2978
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002979 /* Read in the sysctl name for better debug message logging */
2980 for (i = 0; i < args->nlen; i++)
2981 if (get_user(name[i], args->name + i))
2982 return -EFAULT;
2983
2984 /* Ignore accesses to kernel.version */
2985 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2986 return 0;
2987
2988 if (msg_count < 5) {
2989 msg_count++;
2990 printk(KERN_INFO
2991 "warning: process `%s' used the deprecated sysctl "
2992 "system call with ", current->comm);
2993 for (i = 0; i < args->nlen; i++)
2994 printk("%d.", name[i]);
2995 printk("\n");
2996 }
2997 return 0;
2998}
2999
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000/*
3001 * No sense putting this after each symbol definition, twice,
3002 * exception granted :-)
3003 */
3004EXPORT_SYMBOL(proc_dointvec);
3005EXPORT_SYMBOL(proc_dointvec_jiffies);
3006EXPORT_SYMBOL(proc_dointvec_minmax);
3007EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3008EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3009EXPORT_SYMBOL(proc_dostring);
3010EXPORT_SYMBOL(proc_doulongvec_minmax);
3011EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3012EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003013EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014EXPORT_SYMBOL(sysctl_intvec);
3015EXPORT_SYMBOL(sysctl_jiffies);
3016EXPORT_SYMBOL(sysctl_ms_jiffies);
3017EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003018EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019EXPORT_SYMBOL(unregister_sysctl_table);