blob: 4588b2cf2ecb6f575967f262ecc874dde7c4bf75 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include <asm/uaccess.h>
53#include <asm/processor.h>
54
Andi Kleen29cbc782006-09-30 01:47:55 +020055#ifdef CONFIG_X86
56#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010057#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010058#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020059#endif
60
Eric W. Biederman7058cb02007-10-18 03:05:58 -070061static int deprecated_sysctl_warning(struct __sysctl_args *args);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#if defined(CONFIG_SYSCTL)
64
65/* External variables not in a header file. */
66extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070067extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int sysctl_overcommit_memory;
69extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070070extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070071extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080072extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070075extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max;
78extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080080extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080081extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020082extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070083extern int maps_protect;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070086#ifdef CONFIG_RCU_TORTURE_TEST
87extern int rcutorture_runnable;
88#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070090/* Constants used for minimum and maximum */
Ingo Molnar1c4cd6d2008-05-12 21:21:14 +020091#if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092static int one = 1;
Bron Gondwana195cf4532008-02-04 22:29:20 -080093#endif
94
95#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020097static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098#endif
99
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +0200100#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700101static int two = 2;
102#endif
103
104static int zero;
105static int one_hundred = 100;
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108static int maxolduid = 65535;
109static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112static int ngroups_max = NGROUPS_MAX;
113
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200114#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115extern char modprobe_path[];
116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#ifdef CONFIG_CHR_DEV_SG
118extern int sg_big_buff;
119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121#ifdef __sparc__
122extern char reboot_command [];
123extern int stop_a_enabled;
124extern int scons_pwroff;
125#endif
126
127#ifdef __hppa__
128extern int pwrsw_enabled;
129extern int unaligned_enabled;
130#endif
131
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800132#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#ifdef CONFIG_MATHEMU
134extern int sysctl_ieee_emulation_warnings;
135#endif
136extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700137extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#endif
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef CONFIG_BSD_PROCESS_ACCT
141extern int acct_parm[];
142#endif
143
Jes Sorensend2b176e2006-02-28 09:42:23 -0800144#ifdef CONFIG_IA64
145extern int no_unaligned_warning;
146#endif
147
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700148#ifdef CONFIG_RT_MUTEXES
149extern int max_lock_depth;
150#endif
151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700153static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700154 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800156 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700158
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700159static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100160static struct ctl_table_root sysctl_table_root;
161static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100162 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100163 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400164 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100165 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400166 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100167};
168static struct ctl_table_root sysctl_table_root = {
169 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400170 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100171};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700173static struct ctl_table kern_table[];
174static struct ctl_table vm_table[];
175static struct ctl_table fs_table[];
176static struct ctl_table debug_table[];
177static struct ctl_table dev_table[];
178extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700179#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700180extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400181#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
184int sysctl_legacy_va_layout;
185#endif
186
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700187extern int prove_locking;
188extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* The default sysctl tables: */
191
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700192static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 {
194 .ctl_name = CTL_KERN,
195 .procname = "kernel",
196 .mode = 0555,
197 .child = kern_table,
198 },
199 {
200 .ctl_name = CTL_VM,
201 .procname = "vm",
202 .mode = 0555,
203 .child = vm_table,
204 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 .ctl_name = CTL_FS,
207 .procname = "fs",
208 .mode = 0555,
209 .child = fs_table,
210 },
211 {
212 .ctl_name = CTL_DEBUG,
213 .procname = "debug",
214 .mode = 0555,
215 .child = debug_table,
216 },
217 {
218 .ctl_name = CTL_DEV,
219 .procname = "dev",
220 .mode = 0555,
221 .child = dev_table,
222 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700223/*
224 * NOTE: do not add new entries to this table unless you have read
225 * Documentation/sysctl/ctl_unnumbered.txt
226 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 { .ctl_name = 0 }
228};
229
Ingo Molnar77e54a12007-07-09 18:52:00 +0200230#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100231static int min_sched_granularity_ns = 100000; /* 100 usecs */
232static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
233static int min_wakeup_granularity_ns; /* 0 usecs */
234static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#endif
236
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700237static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238#ifdef CONFIG_SCHED_DEBUG
239 {
240 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100241 .procname = "sched_min_granularity_ns",
242 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243 .maxlen = sizeof(unsigned int),
244 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100245 .proc_handler = &sched_nr_latency_handler,
246 .strategy = &sysctl_intvec,
247 .extra1 = &min_sched_granularity_ns,
248 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249 },
250 {
251 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200252 .procname = "sched_latency_ns",
253 .data = &sysctl_sched_latency,
254 .maxlen = sizeof(unsigned int),
255 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100256 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200257 .strategy = &sysctl_intvec,
258 .extra1 = &min_sched_granularity_ns,
259 .extra2 = &max_sched_granularity_ns,
260 },
261 {
262 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200263 .procname = "sched_wakeup_granularity_ns",
264 .data = &sysctl_sched_wakeup_granularity,
265 .maxlen = sizeof(unsigned int),
266 .mode = 0644,
267 .proc_handler = &proc_dointvec_minmax,
268 .strategy = &sysctl_intvec,
269 .extra1 = &min_wakeup_granularity_ns,
270 .extra2 = &max_wakeup_granularity_ns,
271 },
272 {
273 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200274 .procname = "sched_shares_ratelimit",
275 .data = &sysctl_sched_shares_ratelimit,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
278 .proc_handler = &proc_dointvec,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
287 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200288 {
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_features",
291 .data = &sysctl_sched_features,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec,
295 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200296 {
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_migration_cost",
299 .data = &sysctl_sched_migration_cost,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
302 .proc_handler = &proc_dointvec,
303 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100304 {
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_nr_migrate",
307 .data = &sysctl_sched_nr_migrate,
308 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100309 .mode = 0644,
310 .proc_handler = &proc_dointvec,
311 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200312#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200313 {
314 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100315 .procname = "sched_rt_period_us",
316 .data = &sysctl_sched_rt_period,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200319 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100320 },
321 {
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_rt_runtime_us",
324 .data = &sysctl_sched_rt_runtime,
325 .maxlen = sizeof(int),
326 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200327 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100328 },
329 {
330 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200331 .procname = "sched_compat_yield",
332 .data = &sysctl_sched_compat_yield,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
335 .proc_handler = &proc_dointvec,
336 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700337#ifdef CONFIG_PROVE_LOCKING
338 {
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "prove_locking",
341 .data = &prove_locking,
342 .maxlen = sizeof(int),
343 .mode = 0644,
344 .proc_handler = &proc_dointvec,
345 },
346#endif
347#ifdef CONFIG_LOCK_STAT
348 {
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "lock_stat",
351 .data = &lock_stat,
352 .maxlen = sizeof(int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
355 },
356#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200357 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 .ctl_name = KERN_PANIC,
359 .procname = "panic",
360 .data = &panic_timeout,
361 .maxlen = sizeof(int),
362 .mode = 0644,
363 .proc_handler = &proc_dointvec,
364 },
365 {
366 .ctl_name = KERN_CORE_USES_PID,
367 .procname = "core_uses_pid",
368 .data = &core_uses_pid,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &proc_dointvec,
372 },
373 {
374 .ctl_name = KERN_CORE_PATTERN,
375 .procname = "core_pattern",
376 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700377 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .mode = 0644,
379 .proc_handler = &proc_dostring,
380 .strategy = &sysctl_string,
381 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800382#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 .procname = "tainted",
385 .data = &tainted,
386 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800387 .mode = 0644,
388 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800390#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100391#ifdef CONFIG_LATENCYTOP
392 {
393 .procname = "latencytop",
394 .data = &latencytop_enabled,
395 .maxlen = sizeof(int),
396 .mode = 0644,
397 .proc_handler = &proc_dointvec,
398 },
399#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#ifdef CONFIG_BLK_DEV_INITRD
401 {
402 .ctl_name = KERN_REALROOTDEV,
403 .procname = "real-root-dev",
404 .data = &real_root_dev,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec,
408 },
409#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700410 {
411 .ctl_name = CTL_UNNUMBERED,
412 .procname = "print-fatal-signals",
413 .data = &print_fatal_signals,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
417 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#ifdef __sparc__
419 {
420 .ctl_name = KERN_SPARC_REBOOT,
421 .procname = "reboot-cmd",
422 .data = reboot_command,
423 .maxlen = 256,
424 .mode = 0644,
425 .proc_handler = &proc_dostring,
426 .strategy = &sysctl_string,
427 },
428 {
429 .ctl_name = KERN_SPARC_STOP_A,
430 .procname = "stop-a",
431 .data = &stop_a_enabled,
432 .maxlen = sizeof (int),
433 .mode = 0644,
434 .proc_handler = &proc_dointvec,
435 },
436 {
437 .ctl_name = KERN_SPARC_SCONS_PWROFF,
438 .procname = "scons-poweroff",
439 .data = &scons_pwroff,
440 .maxlen = sizeof (int),
441 .mode = 0644,
442 .proc_handler = &proc_dointvec,
443 },
444#endif
445#ifdef __hppa__
446 {
447 .ctl_name = KERN_HPPA_PWRSW,
448 .procname = "soft-power",
449 .data = &pwrsw_enabled,
450 .maxlen = sizeof (int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
453 },
454 {
455 .ctl_name = KERN_HPPA_UNALIGNED,
456 .procname = "unaligned-trap",
457 .data = &unaligned_enabled,
458 .maxlen = sizeof (int),
459 .mode = 0644,
460 .proc_handler = &proc_dointvec,
461 },
462#endif
463 {
464 .ctl_name = KERN_CTLALTDEL,
465 .procname = "ctrl-alt-del",
466 .data = &C_A_D,
467 .maxlen = sizeof(int),
468 .mode = 0644,
469 .proc_handler = &proc_dointvec,
470 },
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200471#ifdef CONFIG_FTRACE
472 {
473 .ctl_name = CTL_UNNUMBERED,
474 .procname = "ftrace_enabled",
475 .data = &ftrace_enabled,
476 .maxlen = sizeof(int),
477 .mode = 0644,
478 .proc_handler = &ftrace_enable_sysctl,
479 },
480#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200481#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 {
483 .ctl_name = KERN_MODPROBE,
484 .procname = "modprobe",
485 .data = &modprobe_path,
486 .maxlen = KMOD_PATH_LEN,
487 .mode = 0644,
488 .proc_handler = &proc_dostring,
489 .strategy = &sysctl_string,
490 },
491#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700492#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 {
494 .ctl_name = KERN_HOTPLUG,
495 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100496 .data = &uevent_helper,
497 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .mode = 0644,
499 .proc_handler = &proc_dostring,
500 .strategy = &sysctl_string,
501 },
502#endif
503#ifdef CONFIG_CHR_DEV_SG
504 {
505 .ctl_name = KERN_SG_BIG_BUFF,
506 .procname = "sg-big-buff",
507 .data = &sg_big_buff,
508 .maxlen = sizeof (int),
509 .mode = 0444,
510 .proc_handler = &proc_dointvec,
511 },
512#endif
513#ifdef CONFIG_BSD_PROCESS_ACCT
514 {
515 .ctl_name = KERN_ACCT,
516 .procname = "acct",
517 .data = &acct_parm,
518 .maxlen = 3*sizeof(int),
519 .mode = 0644,
520 .proc_handler = &proc_dointvec,
521 },
522#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#ifdef CONFIG_MAGIC_SYSRQ
524 {
525 .ctl_name = KERN_SYSRQ,
526 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800527 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 .maxlen = sizeof (int),
529 .mode = 0644,
530 .proc_handler = &proc_dointvec,
531 },
532#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700533#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700536 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 .maxlen = sizeof (int),
538 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700539 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700541#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 {
543 .ctl_name = KERN_MAX_THREADS,
544 .procname = "threads-max",
545 .data = &max_threads,
546 .maxlen = sizeof(int),
547 .mode = 0644,
548 .proc_handler = &proc_dointvec,
549 },
550 {
551 .ctl_name = KERN_RANDOM,
552 .procname = "random",
553 .mode = 0555,
554 .child = random_table,
555 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 {
557 .ctl_name = KERN_OVERFLOWUID,
558 .procname = "overflowuid",
559 .data = &overflowuid,
560 .maxlen = sizeof(int),
561 .mode = 0644,
562 .proc_handler = &proc_dointvec_minmax,
563 .strategy = &sysctl_intvec,
564 .extra1 = &minolduid,
565 .extra2 = &maxolduid,
566 },
567 {
568 .ctl_name = KERN_OVERFLOWGID,
569 .procname = "overflowgid",
570 .data = &overflowgid,
571 .maxlen = sizeof(int),
572 .mode = 0644,
573 .proc_handler = &proc_dointvec_minmax,
574 .strategy = &sysctl_intvec,
575 .extra1 = &minolduid,
576 .extra2 = &maxolduid,
577 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800578#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#ifdef CONFIG_MATHEMU
580 {
581 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
582 .procname = "ieee_emulation_warnings",
583 .data = &sysctl_ieee_emulation_warnings,
584 .maxlen = sizeof(int),
585 .mode = 0644,
586 .proc_handler = &proc_dointvec,
587 },
588#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 {
590 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
591 .procname = "userprocess_debug",
592 .data = &sysctl_userprocess_debug,
593 .maxlen = sizeof(int),
594 .mode = 0644,
595 .proc_handler = &proc_dointvec,
596 },
597#endif
598 {
599 .ctl_name = KERN_PIDMAX,
600 .procname = "pid_max",
601 .data = &pid_max,
602 .maxlen = sizeof (int),
603 .mode = 0644,
604 .proc_handler = &proc_dointvec_minmax,
605 .strategy = sysctl_intvec,
606 .extra1 = &pid_max_min,
607 .extra2 = &pid_max_max,
608 },
609 {
610 .ctl_name = KERN_PANIC_ON_OOPS,
611 .procname = "panic_on_oops",
612 .data = &panic_on_oops,
613 .maxlen = sizeof(int),
614 .mode = 0644,
615 .proc_handler = &proc_dointvec,
616 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800617#if defined CONFIG_PRINTK
618 {
619 .ctl_name = KERN_PRINTK,
620 .procname = "printk",
621 .data = &console_loglevel,
622 .maxlen = 4*sizeof(int),
623 .mode = 0644,
624 .proc_handler = &proc_dointvec,
625 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 {
627 .ctl_name = KERN_PRINTK_RATELIMIT,
628 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700629 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec_jiffies,
633 .strategy = &sysctl_jiffies,
634 },
635 {
636 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
637 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700638 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 .maxlen = sizeof(int),
640 .mode = 0644,
641 .proc_handler = &proc_dointvec,
642 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800643#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 {
645 .ctl_name = KERN_NGROUPS_MAX,
646 .procname = "ngroups_max",
647 .data = &ngroups_max,
648 .maxlen = sizeof (int),
649 .mode = 0444,
650 .proc_handler = &proc_dointvec,
651 },
652#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
653 {
654 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
655 .procname = "unknown_nmi_panic",
656 .data = &unknown_nmi_panic,
657 .maxlen = sizeof (int),
658 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200659 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 },
Don Zickus407984f2006-09-26 10:52:27 +0200661 {
Don Zickus407984f2006-09-26 10:52:27 +0200662 .procname = "nmi_watchdog",
663 .data = &nmi_watchdog_enabled,
664 .maxlen = sizeof (int),
665 .mode = 0644,
666 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 },
668#endif
669#if defined(CONFIG_X86)
670 {
Don Zickus8da5add2006-09-26 10:52:27 +0200671 .ctl_name = KERN_PANIC_ON_NMI,
672 .procname = "panic_on_unrecovered_nmi",
673 .data = &panic_on_unrecovered_nmi,
674 .maxlen = sizeof(int),
675 .mode = 0644,
676 .proc_handler = &proc_dointvec,
677 },
678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 .ctl_name = KERN_BOOTLOADER_TYPE,
680 .procname = "bootloader_type",
681 .data = &bootloader_type,
682 .maxlen = sizeof (int),
683 .mode = 0444,
684 .proc_handler = &proc_dointvec,
685 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100686 {
687 .ctl_name = CTL_UNNUMBERED,
688 .procname = "kstack_depth_to_print",
689 .data = &kstack_depth_to_print,
690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = &proc_dointvec,
693 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100694 {
695 .ctl_name = CTL_UNNUMBERED,
696 .procname = "io_delay_type",
697 .data = &io_delay_type,
698 .maxlen = sizeof(int),
699 .mode = 0644,
700 .proc_handler = &proc_dointvec,
701 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800703#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 {
705 .ctl_name = KERN_RANDOMIZE,
706 .procname = "randomize_va_space",
707 .data = &randomize_va_space,
708 .maxlen = sizeof(int),
709 .mode = 0644,
710 .proc_handler = &proc_dointvec,
711 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800712#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800713#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700714 {
715 .ctl_name = KERN_SPIN_RETRY,
716 .procname = "spin_retry",
717 .data = &spin_retry,
718 .maxlen = sizeof (int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
721 },
722#endif
Len Brown673d5b42007-07-28 03:33:16 -0400723#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800724 {
Pavel Machekc255d842006-02-20 18:27:58 -0800725 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700726 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800727 .maxlen = sizeof (unsigned long),
728 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800729 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800730 },
731#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800732#ifdef CONFIG_IA64
733 {
734 .ctl_name = KERN_IA64_UNALIGNED,
735 .procname = "ignore-unaligned-usertrap",
736 .data = &no_unaligned_warning,
737 .maxlen = sizeof (int),
738 .mode = 0644,
739 .proc_handler = &proc_dointvec,
740 },
741#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700742#ifdef CONFIG_DETECT_SOFTLOCKUP
743 {
744 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200745 .procname = "softlockup_panic",
746 .data = &softlockup_panic,
747 .maxlen = sizeof(int),
748 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700749 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200750 .strategy = &sysctl_intvec,
751 .extra1 = &zero,
752 .extra2 = &one,
753 },
754 {
755 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700756 .procname = "softlockup_thresh",
757 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200758 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700759 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200760 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700761 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200762 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700763 .extra2 = &sixty,
764 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100765 {
766 .ctl_name = CTL_UNNUMBERED,
767 .procname = "hung_task_check_count",
768 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100769 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100770 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100771 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100772 .strategy = &sysctl_intvec,
773 },
774 {
775 .ctl_name = CTL_UNNUMBERED,
776 .procname = "hung_task_timeout_secs",
777 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100778 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100779 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100780 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100781 .strategy = &sysctl_intvec,
782 },
783 {
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "hung_task_warnings",
786 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100787 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100788 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100789 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100790 .strategy = &sysctl_intvec,
791 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700792#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200793#ifdef CONFIG_COMPAT
794 {
795 .ctl_name = KERN_COMPAT_LOG,
796 .procname = "compat-log",
797 .data = &compat_log,
798 .maxlen = sizeof (int),
799 .mode = 0644,
800 .proc_handler = &proc_dointvec,
801 },
802#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700803#ifdef CONFIG_RT_MUTEXES
804 {
805 .ctl_name = KERN_MAX_LOCK_DEPTH,
806 .procname = "max_lock_depth",
807 .data = &max_lock_depth,
808 .maxlen = sizeof(int),
809 .mode = 0644,
810 .proc_handler = &proc_dointvec,
811 },
812#endif
Kees Cook5096add2007-05-08 00:26:04 -0700813#ifdef CONFIG_PROC_FS
814 {
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "maps_protect",
817 .data = &maps_protect,
818 .maxlen = sizeof(int),
819 .mode = 0644,
820 .proc_handler = &proc_dointvec,
821 },
822#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700823 {
824 .ctl_name = CTL_UNNUMBERED,
825 .procname = "poweroff_cmd",
826 .data = &poweroff_cmd,
827 .maxlen = POWEROFF_CMD_PATH_LEN,
828 .mode = 0644,
829 .proc_handler = &proc_dostring,
830 .strategy = &sysctl_string,
831 },
David Howells0b77f5b2008-04-29 01:01:32 -0700832#ifdef CONFIG_KEYS
833 {
834 .ctl_name = CTL_UNNUMBERED,
835 .procname = "keys",
836 .mode = 0555,
837 .child = key_sysctls,
838 },
839#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700840#ifdef CONFIG_RCU_TORTURE_TEST
841 {
842 .ctl_name = CTL_UNNUMBERED,
843 .procname = "rcutorture_runnable",
844 .data = &rcutorture_runnable,
845 .maxlen = sizeof(int),
846 .mode = 0644,
847 .proc_handler = &proc_dointvec,
848 },
849#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700850/*
851 * NOTE: do not add new entries to this table unless you have read
852 * Documentation/sysctl/ctl_unnumbered.txt
853 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 { .ctl_name = 0 }
855};
856
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700857static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 {
859 .ctl_name = VM_OVERCOMMIT_MEMORY,
860 .procname = "overcommit_memory",
861 .data = &sysctl_overcommit_memory,
862 .maxlen = sizeof(sysctl_overcommit_memory),
863 .mode = 0644,
864 .proc_handler = &proc_dointvec,
865 },
866 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700867 .ctl_name = VM_PANIC_ON_OOM,
868 .procname = "panic_on_oom",
869 .data = &sysctl_panic_on_oom,
870 .maxlen = sizeof(sysctl_panic_on_oom),
871 .mode = 0644,
872 .proc_handler = &proc_dointvec,
873 },
874 {
David Rientjesfe071d72007-10-16 23:25:56 -0700875 .ctl_name = CTL_UNNUMBERED,
876 .procname = "oom_kill_allocating_task",
877 .data = &sysctl_oom_kill_allocating_task,
878 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
879 .mode = 0644,
880 .proc_handler = &proc_dointvec,
881 },
882 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800883 .ctl_name = CTL_UNNUMBERED,
884 .procname = "oom_dump_tasks",
885 .data = &sysctl_oom_dump_tasks,
886 .maxlen = sizeof(sysctl_oom_dump_tasks),
887 .mode = 0644,
888 .proc_handler = &proc_dointvec,
889 },
890 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 .ctl_name = VM_OVERCOMMIT_RATIO,
892 .procname = "overcommit_ratio",
893 .data = &sysctl_overcommit_ratio,
894 .maxlen = sizeof(sysctl_overcommit_ratio),
895 .mode = 0644,
896 .proc_handler = &proc_dointvec,
897 },
898 {
899 .ctl_name = VM_PAGE_CLUSTER,
900 .procname = "page-cluster",
901 .data = &page_cluster,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = &proc_dointvec,
905 },
906 {
907 .ctl_name = VM_DIRTY_BACKGROUND,
908 .procname = "dirty_background_ratio",
909 .data = &dirty_background_ratio,
910 .maxlen = sizeof(dirty_background_ratio),
911 .mode = 0644,
912 .proc_handler = &proc_dointvec_minmax,
913 .strategy = &sysctl_intvec,
914 .extra1 = &zero,
915 .extra2 = &one_hundred,
916 },
917 {
918 .ctl_name = VM_DIRTY_RATIO,
919 .procname = "dirty_ratio",
920 .data = &vm_dirty_ratio,
921 .maxlen = sizeof(vm_dirty_ratio),
922 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700923 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 .strategy = &sysctl_intvec,
925 .extra1 = &zero,
926 .extra2 = &one_hundred,
927 },
928 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800930 .data = &dirty_writeback_interval,
931 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 .mode = 0644,
933 .proc_handler = &dirty_writeback_centisecs_handler,
934 },
935 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800937 .data = &dirty_expire_interval,
938 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800940 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 },
942 {
943 .ctl_name = VM_NR_PDFLUSH_THREADS,
944 .procname = "nr_pdflush_threads",
945 .data = &nr_pdflush_threads,
946 .maxlen = sizeof nr_pdflush_threads,
947 .mode = 0444 /* read-only*/,
948 .proc_handler = &proc_dointvec,
949 },
950 {
951 .ctl_name = VM_SWAPPINESS,
952 .procname = "swappiness",
953 .data = &vm_swappiness,
954 .maxlen = sizeof(vm_swappiness),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec_minmax,
957 .strategy = &sysctl_intvec,
958 .extra1 = &zero,
959 .extra2 = &one_hundred,
960 },
961#ifdef CONFIG_HUGETLB_PAGE
962 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700964 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 .maxlen = sizeof(unsigned long),
966 .mode = 0644,
967 .proc_handler = &hugetlb_sysctl_handler,
968 .extra1 = (void *)&hugetlb_zero,
969 .extra2 = (void *)&hugetlb_infinity,
970 },
971 {
972 .ctl_name = VM_HUGETLB_GROUP,
973 .procname = "hugetlb_shm_group",
974 .data = &sysctl_hugetlb_shm_group,
975 .maxlen = sizeof(gid_t),
976 .mode = 0644,
977 .proc_handler = &proc_dointvec,
978 },
Mel Gorman396faf02007-07-17 04:03:13 -0700979 {
980 .ctl_name = CTL_UNNUMBERED,
981 .procname = "hugepages_treat_as_movable",
982 .data = &hugepages_treat_as_movable,
983 .maxlen = sizeof(int),
984 .mode = 0644,
985 .proc_handler = &hugetlb_treat_movable_handler,
986 },
Adam Litke54f9f802007-10-16 01:26:20 -0700987 {
988 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800989 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700990 .data = NULL,
991 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800992 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800993 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -0700994 .extra1 = (void *)&hugetlb_zero,
995 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800996 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997#endif
998 {
999 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1000 .procname = "lowmem_reserve_ratio",
1001 .data = &sysctl_lowmem_reserve_ratio,
1002 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1003 .mode = 0644,
1004 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1005 .strategy = &sysctl_intvec,
1006 },
1007 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001008 .ctl_name = VM_DROP_PAGECACHE,
1009 .procname = "drop_caches",
1010 .data = &sysctl_drop_caches,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
1013 .proc_handler = drop_caches_sysctl_handler,
1014 .strategy = &sysctl_intvec,
1015 },
1016 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 .ctl_name = VM_MIN_FREE_KBYTES,
1018 .procname = "min_free_kbytes",
1019 .data = &min_free_kbytes,
1020 .maxlen = sizeof(min_free_kbytes),
1021 .mode = 0644,
1022 .proc_handler = &min_free_kbytes_sysctl_handler,
1023 .strategy = &sysctl_intvec,
1024 .extra1 = &zero,
1025 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001026 {
1027 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1028 .procname = "percpu_pagelist_fraction",
1029 .data = &percpu_pagelist_fraction,
1030 .maxlen = sizeof(percpu_pagelist_fraction),
1031 .mode = 0644,
1032 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1033 .strategy = &sysctl_intvec,
1034 .extra1 = &min_percpu_pagelist_fract,
1035 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036#ifdef CONFIG_MMU
1037 {
1038 .ctl_name = VM_MAX_MAP_COUNT,
1039 .procname = "max_map_count",
1040 .data = &sysctl_max_map_count,
1041 .maxlen = sizeof(sysctl_max_map_count),
1042 .mode = 0644,
1043 .proc_handler = &proc_dointvec
1044 },
1045#endif
1046 {
1047 .ctl_name = VM_LAPTOP_MODE,
1048 .procname = "laptop_mode",
1049 .data = &laptop_mode,
1050 .maxlen = sizeof(laptop_mode),
1051 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001052 .proc_handler = &proc_dointvec_jiffies,
1053 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 },
1055 {
1056 .ctl_name = VM_BLOCK_DUMP,
1057 .procname = "block_dump",
1058 .data = &block_dump,
1059 .maxlen = sizeof(block_dump),
1060 .mode = 0644,
1061 .proc_handler = &proc_dointvec,
1062 .strategy = &sysctl_intvec,
1063 .extra1 = &zero,
1064 },
1065 {
1066 .ctl_name = VM_VFS_CACHE_PRESSURE,
1067 .procname = "vfs_cache_pressure",
1068 .data = &sysctl_vfs_cache_pressure,
1069 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1070 .mode = 0644,
1071 .proc_handler = &proc_dointvec,
1072 .strategy = &sysctl_intvec,
1073 .extra1 = &zero,
1074 },
1075#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1076 {
1077 .ctl_name = VM_LEGACY_VA_LAYOUT,
1078 .procname = "legacy_va_layout",
1079 .data = &sysctl_legacy_va_layout,
1080 .maxlen = sizeof(sysctl_legacy_va_layout),
1081 .mode = 0644,
1082 .proc_handler = &proc_dointvec,
1083 .strategy = &sysctl_intvec,
1084 .extra1 = &zero,
1085 },
1086#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001087#ifdef CONFIG_NUMA
1088 {
1089 .ctl_name = VM_ZONE_RECLAIM_MODE,
1090 .procname = "zone_reclaim_mode",
1091 .data = &zone_reclaim_mode,
1092 .maxlen = sizeof(zone_reclaim_mode),
1093 .mode = 0644,
1094 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001095 .strategy = &sysctl_intvec,
1096 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001097 },
Christoph Lameter96146342006-07-03 00:24:13 -07001098 {
1099 .ctl_name = VM_MIN_UNMAPPED,
1100 .procname = "min_unmapped_ratio",
1101 .data = &sysctl_min_unmapped_ratio,
1102 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1103 .mode = 0644,
1104 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1105 .strategy = &sysctl_intvec,
1106 .extra1 = &zero,
1107 .extra2 = &one_hundred,
1108 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001109 {
1110 .ctl_name = VM_MIN_SLAB,
1111 .procname = "min_slab_ratio",
1112 .data = &sysctl_min_slab_ratio,
1113 .maxlen = sizeof(sysctl_min_slab_ratio),
1114 .mode = 0644,
1115 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1116 .strategy = &sysctl_intvec,
1117 .extra1 = &zero,
1118 .extra2 = &one_hundred,
1119 },
Christoph Lameter17436602006-01-18 17:42:32 -08001120#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001121#ifdef CONFIG_SMP
1122 {
1123 .ctl_name = CTL_UNNUMBERED,
1124 .procname = "stat_interval",
1125 .data = &sysctl_stat_interval,
1126 .maxlen = sizeof(sysctl_stat_interval),
1127 .mode = 0644,
1128 .proc_handler = &proc_dointvec_jiffies,
1129 .strategy = &sysctl_jiffies,
1130 },
1131#endif
Eric Parised032182007-06-28 15:55:21 -04001132#ifdef CONFIG_SECURITY
1133 {
1134 .ctl_name = CTL_UNNUMBERED,
1135 .procname = "mmap_min_addr",
1136 .data = &mmap_min_addr,
1137 .maxlen = sizeof(unsigned long),
1138 .mode = 0644,
1139 .proc_handler = &proc_doulongvec_minmax,
1140 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001141#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001142#ifdef CONFIG_NUMA
1143 {
1144 .ctl_name = CTL_UNNUMBERED,
1145 .procname = "numa_zonelist_order",
1146 .data = &numa_zonelist_order,
1147 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1148 .mode = 0644,
1149 .proc_handler = &numa_zonelist_order_handler,
1150 .strategy = &sysctl_string,
1151 },
1152#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001153#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001154 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001155 {
1156 .ctl_name = VM_VDSO_ENABLED,
1157 .procname = "vdso_enabled",
1158 .data = &vdso_enabled,
1159 .maxlen = sizeof(vdso_enabled),
1160 .mode = 0644,
1161 .proc_handler = &proc_dointvec,
1162 .strategy = &sysctl_intvec,
1163 .extra1 = &zero,
1164 },
1165#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001166#ifdef CONFIG_HIGHMEM
1167 {
1168 .ctl_name = CTL_UNNUMBERED,
1169 .procname = "highmem_is_dirtyable",
1170 .data = &vm_highmem_is_dirtyable,
1171 .maxlen = sizeof(vm_highmem_is_dirtyable),
1172 .mode = 0644,
1173 .proc_handler = &proc_dointvec_minmax,
1174 .strategy = &sysctl_intvec,
1175 .extra1 = &zero,
1176 .extra2 = &one,
1177 },
1178#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001179/*
1180 * NOTE: do not add new entries to this table unless you have read
1181 * Documentation/sysctl/ctl_unnumbered.txt
1182 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 { .ctl_name = 0 }
1184};
1185
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001186#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001187static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001188 { .ctl_name = 0 }
1189};
1190#endif
1191
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001192static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 {
1194 .ctl_name = FS_NRINODE,
1195 .procname = "inode-nr",
1196 .data = &inodes_stat,
1197 .maxlen = 2*sizeof(int),
1198 .mode = 0444,
1199 .proc_handler = &proc_dointvec,
1200 },
1201 {
1202 .ctl_name = FS_STATINODE,
1203 .procname = "inode-state",
1204 .data = &inodes_stat,
1205 .maxlen = 7*sizeof(int),
1206 .mode = 0444,
1207 .proc_handler = &proc_dointvec,
1208 },
1209 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 .procname = "file-nr",
1211 .data = &files_stat,
1212 .maxlen = 3*sizeof(int),
1213 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001214 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 },
1216 {
1217 .ctl_name = FS_MAXFILE,
1218 .procname = "file-max",
1219 .data = &files_stat.max_files,
1220 .maxlen = sizeof(int),
1221 .mode = 0644,
1222 .proc_handler = &proc_dointvec,
1223 },
1224 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001225 .ctl_name = CTL_UNNUMBERED,
1226 .procname = "nr_open",
1227 .data = &sysctl_nr_open,
1228 .maxlen = sizeof(int),
1229 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001230 .proc_handler = &proc_dointvec_minmax,
1231 .extra1 = &sysctl_nr_open_min,
1232 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001233 },
1234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 .ctl_name = FS_DENTRY,
1236 .procname = "dentry-state",
1237 .data = &dentry_stat,
1238 .maxlen = 6*sizeof(int),
1239 .mode = 0444,
1240 .proc_handler = &proc_dointvec,
1241 },
1242 {
1243 .ctl_name = FS_OVERFLOWUID,
1244 .procname = "overflowuid",
1245 .data = &fs_overflowuid,
1246 .maxlen = sizeof(int),
1247 .mode = 0644,
1248 .proc_handler = &proc_dointvec_minmax,
1249 .strategy = &sysctl_intvec,
1250 .extra1 = &minolduid,
1251 .extra2 = &maxolduid,
1252 },
1253 {
1254 .ctl_name = FS_OVERFLOWGID,
1255 .procname = "overflowgid",
1256 .data = &fs_overflowgid,
1257 .maxlen = sizeof(int),
1258 .mode = 0644,
1259 .proc_handler = &proc_dointvec_minmax,
1260 .strategy = &sysctl_intvec,
1261 .extra1 = &minolduid,
1262 .extra2 = &maxolduid,
1263 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001264#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 {
1266 .ctl_name = FS_LEASES,
1267 .procname = "leases-enable",
1268 .data = &leases_enable,
1269 .maxlen = sizeof(int),
1270 .mode = 0644,
1271 .proc_handler = &proc_dointvec,
1272 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001273#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274#ifdef CONFIG_DNOTIFY
1275 {
1276 .ctl_name = FS_DIR_NOTIFY,
1277 .procname = "dir-notify-enable",
1278 .data = &dir_notify_enable,
1279 .maxlen = sizeof(int),
1280 .mode = 0644,
1281 .proc_handler = &proc_dointvec,
1282 },
1283#endif
1284#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001285#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 {
1287 .ctl_name = FS_LEASE_TIME,
1288 .procname = "lease-break-time",
1289 .data = &lease_break_time,
1290 .maxlen = sizeof(int),
1291 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001292 .proc_handler = &proc_dointvec_minmax,
1293 .strategy = &sysctl_intvec,
1294 .extra1 = &zero,
1295 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001297#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 .procname = "aio-nr",
1300 .data = &aio_nr,
1301 .maxlen = sizeof(aio_nr),
1302 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001303 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 },
1305 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 .procname = "aio-max-nr",
1307 .data = &aio_max_nr,
1308 .maxlen = sizeof(aio_max_nr),
1309 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001310 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001312#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001313 {
1314 .ctl_name = FS_INOTIFY,
1315 .procname = "inotify",
1316 .mode = 0555,
1317 .child = inotify_table,
1318 },
1319#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001321 {
1322 .ctl_name = KERN_SETUID_DUMPABLE,
1323 .procname = "suid_dumpable",
1324 .data = &suid_dumpable,
1325 .maxlen = sizeof(int),
1326 .mode = 0644,
1327 .proc_handler = &proc_dointvec,
1328 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001329#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1330 {
1331 .ctl_name = CTL_UNNUMBERED,
1332 .procname = "binfmt_misc",
1333 .mode = 0555,
1334 .child = binfmt_misc_table,
1335 },
1336#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001337/*
1338 * NOTE: do not add new entries to this table unless you have read
1339 * Documentation/sysctl/ctl_unnumbered.txt
1340 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 { .ctl_name = 0 }
1342};
1343
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001344static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001345#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001346 {
1347 .ctl_name = CTL_UNNUMBERED,
1348 .procname = "exception-trace",
1349 .data = &show_unhandled_signals,
1350 .maxlen = sizeof(int),
1351 .mode = 0644,
1352 .proc_handler = proc_dointvec
1353 },
1354#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 { .ctl_name = 0 }
1356};
1357
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001358static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001360};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
Al Viro330d57f2005-11-04 10:18:40 +00001362static DEFINE_SPINLOCK(sysctl_lock);
1363
1364/* called under sysctl_lock */
1365static int use_table(struct ctl_table_header *p)
1366{
1367 if (unlikely(p->unregistering))
1368 return 0;
1369 p->used++;
1370 return 1;
1371}
1372
1373/* called under sysctl_lock */
1374static void unuse_table(struct ctl_table_header *p)
1375{
1376 if (!--p->used)
1377 if (unlikely(p->unregistering))
1378 complete(p->unregistering);
1379}
1380
1381/* called under sysctl_lock, will reacquire if has to wait */
1382static void start_unregistering(struct ctl_table_header *p)
1383{
1384 /*
1385 * if p->used is 0, nobody will ever touch that entry again;
1386 * we'll eliminate all paths to it before dropping sysctl_lock
1387 */
1388 if (unlikely(p->used)) {
1389 struct completion wait;
1390 init_completion(&wait);
1391 p->unregistering = &wait;
1392 spin_unlock(&sysctl_lock);
1393 wait_for_completion(&wait);
1394 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001395 } else {
1396 /* anything non-NULL; we'll never dereference it */
1397 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001398 }
1399 /*
1400 * do not remove from the list until nobody holds it; walking the
1401 * list in do_sysctl() relies on that.
1402 */
1403 list_del_init(&p->ctl_entry);
1404}
1405
Al Virof7e6ced2008-07-15 01:44:23 -04001406void sysctl_head_get(struct ctl_table_header *head)
1407{
1408 spin_lock(&sysctl_lock);
1409 head->count++;
1410 spin_unlock(&sysctl_lock);
1411}
1412
1413void sysctl_head_put(struct ctl_table_header *head)
1414{
1415 spin_lock(&sysctl_lock);
1416 if (!--head->count)
1417 kfree(head);
1418 spin_unlock(&sysctl_lock);
1419}
1420
1421struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1422{
1423 if (!head)
1424 BUG();
1425 spin_lock(&sysctl_lock);
1426 if (!use_table(head))
1427 head = ERR_PTR(-ENOENT);
1428 spin_unlock(&sysctl_lock);
1429 return head;
1430}
1431
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001432void sysctl_head_finish(struct ctl_table_header *head)
1433{
1434 if (!head)
1435 return;
1436 spin_lock(&sysctl_lock);
1437 unuse_table(head);
1438 spin_unlock(&sysctl_lock);
1439}
1440
Al Viro73455092008-07-14 21:22:20 -04001441static struct ctl_table_set *
1442lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1443{
1444 struct ctl_table_set *set = &root->default_set;
1445 if (root->lookup)
1446 set = root->lookup(root, namespaces);
1447 return set;
1448}
1449
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001450static struct list_head *
1451lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001452{
Al Viro73455092008-07-14 21:22:20 -04001453 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1454 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001455}
1456
1457struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1458 struct ctl_table_header *prev)
1459{
1460 struct ctl_table_root *root;
1461 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001462 struct ctl_table_header *head;
1463 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001464
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001465 spin_lock(&sysctl_lock);
1466 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001467 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001468 tmp = &prev->ctl_entry;
1469 unuse_table(prev);
1470 goto next;
1471 }
1472 tmp = &root_table_header.ctl_entry;
1473 for (;;) {
1474 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1475
1476 if (!use_table(head))
1477 goto next;
1478 spin_unlock(&sysctl_lock);
1479 return head;
1480 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001481 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001482 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001483 header_list = lookup_header_list(root, namespaces);
1484 if (tmp != header_list)
1485 continue;
1486
1487 do {
1488 root = list_entry(root->root_list.next,
1489 struct ctl_table_root, root_list);
1490 if (root == &sysctl_table_root)
1491 goto out;
1492 header_list = lookup_header_list(root, namespaces);
1493 } while (list_empty(header_list));
1494 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001495 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001496out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001497 spin_unlock(&sysctl_lock);
1498 return NULL;
1499}
1500
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001501struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1502{
1503 return __sysctl_head_next(current->nsproxy, prev);
1504}
1505
1506void register_sysctl_root(struct ctl_table_root *root)
1507{
1508 spin_lock(&sysctl_lock);
1509 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1510 spin_unlock(&sysctl_lock);
1511}
1512
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001513#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001514/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001515static int do_sysctl_strategy(struct ctl_table_root *root,
1516 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001517 int __user *name, int nlen,
1518 void __user *oldval, size_t __user *oldlenp,
1519 void __user *newval, size_t newlen)
1520{
1521 int op = 0, rc;
1522
1523 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001524 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001525 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001526 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001527 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001528 return -EPERM;
1529
1530 if (table->strategy) {
1531 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1532 newval, newlen);
1533 if (rc < 0)
1534 return rc;
1535 if (rc > 0)
1536 return 0;
1537 }
1538
1539 /* If there is no strategy routine, or if the strategy returns
1540 * zero, proceed with automatic r/w */
1541 if (table->data && table->maxlen) {
1542 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1543 newval, newlen);
1544 if (rc < 0)
1545 return rc;
1546 }
1547 return 0;
1548}
1549
1550static int parse_table(int __user *name, int nlen,
1551 void __user *oldval, size_t __user *oldlenp,
1552 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001553 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001554 struct ctl_table *table)
1555{
1556 int n;
1557repeat:
1558 if (!nlen)
1559 return -ENOTDIR;
1560 if (get_user(n, name))
1561 return -EFAULT;
1562 for ( ; table->ctl_name || table->procname; table++) {
1563 if (!table->ctl_name)
1564 continue;
1565 if (n == table->ctl_name) {
1566 int error;
1567 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001568 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001569 return -EPERM;
1570 name++;
1571 nlen--;
1572 table = table->child;
1573 goto repeat;
1574 }
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001575 error = do_sysctl_strategy(root, table, name, nlen,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001576 oldval, oldlenp,
1577 newval, newlen);
1578 return error;
1579 }
1580 }
1581 return -ENOTDIR;
1582}
1583
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1585 void __user *newval, size_t newlen)
1586{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001587 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001588 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
1590 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1591 return -ENOTDIR;
1592 if (oldval) {
1593 int old_len;
1594 if (!oldlenp || get_user(old_len, oldlenp))
1595 return -EFAULT;
1596 }
Al Viro330d57f2005-11-04 10:18:40 +00001597
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001598 for (head = sysctl_head_next(NULL); head;
1599 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001600 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001601 newval, newlen,
1602 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001603 if (error != -ENOTDIR) {
1604 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001605 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001606 }
1607 }
Al Viro330d57f2005-11-04 10:18:40 +00001608 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609}
1610
1611asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1612{
1613 struct __sysctl_args tmp;
1614 int error;
1615
1616 if (copy_from_user(&tmp, args, sizeof(tmp)))
1617 return -EFAULT;
1618
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001619 error = deprecated_sysctl_warning(&tmp);
1620 if (error)
1621 goto out;
1622
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 lock_kernel();
1624 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1625 tmp.newval, tmp.newlen);
1626 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001627out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 return error;
1629}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001630#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
1632/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001633 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 * some sysctl variables are readonly even to root.
1635 */
1636
1637static int test_perm(int mode, int op)
1638{
1639 if (!current->euid)
1640 mode >>= 6;
1641 else if (in_egroup_p(0))
1642 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001643 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 return 0;
1645 return -EACCES;
1646}
1647
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001648int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649{
1650 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001651 int mode;
1652
Al Viroe6305c42008-07-15 21:03:57 -04001653 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 if (error)
1655 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001656
1657 if (root->permissions)
1658 mode = root->permissions(root, current->nsproxy, table);
1659 else
1660 mode = table->mode;
1661
1662 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001665static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1666{
1667 for (; table->ctl_name || table->procname; table++) {
1668 table->parent = parent;
1669 if (table->child)
1670 sysctl_set_parent(table, table->child);
1671 }
1672}
1673
1674static __init int sysctl_init(void)
1675{
1676 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001677#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1678 {
1679 int err;
1680 err = sysctl_check_table(current->nsproxy, root_table);
1681 }
1682#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001683 return 0;
1684}
1685
1686core_initcall(sysctl_init);
1687
Al Virobfbcf032008-07-27 06:31:22 +01001688static struct ctl_table *is_branch_in(struct ctl_table *branch,
1689 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001690{
1691 struct ctl_table *p;
1692 const char *s = branch->procname;
1693
1694 /* branch should have named subdirectory as its first element */
1695 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001696 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001697
1698 /* ... and nothing else */
1699 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001700 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001701
1702 /* table should contain subdirectory with the same name */
1703 for (p = table; p->procname || p->ctl_name; p++) {
1704 if (!p->child)
1705 continue;
1706 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001707 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001708 }
Al Virobfbcf032008-07-27 06:31:22 +01001709 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001710}
1711
1712/* see if attaching q to p would be an improvement */
1713static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1714{
1715 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001716 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001717 int is_better = 0;
1718 int not_in_parent = !p->attached_by;
1719
Al Virobfbcf032008-07-27 06:31:22 +01001720 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001721 if (by == q->attached_by)
1722 is_better = 1;
1723 if (to == p->attached_by)
1724 not_in_parent = 1;
1725 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001726 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001727 }
1728
1729 if (is_better && not_in_parent) {
1730 q->attached_by = by;
1731 q->attached_to = to;
1732 q->parent = p;
1733 }
1734}
1735
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001737 * __register_sysctl_paths - register a sysctl hierarchy
1738 * @root: List of sysctl headers to register on
1739 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001740 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 *
1743 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001744 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001746 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 *
1748 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1749 * must be unique within that level of sysctl
1750 *
1751 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1752 * enter a sysctl file
1753 *
1754 * data - a pointer to data for use by proc_handler
1755 *
1756 * maxlen - the maximum size in bytes of the data
1757 *
1758 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1759 *
1760 * child - a pointer to the child sysctl table if this entry is a directory, or
1761 * %NULL.
1762 *
1763 * proc_handler - the text handler routine (described below)
1764 *
1765 * strategy - the strategy routine (described below)
1766 *
1767 * de - for internal use by the sysctl routines
1768 *
1769 * extra1, extra2 - extra pointers usable by the proc handler routines
1770 *
1771 * Leaf nodes in the sysctl tree will be represented by a single file
1772 * under /proc; non-leaf nodes will be represented by directories.
1773 *
1774 * sysctl(2) can automatically manage read and write requests through
1775 * the sysctl table. The data and maxlen fields of the ctl_table
1776 * struct enable minimal validation of the values being written to be
1777 * performed, and the mode field allows minimal authentication.
1778 *
1779 * More sophisticated management can be enabled by the provision of a
1780 * strategy routine with the table entry. This will be called before
1781 * any automatic read or write of the data is performed.
1782 *
1783 * The strategy routine may return
1784 *
1785 * < 0 - Error occurred (error is passed to user process)
1786 *
1787 * 0 - OK - proceed with automatic read or write.
1788 *
1789 * > 0 - OK - read or write has been done by the strategy routine, so
1790 * return immediately.
1791 *
1792 * There must be a proc_handler routine for any terminal nodes
1793 * mirrored under /proc/sys (non-terminals are handled by a built-in
1794 * directory handler). Several default handlers are available to
1795 * cover common cases -
1796 *
1797 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1798 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1799 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1800 *
1801 * It is the handler's job to read the input buffer from user memory
1802 * and process it. The handler should return 0 on success.
1803 *
1804 * This routine returns %NULL on a failure to register, and a pointer
1805 * to the table header on success.
1806 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001807struct ctl_table_header *__register_sysctl_paths(
1808 struct ctl_table_root *root,
1809 struct nsproxy *namespaces,
1810 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001812 struct ctl_table_header *header;
1813 struct ctl_table *new, **prevp;
1814 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001815 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001816
1817 /* Count the path components */
1818 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1819 ;
1820
1821 /*
1822 * For each path component, allocate a 2-element ctl_table array.
1823 * The first array element will be filled with the sysctl entry
1824 * for this, the second will be the sentinel (ctl_name == 0).
1825 *
1826 * We allocate everything in one go so that we don't have to
1827 * worry about freeing additional memory in unregister_sysctl_table.
1828 */
1829 header = kzalloc(sizeof(struct ctl_table_header) +
1830 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1831 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001833
1834 new = (struct ctl_table *) (header + 1);
1835
1836 /* Now connect the dots */
1837 prevp = &header->ctl_table;
1838 for (n = 0; n < npath; ++n, ++path) {
1839 /* Copy the procname */
1840 new->procname = path->procname;
1841 new->ctl_name = path->ctl_name;
1842 new->mode = 0555;
1843
1844 *prevp = new;
1845 prevp = &new->child;
1846
1847 new += 2;
1848 }
1849 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001850 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001851
1852 INIT_LIST_HEAD(&header->ctl_entry);
1853 header->used = 0;
1854 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001855 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001856 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001857 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001858#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001859 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001860 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001861 return NULL;
1862 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001863#endif
Al Viro330d57f2005-11-04 10:18:40 +00001864 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001865 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001866 header->attached_by = header->ctl_table;
1867 header->attached_to = root_table;
1868 header->parent = &root_table_header;
1869 for (set = header->set; set; set = set->parent) {
1870 struct ctl_table_header *p;
1871 list_for_each_entry(p, &set->list, ctl_entry) {
1872 if (p->unregistering)
1873 continue;
1874 try_attach(p, header);
1875 }
1876 }
1877 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001878 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001879 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001880
1881 return header;
1882}
1883
1884/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001885 * register_sysctl_table_path - register a sysctl table hierarchy
1886 * @path: The path to the directory the sysctl table is in.
1887 * @table: the top-level table structure
1888 *
1889 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1890 * array. A completely 0 filled entry terminates the table.
1891 *
1892 * See __register_sysctl_paths for more details.
1893 */
1894struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1895 struct ctl_table *table)
1896{
1897 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1898 path, table);
1899}
1900
1901/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001902 * register_sysctl_table - register a sysctl table hierarchy
1903 * @table: the top-level table structure
1904 *
1905 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1906 * array. A completely 0 filled entry terminates the table.
1907 *
1908 * See register_sysctl_paths for more details.
1909 */
1910struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1911{
1912 static const struct ctl_path null_path[] = { {} };
1913
1914 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915}
1916
1917/**
1918 * unregister_sysctl_table - unregister a sysctl table hierarchy
1919 * @header: the header returned from register_sysctl_table
1920 *
1921 * Unregisters the sysctl table and all children. proc entries may not
1922 * actually be removed until they are no longer used by anyone.
1923 */
1924void unregister_sysctl_table(struct ctl_table_header * header)
1925{
Al Viro330d57f2005-11-04 10:18:40 +00001926 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001927
1928 if (header == NULL)
1929 return;
1930
Al Viro330d57f2005-11-04 10:18:40 +00001931 spin_lock(&sysctl_lock);
1932 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001933 if (!--header->parent->count) {
1934 WARN_ON(1);
1935 kfree(header->parent);
1936 }
Al Virof7e6ced2008-07-15 01:44:23 -04001937 if (!--header->count)
1938 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001939 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940}
1941
Al Viro9043476f2008-07-15 08:54:06 -04001942int sysctl_is_seen(struct ctl_table_header *p)
1943{
1944 struct ctl_table_set *set = p->set;
1945 int res;
1946 spin_lock(&sysctl_lock);
1947 if (p->unregistering)
1948 res = 0;
1949 else if (!set->is_seen)
1950 res = 1;
1951 else
1952 res = set->is_seen(set);
1953 spin_unlock(&sysctl_lock);
1954 return res;
1955}
1956
Al Viro73455092008-07-14 21:22:20 -04001957void setup_sysctl_set(struct ctl_table_set *p,
1958 struct ctl_table_set *parent,
1959 int (*is_seen)(struct ctl_table_set *))
1960{
1961 INIT_LIST_HEAD(&p->list);
1962 p->parent = parent ? parent : &sysctl_table_root.default_set;
1963 p->is_seen = is_seen;
1964}
1965
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001966#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001967struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001968{
1969 return NULL;
1970}
1971
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001972struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1973 struct ctl_table *table)
1974{
1975 return NULL;
1976}
1977
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001978void unregister_sysctl_table(struct ctl_table_header * table)
1979{
1980}
1981
Al Viro73455092008-07-14 21:22:20 -04001982void setup_sysctl_set(struct ctl_table_set *p,
1983 struct ctl_table_set *parent,
1984 int (*is_seen)(struct ctl_table_set *))
1985{
1986}
1987
Al Virof7e6ced2008-07-15 01:44:23 -04001988void sysctl_head_put(struct ctl_table_header *head)
1989{
1990}
1991
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001992#endif /* CONFIG_SYSCTL */
1993
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994/*
1995 * /proc/sys support
1996 */
1997
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001998#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002000static int _proc_do_string(void* data, int maxlen, int write,
2001 struct file *filp, void __user *buffer,
2002 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002003{
2004 size_t len;
2005 char __user *p;
2006 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002007
2008 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002009 *lenp = 0;
2010 return 0;
2011 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002012
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002013 if (write) {
2014 len = 0;
2015 p = buffer;
2016 while (len < *lenp) {
2017 if (get_user(c, p++))
2018 return -EFAULT;
2019 if (c == 0 || c == '\n')
2020 break;
2021 len++;
2022 }
2023 if (len >= maxlen)
2024 len = maxlen-1;
2025 if(copy_from_user(data, buffer, len))
2026 return -EFAULT;
2027 ((char *) data)[len] = 0;
2028 *ppos += *lenp;
2029 } else {
2030 len = strlen(data);
2031 if (len > maxlen)
2032 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002033
2034 if (*ppos > len) {
2035 *lenp = 0;
2036 return 0;
2037 }
2038
2039 data += *ppos;
2040 len -= *ppos;
2041
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002042 if (len > *lenp)
2043 len = *lenp;
2044 if (len)
2045 if(copy_to_user(buffer, data, len))
2046 return -EFAULT;
2047 if (len < *lenp) {
2048 if(put_user('\n', ((char __user *) buffer) + len))
2049 return -EFAULT;
2050 len++;
2051 }
2052 *lenp = len;
2053 *ppos += len;
2054 }
2055 return 0;
2056}
2057
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058/**
2059 * proc_dostring - read a string sysctl
2060 * @table: the sysctl table
2061 * @write: %TRUE if this is a write to the sysctl file
2062 * @filp: the file structure
2063 * @buffer: the user buffer
2064 * @lenp: the size of the user buffer
2065 * @ppos: file position
2066 *
2067 * Reads/writes a string from/to the user buffer. If the kernel
2068 * buffer provided is not large enough to hold the string, the
2069 * string is truncated. The copied string is %NULL-terminated.
2070 * If the string is being read by the user process, it is copied
2071 * and a newline '\n' is added. It is truncated if the buffer is
2072 * not large enough.
2073 *
2074 * Returns 0 on success.
2075 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002076int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 void __user *buffer, size_t *lenp, loff_t *ppos)
2078{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002079 return _proc_do_string(table->data, table->maxlen, write, filp,
2080 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081}
2082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
2084static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2085 int *valp,
2086 int write, void *data)
2087{
2088 if (write) {
2089 *valp = *negp ? -*lvalp : *lvalp;
2090 } else {
2091 int val = *valp;
2092 if (val < 0) {
2093 *negp = -1;
2094 *lvalp = (unsigned long)-val;
2095 } else {
2096 *negp = 0;
2097 *lvalp = (unsigned long)val;
2098 }
2099 }
2100 return 0;
2101}
2102
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002103static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002104 int write, struct file *filp, void __user *buffer,
2105 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2107 int write, void *data),
2108 void *data)
2109{
2110#define TMPBUFLEN 21
2111 int *i, vleft, first=1, neg, val;
2112 unsigned long lval;
2113 size_t left, len;
2114
2115 char buf[TMPBUFLEN], *p;
2116 char __user *s = buffer;
2117
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002118 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 (*ppos && !write)) {
2120 *lenp = 0;
2121 return 0;
2122 }
2123
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002124 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 vleft = table->maxlen / sizeof(*i);
2126 left = *lenp;
2127
2128 if (!conv)
2129 conv = do_proc_dointvec_conv;
2130
2131 for (; left && vleft--; i++, first=0) {
2132 if (write) {
2133 while (left) {
2134 char c;
2135 if (get_user(c, s))
2136 return -EFAULT;
2137 if (!isspace(c))
2138 break;
2139 left--;
2140 s++;
2141 }
2142 if (!left)
2143 break;
2144 neg = 0;
2145 len = left;
2146 if (len > sizeof(buf) - 1)
2147 len = sizeof(buf) - 1;
2148 if (copy_from_user(buf, s, len))
2149 return -EFAULT;
2150 buf[len] = 0;
2151 p = buf;
2152 if (*p == '-' && left > 1) {
2153 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002154 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 }
2156 if (*p < '0' || *p > '9')
2157 break;
2158
2159 lval = simple_strtoul(p, &p, 0);
2160
2161 len = p-buf;
2162 if ((len < left) && *p && !isspace(*p))
2163 break;
2164 if (neg)
2165 val = -val;
2166 s += len;
2167 left -= len;
2168
2169 if (conv(&neg, &lval, i, 1, data))
2170 break;
2171 } else {
2172 p = buf;
2173 if (!first)
2174 *p++ = '\t';
2175
2176 if (conv(&neg, &lval, i, 0, data))
2177 break;
2178
2179 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2180 len = strlen(buf);
2181 if (len > left)
2182 len = left;
2183 if(copy_to_user(s, buf, len))
2184 return -EFAULT;
2185 left -= len;
2186 s += len;
2187 }
2188 }
2189
2190 if (!write && !first && left) {
2191 if(put_user('\n', s))
2192 return -EFAULT;
2193 left--, s++;
2194 }
2195 if (write) {
2196 while (left) {
2197 char c;
2198 if (get_user(c, s++))
2199 return -EFAULT;
2200 if (!isspace(c))
2201 break;
2202 left--;
2203 }
2204 }
2205 if (write && first)
2206 return -EINVAL;
2207 *lenp -= left;
2208 *ppos += *lenp;
2209 return 0;
2210#undef TMPBUFLEN
2211}
2212
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002213static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002214 void __user *buffer, size_t *lenp, loff_t *ppos,
2215 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2216 int write, void *data),
2217 void *data)
2218{
2219 return __do_proc_dointvec(table->data, table, write, filp,
2220 buffer, lenp, ppos, conv, data);
2221}
2222
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223/**
2224 * proc_dointvec - read a vector of integers
2225 * @table: the sysctl table
2226 * @write: %TRUE if this is a write to the sysctl file
2227 * @filp: the file structure
2228 * @buffer: the user buffer
2229 * @lenp: the size of the user buffer
2230 * @ppos: file position
2231 *
2232 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2233 * values from/to the user buffer, treated as an ASCII string.
2234 *
2235 * Returns 0 on success.
2236 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002237int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 void __user *buffer, size_t *lenp, loff_t *ppos)
2239{
2240 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2241 NULL,NULL);
2242}
2243
2244#define OP_SET 0
2245#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002246#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
2248static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2249 int *valp,
2250 int write, void *data)
2251{
2252 int op = *(int *)data;
2253 if (write) {
2254 int val = *negp ? -*lvalp : *lvalp;
2255 switch(op) {
2256 case OP_SET: *valp = val; break;
2257 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002258 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 }
2260 } else {
2261 int val = *valp;
2262 if (val < 0) {
2263 *negp = -1;
2264 *lvalp = (unsigned long)-val;
2265 } else {
2266 *negp = 0;
2267 *lvalp = (unsigned long)val;
2268 }
2269 }
2270 return 0;
2271}
2272
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002273/*
2274 * Taint values can only be increased
2275 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002276static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002277 void __user *buffer, size_t *lenp, loff_t *ppos)
2278{
2279 int op;
2280
Bastian Blank91fcd412007-04-23 14:41:14 -07002281 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002282 return -EPERM;
2283
2284 op = OP_OR;
2285 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2286 do_proc_dointvec_bset_conv,&op);
2287}
2288
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289struct do_proc_dointvec_minmax_conv_param {
2290 int *min;
2291 int *max;
2292};
2293
2294static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2295 int *valp,
2296 int write, void *data)
2297{
2298 struct do_proc_dointvec_minmax_conv_param *param = data;
2299 if (write) {
2300 int val = *negp ? -*lvalp : *lvalp;
2301 if ((param->min && *param->min > val) ||
2302 (param->max && *param->max < val))
2303 return -EINVAL;
2304 *valp = val;
2305 } else {
2306 int val = *valp;
2307 if (val < 0) {
2308 *negp = -1;
2309 *lvalp = (unsigned long)-val;
2310 } else {
2311 *negp = 0;
2312 *lvalp = (unsigned long)val;
2313 }
2314 }
2315 return 0;
2316}
2317
2318/**
2319 * proc_dointvec_minmax - read a vector of integers with min/max values
2320 * @table: the sysctl table
2321 * @write: %TRUE if this is a write to the sysctl file
2322 * @filp: the file structure
2323 * @buffer: the user buffer
2324 * @lenp: the size of the user buffer
2325 * @ppos: file position
2326 *
2327 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2328 * values from/to the user buffer, treated as an ASCII string.
2329 *
2330 * This routine will ensure the values are within the range specified by
2331 * table->extra1 (min) and table->extra2 (max).
2332 *
2333 * Returns 0 on success.
2334 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002335int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 void __user *buffer, size_t *lenp, loff_t *ppos)
2337{
2338 struct do_proc_dointvec_minmax_conv_param param = {
2339 .min = (int *) table->extra1,
2340 .max = (int *) table->extra2,
2341 };
2342 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2343 do_proc_dointvec_minmax_conv, &param);
2344}
2345
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002346static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 struct file *filp,
2348 void __user *buffer,
2349 size_t *lenp, loff_t *ppos,
2350 unsigned long convmul,
2351 unsigned long convdiv)
2352{
2353#define TMPBUFLEN 21
2354 unsigned long *i, *min, *max, val;
2355 int vleft, first=1, neg;
2356 size_t len, left;
2357 char buf[TMPBUFLEN], *p;
2358 char __user *s = buffer;
2359
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002360 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 (*ppos && !write)) {
2362 *lenp = 0;
2363 return 0;
2364 }
2365
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002366 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 min = (unsigned long *) table->extra1;
2368 max = (unsigned long *) table->extra2;
2369 vleft = table->maxlen / sizeof(unsigned long);
2370 left = *lenp;
2371
2372 for (; left && vleft--; i++, min++, max++, first=0) {
2373 if (write) {
2374 while (left) {
2375 char c;
2376 if (get_user(c, s))
2377 return -EFAULT;
2378 if (!isspace(c))
2379 break;
2380 left--;
2381 s++;
2382 }
2383 if (!left)
2384 break;
2385 neg = 0;
2386 len = left;
2387 if (len > TMPBUFLEN-1)
2388 len = TMPBUFLEN-1;
2389 if (copy_from_user(buf, s, len))
2390 return -EFAULT;
2391 buf[len] = 0;
2392 p = buf;
2393 if (*p == '-' && left > 1) {
2394 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002395 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 }
2397 if (*p < '0' || *p > '9')
2398 break;
2399 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2400 len = p-buf;
2401 if ((len < left) && *p && !isspace(*p))
2402 break;
2403 if (neg)
2404 val = -val;
2405 s += len;
2406 left -= len;
2407
2408 if(neg)
2409 continue;
2410 if ((min && val < *min) || (max && val > *max))
2411 continue;
2412 *i = val;
2413 } else {
2414 p = buf;
2415 if (!first)
2416 *p++ = '\t';
2417 sprintf(p, "%lu", convdiv * (*i) / convmul);
2418 len = strlen(buf);
2419 if (len > left)
2420 len = left;
2421 if(copy_to_user(s, buf, len))
2422 return -EFAULT;
2423 left -= len;
2424 s += len;
2425 }
2426 }
2427
2428 if (!write && !first && left) {
2429 if(put_user('\n', s))
2430 return -EFAULT;
2431 left--, s++;
2432 }
2433 if (write) {
2434 while (left) {
2435 char c;
2436 if (get_user(c, s++))
2437 return -EFAULT;
2438 if (!isspace(c))
2439 break;
2440 left--;
2441 }
2442 }
2443 if (write && first)
2444 return -EINVAL;
2445 *lenp -= left;
2446 *ppos += *lenp;
2447 return 0;
2448#undef TMPBUFLEN
2449}
2450
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002451static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002452 struct file *filp,
2453 void __user *buffer,
2454 size_t *lenp, loff_t *ppos,
2455 unsigned long convmul,
2456 unsigned long convdiv)
2457{
2458 return __do_proc_doulongvec_minmax(table->data, table, write,
2459 filp, buffer, lenp, ppos, convmul, convdiv);
2460}
2461
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462/**
2463 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2464 * @table: the sysctl table
2465 * @write: %TRUE if this is a write to the sysctl file
2466 * @filp: the file structure
2467 * @buffer: the user buffer
2468 * @lenp: the size of the user buffer
2469 * @ppos: file position
2470 *
2471 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2472 * values from/to the user buffer, treated as an ASCII string.
2473 *
2474 * This routine will ensure the values are within the range specified by
2475 * table->extra1 (min) and table->extra2 (max).
2476 *
2477 * Returns 0 on success.
2478 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002479int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 void __user *buffer, size_t *lenp, loff_t *ppos)
2481{
2482 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2483}
2484
2485/**
2486 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2487 * @table: the sysctl table
2488 * @write: %TRUE if this is a write to the sysctl file
2489 * @filp: the file structure
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2493 *
2494 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2495 * values from/to the user buffer, treated as an ASCII string. The values
2496 * are treated as milliseconds, and converted to jiffies when they are stored.
2497 *
2498 * This routine will ensure the values are within the range specified by
2499 * table->extra1 (min) and table->extra2 (max).
2500 *
2501 * Returns 0 on success.
2502 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002503int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 struct file *filp,
2505 void __user *buffer,
2506 size_t *lenp, loff_t *ppos)
2507{
2508 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2509 lenp, ppos, HZ, 1000l);
2510}
2511
2512
2513static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2514 int *valp,
2515 int write, void *data)
2516{
2517 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002518 if (*lvalp > LONG_MAX / HZ)
2519 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2521 } else {
2522 int val = *valp;
2523 unsigned long lval;
2524 if (val < 0) {
2525 *negp = -1;
2526 lval = (unsigned long)-val;
2527 } else {
2528 *negp = 0;
2529 lval = (unsigned long)val;
2530 }
2531 *lvalp = lval / HZ;
2532 }
2533 return 0;
2534}
2535
2536static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2537 int *valp,
2538 int write, void *data)
2539{
2540 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002541 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2542 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2544 } else {
2545 int val = *valp;
2546 unsigned long lval;
2547 if (val < 0) {
2548 *negp = -1;
2549 lval = (unsigned long)-val;
2550 } else {
2551 *negp = 0;
2552 lval = (unsigned long)val;
2553 }
2554 *lvalp = jiffies_to_clock_t(lval);
2555 }
2556 return 0;
2557}
2558
2559static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2560 int *valp,
2561 int write, void *data)
2562{
2563 if (write) {
2564 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2565 } else {
2566 int val = *valp;
2567 unsigned long lval;
2568 if (val < 0) {
2569 *negp = -1;
2570 lval = (unsigned long)-val;
2571 } else {
2572 *negp = 0;
2573 lval = (unsigned long)val;
2574 }
2575 *lvalp = jiffies_to_msecs(lval);
2576 }
2577 return 0;
2578}
2579
2580/**
2581 * proc_dointvec_jiffies - read a vector of integers as seconds
2582 * @table: the sysctl table
2583 * @write: %TRUE if this is a write to the sysctl file
2584 * @filp: the file structure
2585 * @buffer: the user buffer
2586 * @lenp: the size of the user buffer
2587 * @ppos: file position
2588 *
2589 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2590 * values from/to the user buffer, treated as an ASCII string.
2591 * The values read are assumed to be in seconds, and are converted into
2592 * jiffies.
2593 *
2594 * Returns 0 on success.
2595 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002596int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 void __user *buffer, size_t *lenp, loff_t *ppos)
2598{
2599 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2600 do_proc_dointvec_jiffies_conv,NULL);
2601}
2602
2603/**
2604 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
2607 * @filp: the file structure
2608 * @buffer: the user buffer
2609 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002610 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 *
2612 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2613 * values from/to the user buffer, treated as an ASCII string.
2614 * The values read are assumed to be in 1/USER_HZ seconds, and
2615 * are converted into jiffies.
2616 *
2617 * Returns 0 on success.
2618 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002619int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 void __user *buffer, size_t *lenp, loff_t *ppos)
2621{
2622 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2623 do_proc_dointvec_userhz_jiffies_conv,NULL);
2624}
2625
2626/**
2627 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2628 * @table: the sysctl table
2629 * @write: %TRUE if this is a write to the sysctl file
2630 * @filp: the file structure
2631 * @buffer: the user buffer
2632 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002633 * @ppos: file position
2634 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 *
2636 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2637 * values from/to the user buffer, treated as an ASCII string.
2638 * The values read are assumed to be in 1/1000 seconds, and
2639 * are converted into jiffies.
2640 *
2641 * Returns 0 on success.
2642 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002643int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 void __user *buffer, size_t *lenp, loff_t *ppos)
2645{
2646 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2647 do_proc_dointvec_ms_jiffies_conv, NULL);
2648}
2649
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002650static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002651 void __user *buffer, size_t *lenp, loff_t *ppos)
2652{
2653 struct pid *new_pid;
2654 pid_t tmp;
2655 int r;
2656
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002657 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002658
2659 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2660 lenp, ppos, NULL, NULL);
2661 if (r || !write)
2662 return r;
2663
2664 new_pid = find_get_pid(tmp);
2665 if (!new_pid)
2666 return -ESRCH;
2667
2668 put_pid(xchg(&cad_pid, new_pid));
2669 return 0;
2670}
2671
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672#else /* CONFIG_PROC_FS */
2673
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002674int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 void __user *buffer, size_t *lenp, loff_t *ppos)
2676{
2677 return -ENOSYS;
2678}
2679
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002680int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 void __user *buffer, size_t *lenp, loff_t *ppos)
2682{
2683 return -ENOSYS;
2684}
2685
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002686int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 void __user *buffer, size_t *lenp, loff_t *ppos)
2688{
2689 return -ENOSYS;
2690}
2691
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002692int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 void __user *buffer, size_t *lenp, loff_t *ppos)
2694{
2695 return -ENOSYS;
2696}
2697
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002698int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 void __user *buffer, size_t *lenp, loff_t *ppos)
2700{
2701 return -ENOSYS;
2702}
2703
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002704int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 void __user *buffer, size_t *lenp, loff_t *ppos)
2706{
2707 return -ENOSYS;
2708}
2709
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002710int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 void __user *buffer, size_t *lenp, loff_t *ppos)
2712{
2713 return -ENOSYS;
2714}
2715
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002716int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 struct file *filp,
2718 void __user *buffer,
2719 size_t *lenp, loff_t *ppos)
2720{
2721 return -ENOSYS;
2722}
2723
2724
2725#endif /* CONFIG_PROC_FS */
2726
2727
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002728#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729/*
2730 * General sysctl support routines
2731 */
2732
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002733/* The generic sysctl data routine (used if no strategy routine supplied) */
2734int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2735 void __user *oldval, size_t __user *oldlenp,
2736 void __user *newval, size_t newlen)
2737{
2738 size_t len;
2739
2740 /* Get out of I don't have a variable */
2741 if (!table->data || !table->maxlen)
2742 return -ENOTDIR;
2743
2744 if (oldval && oldlenp) {
2745 if (get_user(len, oldlenp))
2746 return -EFAULT;
2747 if (len) {
2748 if (len > table->maxlen)
2749 len = table->maxlen;
2750 if (copy_to_user(oldval, table->data, len))
2751 return -EFAULT;
2752 if (put_user(len, oldlenp))
2753 return -EFAULT;
2754 }
2755 }
2756
2757 if (newval && newlen) {
2758 if (newlen > table->maxlen)
2759 newlen = table->maxlen;
2760
2761 if (copy_from_user(table->data, newval, newlen))
2762 return -EFAULT;
2763 }
2764 return 1;
2765}
2766
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002768int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002770 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 if (!table->data || !table->maxlen)
2773 return -ENOTDIR;
2774
2775 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002776 size_t bufsize;
2777 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002779 if (bufsize) {
2780 size_t len = strlen(table->data), copied;
2781
2782 /* This shouldn't trigger for a well-formed sysctl */
2783 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002785
2786 /* Copy up to a max of bufsize-1 bytes of the string */
2787 copied = (len >= bufsize) ? bufsize - 1 : len;
2788
2789 if (copy_to_user(oldval, table->data, copied) ||
2790 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002792 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 return -EFAULT;
2794 }
2795 }
2796 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002797 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 if (len > table->maxlen)
2799 len = table->maxlen;
2800 if(copy_from_user(table->data, newval, len))
2801 return -EFAULT;
2802 if (len == table->maxlen)
2803 len--;
2804 ((char *) table->data)[len] = 0;
2805 }
Yi Yang82c9df82005-12-30 16:37:10 +08002806 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807}
2808
2809/*
2810 * This function makes sure that all of the integers in the vector
2811 * are between the minimum and maximum values given in the arrays
2812 * table->extra1 and table->extra2, respectively.
2813 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002814int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002816 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817{
2818
2819 if (newval && newlen) {
2820 int __user *vec = (int __user *) newval;
2821 int *min = (int *) table->extra1;
2822 int *max = (int *) table->extra2;
2823 size_t length;
2824 int i;
2825
2826 if (newlen % sizeof(int) != 0)
2827 return -EINVAL;
2828
2829 if (!table->extra1 && !table->extra2)
2830 return 0;
2831
2832 if (newlen > table->maxlen)
2833 newlen = table->maxlen;
2834 length = newlen / sizeof(int);
2835
2836 for (i = 0; i < length; i++) {
2837 int value;
2838 if (get_user(value, vec + i))
2839 return -EFAULT;
2840 if (min && value < min[i])
2841 return -EINVAL;
2842 if (max && value > max[i])
2843 return -EINVAL;
2844 }
2845 }
2846 return 0;
2847}
2848
2849/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002850int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002852 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002854 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002856
2857 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002859 if (olen) {
2860 int val;
2861
2862 if (olen < sizeof(int))
2863 return -EINVAL;
2864
2865 val = *(int *)(table->data) / HZ;
2866 if (put_user(val, (int __user *)oldval))
2867 return -EFAULT;
2868 if (put_user(sizeof(int), oldlenp))
2869 return -EFAULT;
2870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 }
2872 if (newval && newlen) {
2873 int new;
2874 if (newlen != sizeof(int))
2875 return -EINVAL;
2876 if (get_user(new, (int __user *)newval))
2877 return -EFAULT;
2878 *(int *)(table->data) = new*HZ;
2879 }
2880 return 1;
2881}
2882
2883/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002884int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002886 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002888 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002890
2891 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002893 if (olen) {
2894 int val;
2895
2896 if (olen < sizeof(int))
2897 return -EINVAL;
2898
2899 val = jiffies_to_msecs(*(int *)(table->data));
2900 if (put_user(val, (int __user *)oldval))
2901 return -EFAULT;
2902 if (put_user(sizeof(int), oldlenp))
2903 return -EFAULT;
2904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 }
2906 if (newval && newlen) {
2907 int new;
2908 if (newlen != sizeof(int))
2909 return -EINVAL;
2910 if (get_user(new, (int __user *)newval))
2911 return -EFAULT;
2912 *(int *)(table->data) = msecs_to_jiffies(new);
2913 }
2914 return 1;
2915}
2916
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002917
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002918
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002919#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920
2921
2922asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2923{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002924 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002925 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002926
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002927 if (copy_from_user(&tmp, args, sizeof(tmp)))
2928 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002929
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002930 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002931
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002932 /* If no error reading the parameters then just -ENOSYS ... */
2933 if (!error)
2934 error = -ENOSYS;
2935
2936 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937}
2938
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002939int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2940 void __user *oldval, size_t __user *oldlenp,
2941 void __user *newval, size_t newlen)
2942{
2943 return -ENOSYS;
2944}
2945
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002946int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002948 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949{
2950 return -ENOSYS;
2951}
2952
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002953int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002955 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956{
2957 return -ENOSYS;
2958}
2959
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002960int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002962 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963{
2964 return -ENOSYS;
2965}
2966
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002967int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002969 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970{
2971 return -ENOSYS;
2972}
2973
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002974#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002976static int deprecated_sysctl_warning(struct __sysctl_args *args)
2977{
2978 static int msg_count;
2979 int name[CTL_MAXNAME];
2980 int i;
2981
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002982 /* Check args->nlen. */
2983 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2984 return -ENOTDIR;
2985
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002986 /* Read in the sysctl name for better debug message logging */
2987 for (i = 0; i < args->nlen; i++)
2988 if (get_user(name[i], args->name + i))
2989 return -EFAULT;
2990
2991 /* Ignore accesses to kernel.version */
2992 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2993 return 0;
2994
2995 if (msg_count < 5) {
2996 msg_count++;
2997 printk(KERN_INFO
2998 "warning: process `%s' used the deprecated sysctl "
2999 "system call with ", current->comm);
3000 for (i = 0; i < args->nlen; i++)
3001 printk("%d.", name[i]);
3002 printk("\n");
3003 }
3004 return 0;
3005}
3006
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007/*
3008 * No sense putting this after each symbol definition, twice,
3009 * exception granted :-)
3010 */
3011EXPORT_SYMBOL(proc_dointvec);
3012EXPORT_SYMBOL(proc_dointvec_jiffies);
3013EXPORT_SYMBOL(proc_dointvec_minmax);
3014EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3015EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3016EXPORT_SYMBOL(proc_dostring);
3017EXPORT_SYMBOL(proc_doulongvec_minmax);
3018EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3019EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003020EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021EXPORT_SYMBOL(sysctl_intvec);
3022EXPORT_SYMBOL(sysctl_jiffies);
3023EXPORT_SYMBOL(sysctl_ms_jiffies);
3024EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003025EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026EXPORT_SYMBOL(unregister_sysctl_table);