blob: b2970d56fb7678d6493e44c766db536f691656b7 [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>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/uaccess.h>
54#include <asm/processor.h>
55
Andi Kleen29cbc782006-09-30 01:47:55 +020056#ifdef CONFIG_X86
57#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010058#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010059#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020060#endif
61
Eric W. Biederman7058cb02007-10-18 03:05:58 -070062static int deprecated_sysctl_warning(struct __sysctl_args *args);
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#if defined(CONFIG_SYSCTL)
65
66/* External variables not in a header file. */
67extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070068extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int sysctl_overcommit_memory;
70extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070071extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070072extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080073extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070076extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int pid_max;
79extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080081extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080082extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020083extern int compat_log;
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 Mundtdd8632a2009-01-08 12:04:47 +000086#ifndef CONFIG_MMU
87extern int sysctl_nr_trim_pages;
88#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070089#ifdef CONFIG_RCU_TORTURE_TEST
90extern int rcutorture_runnable;
91#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070093/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080094#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020096static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097#endif
98
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700100static int __maybe_unused one = 1;
101static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800102static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103static int one_hundred = 100;
104
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700105/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
106static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
109static int maxolduid = 65535;
110static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800111static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113static int ngroups_max = NGROUPS_MAX;
114
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200115#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116extern char modprobe_path[];
117#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#ifdef CONFIG_CHR_DEV_SG
119extern int sg_big_buff;
120#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
David S. Miller72c57ed2008-09-11 23:29:54 -0700122#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700123#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#endif
125
David S. Miller08714202008-11-16 23:49:24 -0800126#ifdef CONFIG_SPARC64
127extern int sysctl_tsb_ratio;
128#endif
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#ifdef __hppa__
131extern int pwrsw_enabled;
132extern int unaligned_enabled;
133#endif
134
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800135#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#ifdef CONFIG_MATHEMU
137extern int sysctl_ieee_emulation_warnings;
138#endif
139extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700140extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#endif
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#ifdef CONFIG_BSD_PROCESS_ACCT
144extern int acct_parm[];
145#endif
146
Jes Sorensend2b176e2006-02-28 09:42:23 -0800147#ifdef CONFIG_IA64
148extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800149extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800150#endif
151
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700152#ifdef CONFIG_RT_MUTEXES
153extern int max_lock_depth;
154#endif
155
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700156#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700157static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700158 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700159static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800160 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700161#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700162
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700163static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100164static struct ctl_table_root sysctl_table_root;
165static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100166 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100167 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400168 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100169 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400170 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100171};
172static struct ctl_table_root sysctl_table_root = {
173 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400174 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100175};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700177static struct ctl_table kern_table[];
178static struct ctl_table vm_table[];
179static struct ctl_table fs_table[];
180static struct ctl_table debug_table[];
181static struct ctl_table dev_table[];
182extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700183#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700184extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400185#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800186#ifdef CONFIG_EPOLL
187extern struct ctl_table epoll_table[];
188#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
191int sysctl_legacy_va_layout;
192#endif
193
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700194extern int prove_locking;
195extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/* The default sysctl tables: */
198
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700199static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 {
201 .ctl_name = CTL_KERN,
202 .procname = "kernel",
203 .mode = 0555,
204 .child = kern_table,
205 },
206 {
207 .ctl_name = CTL_VM,
208 .procname = "vm",
209 .mode = 0555,
210 .child = vm_table,
211 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 .ctl_name = CTL_FS,
214 .procname = "fs",
215 .mode = 0555,
216 .child = fs_table,
217 },
218 {
219 .ctl_name = CTL_DEBUG,
220 .procname = "debug",
221 .mode = 0555,
222 .child = debug_table,
223 },
224 {
225 .ctl_name = CTL_DEV,
226 .procname = "dev",
227 .mode = 0555,
228 .child = dev_table,
229 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700230/*
231 * NOTE: do not add new entries to this table unless you have read
232 * Documentation/sysctl/ctl_unnumbered.txt
233 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 { .ctl_name = 0 }
235};
236
Ingo Molnar77e54a12007-07-09 18:52:00 +0200237#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100238static int min_sched_granularity_ns = 100000; /* 100 usecs */
239static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
240static int min_wakeup_granularity_ns; /* 0 usecs */
241static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200242#endif
243
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700244static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200245#ifdef CONFIG_SCHED_DEBUG
246 {
247 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100248 .procname = "sched_min_granularity_ns",
249 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200250 .maxlen = sizeof(unsigned int),
251 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100252 .proc_handler = &sched_nr_latency_handler,
253 .strategy = &sysctl_intvec,
254 .extra1 = &min_sched_granularity_ns,
255 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200256 },
257 {
258 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200259 .procname = "sched_latency_ns",
260 .data = &sysctl_sched_latency,
261 .maxlen = sizeof(unsigned int),
262 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100263 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200264 .strategy = &sysctl_intvec,
265 .extra1 = &min_sched_granularity_ns,
266 .extra2 = &max_sched_granularity_ns,
267 },
268 {
269 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200270 .procname = "sched_wakeup_granularity_ns",
271 .data = &sysctl_sched_wakeup_granularity,
272 .maxlen = sizeof(unsigned int),
273 .mode = 0644,
274 .proc_handler = &proc_dointvec_minmax,
275 .strategy = &sysctl_intvec,
276 .extra1 = &min_wakeup_granularity_ns,
277 .extra2 = &max_wakeup_granularity_ns,
278 },
279 {
280 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200281 .procname = "sched_shares_ratelimit",
282 .data = &sysctl_sched_shares_ratelimit,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
285 .proc_handler = &proc_dointvec,
286 },
287 {
288 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200289 .procname = "sched_shares_thresh",
290 .data = &sysctl_sched_shares_thresh,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
293 .proc_handler = &proc_dointvec_minmax,
294 .strategy = &sysctl_intvec,
295 .extra1 = &zero,
296 },
297 {
298 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299 .procname = "sched_child_runs_first",
300 .data = &sysctl_sched_child_runs_first,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
303 .proc_handler = &proc_dointvec,
304 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200305 {
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_features",
308 .data = &sysctl_sched_features,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
311 .proc_handler = &proc_dointvec,
312 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200313 {
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_migration_cost",
316 .data = &sysctl_sched_migration_cost,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
319 .proc_handler = &proc_dointvec,
320 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100321 {
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_nr_migrate",
324 .data = &sysctl_sched_nr_migrate,
325 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
328 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200329#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200330 {
331 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100332 .procname = "sched_rt_period_us",
333 .data = &sysctl_sched_rt_period,
334 .maxlen = sizeof(unsigned int),
335 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200336 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100337 },
338 {
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "sched_rt_runtime_us",
341 .data = &sysctl_sched_rt_runtime,
342 .maxlen = sizeof(int),
343 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200344 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100345 },
346 {
347 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200348 .procname = "sched_compat_yield",
349 .data = &sysctl_sched_compat_yield,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = &proc_dointvec,
353 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700354#ifdef CONFIG_PROVE_LOCKING
355 {
356 .ctl_name = CTL_UNNUMBERED,
357 .procname = "prove_locking",
358 .data = &prove_locking,
359 .maxlen = sizeof(int),
360 .mode = 0644,
361 .proc_handler = &proc_dointvec,
362 },
363#endif
364#ifdef CONFIG_LOCK_STAT
365 {
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "lock_stat",
368 .data = &lock_stat,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &proc_dointvec,
372 },
373#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 .ctl_name = KERN_PANIC,
376 .procname = "panic",
377 .data = &panic_timeout,
378 .maxlen = sizeof(int),
379 .mode = 0644,
380 .proc_handler = &proc_dointvec,
381 },
382 {
383 .ctl_name = KERN_CORE_USES_PID,
384 .procname = "core_uses_pid",
385 .data = &core_uses_pid,
386 .maxlen = sizeof(int),
387 .mode = 0644,
388 .proc_handler = &proc_dointvec,
389 },
390 {
391 .ctl_name = KERN_CORE_PATTERN,
392 .procname = "core_pattern",
393 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700394 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 .mode = 0644,
396 .proc_handler = &proc_dostring,
397 .strategy = &sysctl_string,
398 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800399#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700402 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800403 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700404 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800406#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100407#ifdef CONFIG_LATENCYTOP
408 {
409 .procname = "latencytop",
410 .data = &latencytop_enabled,
411 .maxlen = sizeof(int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
414 },
415#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#ifdef CONFIG_BLK_DEV_INITRD
417 {
418 .ctl_name = KERN_REALROOTDEV,
419 .procname = "real-root-dev",
420 .data = &real_root_dev,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = &proc_dointvec,
424 },
425#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700426 {
427 .ctl_name = CTL_UNNUMBERED,
428 .procname = "print-fatal-signals",
429 .data = &print_fatal_signals,
430 .maxlen = sizeof(int),
431 .mode = 0644,
432 .proc_handler = &proc_dointvec,
433 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700434#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 {
436 .ctl_name = KERN_SPARC_REBOOT,
437 .procname = "reboot-cmd",
438 .data = reboot_command,
439 .maxlen = 256,
440 .mode = 0644,
441 .proc_handler = &proc_dostring,
442 .strategy = &sysctl_string,
443 },
444 {
445 .ctl_name = KERN_SPARC_STOP_A,
446 .procname = "stop-a",
447 .data = &stop_a_enabled,
448 .maxlen = sizeof (int),
449 .mode = 0644,
450 .proc_handler = &proc_dointvec,
451 },
452 {
453 .ctl_name = KERN_SPARC_SCONS_PWROFF,
454 .procname = "scons-poweroff",
455 .data = &scons_pwroff,
456 .maxlen = sizeof (int),
457 .mode = 0644,
458 .proc_handler = &proc_dointvec,
459 },
460#endif
David S. Miller08714202008-11-16 23:49:24 -0800461#ifdef CONFIG_SPARC64
462 {
463 .ctl_name = CTL_UNNUMBERED,
464 .procname = "tsb-ratio",
465 .data = &sysctl_tsb_ratio,
466 .maxlen = sizeof (int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
469 },
470#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#ifdef __hppa__
472 {
473 .ctl_name = KERN_HPPA_PWRSW,
474 .procname = "soft-power",
475 .data = &pwrsw_enabled,
476 .maxlen = sizeof (int),
477 .mode = 0644,
478 .proc_handler = &proc_dointvec,
479 },
480 {
481 .ctl_name = KERN_HPPA_UNALIGNED,
482 .procname = "unaligned-trap",
483 .data = &unaligned_enabled,
484 .maxlen = sizeof (int),
485 .mode = 0644,
486 .proc_handler = &proc_dointvec,
487 },
488#endif
489 {
490 .ctl_name = KERN_CTLALTDEL,
491 .procname = "ctrl-alt-del",
492 .data = &C_A_D,
493 .maxlen = sizeof(int),
494 .mode = 0644,
495 .proc_handler = &proc_dointvec,
496 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400497#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200498 {
499 .ctl_name = CTL_UNNUMBERED,
500 .procname = "ftrace_enabled",
501 .data = &ftrace_enabled,
502 .maxlen = sizeof(int),
503 .mode = 0644,
504 .proc_handler = &ftrace_enable_sysctl,
505 },
506#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500507#ifdef CONFIG_STACK_TRACER
508 {
509 .ctl_name = CTL_UNNUMBERED,
510 .procname = "stack_tracer_enabled",
511 .data = &stack_tracer_enabled,
512 .maxlen = sizeof(int),
513 .mode = 0644,
514 .proc_handler = &stack_trace_sysctl,
515 },
516#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400517#ifdef CONFIG_TRACING
518 {
519 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100520 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400521 .data = &ftrace_dump_on_oops,
522 .maxlen = sizeof(int),
523 .mode = 0644,
524 .proc_handler = &proc_dointvec,
525 },
526#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200527#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 {
529 .ctl_name = KERN_MODPROBE,
530 .procname = "modprobe",
531 .data = &modprobe_path,
532 .maxlen = KMOD_PATH_LEN,
533 .mode = 0644,
534 .proc_handler = &proc_dostring,
535 .strategy = &sysctl_string,
536 },
537#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700538#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 {
540 .ctl_name = KERN_HOTPLUG,
541 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100542 .data = &uevent_helper,
543 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .mode = 0644,
545 .proc_handler = &proc_dostring,
546 .strategy = &sysctl_string,
547 },
548#endif
549#ifdef CONFIG_CHR_DEV_SG
550 {
551 .ctl_name = KERN_SG_BIG_BUFF,
552 .procname = "sg-big-buff",
553 .data = &sg_big_buff,
554 .maxlen = sizeof (int),
555 .mode = 0444,
556 .proc_handler = &proc_dointvec,
557 },
558#endif
559#ifdef CONFIG_BSD_PROCESS_ACCT
560 {
561 .ctl_name = KERN_ACCT,
562 .procname = "acct",
563 .data = &acct_parm,
564 .maxlen = 3*sizeof(int),
565 .mode = 0644,
566 .proc_handler = &proc_dointvec,
567 },
568#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#ifdef CONFIG_MAGIC_SYSRQ
570 {
571 .ctl_name = KERN_SYSRQ,
572 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800573 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .maxlen = sizeof (int),
575 .mode = 0644,
576 .proc_handler = &proc_dointvec,
577 },
578#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700579#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700582 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 .maxlen = sizeof (int),
584 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700585 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700587#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 {
589 .ctl_name = KERN_MAX_THREADS,
590 .procname = "threads-max",
591 .data = &max_threads,
592 .maxlen = sizeof(int),
593 .mode = 0644,
594 .proc_handler = &proc_dointvec,
595 },
596 {
597 .ctl_name = KERN_RANDOM,
598 .procname = "random",
599 .mode = 0555,
600 .child = random_table,
601 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 {
603 .ctl_name = KERN_OVERFLOWUID,
604 .procname = "overflowuid",
605 .data = &overflowuid,
606 .maxlen = sizeof(int),
607 .mode = 0644,
608 .proc_handler = &proc_dointvec_minmax,
609 .strategy = &sysctl_intvec,
610 .extra1 = &minolduid,
611 .extra2 = &maxolduid,
612 },
613 {
614 .ctl_name = KERN_OVERFLOWGID,
615 .procname = "overflowgid",
616 .data = &overflowgid,
617 .maxlen = sizeof(int),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec_minmax,
620 .strategy = &sysctl_intvec,
621 .extra1 = &minolduid,
622 .extra2 = &maxolduid,
623 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800624#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#ifdef CONFIG_MATHEMU
626 {
627 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
628 .procname = "ieee_emulation_warnings",
629 .data = &sysctl_ieee_emulation_warnings,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec,
633 },
634#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 {
636 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
637 .procname = "userprocess_debug",
638 .data = &sysctl_userprocess_debug,
639 .maxlen = sizeof(int),
640 .mode = 0644,
641 .proc_handler = &proc_dointvec,
642 },
643#endif
644 {
645 .ctl_name = KERN_PIDMAX,
646 .procname = "pid_max",
647 .data = &pid_max,
648 .maxlen = sizeof (int),
649 .mode = 0644,
650 .proc_handler = &proc_dointvec_minmax,
651 .strategy = sysctl_intvec,
652 .extra1 = &pid_max_min,
653 .extra2 = &pid_max_max,
654 },
655 {
656 .ctl_name = KERN_PANIC_ON_OOPS,
657 .procname = "panic_on_oops",
658 .data = &panic_on_oops,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = &proc_dointvec,
662 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800663#if defined CONFIG_PRINTK
664 {
665 .ctl_name = KERN_PRINTK,
666 .procname = "printk",
667 .data = &console_loglevel,
668 .maxlen = 4*sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
671 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 {
673 .ctl_name = KERN_PRINTK_RATELIMIT,
674 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700675 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .maxlen = sizeof(int),
677 .mode = 0644,
678 .proc_handler = &proc_dointvec_jiffies,
679 .strategy = &sysctl_jiffies,
680 },
681 {
682 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
683 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700684 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .maxlen = sizeof(int),
686 .mode = 0644,
687 .proc_handler = &proc_dointvec,
688 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800689#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 {
691 .ctl_name = KERN_NGROUPS_MAX,
692 .procname = "ngroups_max",
693 .data = &ngroups_max,
694 .maxlen = sizeof (int),
695 .mode = 0444,
696 .proc_handler = &proc_dointvec,
697 },
698#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
699 {
700 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
701 .procname = "unknown_nmi_panic",
702 .data = &unknown_nmi_panic,
703 .maxlen = sizeof (int),
704 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200705 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 },
Don Zickus407984f2006-09-26 10:52:27 +0200707 {
Don Zickus407984f2006-09-26 10:52:27 +0200708 .procname = "nmi_watchdog",
709 .data = &nmi_watchdog_enabled,
710 .maxlen = sizeof (int),
711 .mode = 0644,
712 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 },
714#endif
715#if defined(CONFIG_X86)
716 {
Don Zickus8da5add2006-09-26 10:52:27 +0200717 .ctl_name = KERN_PANIC_ON_NMI,
718 .procname = "panic_on_unrecovered_nmi",
719 .data = &panic_on_unrecovered_nmi,
720 .maxlen = sizeof(int),
721 .mode = 0644,
722 .proc_handler = &proc_dointvec,
723 },
724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .ctl_name = KERN_BOOTLOADER_TYPE,
726 .procname = "bootloader_type",
727 .data = &bootloader_type,
728 .maxlen = sizeof (int),
729 .mode = 0444,
730 .proc_handler = &proc_dointvec,
731 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100732 {
733 .ctl_name = CTL_UNNUMBERED,
734 .procname = "kstack_depth_to_print",
735 .data = &kstack_depth_to_print,
736 .maxlen = sizeof(int),
737 .mode = 0644,
738 .proc_handler = &proc_dointvec,
739 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100740 {
741 .ctl_name = CTL_UNNUMBERED,
742 .procname = "io_delay_type",
743 .data = &io_delay_type,
744 .maxlen = sizeof(int),
745 .mode = 0644,
746 .proc_handler = &proc_dointvec,
747 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800749#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 {
751 .ctl_name = KERN_RANDOMIZE,
752 .procname = "randomize_va_space",
753 .data = &randomize_va_space,
754 .maxlen = sizeof(int),
755 .mode = 0644,
756 .proc_handler = &proc_dointvec,
757 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800758#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800759#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700760 {
761 .ctl_name = KERN_SPIN_RETRY,
762 .procname = "spin_retry",
763 .data = &spin_retry,
764 .maxlen = sizeof (int),
765 .mode = 0644,
766 .proc_handler = &proc_dointvec,
767 },
768#endif
Len Brown673d5b42007-07-28 03:33:16 -0400769#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800770 {
Pavel Machekc255d842006-02-20 18:27:58 -0800771 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700772 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800773 .maxlen = sizeof (unsigned long),
774 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800775 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800776 },
777#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800778#ifdef CONFIG_IA64
779 {
780 .ctl_name = KERN_IA64_UNALIGNED,
781 .procname = "ignore-unaligned-usertrap",
782 .data = &no_unaligned_warning,
783 .maxlen = sizeof (int),
784 .mode = 0644,
785 .proc_handler = &proc_dointvec,
786 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800787 {
788 .ctl_name = CTL_UNNUMBERED,
789 .procname = "unaligned-dump-stack",
790 .data = &unaligned_dump_stack,
791 .maxlen = sizeof (int),
792 .mode = 0644,
793 .proc_handler = &proc_dointvec,
794 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800795#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700796#ifdef CONFIG_DETECT_SOFTLOCKUP
797 {
798 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200799 .procname = "softlockup_panic",
800 .data = &softlockup_panic,
801 .maxlen = sizeof(int),
802 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700803 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200804 .strategy = &sysctl_intvec,
805 .extra1 = &zero,
806 .extra2 = &one,
807 },
808 {
809 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700810 .procname = "softlockup_thresh",
811 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200812 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700813 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800814 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700815 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200816 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700817 .extra2 = &sixty,
818 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800819#endif
820#ifdef CONFIG_DETECT_HUNG_TASK
821 {
822 .ctl_name = CTL_UNNUMBERED,
823 .procname = "hung_task_panic",
824 .data = &sysctl_hung_task_panic,
825 .maxlen = sizeof(int),
826 .mode = 0644,
827 .proc_handler = &proc_dointvec_minmax,
828 .strategy = &sysctl_intvec,
829 .extra1 = &zero,
830 .extra2 = &one,
831 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100832 {
833 .ctl_name = CTL_UNNUMBERED,
834 .procname = "hung_task_check_count",
835 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100836 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100837 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100838 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100839 .strategy = &sysctl_intvec,
840 },
841 {
842 .ctl_name = CTL_UNNUMBERED,
843 .procname = "hung_task_timeout_secs",
844 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100845 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100846 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800847 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100848 .strategy = &sysctl_intvec,
849 },
850 {
851 .ctl_name = CTL_UNNUMBERED,
852 .procname = "hung_task_warnings",
853 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100854 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100855 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100856 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100857 .strategy = &sysctl_intvec,
858 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700859#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200860#ifdef CONFIG_COMPAT
861 {
862 .ctl_name = KERN_COMPAT_LOG,
863 .procname = "compat-log",
864 .data = &compat_log,
865 .maxlen = sizeof (int),
866 .mode = 0644,
867 .proc_handler = &proc_dointvec,
868 },
869#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700870#ifdef CONFIG_RT_MUTEXES
871 {
872 .ctl_name = KERN_MAX_LOCK_DEPTH,
873 .procname = "max_lock_depth",
874 .data = &max_lock_depth,
875 .maxlen = sizeof(int),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec,
878 },
879#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700880 {
881 .ctl_name = CTL_UNNUMBERED,
882 .procname = "poweroff_cmd",
883 .data = &poweroff_cmd,
884 .maxlen = POWEROFF_CMD_PATH_LEN,
885 .mode = 0644,
886 .proc_handler = &proc_dostring,
887 .strategy = &sysctl_string,
888 },
David Howells0b77f5b2008-04-29 01:01:32 -0700889#ifdef CONFIG_KEYS
890 {
891 .ctl_name = CTL_UNNUMBERED,
892 .procname = "keys",
893 .mode = 0555,
894 .child = key_sysctls,
895 },
896#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700897#ifdef CONFIG_RCU_TORTURE_TEST
898 {
899 .ctl_name = CTL_UNNUMBERED,
900 .procname = "rcutorture_runnable",
901 .data = &rcutorture_runnable,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = &proc_dointvec,
905 },
906#endif
David Howells12e22c52009-04-03 16:42:35 +0100907#ifdef CONFIG_SLOW_WORK
908 {
909 .ctl_name = CTL_UNNUMBERED,
910 .procname = "slow-work",
911 .mode = 0555,
912 .child = slow_work_sysctls,
913 },
914#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700915/*
916 * NOTE: do not add new entries to this table unless you have read
917 * Documentation/sysctl/ctl_unnumbered.txt
918 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 { .ctl_name = 0 }
920};
921
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700922static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 {
924 .ctl_name = VM_OVERCOMMIT_MEMORY,
925 .procname = "overcommit_memory",
926 .data = &sysctl_overcommit_memory,
927 .maxlen = sizeof(sysctl_overcommit_memory),
928 .mode = 0644,
929 .proc_handler = &proc_dointvec,
930 },
931 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700932 .ctl_name = VM_PANIC_ON_OOM,
933 .procname = "panic_on_oom",
934 .data = &sysctl_panic_on_oom,
935 .maxlen = sizeof(sysctl_panic_on_oom),
936 .mode = 0644,
937 .proc_handler = &proc_dointvec,
938 },
939 {
David Rientjesfe071d72007-10-16 23:25:56 -0700940 .ctl_name = CTL_UNNUMBERED,
941 .procname = "oom_kill_allocating_task",
942 .data = &sysctl_oom_kill_allocating_task,
943 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
944 .mode = 0644,
945 .proc_handler = &proc_dointvec,
946 },
947 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800948 .ctl_name = CTL_UNNUMBERED,
949 .procname = "oom_dump_tasks",
950 .data = &sysctl_oom_dump_tasks,
951 .maxlen = sizeof(sysctl_oom_dump_tasks),
952 .mode = 0644,
953 .proc_handler = &proc_dointvec,
954 },
955 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 .ctl_name = VM_OVERCOMMIT_RATIO,
957 .procname = "overcommit_ratio",
958 .data = &sysctl_overcommit_ratio,
959 .maxlen = sizeof(sysctl_overcommit_ratio),
960 .mode = 0644,
961 .proc_handler = &proc_dointvec,
962 },
963 {
964 .ctl_name = VM_PAGE_CLUSTER,
965 .procname = "page-cluster",
966 .data = &page_cluster,
967 .maxlen = sizeof(int),
968 .mode = 0644,
969 .proc_handler = &proc_dointvec,
970 },
971 {
972 .ctl_name = VM_DIRTY_BACKGROUND,
973 .procname = "dirty_background_ratio",
974 .data = &dirty_background_ratio,
975 .maxlen = sizeof(dirty_background_ratio),
976 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800977 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 .strategy = &sysctl_intvec,
979 .extra1 = &zero,
980 .extra2 = &one_hundred,
981 },
982 {
David Rientjes2da02992009-01-06 14:39:31 -0800983 .ctl_name = CTL_UNNUMBERED,
984 .procname = "dirty_background_bytes",
985 .data = &dirty_background_bytes,
986 .maxlen = sizeof(dirty_background_bytes),
987 .mode = 0644,
988 .proc_handler = &dirty_background_bytes_handler,
989 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800990 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -0800991 },
992 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 .ctl_name = VM_DIRTY_RATIO,
994 .procname = "dirty_ratio",
995 .data = &vm_dirty_ratio,
996 .maxlen = sizeof(vm_dirty_ratio),
997 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700998 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 .strategy = &sysctl_intvec,
1000 .extra1 = &zero,
1001 .extra2 = &one_hundred,
1002 },
1003 {
David Rientjes2da02992009-01-06 14:39:31 -08001004 .ctl_name = CTL_UNNUMBERED,
1005 .procname = "dirty_bytes",
1006 .data = &vm_dirty_bytes,
1007 .maxlen = sizeof(vm_dirty_bytes),
1008 .mode = 0644,
1009 .proc_handler = &dirty_bytes_handler,
1010 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001011 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001012 },
1013 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001015 .data = &dirty_writeback_interval,
1016 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 .mode = 0644,
1018 .proc_handler = &dirty_writeback_centisecs_handler,
1019 },
1020 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001022 .data = &dirty_expire_interval,
1023 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001025 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 },
1027 {
1028 .ctl_name = VM_NR_PDFLUSH_THREADS,
1029 .procname = "nr_pdflush_threads",
1030 .data = &nr_pdflush_threads,
1031 .maxlen = sizeof nr_pdflush_threads,
1032 .mode = 0444 /* read-only*/,
1033 .proc_handler = &proc_dointvec,
1034 },
1035 {
1036 .ctl_name = VM_SWAPPINESS,
1037 .procname = "swappiness",
1038 .data = &vm_swappiness,
1039 .maxlen = sizeof(vm_swappiness),
1040 .mode = 0644,
1041 .proc_handler = &proc_dointvec_minmax,
1042 .strategy = &sysctl_intvec,
1043 .extra1 = &zero,
1044 .extra2 = &one_hundred,
1045 },
1046#ifdef CONFIG_HUGETLB_PAGE
1047 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001049 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 .maxlen = sizeof(unsigned long),
1051 .mode = 0644,
1052 .proc_handler = &hugetlb_sysctl_handler,
1053 .extra1 = (void *)&hugetlb_zero,
1054 .extra2 = (void *)&hugetlb_infinity,
1055 },
1056 {
1057 .ctl_name = VM_HUGETLB_GROUP,
1058 .procname = "hugetlb_shm_group",
1059 .data = &sysctl_hugetlb_shm_group,
1060 .maxlen = sizeof(gid_t),
1061 .mode = 0644,
1062 .proc_handler = &proc_dointvec,
1063 },
Mel Gorman396faf02007-07-17 04:03:13 -07001064 {
1065 .ctl_name = CTL_UNNUMBERED,
1066 .procname = "hugepages_treat_as_movable",
1067 .data = &hugepages_treat_as_movable,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
1070 .proc_handler = &hugetlb_treat_movable_handler,
1071 },
Adam Litke54f9f802007-10-16 01:26:20 -07001072 {
1073 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001074 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001075 .data = NULL,
1076 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001077 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001078 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001079 .extra1 = (void *)&hugetlb_zero,
1080 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001081 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082#endif
1083 {
1084 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1085 .procname = "lowmem_reserve_ratio",
1086 .data = &sysctl_lowmem_reserve_ratio,
1087 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1088 .mode = 0644,
1089 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1090 .strategy = &sysctl_intvec,
1091 },
1092 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001093 .ctl_name = VM_DROP_PAGECACHE,
1094 .procname = "drop_caches",
1095 .data = &sysctl_drop_caches,
1096 .maxlen = sizeof(int),
1097 .mode = 0644,
1098 .proc_handler = drop_caches_sysctl_handler,
1099 .strategy = &sysctl_intvec,
1100 },
1101 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 .ctl_name = VM_MIN_FREE_KBYTES,
1103 .procname = "min_free_kbytes",
1104 .data = &min_free_kbytes,
1105 .maxlen = sizeof(min_free_kbytes),
1106 .mode = 0644,
1107 .proc_handler = &min_free_kbytes_sysctl_handler,
1108 .strategy = &sysctl_intvec,
1109 .extra1 = &zero,
1110 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001111 {
1112 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1113 .procname = "percpu_pagelist_fraction",
1114 .data = &percpu_pagelist_fraction,
1115 .maxlen = sizeof(percpu_pagelist_fraction),
1116 .mode = 0644,
1117 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1118 .strategy = &sysctl_intvec,
1119 .extra1 = &min_percpu_pagelist_fract,
1120 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121#ifdef CONFIG_MMU
1122 {
1123 .ctl_name = VM_MAX_MAP_COUNT,
1124 .procname = "max_map_count",
1125 .data = &sysctl_max_map_count,
1126 .maxlen = sizeof(sysctl_max_map_count),
1127 .mode = 0644,
1128 .proc_handler = &proc_dointvec
1129 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001130#else
1131 {
1132 .ctl_name = CTL_UNNUMBERED,
1133 .procname = "nr_trim_pages",
1134 .data = &sysctl_nr_trim_pages,
1135 .maxlen = sizeof(sysctl_nr_trim_pages),
1136 .mode = 0644,
1137 .proc_handler = &proc_dointvec_minmax,
1138 .strategy = &sysctl_intvec,
1139 .extra1 = &zero,
1140 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141#endif
1142 {
1143 .ctl_name = VM_LAPTOP_MODE,
1144 .procname = "laptop_mode",
1145 .data = &laptop_mode,
1146 .maxlen = sizeof(laptop_mode),
1147 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001148 .proc_handler = &proc_dointvec_jiffies,
1149 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 },
1151 {
1152 .ctl_name = VM_BLOCK_DUMP,
1153 .procname = "block_dump",
1154 .data = &block_dump,
1155 .maxlen = sizeof(block_dump),
1156 .mode = 0644,
1157 .proc_handler = &proc_dointvec,
1158 .strategy = &sysctl_intvec,
1159 .extra1 = &zero,
1160 },
1161 {
1162 .ctl_name = VM_VFS_CACHE_PRESSURE,
1163 .procname = "vfs_cache_pressure",
1164 .data = &sysctl_vfs_cache_pressure,
1165 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1166 .mode = 0644,
1167 .proc_handler = &proc_dointvec,
1168 .strategy = &sysctl_intvec,
1169 .extra1 = &zero,
1170 },
1171#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1172 {
1173 .ctl_name = VM_LEGACY_VA_LAYOUT,
1174 .procname = "legacy_va_layout",
1175 .data = &sysctl_legacy_va_layout,
1176 .maxlen = sizeof(sysctl_legacy_va_layout),
1177 .mode = 0644,
1178 .proc_handler = &proc_dointvec,
1179 .strategy = &sysctl_intvec,
1180 .extra1 = &zero,
1181 },
1182#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001183#ifdef CONFIG_NUMA
1184 {
1185 .ctl_name = VM_ZONE_RECLAIM_MODE,
1186 .procname = "zone_reclaim_mode",
1187 .data = &zone_reclaim_mode,
1188 .maxlen = sizeof(zone_reclaim_mode),
1189 .mode = 0644,
1190 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001191 .strategy = &sysctl_intvec,
1192 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001193 },
Christoph Lameter96146342006-07-03 00:24:13 -07001194 {
1195 .ctl_name = VM_MIN_UNMAPPED,
1196 .procname = "min_unmapped_ratio",
1197 .data = &sysctl_min_unmapped_ratio,
1198 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1199 .mode = 0644,
1200 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1201 .strategy = &sysctl_intvec,
1202 .extra1 = &zero,
1203 .extra2 = &one_hundred,
1204 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001205 {
1206 .ctl_name = VM_MIN_SLAB,
1207 .procname = "min_slab_ratio",
1208 .data = &sysctl_min_slab_ratio,
1209 .maxlen = sizeof(sysctl_min_slab_ratio),
1210 .mode = 0644,
1211 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1212 .strategy = &sysctl_intvec,
1213 .extra1 = &zero,
1214 .extra2 = &one_hundred,
1215 },
Christoph Lameter17436602006-01-18 17:42:32 -08001216#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001217#ifdef CONFIG_SMP
1218 {
1219 .ctl_name = CTL_UNNUMBERED,
1220 .procname = "stat_interval",
1221 .data = &sysctl_stat_interval,
1222 .maxlen = sizeof(sysctl_stat_interval),
1223 .mode = 0644,
1224 .proc_handler = &proc_dointvec_jiffies,
1225 .strategy = &sysctl_jiffies,
1226 },
1227#endif
Eric Parised032182007-06-28 15:55:21 -04001228#ifdef CONFIG_SECURITY
1229 {
1230 .ctl_name = CTL_UNNUMBERED,
1231 .procname = "mmap_min_addr",
1232 .data = &mmap_min_addr,
1233 .maxlen = sizeof(unsigned long),
1234 .mode = 0644,
1235 .proc_handler = &proc_doulongvec_minmax,
1236 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001237#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001238#ifdef CONFIG_NUMA
1239 {
1240 .ctl_name = CTL_UNNUMBERED,
1241 .procname = "numa_zonelist_order",
1242 .data = &numa_zonelist_order,
1243 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1244 .mode = 0644,
1245 .proc_handler = &numa_zonelist_order_handler,
1246 .strategy = &sysctl_string,
1247 },
1248#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001249#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001250 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001251 {
1252 .ctl_name = VM_VDSO_ENABLED,
1253 .procname = "vdso_enabled",
1254 .data = &vdso_enabled,
1255 .maxlen = sizeof(vdso_enabled),
1256 .mode = 0644,
1257 .proc_handler = &proc_dointvec,
1258 .strategy = &sysctl_intvec,
1259 .extra1 = &zero,
1260 },
1261#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001262#ifdef CONFIG_HIGHMEM
1263 {
1264 .ctl_name = CTL_UNNUMBERED,
1265 .procname = "highmem_is_dirtyable",
1266 .data = &vm_highmem_is_dirtyable,
1267 .maxlen = sizeof(vm_highmem_is_dirtyable),
1268 .mode = 0644,
1269 .proc_handler = &proc_dointvec_minmax,
1270 .strategy = &sysctl_intvec,
1271 .extra1 = &zero,
1272 .extra2 = &one,
1273 },
1274#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001275#ifdef CONFIG_UNEVICTABLE_LRU
1276 {
1277 .ctl_name = CTL_UNNUMBERED,
1278 .procname = "scan_unevictable_pages",
1279 .data = &scan_unevictable_pages,
1280 .maxlen = sizeof(scan_unevictable_pages),
1281 .mode = 0644,
1282 .proc_handler = &scan_unevictable_handler,
1283 },
1284#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001285/*
1286 * NOTE: do not add new entries to this table unless you have read
1287 * Documentation/sysctl/ctl_unnumbered.txt
1288 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 { .ctl_name = 0 }
1290};
1291
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001292#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001293static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001294 { .ctl_name = 0 }
1295};
1296#endif
1297
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001298static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 {
1300 .ctl_name = FS_NRINODE,
1301 .procname = "inode-nr",
1302 .data = &inodes_stat,
1303 .maxlen = 2*sizeof(int),
1304 .mode = 0444,
1305 .proc_handler = &proc_dointvec,
1306 },
1307 {
1308 .ctl_name = FS_STATINODE,
1309 .procname = "inode-state",
1310 .data = &inodes_stat,
1311 .maxlen = 7*sizeof(int),
1312 .mode = 0444,
1313 .proc_handler = &proc_dointvec,
1314 },
1315 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 .procname = "file-nr",
1317 .data = &files_stat,
1318 .maxlen = 3*sizeof(int),
1319 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001320 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 },
1322 {
1323 .ctl_name = FS_MAXFILE,
1324 .procname = "file-max",
1325 .data = &files_stat.max_files,
1326 .maxlen = sizeof(int),
1327 .mode = 0644,
1328 .proc_handler = &proc_dointvec,
1329 },
1330 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001331 .ctl_name = CTL_UNNUMBERED,
1332 .procname = "nr_open",
1333 .data = &sysctl_nr_open,
1334 .maxlen = sizeof(int),
1335 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001336 .proc_handler = &proc_dointvec_minmax,
1337 .extra1 = &sysctl_nr_open_min,
1338 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001339 },
1340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .ctl_name = FS_DENTRY,
1342 .procname = "dentry-state",
1343 .data = &dentry_stat,
1344 .maxlen = 6*sizeof(int),
1345 .mode = 0444,
1346 .proc_handler = &proc_dointvec,
1347 },
1348 {
1349 .ctl_name = FS_OVERFLOWUID,
1350 .procname = "overflowuid",
1351 .data = &fs_overflowuid,
1352 .maxlen = sizeof(int),
1353 .mode = 0644,
1354 .proc_handler = &proc_dointvec_minmax,
1355 .strategy = &sysctl_intvec,
1356 .extra1 = &minolduid,
1357 .extra2 = &maxolduid,
1358 },
1359 {
1360 .ctl_name = FS_OVERFLOWGID,
1361 .procname = "overflowgid",
1362 .data = &fs_overflowgid,
1363 .maxlen = sizeof(int),
1364 .mode = 0644,
1365 .proc_handler = &proc_dointvec_minmax,
1366 .strategy = &sysctl_intvec,
1367 .extra1 = &minolduid,
1368 .extra2 = &maxolduid,
1369 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001370#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 {
1372 .ctl_name = FS_LEASES,
1373 .procname = "leases-enable",
1374 .data = &leases_enable,
1375 .maxlen = sizeof(int),
1376 .mode = 0644,
1377 .proc_handler = &proc_dointvec,
1378 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001379#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380#ifdef CONFIG_DNOTIFY
1381 {
1382 .ctl_name = FS_DIR_NOTIFY,
1383 .procname = "dir-notify-enable",
1384 .data = &dir_notify_enable,
1385 .maxlen = sizeof(int),
1386 .mode = 0644,
1387 .proc_handler = &proc_dointvec,
1388 },
1389#endif
1390#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001391#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 {
1393 .ctl_name = FS_LEASE_TIME,
1394 .procname = "lease-break-time",
1395 .data = &lease_break_time,
1396 .maxlen = sizeof(int),
1397 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001398 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001400#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001401#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .procname = "aio-nr",
1404 .data = &aio_nr,
1405 .maxlen = sizeof(aio_nr),
1406 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001407 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 },
1409 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 .procname = "aio-max-nr",
1411 .data = &aio_max_nr,
1412 .maxlen = sizeof(aio_max_nr),
1413 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001414 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001416#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001417#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001418 {
1419 .ctl_name = FS_INOTIFY,
1420 .procname = "inotify",
1421 .mode = 0555,
1422 .child = inotify_table,
1423 },
1424#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001425#ifdef CONFIG_EPOLL
1426 {
1427 .procname = "epoll",
1428 .mode = 0555,
1429 .child = epoll_table,
1430 },
1431#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001433 {
1434 .ctl_name = KERN_SETUID_DUMPABLE,
1435 .procname = "suid_dumpable",
1436 .data = &suid_dumpable,
1437 .maxlen = sizeof(int),
1438 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001439 .proc_handler = &proc_dointvec_minmax,
1440 .strategy = &sysctl_intvec,
1441 .extra1 = &zero,
1442 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001443 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001444#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1445 {
1446 .ctl_name = CTL_UNNUMBERED,
1447 .procname = "binfmt_misc",
1448 .mode = 0555,
1449 .child = binfmt_misc_table,
1450 },
1451#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001452/*
1453 * NOTE: do not add new entries to this table unless you have read
1454 * Documentation/sysctl/ctl_unnumbered.txt
1455 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 { .ctl_name = 0 }
1457};
1458
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001459static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001460#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001461 {
1462 .ctl_name = CTL_UNNUMBERED,
1463 .procname = "exception-trace",
1464 .data = &show_unhandled_signals,
1465 .maxlen = sizeof(int),
1466 .mode = 0644,
1467 .proc_handler = proc_dointvec
1468 },
1469#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 { .ctl_name = 0 }
1471};
1472
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001473static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001475};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Al Viro330d57f2005-11-04 10:18:40 +00001477static DEFINE_SPINLOCK(sysctl_lock);
1478
1479/* called under sysctl_lock */
1480static int use_table(struct ctl_table_header *p)
1481{
1482 if (unlikely(p->unregistering))
1483 return 0;
1484 p->used++;
1485 return 1;
1486}
1487
1488/* called under sysctl_lock */
1489static void unuse_table(struct ctl_table_header *p)
1490{
1491 if (!--p->used)
1492 if (unlikely(p->unregistering))
1493 complete(p->unregistering);
1494}
1495
1496/* called under sysctl_lock, will reacquire if has to wait */
1497static void start_unregistering(struct ctl_table_header *p)
1498{
1499 /*
1500 * if p->used is 0, nobody will ever touch that entry again;
1501 * we'll eliminate all paths to it before dropping sysctl_lock
1502 */
1503 if (unlikely(p->used)) {
1504 struct completion wait;
1505 init_completion(&wait);
1506 p->unregistering = &wait;
1507 spin_unlock(&sysctl_lock);
1508 wait_for_completion(&wait);
1509 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001510 } else {
1511 /* anything non-NULL; we'll never dereference it */
1512 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001513 }
1514 /*
1515 * do not remove from the list until nobody holds it; walking the
1516 * list in do_sysctl() relies on that.
1517 */
1518 list_del_init(&p->ctl_entry);
1519}
1520
Al Virof7e6ced2008-07-15 01:44:23 -04001521void sysctl_head_get(struct ctl_table_header *head)
1522{
1523 spin_lock(&sysctl_lock);
1524 head->count++;
1525 spin_unlock(&sysctl_lock);
1526}
1527
1528void sysctl_head_put(struct ctl_table_header *head)
1529{
1530 spin_lock(&sysctl_lock);
1531 if (!--head->count)
1532 kfree(head);
1533 spin_unlock(&sysctl_lock);
1534}
1535
1536struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1537{
1538 if (!head)
1539 BUG();
1540 spin_lock(&sysctl_lock);
1541 if (!use_table(head))
1542 head = ERR_PTR(-ENOENT);
1543 spin_unlock(&sysctl_lock);
1544 return head;
1545}
1546
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001547void sysctl_head_finish(struct ctl_table_header *head)
1548{
1549 if (!head)
1550 return;
1551 spin_lock(&sysctl_lock);
1552 unuse_table(head);
1553 spin_unlock(&sysctl_lock);
1554}
1555
Al Viro73455092008-07-14 21:22:20 -04001556static struct ctl_table_set *
1557lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1558{
1559 struct ctl_table_set *set = &root->default_set;
1560 if (root->lookup)
1561 set = root->lookup(root, namespaces);
1562 return set;
1563}
1564
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001565static struct list_head *
1566lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001567{
Al Viro73455092008-07-14 21:22:20 -04001568 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1569 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001570}
1571
1572struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1573 struct ctl_table_header *prev)
1574{
1575 struct ctl_table_root *root;
1576 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001577 struct ctl_table_header *head;
1578 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001579
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001580 spin_lock(&sysctl_lock);
1581 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001582 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001583 tmp = &prev->ctl_entry;
1584 unuse_table(prev);
1585 goto next;
1586 }
1587 tmp = &root_table_header.ctl_entry;
1588 for (;;) {
1589 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1590
1591 if (!use_table(head))
1592 goto next;
1593 spin_unlock(&sysctl_lock);
1594 return head;
1595 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001596 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001597 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001598 header_list = lookup_header_list(root, namespaces);
1599 if (tmp != header_list)
1600 continue;
1601
1602 do {
1603 root = list_entry(root->root_list.next,
1604 struct ctl_table_root, root_list);
1605 if (root == &sysctl_table_root)
1606 goto out;
1607 header_list = lookup_header_list(root, namespaces);
1608 } while (list_empty(header_list));
1609 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001610 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001611out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001612 spin_unlock(&sysctl_lock);
1613 return NULL;
1614}
1615
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001616struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1617{
1618 return __sysctl_head_next(current->nsproxy, prev);
1619}
1620
1621void register_sysctl_root(struct ctl_table_root *root)
1622{
1623 spin_lock(&sysctl_lock);
1624 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1625 spin_unlock(&sysctl_lock);
1626}
1627
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001628#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001629/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001630static int do_sysctl_strategy(struct ctl_table_root *root,
1631 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001632 void __user *oldval, size_t __user *oldlenp,
1633 void __user *newval, size_t newlen)
1634{
1635 int op = 0, rc;
1636
1637 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001638 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001639 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001640 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001641 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001642 return -EPERM;
1643
1644 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001645 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001646 if (rc < 0)
1647 return rc;
1648 if (rc > 0)
1649 return 0;
1650 }
1651
1652 /* If there is no strategy routine, or if the strategy returns
1653 * zero, proceed with automatic r/w */
1654 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001655 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001656 if (rc < 0)
1657 return rc;
1658 }
1659 return 0;
1660}
1661
1662static int parse_table(int __user *name, int nlen,
1663 void __user *oldval, size_t __user *oldlenp,
1664 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001665 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001666 struct ctl_table *table)
1667{
1668 int n;
1669repeat:
1670 if (!nlen)
1671 return -ENOTDIR;
1672 if (get_user(n, name))
1673 return -EFAULT;
1674 for ( ; table->ctl_name || table->procname; table++) {
1675 if (!table->ctl_name)
1676 continue;
1677 if (n == table->ctl_name) {
1678 int error;
1679 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001680 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001681 return -EPERM;
1682 name++;
1683 nlen--;
1684 table = table->child;
1685 goto repeat;
1686 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001687 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001688 oldval, oldlenp,
1689 newval, newlen);
1690 return error;
1691 }
1692 }
1693 return -ENOTDIR;
1694}
1695
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1697 void __user *newval, size_t newlen)
1698{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001699 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001700 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
1702 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1703 return -ENOTDIR;
1704 if (oldval) {
1705 int old_len;
1706 if (!oldlenp || get_user(old_len, oldlenp))
1707 return -EFAULT;
1708 }
Al Viro330d57f2005-11-04 10:18:40 +00001709
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001710 for (head = sysctl_head_next(NULL); head;
1711 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001712 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001713 newval, newlen,
1714 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001715 if (error != -ENOTDIR) {
1716 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001717 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001718 }
1719 }
Al Viro330d57f2005-11-04 10:18:40 +00001720 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721}
1722
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001723SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724{
1725 struct __sysctl_args tmp;
1726 int error;
1727
1728 if (copy_from_user(&tmp, args, sizeof(tmp)))
1729 return -EFAULT;
1730
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001731 error = deprecated_sysctl_warning(&tmp);
1732 if (error)
1733 goto out;
1734
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 lock_kernel();
1736 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1737 tmp.newval, tmp.newlen);
1738 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001739out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 return error;
1741}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001742#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001745 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 * some sysctl variables are readonly even to root.
1747 */
1748
1749static int test_perm(int mode, int op)
1750{
David Howells76aac0e2008-11-14 10:39:12 +11001751 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 mode >>= 6;
1753 else if (in_egroup_p(0))
1754 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001755 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 return 0;
1757 return -EACCES;
1758}
1759
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001760int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761{
1762 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001763 int mode;
1764
Al Viroe6305c42008-07-15 21:03:57 -04001765 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 if (error)
1767 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001768
1769 if (root->permissions)
1770 mode = root->permissions(root, current->nsproxy, table);
1771 else
1772 mode = table->mode;
1773
1774 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001777static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1778{
1779 for (; table->ctl_name || table->procname; table++) {
1780 table->parent = parent;
1781 if (table->child)
1782 sysctl_set_parent(table, table->child);
1783 }
1784}
1785
1786static __init int sysctl_init(void)
1787{
1788 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001789#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1790 {
1791 int err;
1792 err = sysctl_check_table(current->nsproxy, root_table);
1793 }
1794#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001795 return 0;
1796}
1797
1798core_initcall(sysctl_init);
1799
Al Virobfbcf032008-07-27 06:31:22 +01001800static struct ctl_table *is_branch_in(struct ctl_table *branch,
1801 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001802{
1803 struct ctl_table *p;
1804 const char *s = branch->procname;
1805
1806 /* branch should have named subdirectory as its first element */
1807 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001808 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001809
1810 /* ... and nothing else */
1811 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001812 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001813
1814 /* table should contain subdirectory with the same name */
1815 for (p = table; p->procname || p->ctl_name; p++) {
1816 if (!p->child)
1817 continue;
1818 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001819 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001820 }
Al Virobfbcf032008-07-27 06:31:22 +01001821 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001822}
1823
1824/* see if attaching q to p would be an improvement */
1825static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1826{
1827 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001828 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001829 int is_better = 0;
1830 int not_in_parent = !p->attached_by;
1831
Al Virobfbcf032008-07-27 06:31:22 +01001832 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001833 if (by == q->attached_by)
1834 is_better = 1;
1835 if (to == p->attached_by)
1836 not_in_parent = 1;
1837 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001838 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001839 }
1840
1841 if (is_better && not_in_parent) {
1842 q->attached_by = by;
1843 q->attached_to = to;
1844 q->parent = p;
1845 }
1846}
1847
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001849 * __register_sysctl_paths - register a sysctl hierarchy
1850 * @root: List of sysctl headers to register on
1851 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001852 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 *
1855 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001856 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001858 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 *
1860 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1861 * must be unique within that level of sysctl
1862 *
1863 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1864 * enter a sysctl file
1865 *
1866 * data - a pointer to data for use by proc_handler
1867 *
1868 * maxlen - the maximum size in bytes of the data
1869 *
1870 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1871 *
1872 * child - a pointer to the child sysctl table if this entry is a directory, or
1873 * %NULL.
1874 *
1875 * proc_handler - the text handler routine (described below)
1876 *
1877 * strategy - the strategy routine (described below)
1878 *
1879 * de - for internal use by the sysctl routines
1880 *
1881 * extra1, extra2 - extra pointers usable by the proc handler routines
1882 *
1883 * Leaf nodes in the sysctl tree will be represented by a single file
1884 * under /proc; non-leaf nodes will be represented by directories.
1885 *
1886 * sysctl(2) can automatically manage read and write requests through
1887 * the sysctl table. The data and maxlen fields of the ctl_table
1888 * struct enable minimal validation of the values being written to be
1889 * performed, and the mode field allows minimal authentication.
1890 *
1891 * More sophisticated management can be enabled by the provision of a
1892 * strategy routine with the table entry. This will be called before
1893 * any automatic read or write of the data is performed.
1894 *
1895 * The strategy routine may return
1896 *
1897 * < 0 - Error occurred (error is passed to user process)
1898 *
1899 * 0 - OK - proceed with automatic read or write.
1900 *
1901 * > 0 - OK - read or write has been done by the strategy routine, so
1902 * return immediately.
1903 *
1904 * There must be a proc_handler routine for any terminal nodes
1905 * mirrored under /proc/sys (non-terminals are handled by a built-in
1906 * directory handler). Several default handlers are available to
1907 * cover common cases -
1908 *
1909 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1910 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1911 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1912 *
1913 * It is the handler's job to read the input buffer from user memory
1914 * and process it. The handler should return 0 on success.
1915 *
1916 * This routine returns %NULL on a failure to register, and a pointer
1917 * to the table header on success.
1918 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001919struct ctl_table_header *__register_sysctl_paths(
1920 struct ctl_table_root *root,
1921 struct nsproxy *namespaces,
1922 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001924 struct ctl_table_header *header;
1925 struct ctl_table *new, **prevp;
1926 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001927 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001928
1929 /* Count the path components */
1930 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1931 ;
1932
1933 /*
1934 * For each path component, allocate a 2-element ctl_table array.
1935 * The first array element will be filled with the sysctl entry
1936 * for this, the second will be the sentinel (ctl_name == 0).
1937 *
1938 * We allocate everything in one go so that we don't have to
1939 * worry about freeing additional memory in unregister_sysctl_table.
1940 */
1941 header = kzalloc(sizeof(struct ctl_table_header) +
1942 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1943 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001945
1946 new = (struct ctl_table *) (header + 1);
1947
1948 /* Now connect the dots */
1949 prevp = &header->ctl_table;
1950 for (n = 0; n < npath; ++n, ++path) {
1951 /* Copy the procname */
1952 new->procname = path->procname;
1953 new->ctl_name = path->ctl_name;
1954 new->mode = 0555;
1955
1956 *prevp = new;
1957 prevp = &new->child;
1958
1959 new += 2;
1960 }
1961 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001962 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001963
1964 INIT_LIST_HEAD(&header->ctl_entry);
1965 header->used = 0;
1966 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001967 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001968 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001969 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001970#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001971 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001972 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001973 return NULL;
1974 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001975#endif
Al Viro330d57f2005-11-04 10:18:40 +00001976 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001977 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001978 header->attached_by = header->ctl_table;
1979 header->attached_to = root_table;
1980 header->parent = &root_table_header;
1981 for (set = header->set; set; set = set->parent) {
1982 struct ctl_table_header *p;
1983 list_for_each_entry(p, &set->list, ctl_entry) {
1984 if (p->unregistering)
1985 continue;
1986 try_attach(p, header);
1987 }
1988 }
1989 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001990 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001991 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001992
1993 return header;
1994}
1995
1996/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001997 * register_sysctl_table_path - register a sysctl table hierarchy
1998 * @path: The path to the directory the sysctl table is in.
1999 * @table: the top-level table structure
2000 *
2001 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2002 * array. A completely 0 filled entry terminates the table.
2003 *
2004 * See __register_sysctl_paths for more details.
2005 */
2006struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2007 struct ctl_table *table)
2008{
2009 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2010 path, table);
2011}
2012
2013/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002014 * register_sysctl_table - register a sysctl table hierarchy
2015 * @table: the top-level table structure
2016 *
2017 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2018 * array. A completely 0 filled entry terminates the table.
2019 *
2020 * See register_sysctl_paths for more details.
2021 */
2022struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2023{
2024 static const struct ctl_path null_path[] = { {} };
2025
2026 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027}
2028
2029/**
2030 * unregister_sysctl_table - unregister a sysctl table hierarchy
2031 * @header: the header returned from register_sysctl_table
2032 *
2033 * Unregisters the sysctl table and all children. proc entries may not
2034 * actually be removed until they are no longer used by anyone.
2035 */
2036void unregister_sysctl_table(struct ctl_table_header * header)
2037{
Al Viro330d57f2005-11-04 10:18:40 +00002038 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002039
2040 if (header == NULL)
2041 return;
2042
Al Viro330d57f2005-11-04 10:18:40 +00002043 spin_lock(&sysctl_lock);
2044 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002045 if (!--header->parent->count) {
2046 WARN_ON(1);
2047 kfree(header->parent);
2048 }
Al Virof7e6ced2008-07-15 01:44:23 -04002049 if (!--header->count)
2050 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002051 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052}
2053
Al Viro9043476f2008-07-15 08:54:06 -04002054int sysctl_is_seen(struct ctl_table_header *p)
2055{
2056 struct ctl_table_set *set = p->set;
2057 int res;
2058 spin_lock(&sysctl_lock);
2059 if (p->unregistering)
2060 res = 0;
2061 else if (!set->is_seen)
2062 res = 1;
2063 else
2064 res = set->is_seen(set);
2065 spin_unlock(&sysctl_lock);
2066 return res;
2067}
2068
Al Viro73455092008-07-14 21:22:20 -04002069void setup_sysctl_set(struct ctl_table_set *p,
2070 struct ctl_table_set *parent,
2071 int (*is_seen)(struct ctl_table_set *))
2072{
2073 INIT_LIST_HEAD(&p->list);
2074 p->parent = parent ? parent : &sysctl_table_root.default_set;
2075 p->is_seen = is_seen;
2076}
2077
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002078#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002079struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002080{
2081 return NULL;
2082}
2083
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002084struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2085 struct ctl_table *table)
2086{
2087 return NULL;
2088}
2089
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002090void unregister_sysctl_table(struct ctl_table_header * table)
2091{
2092}
2093
Al Viro73455092008-07-14 21:22:20 -04002094void setup_sysctl_set(struct ctl_table_set *p,
2095 struct ctl_table_set *parent,
2096 int (*is_seen)(struct ctl_table_set *))
2097{
2098}
2099
Al Virof7e6ced2008-07-15 01:44:23 -04002100void sysctl_head_put(struct ctl_table_header *head)
2101{
2102}
2103
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002104#endif /* CONFIG_SYSCTL */
2105
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106/*
2107 * /proc/sys support
2108 */
2109
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002110#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002112static int _proc_do_string(void* data, int maxlen, int write,
2113 struct file *filp, void __user *buffer,
2114 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002115{
2116 size_t len;
2117 char __user *p;
2118 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002119
2120 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002121 *lenp = 0;
2122 return 0;
2123 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002124
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002125 if (write) {
2126 len = 0;
2127 p = buffer;
2128 while (len < *lenp) {
2129 if (get_user(c, p++))
2130 return -EFAULT;
2131 if (c == 0 || c == '\n')
2132 break;
2133 len++;
2134 }
2135 if (len >= maxlen)
2136 len = maxlen-1;
2137 if(copy_from_user(data, buffer, len))
2138 return -EFAULT;
2139 ((char *) data)[len] = 0;
2140 *ppos += *lenp;
2141 } else {
2142 len = strlen(data);
2143 if (len > maxlen)
2144 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002145
2146 if (*ppos > len) {
2147 *lenp = 0;
2148 return 0;
2149 }
2150
2151 data += *ppos;
2152 len -= *ppos;
2153
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002154 if (len > *lenp)
2155 len = *lenp;
2156 if (len)
2157 if(copy_to_user(buffer, data, len))
2158 return -EFAULT;
2159 if (len < *lenp) {
2160 if(put_user('\n', ((char __user *) buffer) + len))
2161 return -EFAULT;
2162 len++;
2163 }
2164 *lenp = len;
2165 *ppos += len;
2166 }
2167 return 0;
2168}
2169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170/**
2171 * proc_dostring - read a string sysctl
2172 * @table: the sysctl table
2173 * @write: %TRUE if this is a write to the sysctl file
2174 * @filp: the file structure
2175 * @buffer: the user buffer
2176 * @lenp: the size of the user buffer
2177 * @ppos: file position
2178 *
2179 * Reads/writes a string from/to the user buffer. If the kernel
2180 * buffer provided is not large enough to hold the string, the
2181 * string is truncated. The copied string is %NULL-terminated.
2182 * If the string is being read by the user process, it is copied
2183 * and a newline '\n' is added. It is truncated if the buffer is
2184 * not large enough.
2185 *
2186 * Returns 0 on success.
2187 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002188int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 void __user *buffer, size_t *lenp, loff_t *ppos)
2190{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002191 return _proc_do_string(table->data, table->maxlen, write, filp,
2192 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193}
2194
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2197 int *valp,
2198 int write, void *data)
2199{
2200 if (write) {
2201 *valp = *negp ? -*lvalp : *lvalp;
2202 } else {
2203 int val = *valp;
2204 if (val < 0) {
2205 *negp = -1;
2206 *lvalp = (unsigned long)-val;
2207 } else {
2208 *negp = 0;
2209 *lvalp = (unsigned long)val;
2210 }
2211 }
2212 return 0;
2213}
2214
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002215static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002216 int write, struct file *filp, void __user *buffer,
2217 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2219 int write, void *data),
2220 void *data)
2221{
2222#define TMPBUFLEN 21
2223 int *i, vleft, first=1, neg, val;
2224 unsigned long lval;
2225 size_t left, len;
2226
2227 char buf[TMPBUFLEN], *p;
2228 char __user *s = buffer;
2229
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002230 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 (*ppos && !write)) {
2232 *lenp = 0;
2233 return 0;
2234 }
2235
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002236 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 vleft = table->maxlen / sizeof(*i);
2238 left = *lenp;
2239
2240 if (!conv)
2241 conv = do_proc_dointvec_conv;
2242
2243 for (; left && vleft--; i++, first=0) {
2244 if (write) {
2245 while (left) {
2246 char c;
2247 if (get_user(c, s))
2248 return -EFAULT;
2249 if (!isspace(c))
2250 break;
2251 left--;
2252 s++;
2253 }
2254 if (!left)
2255 break;
2256 neg = 0;
2257 len = left;
2258 if (len > sizeof(buf) - 1)
2259 len = sizeof(buf) - 1;
2260 if (copy_from_user(buf, s, len))
2261 return -EFAULT;
2262 buf[len] = 0;
2263 p = buf;
2264 if (*p == '-' && left > 1) {
2265 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002266 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 }
2268 if (*p < '0' || *p > '9')
2269 break;
2270
2271 lval = simple_strtoul(p, &p, 0);
2272
2273 len = p-buf;
2274 if ((len < left) && *p && !isspace(*p))
2275 break;
2276 if (neg)
2277 val = -val;
2278 s += len;
2279 left -= len;
2280
2281 if (conv(&neg, &lval, i, 1, data))
2282 break;
2283 } else {
2284 p = buf;
2285 if (!first)
2286 *p++ = '\t';
2287
2288 if (conv(&neg, &lval, i, 0, data))
2289 break;
2290
2291 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2292 len = strlen(buf);
2293 if (len > left)
2294 len = left;
2295 if(copy_to_user(s, buf, len))
2296 return -EFAULT;
2297 left -= len;
2298 s += len;
2299 }
2300 }
2301
2302 if (!write && !first && left) {
2303 if(put_user('\n', s))
2304 return -EFAULT;
2305 left--, s++;
2306 }
2307 if (write) {
2308 while (left) {
2309 char c;
2310 if (get_user(c, s++))
2311 return -EFAULT;
2312 if (!isspace(c))
2313 break;
2314 left--;
2315 }
2316 }
2317 if (write && first)
2318 return -EINVAL;
2319 *lenp -= left;
2320 *ppos += *lenp;
2321 return 0;
2322#undef TMPBUFLEN
2323}
2324
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002325static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002326 void __user *buffer, size_t *lenp, loff_t *ppos,
2327 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2328 int write, void *data),
2329 void *data)
2330{
2331 return __do_proc_dointvec(table->data, table, write, filp,
2332 buffer, lenp, ppos, conv, data);
2333}
2334
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335/**
2336 * proc_dointvec - read a vector of integers
2337 * @table: the sysctl table
2338 * @write: %TRUE if this is a write to the sysctl file
2339 * @filp: the file structure
2340 * @buffer: the user buffer
2341 * @lenp: the size of the user buffer
2342 * @ppos: file position
2343 *
2344 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2345 * values from/to the user buffer, treated as an ASCII string.
2346 *
2347 * Returns 0 on success.
2348 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002349int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 void __user *buffer, size_t *lenp, loff_t *ppos)
2351{
2352 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2353 NULL,NULL);
2354}
2355
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002356/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002357 * Taint values can only be increased
2358 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002359 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002360static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002361 void __user *buffer, size_t *lenp, loff_t *ppos)
2362{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002363 struct ctl_table t;
2364 unsigned long tmptaint = get_taint();
2365 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002366
Bastian Blank91fcd412007-04-23 14:41:14 -07002367 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002368 return -EPERM;
2369
Andi Kleen25ddbb12008-10-15 22:01:41 -07002370 t = *table;
2371 t.data = &tmptaint;
2372 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2373 if (err < 0)
2374 return err;
2375
2376 if (write) {
2377 /*
2378 * Poor man's atomic or. Not worth adding a primitive
2379 * to everyone's atomic.h for this
2380 */
2381 int i;
2382 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2383 if ((tmptaint >> i) & 1)
2384 add_taint(i);
2385 }
2386 }
2387
2388 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002389}
2390
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391struct do_proc_dointvec_minmax_conv_param {
2392 int *min;
2393 int *max;
2394};
2395
2396static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2397 int *valp,
2398 int write, void *data)
2399{
2400 struct do_proc_dointvec_minmax_conv_param *param = data;
2401 if (write) {
2402 int val = *negp ? -*lvalp : *lvalp;
2403 if ((param->min && *param->min > val) ||
2404 (param->max && *param->max < val))
2405 return -EINVAL;
2406 *valp = val;
2407 } else {
2408 int val = *valp;
2409 if (val < 0) {
2410 *negp = -1;
2411 *lvalp = (unsigned long)-val;
2412 } else {
2413 *negp = 0;
2414 *lvalp = (unsigned long)val;
2415 }
2416 }
2417 return 0;
2418}
2419
2420/**
2421 * proc_dointvec_minmax - read a vector of integers with min/max values
2422 * @table: the sysctl table
2423 * @write: %TRUE if this is a write to the sysctl file
2424 * @filp: the file structure
2425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
2427 * @ppos: file position
2428 *
2429 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2430 * values from/to the user buffer, treated as an ASCII string.
2431 *
2432 * This routine will ensure the values are within the range specified by
2433 * table->extra1 (min) and table->extra2 (max).
2434 *
2435 * Returns 0 on success.
2436 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002437int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 void __user *buffer, size_t *lenp, loff_t *ppos)
2439{
2440 struct do_proc_dointvec_minmax_conv_param param = {
2441 .min = (int *) table->extra1,
2442 .max = (int *) table->extra2,
2443 };
2444 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2445 do_proc_dointvec_minmax_conv, &param);
2446}
2447
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002448static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 struct file *filp,
2450 void __user *buffer,
2451 size_t *lenp, loff_t *ppos,
2452 unsigned long convmul,
2453 unsigned long convdiv)
2454{
2455#define TMPBUFLEN 21
2456 unsigned long *i, *min, *max, val;
2457 int vleft, first=1, neg;
2458 size_t len, left;
2459 char buf[TMPBUFLEN], *p;
2460 char __user *s = buffer;
2461
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002462 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 (*ppos && !write)) {
2464 *lenp = 0;
2465 return 0;
2466 }
2467
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002468 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 min = (unsigned long *) table->extra1;
2470 max = (unsigned long *) table->extra2;
2471 vleft = table->maxlen / sizeof(unsigned long);
2472 left = *lenp;
2473
2474 for (; left && vleft--; i++, min++, max++, first=0) {
2475 if (write) {
2476 while (left) {
2477 char c;
2478 if (get_user(c, s))
2479 return -EFAULT;
2480 if (!isspace(c))
2481 break;
2482 left--;
2483 s++;
2484 }
2485 if (!left)
2486 break;
2487 neg = 0;
2488 len = left;
2489 if (len > TMPBUFLEN-1)
2490 len = TMPBUFLEN-1;
2491 if (copy_from_user(buf, s, len))
2492 return -EFAULT;
2493 buf[len] = 0;
2494 p = buf;
2495 if (*p == '-' && left > 1) {
2496 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002497 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 }
2499 if (*p < '0' || *p > '9')
2500 break;
2501 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2502 len = p-buf;
2503 if ((len < left) && *p && !isspace(*p))
2504 break;
2505 if (neg)
2506 val = -val;
2507 s += len;
2508 left -= len;
2509
2510 if(neg)
2511 continue;
2512 if ((min && val < *min) || (max && val > *max))
2513 continue;
2514 *i = val;
2515 } else {
2516 p = buf;
2517 if (!first)
2518 *p++ = '\t';
2519 sprintf(p, "%lu", convdiv * (*i) / convmul);
2520 len = strlen(buf);
2521 if (len > left)
2522 len = left;
2523 if(copy_to_user(s, buf, len))
2524 return -EFAULT;
2525 left -= len;
2526 s += len;
2527 }
2528 }
2529
2530 if (!write && !first && left) {
2531 if(put_user('\n', s))
2532 return -EFAULT;
2533 left--, s++;
2534 }
2535 if (write) {
2536 while (left) {
2537 char c;
2538 if (get_user(c, s++))
2539 return -EFAULT;
2540 if (!isspace(c))
2541 break;
2542 left--;
2543 }
2544 }
2545 if (write && first)
2546 return -EINVAL;
2547 *lenp -= left;
2548 *ppos += *lenp;
2549 return 0;
2550#undef TMPBUFLEN
2551}
2552
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002553static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002554 struct file *filp,
2555 void __user *buffer,
2556 size_t *lenp, loff_t *ppos,
2557 unsigned long convmul,
2558 unsigned long convdiv)
2559{
2560 return __do_proc_doulongvec_minmax(table->data, table, write,
2561 filp, buffer, lenp, ppos, convmul, convdiv);
2562}
2563
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564/**
2565 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2566 * @table: the sysctl table
2567 * @write: %TRUE if this is a write to the sysctl file
2568 * @filp: the file structure
2569 * @buffer: the user buffer
2570 * @lenp: the size of the user buffer
2571 * @ppos: file position
2572 *
2573 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2574 * values from/to the user buffer, treated as an ASCII string.
2575 *
2576 * This routine will ensure the values are within the range specified by
2577 * table->extra1 (min) and table->extra2 (max).
2578 *
2579 * Returns 0 on success.
2580 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002581int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 void __user *buffer, size_t *lenp, loff_t *ppos)
2583{
2584 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2585}
2586
2587/**
2588 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2589 * @table: the sysctl table
2590 * @write: %TRUE if this is a write to the sysctl file
2591 * @filp: the file structure
2592 * @buffer: the user buffer
2593 * @lenp: the size of the user buffer
2594 * @ppos: file position
2595 *
2596 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2597 * values from/to the user buffer, treated as an ASCII string. The values
2598 * are treated as milliseconds, and converted to jiffies when they are stored.
2599 *
2600 * This routine will ensure the values are within the range specified by
2601 * table->extra1 (min) and table->extra2 (max).
2602 *
2603 * Returns 0 on success.
2604 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002605int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 struct file *filp,
2607 void __user *buffer,
2608 size_t *lenp, loff_t *ppos)
2609{
2610 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2611 lenp, ppos, HZ, 1000l);
2612}
2613
2614
2615static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2616 int *valp,
2617 int write, void *data)
2618{
2619 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002620 if (*lvalp > LONG_MAX / HZ)
2621 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2623 } else {
2624 int val = *valp;
2625 unsigned long lval;
2626 if (val < 0) {
2627 *negp = -1;
2628 lval = (unsigned long)-val;
2629 } else {
2630 *negp = 0;
2631 lval = (unsigned long)val;
2632 }
2633 *lvalp = lval / HZ;
2634 }
2635 return 0;
2636}
2637
2638static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2639 int *valp,
2640 int write, void *data)
2641{
2642 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002643 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2644 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2646 } else {
2647 int val = *valp;
2648 unsigned long lval;
2649 if (val < 0) {
2650 *negp = -1;
2651 lval = (unsigned long)-val;
2652 } else {
2653 *negp = 0;
2654 lval = (unsigned long)val;
2655 }
2656 *lvalp = jiffies_to_clock_t(lval);
2657 }
2658 return 0;
2659}
2660
2661static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2662 int *valp,
2663 int write, void *data)
2664{
2665 if (write) {
2666 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2667 } else {
2668 int val = *valp;
2669 unsigned long lval;
2670 if (val < 0) {
2671 *negp = -1;
2672 lval = (unsigned long)-val;
2673 } else {
2674 *negp = 0;
2675 lval = (unsigned long)val;
2676 }
2677 *lvalp = jiffies_to_msecs(lval);
2678 }
2679 return 0;
2680}
2681
2682/**
2683 * proc_dointvec_jiffies - read a vector of integers as seconds
2684 * @table: the sysctl table
2685 * @write: %TRUE if this is a write to the sysctl file
2686 * @filp: the file structure
2687 * @buffer: the user buffer
2688 * @lenp: the size of the user buffer
2689 * @ppos: file position
2690 *
2691 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2692 * values from/to the user buffer, treated as an ASCII string.
2693 * The values read are assumed to be in seconds, and are converted into
2694 * jiffies.
2695 *
2696 * Returns 0 on success.
2697 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002698int proc_dointvec_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 do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2702 do_proc_dointvec_jiffies_conv,NULL);
2703}
2704
2705/**
2706 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2707 * @table: the sysctl table
2708 * @write: %TRUE if this is a write to the sysctl file
2709 * @filp: the file structure
2710 * @buffer: the user buffer
2711 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002712 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 *
2714 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2715 * values from/to the user buffer, treated as an ASCII string.
2716 * The values read are assumed to be in 1/USER_HZ seconds, and
2717 * are converted into jiffies.
2718 *
2719 * Returns 0 on success.
2720 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002721int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 void __user *buffer, size_t *lenp, loff_t *ppos)
2723{
2724 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2725 do_proc_dointvec_userhz_jiffies_conv,NULL);
2726}
2727
2728/**
2729 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2730 * @table: the sysctl table
2731 * @write: %TRUE if this is a write to the sysctl file
2732 * @filp: the file structure
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002735 * @ppos: file position
2736 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 *
2738 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2739 * values from/to the user buffer, treated as an ASCII string.
2740 * The values read are assumed to be in 1/1000 seconds, and
2741 * are converted into jiffies.
2742 *
2743 * Returns 0 on success.
2744 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002745int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 void __user *buffer, size_t *lenp, loff_t *ppos)
2747{
2748 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2749 do_proc_dointvec_ms_jiffies_conv, NULL);
2750}
2751
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002752static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002753 void __user *buffer, size_t *lenp, loff_t *ppos)
2754{
2755 struct pid *new_pid;
2756 pid_t tmp;
2757 int r;
2758
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002759 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002760
2761 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2762 lenp, ppos, NULL, NULL);
2763 if (r || !write)
2764 return r;
2765
2766 new_pid = find_get_pid(tmp);
2767 if (!new_pid)
2768 return -ESRCH;
2769
2770 put_pid(xchg(&cad_pid, new_pid));
2771 return 0;
2772}
2773
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774#else /* CONFIG_PROC_FS */
2775
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002776int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 void __user *buffer, size_t *lenp, loff_t *ppos)
2778{
2779 return -ENOSYS;
2780}
2781
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002782int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 void __user *buffer, size_t *lenp, loff_t *ppos)
2784{
2785 return -ENOSYS;
2786}
2787
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002788int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 void __user *buffer, size_t *lenp, loff_t *ppos)
2790{
2791 return -ENOSYS;
2792}
2793
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002794int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 void __user *buffer, size_t *lenp, loff_t *ppos)
2796{
2797 return -ENOSYS;
2798}
2799
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002800int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 void __user *buffer, size_t *lenp, loff_t *ppos)
2802{
2803 return -ENOSYS;
2804}
2805
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002806int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 void __user *buffer, size_t *lenp, loff_t *ppos)
2808{
2809 return -ENOSYS;
2810}
2811
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002812int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 void __user *buffer, size_t *lenp, loff_t *ppos)
2814{
2815 return -ENOSYS;
2816}
2817
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002818int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 struct file *filp,
2820 void __user *buffer,
2821 size_t *lenp, loff_t *ppos)
2822{
2823 return -ENOSYS;
2824}
2825
2826
2827#endif /* CONFIG_PROC_FS */
2828
2829
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002830#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831/*
2832 * General sysctl support routines
2833 */
2834
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002835/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002836int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002837 void __user *oldval, size_t __user *oldlenp,
2838 void __user *newval, size_t newlen)
2839{
2840 size_t len;
2841
2842 /* Get out of I don't have a variable */
2843 if (!table->data || !table->maxlen)
2844 return -ENOTDIR;
2845
2846 if (oldval && oldlenp) {
2847 if (get_user(len, oldlenp))
2848 return -EFAULT;
2849 if (len) {
2850 if (len > table->maxlen)
2851 len = table->maxlen;
2852 if (copy_to_user(oldval, table->data, len))
2853 return -EFAULT;
2854 if (put_user(len, oldlenp))
2855 return -EFAULT;
2856 }
2857 }
2858
2859 if (newval && newlen) {
2860 if (newlen > table->maxlen)
2861 newlen = table->maxlen;
2862
2863 if (copy_from_user(table->data, newval, newlen))
2864 return -EFAULT;
2865 }
2866 return 1;
2867}
2868
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002870int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002872 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 if (!table->data || !table->maxlen)
2875 return -ENOTDIR;
2876
2877 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002878 size_t bufsize;
2879 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002881 if (bufsize) {
2882 size_t len = strlen(table->data), copied;
2883
2884 /* This shouldn't trigger for a well-formed sysctl */
2885 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002887
2888 /* Copy up to a max of bufsize-1 bytes of the string */
2889 copied = (len >= bufsize) ? bufsize - 1 : len;
2890
2891 if (copy_to_user(oldval, table->data, copied) ||
2892 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002894 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 return -EFAULT;
2896 }
2897 }
2898 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002899 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 if (len > table->maxlen)
2901 len = table->maxlen;
2902 if(copy_from_user(table->data, newval, len))
2903 return -EFAULT;
2904 if (len == table->maxlen)
2905 len--;
2906 ((char *) table->data)[len] = 0;
2907 }
Yi Yang82c9df82005-12-30 16:37:10 +08002908 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909}
2910
2911/*
2912 * This function makes sure that all of the integers in the vector
2913 * are between the minimum and maximum values given in the arrays
2914 * table->extra1 and table->extra2, respectively.
2915 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002916int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002918 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919{
2920
2921 if (newval && newlen) {
2922 int __user *vec = (int __user *) newval;
2923 int *min = (int *) table->extra1;
2924 int *max = (int *) table->extra2;
2925 size_t length;
2926 int i;
2927
2928 if (newlen % sizeof(int) != 0)
2929 return -EINVAL;
2930
2931 if (!table->extra1 && !table->extra2)
2932 return 0;
2933
2934 if (newlen > table->maxlen)
2935 newlen = table->maxlen;
2936 length = newlen / sizeof(int);
2937
2938 for (i = 0; i < length; i++) {
2939 int value;
2940 if (get_user(value, vec + i))
2941 return -EFAULT;
2942 if (min && value < min[i])
2943 return -EINVAL;
2944 if (max && value > max[i])
2945 return -EINVAL;
2946 }
2947 }
2948 return 0;
2949}
2950
2951/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002952int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002954 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002956 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002958
2959 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002961 if (olen) {
2962 int val;
2963
2964 if (olen < sizeof(int))
2965 return -EINVAL;
2966
2967 val = *(int *)(table->data) / HZ;
2968 if (put_user(val, (int __user *)oldval))
2969 return -EFAULT;
2970 if (put_user(sizeof(int), oldlenp))
2971 return -EFAULT;
2972 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 }
2974 if (newval && newlen) {
2975 int new;
2976 if (newlen != sizeof(int))
2977 return -EINVAL;
2978 if (get_user(new, (int __user *)newval))
2979 return -EFAULT;
2980 *(int *)(table->data) = new*HZ;
2981 }
2982 return 1;
2983}
2984
2985/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002986int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002988 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002990 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002992
2993 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002995 if (olen) {
2996 int val;
2997
2998 if (olen < sizeof(int))
2999 return -EINVAL;
3000
3001 val = jiffies_to_msecs(*(int *)(table->data));
3002 if (put_user(val, (int __user *)oldval))
3003 return -EFAULT;
3004 if (put_user(sizeof(int), oldlenp))
3005 return -EFAULT;
3006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 }
3008 if (newval && newlen) {
3009 int new;
3010 if (newlen != sizeof(int))
3011 return -EINVAL;
3012 if (get_user(new, (int __user *)newval))
3013 return -EFAULT;
3014 *(int *)(table->data) = msecs_to_jiffies(new);
3015 }
3016 return 1;
3017}
3018
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003019
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003020
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003021#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022
3023
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003024SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003026 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003027 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003028
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003029 if (copy_from_user(&tmp, args, sizeof(tmp)))
3030 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003031
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003032 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003033
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003034 /* If no error reading the parameters then just -ENOSYS ... */
3035 if (!error)
3036 error = -ENOSYS;
3037
3038 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039}
3040
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003041int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003042 void __user *oldval, size_t __user *oldlenp,
3043 void __user *newval, size_t newlen)
3044{
3045 return -ENOSYS;
3046}
3047
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003048int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003050 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051{
3052 return -ENOSYS;
3053}
3054
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003055int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003057 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058{
3059 return -ENOSYS;
3060}
3061
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003062int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003064 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065{
3066 return -ENOSYS;
3067}
3068
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003069int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003071 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072{
3073 return -ENOSYS;
3074}
3075
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003076#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003078static int deprecated_sysctl_warning(struct __sysctl_args *args)
3079{
3080 static int msg_count;
3081 int name[CTL_MAXNAME];
3082 int i;
3083
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003084 /* Check args->nlen. */
3085 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3086 return -ENOTDIR;
3087
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003088 /* Read in the sysctl name for better debug message logging */
3089 for (i = 0; i < args->nlen; i++)
3090 if (get_user(name[i], args->name + i))
3091 return -EFAULT;
3092
3093 /* Ignore accesses to kernel.version */
3094 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3095 return 0;
3096
3097 if (msg_count < 5) {
3098 msg_count++;
3099 printk(KERN_INFO
3100 "warning: process `%s' used the deprecated sysctl "
3101 "system call with ", current->comm);
3102 for (i = 0; i < args->nlen; i++)
3103 printk("%d.", name[i]);
3104 printk("\n");
3105 }
3106 return 0;
3107}
3108
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109/*
3110 * No sense putting this after each symbol definition, twice,
3111 * exception granted :-)
3112 */
3113EXPORT_SYMBOL(proc_dointvec);
3114EXPORT_SYMBOL(proc_dointvec_jiffies);
3115EXPORT_SYMBOL(proc_dointvec_minmax);
3116EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3117EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3118EXPORT_SYMBOL(proc_dostring);
3119EXPORT_SYMBOL(proc_doulongvec_minmax);
3120EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3121EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003122EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123EXPORT_SYMBOL(sysctl_intvec);
3124EXPORT_SYMBOL(sysctl_jiffies);
3125EXPORT_SYMBOL(sysctl_ms_jiffies);
3126EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003127EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128EXPORT_SYMBOL(unregister_sysctl_table);