blob: ce664f98e3fb67d7741182b9bce3fd29f4b8b88f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Peter Zijlstra1ccd1542009-04-09 10:53:45 +020052#include <linux/perf_counter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <asm/uaccess.h>
55#include <asm/processor.h>
56
Andi Kleen29cbc782006-09-30 01:47:55 +020057#ifdef CONFIG_X86
58#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010059#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010060#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020061#endif
62
Eric W. Biederman7058cb02007-10-18 03:05:58 -070063static int deprecated_sysctl_warning(struct __sysctl_args *args);
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#if defined(CONFIG_SYSCTL)
66
67/* External variables not in a header file. */
68extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070069extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int sysctl_overcommit_memory;
71extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070072extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070073extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080074extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070077extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max;
80extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080082extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080083extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020084extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010085extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040086extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000087#ifndef CONFIG_MMU
88extern int sysctl_nr_trim_pages;
89#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070090#ifdef CONFIG_RCU_TORTURE_TEST
91extern int rcutorture_runnable;
92#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070094/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080095#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020097static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098#endif
99
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700101static int __maybe_unused one = 1;
102static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800103static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700104static int one_hundred = 100;
105
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700106/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
107static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110static int maxolduid = 65535;
111static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800112static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static int ngroups_max = NGROUPS_MAX;
115
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200116#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700118extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#ifdef CONFIG_CHR_DEV_SG
121extern int sg_big_buff;
122#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
David S. Miller72c57ed2008-09-11 23:29:54 -0700124#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700125#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#endif
127
David S. Miller08714202008-11-16 23:49:24 -0800128#ifdef CONFIG_SPARC64
129extern int sysctl_tsb_ratio;
130#endif
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#ifdef __hppa__
133extern int pwrsw_enabled;
134extern int unaligned_enabled;
135#endif
136
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800137#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#ifdef CONFIG_MATHEMU
139extern int sysctl_ieee_emulation_warnings;
140#endif
141extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700142extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#endif
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#ifdef CONFIG_BSD_PROCESS_ACCT
146extern int acct_parm[];
147#endif
148
Jes Sorensend2b176e2006-02-28 09:42:23 -0800149#ifdef CONFIG_IA64
150extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800151extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800152#endif
153
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700154#ifdef CONFIG_RT_MUTEXES
155extern int max_lock_depth;
156#endif
157
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700158#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700159static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700160 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700161static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800162 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700163#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700164
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700165static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100166static struct ctl_table_root sysctl_table_root;
167static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100168 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100169 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400170 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100171 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400172 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100173};
174static struct ctl_table_root sysctl_table_root = {
175 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400176 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100177};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700179static struct ctl_table kern_table[];
180static struct ctl_table vm_table[];
181static struct ctl_table fs_table[];
182static struct ctl_table debug_table[];
183static struct ctl_table dev_table[];
184extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700185#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700186extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400187#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800188#ifdef CONFIG_EPOLL
189extern struct ctl_table epoll_table[];
190#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
193int sysctl_legacy_va_layout;
194#endif
195
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700196extern int prove_locking;
197extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199/* The default sysctl tables: */
200
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700201static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 {
203 .ctl_name = CTL_KERN,
204 .procname = "kernel",
205 .mode = 0555,
206 .child = kern_table,
207 },
208 {
209 .ctl_name = CTL_VM,
210 .procname = "vm",
211 .mode = 0555,
212 .child = vm_table,
213 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 .ctl_name = CTL_FS,
216 .procname = "fs",
217 .mode = 0555,
218 .child = fs_table,
219 },
220 {
221 .ctl_name = CTL_DEBUG,
222 .procname = "debug",
223 .mode = 0555,
224 .child = debug_table,
225 },
226 {
227 .ctl_name = CTL_DEV,
228 .procname = "dev",
229 .mode = 0555,
230 .child = dev_table,
231 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700232/*
233 * NOTE: do not add new entries to this table unless you have read
234 * Documentation/sysctl/ctl_unnumbered.txt
235 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 { .ctl_name = 0 }
237};
238
Ingo Molnar77e54a12007-07-09 18:52:00 +0200239#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100240static int min_sched_granularity_ns = 100000; /* 100 usecs */
241static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
242static int min_wakeup_granularity_ns; /* 0 usecs */
243static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244#endif
245
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700246static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200247#ifdef CONFIG_SCHED_DEBUG
248 {
249 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100250 .procname = "sched_min_granularity_ns",
251 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200252 .maxlen = sizeof(unsigned int),
253 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100254 .proc_handler = &sched_nr_latency_handler,
255 .strategy = &sysctl_intvec,
256 .extra1 = &min_sched_granularity_ns,
257 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200258 },
259 {
260 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200261 .procname = "sched_latency_ns",
262 .data = &sysctl_sched_latency,
263 .maxlen = sizeof(unsigned int),
264 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100265 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200266 .strategy = &sysctl_intvec,
267 .extra1 = &min_sched_granularity_ns,
268 .extra2 = &max_sched_granularity_ns,
269 },
270 {
271 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200272 .procname = "sched_wakeup_granularity_ns",
273 .data = &sysctl_sched_wakeup_granularity,
274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
276 .proc_handler = &proc_dointvec_minmax,
277 .strategy = &sysctl_intvec,
278 .extra1 = &min_wakeup_granularity_ns,
279 .extra2 = &max_wakeup_granularity_ns,
280 },
281 {
282 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200283 .procname = "sched_shares_ratelimit",
284 .data = &sysctl_sched_shares_ratelimit,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = &proc_dointvec,
288 },
289 {
290 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200291 .procname = "sched_shares_thresh",
292 .data = &sysctl_sched_shares_thresh,
293 .maxlen = sizeof(unsigned int),
294 .mode = 0644,
295 .proc_handler = &proc_dointvec_minmax,
296 .strategy = &sysctl_intvec,
297 .extra1 = &zero,
298 },
299 {
300 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301 .procname = "sched_child_runs_first",
302 .data = &sysctl_sched_child_runs_first,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = &proc_dointvec,
306 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200307 {
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "sched_features",
310 .data = &sysctl_sched_features,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = &proc_dointvec,
314 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200315 {
316 .ctl_name = CTL_UNNUMBERED,
317 .procname = "sched_migration_cost",
318 .data = &sysctl_sched_migration_cost,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
321 .proc_handler = &proc_dointvec,
322 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100323 {
324 .ctl_name = CTL_UNNUMBERED,
325 .procname = "sched_nr_migrate",
326 .data = &sysctl_sched_nr_migrate,
327 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100328 .mode = 0644,
329 .proc_handler = &proc_dointvec,
330 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200331#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200332 {
333 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100334 .procname = "sched_rt_period_us",
335 .data = &sysctl_sched_rt_period,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200338 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100339 },
340 {
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "sched_rt_runtime_us",
343 .data = &sysctl_sched_rt_runtime,
344 .maxlen = sizeof(int),
345 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200346 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100347 },
348 {
349 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200350 .procname = "sched_compat_yield",
351 .data = &sysctl_sched_compat_yield,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
355 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700356#ifdef CONFIG_PROVE_LOCKING
357 {
358 .ctl_name = CTL_UNNUMBERED,
359 .procname = "prove_locking",
360 .data = &prove_locking,
361 .maxlen = sizeof(int),
362 .mode = 0644,
363 .proc_handler = &proc_dointvec,
364 },
365#endif
366#ifdef CONFIG_LOCK_STAT
367 {
368 .ctl_name = CTL_UNNUMBERED,
369 .procname = "lock_stat",
370 .data = &lock_stat,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = &proc_dointvec,
374 },
375#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200376 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 .ctl_name = KERN_PANIC,
378 .procname = "panic",
379 .data = &panic_timeout,
380 .maxlen = sizeof(int),
381 .mode = 0644,
382 .proc_handler = &proc_dointvec,
383 },
384 {
385 .ctl_name = KERN_CORE_USES_PID,
386 .procname = "core_uses_pid",
387 .data = &core_uses_pid,
388 .maxlen = sizeof(int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
391 },
392 {
393 .ctl_name = KERN_CORE_PATTERN,
394 .procname = "core_pattern",
395 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700396 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 .mode = 0644,
398 .proc_handler = &proc_dostring,
399 .strategy = &sysctl_string,
400 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800401#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700404 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800405 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700406 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800408#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100409#ifdef CONFIG_LATENCYTOP
410 {
411 .procname = "latencytop",
412 .data = &latencytop_enabled,
413 .maxlen = sizeof(int),
414 .mode = 0644,
415 .proc_handler = &proc_dointvec,
416 },
417#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#ifdef CONFIG_BLK_DEV_INITRD
419 {
420 .ctl_name = KERN_REALROOTDEV,
421 .procname = "real-root-dev",
422 .data = &real_root_dev,
423 .maxlen = sizeof(int),
424 .mode = 0644,
425 .proc_handler = &proc_dointvec,
426 },
427#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700428 {
429 .ctl_name = CTL_UNNUMBERED,
430 .procname = "print-fatal-signals",
431 .data = &print_fatal_signals,
432 .maxlen = sizeof(int),
433 .mode = 0644,
434 .proc_handler = &proc_dointvec,
435 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700436#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 {
438 .ctl_name = KERN_SPARC_REBOOT,
439 .procname = "reboot-cmd",
440 .data = reboot_command,
441 .maxlen = 256,
442 .mode = 0644,
443 .proc_handler = &proc_dostring,
444 .strategy = &sysctl_string,
445 },
446 {
447 .ctl_name = KERN_SPARC_STOP_A,
448 .procname = "stop-a",
449 .data = &stop_a_enabled,
450 .maxlen = sizeof (int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
453 },
454 {
455 .ctl_name = KERN_SPARC_SCONS_PWROFF,
456 .procname = "scons-poweroff",
457 .data = &scons_pwroff,
458 .maxlen = sizeof (int),
459 .mode = 0644,
460 .proc_handler = &proc_dointvec,
461 },
462#endif
David S. Miller08714202008-11-16 23:49:24 -0800463#ifdef CONFIG_SPARC64
464 {
465 .ctl_name = CTL_UNNUMBERED,
466 .procname = "tsb-ratio",
467 .data = &sysctl_tsb_ratio,
468 .maxlen = sizeof (int),
469 .mode = 0644,
470 .proc_handler = &proc_dointvec,
471 },
472#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#ifdef __hppa__
474 {
475 .ctl_name = KERN_HPPA_PWRSW,
476 .procname = "soft-power",
477 .data = &pwrsw_enabled,
478 .maxlen = sizeof (int),
479 .mode = 0644,
480 .proc_handler = &proc_dointvec,
481 },
482 {
483 .ctl_name = KERN_HPPA_UNALIGNED,
484 .procname = "unaligned-trap",
485 .data = &unaligned_enabled,
486 .maxlen = sizeof (int),
487 .mode = 0644,
488 .proc_handler = &proc_dointvec,
489 },
490#endif
491 {
492 .ctl_name = KERN_CTLALTDEL,
493 .procname = "ctrl-alt-del",
494 .data = &C_A_D,
495 .maxlen = sizeof(int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
498 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400499#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200500 {
501 .ctl_name = CTL_UNNUMBERED,
502 .procname = "ftrace_enabled",
503 .data = &ftrace_enabled,
504 .maxlen = sizeof(int),
505 .mode = 0644,
506 .proc_handler = &ftrace_enable_sysctl,
507 },
508#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500509#ifdef CONFIG_STACK_TRACER
510 {
511 .ctl_name = CTL_UNNUMBERED,
512 .procname = "stack_tracer_enabled",
513 .data = &stack_tracer_enabled,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = &stack_trace_sysctl,
517 },
518#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400519#ifdef CONFIG_TRACING
520 {
521 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100522 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400523 .data = &ftrace_dump_on_oops,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = &proc_dointvec,
527 },
528#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200529#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 {
531 .ctl_name = KERN_MODPROBE,
532 .procname = "modprobe",
533 .data = &modprobe_path,
534 .maxlen = KMOD_PATH_LEN,
535 .mode = 0644,
536 .proc_handler = &proc_dostring,
537 .strategy = &sysctl_string,
538 },
Kees Cook3d433212009-04-02 15:49:29 -0700539 {
540 .ctl_name = CTL_UNNUMBERED,
541 .procname = "modules_disabled",
542 .data = &modules_disabled,
543 .maxlen = sizeof(int),
544 .mode = 0644,
545 /* only handle a transition from default "0" to "1" */
546 .proc_handler = &proc_dointvec_minmax,
547 .extra1 = &one,
548 .extra2 = &one,
549 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700551#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 {
553 .ctl_name = KERN_HOTPLUG,
554 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100555 .data = &uevent_helper,
556 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .mode = 0644,
558 .proc_handler = &proc_dostring,
559 .strategy = &sysctl_string,
560 },
561#endif
562#ifdef CONFIG_CHR_DEV_SG
563 {
564 .ctl_name = KERN_SG_BIG_BUFF,
565 .procname = "sg-big-buff",
566 .data = &sg_big_buff,
567 .maxlen = sizeof (int),
568 .mode = 0444,
569 .proc_handler = &proc_dointvec,
570 },
571#endif
572#ifdef CONFIG_BSD_PROCESS_ACCT
573 {
574 .ctl_name = KERN_ACCT,
575 .procname = "acct",
576 .data = &acct_parm,
577 .maxlen = 3*sizeof(int),
578 .mode = 0644,
579 .proc_handler = &proc_dointvec,
580 },
581#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582#ifdef CONFIG_MAGIC_SYSRQ
583 {
584 .ctl_name = KERN_SYSRQ,
585 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800586 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .maxlen = sizeof (int),
588 .mode = 0644,
589 .proc_handler = &proc_dointvec,
590 },
591#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700592#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700595 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 .maxlen = sizeof (int),
597 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700598 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700600#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 {
602 .ctl_name = KERN_MAX_THREADS,
603 .procname = "threads-max",
604 .data = &max_threads,
605 .maxlen = sizeof(int),
606 .mode = 0644,
607 .proc_handler = &proc_dointvec,
608 },
609 {
610 .ctl_name = KERN_RANDOM,
611 .procname = "random",
612 .mode = 0555,
613 .child = random_table,
614 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 {
616 .ctl_name = KERN_OVERFLOWUID,
617 .procname = "overflowuid",
618 .data = &overflowuid,
619 .maxlen = sizeof(int),
620 .mode = 0644,
621 .proc_handler = &proc_dointvec_minmax,
622 .strategy = &sysctl_intvec,
623 .extra1 = &minolduid,
624 .extra2 = &maxolduid,
625 },
626 {
627 .ctl_name = KERN_OVERFLOWGID,
628 .procname = "overflowgid",
629 .data = &overflowgid,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec_minmax,
633 .strategy = &sysctl_intvec,
634 .extra1 = &minolduid,
635 .extra2 = &maxolduid,
636 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800637#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638#ifdef CONFIG_MATHEMU
639 {
640 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
641 .procname = "ieee_emulation_warnings",
642 .data = &sysctl_ieee_emulation_warnings,
643 .maxlen = sizeof(int),
644 .mode = 0644,
645 .proc_handler = &proc_dointvec,
646 },
647#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 {
649 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
650 .procname = "userprocess_debug",
651 .data = &sysctl_userprocess_debug,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = &proc_dointvec,
655 },
656#endif
657 {
658 .ctl_name = KERN_PIDMAX,
659 .procname = "pid_max",
660 .data = &pid_max,
661 .maxlen = sizeof (int),
662 .mode = 0644,
663 .proc_handler = &proc_dointvec_minmax,
664 .strategy = sysctl_intvec,
665 .extra1 = &pid_max_min,
666 .extra2 = &pid_max_max,
667 },
668 {
669 .ctl_name = KERN_PANIC_ON_OOPS,
670 .procname = "panic_on_oops",
671 .data = &panic_on_oops,
672 .maxlen = sizeof(int),
673 .mode = 0644,
674 .proc_handler = &proc_dointvec,
675 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800676#if defined CONFIG_PRINTK
677 {
678 .ctl_name = KERN_PRINTK,
679 .procname = "printk",
680 .data = &console_loglevel,
681 .maxlen = 4*sizeof(int),
682 .mode = 0644,
683 .proc_handler = &proc_dointvec,
684 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 {
686 .ctl_name = KERN_PRINTK_RATELIMIT,
687 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700688 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .maxlen = sizeof(int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec_jiffies,
692 .strategy = &sysctl_jiffies,
693 },
694 {
695 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
696 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700697 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .maxlen = sizeof(int),
699 .mode = 0644,
700 .proc_handler = &proc_dointvec,
701 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800702#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 {
704 .ctl_name = KERN_NGROUPS_MAX,
705 .procname = "ngroups_max",
706 .data = &ngroups_max,
707 .maxlen = sizeof (int),
708 .mode = 0444,
709 .proc_handler = &proc_dointvec,
710 },
711#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
712 {
713 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
714 .procname = "unknown_nmi_panic",
715 .data = &unknown_nmi_panic,
716 .maxlen = sizeof (int),
717 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200718 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 },
Don Zickus407984f2006-09-26 10:52:27 +0200720 {
Don Zickus407984f2006-09-26 10:52:27 +0200721 .procname = "nmi_watchdog",
722 .data = &nmi_watchdog_enabled,
723 .maxlen = sizeof (int),
724 .mode = 0644,
725 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 },
727#endif
728#if defined(CONFIG_X86)
729 {
Don Zickus8da5add2006-09-26 10:52:27 +0200730 .ctl_name = KERN_PANIC_ON_NMI,
731 .procname = "panic_on_unrecovered_nmi",
732 .data = &panic_on_unrecovered_nmi,
733 .maxlen = sizeof(int),
734 .mode = 0644,
735 .proc_handler = &proc_dointvec,
736 },
737 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 .ctl_name = KERN_BOOTLOADER_TYPE,
739 .procname = "bootloader_type",
740 .data = &bootloader_type,
741 .maxlen = sizeof (int),
742 .mode = 0444,
743 .proc_handler = &proc_dointvec,
744 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100745 {
746 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700747 .procname = "bootloader_version",
748 .data = &bootloader_version,
749 .maxlen = sizeof (int),
750 .mode = 0444,
751 .proc_handler = &proc_dointvec,
752 },
753 {
754 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100755 .procname = "kstack_depth_to_print",
756 .data = &kstack_depth_to_print,
757 .maxlen = sizeof(int),
758 .mode = 0644,
759 .proc_handler = &proc_dointvec,
760 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100761 {
762 .ctl_name = CTL_UNNUMBERED,
763 .procname = "io_delay_type",
764 .data = &io_delay_type,
765 .maxlen = sizeof(int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
768 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800770#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 {
772 .ctl_name = KERN_RANDOMIZE,
773 .procname = "randomize_va_space",
774 .data = &randomize_va_space,
775 .maxlen = sizeof(int),
776 .mode = 0644,
777 .proc_handler = &proc_dointvec,
778 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800779#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800780#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700781 {
782 .ctl_name = KERN_SPIN_RETRY,
783 .procname = "spin_retry",
784 .data = &spin_retry,
785 .maxlen = sizeof (int),
786 .mode = 0644,
787 .proc_handler = &proc_dointvec,
788 },
789#endif
Len Brown673d5b42007-07-28 03:33:16 -0400790#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800791 {
Pavel Machekc255d842006-02-20 18:27:58 -0800792 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700793 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800794 .maxlen = sizeof (unsigned long),
795 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800796 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800797 },
798#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800799#ifdef CONFIG_IA64
800 {
801 .ctl_name = KERN_IA64_UNALIGNED,
802 .procname = "ignore-unaligned-usertrap",
803 .data = &no_unaligned_warning,
804 .maxlen = sizeof (int),
805 .mode = 0644,
806 .proc_handler = &proc_dointvec,
807 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800808 {
809 .ctl_name = CTL_UNNUMBERED,
810 .procname = "unaligned-dump-stack",
811 .data = &unaligned_dump_stack,
812 .maxlen = sizeof (int),
813 .mode = 0644,
814 .proc_handler = &proc_dointvec,
815 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800816#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700817#ifdef CONFIG_DETECT_SOFTLOCKUP
818 {
819 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200820 .procname = "softlockup_panic",
821 .data = &softlockup_panic,
822 .maxlen = sizeof(int),
823 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700824 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200825 .strategy = &sysctl_intvec,
826 .extra1 = &zero,
827 .extra2 = &one,
828 },
829 {
830 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700831 .procname = "softlockup_thresh",
832 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200833 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700834 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800835 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700836 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200837 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700838 .extra2 = &sixty,
839 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800840#endif
841#ifdef CONFIG_DETECT_HUNG_TASK
842 {
843 .ctl_name = CTL_UNNUMBERED,
844 .procname = "hung_task_panic",
845 .data = &sysctl_hung_task_panic,
846 .maxlen = sizeof(int),
847 .mode = 0644,
848 .proc_handler = &proc_dointvec_minmax,
849 .strategy = &sysctl_intvec,
850 .extra1 = &zero,
851 .extra2 = &one,
852 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100853 {
854 .ctl_name = CTL_UNNUMBERED,
855 .procname = "hung_task_check_count",
856 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100857 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100858 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100859 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100860 .strategy = &sysctl_intvec,
861 },
862 {
863 .ctl_name = CTL_UNNUMBERED,
864 .procname = "hung_task_timeout_secs",
865 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100866 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100867 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800868 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100869 .strategy = &sysctl_intvec,
870 },
871 {
872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "hung_task_warnings",
874 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100875 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100876 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100877 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100878 .strategy = &sysctl_intvec,
879 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700880#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200881#ifdef CONFIG_COMPAT
882 {
883 .ctl_name = KERN_COMPAT_LOG,
884 .procname = "compat-log",
885 .data = &compat_log,
886 .maxlen = sizeof (int),
887 .mode = 0644,
888 .proc_handler = &proc_dointvec,
889 },
890#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700891#ifdef CONFIG_RT_MUTEXES
892 {
893 .ctl_name = KERN_MAX_LOCK_DEPTH,
894 .procname = "max_lock_depth",
895 .data = &max_lock_depth,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = &proc_dointvec,
899 },
900#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700901 {
902 .ctl_name = CTL_UNNUMBERED,
903 .procname = "poweroff_cmd",
904 .data = &poweroff_cmd,
905 .maxlen = POWEROFF_CMD_PATH_LEN,
906 .mode = 0644,
907 .proc_handler = &proc_dostring,
908 .strategy = &sysctl_string,
909 },
David Howells0b77f5b2008-04-29 01:01:32 -0700910#ifdef CONFIG_KEYS
911 {
912 .ctl_name = CTL_UNNUMBERED,
913 .procname = "keys",
914 .mode = 0555,
915 .child = key_sysctls,
916 },
917#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700918#ifdef CONFIG_RCU_TORTURE_TEST
919 {
920 .ctl_name = CTL_UNNUMBERED,
921 .procname = "rcutorture_runnable",
922 .data = &rcutorture_runnable,
923 .maxlen = sizeof(int),
924 .mode = 0644,
925 .proc_handler = &proc_dointvec,
926 },
927#endif
David Howells12e22c52009-04-03 16:42:35 +0100928#ifdef CONFIG_SLOW_WORK
929 {
930 .ctl_name = CTL_UNNUMBERED,
931 .procname = "slow-work",
932 .mode = 0555,
933 .child = slow_work_sysctls,
934 },
935#endif
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200936#ifdef CONFIG_PERF_COUNTERS
937 {
938 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra07647712009-06-11 11:18:36 +0200939 .procname = "perf_counter_paranoid",
940 .data = &sysctl_perf_counter_paranoid,
941 .maxlen = sizeof(sysctl_perf_counter_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200942 .mode = 0644,
943 .proc_handler = &proc_dointvec,
944 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200945 {
946 .ctl_name = CTL_UNNUMBERED,
947 .procname = "perf_counter_mlock_kb",
948 .data = &sysctl_perf_counter_mlock,
949 .maxlen = sizeof(sysctl_perf_counter_mlock),
950 .mode = 0644,
951 .proc_handler = &proc_dointvec,
952 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200953 {
954 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstradf58ab22009-06-11 11:25:05 +0200955 .procname = "perf_counter_max_sample_rate",
956 .data = &sysctl_perf_counter_sample_rate,
957 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200958 .mode = 0644,
959 .proc_handler = &proc_dointvec,
960 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200961#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700962/*
963 * NOTE: do not add new entries to this table unless you have read
964 * Documentation/sysctl/ctl_unnumbered.txt
965 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 { .ctl_name = 0 }
967};
968
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700969static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 {
971 .ctl_name = VM_OVERCOMMIT_MEMORY,
972 .procname = "overcommit_memory",
973 .data = &sysctl_overcommit_memory,
974 .maxlen = sizeof(sysctl_overcommit_memory),
975 .mode = 0644,
976 .proc_handler = &proc_dointvec,
977 },
978 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700979 .ctl_name = VM_PANIC_ON_OOM,
980 .procname = "panic_on_oom",
981 .data = &sysctl_panic_on_oom,
982 .maxlen = sizeof(sysctl_panic_on_oom),
983 .mode = 0644,
984 .proc_handler = &proc_dointvec,
985 },
986 {
David Rientjesfe071d72007-10-16 23:25:56 -0700987 .ctl_name = CTL_UNNUMBERED,
988 .procname = "oom_kill_allocating_task",
989 .data = &sysctl_oom_kill_allocating_task,
990 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
991 .mode = 0644,
992 .proc_handler = &proc_dointvec,
993 },
994 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800995 .ctl_name = CTL_UNNUMBERED,
996 .procname = "oom_dump_tasks",
997 .data = &sysctl_oom_dump_tasks,
998 .maxlen = sizeof(sysctl_oom_dump_tasks),
999 .mode = 0644,
1000 .proc_handler = &proc_dointvec,
1001 },
1002 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 .ctl_name = VM_OVERCOMMIT_RATIO,
1004 .procname = "overcommit_ratio",
1005 .data = &sysctl_overcommit_ratio,
1006 .maxlen = sizeof(sysctl_overcommit_ratio),
1007 .mode = 0644,
1008 .proc_handler = &proc_dointvec,
1009 },
1010 {
1011 .ctl_name = VM_PAGE_CLUSTER,
1012 .procname = "page-cluster",
1013 .data = &page_cluster,
1014 .maxlen = sizeof(int),
1015 .mode = 0644,
1016 .proc_handler = &proc_dointvec,
1017 },
1018 {
1019 .ctl_name = VM_DIRTY_BACKGROUND,
1020 .procname = "dirty_background_ratio",
1021 .data = &dirty_background_ratio,
1022 .maxlen = sizeof(dirty_background_ratio),
1023 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001024 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 .strategy = &sysctl_intvec,
1026 .extra1 = &zero,
1027 .extra2 = &one_hundred,
1028 },
1029 {
David Rientjes2da02992009-01-06 14:39:31 -08001030 .ctl_name = CTL_UNNUMBERED,
1031 .procname = "dirty_background_bytes",
1032 .data = &dirty_background_bytes,
1033 .maxlen = sizeof(dirty_background_bytes),
1034 .mode = 0644,
1035 .proc_handler = &dirty_background_bytes_handler,
1036 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001037 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001038 },
1039 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .ctl_name = VM_DIRTY_RATIO,
1041 .procname = "dirty_ratio",
1042 .data = &vm_dirty_ratio,
1043 .maxlen = sizeof(vm_dirty_ratio),
1044 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001045 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 .strategy = &sysctl_intvec,
1047 .extra1 = &zero,
1048 .extra2 = &one_hundred,
1049 },
1050 {
David Rientjes2da02992009-01-06 14:39:31 -08001051 .ctl_name = CTL_UNNUMBERED,
1052 .procname = "dirty_bytes",
1053 .data = &vm_dirty_bytes,
1054 .maxlen = sizeof(vm_dirty_bytes),
1055 .mode = 0644,
1056 .proc_handler = &dirty_bytes_handler,
1057 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001058 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001059 },
1060 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001062 .data = &dirty_writeback_interval,
1063 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 .mode = 0644,
1065 .proc_handler = &dirty_writeback_centisecs_handler,
1066 },
1067 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001069 .data = &dirty_expire_interval,
1070 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001072 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 },
1074 {
1075 .ctl_name = VM_NR_PDFLUSH_THREADS,
1076 .procname = "nr_pdflush_threads",
1077 .data = &nr_pdflush_threads,
1078 .maxlen = sizeof nr_pdflush_threads,
1079 .mode = 0444 /* read-only*/,
1080 .proc_handler = &proc_dointvec,
1081 },
1082 {
1083 .ctl_name = VM_SWAPPINESS,
1084 .procname = "swappiness",
1085 .data = &vm_swappiness,
1086 .maxlen = sizeof(vm_swappiness),
1087 .mode = 0644,
1088 .proc_handler = &proc_dointvec_minmax,
1089 .strategy = &sysctl_intvec,
1090 .extra1 = &zero,
1091 .extra2 = &one_hundred,
1092 },
1093#ifdef CONFIG_HUGETLB_PAGE
1094 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001096 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 .maxlen = sizeof(unsigned long),
1098 .mode = 0644,
1099 .proc_handler = &hugetlb_sysctl_handler,
1100 .extra1 = (void *)&hugetlb_zero,
1101 .extra2 = (void *)&hugetlb_infinity,
1102 },
1103 {
1104 .ctl_name = VM_HUGETLB_GROUP,
1105 .procname = "hugetlb_shm_group",
1106 .data = &sysctl_hugetlb_shm_group,
1107 .maxlen = sizeof(gid_t),
1108 .mode = 0644,
1109 .proc_handler = &proc_dointvec,
1110 },
Mel Gorman396faf02007-07-17 04:03:13 -07001111 {
1112 .ctl_name = CTL_UNNUMBERED,
1113 .procname = "hugepages_treat_as_movable",
1114 .data = &hugepages_treat_as_movable,
1115 .maxlen = sizeof(int),
1116 .mode = 0644,
1117 .proc_handler = &hugetlb_treat_movable_handler,
1118 },
Adam Litke54f9f802007-10-16 01:26:20 -07001119 {
1120 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001121 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001122 .data = NULL,
1123 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001124 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001125 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001126 .extra1 = (void *)&hugetlb_zero,
1127 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001128 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129#endif
1130 {
1131 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1132 .procname = "lowmem_reserve_ratio",
1133 .data = &sysctl_lowmem_reserve_ratio,
1134 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1135 .mode = 0644,
1136 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1137 .strategy = &sysctl_intvec,
1138 },
1139 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001140 .ctl_name = VM_DROP_PAGECACHE,
1141 .procname = "drop_caches",
1142 .data = &sysctl_drop_caches,
1143 .maxlen = sizeof(int),
1144 .mode = 0644,
1145 .proc_handler = drop_caches_sysctl_handler,
1146 .strategy = &sysctl_intvec,
1147 },
1148 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 .ctl_name = VM_MIN_FREE_KBYTES,
1150 .procname = "min_free_kbytes",
1151 .data = &min_free_kbytes,
1152 .maxlen = sizeof(min_free_kbytes),
1153 .mode = 0644,
1154 .proc_handler = &min_free_kbytes_sysctl_handler,
1155 .strategy = &sysctl_intvec,
1156 .extra1 = &zero,
1157 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001158 {
1159 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1160 .procname = "percpu_pagelist_fraction",
1161 .data = &percpu_pagelist_fraction,
1162 .maxlen = sizeof(percpu_pagelist_fraction),
1163 .mode = 0644,
1164 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1165 .strategy = &sysctl_intvec,
1166 .extra1 = &min_percpu_pagelist_fract,
1167 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168#ifdef CONFIG_MMU
1169 {
1170 .ctl_name = VM_MAX_MAP_COUNT,
1171 .procname = "max_map_count",
1172 .data = &sysctl_max_map_count,
1173 .maxlen = sizeof(sysctl_max_map_count),
1174 .mode = 0644,
1175 .proc_handler = &proc_dointvec
1176 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001177#else
1178 {
1179 .ctl_name = CTL_UNNUMBERED,
1180 .procname = "nr_trim_pages",
1181 .data = &sysctl_nr_trim_pages,
1182 .maxlen = sizeof(sysctl_nr_trim_pages),
1183 .mode = 0644,
1184 .proc_handler = &proc_dointvec_minmax,
1185 .strategy = &sysctl_intvec,
1186 .extra1 = &zero,
1187 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188#endif
1189 {
1190 .ctl_name = VM_LAPTOP_MODE,
1191 .procname = "laptop_mode",
1192 .data = &laptop_mode,
1193 .maxlen = sizeof(laptop_mode),
1194 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001195 .proc_handler = &proc_dointvec_jiffies,
1196 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 },
1198 {
1199 .ctl_name = VM_BLOCK_DUMP,
1200 .procname = "block_dump",
1201 .data = &block_dump,
1202 .maxlen = sizeof(block_dump),
1203 .mode = 0644,
1204 .proc_handler = &proc_dointvec,
1205 .strategy = &sysctl_intvec,
1206 .extra1 = &zero,
1207 },
1208 {
1209 .ctl_name = VM_VFS_CACHE_PRESSURE,
1210 .procname = "vfs_cache_pressure",
1211 .data = &sysctl_vfs_cache_pressure,
1212 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1213 .mode = 0644,
1214 .proc_handler = &proc_dointvec,
1215 .strategy = &sysctl_intvec,
1216 .extra1 = &zero,
1217 },
1218#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1219 {
1220 .ctl_name = VM_LEGACY_VA_LAYOUT,
1221 .procname = "legacy_va_layout",
1222 .data = &sysctl_legacy_va_layout,
1223 .maxlen = sizeof(sysctl_legacy_va_layout),
1224 .mode = 0644,
1225 .proc_handler = &proc_dointvec,
1226 .strategy = &sysctl_intvec,
1227 .extra1 = &zero,
1228 },
1229#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001230#ifdef CONFIG_NUMA
1231 {
1232 .ctl_name = VM_ZONE_RECLAIM_MODE,
1233 .procname = "zone_reclaim_mode",
1234 .data = &zone_reclaim_mode,
1235 .maxlen = sizeof(zone_reclaim_mode),
1236 .mode = 0644,
1237 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001238 .strategy = &sysctl_intvec,
1239 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001240 },
Christoph Lameter96146342006-07-03 00:24:13 -07001241 {
1242 .ctl_name = VM_MIN_UNMAPPED,
1243 .procname = "min_unmapped_ratio",
1244 .data = &sysctl_min_unmapped_ratio,
1245 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1246 .mode = 0644,
1247 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1248 .strategy = &sysctl_intvec,
1249 .extra1 = &zero,
1250 .extra2 = &one_hundred,
1251 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001252 {
1253 .ctl_name = VM_MIN_SLAB,
1254 .procname = "min_slab_ratio",
1255 .data = &sysctl_min_slab_ratio,
1256 .maxlen = sizeof(sysctl_min_slab_ratio),
1257 .mode = 0644,
1258 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1259 .strategy = &sysctl_intvec,
1260 .extra1 = &zero,
1261 .extra2 = &one_hundred,
1262 },
Christoph Lameter17436602006-01-18 17:42:32 -08001263#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001264#ifdef CONFIG_SMP
1265 {
1266 .ctl_name = CTL_UNNUMBERED,
1267 .procname = "stat_interval",
1268 .data = &sysctl_stat_interval,
1269 .maxlen = sizeof(sysctl_stat_interval),
1270 .mode = 0644,
1271 .proc_handler = &proc_dointvec_jiffies,
1272 .strategy = &sysctl_jiffies,
1273 },
1274#endif
Eric Parised032182007-06-28 15:55:21 -04001275 {
1276 .ctl_name = CTL_UNNUMBERED,
1277 .procname = "mmap_min_addr",
1278 .data = &mmap_min_addr,
1279 .maxlen = sizeof(unsigned long),
1280 .mode = 0644,
1281 .proc_handler = &proc_doulongvec_minmax,
1282 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001283#ifdef CONFIG_NUMA
1284 {
1285 .ctl_name = CTL_UNNUMBERED,
1286 .procname = "numa_zonelist_order",
1287 .data = &numa_zonelist_order,
1288 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1289 .mode = 0644,
1290 .proc_handler = &numa_zonelist_order_handler,
1291 .strategy = &sysctl_string,
1292 },
1293#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001294#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001295 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001296 {
1297 .ctl_name = VM_VDSO_ENABLED,
1298 .procname = "vdso_enabled",
1299 .data = &vdso_enabled,
1300 .maxlen = sizeof(vdso_enabled),
1301 .mode = 0644,
1302 .proc_handler = &proc_dointvec,
1303 .strategy = &sysctl_intvec,
1304 .extra1 = &zero,
1305 },
1306#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001307#ifdef CONFIG_HIGHMEM
1308 {
1309 .ctl_name = CTL_UNNUMBERED,
1310 .procname = "highmem_is_dirtyable",
1311 .data = &vm_highmem_is_dirtyable,
1312 .maxlen = sizeof(vm_highmem_is_dirtyable),
1313 .mode = 0644,
1314 .proc_handler = &proc_dointvec_minmax,
1315 .strategy = &sysctl_intvec,
1316 .extra1 = &zero,
1317 .extra2 = &one,
1318 },
1319#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001320#ifdef CONFIG_UNEVICTABLE_LRU
1321 {
1322 .ctl_name = CTL_UNNUMBERED,
1323 .procname = "scan_unevictable_pages",
1324 .data = &scan_unevictable_pages,
1325 .maxlen = sizeof(scan_unevictable_pages),
1326 .mode = 0644,
1327 .proc_handler = &scan_unevictable_handler,
1328 },
1329#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001330/*
1331 * NOTE: do not add new entries to this table unless you have read
1332 * Documentation/sysctl/ctl_unnumbered.txt
1333 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 { .ctl_name = 0 }
1335};
1336
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001337#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001338static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001339 { .ctl_name = 0 }
1340};
1341#endif
1342
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001343static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 {
1345 .ctl_name = FS_NRINODE,
1346 .procname = "inode-nr",
1347 .data = &inodes_stat,
1348 .maxlen = 2*sizeof(int),
1349 .mode = 0444,
1350 .proc_handler = &proc_dointvec,
1351 },
1352 {
1353 .ctl_name = FS_STATINODE,
1354 .procname = "inode-state",
1355 .data = &inodes_stat,
1356 .maxlen = 7*sizeof(int),
1357 .mode = 0444,
1358 .proc_handler = &proc_dointvec,
1359 },
1360 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .procname = "file-nr",
1362 .data = &files_stat,
1363 .maxlen = 3*sizeof(int),
1364 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001365 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 },
1367 {
1368 .ctl_name = FS_MAXFILE,
1369 .procname = "file-max",
1370 .data = &files_stat.max_files,
1371 .maxlen = sizeof(int),
1372 .mode = 0644,
1373 .proc_handler = &proc_dointvec,
1374 },
1375 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001376 .ctl_name = CTL_UNNUMBERED,
1377 .procname = "nr_open",
1378 .data = &sysctl_nr_open,
1379 .maxlen = sizeof(int),
1380 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001381 .proc_handler = &proc_dointvec_minmax,
1382 .extra1 = &sysctl_nr_open_min,
1383 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001384 },
1385 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .ctl_name = FS_DENTRY,
1387 .procname = "dentry-state",
1388 .data = &dentry_stat,
1389 .maxlen = 6*sizeof(int),
1390 .mode = 0444,
1391 .proc_handler = &proc_dointvec,
1392 },
1393 {
1394 .ctl_name = FS_OVERFLOWUID,
1395 .procname = "overflowuid",
1396 .data = &fs_overflowuid,
1397 .maxlen = sizeof(int),
1398 .mode = 0644,
1399 .proc_handler = &proc_dointvec_minmax,
1400 .strategy = &sysctl_intvec,
1401 .extra1 = &minolduid,
1402 .extra2 = &maxolduid,
1403 },
1404 {
1405 .ctl_name = FS_OVERFLOWGID,
1406 .procname = "overflowgid",
1407 .data = &fs_overflowgid,
1408 .maxlen = sizeof(int),
1409 .mode = 0644,
1410 .proc_handler = &proc_dointvec_minmax,
1411 .strategy = &sysctl_intvec,
1412 .extra1 = &minolduid,
1413 .extra2 = &maxolduid,
1414 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001415#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 {
1417 .ctl_name = FS_LEASES,
1418 .procname = "leases-enable",
1419 .data = &leases_enable,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
1422 .proc_handler = &proc_dointvec,
1423 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001424#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425#ifdef CONFIG_DNOTIFY
1426 {
1427 .ctl_name = FS_DIR_NOTIFY,
1428 .procname = "dir-notify-enable",
1429 .data = &dir_notify_enable,
1430 .maxlen = sizeof(int),
1431 .mode = 0644,
1432 .proc_handler = &proc_dointvec,
1433 },
1434#endif
1435#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001436#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 {
1438 .ctl_name = FS_LEASE_TIME,
1439 .procname = "lease-break-time",
1440 .data = &lease_break_time,
1441 .maxlen = sizeof(int),
1442 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001443 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001445#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001446#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .procname = "aio-nr",
1449 .data = &aio_nr,
1450 .maxlen = sizeof(aio_nr),
1451 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001452 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 },
1454 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 .procname = "aio-max-nr",
1456 .data = &aio_max_nr,
1457 .maxlen = sizeof(aio_max_nr),
1458 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001459 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001461#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001462#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001463 {
1464 .ctl_name = FS_INOTIFY,
1465 .procname = "inotify",
1466 .mode = 0555,
1467 .child = inotify_table,
1468 },
1469#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001470#ifdef CONFIG_EPOLL
1471 {
1472 .procname = "epoll",
1473 .mode = 0555,
1474 .child = epoll_table,
1475 },
1476#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001478 {
1479 .ctl_name = KERN_SETUID_DUMPABLE,
1480 .procname = "suid_dumpable",
1481 .data = &suid_dumpable,
1482 .maxlen = sizeof(int),
1483 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001484 .proc_handler = &proc_dointvec_minmax,
1485 .strategy = &sysctl_intvec,
1486 .extra1 = &zero,
1487 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001488 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001489#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1490 {
1491 .ctl_name = CTL_UNNUMBERED,
1492 .procname = "binfmt_misc",
1493 .mode = 0555,
1494 .child = binfmt_misc_table,
1495 },
1496#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001497/*
1498 * NOTE: do not add new entries to this table unless you have read
1499 * Documentation/sysctl/ctl_unnumbered.txt
1500 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 { .ctl_name = 0 }
1502};
1503
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001504static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001505#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001506 {
1507 .ctl_name = CTL_UNNUMBERED,
1508 .procname = "exception-trace",
1509 .data = &show_unhandled_signals,
1510 .maxlen = sizeof(int),
1511 .mode = 0644,
1512 .proc_handler = proc_dointvec
1513 },
1514#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 { .ctl_name = 0 }
1516};
1517
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001518static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001520};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
Al Viro330d57f2005-11-04 10:18:40 +00001522static DEFINE_SPINLOCK(sysctl_lock);
1523
1524/* called under sysctl_lock */
1525static int use_table(struct ctl_table_header *p)
1526{
1527 if (unlikely(p->unregistering))
1528 return 0;
1529 p->used++;
1530 return 1;
1531}
1532
1533/* called under sysctl_lock */
1534static void unuse_table(struct ctl_table_header *p)
1535{
1536 if (!--p->used)
1537 if (unlikely(p->unregistering))
1538 complete(p->unregistering);
1539}
1540
1541/* called under sysctl_lock, will reacquire if has to wait */
1542static void start_unregistering(struct ctl_table_header *p)
1543{
1544 /*
1545 * if p->used is 0, nobody will ever touch that entry again;
1546 * we'll eliminate all paths to it before dropping sysctl_lock
1547 */
1548 if (unlikely(p->used)) {
1549 struct completion wait;
1550 init_completion(&wait);
1551 p->unregistering = &wait;
1552 spin_unlock(&sysctl_lock);
1553 wait_for_completion(&wait);
1554 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001555 } else {
1556 /* anything non-NULL; we'll never dereference it */
1557 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001558 }
1559 /*
1560 * do not remove from the list until nobody holds it; walking the
1561 * list in do_sysctl() relies on that.
1562 */
1563 list_del_init(&p->ctl_entry);
1564}
1565
Al Virof7e6ced2008-07-15 01:44:23 -04001566void sysctl_head_get(struct ctl_table_header *head)
1567{
1568 spin_lock(&sysctl_lock);
1569 head->count++;
1570 spin_unlock(&sysctl_lock);
1571}
1572
1573void sysctl_head_put(struct ctl_table_header *head)
1574{
1575 spin_lock(&sysctl_lock);
1576 if (!--head->count)
1577 kfree(head);
1578 spin_unlock(&sysctl_lock);
1579}
1580
1581struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1582{
1583 if (!head)
1584 BUG();
1585 spin_lock(&sysctl_lock);
1586 if (!use_table(head))
1587 head = ERR_PTR(-ENOENT);
1588 spin_unlock(&sysctl_lock);
1589 return head;
1590}
1591
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001592void sysctl_head_finish(struct ctl_table_header *head)
1593{
1594 if (!head)
1595 return;
1596 spin_lock(&sysctl_lock);
1597 unuse_table(head);
1598 spin_unlock(&sysctl_lock);
1599}
1600
Al Viro73455092008-07-14 21:22:20 -04001601static struct ctl_table_set *
1602lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1603{
1604 struct ctl_table_set *set = &root->default_set;
1605 if (root->lookup)
1606 set = root->lookup(root, namespaces);
1607 return set;
1608}
1609
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001610static struct list_head *
1611lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001612{
Al Viro73455092008-07-14 21:22:20 -04001613 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1614 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001615}
1616
1617struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1618 struct ctl_table_header *prev)
1619{
1620 struct ctl_table_root *root;
1621 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001622 struct ctl_table_header *head;
1623 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001624
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001625 spin_lock(&sysctl_lock);
1626 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001627 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001628 tmp = &prev->ctl_entry;
1629 unuse_table(prev);
1630 goto next;
1631 }
1632 tmp = &root_table_header.ctl_entry;
1633 for (;;) {
1634 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1635
1636 if (!use_table(head))
1637 goto next;
1638 spin_unlock(&sysctl_lock);
1639 return head;
1640 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001641 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001642 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001643 header_list = lookup_header_list(root, namespaces);
1644 if (tmp != header_list)
1645 continue;
1646
1647 do {
1648 root = list_entry(root->root_list.next,
1649 struct ctl_table_root, root_list);
1650 if (root == &sysctl_table_root)
1651 goto out;
1652 header_list = lookup_header_list(root, namespaces);
1653 } while (list_empty(header_list));
1654 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001655 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001656out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001657 spin_unlock(&sysctl_lock);
1658 return NULL;
1659}
1660
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001661struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1662{
1663 return __sysctl_head_next(current->nsproxy, prev);
1664}
1665
1666void register_sysctl_root(struct ctl_table_root *root)
1667{
1668 spin_lock(&sysctl_lock);
1669 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1670 spin_unlock(&sysctl_lock);
1671}
1672
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001673#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001674/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001675static int do_sysctl_strategy(struct ctl_table_root *root,
1676 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001677 void __user *oldval, size_t __user *oldlenp,
1678 void __user *newval, size_t newlen)
1679{
1680 int op = 0, rc;
1681
1682 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001683 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001684 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001685 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001686 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001687 return -EPERM;
1688
1689 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001690 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001691 if (rc < 0)
1692 return rc;
1693 if (rc > 0)
1694 return 0;
1695 }
1696
1697 /* If there is no strategy routine, or if the strategy returns
1698 * zero, proceed with automatic r/w */
1699 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001700 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001701 if (rc < 0)
1702 return rc;
1703 }
1704 return 0;
1705}
1706
1707static int parse_table(int __user *name, int nlen,
1708 void __user *oldval, size_t __user *oldlenp,
1709 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001710 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001711 struct ctl_table *table)
1712{
1713 int n;
1714repeat:
1715 if (!nlen)
1716 return -ENOTDIR;
1717 if (get_user(n, name))
1718 return -EFAULT;
1719 for ( ; table->ctl_name || table->procname; table++) {
1720 if (!table->ctl_name)
1721 continue;
1722 if (n == table->ctl_name) {
1723 int error;
1724 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001725 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001726 return -EPERM;
1727 name++;
1728 nlen--;
1729 table = table->child;
1730 goto repeat;
1731 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001732 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001733 oldval, oldlenp,
1734 newval, newlen);
1735 return error;
1736 }
1737 }
1738 return -ENOTDIR;
1739}
1740
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1742 void __user *newval, size_t newlen)
1743{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001744 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001745 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
1747 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1748 return -ENOTDIR;
1749 if (oldval) {
1750 int old_len;
1751 if (!oldlenp || get_user(old_len, oldlenp))
1752 return -EFAULT;
1753 }
Al Viro330d57f2005-11-04 10:18:40 +00001754
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001755 for (head = sysctl_head_next(NULL); head;
1756 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001757 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001758 newval, newlen,
1759 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001760 if (error != -ENOTDIR) {
1761 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001762 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001763 }
1764 }
Al Viro330d57f2005-11-04 10:18:40 +00001765 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766}
1767
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001768SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769{
1770 struct __sysctl_args tmp;
1771 int error;
1772
1773 if (copy_from_user(&tmp, args, sizeof(tmp)))
1774 return -EFAULT;
1775
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001776 error = deprecated_sysctl_warning(&tmp);
1777 if (error)
1778 goto out;
1779
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 lock_kernel();
1781 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1782 tmp.newval, tmp.newlen);
1783 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001784out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 return error;
1786}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001787#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001790 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 * some sysctl variables are readonly even to root.
1792 */
1793
1794static int test_perm(int mode, int op)
1795{
David Howells76aac0e2008-11-14 10:39:12 +11001796 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 mode >>= 6;
1798 else if (in_egroup_p(0))
1799 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001800 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 return 0;
1802 return -EACCES;
1803}
1804
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001805int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806{
1807 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001808 int mode;
1809
Al Viroe6305c42008-07-15 21:03:57 -04001810 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 if (error)
1812 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001813
1814 if (root->permissions)
1815 mode = root->permissions(root, current->nsproxy, table);
1816 else
1817 mode = table->mode;
1818
1819 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820}
1821
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001822static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1823{
1824 for (; table->ctl_name || table->procname; table++) {
1825 table->parent = parent;
1826 if (table->child)
1827 sysctl_set_parent(table, table->child);
1828 }
1829}
1830
1831static __init int sysctl_init(void)
1832{
1833 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001834#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1835 {
1836 int err;
1837 err = sysctl_check_table(current->nsproxy, root_table);
1838 }
1839#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001840 return 0;
1841}
1842
1843core_initcall(sysctl_init);
1844
Al Virobfbcf032008-07-27 06:31:22 +01001845static struct ctl_table *is_branch_in(struct ctl_table *branch,
1846 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001847{
1848 struct ctl_table *p;
1849 const char *s = branch->procname;
1850
1851 /* branch should have named subdirectory as its first element */
1852 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001853 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001854
1855 /* ... and nothing else */
1856 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001857 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001858
1859 /* table should contain subdirectory with the same name */
1860 for (p = table; p->procname || p->ctl_name; p++) {
1861 if (!p->child)
1862 continue;
1863 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001864 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001865 }
Al Virobfbcf032008-07-27 06:31:22 +01001866 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001867}
1868
1869/* see if attaching q to p would be an improvement */
1870static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1871{
1872 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001873 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001874 int is_better = 0;
1875 int not_in_parent = !p->attached_by;
1876
Al Virobfbcf032008-07-27 06:31:22 +01001877 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001878 if (by == q->attached_by)
1879 is_better = 1;
1880 if (to == p->attached_by)
1881 not_in_parent = 1;
1882 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001883 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001884 }
1885
1886 if (is_better && not_in_parent) {
1887 q->attached_by = by;
1888 q->attached_to = to;
1889 q->parent = p;
1890 }
1891}
1892
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001894 * __register_sysctl_paths - register a sysctl hierarchy
1895 * @root: List of sysctl headers to register on
1896 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001897 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 *
1900 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001901 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001903 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 *
1905 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1906 * must be unique within that level of sysctl
1907 *
1908 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1909 * enter a sysctl file
1910 *
1911 * data - a pointer to data for use by proc_handler
1912 *
1913 * maxlen - the maximum size in bytes of the data
1914 *
1915 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1916 *
1917 * child - a pointer to the child sysctl table if this entry is a directory, or
1918 * %NULL.
1919 *
1920 * proc_handler - the text handler routine (described below)
1921 *
1922 * strategy - the strategy routine (described below)
1923 *
1924 * de - for internal use by the sysctl routines
1925 *
1926 * extra1, extra2 - extra pointers usable by the proc handler routines
1927 *
1928 * Leaf nodes in the sysctl tree will be represented by a single file
1929 * under /proc; non-leaf nodes will be represented by directories.
1930 *
1931 * sysctl(2) can automatically manage read and write requests through
1932 * the sysctl table. The data and maxlen fields of the ctl_table
1933 * struct enable minimal validation of the values being written to be
1934 * performed, and the mode field allows minimal authentication.
1935 *
1936 * More sophisticated management can be enabled by the provision of a
1937 * strategy routine with the table entry. This will be called before
1938 * any automatic read or write of the data is performed.
1939 *
1940 * The strategy routine may return
1941 *
1942 * < 0 - Error occurred (error is passed to user process)
1943 *
1944 * 0 - OK - proceed with automatic read or write.
1945 *
1946 * > 0 - OK - read or write has been done by the strategy routine, so
1947 * return immediately.
1948 *
1949 * There must be a proc_handler routine for any terminal nodes
1950 * mirrored under /proc/sys (non-terminals are handled by a built-in
1951 * directory handler). Several default handlers are available to
1952 * cover common cases -
1953 *
1954 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1955 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1956 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1957 *
1958 * It is the handler's job to read the input buffer from user memory
1959 * and process it. The handler should return 0 on success.
1960 *
1961 * This routine returns %NULL on a failure to register, and a pointer
1962 * to the table header on success.
1963 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001964struct ctl_table_header *__register_sysctl_paths(
1965 struct ctl_table_root *root,
1966 struct nsproxy *namespaces,
1967 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001969 struct ctl_table_header *header;
1970 struct ctl_table *new, **prevp;
1971 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001972 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001973
1974 /* Count the path components */
1975 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1976 ;
1977
1978 /*
1979 * For each path component, allocate a 2-element ctl_table array.
1980 * The first array element will be filled with the sysctl entry
1981 * for this, the second will be the sentinel (ctl_name == 0).
1982 *
1983 * We allocate everything in one go so that we don't have to
1984 * worry about freeing additional memory in unregister_sysctl_table.
1985 */
1986 header = kzalloc(sizeof(struct ctl_table_header) +
1987 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1988 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001990
1991 new = (struct ctl_table *) (header + 1);
1992
1993 /* Now connect the dots */
1994 prevp = &header->ctl_table;
1995 for (n = 0; n < npath; ++n, ++path) {
1996 /* Copy the procname */
1997 new->procname = path->procname;
1998 new->ctl_name = path->ctl_name;
1999 new->mode = 0555;
2000
2001 *prevp = new;
2002 prevp = &new->child;
2003
2004 new += 2;
2005 }
2006 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002007 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002008
2009 INIT_LIST_HEAD(&header->ctl_entry);
2010 header->used = 0;
2011 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002012 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002013 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002014 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002015#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002016 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002017 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002018 return NULL;
2019 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002020#endif
Al Viro330d57f2005-11-04 10:18:40 +00002021 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002022 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002023 header->attached_by = header->ctl_table;
2024 header->attached_to = root_table;
2025 header->parent = &root_table_header;
2026 for (set = header->set; set; set = set->parent) {
2027 struct ctl_table_header *p;
2028 list_for_each_entry(p, &set->list, ctl_entry) {
2029 if (p->unregistering)
2030 continue;
2031 try_attach(p, header);
2032 }
2033 }
2034 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002035 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002036 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002037
2038 return header;
2039}
2040
2041/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002042 * register_sysctl_table_path - register a sysctl table hierarchy
2043 * @path: The path to the directory the sysctl table is in.
2044 * @table: the top-level table structure
2045 *
2046 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2047 * array. A completely 0 filled entry terminates the table.
2048 *
2049 * See __register_sysctl_paths for more details.
2050 */
2051struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2052 struct ctl_table *table)
2053{
2054 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2055 path, table);
2056}
2057
2058/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002059 * register_sysctl_table - register a sysctl table hierarchy
2060 * @table: the top-level table structure
2061 *
2062 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2063 * array. A completely 0 filled entry terminates the table.
2064 *
2065 * See register_sysctl_paths for more details.
2066 */
2067struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2068{
2069 static const struct ctl_path null_path[] = { {} };
2070
2071 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072}
2073
2074/**
2075 * unregister_sysctl_table - unregister a sysctl table hierarchy
2076 * @header: the header returned from register_sysctl_table
2077 *
2078 * Unregisters the sysctl table and all children. proc entries may not
2079 * actually be removed until they are no longer used by anyone.
2080 */
2081void unregister_sysctl_table(struct ctl_table_header * header)
2082{
Al Viro330d57f2005-11-04 10:18:40 +00002083 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002084
2085 if (header == NULL)
2086 return;
2087
Al Viro330d57f2005-11-04 10:18:40 +00002088 spin_lock(&sysctl_lock);
2089 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002090 if (!--header->parent->count) {
2091 WARN_ON(1);
2092 kfree(header->parent);
2093 }
Al Virof7e6ced2008-07-15 01:44:23 -04002094 if (!--header->count)
2095 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002096 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097}
2098
Al Viro9043476f2008-07-15 08:54:06 -04002099int sysctl_is_seen(struct ctl_table_header *p)
2100{
2101 struct ctl_table_set *set = p->set;
2102 int res;
2103 spin_lock(&sysctl_lock);
2104 if (p->unregistering)
2105 res = 0;
2106 else if (!set->is_seen)
2107 res = 1;
2108 else
2109 res = set->is_seen(set);
2110 spin_unlock(&sysctl_lock);
2111 return res;
2112}
2113
Al Viro73455092008-07-14 21:22:20 -04002114void setup_sysctl_set(struct ctl_table_set *p,
2115 struct ctl_table_set *parent,
2116 int (*is_seen)(struct ctl_table_set *))
2117{
2118 INIT_LIST_HEAD(&p->list);
2119 p->parent = parent ? parent : &sysctl_table_root.default_set;
2120 p->is_seen = is_seen;
2121}
2122
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002123#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002124struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002125{
2126 return NULL;
2127}
2128
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002129struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2130 struct ctl_table *table)
2131{
2132 return NULL;
2133}
2134
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002135void unregister_sysctl_table(struct ctl_table_header * table)
2136{
2137}
2138
Al Viro73455092008-07-14 21:22:20 -04002139void setup_sysctl_set(struct ctl_table_set *p,
2140 struct ctl_table_set *parent,
2141 int (*is_seen)(struct ctl_table_set *))
2142{
2143}
2144
Al Virof7e6ced2008-07-15 01:44:23 -04002145void sysctl_head_put(struct ctl_table_header *head)
2146{
2147}
2148
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002149#endif /* CONFIG_SYSCTL */
2150
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151/*
2152 * /proc/sys support
2153 */
2154
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002155#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002157static int _proc_do_string(void* data, int maxlen, int write,
2158 struct file *filp, void __user *buffer,
2159 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002160{
2161 size_t len;
2162 char __user *p;
2163 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002164
2165 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002166 *lenp = 0;
2167 return 0;
2168 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002169
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002170 if (write) {
2171 len = 0;
2172 p = buffer;
2173 while (len < *lenp) {
2174 if (get_user(c, p++))
2175 return -EFAULT;
2176 if (c == 0 || c == '\n')
2177 break;
2178 len++;
2179 }
2180 if (len >= maxlen)
2181 len = maxlen-1;
2182 if(copy_from_user(data, buffer, len))
2183 return -EFAULT;
2184 ((char *) data)[len] = 0;
2185 *ppos += *lenp;
2186 } else {
2187 len = strlen(data);
2188 if (len > maxlen)
2189 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002190
2191 if (*ppos > len) {
2192 *lenp = 0;
2193 return 0;
2194 }
2195
2196 data += *ppos;
2197 len -= *ppos;
2198
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002199 if (len > *lenp)
2200 len = *lenp;
2201 if (len)
2202 if(copy_to_user(buffer, data, len))
2203 return -EFAULT;
2204 if (len < *lenp) {
2205 if(put_user('\n', ((char __user *) buffer) + len))
2206 return -EFAULT;
2207 len++;
2208 }
2209 *lenp = len;
2210 *ppos += len;
2211 }
2212 return 0;
2213}
2214
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215/**
2216 * proc_dostring - read a string sysctl
2217 * @table: the sysctl table
2218 * @write: %TRUE if this is a write to the sysctl file
2219 * @filp: the file structure
2220 * @buffer: the user buffer
2221 * @lenp: the size of the user buffer
2222 * @ppos: file position
2223 *
2224 * Reads/writes a string from/to the user buffer. If the kernel
2225 * buffer provided is not large enough to hold the string, the
2226 * string is truncated. The copied string is %NULL-terminated.
2227 * If the string is being read by the user process, it is copied
2228 * and a newline '\n' is added. It is truncated if the buffer is
2229 * not large enough.
2230 *
2231 * Returns 0 on success.
2232 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002233int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 void __user *buffer, size_t *lenp, loff_t *ppos)
2235{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002236 return _proc_do_string(table->data, table->maxlen, write, filp,
2237 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238}
2239
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
2241static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2242 int *valp,
2243 int write, void *data)
2244{
2245 if (write) {
2246 *valp = *negp ? -*lvalp : *lvalp;
2247 } else {
2248 int val = *valp;
2249 if (val < 0) {
2250 *negp = -1;
2251 *lvalp = (unsigned long)-val;
2252 } else {
2253 *negp = 0;
2254 *lvalp = (unsigned long)val;
2255 }
2256 }
2257 return 0;
2258}
2259
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002260static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002261 int write, struct file *filp, void __user *buffer,
2262 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2264 int write, void *data),
2265 void *data)
2266{
2267#define TMPBUFLEN 21
2268 int *i, vleft, first=1, neg, val;
2269 unsigned long lval;
2270 size_t left, len;
2271
2272 char buf[TMPBUFLEN], *p;
2273 char __user *s = buffer;
2274
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002275 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 (*ppos && !write)) {
2277 *lenp = 0;
2278 return 0;
2279 }
2280
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002281 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 vleft = table->maxlen / sizeof(*i);
2283 left = *lenp;
2284
2285 if (!conv)
2286 conv = do_proc_dointvec_conv;
2287
2288 for (; left && vleft--; i++, first=0) {
2289 if (write) {
2290 while (left) {
2291 char c;
2292 if (get_user(c, s))
2293 return -EFAULT;
2294 if (!isspace(c))
2295 break;
2296 left--;
2297 s++;
2298 }
2299 if (!left)
2300 break;
2301 neg = 0;
2302 len = left;
2303 if (len > sizeof(buf) - 1)
2304 len = sizeof(buf) - 1;
2305 if (copy_from_user(buf, s, len))
2306 return -EFAULT;
2307 buf[len] = 0;
2308 p = buf;
2309 if (*p == '-' && left > 1) {
2310 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002311 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 }
2313 if (*p < '0' || *p > '9')
2314 break;
2315
2316 lval = simple_strtoul(p, &p, 0);
2317
2318 len = p-buf;
2319 if ((len < left) && *p && !isspace(*p))
2320 break;
2321 if (neg)
2322 val = -val;
2323 s += len;
2324 left -= len;
2325
2326 if (conv(&neg, &lval, i, 1, data))
2327 break;
2328 } else {
2329 p = buf;
2330 if (!first)
2331 *p++ = '\t';
2332
2333 if (conv(&neg, &lval, i, 0, data))
2334 break;
2335
2336 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2337 len = strlen(buf);
2338 if (len > left)
2339 len = left;
2340 if(copy_to_user(s, buf, len))
2341 return -EFAULT;
2342 left -= len;
2343 s += len;
2344 }
2345 }
2346
2347 if (!write && !first && left) {
2348 if(put_user('\n', s))
2349 return -EFAULT;
2350 left--, s++;
2351 }
2352 if (write) {
2353 while (left) {
2354 char c;
2355 if (get_user(c, s++))
2356 return -EFAULT;
2357 if (!isspace(c))
2358 break;
2359 left--;
2360 }
2361 }
2362 if (write && first)
2363 return -EINVAL;
2364 *lenp -= left;
2365 *ppos += *lenp;
2366 return 0;
2367#undef TMPBUFLEN
2368}
2369
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002370static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002371 void __user *buffer, size_t *lenp, loff_t *ppos,
2372 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2373 int write, void *data),
2374 void *data)
2375{
2376 return __do_proc_dointvec(table->data, table, write, filp,
2377 buffer, lenp, ppos, conv, data);
2378}
2379
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380/**
2381 * proc_dointvec - read a vector of integers
2382 * @table: the sysctl table
2383 * @write: %TRUE if this is a write to the sysctl file
2384 * @filp: the file structure
2385 * @buffer: the user buffer
2386 * @lenp: the size of the user buffer
2387 * @ppos: file position
2388 *
2389 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2390 * values from/to the user buffer, treated as an ASCII string.
2391 *
2392 * Returns 0 on success.
2393 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002394int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 void __user *buffer, size_t *lenp, loff_t *ppos)
2396{
2397 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2398 NULL,NULL);
2399}
2400
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002401/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002402 * Taint values can only be increased
2403 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002404 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002405static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002406 void __user *buffer, size_t *lenp, loff_t *ppos)
2407{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002408 struct ctl_table t;
2409 unsigned long tmptaint = get_taint();
2410 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002411
Bastian Blank91fcd412007-04-23 14:41:14 -07002412 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002413 return -EPERM;
2414
Andi Kleen25ddbb12008-10-15 22:01:41 -07002415 t = *table;
2416 t.data = &tmptaint;
2417 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2418 if (err < 0)
2419 return err;
2420
2421 if (write) {
2422 /*
2423 * Poor man's atomic or. Not worth adding a primitive
2424 * to everyone's atomic.h for this
2425 */
2426 int i;
2427 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2428 if ((tmptaint >> i) & 1)
2429 add_taint(i);
2430 }
2431 }
2432
2433 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002434}
2435
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436struct do_proc_dointvec_minmax_conv_param {
2437 int *min;
2438 int *max;
2439};
2440
2441static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2442 int *valp,
2443 int write, void *data)
2444{
2445 struct do_proc_dointvec_minmax_conv_param *param = data;
2446 if (write) {
2447 int val = *negp ? -*lvalp : *lvalp;
2448 if ((param->min && *param->min > val) ||
2449 (param->max && *param->max < val))
2450 return -EINVAL;
2451 *valp = val;
2452 } else {
2453 int val = *valp;
2454 if (val < 0) {
2455 *negp = -1;
2456 *lvalp = (unsigned long)-val;
2457 } else {
2458 *negp = 0;
2459 *lvalp = (unsigned long)val;
2460 }
2461 }
2462 return 0;
2463}
2464
2465/**
2466 * proc_dointvec_minmax - read a vector of integers with min/max values
2467 * @table: the sysctl table
2468 * @write: %TRUE if this is a write to the sysctl file
2469 * @filp: the file structure
2470 * @buffer: the user buffer
2471 * @lenp: the size of the user buffer
2472 * @ppos: file position
2473 *
2474 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2475 * values from/to the user buffer, treated as an ASCII string.
2476 *
2477 * This routine will ensure the values are within the range specified by
2478 * table->extra1 (min) and table->extra2 (max).
2479 *
2480 * Returns 0 on success.
2481 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002482int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 void __user *buffer, size_t *lenp, loff_t *ppos)
2484{
2485 struct do_proc_dointvec_minmax_conv_param param = {
2486 .min = (int *) table->extra1,
2487 .max = (int *) table->extra2,
2488 };
2489 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2490 do_proc_dointvec_minmax_conv, &param);
2491}
2492
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002493static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 struct file *filp,
2495 void __user *buffer,
2496 size_t *lenp, loff_t *ppos,
2497 unsigned long convmul,
2498 unsigned long convdiv)
2499{
2500#define TMPBUFLEN 21
2501 unsigned long *i, *min, *max, val;
2502 int vleft, first=1, neg;
2503 size_t len, left;
2504 char buf[TMPBUFLEN], *p;
2505 char __user *s = buffer;
2506
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002507 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 (*ppos && !write)) {
2509 *lenp = 0;
2510 return 0;
2511 }
2512
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002513 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 min = (unsigned long *) table->extra1;
2515 max = (unsigned long *) table->extra2;
2516 vleft = table->maxlen / sizeof(unsigned long);
2517 left = *lenp;
2518
2519 for (; left && vleft--; i++, min++, max++, first=0) {
2520 if (write) {
2521 while (left) {
2522 char c;
2523 if (get_user(c, s))
2524 return -EFAULT;
2525 if (!isspace(c))
2526 break;
2527 left--;
2528 s++;
2529 }
2530 if (!left)
2531 break;
2532 neg = 0;
2533 len = left;
2534 if (len > TMPBUFLEN-1)
2535 len = TMPBUFLEN-1;
2536 if (copy_from_user(buf, s, len))
2537 return -EFAULT;
2538 buf[len] = 0;
2539 p = buf;
2540 if (*p == '-' && left > 1) {
2541 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002542 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 }
2544 if (*p < '0' || *p > '9')
2545 break;
2546 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2547 len = p-buf;
2548 if ((len < left) && *p && !isspace(*p))
2549 break;
2550 if (neg)
2551 val = -val;
2552 s += len;
2553 left -= len;
2554
2555 if(neg)
2556 continue;
2557 if ((min && val < *min) || (max && val > *max))
2558 continue;
2559 *i = val;
2560 } else {
2561 p = buf;
2562 if (!first)
2563 *p++ = '\t';
2564 sprintf(p, "%lu", convdiv * (*i) / convmul);
2565 len = strlen(buf);
2566 if (len > left)
2567 len = left;
2568 if(copy_to_user(s, buf, len))
2569 return -EFAULT;
2570 left -= len;
2571 s += len;
2572 }
2573 }
2574
2575 if (!write && !first && left) {
2576 if(put_user('\n', s))
2577 return -EFAULT;
2578 left--, s++;
2579 }
2580 if (write) {
2581 while (left) {
2582 char c;
2583 if (get_user(c, s++))
2584 return -EFAULT;
2585 if (!isspace(c))
2586 break;
2587 left--;
2588 }
2589 }
2590 if (write && first)
2591 return -EINVAL;
2592 *lenp -= left;
2593 *ppos += *lenp;
2594 return 0;
2595#undef TMPBUFLEN
2596}
2597
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002598static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002599 struct file *filp,
2600 void __user *buffer,
2601 size_t *lenp, loff_t *ppos,
2602 unsigned long convmul,
2603 unsigned long convdiv)
2604{
2605 return __do_proc_doulongvec_minmax(table->data, table, write,
2606 filp, buffer, lenp, ppos, convmul, convdiv);
2607}
2608
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609/**
2610 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2611 * @table: the sysctl table
2612 * @write: %TRUE if this is a write to the sysctl file
2613 * @filp: the file structure
2614 * @buffer: the user buffer
2615 * @lenp: the size of the user buffer
2616 * @ppos: file position
2617 *
2618 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2619 * values from/to the user buffer, treated as an ASCII string.
2620 *
2621 * This routine will ensure the values are within the range specified by
2622 * table->extra1 (min) and table->extra2 (max).
2623 *
2624 * Returns 0 on success.
2625 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002626int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 void __user *buffer, size_t *lenp, loff_t *ppos)
2628{
2629 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2630}
2631
2632/**
2633 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2634 * @table: the sysctl table
2635 * @write: %TRUE if this is a write to the sysctl file
2636 * @filp: the file structure
2637 * @buffer: the user buffer
2638 * @lenp: the size of the user buffer
2639 * @ppos: file position
2640 *
2641 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2642 * values from/to the user buffer, treated as an ASCII string. The values
2643 * are treated as milliseconds, and converted to jiffies when they are stored.
2644 *
2645 * This routine will ensure the values are within the range specified by
2646 * table->extra1 (min) and table->extra2 (max).
2647 *
2648 * Returns 0 on success.
2649 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002650int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 struct file *filp,
2652 void __user *buffer,
2653 size_t *lenp, loff_t *ppos)
2654{
2655 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2656 lenp, ppos, HZ, 1000l);
2657}
2658
2659
2660static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2661 int *valp,
2662 int write, void *data)
2663{
2664 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002665 if (*lvalp > LONG_MAX / HZ)
2666 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2668 } else {
2669 int val = *valp;
2670 unsigned long lval;
2671 if (val < 0) {
2672 *negp = -1;
2673 lval = (unsigned long)-val;
2674 } else {
2675 *negp = 0;
2676 lval = (unsigned long)val;
2677 }
2678 *lvalp = lval / HZ;
2679 }
2680 return 0;
2681}
2682
2683static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2684 int *valp,
2685 int write, void *data)
2686{
2687 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002688 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2689 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2691 } else {
2692 int val = *valp;
2693 unsigned long lval;
2694 if (val < 0) {
2695 *negp = -1;
2696 lval = (unsigned long)-val;
2697 } else {
2698 *negp = 0;
2699 lval = (unsigned long)val;
2700 }
2701 *lvalp = jiffies_to_clock_t(lval);
2702 }
2703 return 0;
2704}
2705
2706static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2707 int *valp,
2708 int write, void *data)
2709{
2710 if (write) {
2711 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2712 } else {
2713 int val = *valp;
2714 unsigned long lval;
2715 if (val < 0) {
2716 *negp = -1;
2717 lval = (unsigned long)-val;
2718 } else {
2719 *negp = 0;
2720 lval = (unsigned long)val;
2721 }
2722 *lvalp = jiffies_to_msecs(lval);
2723 }
2724 return 0;
2725}
2726
2727/**
2728 * proc_dointvec_jiffies - read a vector of integers as seconds
2729 * @table: the sysctl table
2730 * @write: %TRUE if this is a write to the sysctl file
2731 * @filp: the file structure
2732 * @buffer: the user buffer
2733 * @lenp: the size of the user buffer
2734 * @ppos: file position
2735 *
2736 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2737 * values from/to the user buffer, treated as an ASCII string.
2738 * The values read are assumed to be in seconds, and are converted into
2739 * jiffies.
2740 *
2741 * Returns 0 on success.
2742 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002743int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 void __user *buffer, size_t *lenp, loff_t *ppos)
2745{
2746 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2747 do_proc_dointvec_jiffies_conv,NULL);
2748}
2749
2750/**
2751 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2752 * @table: the sysctl table
2753 * @write: %TRUE if this is a write to the sysctl file
2754 * @filp: the file structure
2755 * @buffer: the user buffer
2756 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002757 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 *
2759 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2760 * values from/to the user buffer, treated as an ASCII string.
2761 * The values read are assumed to be in 1/USER_HZ seconds, and
2762 * are converted into jiffies.
2763 *
2764 * Returns 0 on success.
2765 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002766int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 void __user *buffer, size_t *lenp, loff_t *ppos)
2768{
2769 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2770 do_proc_dointvec_userhz_jiffies_conv,NULL);
2771}
2772
2773/**
2774 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2775 * @table: the sysctl table
2776 * @write: %TRUE if this is a write to the sysctl file
2777 * @filp: the file structure
2778 * @buffer: the user buffer
2779 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002780 * @ppos: file position
2781 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 *
2783 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2784 * values from/to the user buffer, treated as an ASCII string.
2785 * The values read are assumed to be in 1/1000 seconds, and
2786 * are converted into jiffies.
2787 *
2788 * Returns 0 on success.
2789 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002790int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 void __user *buffer, size_t *lenp, loff_t *ppos)
2792{
2793 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2794 do_proc_dointvec_ms_jiffies_conv, NULL);
2795}
2796
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002797static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002798 void __user *buffer, size_t *lenp, loff_t *ppos)
2799{
2800 struct pid *new_pid;
2801 pid_t tmp;
2802 int r;
2803
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002804 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002805
2806 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2807 lenp, ppos, NULL, NULL);
2808 if (r || !write)
2809 return r;
2810
2811 new_pid = find_get_pid(tmp);
2812 if (!new_pid)
2813 return -ESRCH;
2814
2815 put_pid(xchg(&cad_pid, new_pid));
2816 return 0;
2817}
2818
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819#else /* CONFIG_PROC_FS */
2820
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002821int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 void __user *buffer, size_t *lenp, loff_t *ppos)
2823{
2824 return -ENOSYS;
2825}
2826
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002827int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 void __user *buffer, size_t *lenp, loff_t *ppos)
2829{
2830 return -ENOSYS;
2831}
2832
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002833int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 void __user *buffer, size_t *lenp, loff_t *ppos)
2835{
2836 return -ENOSYS;
2837}
2838
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002839int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 void __user *buffer, size_t *lenp, loff_t *ppos)
2841{
2842 return -ENOSYS;
2843}
2844
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002845int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 void __user *buffer, size_t *lenp, loff_t *ppos)
2847{
2848 return -ENOSYS;
2849}
2850
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002851int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 void __user *buffer, size_t *lenp, loff_t *ppos)
2853{
2854 return -ENOSYS;
2855}
2856
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002857int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 void __user *buffer, size_t *lenp, loff_t *ppos)
2859{
2860 return -ENOSYS;
2861}
2862
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002863int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 struct file *filp,
2865 void __user *buffer,
2866 size_t *lenp, loff_t *ppos)
2867{
2868 return -ENOSYS;
2869}
2870
2871
2872#endif /* CONFIG_PROC_FS */
2873
2874
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002875#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876/*
2877 * General sysctl support routines
2878 */
2879
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002880/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002881int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002882 void __user *oldval, size_t __user *oldlenp,
2883 void __user *newval, size_t newlen)
2884{
2885 size_t len;
2886
2887 /* Get out of I don't have a variable */
2888 if (!table->data || !table->maxlen)
2889 return -ENOTDIR;
2890
2891 if (oldval && oldlenp) {
2892 if (get_user(len, oldlenp))
2893 return -EFAULT;
2894 if (len) {
2895 if (len > table->maxlen)
2896 len = table->maxlen;
2897 if (copy_to_user(oldval, table->data, len))
2898 return -EFAULT;
2899 if (put_user(len, oldlenp))
2900 return -EFAULT;
2901 }
2902 }
2903
2904 if (newval && newlen) {
2905 if (newlen > table->maxlen)
2906 newlen = table->maxlen;
2907
2908 if (copy_from_user(table->data, newval, newlen))
2909 return -EFAULT;
2910 }
2911 return 1;
2912}
2913
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002915int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002917 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 if (!table->data || !table->maxlen)
2920 return -ENOTDIR;
2921
2922 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002923 size_t bufsize;
2924 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002926 if (bufsize) {
2927 size_t len = strlen(table->data), copied;
2928
2929 /* This shouldn't trigger for a well-formed sysctl */
2930 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002932
2933 /* Copy up to a max of bufsize-1 bytes of the string */
2934 copied = (len >= bufsize) ? bufsize - 1 : len;
2935
2936 if (copy_to_user(oldval, table->data, copied) ||
2937 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002939 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 return -EFAULT;
2941 }
2942 }
2943 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002944 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 if (len > table->maxlen)
2946 len = table->maxlen;
2947 if(copy_from_user(table->data, newval, len))
2948 return -EFAULT;
2949 if (len == table->maxlen)
2950 len--;
2951 ((char *) table->data)[len] = 0;
2952 }
Yi Yang82c9df82005-12-30 16:37:10 +08002953 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954}
2955
2956/*
2957 * This function makes sure that all of the integers in the vector
2958 * are between the minimum and maximum values given in the arrays
2959 * table->extra1 and table->extra2, respectively.
2960 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002961int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002963 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964{
2965
2966 if (newval && newlen) {
2967 int __user *vec = (int __user *) newval;
2968 int *min = (int *) table->extra1;
2969 int *max = (int *) table->extra2;
2970 size_t length;
2971 int i;
2972
2973 if (newlen % sizeof(int) != 0)
2974 return -EINVAL;
2975
2976 if (!table->extra1 && !table->extra2)
2977 return 0;
2978
2979 if (newlen > table->maxlen)
2980 newlen = table->maxlen;
2981 length = newlen / sizeof(int);
2982
2983 for (i = 0; i < length; i++) {
2984 int value;
2985 if (get_user(value, vec + i))
2986 return -EFAULT;
2987 if (min && value < min[i])
2988 return -EINVAL;
2989 if (max && value > max[i])
2990 return -EINVAL;
2991 }
2992 }
2993 return 0;
2994}
2995
2996/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002997int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002999 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003001 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003003
3004 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003006 if (olen) {
3007 int val;
3008
3009 if (olen < sizeof(int))
3010 return -EINVAL;
3011
3012 val = *(int *)(table->data) / HZ;
3013 if (put_user(val, (int __user *)oldval))
3014 return -EFAULT;
3015 if (put_user(sizeof(int), oldlenp))
3016 return -EFAULT;
3017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 }
3019 if (newval && newlen) {
3020 int new;
3021 if (newlen != sizeof(int))
3022 return -EINVAL;
3023 if (get_user(new, (int __user *)newval))
3024 return -EFAULT;
3025 *(int *)(table->data) = new*HZ;
3026 }
3027 return 1;
3028}
3029
3030/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003031int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003033 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003035 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003037
3038 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003040 if (olen) {
3041 int val;
3042
3043 if (olen < sizeof(int))
3044 return -EINVAL;
3045
3046 val = jiffies_to_msecs(*(int *)(table->data));
3047 if (put_user(val, (int __user *)oldval))
3048 return -EFAULT;
3049 if (put_user(sizeof(int), oldlenp))
3050 return -EFAULT;
3051 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 }
3053 if (newval && newlen) {
3054 int new;
3055 if (newlen != sizeof(int))
3056 return -EINVAL;
3057 if (get_user(new, (int __user *)newval))
3058 return -EFAULT;
3059 *(int *)(table->data) = msecs_to_jiffies(new);
3060 }
3061 return 1;
3062}
3063
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003064
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003065
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003066#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
3068
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003069SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003071 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003072 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003073
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003074 if (copy_from_user(&tmp, args, sizeof(tmp)))
3075 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003076
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003077 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003078
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003079 /* If no error reading the parameters then just -ENOSYS ... */
3080 if (!error)
3081 error = -ENOSYS;
3082
3083 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084}
3085
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003086int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003087 void __user *oldval, size_t __user *oldlenp,
3088 void __user *newval, size_t newlen)
3089{
3090 return -ENOSYS;
3091}
3092
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003093int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003095 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096{
3097 return -ENOSYS;
3098}
3099
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003100int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003102 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103{
3104 return -ENOSYS;
3105}
3106
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003107int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003109 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110{
3111 return -ENOSYS;
3112}
3113
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003114int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003116 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117{
3118 return -ENOSYS;
3119}
3120
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003121#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003123static int deprecated_sysctl_warning(struct __sysctl_args *args)
3124{
3125 static int msg_count;
3126 int name[CTL_MAXNAME];
3127 int i;
3128
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003129 /* Check args->nlen. */
3130 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3131 return -ENOTDIR;
3132
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003133 /* Read in the sysctl name for better debug message logging */
3134 for (i = 0; i < args->nlen; i++)
3135 if (get_user(name[i], args->name + i))
3136 return -EFAULT;
3137
3138 /* Ignore accesses to kernel.version */
3139 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3140 return 0;
3141
3142 if (msg_count < 5) {
3143 msg_count++;
3144 printk(KERN_INFO
3145 "warning: process `%s' used the deprecated sysctl "
3146 "system call with ", current->comm);
3147 for (i = 0; i < args->nlen; i++)
3148 printk("%d.", name[i]);
3149 printk("\n");
3150 }
3151 return 0;
3152}
3153
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154/*
3155 * No sense putting this after each symbol definition, twice,
3156 * exception granted :-)
3157 */
3158EXPORT_SYMBOL(proc_dointvec);
3159EXPORT_SYMBOL(proc_dointvec_jiffies);
3160EXPORT_SYMBOL(proc_dointvec_minmax);
3161EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3162EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3163EXPORT_SYMBOL(proc_dostring);
3164EXPORT_SYMBOL(proc_doulongvec_minmax);
3165EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3166EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003167EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168EXPORT_SYMBOL(sysctl_intvec);
3169EXPORT_SYMBOL(sysctl_jiffies);
3170EXPORT_SYMBOL(sysctl_ms_jiffies);
3171EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003172EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173EXPORT_SYMBOL(unregister_sysctl_table);