blob: 3e38b74b6124a6e057e15194a503da9c427d332c [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 Mundtdd8632a2009-01-08 12:04:47 +000085#ifndef CONFIG_MMU
86extern int sysctl_nr_trim_pages;
87#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070088#ifdef CONFIG_RCU_TORTURE_TEST
89extern int rcutorture_runnable;
90#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080093#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070094static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020095static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096#endif
97
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +020098#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int two = 2;
100#endif
101
102static int zero;
David Rientjes2da02992009-01-06 14:39:31 -0800103static int one = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700104static 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
David S. Miller08714202008-11-16 23:49:24 -0800124#ifdef CONFIG_SPARC64
125extern int sysctl_tsb_ratio;
126#endif
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef __hppa__
129extern int pwrsw_enabled;
130extern int unaligned_enabled;
131#endif
132
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800133#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef CONFIG_MATHEMU
135extern int sysctl_ieee_emulation_warnings;
136#endif
137extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700138extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#endif
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#ifdef CONFIG_BSD_PROCESS_ACCT
142extern int acct_parm[];
143#endif
144
Jes Sorensend2b176e2006-02-28 09:42:23 -0800145#ifdef CONFIG_IA64
146extern int no_unaligned_warning;
147#endif
148
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700149#ifdef CONFIG_RT_MUTEXES
150extern int max_lock_depth;
151#endif
152
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700153#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700154static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700156static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800157 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700158#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700159
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700160static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100161static struct ctl_table_root sysctl_table_root;
162static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100163 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100164 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400165 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100166 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400167 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168};
169static struct ctl_table_root sysctl_table_root = {
170 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400171 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100172};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700174static struct ctl_table kern_table[];
175static struct ctl_table vm_table[];
176static struct ctl_table fs_table[];
177static struct ctl_table debug_table[];
178static struct ctl_table dev_table[];
179extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700180#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700181extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400182#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800183#ifdef CONFIG_EPOLL
184extern struct ctl_table epoll_table[];
185#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
188int sysctl_legacy_va_layout;
189#endif
190
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700191extern int prove_locking;
192extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194/* The default sysctl tables: */
195
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700196static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 {
198 .ctl_name = CTL_KERN,
199 .procname = "kernel",
200 .mode = 0555,
201 .child = kern_table,
202 },
203 {
204 .ctl_name = CTL_VM,
205 .procname = "vm",
206 .mode = 0555,
207 .child = vm_table,
208 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 .ctl_name = CTL_FS,
211 .procname = "fs",
212 .mode = 0555,
213 .child = fs_table,
214 },
215 {
216 .ctl_name = CTL_DEBUG,
217 .procname = "debug",
218 .mode = 0555,
219 .child = debug_table,
220 },
221 {
222 .ctl_name = CTL_DEV,
223 .procname = "dev",
224 .mode = 0555,
225 .child = dev_table,
226 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700227/*
228 * NOTE: do not add new entries to this table unless you have read
229 * Documentation/sysctl/ctl_unnumbered.txt
230 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 { .ctl_name = 0 }
232};
233
Ingo Molnar77e54a12007-07-09 18:52:00 +0200234#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100235static int min_sched_granularity_ns = 100000; /* 100 usecs */
236static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
237static int min_wakeup_granularity_ns; /* 0 usecs */
238static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200239#endif
240
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700241static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200242#ifdef CONFIG_SCHED_DEBUG
243 {
244 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100245 .procname = "sched_min_granularity_ns",
246 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200247 .maxlen = sizeof(unsigned int),
248 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100249 .proc_handler = &sched_nr_latency_handler,
250 .strategy = &sysctl_intvec,
251 .extra1 = &min_sched_granularity_ns,
252 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200253 },
254 {
255 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200256 .procname = "sched_latency_ns",
257 .data = &sysctl_sched_latency,
258 .maxlen = sizeof(unsigned int),
259 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100260 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200261 .strategy = &sysctl_intvec,
262 .extra1 = &min_sched_granularity_ns,
263 .extra2 = &max_sched_granularity_ns,
264 },
265 {
266 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200267 .procname = "sched_wakeup_granularity_ns",
268 .data = &sysctl_sched_wakeup_granularity,
269 .maxlen = sizeof(unsigned int),
270 .mode = 0644,
271 .proc_handler = &proc_dointvec_minmax,
272 .strategy = &sysctl_intvec,
273 .extra1 = &min_wakeup_granularity_ns,
274 .extra2 = &max_wakeup_granularity_ns,
275 },
276 {
277 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200278 .procname = "sched_shares_ratelimit",
279 .data = &sysctl_sched_shares_ratelimit,
280 .maxlen = sizeof(unsigned int),
281 .mode = 0644,
282 .proc_handler = &proc_dointvec,
283 },
284 {
285 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200286 .procname = "sched_shares_thresh",
287 .data = &sysctl_sched_shares_thresh,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec_minmax,
291 .strategy = &sysctl_intvec,
292 .extra1 = &zero,
293 },
294 {
295 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200296 .procname = "sched_child_runs_first",
297 .data = &sysctl_sched_child_runs_first,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
300 .proc_handler = &proc_dointvec,
301 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200302 {
303 .ctl_name = CTL_UNNUMBERED,
304 .procname = "sched_features",
305 .data = &sysctl_sched_features,
306 .maxlen = sizeof(unsigned int),
307 .mode = 0644,
308 .proc_handler = &proc_dointvec,
309 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200310 {
311 .ctl_name = CTL_UNNUMBERED,
312 .procname = "sched_migration_cost",
313 .data = &sysctl_sched_migration_cost,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
316 .proc_handler = &proc_dointvec,
317 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100318 {
319 .ctl_name = CTL_UNNUMBERED,
320 .procname = "sched_nr_migrate",
321 .data = &sysctl_sched_nr_migrate,
322 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100323 .mode = 0644,
324 .proc_handler = &proc_dointvec,
325 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200326#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200327 {
328 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100329 .procname = "sched_rt_period_us",
330 .data = &sysctl_sched_rt_period,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200333 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100334 },
335 {
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "sched_rt_runtime_us",
338 .data = &sysctl_sched_rt_runtime,
339 .maxlen = sizeof(int),
340 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200341 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100342 },
343 {
344 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200345 .procname = "sched_compat_yield",
346 .data = &sysctl_sched_compat_yield,
347 .maxlen = sizeof(unsigned int),
348 .mode = 0644,
349 .proc_handler = &proc_dointvec,
350 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700351#ifdef CONFIG_PROVE_LOCKING
352 {
353 .ctl_name = CTL_UNNUMBERED,
354 .procname = "prove_locking",
355 .data = &prove_locking,
356 .maxlen = sizeof(int),
357 .mode = 0644,
358 .proc_handler = &proc_dointvec,
359 },
360#endif
361#ifdef CONFIG_LOCK_STAT
362 {
363 .ctl_name = CTL_UNNUMBERED,
364 .procname = "lock_stat",
365 .data = &lock_stat,
366 .maxlen = sizeof(int),
367 .mode = 0644,
368 .proc_handler = &proc_dointvec,
369 },
370#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200371 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 .ctl_name = KERN_PANIC,
373 .procname = "panic",
374 .data = &panic_timeout,
375 .maxlen = sizeof(int),
376 .mode = 0644,
377 .proc_handler = &proc_dointvec,
378 },
379 {
380 .ctl_name = KERN_CORE_USES_PID,
381 .procname = "core_uses_pid",
382 .data = &core_uses_pid,
383 .maxlen = sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
386 },
387 {
388 .ctl_name = KERN_CORE_PATTERN,
389 .procname = "core_pattern",
390 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700391 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 .mode = 0644,
393 .proc_handler = &proc_dostring,
394 .strategy = &sysctl_string,
395 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800396#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700399 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800400 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700401 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800403#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100404#ifdef CONFIG_LATENCYTOP
405 {
406 .procname = "latencytop",
407 .data = &latencytop_enabled,
408 .maxlen = sizeof(int),
409 .mode = 0644,
410 .proc_handler = &proc_dointvec,
411 },
412#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413#ifdef CONFIG_BLK_DEV_INITRD
414 {
415 .ctl_name = KERN_REALROOTDEV,
416 .procname = "real-root-dev",
417 .data = &real_root_dev,
418 .maxlen = sizeof(int),
419 .mode = 0644,
420 .proc_handler = &proc_dointvec,
421 },
422#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700423 {
424 .ctl_name = CTL_UNNUMBERED,
425 .procname = "print-fatal-signals",
426 .data = &print_fatal_signals,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700431#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 {
433 .ctl_name = KERN_SPARC_REBOOT,
434 .procname = "reboot-cmd",
435 .data = reboot_command,
436 .maxlen = 256,
437 .mode = 0644,
438 .proc_handler = &proc_dostring,
439 .strategy = &sysctl_string,
440 },
441 {
442 .ctl_name = KERN_SPARC_STOP_A,
443 .procname = "stop-a",
444 .data = &stop_a_enabled,
445 .maxlen = sizeof (int),
446 .mode = 0644,
447 .proc_handler = &proc_dointvec,
448 },
449 {
450 .ctl_name = KERN_SPARC_SCONS_PWROFF,
451 .procname = "scons-poweroff",
452 .data = &scons_pwroff,
453 .maxlen = sizeof (int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
456 },
457#endif
David S. Miller08714202008-11-16 23:49:24 -0800458#ifdef CONFIG_SPARC64
459 {
460 .ctl_name = CTL_UNNUMBERED,
461 .procname = "tsb-ratio",
462 .data = &sysctl_tsb_ratio,
463 .maxlen = sizeof (int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
466 },
467#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#ifdef __hppa__
469 {
470 .ctl_name = KERN_HPPA_PWRSW,
471 .procname = "soft-power",
472 .data = &pwrsw_enabled,
473 .maxlen = sizeof (int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec,
476 },
477 {
478 .ctl_name = KERN_HPPA_UNALIGNED,
479 .procname = "unaligned-trap",
480 .data = &unaligned_enabled,
481 .maxlen = sizeof (int),
482 .mode = 0644,
483 .proc_handler = &proc_dointvec,
484 },
485#endif
486 {
487 .ctl_name = KERN_CTLALTDEL,
488 .procname = "ctrl-alt-del",
489 .data = &C_A_D,
490 .maxlen = sizeof(int),
491 .mode = 0644,
492 .proc_handler = &proc_dointvec,
493 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400494#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200495 {
496 .ctl_name = CTL_UNNUMBERED,
497 .procname = "ftrace_enabled",
498 .data = &ftrace_enabled,
499 .maxlen = sizeof(int),
500 .mode = 0644,
501 .proc_handler = &ftrace_enable_sysctl,
502 },
503#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500504#ifdef CONFIG_STACK_TRACER
505 {
506 .ctl_name = CTL_UNNUMBERED,
507 .procname = "stack_tracer_enabled",
508 .data = &stack_tracer_enabled,
509 .maxlen = sizeof(int),
510 .mode = 0644,
511 .proc_handler = &stack_trace_sysctl,
512 },
513#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400514#ifdef CONFIG_TRACING
515 {
516 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100517 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400518 .data = &ftrace_dump_on_oops,
519 .maxlen = sizeof(int),
520 .mode = 0644,
521 .proc_handler = &proc_dointvec,
522 },
523#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200524#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 {
526 .ctl_name = KERN_MODPROBE,
527 .procname = "modprobe",
528 .data = &modprobe_path,
529 .maxlen = KMOD_PATH_LEN,
530 .mode = 0644,
531 .proc_handler = &proc_dostring,
532 .strategy = &sysctl_string,
533 },
534#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700535#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 {
537 .ctl_name = KERN_HOTPLUG,
538 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100539 .data = &uevent_helper,
540 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 .mode = 0644,
542 .proc_handler = &proc_dostring,
543 .strategy = &sysctl_string,
544 },
545#endif
546#ifdef CONFIG_CHR_DEV_SG
547 {
548 .ctl_name = KERN_SG_BIG_BUFF,
549 .procname = "sg-big-buff",
550 .data = &sg_big_buff,
551 .maxlen = sizeof (int),
552 .mode = 0444,
553 .proc_handler = &proc_dointvec,
554 },
555#endif
556#ifdef CONFIG_BSD_PROCESS_ACCT
557 {
558 .ctl_name = KERN_ACCT,
559 .procname = "acct",
560 .data = &acct_parm,
561 .maxlen = 3*sizeof(int),
562 .mode = 0644,
563 .proc_handler = &proc_dointvec,
564 },
565#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566#ifdef CONFIG_MAGIC_SYSRQ
567 {
568 .ctl_name = KERN_SYSRQ,
569 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800570 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .maxlen = sizeof (int),
572 .mode = 0644,
573 .proc_handler = &proc_dointvec,
574 },
575#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700576#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700579 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .maxlen = sizeof (int),
581 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700582 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700584#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 {
586 .ctl_name = KERN_MAX_THREADS,
587 .procname = "threads-max",
588 .data = &max_threads,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = &proc_dointvec,
592 },
593 {
594 .ctl_name = KERN_RANDOM,
595 .procname = "random",
596 .mode = 0555,
597 .child = random_table,
598 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 {
600 .ctl_name = KERN_OVERFLOWUID,
601 .procname = "overflowuid",
602 .data = &overflowuid,
603 .maxlen = sizeof(int),
604 .mode = 0644,
605 .proc_handler = &proc_dointvec_minmax,
606 .strategy = &sysctl_intvec,
607 .extra1 = &minolduid,
608 .extra2 = &maxolduid,
609 },
610 {
611 .ctl_name = KERN_OVERFLOWGID,
612 .procname = "overflowgid",
613 .data = &overflowgid,
614 .maxlen = sizeof(int),
615 .mode = 0644,
616 .proc_handler = &proc_dointvec_minmax,
617 .strategy = &sysctl_intvec,
618 .extra1 = &minolduid,
619 .extra2 = &maxolduid,
620 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800621#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#ifdef CONFIG_MATHEMU
623 {
624 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
625 .procname = "ieee_emulation_warnings",
626 .data = &sysctl_ieee_emulation_warnings,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = &proc_dointvec,
630 },
631#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 {
633 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
634 .procname = "userprocess_debug",
635 .data = &sysctl_userprocess_debug,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec,
639 },
640#endif
641 {
642 .ctl_name = KERN_PIDMAX,
643 .procname = "pid_max",
644 .data = &pid_max,
645 .maxlen = sizeof (int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec_minmax,
648 .strategy = sysctl_intvec,
649 .extra1 = &pid_max_min,
650 .extra2 = &pid_max_max,
651 },
652 {
653 .ctl_name = KERN_PANIC_ON_OOPS,
654 .procname = "panic_on_oops",
655 .data = &panic_on_oops,
656 .maxlen = sizeof(int),
657 .mode = 0644,
658 .proc_handler = &proc_dointvec,
659 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800660#if defined CONFIG_PRINTK
661 {
662 .ctl_name = KERN_PRINTK,
663 .procname = "printk",
664 .data = &console_loglevel,
665 .maxlen = 4*sizeof(int),
666 .mode = 0644,
667 .proc_handler = &proc_dointvec,
668 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 {
670 .ctl_name = KERN_PRINTK_RATELIMIT,
671 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700672 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = &proc_dointvec_jiffies,
676 .strategy = &sysctl_jiffies,
677 },
678 {
679 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
680 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700681 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 .maxlen = sizeof(int),
683 .mode = 0644,
684 .proc_handler = &proc_dointvec,
685 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800686#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 {
688 .ctl_name = KERN_NGROUPS_MAX,
689 .procname = "ngroups_max",
690 .data = &ngroups_max,
691 .maxlen = sizeof (int),
692 .mode = 0444,
693 .proc_handler = &proc_dointvec,
694 },
695#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
696 {
697 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
698 .procname = "unknown_nmi_panic",
699 .data = &unknown_nmi_panic,
700 .maxlen = sizeof (int),
701 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200702 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 },
Don Zickus407984f2006-09-26 10:52:27 +0200704 {
Don Zickus407984f2006-09-26 10:52:27 +0200705 .procname = "nmi_watchdog",
706 .data = &nmi_watchdog_enabled,
707 .maxlen = sizeof (int),
708 .mode = 0644,
709 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 },
711#endif
712#if defined(CONFIG_X86)
713 {
Don Zickus8da5add2006-09-26 10:52:27 +0200714 .ctl_name = KERN_PANIC_ON_NMI,
715 .procname = "panic_on_unrecovered_nmi",
716 .data = &panic_on_unrecovered_nmi,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = &proc_dointvec,
720 },
721 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 .ctl_name = KERN_BOOTLOADER_TYPE,
723 .procname = "bootloader_type",
724 .data = &bootloader_type,
725 .maxlen = sizeof (int),
726 .mode = 0444,
727 .proc_handler = &proc_dointvec,
728 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100729 {
730 .ctl_name = CTL_UNNUMBERED,
731 .procname = "kstack_depth_to_print",
732 .data = &kstack_depth_to_print,
733 .maxlen = sizeof(int),
734 .mode = 0644,
735 .proc_handler = &proc_dointvec,
736 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100737 {
738 .ctl_name = CTL_UNNUMBERED,
739 .procname = "io_delay_type",
740 .data = &io_delay_type,
741 .maxlen = sizeof(int),
742 .mode = 0644,
743 .proc_handler = &proc_dointvec,
744 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800746#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 {
748 .ctl_name = KERN_RANDOMIZE,
749 .procname = "randomize_va_space",
750 .data = &randomize_va_space,
751 .maxlen = sizeof(int),
752 .mode = 0644,
753 .proc_handler = &proc_dointvec,
754 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800755#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800756#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700757 {
758 .ctl_name = KERN_SPIN_RETRY,
759 .procname = "spin_retry",
760 .data = &spin_retry,
761 .maxlen = sizeof (int),
762 .mode = 0644,
763 .proc_handler = &proc_dointvec,
764 },
765#endif
Len Brown673d5b42007-07-28 03:33:16 -0400766#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800767 {
Pavel Machekc255d842006-02-20 18:27:58 -0800768 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700769 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800770 .maxlen = sizeof (unsigned long),
771 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800772 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800773 },
774#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800775#ifdef CONFIG_IA64
776 {
777 .ctl_name = KERN_IA64_UNALIGNED,
778 .procname = "ignore-unaligned-usertrap",
779 .data = &no_unaligned_warning,
780 .maxlen = sizeof (int),
781 .mode = 0644,
782 .proc_handler = &proc_dointvec,
783 },
784#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700785#ifdef CONFIG_DETECT_SOFTLOCKUP
786 {
787 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200788 .procname = "softlockup_panic",
789 .data = &softlockup_panic,
790 .maxlen = sizeof(int),
791 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700792 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200793 .strategy = &sysctl_intvec,
794 .extra1 = &zero,
795 .extra2 = &one,
796 },
797 {
798 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700799 .procname = "softlockup_thresh",
800 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200801 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700802 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200803 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700804 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200805 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700806 .extra2 = &sixty,
807 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100808 {
809 .ctl_name = CTL_UNNUMBERED,
810 .procname = "hung_task_check_count",
811 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100812 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100813 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100814 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100815 .strategy = &sysctl_intvec,
816 },
817 {
818 .ctl_name = CTL_UNNUMBERED,
819 .procname = "hung_task_timeout_secs",
820 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100821 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100822 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100823 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100824 .strategy = &sysctl_intvec,
825 },
826 {
827 .ctl_name = CTL_UNNUMBERED,
828 .procname = "hung_task_warnings",
829 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100830 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100831 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100832 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100833 .strategy = &sysctl_intvec,
834 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700835#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200836#ifdef CONFIG_COMPAT
837 {
838 .ctl_name = KERN_COMPAT_LOG,
839 .procname = "compat-log",
840 .data = &compat_log,
841 .maxlen = sizeof (int),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
844 },
845#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700846#ifdef CONFIG_RT_MUTEXES
847 {
848 .ctl_name = KERN_MAX_LOCK_DEPTH,
849 .procname = "max_lock_depth",
850 .data = &max_lock_depth,
851 .maxlen = sizeof(int),
852 .mode = 0644,
853 .proc_handler = &proc_dointvec,
854 },
855#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700856 {
857 .ctl_name = CTL_UNNUMBERED,
858 .procname = "poweroff_cmd",
859 .data = &poweroff_cmd,
860 .maxlen = POWEROFF_CMD_PATH_LEN,
861 .mode = 0644,
862 .proc_handler = &proc_dostring,
863 .strategy = &sysctl_string,
864 },
David Howells0b77f5b2008-04-29 01:01:32 -0700865#ifdef CONFIG_KEYS
866 {
867 .ctl_name = CTL_UNNUMBERED,
868 .procname = "keys",
869 .mode = 0555,
870 .child = key_sysctls,
871 },
872#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700873#ifdef CONFIG_RCU_TORTURE_TEST
874 {
875 .ctl_name = CTL_UNNUMBERED,
876 .procname = "rcutorture_runnable",
877 .data = &rcutorture_runnable,
878 .maxlen = sizeof(int),
879 .mode = 0644,
880 .proc_handler = &proc_dointvec,
881 },
882#endif
Lee Schermerhornaf936a12008-10-18 20:26:53 -0700883#ifdef CONFIG_UNEVICTABLE_LRU
884 {
885 .ctl_name = CTL_UNNUMBERED,
886 .procname = "scan_unevictable_pages",
887 .data = &scan_unevictable_pages,
888 .maxlen = sizeof(scan_unevictable_pages),
889 .mode = 0644,
890 .proc_handler = &scan_unevictable_handler,
891 },
892#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700893/*
894 * NOTE: do not add new entries to this table unless you have read
895 * Documentation/sysctl/ctl_unnumbered.txt
896 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 { .ctl_name = 0 }
898};
899
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700900static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 {
902 .ctl_name = VM_OVERCOMMIT_MEMORY,
903 .procname = "overcommit_memory",
904 .data = &sysctl_overcommit_memory,
905 .maxlen = sizeof(sysctl_overcommit_memory),
906 .mode = 0644,
907 .proc_handler = &proc_dointvec,
908 },
909 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700910 .ctl_name = VM_PANIC_ON_OOM,
911 .procname = "panic_on_oom",
912 .data = &sysctl_panic_on_oom,
913 .maxlen = sizeof(sysctl_panic_on_oom),
914 .mode = 0644,
915 .proc_handler = &proc_dointvec,
916 },
917 {
David Rientjesfe071d72007-10-16 23:25:56 -0700918 .ctl_name = CTL_UNNUMBERED,
919 .procname = "oom_kill_allocating_task",
920 .data = &sysctl_oom_kill_allocating_task,
921 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
922 .mode = 0644,
923 .proc_handler = &proc_dointvec,
924 },
925 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800926 .ctl_name = CTL_UNNUMBERED,
927 .procname = "oom_dump_tasks",
928 .data = &sysctl_oom_dump_tasks,
929 .maxlen = sizeof(sysctl_oom_dump_tasks),
930 .mode = 0644,
931 .proc_handler = &proc_dointvec,
932 },
933 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 .ctl_name = VM_OVERCOMMIT_RATIO,
935 .procname = "overcommit_ratio",
936 .data = &sysctl_overcommit_ratio,
937 .maxlen = sizeof(sysctl_overcommit_ratio),
938 .mode = 0644,
939 .proc_handler = &proc_dointvec,
940 },
941 {
942 .ctl_name = VM_PAGE_CLUSTER,
943 .procname = "page-cluster",
944 .data = &page_cluster,
945 .maxlen = sizeof(int),
946 .mode = 0644,
947 .proc_handler = &proc_dointvec,
948 },
949 {
950 .ctl_name = VM_DIRTY_BACKGROUND,
951 .procname = "dirty_background_ratio",
952 .data = &dirty_background_ratio,
953 .maxlen = sizeof(dirty_background_ratio),
954 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -0800955 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 .strategy = &sysctl_intvec,
957 .extra1 = &zero,
958 .extra2 = &one_hundred,
959 },
960 {
David Rientjes2da02992009-01-06 14:39:31 -0800961 .ctl_name = CTL_UNNUMBERED,
962 .procname = "dirty_background_bytes",
963 .data = &dirty_background_bytes,
964 .maxlen = sizeof(dirty_background_bytes),
965 .mode = 0644,
966 .proc_handler = &dirty_background_bytes_handler,
967 .strategy = &sysctl_intvec,
968 .extra1 = &one,
969 },
970 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 .ctl_name = VM_DIRTY_RATIO,
972 .procname = "dirty_ratio",
973 .data = &vm_dirty_ratio,
974 .maxlen = sizeof(vm_dirty_ratio),
975 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700976 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 .strategy = &sysctl_intvec,
978 .extra1 = &zero,
979 .extra2 = &one_hundred,
980 },
981 {
David Rientjes2da02992009-01-06 14:39:31 -0800982 .ctl_name = CTL_UNNUMBERED,
983 .procname = "dirty_bytes",
984 .data = &vm_dirty_bytes,
985 .maxlen = sizeof(vm_dirty_bytes),
986 .mode = 0644,
987 .proc_handler = &dirty_bytes_handler,
988 .strategy = &sysctl_intvec,
989 .extra1 = &one,
990 },
991 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800993 .data = &dirty_writeback_interval,
994 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 .mode = 0644,
996 .proc_handler = &dirty_writeback_centisecs_handler,
997 },
998 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001000 .data = &dirty_expire_interval,
1001 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -08001003 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 },
1005 {
1006 .ctl_name = VM_NR_PDFLUSH_THREADS,
1007 .procname = "nr_pdflush_threads",
1008 .data = &nr_pdflush_threads,
1009 .maxlen = sizeof nr_pdflush_threads,
1010 .mode = 0444 /* read-only*/,
1011 .proc_handler = &proc_dointvec,
1012 },
1013 {
1014 .ctl_name = VM_SWAPPINESS,
1015 .procname = "swappiness",
1016 .data = &vm_swappiness,
1017 .maxlen = sizeof(vm_swappiness),
1018 .mode = 0644,
1019 .proc_handler = &proc_dointvec_minmax,
1020 .strategy = &sysctl_intvec,
1021 .extra1 = &zero,
1022 .extra2 = &one_hundred,
1023 },
1024#ifdef CONFIG_HUGETLB_PAGE
1025 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001027 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 .maxlen = sizeof(unsigned long),
1029 .mode = 0644,
1030 .proc_handler = &hugetlb_sysctl_handler,
1031 .extra1 = (void *)&hugetlb_zero,
1032 .extra2 = (void *)&hugetlb_infinity,
1033 },
1034 {
1035 .ctl_name = VM_HUGETLB_GROUP,
1036 .procname = "hugetlb_shm_group",
1037 .data = &sysctl_hugetlb_shm_group,
1038 .maxlen = sizeof(gid_t),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec,
1041 },
Mel Gorman396faf02007-07-17 04:03:13 -07001042 {
1043 .ctl_name = CTL_UNNUMBERED,
1044 .procname = "hugepages_treat_as_movable",
1045 .data = &hugepages_treat_as_movable,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
1048 .proc_handler = &hugetlb_treat_movable_handler,
1049 },
Adam Litke54f9f802007-10-16 01:26:20 -07001050 {
1051 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001052 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001053 .data = NULL,
1054 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001055 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001056 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001057 .extra1 = (void *)&hugetlb_zero,
1058 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001059 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060#endif
1061 {
1062 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1063 .procname = "lowmem_reserve_ratio",
1064 .data = &sysctl_lowmem_reserve_ratio,
1065 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1066 .mode = 0644,
1067 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1068 .strategy = &sysctl_intvec,
1069 },
1070 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001071 .ctl_name = VM_DROP_PAGECACHE,
1072 .procname = "drop_caches",
1073 .data = &sysctl_drop_caches,
1074 .maxlen = sizeof(int),
1075 .mode = 0644,
1076 .proc_handler = drop_caches_sysctl_handler,
1077 .strategy = &sysctl_intvec,
1078 },
1079 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 .ctl_name = VM_MIN_FREE_KBYTES,
1081 .procname = "min_free_kbytes",
1082 .data = &min_free_kbytes,
1083 .maxlen = sizeof(min_free_kbytes),
1084 .mode = 0644,
1085 .proc_handler = &min_free_kbytes_sysctl_handler,
1086 .strategy = &sysctl_intvec,
1087 .extra1 = &zero,
1088 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001089 {
1090 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1091 .procname = "percpu_pagelist_fraction",
1092 .data = &percpu_pagelist_fraction,
1093 .maxlen = sizeof(percpu_pagelist_fraction),
1094 .mode = 0644,
1095 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1096 .strategy = &sysctl_intvec,
1097 .extra1 = &min_percpu_pagelist_fract,
1098 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099#ifdef CONFIG_MMU
1100 {
1101 .ctl_name = VM_MAX_MAP_COUNT,
1102 .procname = "max_map_count",
1103 .data = &sysctl_max_map_count,
1104 .maxlen = sizeof(sysctl_max_map_count),
1105 .mode = 0644,
1106 .proc_handler = &proc_dointvec
1107 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001108#else
1109 {
1110 .ctl_name = CTL_UNNUMBERED,
1111 .procname = "nr_trim_pages",
1112 .data = &sysctl_nr_trim_pages,
1113 .maxlen = sizeof(sysctl_nr_trim_pages),
1114 .mode = 0644,
1115 .proc_handler = &proc_dointvec_minmax,
1116 .strategy = &sysctl_intvec,
1117 .extra1 = &zero,
1118 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119#endif
1120 {
1121 .ctl_name = VM_LAPTOP_MODE,
1122 .procname = "laptop_mode",
1123 .data = &laptop_mode,
1124 .maxlen = sizeof(laptop_mode),
1125 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001126 .proc_handler = &proc_dointvec_jiffies,
1127 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 },
1129 {
1130 .ctl_name = VM_BLOCK_DUMP,
1131 .procname = "block_dump",
1132 .data = &block_dump,
1133 .maxlen = sizeof(block_dump),
1134 .mode = 0644,
1135 .proc_handler = &proc_dointvec,
1136 .strategy = &sysctl_intvec,
1137 .extra1 = &zero,
1138 },
1139 {
1140 .ctl_name = VM_VFS_CACHE_PRESSURE,
1141 .procname = "vfs_cache_pressure",
1142 .data = &sysctl_vfs_cache_pressure,
1143 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1144 .mode = 0644,
1145 .proc_handler = &proc_dointvec,
1146 .strategy = &sysctl_intvec,
1147 .extra1 = &zero,
1148 },
1149#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1150 {
1151 .ctl_name = VM_LEGACY_VA_LAYOUT,
1152 .procname = "legacy_va_layout",
1153 .data = &sysctl_legacy_va_layout,
1154 .maxlen = sizeof(sysctl_legacy_va_layout),
1155 .mode = 0644,
1156 .proc_handler = &proc_dointvec,
1157 .strategy = &sysctl_intvec,
1158 .extra1 = &zero,
1159 },
1160#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001161#ifdef CONFIG_NUMA
1162 {
1163 .ctl_name = VM_ZONE_RECLAIM_MODE,
1164 .procname = "zone_reclaim_mode",
1165 .data = &zone_reclaim_mode,
1166 .maxlen = sizeof(zone_reclaim_mode),
1167 .mode = 0644,
1168 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001169 .strategy = &sysctl_intvec,
1170 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001171 },
Christoph Lameter96146342006-07-03 00:24:13 -07001172 {
1173 .ctl_name = VM_MIN_UNMAPPED,
1174 .procname = "min_unmapped_ratio",
1175 .data = &sysctl_min_unmapped_ratio,
1176 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1177 .mode = 0644,
1178 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1179 .strategy = &sysctl_intvec,
1180 .extra1 = &zero,
1181 .extra2 = &one_hundred,
1182 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001183 {
1184 .ctl_name = VM_MIN_SLAB,
1185 .procname = "min_slab_ratio",
1186 .data = &sysctl_min_slab_ratio,
1187 .maxlen = sizeof(sysctl_min_slab_ratio),
1188 .mode = 0644,
1189 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1190 .strategy = &sysctl_intvec,
1191 .extra1 = &zero,
1192 .extra2 = &one_hundred,
1193 },
Christoph Lameter17436602006-01-18 17:42:32 -08001194#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001195#ifdef CONFIG_SMP
1196 {
1197 .ctl_name = CTL_UNNUMBERED,
1198 .procname = "stat_interval",
1199 .data = &sysctl_stat_interval,
1200 .maxlen = sizeof(sysctl_stat_interval),
1201 .mode = 0644,
1202 .proc_handler = &proc_dointvec_jiffies,
1203 .strategy = &sysctl_jiffies,
1204 },
1205#endif
Eric Parised032182007-06-28 15:55:21 -04001206#ifdef CONFIG_SECURITY
1207 {
1208 .ctl_name = CTL_UNNUMBERED,
1209 .procname = "mmap_min_addr",
1210 .data = &mmap_min_addr,
1211 .maxlen = sizeof(unsigned long),
1212 .mode = 0644,
1213 .proc_handler = &proc_doulongvec_minmax,
1214 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001215#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001216#ifdef CONFIG_NUMA
1217 {
1218 .ctl_name = CTL_UNNUMBERED,
1219 .procname = "numa_zonelist_order",
1220 .data = &numa_zonelist_order,
1221 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1222 .mode = 0644,
1223 .proc_handler = &numa_zonelist_order_handler,
1224 .strategy = &sysctl_string,
1225 },
1226#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001227#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001228 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001229 {
1230 .ctl_name = VM_VDSO_ENABLED,
1231 .procname = "vdso_enabled",
1232 .data = &vdso_enabled,
1233 .maxlen = sizeof(vdso_enabled),
1234 .mode = 0644,
1235 .proc_handler = &proc_dointvec,
1236 .strategy = &sysctl_intvec,
1237 .extra1 = &zero,
1238 },
1239#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001240#ifdef CONFIG_HIGHMEM
1241 {
1242 .ctl_name = CTL_UNNUMBERED,
1243 .procname = "highmem_is_dirtyable",
1244 .data = &vm_highmem_is_dirtyable,
1245 .maxlen = sizeof(vm_highmem_is_dirtyable),
1246 .mode = 0644,
1247 .proc_handler = &proc_dointvec_minmax,
1248 .strategy = &sysctl_intvec,
1249 .extra1 = &zero,
1250 .extra2 = &one,
1251 },
1252#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001253/*
1254 * NOTE: do not add new entries to this table unless you have read
1255 * Documentation/sysctl/ctl_unnumbered.txt
1256 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 { .ctl_name = 0 }
1258};
1259
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001260#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001261static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001262 { .ctl_name = 0 }
1263};
1264#endif
1265
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001266static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 {
1268 .ctl_name = FS_NRINODE,
1269 .procname = "inode-nr",
1270 .data = &inodes_stat,
1271 .maxlen = 2*sizeof(int),
1272 .mode = 0444,
1273 .proc_handler = &proc_dointvec,
1274 },
1275 {
1276 .ctl_name = FS_STATINODE,
1277 .procname = "inode-state",
1278 .data = &inodes_stat,
1279 .maxlen = 7*sizeof(int),
1280 .mode = 0444,
1281 .proc_handler = &proc_dointvec,
1282 },
1283 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 .procname = "file-nr",
1285 .data = &files_stat,
1286 .maxlen = 3*sizeof(int),
1287 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001288 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 },
1290 {
1291 .ctl_name = FS_MAXFILE,
1292 .procname = "file-max",
1293 .data = &files_stat.max_files,
1294 .maxlen = sizeof(int),
1295 .mode = 0644,
1296 .proc_handler = &proc_dointvec,
1297 },
1298 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001299 .ctl_name = CTL_UNNUMBERED,
1300 .procname = "nr_open",
1301 .data = &sysctl_nr_open,
1302 .maxlen = sizeof(int),
1303 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001304 .proc_handler = &proc_dointvec_minmax,
1305 .extra1 = &sysctl_nr_open_min,
1306 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001307 },
1308 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 .ctl_name = FS_DENTRY,
1310 .procname = "dentry-state",
1311 .data = &dentry_stat,
1312 .maxlen = 6*sizeof(int),
1313 .mode = 0444,
1314 .proc_handler = &proc_dointvec,
1315 },
1316 {
1317 .ctl_name = FS_OVERFLOWUID,
1318 .procname = "overflowuid",
1319 .data = &fs_overflowuid,
1320 .maxlen = sizeof(int),
1321 .mode = 0644,
1322 .proc_handler = &proc_dointvec_minmax,
1323 .strategy = &sysctl_intvec,
1324 .extra1 = &minolduid,
1325 .extra2 = &maxolduid,
1326 },
1327 {
1328 .ctl_name = FS_OVERFLOWGID,
1329 .procname = "overflowgid",
1330 .data = &fs_overflowgid,
1331 .maxlen = sizeof(int),
1332 .mode = 0644,
1333 .proc_handler = &proc_dointvec_minmax,
1334 .strategy = &sysctl_intvec,
1335 .extra1 = &minolduid,
1336 .extra2 = &maxolduid,
1337 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001338#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 {
1340 .ctl_name = FS_LEASES,
1341 .procname = "leases-enable",
1342 .data = &leases_enable,
1343 .maxlen = sizeof(int),
1344 .mode = 0644,
1345 .proc_handler = &proc_dointvec,
1346 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001347#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348#ifdef CONFIG_DNOTIFY
1349 {
1350 .ctl_name = FS_DIR_NOTIFY,
1351 .procname = "dir-notify-enable",
1352 .data = &dir_notify_enable,
1353 .maxlen = sizeof(int),
1354 .mode = 0644,
1355 .proc_handler = &proc_dointvec,
1356 },
1357#endif
1358#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001359#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 {
1361 .ctl_name = FS_LEASE_TIME,
1362 .procname = "lease-break-time",
1363 .data = &lease_break_time,
1364 .maxlen = sizeof(int),
1365 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001366 .proc_handler = &proc_dointvec_minmax,
1367 .strategy = &sysctl_intvec,
1368 .extra1 = &zero,
1369 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001371#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001372#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .procname = "aio-nr",
1375 .data = &aio_nr,
1376 .maxlen = sizeof(aio_nr),
1377 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001378 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 },
1380 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 .procname = "aio-max-nr",
1382 .data = &aio_max_nr,
1383 .maxlen = sizeof(aio_max_nr),
1384 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001385 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001387#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001388#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001389 {
1390 .ctl_name = FS_INOTIFY,
1391 .procname = "inotify",
1392 .mode = 0555,
1393 .child = inotify_table,
1394 },
1395#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001396#ifdef CONFIG_EPOLL
1397 {
1398 .procname = "epoll",
1399 .mode = 0555,
1400 .child = epoll_table,
1401 },
1402#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001404 {
1405 .ctl_name = KERN_SETUID_DUMPABLE,
1406 .procname = "suid_dumpable",
1407 .data = &suid_dumpable,
1408 .maxlen = sizeof(int),
1409 .mode = 0644,
1410 .proc_handler = &proc_dointvec,
1411 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001412#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1413 {
1414 .ctl_name = CTL_UNNUMBERED,
1415 .procname = "binfmt_misc",
1416 .mode = 0555,
1417 .child = binfmt_misc_table,
1418 },
1419#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001420/*
1421 * NOTE: do not add new entries to this table unless you have read
1422 * Documentation/sysctl/ctl_unnumbered.txt
1423 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 { .ctl_name = 0 }
1425};
1426
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001427static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001428#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001429 {
1430 .ctl_name = CTL_UNNUMBERED,
1431 .procname = "exception-trace",
1432 .data = &show_unhandled_signals,
1433 .maxlen = sizeof(int),
1434 .mode = 0644,
1435 .proc_handler = proc_dointvec
1436 },
1437#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 { .ctl_name = 0 }
1439};
1440
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001441static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001443};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Al Viro330d57f2005-11-04 10:18:40 +00001445static DEFINE_SPINLOCK(sysctl_lock);
1446
1447/* called under sysctl_lock */
1448static int use_table(struct ctl_table_header *p)
1449{
1450 if (unlikely(p->unregistering))
1451 return 0;
1452 p->used++;
1453 return 1;
1454}
1455
1456/* called under sysctl_lock */
1457static void unuse_table(struct ctl_table_header *p)
1458{
1459 if (!--p->used)
1460 if (unlikely(p->unregistering))
1461 complete(p->unregistering);
1462}
1463
1464/* called under sysctl_lock, will reacquire if has to wait */
1465static void start_unregistering(struct ctl_table_header *p)
1466{
1467 /*
1468 * if p->used is 0, nobody will ever touch that entry again;
1469 * we'll eliminate all paths to it before dropping sysctl_lock
1470 */
1471 if (unlikely(p->used)) {
1472 struct completion wait;
1473 init_completion(&wait);
1474 p->unregistering = &wait;
1475 spin_unlock(&sysctl_lock);
1476 wait_for_completion(&wait);
1477 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001478 } else {
1479 /* anything non-NULL; we'll never dereference it */
1480 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001481 }
1482 /*
1483 * do not remove from the list until nobody holds it; walking the
1484 * list in do_sysctl() relies on that.
1485 */
1486 list_del_init(&p->ctl_entry);
1487}
1488
Al Virof7e6ced2008-07-15 01:44:23 -04001489void sysctl_head_get(struct ctl_table_header *head)
1490{
1491 spin_lock(&sysctl_lock);
1492 head->count++;
1493 spin_unlock(&sysctl_lock);
1494}
1495
1496void sysctl_head_put(struct ctl_table_header *head)
1497{
1498 spin_lock(&sysctl_lock);
1499 if (!--head->count)
1500 kfree(head);
1501 spin_unlock(&sysctl_lock);
1502}
1503
1504struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1505{
1506 if (!head)
1507 BUG();
1508 spin_lock(&sysctl_lock);
1509 if (!use_table(head))
1510 head = ERR_PTR(-ENOENT);
1511 spin_unlock(&sysctl_lock);
1512 return head;
1513}
1514
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001515void sysctl_head_finish(struct ctl_table_header *head)
1516{
1517 if (!head)
1518 return;
1519 spin_lock(&sysctl_lock);
1520 unuse_table(head);
1521 spin_unlock(&sysctl_lock);
1522}
1523
Al Viro73455092008-07-14 21:22:20 -04001524static struct ctl_table_set *
1525lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1526{
1527 struct ctl_table_set *set = &root->default_set;
1528 if (root->lookup)
1529 set = root->lookup(root, namespaces);
1530 return set;
1531}
1532
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001533static struct list_head *
1534lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001535{
Al Viro73455092008-07-14 21:22:20 -04001536 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1537 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001538}
1539
1540struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1541 struct ctl_table_header *prev)
1542{
1543 struct ctl_table_root *root;
1544 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001545 struct ctl_table_header *head;
1546 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001547
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001548 spin_lock(&sysctl_lock);
1549 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001550 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001551 tmp = &prev->ctl_entry;
1552 unuse_table(prev);
1553 goto next;
1554 }
1555 tmp = &root_table_header.ctl_entry;
1556 for (;;) {
1557 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1558
1559 if (!use_table(head))
1560 goto next;
1561 spin_unlock(&sysctl_lock);
1562 return head;
1563 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001564 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001565 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001566 header_list = lookup_header_list(root, namespaces);
1567 if (tmp != header_list)
1568 continue;
1569
1570 do {
1571 root = list_entry(root->root_list.next,
1572 struct ctl_table_root, root_list);
1573 if (root == &sysctl_table_root)
1574 goto out;
1575 header_list = lookup_header_list(root, namespaces);
1576 } while (list_empty(header_list));
1577 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001578 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001579out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001580 spin_unlock(&sysctl_lock);
1581 return NULL;
1582}
1583
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001584struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1585{
1586 return __sysctl_head_next(current->nsproxy, prev);
1587}
1588
1589void register_sysctl_root(struct ctl_table_root *root)
1590{
1591 spin_lock(&sysctl_lock);
1592 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1593 spin_unlock(&sysctl_lock);
1594}
1595
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001596#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001597/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001598static int do_sysctl_strategy(struct ctl_table_root *root,
1599 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001600 void __user *oldval, size_t __user *oldlenp,
1601 void __user *newval, size_t newlen)
1602{
1603 int op = 0, rc;
1604
1605 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001606 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001607 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001608 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001609 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001610 return -EPERM;
1611
1612 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001613 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001614 if (rc < 0)
1615 return rc;
1616 if (rc > 0)
1617 return 0;
1618 }
1619
1620 /* If there is no strategy routine, or if the strategy returns
1621 * zero, proceed with automatic r/w */
1622 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001623 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001624 if (rc < 0)
1625 return rc;
1626 }
1627 return 0;
1628}
1629
1630static int parse_table(int __user *name, int nlen,
1631 void __user *oldval, size_t __user *oldlenp,
1632 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001633 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001634 struct ctl_table *table)
1635{
1636 int n;
1637repeat:
1638 if (!nlen)
1639 return -ENOTDIR;
1640 if (get_user(n, name))
1641 return -EFAULT;
1642 for ( ; table->ctl_name || table->procname; table++) {
1643 if (!table->ctl_name)
1644 continue;
1645 if (n == table->ctl_name) {
1646 int error;
1647 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001648 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001649 return -EPERM;
1650 name++;
1651 nlen--;
1652 table = table->child;
1653 goto repeat;
1654 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001655 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001656 oldval, oldlenp,
1657 newval, newlen);
1658 return error;
1659 }
1660 }
1661 return -ENOTDIR;
1662}
1663
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1665 void __user *newval, size_t newlen)
1666{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001667 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001668 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
1670 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1671 return -ENOTDIR;
1672 if (oldval) {
1673 int old_len;
1674 if (!oldlenp || get_user(old_len, oldlenp))
1675 return -EFAULT;
1676 }
Al Viro330d57f2005-11-04 10:18:40 +00001677
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001678 for (head = sysctl_head_next(NULL); head;
1679 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001680 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001681 newval, newlen,
1682 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001683 if (error != -ENOTDIR) {
1684 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001685 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001686 }
1687 }
Al Viro330d57f2005-11-04 10:18:40 +00001688 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689}
1690
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001691SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
1693 struct __sysctl_args tmp;
1694 int error;
1695
1696 if (copy_from_user(&tmp, args, sizeof(tmp)))
1697 return -EFAULT;
1698
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001699 error = deprecated_sysctl_warning(&tmp);
1700 if (error)
1701 goto out;
1702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 lock_kernel();
1704 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1705 tmp.newval, tmp.newlen);
1706 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001707out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 return error;
1709}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001710#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001713 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 * some sysctl variables are readonly even to root.
1715 */
1716
1717static int test_perm(int mode, int op)
1718{
David Howells76aac0e2008-11-14 10:39:12 +11001719 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 mode >>= 6;
1721 else if (in_egroup_p(0))
1722 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001723 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 return 0;
1725 return -EACCES;
1726}
1727
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001728int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729{
1730 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001731 int mode;
1732
Al Viroe6305c42008-07-15 21:03:57 -04001733 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 if (error)
1735 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001736
1737 if (root->permissions)
1738 mode = root->permissions(root, current->nsproxy, table);
1739 else
1740 mode = table->mode;
1741
1742 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
1744
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001745static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1746{
1747 for (; table->ctl_name || table->procname; table++) {
1748 table->parent = parent;
1749 if (table->child)
1750 sysctl_set_parent(table, table->child);
1751 }
1752}
1753
1754static __init int sysctl_init(void)
1755{
1756 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001757#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1758 {
1759 int err;
1760 err = sysctl_check_table(current->nsproxy, root_table);
1761 }
1762#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001763 return 0;
1764}
1765
1766core_initcall(sysctl_init);
1767
Al Virobfbcf032008-07-27 06:31:22 +01001768static struct ctl_table *is_branch_in(struct ctl_table *branch,
1769 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001770{
1771 struct ctl_table *p;
1772 const char *s = branch->procname;
1773
1774 /* branch should have named subdirectory as its first element */
1775 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001776 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001777
1778 /* ... and nothing else */
1779 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001780 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001781
1782 /* table should contain subdirectory with the same name */
1783 for (p = table; p->procname || p->ctl_name; p++) {
1784 if (!p->child)
1785 continue;
1786 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001787 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001788 }
Al Virobfbcf032008-07-27 06:31:22 +01001789 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001790}
1791
1792/* see if attaching q to p would be an improvement */
1793static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1794{
1795 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001796 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001797 int is_better = 0;
1798 int not_in_parent = !p->attached_by;
1799
Al Virobfbcf032008-07-27 06:31:22 +01001800 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001801 if (by == q->attached_by)
1802 is_better = 1;
1803 if (to == p->attached_by)
1804 not_in_parent = 1;
1805 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001806 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001807 }
1808
1809 if (is_better && not_in_parent) {
1810 q->attached_by = by;
1811 q->attached_to = to;
1812 q->parent = p;
1813 }
1814}
1815
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001817 * __register_sysctl_paths - register a sysctl hierarchy
1818 * @root: List of sysctl headers to register on
1819 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001820 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 *
1823 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001824 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001826 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 *
1828 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1829 * must be unique within that level of sysctl
1830 *
1831 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1832 * enter a sysctl file
1833 *
1834 * data - a pointer to data for use by proc_handler
1835 *
1836 * maxlen - the maximum size in bytes of the data
1837 *
1838 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1839 *
1840 * child - a pointer to the child sysctl table if this entry is a directory, or
1841 * %NULL.
1842 *
1843 * proc_handler - the text handler routine (described below)
1844 *
1845 * strategy - the strategy routine (described below)
1846 *
1847 * de - for internal use by the sysctl routines
1848 *
1849 * extra1, extra2 - extra pointers usable by the proc handler routines
1850 *
1851 * Leaf nodes in the sysctl tree will be represented by a single file
1852 * under /proc; non-leaf nodes will be represented by directories.
1853 *
1854 * sysctl(2) can automatically manage read and write requests through
1855 * the sysctl table. The data and maxlen fields of the ctl_table
1856 * struct enable minimal validation of the values being written to be
1857 * performed, and the mode field allows minimal authentication.
1858 *
1859 * More sophisticated management can be enabled by the provision of a
1860 * strategy routine with the table entry. This will be called before
1861 * any automatic read or write of the data is performed.
1862 *
1863 * The strategy routine may return
1864 *
1865 * < 0 - Error occurred (error is passed to user process)
1866 *
1867 * 0 - OK - proceed with automatic read or write.
1868 *
1869 * > 0 - OK - read or write has been done by the strategy routine, so
1870 * return immediately.
1871 *
1872 * There must be a proc_handler routine for any terminal nodes
1873 * mirrored under /proc/sys (non-terminals are handled by a built-in
1874 * directory handler). Several default handlers are available to
1875 * cover common cases -
1876 *
1877 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1878 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1879 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1880 *
1881 * It is the handler's job to read the input buffer from user memory
1882 * and process it. The handler should return 0 on success.
1883 *
1884 * This routine returns %NULL on a failure to register, and a pointer
1885 * to the table header on success.
1886 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001887struct ctl_table_header *__register_sysctl_paths(
1888 struct ctl_table_root *root,
1889 struct nsproxy *namespaces,
1890 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001892 struct ctl_table_header *header;
1893 struct ctl_table *new, **prevp;
1894 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001895 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001896
1897 /* Count the path components */
1898 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1899 ;
1900
1901 /*
1902 * For each path component, allocate a 2-element ctl_table array.
1903 * The first array element will be filled with the sysctl entry
1904 * for this, the second will be the sentinel (ctl_name == 0).
1905 *
1906 * We allocate everything in one go so that we don't have to
1907 * worry about freeing additional memory in unregister_sysctl_table.
1908 */
1909 header = kzalloc(sizeof(struct ctl_table_header) +
1910 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1911 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001913
1914 new = (struct ctl_table *) (header + 1);
1915
1916 /* Now connect the dots */
1917 prevp = &header->ctl_table;
1918 for (n = 0; n < npath; ++n, ++path) {
1919 /* Copy the procname */
1920 new->procname = path->procname;
1921 new->ctl_name = path->ctl_name;
1922 new->mode = 0555;
1923
1924 *prevp = new;
1925 prevp = &new->child;
1926
1927 new += 2;
1928 }
1929 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001930 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001931
1932 INIT_LIST_HEAD(&header->ctl_entry);
1933 header->used = 0;
1934 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001935 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001936 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001937 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001938#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001939 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001940 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001941 return NULL;
1942 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001943#endif
Al Viro330d57f2005-11-04 10:18:40 +00001944 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001945 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001946 header->attached_by = header->ctl_table;
1947 header->attached_to = root_table;
1948 header->parent = &root_table_header;
1949 for (set = header->set; set; set = set->parent) {
1950 struct ctl_table_header *p;
1951 list_for_each_entry(p, &set->list, ctl_entry) {
1952 if (p->unregistering)
1953 continue;
1954 try_attach(p, header);
1955 }
1956 }
1957 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001958 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001959 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001960
1961 return header;
1962}
1963
1964/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001965 * register_sysctl_table_path - register a sysctl table hierarchy
1966 * @path: The path to the directory the sysctl table is in.
1967 * @table: the top-level table structure
1968 *
1969 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1970 * array. A completely 0 filled entry terminates the table.
1971 *
1972 * See __register_sysctl_paths for more details.
1973 */
1974struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1975 struct ctl_table *table)
1976{
1977 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1978 path, table);
1979}
1980
1981/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001982 * register_sysctl_table - register a sysctl table hierarchy
1983 * @table: the top-level table structure
1984 *
1985 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1986 * array. A completely 0 filled entry terminates the table.
1987 *
1988 * See register_sysctl_paths for more details.
1989 */
1990struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1991{
1992 static const struct ctl_path null_path[] = { {} };
1993
1994 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995}
1996
1997/**
1998 * unregister_sysctl_table - unregister a sysctl table hierarchy
1999 * @header: the header returned from register_sysctl_table
2000 *
2001 * Unregisters the sysctl table and all children. proc entries may not
2002 * actually be removed until they are no longer used by anyone.
2003 */
2004void unregister_sysctl_table(struct ctl_table_header * header)
2005{
Al Viro330d57f2005-11-04 10:18:40 +00002006 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002007
2008 if (header == NULL)
2009 return;
2010
Al Viro330d57f2005-11-04 10:18:40 +00002011 spin_lock(&sysctl_lock);
2012 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002013 if (!--header->parent->count) {
2014 WARN_ON(1);
2015 kfree(header->parent);
2016 }
Al Virof7e6ced2008-07-15 01:44:23 -04002017 if (!--header->count)
2018 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002019 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020}
2021
Al Viro9043476f2008-07-15 08:54:06 -04002022int sysctl_is_seen(struct ctl_table_header *p)
2023{
2024 struct ctl_table_set *set = p->set;
2025 int res;
2026 spin_lock(&sysctl_lock);
2027 if (p->unregistering)
2028 res = 0;
2029 else if (!set->is_seen)
2030 res = 1;
2031 else
2032 res = set->is_seen(set);
2033 spin_unlock(&sysctl_lock);
2034 return res;
2035}
2036
Al Viro73455092008-07-14 21:22:20 -04002037void setup_sysctl_set(struct ctl_table_set *p,
2038 struct ctl_table_set *parent,
2039 int (*is_seen)(struct ctl_table_set *))
2040{
2041 INIT_LIST_HEAD(&p->list);
2042 p->parent = parent ? parent : &sysctl_table_root.default_set;
2043 p->is_seen = is_seen;
2044}
2045
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002046#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002047struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002048{
2049 return NULL;
2050}
2051
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002052struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2053 struct ctl_table *table)
2054{
2055 return NULL;
2056}
2057
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002058void unregister_sysctl_table(struct ctl_table_header * table)
2059{
2060}
2061
Al Viro73455092008-07-14 21:22:20 -04002062void setup_sysctl_set(struct ctl_table_set *p,
2063 struct ctl_table_set *parent,
2064 int (*is_seen)(struct ctl_table_set *))
2065{
2066}
2067
Al Virof7e6ced2008-07-15 01:44:23 -04002068void sysctl_head_put(struct ctl_table_header *head)
2069{
2070}
2071
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002072#endif /* CONFIG_SYSCTL */
2073
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074/*
2075 * /proc/sys support
2076 */
2077
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002078#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002080static int _proc_do_string(void* data, int maxlen, int write,
2081 struct file *filp, void __user *buffer,
2082 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002083{
2084 size_t len;
2085 char __user *p;
2086 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002087
2088 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002089 *lenp = 0;
2090 return 0;
2091 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002092
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002093 if (write) {
2094 len = 0;
2095 p = buffer;
2096 while (len < *lenp) {
2097 if (get_user(c, p++))
2098 return -EFAULT;
2099 if (c == 0 || c == '\n')
2100 break;
2101 len++;
2102 }
2103 if (len >= maxlen)
2104 len = maxlen-1;
2105 if(copy_from_user(data, buffer, len))
2106 return -EFAULT;
2107 ((char *) data)[len] = 0;
2108 *ppos += *lenp;
2109 } else {
2110 len = strlen(data);
2111 if (len > maxlen)
2112 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002113
2114 if (*ppos > len) {
2115 *lenp = 0;
2116 return 0;
2117 }
2118
2119 data += *ppos;
2120 len -= *ppos;
2121
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002122 if (len > *lenp)
2123 len = *lenp;
2124 if (len)
2125 if(copy_to_user(buffer, data, len))
2126 return -EFAULT;
2127 if (len < *lenp) {
2128 if(put_user('\n', ((char __user *) buffer) + len))
2129 return -EFAULT;
2130 len++;
2131 }
2132 *lenp = len;
2133 *ppos += len;
2134 }
2135 return 0;
2136}
2137
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138/**
2139 * proc_dostring - read a string sysctl
2140 * @table: the sysctl table
2141 * @write: %TRUE if this is a write to the sysctl file
2142 * @filp: the file structure
2143 * @buffer: the user buffer
2144 * @lenp: the size of the user buffer
2145 * @ppos: file position
2146 *
2147 * Reads/writes a string from/to the user buffer. If the kernel
2148 * buffer provided is not large enough to hold the string, the
2149 * string is truncated. The copied string is %NULL-terminated.
2150 * If the string is being read by the user process, it is copied
2151 * and a newline '\n' is added. It is truncated if the buffer is
2152 * not large enough.
2153 *
2154 * Returns 0 on success.
2155 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002156int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 void __user *buffer, size_t *lenp, loff_t *ppos)
2158{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002159 return _proc_do_string(table->data, table->maxlen, write, filp,
2160 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161}
2162
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2165 int *valp,
2166 int write, void *data)
2167{
2168 if (write) {
2169 *valp = *negp ? -*lvalp : *lvalp;
2170 } else {
2171 int val = *valp;
2172 if (val < 0) {
2173 *negp = -1;
2174 *lvalp = (unsigned long)-val;
2175 } else {
2176 *negp = 0;
2177 *lvalp = (unsigned long)val;
2178 }
2179 }
2180 return 0;
2181}
2182
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002183static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002184 int write, struct file *filp, void __user *buffer,
2185 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2187 int write, void *data),
2188 void *data)
2189{
2190#define TMPBUFLEN 21
2191 int *i, vleft, first=1, neg, val;
2192 unsigned long lval;
2193 size_t left, len;
2194
2195 char buf[TMPBUFLEN], *p;
2196 char __user *s = buffer;
2197
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002198 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 (*ppos && !write)) {
2200 *lenp = 0;
2201 return 0;
2202 }
2203
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002204 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 vleft = table->maxlen / sizeof(*i);
2206 left = *lenp;
2207
2208 if (!conv)
2209 conv = do_proc_dointvec_conv;
2210
2211 for (; left && vleft--; i++, first=0) {
2212 if (write) {
2213 while (left) {
2214 char c;
2215 if (get_user(c, s))
2216 return -EFAULT;
2217 if (!isspace(c))
2218 break;
2219 left--;
2220 s++;
2221 }
2222 if (!left)
2223 break;
2224 neg = 0;
2225 len = left;
2226 if (len > sizeof(buf) - 1)
2227 len = sizeof(buf) - 1;
2228 if (copy_from_user(buf, s, len))
2229 return -EFAULT;
2230 buf[len] = 0;
2231 p = buf;
2232 if (*p == '-' && left > 1) {
2233 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002234 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 }
2236 if (*p < '0' || *p > '9')
2237 break;
2238
2239 lval = simple_strtoul(p, &p, 0);
2240
2241 len = p-buf;
2242 if ((len < left) && *p && !isspace(*p))
2243 break;
2244 if (neg)
2245 val = -val;
2246 s += len;
2247 left -= len;
2248
2249 if (conv(&neg, &lval, i, 1, data))
2250 break;
2251 } else {
2252 p = buf;
2253 if (!first)
2254 *p++ = '\t';
2255
2256 if (conv(&neg, &lval, i, 0, data))
2257 break;
2258
2259 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2260 len = strlen(buf);
2261 if (len > left)
2262 len = left;
2263 if(copy_to_user(s, buf, len))
2264 return -EFAULT;
2265 left -= len;
2266 s += len;
2267 }
2268 }
2269
2270 if (!write && !first && left) {
2271 if(put_user('\n', s))
2272 return -EFAULT;
2273 left--, s++;
2274 }
2275 if (write) {
2276 while (left) {
2277 char c;
2278 if (get_user(c, s++))
2279 return -EFAULT;
2280 if (!isspace(c))
2281 break;
2282 left--;
2283 }
2284 }
2285 if (write && first)
2286 return -EINVAL;
2287 *lenp -= left;
2288 *ppos += *lenp;
2289 return 0;
2290#undef TMPBUFLEN
2291}
2292
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002293static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002294 void __user *buffer, size_t *lenp, loff_t *ppos,
2295 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2296 int write, void *data),
2297 void *data)
2298{
2299 return __do_proc_dointvec(table->data, table, write, filp,
2300 buffer, lenp, ppos, conv, data);
2301}
2302
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303/**
2304 * proc_dointvec - read a vector of integers
2305 * @table: the sysctl table
2306 * @write: %TRUE if this is a write to the sysctl file
2307 * @filp: the file structure
2308 * @buffer: the user buffer
2309 * @lenp: the size of the user buffer
2310 * @ppos: file position
2311 *
2312 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2313 * values from/to the user buffer, treated as an ASCII string.
2314 *
2315 * Returns 0 on success.
2316 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002317int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 void __user *buffer, size_t *lenp, loff_t *ppos)
2319{
2320 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2321 NULL,NULL);
2322}
2323
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002324/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002325 * Taint values can only be increased
2326 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002327 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002328static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002329 void __user *buffer, size_t *lenp, loff_t *ppos)
2330{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002331 struct ctl_table t;
2332 unsigned long tmptaint = get_taint();
2333 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002334
Bastian Blank91fcd412007-04-23 14:41:14 -07002335 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002336 return -EPERM;
2337
Andi Kleen25ddbb12008-10-15 22:01:41 -07002338 t = *table;
2339 t.data = &tmptaint;
2340 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2341 if (err < 0)
2342 return err;
2343
2344 if (write) {
2345 /*
2346 * Poor man's atomic or. Not worth adding a primitive
2347 * to everyone's atomic.h for this
2348 */
2349 int i;
2350 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2351 if ((tmptaint >> i) & 1)
2352 add_taint(i);
2353 }
2354 }
2355
2356 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002357}
2358
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359struct do_proc_dointvec_minmax_conv_param {
2360 int *min;
2361 int *max;
2362};
2363
2364static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2365 int *valp,
2366 int write, void *data)
2367{
2368 struct do_proc_dointvec_minmax_conv_param *param = data;
2369 if (write) {
2370 int val = *negp ? -*lvalp : *lvalp;
2371 if ((param->min && *param->min > val) ||
2372 (param->max && *param->max < val))
2373 return -EINVAL;
2374 *valp = val;
2375 } else {
2376 int val = *valp;
2377 if (val < 0) {
2378 *negp = -1;
2379 *lvalp = (unsigned long)-val;
2380 } else {
2381 *negp = 0;
2382 *lvalp = (unsigned long)val;
2383 }
2384 }
2385 return 0;
2386}
2387
2388/**
2389 * proc_dointvec_minmax - read a vector of integers with min/max values
2390 * @table: the sysctl table
2391 * @write: %TRUE if this is a write to the sysctl file
2392 * @filp: the file structure
2393 * @buffer: the user buffer
2394 * @lenp: the size of the user buffer
2395 * @ppos: file position
2396 *
2397 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2398 * values from/to the user buffer, treated as an ASCII string.
2399 *
2400 * This routine will ensure the values are within the range specified by
2401 * table->extra1 (min) and table->extra2 (max).
2402 *
2403 * Returns 0 on success.
2404 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002405int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 void __user *buffer, size_t *lenp, loff_t *ppos)
2407{
2408 struct do_proc_dointvec_minmax_conv_param param = {
2409 .min = (int *) table->extra1,
2410 .max = (int *) table->extra2,
2411 };
2412 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2413 do_proc_dointvec_minmax_conv, &param);
2414}
2415
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002416static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 struct file *filp,
2418 void __user *buffer,
2419 size_t *lenp, loff_t *ppos,
2420 unsigned long convmul,
2421 unsigned long convdiv)
2422{
2423#define TMPBUFLEN 21
2424 unsigned long *i, *min, *max, val;
2425 int vleft, first=1, neg;
2426 size_t len, left;
2427 char buf[TMPBUFLEN], *p;
2428 char __user *s = buffer;
2429
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002430 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 (*ppos && !write)) {
2432 *lenp = 0;
2433 return 0;
2434 }
2435
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002436 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 min = (unsigned long *) table->extra1;
2438 max = (unsigned long *) table->extra2;
2439 vleft = table->maxlen / sizeof(unsigned long);
2440 left = *lenp;
2441
2442 for (; left && vleft--; i++, min++, max++, first=0) {
2443 if (write) {
2444 while (left) {
2445 char c;
2446 if (get_user(c, s))
2447 return -EFAULT;
2448 if (!isspace(c))
2449 break;
2450 left--;
2451 s++;
2452 }
2453 if (!left)
2454 break;
2455 neg = 0;
2456 len = left;
2457 if (len > TMPBUFLEN-1)
2458 len = TMPBUFLEN-1;
2459 if (copy_from_user(buf, s, len))
2460 return -EFAULT;
2461 buf[len] = 0;
2462 p = buf;
2463 if (*p == '-' && left > 1) {
2464 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002465 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 }
2467 if (*p < '0' || *p > '9')
2468 break;
2469 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2470 len = p-buf;
2471 if ((len < left) && *p && !isspace(*p))
2472 break;
2473 if (neg)
2474 val = -val;
2475 s += len;
2476 left -= len;
2477
2478 if(neg)
2479 continue;
2480 if ((min && val < *min) || (max && val > *max))
2481 continue;
2482 *i = val;
2483 } else {
2484 p = buf;
2485 if (!first)
2486 *p++ = '\t';
2487 sprintf(p, "%lu", convdiv * (*i) / convmul);
2488 len = strlen(buf);
2489 if (len > left)
2490 len = left;
2491 if(copy_to_user(s, buf, len))
2492 return -EFAULT;
2493 left -= len;
2494 s += len;
2495 }
2496 }
2497
2498 if (!write && !first && left) {
2499 if(put_user('\n', s))
2500 return -EFAULT;
2501 left--, s++;
2502 }
2503 if (write) {
2504 while (left) {
2505 char c;
2506 if (get_user(c, s++))
2507 return -EFAULT;
2508 if (!isspace(c))
2509 break;
2510 left--;
2511 }
2512 }
2513 if (write && first)
2514 return -EINVAL;
2515 *lenp -= left;
2516 *ppos += *lenp;
2517 return 0;
2518#undef TMPBUFLEN
2519}
2520
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002521static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002522 struct file *filp,
2523 void __user *buffer,
2524 size_t *lenp, loff_t *ppos,
2525 unsigned long convmul,
2526 unsigned long convdiv)
2527{
2528 return __do_proc_doulongvec_minmax(table->data, table, write,
2529 filp, buffer, lenp, ppos, convmul, convdiv);
2530}
2531
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532/**
2533 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2534 * @table: the sysctl table
2535 * @write: %TRUE if this is a write to the sysctl file
2536 * @filp: the file structure
2537 * @buffer: the user buffer
2538 * @lenp: the size of the user buffer
2539 * @ppos: file position
2540 *
2541 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2542 * values from/to the user buffer, treated as an ASCII string.
2543 *
2544 * This routine will ensure the values are within the range specified by
2545 * table->extra1 (min) and table->extra2 (max).
2546 *
2547 * Returns 0 on success.
2548 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002549int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 void __user *buffer, size_t *lenp, loff_t *ppos)
2551{
2552 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2553}
2554
2555/**
2556 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2557 * @table: the sysctl table
2558 * @write: %TRUE if this is a write to the sysctl file
2559 * @filp: the file structure
2560 * @buffer: the user buffer
2561 * @lenp: the size of the user buffer
2562 * @ppos: file position
2563 *
2564 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2565 * values from/to the user buffer, treated as an ASCII string. The values
2566 * are treated as milliseconds, and converted to jiffies when they are stored.
2567 *
2568 * This routine will ensure the values are within the range specified by
2569 * table->extra1 (min) and table->extra2 (max).
2570 *
2571 * Returns 0 on success.
2572 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002573int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 struct file *filp,
2575 void __user *buffer,
2576 size_t *lenp, loff_t *ppos)
2577{
2578 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2579 lenp, ppos, HZ, 1000l);
2580}
2581
2582
2583static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2584 int *valp,
2585 int write, void *data)
2586{
2587 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002588 if (*lvalp > LONG_MAX / HZ)
2589 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2591 } else {
2592 int val = *valp;
2593 unsigned long lval;
2594 if (val < 0) {
2595 *negp = -1;
2596 lval = (unsigned long)-val;
2597 } else {
2598 *negp = 0;
2599 lval = (unsigned long)val;
2600 }
2601 *lvalp = lval / HZ;
2602 }
2603 return 0;
2604}
2605
2606static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2607 int *valp,
2608 int write, void *data)
2609{
2610 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002611 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2612 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2614 } else {
2615 int val = *valp;
2616 unsigned long lval;
2617 if (val < 0) {
2618 *negp = -1;
2619 lval = (unsigned long)-val;
2620 } else {
2621 *negp = 0;
2622 lval = (unsigned long)val;
2623 }
2624 *lvalp = jiffies_to_clock_t(lval);
2625 }
2626 return 0;
2627}
2628
2629static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2630 int *valp,
2631 int write, void *data)
2632{
2633 if (write) {
2634 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2635 } else {
2636 int val = *valp;
2637 unsigned long lval;
2638 if (val < 0) {
2639 *negp = -1;
2640 lval = (unsigned long)-val;
2641 } else {
2642 *negp = 0;
2643 lval = (unsigned long)val;
2644 }
2645 *lvalp = jiffies_to_msecs(lval);
2646 }
2647 return 0;
2648}
2649
2650/**
2651 * proc_dointvec_jiffies - read a vector of integers as seconds
2652 * @table: the sysctl table
2653 * @write: %TRUE if this is a write to the sysctl file
2654 * @filp: the file structure
2655 * @buffer: the user buffer
2656 * @lenp: the size of the user buffer
2657 * @ppos: file position
2658 *
2659 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2660 * values from/to the user buffer, treated as an ASCII string.
2661 * The values read are assumed to be in seconds, and are converted into
2662 * jiffies.
2663 *
2664 * Returns 0 on success.
2665 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002666int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 void __user *buffer, size_t *lenp, loff_t *ppos)
2668{
2669 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2670 do_proc_dointvec_jiffies_conv,NULL);
2671}
2672
2673/**
2674 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2675 * @table: the sysctl table
2676 * @write: %TRUE if this is a write to the sysctl file
2677 * @filp: the file structure
2678 * @buffer: the user buffer
2679 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002680 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 *
2682 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2683 * values from/to the user buffer, treated as an ASCII string.
2684 * The values read are assumed to be in 1/USER_HZ seconds, and
2685 * are converted into jiffies.
2686 *
2687 * Returns 0 on success.
2688 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002689int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 void __user *buffer, size_t *lenp, loff_t *ppos)
2691{
2692 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2693 do_proc_dointvec_userhz_jiffies_conv,NULL);
2694}
2695
2696/**
2697 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2698 * @table: the sysctl table
2699 * @write: %TRUE if this is a write to the sysctl file
2700 * @filp: the file structure
2701 * @buffer: the user buffer
2702 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002703 * @ppos: file position
2704 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 *
2706 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2707 * values from/to the user buffer, treated as an ASCII string.
2708 * The values read are assumed to be in 1/1000 seconds, and
2709 * are converted into jiffies.
2710 *
2711 * Returns 0 on success.
2712 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002713int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 void __user *buffer, size_t *lenp, loff_t *ppos)
2715{
2716 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2717 do_proc_dointvec_ms_jiffies_conv, NULL);
2718}
2719
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002720static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002721 void __user *buffer, size_t *lenp, loff_t *ppos)
2722{
2723 struct pid *new_pid;
2724 pid_t tmp;
2725 int r;
2726
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002727 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002728
2729 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2730 lenp, ppos, NULL, NULL);
2731 if (r || !write)
2732 return r;
2733
2734 new_pid = find_get_pid(tmp);
2735 if (!new_pid)
2736 return -ESRCH;
2737
2738 put_pid(xchg(&cad_pid, new_pid));
2739 return 0;
2740}
2741
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742#else /* CONFIG_PROC_FS */
2743
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002744int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 void __user *buffer, size_t *lenp, loff_t *ppos)
2746{
2747 return -ENOSYS;
2748}
2749
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002750int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 void __user *buffer, size_t *lenp, loff_t *ppos)
2752{
2753 return -ENOSYS;
2754}
2755
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002756int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 void __user *buffer, size_t *lenp, loff_t *ppos)
2758{
2759 return -ENOSYS;
2760}
2761
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002762int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 void __user *buffer, size_t *lenp, loff_t *ppos)
2764{
2765 return -ENOSYS;
2766}
2767
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002768int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 void __user *buffer, size_t *lenp, loff_t *ppos)
2770{
2771 return -ENOSYS;
2772}
2773
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002774int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 void __user *buffer, size_t *lenp, loff_t *ppos)
2776{
2777 return -ENOSYS;
2778}
2779
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002780int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 void __user *buffer, size_t *lenp, loff_t *ppos)
2782{
2783 return -ENOSYS;
2784}
2785
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002786int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 struct file *filp,
2788 void __user *buffer,
2789 size_t *lenp, loff_t *ppos)
2790{
2791 return -ENOSYS;
2792}
2793
2794
2795#endif /* CONFIG_PROC_FS */
2796
2797
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002798#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799/*
2800 * General sysctl support routines
2801 */
2802
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002803/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002804int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002805 void __user *oldval, size_t __user *oldlenp,
2806 void __user *newval, size_t newlen)
2807{
2808 size_t len;
2809
2810 /* Get out of I don't have a variable */
2811 if (!table->data || !table->maxlen)
2812 return -ENOTDIR;
2813
2814 if (oldval && oldlenp) {
2815 if (get_user(len, oldlenp))
2816 return -EFAULT;
2817 if (len) {
2818 if (len > table->maxlen)
2819 len = table->maxlen;
2820 if (copy_to_user(oldval, table->data, len))
2821 return -EFAULT;
2822 if (put_user(len, oldlenp))
2823 return -EFAULT;
2824 }
2825 }
2826
2827 if (newval && newlen) {
2828 if (newlen > table->maxlen)
2829 newlen = table->maxlen;
2830
2831 if (copy_from_user(table->data, newval, newlen))
2832 return -EFAULT;
2833 }
2834 return 1;
2835}
2836
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002838int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002840 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 if (!table->data || !table->maxlen)
2843 return -ENOTDIR;
2844
2845 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002846 size_t bufsize;
2847 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002849 if (bufsize) {
2850 size_t len = strlen(table->data), copied;
2851
2852 /* This shouldn't trigger for a well-formed sysctl */
2853 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002855
2856 /* Copy up to a max of bufsize-1 bytes of the string */
2857 copied = (len >= bufsize) ? bufsize - 1 : len;
2858
2859 if (copy_to_user(oldval, table->data, copied) ||
2860 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002862 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 return -EFAULT;
2864 }
2865 }
2866 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002867 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 if (len > table->maxlen)
2869 len = table->maxlen;
2870 if(copy_from_user(table->data, newval, len))
2871 return -EFAULT;
2872 if (len == table->maxlen)
2873 len--;
2874 ((char *) table->data)[len] = 0;
2875 }
Yi Yang82c9df82005-12-30 16:37:10 +08002876 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877}
2878
2879/*
2880 * This function makes sure that all of the integers in the vector
2881 * are between the minimum and maximum values given in the arrays
2882 * table->extra1 and table->extra2, respectively.
2883 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002884int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002886 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887{
2888
2889 if (newval && newlen) {
2890 int __user *vec = (int __user *) newval;
2891 int *min = (int *) table->extra1;
2892 int *max = (int *) table->extra2;
2893 size_t length;
2894 int i;
2895
2896 if (newlen % sizeof(int) != 0)
2897 return -EINVAL;
2898
2899 if (!table->extra1 && !table->extra2)
2900 return 0;
2901
2902 if (newlen > table->maxlen)
2903 newlen = table->maxlen;
2904 length = newlen / sizeof(int);
2905
2906 for (i = 0; i < length; i++) {
2907 int value;
2908 if (get_user(value, vec + i))
2909 return -EFAULT;
2910 if (min && value < min[i])
2911 return -EINVAL;
2912 if (max && value > max[i])
2913 return -EINVAL;
2914 }
2915 }
2916 return 0;
2917}
2918
2919/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002920int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002922 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002924 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002926
2927 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002929 if (olen) {
2930 int val;
2931
2932 if (olen < sizeof(int))
2933 return -EINVAL;
2934
2935 val = *(int *)(table->data) / HZ;
2936 if (put_user(val, (int __user *)oldval))
2937 return -EFAULT;
2938 if (put_user(sizeof(int), oldlenp))
2939 return -EFAULT;
2940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 }
2942 if (newval && newlen) {
2943 int new;
2944 if (newlen != sizeof(int))
2945 return -EINVAL;
2946 if (get_user(new, (int __user *)newval))
2947 return -EFAULT;
2948 *(int *)(table->data) = new*HZ;
2949 }
2950 return 1;
2951}
2952
2953/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002954int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002956 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002958 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002960
2961 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002963 if (olen) {
2964 int val;
2965
2966 if (olen < sizeof(int))
2967 return -EINVAL;
2968
2969 val = jiffies_to_msecs(*(int *)(table->data));
2970 if (put_user(val, (int __user *)oldval))
2971 return -EFAULT;
2972 if (put_user(sizeof(int), oldlenp))
2973 return -EFAULT;
2974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 }
2976 if (newval && newlen) {
2977 int new;
2978 if (newlen != sizeof(int))
2979 return -EINVAL;
2980 if (get_user(new, (int __user *)newval))
2981 return -EFAULT;
2982 *(int *)(table->data) = msecs_to_jiffies(new);
2983 }
2984 return 1;
2985}
2986
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002987
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002988
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002989#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
2991
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01002992SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002994 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002995 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002996
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002997 if (copy_from_user(&tmp, args, sizeof(tmp)))
2998 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002999
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003000 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003001
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003002 /* If no error reading the parameters then just -ENOSYS ... */
3003 if (!error)
3004 error = -ENOSYS;
3005
3006 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007}
3008
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003009int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003010 void __user *oldval, size_t __user *oldlenp,
3011 void __user *newval, size_t newlen)
3012{
3013 return -ENOSYS;
3014}
3015
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003016int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003018 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019{
3020 return -ENOSYS;
3021}
3022
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003023int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003025 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026{
3027 return -ENOSYS;
3028}
3029
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003030int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003032 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033{
3034 return -ENOSYS;
3035}
3036
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003037int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003039 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040{
3041 return -ENOSYS;
3042}
3043
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003044#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003046static int deprecated_sysctl_warning(struct __sysctl_args *args)
3047{
3048 static int msg_count;
3049 int name[CTL_MAXNAME];
3050 int i;
3051
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003052 /* Check args->nlen. */
3053 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3054 return -ENOTDIR;
3055
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003056 /* Read in the sysctl name for better debug message logging */
3057 for (i = 0; i < args->nlen; i++)
3058 if (get_user(name[i], args->name + i))
3059 return -EFAULT;
3060
3061 /* Ignore accesses to kernel.version */
3062 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3063 return 0;
3064
3065 if (msg_count < 5) {
3066 msg_count++;
3067 printk(KERN_INFO
3068 "warning: process `%s' used the deprecated sysctl "
3069 "system call with ", current->comm);
3070 for (i = 0; i < args->nlen; i++)
3071 printk("%d.", name[i]);
3072 printk("\n");
3073 }
3074 return 0;
3075}
3076
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077/*
3078 * No sense putting this after each symbol definition, twice,
3079 * exception granted :-)
3080 */
3081EXPORT_SYMBOL(proc_dointvec);
3082EXPORT_SYMBOL(proc_dointvec_jiffies);
3083EXPORT_SYMBOL(proc_dointvec_minmax);
3084EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3085EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3086EXPORT_SYMBOL(proc_dostring);
3087EXPORT_SYMBOL(proc_doulongvec_minmax);
3088EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3089EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003090EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091EXPORT_SYMBOL(sysctl_intvec);
3092EXPORT_SYMBOL(sysctl_jiffies);
3093EXPORT_SYMBOL(sysctl_ms_jiffies);
3094EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003095EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096EXPORT_SYMBOL(unregister_sysctl_table);