blob: 6bb59f707402c6ea456a9f58322e67f5b611f64d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020030#include <linux/kmemcheck.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070032#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010035#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030036#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/sysrq.h>
38#include <linux/highuid.h>
39#include <linux/writeback.h>
40#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070042#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/times.h>
44#include <linux/limits.h>
45#include <linux/dcache.h>
46#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070047#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080048#include <linux/nfs_fs.h>
49#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070050#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020051#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010052#include <linux/slow-work.h>
Peter Zijlstra1ccd1542009-04-09 10:53:45 +020053#include <linux/perf_counter.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55#include <asm/uaccess.h>
56#include <asm/processor.h>
57
Andi Kleen29cbc782006-09-30 01:47:55 +020058#ifdef CONFIG_X86
59#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010060#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010061#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020062#endif
63
Eric W. Biederman7058cb02007-10-18 03:05:58 -070064static int deprecated_sysctl_warning(struct __sysctl_args *args);
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#if defined(CONFIG_SYSCTL)
67
68/* External variables not in a header file. */
69extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070070extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int sysctl_overcommit_memory;
72extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070073extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070074extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080075extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070078extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern int pid_max;
81extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080083extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080084extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020085extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010086extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040087extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000088#ifndef CONFIG_MMU
89extern int sysctl_nr_trim_pages;
90#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070091#ifdef CONFIG_RCU_TORTURE_TEST
92extern int rcutorture_runnable;
93#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Jens Axboe5e605b62009-08-05 09:07:21 +020094extern int blk_iopoll_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080097#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020099static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100#endif
101
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700102static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700103static int __maybe_unused one = 1;
104static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800105static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700106static int one_hundred = 100;
107
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700108/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
109static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
112static int maxolduid = 65535;
113static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800114static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116static int ngroups_max = NGROUPS_MAX;
117
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200118#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700120extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#ifdef CONFIG_CHR_DEV_SG
123extern int sg_big_buff;
124#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
David S. Miller72c57ed2008-09-11 23:29:54 -0700126#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700127#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#endif
129
David S. Miller08714202008-11-16 23:49:24 -0800130#ifdef CONFIG_SPARC64
131extern int sysctl_tsb_ratio;
132#endif
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef __hppa__
135extern int pwrsw_enabled;
136extern int unaligned_enabled;
137#endif
138
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800139#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef CONFIG_MATHEMU
141extern int sysctl_ieee_emulation_warnings;
142#endif
143extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700144extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#endif
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#ifdef CONFIG_BSD_PROCESS_ACCT
148extern int acct_parm[];
149#endif
150
Jes Sorensend2b176e2006-02-28 09:42:23 -0800151#ifdef CONFIG_IA64
152extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800153extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800154#endif
155
Ingo Molnar23f78d42006-06-27 02:54:53 -0700156#ifdef CONFIG_RT_MUTEXES
157extern int max_lock_depth;
158#endif
159
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700160#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700161static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700162 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700163static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800164 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700165#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700166
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700167static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100168static struct ctl_table_root sysctl_table_root;
169static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100170 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100171 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400172 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100173 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400174 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100175};
176static struct ctl_table_root sysctl_table_root = {
177 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400178 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100179};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700181static struct ctl_table kern_table[];
182static struct ctl_table vm_table[];
183static struct ctl_table fs_table[];
184static struct ctl_table debug_table[];
185static struct ctl_table dev_table[];
186extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700187#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700188extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400189#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800190#ifdef CONFIG_EPOLL
191extern struct ctl_table epoll_table[];
192#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
195int sysctl_legacy_va_layout;
196#endif
197
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700198extern int prove_locking;
199extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/* The default sysctl tables: */
202
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700203static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 {
205 .ctl_name = CTL_KERN,
206 .procname = "kernel",
207 .mode = 0555,
208 .child = kern_table,
209 },
210 {
211 .ctl_name = CTL_VM,
212 .procname = "vm",
213 .mode = 0555,
214 .child = vm_table,
215 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 .ctl_name = CTL_FS,
218 .procname = "fs",
219 .mode = 0555,
220 .child = fs_table,
221 },
222 {
223 .ctl_name = CTL_DEBUG,
224 .procname = "debug",
225 .mode = 0555,
226 .child = debug_table,
227 },
228 {
229 .ctl_name = CTL_DEV,
230 .procname = "dev",
231 .mode = 0555,
232 .child = dev_table,
233 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700234/*
235 * NOTE: do not add new entries to this table unless you have read
236 * Documentation/sysctl/ctl_unnumbered.txt
237 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 { .ctl_name = 0 }
239};
240
Ingo Molnar77e54a12007-07-09 18:52:00 +0200241#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100242static int min_sched_granularity_ns = 100000; /* 100 usecs */
243static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
244static int min_wakeup_granularity_ns; /* 0 usecs */
245static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200246#endif
247
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700248static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200249 {
250 .ctl_name = CTL_UNNUMBERED,
251 .procname = "sched_child_runs_first",
252 .data = &sysctl_sched_child_runs_first,
253 .maxlen = sizeof(unsigned int),
254 .mode = 0644,
255 .proc_handler = &proc_dointvec,
256 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200257#ifdef CONFIG_SCHED_DEBUG
258 {
259 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100260 .procname = "sched_min_granularity_ns",
261 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200262 .maxlen = sizeof(unsigned int),
263 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100264 .proc_handler = &sched_nr_latency_handler,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_sched_granularity_ns,
267 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200268 },
269 {
270 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200271 .procname = "sched_latency_ns",
272 .data = &sysctl_sched_latency,
273 .maxlen = sizeof(unsigned int),
274 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100275 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200276 .strategy = &sysctl_intvec,
277 .extra1 = &min_sched_granularity_ns,
278 .extra2 = &max_sched_granularity_ns,
279 },
280 {
281 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200282 .procname = "sched_wakeup_granularity_ns",
283 .data = &sysctl_sched_wakeup_granularity,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec_minmax,
287 .strategy = &sysctl_intvec,
288 .extra1 = &min_wakeup_granularity_ns,
289 .extra2 = &max_wakeup_granularity_ns,
290 },
291 {
292 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200293 .procname = "sched_shares_ratelimit",
294 .data = &sysctl_sched_shares_ratelimit,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
297 .proc_handler = &proc_dointvec,
298 },
299 {
300 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200301 .procname = "sched_shares_thresh",
302 .data = &sysctl_sched_shares_thresh,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = &proc_dointvec_minmax,
306 .strategy = &sysctl_intvec,
307 .extra1 = &zero,
308 },
309 {
310 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200311 .procname = "sched_features",
312 .data = &sysctl_sched_features,
313 .maxlen = sizeof(unsigned int),
314 .mode = 0644,
315 .proc_handler = &proc_dointvec,
316 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200317 {
318 .ctl_name = CTL_UNNUMBERED,
319 .procname = "sched_migration_cost",
320 .data = &sysctl_sched_migration_cost,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
323 .proc_handler = &proc_dointvec,
324 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100325 {
326 .ctl_name = CTL_UNNUMBERED,
327 .procname = "sched_nr_migrate",
328 .data = &sysctl_sched_nr_migrate,
329 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100330 .mode = 0644,
331 .proc_handler = &proc_dointvec,
332 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530333 {
334 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200335 .procname = "sched_time_avg",
336 .data = &sysctl_sched_time_avg,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341 {
342 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530343 .procname = "timer_migration",
344 .data = &sysctl_timer_migration,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530347 .proc_handler = &proc_dointvec_minmax,
348 .strategy = &sysctl_intvec,
349 .extra1 = &zero,
350 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530351 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200352#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200353 {
354 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100355 .procname = "sched_rt_period_us",
356 .data = &sysctl_sched_rt_period,
357 .maxlen = sizeof(unsigned int),
358 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200359 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100360 },
361 {
362 .ctl_name = CTL_UNNUMBERED,
363 .procname = "sched_rt_runtime_us",
364 .data = &sysctl_sched_rt_runtime,
365 .maxlen = sizeof(int),
366 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200367 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100368 },
369 {
370 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200371 .procname = "sched_compat_yield",
372 .data = &sysctl_sched_compat_yield,
373 .maxlen = sizeof(unsigned int),
374 .mode = 0644,
375 .proc_handler = &proc_dointvec,
376 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700377#ifdef CONFIG_PROVE_LOCKING
378 {
379 .ctl_name = CTL_UNNUMBERED,
380 .procname = "prove_locking",
381 .data = &prove_locking,
382 .maxlen = sizeof(int),
383 .mode = 0644,
384 .proc_handler = &proc_dointvec,
385 },
386#endif
387#ifdef CONFIG_LOCK_STAT
388 {
389 .ctl_name = CTL_UNNUMBERED,
390 .procname = "lock_stat",
391 .data = &lock_stat,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = &proc_dointvec,
395 },
396#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .ctl_name = KERN_PANIC,
399 .procname = "panic",
400 .data = &panic_timeout,
401 .maxlen = sizeof(int),
402 .mode = 0644,
403 .proc_handler = &proc_dointvec,
404 },
405 {
406 .ctl_name = KERN_CORE_USES_PID,
407 .procname = "core_uses_pid",
408 .data = &core_uses_pid,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
412 },
413 {
414 .ctl_name = KERN_CORE_PATTERN,
415 .procname = "core_pattern",
416 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700417 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .mode = 0644,
419 .proc_handler = &proc_dostring,
420 .strategy = &sysctl_string,
421 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800422#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700425 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800426 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700427 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800429#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100430#ifdef CONFIG_LATENCYTOP
431 {
432 .procname = "latencytop",
433 .data = &latencytop_enabled,
434 .maxlen = sizeof(int),
435 .mode = 0644,
436 .proc_handler = &proc_dointvec,
437 },
438#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#ifdef CONFIG_BLK_DEV_INITRD
440 {
441 .ctl_name = KERN_REALROOTDEV,
442 .procname = "real-root-dev",
443 .data = &real_root_dev,
444 .maxlen = sizeof(int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
447 },
448#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700449 {
450 .ctl_name = CTL_UNNUMBERED,
451 .procname = "print-fatal-signals",
452 .data = &print_fatal_signals,
453 .maxlen = sizeof(int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
456 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700457#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 {
459 .ctl_name = KERN_SPARC_REBOOT,
460 .procname = "reboot-cmd",
461 .data = reboot_command,
462 .maxlen = 256,
463 .mode = 0644,
464 .proc_handler = &proc_dostring,
465 .strategy = &sysctl_string,
466 },
467 {
468 .ctl_name = KERN_SPARC_STOP_A,
469 .procname = "stop-a",
470 .data = &stop_a_enabled,
471 .maxlen = sizeof (int),
472 .mode = 0644,
473 .proc_handler = &proc_dointvec,
474 },
475 {
476 .ctl_name = KERN_SPARC_SCONS_PWROFF,
477 .procname = "scons-poweroff",
478 .data = &scons_pwroff,
479 .maxlen = sizeof (int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
482 },
483#endif
David S. Miller08714202008-11-16 23:49:24 -0800484#ifdef CONFIG_SPARC64
485 {
486 .ctl_name = CTL_UNNUMBERED,
487 .procname = "tsb-ratio",
488 .data = &sysctl_tsb_ratio,
489 .maxlen = sizeof (int),
490 .mode = 0644,
491 .proc_handler = &proc_dointvec,
492 },
493#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494#ifdef __hppa__
495 {
496 .ctl_name = KERN_HPPA_PWRSW,
497 .procname = "soft-power",
498 .data = &pwrsw_enabled,
499 .maxlen = sizeof (int),
500 .mode = 0644,
501 .proc_handler = &proc_dointvec,
502 },
503 {
504 .ctl_name = KERN_HPPA_UNALIGNED,
505 .procname = "unaligned-trap",
506 .data = &unaligned_enabled,
507 .maxlen = sizeof (int),
508 .mode = 0644,
509 .proc_handler = &proc_dointvec,
510 },
511#endif
512 {
513 .ctl_name = KERN_CTLALTDEL,
514 .procname = "ctrl-alt-del",
515 .data = &C_A_D,
516 .maxlen = sizeof(int),
517 .mode = 0644,
518 .proc_handler = &proc_dointvec,
519 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400520#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200521 {
522 .ctl_name = CTL_UNNUMBERED,
523 .procname = "ftrace_enabled",
524 .data = &ftrace_enabled,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = &ftrace_enable_sysctl,
528 },
529#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500530#ifdef CONFIG_STACK_TRACER
531 {
532 .ctl_name = CTL_UNNUMBERED,
533 .procname = "stack_tracer_enabled",
534 .data = &stack_tracer_enabled,
535 .maxlen = sizeof(int),
536 .mode = 0644,
537 .proc_handler = &stack_trace_sysctl,
538 },
539#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400540#ifdef CONFIG_TRACING
541 {
542 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100543 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400544 .data = &ftrace_dump_on_oops,
545 .maxlen = sizeof(int),
546 .mode = 0644,
547 .proc_handler = &proc_dointvec,
548 },
549#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200550#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 {
552 .ctl_name = KERN_MODPROBE,
553 .procname = "modprobe",
554 .data = &modprobe_path,
555 .maxlen = KMOD_PATH_LEN,
556 .mode = 0644,
557 .proc_handler = &proc_dostring,
558 .strategy = &sysctl_string,
559 },
Kees Cook3d433212009-04-02 15:49:29 -0700560 {
561 .ctl_name = CTL_UNNUMBERED,
562 .procname = "modules_disabled",
563 .data = &modules_disabled,
564 .maxlen = sizeof(int),
565 .mode = 0644,
566 /* only handle a transition from default "0" to "1" */
567 .proc_handler = &proc_dointvec_minmax,
568 .extra1 = &one,
569 .extra2 = &one,
570 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700572#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 {
574 .ctl_name = KERN_HOTPLUG,
575 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100576 .data = &uevent_helper,
577 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 .mode = 0644,
579 .proc_handler = &proc_dostring,
580 .strategy = &sysctl_string,
581 },
582#endif
583#ifdef CONFIG_CHR_DEV_SG
584 {
585 .ctl_name = KERN_SG_BIG_BUFF,
586 .procname = "sg-big-buff",
587 .data = &sg_big_buff,
588 .maxlen = sizeof (int),
589 .mode = 0444,
590 .proc_handler = &proc_dointvec,
591 },
592#endif
593#ifdef CONFIG_BSD_PROCESS_ACCT
594 {
595 .ctl_name = KERN_ACCT,
596 .procname = "acct",
597 .data = &acct_parm,
598 .maxlen = 3*sizeof(int),
599 .mode = 0644,
600 .proc_handler = &proc_dointvec,
601 },
602#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#ifdef CONFIG_MAGIC_SYSRQ
604 {
605 .ctl_name = KERN_SYSRQ,
606 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800607 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .maxlen = sizeof (int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec,
611 },
612#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700613#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700616 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 .maxlen = sizeof (int),
618 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700619 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700621#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 {
623 .ctl_name = KERN_MAX_THREADS,
624 .procname = "threads-max",
625 .data = &max_threads,
626 .maxlen = sizeof(int),
627 .mode = 0644,
628 .proc_handler = &proc_dointvec,
629 },
630 {
631 .ctl_name = KERN_RANDOM,
632 .procname = "random",
633 .mode = 0555,
634 .child = random_table,
635 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 {
637 .ctl_name = KERN_OVERFLOWUID,
638 .procname = "overflowuid",
639 .data = &overflowuid,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec_minmax,
643 .strategy = &sysctl_intvec,
644 .extra1 = &minolduid,
645 .extra2 = &maxolduid,
646 },
647 {
648 .ctl_name = KERN_OVERFLOWGID,
649 .procname = "overflowgid",
650 .data = &overflowgid,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec_minmax,
654 .strategy = &sysctl_intvec,
655 .extra1 = &minolduid,
656 .extra2 = &maxolduid,
657 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800658#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#ifdef CONFIG_MATHEMU
660 {
661 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
662 .procname = "ieee_emulation_warnings",
663 .data = &sysctl_ieee_emulation_warnings,
664 .maxlen = sizeof(int),
665 .mode = 0644,
666 .proc_handler = &proc_dointvec,
667 },
668#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 {
670 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
671 .procname = "userprocess_debug",
672 .data = &sysctl_userprocess_debug,
673 .maxlen = sizeof(int),
674 .mode = 0644,
675 .proc_handler = &proc_dointvec,
676 },
677#endif
678 {
679 .ctl_name = KERN_PIDMAX,
680 .procname = "pid_max",
681 .data = &pid_max,
682 .maxlen = sizeof (int),
683 .mode = 0644,
684 .proc_handler = &proc_dointvec_minmax,
685 .strategy = sysctl_intvec,
686 .extra1 = &pid_max_min,
687 .extra2 = &pid_max_max,
688 },
689 {
690 .ctl_name = KERN_PANIC_ON_OOPS,
691 .procname = "panic_on_oops",
692 .data = &panic_on_oops,
693 .maxlen = sizeof(int),
694 .mode = 0644,
695 .proc_handler = &proc_dointvec,
696 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800697#if defined CONFIG_PRINTK
698 {
699 .ctl_name = KERN_PRINTK,
700 .procname = "printk",
701 .data = &console_loglevel,
702 .maxlen = 4*sizeof(int),
703 .mode = 0644,
704 .proc_handler = &proc_dointvec,
705 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 {
707 .ctl_name = KERN_PRINTK_RATELIMIT,
708 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700709 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec_jiffies,
713 .strategy = &sysctl_jiffies,
714 },
715 {
716 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
717 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700718 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
722 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800723#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 {
725 .ctl_name = KERN_NGROUPS_MAX,
726 .procname = "ngroups_max",
727 .data = &ngroups_max,
728 .maxlen = sizeof (int),
729 .mode = 0444,
730 .proc_handler = &proc_dointvec,
731 },
732#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
733 {
734 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
735 .procname = "unknown_nmi_panic",
736 .data = &unknown_nmi_panic,
737 .maxlen = sizeof (int),
738 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200739 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 },
Don Zickus407984f2006-09-26 10:52:27 +0200741 {
Don Zickus407984f2006-09-26 10:52:27 +0200742 .procname = "nmi_watchdog",
743 .data = &nmi_watchdog_enabled,
744 .maxlen = sizeof (int),
745 .mode = 0644,
746 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 },
748#endif
749#if defined(CONFIG_X86)
750 {
Don Zickus8da5add2006-09-26 10:52:27 +0200751 .ctl_name = KERN_PANIC_ON_NMI,
752 .procname = "panic_on_unrecovered_nmi",
753 .data = &panic_on_unrecovered_nmi,
754 .maxlen = sizeof(int),
755 .mode = 0644,
756 .proc_handler = &proc_dointvec,
757 },
758 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700759 .ctl_name = CTL_UNNUMBERED,
760 .procname = "panic_on_io_nmi",
761 .data = &panic_on_io_nmi,
762 .maxlen = sizeof(int),
763 .mode = 0644,
764 .proc_handler = &proc_dointvec,
765 },
766 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 .ctl_name = KERN_BOOTLOADER_TYPE,
768 .procname = "bootloader_type",
769 .data = &bootloader_type,
770 .maxlen = sizeof (int),
771 .mode = 0444,
772 .proc_handler = &proc_dointvec,
773 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100774 {
775 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700776 .procname = "bootloader_version",
777 .data = &bootloader_version,
778 .maxlen = sizeof (int),
779 .mode = 0444,
780 .proc_handler = &proc_dointvec,
781 },
782 {
783 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100784 .procname = "kstack_depth_to_print",
785 .data = &kstack_depth_to_print,
786 .maxlen = sizeof(int),
787 .mode = 0644,
788 .proc_handler = &proc_dointvec,
789 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100790 {
791 .ctl_name = CTL_UNNUMBERED,
792 .procname = "io_delay_type",
793 .data = &io_delay_type,
794 .maxlen = sizeof(int),
795 .mode = 0644,
796 .proc_handler = &proc_dointvec,
797 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800799#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 {
801 .ctl_name = KERN_RANDOMIZE,
802 .procname = "randomize_va_space",
803 .data = &randomize_va_space,
804 .maxlen = sizeof(int),
805 .mode = 0644,
806 .proc_handler = &proc_dointvec,
807 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800808#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800809#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700810 {
811 .ctl_name = KERN_SPIN_RETRY,
812 .procname = "spin_retry",
813 .data = &spin_retry,
814 .maxlen = sizeof (int),
815 .mode = 0644,
816 .proc_handler = &proc_dointvec,
817 },
818#endif
Len Brown673d5b42007-07-28 03:33:16 -0400819#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800820 {
Pavel Machekc255d842006-02-20 18:27:58 -0800821 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700822 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800823 .maxlen = sizeof (unsigned long),
824 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800825 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800826 },
827#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800828#ifdef CONFIG_IA64
829 {
830 .ctl_name = KERN_IA64_UNALIGNED,
831 .procname = "ignore-unaligned-usertrap",
832 .data = &no_unaligned_warning,
833 .maxlen = sizeof (int),
834 .mode = 0644,
835 .proc_handler = &proc_dointvec,
836 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800837 {
838 .ctl_name = CTL_UNNUMBERED,
839 .procname = "unaligned-dump-stack",
840 .data = &unaligned_dump_stack,
841 .maxlen = sizeof (int),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
844 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800845#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700846#ifdef CONFIG_DETECT_SOFTLOCKUP
847 {
848 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200849 .procname = "softlockup_panic",
850 .data = &softlockup_panic,
851 .maxlen = sizeof(int),
852 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700853 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200854 .strategy = &sysctl_intvec,
855 .extra1 = &zero,
856 .extra2 = &one,
857 },
858 {
859 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700860 .procname = "softlockup_thresh",
861 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200862 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700863 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800864 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700865 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200866 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700867 .extra2 = &sixty,
868 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800869#endif
870#ifdef CONFIG_DETECT_HUNG_TASK
871 {
872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "hung_task_panic",
874 .data = &sysctl_hung_task_panic,
875 .maxlen = sizeof(int),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec_minmax,
878 .strategy = &sysctl_intvec,
879 .extra1 = &zero,
880 .extra2 = &one,
881 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100882 {
883 .ctl_name = CTL_UNNUMBERED,
884 .procname = "hung_task_check_count",
885 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100886 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100887 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100888 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100889 .strategy = &sysctl_intvec,
890 },
891 {
892 .ctl_name = CTL_UNNUMBERED,
893 .procname = "hung_task_timeout_secs",
894 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100895 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100896 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800897 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100898 .strategy = &sysctl_intvec,
899 },
900 {
901 .ctl_name = CTL_UNNUMBERED,
902 .procname = "hung_task_warnings",
903 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100904 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100905 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100906 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100907 .strategy = &sysctl_intvec,
908 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700909#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200910#ifdef CONFIG_COMPAT
911 {
912 .ctl_name = KERN_COMPAT_LOG,
913 .procname = "compat-log",
914 .data = &compat_log,
915 .maxlen = sizeof (int),
916 .mode = 0644,
917 .proc_handler = &proc_dointvec,
918 },
919#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700920#ifdef CONFIG_RT_MUTEXES
921 {
922 .ctl_name = KERN_MAX_LOCK_DEPTH,
923 .procname = "max_lock_depth",
924 .data = &max_lock_depth,
925 .maxlen = sizeof(int),
926 .mode = 0644,
927 .proc_handler = &proc_dointvec,
928 },
929#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700930 {
931 .ctl_name = CTL_UNNUMBERED,
932 .procname = "poweroff_cmd",
933 .data = &poweroff_cmd,
934 .maxlen = POWEROFF_CMD_PATH_LEN,
935 .mode = 0644,
936 .proc_handler = &proc_dostring,
937 .strategy = &sysctl_string,
938 },
David Howells0b77f5b2008-04-29 01:01:32 -0700939#ifdef CONFIG_KEYS
940 {
941 .ctl_name = CTL_UNNUMBERED,
942 .procname = "keys",
943 .mode = 0555,
944 .child = key_sysctls,
945 },
946#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700947#ifdef CONFIG_RCU_TORTURE_TEST
948 {
949 .ctl_name = CTL_UNNUMBERED,
950 .procname = "rcutorture_runnable",
951 .data = &rcutorture_runnable,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
955 },
956#endif
David Howells12e22c52009-04-03 16:42:35 +0100957#ifdef CONFIG_SLOW_WORK
958 {
959 .ctl_name = CTL_UNNUMBERED,
960 .procname = "slow-work",
961 .mode = 0555,
962 .child = slow_work_sysctls,
963 },
964#endif
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200965#ifdef CONFIG_PERF_COUNTERS
966 {
967 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra07647712009-06-11 11:18:36 +0200968 .procname = "perf_counter_paranoid",
969 .data = &sysctl_perf_counter_paranoid,
970 .maxlen = sizeof(sysctl_perf_counter_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200971 .mode = 0644,
972 .proc_handler = &proc_dointvec,
973 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200974 {
975 .ctl_name = CTL_UNNUMBERED,
976 .procname = "perf_counter_mlock_kb",
977 .data = &sysctl_perf_counter_mlock,
978 .maxlen = sizeof(sysctl_perf_counter_mlock),
979 .mode = 0644,
980 .proc_handler = &proc_dointvec,
981 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200982 {
983 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstradf58ab22009-06-11 11:25:05 +0200984 .procname = "perf_counter_max_sample_rate",
985 .data = &sysctl_perf_counter_sample_rate,
986 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200987 .mode = 0644,
988 .proc_handler = &proc_dointvec,
989 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200990#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200991#ifdef CONFIG_KMEMCHECK
992 {
993 .ctl_name = CTL_UNNUMBERED,
994 .procname = "kmemcheck",
995 .data = &kmemcheck_enabled,
996 .maxlen = sizeof(int),
997 .mode = 0644,
998 .proc_handler = &proc_dointvec,
999 },
1000#endif
Jens Axboe5e605b62009-08-05 09:07:21 +02001001 {
1002 .ctl_name = CTL_UNNUMBERED,
1003 .procname = "blk_iopoll",
1004 .data = &blk_iopoll_enabled,
1005 .maxlen = sizeof(int),
1006 .mode = 0644,
1007 .proc_handler = &proc_dointvec,
1008 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001009/*
1010 * NOTE: do not add new entries to this table unless you have read
1011 * Documentation/sysctl/ctl_unnumbered.txt
1012 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 { .ctl_name = 0 }
1014};
1015
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001016static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 {
1018 .ctl_name = VM_OVERCOMMIT_MEMORY,
1019 .procname = "overcommit_memory",
1020 .data = &sysctl_overcommit_memory,
1021 .maxlen = sizeof(sysctl_overcommit_memory),
1022 .mode = 0644,
1023 .proc_handler = &proc_dointvec,
1024 },
1025 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001026 .ctl_name = VM_PANIC_ON_OOM,
1027 .procname = "panic_on_oom",
1028 .data = &sysctl_panic_on_oom,
1029 .maxlen = sizeof(sysctl_panic_on_oom),
1030 .mode = 0644,
1031 .proc_handler = &proc_dointvec,
1032 },
1033 {
David Rientjesfe071d72007-10-16 23:25:56 -07001034 .ctl_name = CTL_UNNUMBERED,
1035 .procname = "oom_kill_allocating_task",
1036 .data = &sysctl_oom_kill_allocating_task,
1037 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1038 .mode = 0644,
1039 .proc_handler = &proc_dointvec,
1040 },
1041 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001042 .ctl_name = CTL_UNNUMBERED,
1043 .procname = "oom_dump_tasks",
1044 .data = &sysctl_oom_dump_tasks,
1045 .maxlen = sizeof(sysctl_oom_dump_tasks),
1046 .mode = 0644,
1047 .proc_handler = &proc_dointvec,
1048 },
1049 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 .ctl_name = VM_OVERCOMMIT_RATIO,
1051 .procname = "overcommit_ratio",
1052 .data = &sysctl_overcommit_ratio,
1053 .maxlen = sizeof(sysctl_overcommit_ratio),
1054 .mode = 0644,
1055 .proc_handler = &proc_dointvec,
1056 },
1057 {
1058 .ctl_name = VM_PAGE_CLUSTER,
1059 .procname = "page-cluster",
1060 .data = &page_cluster,
1061 .maxlen = sizeof(int),
1062 .mode = 0644,
1063 .proc_handler = &proc_dointvec,
1064 },
1065 {
1066 .ctl_name = VM_DIRTY_BACKGROUND,
1067 .procname = "dirty_background_ratio",
1068 .data = &dirty_background_ratio,
1069 .maxlen = sizeof(dirty_background_ratio),
1070 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001071 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 .strategy = &sysctl_intvec,
1073 .extra1 = &zero,
1074 .extra2 = &one_hundred,
1075 },
1076 {
David Rientjes2da02992009-01-06 14:39:31 -08001077 .ctl_name = CTL_UNNUMBERED,
1078 .procname = "dirty_background_bytes",
1079 .data = &dirty_background_bytes,
1080 .maxlen = sizeof(dirty_background_bytes),
1081 .mode = 0644,
1082 .proc_handler = &dirty_background_bytes_handler,
1083 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001084 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001085 },
1086 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 .ctl_name = VM_DIRTY_RATIO,
1088 .procname = "dirty_ratio",
1089 .data = &vm_dirty_ratio,
1090 .maxlen = sizeof(vm_dirty_ratio),
1091 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001092 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 .strategy = &sysctl_intvec,
1094 .extra1 = &zero,
1095 .extra2 = &one_hundred,
1096 },
1097 {
David Rientjes2da02992009-01-06 14:39:31 -08001098 .ctl_name = CTL_UNNUMBERED,
1099 .procname = "dirty_bytes",
1100 .data = &vm_dirty_bytes,
1101 .maxlen = sizeof(vm_dirty_bytes),
1102 .mode = 0644,
1103 .proc_handler = &dirty_bytes_handler,
1104 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001105 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001106 },
1107 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001109 .data = &dirty_writeback_interval,
1110 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 .mode = 0644,
1112 .proc_handler = &dirty_writeback_centisecs_handler,
1113 },
1114 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001116 .data = &dirty_expire_interval,
1117 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001119 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 },
1121 {
1122 .ctl_name = VM_NR_PDFLUSH_THREADS,
1123 .procname = "nr_pdflush_threads",
1124 .data = &nr_pdflush_threads,
1125 .maxlen = sizeof nr_pdflush_threads,
1126 .mode = 0444 /* read-only*/,
1127 .proc_handler = &proc_dointvec,
1128 },
1129 {
1130 .ctl_name = VM_SWAPPINESS,
1131 .procname = "swappiness",
1132 .data = &vm_swappiness,
1133 .maxlen = sizeof(vm_swappiness),
1134 .mode = 0644,
1135 .proc_handler = &proc_dointvec_minmax,
1136 .strategy = &sysctl_intvec,
1137 .extra1 = &zero,
1138 .extra2 = &one_hundred,
1139 },
1140#ifdef CONFIG_HUGETLB_PAGE
1141 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001143 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 .maxlen = sizeof(unsigned long),
1145 .mode = 0644,
1146 .proc_handler = &hugetlb_sysctl_handler,
1147 .extra1 = (void *)&hugetlb_zero,
1148 .extra2 = (void *)&hugetlb_infinity,
1149 },
1150 {
1151 .ctl_name = VM_HUGETLB_GROUP,
1152 .procname = "hugetlb_shm_group",
1153 .data = &sysctl_hugetlb_shm_group,
1154 .maxlen = sizeof(gid_t),
1155 .mode = 0644,
1156 .proc_handler = &proc_dointvec,
1157 },
Mel Gorman396faf02007-07-17 04:03:13 -07001158 {
1159 .ctl_name = CTL_UNNUMBERED,
1160 .procname = "hugepages_treat_as_movable",
1161 .data = &hugepages_treat_as_movable,
1162 .maxlen = sizeof(int),
1163 .mode = 0644,
1164 .proc_handler = &hugetlb_treat_movable_handler,
1165 },
Adam Litke54f9f802007-10-16 01:26:20 -07001166 {
1167 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001168 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001169 .data = NULL,
1170 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001171 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001172 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001173 .extra1 = (void *)&hugetlb_zero,
1174 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001175 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176#endif
1177 {
1178 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1179 .procname = "lowmem_reserve_ratio",
1180 .data = &sysctl_lowmem_reserve_ratio,
1181 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1182 .mode = 0644,
1183 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1184 .strategy = &sysctl_intvec,
1185 },
1186 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001187 .ctl_name = VM_DROP_PAGECACHE,
1188 .procname = "drop_caches",
1189 .data = &sysctl_drop_caches,
1190 .maxlen = sizeof(int),
1191 .mode = 0644,
1192 .proc_handler = drop_caches_sysctl_handler,
1193 .strategy = &sysctl_intvec,
1194 },
1195 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 .ctl_name = VM_MIN_FREE_KBYTES,
1197 .procname = "min_free_kbytes",
1198 .data = &min_free_kbytes,
1199 .maxlen = sizeof(min_free_kbytes),
1200 .mode = 0644,
1201 .proc_handler = &min_free_kbytes_sysctl_handler,
1202 .strategy = &sysctl_intvec,
1203 .extra1 = &zero,
1204 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001205 {
1206 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1207 .procname = "percpu_pagelist_fraction",
1208 .data = &percpu_pagelist_fraction,
1209 .maxlen = sizeof(percpu_pagelist_fraction),
1210 .mode = 0644,
1211 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1212 .strategy = &sysctl_intvec,
1213 .extra1 = &min_percpu_pagelist_fract,
1214 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215#ifdef CONFIG_MMU
1216 {
1217 .ctl_name = VM_MAX_MAP_COUNT,
1218 .procname = "max_map_count",
1219 .data = &sysctl_max_map_count,
1220 .maxlen = sizeof(sysctl_max_map_count),
1221 .mode = 0644,
1222 .proc_handler = &proc_dointvec
1223 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001224#else
1225 {
1226 .ctl_name = CTL_UNNUMBERED,
1227 .procname = "nr_trim_pages",
1228 .data = &sysctl_nr_trim_pages,
1229 .maxlen = sizeof(sysctl_nr_trim_pages),
1230 .mode = 0644,
1231 .proc_handler = &proc_dointvec_minmax,
1232 .strategy = &sysctl_intvec,
1233 .extra1 = &zero,
1234 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235#endif
1236 {
1237 .ctl_name = VM_LAPTOP_MODE,
1238 .procname = "laptop_mode",
1239 .data = &laptop_mode,
1240 .maxlen = sizeof(laptop_mode),
1241 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001242 .proc_handler = &proc_dointvec_jiffies,
1243 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 },
1245 {
1246 .ctl_name = VM_BLOCK_DUMP,
1247 .procname = "block_dump",
1248 .data = &block_dump,
1249 .maxlen = sizeof(block_dump),
1250 .mode = 0644,
1251 .proc_handler = &proc_dointvec,
1252 .strategy = &sysctl_intvec,
1253 .extra1 = &zero,
1254 },
1255 {
1256 .ctl_name = VM_VFS_CACHE_PRESSURE,
1257 .procname = "vfs_cache_pressure",
1258 .data = &sysctl_vfs_cache_pressure,
1259 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1260 .mode = 0644,
1261 .proc_handler = &proc_dointvec,
1262 .strategy = &sysctl_intvec,
1263 .extra1 = &zero,
1264 },
1265#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1266 {
1267 .ctl_name = VM_LEGACY_VA_LAYOUT,
1268 .procname = "legacy_va_layout",
1269 .data = &sysctl_legacy_va_layout,
1270 .maxlen = sizeof(sysctl_legacy_va_layout),
1271 .mode = 0644,
1272 .proc_handler = &proc_dointvec,
1273 .strategy = &sysctl_intvec,
1274 .extra1 = &zero,
1275 },
1276#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001277#ifdef CONFIG_NUMA
1278 {
1279 .ctl_name = VM_ZONE_RECLAIM_MODE,
1280 .procname = "zone_reclaim_mode",
1281 .data = &zone_reclaim_mode,
1282 .maxlen = sizeof(zone_reclaim_mode),
1283 .mode = 0644,
1284 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001285 .strategy = &sysctl_intvec,
1286 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001287 },
Christoph Lameter96146342006-07-03 00:24:13 -07001288 {
1289 .ctl_name = VM_MIN_UNMAPPED,
1290 .procname = "min_unmapped_ratio",
1291 .data = &sysctl_min_unmapped_ratio,
1292 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1293 .mode = 0644,
1294 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1295 .strategy = &sysctl_intvec,
1296 .extra1 = &zero,
1297 .extra2 = &one_hundred,
1298 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001299 {
1300 .ctl_name = VM_MIN_SLAB,
1301 .procname = "min_slab_ratio",
1302 .data = &sysctl_min_slab_ratio,
1303 .maxlen = sizeof(sysctl_min_slab_ratio),
1304 .mode = 0644,
1305 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1306 .strategy = &sysctl_intvec,
1307 .extra1 = &zero,
1308 .extra2 = &one_hundred,
1309 },
Christoph Lameter17436602006-01-18 17:42:32 -08001310#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001311#ifdef CONFIG_SMP
1312 {
1313 .ctl_name = CTL_UNNUMBERED,
1314 .procname = "stat_interval",
1315 .data = &sysctl_stat_interval,
1316 .maxlen = sizeof(sysctl_stat_interval),
1317 .mode = 0644,
1318 .proc_handler = &proc_dointvec_jiffies,
1319 .strategy = &sysctl_jiffies,
1320 },
1321#endif
Eric Parised032182007-06-28 15:55:21 -04001322 {
1323 .ctl_name = CTL_UNNUMBERED,
1324 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001325 .data = &dac_mmap_min_addr,
1326 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001327 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001328 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001329 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001330#ifdef CONFIG_NUMA
1331 {
1332 .ctl_name = CTL_UNNUMBERED,
1333 .procname = "numa_zonelist_order",
1334 .data = &numa_zonelist_order,
1335 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1336 .mode = 0644,
1337 .proc_handler = &numa_zonelist_order_handler,
1338 .strategy = &sysctl_string,
1339 },
1340#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001341#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001342 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001343 {
1344 .ctl_name = VM_VDSO_ENABLED,
1345 .procname = "vdso_enabled",
1346 .data = &vdso_enabled,
1347 .maxlen = sizeof(vdso_enabled),
1348 .mode = 0644,
1349 .proc_handler = &proc_dointvec,
1350 .strategy = &sysctl_intvec,
1351 .extra1 = &zero,
1352 },
1353#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001354#ifdef CONFIG_HIGHMEM
1355 {
1356 .ctl_name = CTL_UNNUMBERED,
1357 .procname = "highmem_is_dirtyable",
1358 .data = &vm_highmem_is_dirtyable,
1359 .maxlen = sizeof(vm_highmem_is_dirtyable),
1360 .mode = 0644,
1361 .proc_handler = &proc_dointvec_minmax,
1362 .strategy = &sysctl_intvec,
1363 .extra1 = &zero,
1364 .extra2 = &one,
1365 },
1366#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001367 {
1368 .ctl_name = CTL_UNNUMBERED,
1369 .procname = "scan_unevictable_pages",
1370 .data = &scan_unevictable_pages,
1371 .maxlen = sizeof(scan_unevictable_pages),
1372 .mode = 0644,
1373 .proc_handler = &scan_unevictable_handler,
1374 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001375/*
1376 * NOTE: do not add new entries to this table unless you have read
1377 * Documentation/sysctl/ctl_unnumbered.txt
1378 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 { .ctl_name = 0 }
1380};
1381
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001382#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001383static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001384 { .ctl_name = 0 }
1385};
1386#endif
1387
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001388static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 {
1390 .ctl_name = FS_NRINODE,
1391 .procname = "inode-nr",
1392 .data = &inodes_stat,
1393 .maxlen = 2*sizeof(int),
1394 .mode = 0444,
1395 .proc_handler = &proc_dointvec,
1396 },
1397 {
1398 .ctl_name = FS_STATINODE,
1399 .procname = "inode-state",
1400 .data = &inodes_stat,
1401 .maxlen = 7*sizeof(int),
1402 .mode = 0444,
1403 .proc_handler = &proc_dointvec,
1404 },
1405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 .procname = "file-nr",
1407 .data = &files_stat,
1408 .maxlen = 3*sizeof(int),
1409 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001410 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 },
1412 {
1413 .ctl_name = FS_MAXFILE,
1414 .procname = "file-max",
1415 .data = &files_stat.max_files,
1416 .maxlen = sizeof(int),
1417 .mode = 0644,
1418 .proc_handler = &proc_dointvec,
1419 },
1420 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001421 .ctl_name = CTL_UNNUMBERED,
1422 .procname = "nr_open",
1423 .data = &sysctl_nr_open,
1424 .maxlen = sizeof(int),
1425 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001426 .proc_handler = &proc_dointvec_minmax,
1427 .extra1 = &sysctl_nr_open_min,
1428 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001429 },
1430 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 .ctl_name = FS_DENTRY,
1432 .procname = "dentry-state",
1433 .data = &dentry_stat,
1434 .maxlen = 6*sizeof(int),
1435 .mode = 0444,
1436 .proc_handler = &proc_dointvec,
1437 },
1438 {
1439 .ctl_name = FS_OVERFLOWUID,
1440 .procname = "overflowuid",
1441 .data = &fs_overflowuid,
1442 .maxlen = sizeof(int),
1443 .mode = 0644,
1444 .proc_handler = &proc_dointvec_minmax,
1445 .strategy = &sysctl_intvec,
1446 .extra1 = &minolduid,
1447 .extra2 = &maxolduid,
1448 },
1449 {
1450 .ctl_name = FS_OVERFLOWGID,
1451 .procname = "overflowgid",
1452 .data = &fs_overflowgid,
1453 .maxlen = sizeof(int),
1454 .mode = 0644,
1455 .proc_handler = &proc_dointvec_minmax,
1456 .strategy = &sysctl_intvec,
1457 .extra1 = &minolduid,
1458 .extra2 = &maxolduid,
1459 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001460#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 {
1462 .ctl_name = FS_LEASES,
1463 .procname = "leases-enable",
1464 .data = &leases_enable,
1465 .maxlen = sizeof(int),
1466 .mode = 0644,
1467 .proc_handler = &proc_dointvec,
1468 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001469#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470#ifdef CONFIG_DNOTIFY
1471 {
1472 .ctl_name = FS_DIR_NOTIFY,
1473 .procname = "dir-notify-enable",
1474 .data = &dir_notify_enable,
1475 .maxlen = sizeof(int),
1476 .mode = 0644,
1477 .proc_handler = &proc_dointvec,
1478 },
1479#endif
1480#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001481#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 {
1483 .ctl_name = FS_LEASE_TIME,
1484 .procname = "lease-break-time",
1485 .data = &lease_break_time,
1486 .maxlen = sizeof(int),
1487 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001488 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001490#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001491#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 .procname = "aio-nr",
1494 .data = &aio_nr,
1495 .maxlen = sizeof(aio_nr),
1496 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001497 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 },
1499 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 .procname = "aio-max-nr",
1501 .data = &aio_max_nr,
1502 .maxlen = sizeof(aio_max_nr),
1503 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001504 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001506#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001507#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001508 {
1509 .ctl_name = FS_INOTIFY,
1510 .procname = "inotify",
1511 .mode = 0555,
1512 .child = inotify_table,
1513 },
1514#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001515#ifdef CONFIG_EPOLL
1516 {
1517 .procname = "epoll",
1518 .mode = 0555,
1519 .child = epoll_table,
1520 },
1521#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001523 {
1524 .ctl_name = KERN_SETUID_DUMPABLE,
1525 .procname = "suid_dumpable",
1526 .data = &suid_dumpable,
1527 .maxlen = sizeof(int),
1528 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001529 .proc_handler = &proc_dointvec_minmax,
1530 .strategy = &sysctl_intvec,
1531 .extra1 = &zero,
1532 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001533 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001534#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1535 {
1536 .ctl_name = CTL_UNNUMBERED,
1537 .procname = "binfmt_misc",
1538 .mode = 0555,
1539 .child = binfmt_misc_table,
1540 },
1541#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001542/*
1543 * NOTE: do not add new entries to this table unless you have read
1544 * Documentation/sysctl/ctl_unnumbered.txt
1545 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 { .ctl_name = 0 }
1547};
1548
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001549static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001550#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001551 {
1552 .ctl_name = CTL_UNNUMBERED,
1553 .procname = "exception-trace",
1554 .data = &show_unhandled_signals,
1555 .maxlen = sizeof(int),
1556 .mode = 0644,
1557 .proc_handler = proc_dointvec
1558 },
1559#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 { .ctl_name = 0 }
1561};
1562
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001563static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001565};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Al Viro330d57f2005-11-04 10:18:40 +00001567static DEFINE_SPINLOCK(sysctl_lock);
1568
1569/* called under sysctl_lock */
1570static int use_table(struct ctl_table_header *p)
1571{
1572 if (unlikely(p->unregistering))
1573 return 0;
1574 p->used++;
1575 return 1;
1576}
1577
1578/* called under sysctl_lock */
1579static void unuse_table(struct ctl_table_header *p)
1580{
1581 if (!--p->used)
1582 if (unlikely(p->unregistering))
1583 complete(p->unregistering);
1584}
1585
1586/* called under sysctl_lock, will reacquire if has to wait */
1587static void start_unregistering(struct ctl_table_header *p)
1588{
1589 /*
1590 * if p->used is 0, nobody will ever touch that entry again;
1591 * we'll eliminate all paths to it before dropping sysctl_lock
1592 */
1593 if (unlikely(p->used)) {
1594 struct completion wait;
1595 init_completion(&wait);
1596 p->unregistering = &wait;
1597 spin_unlock(&sysctl_lock);
1598 wait_for_completion(&wait);
1599 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001600 } else {
1601 /* anything non-NULL; we'll never dereference it */
1602 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001603 }
1604 /*
1605 * do not remove from the list until nobody holds it; walking the
1606 * list in do_sysctl() relies on that.
1607 */
1608 list_del_init(&p->ctl_entry);
1609}
1610
Al Virof7e6ced2008-07-15 01:44:23 -04001611void sysctl_head_get(struct ctl_table_header *head)
1612{
1613 spin_lock(&sysctl_lock);
1614 head->count++;
1615 spin_unlock(&sysctl_lock);
1616}
1617
1618void sysctl_head_put(struct ctl_table_header *head)
1619{
1620 spin_lock(&sysctl_lock);
1621 if (!--head->count)
1622 kfree(head);
1623 spin_unlock(&sysctl_lock);
1624}
1625
1626struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1627{
1628 if (!head)
1629 BUG();
1630 spin_lock(&sysctl_lock);
1631 if (!use_table(head))
1632 head = ERR_PTR(-ENOENT);
1633 spin_unlock(&sysctl_lock);
1634 return head;
1635}
1636
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001637void sysctl_head_finish(struct ctl_table_header *head)
1638{
1639 if (!head)
1640 return;
1641 spin_lock(&sysctl_lock);
1642 unuse_table(head);
1643 spin_unlock(&sysctl_lock);
1644}
1645
Al Viro73455092008-07-14 21:22:20 -04001646static struct ctl_table_set *
1647lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1648{
1649 struct ctl_table_set *set = &root->default_set;
1650 if (root->lookup)
1651 set = root->lookup(root, namespaces);
1652 return set;
1653}
1654
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001655static struct list_head *
1656lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001657{
Al Viro73455092008-07-14 21:22:20 -04001658 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1659 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001660}
1661
1662struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1663 struct ctl_table_header *prev)
1664{
1665 struct ctl_table_root *root;
1666 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001667 struct ctl_table_header *head;
1668 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001669
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001670 spin_lock(&sysctl_lock);
1671 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001672 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001673 tmp = &prev->ctl_entry;
1674 unuse_table(prev);
1675 goto next;
1676 }
1677 tmp = &root_table_header.ctl_entry;
1678 for (;;) {
1679 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1680
1681 if (!use_table(head))
1682 goto next;
1683 spin_unlock(&sysctl_lock);
1684 return head;
1685 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001686 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001687 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001688 header_list = lookup_header_list(root, namespaces);
1689 if (tmp != header_list)
1690 continue;
1691
1692 do {
1693 root = list_entry(root->root_list.next,
1694 struct ctl_table_root, root_list);
1695 if (root == &sysctl_table_root)
1696 goto out;
1697 header_list = lookup_header_list(root, namespaces);
1698 } while (list_empty(header_list));
1699 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001700 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001701out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001702 spin_unlock(&sysctl_lock);
1703 return NULL;
1704}
1705
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001706struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1707{
1708 return __sysctl_head_next(current->nsproxy, prev);
1709}
1710
1711void register_sysctl_root(struct ctl_table_root *root)
1712{
1713 spin_lock(&sysctl_lock);
1714 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1715 spin_unlock(&sysctl_lock);
1716}
1717
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001718#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001719/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001720static int do_sysctl_strategy(struct ctl_table_root *root,
1721 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001722 void __user *oldval, size_t __user *oldlenp,
1723 void __user *newval, size_t newlen)
1724{
1725 int op = 0, rc;
1726
1727 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001728 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001729 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001730 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001731 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001732 return -EPERM;
1733
1734 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001735 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001736 if (rc < 0)
1737 return rc;
1738 if (rc > 0)
1739 return 0;
1740 }
1741
1742 /* If there is no strategy routine, or if the strategy returns
1743 * zero, proceed with automatic r/w */
1744 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001745 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001746 if (rc < 0)
1747 return rc;
1748 }
1749 return 0;
1750}
1751
1752static int parse_table(int __user *name, int nlen,
1753 void __user *oldval, size_t __user *oldlenp,
1754 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001755 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001756 struct ctl_table *table)
1757{
1758 int n;
1759repeat:
1760 if (!nlen)
1761 return -ENOTDIR;
1762 if (get_user(n, name))
1763 return -EFAULT;
1764 for ( ; table->ctl_name || table->procname; table++) {
1765 if (!table->ctl_name)
1766 continue;
1767 if (n == table->ctl_name) {
1768 int error;
1769 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001770 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001771 return -EPERM;
1772 name++;
1773 nlen--;
1774 table = table->child;
1775 goto repeat;
1776 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001777 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001778 oldval, oldlenp,
1779 newval, newlen);
1780 return error;
1781 }
1782 }
1783 return -ENOTDIR;
1784}
1785
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1787 void __user *newval, size_t newlen)
1788{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001789 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001790 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1793 return -ENOTDIR;
1794 if (oldval) {
1795 int old_len;
1796 if (!oldlenp || get_user(old_len, oldlenp))
1797 return -EFAULT;
1798 }
Al Viro330d57f2005-11-04 10:18:40 +00001799
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001800 for (head = sysctl_head_next(NULL); head;
1801 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001802 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001803 newval, newlen,
1804 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001805 if (error != -ENOTDIR) {
1806 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001807 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001808 }
1809 }
Al Viro330d57f2005-11-04 10:18:40 +00001810 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811}
1812
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001813SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
1815 struct __sysctl_args tmp;
1816 int error;
1817
1818 if (copy_from_user(&tmp, args, sizeof(tmp)))
1819 return -EFAULT;
1820
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001821 error = deprecated_sysctl_warning(&tmp);
1822 if (error)
1823 goto out;
1824
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 lock_kernel();
1826 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1827 tmp.newval, tmp.newlen);
1828 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001829out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 return error;
1831}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001832#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001835 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 * some sysctl variables are readonly even to root.
1837 */
1838
1839static int test_perm(int mode, int op)
1840{
David Howells76aac0e2008-11-14 10:39:12 +11001841 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 mode >>= 6;
1843 else if (in_egroup_p(0))
1844 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001845 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 return 0;
1847 return -EACCES;
1848}
1849
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001850int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851{
1852 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001853 int mode;
1854
Al Viroe6305c42008-07-15 21:03:57 -04001855 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 if (error)
1857 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001858
1859 if (root->permissions)
1860 mode = root->permissions(root, current->nsproxy, table);
1861 else
1862 mode = table->mode;
1863
1864 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865}
1866
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001867static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1868{
1869 for (; table->ctl_name || table->procname; table++) {
1870 table->parent = parent;
1871 if (table->child)
1872 sysctl_set_parent(table, table->child);
1873 }
1874}
1875
1876static __init int sysctl_init(void)
1877{
1878 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001879#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1880 {
1881 int err;
1882 err = sysctl_check_table(current->nsproxy, root_table);
1883 }
1884#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001885 return 0;
1886}
1887
1888core_initcall(sysctl_init);
1889
Al Virobfbcf032008-07-27 06:31:22 +01001890static struct ctl_table *is_branch_in(struct ctl_table *branch,
1891 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001892{
1893 struct ctl_table *p;
1894 const char *s = branch->procname;
1895
1896 /* branch should have named subdirectory as its first element */
1897 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001898 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001899
1900 /* ... and nothing else */
1901 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001902 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001903
1904 /* table should contain subdirectory with the same name */
1905 for (p = table; p->procname || p->ctl_name; p++) {
1906 if (!p->child)
1907 continue;
1908 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001909 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001910 }
Al Virobfbcf032008-07-27 06:31:22 +01001911 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001912}
1913
1914/* see if attaching q to p would be an improvement */
1915static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1916{
1917 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001918 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001919 int is_better = 0;
1920 int not_in_parent = !p->attached_by;
1921
Al Virobfbcf032008-07-27 06:31:22 +01001922 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001923 if (by == q->attached_by)
1924 is_better = 1;
1925 if (to == p->attached_by)
1926 not_in_parent = 1;
1927 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001928 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001929 }
1930
1931 if (is_better && not_in_parent) {
1932 q->attached_by = by;
1933 q->attached_to = to;
1934 q->parent = p;
1935 }
1936}
1937
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001939 * __register_sysctl_paths - register a sysctl hierarchy
1940 * @root: List of sysctl headers to register on
1941 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001942 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 *
1945 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001946 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001948 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 *
1950 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1951 * must be unique within that level of sysctl
1952 *
1953 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1954 * enter a sysctl file
1955 *
1956 * data - a pointer to data for use by proc_handler
1957 *
1958 * maxlen - the maximum size in bytes of the data
1959 *
1960 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1961 *
1962 * child - a pointer to the child sysctl table if this entry is a directory, or
1963 * %NULL.
1964 *
1965 * proc_handler - the text handler routine (described below)
1966 *
1967 * strategy - the strategy routine (described below)
1968 *
1969 * de - for internal use by the sysctl routines
1970 *
1971 * extra1, extra2 - extra pointers usable by the proc handler routines
1972 *
1973 * Leaf nodes in the sysctl tree will be represented by a single file
1974 * under /proc; non-leaf nodes will be represented by directories.
1975 *
1976 * sysctl(2) can automatically manage read and write requests through
1977 * the sysctl table. The data and maxlen fields of the ctl_table
1978 * struct enable minimal validation of the values being written to be
1979 * performed, and the mode field allows minimal authentication.
1980 *
1981 * More sophisticated management can be enabled by the provision of a
1982 * strategy routine with the table entry. This will be called before
1983 * any automatic read or write of the data is performed.
1984 *
1985 * The strategy routine may return
1986 *
1987 * < 0 - Error occurred (error is passed to user process)
1988 *
1989 * 0 - OK - proceed with automatic read or write.
1990 *
1991 * > 0 - OK - read or write has been done by the strategy routine, so
1992 * return immediately.
1993 *
1994 * There must be a proc_handler routine for any terminal nodes
1995 * mirrored under /proc/sys (non-terminals are handled by a built-in
1996 * directory handler). Several default handlers are available to
1997 * cover common cases -
1998 *
1999 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2000 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2001 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2002 *
2003 * It is the handler's job to read the input buffer from user memory
2004 * and process it. The handler should return 0 on success.
2005 *
2006 * This routine returns %NULL on a failure to register, and a pointer
2007 * to the table header on success.
2008 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002009struct ctl_table_header *__register_sysctl_paths(
2010 struct ctl_table_root *root,
2011 struct nsproxy *namespaces,
2012 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002014 struct ctl_table_header *header;
2015 struct ctl_table *new, **prevp;
2016 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04002017 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002018
2019 /* Count the path components */
2020 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2021 ;
2022
2023 /*
2024 * For each path component, allocate a 2-element ctl_table array.
2025 * The first array element will be filled with the sysctl entry
2026 * for this, the second will be the sentinel (ctl_name == 0).
2027 *
2028 * We allocate everything in one go so that we don't have to
2029 * worry about freeing additional memory in unregister_sysctl_table.
2030 */
2031 header = kzalloc(sizeof(struct ctl_table_header) +
2032 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2033 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002035
2036 new = (struct ctl_table *) (header + 1);
2037
2038 /* Now connect the dots */
2039 prevp = &header->ctl_table;
2040 for (n = 0; n < npath; ++n, ++path) {
2041 /* Copy the procname */
2042 new->procname = path->procname;
2043 new->ctl_name = path->ctl_name;
2044 new->mode = 0555;
2045
2046 *prevp = new;
2047 prevp = &new->child;
2048
2049 new += 2;
2050 }
2051 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002052 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002053
2054 INIT_LIST_HEAD(&header->ctl_entry);
2055 header->used = 0;
2056 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002057 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002058 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002059 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002060#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002061 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002062 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002063 return NULL;
2064 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002065#endif
Al Viro330d57f2005-11-04 10:18:40 +00002066 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002067 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002068 header->attached_by = header->ctl_table;
2069 header->attached_to = root_table;
2070 header->parent = &root_table_header;
2071 for (set = header->set; set; set = set->parent) {
2072 struct ctl_table_header *p;
2073 list_for_each_entry(p, &set->list, ctl_entry) {
2074 if (p->unregistering)
2075 continue;
2076 try_attach(p, header);
2077 }
2078 }
2079 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002080 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002081 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002082
2083 return header;
2084}
2085
2086/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002087 * register_sysctl_table_path - register a sysctl table hierarchy
2088 * @path: The path to the directory the sysctl table is in.
2089 * @table: the top-level table structure
2090 *
2091 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2092 * array. A completely 0 filled entry terminates the table.
2093 *
2094 * See __register_sysctl_paths for more details.
2095 */
2096struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2097 struct ctl_table *table)
2098{
2099 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2100 path, table);
2101}
2102
2103/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002104 * register_sysctl_table - register a sysctl table hierarchy
2105 * @table: the top-level table structure
2106 *
2107 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2108 * array. A completely 0 filled entry terminates the table.
2109 *
2110 * See register_sysctl_paths for more details.
2111 */
2112struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2113{
2114 static const struct ctl_path null_path[] = { {} };
2115
2116 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117}
2118
2119/**
2120 * unregister_sysctl_table - unregister a sysctl table hierarchy
2121 * @header: the header returned from register_sysctl_table
2122 *
2123 * Unregisters the sysctl table and all children. proc entries may not
2124 * actually be removed until they are no longer used by anyone.
2125 */
2126void unregister_sysctl_table(struct ctl_table_header * header)
2127{
Al Viro330d57f2005-11-04 10:18:40 +00002128 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002129
2130 if (header == NULL)
2131 return;
2132
Al Viro330d57f2005-11-04 10:18:40 +00002133 spin_lock(&sysctl_lock);
2134 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002135 if (!--header->parent->count) {
2136 WARN_ON(1);
2137 kfree(header->parent);
2138 }
Al Virof7e6ced2008-07-15 01:44:23 -04002139 if (!--header->count)
2140 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002141 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142}
2143
Al Viro90434762008-07-15 08:54:06 -04002144int sysctl_is_seen(struct ctl_table_header *p)
2145{
2146 struct ctl_table_set *set = p->set;
2147 int res;
2148 spin_lock(&sysctl_lock);
2149 if (p->unregistering)
2150 res = 0;
2151 else if (!set->is_seen)
2152 res = 1;
2153 else
2154 res = set->is_seen(set);
2155 spin_unlock(&sysctl_lock);
2156 return res;
2157}
2158
Al Viro73455092008-07-14 21:22:20 -04002159void setup_sysctl_set(struct ctl_table_set *p,
2160 struct ctl_table_set *parent,
2161 int (*is_seen)(struct ctl_table_set *))
2162{
2163 INIT_LIST_HEAD(&p->list);
2164 p->parent = parent ? parent : &sysctl_table_root.default_set;
2165 p->is_seen = is_seen;
2166}
2167
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002168#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002169struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002170{
2171 return NULL;
2172}
2173
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002174struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2175 struct ctl_table *table)
2176{
2177 return NULL;
2178}
2179
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002180void unregister_sysctl_table(struct ctl_table_header * table)
2181{
2182}
2183
Al Viro73455092008-07-14 21:22:20 -04002184void setup_sysctl_set(struct ctl_table_set *p,
2185 struct ctl_table_set *parent,
2186 int (*is_seen)(struct ctl_table_set *))
2187{
2188}
2189
Al Virof7e6ced2008-07-15 01:44:23 -04002190void sysctl_head_put(struct ctl_table_header *head)
2191{
2192}
2193
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002194#endif /* CONFIG_SYSCTL */
2195
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196/*
2197 * /proc/sys support
2198 */
2199
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002200#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002202static int _proc_do_string(void* data, int maxlen, int write,
2203 struct file *filp, void __user *buffer,
2204 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002205{
2206 size_t len;
2207 char __user *p;
2208 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002209
2210 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002211 *lenp = 0;
2212 return 0;
2213 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002214
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002215 if (write) {
2216 len = 0;
2217 p = buffer;
2218 while (len < *lenp) {
2219 if (get_user(c, p++))
2220 return -EFAULT;
2221 if (c == 0 || c == '\n')
2222 break;
2223 len++;
2224 }
2225 if (len >= maxlen)
2226 len = maxlen-1;
2227 if(copy_from_user(data, buffer, len))
2228 return -EFAULT;
2229 ((char *) data)[len] = 0;
2230 *ppos += *lenp;
2231 } else {
2232 len = strlen(data);
2233 if (len > maxlen)
2234 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002235
2236 if (*ppos > len) {
2237 *lenp = 0;
2238 return 0;
2239 }
2240
2241 data += *ppos;
2242 len -= *ppos;
2243
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002244 if (len > *lenp)
2245 len = *lenp;
2246 if (len)
2247 if(copy_to_user(buffer, data, len))
2248 return -EFAULT;
2249 if (len < *lenp) {
2250 if(put_user('\n', ((char __user *) buffer) + len))
2251 return -EFAULT;
2252 len++;
2253 }
2254 *lenp = len;
2255 *ppos += len;
2256 }
2257 return 0;
2258}
2259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260/**
2261 * proc_dostring - read a string sysctl
2262 * @table: the sysctl table
2263 * @write: %TRUE if this is a write to the sysctl file
2264 * @filp: the file structure
2265 * @buffer: the user buffer
2266 * @lenp: the size of the user buffer
2267 * @ppos: file position
2268 *
2269 * Reads/writes a string from/to the user buffer. If the kernel
2270 * buffer provided is not large enough to hold the string, the
2271 * string is truncated. The copied string is %NULL-terminated.
2272 * If the string is being read by the user process, it is copied
2273 * and a newline '\n' is added. It is truncated if the buffer is
2274 * not large enough.
2275 *
2276 * Returns 0 on success.
2277 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002278int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 void __user *buffer, size_t *lenp, loff_t *ppos)
2280{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002281 return _proc_do_string(table->data, table->maxlen, write, filp,
2282 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283}
2284
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
2286static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2287 int *valp,
2288 int write, void *data)
2289{
2290 if (write) {
2291 *valp = *negp ? -*lvalp : *lvalp;
2292 } else {
2293 int val = *valp;
2294 if (val < 0) {
2295 *negp = -1;
2296 *lvalp = (unsigned long)-val;
2297 } else {
2298 *negp = 0;
2299 *lvalp = (unsigned long)val;
2300 }
2301 }
2302 return 0;
2303}
2304
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002305static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002306 int write, struct file *filp, void __user *buffer,
2307 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2309 int write, void *data),
2310 void *data)
2311{
2312#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002313 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 unsigned long lval;
2315 size_t left, len;
2316
2317 char buf[TMPBUFLEN], *p;
2318 char __user *s = buffer;
2319
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002320 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 (*ppos && !write)) {
2322 *lenp = 0;
2323 return 0;
2324 }
2325
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002326 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 vleft = table->maxlen / sizeof(*i);
2328 left = *lenp;
2329
2330 if (!conv)
2331 conv = do_proc_dointvec_conv;
2332
2333 for (; left && vleft--; i++, first=0) {
2334 if (write) {
2335 while (left) {
2336 char c;
2337 if (get_user(c, s))
2338 return -EFAULT;
2339 if (!isspace(c))
2340 break;
2341 left--;
2342 s++;
2343 }
2344 if (!left)
2345 break;
2346 neg = 0;
2347 len = left;
2348 if (len > sizeof(buf) - 1)
2349 len = sizeof(buf) - 1;
2350 if (copy_from_user(buf, s, len))
2351 return -EFAULT;
2352 buf[len] = 0;
2353 p = buf;
2354 if (*p == '-' && left > 1) {
2355 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002356 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 }
2358 if (*p < '0' || *p > '9')
2359 break;
2360
2361 lval = simple_strtoul(p, &p, 0);
2362
2363 len = p-buf;
2364 if ((len < left) && *p && !isspace(*p))
2365 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 s += len;
2367 left -= len;
2368
2369 if (conv(&neg, &lval, i, 1, data))
2370 break;
2371 } else {
2372 p = buf;
2373 if (!first)
2374 *p++ = '\t';
2375
2376 if (conv(&neg, &lval, i, 0, data))
2377 break;
2378
2379 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2380 len = strlen(buf);
2381 if (len > left)
2382 len = left;
2383 if(copy_to_user(s, buf, len))
2384 return -EFAULT;
2385 left -= len;
2386 s += len;
2387 }
2388 }
2389
2390 if (!write && !first && left) {
2391 if(put_user('\n', s))
2392 return -EFAULT;
2393 left--, s++;
2394 }
2395 if (write) {
2396 while (left) {
2397 char c;
2398 if (get_user(c, s++))
2399 return -EFAULT;
2400 if (!isspace(c))
2401 break;
2402 left--;
2403 }
2404 }
2405 if (write && first)
2406 return -EINVAL;
2407 *lenp -= left;
2408 *ppos += *lenp;
2409 return 0;
2410#undef TMPBUFLEN
2411}
2412
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002413static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002414 void __user *buffer, size_t *lenp, loff_t *ppos,
2415 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2416 int write, void *data),
2417 void *data)
2418{
2419 return __do_proc_dointvec(table->data, table, write, filp,
2420 buffer, lenp, ppos, conv, data);
2421}
2422
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423/**
2424 * proc_dointvec - read a vector of integers
2425 * @table: the sysctl table
2426 * @write: %TRUE if this is a write to the sysctl file
2427 * @filp: the file structure
2428 * @buffer: the user buffer
2429 * @lenp: the size of the user buffer
2430 * @ppos: file position
2431 *
2432 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2433 * values from/to the user buffer, treated as an ASCII string.
2434 *
2435 * Returns 0 on success.
2436 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002437int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 void __user *buffer, size_t *lenp, loff_t *ppos)
2439{
2440 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2441 NULL,NULL);
2442}
2443
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002444/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002445 * Taint values can only be increased
2446 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002447 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002448static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002449 void __user *buffer, size_t *lenp, loff_t *ppos)
2450{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002451 struct ctl_table t;
2452 unsigned long tmptaint = get_taint();
2453 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002454
Bastian Blank91fcd412007-04-23 14:41:14 -07002455 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002456 return -EPERM;
2457
Andi Kleen25ddbb12008-10-15 22:01:41 -07002458 t = *table;
2459 t.data = &tmptaint;
2460 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2461 if (err < 0)
2462 return err;
2463
2464 if (write) {
2465 /*
2466 * Poor man's atomic or. Not worth adding a primitive
2467 * to everyone's atomic.h for this
2468 */
2469 int i;
2470 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2471 if ((tmptaint >> i) & 1)
2472 add_taint(i);
2473 }
2474 }
2475
2476 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002477}
2478
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479struct do_proc_dointvec_minmax_conv_param {
2480 int *min;
2481 int *max;
2482};
2483
2484static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2485 int *valp,
2486 int write, void *data)
2487{
2488 struct do_proc_dointvec_minmax_conv_param *param = data;
2489 if (write) {
2490 int val = *negp ? -*lvalp : *lvalp;
2491 if ((param->min && *param->min > val) ||
2492 (param->max && *param->max < val))
2493 return -EINVAL;
2494 *valp = val;
2495 } else {
2496 int val = *valp;
2497 if (val < 0) {
2498 *negp = -1;
2499 *lvalp = (unsigned long)-val;
2500 } else {
2501 *negp = 0;
2502 *lvalp = (unsigned long)val;
2503 }
2504 }
2505 return 0;
2506}
2507
2508/**
2509 * proc_dointvec_minmax - read a vector of integers with min/max values
2510 * @table: the sysctl table
2511 * @write: %TRUE if this is a write to the sysctl file
2512 * @filp: the file structure
2513 * @buffer: the user buffer
2514 * @lenp: the size of the user buffer
2515 * @ppos: file position
2516 *
2517 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2518 * values from/to the user buffer, treated as an ASCII string.
2519 *
2520 * This routine will ensure the values are within the range specified by
2521 * table->extra1 (min) and table->extra2 (max).
2522 *
2523 * Returns 0 on success.
2524 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002525int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 void __user *buffer, size_t *lenp, loff_t *ppos)
2527{
2528 struct do_proc_dointvec_minmax_conv_param param = {
2529 .min = (int *) table->extra1,
2530 .max = (int *) table->extra2,
2531 };
2532 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2533 do_proc_dointvec_minmax_conv, &param);
2534}
2535
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002536static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 struct file *filp,
2538 void __user *buffer,
2539 size_t *lenp, loff_t *ppos,
2540 unsigned long convmul,
2541 unsigned long convdiv)
2542{
2543#define TMPBUFLEN 21
2544 unsigned long *i, *min, *max, val;
2545 int vleft, first=1, neg;
2546 size_t len, left;
2547 char buf[TMPBUFLEN], *p;
2548 char __user *s = buffer;
2549
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002550 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 (*ppos && !write)) {
2552 *lenp = 0;
2553 return 0;
2554 }
2555
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002556 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 min = (unsigned long *) table->extra1;
2558 max = (unsigned long *) table->extra2;
2559 vleft = table->maxlen / sizeof(unsigned long);
2560 left = *lenp;
2561
2562 for (; left && vleft--; i++, min++, max++, first=0) {
2563 if (write) {
2564 while (left) {
2565 char c;
2566 if (get_user(c, s))
2567 return -EFAULT;
2568 if (!isspace(c))
2569 break;
2570 left--;
2571 s++;
2572 }
2573 if (!left)
2574 break;
2575 neg = 0;
2576 len = left;
2577 if (len > TMPBUFLEN-1)
2578 len = TMPBUFLEN-1;
2579 if (copy_from_user(buf, s, len))
2580 return -EFAULT;
2581 buf[len] = 0;
2582 p = buf;
2583 if (*p == '-' && left > 1) {
2584 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002585 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 }
2587 if (*p < '0' || *p > '9')
2588 break;
2589 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2590 len = p-buf;
2591 if ((len < left) && *p && !isspace(*p))
2592 break;
2593 if (neg)
2594 val = -val;
2595 s += len;
2596 left -= len;
2597
2598 if(neg)
2599 continue;
2600 if ((min && val < *min) || (max && val > *max))
2601 continue;
2602 *i = val;
2603 } else {
2604 p = buf;
2605 if (!first)
2606 *p++ = '\t';
2607 sprintf(p, "%lu", convdiv * (*i) / convmul);
2608 len = strlen(buf);
2609 if (len > left)
2610 len = left;
2611 if(copy_to_user(s, buf, len))
2612 return -EFAULT;
2613 left -= len;
2614 s += len;
2615 }
2616 }
2617
2618 if (!write && !first && left) {
2619 if(put_user('\n', s))
2620 return -EFAULT;
2621 left--, s++;
2622 }
2623 if (write) {
2624 while (left) {
2625 char c;
2626 if (get_user(c, s++))
2627 return -EFAULT;
2628 if (!isspace(c))
2629 break;
2630 left--;
2631 }
2632 }
2633 if (write && first)
2634 return -EINVAL;
2635 *lenp -= left;
2636 *ppos += *lenp;
2637 return 0;
2638#undef TMPBUFLEN
2639}
2640
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002641static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002642 struct file *filp,
2643 void __user *buffer,
2644 size_t *lenp, loff_t *ppos,
2645 unsigned long convmul,
2646 unsigned long convdiv)
2647{
2648 return __do_proc_doulongvec_minmax(table->data, table, write,
2649 filp, buffer, lenp, ppos, convmul, convdiv);
2650}
2651
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652/**
2653 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2654 * @table: the sysctl table
2655 * @write: %TRUE if this is a write to the sysctl file
2656 * @filp: the file structure
2657 * @buffer: the user buffer
2658 * @lenp: the size of the user buffer
2659 * @ppos: file position
2660 *
2661 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2662 * values from/to the user buffer, treated as an ASCII string.
2663 *
2664 * This routine will ensure the values are within the range specified by
2665 * table->extra1 (min) and table->extra2 (max).
2666 *
2667 * Returns 0 on success.
2668 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002669int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 void __user *buffer, size_t *lenp, loff_t *ppos)
2671{
2672 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2673}
2674
2675/**
2676 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2677 * @table: the sysctl table
2678 * @write: %TRUE if this is a write to the sysctl file
2679 * @filp: the file structure
2680 * @buffer: the user buffer
2681 * @lenp: the size of the user buffer
2682 * @ppos: file position
2683 *
2684 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2685 * values from/to the user buffer, treated as an ASCII string. The values
2686 * are treated as milliseconds, and converted to jiffies when they are stored.
2687 *
2688 * This routine will ensure the values are within the range specified by
2689 * table->extra1 (min) and table->extra2 (max).
2690 *
2691 * Returns 0 on success.
2692 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002693int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 struct file *filp,
2695 void __user *buffer,
2696 size_t *lenp, loff_t *ppos)
2697{
2698 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2699 lenp, ppos, HZ, 1000l);
2700}
2701
2702
2703static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2704 int *valp,
2705 int write, void *data)
2706{
2707 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002708 if (*lvalp > LONG_MAX / HZ)
2709 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2711 } else {
2712 int val = *valp;
2713 unsigned long lval;
2714 if (val < 0) {
2715 *negp = -1;
2716 lval = (unsigned long)-val;
2717 } else {
2718 *negp = 0;
2719 lval = (unsigned long)val;
2720 }
2721 *lvalp = lval / HZ;
2722 }
2723 return 0;
2724}
2725
2726static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2727 int *valp,
2728 int write, void *data)
2729{
2730 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002731 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2732 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2734 } else {
2735 int val = *valp;
2736 unsigned long lval;
2737 if (val < 0) {
2738 *negp = -1;
2739 lval = (unsigned long)-val;
2740 } else {
2741 *negp = 0;
2742 lval = (unsigned long)val;
2743 }
2744 *lvalp = jiffies_to_clock_t(lval);
2745 }
2746 return 0;
2747}
2748
2749static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2750 int *valp,
2751 int write, void *data)
2752{
2753 if (write) {
2754 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2755 } else {
2756 int val = *valp;
2757 unsigned long lval;
2758 if (val < 0) {
2759 *negp = -1;
2760 lval = (unsigned long)-val;
2761 } else {
2762 *negp = 0;
2763 lval = (unsigned long)val;
2764 }
2765 *lvalp = jiffies_to_msecs(lval);
2766 }
2767 return 0;
2768}
2769
2770/**
2771 * proc_dointvec_jiffies - read a vector of integers as seconds
2772 * @table: the sysctl table
2773 * @write: %TRUE if this is a write to the sysctl file
2774 * @filp: the file structure
2775 * @buffer: the user buffer
2776 * @lenp: the size of the user buffer
2777 * @ppos: file position
2778 *
2779 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2780 * values from/to the user buffer, treated as an ASCII string.
2781 * The values read are assumed to be in seconds, and are converted into
2782 * jiffies.
2783 *
2784 * Returns 0 on success.
2785 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002786int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 void __user *buffer, size_t *lenp, loff_t *ppos)
2788{
2789 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2790 do_proc_dointvec_jiffies_conv,NULL);
2791}
2792
2793/**
2794 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2795 * @table: the sysctl table
2796 * @write: %TRUE if this is a write to the sysctl file
2797 * @filp: the file structure
2798 * @buffer: the user buffer
2799 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002800 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 *
2802 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2803 * values from/to the user buffer, treated as an ASCII string.
2804 * The values read are assumed to be in 1/USER_HZ seconds, and
2805 * are converted into jiffies.
2806 *
2807 * Returns 0 on success.
2808 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002809int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 void __user *buffer, size_t *lenp, loff_t *ppos)
2811{
2812 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2813 do_proc_dointvec_userhz_jiffies_conv,NULL);
2814}
2815
2816/**
2817 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2818 * @table: the sysctl table
2819 * @write: %TRUE if this is a write to the sysctl file
2820 * @filp: the file structure
2821 * @buffer: the user buffer
2822 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002823 * @ppos: file position
2824 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 *
2826 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2827 * values from/to the user buffer, treated as an ASCII string.
2828 * The values read are assumed to be in 1/1000 seconds, and
2829 * are converted into jiffies.
2830 *
2831 * Returns 0 on success.
2832 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002833int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 void __user *buffer, size_t *lenp, loff_t *ppos)
2835{
2836 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2837 do_proc_dointvec_ms_jiffies_conv, NULL);
2838}
2839
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002840static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002841 void __user *buffer, size_t *lenp, loff_t *ppos)
2842{
2843 struct pid *new_pid;
2844 pid_t tmp;
2845 int r;
2846
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002847 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002848
2849 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2850 lenp, ppos, NULL, NULL);
2851 if (r || !write)
2852 return r;
2853
2854 new_pid = find_get_pid(tmp);
2855 if (!new_pid)
2856 return -ESRCH;
2857
2858 put_pid(xchg(&cad_pid, new_pid));
2859 return 0;
2860}
2861
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862#else /* CONFIG_PROC_FS */
2863
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002864int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 void __user *buffer, size_t *lenp, loff_t *ppos)
2866{
2867 return -ENOSYS;
2868}
2869
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002870int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 void __user *buffer, size_t *lenp, loff_t *ppos)
2872{
2873 return -ENOSYS;
2874}
2875
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002876int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 void __user *buffer, size_t *lenp, loff_t *ppos)
2878{
2879 return -ENOSYS;
2880}
2881
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002882int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 void __user *buffer, size_t *lenp, loff_t *ppos)
2884{
2885 return -ENOSYS;
2886}
2887
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002888int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 void __user *buffer, size_t *lenp, loff_t *ppos)
2890{
2891 return -ENOSYS;
2892}
2893
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002894int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 void __user *buffer, size_t *lenp, loff_t *ppos)
2896{
2897 return -ENOSYS;
2898}
2899
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002900int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 void __user *buffer, size_t *lenp, loff_t *ppos)
2902{
2903 return -ENOSYS;
2904}
2905
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002906int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 struct file *filp,
2908 void __user *buffer,
2909 size_t *lenp, loff_t *ppos)
2910{
2911 return -ENOSYS;
2912}
2913
2914
2915#endif /* CONFIG_PROC_FS */
2916
2917
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002918#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919/*
2920 * General sysctl support routines
2921 */
2922
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002923/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002924int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002925 void __user *oldval, size_t __user *oldlenp,
2926 void __user *newval, size_t newlen)
2927{
2928 size_t len;
2929
2930 /* Get out of I don't have a variable */
2931 if (!table->data || !table->maxlen)
2932 return -ENOTDIR;
2933
2934 if (oldval && oldlenp) {
2935 if (get_user(len, oldlenp))
2936 return -EFAULT;
2937 if (len) {
2938 if (len > table->maxlen)
2939 len = table->maxlen;
2940 if (copy_to_user(oldval, table->data, len))
2941 return -EFAULT;
2942 if (put_user(len, oldlenp))
2943 return -EFAULT;
2944 }
2945 }
2946
2947 if (newval && newlen) {
2948 if (newlen > table->maxlen)
2949 newlen = table->maxlen;
2950
2951 if (copy_from_user(table->data, newval, newlen))
2952 return -EFAULT;
2953 }
2954 return 1;
2955}
2956
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002958int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002960 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 if (!table->data || !table->maxlen)
2963 return -ENOTDIR;
2964
2965 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002966 size_t bufsize;
2967 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002969 if (bufsize) {
2970 size_t len = strlen(table->data), copied;
2971
2972 /* This shouldn't trigger for a well-formed sysctl */
2973 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002975
2976 /* Copy up to a max of bufsize-1 bytes of the string */
2977 copied = (len >= bufsize) ? bufsize - 1 : len;
2978
2979 if (copy_to_user(oldval, table->data, copied) ||
2980 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002982 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 return -EFAULT;
2984 }
2985 }
2986 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002987 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 if (len > table->maxlen)
2989 len = table->maxlen;
2990 if(copy_from_user(table->data, newval, len))
2991 return -EFAULT;
2992 if (len == table->maxlen)
2993 len--;
2994 ((char *) table->data)[len] = 0;
2995 }
Yi Yang82c9df82005-12-30 16:37:10 +08002996 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997}
2998
2999/*
3000 * This function makes sure that all of the integers in the vector
3001 * are between the minimum and maximum values given in the arrays
3002 * table->extra1 and table->extra2, respectively.
3003 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003004int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003006 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007{
3008
3009 if (newval && newlen) {
3010 int __user *vec = (int __user *) newval;
3011 int *min = (int *) table->extra1;
3012 int *max = (int *) table->extra2;
3013 size_t length;
3014 int i;
3015
3016 if (newlen % sizeof(int) != 0)
3017 return -EINVAL;
3018
3019 if (!table->extra1 && !table->extra2)
3020 return 0;
3021
3022 if (newlen > table->maxlen)
3023 newlen = table->maxlen;
3024 length = newlen / sizeof(int);
3025
3026 for (i = 0; i < length; i++) {
3027 int value;
3028 if (get_user(value, vec + i))
3029 return -EFAULT;
3030 if (min && value < min[i])
3031 return -EINVAL;
3032 if (max && value > max[i])
3033 return -EINVAL;
3034 }
3035 }
3036 return 0;
3037}
3038
3039/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003040int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003042 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003044 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003046
3047 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003049 if (olen) {
3050 int val;
3051
3052 if (olen < sizeof(int))
3053 return -EINVAL;
3054
3055 val = *(int *)(table->data) / HZ;
3056 if (put_user(val, (int __user *)oldval))
3057 return -EFAULT;
3058 if (put_user(sizeof(int), oldlenp))
3059 return -EFAULT;
3060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 }
3062 if (newval && newlen) {
3063 int new;
3064 if (newlen != sizeof(int))
3065 return -EINVAL;
3066 if (get_user(new, (int __user *)newval))
3067 return -EFAULT;
3068 *(int *)(table->data) = new*HZ;
3069 }
3070 return 1;
3071}
3072
3073/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003074int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003076 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003078 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003080
3081 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003083 if (olen) {
3084 int val;
3085
3086 if (olen < sizeof(int))
3087 return -EINVAL;
3088
3089 val = jiffies_to_msecs(*(int *)(table->data));
3090 if (put_user(val, (int __user *)oldval))
3091 return -EFAULT;
3092 if (put_user(sizeof(int), oldlenp))
3093 return -EFAULT;
3094 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 }
3096 if (newval && newlen) {
3097 int new;
3098 if (newlen != sizeof(int))
3099 return -EINVAL;
3100 if (get_user(new, (int __user *)newval))
3101 return -EFAULT;
3102 *(int *)(table->data) = msecs_to_jiffies(new);
3103 }
3104 return 1;
3105}
3106
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003107
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003108
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003109#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
3111
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003112SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003114 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003115 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003116
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003117 if (copy_from_user(&tmp, args, sizeof(tmp)))
3118 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003119
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003120 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003121
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003122 /* If no error reading the parameters then just -ENOSYS ... */
3123 if (!error)
3124 error = -ENOSYS;
3125
3126 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127}
3128
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003129int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003130 void __user *oldval, size_t __user *oldlenp,
3131 void __user *newval, size_t newlen)
3132{
3133 return -ENOSYS;
3134}
3135
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003136int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003138 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139{
3140 return -ENOSYS;
3141}
3142
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003143int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003145 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146{
3147 return -ENOSYS;
3148}
3149
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003150int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003152 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153{
3154 return -ENOSYS;
3155}
3156
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003157int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003159 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160{
3161 return -ENOSYS;
3162}
3163
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003164#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003166static int deprecated_sysctl_warning(struct __sysctl_args *args)
3167{
3168 static int msg_count;
3169 int name[CTL_MAXNAME];
3170 int i;
3171
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003172 /* Check args->nlen. */
3173 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3174 return -ENOTDIR;
3175
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003176 /* Read in the sysctl name for better debug message logging */
3177 for (i = 0; i < args->nlen; i++)
3178 if (get_user(name[i], args->name + i))
3179 return -EFAULT;
3180
3181 /* Ignore accesses to kernel.version */
3182 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3183 return 0;
3184
3185 if (msg_count < 5) {
3186 msg_count++;
3187 printk(KERN_INFO
3188 "warning: process `%s' used the deprecated sysctl "
3189 "system call with ", current->comm);
3190 for (i = 0; i < args->nlen; i++)
3191 printk("%d.", name[i]);
3192 printk("\n");
3193 }
3194 return 0;
3195}
3196
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197/*
3198 * No sense putting this after each symbol definition, twice,
3199 * exception granted :-)
3200 */
3201EXPORT_SYMBOL(proc_dointvec);
3202EXPORT_SYMBOL(proc_dointvec_jiffies);
3203EXPORT_SYMBOL(proc_dointvec_minmax);
3204EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3205EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3206EXPORT_SYMBOL(proc_dostring);
3207EXPORT_SYMBOL(proc_doulongvec_minmax);
3208EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3209EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003210EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211EXPORT_SYMBOL(sysctl_intvec);
3212EXPORT_SYMBOL(sysctl_jiffies);
3213EXPORT_SYMBOL(sysctl_ms_jiffies);
3214EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003215EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216EXPORT_SYMBOL(unregister_sysctl_table);