blob: 9ef80bba35091e0285054257dcc92c9c564132db [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>
Vegard Nossumdfec0722008-04-04 00:51:41 +020030#include <linux/kmemcheck.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
40#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070042#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/times.h>
44#include <linux/limits.h>
45#include <linux/dcache.h>
46#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070047#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080048#include <linux/nfs_fs.h>
49#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070050#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020051#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010052#include <linux/slow-work.h>
Peter Zijlstra1ccd1542009-04-09 10:53:45 +020053#include <linux/perf_counter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#include <asm/uaccess.h>
56#include <asm/processor.h>
57
Andi Kleen29cbc782006-09-30 01:47:55 +020058#ifdef CONFIG_X86
59#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010060#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010061#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020062#endif
63
Eric W. Biederman7058cb02007-10-18 03:05:58 -070064static int deprecated_sysctl_warning(struct __sysctl_args *args);
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#if defined(CONFIG_SYSCTL)
67
68/* External variables not in a header file. */
69extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070070extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int sysctl_overcommit_memory;
72extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070073extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070074extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080075extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070078extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max;
81extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080083extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080084extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020085extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010086extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040087extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000088#ifndef CONFIG_MMU
89extern int sysctl_nr_trim_pages;
90#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070091#ifdef CONFIG_RCU_TORTURE_TEST
92extern int rcutorture_runnable;
93#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070095/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080096#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020098static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099#endif
100
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700101static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700102static int __maybe_unused one = 1;
103static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800104static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700105static int one_hundred = 100;
106
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700107/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
108static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
111static int maxolduid = 65535;
112static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800113static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115static int ngroups_max = NGROUPS_MAX;
116
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200117#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700119extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#ifdef CONFIG_CHR_DEV_SG
122extern int sg_big_buff;
123#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
David S. Miller72c57ed2008-09-11 23:29:54 -0700125#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700126#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#endif
128
David S. Miller08714202008-11-16 23:49:24 -0800129#ifdef CONFIG_SPARC64
130extern int sysctl_tsb_ratio;
131#endif
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#ifdef __hppa__
134extern int pwrsw_enabled;
135extern int unaligned_enabled;
136#endif
137
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800138#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#ifdef CONFIG_MATHEMU
140extern int sysctl_ieee_emulation_warnings;
141#endif
142extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700143extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#endif
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef CONFIG_BSD_PROCESS_ACCT
147extern int acct_parm[];
148#endif
149
Jes Sorensend2b176e2006-02-28 09:42:23 -0800150#ifdef CONFIG_IA64
151extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800152extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800153#endif
154
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700155#ifdef CONFIG_RT_MUTEXES
156extern int max_lock_depth;
157#endif
158
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700159#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700160static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700161 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700162static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800163 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700164#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700165
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700166static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100167static struct ctl_table_root sysctl_table_root;
168static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100169 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100170 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400171 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100172 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400173 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100174};
175static struct ctl_table_root sysctl_table_root = {
176 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400177 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100178};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700180static struct ctl_table kern_table[];
181static struct ctl_table vm_table[];
182static struct ctl_table fs_table[];
183static struct ctl_table debug_table[];
184static struct ctl_table dev_table[];
185extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700186#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700187extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400188#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800189#ifdef CONFIG_EPOLL
190extern struct ctl_table epoll_table[];
191#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
194int sysctl_legacy_va_layout;
195#endif
196
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700197extern int prove_locking;
198extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200/* The default sysctl tables: */
201
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700202static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 {
204 .ctl_name = CTL_KERN,
205 .procname = "kernel",
206 .mode = 0555,
207 .child = kern_table,
208 },
209 {
210 .ctl_name = CTL_VM,
211 .procname = "vm",
212 .mode = 0555,
213 .child = vm_table,
214 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 .ctl_name = CTL_FS,
217 .procname = "fs",
218 .mode = 0555,
219 .child = fs_table,
220 },
221 {
222 .ctl_name = CTL_DEBUG,
223 .procname = "debug",
224 .mode = 0555,
225 .child = debug_table,
226 },
227 {
228 .ctl_name = CTL_DEV,
229 .procname = "dev",
230 .mode = 0555,
231 .child = dev_table,
232 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700233/*
234 * NOTE: do not add new entries to this table unless you have read
235 * Documentation/sysctl/ctl_unnumbered.txt
236 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 { .ctl_name = 0 }
238};
239
Ingo Molnar77e54a12007-07-09 18:52:00 +0200240#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100241static int min_sched_granularity_ns = 100000; /* 100 usecs */
242static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
243static int min_wakeup_granularity_ns; /* 0 usecs */
244static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200245#endif
246
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700247static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200248#ifdef CONFIG_SCHED_DEBUG
249 {
250 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100251 .procname = "sched_min_granularity_ns",
252 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200253 .maxlen = sizeof(unsigned int),
254 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100255 .proc_handler = &sched_nr_latency_handler,
256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200259 },
260 {
261 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200262 .procname = "sched_latency_ns",
263 .data = &sysctl_sched_latency,
264 .maxlen = sizeof(unsigned int),
265 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100266 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200267 .strategy = &sysctl_intvec,
268 .extra1 = &min_sched_granularity_ns,
269 .extra2 = &max_sched_granularity_ns,
270 },
271 {
272 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200273 .procname = "sched_wakeup_granularity_ns",
274 .data = &sysctl_sched_wakeup_granularity,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
277 .proc_handler = &proc_dointvec_minmax,
278 .strategy = &sysctl_intvec,
279 .extra1 = &min_wakeup_granularity_ns,
280 .extra2 = &max_wakeup_granularity_ns,
281 },
282 {
283 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200284 .procname = "sched_shares_ratelimit",
285 .data = &sysctl_sched_shares_ratelimit,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
288 .proc_handler = &proc_dointvec,
289 },
290 {
291 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200292 .procname = "sched_shares_thresh",
293 .data = &sysctl_sched_shares_thresh,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec_minmax,
297 .strategy = &sysctl_intvec,
298 .extra1 = &zero,
299 },
300 {
301 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200302 .procname = "sched_child_runs_first",
303 .data = &sysctl_sched_child_runs_first,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = &proc_dointvec,
307 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200308 {
309 .ctl_name = CTL_UNNUMBERED,
310 .procname = "sched_features",
311 .data = &sysctl_sched_features,
312 .maxlen = sizeof(unsigned int),
313 .mode = 0644,
314 .proc_handler = &proc_dointvec,
315 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200316 {
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "sched_migration_cost",
319 .data = &sysctl_sched_migration_cost,
320 .maxlen = sizeof(unsigned int),
321 .mode = 0644,
322 .proc_handler = &proc_dointvec,
323 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100324 {
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_nr_migrate",
327 .data = &sysctl_sched_nr_migrate,
328 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100329 .mode = 0644,
330 .proc_handler = &proc_dointvec,
331 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200332#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200333 {
334 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100335 .procname = "sched_rt_period_us",
336 .data = &sysctl_sched_rt_period,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200339 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100340 },
341 {
342 .ctl_name = CTL_UNNUMBERED,
343 .procname = "sched_rt_runtime_us",
344 .data = &sysctl_sched_rt_runtime,
345 .maxlen = sizeof(int),
346 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200347 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100348 },
349 {
350 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200351 .procname = "sched_compat_yield",
352 .data = &sysctl_sched_compat_yield,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec,
356 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700357#ifdef CONFIG_PROVE_LOCKING
358 {
359 .ctl_name = CTL_UNNUMBERED,
360 .procname = "prove_locking",
361 .data = &prove_locking,
362 .maxlen = sizeof(int),
363 .mode = 0644,
364 .proc_handler = &proc_dointvec,
365 },
366#endif
367#ifdef CONFIG_LOCK_STAT
368 {
369 .ctl_name = CTL_UNNUMBERED,
370 .procname = "lock_stat",
371 .data = &lock_stat,
372 .maxlen = sizeof(int),
373 .mode = 0644,
374 .proc_handler = &proc_dointvec,
375 },
376#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200377 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .ctl_name = KERN_PANIC,
379 .procname = "panic",
380 .data = &panic_timeout,
381 .maxlen = sizeof(int),
382 .mode = 0644,
383 .proc_handler = &proc_dointvec,
384 },
385 {
386 .ctl_name = KERN_CORE_USES_PID,
387 .procname = "core_uses_pid",
388 .data = &core_uses_pid,
389 .maxlen = sizeof(int),
390 .mode = 0644,
391 .proc_handler = &proc_dointvec,
392 },
393 {
394 .ctl_name = KERN_CORE_PATTERN,
395 .procname = "core_pattern",
396 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700397 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .mode = 0644,
399 .proc_handler = &proc_dostring,
400 .strategy = &sysctl_string,
401 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800402#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700405 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800406 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700407 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800409#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100410#ifdef CONFIG_LATENCYTOP
411 {
412 .procname = "latencytop",
413 .data = &latencytop_enabled,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
417 },
418#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419#ifdef CONFIG_BLK_DEV_INITRD
420 {
421 .ctl_name = KERN_REALROOTDEV,
422 .procname = "real-root-dev",
423 .data = &real_root_dev,
424 .maxlen = sizeof(int),
425 .mode = 0644,
426 .proc_handler = &proc_dointvec,
427 },
428#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700429 {
430 .ctl_name = CTL_UNNUMBERED,
431 .procname = "print-fatal-signals",
432 .data = &print_fatal_signals,
433 .maxlen = sizeof(int),
434 .mode = 0644,
435 .proc_handler = &proc_dointvec,
436 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700437#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 {
439 .ctl_name = KERN_SPARC_REBOOT,
440 .procname = "reboot-cmd",
441 .data = reboot_command,
442 .maxlen = 256,
443 .mode = 0644,
444 .proc_handler = &proc_dostring,
445 .strategy = &sysctl_string,
446 },
447 {
448 .ctl_name = KERN_SPARC_STOP_A,
449 .procname = "stop-a",
450 .data = &stop_a_enabled,
451 .maxlen = sizeof (int),
452 .mode = 0644,
453 .proc_handler = &proc_dointvec,
454 },
455 {
456 .ctl_name = KERN_SPARC_SCONS_PWROFF,
457 .procname = "scons-poweroff",
458 .data = &scons_pwroff,
459 .maxlen = sizeof (int),
460 .mode = 0644,
461 .proc_handler = &proc_dointvec,
462 },
463#endif
David S. Miller08714202008-11-16 23:49:24 -0800464#ifdef CONFIG_SPARC64
465 {
466 .ctl_name = CTL_UNNUMBERED,
467 .procname = "tsb-ratio",
468 .data = &sysctl_tsb_ratio,
469 .maxlen = sizeof (int),
470 .mode = 0644,
471 .proc_handler = &proc_dointvec,
472 },
473#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#ifdef __hppa__
475 {
476 .ctl_name = KERN_HPPA_PWRSW,
477 .procname = "soft-power",
478 .data = &pwrsw_enabled,
479 .maxlen = sizeof (int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
482 },
483 {
484 .ctl_name = KERN_HPPA_UNALIGNED,
485 .procname = "unaligned-trap",
486 .data = &unaligned_enabled,
487 .maxlen = sizeof (int),
488 .mode = 0644,
489 .proc_handler = &proc_dointvec,
490 },
491#endif
492 {
493 .ctl_name = KERN_CTLALTDEL,
494 .procname = "ctrl-alt-del",
495 .data = &C_A_D,
496 .maxlen = sizeof(int),
497 .mode = 0644,
498 .proc_handler = &proc_dointvec,
499 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400500#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200501 {
502 .ctl_name = CTL_UNNUMBERED,
503 .procname = "ftrace_enabled",
504 .data = &ftrace_enabled,
505 .maxlen = sizeof(int),
506 .mode = 0644,
507 .proc_handler = &ftrace_enable_sysctl,
508 },
509#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500510#ifdef CONFIG_STACK_TRACER
511 {
512 .ctl_name = CTL_UNNUMBERED,
513 .procname = "stack_tracer_enabled",
514 .data = &stack_tracer_enabled,
515 .maxlen = sizeof(int),
516 .mode = 0644,
517 .proc_handler = &stack_trace_sysctl,
518 },
519#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400520#ifdef CONFIG_TRACING
521 {
522 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100523 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400524 .data = &ftrace_dump_on_oops,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = &proc_dointvec,
528 },
529#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200530#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 {
532 .ctl_name = KERN_MODPROBE,
533 .procname = "modprobe",
534 .data = &modprobe_path,
535 .maxlen = KMOD_PATH_LEN,
536 .mode = 0644,
537 .proc_handler = &proc_dostring,
538 .strategy = &sysctl_string,
539 },
Kees Cook3d433212009-04-02 15:49:29 -0700540 {
541 .ctl_name = CTL_UNNUMBERED,
542 .procname = "modules_disabled",
543 .data = &modules_disabled,
544 .maxlen = sizeof(int),
545 .mode = 0644,
546 /* only handle a transition from default "0" to "1" */
547 .proc_handler = &proc_dointvec_minmax,
548 .extra1 = &one,
549 .extra2 = &one,
550 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700552#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 {
554 .ctl_name = KERN_HOTPLUG,
555 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100556 .data = &uevent_helper,
557 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 .mode = 0644,
559 .proc_handler = &proc_dostring,
560 .strategy = &sysctl_string,
561 },
562#endif
563#ifdef CONFIG_CHR_DEV_SG
564 {
565 .ctl_name = KERN_SG_BIG_BUFF,
566 .procname = "sg-big-buff",
567 .data = &sg_big_buff,
568 .maxlen = sizeof (int),
569 .mode = 0444,
570 .proc_handler = &proc_dointvec,
571 },
572#endif
573#ifdef CONFIG_BSD_PROCESS_ACCT
574 {
575 .ctl_name = KERN_ACCT,
576 .procname = "acct",
577 .data = &acct_parm,
578 .maxlen = 3*sizeof(int),
579 .mode = 0644,
580 .proc_handler = &proc_dointvec,
581 },
582#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#ifdef CONFIG_MAGIC_SYSRQ
584 {
585 .ctl_name = KERN_SYSRQ,
586 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800587 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .maxlen = sizeof (int),
589 .mode = 0644,
590 .proc_handler = &proc_dointvec,
591 },
592#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700593#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700596 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .maxlen = sizeof (int),
598 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700599 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700601#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 {
603 .ctl_name = KERN_MAX_THREADS,
604 .procname = "threads-max",
605 .data = &max_threads,
606 .maxlen = sizeof(int),
607 .mode = 0644,
608 .proc_handler = &proc_dointvec,
609 },
610 {
611 .ctl_name = KERN_RANDOM,
612 .procname = "random",
613 .mode = 0555,
614 .child = random_table,
615 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 {
617 .ctl_name = KERN_OVERFLOWUID,
618 .procname = "overflowuid",
619 .data = &overflowuid,
620 .maxlen = sizeof(int),
621 .mode = 0644,
622 .proc_handler = &proc_dointvec_minmax,
623 .strategy = &sysctl_intvec,
624 .extra1 = &minolduid,
625 .extra2 = &maxolduid,
626 },
627 {
628 .ctl_name = KERN_OVERFLOWGID,
629 .procname = "overflowgid",
630 .data = &overflowgid,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec_minmax,
634 .strategy = &sysctl_intvec,
635 .extra1 = &minolduid,
636 .extra2 = &maxolduid,
637 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800638#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#ifdef CONFIG_MATHEMU
640 {
641 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
642 .procname = "ieee_emulation_warnings",
643 .data = &sysctl_ieee_emulation_warnings,
644 .maxlen = sizeof(int),
645 .mode = 0644,
646 .proc_handler = &proc_dointvec,
647 },
648#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 {
650 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
651 .procname = "userprocess_debug",
652 .data = &sysctl_userprocess_debug,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec,
656 },
657#endif
658 {
659 .ctl_name = KERN_PIDMAX,
660 .procname = "pid_max",
661 .data = &pid_max,
662 .maxlen = sizeof (int),
663 .mode = 0644,
664 .proc_handler = &proc_dointvec_minmax,
665 .strategy = sysctl_intvec,
666 .extra1 = &pid_max_min,
667 .extra2 = &pid_max_max,
668 },
669 {
670 .ctl_name = KERN_PANIC_ON_OOPS,
671 .procname = "panic_on_oops",
672 .data = &panic_on_oops,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = &proc_dointvec,
676 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800677#if defined CONFIG_PRINTK
678 {
679 .ctl_name = KERN_PRINTK,
680 .procname = "printk",
681 .data = &console_loglevel,
682 .maxlen = 4*sizeof(int),
683 .mode = 0644,
684 .proc_handler = &proc_dointvec,
685 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 {
687 .ctl_name = KERN_PRINTK_RATELIMIT,
688 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700689 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = &proc_dointvec_jiffies,
693 .strategy = &sysctl_jiffies,
694 },
695 {
696 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
697 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700698 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = &proc_dointvec,
702 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800703#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 {
705 .ctl_name = KERN_NGROUPS_MAX,
706 .procname = "ngroups_max",
707 .data = &ngroups_max,
708 .maxlen = sizeof (int),
709 .mode = 0444,
710 .proc_handler = &proc_dointvec,
711 },
712#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
713 {
714 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
715 .procname = "unknown_nmi_panic",
716 .data = &unknown_nmi_panic,
717 .maxlen = sizeof (int),
718 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200719 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 },
Don Zickus407984f2006-09-26 10:52:27 +0200721 {
Don Zickus407984f2006-09-26 10:52:27 +0200722 .procname = "nmi_watchdog",
723 .data = &nmi_watchdog_enabled,
724 .maxlen = sizeof (int),
725 .mode = 0644,
726 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 },
728#endif
729#if defined(CONFIG_X86)
730 {
Don Zickus8da5add2006-09-26 10:52:27 +0200731 .ctl_name = KERN_PANIC_ON_NMI,
732 .procname = "panic_on_unrecovered_nmi",
733 .data = &panic_on_unrecovered_nmi,
734 .maxlen = sizeof(int),
735 .mode = 0644,
736 .proc_handler = &proc_dointvec,
737 },
738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .ctl_name = KERN_BOOTLOADER_TYPE,
740 .procname = "bootloader_type",
741 .data = &bootloader_type,
742 .maxlen = sizeof (int),
743 .mode = 0444,
744 .proc_handler = &proc_dointvec,
745 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100746 {
747 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700748 .procname = "bootloader_version",
749 .data = &bootloader_version,
750 .maxlen = sizeof (int),
751 .mode = 0444,
752 .proc_handler = &proc_dointvec,
753 },
754 {
755 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100756 .procname = "kstack_depth_to_print",
757 .data = &kstack_depth_to_print,
758 .maxlen = sizeof(int),
759 .mode = 0644,
760 .proc_handler = &proc_dointvec,
761 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100762 {
763 .ctl_name = CTL_UNNUMBERED,
764 .procname = "io_delay_type",
765 .data = &io_delay_type,
766 .maxlen = sizeof(int),
767 .mode = 0644,
768 .proc_handler = &proc_dointvec,
769 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800771#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 {
773 .ctl_name = KERN_RANDOMIZE,
774 .procname = "randomize_va_space",
775 .data = &randomize_va_space,
776 .maxlen = sizeof(int),
777 .mode = 0644,
778 .proc_handler = &proc_dointvec,
779 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800780#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800781#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700782 {
783 .ctl_name = KERN_SPIN_RETRY,
784 .procname = "spin_retry",
785 .data = &spin_retry,
786 .maxlen = sizeof (int),
787 .mode = 0644,
788 .proc_handler = &proc_dointvec,
789 },
790#endif
Len Brown673d5b42007-07-28 03:33:16 -0400791#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800792 {
Pavel Machekc255d842006-02-20 18:27:58 -0800793 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700794 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800795 .maxlen = sizeof (unsigned long),
796 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800797 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800798 },
799#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800800#ifdef CONFIG_IA64
801 {
802 .ctl_name = KERN_IA64_UNALIGNED,
803 .procname = "ignore-unaligned-usertrap",
804 .data = &no_unaligned_warning,
805 .maxlen = sizeof (int),
806 .mode = 0644,
807 .proc_handler = &proc_dointvec,
808 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800809 {
810 .ctl_name = CTL_UNNUMBERED,
811 .procname = "unaligned-dump-stack",
812 .data = &unaligned_dump_stack,
813 .maxlen = sizeof (int),
814 .mode = 0644,
815 .proc_handler = &proc_dointvec,
816 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800817#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700818#ifdef CONFIG_DETECT_SOFTLOCKUP
819 {
820 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200821 .procname = "softlockup_panic",
822 .data = &softlockup_panic,
823 .maxlen = sizeof(int),
824 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700825 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200826 .strategy = &sysctl_intvec,
827 .extra1 = &zero,
828 .extra2 = &one,
829 },
830 {
831 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700832 .procname = "softlockup_thresh",
833 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200834 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700835 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800836 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700837 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200838 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700839 .extra2 = &sixty,
840 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800841#endif
842#ifdef CONFIG_DETECT_HUNG_TASK
843 {
844 .ctl_name = CTL_UNNUMBERED,
845 .procname = "hung_task_panic",
846 .data = &sysctl_hung_task_panic,
847 .maxlen = sizeof(int),
848 .mode = 0644,
849 .proc_handler = &proc_dointvec_minmax,
850 .strategy = &sysctl_intvec,
851 .extra1 = &zero,
852 .extra2 = &one,
853 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100854 {
855 .ctl_name = CTL_UNNUMBERED,
856 .procname = "hung_task_check_count",
857 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100858 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100859 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100860 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 .strategy = &sysctl_intvec,
862 },
863 {
864 .ctl_name = CTL_UNNUMBERED,
865 .procname = "hung_task_timeout_secs",
866 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100867 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800869 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100870 .strategy = &sysctl_intvec,
871 },
872 {
873 .ctl_name = CTL_UNNUMBERED,
874 .procname = "hung_task_warnings",
875 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100876 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100877 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100878 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100879 .strategy = &sysctl_intvec,
880 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700881#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200882#ifdef CONFIG_COMPAT
883 {
884 .ctl_name = KERN_COMPAT_LOG,
885 .procname = "compat-log",
886 .data = &compat_log,
887 .maxlen = sizeof (int),
888 .mode = 0644,
889 .proc_handler = &proc_dointvec,
890 },
891#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700892#ifdef CONFIG_RT_MUTEXES
893 {
894 .ctl_name = KERN_MAX_LOCK_DEPTH,
895 .procname = "max_lock_depth",
896 .data = &max_lock_depth,
897 .maxlen = sizeof(int),
898 .mode = 0644,
899 .proc_handler = &proc_dointvec,
900 },
901#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700902 {
903 .ctl_name = CTL_UNNUMBERED,
904 .procname = "poweroff_cmd",
905 .data = &poweroff_cmd,
906 .maxlen = POWEROFF_CMD_PATH_LEN,
907 .mode = 0644,
908 .proc_handler = &proc_dostring,
909 .strategy = &sysctl_string,
910 },
David Howells0b77f5b2008-04-29 01:01:32 -0700911#ifdef CONFIG_KEYS
912 {
913 .ctl_name = CTL_UNNUMBERED,
914 .procname = "keys",
915 .mode = 0555,
916 .child = key_sysctls,
917 },
918#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700919#ifdef CONFIG_RCU_TORTURE_TEST
920 {
921 .ctl_name = CTL_UNNUMBERED,
922 .procname = "rcutorture_runnable",
923 .data = &rcutorture_runnable,
924 .maxlen = sizeof(int),
925 .mode = 0644,
926 .proc_handler = &proc_dointvec,
927 },
928#endif
David Howells12e22c52009-04-03 16:42:35 +0100929#ifdef CONFIG_SLOW_WORK
930 {
931 .ctl_name = CTL_UNNUMBERED,
932 .procname = "slow-work",
933 .mode = 0555,
934 .child = slow_work_sysctls,
935 },
936#endif
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200937#ifdef CONFIG_PERF_COUNTERS
938 {
939 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra07647712009-06-11 11:18:36 +0200940 .procname = "perf_counter_paranoid",
941 .data = &sysctl_perf_counter_paranoid,
942 .maxlen = sizeof(sysctl_perf_counter_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200943 .mode = 0644,
944 .proc_handler = &proc_dointvec,
945 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200946 {
947 .ctl_name = CTL_UNNUMBERED,
948 .procname = "perf_counter_mlock_kb",
949 .data = &sysctl_perf_counter_mlock,
950 .maxlen = sizeof(sysctl_perf_counter_mlock),
951 .mode = 0644,
952 .proc_handler = &proc_dointvec,
953 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200954 {
955 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstradf58ab22009-06-11 11:25:05 +0200956 .procname = "perf_counter_max_sample_rate",
957 .data = &sysctl_perf_counter_sample_rate,
958 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200959 .mode = 0644,
960 .proc_handler = &proc_dointvec,
961 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200962#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200963#ifdef CONFIG_KMEMCHECK
964 {
965 .ctl_name = CTL_UNNUMBERED,
966 .procname = "kmemcheck",
967 .data = &kmemcheck_enabled,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = &proc_dointvec,
971 },
972#endif
973
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700974/*
975 * NOTE: do not add new entries to this table unless you have read
976 * Documentation/sysctl/ctl_unnumbered.txt
977 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 { .ctl_name = 0 }
979};
980
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700981static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 {
983 .ctl_name = VM_OVERCOMMIT_MEMORY,
984 .procname = "overcommit_memory",
985 .data = &sysctl_overcommit_memory,
986 .maxlen = sizeof(sysctl_overcommit_memory),
987 .mode = 0644,
988 .proc_handler = &proc_dointvec,
989 },
990 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700991 .ctl_name = VM_PANIC_ON_OOM,
992 .procname = "panic_on_oom",
993 .data = &sysctl_panic_on_oom,
994 .maxlen = sizeof(sysctl_panic_on_oom),
995 .mode = 0644,
996 .proc_handler = &proc_dointvec,
997 },
998 {
David Rientjesfe071d72007-10-16 23:25:56 -0700999 .ctl_name = CTL_UNNUMBERED,
1000 .procname = "oom_kill_allocating_task",
1001 .data = &sysctl_oom_kill_allocating_task,
1002 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1003 .mode = 0644,
1004 .proc_handler = &proc_dointvec,
1005 },
1006 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001007 .ctl_name = CTL_UNNUMBERED,
1008 .procname = "oom_dump_tasks",
1009 .data = &sysctl_oom_dump_tasks,
1010 .maxlen = sizeof(sysctl_oom_dump_tasks),
1011 .mode = 0644,
1012 .proc_handler = &proc_dointvec,
1013 },
1014 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .ctl_name = VM_OVERCOMMIT_RATIO,
1016 .procname = "overcommit_ratio",
1017 .data = &sysctl_overcommit_ratio,
1018 .maxlen = sizeof(sysctl_overcommit_ratio),
1019 .mode = 0644,
1020 .proc_handler = &proc_dointvec,
1021 },
1022 {
1023 .ctl_name = VM_PAGE_CLUSTER,
1024 .procname = "page-cluster",
1025 .data = &page_cluster,
1026 .maxlen = sizeof(int),
1027 .mode = 0644,
1028 .proc_handler = &proc_dointvec,
1029 },
1030 {
1031 .ctl_name = VM_DIRTY_BACKGROUND,
1032 .procname = "dirty_background_ratio",
1033 .data = &dirty_background_ratio,
1034 .maxlen = sizeof(dirty_background_ratio),
1035 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001036 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 .strategy = &sysctl_intvec,
1038 .extra1 = &zero,
1039 .extra2 = &one_hundred,
1040 },
1041 {
David Rientjes2da02992009-01-06 14:39:31 -08001042 .ctl_name = CTL_UNNUMBERED,
1043 .procname = "dirty_background_bytes",
1044 .data = &dirty_background_bytes,
1045 .maxlen = sizeof(dirty_background_bytes),
1046 .mode = 0644,
1047 .proc_handler = &dirty_background_bytes_handler,
1048 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001049 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001050 },
1051 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .ctl_name = VM_DIRTY_RATIO,
1053 .procname = "dirty_ratio",
1054 .data = &vm_dirty_ratio,
1055 .maxlen = sizeof(vm_dirty_ratio),
1056 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001057 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 .strategy = &sysctl_intvec,
1059 .extra1 = &zero,
1060 .extra2 = &one_hundred,
1061 },
1062 {
David Rientjes2da02992009-01-06 14:39:31 -08001063 .ctl_name = CTL_UNNUMBERED,
1064 .procname = "dirty_bytes",
1065 .data = &vm_dirty_bytes,
1066 .maxlen = sizeof(vm_dirty_bytes),
1067 .mode = 0644,
1068 .proc_handler = &dirty_bytes_handler,
1069 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001070 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001071 },
1072 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001074 .data = &dirty_writeback_interval,
1075 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .mode = 0644,
1077 .proc_handler = &dirty_writeback_centisecs_handler,
1078 },
1079 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001081 .data = &dirty_expire_interval,
1082 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001084 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 },
1086 {
1087 .ctl_name = VM_NR_PDFLUSH_THREADS,
1088 .procname = "nr_pdflush_threads",
1089 .data = &nr_pdflush_threads,
1090 .maxlen = sizeof nr_pdflush_threads,
1091 .mode = 0444 /* read-only*/,
1092 .proc_handler = &proc_dointvec,
1093 },
1094 {
1095 .ctl_name = VM_SWAPPINESS,
1096 .procname = "swappiness",
1097 .data = &vm_swappiness,
1098 .maxlen = sizeof(vm_swappiness),
1099 .mode = 0644,
1100 .proc_handler = &proc_dointvec_minmax,
1101 .strategy = &sysctl_intvec,
1102 .extra1 = &zero,
1103 .extra2 = &one_hundred,
1104 },
1105#ifdef CONFIG_HUGETLB_PAGE
1106 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001108 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 .maxlen = sizeof(unsigned long),
1110 .mode = 0644,
1111 .proc_handler = &hugetlb_sysctl_handler,
1112 .extra1 = (void *)&hugetlb_zero,
1113 .extra2 = (void *)&hugetlb_infinity,
1114 },
1115 {
1116 .ctl_name = VM_HUGETLB_GROUP,
1117 .procname = "hugetlb_shm_group",
1118 .data = &sysctl_hugetlb_shm_group,
1119 .maxlen = sizeof(gid_t),
1120 .mode = 0644,
1121 .proc_handler = &proc_dointvec,
1122 },
Mel Gorman396faf02007-07-17 04:03:13 -07001123 {
1124 .ctl_name = CTL_UNNUMBERED,
1125 .procname = "hugepages_treat_as_movable",
1126 .data = &hugepages_treat_as_movable,
1127 .maxlen = sizeof(int),
1128 .mode = 0644,
1129 .proc_handler = &hugetlb_treat_movable_handler,
1130 },
Adam Litke54f9f802007-10-16 01:26:20 -07001131 {
1132 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001133 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001134 .data = NULL,
1135 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001136 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001137 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001138 .extra1 = (void *)&hugetlb_zero,
1139 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001140 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141#endif
1142 {
1143 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1144 .procname = "lowmem_reserve_ratio",
1145 .data = &sysctl_lowmem_reserve_ratio,
1146 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1147 .mode = 0644,
1148 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1149 .strategy = &sysctl_intvec,
1150 },
1151 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001152 .ctl_name = VM_DROP_PAGECACHE,
1153 .procname = "drop_caches",
1154 .data = &sysctl_drop_caches,
1155 .maxlen = sizeof(int),
1156 .mode = 0644,
1157 .proc_handler = drop_caches_sysctl_handler,
1158 .strategy = &sysctl_intvec,
1159 },
1160 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 .ctl_name = VM_MIN_FREE_KBYTES,
1162 .procname = "min_free_kbytes",
1163 .data = &min_free_kbytes,
1164 .maxlen = sizeof(min_free_kbytes),
1165 .mode = 0644,
1166 .proc_handler = &min_free_kbytes_sysctl_handler,
1167 .strategy = &sysctl_intvec,
1168 .extra1 = &zero,
1169 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001170 {
1171 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1172 .procname = "percpu_pagelist_fraction",
1173 .data = &percpu_pagelist_fraction,
1174 .maxlen = sizeof(percpu_pagelist_fraction),
1175 .mode = 0644,
1176 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1177 .strategy = &sysctl_intvec,
1178 .extra1 = &min_percpu_pagelist_fract,
1179 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#ifdef CONFIG_MMU
1181 {
1182 .ctl_name = VM_MAX_MAP_COUNT,
1183 .procname = "max_map_count",
1184 .data = &sysctl_max_map_count,
1185 .maxlen = sizeof(sysctl_max_map_count),
1186 .mode = 0644,
1187 .proc_handler = &proc_dointvec
1188 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001189#else
1190 {
1191 .ctl_name = CTL_UNNUMBERED,
1192 .procname = "nr_trim_pages",
1193 .data = &sysctl_nr_trim_pages,
1194 .maxlen = sizeof(sysctl_nr_trim_pages),
1195 .mode = 0644,
1196 .proc_handler = &proc_dointvec_minmax,
1197 .strategy = &sysctl_intvec,
1198 .extra1 = &zero,
1199 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200#endif
1201 {
1202 .ctl_name = VM_LAPTOP_MODE,
1203 .procname = "laptop_mode",
1204 .data = &laptop_mode,
1205 .maxlen = sizeof(laptop_mode),
1206 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001207 .proc_handler = &proc_dointvec_jiffies,
1208 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 },
1210 {
1211 .ctl_name = VM_BLOCK_DUMP,
1212 .procname = "block_dump",
1213 .data = &block_dump,
1214 .maxlen = sizeof(block_dump),
1215 .mode = 0644,
1216 .proc_handler = &proc_dointvec,
1217 .strategy = &sysctl_intvec,
1218 .extra1 = &zero,
1219 },
1220 {
1221 .ctl_name = VM_VFS_CACHE_PRESSURE,
1222 .procname = "vfs_cache_pressure",
1223 .data = &sysctl_vfs_cache_pressure,
1224 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1225 .mode = 0644,
1226 .proc_handler = &proc_dointvec,
1227 .strategy = &sysctl_intvec,
1228 .extra1 = &zero,
1229 },
1230#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1231 {
1232 .ctl_name = VM_LEGACY_VA_LAYOUT,
1233 .procname = "legacy_va_layout",
1234 .data = &sysctl_legacy_va_layout,
1235 .maxlen = sizeof(sysctl_legacy_va_layout),
1236 .mode = 0644,
1237 .proc_handler = &proc_dointvec,
1238 .strategy = &sysctl_intvec,
1239 .extra1 = &zero,
1240 },
1241#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001242#ifdef CONFIG_NUMA
1243 {
1244 .ctl_name = VM_ZONE_RECLAIM_MODE,
1245 .procname = "zone_reclaim_mode",
1246 .data = &zone_reclaim_mode,
1247 .maxlen = sizeof(zone_reclaim_mode),
1248 .mode = 0644,
1249 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001250 .strategy = &sysctl_intvec,
1251 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001252 },
Christoph Lameter96146342006-07-03 00:24:13 -07001253 {
1254 .ctl_name = VM_MIN_UNMAPPED,
1255 .procname = "min_unmapped_ratio",
1256 .data = &sysctl_min_unmapped_ratio,
1257 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1258 .mode = 0644,
1259 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1260 .strategy = &sysctl_intvec,
1261 .extra1 = &zero,
1262 .extra2 = &one_hundred,
1263 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001264 {
1265 .ctl_name = VM_MIN_SLAB,
1266 .procname = "min_slab_ratio",
1267 .data = &sysctl_min_slab_ratio,
1268 .maxlen = sizeof(sysctl_min_slab_ratio),
1269 .mode = 0644,
1270 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1271 .strategy = &sysctl_intvec,
1272 .extra1 = &zero,
1273 .extra2 = &one_hundred,
1274 },
Christoph Lameter17436602006-01-18 17:42:32 -08001275#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001276#ifdef CONFIG_SMP
1277 {
1278 .ctl_name = CTL_UNNUMBERED,
1279 .procname = "stat_interval",
1280 .data = &sysctl_stat_interval,
1281 .maxlen = sizeof(sysctl_stat_interval),
1282 .mode = 0644,
1283 .proc_handler = &proc_dointvec_jiffies,
1284 .strategy = &sysctl_jiffies,
1285 },
1286#endif
Eric Parised032182007-06-28 15:55:21 -04001287 {
1288 .ctl_name = CTL_UNNUMBERED,
1289 .procname = "mmap_min_addr",
1290 .data = &mmap_min_addr,
1291 .maxlen = sizeof(unsigned long),
1292 .mode = 0644,
1293 .proc_handler = &proc_doulongvec_minmax,
1294 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001295#ifdef CONFIG_NUMA
1296 {
1297 .ctl_name = CTL_UNNUMBERED,
1298 .procname = "numa_zonelist_order",
1299 .data = &numa_zonelist_order,
1300 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1301 .mode = 0644,
1302 .proc_handler = &numa_zonelist_order_handler,
1303 .strategy = &sysctl_string,
1304 },
1305#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001306#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001307 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001308 {
1309 .ctl_name = VM_VDSO_ENABLED,
1310 .procname = "vdso_enabled",
1311 .data = &vdso_enabled,
1312 .maxlen = sizeof(vdso_enabled),
1313 .mode = 0644,
1314 .proc_handler = &proc_dointvec,
1315 .strategy = &sysctl_intvec,
1316 .extra1 = &zero,
1317 },
1318#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001319#ifdef CONFIG_HIGHMEM
1320 {
1321 .ctl_name = CTL_UNNUMBERED,
1322 .procname = "highmem_is_dirtyable",
1323 .data = &vm_highmem_is_dirtyable,
1324 .maxlen = sizeof(vm_highmem_is_dirtyable),
1325 .mode = 0644,
1326 .proc_handler = &proc_dointvec_minmax,
1327 .strategy = &sysctl_intvec,
1328 .extra1 = &zero,
1329 .extra2 = &one,
1330 },
1331#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001332#ifdef CONFIG_UNEVICTABLE_LRU
1333 {
1334 .ctl_name = CTL_UNNUMBERED,
1335 .procname = "scan_unevictable_pages",
1336 .data = &scan_unevictable_pages,
1337 .maxlen = sizeof(scan_unevictable_pages),
1338 .mode = 0644,
1339 .proc_handler = &scan_unevictable_handler,
1340 },
1341#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001342/*
1343 * NOTE: do not add new entries to this table unless you have read
1344 * Documentation/sysctl/ctl_unnumbered.txt
1345 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 { .ctl_name = 0 }
1347};
1348
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001349#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001350static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001351 { .ctl_name = 0 }
1352};
1353#endif
1354
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001355static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 {
1357 .ctl_name = FS_NRINODE,
1358 .procname = "inode-nr",
1359 .data = &inodes_stat,
1360 .maxlen = 2*sizeof(int),
1361 .mode = 0444,
1362 .proc_handler = &proc_dointvec,
1363 },
1364 {
1365 .ctl_name = FS_STATINODE,
1366 .procname = "inode-state",
1367 .data = &inodes_stat,
1368 .maxlen = 7*sizeof(int),
1369 .mode = 0444,
1370 .proc_handler = &proc_dointvec,
1371 },
1372 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 .procname = "file-nr",
1374 .data = &files_stat,
1375 .maxlen = 3*sizeof(int),
1376 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001377 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 },
1379 {
1380 .ctl_name = FS_MAXFILE,
1381 .procname = "file-max",
1382 .data = &files_stat.max_files,
1383 .maxlen = sizeof(int),
1384 .mode = 0644,
1385 .proc_handler = &proc_dointvec,
1386 },
1387 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001388 .ctl_name = CTL_UNNUMBERED,
1389 .procname = "nr_open",
1390 .data = &sysctl_nr_open,
1391 .maxlen = sizeof(int),
1392 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001393 .proc_handler = &proc_dointvec_minmax,
1394 .extra1 = &sysctl_nr_open_min,
1395 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001396 },
1397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .ctl_name = FS_DENTRY,
1399 .procname = "dentry-state",
1400 .data = &dentry_stat,
1401 .maxlen = 6*sizeof(int),
1402 .mode = 0444,
1403 .proc_handler = &proc_dointvec,
1404 },
1405 {
1406 .ctl_name = FS_OVERFLOWUID,
1407 .procname = "overflowuid",
1408 .data = &fs_overflowuid,
1409 .maxlen = sizeof(int),
1410 .mode = 0644,
1411 .proc_handler = &proc_dointvec_minmax,
1412 .strategy = &sysctl_intvec,
1413 .extra1 = &minolduid,
1414 .extra2 = &maxolduid,
1415 },
1416 {
1417 .ctl_name = FS_OVERFLOWGID,
1418 .procname = "overflowgid",
1419 .data = &fs_overflowgid,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
1422 .proc_handler = &proc_dointvec_minmax,
1423 .strategy = &sysctl_intvec,
1424 .extra1 = &minolduid,
1425 .extra2 = &maxolduid,
1426 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001427#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 {
1429 .ctl_name = FS_LEASES,
1430 .procname = "leases-enable",
1431 .data = &leases_enable,
1432 .maxlen = sizeof(int),
1433 .mode = 0644,
1434 .proc_handler = &proc_dointvec,
1435 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001436#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437#ifdef CONFIG_DNOTIFY
1438 {
1439 .ctl_name = FS_DIR_NOTIFY,
1440 .procname = "dir-notify-enable",
1441 .data = &dir_notify_enable,
1442 .maxlen = sizeof(int),
1443 .mode = 0644,
1444 .proc_handler = &proc_dointvec,
1445 },
1446#endif
1447#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001448#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 {
1450 .ctl_name = FS_LEASE_TIME,
1451 .procname = "lease-break-time",
1452 .data = &lease_break_time,
1453 .maxlen = sizeof(int),
1454 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001455 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001457#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001458#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 .procname = "aio-nr",
1461 .data = &aio_nr,
1462 .maxlen = sizeof(aio_nr),
1463 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001464 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 },
1466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 .procname = "aio-max-nr",
1468 .data = &aio_max_nr,
1469 .maxlen = sizeof(aio_max_nr),
1470 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001471 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001473#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001474#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001475 {
1476 .ctl_name = FS_INOTIFY,
1477 .procname = "inotify",
1478 .mode = 0555,
1479 .child = inotify_table,
1480 },
1481#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001482#ifdef CONFIG_EPOLL
1483 {
1484 .procname = "epoll",
1485 .mode = 0555,
1486 .child = epoll_table,
1487 },
1488#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001490 {
1491 .ctl_name = KERN_SETUID_DUMPABLE,
1492 .procname = "suid_dumpable",
1493 .data = &suid_dumpable,
1494 .maxlen = sizeof(int),
1495 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001496 .proc_handler = &proc_dointvec_minmax,
1497 .strategy = &sysctl_intvec,
1498 .extra1 = &zero,
1499 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001500 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001501#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1502 {
1503 .ctl_name = CTL_UNNUMBERED,
1504 .procname = "binfmt_misc",
1505 .mode = 0555,
1506 .child = binfmt_misc_table,
1507 },
1508#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001509/*
1510 * NOTE: do not add new entries to this table unless you have read
1511 * Documentation/sysctl/ctl_unnumbered.txt
1512 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 { .ctl_name = 0 }
1514};
1515
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001516static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001517#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001518 {
1519 .ctl_name = CTL_UNNUMBERED,
1520 .procname = "exception-trace",
1521 .data = &show_unhandled_signals,
1522 .maxlen = sizeof(int),
1523 .mode = 0644,
1524 .proc_handler = proc_dointvec
1525 },
1526#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 { .ctl_name = 0 }
1528};
1529
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001530static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001532};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Al Viro330d57f2005-11-04 10:18:40 +00001534static DEFINE_SPINLOCK(sysctl_lock);
1535
1536/* called under sysctl_lock */
1537static int use_table(struct ctl_table_header *p)
1538{
1539 if (unlikely(p->unregistering))
1540 return 0;
1541 p->used++;
1542 return 1;
1543}
1544
1545/* called under sysctl_lock */
1546static void unuse_table(struct ctl_table_header *p)
1547{
1548 if (!--p->used)
1549 if (unlikely(p->unregistering))
1550 complete(p->unregistering);
1551}
1552
1553/* called under sysctl_lock, will reacquire if has to wait */
1554static void start_unregistering(struct ctl_table_header *p)
1555{
1556 /*
1557 * if p->used is 0, nobody will ever touch that entry again;
1558 * we'll eliminate all paths to it before dropping sysctl_lock
1559 */
1560 if (unlikely(p->used)) {
1561 struct completion wait;
1562 init_completion(&wait);
1563 p->unregistering = &wait;
1564 spin_unlock(&sysctl_lock);
1565 wait_for_completion(&wait);
1566 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001567 } else {
1568 /* anything non-NULL; we'll never dereference it */
1569 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001570 }
1571 /*
1572 * do not remove from the list until nobody holds it; walking the
1573 * list in do_sysctl() relies on that.
1574 */
1575 list_del_init(&p->ctl_entry);
1576}
1577
Al Virof7e6ced2008-07-15 01:44:23 -04001578void sysctl_head_get(struct ctl_table_header *head)
1579{
1580 spin_lock(&sysctl_lock);
1581 head->count++;
1582 spin_unlock(&sysctl_lock);
1583}
1584
1585void sysctl_head_put(struct ctl_table_header *head)
1586{
1587 spin_lock(&sysctl_lock);
1588 if (!--head->count)
1589 kfree(head);
1590 spin_unlock(&sysctl_lock);
1591}
1592
1593struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1594{
1595 if (!head)
1596 BUG();
1597 spin_lock(&sysctl_lock);
1598 if (!use_table(head))
1599 head = ERR_PTR(-ENOENT);
1600 spin_unlock(&sysctl_lock);
1601 return head;
1602}
1603
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001604void sysctl_head_finish(struct ctl_table_header *head)
1605{
1606 if (!head)
1607 return;
1608 spin_lock(&sysctl_lock);
1609 unuse_table(head);
1610 spin_unlock(&sysctl_lock);
1611}
1612
Al Viro73455092008-07-14 21:22:20 -04001613static struct ctl_table_set *
1614lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1615{
1616 struct ctl_table_set *set = &root->default_set;
1617 if (root->lookup)
1618 set = root->lookup(root, namespaces);
1619 return set;
1620}
1621
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001622static struct list_head *
1623lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001624{
Al Viro73455092008-07-14 21:22:20 -04001625 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1626 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001627}
1628
1629struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1630 struct ctl_table_header *prev)
1631{
1632 struct ctl_table_root *root;
1633 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001634 struct ctl_table_header *head;
1635 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001636
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001637 spin_lock(&sysctl_lock);
1638 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001639 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001640 tmp = &prev->ctl_entry;
1641 unuse_table(prev);
1642 goto next;
1643 }
1644 tmp = &root_table_header.ctl_entry;
1645 for (;;) {
1646 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1647
1648 if (!use_table(head))
1649 goto next;
1650 spin_unlock(&sysctl_lock);
1651 return head;
1652 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001653 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001654 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001655 header_list = lookup_header_list(root, namespaces);
1656 if (tmp != header_list)
1657 continue;
1658
1659 do {
1660 root = list_entry(root->root_list.next,
1661 struct ctl_table_root, root_list);
1662 if (root == &sysctl_table_root)
1663 goto out;
1664 header_list = lookup_header_list(root, namespaces);
1665 } while (list_empty(header_list));
1666 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001667 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001668out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001669 spin_unlock(&sysctl_lock);
1670 return NULL;
1671}
1672
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001673struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1674{
1675 return __sysctl_head_next(current->nsproxy, prev);
1676}
1677
1678void register_sysctl_root(struct ctl_table_root *root)
1679{
1680 spin_lock(&sysctl_lock);
1681 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1682 spin_unlock(&sysctl_lock);
1683}
1684
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001685#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001686/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001687static int do_sysctl_strategy(struct ctl_table_root *root,
1688 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001689 void __user *oldval, size_t __user *oldlenp,
1690 void __user *newval, size_t newlen)
1691{
1692 int op = 0, rc;
1693
1694 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001695 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001696 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001697 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001698 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001699 return -EPERM;
1700
1701 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001702 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001703 if (rc < 0)
1704 return rc;
1705 if (rc > 0)
1706 return 0;
1707 }
1708
1709 /* If there is no strategy routine, or if the strategy returns
1710 * zero, proceed with automatic r/w */
1711 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001712 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001713 if (rc < 0)
1714 return rc;
1715 }
1716 return 0;
1717}
1718
1719static int parse_table(int __user *name, int nlen,
1720 void __user *oldval, size_t __user *oldlenp,
1721 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001722 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001723 struct ctl_table *table)
1724{
1725 int n;
1726repeat:
1727 if (!nlen)
1728 return -ENOTDIR;
1729 if (get_user(n, name))
1730 return -EFAULT;
1731 for ( ; table->ctl_name || table->procname; table++) {
1732 if (!table->ctl_name)
1733 continue;
1734 if (n == table->ctl_name) {
1735 int error;
1736 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001737 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001738 return -EPERM;
1739 name++;
1740 nlen--;
1741 table = table->child;
1742 goto repeat;
1743 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001744 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001745 oldval, oldlenp,
1746 newval, newlen);
1747 return error;
1748 }
1749 }
1750 return -ENOTDIR;
1751}
1752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1754 void __user *newval, size_t newlen)
1755{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001756 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001757 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
1759 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1760 return -ENOTDIR;
1761 if (oldval) {
1762 int old_len;
1763 if (!oldlenp || get_user(old_len, oldlenp))
1764 return -EFAULT;
1765 }
Al Viro330d57f2005-11-04 10:18:40 +00001766
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001767 for (head = sysctl_head_next(NULL); head;
1768 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001769 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001770 newval, newlen,
1771 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001772 if (error != -ENOTDIR) {
1773 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001774 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001775 }
1776 }
Al Viro330d57f2005-11-04 10:18:40 +00001777 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778}
1779
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001780SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 struct __sysctl_args tmp;
1783 int error;
1784
1785 if (copy_from_user(&tmp, args, sizeof(tmp)))
1786 return -EFAULT;
1787
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001788 error = deprecated_sysctl_warning(&tmp);
1789 if (error)
1790 goto out;
1791
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 lock_kernel();
1793 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1794 tmp.newval, tmp.newlen);
1795 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001796out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 return error;
1798}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001799#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
1801/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001802 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 * some sysctl variables are readonly even to root.
1804 */
1805
1806static int test_perm(int mode, int op)
1807{
David Howells76aac0e2008-11-14 10:39:12 +11001808 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 mode >>= 6;
1810 else if (in_egroup_p(0))
1811 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001812 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 return 0;
1814 return -EACCES;
1815}
1816
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001817int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818{
1819 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001820 int mode;
1821
Al Viroe6305c42008-07-15 21:03:57 -04001822 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 if (error)
1824 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001825
1826 if (root->permissions)
1827 mode = root->permissions(root, current->nsproxy, table);
1828 else
1829 mode = table->mode;
1830
1831 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832}
1833
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001834static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1835{
1836 for (; table->ctl_name || table->procname; table++) {
1837 table->parent = parent;
1838 if (table->child)
1839 sysctl_set_parent(table, table->child);
1840 }
1841}
1842
1843static __init int sysctl_init(void)
1844{
1845 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001846#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1847 {
1848 int err;
1849 err = sysctl_check_table(current->nsproxy, root_table);
1850 }
1851#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001852 return 0;
1853}
1854
1855core_initcall(sysctl_init);
1856
Al Virobfbcf032008-07-27 06:31:22 +01001857static struct ctl_table *is_branch_in(struct ctl_table *branch,
1858 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001859{
1860 struct ctl_table *p;
1861 const char *s = branch->procname;
1862
1863 /* branch should have named subdirectory as its first element */
1864 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001865 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001866
1867 /* ... and nothing else */
1868 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001869 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001870
1871 /* table should contain subdirectory with the same name */
1872 for (p = table; p->procname || p->ctl_name; p++) {
1873 if (!p->child)
1874 continue;
1875 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001876 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001877 }
Al Virobfbcf032008-07-27 06:31:22 +01001878 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001879}
1880
1881/* see if attaching q to p would be an improvement */
1882static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1883{
1884 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001885 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001886 int is_better = 0;
1887 int not_in_parent = !p->attached_by;
1888
Al Virobfbcf032008-07-27 06:31:22 +01001889 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001890 if (by == q->attached_by)
1891 is_better = 1;
1892 if (to == p->attached_by)
1893 not_in_parent = 1;
1894 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001895 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001896 }
1897
1898 if (is_better && not_in_parent) {
1899 q->attached_by = by;
1900 q->attached_to = to;
1901 q->parent = p;
1902 }
1903}
1904
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001906 * __register_sysctl_paths - register a sysctl hierarchy
1907 * @root: List of sysctl headers to register on
1908 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001909 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 *
1912 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001913 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001915 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 *
1917 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1918 * must be unique within that level of sysctl
1919 *
1920 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1921 * enter a sysctl file
1922 *
1923 * data - a pointer to data for use by proc_handler
1924 *
1925 * maxlen - the maximum size in bytes of the data
1926 *
1927 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1928 *
1929 * child - a pointer to the child sysctl table if this entry is a directory, or
1930 * %NULL.
1931 *
1932 * proc_handler - the text handler routine (described below)
1933 *
1934 * strategy - the strategy routine (described below)
1935 *
1936 * de - for internal use by the sysctl routines
1937 *
1938 * extra1, extra2 - extra pointers usable by the proc handler routines
1939 *
1940 * Leaf nodes in the sysctl tree will be represented by a single file
1941 * under /proc; non-leaf nodes will be represented by directories.
1942 *
1943 * sysctl(2) can automatically manage read and write requests through
1944 * the sysctl table. The data and maxlen fields of the ctl_table
1945 * struct enable minimal validation of the values being written to be
1946 * performed, and the mode field allows minimal authentication.
1947 *
1948 * More sophisticated management can be enabled by the provision of a
1949 * strategy routine with the table entry. This will be called before
1950 * any automatic read or write of the data is performed.
1951 *
1952 * The strategy routine may return
1953 *
1954 * < 0 - Error occurred (error is passed to user process)
1955 *
1956 * 0 - OK - proceed with automatic read or write.
1957 *
1958 * > 0 - OK - read or write has been done by the strategy routine, so
1959 * return immediately.
1960 *
1961 * There must be a proc_handler routine for any terminal nodes
1962 * mirrored under /proc/sys (non-terminals are handled by a built-in
1963 * directory handler). Several default handlers are available to
1964 * cover common cases -
1965 *
1966 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1967 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1968 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1969 *
1970 * It is the handler's job to read the input buffer from user memory
1971 * and process it. The handler should return 0 on success.
1972 *
1973 * This routine returns %NULL on a failure to register, and a pointer
1974 * to the table header on success.
1975 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001976struct ctl_table_header *__register_sysctl_paths(
1977 struct ctl_table_root *root,
1978 struct nsproxy *namespaces,
1979 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001981 struct ctl_table_header *header;
1982 struct ctl_table *new, **prevp;
1983 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001984 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001985
1986 /* Count the path components */
1987 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1988 ;
1989
1990 /*
1991 * For each path component, allocate a 2-element ctl_table array.
1992 * The first array element will be filled with the sysctl entry
1993 * for this, the second will be the sentinel (ctl_name == 0).
1994 *
1995 * We allocate everything in one go so that we don't have to
1996 * worry about freeing additional memory in unregister_sysctl_table.
1997 */
1998 header = kzalloc(sizeof(struct ctl_table_header) +
1999 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2000 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002002
2003 new = (struct ctl_table *) (header + 1);
2004
2005 /* Now connect the dots */
2006 prevp = &header->ctl_table;
2007 for (n = 0; n < npath; ++n, ++path) {
2008 /* Copy the procname */
2009 new->procname = path->procname;
2010 new->ctl_name = path->ctl_name;
2011 new->mode = 0555;
2012
2013 *prevp = new;
2014 prevp = &new->child;
2015
2016 new += 2;
2017 }
2018 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002019 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002020
2021 INIT_LIST_HEAD(&header->ctl_entry);
2022 header->used = 0;
2023 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002024 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002025 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002026 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002027#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002028 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002029 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002030 return NULL;
2031 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002032#endif
Al Viro330d57f2005-11-04 10:18:40 +00002033 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002034 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002035 header->attached_by = header->ctl_table;
2036 header->attached_to = root_table;
2037 header->parent = &root_table_header;
2038 for (set = header->set; set; set = set->parent) {
2039 struct ctl_table_header *p;
2040 list_for_each_entry(p, &set->list, ctl_entry) {
2041 if (p->unregistering)
2042 continue;
2043 try_attach(p, header);
2044 }
2045 }
2046 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002047 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002048 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002049
2050 return header;
2051}
2052
2053/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002054 * register_sysctl_table_path - register a sysctl table hierarchy
2055 * @path: The path to the directory the sysctl table is in.
2056 * @table: the top-level table structure
2057 *
2058 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2059 * array. A completely 0 filled entry terminates the table.
2060 *
2061 * See __register_sysctl_paths for more details.
2062 */
2063struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2064 struct ctl_table *table)
2065{
2066 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2067 path, table);
2068}
2069
2070/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002071 * register_sysctl_table - register a sysctl table hierarchy
2072 * @table: the top-level table structure
2073 *
2074 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2075 * array. A completely 0 filled entry terminates the table.
2076 *
2077 * See register_sysctl_paths for more details.
2078 */
2079struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2080{
2081 static const struct ctl_path null_path[] = { {} };
2082
2083 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084}
2085
2086/**
2087 * unregister_sysctl_table - unregister a sysctl table hierarchy
2088 * @header: the header returned from register_sysctl_table
2089 *
2090 * Unregisters the sysctl table and all children. proc entries may not
2091 * actually be removed until they are no longer used by anyone.
2092 */
2093void unregister_sysctl_table(struct ctl_table_header * header)
2094{
Al Viro330d57f2005-11-04 10:18:40 +00002095 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002096
2097 if (header == NULL)
2098 return;
2099
Al Viro330d57f2005-11-04 10:18:40 +00002100 spin_lock(&sysctl_lock);
2101 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002102 if (!--header->parent->count) {
2103 WARN_ON(1);
2104 kfree(header->parent);
2105 }
Al Virof7e6ced2008-07-15 01:44:23 -04002106 if (!--header->count)
2107 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002108 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109}
2110
Al Viro9043476f2008-07-15 08:54:06 -04002111int sysctl_is_seen(struct ctl_table_header *p)
2112{
2113 struct ctl_table_set *set = p->set;
2114 int res;
2115 spin_lock(&sysctl_lock);
2116 if (p->unregistering)
2117 res = 0;
2118 else if (!set->is_seen)
2119 res = 1;
2120 else
2121 res = set->is_seen(set);
2122 spin_unlock(&sysctl_lock);
2123 return res;
2124}
2125
Al Viro73455092008-07-14 21:22:20 -04002126void setup_sysctl_set(struct ctl_table_set *p,
2127 struct ctl_table_set *parent,
2128 int (*is_seen)(struct ctl_table_set *))
2129{
2130 INIT_LIST_HEAD(&p->list);
2131 p->parent = parent ? parent : &sysctl_table_root.default_set;
2132 p->is_seen = is_seen;
2133}
2134
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002135#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002136struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002137{
2138 return NULL;
2139}
2140
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002141struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2142 struct ctl_table *table)
2143{
2144 return NULL;
2145}
2146
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002147void unregister_sysctl_table(struct ctl_table_header * table)
2148{
2149}
2150
Al Viro73455092008-07-14 21:22:20 -04002151void setup_sysctl_set(struct ctl_table_set *p,
2152 struct ctl_table_set *parent,
2153 int (*is_seen)(struct ctl_table_set *))
2154{
2155}
2156
Al Virof7e6ced2008-07-15 01:44:23 -04002157void sysctl_head_put(struct ctl_table_header *head)
2158{
2159}
2160
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002161#endif /* CONFIG_SYSCTL */
2162
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163/*
2164 * /proc/sys support
2165 */
2166
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002167#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002169static int _proc_do_string(void* data, int maxlen, int write,
2170 struct file *filp, void __user *buffer,
2171 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002172{
2173 size_t len;
2174 char __user *p;
2175 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002176
2177 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002178 *lenp = 0;
2179 return 0;
2180 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002181
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002182 if (write) {
2183 len = 0;
2184 p = buffer;
2185 while (len < *lenp) {
2186 if (get_user(c, p++))
2187 return -EFAULT;
2188 if (c == 0 || c == '\n')
2189 break;
2190 len++;
2191 }
2192 if (len >= maxlen)
2193 len = maxlen-1;
2194 if(copy_from_user(data, buffer, len))
2195 return -EFAULT;
2196 ((char *) data)[len] = 0;
2197 *ppos += *lenp;
2198 } else {
2199 len = strlen(data);
2200 if (len > maxlen)
2201 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002202
2203 if (*ppos > len) {
2204 *lenp = 0;
2205 return 0;
2206 }
2207
2208 data += *ppos;
2209 len -= *ppos;
2210
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002211 if (len > *lenp)
2212 len = *lenp;
2213 if (len)
2214 if(copy_to_user(buffer, data, len))
2215 return -EFAULT;
2216 if (len < *lenp) {
2217 if(put_user('\n', ((char __user *) buffer) + len))
2218 return -EFAULT;
2219 len++;
2220 }
2221 *lenp = len;
2222 *ppos += len;
2223 }
2224 return 0;
2225}
2226
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227/**
2228 * proc_dostring - read a string sysctl
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @filp: the file structure
2232 * @buffer: the user buffer
2233 * @lenp: the size of the user buffer
2234 * @ppos: file position
2235 *
2236 * Reads/writes a string from/to the user buffer. If the kernel
2237 * buffer provided is not large enough to hold the string, the
2238 * string is truncated. The copied string is %NULL-terminated.
2239 * If the string is being read by the user process, it is copied
2240 * and a newline '\n' is added. It is truncated if the buffer is
2241 * not large enough.
2242 *
2243 * Returns 0 on success.
2244 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002245int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 void __user *buffer, size_t *lenp, loff_t *ppos)
2247{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002248 return _proc_do_string(table->data, table->maxlen, write, filp,
2249 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250}
2251
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
2253static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2254 int *valp,
2255 int write, void *data)
2256{
2257 if (write) {
2258 *valp = *negp ? -*lvalp : *lvalp;
2259 } else {
2260 int val = *valp;
2261 if (val < 0) {
2262 *negp = -1;
2263 *lvalp = (unsigned long)-val;
2264 } else {
2265 *negp = 0;
2266 *lvalp = (unsigned long)val;
2267 }
2268 }
2269 return 0;
2270}
2271
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002272static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002273 int write, struct file *filp, void __user *buffer,
2274 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2276 int write, void *data),
2277 void *data)
2278{
2279#define TMPBUFLEN 21
2280 int *i, vleft, first=1, neg, val;
2281 unsigned long lval;
2282 size_t left, len;
2283
2284 char buf[TMPBUFLEN], *p;
2285 char __user *s = buffer;
2286
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002287 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 (*ppos && !write)) {
2289 *lenp = 0;
2290 return 0;
2291 }
2292
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002293 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 vleft = table->maxlen / sizeof(*i);
2295 left = *lenp;
2296
2297 if (!conv)
2298 conv = do_proc_dointvec_conv;
2299
2300 for (; left && vleft--; i++, first=0) {
2301 if (write) {
2302 while (left) {
2303 char c;
2304 if (get_user(c, s))
2305 return -EFAULT;
2306 if (!isspace(c))
2307 break;
2308 left--;
2309 s++;
2310 }
2311 if (!left)
2312 break;
2313 neg = 0;
2314 len = left;
2315 if (len > sizeof(buf) - 1)
2316 len = sizeof(buf) - 1;
2317 if (copy_from_user(buf, s, len))
2318 return -EFAULT;
2319 buf[len] = 0;
2320 p = buf;
2321 if (*p == '-' && left > 1) {
2322 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002323 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 }
2325 if (*p < '0' || *p > '9')
2326 break;
2327
2328 lval = simple_strtoul(p, &p, 0);
2329
2330 len = p-buf;
2331 if ((len < left) && *p && !isspace(*p))
2332 break;
2333 if (neg)
2334 val = -val;
2335 s += len;
2336 left -= len;
2337
2338 if (conv(&neg, &lval, i, 1, data))
2339 break;
2340 } else {
2341 p = buf;
2342 if (!first)
2343 *p++ = '\t';
2344
2345 if (conv(&neg, &lval, i, 0, data))
2346 break;
2347
2348 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2349 len = strlen(buf);
2350 if (len > left)
2351 len = left;
2352 if(copy_to_user(s, buf, len))
2353 return -EFAULT;
2354 left -= len;
2355 s += len;
2356 }
2357 }
2358
2359 if (!write && !first && left) {
2360 if(put_user('\n', s))
2361 return -EFAULT;
2362 left--, s++;
2363 }
2364 if (write) {
2365 while (left) {
2366 char c;
2367 if (get_user(c, s++))
2368 return -EFAULT;
2369 if (!isspace(c))
2370 break;
2371 left--;
2372 }
2373 }
2374 if (write && first)
2375 return -EINVAL;
2376 *lenp -= left;
2377 *ppos += *lenp;
2378 return 0;
2379#undef TMPBUFLEN
2380}
2381
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002382static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002383 void __user *buffer, size_t *lenp, loff_t *ppos,
2384 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2385 int write, void *data),
2386 void *data)
2387{
2388 return __do_proc_dointvec(table->data, table, write, filp,
2389 buffer, lenp, ppos, conv, data);
2390}
2391
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392/**
2393 * proc_dointvec - read a vector of integers
2394 * @table: the sysctl table
2395 * @write: %TRUE if this is a write to the sysctl file
2396 * @filp: the file structure
2397 * @buffer: the user buffer
2398 * @lenp: the size of the user buffer
2399 * @ppos: file position
2400 *
2401 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2402 * values from/to the user buffer, treated as an ASCII string.
2403 *
2404 * Returns 0 on success.
2405 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002406int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 void __user *buffer, size_t *lenp, loff_t *ppos)
2408{
2409 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2410 NULL,NULL);
2411}
2412
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002413/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002414 * Taint values can only be increased
2415 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002416 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002417static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002418 void __user *buffer, size_t *lenp, loff_t *ppos)
2419{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002420 struct ctl_table t;
2421 unsigned long tmptaint = get_taint();
2422 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002423
Bastian Blank91fcd412007-04-23 14:41:14 -07002424 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002425 return -EPERM;
2426
Andi Kleen25ddbb12008-10-15 22:01:41 -07002427 t = *table;
2428 t.data = &tmptaint;
2429 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2430 if (err < 0)
2431 return err;
2432
2433 if (write) {
2434 /*
2435 * Poor man's atomic or. Not worth adding a primitive
2436 * to everyone's atomic.h for this
2437 */
2438 int i;
2439 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2440 if ((tmptaint >> i) & 1)
2441 add_taint(i);
2442 }
2443 }
2444
2445 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002446}
2447
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448struct do_proc_dointvec_minmax_conv_param {
2449 int *min;
2450 int *max;
2451};
2452
2453static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2454 int *valp,
2455 int write, void *data)
2456{
2457 struct do_proc_dointvec_minmax_conv_param *param = data;
2458 if (write) {
2459 int val = *negp ? -*lvalp : *lvalp;
2460 if ((param->min && *param->min > val) ||
2461 (param->max && *param->max < val))
2462 return -EINVAL;
2463 *valp = val;
2464 } else {
2465 int val = *valp;
2466 if (val < 0) {
2467 *negp = -1;
2468 *lvalp = (unsigned long)-val;
2469 } else {
2470 *negp = 0;
2471 *lvalp = (unsigned long)val;
2472 }
2473 }
2474 return 0;
2475}
2476
2477/**
2478 * proc_dointvec_minmax - read a vector of integers with min/max values
2479 * @table: the sysctl table
2480 * @write: %TRUE if this is a write to the sysctl file
2481 * @filp: the file structure
2482 * @buffer: the user buffer
2483 * @lenp: the size of the user buffer
2484 * @ppos: file position
2485 *
2486 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2487 * values from/to the user buffer, treated as an ASCII string.
2488 *
2489 * This routine will ensure the values are within the range specified by
2490 * table->extra1 (min) and table->extra2 (max).
2491 *
2492 * Returns 0 on success.
2493 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002494int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 void __user *buffer, size_t *lenp, loff_t *ppos)
2496{
2497 struct do_proc_dointvec_minmax_conv_param param = {
2498 .min = (int *) table->extra1,
2499 .max = (int *) table->extra2,
2500 };
2501 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2502 do_proc_dointvec_minmax_conv, &param);
2503}
2504
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002505static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 struct file *filp,
2507 void __user *buffer,
2508 size_t *lenp, loff_t *ppos,
2509 unsigned long convmul,
2510 unsigned long convdiv)
2511{
2512#define TMPBUFLEN 21
2513 unsigned long *i, *min, *max, val;
2514 int vleft, first=1, neg;
2515 size_t len, left;
2516 char buf[TMPBUFLEN], *p;
2517 char __user *s = buffer;
2518
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002519 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 (*ppos && !write)) {
2521 *lenp = 0;
2522 return 0;
2523 }
2524
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002525 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 min = (unsigned long *) table->extra1;
2527 max = (unsigned long *) table->extra2;
2528 vleft = table->maxlen / sizeof(unsigned long);
2529 left = *lenp;
2530
2531 for (; left && vleft--; i++, min++, max++, first=0) {
2532 if (write) {
2533 while (left) {
2534 char c;
2535 if (get_user(c, s))
2536 return -EFAULT;
2537 if (!isspace(c))
2538 break;
2539 left--;
2540 s++;
2541 }
2542 if (!left)
2543 break;
2544 neg = 0;
2545 len = left;
2546 if (len > TMPBUFLEN-1)
2547 len = TMPBUFLEN-1;
2548 if (copy_from_user(buf, s, len))
2549 return -EFAULT;
2550 buf[len] = 0;
2551 p = buf;
2552 if (*p == '-' && left > 1) {
2553 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002554 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 }
2556 if (*p < '0' || *p > '9')
2557 break;
2558 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2559 len = p-buf;
2560 if ((len < left) && *p && !isspace(*p))
2561 break;
2562 if (neg)
2563 val = -val;
2564 s += len;
2565 left -= len;
2566
2567 if(neg)
2568 continue;
2569 if ((min && val < *min) || (max && val > *max))
2570 continue;
2571 *i = val;
2572 } else {
2573 p = buf;
2574 if (!first)
2575 *p++ = '\t';
2576 sprintf(p, "%lu", convdiv * (*i) / convmul);
2577 len = strlen(buf);
2578 if (len > left)
2579 len = left;
2580 if(copy_to_user(s, buf, len))
2581 return -EFAULT;
2582 left -= len;
2583 s += len;
2584 }
2585 }
2586
2587 if (!write && !first && left) {
2588 if(put_user('\n', s))
2589 return -EFAULT;
2590 left--, s++;
2591 }
2592 if (write) {
2593 while (left) {
2594 char c;
2595 if (get_user(c, s++))
2596 return -EFAULT;
2597 if (!isspace(c))
2598 break;
2599 left--;
2600 }
2601 }
2602 if (write && first)
2603 return -EINVAL;
2604 *lenp -= left;
2605 *ppos += *lenp;
2606 return 0;
2607#undef TMPBUFLEN
2608}
2609
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002610static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002611 struct file *filp,
2612 void __user *buffer,
2613 size_t *lenp, loff_t *ppos,
2614 unsigned long convmul,
2615 unsigned long convdiv)
2616{
2617 return __do_proc_doulongvec_minmax(table->data, table, write,
2618 filp, buffer, lenp, ppos, convmul, convdiv);
2619}
2620
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621/**
2622 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2623 * @table: the sysctl table
2624 * @write: %TRUE if this is a write to the sysctl file
2625 * @filp: the file structure
2626 * @buffer: the user buffer
2627 * @lenp: the size of the user buffer
2628 * @ppos: file position
2629 *
2630 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2631 * values from/to the user buffer, treated as an ASCII string.
2632 *
2633 * This routine will ensure the values are within the range specified by
2634 * table->extra1 (min) and table->extra2 (max).
2635 *
2636 * Returns 0 on success.
2637 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002638int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 void __user *buffer, size_t *lenp, loff_t *ppos)
2640{
2641 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2642}
2643
2644/**
2645 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2646 * @table: the sysctl table
2647 * @write: %TRUE if this is a write to the sysctl file
2648 * @filp: the file structure
2649 * @buffer: the user buffer
2650 * @lenp: the size of the user buffer
2651 * @ppos: file position
2652 *
2653 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2654 * values from/to the user buffer, treated as an ASCII string. The values
2655 * are treated as milliseconds, and converted to jiffies when they are stored.
2656 *
2657 * This routine will ensure the values are within the range specified by
2658 * table->extra1 (min) and table->extra2 (max).
2659 *
2660 * Returns 0 on success.
2661 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002662int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 struct file *filp,
2664 void __user *buffer,
2665 size_t *lenp, loff_t *ppos)
2666{
2667 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2668 lenp, ppos, HZ, 1000l);
2669}
2670
2671
2672static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2673 int *valp,
2674 int write, void *data)
2675{
2676 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002677 if (*lvalp > LONG_MAX / HZ)
2678 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2680 } else {
2681 int val = *valp;
2682 unsigned long lval;
2683 if (val < 0) {
2684 *negp = -1;
2685 lval = (unsigned long)-val;
2686 } else {
2687 *negp = 0;
2688 lval = (unsigned long)val;
2689 }
2690 *lvalp = lval / HZ;
2691 }
2692 return 0;
2693}
2694
2695static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2696 int *valp,
2697 int write, void *data)
2698{
2699 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002700 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2701 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2703 } else {
2704 int val = *valp;
2705 unsigned long lval;
2706 if (val < 0) {
2707 *negp = -1;
2708 lval = (unsigned long)-val;
2709 } else {
2710 *negp = 0;
2711 lval = (unsigned long)val;
2712 }
2713 *lvalp = jiffies_to_clock_t(lval);
2714 }
2715 return 0;
2716}
2717
2718static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2719 int *valp,
2720 int write, void *data)
2721{
2722 if (write) {
2723 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2724 } else {
2725 int val = *valp;
2726 unsigned long lval;
2727 if (val < 0) {
2728 *negp = -1;
2729 lval = (unsigned long)-val;
2730 } else {
2731 *negp = 0;
2732 lval = (unsigned long)val;
2733 }
2734 *lvalp = jiffies_to_msecs(lval);
2735 }
2736 return 0;
2737}
2738
2739/**
2740 * proc_dointvec_jiffies - read a vector of integers as seconds
2741 * @table: the sysctl table
2742 * @write: %TRUE if this is a write to the sysctl file
2743 * @filp: the file structure
2744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
2746 * @ppos: file position
2747 *
2748 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2749 * values from/to the user buffer, treated as an ASCII string.
2750 * The values read are assumed to be in seconds, and are converted into
2751 * jiffies.
2752 *
2753 * Returns 0 on success.
2754 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002755int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 void __user *buffer, size_t *lenp, loff_t *ppos)
2757{
2758 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2759 do_proc_dointvec_jiffies_conv,NULL);
2760}
2761
2762/**
2763 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2764 * @table: the sysctl table
2765 * @write: %TRUE if this is a write to the sysctl file
2766 * @filp: the file structure
2767 * @buffer: the user buffer
2768 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002769 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 *
2771 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2772 * values from/to the user buffer, treated as an ASCII string.
2773 * The values read are assumed to be in 1/USER_HZ seconds, and
2774 * are converted into jiffies.
2775 *
2776 * Returns 0 on success.
2777 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002778int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 void __user *buffer, size_t *lenp, loff_t *ppos)
2780{
2781 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2782 do_proc_dointvec_userhz_jiffies_conv,NULL);
2783}
2784
2785/**
2786 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2787 * @table: the sysctl table
2788 * @write: %TRUE if this is a write to the sysctl file
2789 * @filp: the file structure
2790 * @buffer: the user buffer
2791 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002792 * @ppos: file position
2793 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 *
2795 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2796 * values from/to the user buffer, treated as an ASCII string.
2797 * The values read are assumed to be in 1/1000 seconds, and
2798 * are converted into jiffies.
2799 *
2800 * Returns 0 on success.
2801 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002802int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 void __user *buffer, size_t *lenp, loff_t *ppos)
2804{
2805 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2806 do_proc_dointvec_ms_jiffies_conv, NULL);
2807}
2808
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002809static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002810 void __user *buffer, size_t *lenp, loff_t *ppos)
2811{
2812 struct pid *new_pid;
2813 pid_t tmp;
2814 int r;
2815
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002816 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002817
2818 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2819 lenp, ppos, NULL, NULL);
2820 if (r || !write)
2821 return r;
2822
2823 new_pid = find_get_pid(tmp);
2824 if (!new_pid)
2825 return -ESRCH;
2826
2827 put_pid(xchg(&cad_pid, new_pid));
2828 return 0;
2829}
2830
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831#else /* CONFIG_PROC_FS */
2832
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002833int proc_dostring(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(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_minmax(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_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_dointvec_userhz_jiffies(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_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 void __user *buffer, size_t *lenp, loff_t *ppos)
2865{
2866 return -ENOSYS;
2867}
2868
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002869int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 void __user *buffer, size_t *lenp, loff_t *ppos)
2871{
2872 return -ENOSYS;
2873}
2874
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002875int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 struct file *filp,
2877 void __user *buffer,
2878 size_t *lenp, loff_t *ppos)
2879{
2880 return -ENOSYS;
2881}
2882
2883
2884#endif /* CONFIG_PROC_FS */
2885
2886
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002887#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888/*
2889 * General sysctl support routines
2890 */
2891
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002892/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002893int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002894 void __user *oldval, size_t __user *oldlenp,
2895 void __user *newval, size_t newlen)
2896{
2897 size_t len;
2898
2899 /* Get out of I don't have a variable */
2900 if (!table->data || !table->maxlen)
2901 return -ENOTDIR;
2902
2903 if (oldval && oldlenp) {
2904 if (get_user(len, oldlenp))
2905 return -EFAULT;
2906 if (len) {
2907 if (len > table->maxlen)
2908 len = table->maxlen;
2909 if (copy_to_user(oldval, table->data, len))
2910 return -EFAULT;
2911 if (put_user(len, oldlenp))
2912 return -EFAULT;
2913 }
2914 }
2915
2916 if (newval && newlen) {
2917 if (newlen > table->maxlen)
2918 newlen = table->maxlen;
2919
2920 if (copy_from_user(table->data, newval, newlen))
2921 return -EFAULT;
2922 }
2923 return 1;
2924}
2925
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002927int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002929 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 if (!table->data || !table->maxlen)
2932 return -ENOTDIR;
2933
2934 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002935 size_t bufsize;
2936 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002938 if (bufsize) {
2939 size_t len = strlen(table->data), copied;
2940
2941 /* This shouldn't trigger for a well-formed sysctl */
2942 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002944
2945 /* Copy up to a max of bufsize-1 bytes of the string */
2946 copied = (len >= bufsize) ? bufsize - 1 : len;
2947
2948 if (copy_to_user(oldval, table->data, copied) ||
2949 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002951 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 return -EFAULT;
2953 }
2954 }
2955 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002956 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 if (len > table->maxlen)
2958 len = table->maxlen;
2959 if(copy_from_user(table->data, newval, len))
2960 return -EFAULT;
2961 if (len == table->maxlen)
2962 len--;
2963 ((char *) table->data)[len] = 0;
2964 }
Yi Yang82c9df82005-12-30 16:37:10 +08002965 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966}
2967
2968/*
2969 * This function makes sure that all of the integers in the vector
2970 * are between the minimum and maximum values given in the arrays
2971 * table->extra1 and table->extra2, respectively.
2972 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002973int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002975 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976{
2977
2978 if (newval && newlen) {
2979 int __user *vec = (int __user *) newval;
2980 int *min = (int *) table->extra1;
2981 int *max = (int *) table->extra2;
2982 size_t length;
2983 int i;
2984
2985 if (newlen % sizeof(int) != 0)
2986 return -EINVAL;
2987
2988 if (!table->extra1 && !table->extra2)
2989 return 0;
2990
2991 if (newlen > table->maxlen)
2992 newlen = table->maxlen;
2993 length = newlen / sizeof(int);
2994
2995 for (i = 0; i < length; i++) {
2996 int value;
2997 if (get_user(value, vec + i))
2998 return -EFAULT;
2999 if (min && value < min[i])
3000 return -EINVAL;
3001 if (max && value > max[i])
3002 return -EINVAL;
3003 }
3004 }
3005 return 0;
3006}
3007
3008/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003009int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003011 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003013 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003015
3016 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003018 if (olen) {
3019 int val;
3020
3021 if (olen < sizeof(int))
3022 return -EINVAL;
3023
3024 val = *(int *)(table->data) / HZ;
3025 if (put_user(val, (int __user *)oldval))
3026 return -EFAULT;
3027 if (put_user(sizeof(int), oldlenp))
3028 return -EFAULT;
3029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 }
3031 if (newval && newlen) {
3032 int new;
3033 if (newlen != sizeof(int))
3034 return -EINVAL;
3035 if (get_user(new, (int __user *)newval))
3036 return -EFAULT;
3037 *(int *)(table->data) = new*HZ;
3038 }
3039 return 1;
3040}
3041
3042/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003043int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003045 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003047 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003049
3050 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003052 if (olen) {
3053 int val;
3054
3055 if (olen < sizeof(int))
3056 return -EINVAL;
3057
3058 val = jiffies_to_msecs(*(int *)(table->data));
3059 if (put_user(val, (int __user *)oldval))
3060 return -EFAULT;
3061 if (put_user(sizeof(int), oldlenp))
3062 return -EFAULT;
3063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 }
3065 if (newval && newlen) {
3066 int new;
3067 if (newlen != sizeof(int))
3068 return -EINVAL;
3069 if (get_user(new, (int __user *)newval))
3070 return -EFAULT;
3071 *(int *)(table->data) = msecs_to_jiffies(new);
3072 }
3073 return 1;
3074}
3075
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003076
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003077
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003078#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
3080
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003081SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003083 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003084 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003085
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003086 if (copy_from_user(&tmp, args, sizeof(tmp)))
3087 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003088
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003089 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003090
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003091 /* If no error reading the parameters then just -ENOSYS ... */
3092 if (!error)
3093 error = -ENOSYS;
3094
3095 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096}
3097
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003098int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003099 void __user *oldval, size_t __user *oldlenp,
3100 void __user *newval, size_t newlen)
3101{
3102 return -ENOSYS;
3103}
3104
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003105int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003107 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108{
3109 return -ENOSYS;
3110}
3111
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003112int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003114 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115{
3116 return -ENOSYS;
3117}
3118
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003119int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003121 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122{
3123 return -ENOSYS;
3124}
3125
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003126int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003128 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129{
3130 return -ENOSYS;
3131}
3132
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003133#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003135static int deprecated_sysctl_warning(struct __sysctl_args *args)
3136{
3137 static int msg_count;
3138 int name[CTL_MAXNAME];
3139 int i;
3140
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003141 /* Check args->nlen. */
3142 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3143 return -ENOTDIR;
3144
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003145 /* Read in the sysctl name for better debug message logging */
3146 for (i = 0; i < args->nlen; i++)
3147 if (get_user(name[i], args->name + i))
3148 return -EFAULT;
3149
3150 /* Ignore accesses to kernel.version */
3151 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3152 return 0;
3153
3154 if (msg_count < 5) {
3155 msg_count++;
3156 printk(KERN_INFO
3157 "warning: process `%s' used the deprecated sysctl "
3158 "system call with ", current->comm);
3159 for (i = 0; i < args->nlen; i++)
3160 printk("%d.", name[i]);
3161 printk("\n");
3162 }
3163 return 0;
3164}
3165
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166/*
3167 * No sense putting this after each symbol definition, twice,
3168 * exception granted :-)
3169 */
3170EXPORT_SYMBOL(proc_dointvec);
3171EXPORT_SYMBOL(proc_dointvec_jiffies);
3172EXPORT_SYMBOL(proc_dointvec_minmax);
3173EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3174EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3175EXPORT_SYMBOL(proc_dostring);
3176EXPORT_SYMBOL(proc_doulongvec_minmax);
3177EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3178EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003179EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180EXPORT_SYMBOL(sysctl_intvec);
3181EXPORT_SYMBOL(sysctl_jiffies);
3182EXPORT_SYMBOL(sysctl_ms_jiffies);
3183EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003184EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185EXPORT_SYMBOL(unregister_sysctl_table);