blob: 4e2ac0aec9b060f3a1a4459f7d6889316d11fdeb [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;
Arjan van de Ven97455122008-01-25 21:08:34 +010083extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040084extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070085#ifdef CONFIG_RCU_TORTURE_TEST
86extern int rcutorture_runnable;
87#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070089/* Constants used for minimum and maximum */
Ingo Molnar1c4cd6d2008-05-12 21:21:14 +020090#if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070091static int one = 1;
Bron Gondwana195cf4532008-02-04 22:29:20 -080092#endif
93
94#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020096static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097#endif
98
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +020099#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100static int two = 2;
101#endif
102
103static int zero;
104static int one_hundred = 100;
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107static int maxolduid = 65535;
108static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111static int ngroups_max = NGROUPS_MAX;
112
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200113#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern char modprobe_path[];
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#ifdef CONFIG_CHR_DEV_SG
117extern int sg_big_buff;
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
David S. Miller72c57ed2008-09-11 23:29:54 -0700120#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700121#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#endif
123
David S. Miller08714202008-11-16 23:49:24 -0800124#ifdef CONFIG_SPARC64
125extern int sysctl_tsb_ratio;
126#endif
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef __hppa__
129extern int pwrsw_enabled;
130extern int unaligned_enabled;
131#endif
132
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800133#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef CONFIG_MATHEMU
135extern int sysctl_ieee_emulation_warnings;
136#endif
137extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700138extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#endif
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#ifdef CONFIG_BSD_PROCESS_ACCT
142extern int acct_parm[];
143#endif
144
Jes Sorensend2b176e2006-02-28 09:42:23 -0800145#ifdef CONFIG_IA64
146extern int no_unaligned_warning;
147#endif
148
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700149#ifdef CONFIG_RT_MUTEXES
150extern int max_lock_depth;
151#endif
152
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700153#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700154static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700156static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800157 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700158#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700159
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700160static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100161static struct ctl_table_root sysctl_table_root;
162static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100163 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100164 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400165 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100166 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400167 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168};
169static struct ctl_table_root sysctl_table_root = {
170 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400171 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100172};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700174static struct ctl_table kern_table[];
175static struct ctl_table vm_table[];
176static struct ctl_table fs_table[];
177static struct ctl_table debug_table[];
178static struct ctl_table dev_table[];
179extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700180#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700181extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400182#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800183#ifdef CONFIG_EPOLL
184extern struct ctl_table epoll_table[];
185#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
188int sysctl_legacy_va_layout;
189#endif
190
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700191extern int prove_locking;
192extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/* The default sysctl tables: */
195
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700196static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 {
198 .ctl_name = CTL_KERN,
199 .procname = "kernel",
200 .mode = 0555,
201 .child = kern_table,
202 },
203 {
204 .ctl_name = CTL_VM,
205 .procname = "vm",
206 .mode = 0555,
207 .child = vm_table,
208 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 .ctl_name = CTL_FS,
211 .procname = "fs",
212 .mode = 0555,
213 .child = fs_table,
214 },
215 {
216 .ctl_name = CTL_DEBUG,
217 .procname = "debug",
218 .mode = 0555,
219 .child = debug_table,
220 },
221 {
222 .ctl_name = CTL_DEV,
223 .procname = "dev",
224 .mode = 0555,
225 .child = dev_table,
226 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700227/*
228 * NOTE: do not add new entries to this table unless you have read
229 * Documentation/sysctl/ctl_unnumbered.txt
230 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 { .ctl_name = 0 }
232};
233
Ingo Molnar77e54a12007-07-09 18:52:00 +0200234#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100235static int min_sched_granularity_ns = 100000; /* 100 usecs */
236static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
237static int min_wakeup_granularity_ns; /* 0 usecs */
238static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200239#endif
240
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700241static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200242#ifdef CONFIG_SCHED_DEBUG
243 {
244 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100245 .procname = "sched_min_granularity_ns",
246 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200247 .maxlen = sizeof(unsigned int),
248 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100249 .proc_handler = &sched_nr_latency_handler,
250 .strategy = &sysctl_intvec,
251 .extra1 = &min_sched_granularity_ns,
252 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200253 },
254 {
255 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200256 .procname = "sched_latency_ns",
257 .data = &sysctl_sched_latency,
258 .maxlen = sizeof(unsigned int),
259 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100260 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200261 .strategy = &sysctl_intvec,
262 .extra1 = &min_sched_granularity_ns,
263 .extra2 = &max_sched_granularity_ns,
264 },
265 {
266 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200267 .procname = "sched_wakeup_granularity_ns",
268 .data = &sysctl_sched_wakeup_granularity,
269 .maxlen = sizeof(unsigned int),
270 .mode = 0644,
271 .proc_handler = &proc_dointvec_minmax,
272 .strategy = &sysctl_intvec,
273 .extra1 = &min_wakeup_granularity_ns,
274 .extra2 = &max_wakeup_granularity_ns,
275 },
276 {
277 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200278 .procname = "sched_shares_ratelimit",
279 .data = &sysctl_sched_shares_ratelimit,
280 .maxlen = sizeof(unsigned int),
281 .mode = 0644,
282 .proc_handler = &proc_dointvec,
283 },
284 {
285 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200286 .procname = "sched_shares_thresh",
287 .data = &sysctl_sched_shares_thresh,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec_minmax,
291 .strategy = &sysctl_intvec,
292 .extra1 = &zero,
293 },
294 {
295 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200296 .procname = "sched_child_runs_first",
297 .data = &sysctl_sched_child_runs_first,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
300 .proc_handler = &proc_dointvec,
301 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200302 {
303 .ctl_name = CTL_UNNUMBERED,
304 .procname = "sched_features",
305 .data = &sysctl_sched_features,
306 .maxlen = sizeof(unsigned int),
307 .mode = 0644,
308 .proc_handler = &proc_dointvec,
309 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200310 {
311 .ctl_name = CTL_UNNUMBERED,
312 .procname = "sched_migration_cost",
313 .data = &sysctl_sched_migration_cost,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
316 .proc_handler = &proc_dointvec,
317 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100318 {
319 .ctl_name = CTL_UNNUMBERED,
320 .procname = "sched_nr_migrate",
321 .data = &sysctl_sched_nr_migrate,
322 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100323 .mode = 0644,
324 .proc_handler = &proc_dointvec,
325 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200326#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200327 {
328 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100329 .procname = "sched_rt_period_us",
330 .data = &sysctl_sched_rt_period,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200333 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100334 },
335 {
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "sched_rt_runtime_us",
338 .data = &sysctl_sched_rt_runtime,
339 .maxlen = sizeof(int),
340 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200341 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100342 },
343 {
344 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200345 .procname = "sched_compat_yield",
346 .data = &sysctl_sched_compat_yield,
347 .maxlen = sizeof(unsigned int),
348 .mode = 0644,
349 .proc_handler = &proc_dointvec,
350 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700351#ifdef CONFIG_PROVE_LOCKING
352 {
353 .ctl_name = CTL_UNNUMBERED,
354 .procname = "prove_locking",
355 .data = &prove_locking,
356 .maxlen = sizeof(int),
357 .mode = 0644,
358 .proc_handler = &proc_dointvec,
359 },
360#endif
361#ifdef CONFIG_LOCK_STAT
362 {
363 .ctl_name = CTL_UNNUMBERED,
364 .procname = "lock_stat",
365 .data = &lock_stat,
366 .maxlen = sizeof(int),
367 .mode = 0644,
368 .proc_handler = &proc_dointvec,
369 },
370#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200371 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 .ctl_name = KERN_PANIC,
373 .procname = "panic",
374 .data = &panic_timeout,
375 .maxlen = sizeof(int),
376 .mode = 0644,
377 .proc_handler = &proc_dointvec,
378 },
379 {
380 .ctl_name = KERN_CORE_USES_PID,
381 .procname = "core_uses_pid",
382 .data = &core_uses_pid,
383 .maxlen = sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
386 },
387 {
388 .ctl_name = KERN_CORE_PATTERN,
389 .procname = "core_pattern",
390 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700391 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 .mode = 0644,
393 .proc_handler = &proc_dostring,
394 .strategy = &sysctl_string,
395 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800396#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700399 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800400 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700401 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800403#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100404#ifdef CONFIG_LATENCYTOP
405 {
406 .procname = "latencytop",
407 .data = &latencytop_enabled,
408 .maxlen = sizeof(int),
409 .mode = 0644,
410 .proc_handler = &proc_dointvec,
411 },
412#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413#ifdef CONFIG_BLK_DEV_INITRD
414 {
415 .ctl_name = KERN_REALROOTDEV,
416 .procname = "real-root-dev",
417 .data = &real_root_dev,
418 .maxlen = sizeof(int),
419 .mode = 0644,
420 .proc_handler = &proc_dointvec,
421 },
422#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700423 {
424 .ctl_name = CTL_UNNUMBERED,
425 .procname = "print-fatal-signals",
426 .data = &print_fatal_signals,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700431#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 {
433 .ctl_name = KERN_SPARC_REBOOT,
434 .procname = "reboot-cmd",
435 .data = reboot_command,
436 .maxlen = 256,
437 .mode = 0644,
438 .proc_handler = &proc_dostring,
439 .strategy = &sysctl_string,
440 },
441 {
442 .ctl_name = KERN_SPARC_STOP_A,
443 .procname = "stop-a",
444 .data = &stop_a_enabled,
445 .maxlen = sizeof (int),
446 .mode = 0644,
447 .proc_handler = &proc_dointvec,
448 },
449 {
450 .ctl_name = KERN_SPARC_SCONS_PWROFF,
451 .procname = "scons-poweroff",
452 .data = &scons_pwroff,
453 .maxlen = sizeof (int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
456 },
457#endif
David S. Miller08714202008-11-16 23:49:24 -0800458#ifdef CONFIG_SPARC64
459 {
460 .ctl_name = CTL_UNNUMBERED,
461 .procname = "tsb-ratio",
462 .data = &sysctl_tsb_ratio,
463 .maxlen = sizeof (int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
466 },
467#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#ifdef __hppa__
469 {
470 .ctl_name = KERN_HPPA_PWRSW,
471 .procname = "soft-power",
472 .data = &pwrsw_enabled,
473 .maxlen = sizeof (int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec,
476 },
477 {
478 .ctl_name = KERN_HPPA_UNALIGNED,
479 .procname = "unaligned-trap",
480 .data = &unaligned_enabled,
481 .maxlen = sizeof (int),
482 .mode = 0644,
483 .proc_handler = &proc_dointvec,
484 },
485#endif
486 {
487 .ctl_name = KERN_CTLALTDEL,
488 .procname = "ctrl-alt-del",
489 .data = &C_A_D,
490 .maxlen = sizeof(int),
491 .mode = 0644,
492 .proc_handler = &proc_dointvec,
493 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400494#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200495 {
496 .ctl_name = CTL_UNNUMBERED,
497 .procname = "ftrace_enabled",
498 .data = &ftrace_enabled,
499 .maxlen = sizeof(int),
500 .mode = 0644,
501 .proc_handler = &ftrace_enable_sysctl,
502 },
503#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200504#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 {
506 .ctl_name = KERN_MODPROBE,
507 .procname = "modprobe",
508 .data = &modprobe_path,
509 .maxlen = KMOD_PATH_LEN,
510 .mode = 0644,
511 .proc_handler = &proc_dostring,
512 .strategy = &sysctl_string,
513 },
514#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700515#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 {
517 .ctl_name = KERN_HOTPLUG,
518 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100519 .data = &uevent_helper,
520 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 .mode = 0644,
522 .proc_handler = &proc_dostring,
523 .strategy = &sysctl_string,
524 },
525#endif
526#ifdef CONFIG_CHR_DEV_SG
527 {
528 .ctl_name = KERN_SG_BIG_BUFF,
529 .procname = "sg-big-buff",
530 .data = &sg_big_buff,
531 .maxlen = sizeof (int),
532 .mode = 0444,
533 .proc_handler = &proc_dointvec,
534 },
535#endif
536#ifdef CONFIG_BSD_PROCESS_ACCT
537 {
538 .ctl_name = KERN_ACCT,
539 .procname = "acct",
540 .data = &acct_parm,
541 .maxlen = 3*sizeof(int),
542 .mode = 0644,
543 .proc_handler = &proc_dointvec,
544 },
545#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546#ifdef CONFIG_MAGIC_SYSRQ
547 {
548 .ctl_name = KERN_SYSRQ,
549 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800550 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 .maxlen = sizeof (int),
552 .mode = 0644,
553 .proc_handler = &proc_dointvec,
554 },
555#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700556#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700559 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 .maxlen = sizeof (int),
561 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700562 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700564#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 {
566 .ctl_name = KERN_MAX_THREADS,
567 .procname = "threads-max",
568 .data = &max_threads,
569 .maxlen = sizeof(int),
570 .mode = 0644,
571 .proc_handler = &proc_dointvec,
572 },
573 {
574 .ctl_name = KERN_RANDOM,
575 .procname = "random",
576 .mode = 0555,
577 .child = random_table,
578 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 {
580 .ctl_name = KERN_OVERFLOWUID,
581 .procname = "overflowuid",
582 .data = &overflowuid,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec_minmax,
586 .strategy = &sysctl_intvec,
587 .extra1 = &minolduid,
588 .extra2 = &maxolduid,
589 },
590 {
591 .ctl_name = KERN_OVERFLOWGID,
592 .procname = "overflowgid",
593 .data = &overflowgid,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec_minmax,
597 .strategy = &sysctl_intvec,
598 .extra1 = &minolduid,
599 .extra2 = &maxolduid,
600 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800601#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602#ifdef CONFIG_MATHEMU
603 {
604 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
605 .procname = "ieee_emulation_warnings",
606 .data = &sysctl_ieee_emulation_warnings,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec,
610 },
611#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 {
613 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
614 .procname = "userprocess_debug",
615 .data = &sysctl_userprocess_debug,
616 .maxlen = sizeof(int),
617 .mode = 0644,
618 .proc_handler = &proc_dointvec,
619 },
620#endif
621 {
622 .ctl_name = KERN_PIDMAX,
623 .procname = "pid_max",
624 .data = &pid_max,
625 .maxlen = sizeof (int),
626 .mode = 0644,
627 .proc_handler = &proc_dointvec_minmax,
628 .strategy = sysctl_intvec,
629 .extra1 = &pid_max_min,
630 .extra2 = &pid_max_max,
631 },
632 {
633 .ctl_name = KERN_PANIC_ON_OOPS,
634 .procname = "panic_on_oops",
635 .data = &panic_on_oops,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec,
639 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800640#if defined CONFIG_PRINTK
641 {
642 .ctl_name = KERN_PRINTK,
643 .procname = "printk",
644 .data = &console_loglevel,
645 .maxlen = 4*sizeof(int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
648 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 {
650 .ctl_name = KERN_PRINTK_RATELIMIT,
651 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700652 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec_jiffies,
656 .strategy = &sysctl_jiffies,
657 },
658 {
659 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
660 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700661 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 .maxlen = sizeof(int),
663 .mode = 0644,
664 .proc_handler = &proc_dointvec,
665 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800666#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 {
668 .ctl_name = KERN_NGROUPS_MAX,
669 .procname = "ngroups_max",
670 .data = &ngroups_max,
671 .maxlen = sizeof (int),
672 .mode = 0444,
673 .proc_handler = &proc_dointvec,
674 },
675#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
676 {
677 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
678 .procname = "unknown_nmi_panic",
679 .data = &unknown_nmi_panic,
680 .maxlen = sizeof (int),
681 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200682 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 },
Don Zickus407984f2006-09-26 10:52:27 +0200684 {
Don Zickus407984f2006-09-26 10:52:27 +0200685 .procname = "nmi_watchdog",
686 .data = &nmi_watchdog_enabled,
687 .maxlen = sizeof (int),
688 .mode = 0644,
689 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 },
691#endif
692#if defined(CONFIG_X86)
693 {
Don Zickus8da5add2006-09-26 10:52:27 +0200694 .ctl_name = KERN_PANIC_ON_NMI,
695 .procname = "panic_on_unrecovered_nmi",
696 .data = &panic_on_unrecovered_nmi,
697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec,
700 },
701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .ctl_name = KERN_BOOTLOADER_TYPE,
703 .procname = "bootloader_type",
704 .data = &bootloader_type,
705 .maxlen = sizeof (int),
706 .mode = 0444,
707 .proc_handler = &proc_dointvec,
708 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100709 {
710 .ctl_name = CTL_UNNUMBERED,
711 .procname = "kstack_depth_to_print",
712 .data = &kstack_depth_to_print,
713 .maxlen = sizeof(int),
714 .mode = 0644,
715 .proc_handler = &proc_dointvec,
716 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100717 {
718 .ctl_name = CTL_UNNUMBERED,
719 .procname = "io_delay_type",
720 .data = &io_delay_type,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec,
724 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800726#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 {
728 .ctl_name = KERN_RANDOMIZE,
729 .procname = "randomize_va_space",
730 .data = &randomize_va_space,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = &proc_dointvec,
734 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800735#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800736#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700737 {
738 .ctl_name = KERN_SPIN_RETRY,
739 .procname = "spin_retry",
740 .data = &spin_retry,
741 .maxlen = sizeof (int),
742 .mode = 0644,
743 .proc_handler = &proc_dointvec,
744 },
745#endif
Len Brown673d5b42007-07-28 03:33:16 -0400746#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800747 {
Pavel Machekc255d842006-02-20 18:27:58 -0800748 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700749 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800750 .maxlen = sizeof (unsigned long),
751 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800752 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800753 },
754#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800755#ifdef CONFIG_IA64
756 {
757 .ctl_name = KERN_IA64_UNALIGNED,
758 .procname = "ignore-unaligned-usertrap",
759 .data = &no_unaligned_warning,
760 .maxlen = sizeof (int),
761 .mode = 0644,
762 .proc_handler = &proc_dointvec,
763 },
764#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700765#ifdef CONFIG_DETECT_SOFTLOCKUP
766 {
767 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200768 .procname = "softlockup_panic",
769 .data = &softlockup_panic,
770 .maxlen = sizeof(int),
771 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700772 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200773 .strategy = &sysctl_intvec,
774 .extra1 = &zero,
775 .extra2 = &one,
776 },
777 {
778 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700779 .procname = "softlockup_thresh",
780 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200781 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700782 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200783 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700784 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200785 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700786 .extra2 = &sixty,
787 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100788 {
789 .ctl_name = CTL_UNNUMBERED,
790 .procname = "hung_task_check_count",
791 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100792 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100793 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100794 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100795 .strategy = &sysctl_intvec,
796 },
797 {
798 .ctl_name = CTL_UNNUMBERED,
799 .procname = "hung_task_timeout_secs",
800 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100801 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100802 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100803 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100804 .strategy = &sysctl_intvec,
805 },
806 {
807 .ctl_name = CTL_UNNUMBERED,
808 .procname = "hung_task_warnings",
809 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100810 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100811 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100812 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100813 .strategy = &sysctl_intvec,
814 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700815#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200816#ifdef CONFIG_COMPAT
817 {
818 .ctl_name = KERN_COMPAT_LOG,
819 .procname = "compat-log",
820 .data = &compat_log,
821 .maxlen = sizeof (int),
822 .mode = 0644,
823 .proc_handler = &proc_dointvec,
824 },
825#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700826#ifdef CONFIG_RT_MUTEXES
827 {
828 .ctl_name = KERN_MAX_LOCK_DEPTH,
829 .procname = "max_lock_depth",
830 .data = &max_lock_depth,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec,
834 },
835#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700836 {
837 .ctl_name = CTL_UNNUMBERED,
838 .procname = "poweroff_cmd",
839 .data = &poweroff_cmd,
840 .maxlen = POWEROFF_CMD_PATH_LEN,
841 .mode = 0644,
842 .proc_handler = &proc_dostring,
843 .strategy = &sysctl_string,
844 },
David Howells0b77f5b2008-04-29 01:01:32 -0700845#ifdef CONFIG_KEYS
846 {
847 .ctl_name = CTL_UNNUMBERED,
848 .procname = "keys",
849 .mode = 0555,
850 .child = key_sysctls,
851 },
852#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700853#ifdef CONFIG_RCU_TORTURE_TEST
854 {
855 .ctl_name = CTL_UNNUMBERED,
856 .procname = "rcutorture_runnable",
857 .data = &rcutorture_runnable,
858 .maxlen = sizeof(int),
859 .mode = 0644,
860 .proc_handler = &proc_dointvec,
861 },
862#endif
Lee Schermerhornaf936a12008-10-18 20:26:53 -0700863#ifdef CONFIG_UNEVICTABLE_LRU
864 {
865 .ctl_name = CTL_UNNUMBERED,
866 .procname = "scan_unevictable_pages",
867 .data = &scan_unevictable_pages,
868 .maxlen = sizeof(scan_unevictable_pages),
869 .mode = 0644,
870 .proc_handler = &scan_unevictable_handler,
871 },
872#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700873/*
874 * NOTE: do not add new entries to this table unless you have read
875 * Documentation/sysctl/ctl_unnumbered.txt
876 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 { .ctl_name = 0 }
878};
879
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700880static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 {
882 .ctl_name = VM_OVERCOMMIT_MEMORY,
883 .procname = "overcommit_memory",
884 .data = &sysctl_overcommit_memory,
885 .maxlen = sizeof(sysctl_overcommit_memory),
886 .mode = 0644,
887 .proc_handler = &proc_dointvec,
888 },
889 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700890 .ctl_name = VM_PANIC_ON_OOM,
891 .procname = "panic_on_oom",
892 .data = &sysctl_panic_on_oom,
893 .maxlen = sizeof(sysctl_panic_on_oom),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec,
896 },
897 {
David Rientjesfe071d72007-10-16 23:25:56 -0700898 .ctl_name = CTL_UNNUMBERED,
899 .procname = "oom_kill_allocating_task",
900 .data = &sysctl_oom_kill_allocating_task,
901 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
902 .mode = 0644,
903 .proc_handler = &proc_dointvec,
904 },
905 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800906 .ctl_name = CTL_UNNUMBERED,
907 .procname = "oom_dump_tasks",
908 .data = &sysctl_oom_dump_tasks,
909 .maxlen = sizeof(sysctl_oom_dump_tasks),
910 .mode = 0644,
911 .proc_handler = &proc_dointvec,
912 },
913 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 .ctl_name = VM_OVERCOMMIT_RATIO,
915 .procname = "overcommit_ratio",
916 .data = &sysctl_overcommit_ratio,
917 .maxlen = sizeof(sysctl_overcommit_ratio),
918 .mode = 0644,
919 .proc_handler = &proc_dointvec,
920 },
921 {
922 .ctl_name = VM_PAGE_CLUSTER,
923 .procname = "page-cluster",
924 .data = &page_cluster,
925 .maxlen = sizeof(int),
926 .mode = 0644,
927 .proc_handler = &proc_dointvec,
928 },
929 {
930 .ctl_name = VM_DIRTY_BACKGROUND,
931 .procname = "dirty_background_ratio",
932 .data = &dirty_background_ratio,
933 .maxlen = sizeof(dirty_background_ratio),
934 .mode = 0644,
935 .proc_handler = &proc_dointvec_minmax,
936 .strategy = &sysctl_intvec,
937 .extra1 = &zero,
938 .extra2 = &one_hundred,
939 },
940 {
941 .ctl_name = VM_DIRTY_RATIO,
942 .procname = "dirty_ratio",
943 .data = &vm_dirty_ratio,
944 .maxlen = sizeof(vm_dirty_ratio),
945 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700946 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 .strategy = &sysctl_intvec,
948 .extra1 = &zero,
949 .extra2 = &one_hundred,
950 },
951 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800953 .data = &dirty_writeback_interval,
954 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 .mode = 0644,
956 .proc_handler = &dirty_writeback_centisecs_handler,
957 },
958 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800960 .data = &dirty_expire_interval,
961 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800963 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 },
965 {
966 .ctl_name = VM_NR_PDFLUSH_THREADS,
967 .procname = "nr_pdflush_threads",
968 .data = &nr_pdflush_threads,
969 .maxlen = sizeof nr_pdflush_threads,
970 .mode = 0444 /* read-only*/,
971 .proc_handler = &proc_dointvec,
972 },
973 {
974 .ctl_name = VM_SWAPPINESS,
975 .procname = "swappiness",
976 .data = &vm_swappiness,
977 .maxlen = sizeof(vm_swappiness),
978 .mode = 0644,
979 .proc_handler = &proc_dointvec_minmax,
980 .strategy = &sysctl_intvec,
981 .extra1 = &zero,
982 .extra2 = &one_hundred,
983 },
984#ifdef CONFIG_HUGETLB_PAGE
985 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700987 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 .maxlen = sizeof(unsigned long),
989 .mode = 0644,
990 .proc_handler = &hugetlb_sysctl_handler,
991 .extra1 = (void *)&hugetlb_zero,
992 .extra2 = (void *)&hugetlb_infinity,
993 },
994 {
995 .ctl_name = VM_HUGETLB_GROUP,
996 .procname = "hugetlb_shm_group",
997 .data = &sysctl_hugetlb_shm_group,
998 .maxlen = sizeof(gid_t),
999 .mode = 0644,
1000 .proc_handler = &proc_dointvec,
1001 },
Mel Gorman396faf02007-07-17 04:03:13 -07001002 {
1003 .ctl_name = CTL_UNNUMBERED,
1004 .procname = "hugepages_treat_as_movable",
1005 .data = &hugepages_treat_as_movable,
1006 .maxlen = sizeof(int),
1007 .mode = 0644,
1008 .proc_handler = &hugetlb_treat_movable_handler,
1009 },
Adam Litke54f9f802007-10-16 01:26:20 -07001010 {
1011 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001012 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001013 .data = NULL,
1014 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001015 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001016 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001017 .extra1 = (void *)&hugetlb_zero,
1018 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001019 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020#endif
1021 {
1022 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1023 .procname = "lowmem_reserve_ratio",
1024 .data = &sysctl_lowmem_reserve_ratio,
1025 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1026 .mode = 0644,
1027 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1028 .strategy = &sysctl_intvec,
1029 },
1030 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001031 .ctl_name = VM_DROP_PAGECACHE,
1032 .procname = "drop_caches",
1033 .data = &sysctl_drop_caches,
1034 .maxlen = sizeof(int),
1035 .mode = 0644,
1036 .proc_handler = drop_caches_sysctl_handler,
1037 .strategy = &sysctl_intvec,
1038 },
1039 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .ctl_name = VM_MIN_FREE_KBYTES,
1041 .procname = "min_free_kbytes",
1042 .data = &min_free_kbytes,
1043 .maxlen = sizeof(min_free_kbytes),
1044 .mode = 0644,
1045 .proc_handler = &min_free_kbytes_sysctl_handler,
1046 .strategy = &sysctl_intvec,
1047 .extra1 = &zero,
1048 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001049 {
1050 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1051 .procname = "percpu_pagelist_fraction",
1052 .data = &percpu_pagelist_fraction,
1053 .maxlen = sizeof(percpu_pagelist_fraction),
1054 .mode = 0644,
1055 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1056 .strategy = &sysctl_intvec,
1057 .extra1 = &min_percpu_pagelist_fract,
1058 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059#ifdef CONFIG_MMU
1060 {
1061 .ctl_name = VM_MAX_MAP_COUNT,
1062 .procname = "max_map_count",
1063 .data = &sysctl_max_map_count,
1064 .maxlen = sizeof(sysctl_max_map_count),
1065 .mode = 0644,
1066 .proc_handler = &proc_dointvec
1067 },
1068#endif
1069 {
1070 .ctl_name = VM_LAPTOP_MODE,
1071 .procname = "laptop_mode",
1072 .data = &laptop_mode,
1073 .maxlen = sizeof(laptop_mode),
1074 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001075 .proc_handler = &proc_dointvec_jiffies,
1076 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 },
1078 {
1079 .ctl_name = VM_BLOCK_DUMP,
1080 .procname = "block_dump",
1081 .data = &block_dump,
1082 .maxlen = sizeof(block_dump),
1083 .mode = 0644,
1084 .proc_handler = &proc_dointvec,
1085 .strategy = &sysctl_intvec,
1086 .extra1 = &zero,
1087 },
1088 {
1089 .ctl_name = VM_VFS_CACHE_PRESSURE,
1090 .procname = "vfs_cache_pressure",
1091 .data = &sysctl_vfs_cache_pressure,
1092 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1093 .mode = 0644,
1094 .proc_handler = &proc_dointvec,
1095 .strategy = &sysctl_intvec,
1096 .extra1 = &zero,
1097 },
1098#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1099 {
1100 .ctl_name = VM_LEGACY_VA_LAYOUT,
1101 .procname = "legacy_va_layout",
1102 .data = &sysctl_legacy_va_layout,
1103 .maxlen = sizeof(sysctl_legacy_va_layout),
1104 .mode = 0644,
1105 .proc_handler = &proc_dointvec,
1106 .strategy = &sysctl_intvec,
1107 .extra1 = &zero,
1108 },
1109#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001110#ifdef CONFIG_NUMA
1111 {
1112 .ctl_name = VM_ZONE_RECLAIM_MODE,
1113 .procname = "zone_reclaim_mode",
1114 .data = &zone_reclaim_mode,
1115 .maxlen = sizeof(zone_reclaim_mode),
1116 .mode = 0644,
1117 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001118 .strategy = &sysctl_intvec,
1119 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001120 },
Christoph Lameter96146342006-07-03 00:24:13 -07001121 {
1122 .ctl_name = VM_MIN_UNMAPPED,
1123 .procname = "min_unmapped_ratio",
1124 .data = &sysctl_min_unmapped_ratio,
1125 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1126 .mode = 0644,
1127 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1128 .strategy = &sysctl_intvec,
1129 .extra1 = &zero,
1130 .extra2 = &one_hundred,
1131 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001132 {
1133 .ctl_name = VM_MIN_SLAB,
1134 .procname = "min_slab_ratio",
1135 .data = &sysctl_min_slab_ratio,
1136 .maxlen = sizeof(sysctl_min_slab_ratio),
1137 .mode = 0644,
1138 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1139 .strategy = &sysctl_intvec,
1140 .extra1 = &zero,
1141 .extra2 = &one_hundred,
1142 },
Christoph Lameter17436602006-01-18 17:42:32 -08001143#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001144#ifdef CONFIG_SMP
1145 {
1146 .ctl_name = CTL_UNNUMBERED,
1147 .procname = "stat_interval",
1148 .data = &sysctl_stat_interval,
1149 .maxlen = sizeof(sysctl_stat_interval),
1150 .mode = 0644,
1151 .proc_handler = &proc_dointvec_jiffies,
1152 .strategy = &sysctl_jiffies,
1153 },
1154#endif
Eric Parised032182007-06-28 15:55:21 -04001155#ifdef CONFIG_SECURITY
1156 {
1157 .ctl_name = CTL_UNNUMBERED,
1158 .procname = "mmap_min_addr",
1159 .data = &mmap_min_addr,
1160 .maxlen = sizeof(unsigned long),
1161 .mode = 0644,
1162 .proc_handler = &proc_doulongvec_minmax,
1163 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001164#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001165#ifdef CONFIG_NUMA
1166 {
1167 .ctl_name = CTL_UNNUMBERED,
1168 .procname = "numa_zonelist_order",
1169 .data = &numa_zonelist_order,
1170 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1171 .mode = 0644,
1172 .proc_handler = &numa_zonelist_order_handler,
1173 .strategy = &sysctl_string,
1174 },
1175#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001176#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001177 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001178 {
1179 .ctl_name = VM_VDSO_ENABLED,
1180 .procname = "vdso_enabled",
1181 .data = &vdso_enabled,
1182 .maxlen = sizeof(vdso_enabled),
1183 .mode = 0644,
1184 .proc_handler = &proc_dointvec,
1185 .strategy = &sysctl_intvec,
1186 .extra1 = &zero,
1187 },
1188#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001189#ifdef CONFIG_HIGHMEM
1190 {
1191 .ctl_name = CTL_UNNUMBERED,
1192 .procname = "highmem_is_dirtyable",
1193 .data = &vm_highmem_is_dirtyable,
1194 .maxlen = sizeof(vm_highmem_is_dirtyable),
1195 .mode = 0644,
1196 .proc_handler = &proc_dointvec_minmax,
1197 .strategy = &sysctl_intvec,
1198 .extra1 = &zero,
1199 .extra2 = &one,
1200 },
1201#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001202/*
1203 * NOTE: do not add new entries to this table unless you have read
1204 * Documentation/sysctl/ctl_unnumbered.txt
1205 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 { .ctl_name = 0 }
1207};
1208
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001209#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001210static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001211 { .ctl_name = 0 }
1212};
1213#endif
1214
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001215static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 {
1217 .ctl_name = FS_NRINODE,
1218 .procname = "inode-nr",
1219 .data = &inodes_stat,
1220 .maxlen = 2*sizeof(int),
1221 .mode = 0444,
1222 .proc_handler = &proc_dointvec,
1223 },
1224 {
1225 .ctl_name = FS_STATINODE,
1226 .procname = "inode-state",
1227 .data = &inodes_stat,
1228 .maxlen = 7*sizeof(int),
1229 .mode = 0444,
1230 .proc_handler = &proc_dointvec,
1231 },
1232 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 .procname = "file-nr",
1234 .data = &files_stat,
1235 .maxlen = 3*sizeof(int),
1236 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001237 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 },
1239 {
1240 .ctl_name = FS_MAXFILE,
1241 .procname = "file-max",
1242 .data = &files_stat.max_files,
1243 .maxlen = sizeof(int),
1244 .mode = 0644,
1245 .proc_handler = &proc_dointvec,
1246 },
1247 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001248 .ctl_name = CTL_UNNUMBERED,
1249 .procname = "nr_open",
1250 .data = &sysctl_nr_open,
1251 .maxlen = sizeof(int),
1252 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001253 .proc_handler = &proc_dointvec_minmax,
1254 .extra1 = &sysctl_nr_open_min,
1255 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001256 },
1257 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 .ctl_name = FS_DENTRY,
1259 .procname = "dentry-state",
1260 .data = &dentry_stat,
1261 .maxlen = 6*sizeof(int),
1262 .mode = 0444,
1263 .proc_handler = &proc_dointvec,
1264 },
1265 {
1266 .ctl_name = FS_OVERFLOWUID,
1267 .procname = "overflowuid",
1268 .data = &fs_overflowuid,
1269 .maxlen = sizeof(int),
1270 .mode = 0644,
1271 .proc_handler = &proc_dointvec_minmax,
1272 .strategy = &sysctl_intvec,
1273 .extra1 = &minolduid,
1274 .extra2 = &maxolduid,
1275 },
1276 {
1277 .ctl_name = FS_OVERFLOWGID,
1278 .procname = "overflowgid",
1279 .data = &fs_overflowgid,
1280 .maxlen = sizeof(int),
1281 .mode = 0644,
1282 .proc_handler = &proc_dointvec_minmax,
1283 .strategy = &sysctl_intvec,
1284 .extra1 = &minolduid,
1285 .extra2 = &maxolduid,
1286 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001287#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 {
1289 .ctl_name = FS_LEASES,
1290 .procname = "leases-enable",
1291 .data = &leases_enable,
1292 .maxlen = sizeof(int),
1293 .mode = 0644,
1294 .proc_handler = &proc_dointvec,
1295 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001296#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297#ifdef CONFIG_DNOTIFY
1298 {
1299 .ctl_name = FS_DIR_NOTIFY,
1300 .procname = "dir-notify-enable",
1301 .data = &dir_notify_enable,
1302 .maxlen = sizeof(int),
1303 .mode = 0644,
1304 .proc_handler = &proc_dointvec,
1305 },
1306#endif
1307#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001308#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 {
1310 .ctl_name = FS_LEASE_TIME,
1311 .procname = "lease-break-time",
1312 .data = &lease_break_time,
1313 .maxlen = sizeof(int),
1314 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001315 .proc_handler = &proc_dointvec_minmax,
1316 .strategy = &sysctl_intvec,
1317 .extra1 = &zero,
1318 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001320#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001321#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 .procname = "aio-nr",
1324 .data = &aio_nr,
1325 .maxlen = sizeof(aio_nr),
1326 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001327 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 },
1329 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 .procname = "aio-max-nr",
1331 .data = &aio_max_nr,
1332 .maxlen = sizeof(aio_max_nr),
1333 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001334 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001336#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001337#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001338 {
1339 .ctl_name = FS_INOTIFY,
1340 .procname = "inotify",
1341 .mode = 0555,
1342 .child = inotify_table,
1343 },
1344#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001345#ifdef CONFIG_EPOLL
1346 {
1347 .procname = "epoll",
1348 .mode = 0555,
1349 .child = epoll_table,
1350 },
1351#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001353 {
1354 .ctl_name = KERN_SETUID_DUMPABLE,
1355 .procname = "suid_dumpable",
1356 .data = &suid_dumpable,
1357 .maxlen = sizeof(int),
1358 .mode = 0644,
1359 .proc_handler = &proc_dointvec,
1360 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001361#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1362 {
1363 .ctl_name = CTL_UNNUMBERED,
1364 .procname = "binfmt_misc",
1365 .mode = 0555,
1366 .child = binfmt_misc_table,
1367 },
1368#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001369/*
1370 * NOTE: do not add new entries to this table unless you have read
1371 * Documentation/sysctl/ctl_unnumbered.txt
1372 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 { .ctl_name = 0 }
1374};
1375
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001376static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001377#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001378 {
1379 .ctl_name = CTL_UNNUMBERED,
1380 .procname = "exception-trace",
1381 .data = &show_unhandled_signals,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = proc_dointvec
1385 },
1386#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 { .ctl_name = 0 }
1388};
1389
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001390static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001392};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Al Viro330d57f2005-11-04 10:18:40 +00001394static DEFINE_SPINLOCK(sysctl_lock);
1395
1396/* called under sysctl_lock */
1397static int use_table(struct ctl_table_header *p)
1398{
1399 if (unlikely(p->unregistering))
1400 return 0;
1401 p->used++;
1402 return 1;
1403}
1404
1405/* called under sysctl_lock */
1406static void unuse_table(struct ctl_table_header *p)
1407{
1408 if (!--p->used)
1409 if (unlikely(p->unregistering))
1410 complete(p->unregistering);
1411}
1412
1413/* called under sysctl_lock, will reacquire if has to wait */
1414static void start_unregistering(struct ctl_table_header *p)
1415{
1416 /*
1417 * if p->used is 0, nobody will ever touch that entry again;
1418 * we'll eliminate all paths to it before dropping sysctl_lock
1419 */
1420 if (unlikely(p->used)) {
1421 struct completion wait;
1422 init_completion(&wait);
1423 p->unregistering = &wait;
1424 spin_unlock(&sysctl_lock);
1425 wait_for_completion(&wait);
1426 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001427 } else {
1428 /* anything non-NULL; we'll never dereference it */
1429 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001430 }
1431 /*
1432 * do not remove from the list until nobody holds it; walking the
1433 * list in do_sysctl() relies on that.
1434 */
1435 list_del_init(&p->ctl_entry);
1436}
1437
Al Virof7e6ced2008-07-15 01:44:23 -04001438void sysctl_head_get(struct ctl_table_header *head)
1439{
1440 spin_lock(&sysctl_lock);
1441 head->count++;
1442 spin_unlock(&sysctl_lock);
1443}
1444
1445void sysctl_head_put(struct ctl_table_header *head)
1446{
1447 spin_lock(&sysctl_lock);
1448 if (!--head->count)
1449 kfree(head);
1450 spin_unlock(&sysctl_lock);
1451}
1452
1453struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1454{
1455 if (!head)
1456 BUG();
1457 spin_lock(&sysctl_lock);
1458 if (!use_table(head))
1459 head = ERR_PTR(-ENOENT);
1460 spin_unlock(&sysctl_lock);
1461 return head;
1462}
1463
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001464void sysctl_head_finish(struct ctl_table_header *head)
1465{
1466 if (!head)
1467 return;
1468 spin_lock(&sysctl_lock);
1469 unuse_table(head);
1470 spin_unlock(&sysctl_lock);
1471}
1472
Al Viro73455092008-07-14 21:22:20 -04001473static struct ctl_table_set *
1474lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1475{
1476 struct ctl_table_set *set = &root->default_set;
1477 if (root->lookup)
1478 set = root->lookup(root, namespaces);
1479 return set;
1480}
1481
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001482static struct list_head *
1483lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001484{
Al Viro73455092008-07-14 21:22:20 -04001485 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1486 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001487}
1488
1489struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1490 struct ctl_table_header *prev)
1491{
1492 struct ctl_table_root *root;
1493 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001494 struct ctl_table_header *head;
1495 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001496
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001497 spin_lock(&sysctl_lock);
1498 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001499 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001500 tmp = &prev->ctl_entry;
1501 unuse_table(prev);
1502 goto next;
1503 }
1504 tmp = &root_table_header.ctl_entry;
1505 for (;;) {
1506 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1507
1508 if (!use_table(head))
1509 goto next;
1510 spin_unlock(&sysctl_lock);
1511 return head;
1512 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001513 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001514 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001515 header_list = lookup_header_list(root, namespaces);
1516 if (tmp != header_list)
1517 continue;
1518
1519 do {
1520 root = list_entry(root->root_list.next,
1521 struct ctl_table_root, root_list);
1522 if (root == &sysctl_table_root)
1523 goto out;
1524 header_list = lookup_header_list(root, namespaces);
1525 } while (list_empty(header_list));
1526 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001527 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001528out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001529 spin_unlock(&sysctl_lock);
1530 return NULL;
1531}
1532
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001533struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1534{
1535 return __sysctl_head_next(current->nsproxy, prev);
1536}
1537
1538void register_sysctl_root(struct ctl_table_root *root)
1539{
1540 spin_lock(&sysctl_lock);
1541 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1542 spin_unlock(&sysctl_lock);
1543}
1544
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001545#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001546/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001547static int do_sysctl_strategy(struct ctl_table_root *root,
1548 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001549 void __user *oldval, size_t __user *oldlenp,
1550 void __user *newval, size_t newlen)
1551{
1552 int op = 0, rc;
1553
1554 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001555 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001556 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001557 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001558 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001559 return -EPERM;
1560
1561 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001562 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001563 if (rc < 0)
1564 return rc;
1565 if (rc > 0)
1566 return 0;
1567 }
1568
1569 /* If there is no strategy routine, or if the strategy returns
1570 * zero, proceed with automatic r/w */
1571 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001572 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001573 if (rc < 0)
1574 return rc;
1575 }
1576 return 0;
1577}
1578
1579static int parse_table(int __user *name, int nlen,
1580 void __user *oldval, size_t __user *oldlenp,
1581 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001582 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001583 struct ctl_table *table)
1584{
1585 int n;
1586repeat:
1587 if (!nlen)
1588 return -ENOTDIR;
1589 if (get_user(n, name))
1590 return -EFAULT;
1591 for ( ; table->ctl_name || table->procname; table++) {
1592 if (!table->ctl_name)
1593 continue;
1594 if (n == table->ctl_name) {
1595 int error;
1596 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001597 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001598 return -EPERM;
1599 name++;
1600 nlen--;
1601 table = table->child;
1602 goto repeat;
1603 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001604 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001605 oldval, oldlenp,
1606 newval, newlen);
1607 return error;
1608 }
1609 }
1610 return -ENOTDIR;
1611}
1612
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1614 void __user *newval, size_t newlen)
1615{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001616 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001617 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
1619 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1620 return -ENOTDIR;
1621 if (oldval) {
1622 int old_len;
1623 if (!oldlenp || get_user(old_len, oldlenp))
1624 return -EFAULT;
1625 }
Al Viro330d57f2005-11-04 10:18:40 +00001626
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001627 for (head = sysctl_head_next(NULL); head;
1628 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001629 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001630 newval, newlen,
1631 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001632 if (error != -ENOTDIR) {
1633 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001634 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001635 }
1636 }
Al Viro330d57f2005-11-04 10:18:40 +00001637 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638}
1639
1640asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1641{
1642 struct __sysctl_args tmp;
1643 int error;
1644
1645 if (copy_from_user(&tmp, args, sizeof(tmp)))
1646 return -EFAULT;
1647
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001648 error = deprecated_sysctl_warning(&tmp);
1649 if (error)
1650 goto out;
1651
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 lock_kernel();
1653 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1654 tmp.newval, tmp.newlen);
1655 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001656out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 return error;
1658}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001659#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001662 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 * some sysctl variables are readonly even to root.
1664 */
1665
1666static int test_perm(int mode, int op)
1667{
1668 if (!current->euid)
1669 mode >>= 6;
1670 else if (in_egroup_p(0))
1671 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001672 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 return 0;
1674 return -EACCES;
1675}
1676
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001677int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678{
1679 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001680 int mode;
1681
Al Viroe6305c42008-07-15 21:03:57 -04001682 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 if (error)
1684 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001685
1686 if (root->permissions)
1687 mode = root->permissions(root, current->nsproxy, table);
1688 else
1689 mode = table->mode;
1690
1691 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001694static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1695{
1696 for (; table->ctl_name || table->procname; table++) {
1697 table->parent = parent;
1698 if (table->child)
1699 sysctl_set_parent(table, table->child);
1700 }
1701}
1702
1703static __init int sysctl_init(void)
1704{
1705 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001706#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1707 {
1708 int err;
1709 err = sysctl_check_table(current->nsproxy, root_table);
1710 }
1711#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001712 return 0;
1713}
1714
1715core_initcall(sysctl_init);
1716
Al Virobfbcf032008-07-27 06:31:22 +01001717static struct ctl_table *is_branch_in(struct ctl_table *branch,
1718 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001719{
1720 struct ctl_table *p;
1721 const char *s = branch->procname;
1722
1723 /* branch should have named subdirectory as its first element */
1724 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001725 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001726
1727 /* ... and nothing else */
1728 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001729 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001730
1731 /* table should contain subdirectory with the same name */
1732 for (p = table; p->procname || p->ctl_name; p++) {
1733 if (!p->child)
1734 continue;
1735 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001736 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001737 }
Al Virobfbcf032008-07-27 06:31:22 +01001738 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001739}
1740
1741/* see if attaching q to p would be an improvement */
1742static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1743{
1744 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001745 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001746 int is_better = 0;
1747 int not_in_parent = !p->attached_by;
1748
Al Virobfbcf032008-07-27 06:31:22 +01001749 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001750 if (by == q->attached_by)
1751 is_better = 1;
1752 if (to == p->attached_by)
1753 not_in_parent = 1;
1754 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001755 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001756 }
1757
1758 if (is_better && not_in_parent) {
1759 q->attached_by = by;
1760 q->attached_to = to;
1761 q->parent = p;
1762 }
1763}
1764
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001766 * __register_sysctl_paths - register a sysctl hierarchy
1767 * @root: List of sysctl headers to register on
1768 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001769 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 *
1772 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001773 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001775 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 *
1777 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1778 * must be unique within that level of sysctl
1779 *
1780 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1781 * enter a sysctl file
1782 *
1783 * data - a pointer to data for use by proc_handler
1784 *
1785 * maxlen - the maximum size in bytes of the data
1786 *
1787 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1788 *
1789 * child - a pointer to the child sysctl table if this entry is a directory, or
1790 * %NULL.
1791 *
1792 * proc_handler - the text handler routine (described below)
1793 *
1794 * strategy - the strategy routine (described below)
1795 *
1796 * de - for internal use by the sysctl routines
1797 *
1798 * extra1, extra2 - extra pointers usable by the proc handler routines
1799 *
1800 * Leaf nodes in the sysctl tree will be represented by a single file
1801 * under /proc; non-leaf nodes will be represented by directories.
1802 *
1803 * sysctl(2) can automatically manage read and write requests through
1804 * the sysctl table. The data and maxlen fields of the ctl_table
1805 * struct enable minimal validation of the values being written to be
1806 * performed, and the mode field allows minimal authentication.
1807 *
1808 * More sophisticated management can be enabled by the provision of a
1809 * strategy routine with the table entry. This will be called before
1810 * any automatic read or write of the data is performed.
1811 *
1812 * The strategy routine may return
1813 *
1814 * < 0 - Error occurred (error is passed to user process)
1815 *
1816 * 0 - OK - proceed with automatic read or write.
1817 *
1818 * > 0 - OK - read or write has been done by the strategy routine, so
1819 * return immediately.
1820 *
1821 * There must be a proc_handler routine for any terminal nodes
1822 * mirrored under /proc/sys (non-terminals are handled by a built-in
1823 * directory handler). Several default handlers are available to
1824 * cover common cases -
1825 *
1826 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1827 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1828 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1829 *
1830 * It is the handler's job to read the input buffer from user memory
1831 * and process it. The handler should return 0 on success.
1832 *
1833 * This routine returns %NULL on a failure to register, and a pointer
1834 * to the table header on success.
1835 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001836struct ctl_table_header *__register_sysctl_paths(
1837 struct ctl_table_root *root,
1838 struct nsproxy *namespaces,
1839 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001841 struct ctl_table_header *header;
1842 struct ctl_table *new, **prevp;
1843 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001844 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001845
1846 /* Count the path components */
1847 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1848 ;
1849
1850 /*
1851 * For each path component, allocate a 2-element ctl_table array.
1852 * The first array element will be filled with the sysctl entry
1853 * for this, the second will be the sentinel (ctl_name == 0).
1854 *
1855 * We allocate everything in one go so that we don't have to
1856 * worry about freeing additional memory in unregister_sysctl_table.
1857 */
1858 header = kzalloc(sizeof(struct ctl_table_header) +
1859 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1860 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001862
1863 new = (struct ctl_table *) (header + 1);
1864
1865 /* Now connect the dots */
1866 prevp = &header->ctl_table;
1867 for (n = 0; n < npath; ++n, ++path) {
1868 /* Copy the procname */
1869 new->procname = path->procname;
1870 new->ctl_name = path->ctl_name;
1871 new->mode = 0555;
1872
1873 *prevp = new;
1874 prevp = &new->child;
1875
1876 new += 2;
1877 }
1878 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001879 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001880
1881 INIT_LIST_HEAD(&header->ctl_entry);
1882 header->used = 0;
1883 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001884 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001885 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001886 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001887#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001888 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001889 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001890 return NULL;
1891 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001892#endif
Al Viro330d57f2005-11-04 10:18:40 +00001893 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001894 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001895 header->attached_by = header->ctl_table;
1896 header->attached_to = root_table;
1897 header->parent = &root_table_header;
1898 for (set = header->set; set; set = set->parent) {
1899 struct ctl_table_header *p;
1900 list_for_each_entry(p, &set->list, ctl_entry) {
1901 if (p->unregistering)
1902 continue;
1903 try_attach(p, header);
1904 }
1905 }
1906 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001907 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001908 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001909
1910 return header;
1911}
1912
1913/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001914 * register_sysctl_table_path - register a sysctl table hierarchy
1915 * @path: The path to the directory the sysctl table is in.
1916 * @table: the top-level table structure
1917 *
1918 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1919 * array. A completely 0 filled entry terminates the table.
1920 *
1921 * See __register_sysctl_paths for more details.
1922 */
1923struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1924 struct ctl_table *table)
1925{
1926 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1927 path, table);
1928}
1929
1930/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001931 * register_sysctl_table - register a sysctl table hierarchy
1932 * @table: the top-level table structure
1933 *
1934 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1935 * array. A completely 0 filled entry terminates the table.
1936 *
1937 * See register_sysctl_paths for more details.
1938 */
1939struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1940{
1941 static const struct ctl_path null_path[] = { {} };
1942
1943 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944}
1945
1946/**
1947 * unregister_sysctl_table - unregister a sysctl table hierarchy
1948 * @header: the header returned from register_sysctl_table
1949 *
1950 * Unregisters the sysctl table and all children. proc entries may not
1951 * actually be removed until they are no longer used by anyone.
1952 */
1953void unregister_sysctl_table(struct ctl_table_header * header)
1954{
Al Viro330d57f2005-11-04 10:18:40 +00001955 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001956
1957 if (header == NULL)
1958 return;
1959
Al Viro330d57f2005-11-04 10:18:40 +00001960 spin_lock(&sysctl_lock);
1961 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001962 if (!--header->parent->count) {
1963 WARN_ON(1);
1964 kfree(header->parent);
1965 }
Al Virof7e6ced2008-07-15 01:44:23 -04001966 if (!--header->count)
1967 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001968 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969}
1970
Al Viro9043476f2008-07-15 08:54:06 -04001971int sysctl_is_seen(struct ctl_table_header *p)
1972{
1973 struct ctl_table_set *set = p->set;
1974 int res;
1975 spin_lock(&sysctl_lock);
1976 if (p->unregistering)
1977 res = 0;
1978 else if (!set->is_seen)
1979 res = 1;
1980 else
1981 res = set->is_seen(set);
1982 spin_unlock(&sysctl_lock);
1983 return res;
1984}
1985
Al Viro73455092008-07-14 21:22:20 -04001986void setup_sysctl_set(struct ctl_table_set *p,
1987 struct ctl_table_set *parent,
1988 int (*is_seen)(struct ctl_table_set *))
1989{
1990 INIT_LIST_HEAD(&p->list);
1991 p->parent = parent ? parent : &sysctl_table_root.default_set;
1992 p->is_seen = is_seen;
1993}
1994
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001995#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001996struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001997{
1998 return NULL;
1999}
2000
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002001struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2002 struct ctl_table *table)
2003{
2004 return NULL;
2005}
2006
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002007void unregister_sysctl_table(struct ctl_table_header * table)
2008{
2009}
2010
Al Viro73455092008-07-14 21:22:20 -04002011void setup_sysctl_set(struct ctl_table_set *p,
2012 struct ctl_table_set *parent,
2013 int (*is_seen)(struct ctl_table_set *))
2014{
2015}
2016
Al Virof7e6ced2008-07-15 01:44:23 -04002017void sysctl_head_put(struct ctl_table_header *head)
2018{
2019}
2020
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002021#endif /* CONFIG_SYSCTL */
2022
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023/*
2024 * /proc/sys support
2025 */
2026
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002027#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002029static int _proc_do_string(void* data, int maxlen, int write,
2030 struct file *filp, void __user *buffer,
2031 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002032{
2033 size_t len;
2034 char __user *p;
2035 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002036
2037 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002038 *lenp = 0;
2039 return 0;
2040 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002041
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002042 if (write) {
2043 len = 0;
2044 p = buffer;
2045 while (len < *lenp) {
2046 if (get_user(c, p++))
2047 return -EFAULT;
2048 if (c == 0 || c == '\n')
2049 break;
2050 len++;
2051 }
2052 if (len >= maxlen)
2053 len = maxlen-1;
2054 if(copy_from_user(data, buffer, len))
2055 return -EFAULT;
2056 ((char *) data)[len] = 0;
2057 *ppos += *lenp;
2058 } else {
2059 len = strlen(data);
2060 if (len > maxlen)
2061 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002062
2063 if (*ppos > len) {
2064 *lenp = 0;
2065 return 0;
2066 }
2067
2068 data += *ppos;
2069 len -= *ppos;
2070
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002071 if (len > *lenp)
2072 len = *lenp;
2073 if (len)
2074 if(copy_to_user(buffer, data, len))
2075 return -EFAULT;
2076 if (len < *lenp) {
2077 if(put_user('\n', ((char __user *) buffer) + len))
2078 return -EFAULT;
2079 len++;
2080 }
2081 *lenp = len;
2082 *ppos += len;
2083 }
2084 return 0;
2085}
2086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087/**
2088 * proc_dostring - read a string sysctl
2089 * @table: the sysctl table
2090 * @write: %TRUE if this is a write to the sysctl file
2091 * @filp: the file structure
2092 * @buffer: the user buffer
2093 * @lenp: the size of the user buffer
2094 * @ppos: file position
2095 *
2096 * Reads/writes a string from/to the user buffer. If the kernel
2097 * buffer provided is not large enough to hold the string, the
2098 * string is truncated. The copied string is %NULL-terminated.
2099 * If the string is being read by the user process, it is copied
2100 * and a newline '\n' is added. It is truncated if the buffer is
2101 * not large enough.
2102 *
2103 * Returns 0 on success.
2104 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002105int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 void __user *buffer, size_t *lenp, loff_t *ppos)
2107{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002108 return _proc_do_string(table->data, table->maxlen, write, filp,
2109 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110}
2111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
2113static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2114 int *valp,
2115 int write, void *data)
2116{
2117 if (write) {
2118 *valp = *negp ? -*lvalp : *lvalp;
2119 } else {
2120 int val = *valp;
2121 if (val < 0) {
2122 *negp = -1;
2123 *lvalp = (unsigned long)-val;
2124 } else {
2125 *negp = 0;
2126 *lvalp = (unsigned long)val;
2127 }
2128 }
2129 return 0;
2130}
2131
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002132static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002133 int write, struct file *filp, void __user *buffer,
2134 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2136 int write, void *data),
2137 void *data)
2138{
2139#define TMPBUFLEN 21
2140 int *i, vleft, first=1, neg, val;
2141 unsigned long lval;
2142 size_t left, len;
2143
2144 char buf[TMPBUFLEN], *p;
2145 char __user *s = buffer;
2146
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002147 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 (*ppos && !write)) {
2149 *lenp = 0;
2150 return 0;
2151 }
2152
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002153 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 vleft = table->maxlen / sizeof(*i);
2155 left = *lenp;
2156
2157 if (!conv)
2158 conv = do_proc_dointvec_conv;
2159
2160 for (; left && vleft--; i++, first=0) {
2161 if (write) {
2162 while (left) {
2163 char c;
2164 if (get_user(c, s))
2165 return -EFAULT;
2166 if (!isspace(c))
2167 break;
2168 left--;
2169 s++;
2170 }
2171 if (!left)
2172 break;
2173 neg = 0;
2174 len = left;
2175 if (len > sizeof(buf) - 1)
2176 len = sizeof(buf) - 1;
2177 if (copy_from_user(buf, s, len))
2178 return -EFAULT;
2179 buf[len] = 0;
2180 p = buf;
2181 if (*p == '-' && left > 1) {
2182 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002183 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 }
2185 if (*p < '0' || *p > '9')
2186 break;
2187
2188 lval = simple_strtoul(p, &p, 0);
2189
2190 len = p-buf;
2191 if ((len < left) && *p && !isspace(*p))
2192 break;
2193 if (neg)
2194 val = -val;
2195 s += len;
2196 left -= len;
2197
2198 if (conv(&neg, &lval, i, 1, data))
2199 break;
2200 } else {
2201 p = buf;
2202 if (!first)
2203 *p++ = '\t';
2204
2205 if (conv(&neg, &lval, i, 0, data))
2206 break;
2207
2208 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2209 len = strlen(buf);
2210 if (len > left)
2211 len = left;
2212 if(copy_to_user(s, buf, len))
2213 return -EFAULT;
2214 left -= len;
2215 s += len;
2216 }
2217 }
2218
2219 if (!write && !first && left) {
2220 if(put_user('\n', s))
2221 return -EFAULT;
2222 left--, s++;
2223 }
2224 if (write) {
2225 while (left) {
2226 char c;
2227 if (get_user(c, s++))
2228 return -EFAULT;
2229 if (!isspace(c))
2230 break;
2231 left--;
2232 }
2233 }
2234 if (write && first)
2235 return -EINVAL;
2236 *lenp -= left;
2237 *ppos += *lenp;
2238 return 0;
2239#undef TMPBUFLEN
2240}
2241
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002242static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002243 void __user *buffer, size_t *lenp, loff_t *ppos,
2244 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2245 int write, void *data),
2246 void *data)
2247{
2248 return __do_proc_dointvec(table->data, table, write, filp,
2249 buffer, lenp, ppos, conv, data);
2250}
2251
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252/**
2253 * proc_dointvec - read a vector of integers
2254 * @table: the sysctl table
2255 * @write: %TRUE if this is a write to the sysctl file
2256 * @filp: the file structure
2257 * @buffer: the user buffer
2258 * @lenp: the size of the user buffer
2259 * @ppos: file position
2260 *
2261 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2262 * values from/to the user buffer, treated as an ASCII string.
2263 *
2264 * Returns 0 on success.
2265 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002266int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 void __user *buffer, size_t *lenp, loff_t *ppos)
2268{
2269 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2270 NULL,NULL);
2271}
2272
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002273/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002274 * Taint values can only be increased
2275 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002276 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002277static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002278 void __user *buffer, size_t *lenp, loff_t *ppos)
2279{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002280 struct ctl_table t;
2281 unsigned long tmptaint = get_taint();
2282 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002283
Bastian Blank91fcd412007-04-23 14:41:14 -07002284 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002285 return -EPERM;
2286
Andi Kleen25ddbb12008-10-15 22:01:41 -07002287 t = *table;
2288 t.data = &tmptaint;
2289 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2290 if (err < 0)
2291 return err;
2292
2293 if (write) {
2294 /*
2295 * Poor man's atomic or. Not worth adding a primitive
2296 * to everyone's atomic.h for this
2297 */
2298 int i;
2299 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2300 if ((tmptaint >> i) & 1)
2301 add_taint(i);
2302 }
2303 }
2304
2305 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002306}
2307
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308struct do_proc_dointvec_minmax_conv_param {
2309 int *min;
2310 int *max;
2311};
2312
2313static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2314 int *valp,
2315 int write, void *data)
2316{
2317 struct do_proc_dointvec_minmax_conv_param *param = data;
2318 if (write) {
2319 int val = *negp ? -*lvalp : *lvalp;
2320 if ((param->min && *param->min > val) ||
2321 (param->max && *param->max < val))
2322 return -EINVAL;
2323 *valp = val;
2324 } else {
2325 int val = *valp;
2326 if (val < 0) {
2327 *negp = -1;
2328 *lvalp = (unsigned long)-val;
2329 } else {
2330 *negp = 0;
2331 *lvalp = (unsigned long)val;
2332 }
2333 }
2334 return 0;
2335}
2336
2337/**
2338 * proc_dointvec_minmax - read a vector of integers with min/max values
2339 * @table: the sysctl table
2340 * @write: %TRUE if this is a write to the sysctl file
2341 * @filp: the file structure
2342 * @buffer: the user buffer
2343 * @lenp: the size of the user buffer
2344 * @ppos: file position
2345 *
2346 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2347 * values from/to the user buffer, treated as an ASCII string.
2348 *
2349 * This routine will ensure the values are within the range specified by
2350 * table->extra1 (min) and table->extra2 (max).
2351 *
2352 * Returns 0 on success.
2353 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002354int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 void __user *buffer, size_t *lenp, loff_t *ppos)
2356{
2357 struct do_proc_dointvec_minmax_conv_param param = {
2358 .min = (int *) table->extra1,
2359 .max = (int *) table->extra2,
2360 };
2361 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2362 do_proc_dointvec_minmax_conv, &param);
2363}
2364
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002365static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 struct file *filp,
2367 void __user *buffer,
2368 size_t *lenp, loff_t *ppos,
2369 unsigned long convmul,
2370 unsigned long convdiv)
2371{
2372#define TMPBUFLEN 21
2373 unsigned long *i, *min, *max, val;
2374 int vleft, first=1, neg;
2375 size_t len, left;
2376 char buf[TMPBUFLEN], *p;
2377 char __user *s = buffer;
2378
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002379 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 (*ppos && !write)) {
2381 *lenp = 0;
2382 return 0;
2383 }
2384
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002385 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 min = (unsigned long *) table->extra1;
2387 max = (unsigned long *) table->extra2;
2388 vleft = table->maxlen / sizeof(unsigned long);
2389 left = *lenp;
2390
2391 for (; left && vleft--; i++, min++, max++, first=0) {
2392 if (write) {
2393 while (left) {
2394 char c;
2395 if (get_user(c, s))
2396 return -EFAULT;
2397 if (!isspace(c))
2398 break;
2399 left--;
2400 s++;
2401 }
2402 if (!left)
2403 break;
2404 neg = 0;
2405 len = left;
2406 if (len > TMPBUFLEN-1)
2407 len = TMPBUFLEN-1;
2408 if (copy_from_user(buf, s, len))
2409 return -EFAULT;
2410 buf[len] = 0;
2411 p = buf;
2412 if (*p == '-' && left > 1) {
2413 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002414 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 }
2416 if (*p < '0' || *p > '9')
2417 break;
2418 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2419 len = p-buf;
2420 if ((len < left) && *p && !isspace(*p))
2421 break;
2422 if (neg)
2423 val = -val;
2424 s += len;
2425 left -= len;
2426
2427 if(neg)
2428 continue;
2429 if ((min && val < *min) || (max && val > *max))
2430 continue;
2431 *i = val;
2432 } else {
2433 p = buf;
2434 if (!first)
2435 *p++ = '\t';
2436 sprintf(p, "%lu", convdiv * (*i) / convmul);
2437 len = strlen(buf);
2438 if (len > left)
2439 len = left;
2440 if(copy_to_user(s, buf, len))
2441 return -EFAULT;
2442 left -= len;
2443 s += len;
2444 }
2445 }
2446
2447 if (!write && !first && left) {
2448 if(put_user('\n', s))
2449 return -EFAULT;
2450 left--, s++;
2451 }
2452 if (write) {
2453 while (left) {
2454 char c;
2455 if (get_user(c, s++))
2456 return -EFAULT;
2457 if (!isspace(c))
2458 break;
2459 left--;
2460 }
2461 }
2462 if (write && first)
2463 return -EINVAL;
2464 *lenp -= left;
2465 *ppos += *lenp;
2466 return 0;
2467#undef TMPBUFLEN
2468}
2469
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002470static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002471 struct file *filp,
2472 void __user *buffer,
2473 size_t *lenp, loff_t *ppos,
2474 unsigned long convmul,
2475 unsigned long convdiv)
2476{
2477 return __do_proc_doulongvec_minmax(table->data, table, write,
2478 filp, buffer, lenp, ppos, convmul, convdiv);
2479}
2480
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481/**
2482 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2483 * @table: the sysctl table
2484 * @write: %TRUE if this is a write to the sysctl file
2485 * @filp: the file structure
2486 * @buffer: the user buffer
2487 * @lenp: the size of the user buffer
2488 * @ppos: file position
2489 *
2490 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2491 * values from/to the user buffer, treated as an ASCII string.
2492 *
2493 * This routine will ensure the values are within the range specified by
2494 * table->extra1 (min) and table->extra2 (max).
2495 *
2496 * Returns 0 on success.
2497 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002498int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 void __user *buffer, size_t *lenp, loff_t *ppos)
2500{
2501 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2502}
2503
2504/**
2505 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2506 * @table: the sysctl table
2507 * @write: %TRUE if this is a write to the sysctl file
2508 * @filp: the file structure
2509 * @buffer: the user buffer
2510 * @lenp: the size of the user buffer
2511 * @ppos: file position
2512 *
2513 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2514 * values from/to the user buffer, treated as an ASCII string. The values
2515 * are treated as milliseconds, and converted to jiffies when they are stored.
2516 *
2517 * This routine will ensure the values are within the range specified by
2518 * table->extra1 (min) and table->extra2 (max).
2519 *
2520 * Returns 0 on success.
2521 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002522int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 struct file *filp,
2524 void __user *buffer,
2525 size_t *lenp, loff_t *ppos)
2526{
2527 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2528 lenp, ppos, HZ, 1000l);
2529}
2530
2531
2532static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2533 int *valp,
2534 int write, void *data)
2535{
2536 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002537 if (*lvalp > LONG_MAX / HZ)
2538 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2540 } else {
2541 int val = *valp;
2542 unsigned long lval;
2543 if (val < 0) {
2544 *negp = -1;
2545 lval = (unsigned long)-val;
2546 } else {
2547 *negp = 0;
2548 lval = (unsigned long)val;
2549 }
2550 *lvalp = lval / HZ;
2551 }
2552 return 0;
2553}
2554
2555static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2556 int *valp,
2557 int write, void *data)
2558{
2559 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002560 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2561 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2563 } else {
2564 int val = *valp;
2565 unsigned long lval;
2566 if (val < 0) {
2567 *negp = -1;
2568 lval = (unsigned long)-val;
2569 } else {
2570 *negp = 0;
2571 lval = (unsigned long)val;
2572 }
2573 *lvalp = jiffies_to_clock_t(lval);
2574 }
2575 return 0;
2576}
2577
2578static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2579 int *valp,
2580 int write, void *data)
2581{
2582 if (write) {
2583 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2584 } else {
2585 int val = *valp;
2586 unsigned long lval;
2587 if (val < 0) {
2588 *negp = -1;
2589 lval = (unsigned long)-val;
2590 } else {
2591 *negp = 0;
2592 lval = (unsigned long)val;
2593 }
2594 *lvalp = jiffies_to_msecs(lval);
2595 }
2596 return 0;
2597}
2598
2599/**
2600 * proc_dointvec_jiffies - read a vector of integers as seconds
2601 * @table: the sysctl table
2602 * @write: %TRUE if this is a write to the sysctl file
2603 * @filp: the file structure
2604 * @buffer: the user buffer
2605 * @lenp: the size of the user buffer
2606 * @ppos: file position
2607 *
2608 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2609 * values from/to the user buffer, treated as an ASCII string.
2610 * The values read are assumed to be in seconds, and are converted into
2611 * jiffies.
2612 *
2613 * Returns 0 on success.
2614 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002615int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 void __user *buffer, size_t *lenp, loff_t *ppos)
2617{
2618 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2619 do_proc_dointvec_jiffies_conv,NULL);
2620}
2621
2622/**
2623 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2624 * @table: the sysctl table
2625 * @write: %TRUE if this is a write to the sysctl file
2626 * @filp: the file structure
2627 * @buffer: the user buffer
2628 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002629 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 *
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2632 * values from/to the user buffer, treated as an ASCII string.
2633 * The values read are assumed to be in 1/USER_HZ seconds, and
2634 * are converted into jiffies.
2635 *
2636 * Returns 0 on success.
2637 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002638int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 void __user *buffer, size_t *lenp, loff_t *ppos)
2640{
2641 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2642 do_proc_dointvec_userhz_jiffies_conv,NULL);
2643}
2644
2645/**
2646 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2647 * @table: the sysctl table
2648 * @write: %TRUE if this is a write to the sysctl file
2649 * @filp: the file structure
2650 * @buffer: the user buffer
2651 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002652 * @ppos: file position
2653 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 *
2655 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2656 * values from/to the user buffer, treated as an ASCII string.
2657 * The values read are assumed to be in 1/1000 seconds, and
2658 * are converted into jiffies.
2659 *
2660 * Returns 0 on success.
2661 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002662int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 void __user *buffer, size_t *lenp, loff_t *ppos)
2664{
2665 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2666 do_proc_dointvec_ms_jiffies_conv, NULL);
2667}
2668
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002669static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002670 void __user *buffer, size_t *lenp, loff_t *ppos)
2671{
2672 struct pid *new_pid;
2673 pid_t tmp;
2674 int r;
2675
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002676 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002677
2678 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2679 lenp, ppos, NULL, NULL);
2680 if (r || !write)
2681 return r;
2682
2683 new_pid = find_get_pid(tmp);
2684 if (!new_pid)
2685 return -ESRCH;
2686
2687 put_pid(xchg(&cad_pid, new_pid));
2688 return 0;
2689}
2690
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691#else /* CONFIG_PROC_FS */
2692
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002693int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 void __user *buffer, size_t *lenp, loff_t *ppos)
2695{
2696 return -ENOSYS;
2697}
2698
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002699int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 void __user *buffer, size_t *lenp, loff_t *ppos)
2701{
2702 return -ENOSYS;
2703}
2704
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002705int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 void __user *buffer, size_t *lenp, loff_t *ppos)
2707{
2708 return -ENOSYS;
2709}
2710
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002711int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 void __user *buffer, size_t *lenp, loff_t *ppos)
2713{
2714 return -ENOSYS;
2715}
2716
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002717int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 void __user *buffer, size_t *lenp, loff_t *ppos)
2719{
2720 return -ENOSYS;
2721}
2722
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002723int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 void __user *buffer, size_t *lenp, loff_t *ppos)
2725{
2726 return -ENOSYS;
2727}
2728
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002729int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 void __user *buffer, size_t *lenp, loff_t *ppos)
2731{
2732 return -ENOSYS;
2733}
2734
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002735int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 struct file *filp,
2737 void __user *buffer,
2738 size_t *lenp, loff_t *ppos)
2739{
2740 return -ENOSYS;
2741}
2742
2743
2744#endif /* CONFIG_PROC_FS */
2745
2746
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002747#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748/*
2749 * General sysctl support routines
2750 */
2751
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002752/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002753int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002754 void __user *oldval, size_t __user *oldlenp,
2755 void __user *newval, size_t newlen)
2756{
2757 size_t len;
2758
2759 /* Get out of I don't have a variable */
2760 if (!table->data || !table->maxlen)
2761 return -ENOTDIR;
2762
2763 if (oldval && oldlenp) {
2764 if (get_user(len, oldlenp))
2765 return -EFAULT;
2766 if (len) {
2767 if (len > table->maxlen)
2768 len = table->maxlen;
2769 if (copy_to_user(oldval, table->data, len))
2770 return -EFAULT;
2771 if (put_user(len, oldlenp))
2772 return -EFAULT;
2773 }
2774 }
2775
2776 if (newval && newlen) {
2777 if (newlen > table->maxlen)
2778 newlen = table->maxlen;
2779
2780 if (copy_from_user(table->data, newval, newlen))
2781 return -EFAULT;
2782 }
2783 return 1;
2784}
2785
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002787int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002789 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 if (!table->data || !table->maxlen)
2792 return -ENOTDIR;
2793
2794 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002795 size_t bufsize;
2796 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002798 if (bufsize) {
2799 size_t len = strlen(table->data), copied;
2800
2801 /* This shouldn't trigger for a well-formed sysctl */
2802 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002804
2805 /* Copy up to a max of bufsize-1 bytes of the string */
2806 copied = (len >= bufsize) ? bufsize - 1 : len;
2807
2808 if (copy_to_user(oldval, table->data, copied) ||
2809 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002811 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 return -EFAULT;
2813 }
2814 }
2815 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002816 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 if (len > table->maxlen)
2818 len = table->maxlen;
2819 if(copy_from_user(table->data, newval, len))
2820 return -EFAULT;
2821 if (len == table->maxlen)
2822 len--;
2823 ((char *) table->data)[len] = 0;
2824 }
Yi Yang82c9df82005-12-30 16:37:10 +08002825 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826}
2827
2828/*
2829 * This function makes sure that all of the integers in the vector
2830 * are between the minimum and maximum values given in the arrays
2831 * table->extra1 and table->extra2, respectively.
2832 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002833int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002835 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836{
2837
2838 if (newval && newlen) {
2839 int __user *vec = (int __user *) newval;
2840 int *min = (int *) table->extra1;
2841 int *max = (int *) table->extra2;
2842 size_t length;
2843 int i;
2844
2845 if (newlen % sizeof(int) != 0)
2846 return -EINVAL;
2847
2848 if (!table->extra1 && !table->extra2)
2849 return 0;
2850
2851 if (newlen > table->maxlen)
2852 newlen = table->maxlen;
2853 length = newlen / sizeof(int);
2854
2855 for (i = 0; i < length; i++) {
2856 int value;
2857 if (get_user(value, vec + i))
2858 return -EFAULT;
2859 if (min && value < min[i])
2860 return -EINVAL;
2861 if (max && value > max[i])
2862 return -EINVAL;
2863 }
2864 }
2865 return 0;
2866}
2867
2868/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002869int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002871 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002873 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002875
2876 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002878 if (olen) {
2879 int val;
2880
2881 if (olen < sizeof(int))
2882 return -EINVAL;
2883
2884 val = *(int *)(table->data) / HZ;
2885 if (put_user(val, (int __user *)oldval))
2886 return -EFAULT;
2887 if (put_user(sizeof(int), oldlenp))
2888 return -EFAULT;
2889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 }
2891 if (newval && newlen) {
2892 int new;
2893 if (newlen != sizeof(int))
2894 return -EINVAL;
2895 if (get_user(new, (int __user *)newval))
2896 return -EFAULT;
2897 *(int *)(table->data) = new*HZ;
2898 }
2899 return 1;
2900}
2901
2902/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002903int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002905 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002907 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002909
2910 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002912 if (olen) {
2913 int val;
2914
2915 if (olen < sizeof(int))
2916 return -EINVAL;
2917
2918 val = jiffies_to_msecs(*(int *)(table->data));
2919 if (put_user(val, (int __user *)oldval))
2920 return -EFAULT;
2921 if (put_user(sizeof(int), oldlenp))
2922 return -EFAULT;
2923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 }
2925 if (newval && newlen) {
2926 int new;
2927 if (newlen != sizeof(int))
2928 return -EINVAL;
2929 if (get_user(new, (int __user *)newval))
2930 return -EFAULT;
2931 *(int *)(table->data) = msecs_to_jiffies(new);
2932 }
2933 return 1;
2934}
2935
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002936
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002937
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002938#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939
2940
2941asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2942{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002943 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002944 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002945
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002946 if (copy_from_user(&tmp, args, sizeof(tmp)))
2947 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002948
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002949 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002950
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002951 /* If no error reading the parameters then just -ENOSYS ... */
2952 if (!error)
2953 error = -ENOSYS;
2954
2955 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956}
2957
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002958int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002959 void __user *oldval, size_t __user *oldlenp,
2960 void __user *newval, size_t newlen)
2961{
2962 return -ENOSYS;
2963}
2964
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002965int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002967 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968{
2969 return -ENOSYS;
2970}
2971
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002972int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002974 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975{
2976 return -ENOSYS;
2977}
2978
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002979int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002981 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982{
2983 return -ENOSYS;
2984}
2985
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002986int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002988 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989{
2990 return -ENOSYS;
2991}
2992
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002993#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002995static int deprecated_sysctl_warning(struct __sysctl_args *args)
2996{
2997 static int msg_count;
2998 int name[CTL_MAXNAME];
2999 int i;
3000
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003001 /* Check args->nlen. */
3002 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3003 return -ENOTDIR;
3004
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003005 /* Read in the sysctl name for better debug message logging */
3006 for (i = 0; i < args->nlen; i++)
3007 if (get_user(name[i], args->name + i))
3008 return -EFAULT;
3009
3010 /* Ignore accesses to kernel.version */
3011 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3012 return 0;
3013
3014 if (msg_count < 5) {
3015 msg_count++;
3016 printk(KERN_INFO
3017 "warning: process `%s' used the deprecated sysctl "
3018 "system call with ", current->comm);
3019 for (i = 0; i < args->nlen; i++)
3020 printk("%d.", name[i]);
3021 printk("\n");
3022 }
3023 return 0;
3024}
3025
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026/*
3027 * No sense putting this after each symbol definition, twice,
3028 * exception granted :-)
3029 */
3030EXPORT_SYMBOL(proc_dointvec);
3031EXPORT_SYMBOL(proc_dointvec_jiffies);
3032EXPORT_SYMBOL(proc_dointvec_minmax);
3033EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3034EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3035EXPORT_SYMBOL(proc_dostring);
3036EXPORT_SYMBOL(proc_doulongvec_minmax);
3037EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3038EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003039EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040EXPORT_SYMBOL(sysctl_intvec);
3041EXPORT_SYMBOL(sysctl_jiffies);
3042EXPORT_SYMBOL(sysctl_ms_jiffies);
3043EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003044EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045EXPORT_SYMBOL(unregister_sysctl_table);