blob: b3ce581373030db501d83ea08c4a771f0a02aeae [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/uaccess.h>
54#include <asm/processor.h>
55
Andi Kleen29cbc782006-09-30 01:47:55 +020056#ifdef CONFIG_X86
57#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010058#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010059#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020060#endif
61
Eric W. Biederman7058cb02007-10-18 03:05:58 -070062static int deprecated_sysctl_warning(struct __sysctl_args *args);
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#if defined(CONFIG_SYSCTL)
65
66/* External variables not in a header file. */
67extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070068extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int sysctl_overcommit_memory;
70extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070071extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070072extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080073extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070076extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern int pid_max;
79extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080081extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080082extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020083extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000086#ifndef CONFIG_MMU
87extern int sysctl_nr_trim_pages;
88#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070089#ifdef CONFIG_RCU_TORTURE_TEST
90extern int rcutorture_runnable;
91#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070093/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080094#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020096static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097#endif
98
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700100static int __maybe_unused one = 1;
101static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800102static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103static int one_hundred = 100;
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 Molnar23f78d4a2006-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 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530327 {
328 .ctl_name = CTL_UNNUMBERED,
329 .procname = "timer_migration",
330 .data = &sysctl_timer_migration,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
333 .proc_handler = &proc_dointvec,
334 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200335#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200336 {
337 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100338 .procname = "sched_rt_period_us",
339 .data = &sysctl_sched_rt_period,
340 .maxlen = sizeof(unsigned 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,
346 .procname = "sched_rt_runtime_us",
347 .data = &sysctl_sched_rt_runtime,
348 .maxlen = sizeof(int),
349 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200350 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100351 },
352 {
353 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200354 .procname = "sched_compat_yield",
355 .data = &sysctl_sched_compat_yield,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
358 .proc_handler = &proc_dointvec,
359 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700360#ifdef CONFIG_PROVE_LOCKING
361 {
362 .ctl_name = CTL_UNNUMBERED,
363 .procname = "prove_locking",
364 .data = &prove_locking,
365 .maxlen = sizeof(int),
366 .mode = 0644,
367 .proc_handler = &proc_dointvec,
368 },
369#endif
370#ifdef CONFIG_LOCK_STAT
371 {
372 .ctl_name = CTL_UNNUMBERED,
373 .procname = "lock_stat",
374 .data = &lock_stat,
375 .maxlen = sizeof(int),
376 .mode = 0644,
377 .proc_handler = &proc_dointvec,
378 },
379#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200380 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 .ctl_name = KERN_PANIC,
382 .procname = "panic",
383 .data = &panic_timeout,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = &proc_dointvec,
387 },
388 {
389 .ctl_name = KERN_CORE_USES_PID,
390 .procname = "core_uses_pid",
391 .data = &core_uses_pid,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = &proc_dointvec,
395 },
396 {
397 .ctl_name = KERN_CORE_PATTERN,
398 .procname = "core_pattern",
399 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700400 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 .mode = 0644,
402 .proc_handler = &proc_dostring,
403 .strategy = &sysctl_string,
404 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800405#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700408 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800409 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700410 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800412#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100413#ifdef CONFIG_LATENCYTOP
414 {
415 .procname = "latencytop",
416 .data = &latencytop_enabled,
417 .maxlen = sizeof(int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
420 },
421#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#ifdef CONFIG_BLK_DEV_INITRD
423 {
424 .ctl_name = KERN_REALROOTDEV,
425 .procname = "real-root-dev",
426 .data = &real_root_dev,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
431#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700432 {
433 .ctl_name = CTL_UNNUMBERED,
434 .procname = "print-fatal-signals",
435 .data = &print_fatal_signals,
436 .maxlen = sizeof(int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
439 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700440#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 {
442 .ctl_name = KERN_SPARC_REBOOT,
443 .procname = "reboot-cmd",
444 .data = reboot_command,
445 .maxlen = 256,
446 .mode = 0644,
447 .proc_handler = &proc_dostring,
448 .strategy = &sysctl_string,
449 },
450 {
451 .ctl_name = KERN_SPARC_STOP_A,
452 .procname = "stop-a",
453 .data = &stop_a_enabled,
454 .maxlen = sizeof (int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458 {
459 .ctl_name = KERN_SPARC_SCONS_PWROFF,
460 .procname = "scons-poweroff",
461 .data = &scons_pwroff,
462 .maxlen = sizeof (int),
463 .mode = 0644,
464 .proc_handler = &proc_dointvec,
465 },
466#endif
David S. Miller08714202008-11-16 23:49:24 -0800467#ifdef CONFIG_SPARC64
468 {
469 .ctl_name = CTL_UNNUMBERED,
470 .procname = "tsb-ratio",
471 .data = &sysctl_tsb_ratio,
472 .maxlen = sizeof (int),
473 .mode = 0644,
474 .proc_handler = &proc_dointvec,
475 },
476#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#ifdef __hppa__
478 {
479 .ctl_name = KERN_HPPA_PWRSW,
480 .procname = "soft-power",
481 .data = &pwrsw_enabled,
482 .maxlen = sizeof (int),
483 .mode = 0644,
484 .proc_handler = &proc_dointvec,
485 },
486 {
487 .ctl_name = KERN_HPPA_UNALIGNED,
488 .procname = "unaligned-trap",
489 .data = &unaligned_enabled,
490 .maxlen = sizeof (int),
491 .mode = 0644,
492 .proc_handler = &proc_dointvec,
493 },
494#endif
495 {
496 .ctl_name = KERN_CTLALTDEL,
497 .procname = "ctrl-alt-del",
498 .data = &C_A_D,
499 .maxlen = sizeof(int),
500 .mode = 0644,
501 .proc_handler = &proc_dointvec,
502 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400503#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200504 {
505 .ctl_name = CTL_UNNUMBERED,
506 .procname = "ftrace_enabled",
507 .data = &ftrace_enabled,
508 .maxlen = sizeof(int),
509 .mode = 0644,
510 .proc_handler = &ftrace_enable_sysctl,
511 },
512#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500513#ifdef CONFIG_STACK_TRACER
514 {
515 .ctl_name = CTL_UNNUMBERED,
516 .procname = "stack_tracer_enabled",
517 .data = &stack_tracer_enabled,
518 .maxlen = sizeof(int),
519 .mode = 0644,
520 .proc_handler = &stack_trace_sysctl,
521 },
522#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400523#ifdef CONFIG_TRACING
524 {
525 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100526 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400527 .data = &ftrace_dump_on_oops,
528 .maxlen = sizeof(int),
529 .mode = 0644,
530 .proc_handler = &proc_dointvec,
531 },
532#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200533#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 {
535 .ctl_name = KERN_MODPROBE,
536 .procname = "modprobe",
537 .data = &modprobe_path,
538 .maxlen = KMOD_PATH_LEN,
539 .mode = 0644,
540 .proc_handler = &proc_dostring,
541 .strategy = &sysctl_string,
542 },
543#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700544#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 {
546 .ctl_name = KERN_HOTPLUG,
547 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100548 .data = &uevent_helper,
549 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 .mode = 0644,
551 .proc_handler = &proc_dostring,
552 .strategy = &sysctl_string,
553 },
554#endif
555#ifdef CONFIG_CHR_DEV_SG
556 {
557 .ctl_name = KERN_SG_BIG_BUFF,
558 .procname = "sg-big-buff",
559 .data = &sg_big_buff,
560 .maxlen = sizeof (int),
561 .mode = 0444,
562 .proc_handler = &proc_dointvec,
563 },
564#endif
565#ifdef CONFIG_BSD_PROCESS_ACCT
566 {
567 .ctl_name = KERN_ACCT,
568 .procname = "acct",
569 .data = &acct_parm,
570 .maxlen = 3*sizeof(int),
571 .mode = 0644,
572 .proc_handler = &proc_dointvec,
573 },
574#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#ifdef CONFIG_MAGIC_SYSRQ
576 {
577 .ctl_name = KERN_SYSRQ,
578 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800579 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .maxlen = sizeof (int),
581 .mode = 0644,
582 .proc_handler = &proc_dointvec,
583 },
584#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700585#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700588 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 .maxlen = sizeof (int),
590 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700591 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700593#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 {
595 .ctl_name = KERN_MAX_THREADS,
596 .procname = "threads-max",
597 .data = &max_threads,
598 .maxlen = sizeof(int),
599 .mode = 0644,
600 .proc_handler = &proc_dointvec,
601 },
602 {
603 .ctl_name = KERN_RANDOM,
604 .procname = "random",
605 .mode = 0555,
606 .child = random_table,
607 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 {
609 .ctl_name = KERN_OVERFLOWUID,
610 .procname = "overflowuid",
611 .data = &overflowuid,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec_minmax,
615 .strategy = &sysctl_intvec,
616 .extra1 = &minolduid,
617 .extra2 = &maxolduid,
618 },
619 {
620 .ctl_name = KERN_OVERFLOWGID,
621 .procname = "overflowgid",
622 .data = &overflowgid,
623 .maxlen = sizeof(int),
624 .mode = 0644,
625 .proc_handler = &proc_dointvec_minmax,
626 .strategy = &sysctl_intvec,
627 .extra1 = &minolduid,
628 .extra2 = &maxolduid,
629 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800630#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631#ifdef CONFIG_MATHEMU
632 {
633 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
634 .procname = "ieee_emulation_warnings",
635 .data = &sysctl_ieee_emulation_warnings,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec,
639 },
640#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 {
642 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
643 .procname = "userprocess_debug",
644 .data = &sysctl_userprocess_debug,
645 .maxlen = sizeof(int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
648 },
649#endif
650 {
651 .ctl_name = KERN_PIDMAX,
652 .procname = "pid_max",
653 .data = &pid_max,
654 .maxlen = sizeof (int),
655 .mode = 0644,
656 .proc_handler = &proc_dointvec_minmax,
657 .strategy = sysctl_intvec,
658 .extra1 = &pid_max_min,
659 .extra2 = &pid_max_max,
660 },
661 {
662 .ctl_name = KERN_PANIC_ON_OOPS,
663 .procname = "panic_on_oops",
664 .data = &panic_on_oops,
665 .maxlen = sizeof(int),
666 .mode = 0644,
667 .proc_handler = &proc_dointvec,
668 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800669#if defined CONFIG_PRINTK
670 {
671 .ctl_name = KERN_PRINTK,
672 .procname = "printk",
673 .data = &console_loglevel,
674 .maxlen = 4*sizeof(int),
675 .mode = 0644,
676 .proc_handler = &proc_dointvec,
677 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 {
679 .ctl_name = KERN_PRINTK_RATELIMIT,
680 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700681 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 .maxlen = sizeof(int),
683 .mode = 0644,
684 .proc_handler = &proc_dointvec_jiffies,
685 .strategy = &sysctl_jiffies,
686 },
687 {
688 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
689 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700690 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .maxlen = sizeof(int),
692 .mode = 0644,
693 .proc_handler = &proc_dointvec,
694 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800695#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 {
697 .ctl_name = KERN_NGROUPS_MAX,
698 .procname = "ngroups_max",
699 .data = &ngroups_max,
700 .maxlen = sizeof (int),
701 .mode = 0444,
702 .proc_handler = &proc_dointvec,
703 },
704#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
705 {
706 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
707 .procname = "unknown_nmi_panic",
708 .data = &unknown_nmi_panic,
709 .maxlen = sizeof (int),
710 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200711 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 },
Don Zickus407984f2006-09-26 10:52:27 +0200713 {
Don Zickus407984f2006-09-26 10:52:27 +0200714 .procname = "nmi_watchdog",
715 .data = &nmi_watchdog_enabled,
716 .maxlen = sizeof (int),
717 .mode = 0644,
718 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 },
720#endif
721#if defined(CONFIG_X86)
722 {
Don Zickus8da5add2006-09-26 10:52:27 +0200723 .ctl_name = KERN_PANIC_ON_NMI,
724 .procname = "panic_on_unrecovered_nmi",
725 .data = &panic_on_unrecovered_nmi,
726 .maxlen = sizeof(int),
727 .mode = 0644,
728 .proc_handler = &proc_dointvec,
729 },
730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .ctl_name = KERN_BOOTLOADER_TYPE,
732 .procname = "bootloader_type",
733 .data = &bootloader_type,
734 .maxlen = sizeof (int),
735 .mode = 0444,
736 .proc_handler = &proc_dointvec,
737 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100738 {
739 .ctl_name = CTL_UNNUMBERED,
740 .procname = "kstack_depth_to_print",
741 .data = &kstack_depth_to_print,
742 .maxlen = sizeof(int),
743 .mode = 0644,
744 .proc_handler = &proc_dointvec,
745 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100746 {
747 .ctl_name = CTL_UNNUMBERED,
748 .procname = "io_delay_type",
749 .data = &io_delay_type,
750 .maxlen = sizeof(int),
751 .mode = 0644,
752 .proc_handler = &proc_dointvec,
753 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800755#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 {
757 .ctl_name = KERN_RANDOMIZE,
758 .procname = "randomize_va_space",
759 .data = &randomize_va_space,
760 .maxlen = sizeof(int),
761 .mode = 0644,
762 .proc_handler = &proc_dointvec,
763 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800764#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800765#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700766 {
767 .ctl_name = KERN_SPIN_RETRY,
768 .procname = "spin_retry",
769 .data = &spin_retry,
770 .maxlen = sizeof (int),
771 .mode = 0644,
772 .proc_handler = &proc_dointvec,
773 },
774#endif
Len Brown673d5b42007-07-28 03:33:16 -0400775#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800776 {
Pavel Machekc255d842006-02-20 18:27:58 -0800777 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700778 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800779 .maxlen = sizeof (unsigned long),
780 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800781 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800782 },
783#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800784#ifdef CONFIG_IA64
785 {
786 .ctl_name = KERN_IA64_UNALIGNED,
787 .procname = "ignore-unaligned-usertrap",
788 .data = &no_unaligned_warning,
789 .maxlen = sizeof (int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
792 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800793 {
794 .ctl_name = CTL_UNNUMBERED,
795 .procname = "unaligned-dump-stack",
796 .data = &unaligned_dump_stack,
797 .maxlen = sizeof (int),
798 .mode = 0644,
799 .proc_handler = &proc_dointvec,
800 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800801#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700802#ifdef CONFIG_DETECT_SOFTLOCKUP
803 {
804 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200805 .procname = "softlockup_panic",
806 .data = &softlockup_panic,
807 .maxlen = sizeof(int),
808 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700809 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200810 .strategy = &sysctl_intvec,
811 .extra1 = &zero,
812 .extra2 = &one,
813 },
814 {
815 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700816 .procname = "softlockup_thresh",
817 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200818 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700819 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800820 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700821 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200822 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700823 .extra2 = &sixty,
824 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800825#endif
826#ifdef CONFIG_DETECT_HUNG_TASK
827 {
828 .ctl_name = CTL_UNNUMBERED,
829 .procname = "hung_task_panic",
830 .data = &sysctl_hung_task_panic,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec_minmax,
834 .strategy = &sysctl_intvec,
835 .extra1 = &zero,
836 .extra2 = &one,
837 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100838 {
839 .ctl_name = CTL_UNNUMBERED,
840 .procname = "hung_task_check_count",
841 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100842 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100843 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100844 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100845 .strategy = &sysctl_intvec,
846 },
847 {
848 .ctl_name = CTL_UNNUMBERED,
849 .procname = "hung_task_timeout_secs",
850 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100851 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100852 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800853 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100854 .strategy = &sysctl_intvec,
855 },
856 {
857 .ctl_name = CTL_UNNUMBERED,
858 .procname = "hung_task_warnings",
859 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100860 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100862 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100863 .strategy = &sysctl_intvec,
864 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700865#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200866#ifdef CONFIG_COMPAT
867 {
868 .ctl_name = KERN_COMPAT_LOG,
869 .procname = "compat-log",
870 .data = &compat_log,
871 .maxlen = sizeof (int),
872 .mode = 0644,
873 .proc_handler = &proc_dointvec,
874 },
875#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700876#ifdef CONFIG_RT_MUTEXES
877 {
878 .ctl_name = KERN_MAX_LOCK_DEPTH,
879 .procname = "max_lock_depth",
880 .data = &max_lock_depth,
881 .maxlen = sizeof(int),
882 .mode = 0644,
883 .proc_handler = &proc_dointvec,
884 },
885#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700886 {
887 .ctl_name = CTL_UNNUMBERED,
888 .procname = "poweroff_cmd",
889 .data = &poweroff_cmd,
890 .maxlen = POWEROFF_CMD_PATH_LEN,
891 .mode = 0644,
892 .proc_handler = &proc_dostring,
893 .strategy = &sysctl_string,
894 },
David Howells0b77f5b2008-04-29 01:01:32 -0700895#ifdef CONFIG_KEYS
896 {
897 .ctl_name = CTL_UNNUMBERED,
898 .procname = "keys",
899 .mode = 0555,
900 .child = key_sysctls,
901 },
902#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700903#ifdef CONFIG_RCU_TORTURE_TEST
904 {
905 .ctl_name = CTL_UNNUMBERED,
906 .procname = "rcutorture_runnable",
907 .data = &rcutorture_runnable,
908 .maxlen = sizeof(int),
909 .mode = 0644,
910 .proc_handler = &proc_dointvec,
911 },
912#endif
David Howells12e22c52009-04-03 16:42:35 +0100913#ifdef CONFIG_SLOW_WORK
914 {
915 .ctl_name = CTL_UNNUMBERED,
916 .procname = "slow-work",
917 .mode = 0555,
918 .child = slow_work_sysctls,
919 },
920#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700921/*
922 * NOTE: do not add new entries to this table unless you have read
923 * Documentation/sysctl/ctl_unnumbered.txt
924 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 { .ctl_name = 0 }
926};
927
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700928static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 {
930 .ctl_name = VM_OVERCOMMIT_MEMORY,
931 .procname = "overcommit_memory",
932 .data = &sysctl_overcommit_memory,
933 .maxlen = sizeof(sysctl_overcommit_memory),
934 .mode = 0644,
935 .proc_handler = &proc_dointvec,
936 },
937 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700938 .ctl_name = VM_PANIC_ON_OOM,
939 .procname = "panic_on_oom",
940 .data = &sysctl_panic_on_oom,
941 .maxlen = sizeof(sysctl_panic_on_oom),
942 .mode = 0644,
943 .proc_handler = &proc_dointvec,
944 },
945 {
David Rientjesfe071d72007-10-16 23:25:56 -0700946 .ctl_name = CTL_UNNUMBERED,
947 .procname = "oom_kill_allocating_task",
948 .data = &sysctl_oom_kill_allocating_task,
949 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
950 .mode = 0644,
951 .proc_handler = &proc_dointvec,
952 },
953 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800954 .ctl_name = CTL_UNNUMBERED,
955 .procname = "oom_dump_tasks",
956 .data = &sysctl_oom_dump_tasks,
957 .maxlen = sizeof(sysctl_oom_dump_tasks),
958 .mode = 0644,
959 .proc_handler = &proc_dointvec,
960 },
961 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 .ctl_name = VM_OVERCOMMIT_RATIO,
963 .procname = "overcommit_ratio",
964 .data = &sysctl_overcommit_ratio,
965 .maxlen = sizeof(sysctl_overcommit_ratio),
966 .mode = 0644,
967 .proc_handler = &proc_dointvec,
968 },
969 {
970 .ctl_name = VM_PAGE_CLUSTER,
971 .procname = "page-cluster",
972 .data = &page_cluster,
973 .maxlen = sizeof(int),
974 .mode = 0644,
975 .proc_handler = &proc_dointvec,
976 },
977 {
978 .ctl_name = VM_DIRTY_BACKGROUND,
979 .procname = "dirty_background_ratio",
980 .data = &dirty_background_ratio,
981 .maxlen = sizeof(dirty_background_ratio),
982 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800983 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 .strategy = &sysctl_intvec,
985 .extra1 = &zero,
986 .extra2 = &one_hundred,
987 },
988 {
David Rientjes2da02992009-01-06 14:39:31 -0800989 .ctl_name = CTL_UNNUMBERED,
990 .procname = "dirty_background_bytes",
991 .data = &dirty_background_bytes,
992 .maxlen = sizeof(dirty_background_bytes),
993 .mode = 0644,
994 .proc_handler = &dirty_background_bytes_handler,
995 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800996 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -0800997 },
998 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 .ctl_name = VM_DIRTY_RATIO,
1000 .procname = "dirty_ratio",
1001 .data = &vm_dirty_ratio,
1002 .maxlen = sizeof(vm_dirty_ratio),
1003 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001004 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 .strategy = &sysctl_intvec,
1006 .extra1 = &zero,
1007 .extra2 = &one_hundred,
1008 },
1009 {
David Rientjes2da02992009-01-06 14:39:31 -08001010 .ctl_name = CTL_UNNUMBERED,
1011 .procname = "dirty_bytes",
1012 .data = &vm_dirty_bytes,
1013 .maxlen = sizeof(vm_dirty_bytes),
1014 .mode = 0644,
1015 .proc_handler = &dirty_bytes_handler,
1016 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001017 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001018 },
1019 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001021 .data = &dirty_writeback_interval,
1022 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 .mode = 0644,
1024 .proc_handler = &dirty_writeback_centisecs_handler,
1025 },
1026 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001028 .data = &dirty_expire_interval,
1029 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001031 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 },
1033 {
1034 .ctl_name = VM_NR_PDFLUSH_THREADS,
1035 .procname = "nr_pdflush_threads",
1036 .data = &nr_pdflush_threads,
1037 .maxlen = sizeof nr_pdflush_threads,
1038 .mode = 0444 /* read-only*/,
1039 .proc_handler = &proc_dointvec,
1040 },
1041 {
Peter W Morrealefafd6882009-04-06 19:00:29 -07001042 .ctl_name = CTL_UNNUMBERED,
1043 .procname = "nr_pdflush_threads_min",
1044 .data = &nr_pdflush_threads_min,
1045 .maxlen = sizeof nr_pdflush_threads_min,
1046 .mode = 0644 /* read-write */,
1047 .proc_handler = &proc_dointvec_minmax,
1048 .strategy = &sysctl_intvec,
1049 .extra1 = &one,
1050 .extra2 = &nr_pdflush_threads_max,
1051 },
1052 {
1053 .ctl_name = CTL_UNNUMBERED,
1054 .procname = "nr_pdflush_threads_max",
1055 .data = &nr_pdflush_threads_max,
1056 .maxlen = sizeof nr_pdflush_threads_max,
1057 .mode = 0644 /* read-write */,
1058 .proc_handler = &proc_dointvec_minmax,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &nr_pdflush_threads_min,
1061 .extra2 = &one_thousand,
1062 },
1063 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 .ctl_name = VM_SWAPPINESS,
1065 .procname = "swappiness",
1066 .data = &vm_swappiness,
1067 .maxlen = sizeof(vm_swappiness),
1068 .mode = 0644,
1069 .proc_handler = &proc_dointvec_minmax,
1070 .strategy = &sysctl_intvec,
1071 .extra1 = &zero,
1072 .extra2 = &one_hundred,
1073 },
1074#ifdef CONFIG_HUGETLB_PAGE
1075 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001077 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 .maxlen = sizeof(unsigned long),
1079 .mode = 0644,
1080 .proc_handler = &hugetlb_sysctl_handler,
1081 .extra1 = (void *)&hugetlb_zero,
1082 .extra2 = (void *)&hugetlb_infinity,
1083 },
1084 {
1085 .ctl_name = VM_HUGETLB_GROUP,
1086 .procname = "hugetlb_shm_group",
1087 .data = &sysctl_hugetlb_shm_group,
1088 .maxlen = sizeof(gid_t),
1089 .mode = 0644,
1090 .proc_handler = &proc_dointvec,
1091 },
Mel Gorman396faf02007-07-17 04:03:13 -07001092 {
1093 .ctl_name = CTL_UNNUMBERED,
1094 .procname = "hugepages_treat_as_movable",
1095 .data = &hugepages_treat_as_movable,
1096 .maxlen = sizeof(int),
1097 .mode = 0644,
1098 .proc_handler = &hugetlb_treat_movable_handler,
1099 },
Adam Litke54f9f802007-10-16 01:26:20 -07001100 {
1101 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001102 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001103 .data = NULL,
1104 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001105 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001106 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001107 .extra1 = (void *)&hugetlb_zero,
1108 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001109 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110#endif
1111 {
1112 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1113 .procname = "lowmem_reserve_ratio",
1114 .data = &sysctl_lowmem_reserve_ratio,
1115 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1116 .mode = 0644,
1117 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1118 .strategy = &sysctl_intvec,
1119 },
1120 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001121 .ctl_name = VM_DROP_PAGECACHE,
1122 .procname = "drop_caches",
1123 .data = &sysctl_drop_caches,
1124 .maxlen = sizeof(int),
1125 .mode = 0644,
1126 .proc_handler = drop_caches_sysctl_handler,
1127 .strategy = &sysctl_intvec,
1128 },
1129 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 .ctl_name = VM_MIN_FREE_KBYTES,
1131 .procname = "min_free_kbytes",
1132 .data = &min_free_kbytes,
1133 .maxlen = sizeof(min_free_kbytes),
1134 .mode = 0644,
1135 .proc_handler = &min_free_kbytes_sysctl_handler,
1136 .strategy = &sysctl_intvec,
1137 .extra1 = &zero,
1138 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001139 {
1140 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1141 .procname = "percpu_pagelist_fraction",
1142 .data = &percpu_pagelist_fraction,
1143 .maxlen = sizeof(percpu_pagelist_fraction),
1144 .mode = 0644,
1145 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1146 .strategy = &sysctl_intvec,
1147 .extra1 = &min_percpu_pagelist_fract,
1148 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149#ifdef CONFIG_MMU
1150 {
1151 .ctl_name = VM_MAX_MAP_COUNT,
1152 .procname = "max_map_count",
1153 .data = &sysctl_max_map_count,
1154 .maxlen = sizeof(sysctl_max_map_count),
1155 .mode = 0644,
1156 .proc_handler = &proc_dointvec
1157 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001158#else
1159 {
1160 .ctl_name = CTL_UNNUMBERED,
1161 .procname = "nr_trim_pages",
1162 .data = &sysctl_nr_trim_pages,
1163 .maxlen = sizeof(sysctl_nr_trim_pages),
1164 .mode = 0644,
1165 .proc_handler = &proc_dointvec_minmax,
1166 .strategy = &sysctl_intvec,
1167 .extra1 = &zero,
1168 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169#endif
1170 {
1171 .ctl_name = VM_LAPTOP_MODE,
1172 .procname = "laptop_mode",
1173 .data = &laptop_mode,
1174 .maxlen = sizeof(laptop_mode),
1175 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001176 .proc_handler = &proc_dointvec_jiffies,
1177 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 },
1179 {
1180 .ctl_name = VM_BLOCK_DUMP,
1181 .procname = "block_dump",
1182 .data = &block_dump,
1183 .maxlen = sizeof(block_dump),
1184 .mode = 0644,
1185 .proc_handler = &proc_dointvec,
1186 .strategy = &sysctl_intvec,
1187 .extra1 = &zero,
1188 },
1189 {
1190 .ctl_name = VM_VFS_CACHE_PRESSURE,
1191 .procname = "vfs_cache_pressure",
1192 .data = &sysctl_vfs_cache_pressure,
1193 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1194 .mode = 0644,
1195 .proc_handler = &proc_dointvec,
1196 .strategy = &sysctl_intvec,
1197 .extra1 = &zero,
1198 },
1199#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1200 {
1201 .ctl_name = VM_LEGACY_VA_LAYOUT,
1202 .procname = "legacy_va_layout",
1203 .data = &sysctl_legacy_va_layout,
1204 .maxlen = sizeof(sysctl_legacy_va_layout),
1205 .mode = 0644,
1206 .proc_handler = &proc_dointvec,
1207 .strategy = &sysctl_intvec,
1208 .extra1 = &zero,
1209 },
1210#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001211#ifdef CONFIG_NUMA
1212 {
1213 .ctl_name = VM_ZONE_RECLAIM_MODE,
1214 .procname = "zone_reclaim_mode",
1215 .data = &zone_reclaim_mode,
1216 .maxlen = sizeof(zone_reclaim_mode),
1217 .mode = 0644,
1218 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001219 .strategy = &sysctl_intvec,
1220 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001221 },
Christoph Lameter96146342006-07-03 00:24:13 -07001222 {
1223 .ctl_name = VM_MIN_UNMAPPED,
1224 .procname = "min_unmapped_ratio",
1225 .data = &sysctl_min_unmapped_ratio,
1226 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1227 .mode = 0644,
1228 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1229 .strategy = &sysctl_intvec,
1230 .extra1 = &zero,
1231 .extra2 = &one_hundred,
1232 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001233 {
1234 .ctl_name = VM_MIN_SLAB,
1235 .procname = "min_slab_ratio",
1236 .data = &sysctl_min_slab_ratio,
1237 .maxlen = sizeof(sysctl_min_slab_ratio),
1238 .mode = 0644,
1239 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1240 .strategy = &sysctl_intvec,
1241 .extra1 = &zero,
1242 .extra2 = &one_hundred,
1243 },
Christoph Lameter17436602006-01-18 17:42:32 -08001244#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001245#ifdef CONFIG_SMP
1246 {
1247 .ctl_name = CTL_UNNUMBERED,
1248 .procname = "stat_interval",
1249 .data = &sysctl_stat_interval,
1250 .maxlen = sizeof(sysctl_stat_interval),
1251 .mode = 0644,
1252 .proc_handler = &proc_dointvec_jiffies,
1253 .strategy = &sysctl_jiffies,
1254 },
1255#endif
Eric Parised032182007-06-28 15:55:21 -04001256#ifdef CONFIG_SECURITY
1257 {
1258 .ctl_name = CTL_UNNUMBERED,
1259 .procname = "mmap_min_addr",
1260 .data = &mmap_min_addr,
1261 .maxlen = sizeof(unsigned long),
1262 .mode = 0644,
1263 .proc_handler = &proc_doulongvec_minmax,
1264 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001265#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001266#ifdef CONFIG_NUMA
1267 {
1268 .ctl_name = CTL_UNNUMBERED,
1269 .procname = "numa_zonelist_order",
1270 .data = &numa_zonelist_order,
1271 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1272 .mode = 0644,
1273 .proc_handler = &numa_zonelist_order_handler,
1274 .strategy = &sysctl_string,
1275 },
1276#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001277#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001278 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001279 {
1280 .ctl_name = VM_VDSO_ENABLED,
1281 .procname = "vdso_enabled",
1282 .data = &vdso_enabled,
1283 .maxlen = sizeof(vdso_enabled),
1284 .mode = 0644,
1285 .proc_handler = &proc_dointvec,
1286 .strategy = &sysctl_intvec,
1287 .extra1 = &zero,
1288 },
1289#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001290#ifdef CONFIG_HIGHMEM
1291 {
1292 .ctl_name = CTL_UNNUMBERED,
1293 .procname = "highmem_is_dirtyable",
1294 .data = &vm_highmem_is_dirtyable,
1295 .maxlen = sizeof(vm_highmem_is_dirtyable),
1296 .mode = 0644,
1297 .proc_handler = &proc_dointvec_minmax,
1298 .strategy = &sysctl_intvec,
1299 .extra1 = &zero,
1300 .extra2 = &one,
1301 },
1302#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001303#ifdef CONFIG_UNEVICTABLE_LRU
1304 {
1305 .ctl_name = CTL_UNNUMBERED,
1306 .procname = "scan_unevictable_pages",
1307 .data = &scan_unevictable_pages,
1308 .maxlen = sizeof(scan_unevictable_pages),
1309 .mode = 0644,
1310 .proc_handler = &scan_unevictable_handler,
1311 },
1312#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001313/*
1314 * NOTE: do not add new entries to this table unless you have read
1315 * Documentation/sysctl/ctl_unnumbered.txt
1316 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 { .ctl_name = 0 }
1318};
1319
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001320#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001321static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001322 { .ctl_name = 0 }
1323};
1324#endif
1325
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001326static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 {
1328 .ctl_name = FS_NRINODE,
1329 .procname = "inode-nr",
1330 .data = &inodes_stat,
1331 .maxlen = 2*sizeof(int),
1332 .mode = 0444,
1333 .proc_handler = &proc_dointvec,
1334 },
1335 {
1336 .ctl_name = FS_STATINODE,
1337 .procname = "inode-state",
1338 .data = &inodes_stat,
1339 .maxlen = 7*sizeof(int),
1340 .mode = 0444,
1341 .proc_handler = &proc_dointvec,
1342 },
1343 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 .procname = "file-nr",
1345 .data = &files_stat,
1346 .maxlen = 3*sizeof(int),
1347 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001348 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 },
1350 {
1351 .ctl_name = FS_MAXFILE,
1352 .procname = "file-max",
1353 .data = &files_stat.max_files,
1354 .maxlen = sizeof(int),
1355 .mode = 0644,
1356 .proc_handler = &proc_dointvec,
1357 },
1358 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001359 .ctl_name = CTL_UNNUMBERED,
1360 .procname = "nr_open",
1361 .data = &sysctl_nr_open,
1362 .maxlen = sizeof(int),
1363 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001364 .proc_handler = &proc_dointvec_minmax,
1365 .extra1 = &sysctl_nr_open_min,
1366 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001367 },
1368 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .ctl_name = FS_DENTRY,
1370 .procname = "dentry-state",
1371 .data = &dentry_stat,
1372 .maxlen = 6*sizeof(int),
1373 .mode = 0444,
1374 .proc_handler = &proc_dointvec,
1375 },
1376 {
1377 .ctl_name = FS_OVERFLOWUID,
1378 .procname = "overflowuid",
1379 .data = &fs_overflowuid,
1380 .maxlen = sizeof(int),
1381 .mode = 0644,
1382 .proc_handler = &proc_dointvec_minmax,
1383 .strategy = &sysctl_intvec,
1384 .extra1 = &minolduid,
1385 .extra2 = &maxolduid,
1386 },
1387 {
1388 .ctl_name = FS_OVERFLOWGID,
1389 .procname = "overflowgid",
1390 .data = &fs_overflowgid,
1391 .maxlen = sizeof(int),
1392 .mode = 0644,
1393 .proc_handler = &proc_dointvec_minmax,
1394 .strategy = &sysctl_intvec,
1395 .extra1 = &minolduid,
1396 .extra2 = &maxolduid,
1397 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001398#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 {
1400 .ctl_name = FS_LEASES,
1401 .procname = "leases-enable",
1402 .data = &leases_enable,
1403 .maxlen = sizeof(int),
1404 .mode = 0644,
1405 .proc_handler = &proc_dointvec,
1406 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001407#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408#ifdef CONFIG_DNOTIFY
1409 {
1410 .ctl_name = FS_DIR_NOTIFY,
1411 .procname = "dir-notify-enable",
1412 .data = &dir_notify_enable,
1413 .maxlen = sizeof(int),
1414 .mode = 0644,
1415 .proc_handler = &proc_dointvec,
1416 },
1417#endif
1418#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001419#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 {
1421 .ctl_name = FS_LEASE_TIME,
1422 .procname = "lease-break-time",
1423 .data = &lease_break_time,
1424 .maxlen = sizeof(int),
1425 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001426 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001428#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001429#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 .procname = "aio-nr",
1432 .data = &aio_nr,
1433 .maxlen = sizeof(aio_nr),
1434 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001435 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 },
1437 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 .procname = "aio-max-nr",
1439 .data = &aio_max_nr,
1440 .maxlen = sizeof(aio_max_nr),
1441 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001442 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001444#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001445#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001446 {
1447 .ctl_name = FS_INOTIFY,
1448 .procname = "inotify",
1449 .mode = 0555,
1450 .child = inotify_table,
1451 },
1452#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001453#ifdef CONFIG_EPOLL
1454 {
1455 .procname = "epoll",
1456 .mode = 0555,
1457 .child = epoll_table,
1458 },
1459#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001461 {
1462 .ctl_name = KERN_SETUID_DUMPABLE,
1463 .procname = "suid_dumpable",
1464 .data = &suid_dumpable,
1465 .maxlen = sizeof(int),
1466 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001467 .proc_handler = &proc_dointvec_minmax,
1468 .strategy = &sysctl_intvec,
1469 .extra1 = &zero,
1470 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001471 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001472#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1473 {
1474 .ctl_name = CTL_UNNUMBERED,
1475 .procname = "binfmt_misc",
1476 .mode = 0555,
1477 .child = binfmt_misc_table,
1478 },
1479#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001480/*
1481 * NOTE: do not add new entries to this table unless you have read
1482 * Documentation/sysctl/ctl_unnumbered.txt
1483 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 { .ctl_name = 0 }
1485};
1486
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001487static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001488#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001489 {
1490 .ctl_name = CTL_UNNUMBERED,
1491 .procname = "exception-trace",
1492 .data = &show_unhandled_signals,
1493 .maxlen = sizeof(int),
1494 .mode = 0644,
1495 .proc_handler = proc_dointvec
1496 },
1497#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 { .ctl_name = 0 }
1499};
1500
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001501static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001503};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
Al Viro330d57f2005-11-04 10:18:40 +00001505static DEFINE_SPINLOCK(sysctl_lock);
1506
1507/* called under sysctl_lock */
1508static int use_table(struct ctl_table_header *p)
1509{
1510 if (unlikely(p->unregistering))
1511 return 0;
1512 p->used++;
1513 return 1;
1514}
1515
1516/* called under sysctl_lock */
1517static void unuse_table(struct ctl_table_header *p)
1518{
1519 if (!--p->used)
1520 if (unlikely(p->unregistering))
1521 complete(p->unregistering);
1522}
1523
1524/* called under sysctl_lock, will reacquire if has to wait */
1525static void start_unregistering(struct ctl_table_header *p)
1526{
1527 /*
1528 * if p->used is 0, nobody will ever touch that entry again;
1529 * we'll eliminate all paths to it before dropping sysctl_lock
1530 */
1531 if (unlikely(p->used)) {
1532 struct completion wait;
1533 init_completion(&wait);
1534 p->unregistering = &wait;
1535 spin_unlock(&sysctl_lock);
1536 wait_for_completion(&wait);
1537 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001538 } else {
1539 /* anything non-NULL; we'll never dereference it */
1540 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001541 }
1542 /*
1543 * do not remove from the list until nobody holds it; walking the
1544 * list in do_sysctl() relies on that.
1545 */
1546 list_del_init(&p->ctl_entry);
1547}
1548
Al Virof7e6ced2008-07-15 01:44:23 -04001549void sysctl_head_get(struct ctl_table_header *head)
1550{
1551 spin_lock(&sysctl_lock);
1552 head->count++;
1553 spin_unlock(&sysctl_lock);
1554}
1555
1556void sysctl_head_put(struct ctl_table_header *head)
1557{
1558 spin_lock(&sysctl_lock);
1559 if (!--head->count)
1560 kfree(head);
1561 spin_unlock(&sysctl_lock);
1562}
1563
1564struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1565{
1566 if (!head)
1567 BUG();
1568 spin_lock(&sysctl_lock);
1569 if (!use_table(head))
1570 head = ERR_PTR(-ENOENT);
1571 spin_unlock(&sysctl_lock);
1572 return head;
1573}
1574
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001575void sysctl_head_finish(struct ctl_table_header *head)
1576{
1577 if (!head)
1578 return;
1579 spin_lock(&sysctl_lock);
1580 unuse_table(head);
1581 spin_unlock(&sysctl_lock);
1582}
1583
Al Viro73455092008-07-14 21:22:20 -04001584static struct ctl_table_set *
1585lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1586{
1587 struct ctl_table_set *set = &root->default_set;
1588 if (root->lookup)
1589 set = root->lookup(root, namespaces);
1590 return set;
1591}
1592
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001593static struct list_head *
1594lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001595{
Al Viro73455092008-07-14 21:22:20 -04001596 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1597 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001598}
1599
1600struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1601 struct ctl_table_header *prev)
1602{
1603 struct ctl_table_root *root;
1604 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001605 struct ctl_table_header *head;
1606 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001607
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001608 spin_lock(&sysctl_lock);
1609 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001610 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001611 tmp = &prev->ctl_entry;
1612 unuse_table(prev);
1613 goto next;
1614 }
1615 tmp = &root_table_header.ctl_entry;
1616 for (;;) {
1617 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1618
1619 if (!use_table(head))
1620 goto next;
1621 spin_unlock(&sysctl_lock);
1622 return head;
1623 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001624 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001625 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001626 header_list = lookup_header_list(root, namespaces);
1627 if (tmp != header_list)
1628 continue;
1629
1630 do {
1631 root = list_entry(root->root_list.next,
1632 struct ctl_table_root, root_list);
1633 if (root == &sysctl_table_root)
1634 goto out;
1635 header_list = lookup_header_list(root, namespaces);
1636 } while (list_empty(header_list));
1637 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001638 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001639out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001640 spin_unlock(&sysctl_lock);
1641 return NULL;
1642}
1643
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001644struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1645{
1646 return __sysctl_head_next(current->nsproxy, prev);
1647}
1648
1649void register_sysctl_root(struct ctl_table_root *root)
1650{
1651 spin_lock(&sysctl_lock);
1652 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1653 spin_unlock(&sysctl_lock);
1654}
1655
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001656#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001657/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001658static int do_sysctl_strategy(struct ctl_table_root *root,
1659 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001660 void __user *oldval, size_t __user *oldlenp,
1661 void __user *newval, size_t newlen)
1662{
1663 int op = 0, rc;
1664
1665 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001666 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001667 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001668 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001669 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001670 return -EPERM;
1671
1672 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001673 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001674 if (rc < 0)
1675 return rc;
1676 if (rc > 0)
1677 return 0;
1678 }
1679
1680 /* If there is no strategy routine, or if the strategy returns
1681 * zero, proceed with automatic r/w */
1682 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001683 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001684 if (rc < 0)
1685 return rc;
1686 }
1687 return 0;
1688}
1689
1690static int parse_table(int __user *name, int nlen,
1691 void __user *oldval, size_t __user *oldlenp,
1692 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001693 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001694 struct ctl_table *table)
1695{
1696 int n;
1697repeat:
1698 if (!nlen)
1699 return -ENOTDIR;
1700 if (get_user(n, name))
1701 return -EFAULT;
1702 for ( ; table->ctl_name || table->procname; table++) {
1703 if (!table->ctl_name)
1704 continue;
1705 if (n == table->ctl_name) {
1706 int error;
1707 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001708 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001709 return -EPERM;
1710 name++;
1711 nlen--;
1712 table = table->child;
1713 goto repeat;
1714 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001715 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001716 oldval, oldlenp,
1717 newval, newlen);
1718 return error;
1719 }
1720 }
1721 return -ENOTDIR;
1722}
1723
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1725 void __user *newval, size_t newlen)
1726{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001727 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001728 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
1730 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1731 return -ENOTDIR;
1732 if (oldval) {
1733 int old_len;
1734 if (!oldlenp || get_user(old_len, oldlenp))
1735 return -EFAULT;
1736 }
Al Viro330d57f2005-11-04 10:18:40 +00001737
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001738 for (head = sysctl_head_next(NULL); head;
1739 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001740 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001741 newval, newlen,
1742 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001743 if (error != -ENOTDIR) {
1744 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001745 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001746 }
1747 }
Al Viro330d57f2005-11-04 10:18:40 +00001748 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001751SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752{
1753 struct __sysctl_args tmp;
1754 int error;
1755
1756 if (copy_from_user(&tmp, args, sizeof(tmp)))
1757 return -EFAULT;
1758
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001759 error = deprecated_sysctl_warning(&tmp);
1760 if (error)
1761 goto out;
1762
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 lock_kernel();
1764 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1765 tmp.newval, tmp.newlen);
1766 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001767out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 return error;
1769}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001770#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001773 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 * some sysctl variables are readonly even to root.
1775 */
1776
1777static int test_perm(int mode, int op)
1778{
David Howells76aac0e2008-11-14 10:39:12 +11001779 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 mode >>= 6;
1781 else if (in_egroup_p(0))
1782 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001783 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 return 0;
1785 return -EACCES;
1786}
1787
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001788int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789{
1790 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001791 int mode;
1792
Al Viroe6305c42008-07-15 21:03:57 -04001793 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 if (error)
1795 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001796
1797 if (root->permissions)
1798 mode = root->permissions(root, current->nsproxy, table);
1799 else
1800 mode = table->mode;
1801
1802 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803}
1804
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001805static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1806{
1807 for (; table->ctl_name || table->procname; table++) {
1808 table->parent = parent;
1809 if (table->child)
1810 sysctl_set_parent(table, table->child);
1811 }
1812}
1813
1814static __init int sysctl_init(void)
1815{
1816 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001817#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1818 {
1819 int err;
1820 err = sysctl_check_table(current->nsproxy, root_table);
1821 }
1822#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001823 return 0;
1824}
1825
1826core_initcall(sysctl_init);
1827
Al Virobfbcf032008-07-27 06:31:22 +01001828static struct ctl_table *is_branch_in(struct ctl_table *branch,
1829 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001830{
1831 struct ctl_table *p;
1832 const char *s = branch->procname;
1833
1834 /* branch should have named subdirectory as its first element */
1835 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001836 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001837
1838 /* ... and nothing else */
1839 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001840 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001841
1842 /* table should contain subdirectory with the same name */
1843 for (p = table; p->procname || p->ctl_name; p++) {
1844 if (!p->child)
1845 continue;
1846 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001847 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001848 }
Al Virobfbcf032008-07-27 06:31:22 +01001849 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001850}
1851
1852/* see if attaching q to p would be an improvement */
1853static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1854{
1855 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001856 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001857 int is_better = 0;
1858 int not_in_parent = !p->attached_by;
1859
Al Virobfbcf032008-07-27 06:31:22 +01001860 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001861 if (by == q->attached_by)
1862 is_better = 1;
1863 if (to == p->attached_by)
1864 not_in_parent = 1;
1865 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001866 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001867 }
1868
1869 if (is_better && not_in_parent) {
1870 q->attached_by = by;
1871 q->attached_to = to;
1872 q->parent = p;
1873 }
1874}
1875
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001877 * __register_sysctl_paths - register a sysctl hierarchy
1878 * @root: List of sysctl headers to register on
1879 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001880 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 *
1883 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001884 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001886 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 *
1888 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1889 * must be unique within that level of sysctl
1890 *
1891 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1892 * enter a sysctl file
1893 *
1894 * data - a pointer to data for use by proc_handler
1895 *
1896 * maxlen - the maximum size in bytes of the data
1897 *
1898 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1899 *
1900 * child - a pointer to the child sysctl table if this entry is a directory, or
1901 * %NULL.
1902 *
1903 * proc_handler - the text handler routine (described below)
1904 *
1905 * strategy - the strategy routine (described below)
1906 *
1907 * de - for internal use by the sysctl routines
1908 *
1909 * extra1, extra2 - extra pointers usable by the proc handler routines
1910 *
1911 * Leaf nodes in the sysctl tree will be represented by a single file
1912 * under /proc; non-leaf nodes will be represented by directories.
1913 *
1914 * sysctl(2) can automatically manage read and write requests through
1915 * the sysctl table. The data and maxlen fields of the ctl_table
1916 * struct enable minimal validation of the values being written to be
1917 * performed, and the mode field allows minimal authentication.
1918 *
1919 * More sophisticated management can be enabled by the provision of a
1920 * strategy routine with the table entry. This will be called before
1921 * any automatic read or write of the data is performed.
1922 *
1923 * The strategy routine may return
1924 *
1925 * < 0 - Error occurred (error is passed to user process)
1926 *
1927 * 0 - OK - proceed with automatic read or write.
1928 *
1929 * > 0 - OK - read or write has been done by the strategy routine, so
1930 * return immediately.
1931 *
1932 * There must be a proc_handler routine for any terminal nodes
1933 * mirrored under /proc/sys (non-terminals are handled by a built-in
1934 * directory handler). Several default handlers are available to
1935 * cover common cases -
1936 *
1937 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1938 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1939 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1940 *
1941 * It is the handler's job to read the input buffer from user memory
1942 * and process it. The handler should return 0 on success.
1943 *
1944 * This routine returns %NULL on a failure to register, and a pointer
1945 * to the table header on success.
1946 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001947struct ctl_table_header *__register_sysctl_paths(
1948 struct ctl_table_root *root,
1949 struct nsproxy *namespaces,
1950 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001952 struct ctl_table_header *header;
1953 struct ctl_table *new, **prevp;
1954 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001955 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001956
1957 /* Count the path components */
1958 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1959 ;
1960
1961 /*
1962 * For each path component, allocate a 2-element ctl_table array.
1963 * The first array element will be filled with the sysctl entry
1964 * for this, the second will be the sentinel (ctl_name == 0).
1965 *
1966 * We allocate everything in one go so that we don't have to
1967 * worry about freeing additional memory in unregister_sysctl_table.
1968 */
1969 header = kzalloc(sizeof(struct ctl_table_header) +
1970 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1971 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001973
1974 new = (struct ctl_table *) (header + 1);
1975
1976 /* Now connect the dots */
1977 prevp = &header->ctl_table;
1978 for (n = 0; n < npath; ++n, ++path) {
1979 /* Copy the procname */
1980 new->procname = path->procname;
1981 new->ctl_name = path->ctl_name;
1982 new->mode = 0555;
1983
1984 *prevp = new;
1985 prevp = &new->child;
1986
1987 new += 2;
1988 }
1989 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001990 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001991
1992 INIT_LIST_HEAD(&header->ctl_entry);
1993 header->used = 0;
1994 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001995 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001996 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001997 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001998#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001999 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002000 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002001 return NULL;
2002 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002003#endif
Al Viro330d57f2005-11-04 10:18:40 +00002004 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002005 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002006 header->attached_by = header->ctl_table;
2007 header->attached_to = root_table;
2008 header->parent = &root_table_header;
2009 for (set = header->set; set; set = set->parent) {
2010 struct ctl_table_header *p;
2011 list_for_each_entry(p, &set->list, ctl_entry) {
2012 if (p->unregistering)
2013 continue;
2014 try_attach(p, header);
2015 }
2016 }
2017 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002018 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002019 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002020
2021 return header;
2022}
2023
2024/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002025 * register_sysctl_table_path - register a sysctl table hierarchy
2026 * @path: The path to the directory the sysctl table is in.
2027 * @table: the top-level table structure
2028 *
2029 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2030 * array. A completely 0 filled entry terminates the table.
2031 *
2032 * See __register_sysctl_paths for more details.
2033 */
2034struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2035 struct ctl_table *table)
2036{
2037 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2038 path, table);
2039}
2040
2041/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002042 * register_sysctl_table - register a sysctl table hierarchy
2043 * @table: the top-level table structure
2044 *
2045 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2046 * array. A completely 0 filled entry terminates the table.
2047 *
2048 * See register_sysctl_paths for more details.
2049 */
2050struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2051{
2052 static const struct ctl_path null_path[] = { {} };
2053
2054 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055}
2056
2057/**
2058 * unregister_sysctl_table - unregister a sysctl table hierarchy
2059 * @header: the header returned from register_sysctl_table
2060 *
2061 * Unregisters the sysctl table and all children. proc entries may not
2062 * actually be removed until they are no longer used by anyone.
2063 */
2064void unregister_sysctl_table(struct ctl_table_header * header)
2065{
Al Viro330d57f2005-11-04 10:18:40 +00002066 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002067
2068 if (header == NULL)
2069 return;
2070
Al Viro330d57f2005-11-04 10:18:40 +00002071 spin_lock(&sysctl_lock);
2072 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002073 if (!--header->parent->count) {
2074 WARN_ON(1);
2075 kfree(header->parent);
2076 }
Al Virof7e6ced2008-07-15 01:44:23 -04002077 if (!--header->count)
2078 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002079 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080}
2081
Al Viro9043476f2008-07-15 08:54:06 -04002082int sysctl_is_seen(struct ctl_table_header *p)
2083{
2084 struct ctl_table_set *set = p->set;
2085 int res;
2086 spin_lock(&sysctl_lock);
2087 if (p->unregistering)
2088 res = 0;
2089 else if (!set->is_seen)
2090 res = 1;
2091 else
2092 res = set->is_seen(set);
2093 spin_unlock(&sysctl_lock);
2094 return res;
2095}
2096
Al Viro73455092008-07-14 21:22:20 -04002097void setup_sysctl_set(struct ctl_table_set *p,
2098 struct ctl_table_set *parent,
2099 int (*is_seen)(struct ctl_table_set *))
2100{
2101 INIT_LIST_HEAD(&p->list);
2102 p->parent = parent ? parent : &sysctl_table_root.default_set;
2103 p->is_seen = is_seen;
2104}
2105
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002106#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002107struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002108{
2109 return NULL;
2110}
2111
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002112struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2113 struct ctl_table *table)
2114{
2115 return NULL;
2116}
2117
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002118void unregister_sysctl_table(struct ctl_table_header * table)
2119{
2120}
2121
Al Viro73455092008-07-14 21:22:20 -04002122void setup_sysctl_set(struct ctl_table_set *p,
2123 struct ctl_table_set *parent,
2124 int (*is_seen)(struct ctl_table_set *))
2125{
2126}
2127
Al Virof7e6ced2008-07-15 01:44:23 -04002128void sysctl_head_put(struct ctl_table_header *head)
2129{
2130}
2131
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002132#endif /* CONFIG_SYSCTL */
2133
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134/*
2135 * /proc/sys support
2136 */
2137
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002138#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002140static int _proc_do_string(void* data, int maxlen, int write,
2141 struct file *filp, void __user *buffer,
2142 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002143{
2144 size_t len;
2145 char __user *p;
2146 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002147
2148 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002149 *lenp = 0;
2150 return 0;
2151 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002152
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002153 if (write) {
2154 len = 0;
2155 p = buffer;
2156 while (len < *lenp) {
2157 if (get_user(c, p++))
2158 return -EFAULT;
2159 if (c == 0 || c == '\n')
2160 break;
2161 len++;
2162 }
2163 if (len >= maxlen)
2164 len = maxlen-1;
2165 if(copy_from_user(data, buffer, len))
2166 return -EFAULT;
2167 ((char *) data)[len] = 0;
2168 *ppos += *lenp;
2169 } else {
2170 len = strlen(data);
2171 if (len > maxlen)
2172 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002173
2174 if (*ppos > len) {
2175 *lenp = 0;
2176 return 0;
2177 }
2178
2179 data += *ppos;
2180 len -= *ppos;
2181
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002182 if (len > *lenp)
2183 len = *lenp;
2184 if (len)
2185 if(copy_to_user(buffer, data, len))
2186 return -EFAULT;
2187 if (len < *lenp) {
2188 if(put_user('\n', ((char __user *) buffer) + len))
2189 return -EFAULT;
2190 len++;
2191 }
2192 *lenp = len;
2193 *ppos += len;
2194 }
2195 return 0;
2196}
2197
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198/**
2199 * proc_dostring - read a string sysctl
2200 * @table: the sysctl table
2201 * @write: %TRUE if this is a write to the sysctl file
2202 * @filp: the file structure
2203 * @buffer: the user buffer
2204 * @lenp: the size of the user buffer
2205 * @ppos: file position
2206 *
2207 * Reads/writes a string from/to the user buffer. If the kernel
2208 * buffer provided is not large enough to hold the string, the
2209 * string is truncated. The copied string is %NULL-terminated.
2210 * If the string is being read by the user process, it is copied
2211 * and a newline '\n' is added. It is truncated if the buffer is
2212 * not large enough.
2213 *
2214 * Returns 0 on success.
2215 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002216int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 void __user *buffer, size_t *lenp, loff_t *ppos)
2218{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002219 return _proc_do_string(table->data, table->maxlen, write, filp,
2220 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221}
2222
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
2224static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2225 int *valp,
2226 int write, void *data)
2227{
2228 if (write) {
2229 *valp = *negp ? -*lvalp : *lvalp;
2230 } else {
2231 int val = *valp;
2232 if (val < 0) {
2233 *negp = -1;
2234 *lvalp = (unsigned long)-val;
2235 } else {
2236 *negp = 0;
2237 *lvalp = (unsigned long)val;
2238 }
2239 }
2240 return 0;
2241}
2242
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002243static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002244 int write, struct file *filp, void __user *buffer,
2245 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2247 int write, void *data),
2248 void *data)
2249{
2250#define TMPBUFLEN 21
2251 int *i, vleft, first=1, neg, val;
2252 unsigned long lval;
2253 size_t left, len;
2254
2255 char buf[TMPBUFLEN], *p;
2256 char __user *s = buffer;
2257
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002258 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 (*ppos && !write)) {
2260 *lenp = 0;
2261 return 0;
2262 }
2263
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002264 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 vleft = table->maxlen / sizeof(*i);
2266 left = *lenp;
2267
2268 if (!conv)
2269 conv = do_proc_dointvec_conv;
2270
2271 for (; left && vleft--; i++, first=0) {
2272 if (write) {
2273 while (left) {
2274 char c;
2275 if (get_user(c, s))
2276 return -EFAULT;
2277 if (!isspace(c))
2278 break;
2279 left--;
2280 s++;
2281 }
2282 if (!left)
2283 break;
2284 neg = 0;
2285 len = left;
2286 if (len > sizeof(buf) - 1)
2287 len = sizeof(buf) - 1;
2288 if (copy_from_user(buf, s, len))
2289 return -EFAULT;
2290 buf[len] = 0;
2291 p = buf;
2292 if (*p == '-' && left > 1) {
2293 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002294 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 }
2296 if (*p < '0' || *p > '9')
2297 break;
2298
2299 lval = simple_strtoul(p, &p, 0);
2300
2301 len = p-buf;
2302 if ((len < left) && *p && !isspace(*p))
2303 break;
2304 if (neg)
2305 val = -val;
2306 s += len;
2307 left -= len;
2308
2309 if (conv(&neg, &lval, i, 1, data))
2310 break;
2311 } else {
2312 p = buf;
2313 if (!first)
2314 *p++ = '\t';
2315
2316 if (conv(&neg, &lval, i, 0, data))
2317 break;
2318
2319 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2320 len = strlen(buf);
2321 if (len > left)
2322 len = left;
2323 if(copy_to_user(s, buf, len))
2324 return -EFAULT;
2325 left -= len;
2326 s += len;
2327 }
2328 }
2329
2330 if (!write && !first && left) {
2331 if(put_user('\n', s))
2332 return -EFAULT;
2333 left--, s++;
2334 }
2335 if (write) {
2336 while (left) {
2337 char c;
2338 if (get_user(c, s++))
2339 return -EFAULT;
2340 if (!isspace(c))
2341 break;
2342 left--;
2343 }
2344 }
2345 if (write && first)
2346 return -EINVAL;
2347 *lenp -= left;
2348 *ppos += *lenp;
2349 return 0;
2350#undef TMPBUFLEN
2351}
2352
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002353static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002354 void __user *buffer, size_t *lenp, loff_t *ppos,
2355 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2356 int write, void *data),
2357 void *data)
2358{
2359 return __do_proc_dointvec(table->data, table, write, filp,
2360 buffer, lenp, ppos, conv, data);
2361}
2362
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363/**
2364 * proc_dointvec - read a vector of integers
2365 * @table: the sysctl table
2366 * @write: %TRUE if this is a write to the sysctl file
2367 * @filp: the file structure
2368 * @buffer: the user buffer
2369 * @lenp: the size of the user buffer
2370 * @ppos: file position
2371 *
2372 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2373 * values from/to the user buffer, treated as an ASCII string.
2374 *
2375 * Returns 0 on success.
2376 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002377int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 void __user *buffer, size_t *lenp, loff_t *ppos)
2379{
2380 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2381 NULL,NULL);
2382}
2383
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002384/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002385 * Taint values can only be increased
2386 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002387 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002388static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002389 void __user *buffer, size_t *lenp, loff_t *ppos)
2390{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002391 struct ctl_table t;
2392 unsigned long tmptaint = get_taint();
2393 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002394
Bastian Blank91fcd412007-04-23 14:41:14 -07002395 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002396 return -EPERM;
2397
Andi Kleen25ddbb12008-10-15 22:01:41 -07002398 t = *table;
2399 t.data = &tmptaint;
2400 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2401 if (err < 0)
2402 return err;
2403
2404 if (write) {
2405 /*
2406 * Poor man's atomic or. Not worth adding a primitive
2407 * to everyone's atomic.h for this
2408 */
2409 int i;
2410 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2411 if ((tmptaint >> i) & 1)
2412 add_taint(i);
2413 }
2414 }
2415
2416 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002417}
2418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419struct do_proc_dointvec_minmax_conv_param {
2420 int *min;
2421 int *max;
2422};
2423
2424static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2425 int *valp,
2426 int write, void *data)
2427{
2428 struct do_proc_dointvec_minmax_conv_param *param = data;
2429 if (write) {
2430 int val = *negp ? -*lvalp : *lvalp;
2431 if ((param->min && *param->min > val) ||
2432 (param->max && *param->max < val))
2433 return -EINVAL;
2434 *valp = val;
2435 } else {
2436 int val = *valp;
2437 if (val < 0) {
2438 *negp = -1;
2439 *lvalp = (unsigned long)-val;
2440 } else {
2441 *negp = 0;
2442 *lvalp = (unsigned long)val;
2443 }
2444 }
2445 return 0;
2446}
2447
2448/**
2449 * proc_dointvec_minmax - read a vector of integers with min/max values
2450 * @table: the sysctl table
2451 * @write: %TRUE if this is a write to the sysctl file
2452 * @filp: the file structure
2453 * @buffer: the user buffer
2454 * @lenp: the size of the user buffer
2455 * @ppos: file position
2456 *
2457 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2458 * values from/to the user buffer, treated as an ASCII string.
2459 *
2460 * This routine will ensure the values are within the range specified by
2461 * table->extra1 (min) and table->extra2 (max).
2462 *
2463 * Returns 0 on success.
2464 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002465int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 void __user *buffer, size_t *lenp, loff_t *ppos)
2467{
2468 struct do_proc_dointvec_minmax_conv_param param = {
2469 .min = (int *) table->extra1,
2470 .max = (int *) table->extra2,
2471 };
2472 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2473 do_proc_dointvec_minmax_conv, &param);
2474}
2475
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002476static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 struct file *filp,
2478 void __user *buffer,
2479 size_t *lenp, loff_t *ppos,
2480 unsigned long convmul,
2481 unsigned long convdiv)
2482{
2483#define TMPBUFLEN 21
2484 unsigned long *i, *min, *max, val;
2485 int vleft, first=1, neg;
2486 size_t len, left;
2487 char buf[TMPBUFLEN], *p;
2488 char __user *s = buffer;
2489
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002490 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 (*ppos && !write)) {
2492 *lenp = 0;
2493 return 0;
2494 }
2495
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002496 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 min = (unsigned long *) table->extra1;
2498 max = (unsigned long *) table->extra2;
2499 vleft = table->maxlen / sizeof(unsigned long);
2500 left = *lenp;
2501
2502 for (; left && vleft--; i++, min++, max++, first=0) {
2503 if (write) {
2504 while (left) {
2505 char c;
2506 if (get_user(c, s))
2507 return -EFAULT;
2508 if (!isspace(c))
2509 break;
2510 left--;
2511 s++;
2512 }
2513 if (!left)
2514 break;
2515 neg = 0;
2516 len = left;
2517 if (len > TMPBUFLEN-1)
2518 len = TMPBUFLEN-1;
2519 if (copy_from_user(buf, s, len))
2520 return -EFAULT;
2521 buf[len] = 0;
2522 p = buf;
2523 if (*p == '-' && left > 1) {
2524 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002525 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 }
2527 if (*p < '0' || *p > '9')
2528 break;
2529 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2530 len = p-buf;
2531 if ((len < left) && *p && !isspace(*p))
2532 break;
2533 if (neg)
2534 val = -val;
2535 s += len;
2536 left -= len;
2537
2538 if(neg)
2539 continue;
2540 if ((min && val < *min) || (max && val > *max))
2541 continue;
2542 *i = val;
2543 } else {
2544 p = buf;
2545 if (!first)
2546 *p++ = '\t';
2547 sprintf(p, "%lu", convdiv * (*i) / convmul);
2548 len = strlen(buf);
2549 if (len > left)
2550 len = left;
2551 if(copy_to_user(s, buf, len))
2552 return -EFAULT;
2553 left -= len;
2554 s += len;
2555 }
2556 }
2557
2558 if (!write && !first && left) {
2559 if(put_user('\n', s))
2560 return -EFAULT;
2561 left--, s++;
2562 }
2563 if (write) {
2564 while (left) {
2565 char c;
2566 if (get_user(c, s++))
2567 return -EFAULT;
2568 if (!isspace(c))
2569 break;
2570 left--;
2571 }
2572 }
2573 if (write && first)
2574 return -EINVAL;
2575 *lenp -= left;
2576 *ppos += *lenp;
2577 return 0;
2578#undef TMPBUFLEN
2579}
2580
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002581static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002582 struct file *filp,
2583 void __user *buffer,
2584 size_t *lenp, loff_t *ppos,
2585 unsigned long convmul,
2586 unsigned long convdiv)
2587{
2588 return __do_proc_doulongvec_minmax(table->data, table, write,
2589 filp, buffer, lenp, ppos, convmul, convdiv);
2590}
2591
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592/**
2593 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2594 * @table: the sysctl table
2595 * @write: %TRUE if this is a write to the sysctl file
2596 * @filp: the file structure
2597 * @buffer: the user buffer
2598 * @lenp: the size of the user buffer
2599 * @ppos: file position
2600 *
2601 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2602 * values from/to the user buffer, treated as an ASCII string.
2603 *
2604 * This routine will ensure the values are within the range specified by
2605 * table->extra1 (min) and table->extra2 (max).
2606 *
2607 * Returns 0 on success.
2608 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002609int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 void __user *buffer, size_t *lenp, loff_t *ppos)
2611{
2612 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2613}
2614
2615/**
2616 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2617 * @table: the sysctl table
2618 * @write: %TRUE if this is a write to the sysctl file
2619 * @filp: the file structure
2620 * @buffer: the user buffer
2621 * @lenp: the size of the user buffer
2622 * @ppos: file position
2623 *
2624 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2625 * values from/to the user buffer, treated as an ASCII string. The values
2626 * are treated as milliseconds, and converted to jiffies when they are stored.
2627 *
2628 * This routine will ensure the values are within the range specified by
2629 * table->extra1 (min) and table->extra2 (max).
2630 *
2631 * Returns 0 on success.
2632 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002633int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 struct file *filp,
2635 void __user *buffer,
2636 size_t *lenp, loff_t *ppos)
2637{
2638 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2639 lenp, ppos, HZ, 1000l);
2640}
2641
2642
2643static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2644 int *valp,
2645 int write, void *data)
2646{
2647 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002648 if (*lvalp > LONG_MAX / HZ)
2649 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2651 } else {
2652 int val = *valp;
2653 unsigned long lval;
2654 if (val < 0) {
2655 *negp = -1;
2656 lval = (unsigned long)-val;
2657 } else {
2658 *negp = 0;
2659 lval = (unsigned long)val;
2660 }
2661 *lvalp = lval / HZ;
2662 }
2663 return 0;
2664}
2665
2666static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2667 int *valp,
2668 int write, void *data)
2669{
2670 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002671 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2672 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2674 } else {
2675 int val = *valp;
2676 unsigned long lval;
2677 if (val < 0) {
2678 *negp = -1;
2679 lval = (unsigned long)-val;
2680 } else {
2681 *negp = 0;
2682 lval = (unsigned long)val;
2683 }
2684 *lvalp = jiffies_to_clock_t(lval);
2685 }
2686 return 0;
2687}
2688
2689static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2690 int *valp,
2691 int write, void *data)
2692{
2693 if (write) {
2694 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2695 } else {
2696 int val = *valp;
2697 unsigned long lval;
2698 if (val < 0) {
2699 *negp = -1;
2700 lval = (unsigned long)-val;
2701 } else {
2702 *negp = 0;
2703 lval = (unsigned long)val;
2704 }
2705 *lvalp = jiffies_to_msecs(lval);
2706 }
2707 return 0;
2708}
2709
2710/**
2711 * proc_dointvec_jiffies - read a vector of integers as seconds
2712 * @table: the sysctl table
2713 * @write: %TRUE if this is a write to the sysctl file
2714 * @filp: the file structure
2715 * @buffer: the user buffer
2716 * @lenp: the size of the user buffer
2717 * @ppos: file position
2718 *
2719 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2720 * values from/to the user buffer, treated as an ASCII string.
2721 * The values read are assumed to be in seconds, and are converted into
2722 * jiffies.
2723 *
2724 * Returns 0 on success.
2725 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002726int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 void __user *buffer, size_t *lenp, loff_t *ppos)
2728{
2729 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2730 do_proc_dointvec_jiffies_conv,NULL);
2731}
2732
2733/**
2734 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2735 * @table: the sysctl table
2736 * @write: %TRUE if this is a write to the sysctl file
2737 * @filp: the file structure
2738 * @buffer: the user buffer
2739 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002740 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 *
2742 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2743 * values from/to the user buffer, treated as an ASCII string.
2744 * The values read are assumed to be in 1/USER_HZ seconds, and
2745 * are converted into jiffies.
2746 *
2747 * Returns 0 on success.
2748 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002749int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 void __user *buffer, size_t *lenp, loff_t *ppos)
2751{
2752 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2753 do_proc_dointvec_userhz_jiffies_conv,NULL);
2754}
2755
2756/**
2757 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2758 * @table: the sysctl table
2759 * @write: %TRUE if this is a write to the sysctl file
2760 * @filp: the file structure
2761 * @buffer: the user buffer
2762 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002763 * @ppos: file position
2764 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 *
2766 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2767 * values from/to the user buffer, treated as an ASCII string.
2768 * The values read are assumed to be in 1/1000 seconds, and
2769 * are converted into jiffies.
2770 *
2771 * Returns 0 on success.
2772 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002773int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 void __user *buffer, size_t *lenp, loff_t *ppos)
2775{
2776 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2777 do_proc_dointvec_ms_jiffies_conv, NULL);
2778}
2779
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002780static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002781 void __user *buffer, size_t *lenp, loff_t *ppos)
2782{
2783 struct pid *new_pid;
2784 pid_t tmp;
2785 int r;
2786
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002787 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002788
2789 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2790 lenp, ppos, NULL, NULL);
2791 if (r || !write)
2792 return r;
2793
2794 new_pid = find_get_pid(tmp);
2795 if (!new_pid)
2796 return -ESRCH;
2797
2798 put_pid(xchg(&cad_pid, new_pid));
2799 return 0;
2800}
2801
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802#else /* CONFIG_PROC_FS */
2803
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002804int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 void __user *buffer, size_t *lenp, loff_t *ppos)
2806{
2807 return -ENOSYS;
2808}
2809
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002810int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 void __user *buffer, size_t *lenp, loff_t *ppos)
2812{
2813 return -ENOSYS;
2814}
2815
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002816int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 void __user *buffer, size_t *lenp, loff_t *ppos)
2818{
2819 return -ENOSYS;
2820}
2821
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002822int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 void __user *buffer, size_t *lenp, loff_t *ppos)
2824{
2825 return -ENOSYS;
2826}
2827
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002828int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 void __user *buffer, size_t *lenp, loff_t *ppos)
2830{
2831 return -ENOSYS;
2832}
2833
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002834int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 void __user *buffer, size_t *lenp, loff_t *ppos)
2836{
2837 return -ENOSYS;
2838}
2839
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002840int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 void __user *buffer, size_t *lenp, loff_t *ppos)
2842{
2843 return -ENOSYS;
2844}
2845
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002846int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 struct file *filp,
2848 void __user *buffer,
2849 size_t *lenp, loff_t *ppos)
2850{
2851 return -ENOSYS;
2852}
2853
2854
2855#endif /* CONFIG_PROC_FS */
2856
2857
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002858#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859/*
2860 * General sysctl support routines
2861 */
2862
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002863/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002864int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002865 void __user *oldval, size_t __user *oldlenp,
2866 void __user *newval, size_t newlen)
2867{
2868 size_t len;
2869
2870 /* Get out of I don't have a variable */
2871 if (!table->data || !table->maxlen)
2872 return -ENOTDIR;
2873
2874 if (oldval && oldlenp) {
2875 if (get_user(len, oldlenp))
2876 return -EFAULT;
2877 if (len) {
2878 if (len > table->maxlen)
2879 len = table->maxlen;
2880 if (copy_to_user(oldval, table->data, len))
2881 return -EFAULT;
2882 if (put_user(len, oldlenp))
2883 return -EFAULT;
2884 }
2885 }
2886
2887 if (newval && newlen) {
2888 if (newlen > table->maxlen)
2889 newlen = table->maxlen;
2890
2891 if (copy_from_user(table->data, newval, newlen))
2892 return -EFAULT;
2893 }
2894 return 1;
2895}
2896
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002898int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002900 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 if (!table->data || !table->maxlen)
2903 return -ENOTDIR;
2904
2905 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002906 size_t bufsize;
2907 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002909 if (bufsize) {
2910 size_t len = strlen(table->data), copied;
2911
2912 /* This shouldn't trigger for a well-formed sysctl */
2913 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002915
2916 /* Copy up to a max of bufsize-1 bytes of the string */
2917 copied = (len >= bufsize) ? bufsize - 1 : len;
2918
2919 if (copy_to_user(oldval, table->data, copied) ||
2920 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002922 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 return -EFAULT;
2924 }
2925 }
2926 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002927 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 if (len > table->maxlen)
2929 len = table->maxlen;
2930 if(copy_from_user(table->data, newval, len))
2931 return -EFAULT;
2932 if (len == table->maxlen)
2933 len--;
2934 ((char *) table->data)[len] = 0;
2935 }
Yi Yang82c9df82005-12-30 16:37:10 +08002936 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937}
2938
2939/*
2940 * This function makes sure that all of the integers in the vector
2941 * are between the minimum and maximum values given in the arrays
2942 * table->extra1 and table->extra2, respectively.
2943 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002944int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002946 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947{
2948
2949 if (newval && newlen) {
2950 int __user *vec = (int __user *) newval;
2951 int *min = (int *) table->extra1;
2952 int *max = (int *) table->extra2;
2953 size_t length;
2954 int i;
2955
2956 if (newlen % sizeof(int) != 0)
2957 return -EINVAL;
2958
2959 if (!table->extra1 && !table->extra2)
2960 return 0;
2961
2962 if (newlen > table->maxlen)
2963 newlen = table->maxlen;
2964 length = newlen / sizeof(int);
2965
2966 for (i = 0; i < length; i++) {
2967 int value;
2968 if (get_user(value, vec + i))
2969 return -EFAULT;
2970 if (min && value < min[i])
2971 return -EINVAL;
2972 if (max && value > max[i])
2973 return -EINVAL;
2974 }
2975 }
2976 return 0;
2977}
2978
2979/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002980int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002982 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002984 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002986
2987 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002989 if (olen) {
2990 int val;
2991
2992 if (olen < sizeof(int))
2993 return -EINVAL;
2994
2995 val = *(int *)(table->data) / HZ;
2996 if (put_user(val, (int __user *)oldval))
2997 return -EFAULT;
2998 if (put_user(sizeof(int), oldlenp))
2999 return -EFAULT;
3000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 }
3002 if (newval && newlen) {
3003 int new;
3004 if (newlen != sizeof(int))
3005 return -EINVAL;
3006 if (get_user(new, (int __user *)newval))
3007 return -EFAULT;
3008 *(int *)(table->data) = new*HZ;
3009 }
3010 return 1;
3011}
3012
3013/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003014int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003016 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003018 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003020
3021 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003023 if (olen) {
3024 int val;
3025
3026 if (olen < sizeof(int))
3027 return -EINVAL;
3028
3029 val = jiffies_to_msecs(*(int *)(table->data));
3030 if (put_user(val, (int __user *)oldval))
3031 return -EFAULT;
3032 if (put_user(sizeof(int), oldlenp))
3033 return -EFAULT;
3034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 }
3036 if (newval && newlen) {
3037 int new;
3038 if (newlen != sizeof(int))
3039 return -EINVAL;
3040 if (get_user(new, (int __user *)newval))
3041 return -EFAULT;
3042 *(int *)(table->data) = msecs_to_jiffies(new);
3043 }
3044 return 1;
3045}
3046
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003047
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003048
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003049#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050
3051
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003052SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003054 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003055 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003056
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003057 if (copy_from_user(&tmp, args, sizeof(tmp)))
3058 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003059
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003060 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003061
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003062 /* If no error reading the parameters then just -ENOSYS ... */
3063 if (!error)
3064 error = -ENOSYS;
3065
3066 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067}
3068
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003069int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003070 void __user *oldval, size_t __user *oldlenp,
3071 void __user *newval, size_t newlen)
3072{
3073 return -ENOSYS;
3074}
3075
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003076int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003078 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079{
3080 return -ENOSYS;
3081}
3082
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003083int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003085 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086{
3087 return -ENOSYS;
3088}
3089
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003090int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003092 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093{
3094 return -ENOSYS;
3095}
3096
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003097int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003099 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100{
3101 return -ENOSYS;
3102}
3103
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003104#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003106static int deprecated_sysctl_warning(struct __sysctl_args *args)
3107{
3108 static int msg_count;
3109 int name[CTL_MAXNAME];
3110 int i;
3111
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003112 /* Check args->nlen. */
3113 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3114 return -ENOTDIR;
3115
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003116 /* Read in the sysctl name for better debug message logging */
3117 for (i = 0; i < args->nlen; i++)
3118 if (get_user(name[i], args->name + i))
3119 return -EFAULT;
3120
3121 /* Ignore accesses to kernel.version */
3122 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3123 return 0;
3124
3125 if (msg_count < 5) {
3126 msg_count++;
3127 printk(KERN_INFO
3128 "warning: process `%s' used the deprecated sysctl "
3129 "system call with ", current->comm);
3130 for (i = 0; i < args->nlen; i++)
3131 printk("%d.", name[i]);
3132 printk("\n");
3133 }
3134 return 0;
3135}
3136
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137/*
3138 * No sense putting this after each symbol definition, twice,
3139 * exception granted :-)
3140 */
3141EXPORT_SYMBOL(proc_dointvec);
3142EXPORT_SYMBOL(proc_dointvec_jiffies);
3143EXPORT_SYMBOL(proc_dointvec_minmax);
3144EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3145EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3146EXPORT_SYMBOL(proc_dostring);
3147EXPORT_SYMBOL(proc_doulongvec_minmax);
3148EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3149EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003150EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151EXPORT_SYMBOL(sysctl_intvec);
3152EXPORT_SYMBOL(sysctl_jiffies);
3153EXPORT_SYMBOL(sysctl_ms_jiffies);
3154EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003155EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156EXPORT_SYMBOL(unregister_sysctl_table);