blob: 7f4f57bea4ce5ceb77a677f6415f1f0cfe13f16c [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>
Vegard Nossumdfec0722008-04-04 00:51:41 +020029#include <linux/kmemcheck.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020052#include <linux/perf_event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#include <asm/uaccess.h>
55#include <asm/processor.h>
56
Andi Kleen29cbc782006-09-30 01:47:55 +020057#ifdef CONFIG_X86
58#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010059#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010060#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020061#endif
62
Eric W. Biederman7058cb02007-10-18 03:05:58 -070063static int deprecated_sysctl_warning(struct __sysctl_args *args);
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#if defined(CONFIG_SYSCTL)
66
67/* External variables not in a header file. */
68extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070069extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int sysctl_overcommit_memory;
71extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070072extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070073extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080074extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070077extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max;
80extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080082extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080083extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020084extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010085extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040086extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +000087#ifndef CONFIG_MMU
88extern int sysctl_nr_trim_pages;
89#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070090#ifdef CONFIG_RCU_TORTURE_TEST
91extern int rcutorture_runnable;
92#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Jens Axboecb684b52009-09-15 21:53:11 +020093#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +020094extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +020095#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070097/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -080098#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070099static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200100static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700101#endif
102
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700103static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700104static int __maybe_unused one = 1;
105static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800106static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700107static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700108#ifdef CONFIG_PRINTK
109static int ten_thousand = 10000;
110#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700112/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
113static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
116static int maxolduid = 65535;
117static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800118static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120static int ngroups_max = NGROUPS_MAX;
121
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200122#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700124extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#ifdef CONFIG_CHR_DEV_SG
127extern int sg_big_buff;
128#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
David S. Miller72c57ed2008-09-11 23:29:54 -0700130#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700131#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#endif
133
David S. Miller08714202008-11-16 23:49:24 -0800134#ifdef CONFIG_SPARC64
135extern int sysctl_tsb_ratio;
136#endif
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#ifdef __hppa__
139extern int pwrsw_enabled;
140extern int unaligned_enabled;
141#endif
142
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800143#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#ifdef CONFIG_MATHEMU
145extern int sysctl_ieee_emulation_warnings;
146#endif
147extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700148extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#endif
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#ifdef CONFIG_BSD_PROCESS_ACCT
152extern int acct_parm[];
153#endif
154
Jes Sorensend2b176e2006-02-28 09:42:23 -0800155#ifdef CONFIG_IA64
156extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800157extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800158#endif
159
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700160#ifdef CONFIG_RT_MUTEXES
161extern int max_lock_depth;
162#endif
163
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700164#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700165static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700166 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700167static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800168 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700169#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700170
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700171static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100172static struct ctl_table_root sysctl_table_root;
173static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100174 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100175 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400176 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100177 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400178 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100179};
180static struct ctl_table_root sysctl_table_root = {
181 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400182 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100183};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700185static struct ctl_table kern_table[];
186static struct ctl_table vm_table[];
187static struct ctl_table fs_table[];
188static struct ctl_table debug_table[];
189static struct ctl_table dev_table[];
190extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700191#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700192extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400193#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800194#ifdef CONFIG_EPOLL
195extern struct ctl_table epoll_table[];
196#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
199int sysctl_legacy_va_layout;
200#endif
201
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700202extern int prove_locking;
203extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205/* The default sysctl tables: */
206
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700207static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 {
209 .ctl_name = CTL_KERN,
210 .procname = "kernel",
211 .mode = 0555,
212 .child = kern_table,
213 },
214 {
215 .ctl_name = CTL_VM,
216 .procname = "vm",
217 .mode = 0555,
218 .child = vm_table,
219 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 .ctl_name = CTL_FS,
222 .procname = "fs",
223 .mode = 0555,
224 .child = fs_table,
225 },
226 {
227 .ctl_name = CTL_DEBUG,
228 .procname = "debug",
229 .mode = 0555,
230 .child = debug_table,
231 },
232 {
233 .ctl_name = CTL_DEV,
234 .procname = "dev",
235 .mode = 0555,
236 .child = dev_table,
237 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700238/*
239 * NOTE: do not add new entries to this table unless you have read
240 * Documentation/sysctl/ctl_unnumbered.txt
241 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 { .ctl_name = 0 }
243};
244
Ingo Molnar77e54a12007-07-09 18:52:00 +0200245#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100246static int min_sched_granularity_ns = 100000; /* 100 usecs */
247static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
248static int min_wakeup_granularity_ns; /* 0 usecs */
249static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200250#endif
251
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700252static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200253 {
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "sched_child_runs_first",
256 .data = &sysctl_sched_child_runs_first,
257 .maxlen = sizeof(unsigned int),
258 .mode = 0644,
259 .proc_handler = &proc_dointvec,
260 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200261#ifdef CONFIG_SCHED_DEBUG
262 {
263 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100264 .procname = "sched_min_granularity_ns",
265 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200266 .maxlen = sizeof(unsigned int),
267 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100268 .proc_handler = &sched_nr_latency_handler,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_sched_granularity_ns,
271 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200272 },
273 {
274 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200275 .procname = "sched_latency_ns",
276 .data = &sysctl_sched_latency,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100279 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200280 .strategy = &sysctl_intvec,
281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
283 },
284 {
285 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200286 .procname = "sched_wakeup_granularity_ns",
287 .data = &sysctl_sched_wakeup_granularity,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec_minmax,
291 .strategy = &sysctl_intvec,
292 .extra1 = &min_wakeup_granularity_ns,
293 .extra2 = &max_wakeup_granularity_ns,
294 },
295 {
296 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200297 .procname = "sched_shares_ratelimit",
298 .data = &sysctl_sched_shares_ratelimit,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
302 },
303 {
304 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200305 .procname = "sched_shares_thresh",
306 .data = &sysctl_sched_shares_thresh,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec_minmax,
310 .strategy = &sysctl_intvec,
311 .extra1 = &zero,
312 },
313 {
314 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200315 .procname = "sched_features",
316 .data = &sysctl_sched_features,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
319 .proc_handler = &proc_dointvec,
320 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200321 {
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_migration_cost",
324 .data = &sysctl_sched_migration_cost,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
328 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100329 {
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "sched_nr_migrate",
332 .data = &sysctl_sched_nr_migrate,
333 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100334 .mode = 0644,
335 .proc_handler = &proc_dointvec,
336 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530337 {
338 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200339 .procname = "sched_time_avg",
340 .data = &sysctl_sched_time_avg,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
343 .proc_handler = &proc_dointvec,
344 },
345 {
346 .ctl_name = CTL_UNNUMBERED,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530347 .procname = "timer_migration",
348 .data = &sysctl_timer_migration,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530351 .proc_handler = &proc_dointvec_minmax,
352 .strategy = &sysctl_intvec,
353 .extra1 = &zero,
354 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530355 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200356#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200357 {
358 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100359 .procname = "sched_rt_period_us",
360 .data = &sysctl_sched_rt_period,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200363 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100364 },
365 {
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "sched_rt_runtime_us",
368 .data = &sysctl_sched_rt_runtime,
369 .maxlen = sizeof(int),
370 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200371 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100372 },
373 {
374 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200375 .procname = "sched_compat_yield",
376 .data = &sysctl_sched_compat_yield,
377 .maxlen = sizeof(unsigned int),
378 .mode = 0644,
379 .proc_handler = &proc_dointvec,
380 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700381#ifdef CONFIG_PROVE_LOCKING
382 {
383 .ctl_name = CTL_UNNUMBERED,
384 .procname = "prove_locking",
385 .data = &prove_locking,
386 .maxlen = sizeof(int),
387 .mode = 0644,
388 .proc_handler = &proc_dointvec,
389 },
390#endif
391#ifdef CONFIG_LOCK_STAT
392 {
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "lock_stat",
395 .data = &lock_stat,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
399 },
400#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200401 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 .ctl_name = KERN_PANIC,
403 .procname = "panic",
404 .data = &panic_timeout,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec,
408 },
409 {
410 .ctl_name = KERN_CORE_USES_PID,
411 .procname = "core_uses_pid",
412 .data = &core_uses_pid,
413 .maxlen = sizeof(int),
414 .mode = 0644,
415 .proc_handler = &proc_dointvec,
416 },
417 {
418 .ctl_name = KERN_CORE_PATTERN,
419 .procname = "core_pattern",
420 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700421 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 .mode = 0644,
423 .proc_handler = &proc_dostring,
424 .strategy = &sysctl_string,
425 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800426#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700429 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800430 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700431 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800433#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100434#ifdef CONFIG_LATENCYTOP
435 {
436 .procname = "latencytop",
437 .data = &latencytop_enabled,
438 .maxlen = sizeof(int),
439 .mode = 0644,
440 .proc_handler = &proc_dointvec,
441 },
442#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#ifdef CONFIG_BLK_DEV_INITRD
444 {
445 .ctl_name = KERN_REALROOTDEV,
446 .procname = "real-root-dev",
447 .data = &real_root_dev,
448 .maxlen = sizeof(int),
449 .mode = 0644,
450 .proc_handler = &proc_dointvec,
451 },
452#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700453 {
454 .ctl_name = CTL_UNNUMBERED,
455 .procname = "print-fatal-signals",
456 .data = &print_fatal_signals,
457 .maxlen = sizeof(int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
460 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700461#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 {
463 .ctl_name = KERN_SPARC_REBOOT,
464 .procname = "reboot-cmd",
465 .data = reboot_command,
466 .maxlen = 256,
467 .mode = 0644,
468 .proc_handler = &proc_dostring,
469 .strategy = &sysctl_string,
470 },
471 {
472 .ctl_name = KERN_SPARC_STOP_A,
473 .procname = "stop-a",
474 .data = &stop_a_enabled,
475 .maxlen = sizeof (int),
476 .mode = 0644,
477 .proc_handler = &proc_dointvec,
478 },
479 {
480 .ctl_name = KERN_SPARC_SCONS_PWROFF,
481 .procname = "scons-poweroff",
482 .data = &scons_pwroff,
483 .maxlen = sizeof (int),
484 .mode = 0644,
485 .proc_handler = &proc_dointvec,
486 },
487#endif
David S. Miller08714202008-11-16 23:49:24 -0800488#ifdef CONFIG_SPARC64
489 {
490 .ctl_name = CTL_UNNUMBERED,
491 .procname = "tsb-ratio",
492 .data = &sysctl_tsb_ratio,
493 .maxlen = sizeof (int),
494 .mode = 0644,
495 .proc_handler = &proc_dointvec,
496 },
497#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498#ifdef __hppa__
499 {
500 .ctl_name = KERN_HPPA_PWRSW,
501 .procname = "soft-power",
502 .data = &pwrsw_enabled,
503 .maxlen = sizeof (int),
504 .mode = 0644,
505 .proc_handler = &proc_dointvec,
506 },
507 {
508 .ctl_name = KERN_HPPA_UNALIGNED,
509 .procname = "unaligned-trap",
510 .data = &unaligned_enabled,
511 .maxlen = sizeof (int),
512 .mode = 0644,
513 .proc_handler = &proc_dointvec,
514 },
515#endif
516 {
517 .ctl_name = KERN_CTLALTDEL,
518 .procname = "ctrl-alt-del",
519 .data = &C_A_D,
520 .maxlen = sizeof(int),
521 .mode = 0644,
522 .proc_handler = &proc_dointvec,
523 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400524#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200525 {
526 .ctl_name = CTL_UNNUMBERED,
527 .procname = "ftrace_enabled",
528 .data = &ftrace_enabled,
529 .maxlen = sizeof(int),
530 .mode = 0644,
531 .proc_handler = &ftrace_enable_sysctl,
532 },
533#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500534#ifdef CONFIG_STACK_TRACER
535 {
536 .ctl_name = CTL_UNNUMBERED,
537 .procname = "stack_tracer_enabled",
538 .data = &stack_tracer_enabled,
539 .maxlen = sizeof(int),
540 .mode = 0644,
541 .proc_handler = &stack_trace_sysctl,
542 },
543#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400544#ifdef CONFIG_TRACING
545 {
546 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100547 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400548 .data = &ftrace_dump_on_oops,
549 .maxlen = sizeof(int),
550 .mode = 0644,
551 .proc_handler = &proc_dointvec,
552 },
553#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200554#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 {
556 .ctl_name = KERN_MODPROBE,
557 .procname = "modprobe",
558 .data = &modprobe_path,
559 .maxlen = KMOD_PATH_LEN,
560 .mode = 0644,
561 .proc_handler = &proc_dostring,
562 .strategy = &sysctl_string,
563 },
Kees Cook3d433212009-04-02 15:49:29 -0700564 {
565 .ctl_name = CTL_UNNUMBERED,
566 .procname = "modules_disabled",
567 .data = &modules_disabled,
568 .maxlen = sizeof(int),
569 .mode = 0644,
570 /* only handle a transition from default "0" to "1" */
571 .proc_handler = &proc_dointvec_minmax,
572 .extra1 = &one,
573 .extra2 = &one,
574 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700576#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 {
578 .ctl_name = KERN_HOTPLUG,
579 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100580 .data = &uevent_helper,
581 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .mode = 0644,
583 .proc_handler = &proc_dostring,
584 .strategy = &sysctl_string,
585 },
586#endif
587#ifdef CONFIG_CHR_DEV_SG
588 {
589 .ctl_name = KERN_SG_BIG_BUFF,
590 .procname = "sg-big-buff",
591 .data = &sg_big_buff,
592 .maxlen = sizeof (int),
593 .mode = 0444,
594 .proc_handler = &proc_dointvec,
595 },
596#endif
597#ifdef CONFIG_BSD_PROCESS_ACCT
598 {
599 .ctl_name = KERN_ACCT,
600 .procname = "acct",
601 .data = &acct_parm,
602 .maxlen = 3*sizeof(int),
603 .mode = 0644,
604 .proc_handler = &proc_dointvec,
605 },
606#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#ifdef CONFIG_MAGIC_SYSRQ
608 {
609 .ctl_name = KERN_SYSRQ,
610 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800611 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 .maxlen = sizeof (int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec,
615 },
616#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700617#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700620 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 .maxlen = sizeof (int),
622 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700623 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700625#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 {
627 .ctl_name = KERN_MAX_THREADS,
628 .procname = "threads-max",
629 .data = &max_threads,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec,
633 },
634 {
635 .ctl_name = KERN_RANDOM,
636 .procname = "random",
637 .mode = 0555,
638 .child = random_table,
639 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 {
641 .ctl_name = KERN_OVERFLOWUID,
642 .procname = "overflowuid",
643 .data = &overflowuid,
644 .maxlen = sizeof(int),
645 .mode = 0644,
646 .proc_handler = &proc_dointvec_minmax,
647 .strategy = &sysctl_intvec,
648 .extra1 = &minolduid,
649 .extra2 = &maxolduid,
650 },
651 {
652 .ctl_name = KERN_OVERFLOWGID,
653 .procname = "overflowgid",
654 .data = &overflowgid,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = &proc_dointvec_minmax,
658 .strategy = &sysctl_intvec,
659 .extra1 = &minolduid,
660 .extra2 = &maxolduid,
661 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800662#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663#ifdef CONFIG_MATHEMU
664 {
665 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
666 .procname = "ieee_emulation_warnings",
667 .data = &sysctl_ieee_emulation_warnings,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
671 },
672#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 {
674 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
675 .procname = "userprocess_debug",
676 .data = &sysctl_userprocess_debug,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec,
680 },
681#endif
682 {
683 .ctl_name = KERN_PIDMAX,
684 .procname = "pid_max",
685 .data = &pid_max,
686 .maxlen = sizeof (int),
687 .mode = 0644,
688 .proc_handler = &proc_dointvec_minmax,
689 .strategy = sysctl_intvec,
690 .extra1 = &pid_max_min,
691 .extra2 = &pid_max_max,
692 },
693 {
694 .ctl_name = KERN_PANIC_ON_OOPS,
695 .procname = "panic_on_oops",
696 .data = &panic_on_oops,
697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec,
700 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800701#if defined CONFIG_PRINTK
702 {
703 .ctl_name = KERN_PRINTK,
704 .procname = "printk",
705 .data = &console_loglevel,
706 .maxlen = 4*sizeof(int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
709 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 {
711 .ctl_name = KERN_PRINTK_RATELIMIT,
712 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700713 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = &proc_dointvec_jiffies,
717 .strategy = &sysctl_jiffies,
718 },
719 {
720 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
721 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700722 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .maxlen = sizeof(int),
724 .mode = 0644,
725 .proc_handler = &proc_dointvec,
726 },
Dave Youngaf913222009-09-22 16:43:33 -0700727 {
728 .ctl_name = CTL_UNNUMBERED,
729 .procname = "printk_delay",
730 .data = &printk_delay_msec,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = &proc_dointvec_minmax,
734 .strategy = &sysctl_intvec,
735 .extra1 = &zero,
736 .extra2 = &ten_thousand,
737 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800738#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 {
740 .ctl_name = KERN_NGROUPS_MAX,
741 .procname = "ngroups_max",
742 .data = &ngroups_max,
743 .maxlen = sizeof (int),
744 .mode = 0444,
745 .proc_handler = &proc_dointvec,
746 },
747#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
748 {
749 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
750 .procname = "unknown_nmi_panic",
751 .data = &unknown_nmi_panic,
752 .maxlen = sizeof (int),
753 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200754 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 },
Don Zickus407984f2006-09-26 10:52:27 +0200756 {
Don Zickus407984f2006-09-26 10:52:27 +0200757 .procname = "nmi_watchdog",
758 .data = &nmi_watchdog_enabled,
759 .maxlen = sizeof (int),
760 .mode = 0644,
761 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 },
763#endif
764#if defined(CONFIG_X86)
765 {
Don Zickus8da5add2006-09-26 10:52:27 +0200766 .ctl_name = KERN_PANIC_ON_NMI,
767 .procname = "panic_on_unrecovered_nmi",
768 .data = &panic_on_unrecovered_nmi,
769 .maxlen = sizeof(int),
770 .mode = 0644,
771 .proc_handler = &proc_dointvec,
772 },
773 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700774 .ctl_name = CTL_UNNUMBERED,
775 .procname = "panic_on_io_nmi",
776 .data = &panic_on_io_nmi,
777 .maxlen = sizeof(int),
778 .mode = 0644,
779 .proc_handler = &proc_dointvec,
780 },
781 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 .ctl_name = KERN_BOOTLOADER_TYPE,
783 .procname = "bootloader_type",
784 .data = &bootloader_type,
785 .maxlen = sizeof (int),
786 .mode = 0444,
787 .proc_handler = &proc_dointvec,
788 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100789 {
790 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700791 .procname = "bootloader_version",
792 .data = &bootloader_version,
793 .maxlen = sizeof (int),
794 .mode = 0444,
795 .proc_handler = &proc_dointvec,
796 },
797 {
798 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100799 .procname = "kstack_depth_to_print",
800 .data = &kstack_depth_to_print,
801 .maxlen = sizeof(int),
802 .mode = 0644,
803 .proc_handler = &proc_dointvec,
804 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100805 {
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "io_delay_type",
808 .data = &io_delay_type,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = &proc_dointvec,
812 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800814#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 {
816 .ctl_name = KERN_RANDOMIZE,
817 .procname = "randomize_va_space",
818 .data = &randomize_va_space,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = &proc_dointvec,
822 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800823#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800824#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700825 {
826 .ctl_name = KERN_SPIN_RETRY,
827 .procname = "spin_retry",
828 .data = &spin_retry,
829 .maxlen = sizeof (int),
830 .mode = 0644,
831 .proc_handler = &proc_dointvec,
832 },
833#endif
Len Brown673d5b42007-07-28 03:33:16 -0400834#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800835 {
Pavel Machekc255d842006-02-20 18:27:58 -0800836 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700837 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800838 .maxlen = sizeof (unsigned long),
839 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800840 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800841 },
842#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800843#ifdef CONFIG_IA64
844 {
845 .ctl_name = KERN_IA64_UNALIGNED,
846 .procname = "ignore-unaligned-usertrap",
847 .data = &no_unaligned_warning,
848 .maxlen = sizeof (int),
849 .mode = 0644,
850 .proc_handler = &proc_dointvec,
851 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800852 {
853 .ctl_name = CTL_UNNUMBERED,
854 .procname = "unaligned-dump-stack",
855 .data = &unaligned_dump_stack,
856 .maxlen = sizeof (int),
857 .mode = 0644,
858 .proc_handler = &proc_dointvec,
859 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800860#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700861#ifdef CONFIG_DETECT_SOFTLOCKUP
862 {
863 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200864 .procname = "softlockup_panic",
865 .data = &softlockup_panic,
866 .maxlen = sizeof(int),
867 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700868 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200869 .strategy = &sysctl_intvec,
870 .extra1 = &zero,
871 .extra2 = &one,
872 },
873 {
874 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700875 .procname = "softlockup_thresh",
876 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200877 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700878 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800879 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700880 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200881 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700882 .extra2 = &sixty,
883 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800884#endif
885#ifdef CONFIG_DETECT_HUNG_TASK
886 {
887 .ctl_name = CTL_UNNUMBERED,
888 .procname = "hung_task_panic",
889 .data = &sysctl_hung_task_panic,
890 .maxlen = sizeof(int),
891 .mode = 0644,
892 .proc_handler = &proc_dointvec_minmax,
893 .strategy = &sysctl_intvec,
894 .extra1 = &zero,
895 .extra2 = &one,
896 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100897 {
898 .ctl_name = CTL_UNNUMBERED,
899 .procname = "hung_task_check_count",
900 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100901 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100902 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100903 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100904 .strategy = &sysctl_intvec,
905 },
906 {
907 .ctl_name = CTL_UNNUMBERED,
908 .procname = "hung_task_timeout_secs",
909 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100910 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100911 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800912 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100913 .strategy = &sysctl_intvec,
914 },
915 {
916 .ctl_name = CTL_UNNUMBERED,
917 .procname = "hung_task_warnings",
918 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100919 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100920 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100921 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100922 .strategy = &sysctl_intvec,
923 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700924#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200925#ifdef CONFIG_COMPAT
926 {
927 .ctl_name = KERN_COMPAT_LOG,
928 .procname = "compat-log",
929 .data = &compat_log,
930 .maxlen = sizeof (int),
931 .mode = 0644,
932 .proc_handler = &proc_dointvec,
933 },
934#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700935#ifdef CONFIG_RT_MUTEXES
936 {
937 .ctl_name = KERN_MAX_LOCK_DEPTH,
938 .procname = "max_lock_depth",
939 .data = &max_lock_depth,
940 .maxlen = sizeof(int),
941 .mode = 0644,
942 .proc_handler = &proc_dointvec,
943 },
944#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700945 {
946 .ctl_name = CTL_UNNUMBERED,
947 .procname = "poweroff_cmd",
948 .data = &poweroff_cmd,
949 .maxlen = POWEROFF_CMD_PATH_LEN,
950 .mode = 0644,
951 .proc_handler = &proc_dostring,
952 .strategy = &sysctl_string,
953 },
David Howells0b77f5b2008-04-29 01:01:32 -0700954#ifdef CONFIG_KEYS
955 {
956 .ctl_name = CTL_UNNUMBERED,
957 .procname = "keys",
958 .mode = 0555,
959 .child = key_sysctls,
960 },
961#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700962#ifdef CONFIG_RCU_TORTURE_TEST
963 {
964 .ctl_name = CTL_UNNUMBERED,
965 .procname = "rcutorture_runnable",
966 .data = &rcutorture_runnable,
967 .maxlen = sizeof(int),
968 .mode = 0644,
969 .proc_handler = &proc_dointvec,
970 },
971#endif
David Howells12e22c52009-04-03 16:42:35 +0100972#ifdef CONFIG_SLOW_WORK
973 {
974 .ctl_name = CTL_UNNUMBERED,
975 .procname = "slow-work",
976 .mode = 0555,
977 .child = slow_work_sysctls,
978 },
979#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200980#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200981 {
982 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200983 .procname = "perf_event_paranoid",
984 .data = &sysctl_perf_event_paranoid,
985 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200986 .mode = 0644,
987 .proc_handler = &proc_dointvec,
988 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200989 {
990 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200991 .procname = "perf_event_mlock_kb",
992 .data = &sysctl_perf_event_mlock,
993 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200994 .mode = 0644,
995 .proc_handler = &proc_dointvec,
996 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200997 {
998 .ctl_name = CTL_UNNUMBERED,
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200999 .procname = "perf_event_max_sample_rate",
1000 .data = &sysctl_perf_event_sample_rate,
1001 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001002 .mode = 0644,
1003 .proc_handler = &proc_dointvec,
1004 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001005#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001006#ifdef CONFIG_KMEMCHECK
1007 {
1008 .ctl_name = CTL_UNNUMBERED,
1009 .procname = "kmemcheck",
1010 .data = &kmemcheck_enabled,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
1013 .proc_handler = &proc_dointvec,
1014 },
1015#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001016#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001017 {
1018 .ctl_name = CTL_UNNUMBERED,
1019 .procname = "blk_iopoll",
1020 .data = &blk_iopoll_enabled,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
1023 .proc_handler = &proc_dointvec,
1024 },
Jens Axboecb684b52009-09-15 21:53:11 +02001025#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -07001026/*
1027 * NOTE: do not add new entries to this table unless you have read
1028 * Documentation/sysctl/ctl_unnumbered.txt
1029 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 { .ctl_name = 0 }
1031};
1032
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001033static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 {
1035 .ctl_name = VM_OVERCOMMIT_MEMORY,
1036 .procname = "overcommit_memory",
1037 .data = &sysctl_overcommit_memory,
1038 .maxlen = sizeof(sysctl_overcommit_memory),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec,
1041 },
1042 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001043 .ctl_name = VM_PANIC_ON_OOM,
1044 .procname = "panic_on_oom",
1045 .data = &sysctl_panic_on_oom,
1046 .maxlen = sizeof(sysctl_panic_on_oom),
1047 .mode = 0644,
1048 .proc_handler = &proc_dointvec,
1049 },
1050 {
David Rientjesfe071d72007-10-16 23:25:56 -07001051 .ctl_name = CTL_UNNUMBERED,
1052 .procname = "oom_kill_allocating_task",
1053 .data = &sysctl_oom_kill_allocating_task,
1054 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1055 .mode = 0644,
1056 .proc_handler = &proc_dointvec,
1057 },
1058 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001059 .ctl_name = CTL_UNNUMBERED,
1060 .procname = "oom_dump_tasks",
1061 .data = &sysctl_oom_dump_tasks,
1062 .maxlen = sizeof(sysctl_oom_dump_tasks),
1063 .mode = 0644,
1064 .proc_handler = &proc_dointvec,
1065 },
1066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .ctl_name = VM_OVERCOMMIT_RATIO,
1068 .procname = "overcommit_ratio",
1069 .data = &sysctl_overcommit_ratio,
1070 .maxlen = sizeof(sysctl_overcommit_ratio),
1071 .mode = 0644,
1072 .proc_handler = &proc_dointvec,
1073 },
1074 {
1075 .ctl_name = VM_PAGE_CLUSTER,
1076 .procname = "page-cluster",
1077 .data = &page_cluster,
1078 .maxlen = sizeof(int),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec,
1081 },
1082 {
1083 .ctl_name = VM_DIRTY_BACKGROUND,
1084 .procname = "dirty_background_ratio",
1085 .data = &dirty_background_ratio,
1086 .maxlen = sizeof(dirty_background_ratio),
1087 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001088 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 .strategy = &sysctl_intvec,
1090 .extra1 = &zero,
1091 .extra2 = &one_hundred,
1092 },
1093 {
David Rientjes2da02992009-01-06 14:39:31 -08001094 .ctl_name = CTL_UNNUMBERED,
1095 .procname = "dirty_background_bytes",
1096 .data = &dirty_background_bytes,
1097 .maxlen = sizeof(dirty_background_bytes),
1098 .mode = 0644,
1099 .proc_handler = &dirty_background_bytes_handler,
1100 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001101 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001102 },
1103 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 .ctl_name = VM_DIRTY_RATIO,
1105 .procname = "dirty_ratio",
1106 .data = &vm_dirty_ratio,
1107 .maxlen = sizeof(vm_dirty_ratio),
1108 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001109 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .strategy = &sysctl_intvec,
1111 .extra1 = &zero,
1112 .extra2 = &one_hundred,
1113 },
1114 {
David Rientjes2da02992009-01-06 14:39:31 -08001115 .ctl_name = CTL_UNNUMBERED,
1116 .procname = "dirty_bytes",
1117 .data = &vm_dirty_bytes,
1118 .maxlen = sizeof(vm_dirty_bytes),
1119 .mode = 0644,
1120 .proc_handler = &dirty_bytes_handler,
1121 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001122 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001123 },
1124 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001126 .data = &dirty_writeback_interval,
1127 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 .mode = 0644,
1129 .proc_handler = &dirty_writeback_centisecs_handler,
1130 },
1131 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001133 .data = &dirty_expire_interval,
1134 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001136 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 },
1138 {
1139 .ctl_name = VM_NR_PDFLUSH_THREADS,
1140 .procname = "nr_pdflush_threads",
1141 .data = &nr_pdflush_threads,
1142 .maxlen = sizeof nr_pdflush_threads,
1143 .mode = 0444 /* read-only*/,
1144 .proc_handler = &proc_dointvec,
1145 },
1146 {
1147 .ctl_name = VM_SWAPPINESS,
1148 .procname = "swappiness",
1149 .data = &vm_swappiness,
1150 .maxlen = sizeof(vm_swappiness),
1151 .mode = 0644,
1152 .proc_handler = &proc_dointvec_minmax,
1153 .strategy = &sysctl_intvec,
1154 .extra1 = &zero,
1155 .extra2 = &one_hundred,
1156 },
1157#ifdef CONFIG_HUGETLB_PAGE
1158 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001160 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 .maxlen = sizeof(unsigned long),
1162 .mode = 0644,
1163 .proc_handler = &hugetlb_sysctl_handler,
1164 .extra1 = (void *)&hugetlb_zero,
1165 .extra2 = (void *)&hugetlb_infinity,
1166 },
1167 {
1168 .ctl_name = VM_HUGETLB_GROUP,
1169 .procname = "hugetlb_shm_group",
1170 .data = &sysctl_hugetlb_shm_group,
1171 .maxlen = sizeof(gid_t),
1172 .mode = 0644,
1173 .proc_handler = &proc_dointvec,
1174 },
Mel Gorman396faf02007-07-17 04:03:13 -07001175 {
1176 .ctl_name = CTL_UNNUMBERED,
1177 .procname = "hugepages_treat_as_movable",
1178 .data = &hugepages_treat_as_movable,
1179 .maxlen = sizeof(int),
1180 .mode = 0644,
1181 .proc_handler = &hugetlb_treat_movable_handler,
1182 },
Adam Litke54f9f802007-10-16 01:26:20 -07001183 {
1184 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001185 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001186 .data = NULL,
1187 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001188 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001189 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001190 .extra1 = (void *)&hugetlb_zero,
1191 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001192 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193#endif
1194 {
1195 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1196 .procname = "lowmem_reserve_ratio",
1197 .data = &sysctl_lowmem_reserve_ratio,
1198 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1199 .mode = 0644,
1200 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1201 .strategy = &sysctl_intvec,
1202 },
1203 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001204 .ctl_name = VM_DROP_PAGECACHE,
1205 .procname = "drop_caches",
1206 .data = &sysctl_drop_caches,
1207 .maxlen = sizeof(int),
1208 .mode = 0644,
1209 .proc_handler = drop_caches_sysctl_handler,
1210 .strategy = &sysctl_intvec,
1211 },
1212 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 .ctl_name = VM_MIN_FREE_KBYTES,
1214 .procname = "min_free_kbytes",
1215 .data = &min_free_kbytes,
1216 .maxlen = sizeof(min_free_kbytes),
1217 .mode = 0644,
1218 .proc_handler = &min_free_kbytes_sysctl_handler,
1219 .strategy = &sysctl_intvec,
1220 .extra1 = &zero,
1221 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001222 {
1223 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1224 .procname = "percpu_pagelist_fraction",
1225 .data = &percpu_pagelist_fraction,
1226 .maxlen = sizeof(percpu_pagelist_fraction),
1227 .mode = 0644,
1228 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1229 .strategy = &sysctl_intvec,
1230 .extra1 = &min_percpu_pagelist_fract,
1231 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232#ifdef CONFIG_MMU
1233 {
1234 .ctl_name = VM_MAX_MAP_COUNT,
1235 .procname = "max_map_count",
1236 .data = &sysctl_max_map_count,
1237 .maxlen = sizeof(sysctl_max_map_count),
1238 .mode = 0644,
1239 .proc_handler = &proc_dointvec
1240 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001241#else
1242 {
1243 .ctl_name = CTL_UNNUMBERED,
1244 .procname = "nr_trim_pages",
1245 .data = &sysctl_nr_trim_pages,
1246 .maxlen = sizeof(sysctl_nr_trim_pages),
1247 .mode = 0644,
1248 .proc_handler = &proc_dointvec_minmax,
1249 .strategy = &sysctl_intvec,
1250 .extra1 = &zero,
1251 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252#endif
1253 {
1254 .ctl_name = VM_LAPTOP_MODE,
1255 .procname = "laptop_mode",
1256 .data = &laptop_mode,
1257 .maxlen = sizeof(laptop_mode),
1258 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001259 .proc_handler = &proc_dointvec_jiffies,
1260 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 },
1262 {
1263 .ctl_name = VM_BLOCK_DUMP,
1264 .procname = "block_dump",
1265 .data = &block_dump,
1266 .maxlen = sizeof(block_dump),
1267 .mode = 0644,
1268 .proc_handler = &proc_dointvec,
1269 .strategy = &sysctl_intvec,
1270 .extra1 = &zero,
1271 },
1272 {
1273 .ctl_name = VM_VFS_CACHE_PRESSURE,
1274 .procname = "vfs_cache_pressure",
1275 .data = &sysctl_vfs_cache_pressure,
1276 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1277 .mode = 0644,
1278 .proc_handler = &proc_dointvec,
1279 .strategy = &sysctl_intvec,
1280 .extra1 = &zero,
1281 },
1282#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1283 {
1284 .ctl_name = VM_LEGACY_VA_LAYOUT,
1285 .procname = "legacy_va_layout",
1286 .data = &sysctl_legacy_va_layout,
1287 .maxlen = sizeof(sysctl_legacy_va_layout),
1288 .mode = 0644,
1289 .proc_handler = &proc_dointvec,
1290 .strategy = &sysctl_intvec,
1291 .extra1 = &zero,
1292 },
1293#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001294#ifdef CONFIG_NUMA
1295 {
1296 .ctl_name = VM_ZONE_RECLAIM_MODE,
1297 .procname = "zone_reclaim_mode",
1298 .data = &zone_reclaim_mode,
1299 .maxlen = sizeof(zone_reclaim_mode),
1300 .mode = 0644,
1301 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001302 .strategy = &sysctl_intvec,
1303 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001304 },
Christoph Lameter96146342006-07-03 00:24:13 -07001305 {
1306 .ctl_name = VM_MIN_UNMAPPED,
1307 .procname = "min_unmapped_ratio",
1308 .data = &sysctl_min_unmapped_ratio,
1309 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1310 .mode = 0644,
1311 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1312 .strategy = &sysctl_intvec,
1313 .extra1 = &zero,
1314 .extra2 = &one_hundred,
1315 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001316 {
1317 .ctl_name = VM_MIN_SLAB,
1318 .procname = "min_slab_ratio",
1319 .data = &sysctl_min_slab_ratio,
1320 .maxlen = sizeof(sysctl_min_slab_ratio),
1321 .mode = 0644,
1322 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1323 .strategy = &sysctl_intvec,
1324 .extra1 = &zero,
1325 .extra2 = &one_hundred,
1326 },
Christoph Lameter17436602006-01-18 17:42:32 -08001327#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001328#ifdef CONFIG_SMP
1329 {
1330 .ctl_name = CTL_UNNUMBERED,
1331 .procname = "stat_interval",
1332 .data = &sysctl_stat_interval,
1333 .maxlen = sizeof(sysctl_stat_interval),
1334 .mode = 0644,
1335 .proc_handler = &proc_dointvec_jiffies,
1336 .strategy = &sysctl_jiffies,
1337 },
1338#endif
Eric Parised032182007-06-28 15:55:21 -04001339 {
1340 .ctl_name = CTL_UNNUMBERED,
1341 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001342 .data = &dac_mmap_min_addr,
1343 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001344 .mode = 0644,
Eric Paris788084a2009-07-31 12:54:11 -04001345 .proc_handler = &mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001346 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001347#ifdef CONFIG_NUMA
1348 {
1349 .ctl_name = CTL_UNNUMBERED,
1350 .procname = "numa_zonelist_order",
1351 .data = &numa_zonelist_order,
1352 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1353 .mode = 0644,
1354 .proc_handler = &numa_zonelist_order_handler,
1355 .strategy = &sysctl_string,
1356 },
1357#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001358#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001359 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001360 {
1361 .ctl_name = VM_VDSO_ENABLED,
1362 .procname = "vdso_enabled",
1363 .data = &vdso_enabled,
1364 .maxlen = sizeof(vdso_enabled),
1365 .mode = 0644,
1366 .proc_handler = &proc_dointvec,
1367 .strategy = &sysctl_intvec,
1368 .extra1 = &zero,
1369 },
1370#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001371#ifdef CONFIG_HIGHMEM
1372 {
1373 .ctl_name = CTL_UNNUMBERED,
1374 .procname = "highmem_is_dirtyable",
1375 .data = &vm_highmem_is_dirtyable,
1376 .maxlen = sizeof(vm_highmem_is_dirtyable),
1377 .mode = 0644,
1378 .proc_handler = &proc_dointvec_minmax,
1379 .strategy = &sysctl_intvec,
1380 .extra1 = &zero,
1381 .extra2 = &one,
1382 },
1383#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001384 {
1385 .ctl_name = CTL_UNNUMBERED,
1386 .procname = "scan_unevictable_pages",
1387 .data = &scan_unevictable_pages,
1388 .maxlen = sizeof(scan_unevictable_pages),
1389 .mode = 0644,
1390 .proc_handler = &scan_unevictable_handler,
1391 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001392/*
1393 * NOTE: do not add new entries to this table unless you have read
1394 * Documentation/sysctl/ctl_unnumbered.txt
1395 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 { .ctl_name = 0 }
1397};
1398
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001399#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001400static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001401 { .ctl_name = 0 }
1402};
1403#endif
1404
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001405static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 {
1407 .ctl_name = FS_NRINODE,
1408 .procname = "inode-nr",
1409 .data = &inodes_stat,
1410 .maxlen = 2*sizeof(int),
1411 .mode = 0444,
1412 .proc_handler = &proc_dointvec,
1413 },
1414 {
1415 .ctl_name = FS_STATINODE,
1416 .procname = "inode-state",
1417 .data = &inodes_stat,
1418 .maxlen = 7*sizeof(int),
1419 .mode = 0444,
1420 .proc_handler = &proc_dointvec,
1421 },
1422 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .procname = "file-nr",
1424 .data = &files_stat,
1425 .maxlen = 3*sizeof(int),
1426 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001427 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 },
1429 {
1430 .ctl_name = FS_MAXFILE,
1431 .procname = "file-max",
1432 .data = &files_stat.max_files,
1433 .maxlen = sizeof(int),
1434 .mode = 0644,
1435 .proc_handler = &proc_dointvec,
1436 },
1437 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001438 .ctl_name = CTL_UNNUMBERED,
1439 .procname = "nr_open",
1440 .data = &sysctl_nr_open,
1441 .maxlen = sizeof(int),
1442 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001443 .proc_handler = &proc_dointvec_minmax,
1444 .extra1 = &sysctl_nr_open_min,
1445 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001446 },
1447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .ctl_name = FS_DENTRY,
1449 .procname = "dentry-state",
1450 .data = &dentry_stat,
1451 .maxlen = 6*sizeof(int),
1452 .mode = 0444,
1453 .proc_handler = &proc_dointvec,
1454 },
1455 {
1456 .ctl_name = FS_OVERFLOWUID,
1457 .procname = "overflowuid",
1458 .data = &fs_overflowuid,
1459 .maxlen = sizeof(int),
1460 .mode = 0644,
1461 .proc_handler = &proc_dointvec_minmax,
1462 .strategy = &sysctl_intvec,
1463 .extra1 = &minolduid,
1464 .extra2 = &maxolduid,
1465 },
1466 {
1467 .ctl_name = FS_OVERFLOWGID,
1468 .procname = "overflowgid",
1469 .data = &fs_overflowgid,
1470 .maxlen = sizeof(int),
1471 .mode = 0644,
1472 .proc_handler = &proc_dointvec_minmax,
1473 .strategy = &sysctl_intvec,
1474 .extra1 = &minolduid,
1475 .extra2 = &maxolduid,
1476 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001477#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 {
1479 .ctl_name = FS_LEASES,
1480 .procname = "leases-enable",
1481 .data = &leases_enable,
1482 .maxlen = sizeof(int),
1483 .mode = 0644,
1484 .proc_handler = &proc_dointvec,
1485 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001486#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487#ifdef CONFIG_DNOTIFY
1488 {
1489 .ctl_name = FS_DIR_NOTIFY,
1490 .procname = "dir-notify-enable",
1491 .data = &dir_notify_enable,
1492 .maxlen = sizeof(int),
1493 .mode = 0644,
1494 .proc_handler = &proc_dointvec,
1495 },
1496#endif
1497#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001498#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 {
1500 .ctl_name = FS_LEASE_TIME,
1501 .procname = "lease-break-time",
1502 .data = &lease_break_time,
1503 .maxlen = sizeof(int),
1504 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001505 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001507#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001508#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 .procname = "aio-nr",
1511 .data = &aio_nr,
1512 .maxlen = sizeof(aio_nr),
1513 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001514 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 },
1516 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 .procname = "aio-max-nr",
1518 .data = &aio_max_nr,
1519 .maxlen = sizeof(aio_max_nr),
1520 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001521 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001523#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001524#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001525 {
1526 .ctl_name = FS_INOTIFY,
1527 .procname = "inotify",
1528 .mode = 0555,
1529 .child = inotify_table,
1530 },
1531#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001532#ifdef CONFIG_EPOLL
1533 {
1534 .procname = "epoll",
1535 .mode = 0555,
1536 .child = epoll_table,
1537 },
1538#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001540 {
1541 .ctl_name = KERN_SETUID_DUMPABLE,
1542 .procname = "suid_dumpable",
1543 .data = &suid_dumpable,
1544 .maxlen = sizeof(int),
1545 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001546 .proc_handler = &proc_dointvec_minmax,
1547 .strategy = &sysctl_intvec,
1548 .extra1 = &zero,
1549 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001550 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001551#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1552 {
1553 .ctl_name = CTL_UNNUMBERED,
1554 .procname = "binfmt_misc",
1555 .mode = 0555,
1556 .child = binfmt_misc_table,
1557 },
1558#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001559/*
1560 * NOTE: do not add new entries to this table unless you have read
1561 * Documentation/sysctl/ctl_unnumbered.txt
1562 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 { .ctl_name = 0 }
1564};
1565
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001566static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001567#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001568 {
1569 .ctl_name = CTL_UNNUMBERED,
1570 .procname = "exception-trace",
1571 .data = &show_unhandled_signals,
1572 .maxlen = sizeof(int),
1573 .mode = 0644,
1574 .proc_handler = proc_dointvec
1575 },
1576#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 { .ctl_name = 0 }
1578};
1579
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001580static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001582};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Al Viro330d57f2005-11-04 10:18:40 +00001584static DEFINE_SPINLOCK(sysctl_lock);
1585
1586/* called under sysctl_lock */
1587static int use_table(struct ctl_table_header *p)
1588{
1589 if (unlikely(p->unregistering))
1590 return 0;
1591 p->used++;
1592 return 1;
1593}
1594
1595/* called under sysctl_lock */
1596static void unuse_table(struct ctl_table_header *p)
1597{
1598 if (!--p->used)
1599 if (unlikely(p->unregistering))
1600 complete(p->unregistering);
1601}
1602
1603/* called under sysctl_lock, will reacquire if has to wait */
1604static void start_unregistering(struct ctl_table_header *p)
1605{
1606 /*
1607 * if p->used is 0, nobody will ever touch that entry again;
1608 * we'll eliminate all paths to it before dropping sysctl_lock
1609 */
1610 if (unlikely(p->used)) {
1611 struct completion wait;
1612 init_completion(&wait);
1613 p->unregistering = &wait;
1614 spin_unlock(&sysctl_lock);
1615 wait_for_completion(&wait);
1616 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001617 } else {
1618 /* anything non-NULL; we'll never dereference it */
1619 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001620 }
1621 /*
1622 * do not remove from the list until nobody holds it; walking the
1623 * list in do_sysctl() relies on that.
1624 */
1625 list_del_init(&p->ctl_entry);
1626}
1627
Al Virof7e6ced2008-07-15 01:44:23 -04001628void sysctl_head_get(struct ctl_table_header *head)
1629{
1630 spin_lock(&sysctl_lock);
1631 head->count++;
1632 spin_unlock(&sysctl_lock);
1633}
1634
1635void sysctl_head_put(struct ctl_table_header *head)
1636{
1637 spin_lock(&sysctl_lock);
1638 if (!--head->count)
1639 kfree(head);
1640 spin_unlock(&sysctl_lock);
1641}
1642
1643struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1644{
1645 if (!head)
1646 BUG();
1647 spin_lock(&sysctl_lock);
1648 if (!use_table(head))
1649 head = ERR_PTR(-ENOENT);
1650 spin_unlock(&sysctl_lock);
1651 return head;
1652}
1653
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001654void sysctl_head_finish(struct ctl_table_header *head)
1655{
1656 if (!head)
1657 return;
1658 spin_lock(&sysctl_lock);
1659 unuse_table(head);
1660 spin_unlock(&sysctl_lock);
1661}
1662
Al Viro73455092008-07-14 21:22:20 -04001663static struct ctl_table_set *
1664lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1665{
1666 struct ctl_table_set *set = &root->default_set;
1667 if (root->lookup)
1668 set = root->lookup(root, namespaces);
1669 return set;
1670}
1671
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001672static struct list_head *
1673lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001674{
Al Viro73455092008-07-14 21:22:20 -04001675 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1676 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001677}
1678
1679struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1680 struct ctl_table_header *prev)
1681{
1682 struct ctl_table_root *root;
1683 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001684 struct ctl_table_header *head;
1685 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001686
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001687 spin_lock(&sysctl_lock);
1688 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001689 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001690 tmp = &prev->ctl_entry;
1691 unuse_table(prev);
1692 goto next;
1693 }
1694 tmp = &root_table_header.ctl_entry;
1695 for (;;) {
1696 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1697
1698 if (!use_table(head))
1699 goto next;
1700 spin_unlock(&sysctl_lock);
1701 return head;
1702 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001703 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001704 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001705 header_list = lookup_header_list(root, namespaces);
1706 if (tmp != header_list)
1707 continue;
1708
1709 do {
1710 root = list_entry(root->root_list.next,
1711 struct ctl_table_root, root_list);
1712 if (root == &sysctl_table_root)
1713 goto out;
1714 header_list = lookup_header_list(root, namespaces);
1715 } while (list_empty(header_list));
1716 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001717 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001718out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001719 spin_unlock(&sysctl_lock);
1720 return NULL;
1721}
1722
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001723struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1724{
1725 return __sysctl_head_next(current->nsproxy, prev);
1726}
1727
1728void register_sysctl_root(struct ctl_table_root *root)
1729{
1730 spin_lock(&sysctl_lock);
1731 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1732 spin_unlock(&sysctl_lock);
1733}
1734
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001735#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001736/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001737static int do_sysctl_strategy(struct ctl_table_root *root,
1738 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001739 void __user *oldval, size_t __user *oldlenp,
1740 void __user *newval, size_t newlen)
1741{
1742 int op = 0, rc;
1743
1744 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001745 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001746 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001747 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001748 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001749 return -EPERM;
1750
1751 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001752 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001753 if (rc < 0)
1754 return rc;
1755 if (rc > 0)
1756 return 0;
1757 }
1758
1759 /* If there is no strategy routine, or if the strategy returns
1760 * zero, proceed with automatic r/w */
1761 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001762 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001763 if (rc < 0)
1764 return rc;
1765 }
1766 return 0;
1767}
1768
1769static int parse_table(int __user *name, int nlen,
1770 void __user *oldval, size_t __user *oldlenp,
1771 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001772 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001773 struct ctl_table *table)
1774{
1775 int n;
1776repeat:
1777 if (!nlen)
1778 return -ENOTDIR;
1779 if (get_user(n, name))
1780 return -EFAULT;
1781 for ( ; table->ctl_name || table->procname; table++) {
1782 if (!table->ctl_name)
1783 continue;
1784 if (n == table->ctl_name) {
1785 int error;
1786 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001787 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001788 return -EPERM;
1789 name++;
1790 nlen--;
1791 table = table->child;
1792 goto repeat;
1793 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001794 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001795 oldval, oldlenp,
1796 newval, newlen);
1797 return error;
1798 }
1799 }
1800 return -ENOTDIR;
1801}
1802
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1804 void __user *newval, size_t newlen)
1805{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001806 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001807 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
1809 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1810 return -ENOTDIR;
1811 if (oldval) {
1812 int old_len;
1813 if (!oldlenp || get_user(old_len, oldlenp))
1814 return -EFAULT;
1815 }
Al Viro330d57f2005-11-04 10:18:40 +00001816
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001817 for (head = sysctl_head_next(NULL); head;
1818 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001819 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001820 newval, newlen,
1821 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001822 if (error != -ENOTDIR) {
1823 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001824 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001825 }
1826 }
Al Viro330d57f2005-11-04 10:18:40 +00001827 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828}
1829
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001830SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831{
1832 struct __sysctl_args tmp;
1833 int error;
1834
1835 if (copy_from_user(&tmp, args, sizeof(tmp)))
1836 return -EFAULT;
1837
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001838 error = deprecated_sysctl_warning(&tmp);
1839 if (error)
1840 goto out;
1841
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 lock_kernel();
1843 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1844 tmp.newval, tmp.newlen);
1845 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001846out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 return error;
1848}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001849#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
1851/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001852 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 * some sysctl variables are readonly even to root.
1854 */
1855
1856static int test_perm(int mode, int op)
1857{
David Howells76aac0e2008-11-14 10:39:12 +11001858 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 mode >>= 6;
1860 else if (in_egroup_p(0))
1861 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001862 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 return 0;
1864 return -EACCES;
1865}
1866
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001867int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868{
1869 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001870 int mode;
1871
Al Viroe6305c42008-07-15 21:03:57 -04001872 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 if (error)
1874 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001875
1876 if (root->permissions)
1877 mode = root->permissions(root, current->nsproxy, table);
1878 else
1879 mode = table->mode;
1880
1881 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882}
1883
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001884static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1885{
1886 for (; table->ctl_name || table->procname; table++) {
1887 table->parent = parent;
1888 if (table->child)
1889 sysctl_set_parent(table, table->child);
1890 }
1891}
1892
1893static __init int sysctl_init(void)
1894{
1895 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001896#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1897 {
1898 int err;
1899 err = sysctl_check_table(current->nsproxy, root_table);
1900 }
1901#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001902 return 0;
1903}
1904
1905core_initcall(sysctl_init);
1906
Al Virobfbcf032008-07-27 06:31:22 +01001907static struct ctl_table *is_branch_in(struct ctl_table *branch,
1908 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001909{
1910 struct ctl_table *p;
1911 const char *s = branch->procname;
1912
1913 /* branch should have named subdirectory as its first element */
1914 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001915 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001916
1917 /* ... and nothing else */
1918 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001919 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001920
1921 /* table should contain subdirectory with the same name */
1922 for (p = table; p->procname || p->ctl_name; p++) {
1923 if (!p->child)
1924 continue;
1925 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001926 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001927 }
Al Virobfbcf032008-07-27 06:31:22 +01001928 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001929}
1930
1931/* see if attaching q to p would be an improvement */
1932static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1933{
1934 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001935 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001936 int is_better = 0;
1937 int not_in_parent = !p->attached_by;
1938
Al Virobfbcf032008-07-27 06:31:22 +01001939 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001940 if (by == q->attached_by)
1941 is_better = 1;
1942 if (to == p->attached_by)
1943 not_in_parent = 1;
1944 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001945 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001946 }
1947
1948 if (is_better && not_in_parent) {
1949 q->attached_by = by;
1950 q->attached_to = to;
1951 q->parent = p;
1952 }
1953}
1954
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001956 * __register_sysctl_paths - register a sysctl hierarchy
1957 * @root: List of sysctl headers to register on
1958 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001959 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 *
1962 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001963 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001965 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 *
1967 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1968 * must be unique within that level of sysctl
1969 *
1970 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1971 * enter a sysctl file
1972 *
1973 * data - a pointer to data for use by proc_handler
1974 *
1975 * maxlen - the maximum size in bytes of the data
1976 *
1977 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1978 *
1979 * child - a pointer to the child sysctl table if this entry is a directory, or
1980 * %NULL.
1981 *
1982 * proc_handler - the text handler routine (described below)
1983 *
1984 * strategy - the strategy routine (described below)
1985 *
1986 * de - for internal use by the sysctl routines
1987 *
1988 * extra1, extra2 - extra pointers usable by the proc handler routines
1989 *
1990 * Leaf nodes in the sysctl tree will be represented by a single file
1991 * under /proc; non-leaf nodes will be represented by directories.
1992 *
1993 * sysctl(2) can automatically manage read and write requests through
1994 * the sysctl table. The data and maxlen fields of the ctl_table
1995 * struct enable minimal validation of the values being written to be
1996 * performed, and the mode field allows minimal authentication.
1997 *
1998 * More sophisticated management can be enabled by the provision of a
1999 * strategy routine with the table entry. This will be called before
2000 * any automatic read or write of the data is performed.
2001 *
2002 * The strategy routine may return
2003 *
2004 * < 0 - Error occurred (error is passed to user process)
2005 *
2006 * 0 - OK - proceed with automatic read or write.
2007 *
2008 * > 0 - OK - read or write has been done by the strategy routine, so
2009 * return immediately.
2010 *
2011 * There must be a proc_handler routine for any terminal nodes
2012 * mirrored under /proc/sys (non-terminals are handled by a built-in
2013 * directory handler). Several default handlers are available to
2014 * cover common cases -
2015 *
2016 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2017 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2018 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2019 *
2020 * It is the handler's job to read the input buffer from user memory
2021 * and process it. The handler should return 0 on success.
2022 *
2023 * This routine returns %NULL on a failure to register, and a pointer
2024 * to the table header on success.
2025 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002026struct ctl_table_header *__register_sysctl_paths(
2027 struct ctl_table_root *root,
2028 struct nsproxy *namespaces,
2029 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002031 struct ctl_table_header *header;
2032 struct ctl_table *new, **prevp;
2033 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04002034 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002035
2036 /* Count the path components */
2037 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2038 ;
2039
2040 /*
2041 * For each path component, allocate a 2-element ctl_table array.
2042 * The first array element will be filled with the sysctl entry
2043 * for this, the second will be the sentinel (ctl_name == 0).
2044 *
2045 * We allocate everything in one go so that we don't have to
2046 * worry about freeing additional memory in unregister_sysctl_table.
2047 */
2048 header = kzalloc(sizeof(struct ctl_table_header) +
2049 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2050 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002052
2053 new = (struct ctl_table *) (header + 1);
2054
2055 /* Now connect the dots */
2056 prevp = &header->ctl_table;
2057 for (n = 0; n < npath; ++n, ++path) {
2058 /* Copy the procname */
2059 new->procname = path->procname;
2060 new->ctl_name = path->ctl_name;
2061 new->mode = 0555;
2062
2063 *prevp = new;
2064 prevp = &new->child;
2065
2066 new += 2;
2067 }
2068 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002069 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002070
2071 INIT_LIST_HEAD(&header->ctl_entry);
2072 header->used = 0;
2073 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002074 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002075 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002076 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002077#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002078 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002079 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002080 return NULL;
2081 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002082#endif
Al Viro330d57f2005-11-04 10:18:40 +00002083 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002084 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002085 header->attached_by = header->ctl_table;
2086 header->attached_to = root_table;
2087 header->parent = &root_table_header;
2088 for (set = header->set; set; set = set->parent) {
2089 struct ctl_table_header *p;
2090 list_for_each_entry(p, &set->list, ctl_entry) {
2091 if (p->unregistering)
2092 continue;
2093 try_attach(p, header);
2094 }
2095 }
2096 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002097 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002098 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002099
2100 return header;
2101}
2102
2103/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002104 * register_sysctl_table_path - register a sysctl table hierarchy
2105 * @path: The path to the directory the sysctl table is in.
2106 * @table: the top-level table structure
2107 *
2108 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2109 * array. A completely 0 filled entry terminates the table.
2110 *
2111 * See __register_sysctl_paths for more details.
2112 */
2113struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2114 struct ctl_table *table)
2115{
2116 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2117 path, table);
2118}
2119
2120/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002121 * register_sysctl_table - register a sysctl table hierarchy
2122 * @table: the top-level table structure
2123 *
2124 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2125 * array. A completely 0 filled entry terminates the table.
2126 *
2127 * See register_sysctl_paths for more details.
2128 */
2129struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2130{
2131 static const struct ctl_path null_path[] = { {} };
2132
2133 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
2136/**
2137 * unregister_sysctl_table - unregister a sysctl table hierarchy
2138 * @header: the header returned from register_sysctl_table
2139 *
2140 * Unregisters the sysctl table and all children. proc entries may not
2141 * actually be removed until they are no longer used by anyone.
2142 */
2143void unregister_sysctl_table(struct ctl_table_header * header)
2144{
Al Viro330d57f2005-11-04 10:18:40 +00002145 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002146
2147 if (header == NULL)
2148 return;
2149
Al Viro330d57f2005-11-04 10:18:40 +00002150 spin_lock(&sysctl_lock);
2151 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002152 if (!--header->parent->count) {
2153 WARN_ON(1);
2154 kfree(header->parent);
2155 }
Al Virof7e6ced2008-07-15 01:44:23 -04002156 if (!--header->count)
2157 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002158 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159}
2160
Al Viro9043476f2008-07-15 08:54:06 -04002161int sysctl_is_seen(struct ctl_table_header *p)
2162{
2163 struct ctl_table_set *set = p->set;
2164 int res;
2165 spin_lock(&sysctl_lock);
2166 if (p->unregistering)
2167 res = 0;
2168 else if (!set->is_seen)
2169 res = 1;
2170 else
2171 res = set->is_seen(set);
2172 spin_unlock(&sysctl_lock);
2173 return res;
2174}
2175
Al Viro73455092008-07-14 21:22:20 -04002176void setup_sysctl_set(struct ctl_table_set *p,
2177 struct ctl_table_set *parent,
2178 int (*is_seen)(struct ctl_table_set *))
2179{
2180 INIT_LIST_HEAD(&p->list);
2181 p->parent = parent ? parent : &sysctl_table_root.default_set;
2182 p->is_seen = is_seen;
2183}
2184
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002185#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002186struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002187{
2188 return NULL;
2189}
2190
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002191struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2192 struct ctl_table *table)
2193{
2194 return NULL;
2195}
2196
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002197void unregister_sysctl_table(struct ctl_table_header * table)
2198{
2199}
2200
Al Viro73455092008-07-14 21:22:20 -04002201void setup_sysctl_set(struct ctl_table_set *p,
2202 struct ctl_table_set *parent,
2203 int (*is_seen)(struct ctl_table_set *))
2204{
2205}
2206
Al Virof7e6ced2008-07-15 01:44:23 -04002207void sysctl_head_put(struct ctl_table_header *head)
2208{
2209}
2210
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002211#endif /* CONFIG_SYSCTL */
2212
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213/*
2214 * /proc/sys support
2215 */
2216
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002217#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002219static int _proc_do_string(void* data, int maxlen, int write,
2220 struct file *filp, void __user *buffer,
2221 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002222{
2223 size_t len;
2224 char __user *p;
2225 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002226
2227 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002228 *lenp = 0;
2229 return 0;
2230 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002231
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002232 if (write) {
2233 len = 0;
2234 p = buffer;
2235 while (len < *lenp) {
2236 if (get_user(c, p++))
2237 return -EFAULT;
2238 if (c == 0 || c == '\n')
2239 break;
2240 len++;
2241 }
2242 if (len >= maxlen)
2243 len = maxlen-1;
2244 if(copy_from_user(data, buffer, len))
2245 return -EFAULT;
2246 ((char *) data)[len] = 0;
2247 *ppos += *lenp;
2248 } else {
2249 len = strlen(data);
2250 if (len > maxlen)
2251 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002252
2253 if (*ppos > len) {
2254 *lenp = 0;
2255 return 0;
2256 }
2257
2258 data += *ppos;
2259 len -= *ppos;
2260
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002261 if (len > *lenp)
2262 len = *lenp;
2263 if (len)
2264 if(copy_to_user(buffer, data, len))
2265 return -EFAULT;
2266 if (len < *lenp) {
2267 if(put_user('\n', ((char __user *) buffer) + len))
2268 return -EFAULT;
2269 len++;
2270 }
2271 *lenp = len;
2272 *ppos += len;
2273 }
2274 return 0;
2275}
2276
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277/**
2278 * proc_dostring - read a string sysctl
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
2281 * @filp: the file structure
2282 * @buffer: the user buffer
2283 * @lenp: the size of the user buffer
2284 * @ppos: file position
2285 *
2286 * Reads/writes a string from/to the user buffer. If the kernel
2287 * buffer provided is not large enough to hold the string, the
2288 * string is truncated. The copied string is %NULL-terminated.
2289 * If the string is being read by the user process, it is copied
2290 * and a newline '\n' is added. It is truncated if the buffer is
2291 * not large enough.
2292 *
2293 * Returns 0 on success.
2294 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002295int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 void __user *buffer, size_t *lenp, loff_t *ppos)
2297{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002298 return _proc_do_string(table->data, table->maxlen, write, filp,
2299 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300}
2301
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
2303static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2304 int *valp,
2305 int write, void *data)
2306{
2307 if (write) {
2308 *valp = *negp ? -*lvalp : *lvalp;
2309 } else {
2310 int val = *valp;
2311 if (val < 0) {
2312 *negp = -1;
2313 *lvalp = (unsigned long)-val;
2314 } else {
2315 *negp = 0;
2316 *lvalp = (unsigned long)val;
2317 }
2318 }
2319 return 0;
2320}
2321
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002322static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002323 int write, struct file *filp, void __user *buffer,
2324 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2326 int write, void *data),
2327 void *data)
2328{
2329#define TMPBUFLEN 21
Sukanto Ghosh7338f292009-06-17 16:27:50 -07002330 int *i, vleft, first = 1, neg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 unsigned long lval;
2332 size_t left, len;
2333
2334 char buf[TMPBUFLEN], *p;
2335 char __user *s = buffer;
2336
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002337 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 (*ppos && !write)) {
2339 *lenp = 0;
2340 return 0;
2341 }
2342
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002343 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 vleft = table->maxlen / sizeof(*i);
2345 left = *lenp;
2346
2347 if (!conv)
2348 conv = do_proc_dointvec_conv;
2349
2350 for (; left && vleft--; i++, first=0) {
2351 if (write) {
2352 while (left) {
2353 char c;
2354 if (get_user(c, s))
2355 return -EFAULT;
2356 if (!isspace(c))
2357 break;
2358 left--;
2359 s++;
2360 }
2361 if (!left)
2362 break;
2363 neg = 0;
2364 len = left;
2365 if (len > sizeof(buf) - 1)
2366 len = sizeof(buf) - 1;
2367 if (copy_from_user(buf, s, len))
2368 return -EFAULT;
2369 buf[len] = 0;
2370 p = buf;
2371 if (*p == '-' && left > 1) {
2372 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002373 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 }
2375 if (*p < '0' || *p > '9')
2376 break;
2377
2378 lval = simple_strtoul(p, &p, 0);
2379
2380 len = p-buf;
2381 if ((len < left) && *p && !isspace(*p))
2382 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 s += len;
2384 left -= len;
2385
2386 if (conv(&neg, &lval, i, 1, data))
2387 break;
2388 } else {
2389 p = buf;
2390 if (!first)
2391 *p++ = '\t';
2392
2393 if (conv(&neg, &lval, i, 0, data))
2394 break;
2395
2396 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2397 len = strlen(buf);
2398 if (len > left)
2399 len = left;
2400 if(copy_to_user(s, buf, len))
2401 return -EFAULT;
2402 left -= len;
2403 s += len;
2404 }
2405 }
2406
2407 if (!write && !first && left) {
2408 if(put_user('\n', s))
2409 return -EFAULT;
2410 left--, s++;
2411 }
2412 if (write) {
2413 while (left) {
2414 char c;
2415 if (get_user(c, s++))
2416 return -EFAULT;
2417 if (!isspace(c))
2418 break;
2419 left--;
2420 }
2421 }
2422 if (write && first)
2423 return -EINVAL;
2424 *lenp -= left;
2425 *ppos += *lenp;
2426 return 0;
2427#undef TMPBUFLEN
2428}
2429
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002430static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002431 void __user *buffer, size_t *lenp, loff_t *ppos,
2432 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2433 int write, void *data),
2434 void *data)
2435{
2436 return __do_proc_dointvec(table->data, table, write, filp,
2437 buffer, lenp, ppos, conv, data);
2438}
2439
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440/**
2441 * proc_dointvec - read a vector of integers
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @filp: the file structure
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: file position
2448 *
2449 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2450 * values from/to the user buffer, treated as an ASCII string.
2451 *
2452 * Returns 0 on success.
2453 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002454int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 void __user *buffer, size_t *lenp, loff_t *ppos)
2456{
2457 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2458 NULL,NULL);
2459}
2460
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002461/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002462 * Taint values can only be increased
2463 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002464 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002465static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002466 void __user *buffer, size_t *lenp, loff_t *ppos)
2467{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002468 struct ctl_table t;
2469 unsigned long tmptaint = get_taint();
2470 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002471
Bastian Blank91fcd412007-04-23 14:41:14 -07002472 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002473 return -EPERM;
2474
Andi Kleen25ddbb12008-10-15 22:01:41 -07002475 t = *table;
2476 t.data = &tmptaint;
2477 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2478 if (err < 0)
2479 return err;
2480
2481 if (write) {
2482 /*
2483 * Poor man's atomic or. Not worth adding a primitive
2484 * to everyone's atomic.h for this
2485 */
2486 int i;
2487 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2488 if ((tmptaint >> i) & 1)
2489 add_taint(i);
2490 }
2491 }
2492
2493 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002494}
2495
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496struct do_proc_dointvec_minmax_conv_param {
2497 int *min;
2498 int *max;
2499};
2500
2501static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2502 int *valp,
2503 int write, void *data)
2504{
2505 struct do_proc_dointvec_minmax_conv_param *param = data;
2506 if (write) {
2507 int val = *negp ? -*lvalp : *lvalp;
2508 if ((param->min && *param->min > val) ||
2509 (param->max && *param->max < val))
2510 return -EINVAL;
2511 *valp = val;
2512 } else {
2513 int val = *valp;
2514 if (val < 0) {
2515 *negp = -1;
2516 *lvalp = (unsigned long)-val;
2517 } else {
2518 *negp = 0;
2519 *lvalp = (unsigned long)val;
2520 }
2521 }
2522 return 0;
2523}
2524
2525/**
2526 * proc_dointvec_minmax - read a vector of integers with min/max values
2527 * @table: the sysctl table
2528 * @write: %TRUE if this is a write to the sysctl file
2529 * @filp: the file structure
2530 * @buffer: the user buffer
2531 * @lenp: the size of the user buffer
2532 * @ppos: file position
2533 *
2534 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2535 * values from/to the user buffer, treated as an ASCII string.
2536 *
2537 * This routine will ensure the values are within the range specified by
2538 * table->extra1 (min) and table->extra2 (max).
2539 *
2540 * Returns 0 on success.
2541 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002542int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 void __user *buffer, size_t *lenp, loff_t *ppos)
2544{
2545 struct do_proc_dointvec_minmax_conv_param param = {
2546 .min = (int *) table->extra1,
2547 .max = (int *) table->extra2,
2548 };
2549 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2550 do_proc_dointvec_minmax_conv, &param);
2551}
2552
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002553static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 struct file *filp,
2555 void __user *buffer,
2556 size_t *lenp, loff_t *ppos,
2557 unsigned long convmul,
2558 unsigned long convdiv)
2559{
2560#define TMPBUFLEN 21
2561 unsigned long *i, *min, *max, val;
2562 int vleft, first=1, neg;
2563 size_t len, left;
2564 char buf[TMPBUFLEN], *p;
2565 char __user *s = buffer;
2566
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002567 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 (*ppos && !write)) {
2569 *lenp = 0;
2570 return 0;
2571 }
2572
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002573 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 min = (unsigned long *) table->extra1;
2575 max = (unsigned long *) table->extra2;
2576 vleft = table->maxlen / sizeof(unsigned long);
2577 left = *lenp;
2578
2579 for (; left && vleft--; i++, min++, max++, first=0) {
2580 if (write) {
2581 while (left) {
2582 char c;
2583 if (get_user(c, s))
2584 return -EFAULT;
2585 if (!isspace(c))
2586 break;
2587 left--;
2588 s++;
2589 }
2590 if (!left)
2591 break;
2592 neg = 0;
2593 len = left;
2594 if (len > TMPBUFLEN-1)
2595 len = TMPBUFLEN-1;
2596 if (copy_from_user(buf, s, len))
2597 return -EFAULT;
2598 buf[len] = 0;
2599 p = buf;
2600 if (*p == '-' && left > 1) {
2601 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002602 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 }
2604 if (*p < '0' || *p > '9')
2605 break;
2606 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2607 len = p-buf;
2608 if ((len < left) && *p && !isspace(*p))
2609 break;
2610 if (neg)
2611 val = -val;
2612 s += len;
2613 left -= len;
2614
2615 if(neg)
2616 continue;
2617 if ((min && val < *min) || (max && val > *max))
2618 continue;
2619 *i = val;
2620 } else {
2621 p = buf;
2622 if (!first)
2623 *p++ = '\t';
2624 sprintf(p, "%lu", convdiv * (*i) / convmul);
2625 len = strlen(buf);
2626 if (len > left)
2627 len = left;
2628 if(copy_to_user(s, buf, len))
2629 return -EFAULT;
2630 left -= len;
2631 s += len;
2632 }
2633 }
2634
2635 if (!write && !first && left) {
2636 if(put_user('\n', s))
2637 return -EFAULT;
2638 left--, s++;
2639 }
2640 if (write) {
2641 while (left) {
2642 char c;
2643 if (get_user(c, s++))
2644 return -EFAULT;
2645 if (!isspace(c))
2646 break;
2647 left--;
2648 }
2649 }
2650 if (write && first)
2651 return -EINVAL;
2652 *lenp -= left;
2653 *ppos += *lenp;
2654 return 0;
2655#undef TMPBUFLEN
2656}
2657
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002658static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002659 struct file *filp,
2660 void __user *buffer,
2661 size_t *lenp, loff_t *ppos,
2662 unsigned long convmul,
2663 unsigned long convdiv)
2664{
2665 return __do_proc_doulongvec_minmax(table->data, table, write,
2666 filp, buffer, lenp, ppos, convmul, convdiv);
2667}
2668
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669/**
2670 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2671 * @table: the sysctl table
2672 * @write: %TRUE if this is a write to the sysctl file
2673 * @filp: the file structure
2674 * @buffer: the user buffer
2675 * @lenp: the size of the user buffer
2676 * @ppos: file position
2677 *
2678 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2679 * values from/to the user buffer, treated as an ASCII string.
2680 *
2681 * This routine will ensure the values are within the range specified by
2682 * table->extra1 (min) and table->extra2 (max).
2683 *
2684 * Returns 0 on success.
2685 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002686int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 void __user *buffer, size_t *lenp, loff_t *ppos)
2688{
2689 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2690}
2691
2692/**
2693 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2694 * @table: the sysctl table
2695 * @write: %TRUE if this is a write to the sysctl file
2696 * @filp: the file structure
2697 * @buffer: the user buffer
2698 * @lenp: the size of the user buffer
2699 * @ppos: file position
2700 *
2701 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2702 * values from/to the user buffer, treated as an ASCII string. The values
2703 * are treated as milliseconds, and converted to jiffies when they are stored.
2704 *
2705 * This routine will ensure the values are within the range specified by
2706 * table->extra1 (min) and table->extra2 (max).
2707 *
2708 * Returns 0 on success.
2709 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002710int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 struct file *filp,
2712 void __user *buffer,
2713 size_t *lenp, loff_t *ppos)
2714{
2715 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2716 lenp, ppos, HZ, 1000l);
2717}
2718
2719
2720static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2721 int *valp,
2722 int write, void *data)
2723{
2724 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002725 if (*lvalp > LONG_MAX / HZ)
2726 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2728 } else {
2729 int val = *valp;
2730 unsigned long lval;
2731 if (val < 0) {
2732 *negp = -1;
2733 lval = (unsigned long)-val;
2734 } else {
2735 *negp = 0;
2736 lval = (unsigned long)val;
2737 }
2738 *lvalp = lval / HZ;
2739 }
2740 return 0;
2741}
2742
2743static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2744 int *valp,
2745 int write, void *data)
2746{
2747 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002748 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2749 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2751 } else {
2752 int val = *valp;
2753 unsigned long lval;
2754 if (val < 0) {
2755 *negp = -1;
2756 lval = (unsigned long)-val;
2757 } else {
2758 *negp = 0;
2759 lval = (unsigned long)val;
2760 }
2761 *lvalp = jiffies_to_clock_t(lval);
2762 }
2763 return 0;
2764}
2765
2766static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2767 int *valp,
2768 int write, void *data)
2769{
2770 if (write) {
2771 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2772 } else {
2773 int val = *valp;
2774 unsigned long lval;
2775 if (val < 0) {
2776 *negp = -1;
2777 lval = (unsigned long)-val;
2778 } else {
2779 *negp = 0;
2780 lval = (unsigned long)val;
2781 }
2782 *lvalp = jiffies_to_msecs(lval);
2783 }
2784 return 0;
2785}
2786
2787/**
2788 * proc_dointvec_jiffies - read a vector of integers as seconds
2789 * @table: the sysctl table
2790 * @write: %TRUE if this is a write to the sysctl file
2791 * @filp: the file structure
2792 * @buffer: the user buffer
2793 * @lenp: the size of the user buffer
2794 * @ppos: file position
2795 *
2796 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2797 * values from/to the user buffer, treated as an ASCII string.
2798 * The values read are assumed to be in seconds, and are converted into
2799 * jiffies.
2800 *
2801 * Returns 0 on success.
2802 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002803int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 void __user *buffer, size_t *lenp, loff_t *ppos)
2805{
2806 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2807 do_proc_dointvec_jiffies_conv,NULL);
2808}
2809
2810/**
2811 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2812 * @table: the sysctl table
2813 * @write: %TRUE if this is a write to the sysctl file
2814 * @filp: the file structure
2815 * @buffer: the user buffer
2816 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002817 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 *
2819 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2820 * values from/to the user buffer, treated as an ASCII string.
2821 * The values read are assumed to be in 1/USER_HZ seconds, and
2822 * are converted into jiffies.
2823 *
2824 * Returns 0 on success.
2825 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002826int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 void __user *buffer, size_t *lenp, loff_t *ppos)
2828{
2829 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2830 do_proc_dointvec_userhz_jiffies_conv,NULL);
2831}
2832
2833/**
2834 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2835 * @table: the sysctl table
2836 * @write: %TRUE if this is a write to the sysctl file
2837 * @filp: the file structure
2838 * @buffer: the user buffer
2839 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002840 * @ppos: file position
2841 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 *
2843 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2844 * values from/to the user buffer, treated as an ASCII string.
2845 * The values read are assumed to be in 1/1000 seconds, and
2846 * are converted into jiffies.
2847 *
2848 * Returns 0 on success.
2849 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002850int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 void __user *buffer, size_t *lenp, loff_t *ppos)
2852{
2853 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2854 do_proc_dointvec_ms_jiffies_conv, NULL);
2855}
2856
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002857static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002858 void __user *buffer, size_t *lenp, loff_t *ppos)
2859{
2860 struct pid *new_pid;
2861 pid_t tmp;
2862 int r;
2863
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002864 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002865
2866 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2867 lenp, ppos, NULL, NULL);
2868 if (r || !write)
2869 return r;
2870
2871 new_pid = find_get_pid(tmp);
2872 if (!new_pid)
2873 return -ESRCH;
2874
2875 put_pid(xchg(&cad_pid, new_pid));
2876 return 0;
2877}
2878
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879#else /* CONFIG_PROC_FS */
2880
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002881int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 void __user *buffer, size_t *lenp, loff_t *ppos)
2883{
2884 return -ENOSYS;
2885}
2886
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002887int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 void __user *buffer, size_t *lenp, loff_t *ppos)
2889{
2890 return -ENOSYS;
2891}
2892
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002893int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 void __user *buffer, size_t *lenp, loff_t *ppos)
2895{
2896 return -ENOSYS;
2897}
2898
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002899int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 void __user *buffer, size_t *lenp, loff_t *ppos)
2901{
2902 return -ENOSYS;
2903}
2904
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002905int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 void __user *buffer, size_t *lenp, loff_t *ppos)
2907{
2908 return -ENOSYS;
2909}
2910
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002911int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 void __user *buffer, size_t *lenp, loff_t *ppos)
2913{
2914 return -ENOSYS;
2915}
2916
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002917int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 void __user *buffer, size_t *lenp, loff_t *ppos)
2919{
2920 return -ENOSYS;
2921}
2922
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002923int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 struct file *filp,
2925 void __user *buffer,
2926 size_t *lenp, loff_t *ppos)
2927{
2928 return -ENOSYS;
2929}
2930
2931
2932#endif /* CONFIG_PROC_FS */
2933
2934
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002935#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936/*
2937 * General sysctl support routines
2938 */
2939
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002940/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002941int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002942 void __user *oldval, size_t __user *oldlenp,
2943 void __user *newval, size_t newlen)
2944{
2945 size_t len;
2946
2947 /* Get out of I don't have a variable */
2948 if (!table->data || !table->maxlen)
2949 return -ENOTDIR;
2950
2951 if (oldval && oldlenp) {
2952 if (get_user(len, oldlenp))
2953 return -EFAULT;
2954 if (len) {
2955 if (len > table->maxlen)
2956 len = table->maxlen;
2957 if (copy_to_user(oldval, table->data, len))
2958 return -EFAULT;
2959 if (put_user(len, oldlenp))
2960 return -EFAULT;
2961 }
2962 }
2963
2964 if (newval && newlen) {
2965 if (newlen > table->maxlen)
2966 newlen = table->maxlen;
2967
2968 if (copy_from_user(table->data, newval, newlen))
2969 return -EFAULT;
2970 }
2971 return 1;
2972}
2973
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002975int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002977 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 if (!table->data || !table->maxlen)
2980 return -ENOTDIR;
2981
2982 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002983 size_t bufsize;
2984 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002986 if (bufsize) {
2987 size_t len = strlen(table->data), copied;
2988
2989 /* This shouldn't trigger for a well-formed sysctl */
2990 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002992
2993 /* Copy up to a max of bufsize-1 bytes of the string */
2994 copied = (len >= bufsize) ? bufsize - 1 : len;
2995
2996 if (copy_to_user(oldval, table->data, copied) ||
2997 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002999 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 return -EFAULT;
3001 }
3002 }
3003 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08003004 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 if (len > table->maxlen)
3006 len = table->maxlen;
3007 if(copy_from_user(table->data, newval, len))
3008 return -EFAULT;
3009 if (len == table->maxlen)
3010 len--;
3011 ((char *) table->data)[len] = 0;
3012 }
Yi Yang82c9df82005-12-30 16:37:10 +08003013 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014}
3015
3016/*
3017 * This function makes sure that all of the integers in the vector
3018 * are between the minimum and maximum values given in the arrays
3019 * table->extra1 and table->extra2, respectively.
3020 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003021int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003023 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024{
3025
3026 if (newval && newlen) {
3027 int __user *vec = (int __user *) newval;
3028 int *min = (int *) table->extra1;
3029 int *max = (int *) table->extra2;
3030 size_t length;
3031 int i;
3032
3033 if (newlen % sizeof(int) != 0)
3034 return -EINVAL;
3035
3036 if (!table->extra1 && !table->extra2)
3037 return 0;
3038
3039 if (newlen > table->maxlen)
3040 newlen = table->maxlen;
3041 length = newlen / sizeof(int);
3042
3043 for (i = 0; i < length; i++) {
3044 int value;
3045 if (get_user(value, vec + i))
3046 return -EFAULT;
3047 if (min && value < min[i])
3048 return -EINVAL;
3049 if (max && value > max[i])
3050 return -EINVAL;
3051 }
3052 }
3053 return 0;
3054}
3055
3056/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003057int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003059 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003061 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003063
3064 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003066 if (olen) {
3067 int val;
3068
3069 if (olen < sizeof(int))
3070 return -EINVAL;
3071
3072 val = *(int *)(table->data) / HZ;
3073 if (put_user(val, (int __user *)oldval))
3074 return -EFAULT;
3075 if (put_user(sizeof(int), oldlenp))
3076 return -EFAULT;
3077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 }
3079 if (newval && newlen) {
3080 int new;
3081 if (newlen != sizeof(int))
3082 return -EINVAL;
3083 if (get_user(new, (int __user *)newval))
3084 return -EFAULT;
3085 *(int *)(table->data) = new*HZ;
3086 }
3087 return 1;
3088}
3089
3090/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003091int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003093 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003095 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003097
3098 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003100 if (olen) {
3101 int val;
3102
3103 if (olen < sizeof(int))
3104 return -EINVAL;
3105
3106 val = jiffies_to_msecs(*(int *)(table->data));
3107 if (put_user(val, (int __user *)oldval))
3108 return -EFAULT;
3109 if (put_user(sizeof(int), oldlenp))
3110 return -EFAULT;
3111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 }
3113 if (newval && newlen) {
3114 int new;
3115 if (newlen != sizeof(int))
3116 return -EINVAL;
3117 if (get_user(new, (int __user *)newval))
3118 return -EFAULT;
3119 *(int *)(table->data) = msecs_to_jiffies(new);
3120 }
3121 return 1;
3122}
3123
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003124
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003125
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003126#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127
3128
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003129SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003131 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003132 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003133
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003134 if (copy_from_user(&tmp, args, sizeof(tmp)))
3135 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003136
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003137 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003138
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003139 /* If no error reading the parameters then just -ENOSYS ... */
3140 if (!error)
3141 error = -ENOSYS;
3142
3143 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144}
3145
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003146int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003147 void __user *oldval, size_t __user *oldlenp,
3148 void __user *newval, size_t newlen)
3149{
3150 return -ENOSYS;
3151}
3152
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003153int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003155 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156{
3157 return -ENOSYS;
3158}
3159
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003160int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003162 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163{
3164 return -ENOSYS;
3165}
3166
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003167int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003169 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170{
3171 return -ENOSYS;
3172}
3173
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003174int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003176 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177{
3178 return -ENOSYS;
3179}
3180
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003181#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003183static int deprecated_sysctl_warning(struct __sysctl_args *args)
3184{
3185 static int msg_count;
3186 int name[CTL_MAXNAME];
3187 int i;
3188
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003189 /* Check args->nlen. */
3190 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3191 return -ENOTDIR;
3192
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003193 /* Read in the sysctl name for better debug message logging */
3194 for (i = 0; i < args->nlen; i++)
3195 if (get_user(name[i], args->name + i))
3196 return -EFAULT;
3197
3198 /* Ignore accesses to kernel.version */
3199 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3200 return 0;
3201
3202 if (msg_count < 5) {
3203 msg_count++;
3204 printk(KERN_INFO
3205 "warning: process `%s' used the deprecated sysctl "
3206 "system call with ", current->comm);
3207 for (i = 0; i < args->nlen; i++)
3208 printk("%d.", name[i]);
3209 printk("\n");
3210 }
3211 return 0;
3212}
3213
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214/*
3215 * No sense putting this after each symbol definition, twice,
3216 * exception granted :-)
3217 */
3218EXPORT_SYMBOL(proc_dointvec);
3219EXPORT_SYMBOL(proc_dointvec_jiffies);
3220EXPORT_SYMBOL(proc_dointvec_minmax);
3221EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3222EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3223EXPORT_SYMBOL(proc_dostring);
3224EXPORT_SYMBOL(proc_doulongvec_minmax);
3225EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3226EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003227EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228EXPORT_SYMBOL(sysctl_intvec);
3229EXPORT_SYMBOL(sysctl_jiffies);
3230EXPORT_SYMBOL(sysctl_ms_jiffies);
3231EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003232EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233EXPORT_SYMBOL(unregister_sysctl_table);