blob: ec88fcc9a0d2677ab21bd36bf38dc07da6baf0e1 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
181int sysctl_legacy_va_layout;
182#endif
183
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700184extern int prove_locking;
185extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/* The default sysctl tables: */
188
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700189static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 {
191 .ctl_name = CTL_KERN,
192 .procname = "kernel",
193 .mode = 0555,
194 .child = kern_table,
195 },
196 {
197 .ctl_name = CTL_VM,
198 .procname = "vm",
199 .mode = 0555,
200 .child = vm_table,
201 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
207 },
208 {
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
213 },
214 {
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
219 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700220/*
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
223 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 { .ctl_name = 0 }
225};
226
Ingo Molnar77e54a12007-07-09 18:52:00 +0200227#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100228static int min_sched_granularity_ns = 100000; /* 100 usecs */
229static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230static int min_wakeup_granularity_ns; /* 0 usecs */
231static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200232#endif
233
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700234static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#ifdef CONFIG_SCHED_DEBUG
236 {
237 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240 .maxlen = sizeof(unsigned int),
241 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246 },
247 {
248 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
252 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100253 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
257 },
258 {
259 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200271 .procname = "sched_shares_ratelimit",
272 .data = &sysctl_sched_shares_ratelimit,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec,
276 },
277 {
278 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200279 .procname = "sched_child_runs_first",
280 .data = &sysctl_sched_child_runs_first,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec,
284 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200285 {
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_features",
288 .data = &sysctl_sched_features,
289 .maxlen = sizeof(unsigned int),
290 .mode = 0644,
291 .proc_handler = &proc_dointvec,
292 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200293 {
294 .ctl_name = CTL_UNNUMBERED,
295 .procname = "sched_migration_cost",
296 .data = &sysctl_sched_migration_cost,
297 .maxlen = sizeof(unsigned int),
298 .mode = 0644,
299 .proc_handler = &proc_dointvec,
300 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100301 {
302 .ctl_name = CTL_UNNUMBERED,
303 .procname = "sched_nr_migrate",
304 .data = &sysctl_sched_nr_migrate,
305 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100306 .mode = 0644,
307 .proc_handler = &proc_dointvec,
308 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200309#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200310 {
311 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100312 .procname = "sched_rt_period_us",
313 .data = &sysctl_sched_rt_period,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200316 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100317 },
318 {
319 .ctl_name = CTL_UNNUMBERED,
320 .procname = "sched_rt_runtime_us",
321 .data = &sysctl_sched_rt_runtime,
322 .maxlen = sizeof(int),
323 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200324 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100325 },
326 {
327 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200328 .procname = "sched_compat_yield",
329 .data = &sysctl_sched_compat_yield,
330 .maxlen = sizeof(unsigned int),
331 .mode = 0644,
332 .proc_handler = &proc_dointvec,
333 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700334#ifdef CONFIG_PROVE_LOCKING
335 {
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "prove_locking",
338 .data = &prove_locking,
339 .maxlen = sizeof(int),
340 .mode = 0644,
341 .proc_handler = &proc_dointvec,
342 },
343#endif
344#ifdef CONFIG_LOCK_STAT
345 {
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "lock_stat",
348 .data = &lock_stat,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
352 },
353#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 .ctl_name = KERN_PANIC,
356 .procname = "panic",
357 .data = &panic_timeout,
358 .maxlen = sizeof(int),
359 .mode = 0644,
360 .proc_handler = &proc_dointvec,
361 },
362 {
363 .ctl_name = KERN_CORE_USES_PID,
364 .procname = "core_uses_pid",
365 .data = &core_uses_pid,
366 .maxlen = sizeof(int),
367 .mode = 0644,
368 .proc_handler = &proc_dointvec,
369 },
370 {
371 .ctl_name = KERN_CORE_PATTERN,
372 .procname = "core_pattern",
373 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700374 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 .mode = 0644,
376 .proc_handler = &proc_dostring,
377 .strategy = &sysctl_string,
378 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800379#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700382 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800383 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700384 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800386#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100387#ifdef CONFIG_LATENCYTOP
388 {
389 .procname = "latencytop",
390 .data = &latencytop_enabled,
391 .maxlen = sizeof(int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
394 },
395#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396#ifdef CONFIG_BLK_DEV_INITRD
397 {
398 .ctl_name = KERN_REALROOTDEV,
399 .procname = "real-root-dev",
400 .data = &real_root_dev,
401 .maxlen = sizeof(int),
402 .mode = 0644,
403 .proc_handler = &proc_dointvec,
404 },
405#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700406 {
407 .ctl_name = CTL_UNNUMBERED,
408 .procname = "print-fatal-signals",
409 .data = &print_fatal_signals,
410 .maxlen = sizeof(int),
411 .mode = 0644,
412 .proc_handler = &proc_dointvec,
413 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700414#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 {
416 .ctl_name = KERN_SPARC_REBOOT,
417 .procname = "reboot-cmd",
418 .data = reboot_command,
419 .maxlen = 256,
420 .mode = 0644,
421 .proc_handler = &proc_dostring,
422 .strategy = &sysctl_string,
423 },
424 {
425 .ctl_name = KERN_SPARC_STOP_A,
426 .procname = "stop-a",
427 .data = &stop_a_enabled,
428 .maxlen = sizeof (int),
429 .mode = 0644,
430 .proc_handler = &proc_dointvec,
431 },
432 {
433 .ctl_name = KERN_SPARC_SCONS_PWROFF,
434 .procname = "scons-poweroff",
435 .data = &scons_pwroff,
436 .maxlen = sizeof (int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
439 },
440#endif
441#ifdef __hppa__
442 {
443 .ctl_name = KERN_HPPA_PWRSW,
444 .procname = "soft-power",
445 .data = &pwrsw_enabled,
446 .maxlen = sizeof (int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450 {
451 .ctl_name = KERN_HPPA_UNALIGNED,
452 .procname = "unaligned-trap",
453 .data = &unaligned_enabled,
454 .maxlen = sizeof (int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458#endif
459 {
460 .ctl_name = KERN_CTLALTDEL,
461 .procname = "ctrl-alt-del",
462 .data = &C_A_D,
463 .maxlen = sizeof(int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
466 },
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200467#ifdef CONFIG_FTRACE
468 {
469 .ctl_name = CTL_UNNUMBERED,
470 .procname = "ftrace_enabled",
471 .data = &ftrace_enabled,
472 .maxlen = sizeof(int),
473 .mode = 0644,
474 .proc_handler = &ftrace_enable_sysctl,
475 },
476#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200477#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 {
479 .ctl_name = KERN_MODPROBE,
480 .procname = "modprobe",
481 .data = &modprobe_path,
482 .maxlen = KMOD_PATH_LEN,
483 .mode = 0644,
484 .proc_handler = &proc_dostring,
485 .strategy = &sysctl_string,
486 },
487#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700488#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 {
490 .ctl_name = KERN_HOTPLUG,
491 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100492 .data = &uevent_helper,
493 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .mode = 0644,
495 .proc_handler = &proc_dostring,
496 .strategy = &sysctl_string,
497 },
498#endif
499#ifdef CONFIG_CHR_DEV_SG
500 {
501 .ctl_name = KERN_SG_BIG_BUFF,
502 .procname = "sg-big-buff",
503 .data = &sg_big_buff,
504 .maxlen = sizeof (int),
505 .mode = 0444,
506 .proc_handler = &proc_dointvec,
507 },
508#endif
509#ifdef CONFIG_BSD_PROCESS_ACCT
510 {
511 .ctl_name = KERN_ACCT,
512 .procname = "acct",
513 .data = &acct_parm,
514 .maxlen = 3*sizeof(int),
515 .mode = 0644,
516 .proc_handler = &proc_dointvec,
517 },
518#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#ifdef CONFIG_MAGIC_SYSRQ
520 {
521 .ctl_name = KERN_SYSRQ,
522 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800523 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 .maxlen = sizeof (int),
525 .mode = 0644,
526 .proc_handler = &proc_dointvec,
527 },
528#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700529#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700532 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 .maxlen = sizeof (int),
534 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700535 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700537#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
539 .ctl_name = KERN_MAX_THREADS,
540 .procname = "threads-max",
541 .data = &max_threads,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 .proc_handler = &proc_dointvec,
545 },
546 {
547 .ctl_name = KERN_RANDOM,
548 .procname = "random",
549 .mode = 0555,
550 .child = random_table,
551 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 {
553 .ctl_name = KERN_OVERFLOWUID,
554 .procname = "overflowuid",
555 .data = &overflowuid,
556 .maxlen = sizeof(int),
557 .mode = 0644,
558 .proc_handler = &proc_dointvec_minmax,
559 .strategy = &sysctl_intvec,
560 .extra1 = &minolduid,
561 .extra2 = &maxolduid,
562 },
563 {
564 .ctl_name = KERN_OVERFLOWGID,
565 .procname = "overflowgid",
566 .data = &overflowgid,
567 .maxlen = sizeof(int),
568 .mode = 0644,
569 .proc_handler = &proc_dointvec_minmax,
570 .strategy = &sysctl_intvec,
571 .extra1 = &minolduid,
572 .extra2 = &maxolduid,
573 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800574#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#ifdef CONFIG_MATHEMU
576 {
577 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
578 .procname = "ieee_emulation_warnings",
579 .data = &sysctl_ieee_emulation_warnings,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 .proc_handler = &proc_dointvec,
583 },
584#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 {
586 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
587 .procname = "userprocess_debug",
588 .data = &sysctl_userprocess_debug,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = &proc_dointvec,
592 },
593#endif
594 {
595 .ctl_name = KERN_PIDMAX,
596 .procname = "pid_max",
597 .data = &pid_max,
598 .maxlen = sizeof (int),
599 .mode = 0644,
600 .proc_handler = &proc_dointvec_minmax,
601 .strategy = sysctl_intvec,
602 .extra1 = &pid_max_min,
603 .extra2 = &pid_max_max,
604 },
605 {
606 .ctl_name = KERN_PANIC_ON_OOPS,
607 .procname = "panic_on_oops",
608 .data = &panic_on_oops,
609 .maxlen = sizeof(int),
610 .mode = 0644,
611 .proc_handler = &proc_dointvec,
612 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800613#if defined CONFIG_PRINTK
614 {
615 .ctl_name = KERN_PRINTK,
616 .procname = "printk",
617 .data = &console_loglevel,
618 .maxlen = 4*sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec,
621 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 {
623 .ctl_name = KERN_PRINTK_RATELIMIT,
624 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700625 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 .maxlen = sizeof(int),
627 .mode = 0644,
628 .proc_handler = &proc_dointvec_jiffies,
629 .strategy = &sysctl_jiffies,
630 },
631 {
632 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
633 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700634 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 .maxlen = sizeof(int),
636 .mode = 0644,
637 .proc_handler = &proc_dointvec,
638 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800639#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 {
641 .ctl_name = KERN_NGROUPS_MAX,
642 .procname = "ngroups_max",
643 .data = &ngroups_max,
644 .maxlen = sizeof (int),
645 .mode = 0444,
646 .proc_handler = &proc_dointvec,
647 },
648#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
649 {
650 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
651 .procname = "unknown_nmi_panic",
652 .data = &unknown_nmi_panic,
653 .maxlen = sizeof (int),
654 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200655 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 },
Don Zickus407984f2006-09-26 10:52:27 +0200657 {
Don Zickus407984f2006-09-26 10:52:27 +0200658 .procname = "nmi_watchdog",
659 .data = &nmi_watchdog_enabled,
660 .maxlen = sizeof (int),
661 .mode = 0644,
662 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 },
664#endif
665#if defined(CONFIG_X86)
666 {
Don Zickus8da5adda2006-09-26 10:52:27 +0200667 .ctl_name = KERN_PANIC_ON_NMI,
668 .procname = "panic_on_unrecovered_nmi",
669 .data = &panic_on_unrecovered_nmi,
670 .maxlen = sizeof(int),
671 .mode = 0644,
672 .proc_handler = &proc_dointvec,
673 },
674 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 .ctl_name = KERN_BOOTLOADER_TYPE,
676 .procname = "bootloader_type",
677 .data = &bootloader_type,
678 .maxlen = sizeof (int),
679 .mode = 0444,
680 .proc_handler = &proc_dointvec,
681 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100682 {
683 .ctl_name = CTL_UNNUMBERED,
684 .procname = "kstack_depth_to_print",
685 .data = &kstack_depth_to_print,
686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec,
689 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100690 {
691 .ctl_name = CTL_UNNUMBERED,
692 .procname = "io_delay_type",
693 .data = &io_delay_type,
694 .maxlen = sizeof(int),
695 .mode = 0644,
696 .proc_handler = &proc_dointvec,
697 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800699#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 {
701 .ctl_name = KERN_RANDOMIZE,
702 .procname = "randomize_va_space",
703 .data = &randomize_va_space,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 .proc_handler = &proc_dointvec,
707 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800708#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800709#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700710 {
711 .ctl_name = KERN_SPIN_RETRY,
712 .procname = "spin_retry",
713 .data = &spin_retry,
714 .maxlen = sizeof (int),
715 .mode = 0644,
716 .proc_handler = &proc_dointvec,
717 },
718#endif
Len Brown673d5b42007-07-28 03:33:16 -0400719#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800720 {
Pavel Machekc255d842006-02-20 18:27:58 -0800721 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700722 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800723 .maxlen = sizeof (unsigned long),
724 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800725 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800726 },
727#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800728#ifdef CONFIG_IA64
729 {
730 .ctl_name = KERN_IA64_UNALIGNED,
731 .procname = "ignore-unaligned-usertrap",
732 .data = &no_unaligned_warning,
733 .maxlen = sizeof (int),
734 .mode = 0644,
735 .proc_handler = &proc_dointvec,
736 },
737#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700738#ifdef CONFIG_DETECT_SOFTLOCKUP
739 {
740 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200741 .procname = "softlockup_panic",
742 .data = &softlockup_panic,
743 .maxlen = sizeof(int),
744 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700745 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200746 .strategy = &sysctl_intvec,
747 .extra1 = &zero,
748 .extra2 = &one,
749 },
750 {
751 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700752 .procname = "softlockup_thresh",
753 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200754 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700755 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200756 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700757 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200758 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700759 .extra2 = &sixty,
760 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100761 {
762 .ctl_name = CTL_UNNUMBERED,
763 .procname = "hung_task_check_count",
764 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100765 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100766 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100767 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100768 .strategy = &sysctl_intvec,
769 },
770 {
771 .ctl_name = CTL_UNNUMBERED,
772 .procname = "hung_task_timeout_secs",
773 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100774 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100775 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100776 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100777 .strategy = &sysctl_intvec,
778 },
779 {
780 .ctl_name = CTL_UNNUMBERED,
781 .procname = "hung_task_warnings",
782 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100783 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100784 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100785 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100786 .strategy = &sysctl_intvec,
787 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700788#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200789#ifdef CONFIG_COMPAT
790 {
791 .ctl_name = KERN_COMPAT_LOG,
792 .procname = "compat-log",
793 .data = &compat_log,
794 .maxlen = sizeof (int),
795 .mode = 0644,
796 .proc_handler = &proc_dointvec,
797 },
798#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700799#ifdef CONFIG_RT_MUTEXES
800 {
801 .ctl_name = KERN_MAX_LOCK_DEPTH,
802 .procname = "max_lock_depth",
803 .data = &max_lock_depth,
804 .maxlen = sizeof(int),
805 .mode = 0644,
806 .proc_handler = &proc_dointvec,
807 },
808#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700809 {
810 .ctl_name = CTL_UNNUMBERED,
811 .procname = "poweroff_cmd",
812 .data = &poweroff_cmd,
813 .maxlen = POWEROFF_CMD_PATH_LEN,
814 .mode = 0644,
815 .proc_handler = &proc_dostring,
816 .strategy = &sysctl_string,
817 },
David Howells0b77f5b2008-04-29 01:01:32 -0700818#ifdef CONFIG_KEYS
819 {
820 .ctl_name = CTL_UNNUMBERED,
821 .procname = "keys",
822 .mode = 0555,
823 .child = key_sysctls,
824 },
825#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700826#ifdef CONFIG_RCU_TORTURE_TEST
827 {
828 .ctl_name = CTL_UNNUMBERED,
829 .procname = "rcutorture_runnable",
830 .data = &rcutorture_runnable,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec,
834 },
835#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700836/*
837 * NOTE: do not add new entries to this table unless you have read
838 * Documentation/sysctl/ctl_unnumbered.txt
839 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 { .ctl_name = 0 }
841};
842
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700843static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 {
845 .ctl_name = VM_OVERCOMMIT_MEMORY,
846 .procname = "overcommit_memory",
847 .data = &sysctl_overcommit_memory,
848 .maxlen = sizeof(sysctl_overcommit_memory),
849 .mode = 0644,
850 .proc_handler = &proc_dointvec,
851 },
852 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700853 .ctl_name = VM_PANIC_ON_OOM,
854 .procname = "panic_on_oom",
855 .data = &sysctl_panic_on_oom,
856 .maxlen = sizeof(sysctl_panic_on_oom),
857 .mode = 0644,
858 .proc_handler = &proc_dointvec,
859 },
860 {
David Rientjesfe071d72007-10-16 23:25:56 -0700861 .ctl_name = CTL_UNNUMBERED,
862 .procname = "oom_kill_allocating_task",
863 .data = &sysctl_oom_kill_allocating_task,
864 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
865 .mode = 0644,
866 .proc_handler = &proc_dointvec,
867 },
868 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800869 .ctl_name = CTL_UNNUMBERED,
870 .procname = "oom_dump_tasks",
871 .data = &sysctl_oom_dump_tasks,
872 .maxlen = sizeof(sysctl_oom_dump_tasks),
873 .mode = 0644,
874 .proc_handler = &proc_dointvec,
875 },
876 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 .ctl_name = VM_OVERCOMMIT_RATIO,
878 .procname = "overcommit_ratio",
879 .data = &sysctl_overcommit_ratio,
880 .maxlen = sizeof(sysctl_overcommit_ratio),
881 .mode = 0644,
882 .proc_handler = &proc_dointvec,
883 },
884 {
885 .ctl_name = VM_PAGE_CLUSTER,
886 .procname = "page-cluster",
887 .data = &page_cluster,
888 .maxlen = sizeof(int),
889 .mode = 0644,
890 .proc_handler = &proc_dointvec,
891 },
892 {
893 .ctl_name = VM_DIRTY_BACKGROUND,
894 .procname = "dirty_background_ratio",
895 .data = &dirty_background_ratio,
896 .maxlen = sizeof(dirty_background_ratio),
897 .mode = 0644,
898 .proc_handler = &proc_dointvec_minmax,
899 .strategy = &sysctl_intvec,
900 .extra1 = &zero,
901 .extra2 = &one_hundred,
902 },
903 {
904 .ctl_name = VM_DIRTY_RATIO,
905 .procname = "dirty_ratio",
906 .data = &vm_dirty_ratio,
907 .maxlen = sizeof(vm_dirty_ratio),
908 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700909 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .strategy = &sysctl_intvec,
911 .extra1 = &zero,
912 .extra2 = &one_hundred,
913 },
914 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800916 .data = &dirty_writeback_interval,
917 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 .mode = 0644,
919 .proc_handler = &dirty_writeback_centisecs_handler,
920 },
921 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800923 .data = &dirty_expire_interval,
924 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800926 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 },
928 {
929 .ctl_name = VM_NR_PDFLUSH_THREADS,
930 .procname = "nr_pdflush_threads",
931 .data = &nr_pdflush_threads,
932 .maxlen = sizeof nr_pdflush_threads,
933 .mode = 0444 /* read-only*/,
934 .proc_handler = &proc_dointvec,
935 },
936 {
937 .ctl_name = VM_SWAPPINESS,
938 .procname = "swappiness",
939 .data = &vm_swappiness,
940 .maxlen = sizeof(vm_swappiness),
941 .mode = 0644,
942 .proc_handler = &proc_dointvec_minmax,
943 .strategy = &sysctl_intvec,
944 .extra1 = &zero,
945 .extra2 = &one_hundred,
946 },
947#ifdef CONFIG_HUGETLB_PAGE
948 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700950 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 .maxlen = sizeof(unsigned long),
952 .mode = 0644,
953 .proc_handler = &hugetlb_sysctl_handler,
954 .extra1 = (void *)&hugetlb_zero,
955 .extra2 = (void *)&hugetlb_infinity,
956 },
957 {
958 .ctl_name = VM_HUGETLB_GROUP,
959 .procname = "hugetlb_shm_group",
960 .data = &sysctl_hugetlb_shm_group,
961 .maxlen = sizeof(gid_t),
962 .mode = 0644,
963 .proc_handler = &proc_dointvec,
964 },
Mel Gorman396faf02007-07-17 04:03:13 -0700965 {
966 .ctl_name = CTL_UNNUMBERED,
967 .procname = "hugepages_treat_as_movable",
968 .data = &hugepages_treat_as_movable,
969 .maxlen = sizeof(int),
970 .mode = 0644,
971 .proc_handler = &hugetlb_treat_movable_handler,
972 },
Adam Litke54f9f802007-10-16 01:26:20 -0700973 {
974 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800975 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700976 .data = NULL,
977 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800978 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800979 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -0700980 .extra1 = (void *)&hugetlb_zero,
981 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800982 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983#endif
984 {
985 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
986 .procname = "lowmem_reserve_ratio",
987 .data = &sysctl_lowmem_reserve_ratio,
988 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
989 .mode = 0644,
990 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
991 .strategy = &sysctl_intvec,
992 },
993 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800994 .ctl_name = VM_DROP_PAGECACHE,
995 .procname = "drop_caches",
996 .data = &sysctl_drop_caches,
997 .maxlen = sizeof(int),
998 .mode = 0644,
999 .proc_handler = drop_caches_sysctl_handler,
1000 .strategy = &sysctl_intvec,
1001 },
1002 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 .ctl_name = VM_MIN_FREE_KBYTES,
1004 .procname = "min_free_kbytes",
1005 .data = &min_free_kbytes,
1006 .maxlen = sizeof(min_free_kbytes),
1007 .mode = 0644,
1008 .proc_handler = &min_free_kbytes_sysctl_handler,
1009 .strategy = &sysctl_intvec,
1010 .extra1 = &zero,
1011 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001012 {
1013 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1014 .procname = "percpu_pagelist_fraction",
1015 .data = &percpu_pagelist_fraction,
1016 .maxlen = sizeof(percpu_pagelist_fraction),
1017 .mode = 0644,
1018 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1019 .strategy = &sysctl_intvec,
1020 .extra1 = &min_percpu_pagelist_fract,
1021 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022#ifdef CONFIG_MMU
1023 {
1024 .ctl_name = VM_MAX_MAP_COUNT,
1025 .procname = "max_map_count",
1026 .data = &sysctl_max_map_count,
1027 .maxlen = sizeof(sysctl_max_map_count),
1028 .mode = 0644,
1029 .proc_handler = &proc_dointvec
1030 },
1031#endif
1032 {
1033 .ctl_name = VM_LAPTOP_MODE,
1034 .procname = "laptop_mode",
1035 .data = &laptop_mode,
1036 .maxlen = sizeof(laptop_mode),
1037 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001038 .proc_handler = &proc_dointvec_jiffies,
1039 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 },
1041 {
1042 .ctl_name = VM_BLOCK_DUMP,
1043 .procname = "block_dump",
1044 .data = &block_dump,
1045 .maxlen = sizeof(block_dump),
1046 .mode = 0644,
1047 .proc_handler = &proc_dointvec,
1048 .strategy = &sysctl_intvec,
1049 .extra1 = &zero,
1050 },
1051 {
1052 .ctl_name = VM_VFS_CACHE_PRESSURE,
1053 .procname = "vfs_cache_pressure",
1054 .data = &sysctl_vfs_cache_pressure,
1055 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1056 .mode = 0644,
1057 .proc_handler = &proc_dointvec,
1058 .strategy = &sysctl_intvec,
1059 .extra1 = &zero,
1060 },
1061#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1062 {
1063 .ctl_name = VM_LEGACY_VA_LAYOUT,
1064 .procname = "legacy_va_layout",
1065 .data = &sysctl_legacy_va_layout,
1066 .maxlen = sizeof(sysctl_legacy_va_layout),
1067 .mode = 0644,
1068 .proc_handler = &proc_dointvec,
1069 .strategy = &sysctl_intvec,
1070 .extra1 = &zero,
1071 },
1072#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001073#ifdef CONFIG_NUMA
1074 {
1075 .ctl_name = VM_ZONE_RECLAIM_MODE,
1076 .procname = "zone_reclaim_mode",
1077 .data = &zone_reclaim_mode,
1078 .maxlen = sizeof(zone_reclaim_mode),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001081 .strategy = &sysctl_intvec,
1082 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001083 },
Christoph Lameter96146342006-07-03 00:24:13 -07001084 {
1085 .ctl_name = VM_MIN_UNMAPPED,
1086 .procname = "min_unmapped_ratio",
1087 .data = &sysctl_min_unmapped_ratio,
1088 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1089 .mode = 0644,
1090 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1091 .strategy = &sysctl_intvec,
1092 .extra1 = &zero,
1093 .extra2 = &one_hundred,
1094 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001095 {
1096 .ctl_name = VM_MIN_SLAB,
1097 .procname = "min_slab_ratio",
1098 .data = &sysctl_min_slab_ratio,
1099 .maxlen = sizeof(sysctl_min_slab_ratio),
1100 .mode = 0644,
1101 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1102 .strategy = &sysctl_intvec,
1103 .extra1 = &zero,
1104 .extra2 = &one_hundred,
1105 },
Christoph Lameter17436602006-01-18 17:42:32 -08001106#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001107#ifdef CONFIG_SMP
1108 {
1109 .ctl_name = CTL_UNNUMBERED,
1110 .procname = "stat_interval",
1111 .data = &sysctl_stat_interval,
1112 .maxlen = sizeof(sysctl_stat_interval),
1113 .mode = 0644,
1114 .proc_handler = &proc_dointvec_jiffies,
1115 .strategy = &sysctl_jiffies,
1116 },
1117#endif
Eric Parised032182007-06-28 15:55:21 -04001118#ifdef CONFIG_SECURITY
1119 {
1120 .ctl_name = CTL_UNNUMBERED,
1121 .procname = "mmap_min_addr",
1122 .data = &mmap_min_addr,
1123 .maxlen = sizeof(unsigned long),
1124 .mode = 0644,
1125 .proc_handler = &proc_doulongvec_minmax,
1126 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001127#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001128#ifdef CONFIG_NUMA
1129 {
1130 .ctl_name = CTL_UNNUMBERED,
1131 .procname = "numa_zonelist_order",
1132 .data = &numa_zonelist_order,
1133 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1134 .mode = 0644,
1135 .proc_handler = &numa_zonelist_order_handler,
1136 .strategy = &sysctl_string,
1137 },
1138#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001139#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001140 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001141 {
1142 .ctl_name = VM_VDSO_ENABLED,
1143 .procname = "vdso_enabled",
1144 .data = &vdso_enabled,
1145 .maxlen = sizeof(vdso_enabled),
1146 .mode = 0644,
1147 .proc_handler = &proc_dointvec,
1148 .strategy = &sysctl_intvec,
1149 .extra1 = &zero,
1150 },
1151#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001152#ifdef CONFIG_HIGHMEM
1153 {
1154 .ctl_name = CTL_UNNUMBERED,
1155 .procname = "highmem_is_dirtyable",
1156 .data = &vm_highmem_is_dirtyable,
1157 .maxlen = sizeof(vm_highmem_is_dirtyable),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec_minmax,
1160 .strategy = &sysctl_intvec,
1161 .extra1 = &zero,
1162 .extra2 = &one,
1163 },
1164#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001165/*
1166 * NOTE: do not add new entries to this table unless you have read
1167 * Documentation/sysctl/ctl_unnumbered.txt
1168 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 { .ctl_name = 0 }
1170};
1171
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001172#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001173static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001174 { .ctl_name = 0 }
1175};
1176#endif
1177
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001178static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 {
1180 .ctl_name = FS_NRINODE,
1181 .procname = "inode-nr",
1182 .data = &inodes_stat,
1183 .maxlen = 2*sizeof(int),
1184 .mode = 0444,
1185 .proc_handler = &proc_dointvec,
1186 },
1187 {
1188 .ctl_name = FS_STATINODE,
1189 .procname = "inode-state",
1190 .data = &inodes_stat,
1191 .maxlen = 7*sizeof(int),
1192 .mode = 0444,
1193 .proc_handler = &proc_dointvec,
1194 },
1195 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 .procname = "file-nr",
1197 .data = &files_stat,
1198 .maxlen = 3*sizeof(int),
1199 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001200 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 },
1202 {
1203 .ctl_name = FS_MAXFILE,
1204 .procname = "file-max",
1205 .data = &files_stat.max_files,
1206 .maxlen = sizeof(int),
1207 .mode = 0644,
1208 .proc_handler = &proc_dointvec,
1209 },
1210 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001211 .ctl_name = CTL_UNNUMBERED,
1212 .procname = "nr_open",
1213 .data = &sysctl_nr_open,
1214 .maxlen = sizeof(int),
1215 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001216 .proc_handler = &proc_dointvec_minmax,
1217 .extra1 = &sysctl_nr_open_min,
1218 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001219 },
1220 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 .ctl_name = FS_DENTRY,
1222 .procname = "dentry-state",
1223 .data = &dentry_stat,
1224 .maxlen = 6*sizeof(int),
1225 .mode = 0444,
1226 .proc_handler = &proc_dointvec,
1227 },
1228 {
1229 .ctl_name = FS_OVERFLOWUID,
1230 .procname = "overflowuid",
1231 .data = &fs_overflowuid,
1232 .maxlen = sizeof(int),
1233 .mode = 0644,
1234 .proc_handler = &proc_dointvec_minmax,
1235 .strategy = &sysctl_intvec,
1236 .extra1 = &minolduid,
1237 .extra2 = &maxolduid,
1238 },
1239 {
1240 .ctl_name = FS_OVERFLOWGID,
1241 .procname = "overflowgid",
1242 .data = &fs_overflowgid,
1243 .maxlen = sizeof(int),
1244 .mode = 0644,
1245 .proc_handler = &proc_dointvec_minmax,
1246 .strategy = &sysctl_intvec,
1247 .extra1 = &minolduid,
1248 .extra2 = &maxolduid,
1249 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001250#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 {
1252 .ctl_name = FS_LEASES,
1253 .procname = "leases-enable",
1254 .data = &leases_enable,
1255 .maxlen = sizeof(int),
1256 .mode = 0644,
1257 .proc_handler = &proc_dointvec,
1258 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001259#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260#ifdef CONFIG_DNOTIFY
1261 {
1262 .ctl_name = FS_DIR_NOTIFY,
1263 .procname = "dir-notify-enable",
1264 .data = &dir_notify_enable,
1265 .maxlen = sizeof(int),
1266 .mode = 0644,
1267 .proc_handler = &proc_dointvec,
1268 },
1269#endif
1270#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001271#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 {
1273 .ctl_name = FS_LEASE_TIME,
1274 .procname = "lease-break-time",
1275 .data = &lease_break_time,
1276 .maxlen = sizeof(int),
1277 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001278 .proc_handler = &proc_dointvec_minmax,
1279 .strategy = &sysctl_intvec,
1280 .extra1 = &zero,
1281 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001283#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 .procname = "aio-nr",
1286 .data = &aio_nr,
1287 .maxlen = sizeof(aio_nr),
1288 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001289 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 },
1291 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 .procname = "aio-max-nr",
1293 .data = &aio_max_nr,
1294 .maxlen = sizeof(aio_max_nr),
1295 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001296 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001298#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001299 {
1300 .ctl_name = FS_INOTIFY,
1301 .procname = "inotify",
1302 .mode = 0555,
1303 .child = inotify_table,
1304 },
1305#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001307 {
1308 .ctl_name = KERN_SETUID_DUMPABLE,
1309 .procname = "suid_dumpable",
1310 .data = &suid_dumpable,
1311 .maxlen = sizeof(int),
1312 .mode = 0644,
1313 .proc_handler = &proc_dointvec,
1314 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001315#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1316 {
1317 .ctl_name = CTL_UNNUMBERED,
1318 .procname = "binfmt_misc",
1319 .mode = 0555,
1320 .child = binfmt_misc_table,
1321 },
1322#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001323/*
1324 * NOTE: do not add new entries to this table unless you have read
1325 * Documentation/sysctl/ctl_unnumbered.txt
1326 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 { .ctl_name = 0 }
1328};
1329
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001330static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001331#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001332 {
1333 .ctl_name = CTL_UNNUMBERED,
1334 .procname = "exception-trace",
1335 .data = &show_unhandled_signals,
1336 .maxlen = sizeof(int),
1337 .mode = 0644,
1338 .proc_handler = proc_dointvec
1339 },
1340#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 { .ctl_name = 0 }
1342};
1343
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001344static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001346};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Al Viro330d57f2005-11-04 10:18:40 +00001348static DEFINE_SPINLOCK(sysctl_lock);
1349
1350/* called under sysctl_lock */
1351static int use_table(struct ctl_table_header *p)
1352{
1353 if (unlikely(p->unregistering))
1354 return 0;
1355 p->used++;
1356 return 1;
1357}
1358
1359/* called under sysctl_lock */
1360static void unuse_table(struct ctl_table_header *p)
1361{
1362 if (!--p->used)
1363 if (unlikely(p->unregistering))
1364 complete(p->unregistering);
1365}
1366
1367/* called under sysctl_lock, will reacquire if has to wait */
1368static void start_unregistering(struct ctl_table_header *p)
1369{
1370 /*
1371 * if p->used is 0, nobody will ever touch that entry again;
1372 * we'll eliminate all paths to it before dropping sysctl_lock
1373 */
1374 if (unlikely(p->used)) {
1375 struct completion wait;
1376 init_completion(&wait);
1377 p->unregistering = &wait;
1378 spin_unlock(&sysctl_lock);
1379 wait_for_completion(&wait);
1380 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001381 } else {
1382 /* anything non-NULL; we'll never dereference it */
1383 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001384 }
1385 /*
1386 * do not remove from the list until nobody holds it; walking the
1387 * list in do_sysctl() relies on that.
1388 */
1389 list_del_init(&p->ctl_entry);
1390}
1391
Al Virof7e6ced2008-07-15 01:44:23 -04001392void sysctl_head_get(struct ctl_table_header *head)
1393{
1394 spin_lock(&sysctl_lock);
1395 head->count++;
1396 spin_unlock(&sysctl_lock);
1397}
1398
1399void sysctl_head_put(struct ctl_table_header *head)
1400{
1401 spin_lock(&sysctl_lock);
1402 if (!--head->count)
1403 kfree(head);
1404 spin_unlock(&sysctl_lock);
1405}
1406
1407struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1408{
1409 if (!head)
1410 BUG();
1411 spin_lock(&sysctl_lock);
1412 if (!use_table(head))
1413 head = ERR_PTR(-ENOENT);
1414 spin_unlock(&sysctl_lock);
1415 return head;
1416}
1417
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001418void sysctl_head_finish(struct ctl_table_header *head)
1419{
1420 if (!head)
1421 return;
1422 spin_lock(&sysctl_lock);
1423 unuse_table(head);
1424 spin_unlock(&sysctl_lock);
1425}
1426
Al Viro73455092008-07-14 21:22:20 -04001427static struct ctl_table_set *
1428lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1429{
1430 struct ctl_table_set *set = &root->default_set;
1431 if (root->lookup)
1432 set = root->lookup(root, namespaces);
1433 return set;
1434}
1435
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001436static struct list_head *
1437lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001438{
Al Viro73455092008-07-14 21:22:20 -04001439 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1440 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001441}
1442
1443struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1444 struct ctl_table_header *prev)
1445{
1446 struct ctl_table_root *root;
1447 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001448 struct ctl_table_header *head;
1449 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001450
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001451 spin_lock(&sysctl_lock);
1452 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001453 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001454 tmp = &prev->ctl_entry;
1455 unuse_table(prev);
1456 goto next;
1457 }
1458 tmp = &root_table_header.ctl_entry;
1459 for (;;) {
1460 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1461
1462 if (!use_table(head))
1463 goto next;
1464 spin_unlock(&sysctl_lock);
1465 return head;
1466 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001467 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001468 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001469 header_list = lookup_header_list(root, namespaces);
1470 if (tmp != header_list)
1471 continue;
1472
1473 do {
1474 root = list_entry(root->root_list.next,
1475 struct ctl_table_root, root_list);
1476 if (root == &sysctl_table_root)
1477 goto out;
1478 header_list = lookup_header_list(root, namespaces);
1479 } while (list_empty(header_list));
1480 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001481 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001482out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001483 spin_unlock(&sysctl_lock);
1484 return NULL;
1485}
1486
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001487struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1488{
1489 return __sysctl_head_next(current->nsproxy, prev);
1490}
1491
1492void register_sysctl_root(struct ctl_table_root *root)
1493{
1494 spin_lock(&sysctl_lock);
1495 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1496 spin_unlock(&sysctl_lock);
1497}
1498
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001499#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001500/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001501static int do_sysctl_strategy(struct ctl_table_root *root,
1502 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001503 int __user *name, int nlen,
1504 void __user *oldval, size_t __user *oldlenp,
1505 void __user *newval, size_t newlen)
1506{
1507 int op = 0, rc;
1508
1509 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001510 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001511 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001512 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001513 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001514 return -EPERM;
1515
1516 if (table->strategy) {
1517 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1518 newval, newlen);
1519 if (rc < 0)
1520 return rc;
1521 if (rc > 0)
1522 return 0;
1523 }
1524
1525 /* If there is no strategy routine, or if the strategy returns
1526 * zero, proceed with automatic r/w */
1527 if (table->data && table->maxlen) {
1528 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1529 newval, newlen);
1530 if (rc < 0)
1531 return rc;
1532 }
1533 return 0;
1534}
1535
1536static int parse_table(int __user *name, int nlen,
1537 void __user *oldval, size_t __user *oldlenp,
1538 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001539 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001540 struct ctl_table *table)
1541{
1542 int n;
1543repeat:
1544 if (!nlen)
1545 return -ENOTDIR;
1546 if (get_user(n, name))
1547 return -EFAULT;
1548 for ( ; table->ctl_name || table->procname; table++) {
1549 if (!table->ctl_name)
1550 continue;
1551 if (n == table->ctl_name) {
1552 int error;
1553 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001554 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001555 return -EPERM;
1556 name++;
1557 nlen--;
1558 table = table->child;
1559 goto repeat;
1560 }
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001561 error = do_sysctl_strategy(root, table, name, nlen,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001562 oldval, oldlenp,
1563 newval, newlen);
1564 return error;
1565 }
1566 }
1567 return -ENOTDIR;
1568}
1569
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1571 void __user *newval, size_t newlen)
1572{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001573 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001574 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
1576 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1577 return -ENOTDIR;
1578 if (oldval) {
1579 int old_len;
1580 if (!oldlenp || get_user(old_len, oldlenp))
1581 return -EFAULT;
1582 }
Al Viro330d57f2005-11-04 10:18:40 +00001583
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001584 for (head = sysctl_head_next(NULL); head;
1585 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001586 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001587 newval, newlen,
1588 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001589 if (error != -ENOTDIR) {
1590 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001591 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001592 }
1593 }
Al Viro330d57f2005-11-04 10:18:40 +00001594 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595}
1596
1597asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1598{
1599 struct __sysctl_args tmp;
1600 int error;
1601
1602 if (copy_from_user(&tmp, args, sizeof(tmp)))
1603 return -EFAULT;
1604
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001605 error = deprecated_sysctl_warning(&tmp);
1606 if (error)
1607 goto out;
1608
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 lock_kernel();
1610 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1611 tmp.newval, tmp.newlen);
1612 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001613out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 return error;
1615}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001616#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
1618/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001619 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 * some sysctl variables are readonly even to root.
1621 */
1622
1623static int test_perm(int mode, int op)
1624{
1625 if (!current->euid)
1626 mode >>= 6;
1627 else if (in_egroup_p(0))
1628 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001629 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 return 0;
1631 return -EACCES;
1632}
1633
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001634int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635{
1636 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001637 int mode;
1638
Al Viroe6305c42008-07-15 21:03:57 -04001639 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 if (error)
1641 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001642
1643 if (root->permissions)
1644 mode = root->permissions(root, current->nsproxy, table);
1645 else
1646 mode = table->mode;
1647
1648 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001651static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1652{
1653 for (; table->ctl_name || table->procname; table++) {
1654 table->parent = parent;
1655 if (table->child)
1656 sysctl_set_parent(table, table->child);
1657 }
1658}
1659
1660static __init int sysctl_init(void)
1661{
1662 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001663#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1664 {
1665 int err;
1666 err = sysctl_check_table(current->nsproxy, root_table);
1667 }
1668#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001669 return 0;
1670}
1671
1672core_initcall(sysctl_init);
1673
Al Virobfbcf032008-07-27 06:31:22 +01001674static struct ctl_table *is_branch_in(struct ctl_table *branch,
1675 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001676{
1677 struct ctl_table *p;
1678 const char *s = branch->procname;
1679
1680 /* branch should have named subdirectory as its first element */
1681 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001682 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001683
1684 /* ... and nothing else */
1685 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001686 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001687
1688 /* table should contain subdirectory with the same name */
1689 for (p = table; p->procname || p->ctl_name; p++) {
1690 if (!p->child)
1691 continue;
1692 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001693 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001694 }
Al Virobfbcf032008-07-27 06:31:22 +01001695 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001696}
1697
1698/* see if attaching q to p would be an improvement */
1699static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1700{
1701 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001702 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001703 int is_better = 0;
1704 int not_in_parent = !p->attached_by;
1705
Al Virobfbcf032008-07-27 06:31:22 +01001706 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001707 if (by == q->attached_by)
1708 is_better = 1;
1709 if (to == p->attached_by)
1710 not_in_parent = 1;
1711 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001712 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001713 }
1714
1715 if (is_better && not_in_parent) {
1716 q->attached_by = by;
1717 q->attached_to = to;
1718 q->parent = p;
1719 }
1720}
1721
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001723 * __register_sysctl_paths - register a sysctl hierarchy
1724 * @root: List of sysctl headers to register on
1725 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001726 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 *
1729 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001730 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001732 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 *
1734 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1735 * must be unique within that level of sysctl
1736 *
1737 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1738 * enter a sysctl file
1739 *
1740 * data - a pointer to data for use by proc_handler
1741 *
1742 * maxlen - the maximum size in bytes of the data
1743 *
1744 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1745 *
1746 * child - a pointer to the child sysctl table if this entry is a directory, or
1747 * %NULL.
1748 *
1749 * proc_handler - the text handler routine (described below)
1750 *
1751 * strategy - the strategy routine (described below)
1752 *
1753 * de - for internal use by the sysctl routines
1754 *
1755 * extra1, extra2 - extra pointers usable by the proc handler routines
1756 *
1757 * Leaf nodes in the sysctl tree will be represented by a single file
1758 * under /proc; non-leaf nodes will be represented by directories.
1759 *
1760 * sysctl(2) can automatically manage read and write requests through
1761 * the sysctl table. The data and maxlen fields of the ctl_table
1762 * struct enable minimal validation of the values being written to be
1763 * performed, and the mode field allows minimal authentication.
1764 *
1765 * More sophisticated management can be enabled by the provision of a
1766 * strategy routine with the table entry. This will be called before
1767 * any automatic read or write of the data is performed.
1768 *
1769 * The strategy routine may return
1770 *
1771 * < 0 - Error occurred (error is passed to user process)
1772 *
1773 * 0 - OK - proceed with automatic read or write.
1774 *
1775 * > 0 - OK - read or write has been done by the strategy routine, so
1776 * return immediately.
1777 *
1778 * There must be a proc_handler routine for any terminal nodes
1779 * mirrored under /proc/sys (non-terminals are handled by a built-in
1780 * directory handler). Several default handlers are available to
1781 * cover common cases -
1782 *
1783 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1784 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1785 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1786 *
1787 * It is the handler's job to read the input buffer from user memory
1788 * and process it. The handler should return 0 on success.
1789 *
1790 * This routine returns %NULL on a failure to register, and a pointer
1791 * to the table header on success.
1792 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001793struct ctl_table_header *__register_sysctl_paths(
1794 struct ctl_table_root *root,
1795 struct nsproxy *namespaces,
1796 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001798 struct ctl_table_header *header;
1799 struct ctl_table *new, **prevp;
1800 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001801 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001802
1803 /* Count the path components */
1804 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1805 ;
1806
1807 /*
1808 * For each path component, allocate a 2-element ctl_table array.
1809 * The first array element will be filled with the sysctl entry
1810 * for this, the second will be the sentinel (ctl_name == 0).
1811 *
1812 * We allocate everything in one go so that we don't have to
1813 * worry about freeing additional memory in unregister_sysctl_table.
1814 */
1815 header = kzalloc(sizeof(struct ctl_table_header) +
1816 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1817 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001819
1820 new = (struct ctl_table *) (header + 1);
1821
1822 /* Now connect the dots */
1823 prevp = &header->ctl_table;
1824 for (n = 0; n < npath; ++n, ++path) {
1825 /* Copy the procname */
1826 new->procname = path->procname;
1827 new->ctl_name = path->ctl_name;
1828 new->mode = 0555;
1829
1830 *prevp = new;
1831 prevp = &new->child;
1832
1833 new += 2;
1834 }
1835 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001836 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001837
1838 INIT_LIST_HEAD(&header->ctl_entry);
1839 header->used = 0;
1840 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001841 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001842 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001843 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001844#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001845 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001846 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001847 return NULL;
1848 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001849#endif
Al Viro330d57f2005-11-04 10:18:40 +00001850 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001851 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001852 header->attached_by = header->ctl_table;
1853 header->attached_to = root_table;
1854 header->parent = &root_table_header;
1855 for (set = header->set; set; set = set->parent) {
1856 struct ctl_table_header *p;
1857 list_for_each_entry(p, &set->list, ctl_entry) {
1858 if (p->unregistering)
1859 continue;
1860 try_attach(p, header);
1861 }
1862 }
1863 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001864 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001865 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001866
1867 return header;
1868}
1869
1870/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001871 * register_sysctl_table_path - register a sysctl table hierarchy
1872 * @path: The path to the directory the sysctl table is in.
1873 * @table: the top-level table structure
1874 *
1875 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1876 * array. A completely 0 filled entry terminates the table.
1877 *
1878 * See __register_sysctl_paths for more details.
1879 */
1880struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1881 struct ctl_table *table)
1882{
1883 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1884 path, table);
1885}
1886
1887/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001888 * register_sysctl_table - register a sysctl table hierarchy
1889 * @table: the top-level table structure
1890 *
1891 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1892 * array. A completely 0 filled entry terminates the table.
1893 *
1894 * See register_sysctl_paths for more details.
1895 */
1896struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1897{
1898 static const struct ctl_path null_path[] = { {} };
1899
1900 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
1903/**
1904 * unregister_sysctl_table - unregister a sysctl table hierarchy
1905 * @header: the header returned from register_sysctl_table
1906 *
1907 * Unregisters the sysctl table and all children. proc entries may not
1908 * actually be removed until they are no longer used by anyone.
1909 */
1910void unregister_sysctl_table(struct ctl_table_header * header)
1911{
Al Viro330d57f2005-11-04 10:18:40 +00001912 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001913
1914 if (header == NULL)
1915 return;
1916
Al Viro330d57f2005-11-04 10:18:40 +00001917 spin_lock(&sysctl_lock);
1918 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001919 if (!--header->parent->count) {
1920 WARN_ON(1);
1921 kfree(header->parent);
1922 }
Al Virof7e6ced2008-07-15 01:44:23 -04001923 if (!--header->count)
1924 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001925 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926}
1927
Al Viro90434762008-07-15 08:54:06 -04001928int sysctl_is_seen(struct ctl_table_header *p)
1929{
1930 struct ctl_table_set *set = p->set;
1931 int res;
1932 spin_lock(&sysctl_lock);
1933 if (p->unregistering)
1934 res = 0;
1935 else if (!set->is_seen)
1936 res = 1;
1937 else
1938 res = set->is_seen(set);
1939 spin_unlock(&sysctl_lock);
1940 return res;
1941}
1942
Al Viro73455092008-07-14 21:22:20 -04001943void setup_sysctl_set(struct ctl_table_set *p,
1944 struct ctl_table_set *parent,
1945 int (*is_seen)(struct ctl_table_set *))
1946{
1947 INIT_LIST_HEAD(&p->list);
1948 p->parent = parent ? parent : &sysctl_table_root.default_set;
1949 p->is_seen = is_seen;
1950}
1951
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001952#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001953struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001954{
1955 return NULL;
1956}
1957
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001958struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1959 struct ctl_table *table)
1960{
1961 return NULL;
1962}
1963
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001964void unregister_sysctl_table(struct ctl_table_header * table)
1965{
1966}
1967
Al Viro73455092008-07-14 21:22:20 -04001968void setup_sysctl_set(struct ctl_table_set *p,
1969 struct ctl_table_set *parent,
1970 int (*is_seen)(struct ctl_table_set *))
1971{
1972}
1973
Al Virof7e6ced2008-07-15 01:44:23 -04001974void sysctl_head_put(struct ctl_table_header *head)
1975{
1976}
1977
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001978#endif /* CONFIG_SYSCTL */
1979
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980/*
1981 * /proc/sys support
1982 */
1983
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001984#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001986static int _proc_do_string(void* data, int maxlen, int write,
1987 struct file *filp, void __user *buffer,
1988 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001989{
1990 size_t len;
1991 char __user *p;
1992 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001993
1994 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001995 *lenp = 0;
1996 return 0;
1997 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001998
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001999 if (write) {
2000 len = 0;
2001 p = buffer;
2002 while (len < *lenp) {
2003 if (get_user(c, p++))
2004 return -EFAULT;
2005 if (c == 0 || c == '\n')
2006 break;
2007 len++;
2008 }
2009 if (len >= maxlen)
2010 len = maxlen-1;
2011 if(copy_from_user(data, buffer, len))
2012 return -EFAULT;
2013 ((char *) data)[len] = 0;
2014 *ppos += *lenp;
2015 } else {
2016 len = strlen(data);
2017 if (len > maxlen)
2018 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002019
2020 if (*ppos > len) {
2021 *lenp = 0;
2022 return 0;
2023 }
2024
2025 data += *ppos;
2026 len -= *ppos;
2027
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002028 if (len > *lenp)
2029 len = *lenp;
2030 if (len)
2031 if(copy_to_user(buffer, data, len))
2032 return -EFAULT;
2033 if (len < *lenp) {
2034 if(put_user('\n', ((char __user *) buffer) + len))
2035 return -EFAULT;
2036 len++;
2037 }
2038 *lenp = len;
2039 *ppos += len;
2040 }
2041 return 0;
2042}
2043
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044/**
2045 * proc_dostring - read a string sysctl
2046 * @table: the sysctl table
2047 * @write: %TRUE if this is a write to the sysctl file
2048 * @filp: the file structure
2049 * @buffer: the user buffer
2050 * @lenp: the size of the user buffer
2051 * @ppos: file position
2052 *
2053 * Reads/writes a string from/to the user buffer. If the kernel
2054 * buffer provided is not large enough to hold the string, the
2055 * string is truncated. The copied string is %NULL-terminated.
2056 * If the string is being read by the user process, it is copied
2057 * and a newline '\n' is added. It is truncated if the buffer is
2058 * not large enough.
2059 *
2060 * Returns 0 on success.
2061 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002062int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 void __user *buffer, size_t *lenp, loff_t *ppos)
2064{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002065 return _proc_do_string(table->data, table->maxlen, write, filp,
2066 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067}
2068
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
2070static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2071 int *valp,
2072 int write, void *data)
2073{
2074 if (write) {
2075 *valp = *negp ? -*lvalp : *lvalp;
2076 } else {
2077 int val = *valp;
2078 if (val < 0) {
2079 *negp = -1;
2080 *lvalp = (unsigned long)-val;
2081 } else {
2082 *negp = 0;
2083 *lvalp = (unsigned long)val;
2084 }
2085 }
2086 return 0;
2087}
2088
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002089static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002090 int write, struct file *filp, void __user *buffer,
2091 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2093 int write, void *data),
2094 void *data)
2095{
2096#define TMPBUFLEN 21
2097 int *i, vleft, first=1, neg, val;
2098 unsigned long lval;
2099 size_t left, len;
2100
2101 char buf[TMPBUFLEN], *p;
2102 char __user *s = buffer;
2103
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002104 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 (*ppos && !write)) {
2106 *lenp = 0;
2107 return 0;
2108 }
2109
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002110 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 vleft = table->maxlen / sizeof(*i);
2112 left = *lenp;
2113
2114 if (!conv)
2115 conv = do_proc_dointvec_conv;
2116
2117 for (; left && vleft--; i++, first=0) {
2118 if (write) {
2119 while (left) {
2120 char c;
2121 if (get_user(c, s))
2122 return -EFAULT;
2123 if (!isspace(c))
2124 break;
2125 left--;
2126 s++;
2127 }
2128 if (!left)
2129 break;
2130 neg = 0;
2131 len = left;
2132 if (len > sizeof(buf) - 1)
2133 len = sizeof(buf) - 1;
2134 if (copy_from_user(buf, s, len))
2135 return -EFAULT;
2136 buf[len] = 0;
2137 p = buf;
2138 if (*p == '-' && left > 1) {
2139 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002140 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 }
2142 if (*p < '0' || *p > '9')
2143 break;
2144
2145 lval = simple_strtoul(p, &p, 0);
2146
2147 len = p-buf;
2148 if ((len < left) && *p && !isspace(*p))
2149 break;
2150 if (neg)
2151 val = -val;
2152 s += len;
2153 left -= len;
2154
2155 if (conv(&neg, &lval, i, 1, data))
2156 break;
2157 } else {
2158 p = buf;
2159 if (!first)
2160 *p++ = '\t';
2161
2162 if (conv(&neg, &lval, i, 0, data))
2163 break;
2164
2165 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2166 len = strlen(buf);
2167 if (len > left)
2168 len = left;
2169 if(copy_to_user(s, buf, len))
2170 return -EFAULT;
2171 left -= len;
2172 s += len;
2173 }
2174 }
2175
2176 if (!write && !first && left) {
2177 if(put_user('\n', s))
2178 return -EFAULT;
2179 left--, s++;
2180 }
2181 if (write) {
2182 while (left) {
2183 char c;
2184 if (get_user(c, s++))
2185 return -EFAULT;
2186 if (!isspace(c))
2187 break;
2188 left--;
2189 }
2190 }
2191 if (write && first)
2192 return -EINVAL;
2193 *lenp -= left;
2194 *ppos += *lenp;
2195 return 0;
2196#undef TMPBUFLEN
2197}
2198
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002199static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002200 void __user *buffer, size_t *lenp, loff_t *ppos,
2201 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2202 int write, void *data),
2203 void *data)
2204{
2205 return __do_proc_dointvec(table->data, table, write, filp,
2206 buffer, lenp, ppos, conv, data);
2207}
2208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209/**
2210 * proc_dointvec - read a vector of integers
2211 * @table: the sysctl table
2212 * @write: %TRUE if this is a write to the sysctl file
2213 * @filp: the file structure
2214 * @buffer: the user buffer
2215 * @lenp: the size of the user buffer
2216 * @ppos: file position
2217 *
2218 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2219 * values from/to the user buffer, treated as an ASCII string.
2220 *
2221 * Returns 0 on success.
2222 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002223int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 void __user *buffer, size_t *lenp, loff_t *ppos)
2225{
2226 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2227 NULL,NULL);
2228}
2229
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002230/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002231 * Taint values can only be increased
2232 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002233 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002234static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002235 void __user *buffer, size_t *lenp, loff_t *ppos)
2236{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002237 struct ctl_table t;
2238 unsigned long tmptaint = get_taint();
2239 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002240
Bastian Blank91fcd412007-04-23 14:41:14 -07002241 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002242 return -EPERM;
2243
Andi Kleen25ddbb12008-10-15 22:01:41 -07002244 t = *table;
2245 t.data = &tmptaint;
2246 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2247 if (err < 0)
2248 return err;
2249
2250 if (write) {
2251 /*
2252 * Poor man's atomic or. Not worth adding a primitive
2253 * to everyone's atomic.h for this
2254 */
2255 int i;
2256 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2257 if ((tmptaint >> i) & 1)
2258 add_taint(i);
2259 }
2260 }
2261
2262 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002263}
2264
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265struct do_proc_dointvec_minmax_conv_param {
2266 int *min;
2267 int *max;
2268};
2269
2270static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2271 int *valp,
2272 int write, void *data)
2273{
2274 struct do_proc_dointvec_minmax_conv_param *param = data;
2275 if (write) {
2276 int val = *negp ? -*lvalp : *lvalp;
2277 if ((param->min && *param->min > val) ||
2278 (param->max && *param->max < val))
2279 return -EINVAL;
2280 *valp = val;
2281 } else {
2282 int val = *valp;
2283 if (val < 0) {
2284 *negp = -1;
2285 *lvalp = (unsigned long)-val;
2286 } else {
2287 *negp = 0;
2288 *lvalp = (unsigned long)val;
2289 }
2290 }
2291 return 0;
2292}
2293
2294/**
2295 * proc_dointvec_minmax - read a vector of integers with min/max values
2296 * @table: the sysctl table
2297 * @write: %TRUE if this is a write to the sysctl file
2298 * @filp: the file structure
2299 * @buffer: the user buffer
2300 * @lenp: the size of the user buffer
2301 * @ppos: file position
2302 *
2303 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2304 * values from/to the user buffer, treated as an ASCII string.
2305 *
2306 * This routine will ensure the values are within the range specified by
2307 * table->extra1 (min) and table->extra2 (max).
2308 *
2309 * Returns 0 on success.
2310 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002311int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 void __user *buffer, size_t *lenp, loff_t *ppos)
2313{
2314 struct do_proc_dointvec_minmax_conv_param param = {
2315 .min = (int *) table->extra1,
2316 .max = (int *) table->extra2,
2317 };
2318 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2319 do_proc_dointvec_minmax_conv, &param);
2320}
2321
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002322static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 struct file *filp,
2324 void __user *buffer,
2325 size_t *lenp, loff_t *ppos,
2326 unsigned long convmul,
2327 unsigned long convdiv)
2328{
2329#define TMPBUFLEN 21
2330 unsigned long *i, *min, *max, val;
2331 int vleft, first=1, neg;
2332 size_t len, left;
2333 char buf[TMPBUFLEN], *p;
2334 char __user *s = buffer;
2335
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002336 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 (*ppos && !write)) {
2338 *lenp = 0;
2339 return 0;
2340 }
2341
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002342 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 min = (unsigned long *) table->extra1;
2344 max = (unsigned long *) table->extra2;
2345 vleft = table->maxlen / sizeof(unsigned long);
2346 left = *lenp;
2347
2348 for (; left && vleft--; i++, min++, max++, first=0) {
2349 if (write) {
2350 while (left) {
2351 char c;
2352 if (get_user(c, s))
2353 return -EFAULT;
2354 if (!isspace(c))
2355 break;
2356 left--;
2357 s++;
2358 }
2359 if (!left)
2360 break;
2361 neg = 0;
2362 len = left;
2363 if (len > TMPBUFLEN-1)
2364 len = TMPBUFLEN-1;
2365 if (copy_from_user(buf, s, len))
2366 return -EFAULT;
2367 buf[len] = 0;
2368 p = buf;
2369 if (*p == '-' && left > 1) {
2370 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002371 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 }
2373 if (*p < '0' || *p > '9')
2374 break;
2375 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2376 len = p-buf;
2377 if ((len < left) && *p && !isspace(*p))
2378 break;
2379 if (neg)
2380 val = -val;
2381 s += len;
2382 left -= len;
2383
2384 if(neg)
2385 continue;
2386 if ((min && val < *min) || (max && val > *max))
2387 continue;
2388 *i = val;
2389 } else {
2390 p = buf;
2391 if (!first)
2392 *p++ = '\t';
2393 sprintf(p, "%lu", convdiv * (*i) / convmul);
2394 len = strlen(buf);
2395 if (len > left)
2396 len = left;
2397 if(copy_to_user(s, buf, len))
2398 return -EFAULT;
2399 left -= len;
2400 s += len;
2401 }
2402 }
2403
2404 if (!write && !first && left) {
2405 if(put_user('\n', s))
2406 return -EFAULT;
2407 left--, s++;
2408 }
2409 if (write) {
2410 while (left) {
2411 char c;
2412 if (get_user(c, s++))
2413 return -EFAULT;
2414 if (!isspace(c))
2415 break;
2416 left--;
2417 }
2418 }
2419 if (write && first)
2420 return -EINVAL;
2421 *lenp -= left;
2422 *ppos += *lenp;
2423 return 0;
2424#undef TMPBUFLEN
2425}
2426
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002427static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002428 struct file *filp,
2429 void __user *buffer,
2430 size_t *lenp, loff_t *ppos,
2431 unsigned long convmul,
2432 unsigned long convdiv)
2433{
2434 return __do_proc_doulongvec_minmax(table->data, table, write,
2435 filp, buffer, lenp, ppos, convmul, convdiv);
2436}
2437
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438/**
2439 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2440 * @table: the sysctl table
2441 * @write: %TRUE if this is a write to the sysctl file
2442 * @filp: the file structure
2443 * @buffer: the user buffer
2444 * @lenp: the size of the user buffer
2445 * @ppos: file position
2446 *
2447 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2448 * values from/to the user buffer, treated as an ASCII string.
2449 *
2450 * This routine will ensure the values are within the range specified by
2451 * table->extra1 (min) and table->extra2 (max).
2452 *
2453 * Returns 0 on success.
2454 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002455int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 void __user *buffer, size_t *lenp, loff_t *ppos)
2457{
2458 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2459}
2460
2461/**
2462 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2463 * @table: the sysctl table
2464 * @write: %TRUE if this is a write to the sysctl file
2465 * @filp: the file structure
2466 * @buffer: the user buffer
2467 * @lenp: the size of the user buffer
2468 * @ppos: file position
2469 *
2470 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2471 * values from/to the user buffer, treated as an ASCII string. The values
2472 * are treated as milliseconds, and converted to jiffies when they are stored.
2473 *
2474 * This routine will ensure the values are within the range specified by
2475 * table->extra1 (min) and table->extra2 (max).
2476 *
2477 * Returns 0 on success.
2478 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002479int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 struct file *filp,
2481 void __user *buffer,
2482 size_t *lenp, loff_t *ppos)
2483{
2484 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2485 lenp, ppos, HZ, 1000l);
2486}
2487
2488
2489static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2490 int *valp,
2491 int write, void *data)
2492{
2493 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002494 if (*lvalp > LONG_MAX / HZ)
2495 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2497 } else {
2498 int val = *valp;
2499 unsigned long lval;
2500 if (val < 0) {
2501 *negp = -1;
2502 lval = (unsigned long)-val;
2503 } else {
2504 *negp = 0;
2505 lval = (unsigned long)val;
2506 }
2507 *lvalp = lval / HZ;
2508 }
2509 return 0;
2510}
2511
2512static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2513 int *valp,
2514 int write, void *data)
2515{
2516 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002517 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2518 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2520 } else {
2521 int val = *valp;
2522 unsigned long lval;
2523 if (val < 0) {
2524 *negp = -1;
2525 lval = (unsigned long)-val;
2526 } else {
2527 *negp = 0;
2528 lval = (unsigned long)val;
2529 }
2530 *lvalp = jiffies_to_clock_t(lval);
2531 }
2532 return 0;
2533}
2534
2535static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2536 int *valp,
2537 int write, void *data)
2538{
2539 if (write) {
2540 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2541 } else {
2542 int val = *valp;
2543 unsigned long lval;
2544 if (val < 0) {
2545 *negp = -1;
2546 lval = (unsigned long)-val;
2547 } else {
2548 *negp = 0;
2549 lval = (unsigned long)val;
2550 }
2551 *lvalp = jiffies_to_msecs(lval);
2552 }
2553 return 0;
2554}
2555
2556/**
2557 * proc_dointvec_jiffies - read a vector of integers as seconds
2558 * @table: the sysctl table
2559 * @write: %TRUE if this is a write to the sysctl file
2560 * @filp: the file structure
2561 * @buffer: the user buffer
2562 * @lenp: the size of the user buffer
2563 * @ppos: file position
2564 *
2565 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2566 * values from/to the user buffer, treated as an ASCII string.
2567 * The values read are assumed to be in seconds, and are converted into
2568 * jiffies.
2569 *
2570 * Returns 0 on success.
2571 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002572int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 void __user *buffer, size_t *lenp, loff_t *ppos)
2574{
2575 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2576 do_proc_dointvec_jiffies_conv,NULL);
2577}
2578
2579/**
2580 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2581 * @table: the sysctl table
2582 * @write: %TRUE if this is a write to the sysctl file
2583 * @filp: the file structure
2584 * @buffer: the user buffer
2585 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002586 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 *
2588 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2589 * values from/to the user buffer, treated as an ASCII string.
2590 * The values read are assumed to be in 1/USER_HZ seconds, and
2591 * are converted into jiffies.
2592 *
2593 * Returns 0 on success.
2594 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002595int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 void __user *buffer, size_t *lenp, loff_t *ppos)
2597{
2598 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2599 do_proc_dointvec_userhz_jiffies_conv,NULL);
2600}
2601
2602/**
2603 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2604 * @table: the sysctl table
2605 * @write: %TRUE if this is a write to the sysctl file
2606 * @filp: the file structure
2607 * @buffer: the user buffer
2608 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002609 * @ppos: file position
2610 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 *
2612 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2613 * values from/to the user buffer, treated as an ASCII string.
2614 * The values read are assumed to be in 1/1000 seconds, and
2615 * are converted into jiffies.
2616 *
2617 * Returns 0 on success.
2618 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002619int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 void __user *buffer, size_t *lenp, loff_t *ppos)
2621{
2622 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2623 do_proc_dointvec_ms_jiffies_conv, NULL);
2624}
2625
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002626static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002627 void __user *buffer, size_t *lenp, loff_t *ppos)
2628{
2629 struct pid *new_pid;
2630 pid_t tmp;
2631 int r;
2632
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002633 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002634
2635 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2636 lenp, ppos, NULL, NULL);
2637 if (r || !write)
2638 return r;
2639
2640 new_pid = find_get_pid(tmp);
2641 if (!new_pid)
2642 return -ESRCH;
2643
2644 put_pid(xchg(&cad_pid, new_pid));
2645 return 0;
2646}
2647
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648#else /* CONFIG_PROC_FS */
2649
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002650int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 void __user *buffer, size_t *lenp, loff_t *ppos)
2652{
2653 return -ENOSYS;
2654}
2655
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002656int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 void __user *buffer, size_t *lenp, loff_t *ppos)
2658{
2659 return -ENOSYS;
2660}
2661
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002662int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 void __user *buffer, size_t *lenp, loff_t *ppos)
2664{
2665 return -ENOSYS;
2666}
2667
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002668int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 void __user *buffer, size_t *lenp, loff_t *ppos)
2670{
2671 return -ENOSYS;
2672}
2673
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002674int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 void __user *buffer, size_t *lenp, loff_t *ppos)
2676{
2677 return -ENOSYS;
2678}
2679
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002680int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 void __user *buffer, size_t *lenp, loff_t *ppos)
2682{
2683 return -ENOSYS;
2684}
2685
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002686int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 void __user *buffer, size_t *lenp, loff_t *ppos)
2688{
2689 return -ENOSYS;
2690}
2691
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002692int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 struct file *filp,
2694 void __user *buffer,
2695 size_t *lenp, loff_t *ppos)
2696{
2697 return -ENOSYS;
2698}
2699
2700
2701#endif /* CONFIG_PROC_FS */
2702
2703
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002704#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705/*
2706 * General sysctl support routines
2707 */
2708
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002709/* The generic sysctl data routine (used if no strategy routine supplied) */
2710int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2711 void __user *oldval, size_t __user *oldlenp,
2712 void __user *newval, size_t newlen)
2713{
2714 size_t len;
2715
2716 /* Get out of I don't have a variable */
2717 if (!table->data || !table->maxlen)
2718 return -ENOTDIR;
2719
2720 if (oldval && oldlenp) {
2721 if (get_user(len, oldlenp))
2722 return -EFAULT;
2723 if (len) {
2724 if (len > table->maxlen)
2725 len = table->maxlen;
2726 if (copy_to_user(oldval, table->data, len))
2727 return -EFAULT;
2728 if (put_user(len, oldlenp))
2729 return -EFAULT;
2730 }
2731 }
2732
2733 if (newval && newlen) {
2734 if (newlen > table->maxlen)
2735 newlen = table->maxlen;
2736
2737 if (copy_from_user(table->data, newval, newlen))
2738 return -EFAULT;
2739 }
2740 return 1;
2741}
2742
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002744int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002746 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 if (!table->data || !table->maxlen)
2749 return -ENOTDIR;
2750
2751 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002752 size_t bufsize;
2753 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002755 if (bufsize) {
2756 size_t len = strlen(table->data), copied;
2757
2758 /* This shouldn't trigger for a well-formed sysctl */
2759 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002761
2762 /* Copy up to a max of bufsize-1 bytes of the string */
2763 copied = (len >= bufsize) ? bufsize - 1 : len;
2764
2765 if (copy_to_user(oldval, table->data, copied) ||
2766 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002768 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 return -EFAULT;
2770 }
2771 }
2772 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002773 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 if (len > table->maxlen)
2775 len = table->maxlen;
2776 if(copy_from_user(table->data, newval, len))
2777 return -EFAULT;
2778 if (len == table->maxlen)
2779 len--;
2780 ((char *) table->data)[len] = 0;
2781 }
Yi Yang82c9df82005-12-30 16:37:10 +08002782 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783}
2784
2785/*
2786 * This function makes sure that all of the integers in the vector
2787 * are between the minimum and maximum values given in the arrays
2788 * table->extra1 and table->extra2, respectively.
2789 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002790int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002792 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793{
2794
2795 if (newval && newlen) {
2796 int __user *vec = (int __user *) newval;
2797 int *min = (int *) table->extra1;
2798 int *max = (int *) table->extra2;
2799 size_t length;
2800 int i;
2801
2802 if (newlen % sizeof(int) != 0)
2803 return -EINVAL;
2804
2805 if (!table->extra1 && !table->extra2)
2806 return 0;
2807
2808 if (newlen > table->maxlen)
2809 newlen = table->maxlen;
2810 length = newlen / sizeof(int);
2811
2812 for (i = 0; i < length; i++) {
2813 int value;
2814 if (get_user(value, vec + i))
2815 return -EFAULT;
2816 if (min && value < min[i])
2817 return -EINVAL;
2818 if (max && value > max[i])
2819 return -EINVAL;
2820 }
2821 }
2822 return 0;
2823}
2824
2825/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002826int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002828 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002830 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002832
2833 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002835 if (olen) {
2836 int val;
2837
2838 if (olen < sizeof(int))
2839 return -EINVAL;
2840
2841 val = *(int *)(table->data) / HZ;
2842 if (put_user(val, (int __user *)oldval))
2843 return -EFAULT;
2844 if (put_user(sizeof(int), oldlenp))
2845 return -EFAULT;
2846 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 }
2848 if (newval && newlen) {
2849 int new;
2850 if (newlen != sizeof(int))
2851 return -EINVAL;
2852 if (get_user(new, (int __user *)newval))
2853 return -EFAULT;
2854 *(int *)(table->data) = new*HZ;
2855 }
2856 return 1;
2857}
2858
2859/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002860int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002862 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002864 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002866
2867 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002869 if (olen) {
2870 int val;
2871
2872 if (olen < sizeof(int))
2873 return -EINVAL;
2874
2875 val = jiffies_to_msecs(*(int *)(table->data));
2876 if (put_user(val, (int __user *)oldval))
2877 return -EFAULT;
2878 if (put_user(sizeof(int), oldlenp))
2879 return -EFAULT;
2880 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 }
2882 if (newval && newlen) {
2883 int new;
2884 if (newlen != sizeof(int))
2885 return -EINVAL;
2886 if (get_user(new, (int __user *)newval))
2887 return -EFAULT;
2888 *(int *)(table->data) = msecs_to_jiffies(new);
2889 }
2890 return 1;
2891}
2892
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002893
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002894
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002895#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
2897
2898asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2899{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002900 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002901 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002902
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002903 if (copy_from_user(&tmp, args, sizeof(tmp)))
2904 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002905
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002906 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002907
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002908 /* If no error reading the parameters then just -ENOSYS ... */
2909 if (!error)
2910 error = -ENOSYS;
2911
2912 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913}
2914
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002915int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2916 void __user *oldval, size_t __user *oldlenp,
2917 void __user *newval, size_t newlen)
2918{
2919 return -ENOSYS;
2920}
2921
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002922int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002924 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925{
2926 return -ENOSYS;
2927}
2928
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002929int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002931 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932{
2933 return -ENOSYS;
2934}
2935
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002936int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002938 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939{
2940 return -ENOSYS;
2941}
2942
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002943int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002945 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946{
2947 return -ENOSYS;
2948}
2949
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002950#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002952static int deprecated_sysctl_warning(struct __sysctl_args *args)
2953{
2954 static int msg_count;
2955 int name[CTL_MAXNAME];
2956 int i;
2957
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002958 /* Check args->nlen. */
2959 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2960 return -ENOTDIR;
2961
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002962 /* Read in the sysctl name for better debug message logging */
2963 for (i = 0; i < args->nlen; i++)
2964 if (get_user(name[i], args->name + i))
2965 return -EFAULT;
2966
2967 /* Ignore accesses to kernel.version */
2968 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2969 return 0;
2970
2971 if (msg_count < 5) {
2972 msg_count++;
2973 printk(KERN_INFO
2974 "warning: process `%s' used the deprecated sysctl "
2975 "system call with ", current->comm);
2976 for (i = 0; i < args->nlen; i++)
2977 printk("%d.", name[i]);
2978 printk("\n");
2979 }
2980 return 0;
2981}
2982
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983/*
2984 * No sense putting this after each symbol definition, twice,
2985 * exception granted :-)
2986 */
2987EXPORT_SYMBOL(proc_dointvec);
2988EXPORT_SYMBOL(proc_dointvec_jiffies);
2989EXPORT_SYMBOL(proc_dointvec_minmax);
2990EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2991EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2992EXPORT_SYMBOL(proc_dostring);
2993EXPORT_SYMBOL(proc_doulongvec_minmax);
2994EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2995EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002996EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997EXPORT_SYMBOL(sysctl_intvec);
2998EXPORT_SYMBOL(sysctl_jiffies);
2999EXPORT_SYMBOL(sysctl_ms_jiffies);
3000EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003001EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002EXPORT_SYMBOL(unregister_sysctl_table);