blob: 0e51a35a44869425aa3f4e7cf9fca498787fd0fb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010051#include <linux/slow-work.h>
Peter Zijlstra1ccd1542009-04-09 10:53:45 +020052#include <linux/perf_counter.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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070094/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080095#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020097static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098#endif
99
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700100static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700101static int __maybe_unused one = 1;
102static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800103static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700104static int one_hundred = 100;
105
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700106/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
107static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
110static int maxolduid = 65535;
111static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800112static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114static int ngroups_max = NGROUPS_MAX;
115
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200116#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117extern char modprobe_path[];
Kees Cook3d433212009-04-02 15:49:29 -0700118extern int modules_disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#ifdef CONFIG_CHR_DEV_SG
121extern int sg_big_buff;
122#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
David S. Miller72c57ed2008-09-11 23:29:54 -0700124#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700125#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#endif
127
David S. Miller08714202008-11-16 23:49:24 -0800128#ifdef CONFIG_SPARC64
129extern int sysctl_tsb_ratio;
130#endif
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#ifdef __hppa__
133extern int pwrsw_enabled;
134extern int unaligned_enabled;
135#endif
136
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800137#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#ifdef CONFIG_MATHEMU
139extern int sysctl_ieee_emulation_warnings;
140#endif
141extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700142extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#endif
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#ifdef CONFIG_BSD_PROCESS_ACCT
146extern int acct_parm[];
147#endif
148
Jes Sorensend2b176e2006-02-28 09:42:23 -0800149#ifdef CONFIG_IA64
150extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800151extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800152#endif
153
Ingo Molnar23f78d42006-06-27 02:54:53 -0700154#ifdef CONFIG_RT_MUTEXES
155extern int max_lock_depth;
156#endif
157
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700158#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700159static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700160 void __user *buffer, size_t *lenp, loff_t *ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700161static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800162 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700163#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700164
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700165static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100166static struct ctl_table_root sysctl_table_root;
167static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100168 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100169 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400170 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100171 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400172 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100173};
174static struct ctl_table_root sysctl_table_root = {
175 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400176 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100177};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700179static struct ctl_table kern_table[];
180static struct ctl_table vm_table[];
181static struct ctl_table fs_table[];
182static struct ctl_table debug_table[];
183static struct ctl_table dev_table[];
184extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700185#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700186extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400187#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800188#ifdef CONFIG_EPOLL
189extern struct ctl_table epoll_table[];
190#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
193int sysctl_legacy_va_layout;
194#endif
195
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700196extern int prove_locking;
197extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199/* The default sysctl tables: */
200
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700201static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 {
203 .ctl_name = CTL_KERN,
204 .procname = "kernel",
205 .mode = 0555,
206 .child = kern_table,
207 },
208 {
209 .ctl_name = CTL_VM,
210 .procname = "vm",
211 .mode = 0555,
212 .child = vm_table,
213 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 .ctl_name = CTL_FS,
216 .procname = "fs",
217 .mode = 0555,
218 .child = fs_table,
219 },
220 {
221 .ctl_name = CTL_DEBUG,
222 .procname = "debug",
223 .mode = 0555,
224 .child = debug_table,
225 },
226 {
227 .ctl_name = CTL_DEV,
228 .procname = "dev",
229 .mode = 0555,
230 .child = dev_table,
231 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700232/*
233 * NOTE: do not add new entries to this table unless you have read
234 * Documentation/sysctl/ctl_unnumbered.txt
235 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 { .ctl_name = 0 }
237};
238
Ingo Molnar77e54a12007-07-09 18:52:00 +0200239#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100240static int min_sched_granularity_ns = 100000; /* 100 usecs */
241static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
242static int min_wakeup_granularity_ns; /* 0 usecs */
243static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244#endif
245
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700246static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200247#ifdef CONFIG_SCHED_DEBUG
248 {
249 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100250 .procname = "sched_min_granularity_ns",
251 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200252 .maxlen = sizeof(unsigned int),
253 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100254 .proc_handler = &sched_nr_latency_handler,
255 .strategy = &sysctl_intvec,
256 .extra1 = &min_sched_granularity_ns,
257 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200258 },
259 {
260 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200261 .procname = "sched_latency_ns",
262 .data = &sysctl_sched_latency,
263 .maxlen = sizeof(unsigned int),
264 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100265 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200266 .strategy = &sysctl_intvec,
267 .extra1 = &min_sched_granularity_ns,
268 .extra2 = &max_sched_granularity_ns,
269 },
270 {
271 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200272 .procname = "sched_wakeup_granularity_ns",
273 .data = &sysctl_sched_wakeup_granularity,
274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
276 .proc_handler = &proc_dointvec_minmax,
277 .strategy = &sysctl_intvec,
278 .extra1 = &min_wakeup_granularity_ns,
279 .extra2 = &max_wakeup_granularity_ns,
280 },
281 {
282 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200283 .procname = "sched_shares_ratelimit",
284 .data = &sysctl_sched_shares_ratelimit,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = &proc_dointvec,
288 },
289 {
290 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200291 .procname = "sched_shares_thresh",
292 .data = &sysctl_sched_shares_thresh,
293 .maxlen = sizeof(unsigned int),
294 .mode = 0644,
295 .proc_handler = &proc_dointvec_minmax,
296 .strategy = &sysctl_intvec,
297 .extra1 = &zero,
298 },
299 {
300 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301 .procname = "sched_child_runs_first",
302 .data = &sysctl_sched_child_runs_first,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = &proc_dointvec,
306 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200307 {
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "sched_features",
310 .data = &sysctl_sched_features,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = &proc_dointvec,
314 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200315 {
316 .ctl_name = CTL_UNNUMBERED,
317 .procname = "sched_migration_cost",
318 .data = &sysctl_sched_migration_cost,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
321 .proc_handler = &proc_dointvec,
322 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100323 {
324 .ctl_name = CTL_UNNUMBERED,
325 .procname = "sched_nr_migrate",
326 .data = &sysctl_sched_nr_migrate,
327 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100328 .mode = 0644,
329 .proc_handler = &proc_dointvec,
330 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530331 {
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "timer_migration",
334 .data = &sysctl_timer_migration,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
338 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200339#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200340 {
341 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100342 .procname = "sched_rt_period_us",
343 .data = &sysctl_sched_rt_period,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200346 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100347 },
348 {
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "sched_rt_runtime_us",
351 .data = &sysctl_sched_rt_runtime,
352 .maxlen = sizeof(int),
353 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200354 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100355 },
356 {
357 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200358 .procname = "sched_compat_yield",
359 .data = &sysctl_sched_compat_yield,
360 .maxlen = sizeof(unsigned int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700364#ifdef CONFIG_PROVE_LOCKING
365 {
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "prove_locking",
368 .data = &prove_locking,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &proc_dointvec,
372 },
373#endif
374#ifdef CONFIG_LOCK_STAT
375 {
376 .ctl_name = CTL_UNNUMBERED,
377 .procname = "lock_stat",
378 .data = &lock_stat,
379 .maxlen = sizeof(int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .ctl_name = KERN_PANIC,
386 .procname = "panic",
387 .data = &panic_timeout,
388 .maxlen = sizeof(int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
391 },
392 {
393 .ctl_name = KERN_CORE_USES_PID,
394 .procname = "core_uses_pid",
395 .data = &core_uses_pid,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
399 },
400 {
401 .ctl_name = KERN_CORE_PATTERN,
402 .procname = "core_pattern",
403 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700404 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 .mode = 0644,
406 .proc_handler = &proc_dostring,
407 .strategy = &sysctl_string,
408 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800409#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700412 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800413 .mode = 0644,
Andi Kleen25ddbb12008-10-15 22:01:41 -0700414 .proc_handler = &proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800416#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100417#ifdef CONFIG_LATENCYTOP
418 {
419 .procname = "latencytop",
420 .data = &latencytop_enabled,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = &proc_dointvec,
424 },
425#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#ifdef CONFIG_BLK_DEV_INITRD
427 {
428 .ctl_name = KERN_REALROOTDEV,
429 .procname = "real-root-dev",
430 .data = &real_root_dev,
431 .maxlen = sizeof(int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
435#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700436 {
437 .ctl_name = CTL_UNNUMBERED,
438 .procname = "print-fatal-signals",
439 .data = &print_fatal_signals,
440 .maxlen = sizeof(int),
441 .mode = 0644,
442 .proc_handler = &proc_dointvec,
443 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700444#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 {
446 .ctl_name = KERN_SPARC_REBOOT,
447 .procname = "reboot-cmd",
448 .data = reboot_command,
449 .maxlen = 256,
450 .mode = 0644,
451 .proc_handler = &proc_dostring,
452 .strategy = &sysctl_string,
453 },
454 {
455 .ctl_name = KERN_SPARC_STOP_A,
456 .procname = "stop-a",
457 .data = &stop_a_enabled,
458 .maxlen = sizeof (int),
459 .mode = 0644,
460 .proc_handler = &proc_dointvec,
461 },
462 {
463 .ctl_name = KERN_SPARC_SCONS_PWROFF,
464 .procname = "scons-poweroff",
465 .data = &scons_pwroff,
466 .maxlen = sizeof (int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
469 },
470#endif
David S. Miller08714202008-11-16 23:49:24 -0800471#ifdef CONFIG_SPARC64
472 {
473 .ctl_name = CTL_UNNUMBERED,
474 .procname = "tsb-ratio",
475 .data = &sysctl_tsb_ratio,
476 .maxlen = sizeof (int),
477 .mode = 0644,
478 .proc_handler = &proc_dointvec,
479 },
480#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#ifdef __hppa__
482 {
483 .ctl_name = KERN_HPPA_PWRSW,
484 .procname = "soft-power",
485 .data = &pwrsw_enabled,
486 .maxlen = sizeof (int),
487 .mode = 0644,
488 .proc_handler = &proc_dointvec,
489 },
490 {
491 .ctl_name = KERN_HPPA_UNALIGNED,
492 .procname = "unaligned-trap",
493 .data = &unaligned_enabled,
494 .maxlen = sizeof (int),
495 .mode = 0644,
496 .proc_handler = &proc_dointvec,
497 },
498#endif
499 {
500 .ctl_name = KERN_CTLALTDEL,
501 .procname = "ctrl-alt-del",
502 .data = &C_A_D,
503 .maxlen = sizeof(int),
504 .mode = 0644,
505 .proc_handler = &proc_dointvec,
506 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400507#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200508 {
509 .ctl_name = CTL_UNNUMBERED,
510 .procname = "ftrace_enabled",
511 .data = &ftrace_enabled,
512 .maxlen = sizeof(int),
513 .mode = 0644,
514 .proc_handler = &ftrace_enable_sysctl,
515 },
516#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500517#ifdef CONFIG_STACK_TRACER
518 {
519 .ctl_name = CTL_UNNUMBERED,
520 .procname = "stack_tracer_enabled",
521 .data = &stack_tracer_enabled,
522 .maxlen = sizeof(int),
523 .mode = 0644,
524 .proc_handler = &stack_trace_sysctl,
525 },
526#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400527#ifdef CONFIG_TRACING
528 {
529 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100530 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400531 .data = &ftrace_dump_on_oops,
532 .maxlen = sizeof(int),
533 .mode = 0644,
534 .proc_handler = &proc_dointvec,
535 },
536#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200537#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
539 .ctl_name = KERN_MODPROBE,
540 .procname = "modprobe",
541 .data = &modprobe_path,
542 .maxlen = KMOD_PATH_LEN,
543 .mode = 0644,
544 .proc_handler = &proc_dostring,
545 .strategy = &sysctl_string,
546 },
Kees Cook3d433212009-04-02 15:49:29 -0700547 {
548 .ctl_name = CTL_UNNUMBERED,
549 .procname = "modules_disabled",
550 .data = &modules_disabled,
551 .maxlen = sizeof(int),
552 .mode = 0644,
553 /* only handle a transition from default "0" to "1" */
554 .proc_handler = &proc_dointvec_minmax,
555 .extra1 = &one,
556 .extra2 = &one,
557 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700559#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 {
561 .ctl_name = KERN_HOTPLUG,
562 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100563 .data = &uevent_helper,
564 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .mode = 0644,
566 .proc_handler = &proc_dostring,
567 .strategy = &sysctl_string,
568 },
569#endif
570#ifdef CONFIG_CHR_DEV_SG
571 {
572 .ctl_name = KERN_SG_BIG_BUFF,
573 .procname = "sg-big-buff",
574 .data = &sg_big_buff,
575 .maxlen = sizeof (int),
576 .mode = 0444,
577 .proc_handler = &proc_dointvec,
578 },
579#endif
580#ifdef CONFIG_BSD_PROCESS_ACCT
581 {
582 .ctl_name = KERN_ACCT,
583 .procname = "acct",
584 .data = &acct_parm,
585 .maxlen = 3*sizeof(int),
586 .mode = 0644,
587 .proc_handler = &proc_dointvec,
588 },
589#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#ifdef CONFIG_MAGIC_SYSRQ
591 {
592 .ctl_name = KERN_SYSRQ,
593 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800594 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .maxlen = sizeof (int),
596 .mode = 0644,
597 .proc_handler = &proc_dointvec,
598 },
599#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700600#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700603 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 .maxlen = sizeof (int),
605 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700606 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700608#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 {
610 .ctl_name = KERN_MAX_THREADS,
611 .procname = "threads-max",
612 .data = &max_threads,
613 .maxlen = sizeof(int),
614 .mode = 0644,
615 .proc_handler = &proc_dointvec,
616 },
617 {
618 .ctl_name = KERN_RANDOM,
619 .procname = "random",
620 .mode = 0555,
621 .child = random_table,
622 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 {
624 .ctl_name = KERN_OVERFLOWUID,
625 .procname = "overflowuid",
626 .data = &overflowuid,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = &proc_dointvec_minmax,
630 .strategy = &sysctl_intvec,
631 .extra1 = &minolduid,
632 .extra2 = &maxolduid,
633 },
634 {
635 .ctl_name = KERN_OVERFLOWGID,
636 .procname = "overflowgid",
637 .data = &overflowgid,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 .proc_handler = &proc_dointvec_minmax,
641 .strategy = &sysctl_intvec,
642 .extra1 = &minolduid,
643 .extra2 = &maxolduid,
644 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800645#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646#ifdef CONFIG_MATHEMU
647 {
648 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
649 .procname = "ieee_emulation_warnings",
650 .data = &sysctl_ieee_emulation_warnings,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec,
654 },
655#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 {
657 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
658 .procname = "userprocess_debug",
659 .data = &sysctl_userprocess_debug,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
664#endif
665 {
666 .ctl_name = KERN_PIDMAX,
667 .procname = "pid_max",
668 .data = &pid_max,
669 .maxlen = sizeof (int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec_minmax,
672 .strategy = sysctl_intvec,
673 .extra1 = &pid_max_min,
674 .extra2 = &pid_max_max,
675 },
676 {
677 .ctl_name = KERN_PANIC_ON_OOPS,
678 .procname = "panic_on_oops",
679 .data = &panic_on_oops,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
683 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800684#if defined CONFIG_PRINTK
685 {
686 .ctl_name = KERN_PRINTK,
687 .procname = "printk",
688 .data = &console_loglevel,
689 .maxlen = 4*sizeof(int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec,
692 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 {
694 .ctl_name = KERN_PRINTK_RATELIMIT,
695 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700696 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec_jiffies,
700 .strategy = &sysctl_jiffies,
701 },
702 {
703 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
704 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700705 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 .maxlen = sizeof(int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
709 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800710#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 {
712 .ctl_name = KERN_NGROUPS_MAX,
713 .procname = "ngroups_max",
714 .data = &ngroups_max,
715 .maxlen = sizeof (int),
716 .mode = 0444,
717 .proc_handler = &proc_dointvec,
718 },
719#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
720 {
721 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
722 .procname = "unknown_nmi_panic",
723 .data = &unknown_nmi_panic,
724 .maxlen = sizeof (int),
725 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200726 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 },
Don Zickus407984f2006-09-26 10:52:27 +0200728 {
Don Zickus407984f2006-09-26 10:52:27 +0200729 .procname = "nmi_watchdog",
730 .data = &nmi_watchdog_enabled,
731 .maxlen = sizeof (int),
732 .mode = 0644,
733 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 },
735#endif
736#if defined(CONFIG_X86)
737 {
Don Zickus8da5add2006-09-26 10:52:27 +0200738 .ctl_name = KERN_PANIC_ON_NMI,
739 .procname = "panic_on_unrecovered_nmi",
740 .data = &panic_on_unrecovered_nmi,
741 .maxlen = sizeof(int),
742 .mode = 0644,
743 .proc_handler = &proc_dointvec,
744 },
745 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 .ctl_name = KERN_BOOTLOADER_TYPE,
747 .procname = "bootloader_type",
748 .data = &bootloader_type,
749 .maxlen = sizeof (int),
750 .mode = 0444,
751 .proc_handler = &proc_dointvec,
752 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100753 {
754 .ctl_name = CTL_UNNUMBERED,
H. Peter Anvin50312962009-05-07 16:54:11 -0700755 .procname = "bootloader_version",
756 .data = &bootloader_version,
757 .maxlen = sizeof (int),
758 .mode = 0444,
759 .proc_handler = &proc_dointvec,
760 },
761 {
762 .ctl_name = CTL_UNNUMBERED,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100763 .procname = "kstack_depth_to_print",
764 .data = &kstack_depth_to_print,
765 .maxlen = sizeof(int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
768 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100769 {
770 .ctl_name = CTL_UNNUMBERED,
771 .procname = "io_delay_type",
772 .data = &io_delay_type,
773 .maxlen = sizeof(int),
774 .mode = 0644,
775 .proc_handler = &proc_dointvec,
776 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800778#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 {
780 .ctl_name = KERN_RANDOMIZE,
781 .procname = "randomize_va_space",
782 .data = &randomize_va_space,
783 .maxlen = sizeof(int),
784 .mode = 0644,
785 .proc_handler = &proc_dointvec,
786 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800787#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800788#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700789 {
790 .ctl_name = KERN_SPIN_RETRY,
791 .procname = "spin_retry",
792 .data = &spin_retry,
793 .maxlen = sizeof (int),
794 .mode = 0644,
795 .proc_handler = &proc_dointvec,
796 },
797#endif
Len Brown673d5b42007-07-28 03:33:16 -0400798#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800799 {
Pavel Machekc255d842006-02-20 18:27:58 -0800800 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700801 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800802 .maxlen = sizeof (unsigned long),
803 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800804 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800805 },
806#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800807#ifdef CONFIG_IA64
808 {
809 .ctl_name = KERN_IA64_UNALIGNED,
810 .procname = "ignore-unaligned-usertrap",
811 .data = &no_unaligned_warning,
812 .maxlen = sizeof (int),
813 .mode = 0644,
814 .proc_handler = &proc_dointvec,
815 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800816 {
817 .ctl_name = CTL_UNNUMBERED,
818 .procname = "unaligned-dump-stack",
819 .data = &unaligned_dump_stack,
820 .maxlen = sizeof (int),
821 .mode = 0644,
822 .proc_handler = &proc_dointvec,
823 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800824#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700825#ifdef CONFIG_DETECT_SOFTLOCKUP
826 {
827 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200828 .procname = "softlockup_panic",
829 .data = &softlockup_panic,
830 .maxlen = sizeof(int),
831 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700832 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200833 .strategy = &sysctl_intvec,
834 .extra1 = &zero,
835 .extra2 = &one,
836 },
837 {
838 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700839 .procname = "softlockup_thresh",
840 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200841 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700842 .mode = 0644,
Mandeep Singh Bainesbaf48f62009-01-12 21:15:17 -0800843 .proc_handler = &proc_dosoftlockup_thresh,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700844 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200845 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700846 .extra2 = &sixty,
847 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800848#endif
849#ifdef CONFIG_DETECT_HUNG_TASK
850 {
851 .ctl_name = CTL_UNNUMBERED,
852 .procname = "hung_task_panic",
853 .data = &sysctl_hung_task_panic,
854 .maxlen = sizeof(int),
855 .mode = 0644,
856 .proc_handler = &proc_dointvec_minmax,
857 .strategy = &sysctl_intvec,
858 .extra1 = &zero,
859 .extra2 = &one,
860 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100861 {
862 .ctl_name = CTL_UNNUMBERED,
863 .procname = "hung_task_check_count",
864 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100865 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100866 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100867 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100868 .strategy = &sysctl_intvec,
869 },
870 {
871 .ctl_name = CTL_UNNUMBERED,
872 .procname = "hung_task_timeout_secs",
873 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100874 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100875 .mode = 0644,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800876 .proc_handler = &proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100877 .strategy = &sysctl_intvec,
878 },
879 {
880 .ctl_name = CTL_UNNUMBERED,
881 .procname = "hung_task_warnings",
882 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100883 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100884 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100885 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100886 .strategy = &sysctl_intvec,
887 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700888#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200889#ifdef CONFIG_COMPAT
890 {
891 .ctl_name = KERN_COMPAT_LOG,
892 .procname = "compat-log",
893 .data = &compat_log,
894 .maxlen = sizeof (int),
895 .mode = 0644,
896 .proc_handler = &proc_dointvec,
897 },
898#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700899#ifdef CONFIG_RT_MUTEXES
900 {
901 .ctl_name = KERN_MAX_LOCK_DEPTH,
902 .procname = "max_lock_depth",
903 .data = &max_lock_depth,
904 .maxlen = sizeof(int),
905 .mode = 0644,
906 .proc_handler = &proc_dointvec,
907 },
908#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700909 {
910 .ctl_name = CTL_UNNUMBERED,
911 .procname = "poweroff_cmd",
912 .data = &poweroff_cmd,
913 .maxlen = POWEROFF_CMD_PATH_LEN,
914 .mode = 0644,
915 .proc_handler = &proc_dostring,
916 .strategy = &sysctl_string,
917 },
David Howells0b77f5b2008-04-29 01:01:32 -0700918#ifdef CONFIG_KEYS
919 {
920 .ctl_name = CTL_UNNUMBERED,
921 .procname = "keys",
922 .mode = 0555,
923 .child = key_sysctls,
924 },
925#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700926#ifdef CONFIG_RCU_TORTURE_TEST
927 {
928 .ctl_name = CTL_UNNUMBERED,
929 .procname = "rcutorture_runnable",
930 .data = &rcutorture_runnable,
931 .maxlen = sizeof(int),
932 .mode = 0644,
933 .proc_handler = &proc_dointvec,
934 },
935#endif
David Howells12e22c52009-04-03 16:42:35 +0100936#ifdef CONFIG_SLOW_WORK
937 {
938 .ctl_name = CTL_UNNUMBERED,
939 .procname = "slow-work",
940 .mode = 0555,
941 .child = slow_work_sysctls,
942 },
943#endif
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200944#ifdef CONFIG_PERF_COUNTERS
945 {
946 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra07647712009-06-11 11:18:36 +0200947 .procname = "perf_counter_paranoid",
948 .data = &sysctl_perf_counter_paranoid,
949 .maxlen = sizeof(sysctl_perf_counter_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200950 .mode = 0644,
951 .proc_handler = &proc_dointvec,
952 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200953 {
954 .ctl_name = CTL_UNNUMBERED,
955 .procname = "perf_counter_mlock_kb",
956 .data = &sysctl_perf_counter_mlock,
957 .maxlen = sizeof(sysctl_perf_counter_mlock),
958 .mode = 0644,
959 .proc_handler = &proc_dointvec,
960 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200961 {
962 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstradf58ab22009-06-11 11:25:05 +0200963 .procname = "perf_counter_max_sample_rate",
964 .data = &sysctl_perf_counter_sample_rate,
965 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200966 .mode = 0644,
967 .proc_handler = &proc_dointvec,
968 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200969#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700970/*
971 * NOTE: do not add new entries to this table unless you have read
972 * Documentation/sysctl/ctl_unnumbered.txt
973 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 { .ctl_name = 0 }
975};
976
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700977static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 {
979 .ctl_name = VM_OVERCOMMIT_MEMORY,
980 .procname = "overcommit_memory",
981 .data = &sysctl_overcommit_memory,
982 .maxlen = sizeof(sysctl_overcommit_memory),
983 .mode = 0644,
984 .proc_handler = &proc_dointvec,
985 },
986 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700987 .ctl_name = VM_PANIC_ON_OOM,
988 .procname = "panic_on_oom",
989 .data = &sysctl_panic_on_oom,
990 .maxlen = sizeof(sysctl_panic_on_oom),
991 .mode = 0644,
992 .proc_handler = &proc_dointvec,
993 },
994 {
David Rientjesfe071d72007-10-16 23:25:56 -0700995 .ctl_name = CTL_UNNUMBERED,
996 .procname = "oom_kill_allocating_task",
997 .data = &sysctl_oom_kill_allocating_task,
998 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
999 .mode = 0644,
1000 .proc_handler = &proc_dointvec,
1001 },
1002 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001003 .ctl_name = CTL_UNNUMBERED,
1004 .procname = "oom_dump_tasks",
1005 .data = &sysctl_oom_dump_tasks,
1006 .maxlen = sizeof(sysctl_oom_dump_tasks),
1007 .mode = 0644,
1008 .proc_handler = &proc_dointvec,
1009 },
1010 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 .ctl_name = VM_OVERCOMMIT_RATIO,
1012 .procname = "overcommit_ratio",
1013 .data = &sysctl_overcommit_ratio,
1014 .maxlen = sizeof(sysctl_overcommit_ratio),
1015 .mode = 0644,
1016 .proc_handler = &proc_dointvec,
1017 },
1018 {
1019 .ctl_name = VM_PAGE_CLUSTER,
1020 .procname = "page-cluster",
1021 .data = &page_cluster,
1022 .maxlen = sizeof(int),
1023 .mode = 0644,
1024 .proc_handler = &proc_dointvec,
1025 },
1026 {
1027 .ctl_name = VM_DIRTY_BACKGROUND,
1028 .procname = "dirty_background_ratio",
1029 .data = &dirty_background_ratio,
1030 .maxlen = sizeof(dirty_background_ratio),
1031 .mode = 0644,
David Rientjes2da02992009-01-06 14:39:31 -08001032 .proc_handler = &dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 .strategy = &sysctl_intvec,
1034 .extra1 = &zero,
1035 .extra2 = &one_hundred,
1036 },
1037 {
David Rientjes2da02992009-01-06 14:39:31 -08001038 .ctl_name = CTL_UNNUMBERED,
1039 .procname = "dirty_background_bytes",
1040 .data = &dirty_background_bytes,
1041 .maxlen = sizeof(dirty_background_bytes),
1042 .mode = 0644,
1043 .proc_handler = &dirty_background_bytes_handler,
1044 .strategy = &sysctl_intvec,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001045 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001046 },
1047 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 .ctl_name = VM_DIRTY_RATIO,
1049 .procname = "dirty_ratio",
1050 .data = &vm_dirty_ratio,
1051 .maxlen = sizeof(vm_dirty_ratio),
1052 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -07001053 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 .strategy = &sysctl_intvec,
1055 .extra1 = &zero,
1056 .extra2 = &one_hundred,
1057 },
1058 {
David Rientjes2da02992009-01-06 14:39:31 -08001059 .ctl_name = CTL_UNNUMBERED,
1060 .procname = "dirty_bytes",
1061 .data = &vm_dirty_bytes,
1062 .maxlen = sizeof(vm_dirty_bytes),
1063 .mode = 0644,
1064 .proc_handler = &dirty_bytes_handler,
1065 .strategy = &sysctl_intvec,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001066 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001067 },
1068 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001070 .data = &dirty_writeback_interval,
1071 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 .mode = 0644,
1073 .proc_handler = &dirty_writeback_centisecs_handler,
1074 },
1075 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001077 .data = &dirty_expire_interval,
1078 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 .mode = 0644,
Alexey Dobriyan704503d2009-03-31 15:23:18 -07001080 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 },
1082 {
1083 .ctl_name = VM_NR_PDFLUSH_THREADS,
1084 .procname = "nr_pdflush_threads",
1085 .data = &nr_pdflush_threads,
1086 .maxlen = sizeof nr_pdflush_threads,
1087 .mode = 0444 /* read-only*/,
1088 .proc_handler = &proc_dointvec,
1089 },
1090 {
1091 .ctl_name = VM_SWAPPINESS,
1092 .procname = "swappiness",
1093 .data = &vm_swappiness,
1094 .maxlen = sizeof(vm_swappiness),
1095 .mode = 0644,
1096 .proc_handler = &proc_dointvec_minmax,
1097 .strategy = &sysctl_intvec,
1098 .extra1 = &zero,
1099 .extra2 = &one_hundred,
1100 },
1101#ifdef CONFIG_HUGETLB_PAGE
1102 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001104 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 .maxlen = sizeof(unsigned long),
1106 .mode = 0644,
1107 .proc_handler = &hugetlb_sysctl_handler,
1108 .extra1 = (void *)&hugetlb_zero,
1109 .extra2 = (void *)&hugetlb_infinity,
1110 },
1111 {
1112 .ctl_name = VM_HUGETLB_GROUP,
1113 .procname = "hugetlb_shm_group",
1114 .data = &sysctl_hugetlb_shm_group,
1115 .maxlen = sizeof(gid_t),
1116 .mode = 0644,
1117 .proc_handler = &proc_dointvec,
1118 },
Mel Gorman396faf02007-07-17 04:03:13 -07001119 {
1120 .ctl_name = CTL_UNNUMBERED,
1121 .procname = "hugepages_treat_as_movable",
1122 .data = &hugepages_treat_as_movable,
1123 .maxlen = sizeof(int),
1124 .mode = 0644,
1125 .proc_handler = &hugetlb_treat_movable_handler,
1126 },
Adam Litke54f9f802007-10-16 01:26:20 -07001127 {
1128 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001129 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001130 .data = NULL,
1131 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001132 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -08001133 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001134 .extra1 = (void *)&hugetlb_zero,
1135 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001136 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137#endif
1138 {
1139 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1140 .procname = "lowmem_reserve_ratio",
1141 .data = &sysctl_lowmem_reserve_ratio,
1142 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1143 .mode = 0644,
1144 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1145 .strategy = &sysctl_intvec,
1146 },
1147 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001148 .ctl_name = VM_DROP_PAGECACHE,
1149 .procname = "drop_caches",
1150 .data = &sysctl_drop_caches,
1151 .maxlen = sizeof(int),
1152 .mode = 0644,
1153 .proc_handler = drop_caches_sysctl_handler,
1154 .strategy = &sysctl_intvec,
1155 },
1156 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 .ctl_name = VM_MIN_FREE_KBYTES,
1158 .procname = "min_free_kbytes",
1159 .data = &min_free_kbytes,
1160 .maxlen = sizeof(min_free_kbytes),
1161 .mode = 0644,
1162 .proc_handler = &min_free_kbytes_sysctl_handler,
1163 .strategy = &sysctl_intvec,
1164 .extra1 = &zero,
1165 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001166 {
1167 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1168 .procname = "percpu_pagelist_fraction",
1169 .data = &percpu_pagelist_fraction,
1170 .maxlen = sizeof(percpu_pagelist_fraction),
1171 .mode = 0644,
1172 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1173 .strategy = &sysctl_intvec,
1174 .extra1 = &min_percpu_pagelist_fract,
1175 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176#ifdef CONFIG_MMU
1177 {
1178 .ctl_name = VM_MAX_MAP_COUNT,
1179 .procname = "max_map_count",
1180 .data = &sysctl_max_map_count,
1181 .maxlen = sizeof(sysctl_max_map_count),
1182 .mode = 0644,
1183 .proc_handler = &proc_dointvec
1184 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001185#else
1186 {
1187 .ctl_name = CTL_UNNUMBERED,
1188 .procname = "nr_trim_pages",
1189 .data = &sysctl_nr_trim_pages,
1190 .maxlen = sizeof(sysctl_nr_trim_pages),
1191 .mode = 0644,
1192 .proc_handler = &proc_dointvec_minmax,
1193 .strategy = &sysctl_intvec,
1194 .extra1 = &zero,
1195 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196#endif
1197 {
1198 .ctl_name = VM_LAPTOP_MODE,
1199 .procname = "laptop_mode",
1200 .data = &laptop_mode,
1201 .maxlen = sizeof(laptop_mode),
1202 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001203 .proc_handler = &proc_dointvec_jiffies,
1204 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 },
1206 {
1207 .ctl_name = VM_BLOCK_DUMP,
1208 .procname = "block_dump",
1209 .data = &block_dump,
1210 .maxlen = sizeof(block_dump),
1211 .mode = 0644,
1212 .proc_handler = &proc_dointvec,
1213 .strategy = &sysctl_intvec,
1214 .extra1 = &zero,
1215 },
1216 {
1217 .ctl_name = VM_VFS_CACHE_PRESSURE,
1218 .procname = "vfs_cache_pressure",
1219 .data = &sysctl_vfs_cache_pressure,
1220 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1221 .mode = 0644,
1222 .proc_handler = &proc_dointvec,
1223 .strategy = &sysctl_intvec,
1224 .extra1 = &zero,
1225 },
1226#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1227 {
1228 .ctl_name = VM_LEGACY_VA_LAYOUT,
1229 .procname = "legacy_va_layout",
1230 .data = &sysctl_legacy_va_layout,
1231 .maxlen = sizeof(sysctl_legacy_va_layout),
1232 .mode = 0644,
1233 .proc_handler = &proc_dointvec,
1234 .strategy = &sysctl_intvec,
1235 .extra1 = &zero,
1236 },
1237#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001238#ifdef CONFIG_NUMA
1239 {
1240 .ctl_name = VM_ZONE_RECLAIM_MODE,
1241 .procname = "zone_reclaim_mode",
1242 .data = &zone_reclaim_mode,
1243 .maxlen = sizeof(zone_reclaim_mode),
1244 .mode = 0644,
1245 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001246 .strategy = &sysctl_intvec,
1247 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001248 },
Christoph Lameter96146342006-07-03 00:24:13 -07001249 {
1250 .ctl_name = VM_MIN_UNMAPPED,
1251 .procname = "min_unmapped_ratio",
1252 .data = &sysctl_min_unmapped_ratio,
1253 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1254 .mode = 0644,
1255 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1256 .strategy = &sysctl_intvec,
1257 .extra1 = &zero,
1258 .extra2 = &one_hundred,
1259 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001260 {
1261 .ctl_name = VM_MIN_SLAB,
1262 .procname = "min_slab_ratio",
1263 .data = &sysctl_min_slab_ratio,
1264 .maxlen = sizeof(sysctl_min_slab_ratio),
1265 .mode = 0644,
1266 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1267 .strategy = &sysctl_intvec,
1268 .extra1 = &zero,
1269 .extra2 = &one_hundred,
1270 },
Christoph Lameter17436602006-01-18 17:42:32 -08001271#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001272#ifdef CONFIG_SMP
1273 {
1274 .ctl_name = CTL_UNNUMBERED,
1275 .procname = "stat_interval",
1276 .data = &sysctl_stat_interval,
1277 .maxlen = sizeof(sysctl_stat_interval),
1278 .mode = 0644,
1279 .proc_handler = &proc_dointvec_jiffies,
1280 .strategy = &sysctl_jiffies,
1281 },
1282#endif
Eric Parised032182007-06-28 15:55:21 -04001283 {
1284 .ctl_name = CTL_UNNUMBERED,
1285 .procname = "mmap_min_addr",
1286 .data = &mmap_min_addr,
1287 .maxlen = sizeof(unsigned long),
1288 .mode = 0644,
1289 .proc_handler = &proc_doulongvec_minmax,
1290 },
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001291#ifdef CONFIG_NUMA
1292 {
1293 .ctl_name = CTL_UNNUMBERED,
1294 .procname = "numa_zonelist_order",
1295 .data = &numa_zonelist_order,
1296 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1297 .mode = 0644,
1298 .proc_handler = &numa_zonelist_order_handler,
1299 .strategy = &sysctl_string,
1300 },
1301#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001302#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001303 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001304 {
1305 .ctl_name = VM_VDSO_ENABLED,
1306 .procname = "vdso_enabled",
1307 .data = &vdso_enabled,
1308 .maxlen = sizeof(vdso_enabled),
1309 .mode = 0644,
1310 .proc_handler = &proc_dointvec,
1311 .strategy = &sysctl_intvec,
1312 .extra1 = &zero,
1313 },
1314#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001315#ifdef CONFIG_HIGHMEM
1316 {
1317 .ctl_name = CTL_UNNUMBERED,
1318 .procname = "highmem_is_dirtyable",
1319 .data = &vm_highmem_is_dirtyable,
1320 .maxlen = sizeof(vm_highmem_is_dirtyable),
1321 .mode = 0644,
1322 .proc_handler = &proc_dointvec_minmax,
1323 .strategy = &sysctl_intvec,
1324 .extra1 = &zero,
1325 .extra2 = &one,
1326 },
1327#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001328#ifdef CONFIG_UNEVICTABLE_LRU
1329 {
1330 .ctl_name = CTL_UNNUMBERED,
1331 .procname = "scan_unevictable_pages",
1332 .data = &scan_unevictable_pages,
1333 .maxlen = sizeof(scan_unevictable_pages),
1334 .mode = 0644,
1335 .proc_handler = &scan_unevictable_handler,
1336 },
1337#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001338/*
1339 * NOTE: do not add new entries to this table unless you have read
1340 * Documentation/sysctl/ctl_unnumbered.txt
1341 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 { .ctl_name = 0 }
1343};
1344
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001345#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001346static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001347 { .ctl_name = 0 }
1348};
1349#endif
1350
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001351static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 {
1353 .ctl_name = FS_NRINODE,
1354 .procname = "inode-nr",
1355 .data = &inodes_stat,
1356 .maxlen = 2*sizeof(int),
1357 .mode = 0444,
1358 .proc_handler = &proc_dointvec,
1359 },
1360 {
1361 .ctl_name = FS_STATINODE,
1362 .procname = "inode-state",
1363 .data = &inodes_stat,
1364 .maxlen = 7*sizeof(int),
1365 .mode = 0444,
1366 .proc_handler = &proc_dointvec,
1367 },
1368 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .procname = "file-nr",
1370 .data = &files_stat,
1371 .maxlen = 3*sizeof(int),
1372 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001373 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 },
1375 {
1376 .ctl_name = FS_MAXFILE,
1377 .procname = "file-max",
1378 .data = &files_stat.max_files,
1379 .maxlen = sizeof(int),
1380 .mode = 0644,
1381 .proc_handler = &proc_dointvec,
1382 },
1383 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001384 .ctl_name = CTL_UNNUMBERED,
1385 .procname = "nr_open",
1386 .data = &sysctl_nr_open,
1387 .maxlen = sizeof(int),
1388 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001389 .proc_handler = &proc_dointvec_minmax,
1390 .extra1 = &sysctl_nr_open_min,
1391 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001392 },
1393 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .ctl_name = FS_DENTRY,
1395 .procname = "dentry-state",
1396 .data = &dentry_stat,
1397 .maxlen = 6*sizeof(int),
1398 .mode = 0444,
1399 .proc_handler = &proc_dointvec,
1400 },
1401 {
1402 .ctl_name = FS_OVERFLOWUID,
1403 .procname = "overflowuid",
1404 .data = &fs_overflowuid,
1405 .maxlen = sizeof(int),
1406 .mode = 0644,
1407 .proc_handler = &proc_dointvec_minmax,
1408 .strategy = &sysctl_intvec,
1409 .extra1 = &minolduid,
1410 .extra2 = &maxolduid,
1411 },
1412 {
1413 .ctl_name = FS_OVERFLOWGID,
1414 .procname = "overflowgid",
1415 .data = &fs_overflowgid,
1416 .maxlen = sizeof(int),
1417 .mode = 0644,
1418 .proc_handler = &proc_dointvec_minmax,
1419 .strategy = &sysctl_intvec,
1420 .extra1 = &minolduid,
1421 .extra2 = &maxolduid,
1422 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001423#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 {
1425 .ctl_name = FS_LEASES,
1426 .procname = "leases-enable",
1427 .data = &leases_enable,
1428 .maxlen = sizeof(int),
1429 .mode = 0644,
1430 .proc_handler = &proc_dointvec,
1431 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001432#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433#ifdef CONFIG_DNOTIFY
1434 {
1435 .ctl_name = FS_DIR_NOTIFY,
1436 .procname = "dir-notify-enable",
1437 .data = &dir_notify_enable,
1438 .maxlen = sizeof(int),
1439 .mode = 0644,
1440 .proc_handler = &proc_dointvec,
1441 },
1442#endif
1443#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001444#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 {
1446 .ctl_name = FS_LEASE_TIME,
1447 .procname = "lease-break-time",
1448 .data = &lease_break_time,
1449 .maxlen = sizeof(int),
1450 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001451 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001453#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001454#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 .procname = "aio-nr",
1457 .data = &aio_nr,
1458 .maxlen = sizeof(aio_nr),
1459 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001460 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 },
1462 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 .procname = "aio-max-nr",
1464 .data = &aio_max_nr,
1465 .maxlen = sizeof(aio_max_nr),
1466 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001467 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001469#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001470#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001471 {
1472 .ctl_name = FS_INOTIFY,
1473 .procname = "inotify",
1474 .mode = 0555,
1475 .child = inotify_table,
1476 },
1477#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001478#ifdef CONFIG_EPOLL
1479 {
1480 .procname = "epoll",
1481 .mode = 0555,
1482 .child = epoll_table,
1483 },
1484#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001486 {
1487 .ctl_name = KERN_SETUID_DUMPABLE,
1488 .procname = "suid_dumpable",
1489 .data = &suid_dumpable,
1490 .maxlen = sizeof(int),
1491 .mode = 0644,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001492 .proc_handler = &proc_dointvec_minmax,
1493 .strategy = &sysctl_intvec,
1494 .extra1 = &zero,
1495 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001496 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001497#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1498 {
1499 .ctl_name = CTL_UNNUMBERED,
1500 .procname = "binfmt_misc",
1501 .mode = 0555,
1502 .child = binfmt_misc_table,
1503 },
1504#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001505/*
1506 * NOTE: do not add new entries to this table unless you have read
1507 * Documentation/sysctl/ctl_unnumbered.txt
1508 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 { .ctl_name = 0 }
1510};
1511
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001512static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001513#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001514 {
1515 .ctl_name = CTL_UNNUMBERED,
1516 .procname = "exception-trace",
1517 .data = &show_unhandled_signals,
1518 .maxlen = sizeof(int),
1519 .mode = 0644,
1520 .proc_handler = proc_dointvec
1521 },
1522#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 { .ctl_name = 0 }
1524};
1525
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001526static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001528};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Al Viro330d57f2005-11-04 10:18:40 +00001530static DEFINE_SPINLOCK(sysctl_lock);
1531
1532/* called under sysctl_lock */
1533static int use_table(struct ctl_table_header *p)
1534{
1535 if (unlikely(p->unregistering))
1536 return 0;
1537 p->used++;
1538 return 1;
1539}
1540
1541/* called under sysctl_lock */
1542static void unuse_table(struct ctl_table_header *p)
1543{
1544 if (!--p->used)
1545 if (unlikely(p->unregistering))
1546 complete(p->unregistering);
1547}
1548
1549/* called under sysctl_lock, will reacquire if has to wait */
1550static void start_unregistering(struct ctl_table_header *p)
1551{
1552 /*
1553 * if p->used is 0, nobody will ever touch that entry again;
1554 * we'll eliminate all paths to it before dropping sysctl_lock
1555 */
1556 if (unlikely(p->used)) {
1557 struct completion wait;
1558 init_completion(&wait);
1559 p->unregistering = &wait;
1560 spin_unlock(&sysctl_lock);
1561 wait_for_completion(&wait);
1562 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001563 } else {
1564 /* anything non-NULL; we'll never dereference it */
1565 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001566 }
1567 /*
1568 * do not remove from the list until nobody holds it; walking the
1569 * list in do_sysctl() relies on that.
1570 */
1571 list_del_init(&p->ctl_entry);
1572}
1573
Al Virof7e6ced2008-07-15 01:44:23 -04001574void sysctl_head_get(struct ctl_table_header *head)
1575{
1576 spin_lock(&sysctl_lock);
1577 head->count++;
1578 spin_unlock(&sysctl_lock);
1579}
1580
1581void sysctl_head_put(struct ctl_table_header *head)
1582{
1583 spin_lock(&sysctl_lock);
1584 if (!--head->count)
1585 kfree(head);
1586 spin_unlock(&sysctl_lock);
1587}
1588
1589struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1590{
1591 if (!head)
1592 BUG();
1593 spin_lock(&sysctl_lock);
1594 if (!use_table(head))
1595 head = ERR_PTR(-ENOENT);
1596 spin_unlock(&sysctl_lock);
1597 return head;
1598}
1599
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001600void sysctl_head_finish(struct ctl_table_header *head)
1601{
1602 if (!head)
1603 return;
1604 spin_lock(&sysctl_lock);
1605 unuse_table(head);
1606 spin_unlock(&sysctl_lock);
1607}
1608
Al Viro73455092008-07-14 21:22:20 -04001609static struct ctl_table_set *
1610lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1611{
1612 struct ctl_table_set *set = &root->default_set;
1613 if (root->lookup)
1614 set = root->lookup(root, namespaces);
1615 return set;
1616}
1617
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001618static struct list_head *
1619lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001620{
Al Viro73455092008-07-14 21:22:20 -04001621 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1622 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001623}
1624
1625struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1626 struct ctl_table_header *prev)
1627{
1628 struct ctl_table_root *root;
1629 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001630 struct ctl_table_header *head;
1631 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001632
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001633 spin_lock(&sysctl_lock);
1634 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001635 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001636 tmp = &prev->ctl_entry;
1637 unuse_table(prev);
1638 goto next;
1639 }
1640 tmp = &root_table_header.ctl_entry;
1641 for (;;) {
1642 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1643
1644 if (!use_table(head))
1645 goto next;
1646 spin_unlock(&sysctl_lock);
1647 return head;
1648 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001649 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001650 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001651 header_list = lookup_header_list(root, namespaces);
1652 if (tmp != header_list)
1653 continue;
1654
1655 do {
1656 root = list_entry(root->root_list.next,
1657 struct ctl_table_root, root_list);
1658 if (root == &sysctl_table_root)
1659 goto out;
1660 header_list = lookup_header_list(root, namespaces);
1661 } while (list_empty(header_list));
1662 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001663 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001664out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001665 spin_unlock(&sysctl_lock);
1666 return NULL;
1667}
1668
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001669struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1670{
1671 return __sysctl_head_next(current->nsproxy, prev);
1672}
1673
1674void register_sysctl_root(struct ctl_table_root *root)
1675{
1676 spin_lock(&sysctl_lock);
1677 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1678 spin_unlock(&sysctl_lock);
1679}
1680
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001681#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001682/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001683static int do_sysctl_strategy(struct ctl_table_root *root,
1684 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001685 void __user *oldval, size_t __user *oldlenp,
1686 void __user *newval, size_t newlen)
1687{
1688 int op = 0, rc;
1689
1690 if (oldval)
Al Viroe6305c42008-07-15 21:03:57 -04001691 op |= MAY_READ;
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001692 if (newval)
Al Viroe6305c42008-07-15 21:03:57 -04001693 op |= MAY_WRITE;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001694 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001695 return -EPERM;
1696
1697 if (table->strategy) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001698 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001699 if (rc < 0)
1700 return rc;
1701 if (rc > 0)
1702 return 0;
1703 }
1704
1705 /* If there is no strategy routine, or if the strategy returns
1706 * zero, proceed with automatic r/w */
1707 if (table->data && table->maxlen) {
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001708 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001709 if (rc < 0)
1710 return rc;
1711 }
1712 return 0;
1713}
1714
1715static int parse_table(int __user *name, int nlen,
1716 void __user *oldval, size_t __user *oldlenp,
1717 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001718 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001719 struct ctl_table *table)
1720{
1721 int n;
1722repeat:
1723 if (!nlen)
1724 return -ENOTDIR;
1725 if (get_user(n, name))
1726 return -EFAULT;
1727 for ( ; table->ctl_name || table->procname; table++) {
1728 if (!table->ctl_name)
1729 continue;
1730 if (n == table->ctl_name) {
1731 int error;
1732 if (table->child) {
Al Viroe6305c42008-07-15 21:03:57 -04001733 if (sysctl_perm(root, table, MAY_EXEC))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001734 return -EPERM;
1735 name++;
1736 nlen--;
1737 table = table->child;
1738 goto repeat;
1739 }
Alexey Dobriyanf221e722008-10-15 22:04:23 -07001740 error = do_sysctl_strategy(root, table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001741 oldval, oldlenp,
1742 newval, newlen);
1743 return error;
1744 }
1745 }
1746 return -ENOTDIR;
1747}
1748
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1750 void __user *newval, size_t newlen)
1751{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001752 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001753 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
1755 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1756 return -ENOTDIR;
1757 if (oldval) {
1758 int old_len;
1759 if (!oldlenp || get_user(old_len, oldlenp))
1760 return -EFAULT;
1761 }
Al Viro330d57f2005-11-04 10:18:40 +00001762
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001763 for (head = sysctl_head_next(NULL); head;
1764 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001765 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001766 newval, newlen,
1767 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001768 if (error != -ENOTDIR) {
1769 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001770 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001771 }
1772 }
Al Viro330d57f2005-11-04 10:18:40 +00001773 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774}
1775
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01001776SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777{
1778 struct __sysctl_args tmp;
1779 int error;
1780
1781 if (copy_from_user(&tmp, args, sizeof(tmp)))
1782 return -EFAULT;
1783
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001784 error = deprecated_sysctl_warning(&tmp);
1785 if (error)
1786 goto out;
1787
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 lock_kernel();
1789 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1790 tmp.newval, tmp.newlen);
1791 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001792out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 return error;
1794}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001795#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
1797/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001798 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 * some sysctl variables are readonly even to root.
1800 */
1801
1802static int test_perm(int mode, int op)
1803{
David Howells76aac0e2008-11-14 10:39:12 +11001804 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 mode >>= 6;
1806 else if (in_egroup_p(0))
1807 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001808 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 return 0;
1810 return -EACCES;
1811}
1812
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001813int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814{
1815 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001816 int mode;
1817
Al Viroe6305c42008-07-15 21:03:57 -04001818 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 if (error)
1820 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001821
1822 if (root->permissions)
1823 mode = root->permissions(root, current->nsproxy, table);
1824 else
1825 mode = table->mode;
1826
1827 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828}
1829
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001830static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1831{
1832 for (; table->ctl_name || table->procname; table++) {
1833 table->parent = parent;
1834 if (table->child)
1835 sysctl_set_parent(table, table->child);
1836 }
1837}
1838
1839static __init int sysctl_init(void)
1840{
1841 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001842#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1843 {
1844 int err;
1845 err = sysctl_check_table(current->nsproxy, root_table);
1846 }
1847#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001848 return 0;
1849}
1850
1851core_initcall(sysctl_init);
1852
Al Virobfbcf032008-07-27 06:31:22 +01001853static struct ctl_table *is_branch_in(struct ctl_table *branch,
1854 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001855{
1856 struct ctl_table *p;
1857 const char *s = branch->procname;
1858
1859 /* branch should have named subdirectory as its first element */
1860 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001861 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001862
1863 /* ... and nothing else */
1864 if (branch[1].procname || branch[1].ctl_name)
Al Virobfbcf032008-07-27 06:31:22 +01001865 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001866
1867 /* table should contain subdirectory with the same name */
1868 for (p = table; p->procname || p->ctl_name; p++) {
1869 if (!p->child)
1870 continue;
1871 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001872 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001873 }
Al Virobfbcf032008-07-27 06:31:22 +01001874 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001875}
1876
1877/* see if attaching q to p would be an improvement */
1878static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1879{
1880 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001881 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001882 int is_better = 0;
1883 int not_in_parent = !p->attached_by;
1884
Al Virobfbcf032008-07-27 06:31:22 +01001885 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001886 if (by == q->attached_by)
1887 is_better = 1;
1888 if (to == p->attached_by)
1889 not_in_parent = 1;
1890 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001891 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001892 }
1893
1894 if (is_better && not_in_parent) {
1895 q->attached_by = by;
1896 q->attached_to = to;
1897 q->parent = p;
1898 }
1899}
1900
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001902 * __register_sysctl_paths - register a sysctl hierarchy
1903 * @root: List of sysctl headers to register on
1904 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001905 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 *
1908 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001909 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001911 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 *
1913 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1914 * must be unique within that level of sysctl
1915 *
1916 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1917 * enter a sysctl file
1918 *
1919 * data - a pointer to data for use by proc_handler
1920 *
1921 * maxlen - the maximum size in bytes of the data
1922 *
1923 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1924 *
1925 * child - a pointer to the child sysctl table if this entry is a directory, or
1926 * %NULL.
1927 *
1928 * proc_handler - the text handler routine (described below)
1929 *
1930 * strategy - the strategy routine (described below)
1931 *
1932 * de - for internal use by the sysctl routines
1933 *
1934 * extra1, extra2 - extra pointers usable by the proc handler routines
1935 *
1936 * Leaf nodes in the sysctl tree will be represented by a single file
1937 * under /proc; non-leaf nodes will be represented by directories.
1938 *
1939 * sysctl(2) can automatically manage read and write requests through
1940 * the sysctl table. The data and maxlen fields of the ctl_table
1941 * struct enable minimal validation of the values being written to be
1942 * performed, and the mode field allows minimal authentication.
1943 *
1944 * More sophisticated management can be enabled by the provision of a
1945 * strategy routine with the table entry. This will be called before
1946 * any automatic read or write of the data is performed.
1947 *
1948 * The strategy routine may return
1949 *
1950 * < 0 - Error occurred (error is passed to user process)
1951 *
1952 * 0 - OK - proceed with automatic read or write.
1953 *
1954 * > 0 - OK - read or write has been done by the strategy routine, so
1955 * return immediately.
1956 *
1957 * There must be a proc_handler routine for any terminal nodes
1958 * mirrored under /proc/sys (non-terminals are handled by a built-in
1959 * directory handler). Several default handlers are available to
1960 * cover common cases -
1961 *
1962 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1963 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1964 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1965 *
1966 * It is the handler's job to read the input buffer from user memory
1967 * and process it. The handler should return 0 on success.
1968 *
1969 * This routine returns %NULL on a failure to register, and a pointer
1970 * to the table header on success.
1971 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001972struct ctl_table_header *__register_sysctl_paths(
1973 struct ctl_table_root *root,
1974 struct nsproxy *namespaces,
1975 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001977 struct ctl_table_header *header;
1978 struct ctl_table *new, **prevp;
1979 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001980 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001981
1982 /* Count the path components */
1983 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1984 ;
1985
1986 /*
1987 * For each path component, allocate a 2-element ctl_table array.
1988 * The first array element will be filled with the sysctl entry
1989 * for this, the second will be the sentinel (ctl_name == 0).
1990 *
1991 * We allocate everything in one go so that we don't have to
1992 * worry about freeing additional memory in unregister_sysctl_table.
1993 */
1994 header = kzalloc(sizeof(struct ctl_table_header) +
1995 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1996 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001998
1999 new = (struct ctl_table *) (header + 1);
2000
2001 /* Now connect the dots */
2002 prevp = &header->ctl_table;
2003 for (n = 0; n < npath; ++n, ++path) {
2004 /* Copy the procname */
2005 new->procname = path->procname;
2006 new->ctl_name = path->ctl_name;
2007 new->mode = 0555;
2008
2009 *prevp = new;
2010 prevp = &new->child;
2011
2012 new += 2;
2013 }
2014 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11002015 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002016
2017 INIT_LIST_HEAD(&header->ctl_entry);
2018 header->used = 0;
2019 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002020 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002021 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04002022 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07002023#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002024 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002025 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07002026 return NULL;
2027 }
Holger Schurig88f458e2008-04-29 01:02:36 -07002028#endif
Al Viro330d57f2005-11-04 10:18:40 +00002029 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04002030 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04002031 header->attached_by = header->ctl_table;
2032 header->attached_to = root_table;
2033 header->parent = &root_table_header;
2034 for (set = header->set; set; set = set->parent) {
2035 struct ctl_table_header *p;
2036 list_for_each_entry(p, &set->list, ctl_entry) {
2037 if (p->unregistering)
2038 continue;
2039 try_attach(p, header);
2040 }
2041 }
2042 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04002043 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00002044 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002045
2046 return header;
2047}
2048
2049/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11002050 * register_sysctl_table_path - register a sysctl table hierarchy
2051 * @path: The path to the directory the sysctl table is in.
2052 * @table: the top-level table structure
2053 *
2054 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2055 * array. A completely 0 filled entry terminates the table.
2056 *
2057 * See __register_sysctl_paths for more details.
2058 */
2059struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2060 struct ctl_table *table)
2061{
2062 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2063 path, table);
2064}
2065
2066/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002067 * register_sysctl_table - register a sysctl table hierarchy
2068 * @table: the top-level table structure
2069 *
2070 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2071 * array. A completely 0 filled entry terminates the table.
2072 *
2073 * See register_sysctl_paths for more details.
2074 */
2075struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2076{
2077 static const struct ctl_path null_path[] = { {} };
2078
2079 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080}
2081
2082/**
2083 * unregister_sysctl_table - unregister a sysctl table hierarchy
2084 * @header: the header returned from register_sysctl_table
2085 *
2086 * Unregisters the sysctl table and all children. proc entries may not
2087 * actually be removed until they are no longer used by anyone.
2088 */
2089void unregister_sysctl_table(struct ctl_table_header * header)
2090{
Al Viro330d57f2005-11-04 10:18:40 +00002091 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08002092
2093 if (header == NULL)
2094 return;
2095
Al Viro330d57f2005-11-04 10:18:40 +00002096 spin_lock(&sysctl_lock);
2097 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04002098 if (!--header->parent->count) {
2099 WARN_ON(1);
2100 kfree(header->parent);
2101 }
Al Virof7e6ced2008-07-15 01:44:23 -04002102 if (!--header->count)
2103 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00002104 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105}
2106
Al Viro90434762008-07-15 08:54:06 -04002107int sysctl_is_seen(struct ctl_table_header *p)
2108{
2109 struct ctl_table_set *set = p->set;
2110 int res;
2111 spin_lock(&sysctl_lock);
2112 if (p->unregistering)
2113 res = 0;
2114 else if (!set->is_seen)
2115 res = 1;
2116 else
2117 res = set->is_seen(set);
2118 spin_unlock(&sysctl_lock);
2119 return res;
2120}
2121
Al Viro73455092008-07-14 21:22:20 -04002122void setup_sysctl_set(struct ctl_table_set *p,
2123 struct ctl_table_set *parent,
2124 int (*is_seen)(struct ctl_table_set *))
2125{
2126 INIT_LIST_HEAD(&p->list);
2127 p->parent = parent ? parent : &sysctl_table_root.default_set;
2128 p->is_seen = is_seen;
2129}
2130
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002131#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002132struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002133{
2134 return NULL;
2135}
2136
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002137struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2138 struct ctl_table *table)
2139{
2140 return NULL;
2141}
2142
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002143void unregister_sysctl_table(struct ctl_table_header * table)
2144{
2145}
2146
Al Viro73455092008-07-14 21:22:20 -04002147void setup_sysctl_set(struct ctl_table_set *p,
2148 struct ctl_table_set *parent,
2149 int (*is_seen)(struct ctl_table_set *))
2150{
2151}
2152
Al Virof7e6ced2008-07-15 01:44:23 -04002153void sysctl_head_put(struct ctl_table_header *head)
2154{
2155}
2156
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002157#endif /* CONFIG_SYSCTL */
2158
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159/*
2160 * /proc/sys support
2161 */
2162
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002163#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002165static int _proc_do_string(void* data, int maxlen, int write,
2166 struct file *filp, void __user *buffer,
2167 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002168{
2169 size_t len;
2170 char __user *p;
2171 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002172
2173 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002174 *lenp = 0;
2175 return 0;
2176 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002177
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002178 if (write) {
2179 len = 0;
2180 p = buffer;
2181 while (len < *lenp) {
2182 if (get_user(c, p++))
2183 return -EFAULT;
2184 if (c == 0 || c == '\n')
2185 break;
2186 len++;
2187 }
2188 if (len >= maxlen)
2189 len = maxlen-1;
2190 if(copy_from_user(data, buffer, len))
2191 return -EFAULT;
2192 ((char *) data)[len] = 0;
2193 *ppos += *lenp;
2194 } else {
2195 len = strlen(data);
2196 if (len > maxlen)
2197 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002198
2199 if (*ppos > len) {
2200 *lenp = 0;
2201 return 0;
2202 }
2203
2204 data += *ppos;
2205 len -= *ppos;
2206
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002207 if (len > *lenp)
2208 len = *lenp;
2209 if (len)
2210 if(copy_to_user(buffer, data, len))
2211 return -EFAULT;
2212 if (len < *lenp) {
2213 if(put_user('\n', ((char __user *) buffer) + len))
2214 return -EFAULT;
2215 len++;
2216 }
2217 *lenp = len;
2218 *ppos += len;
2219 }
2220 return 0;
2221}
2222
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223/**
2224 * proc_dostring - read a string sysctl
2225 * @table: the sysctl table
2226 * @write: %TRUE if this is a write to the sysctl file
2227 * @filp: the file structure
2228 * @buffer: the user buffer
2229 * @lenp: the size of the user buffer
2230 * @ppos: file position
2231 *
2232 * Reads/writes a string from/to the user buffer. If the kernel
2233 * buffer provided is not large enough to hold the string, the
2234 * string is truncated. The copied string is %NULL-terminated.
2235 * If the string is being read by the user process, it is copied
2236 * and a newline '\n' is added. It is truncated if the buffer is
2237 * not large enough.
2238 *
2239 * Returns 0 on success.
2240 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002241int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 void __user *buffer, size_t *lenp, loff_t *ppos)
2243{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002244 return _proc_do_string(table->data, table->maxlen, write, filp,
2245 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2250 int *valp,
2251 int write, void *data)
2252{
2253 if (write) {
2254 *valp = *negp ? -*lvalp : *lvalp;
2255 } else {
2256 int val = *valp;
2257 if (val < 0) {
2258 *negp = -1;
2259 *lvalp = (unsigned long)-val;
2260 } else {
2261 *negp = 0;
2262 *lvalp = (unsigned long)val;
2263 }
2264 }
2265 return 0;
2266}
2267
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002268static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002269 int write, struct file *filp, void __user *buffer,
2270 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2272 int write, void *data),
2273 void *data)
2274{
2275#define TMPBUFLEN 21
2276 int *i, vleft, first=1, neg, val;
2277 unsigned long lval;
2278 size_t left, len;
2279
2280 char buf[TMPBUFLEN], *p;
2281 char __user *s = buffer;
2282
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002283 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 (*ppos && !write)) {
2285 *lenp = 0;
2286 return 0;
2287 }
2288
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002289 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 vleft = table->maxlen / sizeof(*i);
2291 left = *lenp;
2292
2293 if (!conv)
2294 conv = do_proc_dointvec_conv;
2295
2296 for (; left && vleft--; i++, first=0) {
2297 if (write) {
2298 while (left) {
2299 char c;
2300 if (get_user(c, s))
2301 return -EFAULT;
2302 if (!isspace(c))
2303 break;
2304 left--;
2305 s++;
2306 }
2307 if (!left)
2308 break;
2309 neg = 0;
2310 len = left;
2311 if (len > sizeof(buf) - 1)
2312 len = sizeof(buf) - 1;
2313 if (copy_from_user(buf, s, len))
2314 return -EFAULT;
2315 buf[len] = 0;
2316 p = buf;
2317 if (*p == '-' && left > 1) {
2318 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002319 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 }
2321 if (*p < '0' || *p > '9')
2322 break;
2323
2324 lval = simple_strtoul(p, &p, 0);
2325
2326 len = p-buf;
2327 if ((len < left) && *p && !isspace(*p))
2328 break;
2329 if (neg)
2330 val = -val;
2331 s += len;
2332 left -= len;
2333
2334 if (conv(&neg, &lval, i, 1, data))
2335 break;
2336 } else {
2337 p = buf;
2338 if (!first)
2339 *p++ = '\t';
2340
2341 if (conv(&neg, &lval, i, 0, data))
2342 break;
2343
2344 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2345 len = strlen(buf);
2346 if (len > left)
2347 len = left;
2348 if(copy_to_user(s, buf, len))
2349 return -EFAULT;
2350 left -= len;
2351 s += len;
2352 }
2353 }
2354
2355 if (!write && !first && left) {
2356 if(put_user('\n', s))
2357 return -EFAULT;
2358 left--, s++;
2359 }
2360 if (write) {
2361 while (left) {
2362 char c;
2363 if (get_user(c, s++))
2364 return -EFAULT;
2365 if (!isspace(c))
2366 break;
2367 left--;
2368 }
2369 }
2370 if (write && first)
2371 return -EINVAL;
2372 *lenp -= left;
2373 *ppos += *lenp;
2374 return 0;
2375#undef TMPBUFLEN
2376}
2377
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002378static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002379 void __user *buffer, size_t *lenp, loff_t *ppos,
2380 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2381 int write, void *data),
2382 void *data)
2383{
2384 return __do_proc_dointvec(table->data, table, write, filp,
2385 buffer, lenp, ppos, conv, data);
2386}
2387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388/**
2389 * proc_dointvec - read a vector of integers
2390 * @table: the sysctl table
2391 * @write: %TRUE if this is a write to the sysctl file
2392 * @filp: the file structure
2393 * @buffer: the user buffer
2394 * @lenp: the size of the user buffer
2395 * @ppos: file position
2396 *
2397 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2398 * values from/to the user buffer, treated as an ASCII string.
2399 *
2400 * Returns 0 on success.
2401 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002402int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 void __user *buffer, size_t *lenp, loff_t *ppos)
2404{
2405 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2406 NULL,NULL);
2407}
2408
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002409/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002410 * Taint values can only be increased
2411 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002412 */
Andi Kleen25ddbb12008-10-15 22:01:41 -07002413static int proc_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002414 void __user *buffer, size_t *lenp, loff_t *ppos)
2415{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002416 struct ctl_table t;
2417 unsigned long tmptaint = get_taint();
2418 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002419
Bastian Blank91fcd412007-04-23 14:41:14 -07002420 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002421 return -EPERM;
2422
Andi Kleen25ddbb12008-10-15 22:01:41 -07002423 t = *table;
2424 t.data = &tmptaint;
2425 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2426 if (err < 0)
2427 return err;
2428
2429 if (write) {
2430 /*
2431 * Poor man's atomic or. Not worth adding a primitive
2432 * to everyone's atomic.h for this
2433 */
2434 int i;
2435 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2436 if ((tmptaint >> i) & 1)
2437 add_taint(i);
2438 }
2439 }
2440
2441 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002442}
2443
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444struct do_proc_dointvec_minmax_conv_param {
2445 int *min;
2446 int *max;
2447};
2448
2449static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2450 int *valp,
2451 int write, void *data)
2452{
2453 struct do_proc_dointvec_minmax_conv_param *param = data;
2454 if (write) {
2455 int val = *negp ? -*lvalp : *lvalp;
2456 if ((param->min && *param->min > val) ||
2457 (param->max && *param->max < val))
2458 return -EINVAL;
2459 *valp = val;
2460 } else {
2461 int val = *valp;
2462 if (val < 0) {
2463 *negp = -1;
2464 *lvalp = (unsigned long)-val;
2465 } else {
2466 *negp = 0;
2467 *lvalp = (unsigned long)val;
2468 }
2469 }
2470 return 0;
2471}
2472
2473/**
2474 * proc_dointvec_minmax - read a vector of integers with min/max values
2475 * @table: the sysctl table
2476 * @write: %TRUE if this is a write to the sysctl file
2477 * @filp: the file structure
2478 * @buffer: the user buffer
2479 * @lenp: the size of the user buffer
2480 * @ppos: file position
2481 *
2482 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2483 * values from/to the user buffer, treated as an ASCII string.
2484 *
2485 * This routine will ensure the values are within the range specified by
2486 * table->extra1 (min) and table->extra2 (max).
2487 *
2488 * Returns 0 on success.
2489 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002490int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 void __user *buffer, size_t *lenp, loff_t *ppos)
2492{
2493 struct do_proc_dointvec_minmax_conv_param param = {
2494 .min = (int *) table->extra1,
2495 .max = (int *) table->extra2,
2496 };
2497 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2498 do_proc_dointvec_minmax_conv, &param);
2499}
2500
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002501static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 struct file *filp,
2503 void __user *buffer,
2504 size_t *lenp, loff_t *ppos,
2505 unsigned long convmul,
2506 unsigned long convdiv)
2507{
2508#define TMPBUFLEN 21
2509 unsigned long *i, *min, *max, val;
2510 int vleft, first=1, neg;
2511 size_t len, left;
2512 char buf[TMPBUFLEN], *p;
2513 char __user *s = buffer;
2514
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002515 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 (*ppos && !write)) {
2517 *lenp = 0;
2518 return 0;
2519 }
2520
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002521 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 min = (unsigned long *) table->extra1;
2523 max = (unsigned long *) table->extra2;
2524 vleft = table->maxlen / sizeof(unsigned long);
2525 left = *lenp;
2526
2527 for (; left && vleft--; i++, min++, max++, first=0) {
2528 if (write) {
2529 while (left) {
2530 char c;
2531 if (get_user(c, s))
2532 return -EFAULT;
2533 if (!isspace(c))
2534 break;
2535 left--;
2536 s++;
2537 }
2538 if (!left)
2539 break;
2540 neg = 0;
2541 len = left;
2542 if (len > TMPBUFLEN-1)
2543 len = TMPBUFLEN-1;
2544 if (copy_from_user(buf, s, len))
2545 return -EFAULT;
2546 buf[len] = 0;
2547 p = buf;
2548 if (*p == '-' && left > 1) {
2549 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002550 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 }
2552 if (*p < '0' || *p > '9')
2553 break;
2554 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2555 len = p-buf;
2556 if ((len < left) && *p && !isspace(*p))
2557 break;
2558 if (neg)
2559 val = -val;
2560 s += len;
2561 left -= len;
2562
2563 if(neg)
2564 continue;
2565 if ((min && val < *min) || (max && val > *max))
2566 continue;
2567 *i = val;
2568 } else {
2569 p = buf;
2570 if (!first)
2571 *p++ = '\t';
2572 sprintf(p, "%lu", convdiv * (*i) / convmul);
2573 len = strlen(buf);
2574 if (len > left)
2575 len = left;
2576 if(copy_to_user(s, buf, len))
2577 return -EFAULT;
2578 left -= len;
2579 s += len;
2580 }
2581 }
2582
2583 if (!write && !first && left) {
2584 if(put_user('\n', s))
2585 return -EFAULT;
2586 left--, s++;
2587 }
2588 if (write) {
2589 while (left) {
2590 char c;
2591 if (get_user(c, s++))
2592 return -EFAULT;
2593 if (!isspace(c))
2594 break;
2595 left--;
2596 }
2597 }
2598 if (write && first)
2599 return -EINVAL;
2600 *lenp -= left;
2601 *ppos += *lenp;
2602 return 0;
2603#undef TMPBUFLEN
2604}
2605
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002606static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002607 struct file *filp,
2608 void __user *buffer,
2609 size_t *lenp, loff_t *ppos,
2610 unsigned long convmul,
2611 unsigned long convdiv)
2612{
2613 return __do_proc_doulongvec_minmax(table->data, table, write,
2614 filp, buffer, lenp, ppos, convmul, convdiv);
2615}
2616
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617/**
2618 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2619 * @table: the sysctl table
2620 * @write: %TRUE if this is a write to the sysctl file
2621 * @filp: the file structure
2622 * @buffer: the user buffer
2623 * @lenp: the size of the user buffer
2624 * @ppos: file position
2625 *
2626 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2627 * values from/to the user buffer, treated as an ASCII string.
2628 *
2629 * This routine will ensure the values are within the range specified by
2630 * table->extra1 (min) and table->extra2 (max).
2631 *
2632 * Returns 0 on success.
2633 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002634int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 void __user *buffer, size_t *lenp, loff_t *ppos)
2636{
2637 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2638}
2639
2640/**
2641 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2642 * @table: the sysctl table
2643 * @write: %TRUE if this is a write to the sysctl file
2644 * @filp: the file structure
2645 * @buffer: the user buffer
2646 * @lenp: the size of the user buffer
2647 * @ppos: file position
2648 *
2649 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2650 * values from/to the user buffer, treated as an ASCII string. The values
2651 * are treated as milliseconds, and converted to jiffies when they are stored.
2652 *
2653 * This routine will ensure the values are within the range specified by
2654 * table->extra1 (min) and table->extra2 (max).
2655 *
2656 * Returns 0 on success.
2657 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002658int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 struct file *filp,
2660 void __user *buffer,
2661 size_t *lenp, loff_t *ppos)
2662{
2663 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2664 lenp, ppos, HZ, 1000l);
2665}
2666
2667
2668static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2669 int *valp,
2670 int write, void *data)
2671{
2672 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002673 if (*lvalp > LONG_MAX / HZ)
2674 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2676 } else {
2677 int val = *valp;
2678 unsigned long lval;
2679 if (val < 0) {
2680 *negp = -1;
2681 lval = (unsigned long)-val;
2682 } else {
2683 *negp = 0;
2684 lval = (unsigned long)val;
2685 }
2686 *lvalp = lval / HZ;
2687 }
2688 return 0;
2689}
2690
2691static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2692 int *valp,
2693 int write, void *data)
2694{
2695 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002696 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2697 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2699 } else {
2700 int val = *valp;
2701 unsigned long lval;
2702 if (val < 0) {
2703 *negp = -1;
2704 lval = (unsigned long)-val;
2705 } else {
2706 *negp = 0;
2707 lval = (unsigned long)val;
2708 }
2709 *lvalp = jiffies_to_clock_t(lval);
2710 }
2711 return 0;
2712}
2713
2714static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2715 int *valp,
2716 int write, void *data)
2717{
2718 if (write) {
2719 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2720 } else {
2721 int val = *valp;
2722 unsigned long lval;
2723 if (val < 0) {
2724 *negp = -1;
2725 lval = (unsigned long)-val;
2726 } else {
2727 *negp = 0;
2728 lval = (unsigned long)val;
2729 }
2730 *lvalp = jiffies_to_msecs(lval);
2731 }
2732 return 0;
2733}
2734
2735/**
2736 * proc_dointvec_jiffies - read a vector of integers as seconds
2737 * @table: the sysctl table
2738 * @write: %TRUE if this is a write to the sysctl file
2739 * @filp: the file structure
2740 * @buffer: the user buffer
2741 * @lenp: the size of the user buffer
2742 * @ppos: file position
2743 *
2744 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2745 * values from/to the user buffer, treated as an ASCII string.
2746 * The values read are assumed to be in seconds, and are converted into
2747 * jiffies.
2748 *
2749 * Returns 0 on success.
2750 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002751int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 void __user *buffer, size_t *lenp, loff_t *ppos)
2753{
2754 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2755 do_proc_dointvec_jiffies_conv,NULL);
2756}
2757
2758/**
2759 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2760 * @table: the sysctl table
2761 * @write: %TRUE if this is a write to the sysctl file
2762 * @filp: the file structure
2763 * @buffer: the user buffer
2764 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002765 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 *
2767 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2768 * values from/to the user buffer, treated as an ASCII string.
2769 * The values read are assumed to be in 1/USER_HZ seconds, and
2770 * are converted into jiffies.
2771 *
2772 * Returns 0 on success.
2773 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002774int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 void __user *buffer, size_t *lenp, loff_t *ppos)
2776{
2777 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2778 do_proc_dointvec_userhz_jiffies_conv,NULL);
2779}
2780
2781/**
2782 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2783 * @table: the sysctl table
2784 * @write: %TRUE if this is a write to the sysctl file
2785 * @filp: the file structure
2786 * @buffer: the user buffer
2787 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002788 * @ppos: file position
2789 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 *
2791 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2792 * values from/to the user buffer, treated as an ASCII string.
2793 * The values read are assumed to be in 1/1000 seconds, and
2794 * are converted into jiffies.
2795 *
2796 * Returns 0 on success.
2797 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002798int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 void __user *buffer, size_t *lenp, loff_t *ppos)
2800{
2801 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2802 do_proc_dointvec_ms_jiffies_conv, NULL);
2803}
2804
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002805static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002806 void __user *buffer, size_t *lenp, loff_t *ppos)
2807{
2808 struct pid *new_pid;
2809 pid_t tmp;
2810 int r;
2811
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002812 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002813
2814 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2815 lenp, ppos, NULL, NULL);
2816 if (r || !write)
2817 return r;
2818
2819 new_pid = find_get_pid(tmp);
2820 if (!new_pid)
2821 return -ESRCH;
2822
2823 put_pid(xchg(&cad_pid, new_pid));
2824 return 0;
2825}
2826
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827#else /* CONFIG_PROC_FS */
2828
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002829int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 void __user *buffer, size_t *lenp, loff_t *ppos)
2831{
2832 return -ENOSYS;
2833}
2834
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002835int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 void __user *buffer, size_t *lenp, loff_t *ppos)
2837{
2838 return -ENOSYS;
2839}
2840
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002841int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 void __user *buffer, size_t *lenp, loff_t *ppos)
2843{
2844 return -ENOSYS;
2845}
2846
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002847int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 void __user *buffer, size_t *lenp, loff_t *ppos)
2849{
2850 return -ENOSYS;
2851}
2852
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002853int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 void __user *buffer, size_t *lenp, loff_t *ppos)
2855{
2856 return -ENOSYS;
2857}
2858
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002859int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 void __user *buffer, size_t *lenp, loff_t *ppos)
2861{
2862 return -ENOSYS;
2863}
2864
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002865int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 void __user *buffer, size_t *lenp, loff_t *ppos)
2867{
2868 return -ENOSYS;
2869}
2870
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002871int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 struct file *filp,
2873 void __user *buffer,
2874 size_t *lenp, loff_t *ppos)
2875{
2876 return -ENOSYS;
2877}
2878
2879
2880#endif /* CONFIG_PROC_FS */
2881
2882
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002883#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884/*
2885 * General sysctl support routines
2886 */
2887
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002888/* The generic sysctl data routine (used if no strategy routine supplied) */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002889int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002890 void __user *oldval, size_t __user *oldlenp,
2891 void __user *newval, size_t newlen)
2892{
2893 size_t len;
2894
2895 /* Get out of I don't have a variable */
2896 if (!table->data || !table->maxlen)
2897 return -ENOTDIR;
2898
2899 if (oldval && oldlenp) {
2900 if (get_user(len, oldlenp))
2901 return -EFAULT;
2902 if (len) {
2903 if (len > table->maxlen)
2904 len = table->maxlen;
2905 if (copy_to_user(oldval, table->data, len))
2906 return -EFAULT;
2907 if (put_user(len, oldlenp))
2908 return -EFAULT;
2909 }
2910 }
2911
2912 if (newval && newlen) {
2913 if (newlen > table->maxlen)
2914 newlen = table->maxlen;
2915
2916 if (copy_from_user(table->data, newval, newlen))
2917 return -EFAULT;
2918 }
2919 return 1;
2920}
2921
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922/* The generic string strategy routine: */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002923int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002925 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 if (!table->data || !table->maxlen)
2928 return -ENOTDIR;
2929
2930 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002931 size_t bufsize;
2932 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002934 if (bufsize) {
2935 size_t len = strlen(table->data), copied;
2936
2937 /* This shouldn't trigger for a well-formed sysctl */
2938 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002940
2941 /* Copy up to a max of bufsize-1 bytes of the string */
2942 copied = (len >= bufsize) ? bufsize - 1 : len;
2943
2944 if (copy_to_user(oldval, table->data, copied) ||
2945 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002947 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 return -EFAULT;
2949 }
2950 }
2951 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002952 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 if (len > table->maxlen)
2954 len = table->maxlen;
2955 if(copy_from_user(table->data, newval, len))
2956 return -EFAULT;
2957 if (len == table->maxlen)
2958 len--;
2959 ((char *) table->data)[len] = 0;
2960 }
Yi Yang82c9df82005-12-30 16:37:10 +08002961 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962}
2963
2964/*
2965 * This function makes sure that all of the integers in the vector
2966 * are between the minimum and maximum values given in the arrays
2967 * table->extra1 and table->extra2, respectively.
2968 */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07002969int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002971 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972{
2973
2974 if (newval && newlen) {
2975 int __user *vec = (int __user *) newval;
2976 int *min = (int *) table->extra1;
2977 int *max = (int *) table->extra2;
2978 size_t length;
2979 int i;
2980
2981 if (newlen % sizeof(int) != 0)
2982 return -EINVAL;
2983
2984 if (!table->extra1 && !table->extra2)
2985 return 0;
2986
2987 if (newlen > table->maxlen)
2988 newlen = table->maxlen;
2989 length = newlen / sizeof(int);
2990
2991 for (i = 0; i < length; i++) {
2992 int value;
2993 if (get_user(value, vec + i))
2994 return -EFAULT;
2995 if (min && value < min[i])
2996 return -EINVAL;
2997 if (max && value > max[i])
2998 return -EINVAL;
2999 }
3000 }
3001 return 0;
3002}
3003
3004/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003005int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003007 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003009 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003011
3012 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003014 if (olen) {
3015 int val;
3016
3017 if (olen < sizeof(int))
3018 return -EINVAL;
3019
3020 val = *(int *)(table->data) / HZ;
3021 if (put_user(val, (int __user *)oldval))
3022 return -EFAULT;
3023 if (put_user(sizeof(int), oldlenp))
3024 return -EFAULT;
3025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 }
3027 if (newval && newlen) {
3028 int new;
3029 if (newlen != sizeof(int))
3030 return -EINVAL;
3031 if (get_user(new, (int __user *)newval))
3032 return -EFAULT;
3033 *(int *)(table->data) = new*HZ;
3034 }
3035 return 1;
3036}
3037
3038/* Strategy function to convert jiffies to seconds */
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003039int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003041 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003043 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003045
3046 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08003048 if (olen) {
3049 int val;
3050
3051 if (olen < sizeof(int))
3052 return -EINVAL;
3053
3054 val = jiffies_to_msecs(*(int *)(table->data));
3055 if (put_user(val, (int __user *)oldval))
3056 return -EFAULT;
3057 if (put_user(sizeof(int), oldlenp))
3058 return -EFAULT;
3059 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 }
3061 if (newval && newlen) {
3062 int new;
3063 if (newlen != sizeof(int))
3064 return -EINVAL;
3065 if (get_user(new, (int __user *)newval))
3066 return -EFAULT;
3067 *(int *)(table->data) = msecs_to_jiffies(new);
3068 }
3069 return 1;
3070}
3071
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003072
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08003073
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003074#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075
3076
Heiko Carstens1e7bfb22009-01-14 14:14:29 +01003077SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003079 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003080 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003081
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003082 if (copy_from_user(&tmp, args, sizeof(tmp)))
3083 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08003084
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003085 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003086
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003087 /* If no error reading the parameters then just -ENOSYS ... */
3088 if (!error)
3089 error = -ENOSYS;
3090
3091 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092}
3093
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003094int sysctl_data(struct ctl_table *table,
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003095 void __user *oldval, size_t __user *oldlenp,
3096 void __user *newval, size_t newlen)
3097{
3098 return -ENOSYS;
3099}
3100
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003101int sysctl_string(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003103 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104{
3105 return -ENOSYS;
3106}
3107
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003108int sysctl_intvec(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003110 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111{
3112 return -ENOSYS;
3113}
3114
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003115int sysctl_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003117 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118{
3119 return -ENOSYS;
3120}
3121
Alexey Dobriyanf221e722008-10-15 22:04:23 -07003122int sysctl_ms_jiffies(struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08003124 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125{
3126 return -ENOSYS;
3127}
3128
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07003129#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003131static int deprecated_sysctl_warning(struct __sysctl_args *args)
3132{
3133 static int msg_count;
3134 int name[CTL_MAXNAME];
3135 int i;
3136
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08003137 /* Check args->nlen. */
3138 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3139 return -ENOTDIR;
3140
Eric W. Biederman7058cb02007-10-18 03:05:58 -07003141 /* Read in the sysctl name for better debug message logging */
3142 for (i = 0; i < args->nlen; i++)
3143 if (get_user(name[i], args->name + i))
3144 return -EFAULT;
3145
3146 /* Ignore accesses to kernel.version */
3147 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3148 return 0;
3149
3150 if (msg_count < 5) {
3151 msg_count++;
3152 printk(KERN_INFO
3153 "warning: process `%s' used the deprecated sysctl "
3154 "system call with ", current->comm);
3155 for (i = 0; i < args->nlen; i++)
3156 printk("%d.", name[i]);
3157 printk("\n");
3158 }
3159 return 0;
3160}
3161
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162/*
3163 * No sense putting this after each symbol definition, twice,
3164 * exception granted :-)
3165 */
3166EXPORT_SYMBOL(proc_dointvec);
3167EXPORT_SYMBOL(proc_dointvec_jiffies);
3168EXPORT_SYMBOL(proc_dointvec_minmax);
3169EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3170EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3171EXPORT_SYMBOL(proc_dostring);
3172EXPORT_SYMBOL(proc_doulongvec_minmax);
3173EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3174EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11003175EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176EXPORT_SYMBOL(sysctl_intvec);
3177EXPORT_SYMBOL(sysctl_jiffies);
3178EXPORT_SYMBOL(sysctl_ms_jiffies);
3179EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07003180EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181EXPORT_SYMBOL(unregister_sysctl_table);