blob: 1a631ba684a4ee73db8a13a1968265afd92a8fbf [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 */
Jens Axboecb684b52009-09-15 21:53:11 +020094#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +020095extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +020096#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080099#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200101static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700102#endif
103
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700104static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700105static int __maybe_unused one = 1;
106static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800107static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700108static int one_hundred = 100;
109
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700110/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
111static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
114static int maxolduid = 65535;
115static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800116static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118static int ngroups_max = NGROUPS_MAX;
119
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200120#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700122extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124#ifdef CONFIG_CHR_DEV_SG
125extern int sg_big_buff;
126#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
David S. Miller72c57ed2008-09-11 23:29:54 -0700128#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700129#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#endif
131
David S. Miller08714202008-11-16 23:49:24 -0800132#ifdef CONFIG_SPARC64
133extern int sysctl_tsb_ratio;
134#endif
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#ifdef __hppa__
137extern int pwrsw_enabled;
138extern int unaligned_enabled;
139#endif
140
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800141#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#ifdef CONFIG_MATHEMU
143extern int sysctl_ieee_emulation_warnings;
144#endif
145extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700146extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#endif
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#ifdef CONFIG_BSD_PROCESS_ACCT
150extern int acct_parm[];
151#endif
152
Jes Sorensend2b176e2006-02-28 09:42:23 -0800153#ifdef CONFIG_IA64
154extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800155extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800156#endif
157
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700158#ifdef CONFIG_RT_MUTEXES
159extern int max_lock_depth;
160#endif
161
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700162#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700163static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700164 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700165static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800166 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700167#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700168
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700169static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100170static struct ctl_table_root sysctl_table_root;
171static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100172 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100173 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400174 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100175 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400176 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100177};
178static struct ctl_table_root sysctl_table_root = {
179 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400180 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100181};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700183static struct ctl_table kern_table[];
184static struct ctl_table vm_table[];
185static struct ctl_table fs_table[];
186static struct ctl_table debug_table[];
187static struct ctl_table dev_table[];
188extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700189#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700190extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400191#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800192#ifdef CONFIG_EPOLL
193extern struct ctl_table epoll_table[];
194#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
197int sysctl_legacy_va_layout;
198#endif
199
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700200extern int prove_locking;
201extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203/* The default sysctl tables: */
204
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700205static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 {
207 .ctl_name = CTL_KERN,
208 .procname = "kernel",
209 .mode = 0555,
210 .child = kern_table,
211 },
212 {
213 .ctl_name = CTL_VM,
214 .procname = "vm",
215 .mode = 0555,
216 .child = vm_table,
217 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 .ctl_name = CTL_FS,
220 .procname = "fs",
221 .mode = 0555,
222 .child = fs_table,
223 },
224 {
225 .ctl_name = CTL_DEBUG,
226 .procname = "debug",
227 .mode = 0555,
228 .child = debug_table,
229 },
230 {
231 .ctl_name = CTL_DEV,
232 .procname = "dev",
233 .mode = 0555,
234 .child = dev_table,
235 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700236/*
237 * NOTE: do not add new entries to this table unless you have read
238 * Documentation/sysctl/ctl_unnumbered.txt
239 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 { .ctl_name = 0 }
241};
242
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100244static int min_sched_granularity_ns = 100000; /* 100 usecs */
245static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
246static int min_wakeup_granularity_ns; /* 0 usecs */
247static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200248#endif
249
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700250static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200251 {
252 .ctl_name = CTL_UNNUMBERED,
253 .procname = "sched_child_runs_first",
254 .data = &sysctl_sched_child_runs_first,
255 .maxlen = sizeof(unsigned int),
256 .mode = 0644,
257 .proc_handler = &proc_dointvec,
258 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200259#ifdef CONFIG_SCHED_DEBUG
260 {
261 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100262 .procname = "sched_min_granularity_ns",
263 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200264 .maxlen = sizeof(unsigned int),
265 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100266 .proc_handler = &sched_nr_latency_handler,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_sched_granularity_ns,
269 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200270 },
271 {
272 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200273 .procname = "sched_latency_ns",
274 .data = &sysctl_sched_latency,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100277 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200278 .strategy = &sysctl_intvec,
279 .extra1 = &min_sched_granularity_ns,
280 .extra2 = &max_sched_granularity_ns,
281 },
282 {
283 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200284 .procname = "sched_wakeup_granularity_ns",
285 .data = &sysctl_sched_wakeup_granularity,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
288 .proc_handler = &proc_dointvec_minmax,
289 .strategy = &sysctl_intvec,
290 .extra1 = &min_wakeup_granularity_ns,
291 .extra2 = &max_wakeup_granularity_ns,
292 },
293 {
294 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200295 .procname = "sched_shares_ratelimit",
296 .data = &sysctl_sched_shares_ratelimit,
297 .maxlen = sizeof(unsigned int),
298 .mode = 0644,
299 .proc_handler = &proc_dointvec,
300 },
301 {
302 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200303 .procname = "sched_shares_thresh",
304 .data = &sysctl_sched_shares_thresh,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
307 .proc_handler = &proc_dointvec_minmax,
308 .strategy = &sysctl_intvec,
309 .extra1 = &zero,
310 },
311 {
312 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200313 .procname = "sched_features",
314 .data = &sysctl_sched_features,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
317 .proc_handler = &proc_dointvec,
318 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200319 {
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "sched_migration_cost",
322 .data = &sysctl_sched_migration_cost,
323 .maxlen = sizeof(unsigned int),
324 .mode = 0644,
325 .proc_handler = &proc_dointvec,
326 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100327 {
328 .ctl_name = CTL_UNNUMBERED,
329 .procname = "sched_nr_migrate",
330 .data = &sysctl_sched_nr_migrate,
331 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100332 .mode = 0644,
333 .proc_handler = &proc_dointvec,
334 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530335 {
336 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200337 .procname = "sched_time_avg",
338 .data = &sysctl_sched_time_avg,
339 .maxlen = sizeof(unsigned int),
340 .mode = 0644,
341 .proc_handler = &proc_dointvec,
342 },
343 {
344 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530345 .procname = "timer_migration",
346 .data = &sysctl_timer_migration,
347 .maxlen = sizeof(unsigned int),
348 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530349 .proc_handler = &proc_dointvec_minmax,
350 .strategy = &sysctl_intvec,
351 .extra1 = &zero,
352 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530353 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200354#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200355 {
356 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100357 .procname = "sched_rt_period_us",
358 .data = &sysctl_sched_rt_period,
359 .maxlen = sizeof(unsigned int),
360 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200361 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100362 },
363 {
364 .ctl_name = CTL_UNNUMBERED,
365 .procname = "sched_rt_runtime_us",
366 .data = &sysctl_sched_rt_runtime,
367 .maxlen = sizeof(int),
368 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200369 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100370 },
371 {
372 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200373 .procname = "sched_compat_yield",
374 .data = &sysctl_sched_compat_yield,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = &proc_dointvec,
378 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700379#ifdef CONFIG_PROVE_LOCKING
380 {
381 .ctl_name = CTL_UNNUMBERED,
382 .procname = "prove_locking",
383 .data = &prove_locking,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = &proc_dointvec,
387 },
388#endif
389#ifdef CONFIG_LOCK_STAT
390 {
391 .ctl_name = CTL_UNNUMBERED,
392 .procname = "lock_stat",
393 .data = &lock_stat,
394 .maxlen = sizeof(int),
395 .mode = 0644,
396 .proc_handler = &proc_dointvec,
397 },
398#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .ctl_name = KERN_PANIC,
401 .procname = "panic",
402 .data = &panic_timeout,
403 .maxlen = sizeof(int),
404 .mode = 0644,
405 .proc_handler = &proc_dointvec,
406 },
407 {
408 .ctl_name = KERN_CORE_USES_PID,
409 .procname = "core_uses_pid",
410 .data = &core_uses_pid,
411 .maxlen = sizeof(int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
414 },
415 {
416 .ctl_name = KERN_CORE_PATTERN,
417 .procname = "core_pattern",
418 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700419 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 .mode = 0644,
421 .proc_handler = &proc_dostring,
422 .strategy = &sysctl_string,
423 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800424#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700427 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800428 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700429 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800431#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100432#ifdef CONFIG_LATENCYTOP
433 {
434 .procname = "latencytop",
435 .data = &latencytop_enabled,
436 .maxlen = sizeof(int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
439 },
440#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#ifdef CONFIG_BLK_DEV_INITRD
442 {
443 .ctl_name = KERN_REALROOTDEV,
444 .procname = "real-root-dev",
445 .data = &real_root_dev,
446 .maxlen = sizeof(int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
449 },
450#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700451 {
452 .ctl_name = CTL_UNNUMBERED,
453 .procname = "print-fatal-signals",
454 .data = &print_fatal_signals,
455 .maxlen = sizeof(int),
456 .mode = 0644,
457 .proc_handler = &proc_dointvec,
458 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700459#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 {
461 .ctl_name = KERN_SPARC_REBOOT,
462 .procname = "reboot-cmd",
463 .data = reboot_command,
464 .maxlen = 256,
465 .mode = 0644,
466 .proc_handler = &proc_dostring,
467 .strategy = &sysctl_string,
468 },
469 {
470 .ctl_name = KERN_SPARC_STOP_A,
471 .procname = "stop-a",
472 .data = &stop_a_enabled,
473 .maxlen = sizeof (int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec,
476 },
477 {
478 .ctl_name = KERN_SPARC_SCONS_PWROFF,
479 .procname = "scons-poweroff",
480 .data = &scons_pwroff,
481 .maxlen = sizeof (int),
482 .mode = 0644,
483 .proc_handler = &proc_dointvec,
484 },
485#endif
David S. Miller08714202008-11-16 23:49:24 -0800486#ifdef CONFIG_SPARC64
487 {
488 .ctl_name = CTL_UNNUMBERED,
489 .procname = "tsb-ratio",
490 .data = &sysctl_tsb_ratio,
491 .maxlen = sizeof (int),
492 .mode = 0644,
493 .proc_handler = &proc_dointvec,
494 },
495#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#ifdef __hppa__
497 {
498 .ctl_name = KERN_HPPA_PWRSW,
499 .procname = "soft-power",
500 .data = &pwrsw_enabled,
501 .maxlen = sizeof (int),
502 .mode = 0644,
503 .proc_handler = &proc_dointvec,
504 },
505 {
506 .ctl_name = KERN_HPPA_UNALIGNED,
507 .procname = "unaligned-trap",
508 .data = &unaligned_enabled,
509 .maxlen = sizeof (int),
510 .mode = 0644,
511 .proc_handler = &proc_dointvec,
512 },
513#endif
514 {
515 .ctl_name = KERN_CTLALTDEL,
516 .procname = "ctrl-alt-del",
517 .data = &C_A_D,
518 .maxlen = sizeof(int),
519 .mode = 0644,
520 .proc_handler = &proc_dointvec,
521 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400522#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200523 {
524 .ctl_name = CTL_UNNUMBERED,
525 .procname = "ftrace_enabled",
526 .data = &ftrace_enabled,
527 .maxlen = sizeof(int),
528 .mode = 0644,
529 .proc_handler = &ftrace_enable_sysctl,
530 },
531#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500532#ifdef CONFIG_STACK_TRACER
533 {
534 .ctl_name = CTL_UNNUMBERED,
535 .procname = "stack_tracer_enabled",
536 .data = &stack_tracer_enabled,
537 .maxlen = sizeof(int),
538 .mode = 0644,
539 .proc_handler = &stack_trace_sysctl,
540 },
541#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400542#ifdef CONFIG_TRACING
543 {
544 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100545 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400546 .data = &ftrace_dump_on_oops,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = &proc_dointvec,
550 },
551#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200552#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 {
554 .ctl_name = KERN_MODPROBE,
555 .procname = "modprobe",
556 .data = &modprobe_path,
557 .maxlen = KMOD_PATH_LEN,
558 .mode = 0644,
559 .proc_handler = &proc_dostring,
560 .strategy = &sysctl_string,
561 },
Kees Cook3d433212009-04-02 15:49:29 -0700562 {
563 .ctl_name = CTL_UNNUMBERED,
564 .procname = "modules_disabled",
565 .data = &modules_disabled,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 /* only handle a transition from default "0" to "1" */
569 .proc_handler = &proc_dointvec_minmax,
570 .extra1 = &one,
571 .extra2 = &one,
572 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700574#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 {
576 .ctl_name = KERN_HOTPLUG,
577 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100578 .data = &uevent_helper,
579 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .mode = 0644,
581 .proc_handler = &proc_dostring,
582 .strategy = &sysctl_string,
583 },
584#endif
585#ifdef CONFIG_CHR_DEV_SG
586 {
587 .ctl_name = KERN_SG_BIG_BUFF,
588 .procname = "sg-big-buff",
589 .data = &sg_big_buff,
590 .maxlen = sizeof (int),
591 .mode = 0444,
592 .proc_handler = &proc_dointvec,
593 },
594#endif
595#ifdef CONFIG_BSD_PROCESS_ACCT
596 {
597 .ctl_name = KERN_ACCT,
598 .procname = "acct",
599 .data = &acct_parm,
600 .maxlen = 3*sizeof(int),
601 .mode = 0644,
602 .proc_handler = &proc_dointvec,
603 },
604#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#ifdef CONFIG_MAGIC_SYSRQ
606 {
607 .ctl_name = KERN_SYSRQ,
608 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800609 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 .maxlen = sizeof (int),
611 .mode = 0644,
612 .proc_handler = &proc_dointvec,
613 },
614#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700615#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700618 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .maxlen = sizeof (int),
620 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700621 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700623#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 {
625 .ctl_name = KERN_MAX_THREADS,
626 .procname = "threads-max",
627 .data = &max_threads,
628 .maxlen = sizeof(int),
629 .mode = 0644,
630 .proc_handler = &proc_dointvec,
631 },
632 {
633 .ctl_name = KERN_RANDOM,
634 .procname = "random",
635 .mode = 0555,
636 .child = random_table,
637 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 {
639 .ctl_name = KERN_OVERFLOWUID,
640 .procname = "overflowuid",
641 .data = &overflowuid,
642 .maxlen = sizeof(int),
643 .mode = 0644,
644 .proc_handler = &proc_dointvec_minmax,
645 .strategy = &sysctl_intvec,
646 .extra1 = &minolduid,
647 .extra2 = &maxolduid,
648 },
649 {
650 .ctl_name = KERN_OVERFLOWGID,
651 .procname = "overflowgid",
652 .data = &overflowgid,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec_minmax,
656 .strategy = &sysctl_intvec,
657 .extra1 = &minolduid,
658 .extra2 = &maxolduid,
659 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800660#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#ifdef CONFIG_MATHEMU
662 {
663 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
664 .procname = "ieee_emulation_warnings",
665 .data = &sysctl_ieee_emulation_warnings,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec,
669 },
670#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 {
672 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
673 .procname = "userprocess_debug",
674 .data = &sysctl_userprocess_debug,
675 .maxlen = sizeof(int),
676 .mode = 0644,
677 .proc_handler = &proc_dointvec,
678 },
679#endif
680 {
681 .ctl_name = KERN_PIDMAX,
682 .procname = "pid_max",
683 .data = &pid_max,
684 .maxlen = sizeof (int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec_minmax,
687 .strategy = sysctl_intvec,
688 .extra1 = &pid_max_min,
689 .extra2 = &pid_max_max,
690 },
691 {
692 .ctl_name = KERN_PANIC_ON_OOPS,
693 .procname = "panic_on_oops",
694 .data = &panic_on_oops,
695 .maxlen = sizeof(int),
696 .mode = 0644,
697 .proc_handler = &proc_dointvec,
698 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800699#if defined CONFIG_PRINTK
700 {
701 .ctl_name = KERN_PRINTK,
702 .procname = "printk",
703 .data = &console_loglevel,
704 .maxlen = 4*sizeof(int),
705 .mode = 0644,
706 .proc_handler = &proc_dointvec,
707 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 {
709 .ctl_name = KERN_PRINTK_RATELIMIT,
710 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700711 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 .maxlen = sizeof(int),
713 .mode = 0644,
714 .proc_handler = &proc_dointvec_jiffies,
715 .strategy = &sysctl_jiffies,
716 },
717 {
718 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
719 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700720 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec,
724 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800725#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 {
727 .ctl_name = KERN_NGROUPS_MAX,
728 .procname = "ngroups_max",
729 .data = &ngroups_max,
730 .maxlen = sizeof (int),
731 .mode = 0444,
732 .proc_handler = &proc_dointvec,
733 },
734#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
735 {
736 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
737 .procname = "unknown_nmi_panic",
738 .data = &unknown_nmi_panic,
739 .maxlen = sizeof (int),
740 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200741 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 },
Don Zickus407984f2006-09-26 10:52:27 +0200743 {
Don Zickus407984f2006-09-26 10:52:27 +0200744 .procname = "nmi_watchdog",
745 .data = &nmi_watchdog_enabled,
746 .maxlen = sizeof (int),
747 .mode = 0644,
748 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 },
750#endif
751#if defined(CONFIG_X86)
752 {
Don Zickus8da5add2006-09-26 10:52:27 +0200753 .ctl_name = KERN_PANIC_ON_NMI,
754 .procname = "panic_on_unrecovered_nmi",
755 .data = &panic_on_unrecovered_nmi,
756 .maxlen = sizeof(int),
757 .mode = 0644,
758 .proc_handler = &proc_dointvec,
759 },
760 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700761 .ctl_name = CTL_UNNUMBERED,
762 .procname = "panic_on_io_nmi",
763 .data = &panic_on_io_nmi,
764 .maxlen = sizeof(int),
765 .mode = 0644,
766 .proc_handler = &proc_dointvec,
767 },
768 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .ctl_name = KERN_BOOTLOADER_TYPE,
770 .procname = "bootloader_type",
771 .data = &bootloader_type,
772 .maxlen = sizeof (int),
773 .mode = 0444,
774 .proc_handler = &proc_dointvec,
775 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100776 {
777 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700778 .procname = "bootloader_version",
779 .data = &bootloader_version,
780 .maxlen = sizeof (int),
781 .mode = 0444,
782 .proc_handler = &proc_dointvec,
783 },
784 {
785 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100786 .procname = "kstack_depth_to_print",
787 .data = &kstack_depth_to_print,
788 .maxlen = sizeof(int),
789 .mode = 0644,
790 .proc_handler = &proc_dointvec,
791 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100792 {
793 .ctl_name = CTL_UNNUMBERED,
794 .procname = "io_delay_type",
795 .data = &io_delay_type,
796 .maxlen = sizeof(int),
797 .mode = 0644,
798 .proc_handler = &proc_dointvec,
799 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800801#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 {
803 .ctl_name = KERN_RANDOMIZE,
804 .procname = "randomize_va_space",
805 .data = &randomize_va_space,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = &proc_dointvec,
809 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800810#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800811#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700812 {
813 .ctl_name = KERN_SPIN_RETRY,
814 .procname = "spin_retry",
815 .data = &spin_retry,
816 .maxlen = sizeof (int),
817 .mode = 0644,
818 .proc_handler = &proc_dointvec,
819 },
820#endif
Len Brown673d5b42007-07-28 03:33:16 -0400821#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800822 {
Pavel Machekc255d842006-02-20 18:27:58 -0800823 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700824 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800825 .maxlen = sizeof (unsigned long),
826 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800827 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800828 },
829#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800830#ifdef CONFIG_IA64
831 {
832 .ctl_name = KERN_IA64_UNALIGNED,
833 .procname = "ignore-unaligned-usertrap",
834 .data = &no_unaligned_warning,
835 .maxlen = sizeof (int),
836 .mode = 0644,
837 .proc_handler = &proc_dointvec,
838 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800839 {
840 .ctl_name = CTL_UNNUMBERED,
841 .procname = "unaligned-dump-stack",
842 .data = &unaligned_dump_stack,
843 .maxlen = sizeof (int),
844 .mode = 0644,
845 .proc_handler = &proc_dointvec,
846 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800847#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700848#ifdef CONFIG_DETECT_SOFTLOCKUP
849 {
850 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200851 .procname = "softlockup_panic",
852 .data = &softlockup_panic,
853 .maxlen = sizeof(int),
854 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700855 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200856 .strategy = &sysctl_intvec,
857 .extra1 = &zero,
858 .extra2 = &one,
859 },
860 {
861 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700862 .procname = "softlockup_thresh",
863 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200864 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700865 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800866 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700867 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200868 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700869 .extra2 = &sixty,
870 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800871#endif
872#ifdef CONFIG_DETECT_HUNG_TASK
873 {
874 .ctl_name = CTL_UNNUMBERED,
875 .procname = "hung_task_panic",
876 .data = &sysctl_hung_task_panic,
877 .maxlen = sizeof(int),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec_minmax,
880 .strategy = &sysctl_intvec,
881 .extra1 = &zero,
882 .extra2 = &one,
883 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100884 {
885 .ctl_name = CTL_UNNUMBERED,
886 .procname = "hung_task_check_count",
887 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100888 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100889 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100890 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100891 .strategy = &sysctl_intvec,
892 },
893 {
894 .ctl_name = CTL_UNNUMBERED,
895 .procname = "hung_task_timeout_secs",
896 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100897 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100898 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800899 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100900 .strategy = &sysctl_intvec,
901 },
902 {
903 .ctl_name = CTL_UNNUMBERED,
904 .procname = "hung_task_warnings",
905 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100906 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100907 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100908 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100909 .strategy = &sysctl_intvec,
910 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700911#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200912#ifdef CONFIG_COMPAT
913 {
914 .ctl_name = KERN_COMPAT_LOG,
915 .procname = "compat-log",
916 .data = &compat_log,
917 .maxlen = sizeof (int),
918 .mode = 0644,
919 .proc_handler = &proc_dointvec,
920 },
921#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700922#ifdef CONFIG_RT_MUTEXES
923 {
924 .ctl_name = KERN_MAX_LOCK_DEPTH,
925 .procname = "max_lock_depth",
926 .data = &max_lock_depth,
927 .maxlen = sizeof(int),
928 .mode = 0644,
929 .proc_handler = &proc_dointvec,
930 },
931#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700932 {
933 .ctl_name = CTL_UNNUMBERED,
934 .procname = "poweroff_cmd",
935 .data = &poweroff_cmd,
936 .maxlen = POWEROFF_CMD_PATH_LEN,
937 .mode = 0644,
938 .proc_handler = &proc_dostring,
939 .strategy = &sysctl_string,
940 },
David Howells0b77f5b2008-04-29 01:01:32 -0700941#ifdef CONFIG_KEYS
942 {
943 .ctl_name = CTL_UNNUMBERED,
944 .procname = "keys",
945 .mode = 0555,
946 .child = key_sysctls,
947 },
948#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700949#ifdef CONFIG_RCU_TORTURE_TEST
950 {
951 .ctl_name = CTL_UNNUMBERED,
952 .procname = "rcutorture_runnable",
953 .data = &rcutorture_runnable,
954 .maxlen = sizeof(int),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec,
957 },
958#endif
David Howells12e22c52009-04-03 16:42:35 +0100959#ifdef CONFIG_SLOW_WORK
960 {
961 .ctl_name = CTL_UNNUMBERED,
962 .procname = "slow-work",
963 .mode = 0555,
964 .child = slow_work_sysctls,
965 },
966#endif
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200967#ifdef CONFIG_PERF_COUNTERS
968 {
969 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra07647712009-06-11 11:18:36 +0200970 .procname = "perf_counter_paranoid",
971 .data = &sysctl_perf_counter_paranoid,
972 .maxlen = sizeof(sysctl_perf_counter_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200973 .mode = 0644,
974 .proc_handler = &proc_dointvec,
975 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200976 {
977 .ctl_name = CTL_UNNUMBERED,
978 .procname = "perf_counter_mlock_kb",
979 .data = &sysctl_perf_counter_mlock,
980 .maxlen = sizeof(sysctl_perf_counter_mlock),
981 .mode = 0644,
982 .proc_handler = &proc_dointvec,
983 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200984 {
985 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstradf58ab22009-06-11 11:25:05 +0200986 .procname = "perf_counter_max_sample_rate",
987 .data = &sysctl_perf_counter_sample_rate,
988 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200989 .mode = 0644,
990 .proc_handler = &proc_dointvec,
991 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200992#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200993#ifdef CONFIG_KMEMCHECK
994 {
995 .ctl_name = CTL_UNNUMBERED,
996 .procname = "kmemcheck",
997 .data = &kmemcheck_enabled,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = &proc_dointvec,
1001 },
1002#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001003#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001004 {
1005 .ctl_name = CTL_UNNUMBERED,
1006 .procname = "blk_iopoll",
1007 .data = &blk_iopoll_enabled,
1008 .maxlen = sizeof(int),
1009 .mode = 0644,
1010 .proc_handler = &proc_dointvec,
1011 },
Jens Axboecb684b52009-09-15 21:53:11 +02001012#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001013/*
1014 * NOTE: do not add new entries to this table unless you have read
1015 * Documentation/sysctl/ctl_unnumbered.txt
1016 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 { .ctl_name = 0 }
1018};
1019
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001020static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 {
1022 .ctl_name = VM_OVERCOMMIT_MEMORY,
1023 .procname = "overcommit_memory",
1024 .data = &sysctl_overcommit_memory,
1025 .maxlen = sizeof(sysctl_overcommit_memory),
1026 .mode = 0644,
1027 .proc_handler = &proc_dointvec,
1028 },
1029 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001030 .ctl_name = VM_PANIC_ON_OOM,
1031 .procname = "panic_on_oom",
1032 .data = &sysctl_panic_on_oom,
1033 .maxlen = sizeof(sysctl_panic_on_oom),
1034 .mode = 0644,
1035 .proc_handler = &proc_dointvec,
1036 },
1037 {
David Rientjesfe071d72007-10-16 23:25:56 -07001038 .ctl_name = CTL_UNNUMBERED,
1039 .procname = "oom_kill_allocating_task",
1040 .data = &sysctl_oom_kill_allocating_task,
1041 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1042 .mode = 0644,
1043 .proc_handler = &proc_dointvec,
1044 },
1045 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001046 .ctl_name = CTL_UNNUMBERED,
1047 .procname = "oom_dump_tasks",
1048 .data = &sysctl_oom_dump_tasks,
1049 .maxlen = sizeof(sysctl_oom_dump_tasks),
1050 .mode = 0644,
1051 .proc_handler = &proc_dointvec,
1052 },
1053 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 .ctl_name = VM_OVERCOMMIT_RATIO,
1055 .procname = "overcommit_ratio",
1056 .data = &sysctl_overcommit_ratio,
1057 .maxlen = sizeof(sysctl_overcommit_ratio),
1058 .mode = 0644,
1059 .proc_handler = &proc_dointvec,
1060 },
1061 {
1062 .ctl_name = VM_PAGE_CLUSTER,
1063 .procname = "page-cluster",
1064 .data = &page_cluster,
1065 .maxlen = sizeof(int),
1066 .mode = 0644,
1067 .proc_handler = &proc_dointvec,
1068 },
1069 {
1070 .ctl_name = VM_DIRTY_BACKGROUND,
1071 .procname = "dirty_background_ratio",
1072 .data = &dirty_background_ratio,
1073 .maxlen = sizeof(dirty_background_ratio),
1074 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001075 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .strategy = &sysctl_intvec,
1077 .extra1 = &zero,
1078 .extra2 = &one_hundred,
1079 },
1080 {
David Rientjes2da02992009-01-06 14:39:31 -08001081 .ctl_name = CTL_UNNUMBERED,
1082 .procname = "dirty_background_bytes",
1083 .data = &dirty_background_bytes,
1084 .maxlen = sizeof(dirty_background_bytes),
1085 .mode = 0644,
1086 .proc_handler = &dirty_background_bytes_handler,
1087 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001088 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001089 },
1090 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 .ctl_name = VM_DIRTY_RATIO,
1092 .procname = "dirty_ratio",
1093 .data = &vm_dirty_ratio,
1094 .maxlen = sizeof(vm_dirty_ratio),
1095 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001096 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 .strategy = &sysctl_intvec,
1098 .extra1 = &zero,
1099 .extra2 = &one_hundred,
1100 },
1101 {
David Rientjes2da02992009-01-06 14:39:31 -08001102 .ctl_name = CTL_UNNUMBERED,
1103 .procname = "dirty_bytes",
1104 .data = &vm_dirty_bytes,
1105 .maxlen = sizeof(vm_dirty_bytes),
1106 .mode = 0644,
1107 .proc_handler = &dirty_bytes_handler,
1108 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001109 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001110 },
1111 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001113 .data = &dirty_writeback_interval,
1114 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 .mode = 0644,
1116 .proc_handler = &dirty_writeback_centisecs_handler,
1117 },
1118 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001120 .data = &dirty_expire_interval,
1121 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001123 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 },
1125 {
1126 .ctl_name = VM_NR_PDFLUSH_THREADS,
1127 .procname = "nr_pdflush_threads",
1128 .data = &nr_pdflush_threads,
1129 .maxlen = sizeof nr_pdflush_threads,
1130 .mode = 0444 /* read-only*/,
1131 .proc_handler = &proc_dointvec,
1132 },
1133 {
1134 .ctl_name = VM_SWAPPINESS,
1135 .procname = "swappiness",
1136 .data = &vm_swappiness,
1137 .maxlen = sizeof(vm_swappiness),
1138 .mode = 0644,
1139 .proc_handler = &proc_dointvec_minmax,
1140 .strategy = &sysctl_intvec,
1141 .extra1 = &zero,
1142 .extra2 = &one_hundred,
1143 },
1144#ifdef CONFIG_HUGETLB_PAGE
1145 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001147 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 .maxlen = sizeof(unsigned long),
1149 .mode = 0644,
1150 .proc_handler = &hugetlb_sysctl_handler,
1151 .extra1 = (void *)&hugetlb_zero,
1152 .extra2 = (void *)&hugetlb_infinity,
1153 },
1154 {
1155 .ctl_name = VM_HUGETLB_GROUP,
1156 .procname = "hugetlb_shm_group",
1157 .data = &sysctl_hugetlb_shm_group,
1158 .maxlen = sizeof(gid_t),
1159 .mode = 0644,
1160 .proc_handler = &proc_dointvec,
1161 },
Mel Gorman396faf02007-07-17 04:03:13 -07001162 {
1163 .ctl_name = CTL_UNNUMBERED,
1164 .procname = "hugepages_treat_as_movable",
1165 .data = &hugepages_treat_as_movable,
1166 .maxlen = sizeof(int),
1167 .mode = 0644,
1168 .proc_handler = &hugetlb_treat_movable_handler,
1169 },
Adam Litke54f9f802007-10-16 01:26:20 -07001170 {
1171 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001172 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001173 .data = NULL,
1174 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001175 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001176 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001177 .extra1 = (void *)&hugetlb_zero,
1178 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001179 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180#endif
1181 {
1182 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1183 .procname = "lowmem_reserve_ratio",
1184 .data = &sysctl_lowmem_reserve_ratio,
1185 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1186 .mode = 0644,
1187 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1188 .strategy = &sysctl_intvec,
1189 },
1190 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001191 .ctl_name = VM_DROP_PAGECACHE,
1192 .procname = "drop_caches",
1193 .data = &sysctl_drop_caches,
1194 .maxlen = sizeof(int),
1195 .mode = 0644,
1196 .proc_handler = drop_caches_sysctl_handler,
1197 .strategy = &sysctl_intvec,
1198 },
1199 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 .ctl_name = VM_MIN_FREE_KBYTES,
1201 .procname = "min_free_kbytes",
1202 .data = &min_free_kbytes,
1203 .maxlen = sizeof(min_free_kbytes),
1204 .mode = 0644,
1205 .proc_handler = &min_free_kbytes_sysctl_handler,
1206 .strategy = &sysctl_intvec,
1207 .extra1 = &zero,
1208 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001209 {
1210 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1211 .procname = "percpu_pagelist_fraction",
1212 .data = &percpu_pagelist_fraction,
1213 .maxlen = sizeof(percpu_pagelist_fraction),
1214 .mode = 0644,
1215 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1216 .strategy = &sysctl_intvec,
1217 .extra1 = &min_percpu_pagelist_fract,
1218 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219#ifdef CONFIG_MMU
1220 {
1221 .ctl_name = VM_MAX_MAP_COUNT,
1222 .procname = "max_map_count",
1223 .data = &sysctl_max_map_count,
1224 .maxlen = sizeof(sysctl_max_map_count),
1225 .mode = 0644,
1226 .proc_handler = &proc_dointvec
1227 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001228#else
1229 {
1230 .ctl_name = CTL_UNNUMBERED,
1231 .procname = "nr_trim_pages",
1232 .data = &sysctl_nr_trim_pages,
1233 .maxlen = sizeof(sysctl_nr_trim_pages),
1234 .mode = 0644,
1235 .proc_handler = &proc_dointvec_minmax,
1236 .strategy = &sysctl_intvec,
1237 .extra1 = &zero,
1238 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239#endif
1240 {
1241 .ctl_name = VM_LAPTOP_MODE,
1242 .procname = "laptop_mode",
1243 .data = &laptop_mode,
1244 .maxlen = sizeof(laptop_mode),
1245 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001246 .proc_handler = &proc_dointvec_jiffies,
1247 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 },
1249 {
1250 .ctl_name = VM_BLOCK_DUMP,
1251 .procname = "block_dump",
1252 .data = &block_dump,
1253 .maxlen = sizeof(block_dump),
1254 .mode = 0644,
1255 .proc_handler = &proc_dointvec,
1256 .strategy = &sysctl_intvec,
1257 .extra1 = &zero,
1258 },
1259 {
1260 .ctl_name = VM_VFS_CACHE_PRESSURE,
1261 .procname = "vfs_cache_pressure",
1262 .data = &sysctl_vfs_cache_pressure,
1263 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1264 .mode = 0644,
1265 .proc_handler = &proc_dointvec,
1266 .strategy = &sysctl_intvec,
1267 .extra1 = &zero,
1268 },
1269#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1270 {
1271 .ctl_name = VM_LEGACY_VA_LAYOUT,
1272 .procname = "legacy_va_layout",
1273 .data = &sysctl_legacy_va_layout,
1274 .maxlen = sizeof(sysctl_legacy_va_layout),
1275 .mode = 0644,
1276 .proc_handler = &proc_dointvec,
1277 .strategy = &sysctl_intvec,
1278 .extra1 = &zero,
1279 },
1280#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001281#ifdef CONFIG_NUMA
1282 {
1283 .ctl_name = VM_ZONE_RECLAIM_MODE,
1284 .procname = "zone_reclaim_mode",
1285 .data = &zone_reclaim_mode,
1286 .maxlen = sizeof(zone_reclaim_mode),
1287 .mode = 0644,
1288 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001289 .strategy = &sysctl_intvec,
1290 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001291 },
Christoph Lameter96146342006-07-03 00:24:13 -07001292 {
1293 .ctl_name = VM_MIN_UNMAPPED,
1294 .procname = "min_unmapped_ratio",
1295 .data = &sysctl_min_unmapped_ratio,
1296 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1297 .mode = 0644,
1298 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1299 .strategy = &sysctl_intvec,
1300 .extra1 = &zero,
1301 .extra2 = &one_hundred,
1302 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001303 {
1304 .ctl_name = VM_MIN_SLAB,
1305 .procname = "min_slab_ratio",
1306 .data = &sysctl_min_slab_ratio,
1307 .maxlen = sizeof(sysctl_min_slab_ratio),
1308 .mode = 0644,
1309 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1310 .strategy = &sysctl_intvec,
1311 .extra1 = &zero,
1312 .extra2 = &one_hundred,
1313 },
Christoph Lameter17436602006-01-18 17:42:32 -08001314#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001315#ifdef CONFIG_SMP
1316 {
1317 .ctl_name = CTL_UNNUMBERED,
1318 .procname = "stat_interval",
1319 .data = &sysctl_stat_interval,
1320 .maxlen = sizeof(sysctl_stat_interval),
1321 .mode = 0644,
1322 .proc_handler = &proc_dointvec_jiffies,
1323 .strategy = &sysctl_jiffies,
1324 },
1325#endif
Eric Parised032182007-06-28 15:55:21 -04001326 {
1327 .ctl_name = CTL_UNNUMBERED,
1328 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001329 .data = &dac_mmap_min_addr,
1330 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001331 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001332 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001333 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001334#ifdef CONFIG_NUMA
1335 {
1336 .ctl_name = CTL_UNNUMBERED,
1337 .procname = "numa_zonelist_order",
1338 .data = &numa_zonelist_order,
1339 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1340 .mode = 0644,
1341 .proc_handler = &numa_zonelist_order_handler,
1342 .strategy = &sysctl_string,
1343 },
1344#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001345#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001346 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001347 {
1348 .ctl_name = VM_VDSO_ENABLED,
1349 .procname = "vdso_enabled",
1350 .data = &vdso_enabled,
1351 .maxlen = sizeof(vdso_enabled),
1352 .mode = 0644,
1353 .proc_handler = &proc_dointvec,
1354 .strategy = &sysctl_intvec,
1355 .extra1 = &zero,
1356 },
1357#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001358#ifdef CONFIG_HIGHMEM
1359 {
1360 .ctl_name = CTL_UNNUMBERED,
1361 .procname = "highmem_is_dirtyable",
1362 .data = &vm_highmem_is_dirtyable,
1363 .maxlen = sizeof(vm_highmem_is_dirtyable),
1364 .mode = 0644,
1365 .proc_handler = &proc_dointvec_minmax,
1366 .strategy = &sysctl_intvec,
1367 .extra1 = &zero,
1368 .extra2 = &one,
1369 },
1370#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001371 {
1372 .ctl_name = CTL_UNNUMBERED,
1373 .procname = "scan_unevictable_pages",
1374 .data = &scan_unevictable_pages,
1375 .maxlen = sizeof(scan_unevictable_pages),
1376 .mode = 0644,
1377 .proc_handler = &scan_unevictable_handler,
1378 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001379/*
1380 * NOTE: do not add new entries to this table unless you have read
1381 * Documentation/sysctl/ctl_unnumbered.txt
1382 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 { .ctl_name = 0 }
1384};
1385
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001386#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001387static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001388 { .ctl_name = 0 }
1389};
1390#endif
1391
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001392static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 {
1394 .ctl_name = FS_NRINODE,
1395 .procname = "inode-nr",
1396 .data = &inodes_stat,
1397 .maxlen = 2*sizeof(int),
1398 .mode = 0444,
1399 .proc_handler = &proc_dointvec,
1400 },
1401 {
1402 .ctl_name = FS_STATINODE,
1403 .procname = "inode-state",
1404 .data = &inodes_stat,
1405 .maxlen = 7*sizeof(int),
1406 .mode = 0444,
1407 .proc_handler = &proc_dointvec,
1408 },
1409 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 .procname = "file-nr",
1411 .data = &files_stat,
1412 .maxlen = 3*sizeof(int),
1413 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001414 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 },
1416 {
1417 .ctl_name = FS_MAXFILE,
1418 .procname = "file-max",
1419 .data = &files_stat.max_files,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
1422 .proc_handler = &proc_dointvec,
1423 },
1424 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001425 .ctl_name = CTL_UNNUMBERED,
1426 .procname = "nr_open",
1427 .data = &sysctl_nr_open,
1428 .maxlen = sizeof(int),
1429 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001430 .proc_handler = &proc_dointvec_minmax,
1431 .extra1 = &sysctl_nr_open_min,
1432 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001433 },
1434 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 .ctl_name = FS_DENTRY,
1436 .procname = "dentry-state",
1437 .data = &dentry_stat,
1438 .maxlen = 6*sizeof(int),
1439 .mode = 0444,
1440 .proc_handler = &proc_dointvec,
1441 },
1442 {
1443 .ctl_name = FS_OVERFLOWUID,
1444 .procname = "overflowuid",
1445 .data = &fs_overflowuid,
1446 .maxlen = sizeof(int),
1447 .mode = 0644,
1448 .proc_handler = &proc_dointvec_minmax,
1449 .strategy = &sysctl_intvec,
1450 .extra1 = &minolduid,
1451 .extra2 = &maxolduid,
1452 },
1453 {
1454 .ctl_name = FS_OVERFLOWGID,
1455 .procname = "overflowgid",
1456 .data = &fs_overflowgid,
1457 .maxlen = sizeof(int),
1458 .mode = 0644,
1459 .proc_handler = &proc_dointvec_minmax,
1460 .strategy = &sysctl_intvec,
1461 .extra1 = &minolduid,
1462 .extra2 = &maxolduid,
1463 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001464#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 {
1466 .ctl_name = FS_LEASES,
1467 .procname = "leases-enable",
1468 .data = &leases_enable,
1469 .maxlen = sizeof(int),
1470 .mode = 0644,
1471 .proc_handler = &proc_dointvec,
1472 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001473#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474#ifdef CONFIG_DNOTIFY
1475 {
1476 .ctl_name = FS_DIR_NOTIFY,
1477 .procname = "dir-notify-enable",
1478 .data = &dir_notify_enable,
1479 .maxlen = sizeof(int),
1480 .mode = 0644,
1481 .proc_handler = &proc_dointvec,
1482 },
1483#endif
1484#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001485#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 {
1487 .ctl_name = FS_LEASE_TIME,
1488 .procname = "lease-break-time",
1489 .data = &lease_break_time,
1490 .maxlen = sizeof(int),
1491 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001492 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001494#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001495#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 .procname = "aio-nr",
1498 .data = &aio_nr,
1499 .maxlen = sizeof(aio_nr),
1500 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001501 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 },
1503 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 .procname = "aio-max-nr",
1505 .data = &aio_max_nr,
1506 .maxlen = sizeof(aio_max_nr),
1507 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001508 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001510#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001511#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001512 {
1513 .ctl_name = FS_INOTIFY,
1514 .procname = "inotify",
1515 .mode = 0555,
1516 .child = inotify_table,
1517 },
1518#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001519#ifdef CONFIG_EPOLL
1520 {
1521 .procname = "epoll",
1522 .mode = 0555,
1523 .child = epoll_table,
1524 },
1525#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001527 {
1528 .ctl_name = KERN_SETUID_DUMPABLE,
1529 .procname = "suid_dumpable",
1530 .data = &suid_dumpable,
1531 .maxlen = sizeof(int),
1532 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001533 .proc_handler = &proc_dointvec_minmax,
1534 .strategy = &sysctl_intvec,
1535 .extra1 = &zero,
1536 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001537 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001538#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1539 {
1540 .ctl_name = CTL_UNNUMBERED,
1541 .procname = "binfmt_misc",
1542 .mode = 0555,
1543 .child = binfmt_misc_table,
1544 },
1545#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001546/*
1547 * NOTE: do not add new entries to this table unless you have read
1548 * Documentation/sysctl/ctl_unnumbered.txt
1549 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 { .ctl_name = 0 }
1551};
1552
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001553static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001554#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001555 {
1556 .ctl_name = CTL_UNNUMBERED,
1557 .procname = "exception-trace",
1558 .data = &show_unhandled_signals,
1559 .maxlen = sizeof(int),
1560 .mode = 0644,
1561 .proc_handler = proc_dointvec
1562 },
1563#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 { .ctl_name = 0 }
1565};
1566
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001567static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001569};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Al Viro330d57f2005-11-04 10:18:40 +00001571static DEFINE_SPINLOCK(sysctl_lock);
1572
1573/* called under sysctl_lock */
1574static int use_table(struct ctl_table_header *p)
1575{
1576 if (unlikely(p->unregistering))
1577 return 0;
1578 p->used++;
1579 return 1;
1580}
1581
1582/* called under sysctl_lock */
1583static void unuse_table(struct ctl_table_header *p)
1584{
1585 if (!--p->used)
1586 if (unlikely(p->unregistering))
1587 complete(p->unregistering);
1588}
1589
1590/* called under sysctl_lock, will reacquire if has to wait */
1591static void start_unregistering(struct ctl_table_header *p)
1592{
1593 /*
1594 * if p->used is 0, nobody will ever touch that entry again;
1595 * we'll eliminate all paths to it before dropping sysctl_lock
1596 */
1597 if (unlikely(p->used)) {
1598 struct completion wait;
1599 init_completion(&wait);
1600 p->unregistering = &wait;
1601 spin_unlock(&sysctl_lock);
1602 wait_for_completion(&wait);
1603 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001604 } else {
1605 /* anything non-NULL; we'll never dereference it */
1606 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001607 }
1608 /*
1609 * do not remove from the list until nobody holds it; walking the
1610 * list in do_sysctl() relies on that.
1611 */
1612 list_del_init(&p->ctl_entry);
1613}
1614
Al Virof7e6ced2008-07-15 01:44:23 -04001615void sysctl_head_get(struct ctl_table_header *head)
1616{
1617 spin_lock(&sysctl_lock);
1618 head->count++;
1619 spin_unlock(&sysctl_lock);
1620}
1621
1622void sysctl_head_put(struct ctl_table_header *head)
1623{
1624 spin_lock(&sysctl_lock);
1625 if (!--head->count)
1626 kfree(head);
1627 spin_unlock(&sysctl_lock);
1628}
1629
1630struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1631{
1632 if (!head)
1633 BUG();
1634 spin_lock(&sysctl_lock);
1635 if (!use_table(head))
1636 head = ERR_PTR(-ENOENT);
1637 spin_unlock(&sysctl_lock);
1638 return head;
1639}
1640
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001641void sysctl_head_finish(struct ctl_table_header *head)
1642{
1643 if (!head)
1644 return;
1645 spin_lock(&sysctl_lock);
1646 unuse_table(head);
1647 spin_unlock(&sysctl_lock);
1648}
1649
Al Viro73455092008-07-14 21:22:20 -04001650static struct ctl_table_set *
1651lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1652{
1653 struct ctl_table_set *set = &root->default_set;
1654 if (root->lookup)
1655 set = root->lookup(root, namespaces);
1656 return set;
1657}
1658
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001659static struct list_head *
1660lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001661{
Al Viro73455092008-07-14 21:22:20 -04001662 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1663 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001664}
1665
1666struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1667 struct ctl_table_header *prev)
1668{
1669 struct ctl_table_root *root;
1670 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001671 struct ctl_table_header *head;
1672 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001673
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001674 spin_lock(&sysctl_lock);
1675 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001676 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001677 tmp = &prev->ctl_entry;
1678 unuse_table(prev);
1679 goto next;
1680 }
1681 tmp = &root_table_header.ctl_entry;
1682 for (;;) {
1683 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1684
1685 if (!use_table(head))
1686 goto next;
1687 spin_unlock(&sysctl_lock);
1688 return head;
1689 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001690 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001691 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001692 header_list = lookup_header_list(root, namespaces);
1693 if (tmp != header_list)
1694 continue;
1695
1696 do {
1697 root = list_entry(root->root_list.next,
1698 struct ctl_table_root, root_list);
1699 if (root == &sysctl_table_root)
1700 goto out;
1701 header_list = lookup_header_list(root, namespaces);
1702 } while (list_empty(header_list));
1703 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001704 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001705out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001706 spin_unlock(&sysctl_lock);
1707 return NULL;
1708}
1709
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001710struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1711{
1712 return __sysctl_head_next(current->nsproxy, prev);
1713}
1714
1715void register_sysctl_root(struct ctl_table_root *root)
1716{
1717 spin_lock(&sysctl_lock);
1718 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1719 spin_unlock(&sysctl_lock);
1720}
1721
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001722#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001723/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001724static int do_sysctl_strategy(struct ctl_table_root *root,
1725 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001726 void __user *oldval, size_t __user *oldlenp,
1727 void __user *newval, size_t newlen)
1728{
1729 int op = 0, rc;
1730
1731 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001732 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001733 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001734 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001735 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001736 return -EPERM;
1737
1738 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001739 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001740 if (rc < 0)
1741 return rc;
1742 if (rc > 0)
1743 return 0;
1744 }
1745
1746 /* If there is no strategy routine, or if the strategy returns
1747 * zero, proceed with automatic r/w */
1748 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001749 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001750 if (rc < 0)
1751 return rc;
1752 }
1753 return 0;
1754}
1755
1756static int parse_table(int __user *name, int nlen,
1757 void __user *oldval, size_t __user *oldlenp,
1758 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001759 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001760 struct ctl_table *table)
1761{
1762 int n;
1763repeat:
1764 if (!nlen)
1765 return -ENOTDIR;
1766 if (get_user(n, name))
1767 return -EFAULT;
1768 for ( ; table->ctl_name || table->procname; table++) {
1769 if (!table->ctl_name)
1770 continue;
1771 if (n == table->ctl_name) {
1772 int error;
1773 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001774 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001775 return -EPERM;
1776 name++;
1777 nlen--;
1778 table = table->child;
1779 goto repeat;
1780 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001781 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001782 oldval, oldlenp,
1783 newval, newlen);
1784 return error;
1785 }
1786 }
1787 return -ENOTDIR;
1788}
1789
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1791 void __user *newval, size_t newlen)
1792{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001793 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001794 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
1796 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1797 return -ENOTDIR;
1798 if (oldval) {
1799 int old_len;
1800 if (!oldlenp || get_user(old_len, oldlenp))
1801 return -EFAULT;
1802 }
Al Viro330d57f2005-11-04 10:18:40 +00001803
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001804 for (head = sysctl_head_next(NULL); head;
1805 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001806 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001807 newval, newlen,
1808 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001809 if (error != -ENOTDIR) {
1810 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001811 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001812 }
1813 }
Al Viro330d57f2005-11-04 10:18:40 +00001814 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815}
1816
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001817SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818{
1819 struct __sysctl_args tmp;
1820 int error;
1821
1822 if (copy_from_user(&tmp, args, sizeof(tmp)))
1823 return -EFAULT;
1824
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001825 error = deprecated_sysctl_warning(&tmp);
1826 if (error)
1827 goto out;
1828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 lock_kernel();
1830 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1831 tmp.newval, tmp.newlen);
1832 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001833out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 return error;
1835}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001836#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
1838/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001839 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 * some sysctl variables are readonly even to root.
1841 */
1842
1843static int test_perm(int mode, int op)
1844{
David Howells76aac0e2008-11-14 10:39:12 +11001845 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 mode >>= 6;
1847 else if (in_egroup_p(0))
1848 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001849 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 return 0;
1851 return -EACCES;
1852}
1853
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001854int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
1856 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001857 int mode;
1858
Al Viroe6305c42008-07-15 21:03:57 -04001859 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 if (error)
1861 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001862
1863 if (root->permissions)
1864 mode = root->permissions(root, current->nsproxy, table);
1865 else
1866 mode = table->mode;
1867
1868 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869}
1870
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001871static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1872{
1873 for (; table->ctl_name || table->procname; table++) {
1874 table->parent = parent;
1875 if (table->child)
1876 sysctl_set_parent(table, table->child);
1877 }
1878}
1879
1880static __init int sysctl_init(void)
1881{
1882 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001883#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1884 {
1885 int err;
1886 err = sysctl_check_table(current->nsproxy, root_table);
1887 }
1888#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001889 return 0;
1890}
1891
1892core_initcall(sysctl_init);
1893
Al Virobfbcf032008-07-27 06:31:22 +01001894static struct ctl_table *is_branch_in(struct ctl_table *branch,
1895 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001896{
1897 struct ctl_table *p;
1898 const char *s = branch->procname;
1899
1900 /* branch should have named subdirectory as its first element */
1901 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001902 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001903
1904 /* ... and nothing else */
1905 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001906 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001907
1908 /* table should contain subdirectory with the same name */
1909 for (p = table; p->procname || p->ctl_name; p++) {
1910 if (!p->child)
1911 continue;
1912 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001913 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001914 }
Al Virobfbcf032008-07-27 06:31:22 +01001915 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001916}
1917
1918/* see if attaching q to p would be an improvement */
1919static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1920{
1921 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001922 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001923 int is_better = 0;
1924 int not_in_parent = !p->attached_by;
1925
Al Virobfbcf032008-07-27 06:31:22 +01001926 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001927 if (by == q->attached_by)
1928 is_better = 1;
1929 if (to == p->attached_by)
1930 not_in_parent = 1;
1931 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001932 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001933 }
1934
1935 if (is_better && not_in_parent) {
1936 q->attached_by = by;
1937 q->attached_to = to;
1938 q->parent = p;
1939 }
1940}
1941
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001943 * __register_sysctl_paths - register a sysctl hierarchy
1944 * @root: List of sysctl headers to register on
1945 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001946 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 *
1949 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001950 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001952 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 *
1954 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1955 * must be unique within that level of sysctl
1956 *
1957 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1958 * enter a sysctl file
1959 *
1960 * data - a pointer to data for use by proc_handler
1961 *
1962 * maxlen - the maximum size in bytes of the data
1963 *
1964 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1965 *
1966 * child - a pointer to the child sysctl table if this entry is a directory, or
1967 * %NULL.
1968 *
1969 * proc_handler - the text handler routine (described below)
1970 *
1971 * strategy - the strategy routine (described below)
1972 *
1973 * de - for internal use by the sysctl routines
1974 *
1975 * extra1, extra2 - extra pointers usable by the proc handler routines
1976 *
1977 * Leaf nodes in the sysctl tree will be represented by a single file
1978 * under /proc; non-leaf nodes will be represented by directories.
1979 *
1980 * sysctl(2) can automatically manage read and write requests through
1981 * the sysctl table. The data and maxlen fields of the ctl_table
1982 * struct enable minimal validation of the values being written to be
1983 * performed, and the mode field allows minimal authentication.
1984 *
1985 * More sophisticated management can be enabled by the provision of a
1986 * strategy routine with the table entry. This will be called before
1987 * any automatic read or write of the data is performed.
1988 *
1989 * The strategy routine may return
1990 *
1991 * < 0 - Error occurred (error is passed to user process)
1992 *
1993 * 0 - OK - proceed with automatic read or write.
1994 *
1995 * > 0 - OK - read or write has been done by the strategy routine, so
1996 * return immediately.
1997 *
1998 * There must be a proc_handler routine for any terminal nodes
1999 * mirrored under /proc/sys (non-terminals are handled by a built-in
2000 * directory handler). Several default handlers are available to
2001 * cover common cases -
2002 *
2003 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2004 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2005 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2006 *
2007 * It is the handler's job to read the input buffer from user memory
2008 * and process it. The handler should return 0 on success.
2009 *
2010 * This routine returns %NULL on a failure to register, and a pointer
2011 * to the table header on success.
2012 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002013struct ctl_table_header *__register_sysctl_paths(
2014 struct ctl_table_root *root,
2015 struct nsproxy *namespaces,
2016 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002018 struct ctl_table_header *header;
2019 struct ctl_table *new, **prevp;
2020 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04002021 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002022
2023 /* Count the path components */
2024 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2025 ;
2026
2027 /*
2028 * For each path component, allocate a 2-element ctl_table array.
2029 * The first array element will be filled with the sysctl entry
2030 * for this, the second will be the sentinel (ctl_name == 0).
2031 *
2032 * We allocate everything in one go so that we don't have to
2033 * worry about freeing additional memory in unregister_sysctl_table.
2034 */
2035 header = kzalloc(sizeof(struct ctl_table_header) +
2036 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2037 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002039
2040 new = (struct ctl_table *) (header + 1);
2041
2042 /* Now connect the dots */
2043 prevp = &header->ctl_table;
2044 for (n = 0; n < npath; ++n, ++path) {
2045 /* Copy the procname */
2046 new->procname = path->procname;
2047 new->ctl_name = path->ctl_name;
2048 new->mode = 0555;
2049
2050 *prevp = new;
2051 prevp = &new->child;
2052
2053 new += 2;
2054 }
2055 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002056 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002057
2058 INIT_LIST_HEAD(&header->ctl_entry);
2059 header->used = 0;
2060 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002061 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002062 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002063 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002064#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002065 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002066 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002067 return NULL;
2068 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002069#endif
Al Viro330d57f2005-11-04 10:18:40 +00002070 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002071 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002072 header->attached_by = header->ctl_table;
2073 header->attached_to = root_table;
2074 header->parent = &root_table_header;
2075 for (set = header->set; set; set = set->parent) {
2076 struct ctl_table_header *p;
2077 list_for_each_entry(p, &set->list, ctl_entry) {
2078 if (p->unregistering)
2079 continue;
2080 try_attach(p, header);
2081 }
2082 }
2083 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002084 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002085 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002086
2087 return header;
2088}
2089
2090/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002091 * register_sysctl_table_path - register a sysctl table hierarchy
2092 * @path: The path to the directory the sysctl table is in.
2093 * @table: the top-level table structure
2094 *
2095 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2096 * array. A completely 0 filled entry terminates the table.
2097 *
2098 * See __register_sysctl_paths for more details.
2099 */
2100struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2101 struct ctl_table *table)
2102{
2103 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2104 path, table);
2105}
2106
2107/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002108 * register_sysctl_table - register a sysctl table hierarchy
2109 * @table: the top-level table structure
2110 *
2111 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2112 * array. A completely 0 filled entry terminates the table.
2113 *
2114 * See register_sysctl_paths for more details.
2115 */
2116struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2117{
2118 static const struct ctl_path null_path[] = { {} };
2119
2120 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121}
2122
2123/**
2124 * unregister_sysctl_table - unregister a sysctl table hierarchy
2125 * @header: the header returned from register_sysctl_table
2126 *
2127 * Unregisters the sysctl table and all children. proc entries may not
2128 * actually be removed until they are no longer used by anyone.
2129 */
2130void unregister_sysctl_table(struct ctl_table_header * header)
2131{
Al Viro330d57f2005-11-04 10:18:40 +00002132 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002133
2134 if (header == NULL)
2135 return;
2136
Al Viro330d57f2005-11-04 10:18:40 +00002137 spin_lock(&sysctl_lock);
2138 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002139 if (!--header->parent->count) {
2140 WARN_ON(1);
2141 kfree(header->parent);
2142 }
Al Virof7e6ced2008-07-15 01:44:23 -04002143 if (!--header->count)
2144 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002145 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146}
2147
Al Viro9043476f2008-07-15 08:54:06 -04002148int sysctl_is_seen(struct ctl_table_header *p)
2149{
2150 struct ctl_table_set *set = p->set;
2151 int res;
2152 spin_lock(&sysctl_lock);
2153 if (p->unregistering)
2154 res = 0;
2155 else if (!set->is_seen)
2156 res = 1;
2157 else
2158 res = set->is_seen(set);
2159 spin_unlock(&sysctl_lock);
2160 return res;
2161}
2162
Al Viro73455092008-07-14 21:22:20 -04002163void setup_sysctl_set(struct ctl_table_set *p,
2164 struct ctl_table_set *parent,
2165 int (*is_seen)(struct ctl_table_set *))
2166{
2167 INIT_LIST_HEAD(&p->list);
2168 p->parent = parent ? parent : &sysctl_table_root.default_set;
2169 p->is_seen = is_seen;
2170}
2171
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002172#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002173struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002174{
2175 return NULL;
2176}
2177
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002178struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2179 struct ctl_table *table)
2180{
2181 return NULL;
2182}
2183
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002184void unregister_sysctl_table(struct ctl_table_header * table)
2185{
2186}
2187
Al Viro73455092008-07-14 21:22:20 -04002188void setup_sysctl_set(struct ctl_table_set *p,
2189 struct ctl_table_set *parent,
2190 int (*is_seen)(struct ctl_table_set *))
2191{
2192}
2193
Al Virof7e6ced2008-07-15 01:44:23 -04002194void sysctl_head_put(struct ctl_table_header *head)
2195{
2196}
2197
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002198#endif /* CONFIG_SYSCTL */
2199
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200/*
2201 * /proc/sys support
2202 */
2203
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002204#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002206static int _proc_do_string(void* data, int maxlen, int write,
2207 struct file *filp, void __user *buffer,
2208 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002209{
2210 size_t len;
2211 char __user *p;
2212 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002213
2214 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002215 *lenp = 0;
2216 return 0;
2217 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002218
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002219 if (write) {
2220 len = 0;
2221 p = buffer;
2222 while (len < *lenp) {
2223 if (get_user(c, p++))
2224 return -EFAULT;
2225 if (c == 0 || c == '\n')
2226 break;
2227 len++;
2228 }
2229 if (len >= maxlen)
2230 len = maxlen-1;
2231 if(copy_from_user(data, buffer, len))
2232 return -EFAULT;
2233 ((char *) data)[len] = 0;
2234 *ppos += *lenp;
2235 } else {
2236 len = strlen(data);
2237 if (len > maxlen)
2238 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002239
2240 if (*ppos > len) {
2241 *lenp = 0;
2242 return 0;
2243 }
2244
2245 data += *ppos;
2246 len -= *ppos;
2247
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002248 if (len > *lenp)
2249 len = *lenp;
2250 if (len)
2251 if(copy_to_user(buffer, data, len))
2252 return -EFAULT;
2253 if (len < *lenp) {
2254 if(put_user('\n', ((char __user *) buffer) + len))
2255 return -EFAULT;
2256 len++;
2257 }
2258 *lenp = len;
2259 *ppos += len;
2260 }
2261 return 0;
2262}
2263
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264/**
2265 * proc_dostring - read a string sysctl
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
2268 * @filp: the file structure
2269 * @buffer: the user buffer
2270 * @lenp: the size of the user buffer
2271 * @ppos: file position
2272 *
2273 * Reads/writes a string from/to the user buffer. If the kernel
2274 * buffer provided is not large enough to hold the string, the
2275 * string is truncated. The copied string is %NULL-terminated.
2276 * If the string is being read by the user process, it is copied
2277 * and a newline '\n' is added. It is truncated if the buffer is
2278 * not large enough.
2279 *
2280 * Returns 0 on success.
2281 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002282int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 void __user *buffer, size_t *lenp, loff_t *ppos)
2284{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002285 return _proc_do_string(table->data, table->maxlen, write, filp,
2286 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287}
2288
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
2290static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2291 int *valp,
2292 int write, void *data)
2293{
2294 if (write) {
2295 *valp = *negp ? -*lvalp : *lvalp;
2296 } else {
2297 int val = *valp;
2298 if (val < 0) {
2299 *negp = -1;
2300 *lvalp = (unsigned long)-val;
2301 } else {
2302 *negp = 0;
2303 *lvalp = (unsigned long)val;
2304 }
2305 }
2306 return 0;
2307}
2308
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002309static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002310 int write, struct file *filp, void __user *buffer,
2311 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2313 int write, void *data),
2314 void *data)
2315{
2316#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002317 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 unsigned long lval;
2319 size_t left, len;
2320
2321 char buf[TMPBUFLEN], *p;
2322 char __user *s = buffer;
2323
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002324 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 (*ppos && !write)) {
2326 *lenp = 0;
2327 return 0;
2328 }
2329
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002330 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 vleft = table->maxlen / sizeof(*i);
2332 left = *lenp;
2333
2334 if (!conv)
2335 conv = do_proc_dointvec_conv;
2336
2337 for (; left && vleft--; i++, first=0) {
2338 if (write) {
2339 while (left) {
2340 char c;
2341 if (get_user(c, s))
2342 return -EFAULT;
2343 if (!isspace(c))
2344 break;
2345 left--;
2346 s++;
2347 }
2348 if (!left)
2349 break;
2350 neg = 0;
2351 len = left;
2352 if (len > sizeof(buf) - 1)
2353 len = sizeof(buf) - 1;
2354 if (copy_from_user(buf, s, len))
2355 return -EFAULT;
2356 buf[len] = 0;
2357 p = buf;
2358 if (*p == '-' && left > 1) {
2359 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002360 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 }
2362 if (*p < '0' || *p > '9')
2363 break;
2364
2365 lval = simple_strtoul(p, &p, 0);
2366
2367 len = p-buf;
2368 if ((len < left) && *p && !isspace(*p))
2369 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 s += len;
2371 left -= len;
2372
2373 if (conv(&neg, &lval, i, 1, data))
2374 break;
2375 } else {
2376 p = buf;
2377 if (!first)
2378 *p++ = '\t';
2379
2380 if (conv(&neg, &lval, i, 0, data))
2381 break;
2382
2383 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2384 len = strlen(buf);
2385 if (len > left)
2386 len = left;
2387 if(copy_to_user(s, buf, len))
2388 return -EFAULT;
2389 left -= len;
2390 s += len;
2391 }
2392 }
2393
2394 if (!write && !first && left) {
2395 if(put_user('\n', s))
2396 return -EFAULT;
2397 left--, s++;
2398 }
2399 if (write) {
2400 while (left) {
2401 char c;
2402 if (get_user(c, s++))
2403 return -EFAULT;
2404 if (!isspace(c))
2405 break;
2406 left--;
2407 }
2408 }
2409 if (write && first)
2410 return -EINVAL;
2411 *lenp -= left;
2412 *ppos += *lenp;
2413 return 0;
2414#undef TMPBUFLEN
2415}
2416
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002417static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002418 void __user *buffer, size_t *lenp, loff_t *ppos,
2419 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2420 int write, void *data),
2421 void *data)
2422{
2423 return __do_proc_dointvec(table->data, table, write, filp,
2424 buffer, lenp, ppos, conv, data);
2425}
2426
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427/**
2428 * proc_dointvec - read a vector of integers
2429 * @table: the sysctl table
2430 * @write: %TRUE if this is a write to the sysctl file
2431 * @filp: the file structure
2432 * @buffer: the user buffer
2433 * @lenp: the size of the user buffer
2434 * @ppos: file position
2435 *
2436 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2437 * values from/to the user buffer, treated as an ASCII string.
2438 *
2439 * Returns 0 on success.
2440 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002441int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 void __user *buffer, size_t *lenp, loff_t *ppos)
2443{
2444 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2445 NULL,NULL);
2446}
2447
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002448/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002449 * Taint values can only be increased
2450 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002451 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002452static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002453 void __user *buffer, size_t *lenp, loff_t *ppos)
2454{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002455 struct ctl_table t;
2456 unsigned long tmptaint = get_taint();
2457 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002458
Bastian Blank91fcd412007-04-23 14:41:14 -07002459 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002460 return -EPERM;
2461
Andi Kleen25ddbb12008-10-15 22:01:41 -07002462 t = *table;
2463 t.data = &tmptaint;
2464 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2465 if (err < 0)
2466 return err;
2467
2468 if (write) {
2469 /*
2470 * Poor man's atomic or. Not worth adding a primitive
2471 * to everyone's atomic.h for this
2472 */
2473 int i;
2474 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2475 if ((tmptaint >> i) & 1)
2476 add_taint(i);
2477 }
2478 }
2479
2480 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002481}
2482
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483struct do_proc_dointvec_minmax_conv_param {
2484 int *min;
2485 int *max;
2486};
2487
2488static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2489 int *valp,
2490 int write, void *data)
2491{
2492 struct do_proc_dointvec_minmax_conv_param *param = data;
2493 if (write) {
2494 int val = *negp ? -*lvalp : *lvalp;
2495 if ((param->min && *param->min > val) ||
2496 (param->max && *param->max < val))
2497 return -EINVAL;
2498 *valp = val;
2499 } else {
2500 int val = *valp;
2501 if (val < 0) {
2502 *negp = -1;
2503 *lvalp = (unsigned long)-val;
2504 } else {
2505 *negp = 0;
2506 *lvalp = (unsigned long)val;
2507 }
2508 }
2509 return 0;
2510}
2511
2512/**
2513 * proc_dointvec_minmax - read a vector of integers with min/max values
2514 * @table: the sysctl table
2515 * @write: %TRUE if this is a write to the sysctl file
2516 * @filp: the file structure
2517 * @buffer: the user buffer
2518 * @lenp: the size of the user buffer
2519 * @ppos: file position
2520 *
2521 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2522 * values from/to the user buffer, treated as an ASCII string.
2523 *
2524 * This routine will ensure the values are within the range specified by
2525 * table->extra1 (min) and table->extra2 (max).
2526 *
2527 * Returns 0 on success.
2528 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002529int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 void __user *buffer, size_t *lenp, loff_t *ppos)
2531{
2532 struct do_proc_dointvec_minmax_conv_param param = {
2533 .min = (int *) table->extra1,
2534 .max = (int *) table->extra2,
2535 };
2536 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2537 do_proc_dointvec_minmax_conv, &param);
2538}
2539
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002540static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 struct file *filp,
2542 void __user *buffer,
2543 size_t *lenp, loff_t *ppos,
2544 unsigned long convmul,
2545 unsigned long convdiv)
2546{
2547#define TMPBUFLEN 21
2548 unsigned long *i, *min, *max, val;
2549 int vleft, first=1, neg;
2550 size_t len, left;
2551 char buf[TMPBUFLEN], *p;
2552 char __user *s = buffer;
2553
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002554 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 (*ppos && !write)) {
2556 *lenp = 0;
2557 return 0;
2558 }
2559
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002560 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 min = (unsigned long *) table->extra1;
2562 max = (unsigned long *) table->extra2;
2563 vleft = table->maxlen / sizeof(unsigned long);
2564 left = *lenp;
2565
2566 for (; left && vleft--; i++, min++, max++, first=0) {
2567 if (write) {
2568 while (left) {
2569 char c;
2570 if (get_user(c, s))
2571 return -EFAULT;
2572 if (!isspace(c))
2573 break;
2574 left--;
2575 s++;
2576 }
2577 if (!left)
2578 break;
2579 neg = 0;
2580 len = left;
2581 if (len > TMPBUFLEN-1)
2582 len = TMPBUFLEN-1;
2583 if (copy_from_user(buf, s, len))
2584 return -EFAULT;
2585 buf[len] = 0;
2586 p = buf;
2587 if (*p == '-' && left > 1) {
2588 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002589 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 }
2591 if (*p < '0' || *p > '9')
2592 break;
2593 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2594 len = p-buf;
2595 if ((len < left) && *p && !isspace(*p))
2596 break;
2597 if (neg)
2598 val = -val;
2599 s += len;
2600 left -= len;
2601
2602 if(neg)
2603 continue;
2604 if ((min && val < *min) || (max && val > *max))
2605 continue;
2606 *i = val;
2607 } else {
2608 p = buf;
2609 if (!first)
2610 *p++ = '\t';
2611 sprintf(p, "%lu", convdiv * (*i) / convmul);
2612 len = strlen(buf);
2613 if (len > left)
2614 len = left;
2615 if(copy_to_user(s, buf, len))
2616 return -EFAULT;
2617 left -= len;
2618 s += len;
2619 }
2620 }
2621
2622 if (!write && !first && left) {
2623 if(put_user('\n', s))
2624 return -EFAULT;
2625 left--, s++;
2626 }
2627 if (write) {
2628 while (left) {
2629 char c;
2630 if (get_user(c, s++))
2631 return -EFAULT;
2632 if (!isspace(c))
2633 break;
2634 left--;
2635 }
2636 }
2637 if (write && first)
2638 return -EINVAL;
2639 *lenp -= left;
2640 *ppos += *lenp;
2641 return 0;
2642#undef TMPBUFLEN
2643}
2644
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002645static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002646 struct file *filp,
2647 void __user *buffer,
2648 size_t *lenp, loff_t *ppos,
2649 unsigned long convmul,
2650 unsigned long convdiv)
2651{
2652 return __do_proc_doulongvec_minmax(table->data, table, write,
2653 filp, buffer, lenp, ppos, convmul, convdiv);
2654}
2655
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656/**
2657 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2658 * @table: the sysctl table
2659 * @write: %TRUE if this is a write to the sysctl file
2660 * @filp: the file structure
2661 * @buffer: the user buffer
2662 * @lenp: the size of the user buffer
2663 * @ppos: file position
2664 *
2665 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2666 * values from/to the user buffer, treated as an ASCII string.
2667 *
2668 * This routine will ensure the values are within the range specified by
2669 * table->extra1 (min) and table->extra2 (max).
2670 *
2671 * Returns 0 on success.
2672 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002673int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 void __user *buffer, size_t *lenp, loff_t *ppos)
2675{
2676 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2677}
2678
2679/**
2680 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2681 * @table: the sysctl table
2682 * @write: %TRUE if this is a write to the sysctl file
2683 * @filp: the file structure
2684 * @buffer: the user buffer
2685 * @lenp: the size of the user buffer
2686 * @ppos: file position
2687 *
2688 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2689 * values from/to the user buffer, treated as an ASCII string. The values
2690 * are treated as milliseconds, and converted to jiffies when they are stored.
2691 *
2692 * This routine will ensure the values are within the range specified by
2693 * table->extra1 (min) and table->extra2 (max).
2694 *
2695 * Returns 0 on success.
2696 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002697int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 struct file *filp,
2699 void __user *buffer,
2700 size_t *lenp, loff_t *ppos)
2701{
2702 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2703 lenp, ppos, HZ, 1000l);
2704}
2705
2706
2707static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2708 int *valp,
2709 int write, void *data)
2710{
2711 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002712 if (*lvalp > LONG_MAX / HZ)
2713 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2715 } else {
2716 int val = *valp;
2717 unsigned long lval;
2718 if (val < 0) {
2719 *negp = -1;
2720 lval = (unsigned long)-val;
2721 } else {
2722 *negp = 0;
2723 lval = (unsigned long)val;
2724 }
2725 *lvalp = lval / HZ;
2726 }
2727 return 0;
2728}
2729
2730static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2731 int *valp,
2732 int write, void *data)
2733{
2734 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002735 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2736 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2738 } else {
2739 int val = *valp;
2740 unsigned long lval;
2741 if (val < 0) {
2742 *negp = -1;
2743 lval = (unsigned long)-val;
2744 } else {
2745 *negp = 0;
2746 lval = (unsigned long)val;
2747 }
2748 *lvalp = jiffies_to_clock_t(lval);
2749 }
2750 return 0;
2751}
2752
2753static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2754 int *valp,
2755 int write, void *data)
2756{
2757 if (write) {
2758 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2759 } else {
2760 int val = *valp;
2761 unsigned long lval;
2762 if (val < 0) {
2763 *negp = -1;
2764 lval = (unsigned long)-val;
2765 } else {
2766 *negp = 0;
2767 lval = (unsigned long)val;
2768 }
2769 *lvalp = jiffies_to_msecs(lval);
2770 }
2771 return 0;
2772}
2773
2774/**
2775 * proc_dointvec_jiffies - read a vector of integers as seconds
2776 * @table: the sysctl table
2777 * @write: %TRUE if this is a write to the sysctl file
2778 * @filp: the file structure
2779 * @buffer: the user buffer
2780 * @lenp: the size of the user buffer
2781 * @ppos: file position
2782 *
2783 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2784 * values from/to the user buffer, treated as an ASCII string.
2785 * The values read are assumed to be in seconds, and are converted into
2786 * jiffies.
2787 *
2788 * Returns 0 on success.
2789 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002790int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 void __user *buffer, size_t *lenp, loff_t *ppos)
2792{
2793 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2794 do_proc_dointvec_jiffies_conv,NULL);
2795}
2796
2797/**
2798 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2799 * @table: the sysctl table
2800 * @write: %TRUE if this is a write to the sysctl file
2801 * @filp: the file structure
2802 * @buffer: the user buffer
2803 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002804 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 *
2806 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2807 * values from/to the user buffer, treated as an ASCII string.
2808 * The values read are assumed to be in 1/USER_HZ seconds, and
2809 * are converted into jiffies.
2810 *
2811 * Returns 0 on success.
2812 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002813int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 void __user *buffer, size_t *lenp, loff_t *ppos)
2815{
2816 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2817 do_proc_dointvec_userhz_jiffies_conv,NULL);
2818}
2819
2820/**
2821 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2822 * @table: the sysctl table
2823 * @write: %TRUE if this is a write to the sysctl file
2824 * @filp: the file structure
2825 * @buffer: the user buffer
2826 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002827 * @ppos: file position
2828 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 *
2830 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2831 * values from/to the user buffer, treated as an ASCII string.
2832 * The values read are assumed to be in 1/1000 seconds, and
2833 * are converted into jiffies.
2834 *
2835 * Returns 0 on success.
2836 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002837int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 void __user *buffer, size_t *lenp, loff_t *ppos)
2839{
2840 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2841 do_proc_dointvec_ms_jiffies_conv, NULL);
2842}
2843
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002844static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002845 void __user *buffer, size_t *lenp, loff_t *ppos)
2846{
2847 struct pid *new_pid;
2848 pid_t tmp;
2849 int r;
2850
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002851 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002852
2853 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2854 lenp, ppos, NULL, NULL);
2855 if (r || !write)
2856 return r;
2857
2858 new_pid = find_get_pid(tmp);
2859 if (!new_pid)
2860 return -ESRCH;
2861
2862 put_pid(xchg(&cad_pid, new_pid));
2863 return 0;
2864}
2865
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866#else /* CONFIG_PROC_FS */
2867
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002868int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 void __user *buffer, size_t *lenp, loff_t *ppos)
2870{
2871 return -ENOSYS;
2872}
2873
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002874int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 void __user *buffer, size_t *lenp, loff_t *ppos)
2876{
2877 return -ENOSYS;
2878}
2879
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002880int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 void __user *buffer, size_t *lenp, loff_t *ppos)
2882{
2883 return -ENOSYS;
2884}
2885
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002886int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 void __user *buffer, size_t *lenp, loff_t *ppos)
2888{
2889 return -ENOSYS;
2890}
2891
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002892int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 void __user *buffer, size_t *lenp, loff_t *ppos)
2894{
2895 return -ENOSYS;
2896}
2897
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002898int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 void __user *buffer, size_t *lenp, loff_t *ppos)
2900{
2901 return -ENOSYS;
2902}
2903
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002904int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 void __user *buffer, size_t *lenp, loff_t *ppos)
2906{
2907 return -ENOSYS;
2908}
2909
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002910int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 struct file *filp,
2912 void __user *buffer,
2913 size_t *lenp, loff_t *ppos)
2914{
2915 return -ENOSYS;
2916}
2917
2918
2919#endif /* CONFIG_PROC_FS */
2920
2921
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002922#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923/*
2924 * General sysctl support routines
2925 */
2926
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002927/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002928int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002929 void __user *oldval, size_t __user *oldlenp,
2930 void __user *newval, size_t newlen)
2931{
2932 size_t len;
2933
2934 /* Get out of I don't have a variable */
2935 if (!table->data || !table->maxlen)
2936 return -ENOTDIR;
2937
2938 if (oldval && oldlenp) {
2939 if (get_user(len, oldlenp))
2940 return -EFAULT;
2941 if (len) {
2942 if (len > table->maxlen)
2943 len = table->maxlen;
2944 if (copy_to_user(oldval, table->data, len))
2945 return -EFAULT;
2946 if (put_user(len, oldlenp))
2947 return -EFAULT;
2948 }
2949 }
2950
2951 if (newval && newlen) {
2952 if (newlen > table->maxlen)
2953 newlen = table->maxlen;
2954
2955 if (copy_from_user(table->data, newval, newlen))
2956 return -EFAULT;
2957 }
2958 return 1;
2959}
2960
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002962int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002964 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 if (!table->data || !table->maxlen)
2967 return -ENOTDIR;
2968
2969 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002970 size_t bufsize;
2971 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002973 if (bufsize) {
2974 size_t len = strlen(table->data), copied;
2975
2976 /* This shouldn't trigger for a well-formed sysctl */
2977 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002979
2980 /* Copy up to a max of bufsize-1 bytes of the string */
2981 copied = (len >= bufsize) ? bufsize - 1 : len;
2982
2983 if (copy_to_user(oldval, table->data, copied) ||
2984 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002986 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 return -EFAULT;
2988 }
2989 }
2990 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002991 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 if (len > table->maxlen)
2993 len = table->maxlen;
2994 if(copy_from_user(table->data, newval, len))
2995 return -EFAULT;
2996 if (len == table->maxlen)
2997 len--;
2998 ((char *) table->data)[len] = 0;
2999 }
Yi Yang82c9df82005-12-30 16:37:10 +08003000 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001}
3002
3003/*
3004 * This function makes sure that all of the integers in the vector
3005 * are between the minimum and maximum values given in the arrays
3006 * table->extra1 and table->extra2, respectively.
3007 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003008int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003010 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011{
3012
3013 if (newval && newlen) {
3014 int __user *vec = (int __user *) newval;
3015 int *min = (int *) table->extra1;
3016 int *max = (int *) table->extra2;
3017 size_t length;
3018 int i;
3019
3020 if (newlen % sizeof(int) != 0)
3021 return -EINVAL;
3022
3023 if (!table->extra1 && !table->extra2)
3024 return 0;
3025
3026 if (newlen > table->maxlen)
3027 newlen = table->maxlen;
3028 length = newlen / sizeof(int);
3029
3030 for (i = 0; i < length; i++) {
3031 int value;
3032 if (get_user(value, vec + i))
3033 return -EFAULT;
3034 if (min && value < min[i])
3035 return -EINVAL;
3036 if (max && value > max[i])
3037 return -EINVAL;
3038 }
3039 }
3040 return 0;
3041}
3042
3043/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003044int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003046 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003048 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003050
3051 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003053 if (olen) {
3054 int val;
3055
3056 if (olen < sizeof(int))
3057 return -EINVAL;
3058
3059 val = *(int *)(table->data) / HZ;
3060 if (put_user(val, (int __user *)oldval))
3061 return -EFAULT;
3062 if (put_user(sizeof(int), oldlenp))
3063 return -EFAULT;
3064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 }
3066 if (newval && newlen) {
3067 int new;
3068 if (newlen != sizeof(int))
3069 return -EINVAL;
3070 if (get_user(new, (int __user *)newval))
3071 return -EFAULT;
3072 *(int *)(table->data) = new*HZ;
3073 }
3074 return 1;
3075}
3076
3077/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003078int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003080 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003082 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003084
3085 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003087 if (olen) {
3088 int val;
3089
3090 if (olen < sizeof(int))
3091 return -EINVAL;
3092
3093 val = jiffies_to_msecs(*(int *)(table->data));
3094 if (put_user(val, (int __user *)oldval))
3095 return -EFAULT;
3096 if (put_user(sizeof(int), oldlenp))
3097 return -EFAULT;
3098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
3100 if (newval && newlen) {
3101 int new;
3102 if (newlen != sizeof(int))
3103 return -EINVAL;
3104 if (get_user(new, (int __user *)newval))
3105 return -EFAULT;
3106 *(int *)(table->data) = msecs_to_jiffies(new);
3107 }
3108 return 1;
3109}
3110
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003111
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003112
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003113#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
3115
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003116SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003118 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003119 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003120
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003121 if (copy_from_user(&tmp, args, sizeof(tmp)))
3122 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003123
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003124 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003125
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003126 /* If no error reading the parameters then just -ENOSYS ... */
3127 if (!error)
3128 error = -ENOSYS;
3129
3130 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131}
3132
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003133int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003134 void __user *oldval, size_t __user *oldlenp,
3135 void __user *newval, size_t newlen)
3136{
3137 return -ENOSYS;
3138}
3139
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003140int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003142 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143{
3144 return -ENOSYS;
3145}
3146
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003147int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003149 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150{
3151 return -ENOSYS;
3152}
3153
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003154int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003156 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157{
3158 return -ENOSYS;
3159}
3160
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003161int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003163 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164{
3165 return -ENOSYS;
3166}
3167
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003168#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003170static int deprecated_sysctl_warning(struct __sysctl_args *args)
3171{
3172 static int msg_count;
3173 int name[CTL_MAXNAME];
3174 int i;
3175
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003176 /* Check args->nlen. */
3177 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3178 return -ENOTDIR;
3179
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003180 /* Read in the sysctl name for better debug message logging */
3181 for (i = 0; i < args->nlen; i++)
3182 if (get_user(name[i], args->name + i))
3183 return -EFAULT;
3184
3185 /* Ignore accesses to kernel.version */
3186 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3187 return 0;
3188
3189 if (msg_count < 5) {
3190 msg_count++;
3191 printk(KERN_INFO
3192 "warning: process `%s' used the deprecated sysctl "
3193 "system call with ", current->comm);
3194 for (i = 0; i < args->nlen; i++)
3195 printk("%d.", name[i]);
3196 printk("\n");
3197 }
3198 return 0;
3199}
3200
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201/*
3202 * No sense putting this after each symbol definition, twice,
3203 * exception granted :-)
3204 */
3205EXPORT_SYMBOL(proc_dointvec);
3206EXPORT_SYMBOL(proc_dointvec_jiffies);
3207EXPORT_SYMBOL(proc_dointvec_minmax);
3208EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3209EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3210EXPORT_SYMBOL(proc_dostring);
3211EXPORT_SYMBOL(proc_doulongvec_minmax);
3212EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3213EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003214EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215EXPORT_SYMBOL(sysctl_intvec);
3216EXPORT_SYMBOL(sysctl_jiffies);
3217EXPORT_SYMBOL(sysctl_ms_jiffies);
3218EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003219EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220EXPORT_SYMBOL(unregister_sysctl_table);