blob: e3d2c7dd59b9791ad14c8b48e5fb804a38052ac8 [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 Gondwana195cf452008-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;
Peter W Morrealefafd6882009-04-06 19:00:29 -0700104static int one_thousand = 1000;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107static int maxolduid = 65535;
108static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111static int ngroups_max = NGROUPS_MAX;
112
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200113#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern char modprobe_path[];
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#ifdef CONFIG_CHR_DEV_SG
117extern int sg_big_buff;
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
David S. Miller72c57ed2008-09-11 23:29:54 -0700120#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700121#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#endif
123
David S. Miller08714202008-11-16 23:49:24 -0800124#ifdef CONFIG_SPARC64
125extern int sysctl_tsb_ratio;
126#endif
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef __hppa__
129extern int pwrsw_enabled;
130extern int unaligned_enabled;
131#endif
132
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800133#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef CONFIG_MATHEMU
135extern int sysctl_ieee_emulation_warnings;
136#endif
137extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700138extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#endif
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#ifdef CONFIG_BSD_PROCESS_ACCT
142extern int acct_parm[];
143#endif
144
Jes Sorensend2b176e2006-02-28 09:42:23 -0800145#ifdef CONFIG_IA64
146extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800147extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800148#endif
149
Ingo Molnar23f78d42006-06-27 02:54:53 -0700150#ifdef CONFIG_RT_MUTEXES
151extern int max_lock_depth;
152#endif
153
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700154#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700156 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700157static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800158 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700159#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700160
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700161static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100162static struct ctl_table_root sysctl_table_root;
163static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100164 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100165 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400166 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100167 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400168 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100169};
170static struct ctl_table_root sysctl_table_root = {
171 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400172 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100173};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700175static struct ctl_table kern_table[];
176static struct ctl_table vm_table[];
177static struct ctl_table fs_table[];
178static struct ctl_table debug_table[];
179static struct ctl_table dev_table[];
180extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700181#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700182extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400183#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800184#ifdef CONFIG_EPOLL
185extern struct ctl_table epoll_table[];
186#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
189int sysctl_legacy_va_layout;
190#endif
191
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700192extern int prove_locking;
193extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195/* The default sysctl tables: */
196
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700197static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 {
199 .ctl_name = CTL_KERN,
200 .procname = "kernel",
201 .mode = 0555,
202 .child = kern_table,
203 },
204 {
205 .ctl_name = CTL_VM,
206 .procname = "vm",
207 .mode = 0555,
208 .child = vm_table,
209 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 .ctl_name = CTL_FS,
212 .procname = "fs",
213 .mode = 0555,
214 .child = fs_table,
215 },
216 {
217 .ctl_name = CTL_DEBUG,
218 .procname = "debug",
219 .mode = 0555,
220 .child = debug_table,
221 },
222 {
223 .ctl_name = CTL_DEV,
224 .procname = "dev",
225 .mode = 0555,
226 .child = dev_table,
227 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700228/*
229 * NOTE: do not add new entries to this table unless you have read
230 * Documentation/sysctl/ctl_unnumbered.txt
231 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 { .ctl_name = 0 }
233};
234
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100236static int min_sched_granularity_ns = 100000; /* 100 usecs */
237static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
238static int min_wakeup_granularity_ns; /* 0 usecs */
239static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240#endif
241
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700242static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243#ifdef CONFIG_SCHED_DEBUG
244 {
245 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100246 .procname = "sched_min_granularity_ns",
247 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200248 .maxlen = sizeof(unsigned int),
249 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100250 .proc_handler = &sched_nr_latency_handler,
251 .strategy = &sysctl_intvec,
252 .extra1 = &min_sched_granularity_ns,
253 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200254 },
255 {
256 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200257 .procname = "sched_latency_ns",
258 .data = &sysctl_sched_latency,
259 .maxlen = sizeof(unsigned int),
260 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100261 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200262 .strategy = &sysctl_intvec,
263 .extra1 = &min_sched_granularity_ns,
264 .extra2 = &max_sched_granularity_ns,
265 },
266 {
267 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200268 .procname = "sched_wakeup_granularity_ns",
269 .data = &sysctl_sched_wakeup_granularity,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
272 .proc_handler = &proc_dointvec_minmax,
273 .strategy = &sysctl_intvec,
274 .extra1 = &min_wakeup_granularity_ns,
275 .extra2 = &max_wakeup_granularity_ns,
276 },
277 {
278 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200279 .procname = "sched_shares_ratelimit",
280 .data = &sysctl_sched_shares_ratelimit,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec,
284 },
285 {
286 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200287 .procname = "sched_shares_thresh",
288 .data = &sysctl_sched_shares_thresh,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = &proc_dointvec_minmax,
292 .strategy = &sysctl_intvec,
293 .extra1 = &zero,
294 },
295 {
296 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200297 .procname = "sched_child_runs_first",
298 .data = &sysctl_sched_child_runs_first,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
302 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200303 {
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_features",
306 .data = &sysctl_sched_features,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec,
310 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200311 {
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "sched_migration_cost",
314 .data = &sysctl_sched_migration_cost,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
317 .proc_handler = &proc_dointvec,
318 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100319 {
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "sched_nr_migrate",
322 .data = &sysctl_sched_nr_migrate,
323 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100324 .mode = 0644,
325 .proc_handler = &proc_dointvec,
326 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200327#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200328 {
329 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100330 .procname = "sched_rt_period_us",
331 .data = &sysctl_sched_rt_period,
332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200334 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100335 },
336 {
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "sched_rt_runtime_us",
339 .data = &sysctl_sched_rt_runtime,
340 .maxlen = sizeof(int),
341 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200342 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100343 },
344 {
345 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200346 .procname = "sched_compat_yield",
347 .data = &sysctl_sched_compat_yield,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
350 .proc_handler = &proc_dointvec,
351 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700352#ifdef CONFIG_PROVE_LOCKING
353 {
354 .ctl_name = CTL_UNNUMBERED,
355 .procname = "prove_locking",
356 .data = &prove_locking,
357 .maxlen = sizeof(int),
358 .mode = 0644,
359 .proc_handler = &proc_dointvec,
360 },
361#endif
362#ifdef CONFIG_LOCK_STAT
363 {
364 .ctl_name = CTL_UNNUMBERED,
365 .procname = "lock_stat",
366 .data = &lock_stat,
367 .maxlen = sizeof(int),
368 .mode = 0644,
369 .proc_handler = &proc_dointvec,
370 },
371#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200372 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 .ctl_name = KERN_PANIC,
374 .procname = "panic",
375 .data = &panic_timeout,
376 .maxlen = sizeof(int),
377 .mode = 0644,
378 .proc_handler = &proc_dointvec,
379 },
380 {
381 .ctl_name = KERN_CORE_USES_PID,
382 .procname = "core_uses_pid",
383 .data = &core_uses_pid,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = &proc_dointvec,
387 },
388 {
389 .ctl_name = KERN_CORE_PATTERN,
390 .procname = "core_pattern",
391 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700392 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 .mode = 0644,
394 .proc_handler = &proc_dostring,
395 .strategy = &sysctl_string,
396 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800397#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700400 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800401 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700402 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800404#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100405#ifdef CONFIG_LATENCYTOP
406 {
407 .procname = "latencytop",
408 .data = &latencytop_enabled,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
412 },
413#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414#ifdef CONFIG_BLK_DEV_INITRD
415 {
416 .ctl_name = KERN_REALROOTDEV,
417 .procname = "real-root-dev",
418 .data = &real_root_dev,
419 .maxlen = sizeof(int),
420 .mode = 0644,
421 .proc_handler = &proc_dointvec,
422 },
423#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700424 {
425 .ctl_name = CTL_UNNUMBERED,
426 .procname = "print-fatal-signals",
427 .data = &print_fatal_signals,
428 .maxlen = sizeof(int),
429 .mode = 0644,
430 .proc_handler = &proc_dointvec,
431 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700432#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 {
434 .ctl_name = KERN_SPARC_REBOOT,
435 .procname = "reboot-cmd",
436 .data = reboot_command,
437 .maxlen = 256,
438 .mode = 0644,
439 .proc_handler = &proc_dostring,
440 .strategy = &sysctl_string,
441 },
442 {
443 .ctl_name = KERN_SPARC_STOP_A,
444 .procname = "stop-a",
445 .data = &stop_a_enabled,
446 .maxlen = sizeof (int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450 {
451 .ctl_name = KERN_SPARC_SCONS_PWROFF,
452 .procname = "scons-poweroff",
453 .data = &scons_pwroff,
454 .maxlen = sizeof (int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458#endif
David S. Miller08714202008-11-16 23:49:24 -0800459#ifdef CONFIG_SPARC64
460 {
461 .ctl_name = CTL_UNNUMBERED,
462 .procname = "tsb-ratio",
463 .data = &sysctl_tsb_ratio,
464 .maxlen = sizeof (int),
465 .mode = 0644,
466 .proc_handler = &proc_dointvec,
467 },
468#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#ifdef __hppa__
470 {
471 .ctl_name = KERN_HPPA_PWRSW,
472 .procname = "soft-power",
473 .data = &pwrsw_enabled,
474 .maxlen = sizeof (int),
475 .mode = 0644,
476 .proc_handler = &proc_dointvec,
477 },
478 {
479 .ctl_name = KERN_HPPA_UNALIGNED,
480 .procname = "unaligned-trap",
481 .data = &unaligned_enabled,
482 .maxlen = sizeof (int),
483 .mode = 0644,
484 .proc_handler = &proc_dointvec,
485 },
486#endif
487 {
488 .ctl_name = KERN_CTLALTDEL,
489 .procname = "ctrl-alt-del",
490 .data = &C_A_D,
491 .maxlen = sizeof(int),
492 .mode = 0644,
493 .proc_handler = &proc_dointvec,
494 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400495#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200496 {
497 .ctl_name = CTL_UNNUMBERED,
498 .procname = "ftrace_enabled",
499 .data = &ftrace_enabled,
500 .maxlen = sizeof(int),
501 .mode = 0644,
502 .proc_handler = &ftrace_enable_sysctl,
503 },
504#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500505#ifdef CONFIG_STACK_TRACER
506 {
507 .ctl_name = CTL_UNNUMBERED,
508 .procname = "stack_tracer_enabled",
509 .data = &stack_tracer_enabled,
510 .maxlen = sizeof(int),
511 .mode = 0644,
512 .proc_handler = &stack_trace_sysctl,
513 },
514#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400515#ifdef CONFIG_TRACING
516 {
517 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100518 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400519 .data = &ftrace_dump_on_oops,
520 .maxlen = sizeof(int),
521 .mode = 0644,
522 .proc_handler = &proc_dointvec,
523 },
524#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200525#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 {
527 .ctl_name = KERN_MODPROBE,
528 .procname = "modprobe",
529 .data = &modprobe_path,
530 .maxlen = KMOD_PATH_LEN,
531 .mode = 0644,
532 .proc_handler = &proc_dostring,
533 .strategy = &sysctl_string,
534 },
535#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700536#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 {
538 .ctl_name = KERN_HOTPLUG,
539 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100540 .data = &uevent_helper,
541 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 .mode = 0644,
543 .proc_handler = &proc_dostring,
544 .strategy = &sysctl_string,
545 },
546#endif
547#ifdef CONFIG_CHR_DEV_SG
548 {
549 .ctl_name = KERN_SG_BIG_BUFF,
550 .procname = "sg-big-buff",
551 .data = &sg_big_buff,
552 .maxlen = sizeof (int),
553 .mode = 0444,
554 .proc_handler = &proc_dointvec,
555 },
556#endif
557#ifdef CONFIG_BSD_PROCESS_ACCT
558 {
559 .ctl_name = KERN_ACCT,
560 .procname = "acct",
561 .data = &acct_parm,
562 .maxlen = 3*sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
565 },
566#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#ifdef CONFIG_MAGIC_SYSRQ
568 {
569 .ctl_name = KERN_SYSRQ,
570 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800571 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .maxlen = sizeof (int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
575 },
576#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700577#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700580 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .maxlen = sizeof (int),
582 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700583 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 {
587 .ctl_name = KERN_MAX_THREADS,
588 .procname = "threads-max",
589 .data = &max_threads,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec,
593 },
594 {
595 .ctl_name = KERN_RANDOM,
596 .procname = "random",
597 .mode = 0555,
598 .child = random_table,
599 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 {
601 .ctl_name = KERN_OVERFLOWUID,
602 .procname = "overflowuid",
603 .data = &overflowuid,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec_minmax,
607 .strategy = &sysctl_intvec,
608 .extra1 = &minolduid,
609 .extra2 = &maxolduid,
610 },
611 {
612 .ctl_name = KERN_OVERFLOWGID,
613 .procname = "overflowgid",
614 .data = &overflowgid,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = &proc_dointvec_minmax,
618 .strategy = &sysctl_intvec,
619 .extra1 = &minolduid,
620 .extra2 = &maxolduid,
621 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800622#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#ifdef CONFIG_MATHEMU
624 {
625 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
626 .procname = "ieee_emulation_warnings",
627 .data = &sysctl_ieee_emulation_warnings,
628 .maxlen = sizeof(int),
629 .mode = 0644,
630 .proc_handler = &proc_dointvec,
631 },
632#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 {
634 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
635 .procname = "userprocess_debug",
636 .data = &sysctl_userprocess_debug,
637 .maxlen = sizeof(int),
638 .mode = 0644,
639 .proc_handler = &proc_dointvec,
640 },
641#endif
642 {
643 .ctl_name = KERN_PIDMAX,
644 .procname = "pid_max",
645 .data = &pid_max,
646 .maxlen = sizeof (int),
647 .mode = 0644,
648 .proc_handler = &proc_dointvec_minmax,
649 .strategy = sysctl_intvec,
650 .extra1 = &pid_max_min,
651 .extra2 = &pid_max_max,
652 },
653 {
654 .ctl_name = KERN_PANIC_ON_OOPS,
655 .procname = "panic_on_oops",
656 .data = &panic_on_oops,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 .proc_handler = &proc_dointvec,
660 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800661#if defined CONFIG_PRINTK
662 {
663 .ctl_name = KERN_PRINTK,
664 .procname = "printk",
665 .data = &console_loglevel,
666 .maxlen = 4*sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec,
669 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 {
671 .ctl_name = KERN_PRINTK_RATELIMIT,
672 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700673 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 .maxlen = sizeof(int),
675 .mode = 0644,
676 .proc_handler = &proc_dointvec_jiffies,
677 .strategy = &sysctl_jiffies,
678 },
679 {
680 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
681 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700682 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 .maxlen = sizeof(int),
684 .mode = 0644,
685 .proc_handler = &proc_dointvec,
686 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800687#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 {
689 .ctl_name = KERN_NGROUPS_MAX,
690 .procname = "ngroups_max",
691 .data = &ngroups_max,
692 .maxlen = sizeof (int),
693 .mode = 0444,
694 .proc_handler = &proc_dointvec,
695 },
696#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
697 {
698 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
699 .procname = "unknown_nmi_panic",
700 .data = &unknown_nmi_panic,
701 .maxlen = sizeof (int),
702 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200703 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 },
Don Zickus407984f2006-09-26 10:52:27 +0200705 {
Don Zickus407984f2006-09-26 10:52:27 +0200706 .procname = "nmi_watchdog",
707 .data = &nmi_watchdog_enabled,
708 .maxlen = sizeof (int),
709 .mode = 0644,
710 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 },
712#endif
713#if defined(CONFIG_X86)
714 {
Don Zickus8da5adda2006-09-26 10:52:27 +0200715 .ctl_name = KERN_PANIC_ON_NMI,
716 .procname = "panic_on_unrecovered_nmi",
717 .data = &panic_on_unrecovered_nmi,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
721 },
722 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .ctl_name = KERN_BOOTLOADER_TYPE,
724 .procname = "bootloader_type",
725 .data = &bootloader_type,
726 .maxlen = sizeof (int),
727 .mode = 0444,
728 .proc_handler = &proc_dointvec,
729 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100730 {
731 .ctl_name = CTL_UNNUMBERED,
732 .procname = "kstack_depth_to_print",
733 .data = &kstack_depth_to_print,
734 .maxlen = sizeof(int),
735 .mode = 0644,
736 .proc_handler = &proc_dointvec,
737 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100738 {
739 .ctl_name = CTL_UNNUMBERED,
740 .procname = "io_delay_type",
741 .data = &io_delay_type,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = &proc_dointvec,
745 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800747#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 {
749 .ctl_name = KERN_RANDOMIZE,
750 .procname = "randomize_va_space",
751 .data = &randomize_va_space,
752 .maxlen = sizeof(int),
753 .mode = 0644,
754 .proc_handler = &proc_dointvec,
755 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800756#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800757#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700758 {
759 .ctl_name = KERN_SPIN_RETRY,
760 .procname = "spin_retry",
761 .data = &spin_retry,
762 .maxlen = sizeof (int),
763 .mode = 0644,
764 .proc_handler = &proc_dointvec,
765 },
766#endif
Len Brown673d5b42007-07-28 03:33:16 -0400767#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800768 {
Pavel Machekc255d842006-02-20 18:27:58 -0800769 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700770 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800771 .maxlen = sizeof (unsigned long),
772 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800773 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800774 },
775#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800776#ifdef CONFIG_IA64
777 {
778 .ctl_name = KERN_IA64_UNALIGNED,
779 .procname = "ignore-unaligned-usertrap",
780 .data = &no_unaligned_warning,
781 .maxlen = sizeof (int),
782 .mode = 0644,
783 .proc_handler = &proc_dointvec,
784 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800785 {
786 .ctl_name = CTL_UNNUMBERED,
787 .procname = "unaligned-dump-stack",
788 .data = &unaligned_dump_stack,
789 .maxlen = sizeof (int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
792 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800793#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700794#ifdef CONFIG_DETECT_SOFTLOCKUP
795 {
796 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200797 .procname = "softlockup_panic",
798 .data = &softlockup_panic,
799 .maxlen = sizeof(int),
800 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700801 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200802 .strategy = &sysctl_intvec,
803 .extra1 = &zero,
804 .extra2 = &one,
805 },
806 {
807 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700808 .procname = "softlockup_thresh",
809 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200810 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700811 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800812 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700813 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200814 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700815 .extra2 = &sixty,
816 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800817#endif
818#ifdef CONFIG_DETECT_HUNG_TASK
819 {
820 .ctl_name = CTL_UNNUMBERED,
821 .procname = "hung_task_panic",
822 .data = &sysctl_hung_task_panic,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec_minmax,
826 .strategy = &sysctl_intvec,
827 .extra1 = &zero,
828 .extra2 = &one,
829 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100830 {
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "hung_task_check_count",
833 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100834 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100835 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100836 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100837 .strategy = &sysctl_intvec,
838 },
839 {
840 .ctl_name = CTL_UNNUMBERED,
841 .procname = "hung_task_timeout_secs",
842 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100843 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100844 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800845 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100846 .strategy = &sysctl_intvec,
847 },
848 {
849 .ctl_name = CTL_UNNUMBERED,
850 .procname = "hung_task_warnings",
851 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100852 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100853 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100854 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100855 .strategy = &sysctl_intvec,
856 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700857#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200858#ifdef CONFIG_COMPAT
859 {
860 .ctl_name = KERN_COMPAT_LOG,
861 .procname = "compat-log",
862 .data = &compat_log,
863 .maxlen = sizeof (int),
864 .mode = 0644,
865 .proc_handler = &proc_dointvec,
866 },
867#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700868#ifdef CONFIG_RT_MUTEXES
869 {
870 .ctl_name = KERN_MAX_LOCK_DEPTH,
871 .procname = "max_lock_depth",
872 .data = &max_lock_depth,
873 .maxlen = sizeof(int),
874 .mode = 0644,
875 .proc_handler = &proc_dointvec,
876 },
877#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700878 {
879 .ctl_name = CTL_UNNUMBERED,
880 .procname = "poweroff_cmd",
881 .data = &poweroff_cmd,
882 .maxlen = POWEROFF_CMD_PATH_LEN,
883 .mode = 0644,
884 .proc_handler = &proc_dostring,
885 .strategy = &sysctl_string,
886 },
David Howells0b77f5b2008-04-29 01:01:32 -0700887#ifdef CONFIG_KEYS
888 {
889 .ctl_name = CTL_UNNUMBERED,
890 .procname = "keys",
891 .mode = 0555,
892 .child = key_sysctls,
893 },
894#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700895#ifdef CONFIG_RCU_TORTURE_TEST
896 {
897 .ctl_name = CTL_UNNUMBERED,
898 .procname = "rcutorture_runnable",
899 .data = &rcutorture_runnable,
900 .maxlen = sizeof(int),
901 .mode = 0644,
902 .proc_handler = &proc_dointvec,
903 },
904#endif
David Howells12e22c52009-04-03 16:42:35 +0100905#ifdef CONFIG_SLOW_WORK
906 {
907 .ctl_name = CTL_UNNUMBERED,
908 .procname = "slow-work",
909 .mode = 0555,
910 .child = slow_work_sysctls,
911 },
912#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700913/*
914 * NOTE: do not add new entries to this table unless you have read
915 * Documentation/sysctl/ctl_unnumbered.txt
916 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 { .ctl_name = 0 }
918};
919
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700920static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 {
922 .ctl_name = VM_OVERCOMMIT_MEMORY,
923 .procname = "overcommit_memory",
924 .data = &sysctl_overcommit_memory,
925 .maxlen = sizeof(sysctl_overcommit_memory),
926 .mode = 0644,
927 .proc_handler = &proc_dointvec,
928 },
929 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700930 .ctl_name = VM_PANIC_ON_OOM,
931 .procname = "panic_on_oom",
932 .data = &sysctl_panic_on_oom,
933 .maxlen = sizeof(sysctl_panic_on_oom),
934 .mode = 0644,
935 .proc_handler = &proc_dointvec,
936 },
937 {
David Rientjesfe071d72007-10-16 23:25:56 -0700938 .ctl_name = CTL_UNNUMBERED,
939 .procname = "oom_kill_allocating_task",
940 .data = &sysctl_oom_kill_allocating_task,
941 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
942 .mode = 0644,
943 .proc_handler = &proc_dointvec,
944 },
945 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800946 .ctl_name = CTL_UNNUMBERED,
947 .procname = "oom_dump_tasks",
948 .data = &sysctl_oom_dump_tasks,
949 .maxlen = sizeof(sysctl_oom_dump_tasks),
950 .mode = 0644,
951 .proc_handler = &proc_dointvec,
952 },
953 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 .ctl_name = VM_OVERCOMMIT_RATIO,
955 .procname = "overcommit_ratio",
956 .data = &sysctl_overcommit_ratio,
957 .maxlen = sizeof(sysctl_overcommit_ratio),
958 .mode = 0644,
959 .proc_handler = &proc_dointvec,
960 },
961 {
962 .ctl_name = VM_PAGE_CLUSTER,
963 .procname = "page-cluster",
964 .data = &page_cluster,
965 .maxlen = sizeof(int),
966 .mode = 0644,
967 .proc_handler = &proc_dointvec,
968 },
969 {
970 .ctl_name = VM_DIRTY_BACKGROUND,
971 .procname = "dirty_background_ratio",
972 .data = &dirty_background_ratio,
973 .maxlen = sizeof(dirty_background_ratio),
974 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800975 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 .strategy = &sysctl_intvec,
977 .extra1 = &zero,
978 .extra2 = &one_hundred,
979 },
980 {
David Rientjes2da02992009-01-06 14:39:31 -0800981 .ctl_name = CTL_UNNUMBERED,
982 .procname = "dirty_background_bytes",
983 .data = &dirty_background_bytes,
984 .maxlen = sizeof(dirty_background_bytes),
985 .mode = 0644,
986 .proc_handler = &dirty_background_bytes_handler,
987 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800988 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -0800989 },
990 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 .ctl_name = VM_DIRTY_RATIO,
992 .procname = "dirty_ratio",
993 .data = &vm_dirty_ratio,
994 .maxlen = sizeof(vm_dirty_ratio),
995 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700996 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 .strategy = &sysctl_intvec,
998 .extra1 = &zero,
999 .extra2 = &one_hundred,
1000 },
1001 {
David Rientjes2da02992009-01-06 14:39:31 -08001002 .ctl_name = CTL_UNNUMBERED,
1003 .procname = "dirty_bytes",
1004 .data = &vm_dirty_bytes,
1005 .maxlen = sizeof(vm_dirty_bytes),
1006 .mode = 0644,
1007 .proc_handler = &dirty_bytes_handler,
1008 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001009 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001010 },
1011 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001013 .data = &dirty_writeback_interval,
1014 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .mode = 0644,
1016 .proc_handler = &dirty_writeback_centisecs_handler,
1017 },
1018 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001020 .data = &dirty_expire_interval,
1021 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001023 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 },
1025 {
1026 .ctl_name = VM_NR_PDFLUSH_THREADS,
1027 .procname = "nr_pdflush_threads",
1028 .data = &nr_pdflush_threads,
1029 .maxlen = sizeof nr_pdflush_threads,
1030 .mode = 0444 /* read-only*/,
1031 .proc_handler = &proc_dointvec,
1032 },
1033 {
Peter W Morrealefafd6882009-04-06 19:00:29 -07001034 .ctl_name = CTL_UNNUMBERED,
1035 .procname = "nr_pdflush_threads_min",
1036 .data = &nr_pdflush_threads_min,
1037 .maxlen = sizeof nr_pdflush_threads_min,
1038 .mode = 0644 /* read-write */,
1039 .proc_handler = &proc_dointvec_minmax,
1040 .strategy = &sysctl_intvec,
1041 .extra1 = &one,
1042 .extra2 = &nr_pdflush_threads_max,
1043 },
1044 {
1045 .ctl_name = CTL_UNNUMBERED,
1046 .procname = "nr_pdflush_threads_max",
1047 .data = &nr_pdflush_threads_max,
1048 .maxlen = sizeof nr_pdflush_threads_max,
1049 .mode = 0644 /* read-write */,
1050 .proc_handler = &proc_dointvec_minmax,
1051 .strategy = &sysctl_intvec,
1052 .extra1 = &nr_pdflush_threads_min,
1053 .extra2 = &one_thousand,
1054 },
1055 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 .ctl_name = VM_SWAPPINESS,
1057 .procname = "swappiness",
1058 .data = &vm_swappiness,
1059 .maxlen = sizeof(vm_swappiness),
1060 .mode = 0644,
1061 .proc_handler = &proc_dointvec_minmax,
1062 .strategy = &sysctl_intvec,
1063 .extra1 = &zero,
1064 .extra2 = &one_hundred,
1065 },
1066#ifdef CONFIG_HUGETLB_PAGE
1067 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001069 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 .maxlen = sizeof(unsigned long),
1071 .mode = 0644,
1072 .proc_handler = &hugetlb_sysctl_handler,
1073 .extra1 = (void *)&hugetlb_zero,
1074 .extra2 = (void *)&hugetlb_infinity,
1075 },
1076 {
1077 .ctl_name = VM_HUGETLB_GROUP,
1078 .procname = "hugetlb_shm_group",
1079 .data = &sysctl_hugetlb_shm_group,
1080 .maxlen = sizeof(gid_t),
1081 .mode = 0644,
1082 .proc_handler = &proc_dointvec,
1083 },
Mel Gorman396faf02007-07-17 04:03:13 -07001084 {
1085 .ctl_name = CTL_UNNUMBERED,
1086 .procname = "hugepages_treat_as_movable",
1087 .data = &hugepages_treat_as_movable,
1088 .maxlen = sizeof(int),
1089 .mode = 0644,
1090 .proc_handler = &hugetlb_treat_movable_handler,
1091 },
Adam Litke54f9f802007-10-16 01:26:20 -07001092 {
1093 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001094 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001095 .data = NULL,
1096 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001097 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001098 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001099 .extra1 = (void *)&hugetlb_zero,
1100 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001101 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102#endif
1103 {
1104 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1105 .procname = "lowmem_reserve_ratio",
1106 .data = &sysctl_lowmem_reserve_ratio,
1107 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1108 .mode = 0644,
1109 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1110 .strategy = &sysctl_intvec,
1111 },
1112 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001113 .ctl_name = VM_DROP_PAGECACHE,
1114 .procname = "drop_caches",
1115 .data = &sysctl_drop_caches,
1116 .maxlen = sizeof(int),
1117 .mode = 0644,
1118 .proc_handler = drop_caches_sysctl_handler,
1119 .strategy = &sysctl_intvec,
1120 },
1121 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 .ctl_name = VM_MIN_FREE_KBYTES,
1123 .procname = "min_free_kbytes",
1124 .data = &min_free_kbytes,
1125 .maxlen = sizeof(min_free_kbytes),
1126 .mode = 0644,
1127 .proc_handler = &min_free_kbytes_sysctl_handler,
1128 .strategy = &sysctl_intvec,
1129 .extra1 = &zero,
1130 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001131 {
1132 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1133 .procname = "percpu_pagelist_fraction",
1134 .data = &percpu_pagelist_fraction,
1135 .maxlen = sizeof(percpu_pagelist_fraction),
1136 .mode = 0644,
1137 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1138 .strategy = &sysctl_intvec,
1139 .extra1 = &min_percpu_pagelist_fract,
1140 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141#ifdef CONFIG_MMU
1142 {
1143 .ctl_name = VM_MAX_MAP_COUNT,
1144 .procname = "max_map_count",
1145 .data = &sysctl_max_map_count,
1146 .maxlen = sizeof(sysctl_max_map_count),
1147 .mode = 0644,
1148 .proc_handler = &proc_dointvec
1149 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001150#else
1151 {
1152 .ctl_name = CTL_UNNUMBERED,
1153 .procname = "nr_trim_pages",
1154 .data = &sysctl_nr_trim_pages,
1155 .maxlen = sizeof(sysctl_nr_trim_pages),
1156 .mode = 0644,
1157 .proc_handler = &proc_dointvec_minmax,
1158 .strategy = &sysctl_intvec,
1159 .extra1 = &zero,
1160 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161#endif
1162 {
1163 .ctl_name = VM_LAPTOP_MODE,
1164 .procname = "laptop_mode",
1165 .data = &laptop_mode,
1166 .maxlen = sizeof(laptop_mode),
1167 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001168 .proc_handler = &proc_dointvec_jiffies,
1169 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 },
1171 {
1172 .ctl_name = VM_BLOCK_DUMP,
1173 .procname = "block_dump",
1174 .data = &block_dump,
1175 .maxlen = sizeof(block_dump),
1176 .mode = 0644,
1177 .proc_handler = &proc_dointvec,
1178 .strategy = &sysctl_intvec,
1179 .extra1 = &zero,
1180 },
1181 {
1182 .ctl_name = VM_VFS_CACHE_PRESSURE,
1183 .procname = "vfs_cache_pressure",
1184 .data = &sysctl_vfs_cache_pressure,
1185 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1186 .mode = 0644,
1187 .proc_handler = &proc_dointvec,
1188 .strategy = &sysctl_intvec,
1189 .extra1 = &zero,
1190 },
1191#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1192 {
1193 .ctl_name = VM_LEGACY_VA_LAYOUT,
1194 .procname = "legacy_va_layout",
1195 .data = &sysctl_legacy_va_layout,
1196 .maxlen = sizeof(sysctl_legacy_va_layout),
1197 .mode = 0644,
1198 .proc_handler = &proc_dointvec,
1199 .strategy = &sysctl_intvec,
1200 .extra1 = &zero,
1201 },
1202#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001203#ifdef CONFIG_NUMA
1204 {
1205 .ctl_name = VM_ZONE_RECLAIM_MODE,
1206 .procname = "zone_reclaim_mode",
1207 .data = &zone_reclaim_mode,
1208 .maxlen = sizeof(zone_reclaim_mode),
1209 .mode = 0644,
1210 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001211 .strategy = &sysctl_intvec,
1212 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001213 },
Christoph Lameter96146342006-07-03 00:24:13 -07001214 {
1215 .ctl_name = VM_MIN_UNMAPPED,
1216 .procname = "min_unmapped_ratio",
1217 .data = &sysctl_min_unmapped_ratio,
1218 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1219 .mode = 0644,
1220 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1221 .strategy = &sysctl_intvec,
1222 .extra1 = &zero,
1223 .extra2 = &one_hundred,
1224 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001225 {
1226 .ctl_name = VM_MIN_SLAB,
1227 .procname = "min_slab_ratio",
1228 .data = &sysctl_min_slab_ratio,
1229 .maxlen = sizeof(sysctl_min_slab_ratio),
1230 .mode = 0644,
1231 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1232 .strategy = &sysctl_intvec,
1233 .extra1 = &zero,
1234 .extra2 = &one_hundred,
1235 },
Christoph Lameter17436602006-01-18 17:42:32 -08001236#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001237#ifdef CONFIG_SMP
1238 {
1239 .ctl_name = CTL_UNNUMBERED,
1240 .procname = "stat_interval",
1241 .data = &sysctl_stat_interval,
1242 .maxlen = sizeof(sysctl_stat_interval),
1243 .mode = 0644,
1244 .proc_handler = &proc_dointvec_jiffies,
1245 .strategy = &sysctl_jiffies,
1246 },
1247#endif
Eric Parised032182007-06-28 15:55:21 -04001248#ifdef CONFIG_SECURITY
1249 {
1250 .ctl_name = CTL_UNNUMBERED,
1251 .procname = "mmap_min_addr",
1252 .data = &mmap_min_addr,
1253 .maxlen = sizeof(unsigned long),
1254 .mode = 0644,
1255 .proc_handler = &proc_doulongvec_minmax,
1256 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001257#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001258#ifdef CONFIG_NUMA
1259 {
1260 .ctl_name = CTL_UNNUMBERED,
1261 .procname = "numa_zonelist_order",
1262 .data = &numa_zonelist_order,
1263 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1264 .mode = 0644,
1265 .proc_handler = &numa_zonelist_order_handler,
1266 .strategy = &sysctl_string,
1267 },
1268#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001269#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001270 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001271 {
1272 .ctl_name = VM_VDSO_ENABLED,
1273 .procname = "vdso_enabled",
1274 .data = &vdso_enabled,
1275 .maxlen = sizeof(vdso_enabled),
1276 .mode = 0644,
1277 .proc_handler = &proc_dointvec,
1278 .strategy = &sysctl_intvec,
1279 .extra1 = &zero,
1280 },
1281#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001282#ifdef CONFIG_HIGHMEM
1283 {
1284 .ctl_name = CTL_UNNUMBERED,
1285 .procname = "highmem_is_dirtyable",
1286 .data = &vm_highmem_is_dirtyable,
1287 .maxlen = sizeof(vm_highmem_is_dirtyable),
1288 .mode = 0644,
1289 .proc_handler = &proc_dointvec_minmax,
1290 .strategy = &sysctl_intvec,
1291 .extra1 = &zero,
1292 .extra2 = &one,
1293 },
1294#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001295#ifdef CONFIG_UNEVICTABLE_LRU
1296 {
1297 .ctl_name = CTL_UNNUMBERED,
1298 .procname = "scan_unevictable_pages",
1299 .data = &scan_unevictable_pages,
1300 .maxlen = sizeof(scan_unevictable_pages),
1301 .mode = 0644,
1302 .proc_handler = &scan_unevictable_handler,
1303 },
1304#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001305/*
1306 * NOTE: do not add new entries to this table unless you have read
1307 * Documentation/sysctl/ctl_unnumbered.txt
1308 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 { .ctl_name = 0 }
1310};
1311
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001312#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001313static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001314 { .ctl_name = 0 }
1315};
1316#endif
1317
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001318static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 {
1320 .ctl_name = FS_NRINODE,
1321 .procname = "inode-nr",
1322 .data = &inodes_stat,
1323 .maxlen = 2*sizeof(int),
1324 .mode = 0444,
1325 .proc_handler = &proc_dointvec,
1326 },
1327 {
1328 .ctl_name = FS_STATINODE,
1329 .procname = "inode-state",
1330 .data = &inodes_stat,
1331 .maxlen = 7*sizeof(int),
1332 .mode = 0444,
1333 .proc_handler = &proc_dointvec,
1334 },
1335 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 .procname = "file-nr",
1337 .data = &files_stat,
1338 .maxlen = 3*sizeof(int),
1339 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001340 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 },
1342 {
1343 .ctl_name = FS_MAXFILE,
1344 .procname = "file-max",
1345 .data = &files_stat.max_files,
1346 .maxlen = sizeof(int),
1347 .mode = 0644,
1348 .proc_handler = &proc_dointvec,
1349 },
1350 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001351 .ctl_name = CTL_UNNUMBERED,
1352 .procname = "nr_open",
1353 .data = &sysctl_nr_open,
1354 .maxlen = sizeof(int),
1355 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001356 .proc_handler = &proc_dointvec_minmax,
1357 .extra1 = &sysctl_nr_open_min,
1358 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001359 },
1360 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .ctl_name = FS_DENTRY,
1362 .procname = "dentry-state",
1363 .data = &dentry_stat,
1364 .maxlen = 6*sizeof(int),
1365 .mode = 0444,
1366 .proc_handler = &proc_dointvec,
1367 },
1368 {
1369 .ctl_name = FS_OVERFLOWUID,
1370 .procname = "overflowuid",
1371 .data = &fs_overflowuid,
1372 .maxlen = sizeof(int),
1373 .mode = 0644,
1374 .proc_handler = &proc_dointvec_minmax,
1375 .strategy = &sysctl_intvec,
1376 .extra1 = &minolduid,
1377 .extra2 = &maxolduid,
1378 },
1379 {
1380 .ctl_name = FS_OVERFLOWGID,
1381 .procname = "overflowgid",
1382 .data = &fs_overflowgid,
1383 .maxlen = sizeof(int),
1384 .mode = 0644,
1385 .proc_handler = &proc_dointvec_minmax,
1386 .strategy = &sysctl_intvec,
1387 .extra1 = &minolduid,
1388 .extra2 = &maxolduid,
1389 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001390#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 {
1392 .ctl_name = FS_LEASES,
1393 .procname = "leases-enable",
1394 .data = &leases_enable,
1395 .maxlen = sizeof(int),
1396 .mode = 0644,
1397 .proc_handler = &proc_dointvec,
1398 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001399#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400#ifdef CONFIG_DNOTIFY
1401 {
1402 .ctl_name = FS_DIR_NOTIFY,
1403 .procname = "dir-notify-enable",
1404 .data = &dir_notify_enable,
1405 .maxlen = sizeof(int),
1406 .mode = 0644,
1407 .proc_handler = &proc_dointvec,
1408 },
1409#endif
1410#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001411#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 {
1413 .ctl_name = FS_LEASE_TIME,
1414 .procname = "lease-break-time",
1415 .data = &lease_break_time,
1416 .maxlen = sizeof(int),
1417 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001418 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001420#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001421#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .procname = "aio-nr",
1424 .data = &aio_nr,
1425 .maxlen = sizeof(aio_nr),
1426 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001427 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 },
1429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .procname = "aio-max-nr",
1431 .data = &aio_max_nr,
1432 .maxlen = sizeof(aio_max_nr),
1433 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001434 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001436#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001437#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001438 {
1439 .ctl_name = FS_INOTIFY,
1440 .procname = "inotify",
1441 .mode = 0555,
1442 .child = inotify_table,
1443 },
1444#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001445#ifdef CONFIG_EPOLL
1446 {
1447 .procname = "epoll",
1448 .mode = 0555,
1449 .child = epoll_table,
1450 },
1451#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001453 {
1454 .ctl_name = KERN_SETUID_DUMPABLE,
1455 .procname = "suid_dumpable",
1456 .data = &suid_dumpable,
1457 .maxlen = sizeof(int),
1458 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001459 .proc_handler = &proc_dointvec_minmax,
1460 .strategy = &sysctl_intvec,
1461 .extra1 = &zero,
1462 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001463 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001464#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1465 {
1466 .ctl_name = CTL_UNNUMBERED,
1467 .procname = "binfmt_misc",
1468 .mode = 0555,
1469 .child = binfmt_misc_table,
1470 },
1471#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001472/*
1473 * NOTE: do not add new entries to this table unless you have read
1474 * Documentation/sysctl/ctl_unnumbered.txt
1475 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 { .ctl_name = 0 }
1477};
1478
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001479static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001480#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001481 {
1482 .ctl_name = CTL_UNNUMBERED,
1483 .procname = "exception-trace",
1484 .data = &show_unhandled_signals,
1485 .maxlen = sizeof(int),
1486 .mode = 0644,
1487 .proc_handler = proc_dointvec
1488 },
1489#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 { .ctl_name = 0 }
1491};
1492
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001493static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001495};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Al Viro330d57f2005-11-04 10:18:40 +00001497static DEFINE_SPINLOCK(sysctl_lock);
1498
1499/* called under sysctl_lock */
1500static int use_table(struct ctl_table_header *p)
1501{
1502 if (unlikely(p->unregistering))
1503 return 0;
1504 p->used++;
1505 return 1;
1506}
1507
1508/* called under sysctl_lock */
1509static void unuse_table(struct ctl_table_header *p)
1510{
1511 if (!--p->used)
1512 if (unlikely(p->unregistering))
1513 complete(p->unregistering);
1514}
1515
1516/* called under sysctl_lock, will reacquire if has to wait */
1517static void start_unregistering(struct ctl_table_header *p)
1518{
1519 /*
1520 * if p->used is 0, nobody will ever touch that entry again;
1521 * we'll eliminate all paths to it before dropping sysctl_lock
1522 */
1523 if (unlikely(p->used)) {
1524 struct completion wait;
1525 init_completion(&wait);
1526 p->unregistering = &wait;
1527 spin_unlock(&sysctl_lock);
1528 wait_for_completion(&wait);
1529 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001530 } else {
1531 /* anything non-NULL; we'll never dereference it */
1532 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001533 }
1534 /*
1535 * do not remove from the list until nobody holds it; walking the
1536 * list in do_sysctl() relies on that.
1537 */
1538 list_del_init(&p->ctl_entry);
1539}
1540
Al Virof7e6ced2008-07-15 01:44:23 -04001541void sysctl_head_get(struct ctl_table_header *head)
1542{
1543 spin_lock(&sysctl_lock);
1544 head->count++;
1545 spin_unlock(&sysctl_lock);
1546}
1547
1548void sysctl_head_put(struct ctl_table_header *head)
1549{
1550 spin_lock(&sysctl_lock);
1551 if (!--head->count)
1552 kfree(head);
1553 spin_unlock(&sysctl_lock);
1554}
1555
1556struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1557{
1558 if (!head)
1559 BUG();
1560 spin_lock(&sysctl_lock);
1561 if (!use_table(head))
1562 head = ERR_PTR(-ENOENT);
1563 spin_unlock(&sysctl_lock);
1564 return head;
1565}
1566
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001567void sysctl_head_finish(struct ctl_table_header *head)
1568{
1569 if (!head)
1570 return;
1571 spin_lock(&sysctl_lock);
1572 unuse_table(head);
1573 spin_unlock(&sysctl_lock);
1574}
1575
Al Viro73455092008-07-14 21:22:20 -04001576static struct ctl_table_set *
1577lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1578{
1579 struct ctl_table_set *set = &root->default_set;
1580 if (root->lookup)
1581 set = root->lookup(root, namespaces);
1582 return set;
1583}
1584
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001585static struct list_head *
1586lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001587{
Al Viro73455092008-07-14 21:22:20 -04001588 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1589 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001590}
1591
1592struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1593 struct ctl_table_header *prev)
1594{
1595 struct ctl_table_root *root;
1596 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001597 struct ctl_table_header *head;
1598 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001599
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001600 spin_lock(&sysctl_lock);
1601 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001602 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001603 tmp = &prev->ctl_entry;
1604 unuse_table(prev);
1605 goto next;
1606 }
1607 tmp = &root_table_header.ctl_entry;
1608 for (;;) {
1609 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1610
1611 if (!use_table(head))
1612 goto next;
1613 spin_unlock(&sysctl_lock);
1614 return head;
1615 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001616 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001617 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001618 header_list = lookup_header_list(root, namespaces);
1619 if (tmp != header_list)
1620 continue;
1621
1622 do {
1623 root = list_entry(root->root_list.next,
1624 struct ctl_table_root, root_list);
1625 if (root == &sysctl_table_root)
1626 goto out;
1627 header_list = lookup_header_list(root, namespaces);
1628 } while (list_empty(header_list));
1629 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001630 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001631out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001632 spin_unlock(&sysctl_lock);
1633 return NULL;
1634}
1635
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001636struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1637{
1638 return __sysctl_head_next(current->nsproxy, prev);
1639}
1640
1641void register_sysctl_root(struct ctl_table_root *root)
1642{
1643 spin_lock(&sysctl_lock);
1644 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1645 spin_unlock(&sysctl_lock);
1646}
1647
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001648#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001649/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001650static int do_sysctl_strategy(struct ctl_table_root *root,
1651 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001652 void __user *oldval, size_t __user *oldlenp,
1653 void __user *newval, size_t newlen)
1654{
1655 int op = 0, rc;
1656
1657 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001658 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001659 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001660 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001661 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001662 return -EPERM;
1663
1664 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001665 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001666 if (rc < 0)
1667 return rc;
1668 if (rc > 0)
1669 return 0;
1670 }
1671
1672 /* If there is no strategy routine, or if the strategy returns
1673 * zero, proceed with automatic r/w */
1674 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001675 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001676 if (rc < 0)
1677 return rc;
1678 }
1679 return 0;
1680}
1681
1682static int parse_table(int __user *name, int nlen,
1683 void __user *oldval, size_t __user *oldlenp,
1684 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001685 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001686 struct ctl_table *table)
1687{
1688 int n;
1689repeat:
1690 if (!nlen)
1691 return -ENOTDIR;
1692 if (get_user(n, name))
1693 return -EFAULT;
1694 for ( ; table->ctl_name || table->procname; table++) {
1695 if (!table->ctl_name)
1696 continue;
1697 if (n == table->ctl_name) {
1698 int error;
1699 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001700 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001701 return -EPERM;
1702 name++;
1703 nlen--;
1704 table = table->child;
1705 goto repeat;
1706 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001707 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001708 oldval, oldlenp,
1709 newval, newlen);
1710 return error;
1711 }
1712 }
1713 return -ENOTDIR;
1714}
1715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1717 void __user *newval, size_t newlen)
1718{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001719 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001720 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
1722 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1723 return -ENOTDIR;
1724 if (oldval) {
1725 int old_len;
1726 if (!oldlenp || get_user(old_len, oldlenp))
1727 return -EFAULT;
1728 }
Al Viro330d57f2005-11-04 10:18:40 +00001729
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001730 for (head = sysctl_head_next(NULL); head;
1731 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001732 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001733 newval, newlen,
1734 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001735 if (error != -ENOTDIR) {
1736 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001737 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001738 }
1739 }
Al Viro330d57f2005-11-04 10:18:40 +00001740 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741}
1742
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001743SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744{
1745 struct __sysctl_args tmp;
1746 int error;
1747
1748 if (copy_from_user(&tmp, args, sizeof(tmp)))
1749 return -EFAULT;
1750
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001751 error = deprecated_sysctl_warning(&tmp);
1752 if (error)
1753 goto out;
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 lock_kernel();
1756 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1757 tmp.newval, tmp.newlen);
1758 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001759out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 return error;
1761}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001762#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763
1764/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001765 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 * some sysctl variables are readonly even to root.
1767 */
1768
1769static int test_perm(int mode, int op)
1770{
David Howells76aac0e2008-11-14 10:39:12 +11001771 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 mode >>= 6;
1773 else if (in_egroup_p(0))
1774 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001775 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 return 0;
1777 return -EACCES;
1778}
1779
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001780int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001783 int mode;
1784
Al Viroe6305c42008-07-15 21:03:57 -04001785 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 if (error)
1787 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001788
1789 if (root->permissions)
1790 mode = root->permissions(root, current->nsproxy, table);
1791 else
1792 mode = table->mode;
1793
1794 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795}
1796
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001797static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1798{
1799 for (; table->ctl_name || table->procname; table++) {
1800 table->parent = parent;
1801 if (table->child)
1802 sysctl_set_parent(table, table->child);
1803 }
1804}
1805
1806static __init int sysctl_init(void)
1807{
1808 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001809#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1810 {
1811 int err;
1812 err = sysctl_check_table(current->nsproxy, root_table);
1813 }
1814#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001815 return 0;
1816}
1817
1818core_initcall(sysctl_init);
1819
Al Virobfbcf032008-07-27 06:31:22 +01001820static struct ctl_table *is_branch_in(struct ctl_table *branch,
1821 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001822{
1823 struct ctl_table *p;
1824 const char *s = branch->procname;
1825
1826 /* branch should have named subdirectory as its first element */
1827 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001828 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001829
1830 /* ... and nothing else */
1831 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001832 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001833
1834 /* table should contain subdirectory with the same name */
1835 for (p = table; p->procname || p->ctl_name; p++) {
1836 if (!p->child)
1837 continue;
1838 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001839 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001840 }
Al Virobfbcf032008-07-27 06:31:22 +01001841 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001842}
1843
1844/* see if attaching q to p would be an improvement */
1845static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1846{
1847 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001848 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001849 int is_better = 0;
1850 int not_in_parent = !p->attached_by;
1851
Al Virobfbcf032008-07-27 06:31:22 +01001852 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001853 if (by == q->attached_by)
1854 is_better = 1;
1855 if (to == p->attached_by)
1856 not_in_parent = 1;
1857 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001858 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001859 }
1860
1861 if (is_better && not_in_parent) {
1862 q->attached_by = by;
1863 q->attached_to = to;
1864 q->parent = p;
1865 }
1866}
1867
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001869 * __register_sysctl_paths - register a sysctl hierarchy
1870 * @root: List of sysctl headers to register on
1871 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001872 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 *
1875 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001876 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001878 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 *
1880 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1881 * must be unique within that level of sysctl
1882 *
1883 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1884 * enter a sysctl file
1885 *
1886 * data - a pointer to data for use by proc_handler
1887 *
1888 * maxlen - the maximum size in bytes of the data
1889 *
1890 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1891 *
1892 * child - a pointer to the child sysctl table if this entry is a directory, or
1893 * %NULL.
1894 *
1895 * proc_handler - the text handler routine (described below)
1896 *
1897 * strategy - the strategy routine (described below)
1898 *
1899 * de - for internal use by the sysctl routines
1900 *
1901 * extra1, extra2 - extra pointers usable by the proc handler routines
1902 *
1903 * Leaf nodes in the sysctl tree will be represented by a single file
1904 * under /proc; non-leaf nodes will be represented by directories.
1905 *
1906 * sysctl(2) can automatically manage read and write requests through
1907 * the sysctl table. The data and maxlen fields of the ctl_table
1908 * struct enable minimal validation of the values being written to be
1909 * performed, and the mode field allows minimal authentication.
1910 *
1911 * More sophisticated management can be enabled by the provision of a
1912 * strategy routine with the table entry. This will be called before
1913 * any automatic read or write of the data is performed.
1914 *
1915 * The strategy routine may return
1916 *
1917 * < 0 - Error occurred (error is passed to user process)
1918 *
1919 * 0 - OK - proceed with automatic read or write.
1920 *
1921 * > 0 - OK - read or write has been done by the strategy routine, so
1922 * return immediately.
1923 *
1924 * There must be a proc_handler routine for any terminal nodes
1925 * mirrored under /proc/sys (non-terminals are handled by a built-in
1926 * directory handler). Several default handlers are available to
1927 * cover common cases -
1928 *
1929 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1930 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1931 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1932 *
1933 * It is the handler's job to read the input buffer from user memory
1934 * and process it. The handler should return 0 on success.
1935 *
1936 * This routine returns %NULL on a failure to register, and a pointer
1937 * to the table header on success.
1938 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001939struct ctl_table_header *__register_sysctl_paths(
1940 struct ctl_table_root *root,
1941 struct nsproxy *namespaces,
1942 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001944 struct ctl_table_header *header;
1945 struct ctl_table *new, **prevp;
1946 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001947 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001948
1949 /* Count the path components */
1950 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1951 ;
1952
1953 /*
1954 * For each path component, allocate a 2-element ctl_table array.
1955 * The first array element will be filled with the sysctl entry
1956 * for this, the second will be the sentinel (ctl_name == 0).
1957 *
1958 * We allocate everything in one go so that we don't have to
1959 * worry about freeing additional memory in unregister_sysctl_table.
1960 */
1961 header = kzalloc(sizeof(struct ctl_table_header) +
1962 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1963 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001965
1966 new = (struct ctl_table *) (header + 1);
1967
1968 /* Now connect the dots */
1969 prevp = &header->ctl_table;
1970 for (n = 0; n < npath; ++n, ++path) {
1971 /* Copy the procname */
1972 new->procname = path->procname;
1973 new->ctl_name = path->ctl_name;
1974 new->mode = 0555;
1975
1976 *prevp = new;
1977 prevp = &new->child;
1978
1979 new += 2;
1980 }
1981 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001982 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001983
1984 INIT_LIST_HEAD(&header->ctl_entry);
1985 header->used = 0;
1986 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001987 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001988 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001989 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001990#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001991 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001992 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001993 return NULL;
1994 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001995#endif
Al Viro330d57f2005-11-04 10:18:40 +00001996 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001997 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001998 header->attached_by = header->ctl_table;
1999 header->attached_to = root_table;
2000 header->parent = &root_table_header;
2001 for (set = header->set; set; set = set->parent) {
2002 struct ctl_table_header *p;
2003 list_for_each_entry(p, &set->list, ctl_entry) {
2004 if (p->unregistering)
2005 continue;
2006 try_attach(p, header);
2007 }
2008 }
2009 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002010 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002011 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002012
2013 return header;
2014}
2015
2016/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002017 * register_sysctl_table_path - register a sysctl table hierarchy
2018 * @path: The path to the directory the sysctl table is in.
2019 * @table: the top-level table structure
2020 *
2021 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2022 * array. A completely 0 filled entry terminates the table.
2023 *
2024 * See __register_sysctl_paths for more details.
2025 */
2026struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2027 struct ctl_table *table)
2028{
2029 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2030 path, table);
2031}
2032
2033/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002034 * register_sysctl_table - register a sysctl table hierarchy
2035 * @table: the top-level table structure
2036 *
2037 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2038 * array. A completely 0 filled entry terminates the table.
2039 *
2040 * See register_sysctl_paths for more details.
2041 */
2042struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2043{
2044 static const struct ctl_path null_path[] = { {} };
2045
2046 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047}
2048
2049/**
2050 * unregister_sysctl_table - unregister a sysctl table hierarchy
2051 * @header: the header returned from register_sysctl_table
2052 *
2053 * Unregisters the sysctl table and all children. proc entries may not
2054 * actually be removed until they are no longer used by anyone.
2055 */
2056void unregister_sysctl_table(struct ctl_table_header * header)
2057{
Al Viro330d57f2005-11-04 10:18:40 +00002058 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002059
2060 if (header == NULL)
2061 return;
2062
Al Viro330d57f2005-11-04 10:18:40 +00002063 spin_lock(&sysctl_lock);
2064 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002065 if (!--header->parent->count) {
2066 WARN_ON(1);
2067 kfree(header->parent);
2068 }
Al Virof7e6ced2008-07-15 01:44:23 -04002069 if (!--header->count)
2070 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002071 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072}
2073
Al Viro90434762008-07-15 08:54:06 -04002074int sysctl_is_seen(struct ctl_table_header *p)
2075{
2076 struct ctl_table_set *set = p->set;
2077 int res;
2078 spin_lock(&sysctl_lock);
2079 if (p->unregistering)
2080 res = 0;
2081 else if (!set->is_seen)
2082 res = 1;
2083 else
2084 res = set->is_seen(set);
2085 spin_unlock(&sysctl_lock);
2086 return res;
2087}
2088
Al Viro73455092008-07-14 21:22:20 -04002089void setup_sysctl_set(struct ctl_table_set *p,
2090 struct ctl_table_set *parent,
2091 int (*is_seen)(struct ctl_table_set *))
2092{
2093 INIT_LIST_HEAD(&p->list);
2094 p->parent = parent ? parent : &sysctl_table_root.default_set;
2095 p->is_seen = is_seen;
2096}
2097
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002098#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002099struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002100{
2101 return NULL;
2102}
2103
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002104struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2105 struct ctl_table *table)
2106{
2107 return NULL;
2108}
2109
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002110void unregister_sysctl_table(struct ctl_table_header * table)
2111{
2112}
2113
Al Viro73455092008-07-14 21:22:20 -04002114void setup_sysctl_set(struct ctl_table_set *p,
2115 struct ctl_table_set *parent,
2116 int (*is_seen)(struct ctl_table_set *))
2117{
2118}
2119
Al Virof7e6ced2008-07-15 01:44:23 -04002120void sysctl_head_put(struct ctl_table_header *head)
2121{
2122}
2123
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002124#endif /* CONFIG_SYSCTL */
2125
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126/*
2127 * /proc/sys support
2128 */
2129
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002130#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002132static int _proc_do_string(void* data, int maxlen, int write,
2133 struct file *filp, void __user *buffer,
2134 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002135{
2136 size_t len;
2137 char __user *p;
2138 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002139
2140 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002141 *lenp = 0;
2142 return 0;
2143 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002144
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002145 if (write) {
2146 len = 0;
2147 p = buffer;
2148 while (len < *lenp) {
2149 if (get_user(c, p++))
2150 return -EFAULT;
2151 if (c == 0 || c == '\n')
2152 break;
2153 len++;
2154 }
2155 if (len >= maxlen)
2156 len = maxlen-1;
2157 if(copy_from_user(data, buffer, len))
2158 return -EFAULT;
2159 ((char *) data)[len] = 0;
2160 *ppos += *lenp;
2161 } else {
2162 len = strlen(data);
2163 if (len > maxlen)
2164 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002165
2166 if (*ppos > len) {
2167 *lenp = 0;
2168 return 0;
2169 }
2170
2171 data += *ppos;
2172 len -= *ppos;
2173
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002174 if (len > *lenp)
2175 len = *lenp;
2176 if (len)
2177 if(copy_to_user(buffer, data, len))
2178 return -EFAULT;
2179 if (len < *lenp) {
2180 if(put_user('\n', ((char __user *) buffer) + len))
2181 return -EFAULT;
2182 len++;
2183 }
2184 *lenp = len;
2185 *ppos += len;
2186 }
2187 return 0;
2188}
2189
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190/**
2191 * proc_dostring - read a string sysctl
2192 * @table: the sysctl table
2193 * @write: %TRUE if this is a write to the sysctl file
2194 * @filp: the file structure
2195 * @buffer: the user buffer
2196 * @lenp: the size of the user buffer
2197 * @ppos: file position
2198 *
2199 * Reads/writes a string from/to the user buffer. If the kernel
2200 * buffer provided is not large enough to hold the string, the
2201 * string is truncated. The copied string is %NULL-terminated.
2202 * If the string is being read by the user process, it is copied
2203 * and a newline '\n' is added. It is truncated if the buffer is
2204 * not large enough.
2205 *
2206 * Returns 0 on success.
2207 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002208int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 void __user *buffer, size_t *lenp, loff_t *ppos)
2210{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002211 return _proc_do_string(table->data, table->maxlen, write, filp,
2212 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213}
2214
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
2216static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2217 int *valp,
2218 int write, void *data)
2219{
2220 if (write) {
2221 *valp = *negp ? -*lvalp : *lvalp;
2222 } else {
2223 int val = *valp;
2224 if (val < 0) {
2225 *negp = -1;
2226 *lvalp = (unsigned long)-val;
2227 } else {
2228 *negp = 0;
2229 *lvalp = (unsigned long)val;
2230 }
2231 }
2232 return 0;
2233}
2234
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002235static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002236 int write, struct file *filp, void __user *buffer,
2237 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2239 int write, void *data),
2240 void *data)
2241{
2242#define TMPBUFLEN 21
2243 int *i, vleft, first=1, neg, val;
2244 unsigned long lval;
2245 size_t left, len;
2246
2247 char buf[TMPBUFLEN], *p;
2248 char __user *s = buffer;
2249
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002250 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 (*ppos && !write)) {
2252 *lenp = 0;
2253 return 0;
2254 }
2255
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002256 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 vleft = table->maxlen / sizeof(*i);
2258 left = *lenp;
2259
2260 if (!conv)
2261 conv = do_proc_dointvec_conv;
2262
2263 for (; left && vleft--; i++, first=0) {
2264 if (write) {
2265 while (left) {
2266 char c;
2267 if (get_user(c, s))
2268 return -EFAULT;
2269 if (!isspace(c))
2270 break;
2271 left--;
2272 s++;
2273 }
2274 if (!left)
2275 break;
2276 neg = 0;
2277 len = left;
2278 if (len > sizeof(buf) - 1)
2279 len = sizeof(buf) - 1;
2280 if (copy_from_user(buf, s, len))
2281 return -EFAULT;
2282 buf[len] = 0;
2283 p = buf;
2284 if (*p == '-' && left > 1) {
2285 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002286 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 }
2288 if (*p < '0' || *p > '9')
2289 break;
2290
2291 lval = simple_strtoul(p, &p, 0);
2292
2293 len = p-buf;
2294 if ((len < left) && *p && !isspace(*p))
2295 break;
2296 if (neg)
2297 val = -val;
2298 s += len;
2299 left -= len;
2300
2301 if (conv(&neg, &lval, i, 1, data))
2302 break;
2303 } else {
2304 p = buf;
2305 if (!first)
2306 *p++ = '\t';
2307
2308 if (conv(&neg, &lval, i, 0, data))
2309 break;
2310
2311 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2312 len = strlen(buf);
2313 if (len > left)
2314 len = left;
2315 if(copy_to_user(s, buf, len))
2316 return -EFAULT;
2317 left -= len;
2318 s += len;
2319 }
2320 }
2321
2322 if (!write && !first && left) {
2323 if(put_user('\n', s))
2324 return -EFAULT;
2325 left--, s++;
2326 }
2327 if (write) {
2328 while (left) {
2329 char c;
2330 if (get_user(c, s++))
2331 return -EFAULT;
2332 if (!isspace(c))
2333 break;
2334 left--;
2335 }
2336 }
2337 if (write && first)
2338 return -EINVAL;
2339 *lenp -= left;
2340 *ppos += *lenp;
2341 return 0;
2342#undef TMPBUFLEN
2343}
2344
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002345static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002346 void __user *buffer, size_t *lenp, loff_t *ppos,
2347 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2348 int write, void *data),
2349 void *data)
2350{
2351 return __do_proc_dointvec(table->data, table, write, filp,
2352 buffer, lenp, ppos, conv, data);
2353}
2354
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355/**
2356 * proc_dointvec - read a vector of integers
2357 * @table: the sysctl table
2358 * @write: %TRUE if this is a write to the sysctl file
2359 * @filp: the file structure
2360 * @buffer: the user buffer
2361 * @lenp: the size of the user buffer
2362 * @ppos: file position
2363 *
2364 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2365 * values from/to the user buffer, treated as an ASCII string.
2366 *
2367 * Returns 0 on success.
2368 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002369int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 void __user *buffer, size_t *lenp, loff_t *ppos)
2371{
2372 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2373 NULL,NULL);
2374}
2375
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002376/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002377 * Taint values can only be increased
2378 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002379 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002380static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002381 void __user *buffer, size_t *lenp, loff_t *ppos)
2382{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002383 struct ctl_table t;
2384 unsigned long tmptaint = get_taint();
2385 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002386
Bastian Blank91fcd412007-04-23 14:41:14 -07002387 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002388 return -EPERM;
2389
Andi Kleen25ddbb12008-10-15 22:01:41 -07002390 t = *table;
2391 t.data = &tmptaint;
2392 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2393 if (err < 0)
2394 return err;
2395
2396 if (write) {
2397 /*
2398 * Poor man's atomic or. Not worth adding a primitive
2399 * to everyone's atomic.h for this
2400 */
2401 int i;
2402 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2403 if ((tmptaint >> i) & 1)
2404 add_taint(i);
2405 }
2406 }
2407
2408 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002409}
2410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411struct do_proc_dointvec_minmax_conv_param {
2412 int *min;
2413 int *max;
2414};
2415
2416static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2417 int *valp,
2418 int write, void *data)
2419{
2420 struct do_proc_dointvec_minmax_conv_param *param = data;
2421 if (write) {
2422 int val = *negp ? -*lvalp : *lvalp;
2423 if ((param->min && *param->min > val) ||
2424 (param->max && *param->max < val))
2425 return -EINVAL;
2426 *valp = val;
2427 } else {
2428 int val = *valp;
2429 if (val < 0) {
2430 *negp = -1;
2431 *lvalp = (unsigned long)-val;
2432 } else {
2433 *negp = 0;
2434 *lvalp = (unsigned long)val;
2435 }
2436 }
2437 return 0;
2438}
2439
2440/**
2441 * proc_dointvec_minmax - read a vector of integers with min/max values
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @filp: the file structure
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: file position
2448 *
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2451 *
2452 * This routine will ensure the values are within the range specified by
2453 * table->extra1 (min) and table->extra2 (max).
2454 *
2455 * Returns 0 on success.
2456 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002457int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 void __user *buffer, size_t *lenp, loff_t *ppos)
2459{
2460 struct do_proc_dointvec_minmax_conv_param param = {
2461 .min = (int *) table->extra1,
2462 .max = (int *) table->extra2,
2463 };
2464 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2465 do_proc_dointvec_minmax_conv, &param);
2466}
2467
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002468static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 struct file *filp,
2470 void __user *buffer,
2471 size_t *lenp, loff_t *ppos,
2472 unsigned long convmul,
2473 unsigned long convdiv)
2474{
2475#define TMPBUFLEN 21
2476 unsigned long *i, *min, *max, val;
2477 int vleft, first=1, neg;
2478 size_t len, left;
2479 char buf[TMPBUFLEN], *p;
2480 char __user *s = buffer;
2481
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002482 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 (*ppos && !write)) {
2484 *lenp = 0;
2485 return 0;
2486 }
2487
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002488 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 min = (unsigned long *) table->extra1;
2490 max = (unsigned long *) table->extra2;
2491 vleft = table->maxlen / sizeof(unsigned long);
2492 left = *lenp;
2493
2494 for (; left && vleft--; i++, min++, max++, first=0) {
2495 if (write) {
2496 while (left) {
2497 char c;
2498 if (get_user(c, s))
2499 return -EFAULT;
2500 if (!isspace(c))
2501 break;
2502 left--;
2503 s++;
2504 }
2505 if (!left)
2506 break;
2507 neg = 0;
2508 len = left;
2509 if (len > TMPBUFLEN-1)
2510 len = TMPBUFLEN-1;
2511 if (copy_from_user(buf, s, len))
2512 return -EFAULT;
2513 buf[len] = 0;
2514 p = buf;
2515 if (*p == '-' && left > 1) {
2516 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002517 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 }
2519 if (*p < '0' || *p > '9')
2520 break;
2521 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2522 len = p-buf;
2523 if ((len < left) && *p && !isspace(*p))
2524 break;
2525 if (neg)
2526 val = -val;
2527 s += len;
2528 left -= len;
2529
2530 if(neg)
2531 continue;
2532 if ((min && val < *min) || (max && val > *max))
2533 continue;
2534 *i = val;
2535 } else {
2536 p = buf;
2537 if (!first)
2538 *p++ = '\t';
2539 sprintf(p, "%lu", convdiv * (*i) / convmul);
2540 len = strlen(buf);
2541 if (len > left)
2542 len = left;
2543 if(copy_to_user(s, buf, len))
2544 return -EFAULT;
2545 left -= len;
2546 s += len;
2547 }
2548 }
2549
2550 if (!write && !first && left) {
2551 if(put_user('\n', s))
2552 return -EFAULT;
2553 left--, s++;
2554 }
2555 if (write) {
2556 while (left) {
2557 char c;
2558 if (get_user(c, s++))
2559 return -EFAULT;
2560 if (!isspace(c))
2561 break;
2562 left--;
2563 }
2564 }
2565 if (write && first)
2566 return -EINVAL;
2567 *lenp -= left;
2568 *ppos += *lenp;
2569 return 0;
2570#undef TMPBUFLEN
2571}
2572
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002573static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002574 struct file *filp,
2575 void __user *buffer,
2576 size_t *lenp, loff_t *ppos,
2577 unsigned long convmul,
2578 unsigned long convdiv)
2579{
2580 return __do_proc_doulongvec_minmax(table->data, table, write,
2581 filp, buffer, lenp, ppos, convmul, convdiv);
2582}
2583
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584/**
2585 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2586 * @table: the sysctl table
2587 * @write: %TRUE if this is a write to the sysctl file
2588 * @filp: the file structure
2589 * @buffer: the user buffer
2590 * @lenp: the size of the user buffer
2591 * @ppos: file position
2592 *
2593 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2594 * values from/to the user buffer, treated as an ASCII string.
2595 *
2596 * This routine will ensure the values are within the range specified by
2597 * table->extra1 (min) and table->extra2 (max).
2598 *
2599 * Returns 0 on success.
2600 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002601int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 void __user *buffer, size_t *lenp, loff_t *ppos)
2603{
2604 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2605}
2606
2607/**
2608 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2609 * @table: the sysctl table
2610 * @write: %TRUE if this is a write to the sysctl file
2611 * @filp: the file structure
2612 * @buffer: the user buffer
2613 * @lenp: the size of the user buffer
2614 * @ppos: file position
2615 *
2616 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2617 * values from/to the user buffer, treated as an ASCII string. The values
2618 * are treated as milliseconds, and converted to jiffies when they are stored.
2619 *
2620 * This routine will ensure the values are within the range specified by
2621 * table->extra1 (min) and table->extra2 (max).
2622 *
2623 * Returns 0 on success.
2624 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002625int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 struct file *filp,
2627 void __user *buffer,
2628 size_t *lenp, loff_t *ppos)
2629{
2630 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2631 lenp, ppos, HZ, 1000l);
2632}
2633
2634
2635static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2636 int *valp,
2637 int write, void *data)
2638{
2639 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002640 if (*lvalp > LONG_MAX / HZ)
2641 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2643 } else {
2644 int val = *valp;
2645 unsigned long lval;
2646 if (val < 0) {
2647 *negp = -1;
2648 lval = (unsigned long)-val;
2649 } else {
2650 *negp = 0;
2651 lval = (unsigned long)val;
2652 }
2653 *lvalp = lval / HZ;
2654 }
2655 return 0;
2656}
2657
2658static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2659 int *valp,
2660 int write, void *data)
2661{
2662 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002663 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2664 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2666 } else {
2667 int val = *valp;
2668 unsigned long lval;
2669 if (val < 0) {
2670 *negp = -1;
2671 lval = (unsigned long)-val;
2672 } else {
2673 *negp = 0;
2674 lval = (unsigned long)val;
2675 }
2676 *lvalp = jiffies_to_clock_t(lval);
2677 }
2678 return 0;
2679}
2680
2681static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2682 int *valp,
2683 int write, void *data)
2684{
2685 if (write) {
2686 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2687 } else {
2688 int val = *valp;
2689 unsigned long lval;
2690 if (val < 0) {
2691 *negp = -1;
2692 lval = (unsigned long)-val;
2693 } else {
2694 *negp = 0;
2695 lval = (unsigned long)val;
2696 }
2697 *lvalp = jiffies_to_msecs(lval);
2698 }
2699 return 0;
2700}
2701
2702/**
2703 * proc_dointvec_jiffies - read a vector of integers as seconds
2704 * @table: the sysctl table
2705 * @write: %TRUE if this is a write to the sysctl file
2706 * @filp: the file structure
2707 * @buffer: the user buffer
2708 * @lenp: the size of the user buffer
2709 * @ppos: file position
2710 *
2711 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2712 * values from/to the user buffer, treated as an ASCII string.
2713 * The values read are assumed to be in seconds, and are converted into
2714 * jiffies.
2715 *
2716 * Returns 0 on success.
2717 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002718int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 void __user *buffer, size_t *lenp, loff_t *ppos)
2720{
2721 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2722 do_proc_dointvec_jiffies_conv,NULL);
2723}
2724
2725/**
2726 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2727 * @table: the sysctl table
2728 * @write: %TRUE if this is a write to the sysctl file
2729 * @filp: the file structure
2730 * @buffer: the user buffer
2731 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002732 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 *
2734 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2735 * values from/to the user buffer, treated as an ASCII string.
2736 * The values read are assumed to be in 1/USER_HZ seconds, and
2737 * are converted into jiffies.
2738 *
2739 * Returns 0 on success.
2740 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002741int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 void __user *buffer, size_t *lenp, loff_t *ppos)
2743{
2744 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2745 do_proc_dointvec_userhz_jiffies_conv,NULL);
2746}
2747
2748/**
2749 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2750 * @table: the sysctl table
2751 * @write: %TRUE if this is a write to the sysctl file
2752 * @filp: the file structure
2753 * @buffer: the user buffer
2754 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002755 * @ppos: file position
2756 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 *
2758 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2759 * values from/to the user buffer, treated as an ASCII string.
2760 * The values read are assumed to be in 1/1000 seconds, and
2761 * are converted into jiffies.
2762 *
2763 * Returns 0 on success.
2764 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002765int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 void __user *buffer, size_t *lenp, loff_t *ppos)
2767{
2768 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2769 do_proc_dointvec_ms_jiffies_conv, NULL);
2770}
2771
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002772static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002773 void __user *buffer, size_t *lenp, loff_t *ppos)
2774{
2775 struct pid *new_pid;
2776 pid_t tmp;
2777 int r;
2778
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002779 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002780
2781 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2782 lenp, ppos, NULL, NULL);
2783 if (r || !write)
2784 return r;
2785
2786 new_pid = find_get_pid(tmp);
2787 if (!new_pid)
2788 return -ESRCH;
2789
2790 put_pid(xchg(&cad_pid, new_pid));
2791 return 0;
2792}
2793
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794#else /* CONFIG_PROC_FS */
2795
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002796int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 void __user *buffer, size_t *lenp, loff_t *ppos)
2798{
2799 return -ENOSYS;
2800}
2801
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002802int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 void __user *buffer, size_t *lenp, loff_t *ppos)
2804{
2805 return -ENOSYS;
2806}
2807
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002808int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 void __user *buffer, size_t *lenp, loff_t *ppos)
2810{
2811 return -ENOSYS;
2812}
2813
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002814int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 void __user *buffer, size_t *lenp, loff_t *ppos)
2816{
2817 return -ENOSYS;
2818}
2819
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002820int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 void __user *buffer, size_t *lenp, loff_t *ppos)
2822{
2823 return -ENOSYS;
2824}
2825
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002826int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 void __user *buffer, size_t *lenp, loff_t *ppos)
2828{
2829 return -ENOSYS;
2830}
2831
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002832int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 void __user *buffer, size_t *lenp, loff_t *ppos)
2834{
2835 return -ENOSYS;
2836}
2837
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002838int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 struct file *filp,
2840 void __user *buffer,
2841 size_t *lenp, loff_t *ppos)
2842{
2843 return -ENOSYS;
2844}
2845
2846
2847#endif /* CONFIG_PROC_FS */
2848
2849
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002850#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851/*
2852 * General sysctl support routines
2853 */
2854
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002855/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002856int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002857 void __user *oldval, size_t __user *oldlenp,
2858 void __user *newval, size_t newlen)
2859{
2860 size_t len;
2861
2862 /* Get out of I don't have a variable */
2863 if (!table->data || !table->maxlen)
2864 return -ENOTDIR;
2865
2866 if (oldval && oldlenp) {
2867 if (get_user(len, oldlenp))
2868 return -EFAULT;
2869 if (len) {
2870 if (len > table->maxlen)
2871 len = table->maxlen;
2872 if (copy_to_user(oldval, table->data, len))
2873 return -EFAULT;
2874 if (put_user(len, oldlenp))
2875 return -EFAULT;
2876 }
2877 }
2878
2879 if (newval && newlen) {
2880 if (newlen > table->maxlen)
2881 newlen = table->maxlen;
2882
2883 if (copy_from_user(table->data, newval, newlen))
2884 return -EFAULT;
2885 }
2886 return 1;
2887}
2888
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002890int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002892 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 if (!table->data || !table->maxlen)
2895 return -ENOTDIR;
2896
2897 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002898 size_t bufsize;
2899 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002901 if (bufsize) {
2902 size_t len = strlen(table->data), copied;
2903
2904 /* This shouldn't trigger for a well-formed sysctl */
2905 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002907
2908 /* Copy up to a max of bufsize-1 bytes of the string */
2909 copied = (len >= bufsize) ? bufsize - 1 : len;
2910
2911 if (copy_to_user(oldval, table->data, copied) ||
2912 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002914 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 return -EFAULT;
2916 }
2917 }
2918 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002919 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 if (len > table->maxlen)
2921 len = table->maxlen;
2922 if(copy_from_user(table->data, newval, len))
2923 return -EFAULT;
2924 if (len == table->maxlen)
2925 len--;
2926 ((char *) table->data)[len] = 0;
2927 }
Yi Yang82c9df82005-12-30 16:37:10 +08002928 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929}
2930
2931/*
2932 * This function makes sure that all of the integers in the vector
2933 * are between the minimum and maximum values given in the arrays
2934 * table->extra1 and table->extra2, respectively.
2935 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002936int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002938 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939{
2940
2941 if (newval && newlen) {
2942 int __user *vec = (int __user *) newval;
2943 int *min = (int *) table->extra1;
2944 int *max = (int *) table->extra2;
2945 size_t length;
2946 int i;
2947
2948 if (newlen % sizeof(int) != 0)
2949 return -EINVAL;
2950
2951 if (!table->extra1 && !table->extra2)
2952 return 0;
2953
2954 if (newlen > table->maxlen)
2955 newlen = table->maxlen;
2956 length = newlen / sizeof(int);
2957
2958 for (i = 0; i < length; i++) {
2959 int value;
2960 if (get_user(value, vec + i))
2961 return -EFAULT;
2962 if (min && value < min[i])
2963 return -EINVAL;
2964 if (max && value > max[i])
2965 return -EINVAL;
2966 }
2967 }
2968 return 0;
2969}
2970
2971/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002972int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002974 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002976 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002978
2979 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002981 if (olen) {
2982 int val;
2983
2984 if (olen < sizeof(int))
2985 return -EINVAL;
2986
2987 val = *(int *)(table->data) / HZ;
2988 if (put_user(val, (int __user *)oldval))
2989 return -EFAULT;
2990 if (put_user(sizeof(int), oldlenp))
2991 return -EFAULT;
2992 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 }
2994 if (newval && newlen) {
2995 int new;
2996 if (newlen != sizeof(int))
2997 return -EINVAL;
2998 if (get_user(new, (int __user *)newval))
2999 return -EFAULT;
3000 *(int *)(table->data) = new*HZ;
3001 }
3002 return 1;
3003}
3004
3005/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003006int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003008 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003010 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003012
3013 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003015 if (olen) {
3016 int val;
3017
3018 if (olen < sizeof(int))
3019 return -EINVAL;
3020
3021 val = jiffies_to_msecs(*(int *)(table->data));
3022 if (put_user(val, (int __user *)oldval))
3023 return -EFAULT;
3024 if (put_user(sizeof(int), oldlenp))
3025 return -EFAULT;
3026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 }
3028 if (newval && newlen) {
3029 int new;
3030 if (newlen != sizeof(int))
3031 return -EINVAL;
3032 if (get_user(new, (int __user *)newval))
3033 return -EFAULT;
3034 *(int *)(table->data) = msecs_to_jiffies(new);
3035 }
3036 return 1;
3037}
3038
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003039
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003040
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003041#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042
3043
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003044SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003046 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003047 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003048
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003049 if (copy_from_user(&tmp, args, sizeof(tmp)))
3050 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003051
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003052 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003053
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003054 /* If no error reading the parameters then just -ENOSYS ... */
3055 if (!error)
3056 error = -ENOSYS;
3057
3058 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059}
3060
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003061int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003062 void __user *oldval, size_t __user *oldlenp,
3063 void __user *newval, size_t newlen)
3064{
3065 return -ENOSYS;
3066}
3067
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003068int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003070 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071{
3072 return -ENOSYS;
3073}
3074
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003075int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003077 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078{
3079 return -ENOSYS;
3080}
3081
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003082int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003084 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085{
3086 return -ENOSYS;
3087}
3088
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003089int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003091 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092{
3093 return -ENOSYS;
3094}
3095
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003096#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003098static int deprecated_sysctl_warning(struct __sysctl_args *args)
3099{
3100 static int msg_count;
3101 int name[CTL_MAXNAME];
3102 int i;
3103
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003104 /* Check args->nlen. */
3105 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3106 return -ENOTDIR;
3107
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003108 /* Read in the sysctl name for better debug message logging */
3109 for (i = 0; i < args->nlen; i++)
3110 if (get_user(name[i], args->name + i))
3111 return -EFAULT;
3112
3113 /* Ignore accesses to kernel.version */
3114 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3115 return 0;
3116
3117 if (msg_count < 5) {
3118 msg_count++;
3119 printk(KERN_INFO
3120 "warning: process `%s' used the deprecated sysctl "
3121 "system call with ", current->comm);
3122 for (i = 0; i < args->nlen; i++)
3123 printk("%d.", name[i]);
3124 printk("\n");
3125 }
3126 return 0;
3127}
3128
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129/*
3130 * No sense putting this after each symbol definition, twice,
3131 * exception granted :-)
3132 */
3133EXPORT_SYMBOL(proc_dointvec);
3134EXPORT_SYMBOL(proc_dointvec_jiffies);
3135EXPORT_SYMBOL(proc_dointvec_minmax);
3136EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3137EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3138EXPORT_SYMBOL(proc_dostring);
3139EXPORT_SYMBOL(proc_doulongvec_minmax);
3140EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3141EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003142EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143EXPORT_SYMBOL(sysctl_intvec);
3144EXPORT_SYMBOL(sysctl_jiffies);
3145EXPORT_SYMBOL(sysctl_ms_jiffies);
3146EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003147EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148EXPORT_SYMBOL(unregister_sysctl_table);