blob: 511031381c330f91ffebb59b2ab14466ddb1fd26 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include <asm/uaccess.h>
53#include <asm/processor.h>
54
Andi Kleen29cbc782006-09-30 01:47:55 +020055#ifdef CONFIG_X86
56#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010057#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010058#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020059#endif
60
Eric W. Biederman7058cb02007-10-18 03:05:58 -070061static int deprecated_sysctl_warning(struct __sysctl_args *args);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#if defined(CONFIG_SYSCTL)
64
65/* External variables not in a header file. */
66extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070067extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int sysctl_overcommit_memory;
69extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070070extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070071extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080072extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070075extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max;
78extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080080extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080081extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020082extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010083extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040084extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070085#ifdef CONFIG_RCU_TORTURE_TEST
86extern int rcutorture_runnable;
87#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070089/* Constants used for minimum and maximum */
Ingo Molnar1c4cd6d2008-05-12 21:21:14 +020090#if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070091static int one = 1;
Bron Gondwana195cf4532008-02-04 22:29:20 -080092#endif
93
94#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020096static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097#endif
98
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +020099#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100static int two = 2;
101#endif
102
103static int zero;
104static int one_hundred = 100;
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107static int maxolduid = 65535;
108static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111static int ngroups_max = NGROUPS_MAX;
112
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200113#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern char modprobe_path[];
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#ifdef CONFIG_CHR_DEV_SG
117extern int sg_big_buff;
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
David S. Miller72c57ed2008-09-11 23:29:54 -0700120#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700121#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#endif
123
124#ifdef __hppa__
125extern int pwrsw_enabled;
126extern int unaligned_enabled;
127#endif
128
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800129#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#ifdef CONFIG_MATHEMU
131extern int sysctl_ieee_emulation_warnings;
132#endif
133extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700134extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#endif
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef CONFIG_BSD_PROCESS_ACCT
138extern int acct_parm[];
139#endif
140
Jes Sorensend2b176e2006-02-28 09:42:23 -0800141#ifdef CONFIG_IA64
142extern int no_unaligned_warning;
143#endif
144
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700145#ifdef CONFIG_RT_MUTEXES
146extern int max_lock_depth;
147#endif
148
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700149#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700150static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700151 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700152static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800153 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700154#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100157static struct ctl_table_root sysctl_table_root;
158static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100159 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100160 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400161 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100162 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400163 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100164};
165static struct ctl_table_root sysctl_table_root = {
166 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400167 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700170static struct ctl_table kern_table[];
171static struct ctl_table vm_table[];
172static struct ctl_table fs_table[];
173static struct ctl_table debug_table[];
174static struct ctl_table dev_table[];
175extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700176#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700177extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400178#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
181int sysctl_legacy_va_layout;
182#endif
183
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700184extern int prove_locking;
185extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/* The default sysctl tables: */
188
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700189static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 {
191 .ctl_name = CTL_KERN,
192 .procname = "kernel",
193 .mode = 0555,
194 .child = kern_table,
195 },
196 {
197 .ctl_name = CTL_VM,
198 .procname = "vm",
199 .mode = 0555,
200 .child = vm_table,
201 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
207 },
208 {
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
213 },
214 {
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
219 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700220/*
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 { .ctl_name = 0 }
225};
226
Ingo Molnar77e54a12007-07-09 18:52:00 +0200227#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100228static int min_sched_granularity_ns = 100000; /* 100 usecs */
229static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230static int min_wakeup_granularity_ns; /* 0 usecs */
231static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200232#endif
233
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700234static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#ifdef CONFIG_SCHED_DEBUG
236 {
237 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240 .maxlen = sizeof(unsigned int),
241 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246 },
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200271 .procname = "sched_shares_ratelimit",
272 .data = &sysctl_sched_shares_ratelimit,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec,
276 },
277 {
278 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200279 .procname = "sched_shares_thresh",
280 .data = &sysctl_sched_shares_thresh,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec_minmax,
284 .strategy = &sysctl_intvec,
285 .extra1 = &zero,
286 },
287 {
288 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200289 .procname = "sched_child_runs_first",
290 .data = &sysctl_sched_child_runs_first,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
293 .proc_handler = &proc_dointvec,
294 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200295 {
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_features",
298 .data = &sysctl_sched_features,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
302 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200303 {
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_migration_cost",
306 .data = &sysctl_sched_migration_cost,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec,
310 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100311 {
312 .ctl_name = CTL_UNNUMBERED,
313 .procname = "sched_nr_migrate",
314 .data = &sysctl_sched_nr_migrate,
315 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100316 .mode = 0644,
317 .proc_handler = &proc_dointvec,
318 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200319#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200320 {
321 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100322 .procname = "sched_rt_period_us",
323 .data = &sysctl_sched_rt_period,
324 .maxlen = sizeof(unsigned int),
325 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200326 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100327 },
328 {
329 .ctl_name = CTL_UNNUMBERED,
330 .procname = "sched_rt_runtime_us",
331 .data = &sysctl_sched_rt_runtime,
332 .maxlen = sizeof(int),
333 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200334 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100335 },
336 {
337 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200338 .procname = "sched_compat_yield",
339 .data = &sysctl_sched_compat_yield,
340 .maxlen = sizeof(unsigned int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
343 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700344#ifdef CONFIG_PROVE_LOCKING
345 {
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "prove_locking",
348 .data = &prove_locking,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
352 },
353#endif
354#ifdef CONFIG_LOCK_STAT
355 {
356 .ctl_name = CTL_UNNUMBERED,
357 .procname = "lock_stat",
358 .data = &lock_stat,
359 .maxlen = sizeof(int),
360 .mode = 0644,
361 .proc_handler = &proc_dointvec,
362 },
363#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200364 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 .ctl_name = KERN_PANIC,
366 .procname = "panic",
367 .data = &panic_timeout,
368 .maxlen = sizeof(int),
369 .mode = 0644,
370 .proc_handler = &proc_dointvec,
371 },
372 {
373 .ctl_name = KERN_CORE_USES_PID,
374 .procname = "core_uses_pid",
375 .data = &core_uses_pid,
376 .maxlen = sizeof(int),
377 .mode = 0644,
378 .proc_handler = &proc_dointvec,
379 },
380 {
381 .ctl_name = KERN_CORE_PATTERN,
382 .procname = "core_pattern",
383 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700384 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .mode = 0644,
386 .proc_handler = &proc_dostring,
387 .strategy = &sysctl_string,
388 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800389#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700392 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800393 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700394 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800396#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100397#ifdef CONFIG_LATENCYTOP
398 {
399 .procname = "latencytop",
400 .data = &latencytop_enabled,
401 .maxlen = sizeof(int),
402 .mode = 0644,
403 .proc_handler = &proc_dointvec,
404 },
405#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#ifdef CONFIG_BLK_DEV_INITRD
407 {
408 .ctl_name = KERN_REALROOTDEV,
409 .procname = "real-root-dev",
410 .data = &real_root_dev,
411 .maxlen = sizeof(int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
414 },
415#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700416 {
417 .ctl_name = CTL_UNNUMBERED,
418 .procname = "print-fatal-signals",
419 .data = &print_fatal_signals,
420 .maxlen = sizeof(int),
421 .mode = 0644,
422 .proc_handler = &proc_dointvec,
423 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700424#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 {
426 .ctl_name = KERN_SPARC_REBOOT,
427 .procname = "reboot-cmd",
428 .data = reboot_command,
429 .maxlen = 256,
430 .mode = 0644,
431 .proc_handler = &proc_dostring,
432 .strategy = &sysctl_string,
433 },
434 {
435 .ctl_name = KERN_SPARC_STOP_A,
436 .procname = "stop-a",
437 .data = &stop_a_enabled,
438 .maxlen = sizeof (int),
439 .mode = 0644,
440 .proc_handler = &proc_dointvec,
441 },
442 {
443 .ctl_name = KERN_SPARC_SCONS_PWROFF,
444 .procname = "scons-poweroff",
445 .data = &scons_pwroff,
446 .maxlen = sizeof (int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450#endif
451#ifdef __hppa__
452 {
453 .ctl_name = KERN_HPPA_PWRSW,
454 .procname = "soft-power",
455 .data = &pwrsw_enabled,
456 .maxlen = sizeof (int),
457 .mode = 0644,
458 .proc_handler = &proc_dointvec,
459 },
460 {
461 .ctl_name = KERN_HPPA_UNALIGNED,
462 .procname = "unaligned-trap",
463 .data = &unaligned_enabled,
464 .maxlen = sizeof (int),
465 .mode = 0644,
466 .proc_handler = &proc_dointvec,
467 },
468#endif
469 {
470 .ctl_name = KERN_CTLALTDEL,
471 .procname = "ctrl-alt-del",
472 .data = &C_A_D,
473 .maxlen = sizeof(int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec,
476 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400477#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200478 {
479 .ctl_name = CTL_UNNUMBERED,
480 .procname = "ftrace_enabled",
481 .data = &ftrace_enabled,
482 .maxlen = sizeof(int),
483 .mode = 0644,
484 .proc_handler = &ftrace_enable_sysctl,
485 },
486#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200487#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 {
489 .ctl_name = KERN_MODPROBE,
490 .procname = "modprobe",
491 .data = &modprobe_path,
492 .maxlen = KMOD_PATH_LEN,
493 .mode = 0644,
494 .proc_handler = &proc_dostring,
495 .strategy = &sysctl_string,
496 },
497#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700498#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 {
500 .ctl_name = KERN_HOTPLUG,
501 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100502 .data = &uevent_helper,
503 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .mode = 0644,
505 .proc_handler = &proc_dostring,
506 .strategy = &sysctl_string,
507 },
508#endif
509#ifdef CONFIG_CHR_DEV_SG
510 {
511 .ctl_name = KERN_SG_BIG_BUFF,
512 .procname = "sg-big-buff",
513 .data = &sg_big_buff,
514 .maxlen = sizeof (int),
515 .mode = 0444,
516 .proc_handler = &proc_dointvec,
517 },
518#endif
519#ifdef CONFIG_BSD_PROCESS_ACCT
520 {
521 .ctl_name = KERN_ACCT,
522 .procname = "acct",
523 .data = &acct_parm,
524 .maxlen = 3*sizeof(int),
525 .mode = 0644,
526 .proc_handler = &proc_dointvec,
527 },
528#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529#ifdef CONFIG_MAGIC_SYSRQ
530 {
531 .ctl_name = KERN_SYSRQ,
532 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800533 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 .maxlen = sizeof (int),
535 .mode = 0644,
536 .proc_handler = &proc_dointvec,
537 },
538#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700539#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700542 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 .maxlen = sizeof (int),
544 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700545 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700547#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 {
549 .ctl_name = KERN_MAX_THREADS,
550 .procname = "threads-max",
551 .data = &max_threads,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 .proc_handler = &proc_dointvec,
555 },
556 {
557 .ctl_name = KERN_RANDOM,
558 .procname = "random",
559 .mode = 0555,
560 .child = random_table,
561 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 {
563 .ctl_name = KERN_OVERFLOWUID,
564 .procname = "overflowuid",
565 .data = &overflowuid,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec_minmax,
569 .strategy = &sysctl_intvec,
570 .extra1 = &minolduid,
571 .extra2 = &maxolduid,
572 },
573 {
574 .ctl_name = KERN_OVERFLOWGID,
575 .procname = "overflowgid",
576 .data = &overflowgid,
577 .maxlen = sizeof(int),
578 .mode = 0644,
579 .proc_handler = &proc_dointvec_minmax,
580 .strategy = &sysctl_intvec,
581 .extra1 = &minolduid,
582 .extra2 = &maxolduid,
583 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800584#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585#ifdef CONFIG_MATHEMU
586 {
587 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
588 .procname = "ieee_emulation_warnings",
589 .data = &sysctl_ieee_emulation_warnings,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec,
593 },
594#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 {
596 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
597 .procname = "userprocess_debug",
598 .data = &sysctl_userprocess_debug,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec,
602 },
603#endif
604 {
605 .ctl_name = KERN_PIDMAX,
606 .procname = "pid_max",
607 .data = &pid_max,
608 .maxlen = sizeof (int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec_minmax,
611 .strategy = sysctl_intvec,
612 .extra1 = &pid_max_min,
613 .extra2 = &pid_max_max,
614 },
615 {
616 .ctl_name = KERN_PANIC_ON_OOPS,
617 .procname = "panic_on_oops",
618 .data = &panic_on_oops,
619 .maxlen = sizeof(int),
620 .mode = 0644,
621 .proc_handler = &proc_dointvec,
622 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800623#if defined CONFIG_PRINTK
624 {
625 .ctl_name = KERN_PRINTK,
626 .procname = "printk",
627 .data = &console_loglevel,
628 .maxlen = 4*sizeof(int),
629 .mode = 0644,
630 .proc_handler = &proc_dointvec,
631 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 {
633 .ctl_name = KERN_PRINTK_RATELIMIT,
634 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700635 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec_jiffies,
639 .strategy = &sysctl_jiffies,
640 },
641 {
642 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
643 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700644 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 .maxlen = sizeof(int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
648 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800649#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 {
651 .ctl_name = KERN_NGROUPS_MAX,
652 .procname = "ngroups_max",
653 .data = &ngroups_max,
654 .maxlen = sizeof (int),
655 .mode = 0444,
656 .proc_handler = &proc_dointvec,
657 },
658#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
659 {
660 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
661 .procname = "unknown_nmi_panic",
662 .data = &unknown_nmi_panic,
663 .maxlen = sizeof (int),
664 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200665 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 },
Don Zickus407984f2006-09-26 10:52:27 +0200667 {
Don Zickus407984f2006-09-26 10:52:27 +0200668 .procname = "nmi_watchdog",
669 .data = &nmi_watchdog_enabled,
670 .maxlen = sizeof (int),
671 .mode = 0644,
672 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 },
674#endif
675#if defined(CONFIG_X86)
676 {
Don Zickus8da5add2006-09-26 10:52:27 +0200677 .ctl_name = KERN_PANIC_ON_NMI,
678 .procname = "panic_on_unrecovered_nmi",
679 .data = &panic_on_unrecovered_nmi,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
683 },
684 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .ctl_name = KERN_BOOTLOADER_TYPE,
686 .procname = "bootloader_type",
687 .data = &bootloader_type,
688 .maxlen = sizeof (int),
689 .mode = 0444,
690 .proc_handler = &proc_dointvec,
691 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100692 {
693 .ctl_name = CTL_UNNUMBERED,
694 .procname = "kstack_depth_to_print",
695 .data = &kstack_depth_to_print,
696 .maxlen = sizeof(int),
697 .mode = 0644,
698 .proc_handler = &proc_dointvec,
699 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100700 {
701 .ctl_name = CTL_UNNUMBERED,
702 .procname = "io_delay_type",
703 .data = &io_delay_type,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 .proc_handler = &proc_dointvec,
707 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800709#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 {
711 .ctl_name = KERN_RANDOMIZE,
712 .procname = "randomize_va_space",
713 .data = &randomize_va_space,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = &proc_dointvec,
717 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800718#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800719#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700720 {
721 .ctl_name = KERN_SPIN_RETRY,
722 .procname = "spin_retry",
723 .data = &spin_retry,
724 .maxlen = sizeof (int),
725 .mode = 0644,
726 .proc_handler = &proc_dointvec,
727 },
728#endif
Len Brown673d5b42007-07-28 03:33:16 -0400729#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800730 {
Pavel Machekc255d842006-02-20 18:27:58 -0800731 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700732 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800733 .maxlen = sizeof (unsigned long),
734 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800735 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800736 },
737#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800738#ifdef CONFIG_IA64
739 {
740 .ctl_name = KERN_IA64_UNALIGNED,
741 .procname = "ignore-unaligned-usertrap",
742 .data = &no_unaligned_warning,
743 .maxlen = sizeof (int),
744 .mode = 0644,
745 .proc_handler = &proc_dointvec,
746 },
747#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700748#ifdef CONFIG_DETECT_SOFTLOCKUP
749 {
750 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200751 .procname = "softlockup_panic",
752 .data = &softlockup_panic,
753 .maxlen = sizeof(int),
754 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700755 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200756 .strategy = &sysctl_intvec,
757 .extra1 = &zero,
758 .extra2 = &one,
759 },
760 {
761 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700762 .procname = "softlockup_thresh",
763 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200764 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700765 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200766 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700767 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200768 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700769 .extra2 = &sixty,
770 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100771 {
772 .ctl_name = CTL_UNNUMBERED,
773 .procname = "hung_task_check_count",
774 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100775 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100776 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100777 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100778 .strategy = &sysctl_intvec,
779 },
780 {
781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "hung_task_timeout_secs",
783 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100784 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100785 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100786 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100787 .strategy = &sysctl_intvec,
788 },
789 {
790 .ctl_name = CTL_UNNUMBERED,
791 .procname = "hung_task_warnings",
792 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100793 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100794 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100795 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100796 .strategy = &sysctl_intvec,
797 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700798#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200799#ifdef CONFIG_COMPAT
800 {
801 .ctl_name = KERN_COMPAT_LOG,
802 .procname = "compat-log",
803 .data = &compat_log,
804 .maxlen = sizeof (int),
805 .mode = 0644,
806 .proc_handler = &proc_dointvec,
807 },
808#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700809#ifdef CONFIG_RT_MUTEXES
810 {
811 .ctl_name = KERN_MAX_LOCK_DEPTH,
812 .procname = "max_lock_depth",
813 .data = &max_lock_depth,
814 .maxlen = sizeof(int),
815 .mode = 0644,
816 .proc_handler = &proc_dointvec,
817 },
818#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700819 {
820 .ctl_name = CTL_UNNUMBERED,
821 .procname = "poweroff_cmd",
822 .data = &poweroff_cmd,
823 .maxlen = POWEROFF_CMD_PATH_LEN,
824 .mode = 0644,
825 .proc_handler = &proc_dostring,
826 .strategy = &sysctl_string,
827 },
David Howells0b77f5b2008-04-29 01:01:32 -0700828#ifdef CONFIG_KEYS
829 {
830 .ctl_name = CTL_UNNUMBERED,
831 .procname = "keys",
832 .mode = 0555,
833 .child = key_sysctls,
834 },
835#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700836#ifdef CONFIG_RCU_TORTURE_TEST
837 {
838 .ctl_name = CTL_UNNUMBERED,
839 .procname = "rcutorture_runnable",
840 .data = &rcutorture_runnable,
841 .maxlen = sizeof(int),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
844 },
845#endif
Lee Schermerhornaf936a12008-10-18 20:26:53 -0700846#ifdef CONFIG_UNEVICTABLE_LRU
847 {
848 .ctl_name = CTL_UNNUMBERED,
849 .procname = "scan_unevictable_pages",
850 .data = &scan_unevictable_pages,
851 .maxlen = sizeof(scan_unevictable_pages),
852 .mode = 0644,
853 .proc_handler = &scan_unevictable_handler,
854 },
855#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700856/*
857 * NOTE: do not add new entries to this table unless you have read
858 * Documentation/sysctl/ctl_unnumbered.txt
859 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 { .ctl_name = 0 }
861};
862
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700863static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 {
865 .ctl_name = VM_OVERCOMMIT_MEMORY,
866 .procname = "overcommit_memory",
867 .data = &sysctl_overcommit_memory,
868 .maxlen = sizeof(sysctl_overcommit_memory),
869 .mode = 0644,
870 .proc_handler = &proc_dointvec,
871 },
872 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700873 .ctl_name = VM_PANIC_ON_OOM,
874 .procname = "panic_on_oom",
875 .data = &sysctl_panic_on_oom,
876 .maxlen = sizeof(sysctl_panic_on_oom),
877 .mode = 0644,
878 .proc_handler = &proc_dointvec,
879 },
880 {
David Rientjesfe071d72007-10-16 23:25:56 -0700881 .ctl_name = CTL_UNNUMBERED,
882 .procname = "oom_kill_allocating_task",
883 .data = &sysctl_oom_kill_allocating_task,
884 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
885 .mode = 0644,
886 .proc_handler = &proc_dointvec,
887 },
888 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800889 .ctl_name = CTL_UNNUMBERED,
890 .procname = "oom_dump_tasks",
891 .data = &sysctl_oom_dump_tasks,
892 .maxlen = sizeof(sysctl_oom_dump_tasks),
893 .mode = 0644,
894 .proc_handler = &proc_dointvec,
895 },
896 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 .ctl_name = VM_OVERCOMMIT_RATIO,
898 .procname = "overcommit_ratio",
899 .data = &sysctl_overcommit_ratio,
900 .maxlen = sizeof(sysctl_overcommit_ratio),
901 .mode = 0644,
902 .proc_handler = &proc_dointvec,
903 },
904 {
905 .ctl_name = VM_PAGE_CLUSTER,
906 .procname = "page-cluster",
907 .data = &page_cluster,
908 .maxlen = sizeof(int),
909 .mode = 0644,
910 .proc_handler = &proc_dointvec,
911 },
912 {
913 .ctl_name = VM_DIRTY_BACKGROUND,
914 .procname = "dirty_background_ratio",
915 .data = &dirty_background_ratio,
916 .maxlen = sizeof(dirty_background_ratio),
917 .mode = 0644,
918 .proc_handler = &proc_dointvec_minmax,
919 .strategy = &sysctl_intvec,
920 .extra1 = &zero,
921 .extra2 = &one_hundred,
922 },
923 {
924 .ctl_name = VM_DIRTY_RATIO,
925 .procname = "dirty_ratio",
926 .data = &vm_dirty_ratio,
927 .maxlen = sizeof(vm_dirty_ratio),
928 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700929 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 .strategy = &sysctl_intvec,
931 .extra1 = &zero,
932 .extra2 = &one_hundred,
933 },
934 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800936 .data = &dirty_writeback_interval,
937 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 .mode = 0644,
939 .proc_handler = &dirty_writeback_centisecs_handler,
940 },
941 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800943 .data = &dirty_expire_interval,
944 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800946 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 },
948 {
949 .ctl_name = VM_NR_PDFLUSH_THREADS,
950 .procname = "nr_pdflush_threads",
951 .data = &nr_pdflush_threads,
952 .maxlen = sizeof nr_pdflush_threads,
953 .mode = 0444 /* read-only*/,
954 .proc_handler = &proc_dointvec,
955 },
956 {
957 .ctl_name = VM_SWAPPINESS,
958 .procname = "swappiness",
959 .data = &vm_swappiness,
960 .maxlen = sizeof(vm_swappiness),
961 .mode = 0644,
962 .proc_handler = &proc_dointvec_minmax,
963 .strategy = &sysctl_intvec,
964 .extra1 = &zero,
965 .extra2 = &one_hundred,
966 },
967#ifdef CONFIG_HUGETLB_PAGE
968 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700970 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 .maxlen = sizeof(unsigned long),
972 .mode = 0644,
973 .proc_handler = &hugetlb_sysctl_handler,
974 .extra1 = (void *)&hugetlb_zero,
975 .extra2 = (void *)&hugetlb_infinity,
976 },
977 {
978 .ctl_name = VM_HUGETLB_GROUP,
979 .procname = "hugetlb_shm_group",
980 .data = &sysctl_hugetlb_shm_group,
981 .maxlen = sizeof(gid_t),
982 .mode = 0644,
983 .proc_handler = &proc_dointvec,
984 },
Mel Gorman396faf02007-07-17 04:03:13 -0700985 {
986 .ctl_name = CTL_UNNUMBERED,
987 .procname = "hugepages_treat_as_movable",
988 .data = &hugepages_treat_as_movable,
989 .maxlen = sizeof(int),
990 .mode = 0644,
991 .proc_handler = &hugetlb_treat_movable_handler,
992 },
Adam Litke54f9f802007-10-16 01:26:20 -0700993 {
994 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800995 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700996 .data = NULL,
997 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800998 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800999 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001000 .extra1 = (void *)&hugetlb_zero,
1001 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001002 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003#endif
1004 {
1005 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1006 .procname = "lowmem_reserve_ratio",
1007 .data = &sysctl_lowmem_reserve_ratio,
1008 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1009 .mode = 0644,
1010 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1012 },
1013 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001014 .ctl_name = VM_DROP_PAGECACHE,
1015 .procname = "drop_caches",
1016 .data = &sysctl_drop_caches,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
1019 .proc_handler = drop_caches_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1021 },
1022 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 .ctl_name = VM_MIN_FREE_KBYTES,
1024 .procname = "min_free_kbytes",
1025 .data = &min_free_kbytes,
1026 .maxlen = sizeof(min_free_kbytes),
1027 .mode = 0644,
1028 .proc_handler = &min_free_kbytes_sysctl_handler,
1029 .strategy = &sysctl_intvec,
1030 .extra1 = &zero,
1031 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001032 {
1033 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1034 .procname = "percpu_pagelist_fraction",
1035 .data = &percpu_pagelist_fraction,
1036 .maxlen = sizeof(percpu_pagelist_fraction),
1037 .mode = 0644,
1038 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1039 .strategy = &sysctl_intvec,
1040 .extra1 = &min_percpu_pagelist_fract,
1041 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042#ifdef CONFIG_MMU
1043 {
1044 .ctl_name = VM_MAX_MAP_COUNT,
1045 .procname = "max_map_count",
1046 .data = &sysctl_max_map_count,
1047 .maxlen = sizeof(sysctl_max_map_count),
1048 .mode = 0644,
1049 .proc_handler = &proc_dointvec
1050 },
1051#endif
1052 {
1053 .ctl_name = VM_LAPTOP_MODE,
1054 .procname = "laptop_mode",
1055 .data = &laptop_mode,
1056 .maxlen = sizeof(laptop_mode),
1057 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001058 .proc_handler = &proc_dointvec_jiffies,
1059 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 },
1061 {
1062 .ctl_name = VM_BLOCK_DUMP,
1063 .procname = "block_dump",
1064 .data = &block_dump,
1065 .maxlen = sizeof(block_dump),
1066 .mode = 0644,
1067 .proc_handler = &proc_dointvec,
1068 .strategy = &sysctl_intvec,
1069 .extra1 = &zero,
1070 },
1071 {
1072 .ctl_name = VM_VFS_CACHE_PRESSURE,
1073 .procname = "vfs_cache_pressure",
1074 .data = &sysctl_vfs_cache_pressure,
1075 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1076 .mode = 0644,
1077 .proc_handler = &proc_dointvec,
1078 .strategy = &sysctl_intvec,
1079 .extra1 = &zero,
1080 },
1081#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1082 {
1083 .ctl_name = VM_LEGACY_VA_LAYOUT,
1084 .procname = "legacy_va_layout",
1085 .data = &sysctl_legacy_va_layout,
1086 .maxlen = sizeof(sysctl_legacy_va_layout),
1087 .mode = 0644,
1088 .proc_handler = &proc_dointvec,
1089 .strategy = &sysctl_intvec,
1090 .extra1 = &zero,
1091 },
1092#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001093#ifdef CONFIG_NUMA
1094 {
1095 .ctl_name = VM_ZONE_RECLAIM_MODE,
1096 .procname = "zone_reclaim_mode",
1097 .data = &zone_reclaim_mode,
1098 .maxlen = sizeof(zone_reclaim_mode),
1099 .mode = 0644,
1100 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001101 .strategy = &sysctl_intvec,
1102 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001103 },
Christoph Lameter96146342006-07-03 00:24:13 -07001104 {
1105 .ctl_name = VM_MIN_UNMAPPED,
1106 .procname = "min_unmapped_ratio",
1107 .data = &sysctl_min_unmapped_ratio,
1108 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1109 .mode = 0644,
1110 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1111 .strategy = &sysctl_intvec,
1112 .extra1 = &zero,
1113 .extra2 = &one_hundred,
1114 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001115 {
1116 .ctl_name = VM_MIN_SLAB,
1117 .procname = "min_slab_ratio",
1118 .data = &sysctl_min_slab_ratio,
1119 .maxlen = sizeof(sysctl_min_slab_ratio),
1120 .mode = 0644,
1121 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1122 .strategy = &sysctl_intvec,
1123 .extra1 = &zero,
1124 .extra2 = &one_hundred,
1125 },
Christoph Lameter17436602006-01-18 17:42:32 -08001126#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001127#ifdef CONFIG_SMP
1128 {
1129 .ctl_name = CTL_UNNUMBERED,
1130 .procname = "stat_interval",
1131 .data = &sysctl_stat_interval,
1132 .maxlen = sizeof(sysctl_stat_interval),
1133 .mode = 0644,
1134 .proc_handler = &proc_dointvec_jiffies,
1135 .strategy = &sysctl_jiffies,
1136 },
1137#endif
Eric Parised032182007-06-28 15:55:21 -04001138#ifdef CONFIG_SECURITY
1139 {
1140 .ctl_name = CTL_UNNUMBERED,
1141 .procname = "mmap_min_addr",
1142 .data = &mmap_min_addr,
1143 .maxlen = sizeof(unsigned long),
1144 .mode = 0644,
1145 .proc_handler = &proc_doulongvec_minmax,
1146 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001147#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001148#ifdef CONFIG_NUMA
1149 {
1150 .ctl_name = CTL_UNNUMBERED,
1151 .procname = "numa_zonelist_order",
1152 .data = &numa_zonelist_order,
1153 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1154 .mode = 0644,
1155 .proc_handler = &numa_zonelist_order_handler,
1156 .strategy = &sysctl_string,
1157 },
1158#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001159#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001160 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001161 {
1162 .ctl_name = VM_VDSO_ENABLED,
1163 .procname = "vdso_enabled",
1164 .data = &vdso_enabled,
1165 .maxlen = sizeof(vdso_enabled),
1166 .mode = 0644,
1167 .proc_handler = &proc_dointvec,
1168 .strategy = &sysctl_intvec,
1169 .extra1 = &zero,
1170 },
1171#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001172#ifdef CONFIG_HIGHMEM
1173 {
1174 .ctl_name = CTL_UNNUMBERED,
1175 .procname = "highmem_is_dirtyable",
1176 .data = &vm_highmem_is_dirtyable,
1177 .maxlen = sizeof(vm_highmem_is_dirtyable),
1178 .mode = 0644,
1179 .proc_handler = &proc_dointvec_minmax,
1180 .strategy = &sysctl_intvec,
1181 .extra1 = &zero,
1182 .extra2 = &one,
1183 },
1184#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001185/*
1186 * NOTE: do not add new entries to this table unless you have read
1187 * Documentation/sysctl/ctl_unnumbered.txt
1188 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 { .ctl_name = 0 }
1190};
1191
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001192#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001193static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001194 { .ctl_name = 0 }
1195};
1196#endif
1197
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001198static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 {
1200 .ctl_name = FS_NRINODE,
1201 .procname = "inode-nr",
1202 .data = &inodes_stat,
1203 .maxlen = 2*sizeof(int),
1204 .mode = 0444,
1205 .proc_handler = &proc_dointvec,
1206 },
1207 {
1208 .ctl_name = FS_STATINODE,
1209 .procname = "inode-state",
1210 .data = &inodes_stat,
1211 .maxlen = 7*sizeof(int),
1212 .mode = 0444,
1213 .proc_handler = &proc_dointvec,
1214 },
1215 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 .procname = "file-nr",
1217 .data = &files_stat,
1218 .maxlen = 3*sizeof(int),
1219 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001220 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 },
1222 {
1223 .ctl_name = FS_MAXFILE,
1224 .procname = "file-max",
1225 .data = &files_stat.max_files,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = &proc_dointvec,
1229 },
1230 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001231 .ctl_name = CTL_UNNUMBERED,
1232 .procname = "nr_open",
1233 .data = &sysctl_nr_open,
1234 .maxlen = sizeof(int),
1235 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001236 .proc_handler = &proc_dointvec_minmax,
1237 .extra1 = &sysctl_nr_open_min,
1238 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001239 },
1240 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 .ctl_name = FS_DENTRY,
1242 .procname = "dentry-state",
1243 .data = &dentry_stat,
1244 .maxlen = 6*sizeof(int),
1245 .mode = 0444,
1246 .proc_handler = &proc_dointvec,
1247 },
1248 {
1249 .ctl_name = FS_OVERFLOWUID,
1250 .procname = "overflowuid",
1251 .data = &fs_overflowuid,
1252 .maxlen = sizeof(int),
1253 .mode = 0644,
1254 .proc_handler = &proc_dointvec_minmax,
1255 .strategy = &sysctl_intvec,
1256 .extra1 = &minolduid,
1257 .extra2 = &maxolduid,
1258 },
1259 {
1260 .ctl_name = FS_OVERFLOWGID,
1261 .procname = "overflowgid",
1262 .data = &fs_overflowgid,
1263 .maxlen = sizeof(int),
1264 .mode = 0644,
1265 .proc_handler = &proc_dointvec_minmax,
1266 .strategy = &sysctl_intvec,
1267 .extra1 = &minolduid,
1268 .extra2 = &maxolduid,
1269 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001270#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 {
1272 .ctl_name = FS_LEASES,
1273 .procname = "leases-enable",
1274 .data = &leases_enable,
1275 .maxlen = sizeof(int),
1276 .mode = 0644,
1277 .proc_handler = &proc_dointvec,
1278 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001279#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280#ifdef CONFIG_DNOTIFY
1281 {
1282 .ctl_name = FS_DIR_NOTIFY,
1283 .procname = "dir-notify-enable",
1284 .data = &dir_notify_enable,
1285 .maxlen = sizeof(int),
1286 .mode = 0644,
1287 .proc_handler = &proc_dointvec,
1288 },
1289#endif
1290#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001291#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 {
1293 .ctl_name = FS_LEASE_TIME,
1294 .procname = "lease-break-time",
1295 .data = &lease_break_time,
1296 .maxlen = sizeof(int),
1297 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001298 .proc_handler = &proc_dointvec_minmax,
1299 .strategy = &sysctl_intvec,
1300 .extra1 = &zero,
1301 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001303#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001304#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 .procname = "aio-nr",
1307 .data = &aio_nr,
1308 .maxlen = sizeof(aio_nr),
1309 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001310 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 },
1312 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 .procname = "aio-max-nr",
1314 .data = &aio_max_nr,
1315 .maxlen = sizeof(aio_max_nr),
1316 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001317 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001319#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001320#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001321 {
1322 .ctl_name = FS_INOTIFY,
1323 .procname = "inotify",
1324 .mode = 0555,
1325 .child = inotify_table,
1326 },
1327#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001329 {
1330 .ctl_name = KERN_SETUID_DUMPABLE,
1331 .procname = "suid_dumpable",
1332 .data = &suid_dumpable,
1333 .maxlen = sizeof(int),
1334 .mode = 0644,
1335 .proc_handler = &proc_dointvec,
1336 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001337#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1338 {
1339 .ctl_name = CTL_UNNUMBERED,
1340 .procname = "binfmt_misc",
1341 .mode = 0555,
1342 .child = binfmt_misc_table,
1343 },
1344#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001345/*
1346 * NOTE: do not add new entries to this table unless you have read
1347 * Documentation/sysctl/ctl_unnumbered.txt
1348 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 { .ctl_name = 0 }
1350};
1351
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001352static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001353#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001354 {
1355 .ctl_name = CTL_UNNUMBERED,
1356 .procname = "exception-trace",
1357 .data = &show_unhandled_signals,
1358 .maxlen = sizeof(int),
1359 .mode = 0644,
1360 .proc_handler = proc_dointvec
1361 },
1362#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 { .ctl_name = 0 }
1364};
1365
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001366static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001368};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Al Viro330d57f2005-11-04 10:18:40 +00001370static DEFINE_SPINLOCK(sysctl_lock);
1371
1372/* called under sysctl_lock */
1373static int use_table(struct ctl_table_header *p)
1374{
1375 if (unlikely(p->unregistering))
1376 return 0;
1377 p->used++;
1378 return 1;
1379}
1380
1381/* called under sysctl_lock */
1382static void unuse_table(struct ctl_table_header *p)
1383{
1384 if (!--p->used)
1385 if (unlikely(p->unregistering))
1386 complete(p->unregistering);
1387}
1388
1389/* called under sysctl_lock, will reacquire if has to wait */
1390static void start_unregistering(struct ctl_table_header *p)
1391{
1392 /*
1393 * if p->used is 0, nobody will ever touch that entry again;
1394 * we'll eliminate all paths to it before dropping sysctl_lock
1395 */
1396 if (unlikely(p->used)) {
1397 struct completion wait;
1398 init_completion(&wait);
1399 p->unregistering = &wait;
1400 spin_unlock(&sysctl_lock);
1401 wait_for_completion(&wait);
1402 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001403 } else {
1404 /* anything non-NULL; we'll never dereference it */
1405 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001406 }
1407 /*
1408 * do not remove from the list until nobody holds it; walking the
1409 * list in do_sysctl() relies on that.
1410 */
1411 list_del_init(&p->ctl_entry);
1412}
1413
Al Virof7e6ced2008-07-15 01:44:23 -04001414void sysctl_head_get(struct ctl_table_header *head)
1415{
1416 spin_lock(&sysctl_lock);
1417 head->count++;
1418 spin_unlock(&sysctl_lock);
1419}
1420
1421void sysctl_head_put(struct ctl_table_header *head)
1422{
1423 spin_lock(&sysctl_lock);
1424 if (!--head->count)
1425 kfree(head);
1426 spin_unlock(&sysctl_lock);
1427}
1428
1429struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1430{
1431 if (!head)
1432 BUG();
1433 spin_lock(&sysctl_lock);
1434 if (!use_table(head))
1435 head = ERR_PTR(-ENOENT);
1436 spin_unlock(&sysctl_lock);
1437 return head;
1438}
1439
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001440void sysctl_head_finish(struct ctl_table_header *head)
1441{
1442 if (!head)
1443 return;
1444 spin_lock(&sysctl_lock);
1445 unuse_table(head);
1446 spin_unlock(&sysctl_lock);
1447}
1448
Al Viro73455092008-07-14 21:22:20 -04001449static struct ctl_table_set *
1450lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1451{
1452 struct ctl_table_set *set = &root->default_set;
1453 if (root->lookup)
1454 set = root->lookup(root, namespaces);
1455 return set;
1456}
1457
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001458static struct list_head *
1459lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001460{
Al Viro73455092008-07-14 21:22:20 -04001461 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1462 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001463}
1464
1465struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1466 struct ctl_table_header *prev)
1467{
1468 struct ctl_table_root *root;
1469 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001470 struct ctl_table_header *head;
1471 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001472
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001473 spin_lock(&sysctl_lock);
1474 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001475 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001476 tmp = &prev->ctl_entry;
1477 unuse_table(prev);
1478 goto next;
1479 }
1480 tmp = &root_table_header.ctl_entry;
1481 for (;;) {
1482 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1483
1484 if (!use_table(head))
1485 goto next;
1486 spin_unlock(&sysctl_lock);
1487 return head;
1488 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001489 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001490 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001491 header_list = lookup_header_list(root, namespaces);
1492 if (tmp != header_list)
1493 continue;
1494
1495 do {
1496 root = list_entry(root->root_list.next,
1497 struct ctl_table_root, root_list);
1498 if (root == &sysctl_table_root)
1499 goto out;
1500 header_list = lookup_header_list(root, namespaces);
1501 } while (list_empty(header_list));
1502 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001503 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001504out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001505 spin_unlock(&sysctl_lock);
1506 return NULL;
1507}
1508
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001509struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1510{
1511 return __sysctl_head_next(current->nsproxy, prev);
1512}
1513
1514void register_sysctl_root(struct ctl_table_root *root)
1515{
1516 spin_lock(&sysctl_lock);
1517 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1518 spin_unlock(&sysctl_lock);
1519}
1520
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001521#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001522/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001523static int do_sysctl_strategy(struct ctl_table_root *root,
1524 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001525 void __user *oldval, size_t __user *oldlenp,
1526 void __user *newval, size_t newlen)
1527{
1528 int op = 0, rc;
1529
1530 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001531 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001532 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001533 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001534 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001535 return -EPERM;
1536
1537 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001538 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001539 if (rc < 0)
1540 return rc;
1541 if (rc > 0)
1542 return 0;
1543 }
1544
1545 /* If there is no strategy routine, or if the strategy returns
1546 * zero, proceed with automatic r/w */
1547 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001548 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001549 if (rc < 0)
1550 return rc;
1551 }
1552 return 0;
1553}
1554
1555static int parse_table(int __user *name, int nlen,
1556 void __user *oldval, size_t __user *oldlenp,
1557 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001558 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001559 struct ctl_table *table)
1560{
1561 int n;
1562repeat:
1563 if (!nlen)
1564 return -ENOTDIR;
1565 if (get_user(n, name))
1566 return -EFAULT;
1567 for ( ; table->ctl_name || table->procname; table++) {
1568 if (!table->ctl_name)
1569 continue;
1570 if (n == table->ctl_name) {
1571 int error;
1572 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001573 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001574 return -EPERM;
1575 name++;
1576 nlen--;
1577 table = table->child;
1578 goto repeat;
1579 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001580 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001581 oldval, oldlenp,
1582 newval, newlen);
1583 return error;
1584 }
1585 }
1586 return -ENOTDIR;
1587}
1588
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1590 void __user *newval, size_t newlen)
1591{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001592 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001593 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594
1595 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1596 return -ENOTDIR;
1597 if (oldval) {
1598 int old_len;
1599 if (!oldlenp || get_user(old_len, oldlenp))
1600 return -EFAULT;
1601 }
Al Viro330d57f2005-11-04 10:18:40 +00001602
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001603 for (head = sysctl_head_next(NULL); head;
1604 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001605 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001606 newval, newlen,
1607 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001608 if (error != -ENOTDIR) {
1609 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001610 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001611 }
1612 }
Al Viro330d57f2005-11-04 10:18:40 +00001613 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
1615
1616asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1617{
1618 struct __sysctl_args tmp;
1619 int error;
1620
1621 if (copy_from_user(&tmp, args, sizeof(tmp)))
1622 return -EFAULT;
1623
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001624 error = deprecated_sysctl_warning(&tmp);
1625 if (error)
1626 goto out;
1627
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 lock_kernel();
1629 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1630 tmp.newval, tmp.newlen);
1631 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001632out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 return error;
1634}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001635#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001638 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 * some sysctl variables are readonly even to root.
1640 */
1641
1642static int test_perm(int mode, int op)
1643{
David Howells76aac0e2008-11-14 10:39:12 +11001644 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 mode >>= 6;
1646 else if (in_egroup_p(0))
1647 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001648 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 return 0;
1650 return -EACCES;
1651}
1652
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001653int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654{
1655 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001656 int mode;
1657
Al Viroe6305c42008-07-15 21:03:57 -04001658 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 if (error)
1660 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001661
1662 if (root->permissions)
1663 mode = root->permissions(root, current->nsproxy, table);
1664 else
1665 mode = table->mode;
1666
1667 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001670static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1671{
1672 for (; table->ctl_name || table->procname; table++) {
1673 table->parent = parent;
1674 if (table->child)
1675 sysctl_set_parent(table, table->child);
1676 }
1677}
1678
1679static __init int sysctl_init(void)
1680{
1681 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001682#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1683 {
1684 int err;
1685 err = sysctl_check_table(current->nsproxy, root_table);
1686 }
1687#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001688 return 0;
1689}
1690
1691core_initcall(sysctl_init);
1692
Al Virobfbcf032008-07-27 06:31:22 +01001693static struct ctl_table *is_branch_in(struct ctl_table *branch,
1694 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001695{
1696 struct ctl_table *p;
1697 const char *s = branch->procname;
1698
1699 /* branch should have named subdirectory as its first element */
1700 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001701 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001702
1703 /* ... and nothing else */
1704 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001705 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001706
1707 /* table should contain subdirectory with the same name */
1708 for (p = table; p->procname || p->ctl_name; p++) {
1709 if (!p->child)
1710 continue;
1711 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001712 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001713 }
Al Virobfbcf032008-07-27 06:31:22 +01001714 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001715}
1716
1717/* see if attaching q to p would be an improvement */
1718static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1719{
1720 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001721 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001722 int is_better = 0;
1723 int not_in_parent = !p->attached_by;
1724
Al Virobfbcf032008-07-27 06:31:22 +01001725 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001726 if (by == q->attached_by)
1727 is_better = 1;
1728 if (to == p->attached_by)
1729 not_in_parent = 1;
1730 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001731 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001732 }
1733
1734 if (is_better && not_in_parent) {
1735 q->attached_by = by;
1736 q->attached_to = to;
1737 q->parent = p;
1738 }
1739}
1740
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001742 * __register_sysctl_paths - register a sysctl hierarchy
1743 * @root: List of sysctl headers to register on
1744 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001745 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 *
1748 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001749 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001751 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 *
1753 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1754 * must be unique within that level of sysctl
1755 *
1756 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1757 * enter a sysctl file
1758 *
1759 * data - a pointer to data for use by proc_handler
1760 *
1761 * maxlen - the maximum size in bytes of the data
1762 *
1763 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1764 *
1765 * child - a pointer to the child sysctl table if this entry is a directory, or
1766 * %NULL.
1767 *
1768 * proc_handler - the text handler routine (described below)
1769 *
1770 * strategy - the strategy routine (described below)
1771 *
1772 * de - for internal use by the sysctl routines
1773 *
1774 * extra1, extra2 - extra pointers usable by the proc handler routines
1775 *
1776 * Leaf nodes in the sysctl tree will be represented by a single file
1777 * under /proc; non-leaf nodes will be represented by directories.
1778 *
1779 * sysctl(2) can automatically manage read and write requests through
1780 * the sysctl table. The data and maxlen fields of the ctl_table
1781 * struct enable minimal validation of the values being written to be
1782 * performed, and the mode field allows minimal authentication.
1783 *
1784 * More sophisticated management can be enabled by the provision of a
1785 * strategy routine with the table entry. This will be called before
1786 * any automatic read or write of the data is performed.
1787 *
1788 * The strategy routine may return
1789 *
1790 * < 0 - Error occurred (error is passed to user process)
1791 *
1792 * 0 - OK - proceed with automatic read or write.
1793 *
1794 * > 0 - OK - read or write has been done by the strategy routine, so
1795 * return immediately.
1796 *
1797 * There must be a proc_handler routine for any terminal nodes
1798 * mirrored under /proc/sys (non-terminals are handled by a built-in
1799 * directory handler). Several default handlers are available to
1800 * cover common cases -
1801 *
1802 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1803 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1804 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1805 *
1806 * It is the handler's job to read the input buffer from user memory
1807 * and process it. The handler should return 0 on success.
1808 *
1809 * This routine returns %NULL on a failure to register, and a pointer
1810 * to the table header on success.
1811 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001812struct ctl_table_header *__register_sysctl_paths(
1813 struct ctl_table_root *root,
1814 struct nsproxy *namespaces,
1815 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001817 struct ctl_table_header *header;
1818 struct ctl_table *new, **prevp;
1819 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001820 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001821
1822 /* Count the path components */
1823 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1824 ;
1825
1826 /*
1827 * For each path component, allocate a 2-element ctl_table array.
1828 * The first array element will be filled with the sysctl entry
1829 * for this, the second will be the sentinel (ctl_name == 0).
1830 *
1831 * We allocate everything in one go so that we don't have to
1832 * worry about freeing additional memory in unregister_sysctl_table.
1833 */
1834 header = kzalloc(sizeof(struct ctl_table_header) +
1835 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1836 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001838
1839 new = (struct ctl_table *) (header + 1);
1840
1841 /* Now connect the dots */
1842 prevp = &header->ctl_table;
1843 for (n = 0; n < npath; ++n, ++path) {
1844 /* Copy the procname */
1845 new->procname = path->procname;
1846 new->ctl_name = path->ctl_name;
1847 new->mode = 0555;
1848
1849 *prevp = new;
1850 prevp = &new->child;
1851
1852 new += 2;
1853 }
1854 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001855 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001856
1857 INIT_LIST_HEAD(&header->ctl_entry);
1858 header->used = 0;
1859 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001860 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001861 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001862 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001863#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001864 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001865 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001866 return NULL;
1867 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001868#endif
Al Viro330d57f2005-11-04 10:18:40 +00001869 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001870 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001871 header->attached_by = header->ctl_table;
1872 header->attached_to = root_table;
1873 header->parent = &root_table_header;
1874 for (set = header->set; set; set = set->parent) {
1875 struct ctl_table_header *p;
1876 list_for_each_entry(p, &set->list, ctl_entry) {
1877 if (p->unregistering)
1878 continue;
1879 try_attach(p, header);
1880 }
1881 }
1882 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001883 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001884 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001885
1886 return header;
1887}
1888
1889/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001890 * register_sysctl_table_path - register a sysctl table hierarchy
1891 * @path: The path to the directory the sysctl table is in.
1892 * @table: the top-level table structure
1893 *
1894 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1895 * array. A completely 0 filled entry terminates the table.
1896 *
1897 * See __register_sysctl_paths for more details.
1898 */
1899struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1900 struct ctl_table *table)
1901{
1902 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1903 path, table);
1904}
1905
1906/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001907 * register_sysctl_table - register a sysctl table hierarchy
1908 * @table: the top-level table structure
1909 *
1910 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1911 * array. A completely 0 filled entry terminates the table.
1912 *
1913 * See register_sysctl_paths for more details.
1914 */
1915struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1916{
1917 static const struct ctl_path null_path[] = { {} };
1918
1919 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920}
1921
1922/**
1923 * unregister_sysctl_table - unregister a sysctl table hierarchy
1924 * @header: the header returned from register_sysctl_table
1925 *
1926 * Unregisters the sysctl table and all children. proc entries may not
1927 * actually be removed until they are no longer used by anyone.
1928 */
1929void unregister_sysctl_table(struct ctl_table_header * header)
1930{
Al Viro330d57f2005-11-04 10:18:40 +00001931 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001932
1933 if (header == NULL)
1934 return;
1935
Al Viro330d57f2005-11-04 10:18:40 +00001936 spin_lock(&sysctl_lock);
1937 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001938 if (!--header->parent->count) {
1939 WARN_ON(1);
1940 kfree(header->parent);
1941 }
Al Virof7e6ced2008-07-15 01:44:23 -04001942 if (!--header->count)
1943 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001944 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945}
1946
Al Viro9043476f2008-07-15 08:54:06 -04001947int sysctl_is_seen(struct ctl_table_header *p)
1948{
1949 struct ctl_table_set *set = p->set;
1950 int res;
1951 spin_lock(&sysctl_lock);
1952 if (p->unregistering)
1953 res = 0;
1954 else if (!set->is_seen)
1955 res = 1;
1956 else
1957 res = set->is_seen(set);
1958 spin_unlock(&sysctl_lock);
1959 return res;
1960}
1961
Al Viro73455092008-07-14 21:22:20 -04001962void setup_sysctl_set(struct ctl_table_set *p,
1963 struct ctl_table_set *parent,
1964 int (*is_seen)(struct ctl_table_set *))
1965{
1966 INIT_LIST_HEAD(&p->list);
1967 p->parent = parent ? parent : &sysctl_table_root.default_set;
1968 p->is_seen = is_seen;
1969}
1970
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001971#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001972struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001973{
1974 return NULL;
1975}
1976
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001977struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1978 struct ctl_table *table)
1979{
1980 return NULL;
1981}
1982
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001983void unregister_sysctl_table(struct ctl_table_header * table)
1984{
1985}
1986
Al Viro73455092008-07-14 21:22:20 -04001987void setup_sysctl_set(struct ctl_table_set *p,
1988 struct ctl_table_set *parent,
1989 int (*is_seen)(struct ctl_table_set *))
1990{
1991}
1992
Al Virof7e6ced2008-07-15 01:44:23 -04001993void sysctl_head_put(struct ctl_table_header *head)
1994{
1995}
1996
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001997#endif /* CONFIG_SYSCTL */
1998
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999/*
2000 * /proc/sys support
2001 */
2002
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002003#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002005static int _proc_do_string(void* data, int maxlen, int write,
2006 struct file *filp, void __user *buffer,
2007 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002008{
2009 size_t len;
2010 char __user *p;
2011 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002012
2013 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002014 *lenp = 0;
2015 return 0;
2016 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002017
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002018 if (write) {
2019 len = 0;
2020 p = buffer;
2021 while (len < *lenp) {
2022 if (get_user(c, p++))
2023 return -EFAULT;
2024 if (c == 0 || c == '\n')
2025 break;
2026 len++;
2027 }
2028 if (len >= maxlen)
2029 len = maxlen-1;
2030 if(copy_from_user(data, buffer, len))
2031 return -EFAULT;
2032 ((char *) data)[len] = 0;
2033 *ppos += *lenp;
2034 } else {
2035 len = strlen(data);
2036 if (len > maxlen)
2037 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002038
2039 if (*ppos > len) {
2040 *lenp = 0;
2041 return 0;
2042 }
2043
2044 data += *ppos;
2045 len -= *ppos;
2046
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002047 if (len > *lenp)
2048 len = *lenp;
2049 if (len)
2050 if(copy_to_user(buffer, data, len))
2051 return -EFAULT;
2052 if (len < *lenp) {
2053 if(put_user('\n', ((char __user *) buffer) + len))
2054 return -EFAULT;
2055 len++;
2056 }
2057 *lenp = len;
2058 *ppos += len;
2059 }
2060 return 0;
2061}
2062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063/**
2064 * proc_dostring - read a string sysctl
2065 * @table: the sysctl table
2066 * @write: %TRUE if this is a write to the sysctl file
2067 * @filp: the file structure
2068 * @buffer: the user buffer
2069 * @lenp: the size of the user buffer
2070 * @ppos: file position
2071 *
2072 * Reads/writes a string from/to the user buffer. If the kernel
2073 * buffer provided is not large enough to hold the string, the
2074 * string is truncated. The copied string is %NULL-terminated.
2075 * If the string is being read by the user process, it is copied
2076 * and a newline '\n' is added. It is truncated if the buffer is
2077 * not large enough.
2078 *
2079 * Returns 0 on success.
2080 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002081int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 void __user *buffer, size_t *lenp, loff_t *ppos)
2083{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002084 return _proc_do_string(table->data, table->maxlen, write, filp,
2085 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086}
2087
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088
2089static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2090 int *valp,
2091 int write, void *data)
2092{
2093 if (write) {
2094 *valp = *negp ? -*lvalp : *lvalp;
2095 } else {
2096 int val = *valp;
2097 if (val < 0) {
2098 *negp = -1;
2099 *lvalp = (unsigned long)-val;
2100 } else {
2101 *negp = 0;
2102 *lvalp = (unsigned long)val;
2103 }
2104 }
2105 return 0;
2106}
2107
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002108static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002109 int write, struct file *filp, void __user *buffer,
2110 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2112 int write, void *data),
2113 void *data)
2114{
2115#define TMPBUFLEN 21
2116 int *i, vleft, first=1, neg, val;
2117 unsigned long lval;
2118 size_t left, len;
2119
2120 char buf[TMPBUFLEN], *p;
2121 char __user *s = buffer;
2122
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002123 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 (*ppos && !write)) {
2125 *lenp = 0;
2126 return 0;
2127 }
2128
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002129 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 vleft = table->maxlen / sizeof(*i);
2131 left = *lenp;
2132
2133 if (!conv)
2134 conv = do_proc_dointvec_conv;
2135
2136 for (; left && vleft--; i++, first=0) {
2137 if (write) {
2138 while (left) {
2139 char c;
2140 if (get_user(c, s))
2141 return -EFAULT;
2142 if (!isspace(c))
2143 break;
2144 left--;
2145 s++;
2146 }
2147 if (!left)
2148 break;
2149 neg = 0;
2150 len = left;
2151 if (len > sizeof(buf) - 1)
2152 len = sizeof(buf) - 1;
2153 if (copy_from_user(buf, s, len))
2154 return -EFAULT;
2155 buf[len] = 0;
2156 p = buf;
2157 if (*p == '-' && left > 1) {
2158 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002159 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 }
2161 if (*p < '0' || *p > '9')
2162 break;
2163
2164 lval = simple_strtoul(p, &p, 0);
2165
2166 len = p-buf;
2167 if ((len < left) && *p && !isspace(*p))
2168 break;
2169 if (neg)
2170 val = -val;
2171 s += len;
2172 left -= len;
2173
2174 if (conv(&neg, &lval, i, 1, data))
2175 break;
2176 } else {
2177 p = buf;
2178 if (!first)
2179 *p++ = '\t';
2180
2181 if (conv(&neg, &lval, i, 0, data))
2182 break;
2183
2184 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2185 len = strlen(buf);
2186 if (len > left)
2187 len = left;
2188 if(copy_to_user(s, buf, len))
2189 return -EFAULT;
2190 left -= len;
2191 s += len;
2192 }
2193 }
2194
2195 if (!write && !first && left) {
2196 if(put_user('\n', s))
2197 return -EFAULT;
2198 left--, s++;
2199 }
2200 if (write) {
2201 while (left) {
2202 char c;
2203 if (get_user(c, s++))
2204 return -EFAULT;
2205 if (!isspace(c))
2206 break;
2207 left--;
2208 }
2209 }
2210 if (write && first)
2211 return -EINVAL;
2212 *lenp -= left;
2213 *ppos += *lenp;
2214 return 0;
2215#undef TMPBUFLEN
2216}
2217
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002218static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002219 void __user *buffer, size_t *lenp, loff_t *ppos,
2220 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2221 int write, void *data),
2222 void *data)
2223{
2224 return __do_proc_dointvec(table->data, table, write, filp,
2225 buffer, lenp, ppos, conv, data);
2226}
2227
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228/**
2229 * proc_dointvec - read a vector of integers
2230 * @table: the sysctl table
2231 * @write: %TRUE if this is a write to the sysctl file
2232 * @filp: the file structure
2233 * @buffer: the user buffer
2234 * @lenp: the size of the user buffer
2235 * @ppos: file position
2236 *
2237 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2238 * values from/to the user buffer, treated as an ASCII string.
2239 *
2240 * Returns 0 on success.
2241 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002242int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 void __user *buffer, size_t *lenp, loff_t *ppos)
2244{
2245 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2246 NULL,NULL);
2247}
2248
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002249/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002250 * Taint values can only be increased
2251 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002252 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002253static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002254 void __user *buffer, size_t *lenp, loff_t *ppos)
2255{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002256 struct ctl_table t;
2257 unsigned long tmptaint = get_taint();
2258 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002259
Bastian Blank91fcd412007-04-23 14:41:14 -07002260 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002261 return -EPERM;
2262
Andi Kleen25ddbb12008-10-15 22:01:41 -07002263 t = *table;
2264 t.data = &tmptaint;
2265 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2266 if (err < 0)
2267 return err;
2268
2269 if (write) {
2270 /*
2271 * Poor man's atomic or. Not worth adding a primitive
2272 * to everyone's atomic.h for this
2273 */
2274 int i;
2275 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2276 if ((tmptaint >> i) & 1)
2277 add_taint(i);
2278 }
2279 }
2280
2281 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002282}
2283
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284struct do_proc_dointvec_minmax_conv_param {
2285 int *min;
2286 int *max;
2287};
2288
2289static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2290 int *valp,
2291 int write, void *data)
2292{
2293 struct do_proc_dointvec_minmax_conv_param *param = data;
2294 if (write) {
2295 int val = *negp ? -*lvalp : *lvalp;
2296 if ((param->min && *param->min > val) ||
2297 (param->max && *param->max < val))
2298 return -EINVAL;
2299 *valp = val;
2300 } else {
2301 int val = *valp;
2302 if (val < 0) {
2303 *negp = -1;
2304 *lvalp = (unsigned long)-val;
2305 } else {
2306 *negp = 0;
2307 *lvalp = (unsigned long)val;
2308 }
2309 }
2310 return 0;
2311}
2312
2313/**
2314 * proc_dointvec_minmax - read a vector of integers with min/max values
2315 * @table: the sysctl table
2316 * @write: %TRUE if this is a write to the sysctl file
2317 * @filp: the file structure
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2321 *
2322 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2323 * values from/to the user buffer, treated as an ASCII string.
2324 *
2325 * This routine will ensure the values are within the range specified by
2326 * table->extra1 (min) and table->extra2 (max).
2327 *
2328 * Returns 0 on success.
2329 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002330int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 void __user *buffer, size_t *lenp, loff_t *ppos)
2332{
2333 struct do_proc_dointvec_minmax_conv_param param = {
2334 .min = (int *) table->extra1,
2335 .max = (int *) table->extra2,
2336 };
2337 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2338 do_proc_dointvec_minmax_conv, &param);
2339}
2340
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002341static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 struct file *filp,
2343 void __user *buffer,
2344 size_t *lenp, loff_t *ppos,
2345 unsigned long convmul,
2346 unsigned long convdiv)
2347{
2348#define TMPBUFLEN 21
2349 unsigned long *i, *min, *max, val;
2350 int vleft, first=1, neg;
2351 size_t len, left;
2352 char buf[TMPBUFLEN], *p;
2353 char __user *s = buffer;
2354
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002355 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 (*ppos && !write)) {
2357 *lenp = 0;
2358 return 0;
2359 }
2360
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002361 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 min = (unsigned long *) table->extra1;
2363 max = (unsigned long *) table->extra2;
2364 vleft = table->maxlen / sizeof(unsigned long);
2365 left = *lenp;
2366
2367 for (; left && vleft--; i++, min++, max++, first=0) {
2368 if (write) {
2369 while (left) {
2370 char c;
2371 if (get_user(c, s))
2372 return -EFAULT;
2373 if (!isspace(c))
2374 break;
2375 left--;
2376 s++;
2377 }
2378 if (!left)
2379 break;
2380 neg = 0;
2381 len = left;
2382 if (len > TMPBUFLEN-1)
2383 len = TMPBUFLEN-1;
2384 if (copy_from_user(buf, s, len))
2385 return -EFAULT;
2386 buf[len] = 0;
2387 p = buf;
2388 if (*p == '-' && left > 1) {
2389 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002390 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 }
2392 if (*p < '0' || *p > '9')
2393 break;
2394 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2395 len = p-buf;
2396 if ((len < left) && *p && !isspace(*p))
2397 break;
2398 if (neg)
2399 val = -val;
2400 s += len;
2401 left -= len;
2402
2403 if(neg)
2404 continue;
2405 if ((min && val < *min) || (max && val > *max))
2406 continue;
2407 *i = val;
2408 } else {
2409 p = buf;
2410 if (!first)
2411 *p++ = '\t';
2412 sprintf(p, "%lu", convdiv * (*i) / convmul);
2413 len = strlen(buf);
2414 if (len > left)
2415 len = left;
2416 if(copy_to_user(s, buf, len))
2417 return -EFAULT;
2418 left -= len;
2419 s += len;
2420 }
2421 }
2422
2423 if (!write && !first && left) {
2424 if(put_user('\n', s))
2425 return -EFAULT;
2426 left--, s++;
2427 }
2428 if (write) {
2429 while (left) {
2430 char c;
2431 if (get_user(c, s++))
2432 return -EFAULT;
2433 if (!isspace(c))
2434 break;
2435 left--;
2436 }
2437 }
2438 if (write && first)
2439 return -EINVAL;
2440 *lenp -= left;
2441 *ppos += *lenp;
2442 return 0;
2443#undef TMPBUFLEN
2444}
2445
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002446static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002447 struct file *filp,
2448 void __user *buffer,
2449 size_t *lenp, loff_t *ppos,
2450 unsigned long convmul,
2451 unsigned long convdiv)
2452{
2453 return __do_proc_doulongvec_minmax(table->data, table, write,
2454 filp, buffer, lenp, ppos, convmul, convdiv);
2455}
2456
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457/**
2458 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2459 * @table: the sysctl table
2460 * @write: %TRUE if this is a write to the sysctl file
2461 * @filp: the file structure
2462 * @buffer: the user buffer
2463 * @lenp: the size of the user buffer
2464 * @ppos: file position
2465 *
2466 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2467 * values from/to the user buffer, treated as an ASCII string.
2468 *
2469 * This routine will ensure the values are within the range specified by
2470 * table->extra1 (min) and table->extra2 (max).
2471 *
2472 * Returns 0 on success.
2473 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002474int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 void __user *buffer, size_t *lenp, loff_t *ppos)
2476{
2477 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2478}
2479
2480/**
2481 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
2484 * @filp: the file structure
2485 * @buffer: the user buffer
2486 * @lenp: the size of the user buffer
2487 * @ppos: file position
2488 *
2489 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2490 * values from/to the user buffer, treated as an ASCII string. The values
2491 * are treated as milliseconds, and converted to jiffies when they are stored.
2492 *
2493 * This routine will ensure the values are within the range specified by
2494 * table->extra1 (min) and table->extra2 (max).
2495 *
2496 * Returns 0 on success.
2497 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002498int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 struct file *filp,
2500 void __user *buffer,
2501 size_t *lenp, loff_t *ppos)
2502{
2503 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2504 lenp, ppos, HZ, 1000l);
2505}
2506
2507
2508static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2509 int *valp,
2510 int write, void *data)
2511{
2512 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002513 if (*lvalp > LONG_MAX / HZ)
2514 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2516 } else {
2517 int val = *valp;
2518 unsigned long lval;
2519 if (val < 0) {
2520 *negp = -1;
2521 lval = (unsigned long)-val;
2522 } else {
2523 *negp = 0;
2524 lval = (unsigned long)val;
2525 }
2526 *lvalp = lval / HZ;
2527 }
2528 return 0;
2529}
2530
2531static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2532 int *valp,
2533 int write, void *data)
2534{
2535 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002536 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2537 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2539 } else {
2540 int val = *valp;
2541 unsigned long lval;
2542 if (val < 0) {
2543 *negp = -1;
2544 lval = (unsigned long)-val;
2545 } else {
2546 *negp = 0;
2547 lval = (unsigned long)val;
2548 }
2549 *lvalp = jiffies_to_clock_t(lval);
2550 }
2551 return 0;
2552}
2553
2554static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2555 int *valp,
2556 int write, void *data)
2557{
2558 if (write) {
2559 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2560 } else {
2561 int val = *valp;
2562 unsigned long lval;
2563 if (val < 0) {
2564 *negp = -1;
2565 lval = (unsigned long)-val;
2566 } else {
2567 *negp = 0;
2568 lval = (unsigned long)val;
2569 }
2570 *lvalp = jiffies_to_msecs(lval);
2571 }
2572 return 0;
2573}
2574
2575/**
2576 * proc_dointvec_jiffies - read a vector of integers as seconds
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
2579 * @filp: the file structure
2580 * @buffer: the user buffer
2581 * @lenp: the size of the user buffer
2582 * @ppos: file position
2583 *
2584 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2585 * values from/to the user buffer, treated as an ASCII string.
2586 * The values read are assumed to be in seconds, and are converted into
2587 * jiffies.
2588 *
2589 * Returns 0 on success.
2590 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002591int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 void __user *buffer, size_t *lenp, loff_t *ppos)
2593{
2594 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2595 do_proc_dointvec_jiffies_conv,NULL);
2596}
2597
2598/**
2599 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2600 * @table: the sysctl table
2601 * @write: %TRUE if this is a write to the sysctl file
2602 * @filp: the file structure
2603 * @buffer: the user buffer
2604 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002605 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 *
2607 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2608 * values from/to the user buffer, treated as an ASCII string.
2609 * The values read are assumed to be in 1/USER_HZ seconds, and
2610 * are converted into jiffies.
2611 *
2612 * Returns 0 on success.
2613 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002614int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 void __user *buffer, size_t *lenp, loff_t *ppos)
2616{
2617 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2618 do_proc_dointvec_userhz_jiffies_conv,NULL);
2619}
2620
2621/**
2622 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2623 * @table: the sysctl table
2624 * @write: %TRUE if this is a write to the sysctl file
2625 * @filp: the file structure
2626 * @buffer: the user buffer
2627 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002628 * @ppos: file position
2629 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 *
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2632 * values from/to the user buffer, treated as an ASCII string.
2633 * The values read are assumed to be in 1/1000 seconds, and
2634 * are converted into jiffies.
2635 *
2636 * Returns 0 on success.
2637 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002638int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 void __user *buffer, size_t *lenp, loff_t *ppos)
2640{
2641 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2642 do_proc_dointvec_ms_jiffies_conv, NULL);
2643}
2644
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002645static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002646 void __user *buffer, size_t *lenp, loff_t *ppos)
2647{
2648 struct pid *new_pid;
2649 pid_t tmp;
2650 int r;
2651
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002652 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002653
2654 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2655 lenp, ppos, NULL, NULL);
2656 if (r || !write)
2657 return r;
2658
2659 new_pid = find_get_pid(tmp);
2660 if (!new_pid)
2661 return -ESRCH;
2662
2663 put_pid(xchg(&cad_pid, new_pid));
2664 return 0;
2665}
2666
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667#else /* CONFIG_PROC_FS */
2668
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002669int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 void __user *buffer, size_t *lenp, loff_t *ppos)
2671{
2672 return -ENOSYS;
2673}
2674
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002675int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 void __user *buffer, size_t *lenp, loff_t *ppos)
2677{
2678 return -ENOSYS;
2679}
2680
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002681int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 void __user *buffer, size_t *lenp, loff_t *ppos)
2683{
2684 return -ENOSYS;
2685}
2686
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002687int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 void __user *buffer, size_t *lenp, loff_t *ppos)
2689{
2690 return -ENOSYS;
2691}
2692
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002693int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 void __user *buffer, size_t *lenp, loff_t *ppos)
2695{
2696 return -ENOSYS;
2697}
2698
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002699int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 void __user *buffer, size_t *lenp, loff_t *ppos)
2701{
2702 return -ENOSYS;
2703}
2704
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002705int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 void __user *buffer, size_t *lenp, loff_t *ppos)
2707{
2708 return -ENOSYS;
2709}
2710
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002711int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 struct file *filp,
2713 void __user *buffer,
2714 size_t *lenp, loff_t *ppos)
2715{
2716 return -ENOSYS;
2717}
2718
2719
2720#endif /* CONFIG_PROC_FS */
2721
2722
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002723#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724/*
2725 * General sysctl support routines
2726 */
2727
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002728/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002729int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002730 void __user *oldval, size_t __user *oldlenp,
2731 void __user *newval, size_t newlen)
2732{
2733 size_t len;
2734
2735 /* Get out of I don't have a variable */
2736 if (!table->data || !table->maxlen)
2737 return -ENOTDIR;
2738
2739 if (oldval && oldlenp) {
2740 if (get_user(len, oldlenp))
2741 return -EFAULT;
2742 if (len) {
2743 if (len > table->maxlen)
2744 len = table->maxlen;
2745 if (copy_to_user(oldval, table->data, len))
2746 return -EFAULT;
2747 if (put_user(len, oldlenp))
2748 return -EFAULT;
2749 }
2750 }
2751
2752 if (newval && newlen) {
2753 if (newlen > table->maxlen)
2754 newlen = table->maxlen;
2755
2756 if (copy_from_user(table->data, newval, newlen))
2757 return -EFAULT;
2758 }
2759 return 1;
2760}
2761
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002763int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002765 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 if (!table->data || !table->maxlen)
2768 return -ENOTDIR;
2769
2770 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002771 size_t bufsize;
2772 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002774 if (bufsize) {
2775 size_t len = strlen(table->data), copied;
2776
2777 /* This shouldn't trigger for a well-formed sysctl */
2778 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002780
2781 /* Copy up to a max of bufsize-1 bytes of the string */
2782 copied = (len >= bufsize) ? bufsize - 1 : len;
2783
2784 if (copy_to_user(oldval, table->data, copied) ||
2785 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002787 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 return -EFAULT;
2789 }
2790 }
2791 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002792 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 if (len > table->maxlen)
2794 len = table->maxlen;
2795 if(copy_from_user(table->data, newval, len))
2796 return -EFAULT;
2797 if (len == table->maxlen)
2798 len--;
2799 ((char *) table->data)[len] = 0;
2800 }
Yi Yang82c9df82005-12-30 16:37:10 +08002801 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802}
2803
2804/*
2805 * This function makes sure that all of the integers in the vector
2806 * are between the minimum and maximum values given in the arrays
2807 * table->extra1 and table->extra2, respectively.
2808 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002809int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002811 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812{
2813
2814 if (newval && newlen) {
2815 int __user *vec = (int __user *) newval;
2816 int *min = (int *) table->extra1;
2817 int *max = (int *) table->extra2;
2818 size_t length;
2819 int i;
2820
2821 if (newlen % sizeof(int) != 0)
2822 return -EINVAL;
2823
2824 if (!table->extra1 && !table->extra2)
2825 return 0;
2826
2827 if (newlen > table->maxlen)
2828 newlen = table->maxlen;
2829 length = newlen / sizeof(int);
2830
2831 for (i = 0; i < length; i++) {
2832 int value;
2833 if (get_user(value, vec + i))
2834 return -EFAULT;
2835 if (min && value < min[i])
2836 return -EINVAL;
2837 if (max && value > max[i])
2838 return -EINVAL;
2839 }
2840 }
2841 return 0;
2842}
2843
2844/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002845int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002847 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002849 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002851
2852 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002854 if (olen) {
2855 int val;
2856
2857 if (olen < sizeof(int))
2858 return -EINVAL;
2859
2860 val = *(int *)(table->data) / HZ;
2861 if (put_user(val, (int __user *)oldval))
2862 return -EFAULT;
2863 if (put_user(sizeof(int), oldlenp))
2864 return -EFAULT;
2865 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 }
2867 if (newval && newlen) {
2868 int new;
2869 if (newlen != sizeof(int))
2870 return -EINVAL;
2871 if (get_user(new, (int __user *)newval))
2872 return -EFAULT;
2873 *(int *)(table->data) = new*HZ;
2874 }
2875 return 1;
2876}
2877
2878/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002879int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002881 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002883 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002885
2886 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002888 if (olen) {
2889 int val;
2890
2891 if (olen < sizeof(int))
2892 return -EINVAL;
2893
2894 val = jiffies_to_msecs(*(int *)(table->data));
2895 if (put_user(val, (int __user *)oldval))
2896 return -EFAULT;
2897 if (put_user(sizeof(int), oldlenp))
2898 return -EFAULT;
2899 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 }
2901 if (newval && newlen) {
2902 int new;
2903 if (newlen != sizeof(int))
2904 return -EINVAL;
2905 if (get_user(new, (int __user *)newval))
2906 return -EFAULT;
2907 *(int *)(table->data) = msecs_to_jiffies(new);
2908 }
2909 return 1;
2910}
2911
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002912
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002913
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002914#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
2916
2917asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2918{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002919 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002920 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002921
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002922 if (copy_from_user(&tmp, args, sizeof(tmp)))
2923 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002924
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002925 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002926
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002927 /* If no error reading the parameters then just -ENOSYS ... */
2928 if (!error)
2929 error = -ENOSYS;
2930
2931 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932}
2933
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002934int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002935 void __user *oldval, size_t __user *oldlenp,
2936 void __user *newval, size_t newlen)
2937{
2938 return -ENOSYS;
2939}
2940
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002941int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002943 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944{
2945 return -ENOSYS;
2946}
2947
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002948int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002950 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951{
2952 return -ENOSYS;
2953}
2954
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002955int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002957 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958{
2959 return -ENOSYS;
2960}
2961
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002962int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002964 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965{
2966 return -ENOSYS;
2967}
2968
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002969#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002971static int deprecated_sysctl_warning(struct __sysctl_args *args)
2972{
2973 static int msg_count;
2974 int name[CTL_MAXNAME];
2975 int i;
2976
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002977 /* Check args->nlen. */
2978 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2979 return -ENOTDIR;
2980
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002981 /* Read in the sysctl name for better debug message logging */
2982 for (i = 0; i < args->nlen; i++)
2983 if (get_user(name[i], args->name + i))
2984 return -EFAULT;
2985
2986 /* Ignore accesses to kernel.version */
2987 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2988 return 0;
2989
2990 if (msg_count < 5) {
2991 msg_count++;
2992 printk(KERN_INFO
2993 "warning: process `%s' used the deprecated sysctl "
2994 "system call with ", current->comm);
2995 for (i = 0; i < args->nlen; i++)
2996 printk("%d.", name[i]);
2997 printk("\n");
2998 }
2999 return 0;
3000}
3001
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002/*
3003 * No sense putting this after each symbol definition, twice,
3004 * exception granted :-)
3005 */
3006EXPORT_SYMBOL(proc_dointvec);
3007EXPORT_SYMBOL(proc_dointvec_jiffies);
3008EXPORT_SYMBOL(proc_dointvec_minmax);
3009EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3010EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3011EXPORT_SYMBOL(proc_dostring);
3012EXPORT_SYMBOL(proc_doulongvec_minmax);
3013EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3014EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003015EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016EXPORT_SYMBOL(sysctl_intvec);
3017EXPORT_SYMBOL(sysctl_jiffies);
3018EXPORT_SYMBOL(sysctl_ms_jiffies);
3019EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003020EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021EXPORT_SYMBOL(unregister_sysctl_table);