blob: 1cdfe942d16025a5af6037c61a82ee093e1a4b3e [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>
Pavel Machekc255d842006-02-20 18:27:58 -080046#include <linux/nfs_fs.h>
47#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
Andi Kleen29cbc782006-09-30 01:47:55 +020053#ifdef CONFIG_X86
54#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010055#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010056#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020057#endif
58
Eric W. Biederman7058cb02007-10-18 03:05:58 -070059static int deprecated_sysctl_warning(struct __sysctl_args *args);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#if defined(CONFIG_SYSCTL)
62
63/* External variables not in a header file. */
64extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070065extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern int sysctl_overcommit_memory;
67extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070068extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070069extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080070extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070073extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern int pid_max;
76extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080078extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080079extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020080extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070081extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070082extern int sysctl_stat_interval;
Arjan van de Ven97455122008-01-25 21:08:34 +010083extern int latencytop_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070085/* Constants used for minimum and maximum */
Bron Gondwana195cf452008-02-04 22:29:20 -080086#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070087static int one = 1;
Bron Gondwana195cf452008-02-04 22:29:20 -080088#endif
89
90#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070091static int sixty = 60;
92#endif
93
94#ifdef CONFIG_MMU
95static int two = 2;
96#endif
97
98static int zero;
99static int one_hundred = 100;
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
102static int maxolduid = 65535;
103static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800104static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106static int ngroups_max = NGROUPS_MAX;
107
108#ifdef CONFIG_KMOD
109extern char modprobe_path[];
110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#ifdef CONFIG_CHR_DEV_SG
112extern int sg_big_buff;
113#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115#ifdef __sparc__
116extern char reboot_command [];
117extern int stop_a_enabled;
118extern int scons_pwroff;
119#endif
120
121#ifdef __hppa__
122extern int pwrsw_enabled;
123extern int unaligned_enabled;
124#endif
125
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800126#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#ifdef CONFIG_MATHEMU
128extern int sysctl_ieee_emulation_warnings;
129#endif
130extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700131extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#endif
133
134extern int sysctl_hz_timer;
135
136#ifdef CONFIG_BSD_PROCESS_ACCT
137extern int acct_parm[];
138#endif
139
Jes Sorensend2b176e2006-02-28 09:42:23 -0800140#ifdef CONFIG_IA64
141extern int no_unaligned_warning;
142#endif
143
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700144#ifdef CONFIG_RT_MUTEXES
145extern int max_lock_depth;
146#endif
147
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700148#ifdef CONFIG_SYSCTL_SYSCALL
149static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700150 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700151#endif
152
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800153
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700154#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700156 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700157static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800158 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700159#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700160
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700161static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100162static struct ctl_table_root sysctl_table_root;
163static struct ctl_table_header root_table_header = {
164 .ctl_table = root_table,
165 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
166 .root = &sysctl_table_root,
167};
168static struct ctl_table_root sysctl_table_root = {
169 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
170 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
171};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700173static struct ctl_table kern_table[];
174static struct ctl_table vm_table[];
175static struct ctl_table fs_table[];
176static struct ctl_table debug_table[];
177static struct ctl_table dev_table[];
178extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700179#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700180extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400181#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
184int sysctl_legacy_va_layout;
185#endif
186
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700187extern int prove_locking;
188extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/* The default sysctl tables: */
191
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700192static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 {
194 .ctl_name = CTL_KERN,
195 .procname = "kernel",
196 .mode = 0555,
197 .child = kern_table,
198 },
199 {
200 .ctl_name = CTL_VM,
201 .procname = "vm",
202 .mode = 0555,
203 .child = vm_table,
204 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 .ctl_name = CTL_FS,
207 .procname = "fs",
208 .mode = 0555,
209 .child = fs_table,
210 },
211 {
212 .ctl_name = CTL_DEBUG,
213 .procname = "debug",
214 .mode = 0555,
215 .child = debug_table,
216 },
217 {
218 .ctl_name = CTL_DEV,
219 .procname = "dev",
220 .mode = 0555,
221 .child = dev_table,
222 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700223/*
224 * NOTE: do not add new entries to this table unless you have read
225 * Documentation/sysctl/ctl_unnumbered.txt
226 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 { .ctl_name = 0 }
228};
229
Ingo Molnar77e54a12007-07-09 18:52:00 +0200230#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100231static int min_sched_granularity_ns = 100000; /* 100 usecs */
232static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
233static int min_wakeup_granularity_ns; /* 0 usecs */
234static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200235#endif
236
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700237static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200238#ifdef CONFIG_SCHED_DEBUG
239 {
240 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100241 .procname = "sched_min_granularity_ns",
242 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200243 .maxlen = sizeof(unsigned int),
244 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100245 .proc_handler = &sched_nr_latency_handler,
246 .strategy = &sysctl_intvec,
247 .extra1 = &min_sched_granularity_ns,
248 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249 },
250 {
251 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200252 .procname = "sched_latency_ns",
253 .data = &sysctl_sched_latency,
254 .maxlen = sizeof(unsigned int),
255 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100256 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200257 .strategy = &sysctl_intvec,
258 .extra1 = &min_sched_granularity_ns,
259 .extra2 = &max_sched_granularity_ns,
260 },
261 {
262 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200263 .procname = "sched_wakeup_granularity_ns",
264 .data = &sysctl_sched_wakeup_granularity,
265 .maxlen = sizeof(unsigned int),
266 .mode = 0644,
267 .proc_handler = &proc_dointvec_minmax,
268 .strategy = &sysctl_intvec,
269 .extra1 = &min_wakeup_granularity_ns,
270 .extra2 = &max_wakeup_granularity_ns,
271 },
272 {
273 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200274 .procname = "sched_child_runs_first",
275 .data = &sysctl_sched_child_runs_first,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
278 .proc_handler = &proc_dointvec,
279 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200280 {
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_features",
283 .data = &sysctl_sched_features,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
287 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200288 {
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_migration_cost",
291 .data = &sysctl_sched_migration_cost,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec,
295 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100296 {
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_nr_migrate",
299 .data = &sysctl_sched_nr_migrate,
300 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100301 .mode = 0644,
302 .proc_handler = &proc_dointvec,
303 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200304#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200305 {
306 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100307 .procname = "sched_rt_period_us",
308 .data = &sysctl_sched_rt_period,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200311 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100312 },
313 {
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_rt_runtime_us",
316 .data = &sysctl_sched_rt_runtime,
317 .maxlen = sizeof(int),
318 .mode = 0644,
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200319 .proc_handler = &sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100320 },
321 {
322 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar1799e352007-09-19 23:34:46 +0200323 .procname = "sched_compat_yield",
324 .data = &sysctl_sched_compat_yield,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
328 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700329#ifdef CONFIG_PROVE_LOCKING
330 {
331 .ctl_name = CTL_UNNUMBERED,
332 .procname = "prove_locking",
333 .data = &prove_locking,
334 .maxlen = sizeof(int),
335 .mode = 0644,
336 .proc_handler = &proc_dointvec,
337 },
338#endif
339#ifdef CONFIG_LOCK_STAT
340 {
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "lock_stat",
343 .data = &lock_stat,
344 .maxlen = sizeof(int),
345 .mode = 0644,
346 .proc_handler = &proc_dointvec,
347 },
348#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200349 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 .ctl_name = KERN_PANIC,
351 .procname = "panic",
352 .data = &panic_timeout,
353 .maxlen = sizeof(int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec,
356 },
357 {
358 .ctl_name = KERN_CORE_USES_PID,
359 .procname = "core_uses_pid",
360 .data = &core_uses_pid,
361 .maxlen = sizeof(int),
362 .mode = 0644,
363 .proc_handler = &proc_dointvec,
364 },
365 {
366 .ctl_name = KERN_CORE_PATTERN,
367 .procname = "core_pattern",
368 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700369 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 .mode = 0644,
371 .proc_handler = &proc_dostring,
372 .strategy = &sysctl_string,
373 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800374#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 .procname = "tainted",
377 .data = &tainted,
378 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800379 .mode = 0644,
380 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800382#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100383#ifdef CONFIG_LATENCYTOP
384 {
385 .procname = "latencytop",
386 .data = &latencytop_enabled,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
391#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392#ifdef CONFIG_BLK_DEV_INITRD
393 {
394 .ctl_name = KERN_REALROOTDEV,
395 .procname = "real-root-dev",
396 .data = &real_root_dev,
397 .maxlen = sizeof(int),
398 .mode = 0644,
399 .proc_handler = &proc_dointvec,
400 },
401#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700402 {
403 .ctl_name = CTL_UNNUMBERED,
404 .procname = "print-fatal-signals",
405 .data = &print_fatal_signals,
406 .maxlen = sizeof(int),
407 .mode = 0644,
408 .proc_handler = &proc_dointvec,
409 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410#ifdef __sparc__
411 {
412 .ctl_name = KERN_SPARC_REBOOT,
413 .procname = "reboot-cmd",
414 .data = reboot_command,
415 .maxlen = 256,
416 .mode = 0644,
417 .proc_handler = &proc_dostring,
418 .strategy = &sysctl_string,
419 },
420 {
421 .ctl_name = KERN_SPARC_STOP_A,
422 .procname = "stop-a",
423 .data = &stop_a_enabled,
424 .maxlen = sizeof (int),
425 .mode = 0644,
426 .proc_handler = &proc_dointvec,
427 },
428 {
429 .ctl_name = KERN_SPARC_SCONS_PWROFF,
430 .procname = "scons-poweroff",
431 .data = &scons_pwroff,
432 .maxlen = sizeof (int),
433 .mode = 0644,
434 .proc_handler = &proc_dointvec,
435 },
436#endif
437#ifdef __hppa__
438 {
439 .ctl_name = KERN_HPPA_PWRSW,
440 .procname = "soft-power",
441 .data = &pwrsw_enabled,
442 .maxlen = sizeof (int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
445 },
446 {
447 .ctl_name = KERN_HPPA_UNALIGNED,
448 .procname = "unaligned-trap",
449 .data = &unaligned_enabled,
450 .maxlen = sizeof (int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
453 },
454#endif
455 {
456 .ctl_name = KERN_CTLALTDEL,
457 .procname = "ctrl-alt-del",
458 .data = &C_A_D,
459 .maxlen = sizeof(int),
460 .mode = 0644,
461 .proc_handler = &proc_dointvec,
462 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#ifdef CONFIG_KMOD
464 {
465 .ctl_name = KERN_MODPROBE,
466 .procname = "modprobe",
467 .data = &modprobe_path,
468 .maxlen = KMOD_PATH_LEN,
469 .mode = 0644,
470 .proc_handler = &proc_dostring,
471 .strategy = &sysctl_string,
472 },
473#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700474#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 {
476 .ctl_name = KERN_HOTPLUG,
477 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100478 .data = &uevent_helper,
479 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .mode = 0644,
481 .proc_handler = &proc_dostring,
482 .strategy = &sysctl_string,
483 },
484#endif
485#ifdef CONFIG_CHR_DEV_SG
486 {
487 .ctl_name = KERN_SG_BIG_BUFF,
488 .procname = "sg-big-buff",
489 .data = &sg_big_buff,
490 .maxlen = sizeof (int),
491 .mode = 0444,
492 .proc_handler = &proc_dointvec,
493 },
494#endif
495#ifdef CONFIG_BSD_PROCESS_ACCT
496 {
497 .ctl_name = KERN_ACCT,
498 .procname = "acct",
499 .data = &acct_parm,
500 .maxlen = 3*sizeof(int),
501 .mode = 0644,
502 .proc_handler = &proc_dointvec,
503 },
504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#ifdef CONFIG_MAGIC_SYSRQ
506 {
507 .ctl_name = KERN_SYSRQ,
508 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800509 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 .maxlen = sizeof (int),
511 .mode = 0644,
512 .proc_handler = &proc_dointvec,
513 },
514#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700515#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700518 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 .maxlen = sizeof (int),
520 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700521 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700523#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 {
525 .ctl_name = KERN_MAX_THREADS,
526 .procname = "threads-max",
527 .data = &max_threads,
528 .maxlen = sizeof(int),
529 .mode = 0644,
530 .proc_handler = &proc_dointvec,
531 },
532 {
533 .ctl_name = KERN_RANDOM,
534 .procname = "random",
535 .mode = 0555,
536 .child = random_table,
537 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
539 .ctl_name = KERN_OVERFLOWUID,
540 .procname = "overflowuid",
541 .data = &overflowuid,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 .proc_handler = &proc_dointvec_minmax,
545 .strategy = &sysctl_intvec,
546 .extra1 = &minolduid,
547 .extra2 = &maxolduid,
548 },
549 {
550 .ctl_name = KERN_OVERFLOWGID,
551 .procname = "overflowgid",
552 .data = &overflowgid,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 .proc_handler = &proc_dointvec_minmax,
556 .strategy = &sysctl_intvec,
557 .extra1 = &minolduid,
558 .extra2 = &maxolduid,
559 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800560#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#ifdef CONFIG_MATHEMU
562 {
563 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
564 .procname = "ieee_emulation_warnings",
565 .data = &sysctl_ieee_emulation_warnings,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec,
569 },
570#endif
571#ifdef CONFIG_NO_IDLE_HZ
572 {
573 .ctl_name = KERN_HZ_TIMER,
574 .procname = "hz_timer",
575 .data = &sysctl_hz_timer,
576 .maxlen = sizeof(int),
577 .mode = 0644,
578 .proc_handler = &proc_dointvec,
579 },
580#endif
581 {
582 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
583 .procname = "userprocess_debug",
584 .data = &sysctl_userprocess_debug,
585 .maxlen = sizeof(int),
586 .mode = 0644,
587 .proc_handler = &proc_dointvec,
588 },
589#endif
590 {
591 .ctl_name = KERN_PIDMAX,
592 .procname = "pid_max",
593 .data = &pid_max,
594 .maxlen = sizeof (int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec_minmax,
597 .strategy = sysctl_intvec,
598 .extra1 = &pid_max_min,
599 .extra2 = &pid_max_max,
600 },
601 {
602 .ctl_name = KERN_PANIC_ON_OOPS,
603 .procname = "panic_on_oops",
604 .data = &panic_on_oops,
605 .maxlen = sizeof(int),
606 .mode = 0644,
607 .proc_handler = &proc_dointvec,
608 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800609#if defined CONFIG_PRINTK
610 {
611 .ctl_name = KERN_PRINTK,
612 .procname = "printk",
613 .data = &console_loglevel,
614 .maxlen = 4*sizeof(int),
615 .mode = 0644,
616 .proc_handler = &proc_dointvec,
617 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 {
619 .ctl_name = KERN_PRINTK_RATELIMIT,
620 .procname = "printk_ratelimit",
621 .data = &printk_ratelimit_jiffies,
622 .maxlen = sizeof(int),
623 .mode = 0644,
624 .proc_handler = &proc_dointvec_jiffies,
625 .strategy = &sysctl_jiffies,
626 },
627 {
628 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
629 .procname = "printk_ratelimit_burst",
630 .data = &printk_ratelimit_burst,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
634 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800635#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 {
637 .ctl_name = KERN_NGROUPS_MAX,
638 .procname = "ngroups_max",
639 .data = &ngroups_max,
640 .maxlen = sizeof (int),
641 .mode = 0444,
642 .proc_handler = &proc_dointvec,
643 },
644#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
645 {
646 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
647 .procname = "unknown_nmi_panic",
648 .data = &unknown_nmi_panic,
649 .maxlen = sizeof (int),
650 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200651 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 },
Don Zickus407984f2006-09-26 10:52:27 +0200653 {
Don Zickus407984f2006-09-26 10:52:27 +0200654 .procname = "nmi_watchdog",
655 .data = &nmi_watchdog_enabled,
656 .maxlen = sizeof (int),
657 .mode = 0644,
658 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 },
660#endif
661#if defined(CONFIG_X86)
662 {
Don Zickus8da5add2006-09-26 10:52:27 +0200663 .ctl_name = KERN_PANIC_ON_NMI,
664 .procname = "panic_on_unrecovered_nmi",
665 .data = &panic_on_unrecovered_nmi,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = &proc_dointvec,
669 },
670 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 .ctl_name = KERN_BOOTLOADER_TYPE,
672 .procname = "bootloader_type",
673 .data = &bootloader_type,
674 .maxlen = sizeof (int),
675 .mode = 0444,
676 .proc_handler = &proc_dointvec,
677 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100678 {
679 .ctl_name = CTL_UNNUMBERED,
680 .procname = "kstack_depth_to_print",
681 .data = &kstack_depth_to_print,
682 .maxlen = sizeof(int),
683 .mode = 0644,
684 .proc_handler = &proc_dointvec,
685 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100686 {
687 .ctl_name = CTL_UNNUMBERED,
688 .procname = "io_delay_type",
689 .data = &io_delay_type,
690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = &proc_dointvec,
693 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800695#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 {
697 .ctl_name = KERN_RANDOMIZE,
698 .procname = "randomize_va_space",
699 .data = &randomize_va_space,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 .proc_handler = &proc_dointvec,
703 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800704#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800705#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700706 {
707 .ctl_name = KERN_SPIN_RETRY,
708 .procname = "spin_retry",
709 .data = &spin_retry,
710 .maxlen = sizeof (int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
714#endif
Len Brown673d5b42007-07-28 03:33:16 -0400715#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800716 {
Pavel Machekc255d842006-02-20 18:27:58 -0800717 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700718 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800719 .maxlen = sizeof (unsigned long),
720 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800721 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800722 },
723#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800724#ifdef CONFIG_IA64
725 {
726 .ctl_name = KERN_IA64_UNALIGNED,
727 .procname = "ignore-unaligned-usertrap",
728 .data = &no_unaligned_warning,
729 .maxlen = sizeof (int),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
732 },
733#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700734#ifdef CONFIG_DETECT_SOFTLOCKUP
735 {
736 .ctl_name = CTL_UNNUMBERED,
737 .procname = "softlockup_thresh",
738 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100739 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700740 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100741 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700742 .strategy = &sysctl_intvec,
743 .extra1 = &one,
744 .extra2 = &sixty,
745 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100746 {
747 .ctl_name = CTL_UNNUMBERED,
748 .procname = "hung_task_check_count",
749 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100750 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100751 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100752 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100753 .strategy = &sysctl_intvec,
754 },
755 {
756 .ctl_name = CTL_UNNUMBERED,
757 .procname = "hung_task_timeout_secs",
758 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100759 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100760 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100761 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100762 .strategy = &sysctl_intvec,
763 },
764 {
765 .ctl_name = CTL_UNNUMBERED,
766 .procname = "hung_task_warnings",
767 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100768 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100769 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100770 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100771 .strategy = &sysctl_intvec,
772 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700773#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200774#ifdef CONFIG_COMPAT
775 {
776 .ctl_name = KERN_COMPAT_LOG,
777 .procname = "compat-log",
778 .data = &compat_log,
779 .maxlen = sizeof (int),
780 .mode = 0644,
781 .proc_handler = &proc_dointvec,
782 },
783#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700784#ifdef CONFIG_RT_MUTEXES
785 {
786 .ctl_name = KERN_MAX_LOCK_DEPTH,
787 .procname = "max_lock_depth",
788 .data = &max_lock_depth,
789 .maxlen = sizeof(int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
792 },
793#endif
Kees Cook5096add2007-05-08 00:26:04 -0700794#ifdef CONFIG_PROC_FS
795 {
796 .ctl_name = CTL_UNNUMBERED,
797 .procname = "maps_protect",
798 .data = &maps_protect,
799 .maxlen = sizeof(int),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
803#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700804 {
805 .ctl_name = CTL_UNNUMBERED,
806 .procname = "poweroff_cmd",
807 .data = &poweroff_cmd,
808 .maxlen = POWEROFF_CMD_PATH_LEN,
809 .mode = 0644,
810 .proc_handler = &proc_dostring,
811 .strategy = &sysctl_string,
812 },
David Howells0b77f5b2008-04-29 01:01:32 -0700813#ifdef CONFIG_KEYS
814 {
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "keys",
817 .mode = 0555,
818 .child = key_sysctls,
819 },
820#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700821/*
822 * NOTE: do not add new entries to this table unless you have read
823 * Documentation/sysctl/ctl_unnumbered.txt
824 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 { .ctl_name = 0 }
826};
827
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700828static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 {
830 .ctl_name = VM_OVERCOMMIT_MEMORY,
831 .procname = "overcommit_memory",
832 .data = &sysctl_overcommit_memory,
833 .maxlen = sizeof(sysctl_overcommit_memory),
834 .mode = 0644,
835 .proc_handler = &proc_dointvec,
836 },
837 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700838 .ctl_name = VM_PANIC_ON_OOM,
839 .procname = "panic_on_oom",
840 .data = &sysctl_panic_on_oom,
841 .maxlen = sizeof(sysctl_panic_on_oom),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
844 },
845 {
David Rientjesfe071d72007-10-16 23:25:56 -0700846 .ctl_name = CTL_UNNUMBERED,
847 .procname = "oom_kill_allocating_task",
848 .data = &sysctl_oom_kill_allocating_task,
849 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
850 .mode = 0644,
851 .proc_handler = &proc_dointvec,
852 },
853 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800854 .ctl_name = CTL_UNNUMBERED,
855 .procname = "oom_dump_tasks",
856 .data = &sysctl_oom_dump_tasks,
857 .maxlen = sizeof(sysctl_oom_dump_tasks),
858 .mode = 0644,
859 .proc_handler = &proc_dointvec,
860 },
861 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 .ctl_name = VM_OVERCOMMIT_RATIO,
863 .procname = "overcommit_ratio",
864 .data = &sysctl_overcommit_ratio,
865 .maxlen = sizeof(sysctl_overcommit_ratio),
866 .mode = 0644,
867 .proc_handler = &proc_dointvec,
868 },
869 {
870 .ctl_name = VM_PAGE_CLUSTER,
871 .procname = "page-cluster",
872 .data = &page_cluster,
873 .maxlen = sizeof(int),
874 .mode = 0644,
875 .proc_handler = &proc_dointvec,
876 },
877 {
878 .ctl_name = VM_DIRTY_BACKGROUND,
879 .procname = "dirty_background_ratio",
880 .data = &dirty_background_ratio,
881 .maxlen = sizeof(dirty_background_ratio),
882 .mode = 0644,
883 .proc_handler = &proc_dointvec_minmax,
884 .strategy = &sysctl_intvec,
885 .extra1 = &zero,
886 .extra2 = &one_hundred,
887 },
888 {
889 .ctl_name = VM_DIRTY_RATIO,
890 .procname = "dirty_ratio",
891 .data = &vm_dirty_ratio,
892 .maxlen = sizeof(vm_dirty_ratio),
893 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700894 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 .strategy = &sysctl_intvec,
896 .extra1 = &zero,
897 .extra2 = &one_hundred,
898 },
899 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800901 .data = &dirty_writeback_interval,
902 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 .mode = 0644,
904 .proc_handler = &dirty_writeback_centisecs_handler,
905 },
906 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800908 .data = &dirty_expire_interval,
909 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800911 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 },
913 {
914 .ctl_name = VM_NR_PDFLUSH_THREADS,
915 .procname = "nr_pdflush_threads",
916 .data = &nr_pdflush_threads,
917 .maxlen = sizeof nr_pdflush_threads,
918 .mode = 0444 /* read-only*/,
919 .proc_handler = &proc_dointvec,
920 },
921 {
922 .ctl_name = VM_SWAPPINESS,
923 .procname = "swappiness",
924 .data = &vm_swappiness,
925 .maxlen = sizeof(vm_swappiness),
926 .mode = 0644,
927 .proc_handler = &proc_dointvec_minmax,
928 .strategy = &sysctl_intvec,
929 .extra1 = &zero,
930 .extra2 = &one_hundred,
931 },
932#ifdef CONFIG_HUGETLB_PAGE
933 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 .procname = "nr_hugepages",
935 .data = &max_huge_pages,
936 .maxlen = sizeof(unsigned long),
937 .mode = 0644,
938 .proc_handler = &hugetlb_sysctl_handler,
939 .extra1 = (void *)&hugetlb_zero,
940 .extra2 = (void *)&hugetlb_infinity,
941 },
942 {
943 .ctl_name = VM_HUGETLB_GROUP,
944 .procname = "hugetlb_shm_group",
945 .data = &sysctl_hugetlb_shm_group,
946 .maxlen = sizeof(gid_t),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec,
949 },
Mel Gorman396faf02007-07-17 04:03:13 -0700950 {
951 .ctl_name = CTL_UNNUMBERED,
952 .procname = "hugepages_treat_as_movable",
953 .data = &hugepages_treat_as_movable,
954 .maxlen = sizeof(int),
955 .mode = 0644,
956 .proc_handler = &hugetlb_treat_movable_handler,
957 },
Adam Litke54f9f802007-10-16 01:26:20 -0700958 {
959 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800960 .procname = "nr_overcommit_hugepages",
Nishanth Aravamudan064d9ef2008-02-13 15:03:19 -0800961 .data = &sysctl_overcommit_huge_pages,
962 .maxlen = sizeof(sysctl_overcommit_huge_pages),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800963 .mode = 0644,
Nishanth Aravamudana3d0c6a2008-02-08 04:18:18 -0800964 .proc_handler = &hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800965 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966#endif
967 {
968 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
969 .procname = "lowmem_reserve_ratio",
970 .data = &sysctl_lowmem_reserve_ratio,
971 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
972 .mode = 0644,
973 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
974 .strategy = &sysctl_intvec,
975 },
976 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800977 .ctl_name = VM_DROP_PAGECACHE,
978 .procname = "drop_caches",
979 .data = &sysctl_drop_caches,
980 .maxlen = sizeof(int),
981 .mode = 0644,
982 .proc_handler = drop_caches_sysctl_handler,
983 .strategy = &sysctl_intvec,
984 },
985 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .ctl_name = VM_MIN_FREE_KBYTES,
987 .procname = "min_free_kbytes",
988 .data = &min_free_kbytes,
989 .maxlen = sizeof(min_free_kbytes),
990 .mode = 0644,
991 .proc_handler = &min_free_kbytes_sysctl_handler,
992 .strategy = &sysctl_intvec,
993 .extra1 = &zero,
994 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800995 {
996 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
997 .procname = "percpu_pagelist_fraction",
998 .data = &percpu_pagelist_fraction,
999 .maxlen = sizeof(percpu_pagelist_fraction),
1000 .mode = 0644,
1001 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1002 .strategy = &sysctl_intvec,
1003 .extra1 = &min_percpu_pagelist_fract,
1004 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005#ifdef CONFIG_MMU
1006 {
1007 .ctl_name = VM_MAX_MAP_COUNT,
1008 .procname = "max_map_count",
1009 .data = &sysctl_max_map_count,
1010 .maxlen = sizeof(sysctl_max_map_count),
1011 .mode = 0644,
1012 .proc_handler = &proc_dointvec
1013 },
1014#endif
1015 {
1016 .ctl_name = VM_LAPTOP_MODE,
1017 .procname = "laptop_mode",
1018 .data = &laptop_mode,
1019 .maxlen = sizeof(laptop_mode),
1020 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001021 .proc_handler = &proc_dointvec_jiffies,
1022 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 },
1024 {
1025 .ctl_name = VM_BLOCK_DUMP,
1026 .procname = "block_dump",
1027 .data = &block_dump,
1028 .maxlen = sizeof(block_dump),
1029 .mode = 0644,
1030 .proc_handler = &proc_dointvec,
1031 .strategy = &sysctl_intvec,
1032 .extra1 = &zero,
1033 },
1034 {
1035 .ctl_name = VM_VFS_CACHE_PRESSURE,
1036 .procname = "vfs_cache_pressure",
1037 .data = &sysctl_vfs_cache_pressure,
1038 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec,
1041 .strategy = &sysctl_intvec,
1042 .extra1 = &zero,
1043 },
1044#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1045 {
1046 .ctl_name = VM_LEGACY_VA_LAYOUT,
1047 .procname = "legacy_va_layout",
1048 .data = &sysctl_legacy_va_layout,
1049 .maxlen = sizeof(sysctl_legacy_va_layout),
1050 .mode = 0644,
1051 .proc_handler = &proc_dointvec,
1052 .strategy = &sysctl_intvec,
1053 .extra1 = &zero,
1054 },
1055#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001056#ifdef CONFIG_NUMA
1057 {
1058 .ctl_name = VM_ZONE_RECLAIM_MODE,
1059 .procname = "zone_reclaim_mode",
1060 .data = &zone_reclaim_mode,
1061 .maxlen = sizeof(zone_reclaim_mode),
1062 .mode = 0644,
1063 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001064 .strategy = &sysctl_intvec,
1065 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001066 },
Christoph Lameter96146342006-07-03 00:24:13 -07001067 {
1068 .ctl_name = VM_MIN_UNMAPPED,
1069 .procname = "min_unmapped_ratio",
1070 .data = &sysctl_min_unmapped_ratio,
1071 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1072 .mode = 0644,
1073 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1074 .strategy = &sysctl_intvec,
1075 .extra1 = &zero,
1076 .extra2 = &one_hundred,
1077 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001078 {
1079 .ctl_name = VM_MIN_SLAB,
1080 .procname = "min_slab_ratio",
1081 .data = &sysctl_min_slab_ratio,
1082 .maxlen = sizeof(sysctl_min_slab_ratio),
1083 .mode = 0644,
1084 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1085 .strategy = &sysctl_intvec,
1086 .extra1 = &zero,
1087 .extra2 = &one_hundred,
1088 },
Christoph Lameter17436602006-01-18 17:42:32 -08001089#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001090#ifdef CONFIG_SMP
1091 {
1092 .ctl_name = CTL_UNNUMBERED,
1093 .procname = "stat_interval",
1094 .data = &sysctl_stat_interval,
1095 .maxlen = sizeof(sysctl_stat_interval),
1096 .mode = 0644,
1097 .proc_handler = &proc_dointvec_jiffies,
1098 .strategy = &sysctl_jiffies,
1099 },
1100#endif
Eric Parised032182007-06-28 15:55:21 -04001101#ifdef CONFIG_SECURITY
1102 {
1103 .ctl_name = CTL_UNNUMBERED,
1104 .procname = "mmap_min_addr",
1105 .data = &mmap_min_addr,
1106 .maxlen = sizeof(unsigned long),
1107 .mode = 0644,
1108 .proc_handler = &proc_doulongvec_minmax,
1109 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001110#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001111#ifdef CONFIG_NUMA
1112 {
1113 .ctl_name = CTL_UNNUMBERED,
1114 .procname = "numa_zonelist_order",
1115 .data = &numa_zonelist_order,
1116 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1117 .mode = 0644,
1118 .proc_handler = &numa_zonelist_order_handler,
1119 .strategy = &sysctl_string,
1120 },
1121#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001122#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001123 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001124 {
1125 .ctl_name = VM_VDSO_ENABLED,
1126 .procname = "vdso_enabled",
1127 .data = &vdso_enabled,
1128 .maxlen = sizeof(vdso_enabled),
1129 .mode = 0644,
1130 .proc_handler = &proc_dointvec,
1131 .strategy = &sysctl_intvec,
1132 .extra1 = &zero,
1133 },
1134#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001135#ifdef CONFIG_HIGHMEM
1136 {
1137 .ctl_name = CTL_UNNUMBERED,
1138 .procname = "highmem_is_dirtyable",
1139 .data = &vm_highmem_is_dirtyable,
1140 .maxlen = sizeof(vm_highmem_is_dirtyable),
1141 .mode = 0644,
1142 .proc_handler = &proc_dointvec_minmax,
1143 .strategy = &sysctl_intvec,
1144 .extra1 = &zero,
1145 .extra2 = &one,
1146 },
1147#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001148/*
1149 * NOTE: do not add new entries to this table unless you have read
1150 * Documentation/sysctl/ctl_unnumbered.txt
1151 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 { .ctl_name = 0 }
1153};
1154
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001155#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001156static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001157 { .ctl_name = 0 }
1158};
1159#endif
1160
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001161static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 {
1163 .ctl_name = FS_NRINODE,
1164 .procname = "inode-nr",
1165 .data = &inodes_stat,
1166 .maxlen = 2*sizeof(int),
1167 .mode = 0444,
1168 .proc_handler = &proc_dointvec,
1169 },
1170 {
1171 .ctl_name = FS_STATINODE,
1172 .procname = "inode-state",
1173 .data = &inodes_stat,
1174 .maxlen = 7*sizeof(int),
1175 .mode = 0444,
1176 .proc_handler = &proc_dointvec,
1177 },
1178 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 .procname = "file-nr",
1180 .data = &files_stat,
1181 .maxlen = 3*sizeof(int),
1182 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001183 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 },
1185 {
1186 .ctl_name = FS_MAXFILE,
1187 .procname = "file-max",
1188 .data = &files_stat.max_files,
1189 .maxlen = sizeof(int),
1190 .mode = 0644,
1191 .proc_handler = &proc_dointvec,
1192 },
1193 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001194 .ctl_name = CTL_UNNUMBERED,
1195 .procname = "nr_open",
1196 .data = &sysctl_nr_open,
1197 .maxlen = sizeof(int),
1198 .mode = 0644,
1199 .proc_handler = &proc_dointvec,
1200 },
1201 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 .ctl_name = FS_DENTRY,
1203 .procname = "dentry-state",
1204 .data = &dentry_stat,
1205 .maxlen = 6*sizeof(int),
1206 .mode = 0444,
1207 .proc_handler = &proc_dointvec,
1208 },
1209 {
1210 .ctl_name = FS_OVERFLOWUID,
1211 .procname = "overflowuid",
1212 .data = &fs_overflowuid,
1213 .maxlen = sizeof(int),
1214 .mode = 0644,
1215 .proc_handler = &proc_dointvec_minmax,
1216 .strategy = &sysctl_intvec,
1217 .extra1 = &minolduid,
1218 .extra2 = &maxolduid,
1219 },
1220 {
1221 .ctl_name = FS_OVERFLOWGID,
1222 .procname = "overflowgid",
1223 .data = &fs_overflowgid,
1224 .maxlen = sizeof(int),
1225 .mode = 0644,
1226 .proc_handler = &proc_dointvec_minmax,
1227 .strategy = &sysctl_intvec,
1228 .extra1 = &minolduid,
1229 .extra2 = &maxolduid,
1230 },
1231 {
1232 .ctl_name = FS_LEASES,
1233 .procname = "leases-enable",
1234 .data = &leases_enable,
1235 .maxlen = sizeof(int),
1236 .mode = 0644,
1237 .proc_handler = &proc_dointvec,
1238 },
1239#ifdef CONFIG_DNOTIFY
1240 {
1241 .ctl_name = FS_DIR_NOTIFY,
1242 .procname = "dir-notify-enable",
1243 .data = &dir_notify_enable,
1244 .maxlen = sizeof(int),
1245 .mode = 0644,
1246 .proc_handler = &proc_dointvec,
1247 },
1248#endif
1249#ifdef CONFIG_MMU
1250 {
1251 .ctl_name = FS_LEASE_TIME,
1252 .procname = "lease-break-time",
1253 .data = &lease_break_time,
1254 .maxlen = sizeof(int),
1255 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001256 .proc_handler = &proc_dointvec_minmax,
1257 .strategy = &sysctl_intvec,
1258 .extra1 = &zero,
1259 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 },
1261 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 .procname = "aio-nr",
1263 .data = &aio_nr,
1264 .maxlen = sizeof(aio_nr),
1265 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001266 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 },
1268 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 .procname = "aio-max-nr",
1270 .data = &aio_max_nr,
1271 .maxlen = sizeof(aio_max_nr),
1272 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001273 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001275#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001276 {
1277 .ctl_name = FS_INOTIFY,
1278 .procname = "inotify",
1279 .mode = 0555,
1280 .child = inotify_table,
1281 },
1282#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001284 {
1285 .ctl_name = KERN_SETUID_DUMPABLE,
1286 .procname = "suid_dumpable",
1287 .data = &suid_dumpable,
1288 .maxlen = sizeof(int),
1289 .mode = 0644,
1290 .proc_handler = &proc_dointvec,
1291 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001292#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1293 {
1294 .ctl_name = CTL_UNNUMBERED,
1295 .procname = "binfmt_misc",
1296 .mode = 0555,
1297 .child = binfmt_misc_table,
1298 },
1299#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001300/*
1301 * NOTE: do not add new entries to this table unless you have read
1302 * Documentation/sysctl/ctl_unnumbered.txt
1303 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 { .ctl_name = 0 }
1305};
1306
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001307static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001308#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001309 {
1310 .ctl_name = CTL_UNNUMBERED,
1311 .procname = "exception-trace",
1312 .data = &show_unhandled_signals,
1313 .maxlen = sizeof(int),
1314 .mode = 0644,
1315 .proc_handler = proc_dointvec
1316 },
1317#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 { .ctl_name = 0 }
1319};
1320
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001321static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001323};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Al Viro330d57f2005-11-04 10:18:40 +00001325static DEFINE_SPINLOCK(sysctl_lock);
1326
1327/* called under sysctl_lock */
1328static int use_table(struct ctl_table_header *p)
1329{
1330 if (unlikely(p->unregistering))
1331 return 0;
1332 p->used++;
1333 return 1;
1334}
1335
1336/* called under sysctl_lock */
1337static void unuse_table(struct ctl_table_header *p)
1338{
1339 if (!--p->used)
1340 if (unlikely(p->unregistering))
1341 complete(p->unregistering);
1342}
1343
1344/* called under sysctl_lock, will reacquire if has to wait */
1345static void start_unregistering(struct ctl_table_header *p)
1346{
1347 /*
1348 * if p->used is 0, nobody will ever touch that entry again;
1349 * we'll eliminate all paths to it before dropping sysctl_lock
1350 */
1351 if (unlikely(p->used)) {
1352 struct completion wait;
1353 init_completion(&wait);
1354 p->unregistering = &wait;
1355 spin_unlock(&sysctl_lock);
1356 wait_for_completion(&wait);
1357 spin_lock(&sysctl_lock);
1358 }
1359 /*
1360 * do not remove from the list until nobody holds it; walking the
1361 * list in do_sysctl() relies on that.
1362 */
1363 list_del_init(&p->ctl_entry);
1364}
1365
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001366void sysctl_head_finish(struct ctl_table_header *head)
1367{
1368 if (!head)
1369 return;
1370 spin_lock(&sysctl_lock);
1371 unuse_table(head);
1372 spin_unlock(&sysctl_lock);
1373}
1374
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001375static struct list_head *
1376lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001377{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001378 struct list_head *header_list;
1379 header_list = &root->header_list;
1380 if (root->lookup)
1381 header_list = root->lookup(root, namespaces);
1382 return header_list;
1383}
1384
1385struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1386 struct ctl_table_header *prev)
1387{
1388 struct ctl_table_root *root;
1389 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001390 struct ctl_table_header *head;
1391 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001392
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001393 spin_lock(&sysctl_lock);
1394 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001395 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001396 tmp = &prev->ctl_entry;
1397 unuse_table(prev);
1398 goto next;
1399 }
1400 tmp = &root_table_header.ctl_entry;
1401 for (;;) {
1402 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1403
1404 if (!use_table(head))
1405 goto next;
1406 spin_unlock(&sysctl_lock);
1407 return head;
1408 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001409 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001410 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001411 header_list = lookup_header_list(root, namespaces);
1412 if (tmp != header_list)
1413 continue;
1414
1415 do {
1416 root = list_entry(root->root_list.next,
1417 struct ctl_table_root, root_list);
1418 if (root == &sysctl_table_root)
1419 goto out;
1420 header_list = lookup_header_list(root, namespaces);
1421 } while (list_empty(header_list));
1422 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001423 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001424out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001425 spin_unlock(&sysctl_lock);
1426 return NULL;
1427}
1428
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001429struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1430{
1431 return __sysctl_head_next(current->nsproxy, prev);
1432}
1433
1434void register_sysctl_root(struct ctl_table_root *root)
1435{
1436 spin_lock(&sysctl_lock);
1437 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1438 spin_unlock(&sysctl_lock);
1439}
1440
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001441#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1443 void __user *newval, size_t newlen)
1444{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001445 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001446 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
1448 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1449 return -ENOTDIR;
1450 if (oldval) {
1451 int old_len;
1452 if (!oldlenp || get_user(old_len, oldlenp))
1453 return -EFAULT;
1454 }
Al Viro330d57f2005-11-04 10:18:40 +00001455
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001456 for (head = sysctl_head_next(NULL); head;
1457 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001458 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001459 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001460 if (error != -ENOTDIR) {
1461 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001462 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001463 }
1464 }
Al Viro330d57f2005-11-04 10:18:40 +00001465 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466}
1467
1468asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1469{
1470 struct __sysctl_args tmp;
1471 int error;
1472
1473 if (copy_from_user(&tmp, args, sizeof(tmp)))
1474 return -EFAULT;
1475
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001476 error = deprecated_sysctl_warning(&tmp);
1477 if (error)
1478 goto out;
1479
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 lock_kernel();
1481 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1482 tmp.newval, tmp.newlen);
1483 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001484out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 return error;
1486}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001487#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001490 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 * some sysctl variables are readonly even to root.
1492 */
1493
1494static int test_perm(int mode, int op)
1495{
1496 if (!current->euid)
1497 mode >>= 6;
1498 else if (in_egroup_p(0))
1499 mode >>= 3;
1500 if ((mode & op & 0007) == op)
1501 return 0;
1502 return -EACCES;
1503}
1504
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001505int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506{
1507 int error;
1508 error = security_sysctl(table, op);
1509 if (error)
1510 return error;
1511 return test_perm(table->mode, op);
1512}
1513
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001514#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515static int parse_table(int __user *name, int nlen,
1516 void __user *oldval, size_t __user *oldlenp,
1517 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001518 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519{
1520 int n;
1521repeat:
1522 if (!nlen)
1523 return -ENOTDIR;
1524 if (get_user(n, name))
1525 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001526 for ( ; table->ctl_name || table->procname; table++) {
1527 if (!table->ctl_name)
1528 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001529 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 int error;
1531 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001532 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 name++;
1535 nlen--;
1536 table = table->child;
1537 goto repeat;
1538 }
1539 error = do_sysctl_strategy(table, name, nlen,
1540 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001541 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 return error;
1543 }
1544 }
1545 return -ENOTDIR;
1546}
1547
1548/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001549int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 int __user *name, int nlen,
1551 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001552 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553{
1554 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 if (oldval)
1557 op |= 004;
1558 if (newval)
1559 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001560 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 return -EPERM;
1562
1563 if (table->strategy) {
1564 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001565 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 if (rc < 0)
1567 return rc;
1568 if (rc > 0)
1569 return 0;
1570 }
1571
1572 /* If there is no strategy routine, or if the strategy returns
1573 * zero, proceed with automatic r/w */
1574 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001575 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1576 newval, newlen);
1577 if (rc < 0)
1578 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 }
1580 return 0;
1581}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001582#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001584static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1585{
1586 for (; table->ctl_name || table->procname; table++) {
1587 table->parent = parent;
1588 if (table->child)
1589 sysctl_set_parent(table, table->child);
1590 }
1591}
1592
1593static __init int sysctl_init(void)
1594{
1595 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001596#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1597 {
1598 int err;
1599 err = sysctl_check_table(current->nsproxy, root_table);
1600 }
1601#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001602 return 0;
1603}
1604
1605core_initcall(sysctl_init);
1606
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001608 * __register_sysctl_paths - register a sysctl hierarchy
1609 * @root: List of sysctl headers to register on
1610 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001611 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 *
1614 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001615 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001617 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 *
1619 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1620 * must be unique within that level of sysctl
1621 *
1622 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1623 * enter a sysctl file
1624 *
1625 * data - a pointer to data for use by proc_handler
1626 *
1627 * maxlen - the maximum size in bytes of the data
1628 *
1629 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1630 *
1631 * child - a pointer to the child sysctl table if this entry is a directory, or
1632 * %NULL.
1633 *
1634 * proc_handler - the text handler routine (described below)
1635 *
1636 * strategy - the strategy routine (described below)
1637 *
1638 * de - for internal use by the sysctl routines
1639 *
1640 * extra1, extra2 - extra pointers usable by the proc handler routines
1641 *
1642 * Leaf nodes in the sysctl tree will be represented by a single file
1643 * under /proc; non-leaf nodes will be represented by directories.
1644 *
1645 * sysctl(2) can automatically manage read and write requests through
1646 * the sysctl table. The data and maxlen fields of the ctl_table
1647 * struct enable minimal validation of the values being written to be
1648 * performed, and the mode field allows minimal authentication.
1649 *
1650 * More sophisticated management can be enabled by the provision of a
1651 * strategy routine with the table entry. This will be called before
1652 * any automatic read or write of the data is performed.
1653 *
1654 * The strategy routine may return
1655 *
1656 * < 0 - Error occurred (error is passed to user process)
1657 *
1658 * 0 - OK - proceed with automatic read or write.
1659 *
1660 * > 0 - OK - read or write has been done by the strategy routine, so
1661 * return immediately.
1662 *
1663 * There must be a proc_handler routine for any terminal nodes
1664 * mirrored under /proc/sys (non-terminals are handled by a built-in
1665 * directory handler). Several default handlers are available to
1666 * cover common cases -
1667 *
1668 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1669 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1670 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1671 *
1672 * It is the handler's job to read the input buffer from user memory
1673 * and process it. The handler should return 0 on success.
1674 *
1675 * This routine returns %NULL on a failure to register, and a pointer
1676 * to the table header on success.
1677 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001678struct ctl_table_header *__register_sysctl_paths(
1679 struct ctl_table_root *root,
1680 struct nsproxy *namespaces,
1681 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001683 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001684 struct ctl_table_header *header;
1685 struct ctl_table *new, **prevp;
1686 unsigned int n, npath;
1687
1688 /* Count the path components */
1689 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1690 ;
1691
1692 /*
1693 * For each path component, allocate a 2-element ctl_table array.
1694 * The first array element will be filled with the sysctl entry
1695 * for this, the second will be the sentinel (ctl_name == 0).
1696 *
1697 * We allocate everything in one go so that we don't have to
1698 * worry about freeing additional memory in unregister_sysctl_table.
1699 */
1700 header = kzalloc(sizeof(struct ctl_table_header) +
1701 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1702 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001704
1705 new = (struct ctl_table *) (header + 1);
1706
1707 /* Now connect the dots */
1708 prevp = &header->ctl_table;
1709 for (n = 0; n < npath; ++n, ++path) {
1710 /* Copy the procname */
1711 new->procname = path->procname;
1712 new->ctl_name = path->ctl_name;
1713 new->mode = 0555;
1714
1715 *prevp = new;
1716 prevp = &new->child;
1717
1718 new += 2;
1719 }
1720 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001721 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001722
1723 INIT_LIST_HEAD(&header->ctl_entry);
1724 header->used = 0;
1725 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001726 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001727 sysctl_set_parent(NULL, header->ctl_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001728#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001729 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001730 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001731 return NULL;
1732 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001733#endif
Al Viro330d57f2005-11-04 10:18:40 +00001734 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001735 header_list = lookup_header_list(root, namespaces);
1736 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001737 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001738
1739 return header;
1740}
1741
1742/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001743 * register_sysctl_table_path - register a sysctl table hierarchy
1744 * @path: The path to the directory the sysctl table is in.
1745 * @table: the top-level table structure
1746 *
1747 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1748 * array. A completely 0 filled entry terminates the table.
1749 *
1750 * See __register_sysctl_paths for more details.
1751 */
1752struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1753 struct ctl_table *table)
1754{
1755 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1756 path, table);
1757}
1758
1759/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001760 * register_sysctl_table - register a sysctl table hierarchy
1761 * @table: the top-level table structure
1762 *
1763 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1764 * array. A completely 0 filled entry terminates the table.
1765 *
1766 * See register_sysctl_paths for more details.
1767 */
1768struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1769{
1770 static const struct ctl_path null_path[] = { {} };
1771
1772 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773}
1774
1775/**
1776 * unregister_sysctl_table - unregister a sysctl table hierarchy
1777 * @header: the header returned from register_sysctl_table
1778 *
1779 * Unregisters the sysctl table and all children. proc entries may not
1780 * actually be removed until they are no longer used by anyone.
1781 */
1782void unregister_sysctl_table(struct ctl_table_header * header)
1783{
Al Viro330d57f2005-11-04 10:18:40 +00001784 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001785
1786 if (header == NULL)
1787 return;
1788
Al Viro330d57f2005-11-04 10:18:40 +00001789 spin_lock(&sysctl_lock);
1790 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001791 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 kfree(header);
1793}
1794
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001795#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001796struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001797{
1798 return NULL;
1799}
1800
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001801struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1802 struct ctl_table *table)
1803{
1804 return NULL;
1805}
1806
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001807void unregister_sysctl_table(struct ctl_table_header * table)
1808{
1809}
1810
1811#endif /* CONFIG_SYSCTL */
1812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813/*
1814 * /proc/sys support
1815 */
1816
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001817#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001819static int _proc_do_string(void* data, int maxlen, int write,
1820 struct file *filp, void __user *buffer,
1821 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001822{
1823 size_t len;
1824 char __user *p;
1825 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001826
1827 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001828 *lenp = 0;
1829 return 0;
1830 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001831
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001832 if (write) {
1833 len = 0;
1834 p = buffer;
1835 while (len < *lenp) {
1836 if (get_user(c, p++))
1837 return -EFAULT;
1838 if (c == 0 || c == '\n')
1839 break;
1840 len++;
1841 }
1842 if (len >= maxlen)
1843 len = maxlen-1;
1844 if(copy_from_user(data, buffer, len))
1845 return -EFAULT;
1846 ((char *) data)[len] = 0;
1847 *ppos += *lenp;
1848 } else {
1849 len = strlen(data);
1850 if (len > maxlen)
1851 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001852
1853 if (*ppos > len) {
1854 *lenp = 0;
1855 return 0;
1856 }
1857
1858 data += *ppos;
1859 len -= *ppos;
1860
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001861 if (len > *lenp)
1862 len = *lenp;
1863 if (len)
1864 if(copy_to_user(buffer, data, len))
1865 return -EFAULT;
1866 if (len < *lenp) {
1867 if(put_user('\n', ((char __user *) buffer) + len))
1868 return -EFAULT;
1869 len++;
1870 }
1871 *lenp = len;
1872 *ppos += len;
1873 }
1874 return 0;
1875}
1876
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877/**
1878 * proc_dostring - read a string sysctl
1879 * @table: the sysctl table
1880 * @write: %TRUE if this is a write to the sysctl file
1881 * @filp: the file structure
1882 * @buffer: the user buffer
1883 * @lenp: the size of the user buffer
1884 * @ppos: file position
1885 *
1886 * Reads/writes a string from/to the user buffer. If the kernel
1887 * buffer provided is not large enough to hold the string, the
1888 * string is truncated. The copied string is %NULL-terminated.
1889 * If the string is being read by the user process, it is copied
1890 * and a newline '\n' is added. It is truncated if the buffer is
1891 * not large enough.
1892 *
1893 * Returns 0 on success.
1894 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001895int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 void __user *buffer, size_t *lenp, loff_t *ppos)
1897{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001898 return _proc_do_string(table->data, table->maxlen, write, filp,
1899 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900}
1901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
1903static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1904 int *valp,
1905 int write, void *data)
1906{
1907 if (write) {
1908 *valp = *negp ? -*lvalp : *lvalp;
1909 } else {
1910 int val = *valp;
1911 if (val < 0) {
1912 *negp = -1;
1913 *lvalp = (unsigned long)-val;
1914 } else {
1915 *negp = 0;
1916 *lvalp = (unsigned long)val;
1917 }
1918 }
1919 return 0;
1920}
1921
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001922static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001923 int write, struct file *filp, void __user *buffer,
1924 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1926 int write, void *data),
1927 void *data)
1928{
1929#define TMPBUFLEN 21
1930 int *i, vleft, first=1, neg, val;
1931 unsigned long lval;
1932 size_t left, len;
1933
1934 char buf[TMPBUFLEN], *p;
1935 char __user *s = buffer;
1936
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001937 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 (*ppos && !write)) {
1939 *lenp = 0;
1940 return 0;
1941 }
1942
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001943 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 vleft = table->maxlen / sizeof(*i);
1945 left = *lenp;
1946
1947 if (!conv)
1948 conv = do_proc_dointvec_conv;
1949
1950 for (; left && vleft--; i++, first=0) {
1951 if (write) {
1952 while (left) {
1953 char c;
1954 if (get_user(c, s))
1955 return -EFAULT;
1956 if (!isspace(c))
1957 break;
1958 left--;
1959 s++;
1960 }
1961 if (!left)
1962 break;
1963 neg = 0;
1964 len = left;
1965 if (len > sizeof(buf) - 1)
1966 len = sizeof(buf) - 1;
1967 if (copy_from_user(buf, s, len))
1968 return -EFAULT;
1969 buf[len] = 0;
1970 p = buf;
1971 if (*p == '-' && left > 1) {
1972 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001973 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 }
1975 if (*p < '0' || *p > '9')
1976 break;
1977
1978 lval = simple_strtoul(p, &p, 0);
1979
1980 len = p-buf;
1981 if ((len < left) && *p && !isspace(*p))
1982 break;
1983 if (neg)
1984 val = -val;
1985 s += len;
1986 left -= len;
1987
1988 if (conv(&neg, &lval, i, 1, data))
1989 break;
1990 } else {
1991 p = buf;
1992 if (!first)
1993 *p++ = '\t';
1994
1995 if (conv(&neg, &lval, i, 0, data))
1996 break;
1997
1998 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1999 len = strlen(buf);
2000 if (len > left)
2001 len = left;
2002 if(copy_to_user(s, buf, len))
2003 return -EFAULT;
2004 left -= len;
2005 s += len;
2006 }
2007 }
2008
2009 if (!write && !first && left) {
2010 if(put_user('\n', s))
2011 return -EFAULT;
2012 left--, s++;
2013 }
2014 if (write) {
2015 while (left) {
2016 char c;
2017 if (get_user(c, s++))
2018 return -EFAULT;
2019 if (!isspace(c))
2020 break;
2021 left--;
2022 }
2023 }
2024 if (write && first)
2025 return -EINVAL;
2026 *lenp -= left;
2027 *ppos += *lenp;
2028 return 0;
2029#undef TMPBUFLEN
2030}
2031
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002032static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002033 void __user *buffer, size_t *lenp, loff_t *ppos,
2034 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2035 int write, void *data),
2036 void *data)
2037{
2038 return __do_proc_dointvec(table->data, table, write, filp,
2039 buffer, lenp, ppos, conv, data);
2040}
2041
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042/**
2043 * proc_dointvec - read a vector of integers
2044 * @table: the sysctl table
2045 * @write: %TRUE if this is a write to the sysctl file
2046 * @filp: the file structure
2047 * @buffer: the user buffer
2048 * @lenp: the size of the user buffer
2049 * @ppos: file position
2050 *
2051 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2052 * values from/to the user buffer, treated as an ASCII string.
2053 *
2054 * Returns 0 on success.
2055 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002056int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 void __user *buffer, size_t *lenp, loff_t *ppos)
2058{
2059 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2060 NULL,NULL);
2061}
2062
2063#define OP_SET 0
2064#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002065#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
2067static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2068 int *valp,
2069 int write, void *data)
2070{
2071 int op = *(int *)data;
2072 if (write) {
2073 int val = *negp ? -*lvalp : *lvalp;
2074 switch(op) {
2075 case OP_SET: *valp = val; break;
2076 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002077 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 }
2079 } else {
2080 int val = *valp;
2081 if (val < 0) {
2082 *negp = -1;
2083 *lvalp = (unsigned long)-val;
2084 } else {
2085 *negp = 0;
2086 *lvalp = (unsigned long)val;
2087 }
2088 }
2089 return 0;
2090}
2091
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002092/*
2093 * Taint values can only be increased
2094 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002095static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002096 void __user *buffer, size_t *lenp, loff_t *ppos)
2097{
2098 int op;
2099
Bastian Blank91fcd412007-04-23 14:41:14 -07002100 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002101 return -EPERM;
2102
2103 op = OP_OR;
2104 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2105 do_proc_dointvec_bset_conv,&op);
2106}
2107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108struct do_proc_dointvec_minmax_conv_param {
2109 int *min;
2110 int *max;
2111};
2112
2113static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2114 int *valp,
2115 int write, void *data)
2116{
2117 struct do_proc_dointvec_minmax_conv_param *param = data;
2118 if (write) {
2119 int val = *negp ? -*lvalp : *lvalp;
2120 if ((param->min && *param->min > val) ||
2121 (param->max && *param->max < val))
2122 return -EINVAL;
2123 *valp = val;
2124 } else {
2125 int val = *valp;
2126 if (val < 0) {
2127 *negp = -1;
2128 *lvalp = (unsigned long)-val;
2129 } else {
2130 *negp = 0;
2131 *lvalp = (unsigned long)val;
2132 }
2133 }
2134 return 0;
2135}
2136
2137/**
2138 * proc_dointvec_minmax - read a vector of integers with min/max values
2139 * @table: the sysctl table
2140 * @write: %TRUE if this is a write to the sysctl file
2141 * @filp: the file structure
2142 * @buffer: the user buffer
2143 * @lenp: the size of the user buffer
2144 * @ppos: file position
2145 *
2146 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2147 * values from/to the user buffer, treated as an ASCII string.
2148 *
2149 * This routine will ensure the values are within the range specified by
2150 * table->extra1 (min) and table->extra2 (max).
2151 *
2152 * Returns 0 on success.
2153 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002154int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 void __user *buffer, size_t *lenp, loff_t *ppos)
2156{
2157 struct do_proc_dointvec_minmax_conv_param param = {
2158 .min = (int *) table->extra1,
2159 .max = (int *) table->extra2,
2160 };
2161 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2162 do_proc_dointvec_minmax_conv, &param);
2163}
2164
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002165static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 struct file *filp,
2167 void __user *buffer,
2168 size_t *lenp, loff_t *ppos,
2169 unsigned long convmul,
2170 unsigned long convdiv)
2171{
2172#define TMPBUFLEN 21
2173 unsigned long *i, *min, *max, val;
2174 int vleft, first=1, neg;
2175 size_t len, left;
2176 char buf[TMPBUFLEN], *p;
2177 char __user *s = buffer;
2178
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002179 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 (*ppos && !write)) {
2181 *lenp = 0;
2182 return 0;
2183 }
2184
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002185 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 min = (unsigned long *) table->extra1;
2187 max = (unsigned long *) table->extra2;
2188 vleft = table->maxlen / sizeof(unsigned long);
2189 left = *lenp;
2190
2191 for (; left && vleft--; i++, min++, max++, first=0) {
2192 if (write) {
2193 while (left) {
2194 char c;
2195 if (get_user(c, s))
2196 return -EFAULT;
2197 if (!isspace(c))
2198 break;
2199 left--;
2200 s++;
2201 }
2202 if (!left)
2203 break;
2204 neg = 0;
2205 len = left;
2206 if (len > TMPBUFLEN-1)
2207 len = TMPBUFLEN-1;
2208 if (copy_from_user(buf, s, len))
2209 return -EFAULT;
2210 buf[len] = 0;
2211 p = buf;
2212 if (*p == '-' && left > 1) {
2213 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002214 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 }
2216 if (*p < '0' || *p > '9')
2217 break;
2218 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2219 len = p-buf;
2220 if ((len < left) && *p && !isspace(*p))
2221 break;
2222 if (neg)
2223 val = -val;
2224 s += len;
2225 left -= len;
2226
2227 if(neg)
2228 continue;
2229 if ((min && val < *min) || (max && val > *max))
2230 continue;
2231 *i = val;
2232 } else {
2233 p = buf;
2234 if (!first)
2235 *p++ = '\t';
2236 sprintf(p, "%lu", convdiv * (*i) / convmul);
2237 len = strlen(buf);
2238 if (len > left)
2239 len = left;
2240 if(copy_to_user(s, buf, len))
2241 return -EFAULT;
2242 left -= len;
2243 s += len;
2244 }
2245 }
2246
2247 if (!write && !first && left) {
2248 if(put_user('\n', s))
2249 return -EFAULT;
2250 left--, s++;
2251 }
2252 if (write) {
2253 while (left) {
2254 char c;
2255 if (get_user(c, s++))
2256 return -EFAULT;
2257 if (!isspace(c))
2258 break;
2259 left--;
2260 }
2261 }
2262 if (write && first)
2263 return -EINVAL;
2264 *lenp -= left;
2265 *ppos += *lenp;
2266 return 0;
2267#undef TMPBUFLEN
2268}
2269
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002270static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002271 struct file *filp,
2272 void __user *buffer,
2273 size_t *lenp, loff_t *ppos,
2274 unsigned long convmul,
2275 unsigned long convdiv)
2276{
2277 return __do_proc_doulongvec_minmax(table->data, table, write,
2278 filp, buffer, lenp, ppos, convmul, convdiv);
2279}
2280
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281/**
2282 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2283 * @table: the sysctl table
2284 * @write: %TRUE if this is a write to the sysctl file
2285 * @filp: the file structure
2286 * @buffer: the user buffer
2287 * @lenp: the size of the user buffer
2288 * @ppos: file position
2289 *
2290 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2291 * values from/to the user buffer, treated as an ASCII string.
2292 *
2293 * This routine will ensure the values are within the range specified by
2294 * table->extra1 (min) and table->extra2 (max).
2295 *
2296 * Returns 0 on success.
2297 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002298int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 void __user *buffer, size_t *lenp, loff_t *ppos)
2300{
2301 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2302}
2303
2304/**
2305 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2306 * @table: the sysctl table
2307 * @write: %TRUE if this is a write to the sysctl file
2308 * @filp: the file structure
2309 * @buffer: the user buffer
2310 * @lenp: the size of the user buffer
2311 * @ppos: file position
2312 *
2313 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2314 * values from/to the user buffer, treated as an ASCII string. The values
2315 * are treated as milliseconds, and converted to jiffies when they are stored.
2316 *
2317 * This routine will ensure the values are within the range specified by
2318 * table->extra1 (min) and table->extra2 (max).
2319 *
2320 * Returns 0 on success.
2321 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002322int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 struct file *filp,
2324 void __user *buffer,
2325 size_t *lenp, loff_t *ppos)
2326{
2327 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2328 lenp, ppos, HZ, 1000l);
2329}
2330
2331
2332static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2333 int *valp,
2334 int write, void *data)
2335{
2336 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002337 if (*lvalp > LONG_MAX / HZ)
2338 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2340 } else {
2341 int val = *valp;
2342 unsigned long lval;
2343 if (val < 0) {
2344 *negp = -1;
2345 lval = (unsigned long)-val;
2346 } else {
2347 *negp = 0;
2348 lval = (unsigned long)val;
2349 }
2350 *lvalp = lval / HZ;
2351 }
2352 return 0;
2353}
2354
2355static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2356 int *valp,
2357 int write, void *data)
2358{
2359 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002360 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2361 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2363 } else {
2364 int val = *valp;
2365 unsigned long lval;
2366 if (val < 0) {
2367 *negp = -1;
2368 lval = (unsigned long)-val;
2369 } else {
2370 *negp = 0;
2371 lval = (unsigned long)val;
2372 }
2373 *lvalp = jiffies_to_clock_t(lval);
2374 }
2375 return 0;
2376}
2377
2378static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2379 int *valp,
2380 int write, void *data)
2381{
2382 if (write) {
2383 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2384 } else {
2385 int val = *valp;
2386 unsigned long lval;
2387 if (val < 0) {
2388 *negp = -1;
2389 lval = (unsigned long)-val;
2390 } else {
2391 *negp = 0;
2392 lval = (unsigned long)val;
2393 }
2394 *lvalp = jiffies_to_msecs(lval);
2395 }
2396 return 0;
2397}
2398
2399/**
2400 * proc_dointvec_jiffies - read a vector of integers as seconds
2401 * @table: the sysctl table
2402 * @write: %TRUE if this is a write to the sysctl file
2403 * @filp: the file structure
2404 * @buffer: the user buffer
2405 * @lenp: the size of the user buffer
2406 * @ppos: file position
2407 *
2408 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2409 * values from/to the user buffer, treated as an ASCII string.
2410 * The values read are assumed to be in seconds, and are converted into
2411 * jiffies.
2412 *
2413 * Returns 0 on success.
2414 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002415int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 void __user *buffer, size_t *lenp, loff_t *ppos)
2417{
2418 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2419 do_proc_dointvec_jiffies_conv,NULL);
2420}
2421
2422/**
2423 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2424 * @table: the sysctl table
2425 * @write: %TRUE if this is a write to the sysctl file
2426 * @filp: the file structure
2427 * @buffer: the user buffer
2428 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002429 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 *
2431 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2432 * values from/to the user buffer, treated as an ASCII string.
2433 * The values read are assumed to be in 1/USER_HZ seconds, and
2434 * are converted into jiffies.
2435 *
2436 * Returns 0 on success.
2437 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002438int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 void __user *buffer, size_t *lenp, loff_t *ppos)
2440{
2441 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2442 do_proc_dointvec_userhz_jiffies_conv,NULL);
2443}
2444
2445/**
2446 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2447 * @table: the sysctl table
2448 * @write: %TRUE if this is a write to the sysctl file
2449 * @filp: the file structure
2450 * @buffer: the user buffer
2451 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002452 * @ppos: file position
2453 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 *
2455 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2456 * values from/to the user buffer, treated as an ASCII string.
2457 * The values read are assumed to be in 1/1000 seconds, and
2458 * are converted into jiffies.
2459 *
2460 * Returns 0 on success.
2461 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002462int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 void __user *buffer, size_t *lenp, loff_t *ppos)
2464{
2465 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2466 do_proc_dointvec_ms_jiffies_conv, NULL);
2467}
2468
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002469static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002470 void __user *buffer, size_t *lenp, loff_t *ppos)
2471{
2472 struct pid *new_pid;
2473 pid_t tmp;
2474 int r;
2475
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002476 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002477
2478 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2479 lenp, ppos, NULL, NULL);
2480 if (r || !write)
2481 return r;
2482
2483 new_pid = find_get_pid(tmp);
2484 if (!new_pid)
2485 return -ESRCH;
2486
2487 put_pid(xchg(&cad_pid, new_pid));
2488 return 0;
2489}
2490
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491#else /* CONFIG_PROC_FS */
2492
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002493int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 void __user *buffer, size_t *lenp, loff_t *ppos)
2495{
2496 return -ENOSYS;
2497}
2498
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002499int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 void __user *buffer, size_t *lenp, loff_t *ppos)
2501{
2502 return -ENOSYS;
2503}
2504
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002505int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 void __user *buffer, size_t *lenp, loff_t *ppos)
2507{
2508 return -ENOSYS;
2509}
2510
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002511int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 void __user *buffer, size_t *lenp, loff_t *ppos)
2513{
2514 return -ENOSYS;
2515}
2516
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002517int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 void __user *buffer, size_t *lenp, loff_t *ppos)
2519{
2520 return -ENOSYS;
2521}
2522
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002523int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 void __user *buffer, size_t *lenp, loff_t *ppos)
2525{
2526 return -ENOSYS;
2527}
2528
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002529int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 void __user *buffer, size_t *lenp, loff_t *ppos)
2531{
2532 return -ENOSYS;
2533}
2534
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002535int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 struct file *filp,
2537 void __user *buffer,
2538 size_t *lenp, loff_t *ppos)
2539{
2540 return -ENOSYS;
2541}
2542
2543
2544#endif /* CONFIG_PROC_FS */
2545
2546
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002547#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548/*
2549 * General sysctl support routines
2550 */
2551
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002552/* The generic sysctl data routine (used if no strategy routine supplied) */
2553int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2554 void __user *oldval, size_t __user *oldlenp,
2555 void __user *newval, size_t newlen)
2556{
2557 size_t len;
2558
2559 /* Get out of I don't have a variable */
2560 if (!table->data || !table->maxlen)
2561 return -ENOTDIR;
2562
2563 if (oldval && oldlenp) {
2564 if (get_user(len, oldlenp))
2565 return -EFAULT;
2566 if (len) {
2567 if (len > table->maxlen)
2568 len = table->maxlen;
2569 if (copy_to_user(oldval, table->data, len))
2570 return -EFAULT;
2571 if (put_user(len, oldlenp))
2572 return -EFAULT;
2573 }
2574 }
2575
2576 if (newval && newlen) {
2577 if (newlen > table->maxlen)
2578 newlen = table->maxlen;
2579
2580 if (copy_from_user(table->data, newval, newlen))
2581 return -EFAULT;
2582 }
2583 return 1;
2584}
2585
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002587int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002589 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 if (!table->data || !table->maxlen)
2592 return -ENOTDIR;
2593
2594 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002595 size_t bufsize;
2596 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002598 if (bufsize) {
2599 size_t len = strlen(table->data), copied;
2600
2601 /* This shouldn't trigger for a well-formed sysctl */
2602 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002604
2605 /* Copy up to a max of bufsize-1 bytes of the string */
2606 copied = (len >= bufsize) ? bufsize - 1 : len;
2607
2608 if (copy_to_user(oldval, table->data, copied) ||
2609 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002611 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 return -EFAULT;
2613 }
2614 }
2615 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002616 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 if (len > table->maxlen)
2618 len = table->maxlen;
2619 if(copy_from_user(table->data, newval, len))
2620 return -EFAULT;
2621 if (len == table->maxlen)
2622 len--;
2623 ((char *) table->data)[len] = 0;
2624 }
Yi Yang82c9df82005-12-30 16:37:10 +08002625 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626}
2627
2628/*
2629 * This function makes sure that all of the integers in the vector
2630 * are between the minimum and maximum values given in the arrays
2631 * table->extra1 and table->extra2, respectively.
2632 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002633int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002635 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636{
2637
2638 if (newval && newlen) {
2639 int __user *vec = (int __user *) newval;
2640 int *min = (int *) table->extra1;
2641 int *max = (int *) table->extra2;
2642 size_t length;
2643 int i;
2644
2645 if (newlen % sizeof(int) != 0)
2646 return -EINVAL;
2647
2648 if (!table->extra1 && !table->extra2)
2649 return 0;
2650
2651 if (newlen > table->maxlen)
2652 newlen = table->maxlen;
2653 length = newlen / sizeof(int);
2654
2655 for (i = 0; i < length; i++) {
2656 int value;
2657 if (get_user(value, vec + i))
2658 return -EFAULT;
2659 if (min && value < min[i])
2660 return -EINVAL;
2661 if (max && value > max[i])
2662 return -EINVAL;
2663 }
2664 }
2665 return 0;
2666}
2667
2668/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002669int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002671 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002673 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002675
2676 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002678 if (olen) {
2679 int val;
2680
2681 if (olen < sizeof(int))
2682 return -EINVAL;
2683
2684 val = *(int *)(table->data) / HZ;
2685 if (put_user(val, (int __user *)oldval))
2686 return -EFAULT;
2687 if (put_user(sizeof(int), oldlenp))
2688 return -EFAULT;
2689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 }
2691 if (newval && newlen) {
2692 int new;
2693 if (newlen != sizeof(int))
2694 return -EINVAL;
2695 if (get_user(new, (int __user *)newval))
2696 return -EFAULT;
2697 *(int *)(table->data) = new*HZ;
2698 }
2699 return 1;
2700}
2701
2702/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002703int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002705 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002707 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002709
2710 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002712 if (olen) {
2713 int val;
2714
2715 if (olen < sizeof(int))
2716 return -EINVAL;
2717
2718 val = jiffies_to_msecs(*(int *)(table->data));
2719 if (put_user(val, (int __user *)oldval))
2720 return -EFAULT;
2721 if (put_user(sizeof(int), oldlenp))
2722 return -EFAULT;
2723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 }
2725 if (newval && newlen) {
2726 int new;
2727 if (newlen != sizeof(int))
2728 return -EINVAL;
2729 if (get_user(new, (int __user *)newval))
2730 return -EFAULT;
2731 *(int *)(table->data) = msecs_to_jiffies(new);
2732 }
2733 return 1;
2734}
2735
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002736
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002737
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002738#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
2740
2741asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2742{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002743 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002744 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002745
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002746 if (copy_from_user(&tmp, args, sizeof(tmp)))
2747 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002748
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002749 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002750
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002751 /* If no error reading the parameters then just -ENOSYS ... */
2752 if (!error)
2753 error = -ENOSYS;
2754
2755 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756}
2757
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002758int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2759 void __user *oldval, size_t __user *oldlenp,
2760 void __user *newval, size_t newlen)
2761{
2762 return -ENOSYS;
2763}
2764
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002765int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002767 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768{
2769 return -ENOSYS;
2770}
2771
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002772int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002774 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775{
2776 return -ENOSYS;
2777}
2778
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002779int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002781 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782{
2783 return -ENOSYS;
2784}
2785
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002786int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002788 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789{
2790 return -ENOSYS;
2791}
2792
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002793#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002795static int deprecated_sysctl_warning(struct __sysctl_args *args)
2796{
2797 static int msg_count;
2798 int name[CTL_MAXNAME];
2799 int i;
2800
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002801 /* Check args->nlen. */
2802 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2803 return -ENOTDIR;
2804
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002805 /* Read in the sysctl name for better debug message logging */
2806 for (i = 0; i < args->nlen; i++)
2807 if (get_user(name[i], args->name + i))
2808 return -EFAULT;
2809
2810 /* Ignore accesses to kernel.version */
2811 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2812 return 0;
2813
2814 if (msg_count < 5) {
2815 msg_count++;
2816 printk(KERN_INFO
2817 "warning: process `%s' used the deprecated sysctl "
2818 "system call with ", current->comm);
2819 for (i = 0; i < args->nlen; i++)
2820 printk("%d.", name[i]);
2821 printk("\n");
2822 }
2823 return 0;
2824}
2825
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826/*
2827 * No sense putting this after each symbol definition, twice,
2828 * exception granted :-)
2829 */
2830EXPORT_SYMBOL(proc_dointvec);
2831EXPORT_SYMBOL(proc_dointvec_jiffies);
2832EXPORT_SYMBOL(proc_dointvec_minmax);
2833EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2834EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2835EXPORT_SYMBOL(proc_dostring);
2836EXPORT_SYMBOL(proc_doulongvec_minmax);
2837EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2838EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002839EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840EXPORT_SYMBOL(sysctl_intvec);
2841EXPORT_SYMBOL(sysctl_jiffies);
2842EXPORT_SYMBOL(sysctl_ms_jiffies);
2843EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002844EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845EXPORT_SYMBOL(unregister_sysctl_table);