blob: c83f566e940abaac4cdef8b7744746104aaabd38 [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 Gondwana195cf452008-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 Molnar23f78d42006-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
Davide Libenzi7ef99642008-12-01 13:13:55 -0800179#ifdef CONFIG_EPOLL
180extern struct ctl_table epoll_table[];
181#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
184int sysctl_legacy_va_layout;
185#endif
186
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700187extern int prove_locking;
188extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* The default sysctl tables: */
191
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700192static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 {
194 .ctl_name = CTL_KERN,
195 .procname = "kernel",
196 .mode = 0555,
197 .child = kern_table,
198 },
199 {
200 .ctl_name = CTL_VM,
201 .procname = "vm",
202 .mode = 0555,
203 .child = vm_table,
204 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 .ctl_name = CTL_FS,
207 .procname = "fs",
208 .mode = 0555,
209 .child = fs_table,
210 },
211 {
212 .ctl_name = CTL_DEBUG,
213 .procname = "debug",
214 .mode = 0555,
215 .child = debug_table,
216 },
217 {
218 .ctl_name = CTL_DEV,
219 .procname = "dev",
220 .mode = 0555,
221 .child = dev_table,
222 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700223/*
224 * NOTE: do not add new entries to this table unless you have read
225 * Documentation/sysctl/ctl_unnumbered.txt
226 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 { .ctl_name = 0 }
228};
229
Ingo Molnar77e54a12007-07-09 18:52:00 +0200230#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100231static int min_sched_granularity_ns = 100000; /* 100 usecs */
232static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
233static int min_wakeup_granularity_ns; /* 0 usecs */
234static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#endif
236
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700237static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238#ifdef CONFIG_SCHED_DEBUG
239 {
240 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100241 .procname = "sched_min_granularity_ns",
242 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243 .maxlen = sizeof(unsigned int),
244 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100245 .proc_handler = &sched_nr_latency_handler,
246 .strategy = &sysctl_intvec,
247 .extra1 = &min_sched_granularity_ns,
248 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249 },
250 {
251 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200252 .procname = "sched_latency_ns",
253 .data = &sysctl_sched_latency,
254 .maxlen = sizeof(unsigned int),
255 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100256 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200257 .strategy = &sysctl_intvec,
258 .extra1 = &min_sched_granularity_ns,
259 .extra2 = &max_sched_granularity_ns,
260 },
261 {
262 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200263 .procname = "sched_wakeup_granularity_ns",
264 .data = &sysctl_sched_wakeup_granularity,
265 .maxlen = sizeof(unsigned int),
266 .mode = 0644,
267 .proc_handler = &proc_dointvec_minmax,
268 .strategy = &sysctl_intvec,
269 .extra1 = &min_wakeup_granularity_ns,
270 .extra2 = &max_wakeup_granularity_ns,
271 },
272 {
273 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200274 .procname = "sched_shares_ratelimit",
275 .data = &sysctl_sched_shares_ratelimit,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
278 .proc_handler = &proc_dointvec,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200282 .procname = "sched_shares_thresh",
283 .data = &sysctl_sched_shares_thresh,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec_minmax,
287 .strategy = &sysctl_intvec,
288 .extra1 = &zero,
289 },
290 {
291 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292 .procname = "sched_child_runs_first",
293 .data = &sysctl_sched_child_runs_first,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec,
297 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200298 {
299 .ctl_name = CTL_UNNUMBERED,
300 .procname = "sched_features",
301 .data = &sysctl_sched_features,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200306 {
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_migration_cost",
309 .data = &sysctl_sched_migration_cost,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
313 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100314 {
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_nr_migrate",
317 .data = &sysctl_sched_nr_migrate,
318 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200322#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200323 {
324 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100325 .procname = "sched_rt_period_us",
326 .data = &sysctl_sched_rt_period,
327 .maxlen = sizeof(unsigned int),
328 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200329 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100330 },
331 {
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_rt_runtime_us",
334 .data = &sysctl_sched_rt_runtime,
335 .maxlen = sizeof(int),
336 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200337 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100338 },
339 {
340 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200341 .procname = "sched_compat_yield",
342 .data = &sysctl_sched_compat_yield,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = &proc_dointvec,
346 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700347#ifdef CONFIG_PROVE_LOCKING
348 {
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "prove_locking",
351 .data = &prove_locking,
352 .maxlen = sizeof(int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
355 },
356#endif
357#ifdef CONFIG_LOCK_STAT
358 {
359 .ctl_name = CTL_UNNUMBERED,
360 .procname = "lock_stat",
361 .data = &lock_stat,
362 .maxlen = sizeof(int),
363 .mode = 0644,
364 .proc_handler = &proc_dointvec,
365 },
366#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200367 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 .ctl_name = KERN_PANIC,
369 .procname = "panic",
370 .data = &panic_timeout,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = &proc_dointvec,
374 },
375 {
376 .ctl_name = KERN_CORE_USES_PID,
377 .procname = "core_uses_pid",
378 .data = &core_uses_pid,
379 .maxlen = sizeof(int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383 {
384 .ctl_name = KERN_CORE_PATTERN,
385 .procname = "core_pattern",
386 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700387 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 .mode = 0644,
389 .proc_handler = &proc_dostring,
390 .strategy = &sysctl_string,
391 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800392#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700395 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800396 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700397 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800399#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100400#ifdef CONFIG_LATENCYTOP
401 {
402 .procname = "latencytop",
403 .data = &latencytop_enabled,
404 .maxlen = sizeof(int),
405 .mode = 0644,
406 .proc_handler = &proc_dointvec,
407 },
408#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#ifdef CONFIG_BLK_DEV_INITRD
410 {
411 .ctl_name = KERN_REALROOTDEV,
412 .procname = "real-root-dev",
413 .data = &real_root_dev,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
417 },
418#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700419 {
420 .ctl_name = CTL_UNNUMBERED,
421 .procname = "print-fatal-signals",
422 .data = &print_fatal_signals,
423 .maxlen = sizeof(int),
424 .mode = 0644,
425 .proc_handler = &proc_dointvec,
426 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700427#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 {
429 .ctl_name = KERN_SPARC_REBOOT,
430 .procname = "reboot-cmd",
431 .data = reboot_command,
432 .maxlen = 256,
433 .mode = 0644,
434 .proc_handler = &proc_dostring,
435 .strategy = &sysctl_string,
436 },
437 {
438 .ctl_name = KERN_SPARC_STOP_A,
439 .procname = "stop-a",
440 .data = &stop_a_enabled,
441 .maxlen = sizeof (int),
442 .mode = 0644,
443 .proc_handler = &proc_dointvec,
444 },
445 {
446 .ctl_name = KERN_SPARC_SCONS_PWROFF,
447 .procname = "scons-poweroff",
448 .data = &scons_pwroff,
449 .maxlen = sizeof (int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec,
452 },
453#endif
454#ifdef __hppa__
455 {
456 .ctl_name = KERN_HPPA_PWRSW,
457 .procname = "soft-power",
458 .data = &pwrsw_enabled,
459 .maxlen = sizeof (int),
460 .mode = 0644,
461 .proc_handler = &proc_dointvec,
462 },
463 {
464 .ctl_name = KERN_HPPA_UNALIGNED,
465 .procname = "unaligned-trap",
466 .data = &unaligned_enabled,
467 .maxlen = sizeof (int),
468 .mode = 0644,
469 .proc_handler = &proc_dointvec,
470 },
471#endif
472 {
473 .ctl_name = KERN_CTLALTDEL,
474 .procname = "ctrl-alt-del",
475 .data = &C_A_D,
476 .maxlen = sizeof(int),
477 .mode = 0644,
478 .proc_handler = &proc_dointvec,
479 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400480#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200481 {
482 .ctl_name = CTL_UNNUMBERED,
483 .procname = "ftrace_enabled",
484 .data = &ftrace_enabled,
485 .maxlen = sizeof(int),
486 .mode = 0644,
487 .proc_handler = &ftrace_enable_sysctl,
488 },
489#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400490#ifdef CONFIG_TRACING
491 {
492 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100493 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400494 .data = &ftrace_dump_on_oops,
495 .maxlen = sizeof(int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
498 },
499#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200500#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 {
502 .ctl_name = KERN_MODPROBE,
503 .procname = "modprobe",
504 .data = &modprobe_path,
505 .maxlen = KMOD_PATH_LEN,
506 .mode = 0644,
507 .proc_handler = &proc_dostring,
508 .strategy = &sysctl_string,
509 },
510#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700511#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 {
513 .ctl_name = KERN_HOTPLUG,
514 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100515 .data = &uevent_helper,
516 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .mode = 0644,
518 .proc_handler = &proc_dostring,
519 .strategy = &sysctl_string,
520 },
521#endif
522#ifdef CONFIG_CHR_DEV_SG
523 {
524 .ctl_name = KERN_SG_BIG_BUFF,
525 .procname = "sg-big-buff",
526 .data = &sg_big_buff,
527 .maxlen = sizeof (int),
528 .mode = 0444,
529 .proc_handler = &proc_dointvec,
530 },
531#endif
532#ifdef CONFIG_BSD_PROCESS_ACCT
533 {
534 .ctl_name = KERN_ACCT,
535 .procname = "acct",
536 .data = &acct_parm,
537 .maxlen = 3*sizeof(int),
538 .mode = 0644,
539 .proc_handler = &proc_dointvec,
540 },
541#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542#ifdef CONFIG_MAGIC_SYSRQ
543 {
544 .ctl_name = KERN_SYSRQ,
545 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800546 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 .maxlen = sizeof (int),
548 .mode = 0644,
549 .proc_handler = &proc_dointvec,
550 },
551#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700552#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700555 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 .maxlen = sizeof (int),
557 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700558 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700560#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 {
562 .ctl_name = KERN_MAX_THREADS,
563 .procname = "threads-max",
564 .data = &max_threads,
565 .maxlen = sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569 {
570 .ctl_name = KERN_RANDOM,
571 .procname = "random",
572 .mode = 0555,
573 .child = random_table,
574 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 {
576 .ctl_name = KERN_OVERFLOWUID,
577 .procname = "overflowuid",
578 .data = &overflowuid,
579 .maxlen = sizeof(int),
580 .mode = 0644,
581 .proc_handler = &proc_dointvec_minmax,
582 .strategy = &sysctl_intvec,
583 .extra1 = &minolduid,
584 .extra2 = &maxolduid,
585 },
586 {
587 .ctl_name = KERN_OVERFLOWGID,
588 .procname = "overflowgid",
589 .data = &overflowgid,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec_minmax,
593 .strategy = &sysctl_intvec,
594 .extra1 = &minolduid,
595 .extra2 = &maxolduid,
596 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800597#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598#ifdef CONFIG_MATHEMU
599 {
600 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
601 .procname = "ieee_emulation_warnings",
602 .data = &sysctl_ieee_emulation_warnings,
603 .maxlen = sizeof(int),
604 .mode = 0644,
605 .proc_handler = &proc_dointvec,
606 },
607#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 {
609 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
610 .procname = "userprocess_debug",
611 .data = &sysctl_userprocess_debug,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec,
615 },
616#endif
617 {
618 .ctl_name = KERN_PIDMAX,
619 .procname = "pid_max",
620 .data = &pid_max,
621 .maxlen = sizeof (int),
622 .mode = 0644,
623 .proc_handler = &proc_dointvec_minmax,
624 .strategy = sysctl_intvec,
625 .extra1 = &pid_max_min,
626 .extra2 = &pid_max_max,
627 },
628 {
629 .ctl_name = KERN_PANIC_ON_OOPS,
630 .procname = "panic_on_oops",
631 .data = &panic_on_oops,
632 .maxlen = sizeof(int),
633 .mode = 0644,
634 .proc_handler = &proc_dointvec,
635 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800636#if defined CONFIG_PRINTK
637 {
638 .ctl_name = KERN_PRINTK,
639 .procname = "printk",
640 .data = &console_loglevel,
641 .maxlen = 4*sizeof(int),
642 .mode = 0644,
643 .proc_handler = &proc_dointvec,
644 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 {
646 .ctl_name = KERN_PRINTK_RATELIMIT,
647 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700648 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .maxlen = sizeof(int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec_jiffies,
652 .strategy = &sysctl_jiffies,
653 },
654 {
655 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
656 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700657 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .maxlen = sizeof(int),
659 .mode = 0644,
660 .proc_handler = &proc_dointvec,
661 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800662#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 {
664 .ctl_name = KERN_NGROUPS_MAX,
665 .procname = "ngroups_max",
666 .data = &ngroups_max,
667 .maxlen = sizeof (int),
668 .mode = 0444,
669 .proc_handler = &proc_dointvec,
670 },
671#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
672 {
673 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
674 .procname = "unknown_nmi_panic",
675 .data = &unknown_nmi_panic,
676 .maxlen = sizeof (int),
677 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200678 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 },
Don Zickus407984f2006-09-26 10:52:27 +0200680 {
Don Zickus407984f2006-09-26 10:52:27 +0200681 .procname = "nmi_watchdog",
682 .data = &nmi_watchdog_enabled,
683 .maxlen = sizeof (int),
684 .mode = 0644,
685 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 },
687#endif
688#if defined(CONFIG_X86)
689 {
Don Zickus8da5add2006-09-26 10:52:27 +0200690 .ctl_name = KERN_PANIC_ON_NMI,
691 .procname = "panic_on_unrecovered_nmi",
692 .data = &panic_on_unrecovered_nmi,
693 .maxlen = sizeof(int),
694 .mode = 0644,
695 .proc_handler = &proc_dointvec,
696 },
697 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .ctl_name = KERN_BOOTLOADER_TYPE,
699 .procname = "bootloader_type",
700 .data = &bootloader_type,
701 .maxlen = sizeof (int),
702 .mode = 0444,
703 .proc_handler = &proc_dointvec,
704 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100705 {
706 .ctl_name = CTL_UNNUMBERED,
707 .procname = "kstack_depth_to_print",
708 .data = &kstack_depth_to_print,
709 .maxlen = sizeof(int),
710 .mode = 0644,
711 .proc_handler = &proc_dointvec,
712 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100713 {
714 .ctl_name = CTL_UNNUMBERED,
715 .procname = "io_delay_type",
716 .data = &io_delay_type,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = &proc_dointvec,
720 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800722#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 {
724 .ctl_name = KERN_RANDOMIZE,
725 .procname = "randomize_va_space",
726 .data = &randomize_va_space,
727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = &proc_dointvec,
730 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800731#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800732#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700733 {
734 .ctl_name = KERN_SPIN_RETRY,
735 .procname = "spin_retry",
736 .data = &spin_retry,
737 .maxlen = sizeof (int),
738 .mode = 0644,
739 .proc_handler = &proc_dointvec,
740 },
741#endif
Len Brown673d5b42007-07-28 03:33:16 -0400742#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800743 {
Pavel Machekc255d842006-02-20 18:27:58 -0800744 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700745 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800746 .maxlen = sizeof (unsigned long),
747 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800748 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800749 },
750#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800751#ifdef CONFIG_IA64
752 {
753 .ctl_name = KERN_IA64_UNALIGNED,
754 .procname = "ignore-unaligned-usertrap",
755 .data = &no_unaligned_warning,
756 .maxlen = sizeof (int),
757 .mode = 0644,
758 .proc_handler = &proc_dointvec,
759 },
760#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700761#ifdef CONFIG_DETECT_SOFTLOCKUP
762 {
763 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200764 .procname = "softlockup_panic",
765 .data = &softlockup_panic,
766 .maxlen = sizeof(int),
767 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700768 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200769 .strategy = &sysctl_intvec,
770 .extra1 = &zero,
771 .extra2 = &one,
772 },
773 {
774 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700775 .procname = "softlockup_thresh",
776 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200777 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700778 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200779 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700780 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200781 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700782 .extra2 = &sixty,
783 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100784 {
785 .ctl_name = CTL_UNNUMBERED,
786 .procname = "hung_task_check_count",
787 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100788 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100789 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100790 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100791 .strategy = &sysctl_intvec,
792 },
793 {
794 .ctl_name = CTL_UNNUMBERED,
795 .procname = "hung_task_timeout_secs",
796 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100797 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100798 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100799 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100800 .strategy = &sysctl_intvec,
801 },
802 {
803 .ctl_name = CTL_UNNUMBERED,
804 .procname = "hung_task_warnings",
805 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100806 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100807 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100808 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100809 .strategy = &sysctl_intvec,
810 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700811#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200812#ifdef CONFIG_COMPAT
813 {
814 .ctl_name = KERN_COMPAT_LOG,
815 .procname = "compat-log",
816 .data = &compat_log,
817 .maxlen = sizeof (int),
818 .mode = 0644,
819 .proc_handler = &proc_dointvec,
820 },
821#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700822#ifdef CONFIG_RT_MUTEXES
823 {
824 .ctl_name = KERN_MAX_LOCK_DEPTH,
825 .procname = "max_lock_depth",
826 .data = &max_lock_depth,
827 .maxlen = sizeof(int),
828 .mode = 0644,
829 .proc_handler = &proc_dointvec,
830 },
831#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700832 {
833 .ctl_name = CTL_UNNUMBERED,
834 .procname = "poweroff_cmd",
835 .data = &poweroff_cmd,
836 .maxlen = POWEROFF_CMD_PATH_LEN,
837 .mode = 0644,
838 .proc_handler = &proc_dostring,
839 .strategy = &sysctl_string,
840 },
David Howells0b77f5b2008-04-29 01:01:32 -0700841#ifdef CONFIG_KEYS
842 {
843 .ctl_name = CTL_UNNUMBERED,
844 .procname = "keys",
845 .mode = 0555,
846 .child = key_sysctls,
847 },
848#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700849#ifdef CONFIG_RCU_TORTURE_TEST
850 {
851 .ctl_name = CTL_UNNUMBERED,
852 .procname = "rcutorture_runnable",
853 .data = &rcutorture_runnable,
854 .maxlen = sizeof(int),
855 .mode = 0644,
856 .proc_handler = &proc_dointvec,
857 },
858#endif
Lee Schermerhornaf936a12008-10-18 20:26:53 -0700859#ifdef CONFIG_UNEVICTABLE_LRU
860 {
861 .ctl_name = CTL_UNNUMBERED,
862 .procname = "scan_unevictable_pages",
863 .data = &scan_unevictable_pages,
864 .maxlen = sizeof(scan_unevictable_pages),
865 .mode = 0644,
866 .proc_handler = &scan_unevictable_handler,
867 },
868#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700869/*
870 * NOTE: do not add new entries to this table unless you have read
871 * Documentation/sysctl/ctl_unnumbered.txt
872 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 { .ctl_name = 0 }
874};
875
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700876static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 {
878 .ctl_name = VM_OVERCOMMIT_MEMORY,
879 .procname = "overcommit_memory",
880 .data = &sysctl_overcommit_memory,
881 .maxlen = sizeof(sysctl_overcommit_memory),
882 .mode = 0644,
883 .proc_handler = &proc_dointvec,
884 },
885 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700886 .ctl_name = VM_PANIC_ON_OOM,
887 .procname = "panic_on_oom",
888 .data = &sysctl_panic_on_oom,
889 .maxlen = sizeof(sysctl_panic_on_oom),
890 .mode = 0644,
891 .proc_handler = &proc_dointvec,
892 },
893 {
David Rientjesfe071d72007-10-16 23:25:56 -0700894 .ctl_name = CTL_UNNUMBERED,
895 .procname = "oom_kill_allocating_task",
896 .data = &sysctl_oom_kill_allocating_task,
897 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
898 .mode = 0644,
899 .proc_handler = &proc_dointvec,
900 },
901 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800902 .ctl_name = CTL_UNNUMBERED,
903 .procname = "oom_dump_tasks",
904 .data = &sysctl_oom_dump_tasks,
905 .maxlen = sizeof(sysctl_oom_dump_tasks),
906 .mode = 0644,
907 .proc_handler = &proc_dointvec,
908 },
909 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .ctl_name = VM_OVERCOMMIT_RATIO,
911 .procname = "overcommit_ratio",
912 .data = &sysctl_overcommit_ratio,
913 .maxlen = sizeof(sysctl_overcommit_ratio),
914 .mode = 0644,
915 .proc_handler = &proc_dointvec,
916 },
917 {
918 .ctl_name = VM_PAGE_CLUSTER,
919 .procname = "page-cluster",
920 .data = &page_cluster,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = &proc_dointvec,
924 },
925 {
926 .ctl_name = VM_DIRTY_BACKGROUND,
927 .procname = "dirty_background_ratio",
928 .data = &dirty_background_ratio,
929 .maxlen = sizeof(dirty_background_ratio),
930 .mode = 0644,
931 .proc_handler = &proc_dointvec_minmax,
932 .strategy = &sysctl_intvec,
933 .extra1 = &zero,
934 .extra2 = &one_hundred,
935 },
936 {
937 .ctl_name = VM_DIRTY_RATIO,
938 .procname = "dirty_ratio",
939 .data = &vm_dirty_ratio,
940 .maxlen = sizeof(vm_dirty_ratio),
941 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700942 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 .strategy = &sysctl_intvec,
944 .extra1 = &zero,
945 .extra2 = &one_hundred,
946 },
947 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800949 .data = &dirty_writeback_interval,
950 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 .mode = 0644,
952 .proc_handler = &dirty_writeback_centisecs_handler,
953 },
954 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800956 .data = &dirty_expire_interval,
957 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800959 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 },
961 {
962 .ctl_name = VM_NR_PDFLUSH_THREADS,
963 .procname = "nr_pdflush_threads",
964 .data = &nr_pdflush_threads,
965 .maxlen = sizeof nr_pdflush_threads,
966 .mode = 0444 /* read-only*/,
967 .proc_handler = &proc_dointvec,
968 },
969 {
970 .ctl_name = VM_SWAPPINESS,
971 .procname = "swappiness",
972 .data = &vm_swappiness,
973 .maxlen = sizeof(vm_swappiness),
974 .mode = 0644,
975 .proc_handler = &proc_dointvec_minmax,
976 .strategy = &sysctl_intvec,
977 .extra1 = &zero,
978 .extra2 = &one_hundred,
979 },
980#ifdef CONFIG_HUGETLB_PAGE
981 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700983 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 .maxlen = sizeof(unsigned long),
985 .mode = 0644,
986 .proc_handler = &hugetlb_sysctl_handler,
987 .extra1 = (void *)&hugetlb_zero,
988 .extra2 = (void *)&hugetlb_infinity,
989 },
990 {
991 .ctl_name = VM_HUGETLB_GROUP,
992 .procname = "hugetlb_shm_group",
993 .data = &sysctl_hugetlb_shm_group,
994 .maxlen = sizeof(gid_t),
995 .mode = 0644,
996 .proc_handler = &proc_dointvec,
997 },
Mel Gorman396faf02007-07-17 04:03:13 -0700998 {
999 .ctl_name = CTL_UNNUMBERED,
1000 .procname = "hugepages_treat_as_movable",
1001 .data = &hugepages_treat_as_movable,
1002 .maxlen = sizeof(int),
1003 .mode = 0644,
1004 .proc_handler = &hugetlb_treat_movable_handler,
1005 },
Adam Litke54f9f802007-10-16 01:26:20 -07001006 {
1007 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001008 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001009 .data = NULL,
1010 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001011 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001012 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001013 .extra1 = (void *)&hugetlb_zero,
1014 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001015 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016#endif
1017 {
1018 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1019 .procname = "lowmem_reserve_ratio",
1020 .data = &sysctl_lowmem_reserve_ratio,
1021 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1022 .mode = 0644,
1023 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1024 .strategy = &sysctl_intvec,
1025 },
1026 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001027 .ctl_name = VM_DROP_PAGECACHE,
1028 .procname = "drop_caches",
1029 .data = &sysctl_drop_caches,
1030 .maxlen = sizeof(int),
1031 .mode = 0644,
1032 .proc_handler = drop_caches_sysctl_handler,
1033 .strategy = &sysctl_intvec,
1034 },
1035 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .ctl_name = VM_MIN_FREE_KBYTES,
1037 .procname = "min_free_kbytes",
1038 .data = &min_free_kbytes,
1039 .maxlen = sizeof(min_free_kbytes),
1040 .mode = 0644,
1041 .proc_handler = &min_free_kbytes_sysctl_handler,
1042 .strategy = &sysctl_intvec,
1043 .extra1 = &zero,
1044 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001045 {
1046 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1047 .procname = "percpu_pagelist_fraction",
1048 .data = &percpu_pagelist_fraction,
1049 .maxlen = sizeof(percpu_pagelist_fraction),
1050 .mode = 0644,
1051 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1052 .strategy = &sysctl_intvec,
1053 .extra1 = &min_percpu_pagelist_fract,
1054 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055#ifdef CONFIG_MMU
1056 {
1057 .ctl_name = VM_MAX_MAP_COUNT,
1058 .procname = "max_map_count",
1059 .data = &sysctl_max_map_count,
1060 .maxlen = sizeof(sysctl_max_map_count),
1061 .mode = 0644,
1062 .proc_handler = &proc_dointvec
1063 },
1064#endif
1065 {
1066 .ctl_name = VM_LAPTOP_MODE,
1067 .procname = "laptop_mode",
1068 .data = &laptop_mode,
1069 .maxlen = sizeof(laptop_mode),
1070 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001071 .proc_handler = &proc_dointvec_jiffies,
1072 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 },
1074 {
1075 .ctl_name = VM_BLOCK_DUMP,
1076 .procname = "block_dump",
1077 .data = &block_dump,
1078 .maxlen = sizeof(block_dump),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec,
1081 .strategy = &sysctl_intvec,
1082 .extra1 = &zero,
1083 },
1084 {
1085 .ctl_name = VM_VFS_CACHE_PRESSURE,
1086 .procname = "vfs_cache_pressure",
1087 .data = &sysctl_vfs_cache_pressure,
1088 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1089 .mode = 0644,
1090 .proc_handler = &proc_dointvec,
1091 .strategy = &sysctl_intvec,
1092 .extra1 = &zero,
1093 },
1094#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1095 {
1096 .ctl_name = VM_LEGACY_VA_LAYOUT,
1097 .procname = "legacy_va_layout",
1098 .data = &sysctl_legacy_va_layout,
1099 .maxlen = sizeof(sysctl_legacy_va_layout),
1100 .mode = 0644,
1101 .proc_handler = &proc_dointvec,
1102 .strategy = &sysctl_intvec,
1103 .extra1 = &zero,
1104 },
1105#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001106#ifdef CONFIG_NUMA
1107 {
1108 .ctl_name = VM_ZONE_RECLAIM_MODE,
1109 .procname = "zone_reclaim_mode",
1110 .data = &zone_reclaim_mode,
1111 .maxlen = sizeof(zone_reclaim_mode),
1112 .mode = 0644,
1113 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001114 .strategy = &sysctl_intvec,
1115 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001116 },
Christoph Lameter96146342006-07-03 00:24:13 -07001117 {
1118 .ctl_name = VM_MIN_UNMAPPED,
1119 .procname = "min_unmapped_ratio",
1120 .data = &sysctl_min_unmapped_ratio,
1121 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1122 .mode = 0644,
1123 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1124 .strategy = &sysctl_intvec,
1125 .extra1 = &zero,
1126 .extra2 = &one_hundred,
1127 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001128 {
1129 .ctl_name = VM_MIN_SLAB,
1130 .procname = "min_slab_ratio",
1131 .data = &sysctl_min_slab_ratio,
1132 .maxlen = sizeof(sysctl_min_slab_ratio),
1133 .mode = 0644,
1134 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1135 .strategy = &sysctl_intvec,
1136 .extra1 = &zero,
1137 .extra2 = &one_hundred,
1138 },
Christoph Lameter17436602006-01-18 17:42:32 -08001139#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001140#ifdef CONFIG_SMP
1141 {
1142 .ctl_name = CTL_UNNUMBERED,
1143 .procname = "stat_interval",
1144 .data = &sysctl_stat_interval,
1145 .maxlen = sizeof(sysctl_stat_interval),
1146 .mode = 0644,
1147 .proc_handler = &proc_dointvec_jiffies,
1148 .strategy = &sysctl_jiffies,
1149 },
1150#endif
Eric Parised032182007-06-28 15:55:21 -04001151#ifdef CONFIG_SECURITY
1152 {
1153 .ctl_name = CTL_UNNUMBERED,
1154 .procname = "mmap_min_addr",
1155 .data = &mmap_min_addr,
1156 .maxlen = sizeof(unsigned long),
1157 .mode = 0644,
1158 .proc_handler = &proc_doulongvec_minmax,
1159 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001160#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001161#ifdef CONFIG_NUMA
1162 {
1163 .ctl_name = CTL_UNNUMBERED,
1164 .procname = "numa_zonelist_order",
1165 .data = &numa_zonelist_order,
1166 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1167 .mode = 0644,
1168 .proc_handler = &numa_zonelist_order_handler,
1169 .strategy = &sysctl_string,
1170 },
1171#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001172#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001173 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001174 {
1175 .ctl_name = VM_VDSO_ENABLED,
1176 .procname = "vdso_enabled",
1177 .data = &vdso_enabled,
1178 .maxlen = sizeof(vdso_enabled),
1179 .mode = 0644,
1180 .proc_handler = &proc_dointvec,
1181 .strategy = &sysctl_intvec,
1182 .extra1 = &zero,
1183 },
1184#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001185#ifdef CONFIG_HIGHMEM
1186 {
1187 .ctl_name = CTL_UNNUMBERED,
1188 .procname = "highmem_is_dirtyable",
1189 .data = &vm_highmem_is_dirtyable,
1190 .maxlen = sizeof(vm_highmem_is_dirtyable),
1191 .mode = 0644,
1192 .proc_handler = &proc_dointvec_minmax,
1193 .strategy = &sysctl_intvec,
1194 .extra1 = &zero,
1195 .extra2 = &one,
1196 },
1197#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001198/*
1199 * NOTE: do not add new entries to this table unless you have read
1200 * Documentation/sysctl/ctl_unnumbered.txt
1201 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 { .ctl_name = 0 }
1203};
1204
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001205#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001206static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001207 { .ctl_name = 0 }
1208};
1209#endif
1210
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001211static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 {
1213 .ctl_name = FS_NRINODE,
1214 .procname = "inode-nr",
1215 .data = &inodes_stat,
1216 .maxlen = 2*sizeof(int),
1217 .mode = 0444,
1218 .proc_handler = &proc_dointvec,
1219 },
1220 {
1221 .ctl_name = FS_STATINODE,
1222 .procname = "inode-state",
1223 .data = &inodes_stat,
1224 .maxlen = 7*sizeof(int),
1225 .mode = 0444,
1226 .proc_handler = &proc_dointvec,
1227 },
1228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 .procname = "file-nr",
1230 .data = &files_stat,
1231 .maxlen = 3*sizeof(int),
1232 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001233 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 },
1235 {
1236 .ctl_name = FS_MAXFILE,
1237 .procname = "file-max",
1238 .data = &files_stat.max_files,
1239 .maxlen = sizeof(int),
1240 .mode = 0644,
1241 .proc_handler = &proc_dointvec,
1242 },
1243 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001244 .ctl_name = CTL_UNNUMBERED,
1245 .procname = "nr_open",
1246 .data = &sysctl_nr_open,
1247 .maxlen = sizeof(int),
1248 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001249 .proc_handler = &proc_dointvec_minmax,
1250 .extra1 = &sysctl_nr_open_min,
1251 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001252 },
1253 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 .ctl_name = FS_DENTRY,
1255 .procname = "dentry-state",
1256 .data = &dentry_stat,
1257 .maxlen = 6*sizeof(int),
1258 .mode = 0444,
1259 .proc_handler = &proc_dointvec,
1260 },
1261 {
1262 .ctl_name = FS_OVERFLOWUID,
1263 .procname = "overflowuid",
1264 .data = &fs_overflowuid,
1265 .maxlen = sizeof(int),
1266 .mode = 0644,
1267 .proc_handler = &proc_dointvec_minmax,
1268 .strategy = &sysctl_intvec,
1269 .extra1 = &minolduid,
1270 .extra2 = &maxolduid,
1271 },
1272 {
1273 .ctl_name = FS_OVERFLOWGID,
1274 .procname = "overflowgid",
1275 .data = &fs_overflowgid,
1276 .maxlen = sizeof(int),
1277 .mode = 0644,
1278 .proc_handler = &proc_dointvec_minmax,
1279 .strategy = &sysctl_intvec,
1280 .extra1 = &minolduid,
1281 .extra2 = &maxolduid,
1282 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001283#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 {
1285 .ctl_name = FS_LEASES,
1286 .procname = "leases-enable",
1287 .data = &leases_enable,
1288 .maxlen = sizeof(int),
1289 .mode = 0644,
1290 .proc_handler = &proc_dointvec,
1291 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001292#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293#ifdef CONFIG_DNOTIFY
1294 {
1295 .ctl_name = FS_DIR_NOTIFY,
1296 .procname = "dir-notify-enable",
1297 .data = &dir_notify_enable,
1298 .maxlen = sizeof(int),
1299 .mode = 0644,
1300 .proc_handler = &proc_dointvec,
1301 },
1302#endif
1303#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001304#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 {
1306 .ctl_name = FS_LEASE_TIME,
1307 .procname = "lease-break-time",
1308 .data = &lease_break_time,
1309 .maxlen = sizeof(int),
1310 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001311 .proc_handler = &proc_dointvec_minmax,
1312 .strategy = &sysctl_intvec,
1313 .extra1 = &zero,
1314 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001316#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001317#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 .procname = "aio-nr",
1320 .data = &aio_nr,
1321 .maxlen = sizeof(aio_nr),
1322 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001323 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 },
1325 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 .procname = "aio-max-nr",
1327 .data = &aio_max_nr,
1328 .maxlen = sizeof(aio_max_nr),
1329 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001330 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001332#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001333#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001334 {
1335 .ctl_name = FS_INOTIFY,
1336 .procname = "inotify",
1337 .mode = 0555,
1338 .child = inotify_table,
1339 },
1340#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001341#ifdef CONFIG_EPOLL
1342 {
1343 .procname = "epoll",
1344 .mode = 0555,
1345 .child = epoll_table,
1346 },
1347#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001349 {
1350 .ctl_name = KERN_SETUID_DUMPABLE,
1351 .procname = "suid_dumpable",
1352 .data = &suid_dumpable,
1353 .maxlen = sizeof(int),
1354 .mode = 0644,
1355 .proc_handler = &proc_dointvec,
1356 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001357#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1358 {
1359 .ctl_name = CTL_UNNUMBERED,
1360 .procname = "binfmt_misc",
1361 .mode = 0555,
1362 .child = binfmt_misc_table,
1363 },
1364#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001365/*
1366 * NOTE: do not add new entries to this table unless you have read
1367 * Documentation/sysctl/ctl_unnumbered.txt
1368 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 { .ctl_name = 0 }
1370};
1371
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001372static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001373#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001374 {
1375 .ctl_name = CTL_UNNUMBERED,
1376 .procname = "exception-trace",
1377 .data = &show_unhandled_signals,
1378 .maxlen = sizeof(int),
1379 .mode = 0644,
1380 .proc_handler = proc_dointvec
1381 },
1382#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 { .ctl_name = 0 }
1384};
1385
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001386static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001388};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Al Viro330d57f2005-11-04 10:18:40 +00001390static DEFINE_SPINLOCK(sysctl_lock);
1391
1392/* called under sysctl_lock */
1393static int use_table(struct ctl_table_header *p)
1394{
1395 if (unlikely(p->unregistering))
1396 return 0;
1397 p->used++;
1398 return 1;
1399}
1400
1401/* called under sysctl_lock */
1402static void unuse_table(struct ctl_table_header *p)
1403{
1404 if (!--p->used)
1405 if (unlikely(p->unregistering))
1406 complete(p->unregistering);
1407}
1408
1409/* called under sysctl_lock, will reacquire if has to wait */
1410static void start_unregistering(struct ctl_table_header *p)
1411{
1412 /*
1413 * if p->used is 0, nobody will ever touch that entry again;
1414 * we'll eliminate all paths to it before dropping sysctl_lock
1415 */
1416 if (unlikely(p->used)) {
1417 struct completion wait;
1418 init_completion(&wait);
1419 p->unregistering = &wait;
1420 spin_unlock(&sysctl_lock);
1421 wait_for_completion(&wait);
1422 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001423 } else {
1424 /* anything non-NULL; we'll never dereference it */
1425 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001426 }
1427 /*
1428 * do not remove from the list until nobody holds it; walking the
1429 * list in do_sysctl() relies on that.
1430 */
1431 list_del_init(&p->ctl_entry);
1432}
1433
Al Virof7e6ced2008-07-15 01:44:23 -04001434void sysctl_head_get(struct ctl_table_header *head)
1435{
1436 spin_lock(&sysctl_lock);
1437 head->count++;
1438 spin_unlock(&sysctl_lock);
1439}
1440
1441void sysctl_head_put(struct ctl_table_header *head)
1442{
1443 spin_lock(&sysctl_lock);
1444 if (!--head->count)
1445 kfree(head);
1446 spin_unlock(&sysctl_lock);
1447}
1448
1449struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1450{
1451 if (!head)
1452 BUG();
1453 spin_lock(&sysctl_lock);
1454 if (!use_table(head))
1455 head = ERR_PTR(-ENOENT);
1456 spin_unlock(&sysctl_lock);
1457 return head;
1458}
1459
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001460void sysctl_head_finish(struct ctl_table_header *head)
1461{
1462 if (!head)
1463 return;
1464 spin_lock(&sysctl_lock);
1465 unuse_table(head);
1466 spin_unlock(&sysctl_lock);
1467}
1468
Al Viro73455092008-07-14 21:22:20 -04001469static struct ctl_table_set *
1470lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1471{
1472 struct ctl_table_set *set = &root->default_set;
1473 if (root->lookup)
1474 set = root->lookup(root, namespaces);
1475 return set;
1476}
1477
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001478static struct list_head *
1479lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001480{
Al Viro73455092008-07-14 21:22:20 -04001481 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1482 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001483}
1484
1485struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1486 struct ctl_table_header *prev)
1487{
1488 struct ctl_table_root *root;
1489 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001490 struct ctl_table_header *head;
1491 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001492
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001493 spin_lock(&sysctl_lock);
1494 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001495 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001496 tmp = &prev->ctl_entry;
1497 unuse_table(prev);
1498 goto next;
1499 }
1500 tmp = &root_table_header.ctl_entry;
1501 for (;;) {
1502 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1503
1504 if (!use_table(head))
1505 goto next;
1506 spin_unlock(&sysctl_lock);
1507 return head;
1508 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001509 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001510 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001511 header_list = lookup_header_list(root, namespaces);
1512 if (tmp != header_list)
1513 continue;
1514
1515 do {
1516 root = list_entry(root->root_list.next,
1517 struct ctl_table_root, root_list);
1518 if (root == &sysctl_table_root)
1519 goto out;
1520 header_list = lookup_header_list(root, namespaces);
1521 } while (list_empty(header_list));
1522 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001523 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001524out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001525 spin_unlock(&sysctl_lock);
1526 return NULL;
1527}
1528
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001529struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1530{
1531 return __sysctl_head_next(current->nsproxy, prev);
1532}
1533
1534void register_sysctl_root(struct ctl_table_root *root)
1535{
1536 spin_lock(&sysctl_lock);
1537 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1538 spin_unlock(&sysctl_lock);
1539}
1540
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001541#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001542/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001543static int do_sysctl_strategy(struct ctl_table_root *root,
1544 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001545 void __user *oldval, size_t __user *oldlenp,
1546 void __user *newval, size_t newlen)
1547{
1548 int op = 0, rc;
1549
1550 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001551 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001552 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001553 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001554 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001555 return -EPERM;
1556
1557 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001558 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001559 if (rc < 0)
1560 return rc;
1561 if (rc > 0)
1562 return 0;
1563 }
1564
1565 /* If there is no strategy routine, or if the strategy returns
1566 * zero, proceed with automatic r/w */
1567 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001568 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001569 if (rc < 0)
1570 return rc;
1571 }
1572 return 0;
1573}
1574
1575static int parse_table(int __user *name, int nlen,
1576 void __user *oldval, size_t __user *oldlenp,
1577 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001578 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001579 struct ctl_table *table)
1580{
1581 int n;
1582repeat:
1583 if (!nlen)
1584 return -ENOTDIR;
1585 if (get_user(n, name))
1586 return -EFAULT;
1587 for ( ; table->ctl_name || table->procname; table++) {
1588 if (!table->ctl_name)
1589 continue;
1590 if (n == table->ctl_name) {
1591 int error;
1592 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001593 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001594 return -EPERM;
1595 name++;
1596 nlen--;
1597 table = table->child;
1598 goto repeat;
1599 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001600 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001601 oldval, oldlenp,
1602 newval, newlen);
1603 return error;
1604 }
1605 }
1606 return -ENOTDIR;
1607}
1608
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1610 void __user *newval, size_t newlen)
1611{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001612 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001613 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
1615 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1616 return -ENOTDIR;
1617 if (oldval) {
1618 int old_len;
1619 if (!oldlenp || get_user(old_len, oldlenp))
1620 return -EFAULT;
1621 }
Al Viro330d57f2005-11-04 10:18:40 +00001622
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001623 for (head = sysctl_head_next(NULL); head;
1624 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001625 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001626 newval, newlen,
1627 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001628 if (error != -ENOTDIR) {
1629 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001630 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001631 }
1632 }
Al Viro330d57f2005-11-04 10:18:40 +00001633 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634}
1635
1636asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1637{
1638 struct __sysctl_args tmp;
1639 int error;
1640
1641 if (copy_from_user(&tmp, args, sizeof(tmp)))
1642 return -EFAULT;
1643
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001644 error = deprecated_sysctl_warning(&tmp);
1645 if (error)
1646 goto out;
1647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 lock_kernel();
1649 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1650 tmp.newval, tmp.newlen);
1651 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001652out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 return error;
1654}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001655#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001658 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 * some sysctl variables are readonly even to root.
1660 */
1661
1662static int test_perm(int mode, int op)
1663{
1664 if (!current->euid)
1665 mode >>= 6;
1666 else if (in_egroup_p(0))
1667 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001668 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 return 0;
1670 return -EACCES;
1671}
1672
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001673int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674{
1675 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001676 int mode;
1677
Al Viroe6305c42008-07-15 21:03:57 -04001678 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 if (error)
1680 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001681
1682 if (root->permissions)
1683 mode = root->permissions(root, current->nsproxy, table);
1684 else
1685 mode = table->mode;
1686
1687 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001690static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1691{
1692 for (; table->ctl_name || table->procname; table++) {
1693 table->parent = parent;
1694 if (table->child)
1695 sysctl_set_parent(table, table->child);
1696 }
1697}
1698
1699static __init int sysctl_init(void)
1700{
1701 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001702#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1703 {
1704 int err;
1705 err = sysctl_check_table(current->nsproxy, root_table);
1706 }
1707#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001708 return 0;
1709}
1710
1711core_initcall(sysctl_init);
1712
Al Virobfbcf032008-07-27 06:31:22 +01001713static struct ctl_table *is_branch_in(struct ctl_table *branch,
1714 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001715{
1716 struct ctl_table *p;
1717 const char *s = branch->procname;
1718
1719 /* branch should have named subdirectory as its first element */
1720 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001721 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001722
1723 /* ... and nothing else */
1724 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001725 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001726
1727 /* table should contain subdirectory with the same name */
1728 for (p = table; p->procname || p->ctl_name; p++) {
1729 if (!p->child)
1730 continue;
1731 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001732 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001733 }
Al Virobfbcf032008-07-27 06:31:22 +01001734 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001735}
1736
1737/* see if attaching q to p would be an improvement */
1738static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1739{
1740 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001741 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001742 int is_better = 0;
1743 int not_in_parent = !p->attached_by;
1744
Al Virobfbcf032008-07-27 06:31:22 +01001745 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001746 if (by == q->attached_by)
1747 is_better = 1;
1748 if (to == p->attached_by)
1749 not_in_parent = 1;
1750 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001751 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001752 }
1753
1754 if (is_better && not_in_parent) {
1755 q->attached_by = by;
1756 q->attached_to = to;
1757 q->parent = p;
1758 }
1759}
1760
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001762 * __register_sysctl_paths - register a sysctl hierarchy
1763 * @root: List of sysctl headers to register on
1764 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001765 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 *
1768 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001769 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001771 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772 *
1773 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1774 * must be unique within that level of sysctl
1775 *
1776 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1777 * enter a sysctl file
1778 *
1779 * data - a pointer to data for use by proc_handler
1780 *
1781 * maxlen - the maximum size in bytes of the data
1782 *
1783 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1784 *
1785 * child - a pointer to the child sysctl table if this entry is a directory, or
1786 * %NULL.
1787 *
1788 * proc_handler - the text handler routine (described below)
1789 *
1790 * strategy - the strategy routine (described below)
1791 *
1792 * de - for internal use by the sysctl routines
1793 *
1794 * extra1, extra2 - extra pointers usable by the proc handler routines
1795 *
1796 * Leaf nodes in the sysctl tree will be represented by a single file
1797 * under /proc; non-leaf nodes will be represented by directories.
1798 *
1799 * sysctl(2) can automatically manage read and write requests through
1800 * the sysctl table. The data and maxlen fields of the ctl_table
1801 * struct enable minimal validation of the values being written to be
1802 * performed, and the mode field allows minimal authentication.
1803 *
1804 * More sophisticated management can be enabled by the provision of a
1805 * strategy routine with the table entry. This will be called before
1806 * any automatic read or write of the data is performed.
1807 *
1808 * The strategy routine may return
1809 *
1810 * < 0 - Error occurred (error is passed to user process)
1811 *
1812 * 0 - OK - proceed with automatic read or write.
1813 *
1814 * > 0 - OK - read or write has been done by the strategy routine, so
1815 * return immediately.
1816 *
1817 * There must be a proc_handler routine for any terminal nodes
1818 * mirrored under /proc/sys (non-terminals are handled by a built-in
1819 * directory handler). Several default handlers are available to
1820 * cover common cases -
1821 *
1822 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1823 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1824 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1825 *
1826 * It is the handler's job to read the input buffer from user memory
1827 * and process it. The handler should return 0 on success.
1828 *
1829 * This routine returns %NULL on a failure to register, and a pointer
1830 * to the table header on success.
1831 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001832struct ctl_table_header *__register_sysctl_paths(
1833 struct ctl_table_root *root,
1834 struct nsproxy *namespaces,
1835 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001837 struct ctl_table_header *header;
1838 struct ctl_table *new, **prevp;
1839 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001840 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001841
1842 /* Count the path components */
1843 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1844 ;
1845
1846 /*
1847 * For each path component, allocate a 2-element ctl_table array.
1848 * The first array element will be filled with the sysctl entry
1849 * for this, the second will be the sentinel (ctl_name == 0).
1850 *
1851 * We allocate everything in one go so that we don't have to
1852 * worry about freeing additional memory in unregister_sysctl_table.
1853 */
1854 header = kzalloc(sizeof(struct ctl_table_header) +
1855 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1856 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001858
1859 new = (struct ctl_table *) (header + 1);
1860
1861 /* Now connect the dots */
1862 prevp = &header->ctl_table;
1863 for (n = 0; n < npath; ++n, ++path) {
1864 /* Copy the procname */
1865 new->procname = path->procname;
1866 new->ctl_name = path->ctl_name;
1867 new->mode = 0555;
1868
1869 *prevp = new;
1870 prevp = &new->child;
1871
1872 new += 2;
1873 }
1874 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001875 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001876
1877 INIT_LIST_HEAD(&header->ctl_entry);
1878 header->used = 0;
1879 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001880 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001881 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001882 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001883#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001884 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001885 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001886 return NULL;
1887 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001888#endif
Al Viro330d57f2005-11-04 10:18:40 +00001889 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001890 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001891 header->attached_by = header->ctl_table;
1892 header->attached_to = root_table;
1893 header->parent = &root_table_header;
1894 for (set = header->set; set; set = set->parent) {
1895 struct ctl_table_header *p;
1896 list_for_each_entry(p, &set->list, ctl_entry) {
1897 if (p->unregistering)
1898 continue;
1899 try_attach(p, header);
1900 }
1901 }
1902 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001903 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001904 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001905
1906 return header;
1907}
1908
1909/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001910 * register_sysctl_table_path - register a sysctl table hierarchy
1911 * @path: The path to the directory the sysctl table is in.
1912 * @table: the top-level table structure
1913 *
1914 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1915 * array. A completely 0 filled entry terminates the table.
1916 *
1917 * See __register_sysctl_paths for more details.
1918 */
1919struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1920 struct ctl_table *table)
1921{
1922 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1923 path, table);
1924}
1925
1926/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001927 * register_sysctl_table - register a sysctl table hierarchy
1928 * @table: the top-level table structure
1929 *
1930 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1931 * array. A completely 0 filled entry terminates the table.
1932 *
1933 * See register_sysctl_paths for more details.
1934 */
1935struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1936{
1937 static const struct ctl_path null_path[] = { {} };
1938
1939 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940}
1941
1942/**
1943 * unregister_sysctl_table - unregister a sysctl table hierarchy
1944 * @header: the header returned from register_sysctl_table
1945 *
1946 * Unregisters the sysctl table and all children. proc entries may not
1947 * actually be removed until they are no longer used by anyone.
1948 */
1949void unregister_sysctl_table(struct ctl_table_header * header)
1950{
Al Viro330d57f2005-11-04 10:18:40 +00001951 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001952
1953 if (header == NULL)
1954 return;
1955
Al Viro330d57f2005-11-04 10:18:40 +00001956 spin_lock(&sysctl_lock);
1957 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001958 if (!--header->parent->count) {
1959 WARN_ON(1);
1960 kfree(header->parent);
1961 }
Al Virof7e6ced2008-07-15 01:44:23 -04001962 if (!--header->count)
1963 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001964 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965}
1966
Al Viro90434762008-07-15 08:54:06 -04001967int sysctl_is_seen(struct ctl_table_header *p)
1968{
1969 struct ctl_table_set *set = p->set;
1970 int res;
1971 spin_lock(&sysctl_lock);
1972 if (p->unregistering)
1973 res = 0;
1974 else if (!set->is_seen)
1975 res = 1;
1976 else
1977 res = set->is_seen(set);
1978 spin_unlock(&sysctl_lock);
1979 return res;
1980}
1981
Al Viro73455092008-07-14 21:22:20 -04001982void setup_sysctl_set(struct ctl_table_set *p,
1983 struct ctl_table_set *parent,
1984 int (*is_seen)(struct ctl_table_set *))
1985{
1986 INIT_LIST_HEAD(&p->list);
1987 p->parent = parent ? parent : &sysctl_table_root.default_set;
1988 p->is_seen = is_seen;
1989}
1990
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001991#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001992struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001993{
1994 return NULL;
1995}
1996
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001997struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1998 struct ctl_table *table)
1999{
2000 return NULL;
2001}
2002
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002003void unregister_sysctl_table(struct ctl_table_header * table)
2004{
2005}
2006
Al Viro73455092008-07-14 21:22:20 -04002007void setup_sysctl_set(struct ctl_table_set *p,
2008 struct ctl_table_set *parent,
2009 int (*is_seen)(struct ctl_table_set *))
2010{
2011}
2012
Al Virof7e6ced2008-07-15 01:44:23 -04002013void sysctl_head_put(struct ctl_table_header *head)
2014{
2015}
2016
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002017#endif /* CONFIG_SYSCTL */
2018
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019/*
2020 * /proc/sys support
2021 */
2022
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002023#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002025static int _proc_do_string(void* data, int maxlen, int write,
2026 struct file *filp, void __user *buffer,
2027 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002028{
2029 size_t len;
2030 char __user *p;
2031 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002032
2033 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002034 *lenp = 0;
2035 return 0;
2036 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002037
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002038 if (write) {
2039 len = 0;
2040 p = buffer;
2041 while (len < *lenp) {
2042 if (get_user(c, p++))
2043 return -EFAULT;
2044 if (c == 0 || c == '\n')
2045 break;
2046 len++;
2047 }
2048 if (len >= maxlen)
2049 len = maxlen-1;
2050 if(copy_from_user(data, buffer, len))
2051 return -EFAULT;
2052 ((char *) data)[len] = 0;
2053 *ppos += *lenp;
2054 } else {
2055 len = strlen(data);
2056 if (len > maxlen)
2057 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002058
2059 if (*ppos > len) {
2060 *lenp = 0;
2061 return 0;
2062 }
2063
2064 data += *ppos;
2065 len -= *ppos;
2066
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002067 if (len > *lenp)
2068 len = *lenp;
2069 if (len)
2070 if(copy_to_user(buffer, data, len))
2071 return -EFAULT;
2072 if (len < *lenp) {
2073 if(put_user('\n', ((char __user *) buffer) + len))
2074 return -EFAULT;
2075 len++;
2076 }
2077 *lenp = len;
2078 *ppos += len;
2079 }
2080 return 0;
2081}
2082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083/**
2084 * proc_dostring - read a string sysctl
2085 * @table: the sysctl table
2086 * @write: %TRUE if this is a write to the sysctl file
2087 * @filp: the file structure
2088 * @buffer: the user buffer
2089 * @lenp: the size of the user buffer
2090 * @ppos: file position
2091 *
2092 * Reads/writes a string from/to the user buffer. If the kernel
2093 * buffer provided is not large enough to hold the string, the
2094 * string is truncated. The copied string is %NULL-terminated.
2095 * If the string is being read by the user process, it is copied
2096 * and a newline '\n' is added. It is truncated if the buffer is
2097 * not large enough.
2098 *
2099 * Returns 0 on success.
2100 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002101int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 void __user *buffer, size_t *lenp, loff_t *ppos)
2103{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002104 return _proc_do_string(table->data, table->maxlen, write, filp,
2105 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2110 int *valp,
2111 int write, void *data)
2112{
2113 if (write) {
2114 *valp = *negp ? -*lvalp : *lvalp;
2115 } else {
2116 int val = *valp;
2117 if (val < 0) {
2118 *negp = -1;
2119 *lvalp = (unsigned long)-val;
2120 } else {
2121 *negp = 0;
2122 *lvalp = (unsigned long)val;
2123 }
2124 }
2125 return 0;
2126}
2127
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002128static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002129 int write, struct file *filp, void __user *buffer,
2130 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2132 int write, void *data),
2133 void *data)
2134{
2135#define TMPBUFLEN 21
2136 int *i, vleft, first=1, neg, val;
2137 unsigned long lval;
2138 size_t left, len;
2139
2140 char buf[TMPBUFLEN], *p;
2141 char __user *s = buffer;
2142
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002143 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 (*ppos && !write)) {
2145 *lenp = 0;
2146 return 0;
2147 }
2148
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002149 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 vleft = table->maxlen / sizeof(*i);
2151 left = *lenp;
2152
2153 if (!conv)
2154 conv = do_proc_dointvec_conv;
2155
2156 for (; left && vleft--; i++, first=0) {
2157 if (write) {
2158 while (left) {
2159 char c;
2160 if (get_user(c, s))
2161 return -EFAULT;
2162 if (!isspace(c))
2163 break;
2164 left--;
2165 s++;
2166 }
2167 if (!left)
2168 break;
2169 neg = 0;
2170 len = left;
2171 if (len > sizeof(buf) - 1)
2172 len = sizeof(buf) - 1;
2173 if (copy_from_user(buf, s, len))
2174 return -EFAULT;
2175 buf[len] = 0;
2176 p = buf;
2177 if (*p == '-' && left > 1) {
2178 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002179 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 }
2181 if (*p < '0' || *p > '9')
2182 break;
2183
2184 lval = simple_strtoul(p, &p, 0);
2185
2186 len = p-buf;
2187 if ((len < left) && *p && !isspace(*p))
2188 break;
2189 if (neg)
2190 val = -val;
2191 s += len;
2192 left -= len;
2193
2194 if (conv(&neg, &lval, i, 1, data))
2195 break;
2196 } else {
2197 p = buf;
2198 if (!first)
2199 *p++ = '\t';
2200
2201 if (conv(&neg, &lval, i, 0, data))
2202 break;
2203
2204 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2205 len = strlen(buf);
2206 if (len > left)
2207 len = left;
2208 if(copy_to_user(s, buf, len))
2209 return -EFAULT;
2210 left -= len;
2211 s += len;
2212 }
2213 }
2214
2215 if (!write && !first && left) {
2216 if(put_user('\n', s))
2217 return -EFAULT;
2218 left--, s++;
2219 }
2220 if (write) {
2221 while (left) {
2222 char c;
2223 if (get_user(c, s++))
2224 return -EFAULT;
2225 if (!isspace(c))
2226 break;
2227 left--;
2228 }
2229 }
2230 if (write && first)
2231 return -EINVAL;
2232 *lenp -= left;
2233 *ppos += *lenp;
2234 return 0;
2235#undef TMPBUFLEN
2236}
2237
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002238static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002239 void __user *buffer, size_t *lenp, loff_t *ppos,
2240 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2241 int write, void *data),
2242 void *data)
2243{
2244 return __do_proc_dointvec(table->data, table, write, filp,
2245 buffer, lenp, ppos, conv, data);
2246}
2247
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248/**
2249 * proc_dointvec - read a vector of integers
2250 * @table: the sysctl table
2251 * @write: %TRUE if this is a write to the sysctl file
2252 * @filp: the file structure
2253 * @buffer: the user buffer
2254 * @lenp: the size of the user buffer
2255 * @ppos: file position
2256 *
2257 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2258 * values from/to the user buffer, treated as an ASCII string.
2259 *
2260 * Returns 0 on success.
2261 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002262int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 void __user *buffer, size_t *lenp, loff_t *ppos)
2264{
2265 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2266 NULL,NULL);
2267}
2268
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002269/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002270 * Taint values can only be increased
2271 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002272 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002273static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002274 void __user *buffer, size_t *lenp, loff_t *ppos)
2275{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002276 struct ctl_table t;
2277 unsigned long tmptaint = get_taint();
2278 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002279
Bastian Blank91fcd412007-04-23 14:41:14 -07002280 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002281 return -EPERM;
2282
Andi Kleen25ddbb12008-10-15 22:01:41 -07002283 t = *table;
2284 t.data = &tmptaint;
2285 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2286 if (err < 0)
2287 return err;
2288
2289 if (write) {
2290 /*
2291 * Poor man's atomic or. Not worth adding a primitive
2292 * to everyone's atomic.h for this
2293 */
2294 int i;
2295 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2296 if ((tmptaint >> i) & 1)
2297 add_taint(i);
2298 }
2299 }
2300
2301 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002302}
2303
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304struct do_proc_dointvec_minmax_conv_param {
2305 int *min;
2306 int *max;
2307};
2308
2309static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2310 int *valp,
2311 int write, void *data)
2312{
2313 struct do_proc_dointvec_minmax_conv_param *param = data;
2314 if (write) {
2315 int val = *negp ? -*lvalp : *lvalp;
2316 if ((param->min && *param->min > val) ||
2317 (param->max && *param->max < val))
2318 return -EINVAL;
2319 *valp = val;
2320 } else {
2321 int val = *valp;
2322 if (val < 0) {
2323 *negp = -1;
2324 *lvalp = (unsigned long)-val;
2325 } else {
2326 *negp = 0;
2327 *lvalp = (unsigned long)val;
2328 }
2329 }
2330 return 0;
2331}
2332
2333/**
2334 * proc_dointvec_minmax - read a vector of integers with min/max values
2335 * @table: the sysctl table
2336 * @write: %TRUE if this is a write to the sysctl file
2337 * @filp: the file structure
2338 * @buffer: the user buffer
2339 * @lenp: the size of the user buffer
2340 * @ppos: file position
2341 *
2342 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2343 * values from/to the user buffer, treated as an ASCII string.
2344 *
2345 * This routine will ensure the values are within the range specified by
2346 * table->extra1 (min) and table->extra2 (max).
2347 *
2348 * Returns 0 on success.
2349 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002350int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 void __user *buffer, size_t *lenp, loff_t *ppos)
2352{
2353 struct do_proc_dointvec_minmax_conv_param param = {
2354 .min = (int *) table->extra1,
2355 .max = (int *) table->extra2,
2356 };
2357 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2358 do_proc_dointvec_minmax_conv, &param);
2359}
2360
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002361static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 struct file *filp,
2363 void __user *buffer,
2364 size_t *lenp, loff_t *ppos,
2365 unsigned long convmul,
2366 unsigned long convdiv)
2367{
2368#define TMPBUFLEN 21
2369 unsigned long *i, *min, *max, val;
2370 int vleft, first=1, neg;
2371 size_t len, left;
2372 char buf[TMPBUFLEN], *p;
2373 char __user *s = buffer;
2374
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002375 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 (*ppos && !write)) {
2377 *lenp = 0;
2378 return 0;
2379 }
2380
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002381 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 min = (unsigned long *) table->extra1;
2383 max = (unsigned long *) table->extra2;
2384 vleft = table->maxlen / sizeof(unsigned long);
2385 left = *lenp;
2386
2387 for (; left && vleft--; i++, min++, max++, first=0) {
2388 if (write) {
2389 while (left) {
2390 char c;
2391 if (get_user(c, s))
2392 return -EFAULT;
2393 if (!isspace(c))
2394 break;
2395 left--;
2396 s++;
2397 }
2398 if (!left)
2399 break;
2400 neg = 0;
2401 len = left;
2402 if (len > TMPBUFLEN-1)
2403 len = TMPBUFLEN-1;
2404 if (copy_from_user(buf, s, len))
2405 return -EFAULT;
2406 buf[len] = 0;
2407 p = buf;
2408 if (*p == '-' && left > 1) {
2409 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002410 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 }
2412 if (*p < '0' || *p > '9')
2413 break;
2414 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2415 len = p-buf;
2416 if ((len < left) && *p && !isspace(*p))
2417 break;
2418 if (neg)
2419 val = -val;
2420 s += len;
2421 left -= len;
2422
2423 if(neg)
2424 continue;
2425 if ((min && val < *min) || (max && val > *max))
2426 continue;
2427 *i = val;
2428 } else {
2429 p = buf;
2430 if (!first)
2431 *p++ = '\t';
2432 sprintf(p, "%lu", convdiv * (*i) / convmul);
2433 len = strlen(buf);
2434 if (len > left)
2435 len = left;
2436 if(copy_to_user(s, buf, len))
2437 return -EFAULT;
2438 left -= len;
2439 s += len;
2440 }
2441 }
2442
2443 if (!write && !first && left) {
2444 if(put_user('\n', s))
2445 return -EFAULT;
2446 left--, s++;
2447 }
2448 if (write) {
2449 while (left) {
2450 char c;
2451 if (get_user(c, s++))
2452 return -EFAULT;
2453 if (!isspace(c))
2454 break;
2455 left--;
2456 }
2457 }
2458 if (write && first)
2459 return -EINVAL;
2460 *lenp -= left;
2461 *ppos += *lenp;
2462 return 0;
2463#undef TMPBUFLEN
2464}
2465
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002466static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002467 struct file *filp,
2468 void __user *buffer,
2469 size_t *lenp, loff_t *ppos,
2470 unsigned long convmul,
2471 unsigned long convdiv)
2472{
2473 return __do_proc_doulongvec_minmax(table->data, table, write,
2474 filp, buffer, lenp, ppos, convmul, convdiv);
2475}
2476
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477/**
2478 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2479 * @table: the sysctl table
2480 * @write: %TRUE if this is a write to the sysctl file
2481 * @filp: the file structure
2482 * @buffer: the user buffer
2483 * @lenp: the size of the user buffer
2484 * @ppos: file position
2485 *
2486 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2487 * values from/to the user buffer, treated as an ASCII string.
2488 *
2489 * This routine will ensure the values are within the range specified by
2490 * table->extra1 (min) and table->extra2 (max).
2491 *
2492 * Returns 0 on success.
2493 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002494int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 void __user *buffer, size_t *lenp, loff_t *ppos)
2496{
2497 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2498}
2499
2500/**
2501 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2502 * @table: the sysctl table
2503 * @write: %TRUE if this is a write to the sysctl file
2504 * @filp: the file structure
2505 * @buffer: the user buffer
2506 * @lenp: the size of the user buffer
2507 * @ppos: file position
2508 *
2509 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2510 * values from/to the user buffer, treated as an ASCII string. The values
2511 * are treated as milliseconds, and converted to jiffies when they are stored.
2512 *
2513 * This routine will ensure the values are within the range specified by
2514 * table->extra1 (min) and table->extra2 (max).
2515 *
2516 * Returns 0 on success.
2517 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002518int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 struct file *filp,
2520 void __user *buffer,
2521 size_t *lenp, loff_t *ppos)
2522{
2523 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2524 lenp, ppos, HZ, 1000l);
2525}
2526
2527
2528static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2529 int *valp,
2530 int write, void *data)
2531{
2532 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002533 if (*lvalp > LONG_MAX / HZ)
2534 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2536 } else {
2537 int val = *valp;
2538 unsigned long lval;
2539 if (val < 0) {
2540 *negp = -1;
2541 lval = (unsigned long)-val;
2542 } else {
2543 *negp = 0;
2544 lval = (unsigned long)val;
2545 }
2546 *lvalp = lval / HZ;
2547 }
2548 return 0;
2549}
2550
2551static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2552 int *valp,
2553 int write, void *data)
2554{
2555 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002556 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2557 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2559 } else {
2560 int val = *valp;
2561 unsigned long lval;
2562 if (val < 0) {
2563 *negp = -1;
2564 lval = (unsigned long)-val;
2565 } else {
2566 *negp = 0;
2567 lval = (unsigned long)val;
2568 }
2569 *lvalp = jiffies_to_clock_t(lval);
2570 }
2571 return 0;
2572}
2573
2574static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2575 int *valp,
2576 int write, void *data)
2577{
2578 if (write) {
2579 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2580 } else {
2581 int val = *valp;
2582 unsigned long lval;
2583 if (val < 0) {
2584 *negp = -1;
2585 lval = (unsigned long)-val;
2586 } else {
2587 *negp = 0;
2588 lval = (unsigned long)val;
2589 }
2590 *lvalp = jiffies_to_msecs(lval);
2591 }
2592 return 0;
2593}
2594
2595/**
2596 * proc_dointvec_jiffies - read a vector of integers as seconds
2597 * @table: the sysctl table
2598 * @write: %TRUE if this is a write to the sysctl file
2599 * @filp: the file structure
2600 * @buffer: the user buffer
2601 * @lenp: the size of the user buffer
2602 * @ppos: file position
2603 *
2604 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2605 * values from/to the user buffer, treated as an ASCII string.
2606 * The values read are assumed to be in seconds, and are converted into
2607 * jiffies.
2608 *
2609 * Returns 0 on success.
2610 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002611int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 void __user *buffer, size_t *lenp, loff_t *ppos)
2613{
2614 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2615 do_proc_dointvec_jiffies_conv,NULL);
2616}
2617
2618/**
2619 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2620 * @table: the sysctl table
2621 * @write: %TRUE if this is a write to the sysctl file
2622 * @filp: the file structure
2623 * @buffer: the user buffer
2624 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002625 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 *
2627 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2628 * values from/to the user buffer, treated as an ASCII string.
2629 * The values read are assumed to be in 1/USER_HZ seconds, and
2630 * are converted into jiffies.
2631 *
2632 * Returns 0 on success.
2633 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002634int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 void __user *buffer, size_t *lenp, loff_t *ppos)
2636{
2637 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2638 do_proc_dointvec_userhz_jiffies_conv,NULL);
2639}
2640
2641/**
2642 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2643 * @table: the sysctl table
2644 * @write: %TRUE if this is a write to the sysctl file
2645 * @filp: the file structure
2646 * @buffer: the user buffer
2647 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002648 * @ppos: file position
2649 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 *
2651 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2652 * values from/to the user buffer, treated as an ASCII string.
2653 * The values read are assumed to be in 1/1000 seconds, and
2654 * are converted into jiffies.
2655 *
2656 * Returns 0 on success.
2657 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002658int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 void __user *buffer, size_t *lenp, loff_t *ppos)
2660{
2661 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2662 do_proc_dointvec_ms_jiffies_conv, NULL);
2663}
2664
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002665static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002666 void __user *buffer, size_t *lenp, loff_t *ppos)
2667{
2668 struct pid *new_pid;
2669 pid_t tmp;
2670 int r;
2671
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002672 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002673
2674 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2675 lenp, ppos, NULL, NULL);
2676 if (r || !write)
2677 return r;
2678
2679 new_pid = find_get_pid(tmp);
2680 if (!new_pid)
2681 return -ESRCH;
2682
2683 put_pid(xchg(&cad_pid, new_pid));
2684 return 0;
2685}
2686
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687#else /* CONFIG_PROC_FS */
2688
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002689int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 void __user *buffer, size_t *lenp, loff_t *ppos)
2691{
2692 return -ENOSYS;
2693}
2694
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002695int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 void __user *buffer, size_t *lenp, loff_t *ppos)
2697{
2698 return -ENOSYS;
2699}
2700
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002701int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 void __user *buffer, size_t *lenp, loff_t *ppos)
2703{
2704 return -ENOSYS;
2705}
2706
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002707int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 void __user *buffer, size_t *lenp, loff_t *ppos)
2709{
2710 return -ENOSYS;
2711}
2712
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002713int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 void __user *buffer, size_t *lenp, loff_t *ppos)
2715{
2716 return -ENOSYS;
2717}
2718
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002719int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 void __user *buffer, size_t *lenp, loff_t *ppos)
2721{
2722 return -ENOSYS;
2723}
2724
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002725int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 void __user *buffer, size_t *lenp, loff_t *ppos)
2727{
2728 return -ENOSYS;
2729}
2730
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002731int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 struct file *filp,
2733 void __user *buffer,
2734 size_t *lenp, loff_t *ppos)
2735{
2736 return -ENOSYS;
2737}
2738
2739
2740#endif /* CONFIG_PROC_FS */
2741
2742
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002743#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744/*
2745 * General sysctl support routines
2746 */
2747
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002748/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002749int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002750 void __user *oldval, size_t __user *oldlenp,
2751 void __user *newval, size_t newlen)
2752{
2753 size_t len;
2754
2755 /* Get out of I don't have a variable */
2756 if (!table->data || !table->maxlen)
2757 return -ENOTDIR;
2758
2759 if (oldval && oldlenp) {
2760 if (get_user(len, oldlenp))
2761 return -EFAULT;
2762 if (len) {
2763 if (len > table->maxlen)
2764 len = table->maxlen;
2765 if (copy_to_user(oldval, table->data, len))
2766 return -EFAULT;
2767 if (put_user(len, oldlenp))
2768 return -EFAULT;
2769 }
2770 }
2771
2772 if (newval && newlen) {
2773 if (newlen > table->maxlen)
2774 newlen = table->maxlen;
2775
2776 if (copy_from_user(table->data, newval, newlen))
2777 return -EFAULT;
2778 }
2779 return 1;
2780}
2781
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002783int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002785 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 if (!table->data || !table->maxlen)
2788 return -ENOTDIR;
2789
2790 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002791 size_t bufsize;
2792 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002794 if (bufsize) {
2795 size_t len = strlen(table->data), copied;
2796
2797 /* This shouldn't trigger for a well-formed sysctl */
2798 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002800
2801 /* Copy up to a max of bufsize-1 bytes of the string */
2802 copied = (len >= bufsize) ? bufsize - 1 : len;
2803
2804 if (copy_to_user(oldval, table->data, copied) ||
2805 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002807 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 return -EFAULT;
2809 }
2810 }
2811 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002812 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 if (len > table->maxlen)
2814 len = table->maxlen;
2815 if(copy_from_user(table->data, newval, len))
2816 return -EFAULT;
2817 if (len == table->maxlen)
2818 len--;
2819 ((char *) table->data)[len] = 0;
2820 }
Yi Yang82c9df82005-12-30 16:37:10 +08002821 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822}
2823
2824/*
2825 * This function makes sure that all of the integers in the vector
2826 * are between the minimum and maximum values given in the arrays
2827 * table->extra1 and table->extra2, respectively.
2828 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002829int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002831 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832{
2833
2834 if (newval && newlen) {
2835 int __user *vec = (int __user *) newval;
2836 int *min = (int *) table->extra1;
2837 int *max = (int *) table->extra2;
2838 size_t length;
2839 int i;
2840
2841 if (newlen % sizeof(int) != 0)
2842 return -EINVAL;
2843
2844 if (!table->extra1 && !table->extra2)
2845 return 0;
2846
2847 if (newlen > table->maxlen)
2848 newlen = table->maxlen;
2849 length = newlen / sizeof(int);
2850
2851 for (i = 0; i < length; i++) {
2852 int value;
2853 if (get_user(value, vec + i))
2854 return -EFAULT;
2855 if (min && value < min[i])
2856 return -EINVAL;
2857 if (max && value > max[i])
2858 return -EINVAL;
2859 }
2860 }
2861 return 0;
2862}
2863
2864/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002865int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002867 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002869 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002871
2872 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002874 if (olen) {
2875 int val;
2876
2877 if (olen < sizeof(int))
2878 return -EINVAL;
2879
2880 val = *(int *)(table->data) / HZ;
2881 if (put_user(val, (int __user *)oldval))
2882 return -EFAULT;
2883 if (put_user(sizeof(int), oldlenp))
2884 return -EFAULT;
2885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 }
2887 if (newval && newlen) {
2888 int new;
2889 if (newlen != sizeof(int))
2890 return -EINVAL;
2891 if (get_user(new, (int __user *)newval))
2892 return -EFAULT;
2893 *(int *)(table->data) = new*HZ;
2894 }
2895 return 1;
2896}
2897
2898/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002899int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002901 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002903 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002905
2906 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002908 if (olen) {
2909 int val;
2910
2911 if (olen < sizeof(int))
2912 return -EINVAL;
2913
2914 val = jiffies_to_msecs(*(int *)(table->data));
2915 if (put_user(val, (int __user *)oldval))
2916 return -EFAULT;
2917 if (put_user(sizeof(int), oldlenp))
2918 return -EFAULT;
2919 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 }
2921 if (newval && newlen) {
2922 int new;
2923 if (newlen != sizeof(int))
2924 return -EINVAL;
2925 if (get_user(new, (int __user *)newval))
2926 return -EFAULT;
2927 *(int *)(table->data) = msecs_to_jiffies(new);
2928 }
2929 return 1;
2930}
2931
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002932
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002933
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002934#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
2936
2937asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2938{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002939 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002940 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002941
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002942 if (copy_from_user(&tmp, args, sizeof(tmp)))
2943 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002944
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002945 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002946
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002947 /* If no error reading the parameters then just -ENOSYS ... */
2948 if (!error)
2949 error = -ENOSYS;
2950
2951 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952}
2953
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002954int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002955 void __user *oldval, size_t __user *oldlenp,
2956 void __user *newval, size_t newlen)
2957{
2958 return -ENOSYS;
2959}
2960
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002961int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002963 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964{
2965 return -ENOSYS;
2966}
2967
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002968int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002970 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971{
2972 return -ENOSYS;
2973}
2974
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002975int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002977 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978{
2979 return -ENOSYS;
2980}
2981
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002982int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002984 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985{
2986 return -ENOSYS;
2987}
2988
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002989#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002991static int deprecated_sysctl_warning(struct __sysctl_args *args)
2992{
2993 static int msg_count;
2994 int name[CTL_MAXNAME];
2995 int i;
2996
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002997 /* Check args->nlen. */
2998 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2999 return -ENOTDIR;
3000
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003001 /* Read in the sysctl name for better debug message logging */
3002 for (i = 0; i < args->nlen; i++)
3003 if (get_user(name[i], args->name + i))
3004 return -EFAULT;
3005
3006 /* Ignore accesses to kernel.version */
3007 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3008 return 0;
3009
3010 if (msg_count < 5) {
3011 msg_count++;
3012 printk(KERN_INFO
3013 "warning: process `%s' used the deprecated sysctl "
3014 "system call with ", current->comm);
3015 for (i = 0; i < args->nlen; i++)
3016 printk("%d.", name[i]);
3017 printk("\n");
3018 }
3019 return 0;
3020}
3021
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022/*
3023 * No sense putting this after each symbol definition, twice,
3024 * exception granted :-)
3025 */
3026EXPORT_SYMBOL(proc_dointvec);
3027EXPORT_SYMBOL(proc_dointvec_jiffies);
3028EXPORT_SYMBOL(proc_dointvec_minmax);
3029EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3030EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3031EXPORT_SYMBOL(proc_dostring);
3032EXPORT_SYMBOL(proc_doulongvec_minmax);
3033EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3034EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003035EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036EXPORT_SYMBOL(sysctl_intvec);
3037EXPORT_SYMBOL(sysctl_jiffies);
3038EXPORT_SYMBOL(sysctl_ms_jiffies);
3039EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003040EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041EXPORT_SYMBOL(unregister_sysctl_table);