blob: 357b68ba23ecd7975f93e4273787cf1041ca8df8 [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>
40#include <linux/security.h>
41#include <linux/initrd.h>
42#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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070072extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int pid_max;
75extern int min_free_kbytes;
76extern int printk_ratelimit_jiffies;
77extern int printk_ratelimit_burst;
78extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080079extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080080extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020081extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070082extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070083extern int sysctl_stat_interval;
Peter Zijlstrabdf4c482007-07-19 01:48:15 -070084extern int audit_argv_kb;
Arjan van de Ven97455122008-01-25 21:08:34 +010085extern int latencytop_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070087/* Constants used for minimum and maximum */
88#ifdef CONFIG_DETECT_SOFTLOCKUP
89static int one = 1;
90static int sixty = 60;
91#endif
92
93#ifdef CONFIG_MMU
94static int two = 2;
95#endif
96
97static int zero;
98static int one_hundred = 100;
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
101static int maxolduid = 65535;
102static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800103static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105static int ngroups_max = NGROUPS_MAX;
106
107#ifdef CONFIG_KMOD
108extern char modprobe_path[];
109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#ifdef CONFIG_CHR_DEV_SG
111extern int sg_big_buff;
112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114#ifdef __sparc__
115extern char reboot_command [];
116extern int stop_a_enabled;
117extern int scons_pwroff;
118#endif
119
120#ifdef __hppa__
121extern int pwrsw_enabled;
122extern int unaligned_enabled;
123#endif
124
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800125#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#ifdef CONFIG_MATHEMU
127extern int sysctl_ieee_emulation_warnings;
128#endif
129extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700130extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#endif
132
133extern int sysctl_hz_timer;
134
135#ifdef CONFIG_BSD_PROCESS_ACCT
136extern int acct_parm[];
137#endif
138
Jes Sorensend2b176e2006-02-28 09:42:23 -0800139#ifdef CONFIG_IA64
140extern int no_unaligned_warning;
141#endif
142
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700143#ifdef CONFIG_RT_MUTEXES
144extern int max_lock_depth;
145#endif
146
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700147#ifdef CONFIG_SYSCTL_SYSCALL
148static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700149 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700150#endif
151
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800152
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700153#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700154static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800157 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700158#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700159
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700160static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100161static struct ctl_table_root sysctl_table_root;
162static struct ctl_table_header root_table_header = {
163 .ctl_table = root_table,
164 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
165 .root = &sysctl_table_root,
166};
167static struct ctl_table_root sysctl_table_root = {
168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
169 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
170};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700172static struct ctl_table kern_table[];
173static struct ctl_table vm_table[];
174static struct ctl_table fs_table[];
175static struct ctl_table debug_table[];
176static struct ctl_table dev_table[];
177extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700178#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700179extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400180#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
182#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183int sysctl_legacy_va_layout;
184#endif
185
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700186extern int prove_locking;
187extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/* The default sysctl tables: */
190
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700191static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
195 .mode = 0555,
196 .child = kern_table,
197 },
198 {
199 .ctl_name = CTL_VM,
200 .procname = "vm",
201 .mode = 0555,
202 .child = vm_table,
203 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 .ctl_name = CTL_FS,
206 .procname = "fs",
207 .mode = 0555,
208 .child = fs_table,
209 },
210 {
211 .ctl_name = CTL_DEBUG,
212 .procname = "debug",
213 .mode = 0555,
214 .child = debug_table,
215 },
216 {
217 .ctl_name = CTL_DEV,
218 .procname = "dev",
219 .mode = 0555,
220 .child = dev_table,
221 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700222/*
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
225 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 { .ctl_name = 0 }
227};
228
Ingo Molnar77e54a12007-07-09 18:52:00 +0200229#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100230static int min_sched_granularity_ns = 100000; /* 100 usecs */
231static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
232static int min_wakeup_granularity_ns; /* 0 usecs */
233static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200234#endif
235
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700236static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200237#ifdef CONFIG_SCHED_DEBUG
238 {
239 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100240 .procname = "sched_min_granularity_ns",
241 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200242 .maxlen = sizeof(unsigned int),
243 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100244 .proc_handler = &sched_nr_latency_handler,
245 .strategy = &sysctl_intvec,
246 .extra1 = &min_sched_granularity_ns,
247 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200248 },
249 {
250 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200251 .procname = "sched_latency_ns",
252 .data = &sysctl_sched_latency,
253 .maxlen = sizeof(unsigned int),
254 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100255 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
259 },
260 {
261 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200262 .procname = "sched_wakeup_granularity_ns",
263 .data = &sysctl_sched_wakeup_granularity,
264 .maxlen = sizeof(unsigned int),
265 .mode = 0644,
266 .proc_handler = &proc_dointvec_minmax,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_wakeup_granularity_ns,
269 .extra2 = &max_wakeup_granularity_ns,
270 },
271 {
272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_batch_wakeup_granularity_ns",
274 .data = &sysctl_sched_batch_wakeup_granularity,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
277 .proc_handler = &proc_dointvec_minmax,
278 .strategy = &sysctl_intvec,
279 .extra1 = &min_wakeup_granularity_ns,
280 .extra2 = &max_wakeup_granularity_ns,
281 },
282 {
283 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200284 .procname = "sched_child_runs_first",
285 .data = &sysctl_sched_child_runs_first,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
288 .proc_handler = &proc_dointvec,
289 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200290 {
291 .ctl_name = CTL_UNNUMBERED,
292 .procname = "sched_features",
293 .data = &sysctl_sched_features,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec,
297 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200298 {
299 .ctl_name = CTL_UNNUMBERED,
300 .procname = "sched_migration_cost",
301 .data = &sysctl_sched_migration_cost,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = &proc_dointvec,
305 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100306 {
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_nr_migrate",
309 .data = &sysctl_sched_nr_migrate,
310 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100311 .mode = 0644,
312 .proc_handler = &proc_dointvec,
313 },
314 {
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_rt_period_ms",
317 .data = &sysctl_sched_rt_period,
318 .maxlen = sizeof(unsigned int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
321 },
322 {
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_rt_ratio",
325 .data = &sysctl_sched_rt_ratio,
326 .maxlen = sizeof(unsigned int),
327 .mode = 0644,
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100328 .proc_handler = &proc_dointvec,
329 },
Srivatsa Vaddagiri6b2d7702008-01-25 21:08:00 +0100330#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
331 {
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_min_bal_int_shares",
334 .data = &sysctl_sched_min_bal_int_shares,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
338 },
339 {
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_max_bal_int_shares",
342 .data = &sysctl_sched_max_bal_int_shares,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
345 .proc_handler = &proc_dointvec,
346 },
347#endif
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200348#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200349 {
350 .ctl_name = CTL_UNNUMBERED,
351 .procname = "sched_compat_yield",
352 .data = &sysctl_sched_compat_yield,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec,
356 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700357#ifdef CONFIG_PROVE_LOCKING
358 {
359 .ctl_name = CTL_UNNUMBERED,
360 .procname = "prove_locking",
361 .data = &prove_locking,
362 .maxlen = sizeof(int),
363 .mode = 0644,
364 .proc_handler = &proc_dointvec,
365 },
366#endif
367#ifdef CONFIG_LOCK_STAT
368 {
369 .ctl_name = CTL_UNNUMBERED,
370 .procname = "lock_stat",
371 .data = &lock_stat,
372 .maxlen = sizeof(int),
373 .mode = 0644,
374 .proc_handler = &proc_dointvec,
375 },
376#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200377 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 .ctl_name = KERN_PANIC,
379 .procname = "panic",
380 .data = &panic_timeout,
381 .maxlen = sizeof(int),
382 .mode = 0644,
383 .proc_handler = &proc_dointvec,
384 },
385 {
386 .ctl_name = KERN_CORE_USES_PID,
387 .procname = "core_uses_pid",
388 .data = &core_uses_pid,
389 .maxlen = sizeof(int),
390 .mode = 0644,
391 .proc_handler = &proc_dointvec,
392 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700393#ifdef CONFIG_AUDITSYSCALL
394 {
395 .ctl_name = CTL_UNNUMBERED,
396 .procname = "audit_argv_kb",
397 .data = &audit_argv_kb,
398 .maxlen = sizeof(int),
399 .mode = 0644,
400 .proc_handler = &proc_dointvec,
401 },
402#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 {
404 .ctl_name = KERN_CORE_PATTERN,
405 .procname = "core_pattern",
406 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700407 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 .mode = 0644,
409 .proc_handler = &proc_dostring,
410 .strategy = &sysctl_string,
411 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800412#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 .procname = "tainted",
415 .data = &tainted,
416 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800417 .mode = 0644,
418 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800420#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100421#ifdef CONFIG_LATENCYTOP
422 {
423 .procname = "latencytop",
424 .data = &latencytop_enabled,
425 .maxlen = sizeof(int),
426 .mode = 0644,
427 .proc_handler = &proc_dointvec,
428 },
429#endif
Andrew Morgan72c2d582007-10-18 03:05:59 -0700430#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 .procname = "cap-bound",
433 .data = &cap_bset,
434 .maxlen = sizeof(kernel_cap_t),
435 .mode = 0600,
436 .proc_handler = &proc_dointvec_bset,
437 },
Andrew Morgan72c2d582007-10-18 03:05:59 -0700438#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#ifdef CONFIG_BLK_DEV_INITRD
440 {
441 .ctl_name = KERN_REALROOTDEV,
442 .procname = "real-root-dev",
443 .data = &real_root_dev,
444 .maxlen = sizeof(int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
447 },
448#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700449 {
450 .ctl_name = CTL_UNNUMBERED,
451 .procname = "print-fatal-signals",
452 .data = &print_fatal_signals,
453 .maxlen = sizeof(int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
456 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457#ifdef __sparc__
458 {
459 .ctl_name = KERN_SPARC_REBOOT,
460 .procname = "reboot-cmd",
461 .data = reboot_command,
462 .maxlen = 256,
463 .mode = 0644,
464 .proc_handler = &proc_dostring,
465 .strategy = &sysctl_string,
466 },
467 {
468 .ctl_name = KERN_SPARC_STOP_A,
469 .procname = "stop-a",
470 .data = &stop_a_enabled,
471 .maxlen = sizeof (int),
472 .mode = 0644,
473 .proc_handler = &proc_dointvec,
474 },
475 {
476 .ctl_name = KERN_SPARC_SCONS_PWROFF,
477 .procname = "scons-poweroff",
478 .data = &scons_pwroff,
479 .maxlen = sizeof (int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
482 },
483#endif
484#ifdef __hppa__
485 {
486 .ctl_name = KERN_HPPA_PWRSW,
487 .procname = "soft-power",
488 .data = &pwrsw_enabled,
489 .maxlen = sizeof (int),
490 .mode = 0644,
491 .proc_handler = &proc_dointvec,
492 },
493 {
494 .ctl_name = KERN_HPPA_UNALIGNED,
495 .procname = "unaligned-trap",
496 .data = &unaligned_enabled,
497 .maxlen = sizeof (int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
500 },
501#endif
502 {
503 .ctl_name = KERN_CTLALTDEL,
504 .procname = "ctrl-alt-del",
505 .data = &C_A_D,
506 .maxlen = sizeof(int),
507 .mode = 0644,
508 .proc_handler = &proc_dointvec,
509 },
510 {
511 .ctl_name = KERN_PRINTK,
512 .procname = "printk",
513 .data = &console_loglevel,
514 .maxlen = 4*sizeof(int),
515 .mode = 0644,
516 .proc_handler = &proc_dointvec,
517 },
518#ifdef CONFIG_KMOD
519 {
520 .ctl_name = KERN_MODPROBE,
521 .procname = "modprobe",
522 .data = &modprobe_path,
523 .maxlen = KMOD_PATH_LEN,
524 .mode = 0644,
525 .proc_handler = &proc_dostring,
526 .strategy = &sysctl_string,
527 },
528#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700529#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 {
531 .ctl_name = KERN_HOTPLUG,
532 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100533 .data = &uevent_helper,
534 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 .mode = 0644,
536 .proc_handler = &proc_dostring,
537 .strategy = &sysctl_string,
538 },
539#endif
540#ifdef CONFIG_CHR_DEV_SG
541 {
542 .ctl_name = KERN_SG_BIG_BUFF,
543 .procname = "sg-big-buff",
544 .data = &sg_big_buff,
545 .maxlen = sizeof (int),
546 .mode = 0444,
547 .proc_handler = &proc_dointvec,
548 },
549#endif
550#ifdef CONFIG_BSD_PROCESS_ACCT
551 {
552 .ctl_name = KERN_ACCT,
553 .procname = "acct",
554 .data = &acct_parm,
555 .maxlen = 3*sizeof(int),
556 .mode = 0644,
557 .proc_handler = &proc_dointvec,
558 },
559#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#ifdef CONFIG_MAGIC_SYSRQ
561 {
562 .ctl_name = KERN_SYSRQ,
563 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800564 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .maxlen = sizeof (int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700570#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700573 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .maxlen = sizeof (int),
575 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700576 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700578#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 {
580 .ctl_name = KERN_MAX_THREADS,
581 .procname = "threads-max",
582 .data = &max_threads,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec,
586 },
587 {
588 .ctl_name = KERN_RANDOM,
589 .procname = "random",
590 .mode = 0555,
591 .child = random_table,
592 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 {
594 .ctl_name = KERN_OVERFLOWUID,
595 .procname = "overflowuid",
596 .data = &overflowuid,
597 .maxlen = sizeof(int),
598 .mode = 0644,
599 .proc_handler = &proc_dointvec_minmax,
600 .strategy = &sysctl_intvec,
601 .extra1 = &minolduid,
602 .extra2 = &maxolduid,
603 },
604 {
605 .ctl_name = KERN_OVERFLOWGID,
606 .procname = "overflowgid",
607 .data = &overflowgid,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec_minmax,
611 .strategy = &sysctl_intvec,
612 .extra1 = &minolduid,
613 .extra2 = &maxolduid,
614 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800615#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616#ifdef CONFIG_MATHEMU
617 {
618 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
619 .procname = "ieee_emulation_warnings",
620 .data = &sysctl_ieee_emulation_warnings,
621 .maxlen = sizeof(int),
622 .mode = 0644,
623 .proc_handler = &proc_dointvec,
624 },
625#endif
626#ifdef CONFIG_NO_IDLE_HZ
627 {
628 .ctl_name = KERN_HZ_TIMER,
629 .procname = "hz_timer",
630 .data = &sysctl_hz_timer,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
634 },
635#endif
636 {
637 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
638 .procname = "userprocess_debug",
639 .data = &sysctl_userprocess_debug,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec,
643 },
644#endif
645 {
646 .ctl_name = KERN_PIDMAX,
647 .procname = "pid_max",
648 .data = &pid_max,
649 .maxlen = sizeof (int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec_minmax,
652 .strategy = sysctl_intvec,
653 .extra1 = &pid_max_min,
654 .extra2 = &pid_max_max,
655 },
656 {
657 .ctl_name = KERN_PANIC_ON_OOPS,
658 .procname = "panic_on_oops",
659 .data = &panic_on_oops,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
664 {
665 .ctl_name = KERN_PRINTK_RATELIMIT,
666 .procname = "printk_ratelimit",
667 .data = &printk_ratelimit_jiffies,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec_jiffies,
671 .strategy = &sysctl_jiffies,
672 },
673 {
674 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
675 .procname = "printk_ratelimit_burst",
676 .data = &printk_ratelimit_burst,
677 .maxlen = sizeof(int),
678 .mode = 0644,
679 .proc_handler = &proc_dointvec,
680 },
681 {
682 .ctl_name = KERN_NGROUPS_MAX,
683 .procname = "ngroups_max",
684 .data = &ngroups_max,
685 .maxlen = sizeof (int),
686 .mode = 0444,
687 .proc_handler = &proc_dointvec,
688 },
689#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
690 {
691 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
692 .procname = "unknown_nmi_panic",
693 .data = &unknown_nmi_panic,
694 .maxlen = sizeof (int),
695 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200696 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 },
Don Zickus407984f2006-09-26 10:52:27 +0200698 {
Don Zickus407984f2006-09-26 10:52:27 +0200699 .procname = "nmi_watchdog",
700 .data = &nmi_watchdog_enabled,
701 .maxlen = sizeof (int),
702 .mode = 0644,
703 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 },
705#endif
706#if defined(CONFIG_X86)
707 {
Don Zickus8da5add2006-09-26 10:52:27 +0200708 .ctl_name = KERN_PANIC_ON_NMI,
709 .procname = "panic_on_unrecovered_nmi",
710 .data = &panic_on_unrecovered_nmi,
711 .maxlen = sizeof(int),
712 .mode = 0644,
713 .proc_handler = &proc_dointvec,
714 },
715 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 .ctl_name = KERN_BOOTLOADER_TYPE,
717 .procname = "bootloader_type",
718 .data = &bootloader_type,
719 .maxlen = sizeof (int),
720 .mode = 0444,
721 .proc_handler = &proc_dointvec,
722 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100723 {
724 .ctl_name = CTL_UNNUMBERED,
725 .procname = "kstack_depth_to_print",
726 .data = &kstack_depth_to_print,
727 .maxlen = sizeof(int),
728 .mode = 0644,
729 .proc_handler = &proc_dointvec,
730 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100731 {
732 .ctl_name = CTL_UNNUMBERED,
733 .procname = "io_delay_type",
734 .data = &io_delay_type,
735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
738 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800740#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 {
742 .ctl_name = KERN_RANDOMIZE,
743 .procname = "randomize_va_space",
744 .data = &randomize_va_space,
745 .maxlen = sizeof(int),
746 .mode = 0644,
747 .proc_handler = &proc_dointvec,
748 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800749#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800750#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700751 {
752 .ctl_name = KERN_SPIN_RETRY,
753 .procname = "spin_retry",
754 .data = &spin_retry,
755 .maxlen = sizeof (int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
758 },
759#endif
Len Brown673d5b42007-07-28 03:33:16 -0400760#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800761 {
Pavel Machekc255d842006-02-20 18:27:58 -0800762 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700763 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800764 .maxlen = sizeof (unsigned long),
765 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800766 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800767 },
768#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800769#ifdef CONFIG_IA64
770 {
771 .ctl_name = KERN_IA64_UNALIGNED,
772 .procname = "ignore-unaligned-usertrap",
773 .data = &no_unaligned_warning,
774 .maxlen = sizeof (int),
775 .mode = 0644,
776 .proc_handler = &proc_dointvec,
777 },
778#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700779#ifdef CONFIG_DETECT_SOFTLOCKUP
780 {
781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "softlockup_thresh",
783 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100784 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700785 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100786 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700787 .strategy = &sysctl_intvec,
788 .extra1 = &one,
789 .extra2 = &sixty,
790 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100791 {
792 .ctl_name = CTL_UNNUMBERED,
793 .procname = "hung_task_check_count",
794 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100795 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100796 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100797 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100798 .strategy = &sysctl_intvec,
799 },
800 {
801 .ctl_name = CTL_UNNUMBERED,
802 .procname = "hung_task_timeout_secs",
803 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100804 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100805 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100806 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100807 .strategy = &sysctl_intvec,
808 },
809 {
810 .ctl_name = CTL_UNNUMBERED,
811 .procname = "hung_task_warnings",
812 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100813 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100814 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100815 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100816 .strategy = &sysctl_intvec,
817 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700818#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200819#ifdef CONFIG_COMPAT
820 {
821 .ctl_name = KERN_COMPAT_LOG,
822 .procname = "compat-log",
823 .data = &compat_log,
824 .maxlen = sizeof (int),
825 .mode = 0644,
826 .proc_handler = &proc_dointvec,
827 },
828#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700829#ifdef CONFIG_RT_MUTEXES
830 {
831 .ctl_name = KERN_MAX_LOCK_DEPTH,
832 .procname = "max_lock_depth",
833 .data = &max_lock_depth,
834 .maxlen = sizeof(int),
835 .mode = 0644,
836 .proc_handler = &proc_dointvec,
837 },
838#endif
Kees Cook5096add2007-05-08 00:26:04 -0700839#ifdef CONFIG_PROC_FS
840 {
841 .ctl_name = CTL_UNNUMBERED,
842 .procname = "maps_protect",
843 .data = &maps_protect,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec,
847 },
848#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700849 {
850 .ctl_name = CTL_UNNUMBERED,
851 .procname = "poweroff_cmd",
852 .data = &poweroff_cmd,
853 .maxlen = POWEROFF_CMD_PATH_LEN,
854 .mode = 0644,
855 .proc_handler = &proc_dostring,
856 .strategy = &sysctl_string,
857 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700858/*
859 * NOTE: do not add new entries to this table unless you have read
860 * Documentation/sysctl/ctl_unnumbered.txt
861 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 { .ctl_name = 0 }
863};
864
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700865static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 {
867 .ctl_name = VM_OVERCOMMIT_MEMORY,
868 .procname = "overcommit_memory",
869 .data = &sysctl_overcommit_memory,
870 .maxlen = sizeof(sysctl_overcommit_memory),
871 .mode = 0644,
872 .proc_handler = &proc_dointvec,
873 },
874 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700875 .ctl_name = VM_PANIC_ON_OOM,
876 .procname = "panic_on_oom",
877 .data = &sysctl_panic_on_oom,
878 .maxlen = sizeof(sysctl_panic_on_oom),
879 .mode = 0644,
880 .proc_handler = &proc_dointvec,
881 },
882 {
David Rientjesfe071d72007-10-16 23:25:56 -0700883 .ctl_name = CTL_UNNUMBERED,
884 .procname = "oom_kill_allocating_task",
885 .data = &sysctl_oom_kill_allocating_task,
886 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
887 .mode = 0644,
888 .proc_handler = &proc_dointvec,
889 },
890 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 .ctl_name = VM_OVERCOMMIT_RATIO,
892 .procname = "overcommit_ratio",
893 .data = &sysctl_overcommit_ratio,
894 .maxlen = sizeof(sysctl_overcommit_ratio),
895 .mode = 0644,
896 .proc_handler = &proc_dointvec,
897 },
898 {
899 .ctl_name = VM_PAGE_CLUSTER,
900 .procname = "page-cluster",
901 .data = &page_cluster,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = &proc_dointvec,
905 },
906 {
907 .ctl_name = VM_DIRTY_BACKGROUND,
908 .procname = "dirty_background_ratio",
909 .data = &dirty_background_ratio,
910 .maxlen = sizeof(dirty_background_ratio),
911 .mode = 0644,
912 .proc_handler = &proc_dointvec_minmax,
913 .strategy = &sysctl_intvec,
914 .extra1 = &zero,
915 .extra2 = &one_hundred,
916 },
917 {
918 .ctl_name = VM_DIRTY_RATIO,
919 .procname = "dirty_ratio",
920 .data = &vm_dirty_ratio,
921 .maxlen = sizeof(vm_dirty_ratio),
922 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700923 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 .strategy = &sysctl_intvec,
925 .extra1 = &zero,
926 .extra2 = &one_hundred,
927 },
928 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800930 .data = &dirty_writeback_interval,
931 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 .mode = 0644,
933 .proc_handler = &dirty_writeback_centisecs_handler,
934 },
935 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800937 .data = &dirty_expire_interval,
938 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800940 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 },
942 {
943 .ctl_name = VM_NR_PDFLUSH_THREADS,
944 .procname = "nr_pdflush_threads",
945 .data = &nr_pdflush_threads,
946 .maxlen = sizeof nr_pdflush_threads,
947 .mode = 0444 /* read-only*/,
948 .proc_handler = &proc_dointvec,
949 },
950 {
951 .ctl_name = VM_SWAPPINESS,
952 .procname = "swappiness",
953 .data = &vm_swappiness,
954 .maxlen = sizeof(vm_swappiness),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec_minmax,
957 .strategy = &sysctl_intvec,
958 .extra1 = &zero,
959 .extra2 = &one_hundred,
960 },
961#ifdef CONFIG_HUGETLB_PAGE
962 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 .procname = "nr_hugepages",
964 .data = &max_huge_pages,
965 .maxlen = sizeof(unsigned long),
966 .mode = 0644,
967 .proc_handler = &hugetlb_sysctl_handler,
968 .extra1 = (void *)&hugetlb_zero,
969 .extra2 = (void *)&hugetlb_infinity,
970 },
971 {
972 .ctl_name = VM_HUGETLB_GROUP,
973 .procname = "hugetlb_shm_group",
974 .data = &sysctl_hugetlb_shm_group,
975 .maxlen = sizeof(gid_t),
976 .mode = 0644,
977 .proc_handler = &proc_dointvec,
978 },
Mel Gorman396faf02007-07-17 04:03:13 -0700979 {
980 .ctl_name = CTL_UNNUMBERED,
981 .procname = "hugepages_treat_as_movable",
982 .data = &hugepages_treat_as_movable,
983 .maxlen = sizeof(int),
984 .mode = 0644,
985 .proc_handler = &hugetlb_treat_movable_handler,
986 },
Adam Litke54f9f802007-10-16 01:26:20 -0700987 {
988 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800989 .procname = "nr_overcommit_hugepages",
990 .data = &nr_overcommit_huge_pages,
991 .maxlen = sizeof(nr_overcommit_huge_pages),
992 .mode = 0644,
993 .proc_handler = &proc_doulongvec_minmax,
994 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995#endif
996 {
997 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
998 .procname = "lowmem_reserve_ratio",
999 .data = &sysctl_lowmem_reserve_ratio,
1000 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1001 .mode = 0644,
1002 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1003 .strategy = &sysctl_intvec,
1004 },
1005 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001006 .ctl_name = VM_DROP_PAGECACHE,
1007 .procname = "drop_caches",
1008 .data = &sysctl_drop_caches,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
1011 .proc_handler = drop_caches_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1013 },
1014 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .ctl_name = VM_MIN_FREE_KBYTES,
1016 .procname = "min_free_kbytes",
1017 .data = &min_free_kbytes,
1018 .maxlen = sizeof(min_free_kbytes),
1019 .mode = 0644,
1020 .proc_handler = &min_free_kbytes_sysctl_handler,
1021 .strategy = &sysctl_intvec,
1022 .extra1 = &zero,
1023 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001024 {
1025 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1026 .procname = "percpu_pagelist_fraction",
1027 .data = &percpu_pagelist_fraction,
1028 .maxlen = sizeof(percpu_pagelist_fraction),
1029 .mode = 0644,
1030 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1031 .strategy = &sysctl_intvec,
1032 .extra1 = &min_percpu_pagelist_fract,
1033 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034#ifdef CONFIG_MMU
1035 {
1036 .ctl_name = VM_MAX_MAP_COUNT,
1037 .procname = "max_map_count",
1038 .data = &sysctl_max_map_count,
1039 .maxlen = sizeof(sysctl_max_map_count),
1040 .mode = 0644,
1041 .proc_handler = &proc_dointvec
1042 },
1043#endif
1044 {
1045 .ctl_name = VM_LAPTOP_MODE,
1046 .procname = "laptop_mode",
1047 .data = &laptop_mode,
1048 .maxlen = sizeof(laptop_mode),
1049 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001050 .proc_handler = &proc_dointvec_jiffies,
1051 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 },
1053 {
1054 .ctl_name = VM_BLOCK_DUMP,
1055 .procname = "block_dump",
1056 .data = &block_dump,
1057 .maxlen = sizeof(block_dump),
1058 .mode = 0644,
1059 .proc_handler = &proc_dointvec,
1060 .strategy = &sysctl_intvec,
1061 .extra1 = &zero,
1062 },
1063 {
1064 .ctl_name = VM_VFS_CACHE_PRESSURE,
1065 .procname = "vfs_cache_pressure",
1066 .data = &sysctl_vfs_cache_pressure,
1067 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1068 .mode = 0644,
1069 .proc_handler = &proc_dointvec,
1070 .strategy = &sysctl_intvec,
1071 .extra1 = &zero,
1072 },
1073#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1074 {
1075 .ctl_name = VM_LEGACY_VA_LAYOUT,
1076 .procname = "legacy_va_layout",
1077 .data = &sysctl_legacy_va_layout,
1078 .maxlen = sizeof(sysctl_legacy_va_layout),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec,
1081 .strategy = &sysctl_intvec,
1082 .extra1 = &zero,
1083 },
1084#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001085#ifdef CONFIG_NUMA
1086 {
1087 .ctl_name = VM_ZONE_RECLAIM_MODE,
1088 .procname = "zone_reclaim_mode",
1089 .data = &zone_reclaim_mode,
1090 .maxlen = sizeof(zone_reclaim_mode),
1091 .mode = 0644,
1092 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001093 .strategy = &sysctl_intvec,
1094 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001095 },
Christoph Lameter96146342006-07-03 00:24:13 -07001096 {
1097 .ctl_name = VM_MIN_UNMAPPED,
1098 .procname = "min_unmapped_ratio",
1099 .data = &sysctl_min_unmapped_ratio,
1100 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1101 .mode = 0644,
1102 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1103 .strategy = &sysctl_intvec,
1104 .extra1 = &zero,
1105 .extra2 = &one_hundred,
1106 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001107 {
1108 .ctl_name = VM_MIN_SLAB,
1109 .procname = "min_slab_ratio",
1110 .data = &sysctl_min_slab_ratio,
1111 .maxlen = sizeof(sysctl_min_slab_ratio),
1112 .mode = 0644,
1113 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1114 .strategy = &sysctl_intvec,
1115 .extra1 = &zero,
1116 .extra2 = &one_hundred,
1117 },
Christoph Lameter17436602006-01-18 17:42:32 -08001118#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001119#ifdef CONFIG_SMP
1120 {
1121 .ctl_name = CTL_UNNUMBERED,
1122 .procname = "stat_interval",
1123 .data = &sysctl_stat_interval,
1124 .maxlen = sizeof(sysctl_stat_interval),
1125 .mode = 0644,
1126 .proc_handler = &proc_dointvec_jiffies,
1127 .strategy = &sysctl_jiffies,
1128 },
1129#endif
Eric Parised032182007-06-28 15:55:21 -04001130#ifdef CONFIG_SECURITY
1131 {
1132 .ctl_name = CTL_UNNUMBERED,
1133 .procname = "mmap_min_addr",
1134 .data = &mmap_min_addr,
1135 .maxlen = sizeof(unsigned long),
1136 .mode = 0644,
1137 .proc_handler = &proc_doulongvec_minmax,
1138 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001139#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001140#ifdef CONFIG_NUMA
1141 {
1142 .ctl_name = CTL_UNNUMBERED,
1143 .procname = "numa_zonelist_order",
1144 .data = &numa_zonelist_order,
1145 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1146 .mode = 0644,
1147 .proc_handler = &numa_zonelist_order_handler,
1148 .strategy = &sysctl_string,
1149 },
1150#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001151#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001152 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001153 {
1154 .ctl_name = VM_VDSO_ENABLED,
1155 .procname = "vdso_enabled",
1156 .data = &vdso_enabled,
1157 .maxlen = sizeof(vdso_enabled),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec,
1160 .strategy = &sysctl_intvec,
1161 .extra1 = &zero,
1162 },
1163#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001164/*
1165 * NOTE: do not add new entries to this table unless you have read
1166 * Documentation/sysctl/ctl_unnumbered.txt
1167 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 { .ctl_name = 0 }
1169};
1170
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001171#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001172static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001173 { .ctl_name = 0 }
1174};
1175#endif
1176
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001177static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 {
1179 .ctl_name = FS_NRINODE,
1180 .procname = "inode-nr",
1181 .data = &inodes_stat,
1182 .maxlen = 2*sizeof(int),
1183 .mode = 0444,
1184 .proc_handler = &proc_dointvec,
1185 },
1186 {
1187 .ctl_name = FS_STATINODE,
1188 .procname = "inode-state",
1189 .data = &inodes_stat,
1190 .maxlen = 7*sizeof(int),
1191 .mode = 0444,
1192 .proc_handler = &proc_dointvec,
1193 },
1194 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 .procname = "file-nr",
1196 .data = &files_stat,
1197 .maxlen = 3*sizeof(int),
1198 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001199 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 },
1201 {
1202 .ctl_name = FS_MAXFILE,
1203 .procname = "file-max",
1204 .data = &files_stat.max_files,
1205 .maxlen = sizeof(int),
1206 .mode = 0644,
1207 .proc_handler = &proc_dointvec,
1208 },
1209 {
1210 .ctl_name = FS_DENTRY,
1211 .procname = "dentry-state",
1212 .data = &dentry_stat,
1213 .maxlen = 6*sizeof(int),
1214 .mode = 0444,
1215 .proc_handler = &proc_dointvec,
1216 },
1217 {
1218 .ctl_name = FS_OVERFLOWUID,
1219 .procname = "overflowuid",
1220 .data = &fs_overflowuid,
1221 .maxlen = sizeof(int),
1222 .mode = 0644,
1223 .proc_handler = &proc_dointvec_minmax,
1224 .strategy = &sysctl_intvec,
1225 .extra1 = &minolduid,
1226 .extra2 = &maxolduid,
1227 },
1228 {
1229 .ctl_name = FS_OVERFLOWGID,
1230 .procname = "overflowgid",
1231 .data = &fs_overflowgid,
1232 .maxlen = sizeof(int),
1233 .mode = 0644,
1234 .proc_handler = &proc_dointvec_minmax,
1235 .strategy = &sysctl_intvec,
1236 .extra1 = &minolduid,
1237 .extra2 = &maxolduid,
1238 },
1239 {
1240 .ctl_name = FS_LEASES,
1241 .procname = "leases-enable",
1242 .data = &leases_enable,
1243 .maxlen = sizeof(int),
1244 .mode = 0644,
1245 .proc_handler = &proc_dointvec,
1246 },
1247#ifdef CONFIG_DNOTIFY
1248 {
1249 .ctl_name = FS_DIR_NOTIFY,
1250 .procname = "dir-notify-enable",
1251 .data = &dir_notify_enable,
1252 .maxlen = sizeof(int),
1253 .mode = 0644,
1254 .proc_handler = &proc_dointvec,
1255 },
1256#endif
1257#ifdef CONFIG_MMU
1258 {
1259 .ctl_name = FS_LEASE_TIME,
1260 .procname = "lease-break-time",
1261 .data = &lease_break_time,
1262 .maxlen = sizeof(int),
1263 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001264 .proc_handler = &proc_dointvec_minmax,
1265 .strategy = &sysctl_intvec,
1266 .extra1 = &zero,
1267 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 },
1269 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 .procname = "aio-nr",
1271 .data = &aio_nr,
1272 .maxlen = sizeof(aio_nr),
1273 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001274 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 },
1276 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 .procname = "aio-max-nr",
1278 .data = &aio_max_nr,
1279 .maxlen = sizeof(aio_max_nr),
1280 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001281 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001283#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001284 {
1285 .ctl_name = FS_INOTIFY,
1286 .procname = "inotify",
1287 .mode = 0555,
1288 .child = inotify_table,
1289 },
1290#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001292 {
1293 .ctl_name = KERN_SETUID_DUMPABLE,
1294 .procname = "suid_dumpable",
1295 .data = &suid_dumpable,
1296 .maxlen = sizeof(int),
1297 .mode = 0644,
1298 .proc_handler = &proc_dointvec,
1299 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001300#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1301 {
1302 .ctl_name = CTL_UNNUMBERED,
1303 .procname = "binfmt_misc",
1304 .mode = 0555,
1305 .child = binfmt_misc_table,
1306 },
1307#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001308/*
1309 * NOTE: do not add new entries to this table unless you have read
1310 * Documentation/sysctl/ctl_unnumbered.txt
1311 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 { .ctl_name = 0 }
1313};
1314
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001315static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001316#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001317 {
1318 .ctl_name = CTL_UNNUMBERED,
1319 .procname = "exception-trace",
1320 .data = &show_unhandled_signals,
1321 .maxlen = sizeof(int),
1322 .mode = 0644,
1323 .proc_handler = proc_dointvec
1324 },
1325#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 { .ctl_name = 0 }
1327};
1328
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001329static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001331};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Al Viro330d57f2005-11-04 10:18:40 +00001333static DEFINE_SPINLOCK(sysctl_lock);
1334
1335/* called under sysctl_lock */
1336static int use_table(struct ctl_table_header *p)
1337{
1338 if (unlikely(p->unregistering))
1339 return 0;
1340 p->used++;
1341 return 1;
1342}
1343
1344/* called under sysctl_lock */
1345static void unuse_table(struct ctl_table_header *p)
1346{
1347 if (!--p->used)
1348 if (unlikely(p->unregistering))
1349 complete(p->unregistering);
1350}
1351
1352/* called under sysctl_lock, will reacquire if has to wait */
1353static void start_unregistering(struct ctl_table_header *p)
1354{
1355 /*
1356 * if p->used is 0, nobody will ever touch that entry again;
1357 * we'll eliminate all paths to it before dropping sysctl_lock
1358 */
1359 if (unlikely(p->used)) {
1360 struct completion wait;
1361 init_completion(&wait);
1362 p->unregistering = &wait;
1363 spin_unlock(&sysctl_lock);
1364 wait_for_completion(&wait);
1365 spin_lock(&sysctl_lock);
1366 }
1367 /*
1368 * do not remove from the list until nobody holds it; walking the
1369 * list in do_sysctl() relies on that.
1370 */
1371 list_del_init(&p->ctl_entry);
1372}
1373
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001374void sysctl_head_finish(struct ctl_table_header *head)
1375{
1376 if (!head)
1377 return;
1378 spin_lock(&sysctl_lock);
1379 unuse_table(head);
1380 spin_unlock(&sysctl_lock);
1381}
1382
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001383static struct list_head *
1384lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001385{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001386 struct list_head *header_list;
1387 header_list = &root->header_list;
1388 if (root->lookup)
1389 header_list = root->lookup(root, namespaces);
1390 return header_list;
1391}
1392
1393struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1394 struct ctl_table_header *prev)
1395{
1396 struct ctl_table_root *root;
1397 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001398 struct ctl_table_header *head;
1399 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001400
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001401 spin_lock(&sysctl_lock);
1402 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001403 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001404 tmp = &prev->ctl_entry;
1405 unuse_table(prev);
1406 goto next;
1407 }
1408 tmp = &root_table_header.ctl_entry;
1409 for (;;) {
1410 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1411
1412 if (!use_table(head))
1413 goto next;
1414 spin_unlock(&sysctl_lock);
1415 return head;
1416 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001417 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001418 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001419 header_list = lookup_header_list(root, namespaces);
1420 if (tmp != header_list)
1421 continue;
1422
1423 do {
1424 root = list_entry(root->root_list.next,
1425 struct ctl_table_root, root_list);
1426 if (root == &sysctl_table_root)
1427 goto out;
1428 header_list = lookup_header_list(root, namespaces);
1429 } while (list_empty(header_list));
1430 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001431 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001432out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001433 spin_unlock(&sysctl_lock);
1434 return NULL;
1435}
1436
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001437struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1438{
1439 return __sysctl_head_next(current->nsproxy, prev);
1440}
1441
1442void register_sysctl_root(struct ctl_table_root *root)
1443{
1444 spin_lock(&sysctl_lock);
1445 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1446 spin_unlock(&sysctl_lock);
1447}
1448
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001449#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1451 void __user *newval, size_t newlen)
1452{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001453 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001454 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
1456 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1457 return -ENOTDIR;
1458 if (oldval) {
1459 int old_len;
1460 if (!oldlenp || get_user(old_len, oldlenp))
1461 return -EFAULT;
1462 }
Al Viro330d57f2005-11-04 10:18:40 +00001463
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001464 for (head = sysctl_head_next(NULL); head;
1465 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001466 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001467 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001468 if (error != -ENOTDIR) {
1469 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001470 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001471 }
1472 }
Al Viro330d57f2005-11-04 10:18:40 +00001473 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474}
1475
1476asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1477{
1478 struct __sysctl_args tmp;
1479 int error;
1480
1481 if (copy_from_user(&tmp, args, sizeof(tmp)))
1482 return -EFAULT;
1483
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001484 error = deprecated_sysctl_warning(&tmp);
1485 if (error)
1486 goto out;
1487
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 lock_kernel();
1489 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1490 tmp.newval, tmp.newlen);
1491 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001492out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 return error;
1494}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001495#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001498 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 * some sysctl variables are readonly even to root.
1500 */
1501
1502static int test_perm(int mode, int op)
1503{
1504 if (!current->euid)
1505 mode >>= 6;
1506 else if (in_egroup_p(0))
1507 mode >>= 3;
1508 if ((mode & op & 0007) == op)
1509 return 0;
1510 return -EACCES;
1511}
1512
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001513int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514{
1515 int error;
1516 error = security_sysctl(table, op);
1517 if (error)
1518 return error;
1519 return test_perm(table->mode, op);
1520}
1521
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001522#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523static int parse_table(int __user *name, int nlen,
1524 void __user *oldval, size_t __user *oldlenp,
1525 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001526 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527{
1528 int n;
1529repeat:
1530 if (!nlen)
1531 return -ENOTDIR;
1532 if (get_user(n, name))
1533 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001534 for ( ; table->ctl_name || table->procname; table++) {
1535 if (!table->ctl_name)
1536 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001537 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 int error;
1539 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001540 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 name++;
1543 nlen--;
1544 table = table->child;
1545 goto repeat;
1546 }
1547 error = do_sysctl_strategy(table, name, nlen,
1548 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001549 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 return error;
1551 }
1552 }
1553 return -ENOTDIR;
1554}
1555
1556/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001557int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 int __user *name, int nlen,
1559 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001560 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
1562 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 if (oldval)
1565 op |= 004;
1566 if (newval)
1567 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001568 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 return -EPERM;
1570
1571 if (table->strategy) {
1572 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001573 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 if (rc < 0)
1575 return rc;
1576 if (rc > 0)
1577 return 0;
1578 }
1579
1580 /* If there is no strategy routine, or if the strategy returns
1581 * zero, proceed with automatic r/w */
1582 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001583 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1584 newval, newlen);
1585 if (rc < 0)
1586 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 }
1588 return 0;
1589}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001590#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001592static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1593{
1594 for (; table->ctl_name || table->procname; table++) {
1595 table->parent = parent;
1596 if (table->child)
1597 sysctl_set_parent(table, table->child);
1598 }
1599}
1600
1601static __init int sysctl_init(void)
1602{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001603 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001604 sysctl_set_parent(NULL, root_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001605 err = sysctl_check_table(current->nsproxy, root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001606 return 0;
1607}
1608
1609core_initcall(sysctl_init);
1610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001612 * __register_sysctl_paths - register a sysctl hierarchy
1613 * @root: List of sysctl headers to register on
1614 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001615 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 *
1618 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001619 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001621 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 *
1623 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1624 * must be unique within that level of sysctl
1625 *
1626 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1627 * enter a sysctl file
1628 *
1629 * data - a pointer to data for use by proc_handler
1630 *
1631 * maxlen - the maximum size in bytes of the data
1632 *
1633 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1634 *
1635 * child - a pointer to the child sysctl table if this entry is a directory, or
1636 * %NULL.
1637 *
1638 * proc_handler - the text handler routine (described below)
1639 *
1640 * strategy - the strategy routine (described below)
1641 *
1642 * de - for internal use by the sysctl routines
1643 *
1644 * extra1, extra2 - extra pointers usable by the proc handler routines
1645 *
1646 * Leaf nodes in the sysctl tree will be represented by a single file
1647 * under /proc; non-leaf nodes will be represented by directories.
1648 *
1649 * sysctl(2) can automatically manage read and write requests through
1650 * the sysctl table. The data and maxlen fields of the ctl_table
1651 * struct enable minimal validation of the values being written to be
1652 * performed, and the mode field allows minimal authentication.
1653 *
1654 * More sophisticated management can be enabled by the provision of a
1655 * strategy routine with the table entry. This will be called before
1656 * any automatic read or write of the data is performed.
1657 *
1658 * The strategy routine may return
1659 *
1660 * < 0 - Error occurred (error is passed to user process)
1661 *
1662 * 0 - OK - proceed with automatic read or write.
1663 *
1664 * > 0 - OK - read or write has been done by the strategy routine, so
1665 * return immediately.
1666 *
1667 * There must be a proc_handler routine for any terminal nodes
1668 * mirrored under /proc/sys (non-terminals are handled by a built-in
1669 * directory handler). Several default handlers are available to
1670 * cover common cases -
1671 *
1672 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1673 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1674 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1675 *
1676 * It is the handler's job to read the input buffer from user memory
1677 * and process it. The handler should return 0 on success.
1678 *
1679 * This routine returns %NULL on a failure to register, and a pointer
1680 * to the table header on success.
1681 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001682struct ctl_table_header *__register_sysctl_paths(
1683 struct ctl_table_root *root,
1684 struct nsproxy *namespaces,
1685 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001687 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001688 struct ctl_table_header *header;
1689 struct ctl_table *new, **prevp;
1690 unsigned int n, npath;
1691
1692 /* Count the path components */
1693 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1694 ;
1695
1696 /*
1697 * For each path component, allocate a 2-element ctl_table array.
1698 * The first array element will be filled with the sysctl entry
1699 * for this, the second will be the sentinel (ctl_name == 0).
1700 *
1701 * We allocate everything in one go so that we don't have to
1702 * worry about freeing additional memory in unregister_sysctl_table.
1703 */
1704 header = kzalloc(sizeof(struct ctl_table_header) +
1705 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1706 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001708
1709 new = (struct ctl_table *) (header + 1);
1710
1711 /* Now connect the dots */
1712 prevp = &header->ctl_table;
1713 for (n = 0; n < npath; ++n, ++path) {
1714 /* Copy the procname */
1715 new->procname = path->procname;
1716 new->ctl_name = path->ctl_name;
1717 new->mode = 0555;
1718
1719 *prevp = new;
1720 prevp = &new->child;
1721
1722 new += 2;
1723 }
1724 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001725 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001726
1727 INIT_LIST_HEAD(&header->ctl_entry);
1728 header->used = 0;
1729 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001730 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001731 sysctl_set_parent(NULL, header->ctl_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001732 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001733 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001734 return NULL;
1735 }
Al Viro330d57f2005-11-04 10:18:40 +00001736 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001737 header_list = lookup_header_list(root, namespaces);
1738 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001739 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001740
1741 return header;
1742}
1743
1744/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001745 * register_sysctl_table_path - register a sysctl table hierarchy
1746 * @path: The path to the directory the sysctl table is in.
1747 * @table: the top-level table structure
1748 *
1749 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1750 * array. A completely 0 filled entry terminates the table.
1751 *
1752 * See __register_sysctl_paths for more details.
1753 */
1754struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1755 struct ctl_table *table)
1756{
1757 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1758 path, table);
1759}
1760
1761/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001762 * register_sysctl_table - register a sysctl table hierarchy
1763 * @table: the top-level table structure
1764 *
1765 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1766 * array. A completely 0 filled entry terminates the table.
1767 *
1768 * See register_sysctl_paths for more details.
1769 */
1770struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1771{
1772 static const struct ctl_path null_path[] = { {} };
1773
1774 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775}
1776
1777/**
1778 * unregister_sysctl_table - unregister a sysctl table hierarchy
1779 * @header: the header returned from register_sysctl_table
1780 *
1781 * Unregisters the sysctl table and all children. proc entries may not
1782 * actually be removed until they are no longer used by anyone.
1783 */
1784void unregister_sysctl_table(struct ctl_table_header * header)
1785{
Al Viro330d57f2005-11-04 10:18:40 +00001786 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001787
1788 if (header == NULL)
1789 return;
1790
Al Viro330d57f2005-11-04 10:18:40 +00001791 spin_lock(&sysctl_lock);
1792 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001793 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 kfree(header);
1795}
1796
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001797#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001798struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001799{
1800 return NULL;
1801}
1802
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001803struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1804 struct ctl_table *table)
1805{
1806 return NULL;
1807}
1808
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001809void unregister_sysctl_table(struct ctl_table_header * table)
1810{
1811}
1812
1813#endif /* CONFIG_SYSCTL */
1814
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815/*
1816 * /proc/sys support
1817 */
1818
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001819#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001821static int _proc_do_string(void* data, int maxlen, int write,
1822 struct file *filp, void __user *buffer,
1823 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001824{
1825 size_t len;
1826 char __user *p;
1827 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001828
1829 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001830 *lenp = 0;
1831 return 0;
1832 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001833
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001834 if (write) {
1835 len = 0;
1836 p = buffer;
1837 while (len < *lenp) {
1838 if (get_user(c, p++))
1839 return -EFAULT;
1840 if (c == 0 || c == '\n')
1841 break;
1842 len++;
1843 }
1844 if (len >= maxlen)
1845 len = maxlen-1;
1846 if(copy_from_user(data, buffer, len))
1847 return -EFAULT;
1848 ((char *) data)[len] = 0;
1849 *ppos += *lenp;
1850 } else {
1851 len = strlen(data);
1852 if (len > maxlen)
1853 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001854
1855 if (*ppos > len) {
1856 *lenp = 0;
1857 return 0;
1858 }
1859
1860 data += *ppos;
1861 len -= *ppos;
1862
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001863 if (len > *lenp)
1864 len = *lenp;
1865 if (len)
1866 if(copy_to_user(buffer, data, len))
1867 return -EFAULT;
1868 if (len < *lenp) {
1869 if(put_user('\n', ((char __user *) buffer) + len))
1870 return -EFAULT;
1871 len++;
1872 }
1873 *lenp = len;
1874 *ppos += len;
1875 }
1876 return 0;
1877}
1878
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879/**
1880 * proc_dostring - read a string sysctl
1881 * @table: the sysctl table
1882 * @write: %TRUE if this is a write to the sysctl file
1883 * @filp: the file structure
1884 * @buffer: the user buffer
1885 * @lenp: the size of the user buffer
1886 * @ppos: file position
1887 *
1888 * Reads/writes a string from/to the user buffer. If the kernel
1889 * buffer provided is not large enough to hold the string, the
1890 * string is truncated. The copied string is %NULL-terminated.
1891 * If the string is being read by the user process, it is copied
1892 * and a newline '\n' is added. It is truncated if the buffer is
1893 * not large enough.
1894 *
1895 * Returns 0 on success.
1896 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001897int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 void __user *buffer, size_t *lenp, loff_t *ppos)
1899{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001900 return _proc_do_string(table->data, table->maxlen, write, filp,
1901 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902}
1903
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
1905static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1906 int *valp,
1907 int write, void *data)
1908{
1909 if (write) {
1910 *valp = *negp ? -*lvalp : *lvalp;
1911 } else {
1912 int val = *valp;
1913 if (val < 0) {
1914 *negp = -1;
1915 *lvalp = (unsigned long)-val;
1916 } else {
1917 *negp = 0;
1918 *lvalp = (unsigned long)val;
1919 }
1920 }
1921 return 0;
1922}
1923
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001924static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001925 int write, struct file *filp, void __user *buffer,
1926 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1928 int write, void *data),
1929 void *data)
1930{
1931#define TMPBUFLEN 21
1932 int *i, vleft, first=1, neg, val;
1933 unsigned long lval;
1934 size_t left, len;
1935
1936 char buf[TMPBUFLEN], *p;
1937 char __user *s = buffer;
1938
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001939 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 (*ppos && !write)) {
1941 *lenp = 0;
1942 return 0;
1943 }
1944
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001945 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 vleft = table->maxlen / sizeof(*i);
1947 left = *lenp;
1948
1949 if (!conv)
1950 conv = do_proc_dointvec_conv;
1951
1952 for (; left && vleft--; i++, first=0) {
1953 if (write) {
1954 while (left) {
1955 char c;
1956 if (get_user(c, s))
1957 return -EFAULT;
1958 if (!isspace(c))
1959 break;
1960 left--;
1961 s++;
1962 }
1963 if (!left)
1964 break;
1965 neg = 0;
1966 len = left;
1967 if (len > sizeof(buf) - 1)
1968 len = sizeof(buf) - 1;
1969 if (copy_from_user(buf, s, len))
1970 return -EFAULT;
1971 buf[len] = 0;
1972 p = buf;
1973 if (*p == '-' && left > 1) {
1974 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001975 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 }
1977 if (*p < '0' || *p > '9')
1978 break;
1979
1980 lval = simple_strtoul(p, &p, 0);
1981
1982 len = p-buf;
1983 if ((len < left) && *p && !isspace(*p))
1984 break;
1985 if (neg)
1986 val = -val;
1987 s += len;
1988 left -= len;
1989
1990 if (conv(&neg, &lval, i, 1, data))
1991 break;
1992 } else {
1993 p = buf;
1994 if (!first)
1995 *p++ = '\t';
1996
1997 if (conv(&neg, &lval, i, 0, data))
1998 break;
1999
2000 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2001 len = strlen(buf);
2002 if (len > left)
2003 len = left;
2004 if(copy_to_user(s, buf, len))
2005 return -EFAULT;
2006 left -= len;
2007 s += len;
2008 }
2009 }
2010
2011 if (!write && !first && left) {
2012 if(put_user('\n', s))
2013 return -EFAULT;
2014 left--, s++;
2015 }
2016 if (write) {
2017 while (left) {
2018 char c;
2019 if (get_user(c, s++))
2020 return -EFAULT;
2021 if (!isspace(c))
2022 break;
2023 left--;
2024 }
2025 }
2026 if (write && first)
2027 return -EINVAL;
2028 *lenp -= left;
2029 *ppos += *lenp;
2030 return 0;
2031#undef TMPBUFLEN
2032}
2033
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002034static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002035 void __user *buffer, size_t *lenp, loff_t *ppos,
2036 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2037 int write, void *data),
2038 void *data)
2039{
2040 return __do_proc_dointvec(table->data, table, write, filp,
2041 buffer, lenp, ppos, conv, data);
2042}
2043
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044/**
2045 * proc_dointvec - read a vector of integers
2046 * @table: the sysctl table
2047 * @write: %TRUE if this is a write to the sysctl file
2048 * @filp: the file structure
2049 * @buffer: the user buffer
2050 * @lenp: the size of the user buffer
2051 * @ppos: file position
2052 *
2053 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2054 * values from/to the user buffer, treated as an ASCII string.
2055 *
2056 * Returns 0 on success.
2057 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002058int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 void __user *buffer, size_t *lenp, loff_t *ppos)
2060{
2061 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2062 NULL,NULL);
2063}
2064
2065#define OP_SET 0
2066#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002067#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
2069static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2070 int *valp,
2071 int write, void *data)
2072{
2073 int op = *(int *)data;
2074 if (write) {
2075 int val = *negp ? -*lvalp : *lvalp;
2076 switch(op) {
2077 case OP_SET: *valp = val; break;
2078 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002079 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
2081 } else {
2082 int val = *valp;
2083 if (val < 0) {
2084 *negp = -1;
2085 *lvalp = (unsigned long)-val;
2086 } else {
2087 *negp = 0;
2088 *lvalp = (unsigned long)val;
2089 }
2090 }
2091 return 0;
2092}
2093
Andrew Morgan72c2d582007-10-18 03:05:59 -07002094#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095/*
2096 * init may raise the set.
2097 */
Andrew Morgan72c2d582007-10-18 03:05:59 -07002098
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002099int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 void __user *buffer, size_t *lenp, loff_t *ppos)
2101{
2102 int op;
2103
Eric Paris6ff1b442007-02-10 01:43:19 -08002104 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 return -EPERM;
2106 }
2107
Serge E. Hallynb460cbc2007-10-18 23:39:52 -07002108 op = is_global_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2110 do_proc_dointvec_bset_conv,&op);
2111}
Andrew Morgan72c2d582007-10-18 03:05:59 -07002112#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002114/*
2115 * Taint values can only be increased
2116 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002117static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002118 void __user *buffer, size_t *lenp, loff_t *ppos)
2119{
2120 int op;
2121
Bastian Blank91fcd412007-04-23 14:41:14 -07002122 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002123 return -EPERM;
2124
2125 op = OP_OR;
2126 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2127 do_proc_dointvec_bset_conv,&op);
2128}
2129
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130struct do_proc_dointvec_minmax_conv_param {
2131 int *min;
2132 int *max;
2133};
2134
2135static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2136 int *valp,
2137 int write, void *data)
2138{
2139 struct do_proc_dointvec_minmax_conv_param *param = data;
2140 if (write) {
2141 int val = *negp ? -*lvalp : *lvalp;
2142 if ((param->min && *param->min > val) ||
2143 (param->max && *param->max < val))
2144 return -EINVAL;
2145 *valp = val;
2146 } else {
2147 int val = *valp;
2148 if (val < 0) {
2149 *negp = -1;
2150 *lvalp = (unsigned long)-val;
2151 } else {
2152 *negp = 0;
2153 *lvalp = (unsigned long)val;
2154 }
2155 }
2156 return 0;
2157}
2158
2159/**
2160 * proc_dointvec_minmax - read a vector of integers with min/max values
2161 * @table: the sysctl table
2162 * @write: %TRUE if this is a write to the sysctl file
2163 * @filp: the file structure
2164 * @buffer: the user buffer
2165 * @lenp: the size of the user buffer
2166 * @ppos: file position
2167 *
2168 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2169 * values from/to the user buffer, treated as an ASCII string.
2170 *
2171 * This routine will ensure the values are within the range specified by
2172 * table->extra1 (min) and table->extra2 (max).
2173 *
2174 * Returns 0 on success.
2175 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002176int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 void __user *buffer, size_t *lenp, loff_t *ppos)
2178{
2179 struct do_proc_dointvec_minmax_conv_param param = {
2180 .min = (int *) table->extra1,
2181 .max = (int *) table->extra2,
2182 };
2183 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2184 do_proc_dointvec_minmax_conv, &param);
2185}
2186
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002187static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 struct file *filp,
2189 void __user *buffer,
2190 size_t *lenp, loff_t *ppos,
2191 unsigned long convmul,
2192 unsigned long convdiv)
2193{
2194#define TMPBUFLEN 21
2195 unsigned long *i, *min, *max, val;
2196 int vleft, first=1, neg;
2197 size_t len, left;
2198 char buf[TMPBUFLEN], *p;
2199 char __user *s = buffer;
2200
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002201 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 (*ppos && !write)) {
2203 *lenp = 0;
2204 return 0;
2205 }
2206
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002207 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 min = (unsigned long *) table->extra1;
2209 max = (unsigned long *) table->extra2;
2210 vleft = table->maxlen / sizeof(unsigned long);
2211 left = *lenp;
2212
2213 for (; left && vleft--; i++, min++, max++, first=0) {
2214 if (write) {
2215 while (left) {
2216 char c;
2217 if (get_user(c, s))
2218 return -EFAULT;
2219 if (!isspace(c))
2220 break;
2221 left--;
2222 s++;
2223 }
2224 if (!left)
2225 break;
2226 neg = 0;
2227 len = left;
2228 if (len > TMPBUFLEN-1)
2229 len = TMPBUFLEN-1;
2230 if (copy_from_user(buf, s, len))
2231 return -EFAULT;
2232 buf[len] = 0;
2233 p = buf;
2234 if (*p == '-' && left > 1) {
2235 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002236 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 }
2238 if (*p < '0' || *p > '9')
2239 break;
2240 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2241 len = p-buf;
2242 if ((len < left) && *p && !isspace(*p))
2243 break;
2244 if (neg)
2245 val = -val;
2246 s += len;
2247 left -= len;
2248
2249 if(neg)
2250 continue;
2251 if ((min && val < *min) || (max && val > *max))
2252 continue;
2253 *i = val;
2254 } else {
2255 p = buf;
2256 if (!first)
2257 *p++ = '\t';
2258 sprintf(p, "%lu", convdiv * (*i) / convmul);
2259 len = strlen(buf);
2260 if (len > left)
2261 len = left;
2262 if(copy_to_user(s, buf, len))
2263 return -EFAULT;
2264 left -= len;
2265 s += len;
2266 }
2267 }
2268
2269 if (!write && !first && left) {
2270 if(put_user('\n', s))
2271 return -EFAULT;
2272 left--, s++;
2273 }
2274 if (write) {
2275 while (left) {
2276 char c;
2277 if (get_user(c, s++))
2278 return -EFAULT;
2279 if (!isspace(c))
2280 break;
2281 left--;
2282 }
2283 }
2284 if (write && first)
2285 return -EINVAL;
2286 *lenp -= left;
2287 *ppos += *lenp;
2288 return 0;
2289#undef TMPBUFLEN
2290}
2291
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002292static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002293 struct file *filp,
2294 void __user *buffer,
2295 size_t *lenp, loff_t *ppos,
2296 unsigned long convmul,
2297 unsigned long convdiv)
2298{
2299 return __do_proc_doulongvec_minmax(table->data, table, write,
2300 filp, buffer, lenp, ppos, convmul, convdiv);
2301}
2302
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303/**
2304 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2305 * @table: the sysctl table
2306 * @write: %TRUE if this is a write to the sysctl file
2307 * @filp: the file structure
2308 * @buffer: the user buffer
2309 * @lenp: the size of the user buffer
2310 * @ppos: file position
2311 *
2312 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2313 * values from/to the user buffer, treated as an ASCII string.
2314 *
2315 * This routine will ensure the values are within the range specified by
2316 * table->extra1 (min) and table->extra2 (max).
2317 *
2318 * Returns 0 on success.
2319 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002320int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 void __user *buffer, size_t *lenp, loff_t *ppos)
2322{
2323 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2324}
2325
2326/**
2327 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2328 * @table: the sysctl table
2329 * @write: %TRUE if this is a write to the sysctl file
2330 * @filp: the file structure
2331 * @buffer: the user buffer
2332 * @lenp: the size of the user buffer
2333 * @ppos: file position
2334 *
2335 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2336 * values from/to the user buffer, treated as an ASCII string. The values
2337 * are treated as milliseconds, and converted to jiffies when they are stored.
2338 *
2339 * This routine will ensure the values are within the range specified by
2340 * table->extra1 (min) and table->extra2 (max).
2341 *
2342 * Returns 0 on success.
2343 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002344int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 struct file *filp,
2346 void __user *buffer,
2347 size_t *lenp, loff_t *ppos)
2348{
2349 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2350 lenp, ppos, HZ, 1000l);
2351}
2352
2353
2354static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2355 int *valp,
2356 int write, void *data)
2357{
2358 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002359 if (*lvalp > LONG_MAX / HZ)
2360 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2362 } else {
2363 int val = *valp;
2364 unsigned long lval;
2365 if (val < 0) {
2366 *negp = -1;
2367 lval = (unsigned long)-val;
2368 } else {
2369 *negp = 0;
2370 lval = (unsigned long)val;
2371 }
2372 *lvalp = lval / HZ;
2373 }
2374 return 0;
2375}
2376
2377static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2378 int *valp,
2379 int write, void *data)
2380{
2381 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002382 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2383 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2385 } else {
2386 int val = *valp;
2387 unsigned long lval;
2388 if (val < 0) {
2389 *negp = -1;
2390 lval = (unsigned long)-val;
2391 } else {
2392 *negp = 0;
2393 lval = (unsigned long)val;
2394 }
2395 *lvalp = jiffies_to_clock_t(lval);
2396 }
2397 return 0;
2398}
2399
2400static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2401 int *valp,
2402 int write, void *data)
2403{
2404 if (write) {
2405 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2406 } else {
2407 int val = *valp;
2408 unsigned long lval;
2409 if (val < 0) {
2410 *negp = -1;
2411 lval = (unsigned long)-val;
2412 } else {
2413 *negp = 0;
2414 lval = (unsigned long)val;
2415 }
2416 *lvalp = jiffies_to_msecs(lval);
2417 }
2418 return 0;
2419}
2420
2421/**
2422 * proc_dointvec_jiffies - read a vector of integers as seconds
2423 * @table: the sysctl table
2424 * @write: %TRUE if this is a write to the sysctl file
2425 * @filp: the file structure
2426 * @buffer: the user buffer
2427 * @lenp: the size of the user buffer
2428 * @ppos: file position
2429 *
2430 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2431 * values from/to the user buffer, treated as an ASCII string.
2432 * The values read are assumed to be in seconds, and are converted into
2433 * jiffies.
2434 *
2435 * Returns 0 on success.
2436 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002437int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 void __user *buffer, size_t *lenp, loff_t *ppos)
2439{
2440 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2441 do_proc_dointvec_jiffies_conv,NULL);
2442}
2443
2444/**
2445 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2446 * @table: the sysctl table
2447 * @write: %TRUE if this is a write to the sysctl file
2448 * @filp: the file structure
2449 * @buffer: the user buffer
2450 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002451 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 *
2453 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2454 * values from/to the user buffer, treated as an ASCII string.
2455 * The values read are assumed to be in 1/USER_HZ seconds, and
2456 * are converted into jiffies.
2457 *
2458 * Returns 0 on success.
2459 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002460int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 void __user *buffer, size_t *lenp, loff_t *ppos)
2462{
2463 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2464 do_proc_dointvec_userhz_jiffies_conv,NULL);
2465}
2466
2467/**
2468 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2469 * @table: the sysctl table
2470 * @write: %TRUE if this is a write to the sysctl file
2471 * @filp: the file structure
2472 * @buffer: the user buffer
2473 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002474 * @ppos: file position
2475 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 *
2477 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2478 * values from/to the user buffer, treated as an ASCII string.
2479 * The values read are assumed to be in 1/1000 seconds, and
2480 * are converted into jiffies.
2481 *
2482 * Returns 0 on success.
2483 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002484int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 void __user *buffer, size_t *lenp, loff_t *ppos)
2486{
2487 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2488 do_proc_dointvec_ms_jiffies_conv, NULL);
2489}
2490
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002491static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002492 void __user *buffer, size_t *lenp, loff_t *ppos)
2493{
2494 struct pid *new_pid;
2495 pid_t tmp;
2496 int r;
2497
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002498 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002499
2500 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2501 lenp, ppos, NULL, NULL);
2502 if (r || !write)
2503 return r;
2504
2505 new_pid = find_get_pid(tmp);
2506 if (!new_pid)
2507 return -ESRCH;
2508
2509 put_pid(xchg(&cad_pid, new_pid));
2510 return 0;
2511}
2512
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513#else /* CONFIG_PROC_FS */
2514
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002515int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 void __user *buffer, size_t *lenp, loff_t *ppos)
2517{
2518 return -ENOSYS;
2519}
2520
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002521int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 void __user *buffer, size_t *lenp, loff_t *ppos)
2523{
2524 return -ENOSYS;
2525}
2526
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002527int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 void __user *buffer, size_t *lenp, loff_t *ppos)
2529{
2530 return -ENOSYS;
2531}
2532
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002533int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 void __user *buffer, size_t *lenp, loff_t *ppos)
2535{
2536 return -ENOSYS;
2537}
2538
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002539int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 void __user *buffer, size_t *lenp, loff_t *ppos)
2541{
2542 return -ENOSYS;
2543}
2544
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002545int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 void __user *buffer, size_t *lenp, loff_t *ppos)
2547{
2548 return -ENOSYS;
2549}
2550
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002551int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 void __user *buffer, size_t *lenp, loff_t *ppos)
2553{
2554 return -ENOSYS;
2555}
2556
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002557int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 void __user *buffer, size_t *lenp, loff_t *ppos)
2559{
2560 return -ENOSYS;
2561}
2562
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002563int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 struct file *filp,
2565 void __user *buffer,
2566 size_t *lenp, loff_t *ppos)
2567{
2568 return -ENOSYS;
2569}
2570
2571
2572#endif /* CONFIG_PROC_FS */
2573
2574
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002575#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576/*
2577 * General sysctl support routines
2578 */
2579
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002580/* The generic sysctl data routine (used if no strategy routine supplied) */
2581int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2582 void __user *oldval, size_t __user *oldlenp,
2583 void __user *newval, size_t newlen)
2584{
2585 size_t len;
2586
2587 /* Get out of I don't have a variable */
2588 if (!table->data || !table->maxlen)
2589 return -ENOTDIR;
2590
2591 if (oldval && oldlenp) {
2592 if (get_user(len, oldlenp))
2593 return -EFAULT;
2594 if (len) {
2595 if (len > table->maxlen)
2596 len = table->maxlen;
2597 if (copy_to_user(oldval, table->data, len))
2598 return -EFAULT;
2599 if (put_user(len, oldlenp))
2600 return -EFAULT;
2601 }
2602 }
2603
2604 if (newval && newlen) {
2605 if (newlen > table->maxlen)
2606 newlen = table->maxlen;
2607
2608 if (copy_from_user(table->data, newval, newlen))
2609 return -EFAULT;
2610 }
2611 return 1;
2612}
2613
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002615int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002617 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 if (!table->data || !table->maxlen)
2620 return -ENOTDIR;
2621
2622 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002623 size_t bufsize;
2624 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002626 if (bufsize) {
2627 size_t len = strlen(table->data), copied;
2628
2629 /* This shouldn't trigger for a well-formed sysctl */
2630 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002632
2633 /* Copy up to a max of bufsize-1 bytes of the string */
2634 copied = (len >= bufsize) ? bufsize - 1 : len;
2635
2636 if (copy_to_user(oldval, table->data, copied) ||
2637 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002639 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 return -EFAULT;
2641 }
2642 }
2643 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002644 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 if (len > table->maxlen)
2646 len = table->maxlen;
2647 if(copy_from_user(table->data, newval, len))
2648 return -EFAULT;
2649 if (len == table->maxlen)
2650 len--;
2651 ((char *) table->data)[len] = 0;
2652 }
Yi Yang82c9df82005-12-30 16:37:10 +08002653 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654}
2655
2656/*
2657 * This function makes sure that all of the integers in the vector
2658 * are between the minimum and maximum values given in the arrays
2659 * table->extra1 and table->extra2, respectively.
2660 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002661int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002663 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664{
2665
2666 if (newval && newlen) {
2667 int __user *vec = (int __user *) newval;
2668 int *min = (int *) table->extra1;
2669 int *max = (int *) table->extra2;
2670 size_t length;
2671 int i;
2672
2673 if (newlen % sizeof(int) != 0)
2674 return -EINVAL;
2675
2676 if (!table->extra1 && !table->extra2)
2677 return 0;
2678
2679 if (newlen > table->maxlen)
2680 newlen = table->maxlen;
2681 length = newlen / sizeof(int);
2682
2683 for (i = 0; i < length; i++) {
2684 int value;
2685 if (get_user(value, vec + i))
2686 return -EFAULT;
2687 if (min && value < min[i])
2688 return -EINVAL;
2689 if (max && value > max[i])
2690 return -EINVAL;
2691 }
2692 }
2693 return 0;
2694}
2695
2696/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002697int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002699 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002701 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002703
2704 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002706 if (olen) {
2707 int val;
2708
2709 if (olen < sizeof(int))
2710 return -EINVAL;
2711
2712 val = *(int *)(table->data) / HZ;
2713 if (put_user(val, (int __user *)oldval))
2714 return -EFAULT;
2715 if (put_user(sizeof(int), oldlenp))
2716 return -EFAULT;
2717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 }
2719 if (newval && newlen) {
2720 int new;
2721 if (newlen != sizeof(int))
2722 return -EINVAL;
2723 if (get_user(new, (int __user *)newval))
2724 return -EFAULT;
2725 *(int *)(table->data) = new*HZ;
2726 }
2727 return 1;
2728}
2729
2730/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002731int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002733 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002735 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002737
2738 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002740 if (olen) {
2741 int val;
2742
2743 if (olen < sizeof(int))
2744 return -EINVAL;
2745
2746 val = jiffies_to_msecs(*(int *)(table->data));
2747 if (put_user(val, (int __user *)oldval))
2748 return -EFAULT;
2749 if (put_user(sizeof(int), oldlenp))
2750 return -EFAULT;
2751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 }
2753 if (newval && newlen) {
2754 int new;
2755 if (newlen != sizeof(int))
2756 return -EINVAL;
2757 if (get_user(new, (int __user *)newval))
2758 return -EFAULT;
2759 *(int *)(table->data) = msecs_to_jiffies(new);
2760 }
2761 return 1;
2762}
2763
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002764
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002765
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002766#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
2768
2769asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2770{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002771 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002772 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002773
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002774 if (copy_from_user(&tmp, args, sizeof(tmp)))
2775 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002776
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002777 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002778
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002779 /* If no error reading the parameters then just -ENOSYS ... */
2780 if (!error)
2781 error = -ENOSYS;
2782
2783 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784}
2785
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002786int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2787 void __user *oldval, size_t __user *oldlenp,
2788 void __user *newval, size_t newlen)
2789{
2790 return -ENOSYS;
2791}
2792
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002793int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002795 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796{
2797 return -ENOSYS;
2798}
2799
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002800int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002802 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803{
2804 return -ENOSYS;
2805}
2806
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002807int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002809 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810{
2811 return -ENOSYS;
2812}
2813
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002814int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002816 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817{
2818 return -ENOSYS;
2819}
2820
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002821#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002823static int deprecated_sysctl_warning(struct __sysctl_args *args)
2824{
2825 static int msg_count;
2826 int name[CTL_MAXNAME];
2827 int i;
2828
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002829 /* Check args->nlen. */
2830 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2831 return -ENOTDIR;
2832
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002833 /* Read in the sysctl name for better debug message logging */
2834 for (i = 0; i < args->nlen; i++)
2835 if (get_user(name[i], args->name + i))
2836 return -EFAULT;
2837
2838 /* Ignore accesses to kernel.version */
2839 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2840 return 0;
2841
2842 if (msg_count < 5) {
2843 msg_count++;
2844 printk(KERN_INFO
2845 "warning: process `%s' used the deprecated sysctl "
2846 "system call with ", current->comm);
2847 for (i = 0; i < args->nlen; i++)
2848 printk("%d.", name[i]);
2849 printk("\n");
2850 }
2851 return 0;
2852}
2853
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854/*
2855 * No sense putting this after each symbol definition, twice,
2856 * exception granted :-)
2857 */
2858EXPORT_SYMBOL(proc_dointvec);
2859EXPORT_SYMBOL(proc_dointvec_jiffies);
2860EXPORT_SYMBOL(proc_dointvec_minmax);
2861EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2862EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2863EXPORT_SYMBOL(proc_dostring);
2864EXPORT_SYMBOL(proc_doulongvec_minmax);
2865EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2866EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002867EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868EXPORT_SYMBOL(sysctl_intvec);
2869EXPORT_SYMBOL(sysctl_jiffies);
2870EXPORT_SYMBOL(sysctl_ms_jiffies);
2871EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002872EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873EXPORT_SYMBOL(unregister_sysctl_table);