blob: c9a0af887033e02f92d7ff89cd084f525387c00d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include <asm/uaccess.h>
53#include <asm/processor.h>
54
Andi Kleen29cbc782006-09-30 01:47:55 +020055#ifdef CONFIG_X86
56#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010057#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010058#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020059#endif
60
Eric W. Biederman7058cb02007-10-18 03:05:58 -070061static int deprecated_sysctl_warning(struct __sysctl_args *args);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#if defined(CONFIG_SYSCTL)
64
65/* External variables not in a header file. */
66extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070067extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int sysctl_overcommit_memory;
69extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070070extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070071extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080072extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070075extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max;
78extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080080extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080081extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020082extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070083extern int maps_protect;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070086#ifdef CONFIG_RCU_TORTURE_TEST
87extern int rcutorture_runnable;
88#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070090/* Constants used for minimum and maximum */
Ingo Molnar1c4cd6d2008-05-12 21:21:14 +020091#if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092static int one = 1;
Bron Gondwana195cf452008-02-04 22:29:20 -080093#endif
94
95#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020097static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098#endif
99
100#ifdef CONFIG_MMU
101static int two = 2;
102#endif
103
104static int zero;
105static int one_hundred = 100;
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108static int maxolduid = 65535;
109static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112static int ngroups_max = NGROUPS_MAX;
113
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200114#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115extern char modprobe_path[];
116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#ifdef CONFIG_CHR_DEV_SG
118extern int sg_big_buff;
119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121#ifdef __sparc__
122extern char reboot_command [];
123extern int stop_a_enabled;
124extern int scons_pwroff;
125#endif
126
127#ifdef __hppa__
128extern int pwrsw_enabled;
129extern int unaligned_enabled;
130#endif
131
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800132#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#ifdef CONFIG_MATHEMU
134extern int sysctl_ieee_emulation_warnings;
135#endif
136extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700137extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#endif
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef CONFIG_BSD_PROCESS_ACCT
141extern int acct_parm[];
142#endif
143
Jes Sorensend2b176e2006-02-28 09:42:23 -0800144#ifdef CONFIG_IA64
145extern int no_unaligned_warning;
146#endif
147
Ingo Molnar23f78d42006-06-27 02:54:53 -0700148#ifdef CONFIG_RT_MUTEXES
149extern int max_lock_depth;
150#endif
151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700153static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700154 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800156 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700158
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700159static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100160static struct ctl_table_root sysctl_table_root;
161static struct ctl_table_header root_table_header = {
162 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100164 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400165 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100166};
167static struct ctl_table_root sysctl_table_root = {
168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400169 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100170};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700172static struct ctl_table kern_table[];
173static struct ctl_table vm_table[];
174static struct ctl_table fs_table[];
175static struct ctl_table debug_table[];
176static struct ctl_table dev_table[];
177extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700178#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700179extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400180#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183int sysctl_legacy_va_layout;
184#endif
185
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700186extern int prove_locking;
187extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/* The default sysctl tables: */
190
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700191static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
195 .mode = 0555,
196 .child = kern_table,
197 },
198 {
199 .ctl_name = CTL_VM,
200 .procname = "vm",
201 .mode = 0555,
202 .child = vm_table,
203 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 .ctl_name = CTL_FS,
206 .procname = "fs",
207 .mode = 0555,
208 .child = fs_table,
209 },
210 {
211 .ctl_name = CTL_DEBUG,
212 .procname = "debug",
213 .mode = 0555,
214 .child = debug_table,
215 },
216 {
217 .ctl_name = CTL_DEV,
218 .procname = "dev",
219 .mode = 0555,
220 .child = dev_table,
221 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700222/*
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
225 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 { .ctl_name = 0 }
227};
228
Ingo Molnar77e54a12007-07-09 18:52:00 +0200229#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100230static int min_sched_granularity_ns = 100000; /* 100 usecs */
231static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
232static int min_wakeup_granularity_ns; /* 0 usecs */
233static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200234#endif
235
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700236static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200237#ifdef CONFIG_SCHED_DEBUG
238 {
239 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100240 .procname = "sched_min_granularity_ns",
241 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200242 .maxlen = sizeof(unsigned int),
243 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100244 .proc_handler = &sched_nr_latency_handler,
245 .strategy = &sysctl_intvec,
246 .extra1 = &min_sched_granularity_ns,
247 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200248 },
249 {
250 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200251 .procname = "sched_latency_ns",
252 .data = &sysctl_sched_latency,
253 .maxlen = sizeof(unsigned int),
254 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100255 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
259 },
260 {
261 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200262 .procname = "sched_wakeup_granularity_ns",
263 .data = &sysctl_sched_wakeup_granularity,
264 .maxlen = sizeof(unsigned int),
265 .mode = 0644,
266 .proc_handler = &proc_dointvec_minmax,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_wakeup_granularity_ns,
269 .extra2 = &max_wakeup_granularity_ns,
270 },
271 {
272 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200273 .procname = "sched_shares_ratelimit",
274 .data = &sysctl_sched_shares_ratelimit,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
277 .proc_handler = &proc_dointvec,
278 },
279 {
280 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200281 .procname = "sched_child_runs_first",
282 .data = &sysctl_sched_child_runs_first,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
285 .proc_handler = &proc_dointvec,
286 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200287 {
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "sched_features",
290 .data = &sysctl_sched_features,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
293 .proc_handler = &proc_dointvec,
294 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200295 {
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_migration_cost",
298 .data = &sysctl_sched_migration_cost,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
302 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100303 {
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_nr_migrate",
306 .data = &sysctl_sched_nr_migrate,
307 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100308 .mode = 0644,
309 .proc_handler = &proc_dointvec,
310 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200311#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200312 {
313 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100314 .procname = "sched_rt_period_us",
315 .data = &sysctl_sched_rt_period,
316 .maxlen = sizeof(unsigned int),
317 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200318 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100319 },
320 {
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_rt_runtime_us",
323 .data = &sysctl_sched_rt_runtime,
324 .maxlen = sizeof(int),
325 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200326 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100327 },
328 {
329 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200330 .procname = "sched_compat_yield",
331 .data = &sysctl_sched_compat_yield,
332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
334 .proc_handler = &proc_dointvec,
335 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700336#ifdef CONFIG_PROVE_LOCKING
337 {
338 .ctl_name = CTL_UNNUMBERED,
339 .procname = "prove_locking",
340 .data = &prove_locking,
341 .maxlen = sizeof(int),
342 .mode = 0644,
343 .proc_handler = &proc_dointvec,
344 },
345#endif
346#ifdef CONFIG_LOCK_STAT
347 {
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "lock_stat",
350 .data = &lock_stat,
351 .maxlen = sizeof(int),
352 .mode = 0644,
353 .proc_handler = &proc_dointvec,
354 },
355#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200356 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 .ctl_name = KERN_PANIC,
358 .procname = "panic",
359 .data = &panic_timeout,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
364 {
365 .ctl_name = KERN_CORE_USES_PID,
366 .procname = "core_uses_pid",
367 .data = &core_uses_pid,
368 .maxlen = sizeof(int),
369 .mode = 0644,
370 .proc_handler = &proc_dointvec,
371 },
372 {
373 .ctl_name = KERN_CORE_PATTERN,
374 .procname = "core_pattern",
375 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700376 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 .mode = 0644,
378 .proc_handler = &proc_dostring,
379 .strategy = &sysctl_string,
380 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800381#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 .procname = "tainted",
384 .data = &tainted,
385 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800386 .mode = 0644,
387 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800389#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100390#ifdef CONFIG_LATENCYTOP
391 {
392 .procname = "latencytop",
393 .data = &latencytop_enabled,
394 .maxlen = sizeof(int),
395 .mode = 0644,
396 .proc_handler = &proc_dointvec,
397 },
398#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#ifdef CONFIG_BLK_DEV_INITRD
400 {
401 .ctl_name = KERN_REALROOTDEV,
402 .procname = "real-root-dev",
403 .data = &real_root_dev,
404 .maxlen = sizeof(int),
405 .mode = 0644,
406 .proc_handler = &proc_dointvec,
407 },
408#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700409 {
410 .ctl_name = CTL_UNNUMBERED,
411 .procname = "print-fatal-signals",
412 .data = &print_fatal_signals,
413 .maxlen = sizeof(int),
414 .mode = 0644,
415 .proc_handler = &proc_dointvec,
416 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417#ifdef __sparc__
418 {
419 .ctl_name = KERN_SPARC_REBOOT,
420 .procname = "reboot-cmd",
421 .data = reboot_command,
422 .maxlen = 256,
423 .mode = 0644,
424 .proc_handler = &proc_dostring,
425 .strategy = &sysctl_string,
426 },
427 {
428 .ctl_name = KERN_SPARC_STOP_A,
429 .procname = "stop-a",
430 .data = &stop_a_enabled,
431 .maxlen = sizeof (int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
435 {
436 .ctl_name = KERN_SPARC_SCONS_PWROFF,
437 .procname = "scons-poweroff",
438 .data = &scons_pwroff,
439 .maxlen = sizeof (int),
440 .mode = 0644,
441 .proc_handler = &proc_dointvec,
442 },
443#endif
444#ifdef __hppa__
445 {
446 .ctl_name = KERN_HPPA_PWRSW,
447 .procname = "soft-power",
448 .data = &pwrsw_enabled,
449 .maxlen = sizeof (int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec,
452 },
453 {
454 .ctl_name = KERN_HPPA_UNALIGNED,
455 .procname = "unaligned-trap",
456 .data = &unaligned_enabled,
457 .maxlen = sizeof (int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
460 },
461#endif
462 {
463 .ctl_name = KERN_CTLALTDEL,
464 .procname = "ctrl-alt-del",
465 .data = &C_A_D,
466 .maxlen = sizeof(int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
469 },
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200470#ifdef CONFIG_FTRACE
471 {
472 .ctl_name = CTL_UNNUMBERED,
473 .procname = "ftrace_enabled",
474 .data = &ftrace_enabled,
475 .maxlen = sizeof(int),
476 .mode = 0644,
477 .proc_handler = &ftrace_enable_sysctl,
478 },
479#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200480#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 {
482 .ctl_name = KERN_MODPROBE,
483 .procname = "modprobe",
484 .data = &modprobe_path,
485 .maxlen = KMOD_PATH_LEN,
486 .mode = 0644,
487 .proc_handler = &proc_dostring,
488 .strategy = &sysctl_string,
489 },
490#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700491#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 {
493 .ctl_name = KERN_HOTPLUG,
494 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100495 .data = &uevent_helper,
496 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 .mode = 0644,
498 .proc_handler = &proc_dostring,
499 .strategy = &sysctl_string,
500 },
501#endif
502#ifdef CONFIG_CHR_DEV_SG
503 {
504 .ctl_name = KERN_SG_BIG_BUFF,
505 .procname = "sg-big-buff",
506 .data = &sg_big_buff,
507 .maxlen = sizeof (int),
508 .mode = 0444,
509 .proc_handler = &proc_dointvec,
510 },
511#endif
512#ifdef CONFIG_BSD_PROCESS_ACCT
513 {
514 .ctl_name = KERN_ACCT,
515 .procname = "acct",
516 .data = &acct_parm,
517 .maxlen = 3*sizeof(int),
518 .mode = 0644,
519 .proc_handler = &proc_dointvec,
520 },
521#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#ifdef CONFIG_MAGIC_SYSRQ
523 {
524 .ctl_name = KERN_SYSRQ,
525 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800526 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 .maxlen = sizeof (int),
528 .mode = 0644,
529 .proc_handler = &proc_dointvec,
530 },
531#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700532#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700535 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 .maxlen = sizeof (int),
537 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700538 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700540#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 {
542 .ctl_name = KERN_MAX_THREADS,
543 .procname = "threads-max",
544 .data = &max_threads,
545 .maxlen = sizeof(int),
546 .mode = 0644,
547 .proc_handler = &proc_dointvec,
548 },
549 {
550 .ctl_name = KERN_RANDOM,
551 .procname = "random",
552 .mode = 0555,
553 .child = random_table,
554 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 {
556 .ctl_name = KERN_OVERFLOWUID,
557 .procname = "overflowuid",
558 .data = &overflowuid,
559 .maxlen = sizeof(int),
560 .mode = 0644,
561 .proc_handler = &proc_dointvec_minmax,
562 .strategy = &sysctl_intvec,
563 .extra1 = &minolduid,
564 .extra2 = &maxolduid,
565 },
566 {
567 .ctl_name = KERN_OVERFLOWGID,
568 .procname = "overflowgid",
569 .data = &overflowgid,
570 .maxlen = sizeof(int),
571 .mode = 0644,
572 .proc_handler = &proc_dointvec_minmax,
573 .strategy = &sysctl_intvec,
574 .extra1 = &minolduid,
575 .extra2 = &maxolduid,
576 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800577#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578#ifdef CONFIG_MATHEMU
579 {
580 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
581 .procname = "ieee_emulation_warnings",
582 .data = &sysctl_ieee_emulation_warnings,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec,
586 },
587#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 {
589 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
590 .procname = "userprocess_debug",
591 .data = &sysctl_userprocess_debug,
592 .maxlen = sizeof(int),
593 .mode = 0644,
594 .proc_handler = &proc_dointvec,
595 },
596#endif
597 {
598 .ctl_name = KERN_PIDMAX,
599 .procname = "pid_max",
600 .data = &pid_max,
601 .maxlen = sizeof (int),
602 .mode = 0644,
603 .proc_handler = &proc_dointvec_minmax,
604 .strategy = sysctl_intvec,
605 .extra1 = &pid_max_min,
606 .extra2 = &pid_max_max,
607 },
608 {
609 .ctl_name = KERN_PANIC_ON_OOPS,
610 .procname = "panic_on_oops",
611 .data = &panic_on_oops,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec,
615 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800616#if defined CONFIG_PRINTK
617 {
618 .ctl_name = KERN_PRINTK,
619 .procname = "printk",
620 .data = &console_loglevel,
621 .maxlen = 4*sizeof(int),
622 .mode = 0644,
623 .proc_handler = &proc_dointvec,
624 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 {
626 .ctl_name = KERN_PRINTK_RATELIMIT,
627 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700628 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = &proc_dointvec_jiffies,
632 .strategy = &sysctl_jiffies,
633 },
634 {
635 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
636 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700637 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 .maxlen = sizeof(int),
639 .mode = 0644,
640 .proc_handler = &proc_dointvec,
641 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800642#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 {
644 .ctl_name = KERN_NGROUPS_MAX,
645 .procname = "ngroups_max",
646 .data = &ngroups_max,
647 .maxlen = sizeof (int),
648 .mode = 0444,
649 .proc_handler = &proc_dointvec,
650 },
651#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
652 {
653 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
654 .procname = "unknown_nmi_panic",
655 .data = &unknown_nmi_panic,
656 .maxlen = sizeof (int),
657 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200658 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 },
Don Zickus407984f2006-09-26 10:52:27 +0200660 {
Don Zickus407984f2006-09-26 10:52:27 +0200661 .procname = "nmi_watchdog",
662 .data = &nmi_watchdog_enabled,
663 .maxlen = sizeof (int),
664 .mode = 0644,
665 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 },
667#endif
668#if defined(CONFIG_X86)
669 {
Don Zickus8da5adda2006-09-26 10:52:27 +0200670 .ctl_name = KERN_PANIC_ON_NMI,
671 .procname = "panic_on_unrecovered_nmi",
672 .data = &panic_on_unrecovered_nmi,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = &proc_dointvec,
676 },
677 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 .ctl_name = KERN_BOOTLOADER_TYPE,
679 .procname = "bootloader_type",
680 .data = &bootloader_type,
681 .maxlen = sizeof (int),
682 .mode = 0444,
683 .proc_handler = &proc_dointvec,
684 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100685 {
686 .ctl_name = CTL_UNNUMBERED,
687 .procname = "kstack_depth_to_print",
688 .data = &kstack_depth_to_print,
689 .maxlen = sizeof(int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec,
692 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100693 {
694 .ctl_name = CTL_UNNUMBERED,
695 .procname = "io_delay_type",
696 .data = &io_delay_type,
697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec,
700 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800702#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 {
704 .ctl_name = KERN_RANDOMIZE,
705 .procname = "randomize_va_space",
706 .data = &randomize_va_space,
707 .maxlen = sizeof(int),
708 .mode = 0644,
709 .proc_handler = &proc_dointvec,
710 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800711#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800712#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700713 {
714 .ctl_name = KERN_SPIN_RETRY,
715 .procname = "spin_retry",
716 .data = &spin_retry,
717 .maxlen = sizeof (int),
718 .mode = 0644,
719 .proc_handler = &proc_dointvec,
720 },
721#endif
Len Brown673d5b42007-07-28 03:33:16 -0400722#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800723 {
Pavel Machekc255d842006-02-20 18:27:58 -0800724 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700725 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800726 .maxlen = sizeof (unsigned long),
727 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800728 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800729 },
730#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800731#ifdef CONFIG_IA64
732 {
733 .ctl_name = KERN_IA64_UNALIGNED,
734 .procname = "ignore-unaligned-usertrap",
735 .data = &no_unaligned_warning,
736 .maxlen = sizeof (int),
737 .mode = 0644,
738 .proc_handler = &proc_dointvec,
739 },
740#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700741#ifdef CONFIG_DETECT_SOFTLOCKUP
742 {
743 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200744 .procname = "softlockup_panic",
745 .data = &softlockup_panic,
746 .maxlen = sizeof(int),
747 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700748 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200749 .strategy = &sysctl_intvec,
750 .extra1 = &zero,
751 .extra2 = &one,
752 },
753 {
754 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700755 .procname = "softlockup_thresh",
756 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200757 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700758 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200759 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700760 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200761 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700762 .extra2 = &sixty,
763 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100764 {
765 .ctl_name = CTL_UNNUMBERED,
766 .procname = "hung_task_check_count",
767 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100768 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100769 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100770 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100771 .strategy = &sysctl_intvec,
772 },
773 {
774 .ctl_name = CTL_UNNUMBERED,
775 .procname = "hung_task_timeout_secs",
776 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100777 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100778 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100779 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100780 .strategy = &sysctl_intvec,
781 },
782 {
783 .ctl_name = CTL_UNNUMBERED,
784 .procname = "hung_task_warnings",
785 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100786 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100787 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100788 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100789 .strategy = &sysctl_intvec,
790 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700791#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200792#ifdef CONFIG_COMPAT
793 {
794 .ctl_name = KERN_COMPAT_LOG,
795 .procname = "compat-log",
796 .data = &compat_log,
797 .maxlen = sizeof (int),
798 .mode = 0644,
799 .proc_handler = &proc_dointvec,
800 },
801#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700802#ifdef CONFIG_RT_MUTEXES
803 {
804 .ctl_name = KERN_MAX_LOCK_DEPTH,
805 .procname = "max_lock_depth",
806 .data = &max_lock_depth,
807 .maxlen = sizeof(int),
808 .mode = 0644,
809 .proc_handler = &proc_dointvec,
810 },
811#endif
Kees Cook5096add2007-05-08 00:26:04 -0700812#ifdef CONFIG_PROC_FS
813 {
814 .ctl_name = CTL_UNNUMBERED,
815 .procname = "maps_protect",
816 .data = &maps_protect,
817 .maxlen = sizeof(int),
818 .mode = 0644,
819 .proc_handler = &proc_dointvec,
820 },
821#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700822 {
823 .ctl_name = CTL_UNNUMBERED,
824 .procname = "poweroff_cmd",
825 .data = &poweroff_cmd,
826 .maxlen = POWEROFF_CMD_PATH_LEN,
827 .mode = 0644,
828 .proc_handler = &proc_dostring,
829 .strategy = &sysctl_string,
830 },
David Howells0b77f5b2008-04-29 01:01:32 -0700831#ifdef CONFIG_KEYS
832 {
833 .ctl_name = CTL_UNNUMBERED,
834 .procname = "keys",
835 .mode = 0555,
836 .child = key_sysctls,
837 },
838#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700839#ifdef CONFIG_RCU_TORTURE_TEST
840 {
841 .ctl_name = CTL_UNNUMBERED,
842 .procname = "rcutorture_runnable",
843 .data = &rcutorture_runnable,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec,
847 },
848#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700849/*
850 * NOTE: do not add new entries to this table unless you have read
851 * Documentation/sysctl/ctl_unnumbered.txt
852 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 { .ctl_name = 0 }
854};
855
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700856static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 {
858 .ctl_name = VM_OVERCOMMIT_MEMORY,
859 .procname = "overcommit_memory",
860 .data = &sysctl_overcommit_memory,
861 .maxlen = sizeof(sysctl_overcommit_memory),
862 .mode = 0644,
863 .proc_handler = &proc_dointvec,
864 },
865 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700866 .ctl_name = VM_PANIC_ON_OOM,
867 .procname = "panic_on_oom",
868 .data = &sysctl_panic_on_oom,
869 .maxlen = sizeof(sysctl_panic_on_oom),
870 .mode = 0644,
871 .proc_handler = &proc_dointvec,
872 },
873 {
David Rientjesfe071d72007-10-16 23:25:56 -0700874 .ctl_name = CTL_UNNUMBERED,
875 .procname = "oom_kill_allocating_task",
876 .data = &sysctl_oom_kill_allocating_task,
877 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec,
880 },
881 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800882 .ctl_name = CTL_UNNUMBERED,
883 .procname = "oom_dump_tasks",
884 .data = &sysctl_oom_dump_tasks,
885 .maxlen = sizeof(sysctl_oom_dump_tasks),
886 .mode = 0644,
887 .proc_handler = &proc_dointvec,
888 },
889 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 .ctl_name = VM_OVERCOMMIT_RATIO,
891 .procname = "overcommit_ratio",
892 .data = &sysctl_overcommit_ratio,
893 .maxlen = sizeof(sysctl_overcommit_ratio),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec,
896 },
897 {
898 .ctl_name = VM_PAGE_CLUSTER,
899 .procname = "page-cluster",
900 .data = &page_cluster,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = &proc_dointvec,
904 },
905 {
906 .ctl_name = VM_DIRTY_BACKGROUND,
907 .procname = "dirty_background_ratio",
908 .data = &dirty_background_ratio,
909 .maxlen = sizeof(dirty_background_ratio),
910 .mode = 0644,
911 .proc_handler = &proc_dointvec_minmax,
912 .strategy = &sysctl_intvec,
913 .extra1 = &zero,
914 .extra2 = &one_hundred,
915 },
916 {
917 .ctl_name = VM_DIRTY_RATIO,
918 .procname = "dirty_ratio",
919 .data = &vm_dirty_ratio,
920 .maxlen = sizeof(vm_dirty_ratio),
921 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700922 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 .strategy = &sysctl_intvec,
924 .extra1 = &zero,
925 .extra2 = &one_hundred,
926 },
927 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800929 .data = &dirty_writeback_interval,
930 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 .mode = 0644,
932 .proc_handler = &dirty_writeback_centisecs_handler,
933 },
934 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800936 .data = &dirty_expire_interval,
937 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800939 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 },
941 {
942 .ctl_name = VM_NR_PDFLUSH_THREADS,
943 .procname = "nr_pdflush_threads",
944 .data = &nr_pdflush_threads,
945 .maxlen = sizeof nr_pdflush_threads,
946 .mode = 0444 /* read-only*/,
947 .proc_handler = &proc_dointvec,
948 },
949 {
950 .ctl_name = VM_SWAPPINESS,
951 .procname = "swappiness",
952 .data = &vm_swappiness,
953 .maxlen = sizeof(vm_swappiness),
954 .mode = 0644,
955 .proc_handler = &proc_dointvec_minmax,
956 .strategy = &sysctl_intvec,
957 .extra1 = &zero,
958 .extra2 = &one_hundred,
959 },
960#ifdef CONFIG_HUGETLB_PAGE
961 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700963 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 .maxlen = sizeof(unsigned long),
965 .mode = 0644,
966 .proc_handler = &hugetlb_sysctl_handler,
967 .extra1 = (void *)&hugetlb_zero,
968 .extra2 = (void *)&hugetlb_infinity,
969 },
970 {
971 .ctl_name = VM_HUGETLB_GROUP,
972 .procname = "hugetlb_shm_group",
973 .data = &sysctl_hugetlb_shm_group,
974 .maxlen = sizeof(gid_t),
975 .mode = 0644,
976 .proc_handler = &proc_dointvec,
977 },
Mel Gorman396faf02007-07-17 04:03:13 -0700978 {
979 .ctl_name = CTL_UNNUMBERED,
980 .procname = "hugepages_treat_as_movable",
981 .data = &hugepages_treat_as_movable,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = &hugetlb_treat_movable_handler,
985 },
Adam Litke54f9f802007-10-16 01:26:20 -0700986 {
987 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800988 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700989 .data = NULL,
990 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800991 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800992 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -0700993 .extra1 = (void *)&hugetlb_zero,
994 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800995 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996#endif
997 {
998 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
999 .procname = "lowmem_reserve_ratio",
1000 .data = &sysctl_lowmem_reserve_ratio,
1001 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1002 .mode = 0644,
1003 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1004 .strategy = &sysctl_intvec,
1005 },
1006 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001007 .ctl_name = VM_DROP_PAGECACHE,
1008 .procname = "drop_caches",
1009 .data = &sysctl_drop_caches,
1010 .maxlen = sizeof(int),
1011 .mode = 0644,
1012 .proc_handler = drop_caches_sysctl_handler,
1013 .strategy = &sysctl_intvec,
1014 },
1015 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 .ctl_name = VM_MIN_FREE_KBYTES,
1017 .procname = "min_free_kbytes",
1018 .data = &min_free_kbytes,
1019 .maxlen = sizeof(min_free_kbytes),
1020 .mode = 0644,
1021 .proc_handler = &min_free_kbytes_sysctl_handler,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &zero,
1024 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001025 {
1026 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1027 .procname = "percpu_pagelist_fraction",
1028 .data = &percpu_pagelist_fraction,
1029 .maxlen = sizeof(percpu_pagelist_fraction),
1030 .mode = 0644,
1031 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1032 .strategy = &sysctl_intvec,
1033 .extra1 = &min_percpu_pagelist_fract,
1034 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035#ifdef CONFIG_MMU
1036 {
1037 .ctl_name = VM_MAX_MAP_COUNT,
1038 .procname = "max_map_count",
1039 .data = &sysctl_max_map_count,
1040 .maxlen = sizeof(sysctl_max_map_count),
1041 .mode = 0644,
1042 .proc_handler = &proc_dointvec
1043 },
1044#endif
1045 {
1046 .ctl_name = VM_LAPTOP_MODE,
1047 .procname = "laptop_mode",
1048 .data = &laptop_mode,
1049 .maxlen = sizeof(laptop_mode),
1050 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001051 .proc_handler = &proc_dointvec_jiffies,
1052 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 },
1054 {
1055 .ctl_name = VM_BLOCK_DUMP,
1056 .procname = "block_dump",
1057 .data = &block_dump,
1058 .maxlen = sizeof(block_dump),
1059 .mode = 0644,
1060 .proc_handler = &proc_dointvec,
1061 .strategy = &sysctl_intvec,
1062 .extra1 = &zero,
1063 },
1064 {
1065 .ctl_name = VM_VFS_CACHE_PRESSURE,
1066 .procname = "vfs_cache_pressure",
1067 .data = &sysctl_vfs_cache_pressure,
1068 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1069 .mode = 0644,
1070 .proc_handler = &proc_dointvec,
1071 .strategy = &sysctl_intvec,
1072 .extra1 = &zero,
1073 },
1074#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1075 {
1076 .ctl_name = VM_LEGACY_VA_LAYOUT,
1077 .procname = "legacy_va_layout",
1078 .data = &sysctl_legacy_va_layout,
1079 .maxlen = sizeof(sysctl_legacy_va_layout),
1080 .mode = 0644,
1081 .proc_handler = &proc_dointvec,
1082 .strategy = &sysctl_intvec,
1083 .extra1 = &zero,
1084 },
1085#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001086#ifdef CONFIG_NUMA
1087 {
1088 .ctl_name = VM_ZONE_RECLAIM_MODE,
1089 .procname = "zone_reclaim_mode",
1090 .data = &zone_reclaim_mode,
1091 .maxlen = sizeof(zone_reclaim_mode),
1092 .mode = 0644,
1093 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001094 .strategy = &sysctl_intvec,
1095 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001096 },
Christoph Lameter96146342006-07-03 00:24:13 -07001097 {
1098 .ctl_name = VM_MIN_UNMAPPED,
1099 .procname = "min_unmapped_ratio",
1100 .data = &sysctl_min_unmapped_ratio,
1101 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1102 .mode = 0644,
1103 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1104 .strategy = &sysctl_intvec,
1105 .extra1 = &zero,
1106 .extra2 = &one_hundred,
1107 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001108 {
1109 .ctl_name = VM_MIN_SLAB,
1110 .procname = "min_slab_ratio",
1111 .data = &sysctl_min_slab_ratio,
1112 .maxlen = sizeof(sysctl_min_slab_ratio),
1113 .mode = 0644,
1114 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1115 .strategy = &sysctl_intvec,
1116 .extra1 = &zero,
1117 .extra2 = &one_hundred,
1118 },
Christoph Lameter17436602006-01-18 17:42:32 -08001119#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001120#ifdef CONFIG_SMP
1121 {
1122 .ctl_name = CTL_UNNUMBERED,
1123 .procname = "stat_interval",
1124 .data = &sysctl_stat_interval,
1125 .maxlen = sizeof(sysctl_stat_interval),
1126 .mode = 0644,
1127 .proc_handler = &proc_dointvec_jiffies,
1128 .strategy = &sysctl_jiffies,
1129 },
1130#endif
Eric Parised032182007-06-28 15:55:21 -04001131#ifdef CONFIG_SECURITY
1132 {
1133 .ctl_name = CTL_UNNUMBERED,
1134 .procname = "mmap_min_addr",
1135 .data = &mmap_min_addr,
1136 .maxlen = sizeof(unsigned long),
1137 .mode = 0644,
1138 .proc_handler = &proc_doulongvec_minmax,
1139 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001140#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001141#ifdef CONFIG_NUMA
1142 {
1143 .ctl_name = CTL_UNNUMBERED,
1144 .procname = "numa_zonelist_order",
1145 .data = &numa_zonelist_order,
1146 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1147 .mode = 0644,
1148 .proc_handler = &numa_zonelist_order_handler,
1149 .strategy = &sysctl_string,
1150 },
1151#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001152#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001153 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001154 {
1155 .ctl_name = VM_VDSO_ENABLED,
1156 .procname = "vdso_enabled",
1157 .data = &vdso_enabled,
1158 .maxlen = sizeof(vdso_enabled),
1159 .mode = 0644,
1160 .proc_handler = &proc_dointvec,
1161 .strategy = &sysctl_intvec,
1162 .extra1 = &zero,
1163 },
1164#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001165#ifdef CONFIG_HIGHMEM
1166 {
1167 .ctl_name = CTL_UNNUMBERED,
1168 .procname = "highmem_is_dirtyable",
1169 .data = &vm_highmem_is_dirtyable,
1170 .maxlen = sizeof(vm_highmem_is_dirtyable),
1171 .mode = 0644,
1172 .proc_handler = &proc_dointvec_minmax,
1173 .strategy = &sysctl_intvec,
1174 .extra1 = &zero,
1175 .extra2 = &one,
1176 },
1177#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001178/*
1179 * NOTE: do not add new entries to this table unless you have read
1180 * Documentation/sysctl/ctl_unnumbered.txt
1181 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 { .ctl_name = 0 }
1183};
1184
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001185#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001186static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001187 { .ctl_name = 0 }
1188};
1189#endif
1190
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001191static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 {
1193 .ctl_name = FS_NRINODE,
1194 .procname = "inode-nr",
1195 .data = &inodes_stat,
1196 .maxlen = 2*sizeof(int),
1197 .mode = 0444,
1198 .proc_handler = &proc_dointvec,
1199 },
1200 {
1201 .ctl_name = FS_STATINODE,
1202 .procname = "inode-state",
1203 .data = &inodes_stat,
1204 .maxlen = 7*sizeof(int),
1205 .mode = 0444,
1206 .proc_handler = &proc_dointvec,
1207 },
1208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 .procname = "file-nr",
1210 .data = &files_stat,
1211 .maxlen = 3*sizeof(int),
1212 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001213 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 },
1215 {
1216 .ctl_name = FS_MAXFILE,
1217 .procname = "file-max",
1218 .data = &files_stat.max_files,
1219 .maxlen = sizeof(int),
1220 .mode = 0644,
1221 .proc_handler = &proc_dointvec,
1222 },
1223 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001224 .ctl_name = CTL_UNNUMBERED,
1225 .procname = "nr_open",
1226 .data = &sysctl_nr_open,
1227 .maxlen = sizeof(int),
1228 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001229 .proc_handler = &proc_dointvec_minmax,
1230 .extra1 = &sysctl_nr_open_min,
1231 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001232 },
1233 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 .ctl_name = FS_DENTRY,
1235 .procname = "dentry-state",
1236 .data = &dentry_stat,
1237 .maxlen = 6*sizeof(int),
1238 .mode = 0444,
1239 .proc_handler = &proc_dointvec,
1240 },
1241 {
1242 .ctl_name = FS_OVERFLOWUID,
1243 .procname = "overflowuid",
1244 .data = &fs_overflowuid,
1245 .maxlen = sizeof(int),
1246 .mode = 0644,
1247 .proc_handler = &proc_dointvec_minmax,
1248 .strategy = &sysctl_intvec,
1249 .extra1 = &minolduid,
1250 .extra2 = &maxolduid,
1251 },
1252 {
1253 .ctl_name = FS_OVERFLOWGID,
1254 .procname = "overflowgid",
1255 .data = &fs_overflowgid,
1256 .maxlen = sizeof(int),
1257 .mode = 0644,
1258 .proc_handler = &proc_dointvec_minmax,
1259 .strategy = &sysctl_intvec,
1260 .extra1 = &minolduid,
1261 .extra2 = &maxolduid,
1262 },
1263 {
1264 .ctl_name = FS_LEASES,
1265 .procname = "leases-enable",
1266 .data = &leases_enable,
1267 .maxlen = sizeof(int),
1268 .mode = 0644,
1269 .proc_handler = &proc_dointvec,
1270 },
1271#ifdef CONFIG_DNOTIFY
1272 {
1273 .ctl_name = FS_DIR_NOTIFY,
1274 .procname = "dir-notify-enable",
1275 .data = &dir_notify_enable,
1276 .maxlen = sizeof(int),
1277 .mode = 0644,
1278 .proc_handler = &proc_dointvec,
1279 },
1280#endif
1281#ifdef CONFIG_MMU
1282 {
1283 .ctl_name = FS_LEASE_TIME,
1284 .procname = "lease-break-time",
1285 .data = &lease_break_time,
1286 .maxlen = sizeof(int),
1287 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001288 .proc_handler = &proc_dointvec_minmax,
1289 .strategy = &sysctl_intvec,
1290 .extra1 = &zero,
1291 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 },
1293 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 .procname = "aio-nr",
1295 .data = &aio_nr,
1296 .maxlen = sizeof(aio_nr),
1297 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001298 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 },
1300 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 .procname = "aio-max-nr",
1302 .data = &aio_max_nr,
1303 .maxlen = sizeof(aio_max_nr),
1304 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001305 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001307#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001308 {
1309 .ctl_name = FS_INOTIFY,
1310 .procname = "inotify",
1311 .mode = 0555,
1312 .child = inotify_table,
1313 },
1314#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001316 {
1317 .ctl_name = KERN_SETUID_DUMPABLE,
1318 .procname = "suid_dumpable",
1319 .data = &suid_dumpable,
1320 .maxlen = sizeof(int),
1321 .mode = 0644,
1322 .proc_handler = &proc_dointvec,
1323 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001324#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1325 {
1326 .ctl_name = CTL_UNNUMBERED,
1327 .procname = "binfmt_misc",
1328 .mode = 0555,
1329 .child = binfmt_misc_table,
1330 },
1331#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001332/*
1333 * NOTE: do not add new entries to this table unless you have read
1334 * Documentation/sysctl/ctl_unnumbered.txt
1335 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 { .ctl_name = 0 }
1337};
1338
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001339static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001340#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001341 {
1342 .ctl_name = CTL_UNNUMBERED,
1343 .procname = "exception-trace",
1344 .data = &show_unhandled_signals,
1345 .maxlen = sizeof(int),
1346 .mode = 0644,
1347 .proc_handler = proc_dointvec
1348 },
1349#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 { .ctl_name = 0 }
1351};
1352
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001353static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001355};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
Al Viro330d57f2005-11-04 10:18:40 +00001357static DEFINE_SPINLOCK(sysctl_lock);
1358
1359/* called under sysctl_lock */
1360static int use_table(struct ctl_table_header *p)
1361{
1362 if (unlikely(p->unregistering))
1363 return 0;
1364 p->used++;
1365 return 1;
1366}
1367
1368/* called under sysctl_lock */
1369static void unuse_table(struct ctl_table_header *p)
1370{
1371 if (!--p->used)
1372 if (unlikely(p->unregistering))
1373 complete(p->unregistering);
1374}
1375
1376/* called under sysctl_lock, will reacquire if has to wait */
1377static void start_unregistering(struct ctl_table_header *p)
1378{
1379 /*
1380 * if p->used is 0, nobody will ever touch that entry again;
1381 * we'll eliminate all paths to it before dropping sysctl_lock
1382 */
1383 if (unlikely(p->used)) {
1384 struct completion wait;
1385 init_completion(&wait);
1386 p->unregistering = &wait;
1387 spin_unlock(&sysctl_lock);
1388 wait_for_completion(&wait);
1389 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001390 } else {
1391 /* anything non-NULL; we'll never dereference it */
1392 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001393 }
1394 /*
1395 * do not remove from the list until nobody holds it; walking the
1396 * list in do_sysctl() relies on that.
1397 */
1398 list_del_init(&p->ctl_entry);
1399}
1400
Al Virof7e6ced2008-07-15 01:44:23 -04001401void sysctl_head_get(struct ctl_table_header *head)
1402{
1403 spin_lock(&sysctl_lock);
1404 head->count++;
1405 spin_unlock(&sysctl_lock);
1406}
1407
1408void sysctl_head_put(struct ctl_table_header *head)
1409{
1410 spin_lock(&sysctl_lock);
1411 if (!--head->count)
1412 kfree(head);
1413 spin_unlock(&sysctl_lock);
1414}
1415
1416struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1417{
1418 if (!head)
1419 BUG();
1420 spin_lock(&sysctl_lock);
1421 if (!use_table(head))
1422 head = ERR_PTR(-ENOENT);
1423 spin_unlock(&sysctl_lock);
1424 return head;
1425}
1426
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001427void sysctl_head_finish(struct ctl_table_header *head)
1428{
1429 if (!head)
1430 return;
1431 spin_lock(&sysctl_lock);
1432 unuse_table(head);
1433 spin_unlock(&sysctl_lock);
1434}
1435
Al Viro73455092008-07-14 21:22:20 -04001436static struct ctl_table_set *
1437lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1438{
1439 struct ctl_table_set *set = &root->default_set;
1440 if (root->lookup)
1441 set = root->lookup(root, namespaces);
1442 return set;
1443}
1444
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001445static struct list_head *
1446lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001447{
Al Viro73455092008-07-14 21:22:20 -04001448 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1449 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001450}
1451
1452struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1453 struct ctl_table_header *prev)
1454{
1455 struct ctl_table_root *root;
1456 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001457 struct ctl_table_header *head;
1458 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001459
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001460 spin_lock(&sysctl_lock);
1461 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001462 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001463 tmp = &prev->ctl_entry;
1464 unuse_table(prev);
1465 goto next;
1466 }
1467 tmp = &root_table_header.ctl_entry;
1468 for (;;) {
1469 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1470
1471 if (!use_table(head))
1472 goto next;
1473 spin_unlock(&sysctl_lock);
1474 return head;
1475 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001476 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001477 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001478 header_list = lookup_header_list(root, namespaces);
1479 if (tmp != header_list)
1480 continue;
1481
1482 do {
1483 root = list_entry(root->root_list.next,
1484 struct ctl_table_root, root_list);
1485 if (root == &sysctl_table_root)
1486 goto out;
1487 header_list = lookup_header_list(root, namespaces);
1488 } while (list_empty(header_list));
1489 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001490 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001491out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001492 spin_unlock(&sysctl_lock);
1493 return NULL;
1494}
1495
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001496struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1497{
1498 return __sysctl_head_next(current->nsproxy, prev);
1499}
1500
1501void register_sysctl_root(struct ctl_table_root *root)
1502{
1503 spin_lock(&sysctl_lock);
1504 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1505 spin_unlock(&sysctl_lock);
1506}
1507
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001508#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001509/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001510static int do_sysctl_strategy(struct ctl_table_root *root,
1511 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001512 int __user *name, int nlen,
1513 void __user *oldval, size_t __user *oldlenp,
1514 void __user *newval, size_t newlen)
1515{
1516 int op = 0, rc;
1517
1518 if (oldval)
1519 op |= 004;
1520 if (newval)
1521 op |= 002;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001522 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001523 return -EPERM;
1524
1525 if (table->strategy) {
1526 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1527 newval, newlen);
1528 if (rc < 0)
1529 return rc;
1530 if (rc > 0)
1531 return 0;
1532 }
1533
1534 /* If there is no strategy routine, or if the strategy returns
1535 * zero, proceed with automatic r/w */
1536 if (table->data && table->maxlen) {
1537 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1538 newval, newlen);
1539 if (rc < 0)
1540 return rc;
1541 }
1542 return 0;
1543}
1544
1545static int parse_table(int __user *name, int nlen,
1546 void __user *oldval, size_t __user *oldlenp,
1547 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001548 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001549 struct ctl_table *table)
1550{
1551 int n;
1552repeat:
1553 if (!nlen)
1554 return -ENOTDIR;
1555 if (get_user(n, name))
1556 return -EFAULT;
1557 for ( ; table->ctl_name || table->procname; table++) {
1558 if (!table->ctl_name)
1559 continue;
1560 if (n == table->ctl_name) {
1561 int error;
1562 if (table->child) {
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001563 if (sysctl_perm(root, table, 001))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001564 return -EPERM;
1565 name++;
1566 nlen--;
1567 table = table->child;
1568 goto repeat;
1569 }
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001570 error = do_sysctl_strategy(root, table, name, nlen,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001571 oldval, oldlenp,
1572 newval, newlen);
1573 return error;
1574 }
1575 }
1576 return -ENOTDIR;
1577}
1578
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1580 void __user *newval, size_t newlen)
1581{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001582 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001583 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1586 return -ENOTDIR;
1587 if (oldval) {
1588 int old_len;
1589 if (!oldlenp || get_user(old_len, oldlenp))
1590 return -EFAULT;
1591 }
Al Viro330d57f2005-11-04 10:18:40 +00001592
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001593 for (head = sysctl_head_next(NULL); head;
1594 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001595 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001596 newval, newlen,
1597 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001598 if (error != -ENOTDIR) {
1599 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001600 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001601 }
1602 }
Al Viro330d57f2005-11-04 10:18:40 +00001603 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604}
1605
1606asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1607{
1608 struct __sysctl_args tmp;
1609 int error;
1610
1611 if (copy_from_user(&tmp, args, sizeof(tmp)))
1612 return -EFAULT;
1613
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001614 error = deprecated_sysctl_warning(&tmp);
1615 if (error)
1616 goto out;
1617
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 lock_kernel();
1619 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1620 tmp.newval, tmp.newlen);
1621 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001622out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 return error;
1624}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001625#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
1627/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001628 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 * some sysctl variables are readonly even to root.
1630 */
1631
1632static int test_perm(int mode, int op)
1633{
1634 if (!current->euid)
1635 mode >>= 6;
1636 else if (in_egroup_p(0))
1637 mode >>= 3;
1638 if ((mode & op & 0007) == op)
1639 return 0;
1640 return -EACCES;
1641}
1642
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001643int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644{
1645 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001646 int mode;
1647
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 error = security_sysctl(table, op);
1649 if (error)
1650 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001651
1652 if (root->permissions)
1653 mode = root->permissions(root, current->nsproxy, table);
1654 else
1655 mode = table->mode;
1656
1657 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658}
1659
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001660static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1661{
1662 for (; table->ctl_name || table->procname; table++) {
1663 table->parent = parent;
1664 if (table->child)
1665 sysctl_set_parent(table, table->child);
1666 }
1667}
1668
1669static __init int sysctl_init(void)
1670{
1671 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001672#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1673 {
1674 int err;
1675 err = sysctl_check_table(current->nsproxy, root_table);
1676 }
1677#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001678 return 0;
1679}
1680
1681core_initcall(sysctl_init);
1682
Al Viroae7edec2008-07-15 06:33:31 -04001683static int is_branch_in(struct ctl_table *branch, struct ctl_table *table)
1684{
1685 struct ctl_table *p;
1686 const char *s = branch->procname;
1687
1688 /* branch should have named subdirectory as its first element */
1689 if (!s || !branch->child)
1690 return 0;
1691
1692 /* ... and nothing else */
1693 if (branch[1].procname || branch[1].ctl_name)
1694 return 0;
1695
1696 /* table should contain subdirectory with the same name */
1697 for (p = table; p->procname || p->ctl_name; p++) {
1698 if (!p->child)
1699 continue;
1700 if (p->procname && strcmp(p->procname, s) == 0)
1701 return 1;
1702 }
1703 return 0;
1704}
1705
1706/* see if attaching q to p would be an improvement */
1707static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1708{
1709 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1710 int is_better = 0;
1711 int not_in_parent = !p->attached_by;
1712
1713 while (is_branch_in(by, to)) {
1714 if (by == q->attached_by)
1715 is_better = 1;
1716 if (to == p->attached_by)
1717 not_in_parent = 1;
1718 by = by->child;
1719 to = to->child;
1720 }
1721
1722 if (is_better && not_in_parent) {
1723 q->attached_by = by;
1724 q->attached_to = to;
1725 q->parent = p;
1726 }
1727}
1728
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001730 * __register_sysctl_paths - register a sysctl hierarchy
1731 * @root: List of sysctl headers to register on
1732 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001733 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 *
1736 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001737 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001739 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 *
1741 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1742 * must be unique within that level of sysctl
1743 *
1744 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1745 * enter a sysctl file
1746 *
1747 * data - a pointer to data for use by proc_handler
1748 *
1749 * maxlen - the maximum size in bytes of the data
1750 *
1751 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1752 *
1753 * child - a pointer to the child sysctl table if this entry is a directory, or
1754 * %NULL.
1755 *
1756 * proc_handler - the text handler routine (described below)
1757 *
1758 * strategy - the strategy routine (described below)
1759 *
1760 * de - for internal use by the sysctl routines
1761 *
1762 * extra1, extra2 - extra pointers usable by the proc handler routines
1763 *
1764 * Leaf nodes in the sysctl tree will be represented by a single file
1765 * under /proc; non-leaf nodes will be represented by directories.
1766 *
1767 * sysctl(2) can automatically manage read and write requests through
1768 * the sysctl table. The data and maxlen fields of the ctl_table
1769 * struct enable minimal validation of the values being written to be
1770 * performed, and the mode field allows minimal authentication.
1771 *
1772 * More sophisticated management can be enabled by the provision of a
1773 * strategy routine with the table entry. This will be called before
1774 * any automatic read or write of the data is performed.
1775 *
1776 * The strategy routine may return
1777 *
1778 * < 0 - Error occurred (error is passed to user process)
1779 *
1780 * 0 - OK - proceed with automatic read or write.
1781 *
1782 * > 0 - OK - read or write has been done by the strategy routine, so
1783 * return immediately.
1784 *
1785 * There must be a proc_handler routine for any terminal nodes
1786 * mirrored under /proc/sys (non-terminals are handled by a built-in
1787 * directory handler). Several default handlers are available to
1788 * cover common cases -
1789 *
1790 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1791 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1792 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1793 *
1794 * It is the handler's job to read the input buffer from user memory
1795 * and process it. The handler should return 0 on success.
1796 *
1797 * This routine returns %NULL on a failure to register, and a pointer
1798 * to the table header on success.
1799 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001800struct ctl_table_header *__register_sysctl_paths(
1801 struct ctl_table_root *root,
1802 struct nsproxy *namespaces,
1803 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001805 struct ctl_table_header *header;
1806 struct ctl_table *new, **prevp;
1807 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001808 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001809
1810 /* Count the path components */
1811 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1812 ;
1813
1814 /*
1815 * For each path component, allocate a 2-element ctl_table array.
1816 * The first array element will be filled with the sysctl entry
1817 * for this, the second will be the sentinel (ctl_name == 0).
1818 *
1819 * We allocate everything in one go so that we don't have to
1820 * worry about freeing additional memory in unregister_sysctl_table.
1821 */
1822 header = kzalloc(sizeof(struct ctl_table_header) +
1823 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1824 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001826
1827 new = (struct ctl_table *) (header + 1);
1828
1829 /* Now connect the dots */
1830 prevp = &header->ctl_table;
1831 for (n = 0; n < npath; ++n, ++path) {
1832 /* Copy the procname */
1833 new->procname = path->procname;
1834 new->ctl_name = path->ctl_name;
1835 new->mode = 0555;
1836
1837 *prevp = new;
1838 prevp = &new->child;
1839
1840 new += 2;
1841 }
1842 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001843 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001844
1845 INIT_LIST_HEAD(&header->ctl_entry);
1846 header->used = 0;
1847 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001848 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001849 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001850 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001851#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001852 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001853 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001854 return NULL;
1855 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001856#endif
Al Viro330d57f2005-11-04 10:18:40 +00001857 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001858 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001859 header->attached_by = header->ctl_table;
1860 header->attached_to = root_table;
1861 header->parent = &root_table_header;
1862 for (set = header->set; set; set = set->parent) {
1863 struct ctl_table_header *p;
1864 list_for_each_entry(p, &set->list, ctl_entry) {
1865 if (p->unregistering)
1866 continue;
1867 try_attach(p, header);
1868 }
1869 }
1870 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001871 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001872 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001873
1874 return header;
1875}
1876
1877/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001878 * register_sysctl_table_path - register a sysctl table hierarchy
1879 * @path: The path to the directory the sysctl table is in.
1880 * @table: the top-level table structure
1881 *
1882 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1883 * array. A completely 0 filled entry terminates the table.
1884 *
1885 * See __register_sysctl_paths for more details.
1886 */
1887struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1888 struct ctl_table *table)
1889{
1890 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1891 path, table);
1892}
1893
1894/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001895 * register_sysctl_table - register a sysctl table hierarchy
1896 * @table: the top-level table structure
1897 *
1898 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1899 * array. A completely 0 filled entry terminates the table.
1900 *
1901 * See register_sysctl_paths for more details.
1902 */
1903struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1904{
1905 static const struct ctl_path null_path[] = { {} };
1906
1907 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908}
1909
1910/**
1911 * unregister_sysctl_table - unregister a sysctl table hierarchy
1912 * @header: the header returned from register_sysctl_table
1913 *
1914 * Unregisters the sysctl table and all children. proc entries may not
1915 * actually be removed until they are no longer used by anyone.
1916 */
1917void unregister_sysctl_table(struct ctl_table_header * header)
1918{
Al Viro330d57f2005-11-04 10:18:40 +00001919 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001920
1921 if (header == NULL)
1922 return;
1923
Al Viro330d57f2005-11-04 10:18:40 +00001924 spin_lock(&sysctl_lock);
1925 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001926 if (!--header->parent->count) {
1927 WARN_ON(1);
1928 kfree(header->parent);
1929 }
Al Virof7e6ced2008-07-15 01:44:23 -04001930 if (!--header->count)
1931 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001932 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
Al Viro73455092008-07-14 21:22:20 -04001935void setup_sysctl_set(struct ctl_table_set *p,
1936 struct ctl_table_set *parent,
1937 int (*is_seen)(struct ctl_table_set *))
1938{
1939 INIT_LIST_HEAD(&p->list);
1940 p->parent = parent ? parent : &sysctl_table_root.default_set;
1941 p->is_seen = is_seen;
1942}
1943
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001944#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001945struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001946{
1947 return NULL;
1948}
1949
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001950struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1951 struct ctl_table *table)
1952{
1953 return NULL;
1954}
1955
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001956void unregister_sysctl_table(struct ctl_table_header * table)
1957{
1958}
1959
Al Viro73455092008-07-14 21:22:20 -04001960void setup_sysctl_set(struct ctl_table_set *p,
1961 struct ctl_table_set *parent,
1962 int (*is_seen)(struct ctl_table_set *))
1963{
1964}
1965
Al Virof7e6ced2008-07-15 01:44:23 -04001966void sysctl_head_put(struct ctl_table_header *head)
1967{
1968}
1969
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001970#endif /* CONFIG_SYSCTL */
1971
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972/*
1973 * /proc/sys support
1974 */
1975
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001976#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001978static int _proc_do_string(void* data, int maxlen, int write,
1979 struct file *filp, void __user *buffer,
1980 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001981{
1982 size_t len;
1983 char __user *p;
1984 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001985
1986 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001987 *lenp = 0;
1988 return 0;
1989 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001990
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001991 if (write) {
1992 len = 0;
1993 p = buffer;
1994 while (len < *lenp) {
1995 if (get_user(c, p++))
1996 return -EFAULT;
1997 if (c == 0 || c == '\n')
1998 break;
1999 len++;
2000 }
2001 if (len >= maxlen)
2002 len = maxlen-1;
2003 if(copy_from_user(data, buffer, len))
2004 return -EFAULT;
2005 ((char *) data)[len] = 0;
2006 *ppos += *lenp;
2007 } else {
2008 len = strlen(data);
2009 if (len > maxlen)
2010 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002011
2012 if (*ppos > len) {
2013 *lenp = 0;
2014 return 0;
2015 }
2016
2017 data += *ppos;
2018 len -= *ppos;
2019
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002020 if (len > *lenp)
2021 len = *lenp;
2022 if (len)
2023 if(copy_to_user(buffer, data, len))
2024 return -EFAULT;
2025 if (len < *lenp) {
2026 if(put_user('\n', ((char __user *) buffer) + len))
2027 return -EFAULT;
2028 len++;
2029 }
2030 *lenp = len;
2031 *ppos += len;
2032 }
2033 return 0;
2034}
2035
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036/**
2037 * proc_dostring - read a string sysctl
2038 * @table: the sysctl table
2039 * @write: %TRUE if this is a write to the sysctl file
2040 * @filp: the file structure
2041 * @buffer: the user buffer
2042 * @lenp: the size of the user buffer
2043 * @ppos: file position
2044 *
2045 * Reads/writes a string from/to the user buffer. If the kernel
2046 * buffer provided is not large enough to hold the string, the
2047 * string is truncated. The copied string is %NULL-terminated.
2048 * If the string is being read by the user process, it is copied
2049 * and a newline '\n' is added. It is truncated if the buffer is
2050 * not large enough.
2051 *
2052 * Returns 0 on success.
2053 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002054int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 void __user *buffer, size_t *lenp, loff_t *ppos)
2056{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002057 return _proc_do_string(table->data, table->maxlen, write, filp,
2058 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
2062static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2063 int *valp,
2064 int write, void *data)
2065{
2066 if (write) {
2067 *valp = *negp ? -*lvalp : *lvalp;
2068 } else {
2069 int val = *valp;
2070 if (val < 0) {
2071 *negp = -1;
2072 *lvalp = (unsigned long)-val;
2073 } else {
2074 *negp = 0;
2075 *lvalp = (unsigned long)val;
2076 }
2077 }
2078 return 0;
2079}
2080
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002081static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002082 int write, struct file *filp, void __user *buffer,
2083 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2085 int write, void *data),
2086 void *data)
2087{
2088#define TMPBUFLEN 21
2089 int *i, vleft, first=1, neg, val;
2090 unsigned long lval;
2091 size_t left, len;
2092
2093 char buf[TMPBUFLEN], *p;
2094 char __user *s = buffer;
2095
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002096 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 (*ppos && !write)) {
2098 *lenp = 0;
2099 return 0;
2100 }
2101
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002102 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 vleft = table->maxlen / sizeof(*i);
2104 left = *lenp;
2105
2106 if (!conv)
2107 conv = do_proc_dointvec_conv;
2108
2109 for (; left && vleft--; i++, first=0) {
2110 if (write) {
2111 while (left) {
2112 char c;
2113 if (get_user(c, s))
2114 return -EFAULT;
2115 if (!isspace(c))
2116 break;
2117 left--;
2118 s++;
2119 }
2120 if (!left)
2121 break;
2122 neg = 0;
2123 len = left;
2124 if (len > sizeof(buf) - 1)
2125 len = sizeof(buf) - 1;
2126 if (copy_from_user(buf, s, len))
2127 return -EFAULT;
2128 buf[len] = 0;
2129 p = buf;
2130 if (*p == '-' && left > 1) {
2131 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002132 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 }
2134 if (*p < '0' || *p > '9')
2135 break;
2136
2137 lval = simple_strtoul(p, &p, 0);
2138
2139 len = p-buf;
2140 if ((len < left) && *p && !isspace(*p))
2141 break;
2142 if (neg)
2143 val = -val;
2144 s += len;
2145 left -= len;
2146
2147 if (conv(&neg, &lval, i, 1, data))
2148 break;
2149 } else {
2150 p = buf;
2151 if (!first)
2152 *p++ = '\t';
2153
2154 if (conv(&neg, &lval, i, 0, data))
2155 break;
2156
2157 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2158 len = strlen(buf);
2159 if (len > left)
2160 len = left;
2161 if(copy_to_user(s, buf, len))
2162 return -EFAULT;
2163 left -= len;
2164 s += len;
2165 }
2166 }
2167
2168 if (!write && !first && left) {
2169 if(put_user('\n', s))
2170 return -EFAULT;
2171 left--, s++;
2172 }
2173 if (write) {
2174 while (left) {
2175 char c;
2176 if (get_user(c, s++))
2177 return -EFAULT;
2178 if (!isspace(c))
2179 break;
2180 left--;
2181 }
2182 }
2183 if (write && first)
2184 return -EINVAL;
2185 *lenp -= left;
2186 *ppos += *lenp;
2187 return 0;
2188#undef TMPBUFLEN
2189}
2190
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002191static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002192 void __user *buffer, size_t *lenp, loff_t *ppos,
2193 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2194 int write, void *data),
2195 void *data)
2196{
2197 return __do_proc_dointvec(table->data, table, write, filp,
2198 buffer, lenp, ppos, conv, data);
2199}
2200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201/**
2202 * proc_dointvec - read a vector of integers
2203 * @table: the sysctl table
2204 * @write: %TRUE if this is a write to the sysctl file
2205 * @filp: the file structure
2206 * @buffer: the user buffer
2207 * @lenp: the size of the user buffer
2208 * @ppos: file position
2209 *
2210 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2211 * values from/to the user buffer, treated as an ASCII string.
2212 *
2213 * Returns 0 on success.
2214 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002215int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 void __user *buffer, size_t *lenp, loff_t *ppos)
2217{
2218 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2219 NULL,NULL);
2220}
2221
2222#define OP_SET 0
2223#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002224#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
2226static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2227 int *valp,
2228 int write, void *data)
2229{
2230 int op = *(int *)data;
2231 if (write) {
2232 int val = *negp ? -*lvalp : *lvalp;
2233 switch(op) {
2234 case OP_SET: *valp = val; break;
2235 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002236 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 }
2238 } else {
2239 int val = *valp;
2240 if (val < 0) {
2241 *negp = -1;
2242 *lvalp = (unsigned long)-val;
2243 } else {
2244 *negp = 0;
2245 *lvalp = (unsigned long)val;
2246 }
2247 }
2248 return 0;
2249}
2250
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002251/*
2252 * Taint values can only be increased
2253 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002254static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002255 void __user *buffer, size_t *lenp, loff_t *ppos)
2256{
2257 int op;
2258
Bastian Blank91fcd412007-04-23 14:41:14 -07002259 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002260 return -EPERM;
2261
2262 op = OP_OR;
2263 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2264 do_proc_dointvec_bset_conv,&op);
2265}
2266
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267struct do_proc_dointvec_minmax_conv_param {
2268 int *min;
2269 int *max;
2270};
2271
2272static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2273 int *valp,
2274 int write, void *data)
2275{
2276 struct do_proc_dointvec_minmax_conv_param *param = data;
2277 if (write) {
2278 int val = *negp ? -*lvalp : *lvalp;
2279 if ((param->min && *param->min > val) ||
2280 (param->max && *param->max < val))
2281 return -EINVAL;
2282 *valp = val;
2283 } else {
2284 int val = *valp;
2285 if (val < 0) {
2286 *negp = -1;
2287 *lvalp = (unsigned long)-val;
2288 } else {
2289 *negp = 0;
2290 *lvalp = (unsigned long)val;
2291 }
2292 }
2293 return 0;
2294}
2295
2296/**
2297 * proc_dointvec_minmax - read a vector of integers with min/max values
2298 * @table: the sysctl table
2299 * @write: %TRUE if this is a write to the sysctl file
2300 * @filp: the file structure
2301 * @buffer: the user buffer
2302 * @lenp: the size of the user buffer
2303 * @ppos: file position
2304 *
2305 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2306 * values from/to the user buffer, treated as an ASCII string.
2307 *
2308 * This routine will ensure the values are within the range specified by
2309 * table->extra1 (min) and table->extra2 (max).
2310 *
2311 * Returns 0 on success.
2312 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002313int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 void __user *buffer, size_t *lenp, loff_t *ppos)
2315{
2316 struct do_proc_dointvec_minmax_conv_param param = {
2317 .min = (int *) table->extra1,
2318 .max = (int *) table->extra2,
2319 };
2320 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2321 do_proc_dointvec_minmax_conv, &param);
2322}
2323
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002324static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 struct file *filp,
2326 void __user *buffer,
2327 size_t *lenp, loff_t *ppos,
2328 unsigned long convmul,
2329 unsigned long convdiv)
2330{
2331#define TMPBUFLEN 21
2332 unsigned long *i, *min, *max, val;
2333 int vleft, first=1, neg;
2334 size_t len, left;
2335 char buf[TMPBUFLEN], *p;
2336 char __user *s = buffer;
2337
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002338 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 (*ppos && !write)) {
2340 *lenp = 0;
2341 return 0;
2342 }
2343
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002344 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 min = (unsigned long *) table->extra1;
2346 max = (unsigned long *) table->extra2;
2347 vleft = table->maxlen / sizeof(unsigned long);
2348 left = *lenp;
2349
2350 for (; left && vleft--; i++, min++, max++, first=0) {
2351 if (write) {
2352 while (left) {
2353 char c;
2354 if (get_user(c, s))
2355 return -EFAULT;
2356 if (!isspace(c))
2357 break;
2358 left--;
2359 s++;
2360 }
2361 if (!left)
2362 break;
2363 neg = 0;
2364 len = left;
2365 if (len > TMPBUFLEN-1)
2366 len = TMPBUFLEN-1;
2367 if (copy_from_user(buf, s, len))
2368 return -EFAULT;
2369 buf[len] = 0;
2370 p = buf;
2371 if (*p == '-' && left > 1) {
2372 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002373 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 }
2375 if (*p < '0' || *p > '9')
2376 break;
2377 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2378 len = p-buf;
2379 if ((len < left) && *p && !isspace(*p))
2380 break;
2381 if (neg)
2382 val = -val;
2383 s += len;
2384 left -= len;
2385
2386 if(neg)
2387 continue;
2388 if ((min && val < *min) || (max && val > *max))
2389 continue;
2390 *i = val;
2391 } else {
2392 p = buf;
2393 if (!first)
2394 *p++ = '\t';
2395 sprintf(p, "%lu", convdiv * (*i) / convmul);
2396 len = strlen(buf);
2397 if (len > left)
2398 len = left;
2399 if(copy_to_user(s, buf, len))
2400 return -EFAULT;
2401 left -= len;
2402 s += len;
2403 }
2404 }
2405
2406 if (!write && !first && left) {
2407 if(put_user('\n', s))
2408 return -EFAULT;
2409 left--, s++;
2410 }
2411 if (write) {
2412 while (left) {
2413 char c;
2414 if (get_user(c, s++))
2415 return -EFAULT;
2416 if (!isspace(c))
2417 break;
2418 left--;
2419 }
2420 }
2421 if (write && first)
2422 return -EINVAL;
2423 *lenp -= left;
2424 *ppos += *lenp;
2425 return 0;
2426#undef TMPBUFLEN
2427}
2428
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002429static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002430 struct file *filp,
2431 void __user *buffer,
2432 size_t *lenp, loff_t *ppos,
2433 unsigned long convmul,
2434 unsigned long convdiv)
2435{
2436 return __do_proc_doulongvec_minmax(table->data, table, write,
2437 filp, buffer, lenp, ppos, convmul, convdiv);
2438}
2439
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440/**
2441 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @filp: the file structure
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: file position
2448 *
2449 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2450 * values from/to the user buffer, treated as an ASCII string.
2451 *
2452 * This routine will ensure the values are within the range specified by
2453 * table->extra1 (min) and table->extra2 (max).
2454 *
2455 * Returns 0 on success.
2456 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002457int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 void __user *buffer, size_t *lenp, loff_t *ppos)
2459{
2460 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2461}
2462
2463/**
2464 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2465 * @table: the sysctl table
2466 * @write: %TRUE if this is a write to the sysctl file
2467 * @filp: the file structure
2468 * @buffer: the user buffer
2469 * @lenp: the size of the user buffer
2470 * @ppos: file position
2471 *
2472 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2473 * values from/to the user buffer, treated as an ASCII string. The values
2474 * are treated as milliseconds, and converted to jiffies when they are stored.
2475 *
2476 * This routine will ensure the values are within the range specified by
2477 * table->extra1 (min) and table->extra2 (max).
2478 *
2479 * Returns 0 on success.
2480 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002481int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 struct file *filp,
2483 void __user *buffer,
2484 size_t *lenp, loff_t *ppos)
2485{
2486 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2487 lenp, ppos, HZ, 1000l);
2488}
2489
2490
2491static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2492 int *valp,
2493 int write, void *data)
2494{
2495 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002496 if (*lvalp > LONG_MAX / HZ)
2497 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2499 } else {
2500 int val = *valp;
2501 unsigned long lval;
2502 if (val < 0) {
2503 *negp = -1;
2504 lval = (unsigned long)-val;
2505 } else {
2506 *negp = 0;
2507 lval = (unsigned long)val;
2508 }
2509 *lvalp = lval / HZ;
2510 }
2511 return 0;
2512}
2513
2514static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2515 int *valp,
2516 int write, void *data)
2517{
2518 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002519 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2520 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2522 } else {
2523 int val = *valp;
2524 unsigned long lval;
2525 if (val < 0) {
2526 *negp = -1;
2527 lval = (unsigned long)-val;
2528 } else {
2529 *negp = 0;
2530 lval = (unsigned long)val;
2531 }
2532 *lvalp = jiffies_to_clock_t(lval);
2533 }
2534 return 0;
2535}
2536
2537static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2538 int *valp,
2539 int write, void *data)
2540{
2541 if (write) {
2542 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2543 } else {
2544 int val = *valp;
2545 unsigned long lval;
2546 if (val < 0) {
2547 *negp = -1;
2548 lval = (unsigned long)-val;
2549 } else {
2550 *negp = 0;
2551 lval = (unsigned long)val;
2552 }
2553 *lvalp = jiffies_to_msecs(lval);
2554 }
2555 return 0;
2556}
2557
2558/**
2559 * proc_dointvec_jiffies - read a vector of integers as seconds
2560 * @table: the sysctl table
2561 * @write: %TRUE if this is a write to the sysctl file
2562 * @filp: the file structure
2563 * @buffer: the user buffer
2564 * @lenp: the size of the user buffer
2565 * @ppos: file position
2566 *
2567 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2568 * values from/to the user buffer, treated as an ASCII string.
2569 * The values read are assumed to be in seconds, and are converted into
2570 * jiffies.
2571 *
2572 * Returns 0 on success.
2573 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002574int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 void __user *buffer, size_t *lenp, loff_t *ppos)
2576{
2577 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2578 do_proc_dointvec_jiffies_conv,NULL);
2579}
2580
2581/**
2582 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2583 * @table: the sysctl table
2584 * @write: %TRUE if this is a write to the sysctl file
2585 * @filp: the file structure
2586 * @buffer: the user buffer
2587 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002588 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 *
2590 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2591 * values from/to the user buffer, treated as an ASCII string.
2592 * The values read are assumed to be in 1/USER_HZ seconds, and
2593 * are converted into jiffies.
2594 *
2595 * Returns 0 on success.
2596 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002597int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 void __user *buffer, size_t *lenp, loff_t *ppos)
2599{
2600 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2601 do_proc_dointvec_userhz_jiffies_conv,NULL);
2602}
2603
2604/**
2605 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2606 * @table: the sysctl table
2607 * @write: %TRUE if this is a write to the sysctl file
2608 * @filp: the file structure
2609 * @buffer: the user buffer
2610 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002611 * @ppos: file position
2612 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 *
2614 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2615 * values from/to the user buffer, treated as an ASCII string.
2616 * The values read are assumed to be in 1/1000 seconds, and
2617 * are converted into jiffies.
2618 *
2619 * Returns 0 on success.
2620 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002621int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 void __user *buffer, size_t *lenp, loff_t *ppos)
2623{
2624 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2625 do_proc_dointvec_ms_jiffies_conv, NULL);
2626}
2627
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002628static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002629 void __user *buffer, size_t *lenp, loff_t *ppos)
2630{
2631 struct pid *new_pid;
2632 pid_t tmp;
2633 int r;
2634
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002635 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002636
2637 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2638 lenp, ppos, NULL, NULL);
2639 if (r || !write)
2640 return r;
2641
2642 new_pid = find_get_pid(tmp);
2643 if (!new_pid)
2644 return -ESRCH;
2645
2646 put_pid(xchg(&cad_pid, new_pid));
2647 return 0;
2648}
2649
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650#else /* CONFIG_PROC_FS */
2651
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002652int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 void __user *buffer, size_t *lenp, loff_t *ppos)
2654{
2655 return -ENOSYS;
2656}
2657
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002658int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 void __user *buffer, size_t *lenp, loff_t *ppos)
2660{
2661 return -ENOSYS;
2662}
2663
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002664int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 void __user *buffer, size_t *lenp, loff_t *ppos)
2666{
2667 return -ENOSYS;
2668}
2669
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002670int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 void __user *buffer, size_t *lenp, loff_t *ppos)
2672{
2673 return -ENOSYS;
2674}
2675
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002676int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 void __user *buffer, size_t *lenp, loff_t *ppos)
2678{
2679 return -ENOSYS;
2680}
2681
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002682int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 void __user *buffer, size_t *lenp, loff_t *ppos)
2684{
2685 return -ENOSYS;
2686}
2687
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002688int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 void __user *buffer, size_t *lenp, loff_t *ppos)
2690{
2691 return -ENOSYS;
2692}
2693
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002694int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 struct file *filp,
2696 void __user *buffer,
2697 size_t *lenp, loff_t *ppos)
2698{
2699 return -ENOSYS;
2700}
2701
2702
2703#endif /* CONFIG_PROC_FS */
2704
2705
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002706#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707/*
2708 * General sysctl support routines
2709 */
2710
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002711/* The generic sysctl data routine (used if no strategy routine supplied) */
2712int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2713 void __user *oldval, size_t __user *oldlenp,
2714 void __user *newval, size_t newlen)
2715{
2716 size_t len;
2717
2718 /* Get out of I don't have a variable */
2719 if (!table->data || !table->maxlen)
2720 return -ENOTDIR;
2721
2722 if (oldval && oldlenp) {
2723 if (get_user(len, oldlenp))
2724 return -EFAULT;
2725 if (len) {
2726 if (len > table->maxlen)
2727 len = table->maxlen;
2728 if (copy_to_user(oldval, table->data, len))
2729 return -EFAULT;
2730 if (put_user(len, oldlenp))
2731 return -EFAULT;
2732 }
2733 }
2734
2735 if (newval && newlen) {
2736 if (newlen > table->maxlen)
2737 newlen = table->maxlen;
2738
2739 if (copy_from_user(table->data, newval, newlen))
2740 return -EFAULT;
2741 }
2742 return 1;
2743}
2744
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002746int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002748 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 if (!table->data || !table->maxlen)
2751 return -ENOTDIR;
2752
2753 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002754 size_t bufsize;
2755 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002757 if (bufsize) {
2758 size_t len = strlen(table->data), copied;
2759
2760 /* This shouldn't trigger for a well-formed sysctl */
2761 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002763
2764 /* Copy up to a max of bufsize-1 bytes of the string */
2765 copied = (len >= bufsize) ? bufsize - 1 : len;
2766
2767 if (copy_to_user(oldval, table->data, copied) ||
2768 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002770 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 return -EFAULT;
2772 }
2773 }
2774 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002775 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 if (len > table->maxlen)
2777 len = table->maxlen;
2778 if(copy_from_user(table->data, newval, len))
2779 return -EFAULT;
2780 if (len == table->maxlen)
2781 len--;
2782 ((char *) table->data)[len] = 0;
2783 }
Yi Yang82c9df82005-12-30 16:37:10 +08002784 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785}
2786
2787/*
2788 * This function makes sure that all of the integers in the vector
2789 * are between the minimum and maximum values given in the arrays
2790 * table->extra1 and table->extra2, respectively.
2791 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002792int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002794 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795{
2796
2797 if (newval && newlen) {
2798 int __user *vec = (int __user *) newval;
2799 int *min = (int *) table->extra1;
2800 int *max = (int *) table->extra2;
2801 size_t length;
2802 int i;
2803
2804 if (newlen % sizeof(int) != 0)
2805 return -EINVAL;
2806
2807 if (!table->extra1 && !table->extra2)
2808 return 0;
2809
2810 if (newlen > table->maxlen)
2811 newlen = table->maxlen;
2812 length = newlen / sizeof(int);
2813
2814 for (i = 0; i < length; i++) {
2815 int value;
2816 if (get_user(value, vec + i))
2817 return -EFAULT;
2818 if (min && value < min[i])
2819 return -EINVAL;
2820 if (max && value > max[i])
2821 return -EINVAL;
2822 }
2823 }
2824 return 0;
2825}
2826
2827/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002828int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002830 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002832 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002834
2835 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002837 if (olen) {
2838 int val;
2839
2840 if (olen < sizeof(int))
2841 return -EINVAL;
2842
2843 val = *(int *)(table->data) / HZ;
2844 if (put_user(val, (int __user *)oldval))
2845 return -EFAULT;
2846 if (put_user(sizeof(int), oldlenp))
2847 return -EFAULT;
2848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 }
2850 if (newval && newlen) {
2851 int new;
2852 if (newlen != sizeof(int))
2853 return -EINVAL;
2854 if (get_user(new, (int __user *)newval))
2855 return -EFAULT;
2856 *(int *)(table->data) = new*HZ;
2857 }
2858 return 1;
2859}
2860
2861/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002862int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002864 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002866 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002868
2869 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002871 if (olen) {
2872 int val;
2873
2874 if (olen < sizeof(int))
2875 return -EINVAL;
2876
2877 val = jiffies_to_msecs(*(int *)(table->data));
2878 if (put_user(val, (int __user *)oldval))
2879 return -EFAULT;
2880 if (put_user(sizeof(int), oldlenp))
2881 return -EFAULT;
2882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 }
2884 if (newval && newlen) {
2885 int new;
2886 if (newlen != sizeof(int))
2887 return -EINVAL;
2888 if (get_user(new, (int __user *)newval))
2889 return -EFAULT;
2890 *(int *)(table->data) = msecs_to_jiffies(new);
2891 }
2892 return 1;
2893}
2894
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002895
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002896
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002897#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
2899
2900asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2901{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002902 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002903 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002904
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002905 if (copy_from_user(&tmp, args, sizeof(tmp)))
2906 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002907
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002908 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002909
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002910 /* If no error reading the parameters then just -ENOSYS ... */
2911 if (!error)
2912 error = -ENOSYS;
2913
2914 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915}
2916
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002917int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2918 void __user *oldval, size_t __user *oldlenp,
2919 void __user *newval, size_t newlen)
2920{
2921 return -ENOSYS;
2922}
2923
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002924int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002926 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927{
2928 return -ENOSYS;
2929}
2930
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002931int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002933 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934{
2935 return -ENOSYS;
2936}
2937
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002938int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002940 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941{
2942 return -ENOSYS;
2943}
2944
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002945int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002947 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948{
2949 return -ENOSYS;
2950}
2951
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002952#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002954static int deprecated_sysctl_warning(struct __sysctl_args *args)
2955{
2956 static int msg_count;
2957 int name[CTL_MAXNAME];
2958 int i;
2959
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002960 /* Check args->nlen. */
2961 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2962 return -ENOTDIR;
2963
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002964 /* Read in the sysctl name for better debug message logging */
2965 for (i = 0; i < args->nlen; i++)
2966 if (get_user(name[i], args->name + i))
2967 return -EFAULT;
2968
2969 /* Ignore accesses to kernel.version */
2970 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2971 return 0;
2972
2973 if (msg_count < 5) {
2974 msg_count++;
2975 printk(KERN_INFO
2976 "warning: process `%s' used the deprecated sysctl "
2977 "system call with ", current->comm);
2978 for (i = 0; i < args->nlen; i++)
2979 printk("%d.", name[i]);
2980 printk("\n");
2981 }
2982 return 0;
2983}
2984
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985/*
2986 * No sense putting this after each symbol definition, twice,
2987 * exception granted :-)
2988 */
2989EXPORT_SYMBOL(proc_dointvec);
2990EXPORT_SYMBOL(proc_dointvec_jiffies);
2991EXPORT_SYMBOL(proc_dointvec_minmax);
2992EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2993EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2994EXPORT_SYMBOL(proc_dostring);
2995EXPORT_SYMBOL(proc_doulongvec_minmax);
2996EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2997EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002998EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999EXPORT_SYMBOL(sysctl_intvec);
3000EXPORT_SYMBOL(sysctl_jiffies);
3001EXPORT_SYMBOL(sysctl_ms_jiffies);
3002EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003003EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004EXPORT_SYMBOL(unregister_sysctl_table);