blob: 35a50db9b6cee1267b5865f543a8a8d86157a65a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
26#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/init.h>
33#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010034#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030035#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/sysrq.h>
37#include <linux/highuid.h>
38#include <linux/writeback.h>
39#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070041#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <linux/times.h>
43#include <linux/limits.h>
44#include <linux/dcache.h>
45#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070046#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080047#include <linux/nfs_fs.h>
48#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070049#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020050#include <linux/ftrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include <asm/uaccess.h>
53#include <asm/processor.h>
54
Andi Kleen29cbc782006-09-30 01:47:55 +020055#ifdef CONFIG_X86
56#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010057#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010058#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020059#endif
60
Eric W. Biederman7058cb02007-10-18 03:05:58 -070061static int deprecated_sysctl_warning(struct __sysctl_args *args);
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#if defined(CONFIG_SYSCTL)
64
65/* External variables not in a header file. */
66extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070067extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern int sysctl_overcommit_memory;
69extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070070extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070071extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080072extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070075extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max;
78extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080080extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080081extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020082extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070083extern int maps_protect;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040085extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul E. McKenney31a72bc2008-06-18 09:26:49 -070086#ifdef CONFIG_RCU_TORTURE_TEST
87extern int rcutorture_runnable;
88#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070090/* Constants used for minimum and maximum */
Ingo Molnar1c4cd6d2008-05-12 21:21:14 +020091#if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092static int one = 1;
Bron Gondwana195cf4532008-02-04 22:29:20 -080093#endif
94
95#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070096static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +020097static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070098#endif
99
100#ifdef CONFIG_MMU
101static int two = 2;
102#endif
103
104static int zero;
105static int one_hundred = 100;
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108static int maxolduid = 65535;
109static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112static int ngroups_max = NGROUPS_MAX;
113
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200114#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115extern char modprobe_path[];
116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#ifdef CONFIG_CHR_DEV_SG
118extern int sg_big_buff;
119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121#ifdef __sparc__
122extern char reboot_command [];
123extern int stop_a_enabled;
124extern int scons_pwroff;
125#endif
126
127#ifdef __hppa__
128extern int pwrsw_enabled;
129extern int unaligned_enabled;
130#endif
131
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800132#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#ifdef CONFIG_MATHEMU
134extern int sysctl_ieee_emulation_warnings;
135#endif
136extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700137extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#endif
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef CONFIG_BSD_PROCESS_ACCT
141extern int acct_parm[];
142#endif
143
Jes Sorensend2b176e2006-02-28 09:42:23 -0800144#ifdef CONFIG_IA64
145extern int no_unaligned_warning;
146#endif
147
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700148#ifdef CONFIG_RT_MUTEXES
149extern int max_lock_depth;
150#endif
151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700153static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700154 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800156 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700158
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700159static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100160static struct ctl_table_root sysctl_table_root;
161static struct ctl_table_header root_table_header = {
162 .ctl_table = root_table,
163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
164 .root = &sysctl_table_root,
165};
166static struct ctl_table_root sysctl_table_root = {
167 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
168 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
169};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700171static struct ctl_table kern_table[];
172static struct ctl_table vm_table[];
173static struct ctl_table fs_table[];
174static struct ctl_table debug_table[];
175static struct ctl_table dev_table[];
176extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700177#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700178extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400179#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
182int sysctl_legacy_va_layout;
183#endif
184
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700185extern int prove_locking;
186extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/* The default sysctl tables: */
189
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700190static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 {
192 .ctl_name = CTL_KERN,
193 .procname = "kernel",
194 .mode = 0555,
195 .child = kern_table,
196 },
197 {
198 .ctl_name = CTL_VM,
199 .procname = "vm",
200 .mode = 0555,
201 .child = vm_table,
202 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 .ctl_name = CTL_FS,
205 .procname = "fs",
206 .mode = 0555,
207 .child = fs_table,
208 },
209 {
210 .ctl_name = CTL_DEBUG,
211 .procname = "debug",
212 .mode = 0555,
213 .child = debug_table,
214 },
215 {
216 .ctl_name = CTL_DEV,
217 .procname = "dev",
218 .mode = 0555,
219 .child = dev_table,
220 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700221/*
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
224 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 { .ctl_name = 0 }
226};
227
Ingo Molnar77e54a12007-07-09 18:52:00 +0200228#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100229static int min_sched_granularity_ns = 100000; /* 100 usecs */
230static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
231static int min_wakeup_granularity_ns; /* 0 usecs */
232static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200233#endif
234
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700235static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200236#ifdef CONFIG_SCHED_DEBUG
237 {
238 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100239 .procname = "sched_min_granularity_ns",
240 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200241 .maxlen = sizeof(unsigned int),
242 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100243 .proc_handler = &sched_nr_latency_handler,
244 .strategy = &sysctl_intvec,
245 .extra1 = &min_sched_granularity_ns,
246 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200247 },
248 {
249 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200250 .procname = "sched_latency_ns",
251 .data = &sysctl_sched_latency,
252 .maxlen = sizeof(unsigned int),
253 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100254 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200255 .strategy = &sysctl_intvec,
256 .extra1 = &min_sched_granularity_ns,
257 .extra2 = &max_sched_granularity_ns,
258 },
259 {
260 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200261 .procname = "sched_wakeup_granularity_ns",
262 .data = &sysctl_sched_wakeup_granularity,
263 .maxlen = sizeof(unsigned int),
264 .mode = 0644,
265 .proc_handler = &proc_dointvec_minmax,
266 .strategy = &sysctl_intvec,
267 .extra1 = &min_wakeup_granularity_ns,
268 .extra2 = &max_wakeup_granularity_ns,
269 },
270 {
271 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200272 .procname = "sched_shares_ratelimit",
273 .data = &sysctl_sched_shares_ratelimit,
274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
276 .proc_handler = &proc_dointvec,
277 },
278 {
279 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200280 .procname = "sched_child_runs_first",
281 .data = &sysctl_sched_child_runs_first,
282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
284 .proc_handler = &proc_dointvec,
285 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200286 {
287 .ctl_name = CTL_UNNUMBERED,
288 .procname = "sched_features",
289 .data = &sysctl_sched_features,
290 .maxlen = sizeof(unsigned int),
291 .mode = 0644,
292 .proc_handler = &proc_dointvec,
293 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200294 {
295 .ctl_name = CTL_UNNUMBERED,
296 .procname = "sched_migration_cost",
297 .data = &sysctl_sched_migration_cost,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
300 .proc_handler = &proc_dointvec,
301 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100302 {
303 .ctl_name = CTL_UNNUMBERED,
304 .procname = "sched_nr_migrate",
305 .data = &sysctl_sched_nr_migrate,
306 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100307 .mode = 0644,
308 .proc_handler = &proc_dointvec,
309 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200310#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200311 {
312 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100313 .procname = "sched_rt_period_us",
314 .data = &sysctl_sched_rt_period,
315 .maxlen = sizeof(unsigned int),
316 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200317 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100318 },
319 {
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "sched_rt_runtime_us",
322 .data = &sysctl_sched_rt_runtime,
323 .maxlen = sizeof(int),
324 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200325 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100326 },
327 {
328 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200329 .procname = "sched_compat_yield",
330 .data = &sysctl_sched_compat_yield,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
333 .proc_handler = &proc_dointvec,
334 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700335#ifdef CONFIG_PROVE_LOCKING
336 {
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "prove_locking",
339 .data = &prove_locking,
340 .maxlen = sizeof(int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
343 },
344#endif
345#ifdef CONFIG_LOCK_STAT
346 {
347 .ctl_name = CTL_UNNUMBERED,
348 .procname = "lock_stat",
349 .data = &lock_stat,
350 .maxlen = sizeof(int),
351 .mode = 0644,
352 .proc_handler = &proc_dointvec,
353 },
354#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200355 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 .ctl_name = KERN_PANIC,
357 .procname = "panic",
358 .data = &panic_timeout,
359 .maxlen = sizeof(int),
360 .mode = 0644,
361 .proc_handler = &proc_dointvec,
362 },
363 {
364 .ctl_name = KERN_CORE_USES_PID,
365 .procname = "core_uses_pid",
366 .data = &core_uses_pid,
367 .maxlen = sizeof(int),
368 .mode = 0644,
369 .proc_handler = &proc_dointvec,
370 },
371 {
372 .ctl_name = KERN_CORE_PATTERN,
373 .procname = "core_pattern",
374 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700375 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .mode = 0644,
377 .proc_handler = &proc_dostring,
378 .strategy = &sysctl_string,
379 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800380#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 .procname = "tainted",
383 .data = &tainted,
384 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800385 .mode = 0644,
386 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800388#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100389#ifdef CONFIG_LATENCYTOP
390 {
391 .procname = "latencytop",
392 .data = &latencytop_enabled,
393 .maxlen = sizeof(int),
394 .mode = 0644,
395 .proc_handler = &proc_dointvec,
396 },
397#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398#ifdef CONFIG_BLK_DEV_INITRD
399 {
400 .ctl_name = KERN_REALROOTDEV,
401 .procname = "real-root-dev",
402 .data = &real_root_dev,
403 .maxlen = sizeof(int),
404 .mode = 0644,
405 .proc_handler = &proc_dointvec,
406 },
407#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700408 {
409 .ctl_name = CTL_UNNUMBERED,
410 .procname = "print-fatal-signals",
411 .data = &print_fatal_signals,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = &proc_dointvec,
415 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416#ifdef __sparc__
417 {
418 .ctl_name = KERN_SPARC_REBOOT,
419 .procname = "reboot-cmd",
420 .data = reboot_command,
421 .maxlen = 256,
422 .mode = 0644,
423 .proc_handler = &proc_dostring,
424 .strategy = &sysctl_string,
425 },
426 {
427 .ctl_name = KERN_SPARC_STOP_A,
428 .procname = "stop-a",
429 .data = &stop_a_enabled,
430 .maxlen = sizeof (int),
431 .mode = 0644,
432 .proc_handler = &proc_dointvec,
433 },
434 {
435 .ctl_name = KERN_SPARC_SCONS_PWROFF,
436 .procname = "scons-poweroff",
437 .data = &scons_pwroff,
438 .maxlen = sizeof (int),
439 .mode = 0644,
440 .proc_handler = &proc_dointvec,
441 },
442#endif
443#ifdef __hppa__
444 {
445 .ctl_name = KERN_HPPA_PWRSW,
446 .procname = "soft-power",
447 .data = &pwrsw_enabled,
448 .maxlen = sizeof (int),
449 .mode = 0644,
450 .proc_handler = &proc_dointvec,
451 },
452 {
453 .ctl_name = KERN_HPPA_UNALIGNED,
454 .procname = "unaligned-trap",
455 .data = &unaligned_enabled,
456 .maxlen = sizeof (int),
457 .mode = 0644,
458 .proc_handler = &proc_dointvec,
459 },
460#endif
461 {
462 .ctl_name = KERN_CTLALTDEL,
463 .procname = "ctrl-alt-del",
464 .data = &C_A_D,
465 .maxlen = sizeof(int),
466 .mode = 0644,
467 .proc_handler = &proc_dointvec,
468 },
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200469#ifdef CONFIG_FTRACE
470 {
471 .ctl_name = CTL_UNNUMBERED,
472 .procname = "ftrace_enabled",
473 .data = &ftrace_enabled,
474 .maxlen = sizeof(int),
475 .mode = 0644,
476 .proc_handler = &ftrace_enable_sysctl,
477 },
478#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200479#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 {
481 .ctl_name = KERN_MODPROBE,
482 .procname = "modprobe",
483 .data = &modprobe_path,
484 .maxlen = KMOD_PATH_LEN,
485 .mode = 0644,
486 .proc_handler = &proc_dostring,
487 .strategy = &sysctl_string,
488 },
489#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700490#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 {
492 .ctl_name = KERN_HOTPLUG,
493 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100494 .data = &uevent_helper,
495 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 .mode = 0644,
497 .proc_handler = &proc_dostring,
498 .strategy = &sysctl_string,
499 },
500#endif
501#ifdef CONFIG_CHR_DEV_SG
502 {
503 .ctl_name = KERN_SG_BIG_BUFF,
504 .procname = "sg-big-buff",
505 .data = &sg_big_buff,
506 .maxlen = sizeof (int),
507 .mode = 0444,
508 .proc_handler = &proc_dointvec,
509 },
510#endif
511#ifdef CONFIG_BSD_PROCESS_ACCT
512 {
513 .ctl_name = KERN_ACCT,
514 .procname = "acct",
515 .data = &acct_parm,
516 .maxlen = 3*sizeof(int),
517 .mode = 0644,
518 .proc_handler = &proc_dointvec,
519 },
520#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#ifdef CONFIG_MAGIC_SYSRQ
522 {
523 .ctl_name = KERN_SYSRQ,
524 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800525 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 .maxlen = sizeof (int),
527 .mode = 0644,
528 .proc_handler = &proc_dointvec,
529 },
530#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700531#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700534 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 .maxlen = sizeof (int),
536 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700537 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700539#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
541 .ctl_name = KERN_MAX_THREADS,
542 .procname = "threads-max",
543 .data = &max_threads,
544 .maxlen = sizeof(int),
545 .mode = 0644,
546 .proc_handler = &proc_dointvec,
547 },
548 {
549 .ctl_name = KERN_RANDOM,
550 .procname = "random",
551 .mode = 0555,
552 .child = random_table,
553 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 {
555 .ctl_name = KERN_OVERFLOWUID,
556 .procname = "overflowuid",
557 .data = &overflowuid,
558 .maxlen = sizeof(int),
559 .mode = 0644,
560 .proc_handler = &proc_dointvec_minmax,
561 .strategy = &sysctl_intvec,
562 .extra1 = &minolduid,
563 .extra2 = &maxolduid,
564 },
565 {
566 .ctl_name = KERN_OVERFLOWGID,
567 .procname = "overflowgid",
568 .data = &overflowgid,
569 .maxlen = sizeof(int),
570 .mode = 0644,
571 .proc_handler = &proc_dointvec_minmax,
572 .strategy = &sysctl_intvec,
573 .extra1 = &minolduid,
574 .extra2 = &maxolduid,
575 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800576#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#ifdef CONFIG_MATHEMU
578 {
579 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
580 .procname = "ieee_emulation_warnings",
581 .data = &sysctl_ieee_emulation_warnings,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = &proc_dointvec,
585 },
586#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 {
588 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
589 .procname = "userprocess_debug",
590 .data = &sysctl_userprocess_debug,
591 .maxlen = sizeof(int),
592 .mode = 0644,
593 .proc_handler = &proc_dointvec,
594 },
595#endif
596 {
597 .ctl_name = KERN_PIDMAX,
598 .procname = "pid_max",
599 .data = &pid_max,
600 .maxlen = sizeof (int),
601 .mode = 0644,
602 .proc_handler = &proc_dointvec_minmax,
603 .strategy = sysctl_intvec,
604 .extra1 = &pid_max_min,
605 .extra2 = &pid_max_max,
606 },
607 {
608 .ctl_name = KERN_PANIC_ON_OOPS,
609 .procname = "panic_on_oops",
610 .data = &panic_on_oops,
611 .maxlen = sizeof(int),
612 .mode = 0644,
613 .proc_handler = &proc_dointvec,
614 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800615#if defined CONFIG_PRINTK
616 {
617 .ctl_name = KERN_PRINTK,
618 .procname = "printk",
619 .data = &console_loglevel,
620 .maxlen = 4*sizeof(int),
621 .mode = 0644,
622 .proc_handler = &proc_dointvec,
623 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 {
625 .ctl_name = KERN_PRINTK_RATELIMIT,
626 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700627 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 .maxlen = sizeof(int),
629 .mode = 0644,
630 .proc_handler = &proc_dointvec_jiffies,
631 .strategy = &sysctl_jiffies,
632 },
633 {
634 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
635 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700636 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 .maxlen = sizeof(int),
638 .mode = 0644,
639 .proc_handler = &proc_dointvec,
640 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800641#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 {
643 .ctl_name = KERN_NGROUPS_MAX,
644 .procname = "ngroups_max",
645 .data = &ngroups_max,
646 .maxlen = sizeof (int),
647 .mode = 0444,
648 .proc_handler = &proc_dointvec,
649 },
650#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
651 {
652 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
653 .procname = "unknown_nmi_panic",
654 .data = &unknown_nmi_panic,
655 .maxlen = sizeof (int),
656 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200657 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 },
Don Zickus407984f2006-09-26 10:52:27 +0200659 {
Don Zickus407984f2006-09-26 10:52:27 +0200660 .procname = "nmi_watchdog",
661 .data = &nmi_watchdog_enabled,
662 .maxlen = sizeof (int),
663 .mode = 0644,
664 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 },
666#endif
667#if defined(CONFIG_X86)
668 {
Don Zickus8da5add2006-09-26 10:52:27 +0200669 .ctl_name = KERN_PANIC_ON_NMI,
670 .procname = "panic_on_unrecovered_nmi",
671 .data = &panic_on_unrecovered_nmi,
672 .maxlen = sizeof(int),
673 .mode = 0644,
674 .proc_handler = &proc_dointvec,
675 },
676 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .ctl_name = KERN_BOOTLOADER_TYPE,
678 .procname = "bootloader_type",
679 .data = &bootloader_type,
680 .maxlen = sizeof (int),
681 .mode = 0444,
682 .proc_handler = &proc_dointvec,
683 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100684 {
685 .ctl_name = CTL_UNNUMBERED,
686 .procname = "kstack_depth_to_print",
687 .data = &kstack_depth_to_print,
688 .maxlen = sizeof(int),
689 .mode = 0644,
690 .proc_handler = &proc_dointvec,
691 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100692 {
693 .ctl_name = CTL_UNNUMBERED,
694 .procname = "io_delay_type",
695 .data = &io_delay_type,
696 .maxlen = sizeof(int),
697 .mode = 0644,
698 .proc_handler = &proc_dointvec,
699 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800701#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 {
703 .ctl_name = KERN_RANDOMIZE,
704 .procname = "randomize_va_space",
705 .data = &randomize_va_space,
706 .maxlen = sizeof(int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
709 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800710#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800711#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700712 {
713 .ctl_name = KERN_SPIN_RETRY,
714 .procname = "spin_retry",
715 .data = &spin_retry,
716 .maxlen = sizeof (int),
717 .mode = 0644,
718 .proc_handler = &proc_dointvec,
719 },
720#endif
Len Brown673d5b42007-07-28 03:33:16 -0400721#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800722 {
Pavel Machekc255d842006-02-20 18:27:58 -0800723 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700724 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800725 .maxlen = sizeof (unsigned long),
726 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800727 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800728 },
729#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800730#ifdef CONFIG_IA64
731 {
732 .ctl_name = KERN_IA64_UNALIGNED,
733 .procname = "ignore-unaligned-usertrap",
734 .data = &no_unaligned_warning,
735 .maxlen = sizeof (int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
738 },
739#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700740#ifdef CONFIG_DETECT_SOFTLOCKUP
741 {
742 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200743 .procname = "softlockup_panic",
744 .data = &softlockup_panic,
745 .maxlen = sizeof(int),
746 .mode = 0644,
Hiroshi Shimamoto4dca10a2008-07-07 18:37:04 -0700747 .proc_handler = &proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200748 .strategy = &sysctl_intvec,
749 .extra1 = &zero,
750 .extra2 = &one,
751 },
752 {
753 .ctl_name = CTL_UNNUMBERED,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700754 .procname = "softlockup_thresh",
755 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200756 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700757 .mode = 0644,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200758 .proc_handler = &proc_dointvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700759 .strategy = &sysctl_intvec,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200760 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700761 .extra2 = &sixty,
762 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100763 {
764 .ctl_name = CTL_UNNUMBERED,
765 .procname = "hung_task_check_count",
766 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100767 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100768 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100769 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100770 .strategy = &sysctl_intvec,
771 },
772 {
773 .ctl_name = CTL_UNNUMBERED,
774 .procname = "hung_task_timeout_secs",
775 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100776 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100777 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100778 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100779 .strategy = &sysctl_intvec,
780 },
781 {
782 .ctl_name = CTL_UNNUMBERED,
783 .procname = "hung_task_warnings",
784 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100785 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100786 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100787 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100788 .strategy = &sysctl_intvec,
789 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700790#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200791#ifdef CONFIG_COMPAT
792 {
793 .ctl_name = KERN_COMPAT_LOG,
794 .procname = "compat-log",
795 .data = &compat_log,
796 .maxlen = sizeof (int),
797 .mode = 0644,
798 .proc_handler = &proc_dointvec,
799 },
800#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700801#ifdef CONFIG_RT_MUTEXES
802 {
803 .ctl_name = KERN_MAX_LOCK_DEPTH,
804 .procname = "max_lock_depth",
805 .data = &max_lock_depth,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = &proc_dointvec,
809 },
810#endif
Kees Cook5096add2007-05-08 00:26:04 -0700811#ifdef CONFIG_PROC_FS
812 {
813 .ctl_name = CTL_UNNUMBERED,
814 .procname = "maps_protect",
815 .data = &maps_protect,
816 .maxlen = sizeof(int),
817 .mode = 0644,
818 .proc_handler = &proc_dointvec,
819 },
820#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700821 {
822 .ctl_name = CTL_UNNUMBERED,
823 .procname = "poweroff_cmd",
824 .data = &poweroff_cmd,
825 .maxlen = POWEROFF_CMD_PATH_LEN,
826 .mode = 0644,
827 .proc_handler = &proc_dostring,
828 .strategy = &sysctl_string,
829 },
David Howells0b77f5b2008-04-29 01:01:32 -0700830#ifdef CONFIG_KEYS
831 {
832 .ctl_name = CTL_UNNUMBERED,
833 .procname = "keys",
834 .mode = 0555,
835 .child = key_sysctls,
836 },
837#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700838#ifdef CONFIG_RCU_TORTURE_TEST
839 {
840 .ctl_name = CTL_UNNUMBERED,
841 .procname = "rcutorture_runnable",
842 .data = &rcutorture_runnable,
843 .maxlen = sizeof(int),
844 .mode = 0644,
845 .proc_handler = &proc_dointvec,
846 },
847#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700848/*
849 * NOTE: do not add new entries to this table unless you have read
850 * Documentation/sysctl/ctl_unnumbered.txt
851 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 { .ctl_name = 0 }
853};
854
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700855static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 {
857 .ctl_name = VM_OVERCOMMIT_MEMORY,
858 .procname = "overcommit_memory",
859 .data = &sysctl_overcommit_memory,
860 .maxlen = sizeof(sysctl_overcommit_memory),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec,
863 },
864 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700865 .ctl_name = VM_PANIC_ON_OOM,
866 .procname = "panic_on_oom",
867 .data = &sysctl_panic_on_oom,
868 .maxlen = sizeof(sysctl_panic_on_oom),
869 .mode = 0644,
870 .proc_handler = &proc_dointvec,
871 },
872 {
David Rientjesfe071d72007-10-16 23:25:56 -0700873 .ctl_name = CTL_UNNUMBERED,
874 .procname = "oom_kill_allocating_task",
875 .data = &sysctl_oom_kill_allocating_task,
876 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
877 .mode = 0644,
878 .proc_handler = &proc_dointvec,
879 },
880 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800881 .ctl_name = CTL_UNNUMBERED,
882 .procname = "oom_dump_tasks",
883 .data = &sysctl_oom_dump_tasks,
884 .maxlen = sizeof(sysctl_oom_dump_tasks),
885 .mode = 0644,
886 .proc_handler = &proc_dointvec,
887 },
888 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 .ctl_name = VM_OVERCOMMIT_RATIO,
890 .procname = "overcommit_ratio",
891 .data = &sysctl_overcommit_ratio,
892 .maxlen = sizeof(sysctl_overcommit_ratio),
893 .mode = 0644,
894 .proc_handler = &proc_dointvec,
895 },
896 {
897 .ctl_name = VM_PAGE_CLUSTER,
898 .procname = "page-cluster",
899 .data = &page_cluster,
900 .maxlen = sizeof(int),
901 .mode = 0644,
902 .proc_handler = &proc_dointvec,
903 },
904 {
905 .ctl_name = VM_DIRTY_BACKGROUND,
906 .procname = "dirty_background_ratio",
907 .data = &dirty_background_ratio,
908 .maxlen = sizeof(dirty_background_ratio),
909 .mode = 0644,
910 .proc_handler = &proc_dointvec_minmax,
911 .strategy = &sysctl_intvec,
912 .extra1 = &zero,
913 .extra2 = &one_hundred,
914 },
915 {
916 .ctl_name = VM_DIRTY_RATIO,
917 .procname = "dirty_ratio",
918 .data = &vm_dirty_ratio,
919 .maxlen = sizeof(vm_dirty_ratio),
920 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700921 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 .strategy = &sysctl_intvec,
923 .extra1 = &zero,
924 .extra2 = &one_hundred,
925 },
926 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800928 .data = &dirty_writeback_interval,
929 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 .mode = 0644,
931 .proc_handler = &dirty_writeback_centisecs_handler,
932 },
933 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800935 .data = &dirty_expire_interval,
936 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800938 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 },
940 {
941 .ctl_name = VM_NR_PDFLUSH_THREADS,
942 .procname = "nr_pdflush_threads",
943 .data = &nr_pdflush_threads,
944 .maxlen = sizeof nr_pdflush_threads,
945 .mode = 0444 /* read-only*/,
946 .proc_handler = &proc_dointvec,
947 },
948 {
949 .ctl_name = VM_SWAPPINESS,
950 .procname = "swappiness",
951 .data = &vm_swappiness,
952 .maxlen = sizeof(vm_swappiness),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec_minmax,
955 .strategy = &sysctl_intvec,
956 .extra1 = &zero,
957 .extra2 = &one_hundred,
958 },
959#ifdef CONFIG_HUGETLB_PAGE
960 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700962 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 .maxlen = sizeof(unsigned long),
964 .mode = 0644,
965 .proc_handler = &hugetlb_sysctl_handler,
966 .extra1 = (void *)&hugetlb_zero,
967 .extra2 = (void *)&hugetlb_infinity,
968 },
969 {
970 .ctl_name = VM_HUGETLB_GROUP,
971 .procname = "hugetlb_shm_group",
972 .data = &sysctl_hugetlb_shm_group,
973 .maxlen = sizeof(gid_t),
974 .mode = 0644,
975 .proc_handler = &proc_dointvec,
976 },
Mel Gorman396faf02007-07-17 04:03:13 -0700977 {
978 .ctl_name = CTL_UNNUMBERED,
979 .procname = "hugepages_treat_as_movable",
980 .data = &hugepages_treat_as_movable,
981 .maxlen = sizeof(int),
982 .mode = 0644,
983 .proc_handler = &hugetlb_treat_movable_handler,
984 },
Adam Litke54f9f802007-10-16 01:26:20 -0700985 {
986 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800987 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -0700988 .data = NULL,
989 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800990 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800991 .proc_handler = &hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -0700992 .extra1 = (void *)&hugetlb_zero,
993 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800994 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995#endif
996 {
997 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
998 .procname = "lowmem_reserve_ratio",
999 .data = &sysctl_lowmem_reserve_ratio,
1000 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1001 .mode = 0644,
1002 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1003 .strategy = &sysctl_intvec,
1004 },
1005 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001006 .ctl_name = VM_DROP_PAGECACHE,
1007 .procname = "drop_caches",
1008 .data = &sysctl_drop_caches,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
1011 .proc_handler = drop_caches_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1013 },
1014 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .ctl_name = VM_MIN_FREE_KBYTES,
1016 .procname = "min_free_kbytes",
1017 .data = &min_free_kbytes,
1018 .maxlen = sizeof(min_free_kbytes),
1019 .mode = 0644,
1020 .proc_handler = &min_free_kbytes_sysctl_handler,
1021 .strategy = &sysctl_intvec,
1022 .extra1 = &zero,
1023 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001024 {
1025 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1026 .procname = "percpu_pagelist_fraction",
1027 .data = &percpu_pagelist_fraction,
1028 .maxlen = sizeof(percpu_pagelist_fraction),
1029 .mode = 0644,
1030 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1031 .strategy = &sysctl_intvec,
1032 .extra1 = &min_percpu_pagelist_fract,
1033 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034#ifdef CONFIG_MMU
1035 {
1036 .ctl_name = VM_MAX_MAP_COUNT,
1037 .procname = "max_map_count",
1038 .data = &sysctl_max_map_count,
1039 .maxlen = sizeof(sysctl_max_map_count),
1040 .mode = 0644,
1041 .proc_handler = &proc_dointvec
1042 },
1043#endif
1044 {
1045 .ctl_name = VM_LAPTOP_MODE,
1046 .procname = "laptop_mode",
1047 .data = &laptop_mode,
1048 .maxlen = sizeof(laptop_mode),
1049 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001050 .proc_handler = &proc_dointvec_jiffies,
1051 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 },
1053 {
1054 .ctl_name = VM_BLOCK_DUMP,
1055 .procname = "block_dump",
1056 .data = &block_dump,
1057 .maxlen = sizeof(block_dump),
1058 .mode = 0644,
1059 .proc_handler = &proc_dointvec,
1060 .strategy = &sysctl_intvec,
1061 .extra1 = &zero,
1062 },
1063 {
1064 .ctl_name = VM_VFS_CACHE_PRESSURE,
1065 .procname = "vfs_cache_pressure",
1066 .data = &sysctl_vfs_cache_pressure,
1067 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1068 .mode = 0644,
1069 .proc_handler = &proc_dointvec,
1070 .strategy = &sysctl_intvec,
1071 .extra1 = &zero,
1072 },
1073#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1074 {
1075 .ctl_name = VM_LEGACY_VA_LAYOUT,
1076 .procname = "legacy_va_layout",
1077 .data = &sysctl_legacy_va_layout,
1078 .maxlen = sizeof(sysctl_legacy_va_layout),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec,
1081 .strategy = &sysctl_intvec,
1082 .extra1 = &zero,
1083 },
1084#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001085#ifdef CONFIG_NUMA
1086 {
1087 .ctl_name = VM_ZONE_RECLAIM_MODE,
1088 .procname = "zone_reclaim_mode",
1089 .data = &zone_reclaim_mode,
1090 .maxlen = sizeof(zone_reclaim_mode),
1091 .mode = 0644,
1092 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001093 .strategy = &sysctl_intvec,
1094 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001095 },
Christoph Lameter96146342006-07-03 00:24:13 -07001096 {
1097 .ctl_name = VM_MIN_UNMAPPED,
1098 .procname = "min_unmapped_ratio",
1099 .data = &sysctl_min_unmapped_ratio,
1100 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1101 .mode = 0644,
1102 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1103 .strategy = &sysctl_intvec,
1104 .extra1 = &zero,
1105 .extra2 = &one_hundred,
1106 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001107 {
1108 .ctl_name = VM_MIN_SLAB,
1109 .procname = "min_slab_ratio",
1110 .data = &sysctl_min_slab_ratio,
1111 .maxlen = sizeof(sysctl_min_slab_ratio),
1112 .mode = 0644,
1113 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1114 .strategy = &sysctl_intvec,
1115 .extra1 = &zero,
1116 .extra2 = &one_hundred,
1117 },
Christoph Lameter17436602006-01-18 17:42:32 -08001118#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001119#ifdef CONFIG_SMP
1120 {
1121 .ctl_name = CTL_UNNUMBERED,
1122 .procname = "stat_interval",
1123 .data = &sysctl_stat_interval,
1124 .maxlen = sizeof(sysctl_stat_interval),
1125 .mode = 0644,
1126 .proc_handler = &proc_dointvec_jiffies,
1127 .strategy = &sysctl_jiffies,
1128 },
1129#endif
Eric Parised032182007-06-28 15:55:21 -04001130#ifdef CONFIG_SECURITY
1131 {
1132 .ctl_name = CTL_UNNUMBERED,
1133 .procname = "mmap_min_addr",
1134 .data = &mmap_min_addr,
1135 .maxlen = sizeof(unsigned long),
1136 .mode = 0644,
1137 .proc_handler = &proc_doulongvec_minmax,
1138 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001139#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001140#ifdef CONFIG_NUMA
1141 {
1142 .ctl_name = CTL_UNNUMBERED,
1143 .procname = "numa_zonelist_order",
1144 .data = &numa_zonelist_order,
1145 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1146 .mode = 0644,
1147 .proc_handler = &numa_zonelist_order_handler,
1148 .strategy = &sysctl_string,
1149 },
1150#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001151#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001152 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001153 {
1154 .ctl_name = VM_VDSO_ENABLED,
1155 .procname = "vdso_enabled",
1156 .data = &vdso_enabled,
1157 .maxlen = sizeof(vdso_enabled),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec,
1160 .strategy = &sysctl_intvec,
1161 .extra1 = &zero,
1162 },
1163#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001164#ifdef CONFIG_HIGHMEM
1165 {
1166 .ctl_name = CTL_UNNUMBERED,
1167 .procname = "highmem_is_dirtyable",
1168 .data = &vm_highmem_is_dirtyable,
1169 .maxlen = sizeof(vm_highmem_is_dirtyable),
1170 .mode = 0644,
1171 .proc_handler = &proc_dointvec_minmax,
1172 .strategy = &sysctl_intvec,
1173 .extra1 = &zero,
1174 .extra2 = &one,
1175 },
1176#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001177/*
1178 * NOTE: do not add new entries to this table unless you have read
1179 * Documentation/sysctl/ctl_unnumbered.txt
1180 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 { .ctl_name = 0 }
1182};
1183
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001184#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001185static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001186 { .ctl_name = 0 }
1187};
1188#endif
1189
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001190static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 {
1192 .ctl_name = FS_NRINODE,
1193 .procname = "inode-nr",
1194 .data = &inodes_stat,
1195 .maxlen = 2*sizeof(int),
1196 .mode = 0444,
1197 .proc_handler = &proc_dointvec,
1198 },
1199 {
1200 .ctl_name = FS_STATINODE,
1201 .procname = "inode-state",
1202 .data = &inodes_stat,
1203 .maxlen = 7*sizeof(int),
1204 .mode = 0444,
1205 .proc_handler = &proc_dointvec,
1206 },
1207 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 .procname = "file-nr",
1209 .data = &files_stat,
1210 .maxlen = 3*sizeof(int),
1211 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001212 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 },
1214 {
1215 .ctl_name = FS_MAXFILE,
1216 .procname = "file-max",
1217 .data = &files_stat.max_files,
1218 .maxlen = sizeof(int),
1219 .mode = 0644,
1220 .proc_handler = &proc_dointvec,
1221 },
1222 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001223 .ctl_name = CTL_UNNUMBERED,
1224 .procname = "nr_open",
1225 .data = &sysctl_nr_open,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
Al Viroeceea0b2008-05-10 10:08:32 -04001228 .proc_handler = &proc_dointvec_minmax,
1229 .extra1 = &sysctl_nr_open_min,
1230 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001231 },
1232 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 .ctl_name = FS_DENTRY,
1234 .procname = "dentry-state",
1235 .data = &dentry_stat,
1236 .maxlen = 6*sizeof(int),
1237 .mode = 0444,
1238 .proc_handler = &proc_dointvec,
1239 },
1240 {
1241 .ctl_name = FS_OVERFLOWUID,
1242 .procname = "overflowuid",
1243 .data = &fs_overflowuid,
1244 .maxlen = sizeof(int),
1245 .mode = 0644,
1246 .proc_handler = &proc_dointvec_minmax,
1247 .strategy = &sysctl_intvec,
1248 .extra1 = &minolduid,
1249 .extra2 = &maxolduid,
1250 },
1251 {
1252 .ctl_name = FS_OVERFLOWGID,
1253 .procname = "overflowgid",
1254 .data = &fs_overflowgid,
1255 .maxlen = sizeof(int),
1256 .mode = 0644,
1257 .proc_handler = &proc_dointvec_minmax,
1258 .strategy = &sysctl_intvec,
1259 .extra1 = &minolduid,
1260 .extra2 = &maxolduid,
1261 },
1262 {
1263 .ctl_name = FS_LEASES,
1264 .procname = "leases-enable",
1265 .data = &leases_enable,
1266 .maxlen = sizeof(int),
1267 .mode = 0644,
1268 .proc_handler = &proc_dointvec,
1269 },
1270#ifdef CONFIG_DNOTIFY
1271 {
1272 .ctl_name = FS_DIR_NOTIFY,
1273 .procname = "dir-notify-enable",
1274 .data = &dir_notify_enable,
1275 .maxlen = sizeof(int),
1276 .mode = 0644,
1277 .proc_handler = &proc_dointvec,
1278 },
1279#endif
1280#ifdef CONFIG_MMU
1281 {
1282 .ctl_name = FS_LEASE_TIME,
1283 .procname = "lease-break-time",
1284 .data = &lease_break_time,
1285 .maxlen = sizeof(int),
1286 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001287 .proc_handler = &proc_dointvec_minmax,
1288 .strategy = &sysctl_intvec,
1289 .extra1 = &zero,
1290 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 },
1292 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 .procname = "aio-nr",
1294 .data = &aio_nr,
1295 .maxlen = sizeof(aio_nr),
1296 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001297 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 },
1299 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 .procname = "aio-max-nr",
1301 .data = &aio_max_nr,
1302 .maxlen = sizeof(aio_max_nr),
1303 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001304 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001306#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001307 {
1308 .ctl_name = FS_INOTIFY,
1309 .procname = "inotify",
1310 .mode = 0555,
1311 .child = inotify_table,
1312 },
1313#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001315 {
1316 .ctl_name = KERN_SETUID_DUMPABLE,
1317 .procname = "suid_dumpable",
1318 .data = &suid_dumpable,
1319 .maxlen = sizeof(int),
1320 .mode = 0644,
1321 .proc_handler = &proc_dointvec,
1322 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001323#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1324 {
1325 .ctl_name = CTL_UNNUMBERED,
1326 .procname = "binfmt_misc",
1327 .mode = 0555,
1328 .child = binfmt_misc_table,
1329 },
1330#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001331/*
1332 * NOTE: do not add new entries to this table unless you have read
1333 * Documentation/sysctl/ctl_unnumbered.txt
1334 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 { .ctl_name = 0 }
1336};
1337
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001338static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001339#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001340 {
1341 .ctl_name = CTL_UNNUMBERED,
1342 .procname = "exception-trace",
1343 .data = &show_unhandled_signals,
1344 .maxlen = sizeof(int),
1345 .mode = 0644,
1346 .proc_handler = proc_dointvec
1347 },
1348#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 { .ctl_name = 0 }
1350};
1351
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001352static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001354};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Al Viro330d57f2005-11-04 10:18:40 +00001356static DEFINE_SPINLOCK(sysctl_lock);
1357
1358/* called under sysctl_lock */
1359static int use_table(struct ctl_table_header *p)
1360{
1361 if (unlikely(p->unregistering))
1362 return 0;
1363 p->used++;
1364 return 1;
1365}
1366
1367/* called under sysctl_lock */
1368static void unuse_table(struct ctl_table_header *p)
1369{
1370 if (!--p->used)
1371 if (unlikely(p->unregistering))
1372 complete(p->unregistering);
1373}
1374
1375/* called under sysctl_lock, will reacquire if has to wait */
1376static void start_unregistering(struct ctl_table_header *p)
1377{
1378 /*
1379 * if p->used is 0, nobody will ever touch that entry again;
1380 * we'll eliminate all paths to it before dropping sysctl_lock
1381 */
1382 if (unlikely(p->used)) {
1383 struct completion wait;
1384 init_completion(&wait);
1385 p->unregistering = &wait;
1386 spin_unlock(&sysctl_lock);
1387 wait_for_completion(&wait);
1388 spin_lock(&sysctl_lock);
1389 }
1390 /*
1391 * do not remove from the list until nobody holds it; walking the
1392 * list in do_sysctl() relies on that.
1393 */
1394 list_del_init(&p->ctl_entry);
1395}
1396
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001397void sysctl_head_finish(struct ctl_table_header *head)
1398{
1399 if (!head)
1400 return;
1401 spin_lock(&sysctl_lock);
1402 unuse_table(head);
1403 spin_unlock(&sysctl_lock);
1404}
1405
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001406static struct list_head *
1407lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001408{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001409 struct list_head *header_list;
1410 header_list = &root->header_list;
1411 if (root->lookup)
1412 header_list = root->lookup(root, namespaces);
1413 return header_list;
1414}
1415
1416struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1417 struct ctl_table_header *prev)
1418{
1419 struct ctl_table_root *root;
1420 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001421 struct ctl_table_header *head;
1422 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001423
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001424 spin_lock(&sysctl_lock);
1425 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001426 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001427 tmp = &prev->ctl_entry;
1428 unuse_table(prev);
1429 goto next;
1430 }
1431 tmp = &root_table_header.ctl_entry;
1432 for (;;) {
1433 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1434
1435 if (!use_table(head))
1436 goto next;
1437 spin_unlock(&sysctl_lock);
1438 return head;
1439 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001440 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001441 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001442 header_list = lookup_header_list(root, namespaces);
1443 if (tmp != header_list)
1444 continue;
1445
1446 do {
1447 root = list_entry(root->root_list.next,
1448 struct ctl_table_root, root_list);
1449 if (root == &sysctl_table_root)
1450 goto out;
1451 header_list = lookup_header_list(root, namespaces);
1452 } while (list_empty(header_list));
1453 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001454 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001455out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001456 spin_unlock(&sysctl_lock);
1457 return NULL;
1458}
1459
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001460struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1461{
1462 return __sysctl_head_next(current->nsproxy, prev);
1463}
1464
1465void register_sysctl_root(struct ctl_table_root *root)
1466{
1467 spin_lock(&sysctl_lock);
1468 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1469 spin_unlock(&sysctl_lock);
1470}
1471
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001472#ifdef CONFIG_SYSCTL_SYSCALL
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001473/* Perform the actual read/write of a sysctl table entry. */
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001474static int do_sysctl_strategy(struct ctl_table_root *root,
1475 struct ctl_table *table,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001476 int __user *name, int nlen,
1477 void __user *oldval, size_t __user *oldlenp,
1478 void __user *newval, size_t newlen)
1479{
1480 int op = 0, rc;
1481
1482 if (oldval)
1483 op |= 004;
1484 if (newval)
1485 op |= 002;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001486 if (sysctl_perm(root, table, op))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001487 return -EPERM;
1488
1489 if (table->strategy) {
1490 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1491 newval, newlen);
1492 if (rc < 0)
1493 return rc;
1494 if (rc > 0)
1495 return 0;
1496 }
1497
1498 /* If there is no strategy routine, or if the strategy returns
1499 * zero, proceed with automatic r/w */
1500 if (table->data && table->maxlen) {
1501 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1502 newval, newlen);
1503 if (rc < 0)
1504 return rc;
1505 }
1506 return 0;
1507}
1508
1509static int parse_table(int __user *name, int nlen,
1510 void __user *oldval, size_t __user *oldlenp,
1511 void __user *newval, size_t newlen,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001512 struct ctl_table_root *root,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001513 struct ctl_table *table)
1514{
1515 int n;
1516repeat:
1517 if (!nlen)
1518 return -ENOTDIR;
1519 if (get_user(n, name))
1520 return -EFAULT;
1521 for ( ; table->ctl_name || table->procname; table++) {
1522 if (!table->ctl_name)
1523 continue;
1524 if (n == table->ctl_name) {
1525 int error;
1526 if (table->child) {
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001527 if (sysctl_perm(root, table, 001))
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001528 return -EPERM;
1529 name++;
1530 nlen--;
1531 table = table->child;
1532 goto repeat;
1533 }
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001534 error = do_sysctl_strategy(root, table, name, nlen,
Pavel Emelyanov2c4c7152008-04-29 01:02:41 -07001535 oldval, oldlenp,
1536 newval, newlen);
1537 return error;
1538 }
1539 }
1540 return -ENOTDIR;
1541}
1542
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1544 void __user *newval, size_t newlen)
1545{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001546 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001547 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1550 return -ENOTDIR;
1551 if (oldval) {
1552 int old_len;
1553 if (!oldlenp || get_user(old_len, oldlenp))
1554 return -EFAULT;
1555 }
Al Viro330d57f2005-11-04 10:18:40 +00001556
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001557 for (head = sysctl_head_next(NULL); head;
1558 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001559 error = parse_table(name, nlen, oldval, oldlenp,
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001560 newval, newlen,
1561 head->root, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001562 if (error != -ENOTDIR) {
1563 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001564 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001565 }
1566 }
Al Viro330d57f2005-11-04 10:18:40 +00001567 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568}
1569
1570asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1571{
1572 struct __sysctl_args tmp;
1573 int error;
1574
1575 if (copy_from_user(&tmp, args, sizeof(tmp)))
1576 return -EFAULT;
1577
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001578 error = deprecated_sysctl_warning(&tmp);
1579 if (error)
1580 goto out;
1581
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 lock_kernel();
1583 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1584 tmp.newval, tmp.newlen);
1585 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001586out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 return error;
1588}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001589#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
1591/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001592 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 * some sysctl variables are readonly even to root.
1594 */
1595
1596static int test_perm(int mode, int op)
1597{
1598 if (!current->euid)
1599 mode >>= 6;
1600 else if (in_egroup_p(0))
1601 mode >>= 3;
1602 if ((mode & op & 0007) == op)
1603 return 0;
1604 return -EACCES;
1605}
1606
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001607int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
1609 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001610 int mode;
1611
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 error = security_sysctl(table, op);
1613 if (error)
1614 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001615
1616 if (root->permissions)
1617 mode = root->permissions(root, current->nsproxy, table);
1618 else
1619 mode = table->mode;
1620
1621 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622}
1623
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001624static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1625{
1626 for (; table->ctl_name || table->procname; table++) {
1627 table->parent = parent;
1628 if (table->child)
1629 sysctl_set_parent(table, table->child);
1630 }
1631}
1632
1633static __init int sysctl_init(void)
1634{
1635 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001636#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1637 {
1638 int err;
1639 err = sysctl_check_table(current->nsproxy, root_table);
1640 }
1641#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001642 return 0;
1643}
1644
1645core_initcall(sysctl_init);
1646
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001648 * __register_sysctl_paths - register a sysctl hierarchy
1649 * @root: List of sysctl headers to register on
1650 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001651 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 *
1654 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001655 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001657 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 *
1659 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1660 * must be unique within that level of sysctl
1661 *
1662 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1663 * enter a sysctl file
1664 *
1665 * data - a pointer to data for use by proc_handler
1666 *
1667 * maxlen - the maximum size in bytes of the data
1668 *
1669 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1670 *
1671 * child - a pointer to the child sysctl table if this entry is a directory, or
1672 * %NULL.
1673 *
1674 * proc_handler - the text handler routine (described below)
1675 *
1676 * strategy - the strategy routine (described below)
1677 *
1678 * de - for internal use by the sysctl routines
1679 *
1680 * extra1, extra2 - extra pointers usable by the proc handler routines
1681 *
1682 * Leaf nodes in the sysctl tree will be represented by a single file
1683 * under /proc; non-leaf nodes will be represented by directories.
1684 *
1685 * sysctl(2) can automatically manage read and write requests through
1686 * the sysctl table. The data and maxlen fields of the ctl_table
1687 * struct enable minimal validation of the values being written to be
1688 * performed, and the mode field allows minimal authentication.
1689 *
1690 * More sophisticated management can be enabled by the provision of a
1691 * strategy routine with the table entry. This will be called before
1692 * any automatic read or write of the data is performed.
1693 *
1694 * The strategy routine may return
1695 *
1696 * < 0 - Error occurred (error is passed to user process)
1697 *
1698 * 0 - OK - proceed with automatic read or write.
1699 *
1700 * > 0 - OK - read or write has been done by the strategy routine, so
1701 * return immediately.
1702 *
1703 * There must be a proc_handler routine for any terminal nodes
1704 * mirrored under /proc/sys (non-terminals are handled by a built-in
1705 * directory handler). Several default handlers are available to
1706 * cover common cases -
1707 *
1708 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1709 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1710 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1711 *
1712 * It is the handler's job to read the input buffer from user memory
1713 * and process it. The handler should return 0 on success.
1714 *
1715 * This routine returns %NULL on a failure to register, and a pointer
1716 * to the table header on success.
1717 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001718struct ctl_table_header *__register_sysctl_paths(
1719 struct ctl_table_root *root,
1720 struct nsproxy *namespaces,
1721 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001723 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001724 struct ctl_table_header *header;
1725 struct ctl_table *new, **prevp;
1726 unsigned int n, npath;
1727
1728 /* Count the path components */
1729 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1730 ;
1731
1732 /*
1733 * For each path component, allocate a 2-element ctl_table array.
1734 * The first array element will be filled with the sysctl entry
1735 * for this, the second will be the sentinel (ctl_name == 0).
1736 *
1737 * We allocate everything in one go so that we don't have to
1738 * worry about freeing additional memory in unregister_sysctl_table.
1739 */
1740 header = kzalloc(sizeof(struct ctl_table_header) +
1741 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1742 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001744
1745 new = (struct ctl_table *) (header + 1);
1746
1747 /* Now connect the dots */
1748 prevp = &header->ctl_table;
1749 for (n = 0; n < npath; ++n, ++path) {
1750 /* Copy the procname */
1751 new->procname = path->procname;
1752 new->ctl_name = path->ctl_name;
1753 new->mode = 0555;
1754
1755 *prevp = new;
1756 prevp = &new->child;
1757
1758 new += 2;
1759 }
1760 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001761 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001762
1763 INIT_LIST_HEAD(&header->ctl_entry);
1764 header->used = 0;
1765 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001766 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001767 sysctl_set_parent(NULL, header->ctl_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001768#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001769 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001770 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001771 return NULL;
1772 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001773#endif
Al Viro330d57f2005-11-04 10:18:40 +00001774 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001775 header_list = lookup_header_list(root, namespaces);
1776 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001777 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001778
1779 return header;
1780}
1781
1782/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001783 * register_sysctl_table_path - register a sysctl table hierarchy
1784 * @path: The path to the directory the sysctl table is in.
1785 * @table: the top-level table structure
1786 *
1787 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1788 * array. A completely 0 filled entry terminates the table.
1789 *
1790 * See __register_sysctl_paths for more details.
1791 */
1792struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1793 struct ctl_table *table)
1794{
1795 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1796 path, table);
1797}
1798
1799/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001800 * register_sysctl_table - register a sysctl table hierarchy
1801 * @table: the top-level table structure
1802 *
1803 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1804 * array. A completely 0 filled entry terminates the table.
1805 *
1806 * See register_sysctl_paths for more details.
1807 */
1808struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1809{
1810 static const struct ctl_path null_path[] = { {} };
1811
1812 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813}
1814
1815/**
1816 * unregister_sysctl_table - unregister a sysctl table hierarchy
1817 * @header: the header returned from register_sysctl_table
1818 *
1819 * Unregisters the sysctl table and all children. proc entries may not
1820 * actually be removed until they are no longer used by anyone.
1821 */
1822void unregister_sysctl_table(struct ctl_table_header * header)
1823{
Al Viro330d57f2005-11-04 10:18:40 +00001824 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001825
1826 if (header == NULL)
1827 return;
1828
Al Viro330d57f2005-11-04 10:18:40 +00001829 spin_lock(&sysctl_lock);
1830 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001831 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 kfree(header);
1833}
1834
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001835#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001836struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001837{
1838 return NULL;
1839}
1840
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001841struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1842 struct ctl_table *table)
1843{
1844 return NULL;
1845}
1846
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001847void unregister_sysctl_table(struct ctl_table_header * table)
1848{
1849}
1850
1851#endif /* CONFIG_SYSCTL */
1852
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853/*
1854 * /proc/sys support
1855 */
1856
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001857#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001859static int _proc_do_string(void* data, int maxlen, int write,
1860 struct file *filp, void __user *buffer,
1861 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001862{
1863 size_t len;
1864 char __user *p;
1865 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001866
1867 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001868 *lenp = 0;
1869 return 0;
1870 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001871
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001872 if (write) {
1873 len = 0;
1874 p = buffer;
1875 while (len < *lenp) {
1876 if (get_user(c, p++))
1877 return -EFAULT;
1878 if (c == 0 || c == '\n')
1879 break;
1880 len++;
1881 }
1882 if (len >= maxlen)
1883 len = maxlen-1;
1884 if(copy_from_user(data, buffer, len))
1885 return -EFAULT;
1886 ((char *) data)[len] = 0;
1887 *ppos += *lenp;
1888 } else {
1889 len = strlen(data);
1890 if (len > maxlen)
1891 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001892
1893 if (*ppos > len) {
1894 *lenp = 0;
1895 return 0;
1896 }
1897
1898 data += *ppos;
1899 len -= *ppos;
1900
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001901 if (len > *lenp)
1902 len = *lenp;
1903 if (len)
1904 if(copy_to_user(buffer, data, len))
1905 return -EFAULT;
1906 if (len < *lenp) {
1907 if(put_user('\n', ((char __user *) buffer) + len))
1908 return -EFAULT;
1909 len++;
1910 }
1911 *lenp = len;
1912 *ppos += len;
1913 }
1914 return 0;
1915}
1916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917/**
1918 * proc_dostring - read a string sysctl
1919 * @table: the sysctl table
1920 * @write: %TRUE if this is a write to the sysctl file
1921 * @filp: the file structure
1922 * @buffer: the user buffer
1923 * @lenp: the size of the user buffer
1924 * @ppos: file position
1925 *
1926 * Reads/writes a string from/to the user buffer. If the kernel
1927 * buffer provided is not large enough to hold the string, the
1928 * string is truncated. The copied string is %NULL-terminated.
1929 * If the string is being read by the user process, it is copied
1930 * and a newline '\n' is added. It is truncated if the buffer is
1931 * not large enough.
1932 *
1933 * Returns 0 on success.
1934 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001935int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 void __user *buffer, size_t *lenp, loff_t *ppos)
1937{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001938 return _proc_do_string(table->data, table->maxlen, write, filp,
1939 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940}
1941
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1944 int *valp,
1945 int write, void *data)
1946{
1947 if (write) {
1948 *valp = *negp ? -*lvalp : *lvalp;
1949 } else {
1950 int val = *valp;
1951 if (val < 0) {
1952 *negp = -1;
1953 *lvalp = (unsigned long)-val;
1954 } else {
1955 *negp = 0;
1956 *lvalp = (unsigned long)val;
1957 }
1958 }
1959 return 0;
1960}
1961
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001962static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001963 int write, struct file *filp, void __user *buffer,
1964 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1966 int write, void *data),
1967 void *data)
1968{
1969#define TMPBUFLEN 21
1970 int *i, vleft, first=1, neg, val;
1971 unsigned long lval;
1972 size_t left, len;
1973
1974 char buf[TMPBUFLEN], *p;
1975 char __user *s = buffer;
1976
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001977 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 (*ppos && !write)) {
1979 *lenp = 0;
1980 return 0;
1981 }
1982
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001983 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 vleft = table->maxlen / sizeof(*i);
1985 left = *lenp;
1986
1987 if (!conv)
1988 conv = do_proc_dointvec_conv;
1989
1990 for (; left && vleft--; i++, first=0) {
1991 if (write) {
1992 while (left) {
1993 char c;
1994 if (get_user(c, s))
1995 return -EFAULT;
1996 if (!isspace(c))
1997 break;
1998 left--;
1999 s++;
2000 }
2001 if (!left)
2002 break;
2003 neg = 0;
2004 len = left;
2005 if (len > sizeof(buf) - 1)
2006 len = sizeof(buf) - 1;
2007 if (copy_from_user(buf, s, len))
2008 return -EFAULT;
2009 buf[len] = 0;
2010 p = buf;
2011 if (*p == '-' && left > 1) {
2012 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002013 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 }
2015 if (*p < '0' || *p > '9')
2016 break;
2017
2018 lval = simple_strtoul(p, &p, 0);
2019
2020 len = p-buf;
2021 if ((len < left) && *p && !isspace(*p))
2022 break;
2023 if (neg)
2024 val = -val;
2025 s += len;
2026 left -= len;
2027
2028 if (conv(&neg, &lval, i, 1, data))
2029 break;
2030 } else {
2031 p = buf;
2032 if (!first)
2033 *p++ = '\t';
2034
2035 if (conv(&neg, &lval, i, 0, data))
2036 break;
2037
2038 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2039 len = strlen(buf);
2040 if (len > left)
2041 len = left;
2042 if(copy_to_user(s, buf, len))
2043 return -EFAULT;
2044 left -= len;
2045 s += len;
2046 }
2047 }
2048
2049 if (!write && !first && left) {
2050 if(put_user('\n', s))
2051 return -EFAULT;
2052 left--, s++;
2053 }
2054 if (write) {
2055 while (left) {
2056 char c;
2057 if (get_user(c, s++))
2058 return -EFAULT;
2059 if (!isspace(c))
2060 break;
2061 left--;
2062 }
2063 }
2064 if (write && first)
2065 return -EINVAL;
2066 *lenp -= left;
2067 *ppos += *lenp;
2068 return 0;
2069#undef TMPBUFLEN
2070}
2071
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002072static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002073 void __user *buffer, size_t *lenp, loff_t *ppos,
2074 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2075 int write, void *data),
2076 void *data)
2077{
2078 return __do_proc_dointvec(table->data, table, write, filp,
2079 buffer, lenp, ppos, conv, data);
2080}
2081
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082/**
2083 * proc_dointvec - read a vector of integers
2084 * @table: the sysctl table
2085 * @write: %TRUE if this is a write to the sysctl file
2086 * @filp: the file structure
2087 * @buffer: the user buffer
2088 * @lenp: the size of the user buffer
2089 * @ppos: file position
2090 *
2091 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2092 * values from/to the user buffer, treated as an ASCII string.
2093 *
2094 * Returns 0 on success.
2095 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002096int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 void __user *buffer, size_t *lenp, loff_t *ppos)
2098{
2099 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2100 NULL,NULL);
2101}
2102
2103#define OP_SET 0
2104#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002105#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
2107static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2108 int *valp,
2109 int write, void *data)
2110{
2111 int op = *(int *)data;
2112 if (write) {
2113 int val = *negp ? -*lvalp : *lvalp;
2114 switch(op) {
2115 case OP_SET: *valp = val; break;
2116 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002117 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 }
2119 } else {
2120 int val = *valp;
2121 if (val < 0) {
2122 *negp = -1;
2123 *lvalp = (unsigned long)-val;
2124 } else {
2125 *negp = 0;
2126 *lvalp = (unsigned long)val;
2127 }
2128 }
2129 return 0;
2130}
2131
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002132/*
2133 * Taint values can only be increased
2134 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002135static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002136 void __user *buffer, size_t *lenp, loff_t *ppos)
2137{
2138 int op;
2139
Bastian Blank91fcd412007-04-23 14:41:14 -07002140 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002141 return -EPERM;
2142
2143 op = OP_OR;
2144 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2145 do_proc_dointvec_bset_conv,&op);
2146}
2147
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148struct do_proc_dointvec_minmax_conv_param {
2149 int *min;
2150 int *max;
2151};
2152
2153static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2154 int *valp,
2155 int write, void *data)
2156{
2157 struct do_proc_dointvec_minmax_conv_param *param = data;
2158 if (write) {
2159 int val = *negp ? -*lvalp : *lvalp;
2160 if ((param->min && *param->min > val) ||
2161 (param->max && *param->max < val))
2162 return -EINVAL;
2163 *valp = val;
2164 } else {
2165 int val = *valp;
2166 if (val < 0) {
2167 *negp = -1;
2168 *lvalp = (unsigned long)-val;
2169 } else {
2170 *negp = 0;
2171 *lvalp = (unsigned long)val;
2172 }
2173 }
2174 return 0;
2175}
2176
2177/**
2178 * proc_dointvec_minmax - read a vector of integers with min/max values
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @filp: the file structure
2182 * @buffer: the user buffer
2183 * @lenp: the size of the user buffer
2184 * @ppos: file position
2185 *
2186 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2187 * values from/to the user buffer, treated as an ASCII string.
2188 *
2189 * This routine will ensure the values are within the range specified by
2190 * table->extra1 (min) and table->extra2 (max).
2191 *
2192 * Returns 0 on success.
2193 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002194int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 void __user *buffer, size_t *lenp, loff_t *ppos)
2196{
2197 struct do_proc_dointvec_minmax_conv_param param = {
2198 .min = (int *) table->extra1,
2199 .max = (int *) table->extra2,
2200 };
2201 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2202 do_proc_dointvec_minmax_conv, &param);
2203}
2204
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002205static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 struct file *filp,
2207 void __user *buffer,
2208 size_t *lenp, loff_t *ppos,
2209 unsigned long convmul,
2210 unsigned long convdiv)
2211{
2212#define TMPBUFLEN 21
2213 unsigned long *i, *min, *max, val;
2214 int vleft, first=1, neg;
2215 size_t len, left;
2216 char buf[TMPBUFLEN], *p;
2217 char __user *s = buffer;
2218
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002219 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 (*ppos && !write)) {
2221 *lenp = 0;
2222 return 0;
2223 }
2224
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002225 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 min = (unsigned long *) table->extra1;
2227 max = (unsigned long *) table->extra2;
2228 vleft = table->maxlen / sizeof(unsigned long);
2229 left = *lenp;
2230
2231 for (; left && vleft--; i++, min++, max++, first=0) {
2232 if (write) {
2233 while (left) {
2234 char c;
2235 if (get_user(c, s))
2236 return -EFAULT;
2237 if (!isspace(c))
2238 break;
2239 left--;
2240 s++;
2241 }
2242 if (!left)
2243 break;
2244 neg = 0;
2245 len = left;
2246 if (len > TMPBUFLEN-1)
2247 len = TMPBUFLEN-1;
2248 if (copy_from_user(buf, s, len))
2249 return -EFAULT;
2250 buf[len] = 0;
2251 p = buf;
2252 if (*p == '-' && left > 1) {
2253 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002254 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 }
2256 if (*p < '0' || *p > '9')
2257 break;
2258 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2259 len = p-buf;
2260 if ((len < left) && *p && !isspace(*p))
2261 break;
2262 if (neg)
2263 val = -val;
2264 s += len;
2265 left -= len;
2266
2267 if(neg)
2268 continue;
2269 if ((min && val < *min) || (max && val > *max))
2270 continue;
2271 *i = val;
2272 } else {
2273 p = buf;
2274 if (!first)
2275 *p++ = '\t';
2276 sprintf(p, "%lu", convdiv * (*i) / convmul);
2277 len = strlen(buf);
2278 if (len > left)
2279 len = left;
2280 if(copy_to_user(s, buf, len))
2281 return -EFAULT;
2282 left -= len;
2283 s += len;
2284 }
2285 }
2286
2287 if (!write && !first && left) {
2288 if(put_user('\n', s))
2289 return -EFAULT;
2290 left--, s++;
2291 }
2292 if (write) {
2293 while (left) {
2294 char c;
2295 if (get_user(c, s++))
2296 return -EFAULT;
2297 if (!isspace(c))
2298 break;
2299 left--;
2300 }
2301 }
2302 if (write && first)
2303 return -EINVAL;
2304 *lenp -= left;
2305 *ppos += *lenp;
2306 return 0;
2307#undef TMPBUFLEN
2308}
2309
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002310static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002311 struct file *filp,
2312 void __user *buffer,
2313 size_t *lenp, loff_t *ppos,
2314 unsigned long convmul,
2315 unsigned long convdiv)
2316{
2317 return __do_proc_doulongvec_minmax(table->data, table, write,
2318 filp, buffer, lenp, ppos, convmul, convdiv);
2319}
2320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321/**
2322 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2323 * @table: the sysctl table
2324 * @write: %TRUE if this is a write to the sysctl file
2325 * @filp: the file structure
2326 * @buffer: the user buffer
2327 * @lenp: the size of the user buffer
2328 * @ppos: file position
2329 *
2330 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2331 * values from/to the user buffer, treated as an ASCII string.
2332 *
2333 * This routine will ensure the values are within the range specified by
2334 * table->extra1 (min) and table->extra2 (max).
2335 *
2336 * Returns 0 on success.
2337 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002338int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 void __user *buffer, size_t *lenp, loff_t *ppos)
2340{
2341 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2342}
2343
2344/**
2345 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2346 * @table: the sysctl table
2347 * @write: %TRUE if this is a write to the sysctl file
2348 * @filp: the file structure
2349 * @buffer: the user buffer
2350 * @lenp: the size of the user buffer
2351 * @ppos: file position
2352 *
2353 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2354 * values from/to the user buffer, treated as an ASCII string. The values
2355 * are treated as milliseconds, and converted to jiffies when they are stored.
2356 *
2357 * This routine will ensure the values are within the range specified by
2358 * table->extra1 (min) and table->extra2 (max).
2359 *
2360 * Returns 0 on success.
2361 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002362int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 struct file *filp,
2364 void __user *buffer,
2365 size_t *lenp, loff_t *ppos)
2366{
2367 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2368 lenp, ppos, HZ, 1000l);
2369}
2370
2371
2372static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2373 int *valp,
2374 int write, void *data)
2375{
2376 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002377 if (*lvalp > LONG_MAX / HZ)
2378 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2380 } else {
2381 int val = *valp;
2382 unsigned long lval;
2383 if (val < 0) {
2384 *negp = -1;
2385 lval = (unsigned long)-val;
2386 } else {
2387 *negp = 0;
2388 lval = (unsigned long)val;
2389 }
2390 *lvalp = lval / HZ;
2391 }
2392 return 0;
2393}
2394
2395static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2396 int *valp,
2397 int write, void *data)
2398{
2399 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002400 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2401 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2403 } else {
2404 int val = *valp;
2405 unsigned long lval;
2406 if (val < 0) {
2407 *negp = -1;
2408 lval = (unsigned long)-val;
2409 } else {
2410 *negp = 0;
2411 lval = (unsigned long)val;
2412 }
2413 *lvalp = jiffies_to_clock_t(lval);
2414 }
2415 return 0;
2416}
2417
2418static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2419 int *valp,
2420 int write, void *data)
2421{
2422 if (write) {
2423 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2424 } else {
2425 int val = *valp;
2426 unsigned long lval;
2427 if (val < 0) {
2428 *negp = -1;
2429 lval = (unsigned long)-val;
2430 } else {
2431 *negp = 0;
2432 lval = (unsigned long)val;
2433 }
2434 *lvalp = jiffies_to_msecs(lval);
2435 }
2436 return 0;
2437}
2438
2439/**
2440 * proc_dointvec_jiffies - read a vector of integers as seconds
2441 * @table: the sysctl table
2442 * @write: %TRUE if this is a write to the sysctl file
2443 * @filp: the file structure
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2447 *
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2449 * values from/to the user buffer, treated as an ASCII string.
2450 * The values read are assumed to be in seconds, and are converted into
2451 * jiffies.
2452 *
2453 * Returns 0 on success.
2454 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002455int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 void __user *buffer, size_t *lenp, loff_t *ppos)
2457{
2458 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2459 do_proc_dointvec_jiffies_conv,NULL);
2460}
2461
2462/**
2463 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2464 * @table: the sysctl table
2465 * @write: %TRUE if this is a write to the sysctl file
2466 * @filp: the file structure
2467 * @buffer: the user buffer
2468 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002469 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 *
2471 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2472 * values from/to the user buffer, treated as an ASCII string.
2473 * The values read are assumed to be in 1/USER_HZ seconds, and
2474 * are converted into jiffies.
2475 *
2476 * Returns 0 on success.
2477 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002478int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 void __user *buffer, size_t *lenp, loff_t *ppos)
2480{
2481 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2482 do_proc_dointvec_userhz_jiffies_conv,NULL);
2483}
2484
2485/**
2486 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2487 * @table: the sysctl table
2488 * @write: %TRUE if this is a write to the sysctl file
2489 * @filp: the file structure
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002492 * @ppos: file position
2493 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 *
2495 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2496 * values from/to the user buffer, treated as an ASCII string.
2497 * The values read are assumed to be in 1/1000 seconds, and
2498 * are converted into jiffies.
2499 *
2500 * Returns 0 on success.
2501 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002502int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 void __user *buffer, size_t *lenp, loff_t *ppos)
2504{
2505 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2506 do_proc_dointvec_ms_jiffies_conv, NULL);
2507}
2508
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002509static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002510 void __user *buffer, size_t *lenp, loff_t *ppos)
2511{
2512 struct pid *new_pid;
2513 pid_t tmp;
2514 int r;
2515
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002516 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002517
2518 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2519 lenp, ppos, NULL, NULL);
2520 if (r || !write)
2521 return r;
2522
2523 new_pid = find_get_pid(tmp);
2524 if (!new_pid)
2525 return -ESRCH;
2526
2527 put_pid(xchg(&cad_pid, new_pid));
2528 return 0;
2529}
2530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531#else /* CONFIG_PROC_FS */
2532
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002533int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 void __user *buffer, size_t *lenp, loff_t *ppos)
2535{
2536 return -ENOSYS;
2537}
2538
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002539int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 void __user *buffer, size_t *lenp, loff_t *ppos)
2541{
2542 return -ENOSYS;
2543}
2544
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002545int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 void __user *buffer, size_t *lenp, loff_t *ppos)
2547{
2548 return -ENOSYS;
2549}
2550
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002551int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 void __user *buffer, size_t *lenp, loff_t *ppos)
2553{
2554 return -ENOSYS;
2555}
2556
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002557int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 void __user *buffer, size_t *lenp, loff_t *ppos)
2559{
2560 return -ENOSYS;
2561}
2562
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002563int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 void __user *buffer, size_t *lenp, loff_t *ppos)
2565{
2566 return -ENOSYS;
2567}
2568
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002569int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 void __user *buffer, size_t *lenp, loff_t *ppos)
2571{
2572 return -ENOSYS;
2573}
2574
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002575int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct file *filp,
2577 void __user *buffer,
2578 size_t *lenp, loff_t *ppos)
2579{
2580 return -ENOSYS;
2581}
2582
2583
2584#endif /* CONFIG_PROC_FS */
2585
2586
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002587#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588/*
2589 * General sysctl support routines
2590 */
2591
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002592/* The generic sysctl data routine (used if no strategy routine supplied) */
2593int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2594 void __user *oldval, size_t __user *oldlenp,
2595 void __user *newval, size_t newlen)
2596{
2597 size_t len;
2598
2599 /* Get out of I don't have a variable */
2600 if (!table->data || !table->maxlen)
2601 return -ENOTDIR;
2602
2603 if (oldval && oldlenp) {
2604 if (get_user(len, oldlenp))
2605 return -EFAULT;
2606 if (len) {
2607 if (len > table->maxlen)
2608 len = table->maxlen;
2609 if (copy_to_user(oldval, table->data, len))
2610 return -EFAULT;
2611 if (put_user(len, oldlenp))
2612 return -EFAULT;
2613 }
2614 }
2615
2616 if (newval && newlen) {
2617 if (newlen > table->maxlen)
2618 newlen = table->maxlen;
2619
2620 if (copy_from_user(table->data, newval, newlen))
2621 return -EFAULT;
2622 }
2623 return 1;
2624}
2625
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002627int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002629 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 if (!table->data || !table->maxlen)
2632 return -ENOTDIR;
2633
2634 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002635 size_t bufsize;
2636 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002638 if (bufsize) {
2639 size_t len = strlen(table->data), copied;
2640
2641 /* This shouldn't trigger for a well-formed sysctl */
2642 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002644
2645 /* Copy up to a max of bufsize-1 bytes of the string */
2646 copied = (len >= bufsize) ? bufsize - 1 : len;
2647
2648 if (copy_to_user(oldval, table->data, copied) ||
2649 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002651 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 return -EFAULT;
2653 }
2654 }
2655 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002656 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 if (len > table->maxlen)
2658 len = table->maxlen;
2659 if(copy_from_user(table->data, newval, len))
2660 return -EFAULT;
2661 if (len == table->maxlen)
2662 len--;
2663 ((char *) table->data)[len] = 0;
2664 }
Yi Yang82c9df82005-12-30 16:37:10 +08002665 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666}
2667
2668/*
2669 * This function makes sure that all of the integers in the vector
2670 * are between the minimum and maximum values given in the arrays
2671 * table->extra1 and table->extra2, respectively.
2672 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002673int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002675 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676{
2677
2678 if (newval && newlen) {
2679 int __user *vec = (int __user *) newval;
2680 int *min = (int *) table->extra1;
2681 int *max = (int *) table->extra2;
2682 size_t length;
2683 int i;
2684
2685 if (newlen % sizeof(int) != 0)
2686 return -EINVAL;
2687
2688 if (!table->extra1 && !table->extra2)
2689 return 0;
2690
2691 if (newlen > table->maxlen)
2692 newlen = table->maxlen;
2693 length = newlen / sizeof(int);
2694
2695 for (i = 0; i < length; i++) {
2696 int value;
2697 if (get_user(value, vec + i))
2698 return -EFAULT;
2699 if (min && value < min[i])
2700 return -EINVAL;
2701 if (max && value > max[i])
2702 return -EINVAL;
2703 }
2704 }
2705 return 0;
2706}
2707
2708/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002709int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002711 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002713 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002715
2716 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002718 if (olen) {
2719 int val;
2720
2721 if (olen < sizeof(int))
2722 return -EINVAL;
2723
2724 val = *(int *)(table->data) / HZ;
2725 if (put_user(val, (int __user *)oldval))
2726 return -EFAULT;
2727 if (put_user(sizeof(int), oldlenp))
2728 return -EFAULT;
2729 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 }
2731 if (newval && newlen) {
2732 int new;
2733 if (newlen != sizeof(int))
2734 return -EINVAL;
2735 if (get_user(new, (int __user *)newval))
2736 return -EFAULT;
2737 *(int *)(table->data) = new*HZ;
2738 }
2739 return 1;
2740}
2741
2742/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002743int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002745 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002747 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002749
2750 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002752 if (olen) {
2753 int val;
2754
2755 if (olen < sizeof(int))
2756 return -EINVAL;
2757
2758 val = jiffies_to_msecs(*(int *)(table->data));
2759 if (put_user(val, (int __user *)oldval))
2760 return -EFAULT;
2761 if (put_user(sizeof(int), oldlenp))
2762 return -EFAULT;
2763 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 }
2765 if (newval && newlen) {
2766 int new;
2767 if (newlen != sizeof(int))
2768 return -EINVAL;
2769 if (get_user(new, (int __user *)newval))
2770 return -EFAULT;
2771 *(int *)(table->data) = msecs_to_jiffies(new);
2772 }
2773 return 1;
2774}
2775
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002776
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002777
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002778#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779
2780
2781asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2782{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002783 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002784 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002785
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002786 if (copy_from_user(&tmp, args, sizeof(tmp)))
2787 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002788
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002789 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002790
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002791 /* If no error reading the parameters then just -ENOSYS ... */
2792 if (!error)
2793 error = -ENOSYS;
2794
2795 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796}
2797
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002798int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2799 void __user *oldval, size_t __user *oldlenp,
2800 void __user *newval, size_t newlen)
2801{
2802 return -ENOSYS;
2803}
2804
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002805int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002807 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808{
2809 return -ENOSYS;
2810}
2811
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002812int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002814 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815{
2816 return -ENOSYS;
2817}
2818
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002819int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002821 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822{
2823 return -ENOSYS;
2824}
2825
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002826int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002828 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829{
2830 return -ENOSYS;
2831}
2832
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002833#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002835static int deprecated_sysctl_warning(struct __sysctl_args *args)
2836{
2837 static int msg_count;
2838 int name[CTL_MAXNAME];
2839 int i;
2840
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002841 /* Check args->nlen. */
2842 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2843 return -ENOTDIR;
2844
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002845 /* Read in the sysctl name for better debug message logging */
2846 for (i = 0; i < args->nlen; i++)
2847 if (get_user(name[i], args->name + i))
2848 return -EFAULT;
2849
2850 /* Ignore accesses to kernel.version */
2851 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2852 return 0;
2853
2854 if (msg_count < 5) {
2855 msg_count++;
2856 printk(KERN_INFO
2857 "warning: process `%s' used the deprecated sysctl "
2858 "system call with ", current->comm);
2859 for (i = 0; i < args->nlen; i++)
2860 printk("%d.", name[i]);
2861 printk("\n");
2862 }
2863 return 0;
2864}
2865
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866/*
2867 * No sense putting this after each symbol definition, twice,
2868 * exception granted :-)
2869 */
2870EXPORT_SYMBOL(proc_dointvec);
2871EXPORT_SYMBOL(proc_dointvec_jiffies);
2872EXPORT_SYMBOL(proc_dointvec_minmax);
2873EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2874EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2875EXPORT_SYMBOL(proc_dostring);
2876EXPORT_SYMBOL(proc_doulongvec_minmax);
2877EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2878EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002879EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880EXPORT_SYMBOL(sysctl_intvec);
2881EXPORT_SYMBOL(sysctl_jiffies);
2882EXPORT_SYMBOL(sysctl_ms_jiffies);
2883EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002884EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885EXPORT_SYMBOL(unregister_sysctl_table);