blob: 45e76f209dcbd8a84083776e80ecb88f3ea8bfaa [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>
Andi Kleen29cbc782006-09-30 01:47:55 +020056#endif
57
Eric W. Biederman7058cb02007-10-18 03:05:58 -070058static int deprecated_sysctl_warning(struct __sysctl_args *args);
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#if defined(CONFIG_SYSCTL)
61
62/* External variables not in a header file. */
63extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070064extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065extern int sysctl_overcommit_memory;
66extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070067extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070068extern int sysctl_oom_kill_allocating_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070071extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int pid_max;
74extern int min_free_kbytes;
75extern int printk_ratelimit_jiffies;
76extern int printk_ratelimit_burst;
77extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080078extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080079extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020080extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070081extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070082extern int sysctl_stat_interval;
Peter Zijlstrabdf4c482007-07-19 01:48:15 -070083extern int audit_argv_kb;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070086/* Constants used for minimum and maximum */
87#ifdef CONFIG_DETECT_SOFTLOCKUP
88static int one = 1;
89static int sixty = 60;
90#endif
91
92#ifdef CONFIG_MMU
93static int two = 2;
94#endif
95
96static int zero;
97static int one_hundred = 100;
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
100static int maxolduid = 65535;
101static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800102static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104static int ngroups_max = NGROUPS_MAX;
105
106#ifdef CONFIG_KMOD
107extern char modprobe_path[];
108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#ifdef CONFIG_CHR_DEV_SG
110extern int sg_big_buff;
111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113#ifdef __sparc__
114extern char reboot_command [];
115extern int stop_a_enabled;
116extern int scons_pwroff;
117#endif
118
119#ifdef __hppa__
120extern int pwrsw_enabled;
121extern int unaligned_enabled;
122#endif
123
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800124#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#ifdef CONFIG_MATHEMU
126extern int sysctl_ieee_emulation_warnings;
127#endif
128extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700129extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#endif
131
132extern int sysctl_hz_timer;
133
134#ifdef CONFIG_BSD_PROCESS_ACCT
135extern int acct_parm[];
136#endif
137
Jes Sorensend2b176e2006-02-28 09:42:23 -0800138#ifdef CONFIG_IA64
139extern int no_unaligned_warning;
140#endif
141
Ingo Molnar23f78d42006-06-27 02:54:53 -0700142#ifdef CONFIG_RT_MUTEXES
143extern int max_lock_depth;
144#endif
145
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700146#ifdef CONFIG_SYSCTL_SYSCALL
147static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700148 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700149#endif
150
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700153static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700154 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800156 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700158
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700159static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100160static struct ctl_table_root sysctl_table_root;
161static struct ctl_table_header root_table_header = {
162 .ctl_table = root_table,
163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
164 .root = &sysctl_table_root,
165};
166static struct ctl_table_root sysctl_table_root = {
167 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
168 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
169};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700171static struct ctl_table kern_table[];
172static struct ctl_table vm_table[];
173static struct ctl_table fs_table[];
174static struct ctl_table debug_table[];
175static struct ctl_table dev_table[];
176extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700177#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700178extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400179#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
182int sysctl_legacy_va_layout;
183#endif
184
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700185extern int prove_locking;
186extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188/* The default sysctl tables: */
189
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700190static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 {
192 .ctl_name = CTL_KERN,
193 .procname = "kernel",
194 .mode = 0555,
195 .child = kern_table,
196 },
197 {
198 .ctl_name = CTL_VM,
199 .procname = "vm",
200 .mode = 0555,
201 .child = vm_table,
202 },
203#ifdef CONFIG_NET
204 {
205 .ctl_name = CTL_NET,
206 .procname = "net",
207 .mode = 0555,
208 .child = net_table,
209 },
210#endif
211 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 .ctl_name = CTL_FS,
213 .procname = "fs",
214 .mode = 0555,
215 .child = fs_table,
216 },
217 {
218 .ctl_name = CTL_DEBUG,
219 .procname = "debug",
220 .mode = 0555,
221 .child = debug_table,
222 },
223 {
224 .ctl_name = CTL_DEV,
225 .procname = "dev",
226 .mode = 0555,
227 .child = dev_table,
228 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700229/*
230 * NOTE: do not add new entries to this table unless you have read
231 * Documentation/sysctl/ctl_unnumbered.txt
232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 { .ctl_name = 0 }
234};
235
Ingo Molnar77e54a12007-07-09 18:52:00 +0200236#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100237static int min_sched_granularity_ns = 100000; /* 100 usecs */
238static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
239static int min_wakeup_granularity_ns; /* 0 usecs */
240static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200241#endif
242
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700243static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244#ifdef CONFIG_SCHED_DEBUG
245 {
246 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100247 .procname = "sched_min_granularity_ns",
248 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200249 .maxlen = sizeof(unsigned int),
250 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100251 .proc_handler = &sched_nr_latency_handler,
252 .strategy = &sysctl_intvec,
253 .extra1 = &min_sched_granularity_ns,
254 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200255 },
256 {
257 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200258 .procname = "sched_latency_ns",
259 .data = &sysctl_sched_latency,
260 .maxlen = sizeof(unsigned int),
261 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100262 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200263 .strategy = &sysctl_intvec,
264 .extra1 = &min_sched_granularity_ns,
265 .extra2 = &max_sched_granularity_ns,
266 },
267 {
268 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200269 .procname = "sched_wakeup_granularity_ns",
270 .data = &sysctl_sched_wakeup_granularity,
271 .maxlen = sizeof(unsigned int),
272 .mode = 0644,
273 .proc_handler = &proc_dointvec_minmax,
274 .strategy = &sysctl_intvec,
275 .extra1 = &min_wakeup_granularity_ns,
276 .extra2 = &max_wakeup_granularity_ns,
277 },
278 {
279 .ctl_name = CTL_UNNUMBERED,
280 .procname = "sched_batch_wakeup_granularity_ns",
281 .data = &sysctl_sched_batch_wakeup_granularity,
282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
284 .proc_handler = &proc_dointvec_minmax,
285 .strategy = &sysctl_intvec,
286 .extra1 = &min_wakeup_granularity_ns,
287 .extra2 = &max_wakeup_granularity_ns,
288 },
289 {
290 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200291 .procname = "sched_child_runs_first",
292 .data = &sysctl_sched_child_runs_first,
293 .maxlen = sizeof(unsigned int),
294 .mode = 0644,
295 .proc_handler = &proc_dointvec,
296 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200297 {
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_features",
300 .data = &sysctl_sched_features,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
303 .proc_handler = &proc_dointvec,
304 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200305 {
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_migration_cost",
308 .data = &sysctl_sched_migration_cost,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
311 .proc_handler = &proc_dointvec,
312 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100313 {
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_nr_migrate",
316 .data = &sysctl_sched_nr_migrate,
317 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100318 .mode = 0644,
319 .proc_handler = &proc_dointvec,
320 },
321 {
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_rt_period_ms",
324 .data = &sysctl_sched_rt_period,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
327 .proc_handler = &proc_dointvec,
328 },
329 {
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "sched_rt_ratio",
332 .data = &sysctl_sched_rt_ratio,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100335 .proc_handler = &proc_dointvec,
336 },
Srivatsa Vaddagiri6b2d7702008-01-25 21:08:00 +0100337#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
338 {
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "sched_min_bal_int_shares",
341 .data = &sysctl_sched_min_bal_int_shares,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = &proc_dointvec,
345 },
346 {
347 .ctl_name = CTL_UNNUMBERED,
348 .procname = "sched_max_bal_int_shares",
349 .data = &sysctl_sched_max_bal_int_shares,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = &proc_dointvec,
353 },
354#endif
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200355#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200356 {
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "sched_compat_yield",
359 .data = &sysctl_sched_compat_yield,
360 .maxlen = sizeof(unsigned int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700364#ifdef CONFIG_PROVE_LOCKING
365 {
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "prove_locking",
368 .data = &prove_locking,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &proc_dointvec,
372 },
373#endif
374#ifdef CONFIG_LOCK_STAT
375 {
376 .ctl_name = CTL_UNNUMBERED,
377 .procname = "lock_stat",
378 .data = &lock_stat,
379 .maxlen = sizeof(int),
380 .mode = 0644,
381 .proc_handler = &proc_dointvec,
382 },
383#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .ctl_name = KERN_PANIC,
386 .procname = "panic",
387 .data = &panic_timeout,
388 .maxlen = sizeof(int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
391 },
392 {
393 .ctl_name = KERN_CORE_USES_PID,
394 .procname = "core_uses_pid",
395 .data = &core_uses_pid,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
399 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700400#ifdef CONFIG_AUDITSYSCALL
401 {
402 .ctl_name = CTL_UNNUMBERED,
403 .procname = "audit_argv_kb",
404 .data = &audit_argv_kb,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec,
408 },
409#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 {
411 .ctl_name = KERN_CORE_PATTERN,
412 .procname = "core_pattern",
413 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700414 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 .mode = 0644,
416 .proc_handler = &proc_dostring,
417 .strategy = &sysctl_string,
418 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800419#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 .procname = "tainted",
422 .data = &tainted,
423 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800424 .mode = 0644,
425 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800427#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100428#ifdef CONFIG_LATENCYTOP
429 {
430 .procname = "latencytop",
431 .data = &latencytop_enabled,
432 .maxlen = sizeof(int),
433 .mode = 0644,
434 .proc_handler = &proc_dointvec,
435 },
436#endif
Andrew Morgan72c2d582007-10-18 03:05:59 -0700437#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 .procname = "cap-bound",
440 .data = &cap_bset,
441 .maxlen = sizeof(kernel_cap_t),
442 .mode = 0600,
443 .proc_handler = &proc_dointvec_bset,
444 },
Andrew Morgan72c2d582007-10-18 03:05:59 -0700445#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446#ifdef CONFIG_BLK_DEV_INITRD
447 {
448 .ctl_name = KERN_REALROOTDEV,
449 .procname = "real-root-dev",
450 .data = &real_root_dev,
451 .maxlen = sizeof(int),
452 .mode = 0644,
453 .proc_handler = &proc_dointvec,
454 },
455#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700456 {
457 .ctl_name = CTL_UNNUMBERED,
458 .procname = "print-fatal-signals",
459 .data = &print_fatal_signals,
460 .maxlen = sizeof(int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
463 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464#ifdef __sparc__
465 {
466 .ctl_name = KERN_SPARC_REBOOT,
467 .procname = "reboot-cmd",
468 .data = reboot_command,
469 .maxlen = 256,
470 .mode = 0644,
471 .proc_handler = &proc_dostring,
472 .strategy = &sysctl_string,
473 },
474 {
475 .ctl_name = KERN_SPARC_STOP_A,
476 .procname = "stop-a",
477 .data = &stop_a_enabled,
478 .maxlen = sizeof (int),
479 .mode = 0644,
480 .proc_handler = &proc_dointvec,
481 },
482 {
483 .ctl_name = KERN_SPARC_SCONS_PWROFF,
484 .procname = "scons-poweroff",
485 .data = &scons_pwroff,
486 .maxlen = sizeof (int),
487 .mode = 0644,
488 .proc_handler = &proc_dointvec,
489 },
490#endif
491#ifdef __hppa__
492 {
493 .ctl_name = KERN_HPPA_PWRSW,
494 .procname = "soft-power",
495 .data = &pwrsw_enabled,
496 .maxlen = sizeof (int),
497 .mode = 0644,
498 .proc_handler = &proc_dointvec,
499 },
500 {
501 .ctl_name = KERN_HPPA_UNALIGNED,
502 .procname = "unaligned-trap",
503 .data = &unaligned_enabled,
504 .maxlen = sizeof (int),
505 .mode = 0644,
506 .proc_handler = &proc_dointvec,
507 },
508#endif
509 {
510 .ctl_name = KERN_CTLALTDEL,
511 .procname = "ctrl-alt-del",
512 .data = &C_A_D,
513 .maxlen = sizeof(int),
514 .mode = 0644,
515 .proc_handler = &proc_dointvec,
516 },
517 {
518 .ctl_name = KERN_PRINTK,
519 .procname = "printk",
520 .data = &console_loglevel,
521 .maxlen = 4*sizeof(int),
522 .mode = 0644,
523 .proc_handler = &proc_dointvec,
524 },
525#ifdef CONFIG_KMOD
526 {
527 .ctl_name = KERN_MODPROBE,
528 .procname = "modprobe",
529 .data = &modprobe_path,
530 .maxlen = KMOD_PATH_LEN,
531 .mode = 0644,
532 .proc_handler = &proc_dostring,
533 .strategy = &sysctl_string,
534 },
535#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700536#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 {
538 .ctl_name = KERN_HOTPLUG,
539 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100540 .data = &uevent_helper,
541 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 .mode = 0644,
543 .proc_handler = &proc_dostring,
544 .strategy = &sysctl_string,
545 },
546#endif
547#ifdef CONFIG_CHR_DEV_SG
548 {
549 .ctl_name = KERN_SG_BIG_BUFF,
550 .procname = "sg-big-buff",
551 .data = &sg_big_buff,
552 .maxlen = sizeof (int),
553 .mode = 0444,
554 .proc_handler = &proc_dointvec,
555 },
556#endif
557#ifdef CONFIG_BSD_PROCESS_ACCT
558 {
559 .ctl_name = KERN_ACCT,
560 .procname = "acct",
561 .data = &acct_parm,
562 .maxlen = 3*sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
565 },
566#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#ifdef CONFIG_MAGIC_SYSRQ
568 {
569 .ctl_name = KERN_SYSRQ,
570 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800571 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .maxlen = sizeof (int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
575 },
576#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700577#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700580 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .maxlen = sizeof (int),
582 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700583 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 {
587 .ctl_name = KERN_MAX_THREADS,
588 .procname = "threads-max",
589 .data = &max_threads,
590 .maxlen = sizeof(int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec,
593 },
594 {
595 .ctl_name = KERN_RANDOM,
596 .procname = "random",
597 .mode = 0555,
598 .child = random_table,
599 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 {
601 .ctl_name = KERN_OVERFLOWUID,
602 .procname = "overflowuid",
603 .data = &overflowuid,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec_minmax,
607 .strategy = &sysctl_intvec,
608 .extra1 = &minolduid,
609 .extra2 = &maxolduid,
610 },
611 {
612 .ctl_name = KERN_OVERFLOWGID,
613 .procname = "overflowgid",
614 .data = &overflowgid,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = &proc_dointvec_minmax,
618 .strategy = &sysctl_intvec,
619 .extra1 = &minolduid,
620 .extra2 = &maxolduid,
621 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800622#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623#ifdef CONFIG_MATHEMU
624 {
625 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
626 .procname = "ieee_emulation_warnings",
627 .data = &sysctl_ieee_emulation_warnings,
628 .maxlen = sizeof(int),
629 .mode = 0644,
630 .proc_handler = &proc_dointvec,
631 },
632#endif
633#ifdef CONFIG_NO_IDLE_HZ
634 {
635 .ctl_name = KERN_HZ_TIMER,
636 .procname = "hz_timer",
637 .data = &sysctl_hz_timer,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 .proc_handler = &proc_dointvec,
641 },
642#endif
643 {
644 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
645 .procname = "userprocess_debug",
646 .data = &sysctl_userprocess_debug,
647 .maxlen = sizeof(int),
648 .mode = 0644,
649 .proc_handler = &proc_dointvec,
650 },
651#endif
652 {
653 .ctl_name = KERN_PIDMAX,
654 .procname = "pid_max",
655 .data = &pid_max,
656 .maxlen = sizeof (int),
657 .mode = 0644,
658 .proc_handler = &proc_dointvec_minmax,
659 .strategy = sysctl_intvec,
660 .extra1 = &pid_max_min,
661 .extra2 = &pid_max_max,
662 },
663 {
664 .ctl_name = KERN_PANIC_ON_OOPS,
665 .procname = "panic_on_oops",
666 .data = &panic_on_oops,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = &proc_dointvec,
670 },
671 {
672 .ctl_name = KERN_PRINTK_RATELIMIT,
673 .procname = "printk_ratelimit",
674 .data = &printk_ratelimit_jiffies,
675 .maxlen = sizeof(int),
676 .mode = 0644,
677 .proc_handler = &proc_dointvec_jiffies,
678 .strategy = &sysctl_jiffies,
679 },
680 {
681 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
682 .procname = "printk_ratelimit_burst",
683 .data = &printk_ratelimit_burst,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec,
687 },
688 {
689 .ctl_name = KERN_NGROUPS_MAX,
690 .procname = "ngroups_max",
691 .data = &ngroups_max,
692 .maxlen = sizeof (int),
693 .mode = 0444,
694 .proc_handler = &proc_dointvec,
695 },
696#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
697 {
698 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
699 .procname = "unknown_nmi_panic",
700 .data = &unknown_nmi_panic,
701 .maxlen = sizeof (int),
702 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200703 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 },
Don Zickus407984f2006-09-26 10:52:27 +0200705 {
Don Zickus407984f2006-09-26 10:52:27 +0200706 .procname = "nmi_watchdog",
707 .data = &nmi_watchdog_enabled,
708 .maxlen = sizeof (int),
709 .mode = 0644,
710 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 },
712#endif
713#if defined(CONFIG_X86)
714 {
Don Zickus8da5add2006-09-26 10:52:27 +0200715 .ctl_name = KERN_PANIC_ON_NMI,
716 .procname = "panic_on_unrecovered_nmi",
717 .data = &panic_on_unrecovered_nmi,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
721 },
722 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .ctl_name = KERN_BOOTLOADER_TYPE,
724 .procname = "bootloader_type",
725 .data = &bootloader_type,
726 .maxlen = sizeof (int),
727 .mode = 0444,
728 .proc_handler = &proc_dointvec,
729 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100730 {
731 .ctl_name = CTL_UNNUMBERED,
732 .procname = "kstack_depth_to_print",
733 .data = &kstack_depth_to_print,
734 .maxlen = sizeof(int),
735 .mode = 0644,
736 .proc_handler = &proc_dointvec,
737 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800739#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 {
741 .ctl_name = KERN_RANDOMIZE,
742 .procname = "randomize_va_space",
743 .data = &randomize_va_space,
744 .maxlen = sizeof(int),
745 .mode = 0644,
746 .proc_handler = &proc_dointvec,
747 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800748#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800749#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700750 {
751 .ctl_name = KERN_SPIN_RETRY,
752 .procname = "spin_retry",
753 .data = &spin_retry,
754 .maxlen = sizeof (int),
755 .mode = 0644,
756 .proc_handler = &proc_dointvec,
757 },
758#endif
Len Brown673d5b42007-07-28 03:33:16 -0400759#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800760 {
Pavel Machekc255d842006-02-20 18:27:58 -0800761 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700762 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800763 .maxlen = sizeof (unsigned long),
764 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800765 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800766 },
767#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800768#ifdef CONFIG_IA64
769 {
770 .ctl_name = KERN_IA64_UNALIGNED,
771 .procname = "ignore-unaligned-usertrap",
772 .data = &no_unaligned_warning,
773 .maxlen = sizeof (int),
774 .mode = 0644,
775 .proc_handler = &proc_dointvec,
776 },
777#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700778#ifdef CONFIG_DETECT_SOFTLOCKUP
779 {
780 .ctl_name = CTL_UNNUMBERED,
781 .procname = "softlockup_thresh",
782 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100783 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700784 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100785 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700786 .strategy = &sysctl_intvec,
787 .extra1 = &one,
788 .extra2 = &sixty,
789 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100790 {
791 .ctl_name = CTL_UNNUMBERED,
792 .procname = "hung_task_check_count",
793 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100794 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100795 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100796 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100797 .strategy = &sysctl_intvec,
798 },
799 {
800 .ctl_name = CTL_UNNUMBERED,
801 .procname = "hung_task_timeout_secs",
802 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100803 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100804 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100805 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100806 .strategy = &sysctl_intvec,
807 },
808 {
809 .ctl_name = CTL_UNNUMBERED,
810 .procname = "hung_task_warnings",
811 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100812 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100813 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100814 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100815 .strategy = &sysctl_intvec,
816 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700817#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200818#ifdef CONFIG_COMPAT
819 {
820 .ctl_name = KERN_COMPAT_LOG,
821 .procname = "compat-log",
822 .data = &compat_log,
823 .maxlen = sizeof (int),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec,
826 },
827#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700828#ifdef CONFIG_RT_MUTEXES
829 {
830 .ctl_name = KERN_MAX_LOCK_DEPTH,
831 .procname = "max_lock_depth",
832 .data = &max_lock_depth,
833 .maxlen = sizeof(int),
834 .mode = 0644,
835 .proc_handler = &proc_dointvec,
836 },
837#endif
Kees Cook5096add2007-05-08 00:26:04 -0700838#ifdef CONFIG_PROC_FS
839 {
840 .ctl_name = CTL_UNNUMBERED,
841 .procname = "maps_protect",
842 .data = &maps_protect,
843 .maxlen = sizeof(int),
844 .mode = 0644,
845 .proc_handler = &proc_dointvec,
846 },
847#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700848 {
849 .ctl_name = CTL_UNNUMBERED,
850 .procname = "poweroff_cmd",
851 .data = &poweroff_cmd,
852 .maxlen = POWEROFF_CMD_PATH_LEN,
853 .mode = 0644,
854 .proc_handler = &proc_dostring,
855 .strategy = &sysctl_string,
856 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700857/*
858 * NOTE: do not add new entries to this table unless you have read
859 * Documentation/sysctl/ctl_unnumbered.txt
860 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 { .ctl_name = 0 }
862};
863
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700864static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 {
866 .ctl_name = VM_OVERCOMMIT_MEMORY,
867 .procname = "overcommit_memory",
868 .data = &sysctl_overcommit_memory,
869 .maxlen = sizeof(sysctl_overcommit_memory),
870 .mode = 0644,
871 .proc_handler = &proc_dointvec,
872 },
873 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700874 .ctl_name = VM_PANIC_ON_OOM,
875 .procname = "panic_on_oom",
876 .data = &sysctl_panic_on_oom,
877 .maxlen = sizeof(sysctl_panic_on_oom),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec,
880 },
881 {
David Rientjesfe071d72007-10-16 23:25:56 -0700882 .ctl_name = CTL_UNNUMBERED,
883 .procname = "oom_kill_allocating_task",
884 .data = &sysctl_oom_kill_allocating_task,
885 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
886 .mode = 0644,
887 .proc_handler = &proc_dointvec,
888 },
889 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 .ctl_name = VM_OVERCOMMIT_RATIO,
891 .procname = "overcommit_ratio",
892 .data = &sysctl_overcommit_ratio,
893 .maxlen = sizeof(sysctl_overcommit_ratio),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec,
896 },
897 {
898 .ctl_name = VM_PAGE_CLUSTER,
899 .procname = "page-cluster",
900 .data = &page_cluster,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = &proc_dointvec,
904 },
905 {
906 .ctl_name = VM_DIRTY_BACKGROUND,
907 .procname = "dirty_background_ratio",
908 .data = &dirty_background_ratio,
909 .maxlen = sizeof(dirty_background_ratio),
910 .mode = 0644,
911 .proc_handler = &proc_dointvec_minmax,
912 .strategy = &sysctl_intvec,
913 .extra1 = &zero,
914 .extra2 = &one_hundred,
915 },
916 {
917 .ctl_name = VM_DIRTY_RATIO,
918 .procname = "dirty_ratio",
919 .data = &vm_dirty_ratio,
920 .maxlen = sizeof(vm_dirty_ratio),
921 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700922 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 .strategy = &sysctl_intvec,
924 .extra1 = &zero,
925 .extra2 = &one_hundred,
926 },
927 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800929 .data = &dirty_writeback_interval,
930 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 .mode = 0644,
932 .proc_handler = &dirty_writeback_centisecs_handler,
933 },
934 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800936 .data = &dirty_expire_interval,
937 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800939 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 },
941 {
942 .ctl_name = VM_NR_PDFLUSH_THREADS,
943 .procname = "nr_pdflush_threads",
944 .data = &nr_pdflush_threads,
945 .maxlen = sizeof nr_pdflush_threads,
946 .mode = 0444 /* read-only*/,
947 .proc_handler = &proc_dointvec,
948 },
949 {
950 .ctl_name = VM_SWAPPINESS,
951 .procname = "swappiness",
952 .data = &vm_swappiness,
953 .maxlen = sizeof(vm_swappiness),
954 .mode = 0644,
955 .proc_handler = &proc_dointvec_minmax,
956 .strategy = &sysctl_intvec,
957 .extra1 = &zero,
958 .extra2 = &one_hundred,
959 },
960#ifdef CONFIG_HUGETLB_PAGE
961 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 .procname = "nr_hugepages",
963 .data = &max_huge_pages,
964 .maxlen = sizeof(unsigned long),
965 .mode = 0644,
966 .proc_handler = &hugetlb_sysctl_handler,
967 .extra1 = (void *)&hugetlb_zero,
968 .extra2 = (void *)&hugetlb_infinity,
969 },
970 {
971 .ctl_name = VM_HUGETLB_GROUP,
972 .procname = "hugetlb_shm_group",
973 .data = &sysctl_hugetlb_shm_group,
974 .maxlen = sizeof(gid_t),
975 .mode = 0644,
976 .proc_handler = &proc_dointvec,
977 },
Mel Gorman396faf02007-07-17 04:03:13 -0700978 {
979 .ctl_name = CTL_UNNUMBERED,
980 .procname = "hugepages_treat_as_movable",
981 .data = &hugepages_treat_as_movable,
982 .maxlen = sizeof(int),
983 .mode = 0644,
984 .proc_handler = &hugetlb_treat_movable_handler,
985 },
Adam Litke54f9f802007-10-16 01:26:20 -0700986 {
987 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800988 .procname = "nr_overcommit_hugepages",
989 .data = &nr_overcommit_huge_pages,
990 .maxlen = sizeof(nr_overcommit_huge_pages),
991 .mode = 0644,
992 .proc_handler = &proc_doulongvec_minmax,
993 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994#endif
995 {
996 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
997 .procname = "lowmem_reserve_ratio",
998 .data = &sysctl_lowmem_reserve_ratio,
999 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1000 .mode = 0644,
1001 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1002 .strategy = &sysctl_intvec,
1003 },
1004 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001005 .ctl_name = VM_DROP_PAGECACHE,
1006 .procname = "drop_caches",
1007 .data = &sysctl_drop_caches,
1008 .maxlen = sizeof(int),
1009 .mode = 0644,
1010 .proc_handler = drop_caches_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1012 },
1013 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 .ctl_name = VM_MIN_FREE_KBYTES,
1015 .procname = "min_free_kbytes",
1016 .data = &min_free_kbytes,
1017 .maxlen = sizeof(min_free_kbytes),
1018 .mode = 0644,
1019 .proc_handler = &min_free_kbytes_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1021 .extra1 = &zero,
1022 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001023 {
1024 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1025 .procname = "percpu_pagelist_fraction",
1026 .data = &percpu_pagelist_fraction,
1027 .maxlen = sizeof(percpu_pagelist_fraction),
1028 .mode = 0644,
1029 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1030 .strategy = &sysctl_intvec,
1031 .extra1 = &min_percpu_pagelist_fract,
1032 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033#ifdef CONFIG_MMU
1034 {
1035 .ctl_name = VM_MAX_MAP_COUNT,
1036 .procname = "max_map_count",
1037 .data = &sysctl_max_map_count,
1038 .maxlen = sizeof(sysctl_max_map_count),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec
1041 },
1042#endif
1043 {
1044 .ctl_name = VM_LAPTOP_MODE,
1045 .procname = "laptop_mode",
1046 .data = &laptop_mode,
1047 .maxlen = sizeof(laptop_mode),
1048 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001049 .proc_handler = &proc_dointvec_jiffies,
1050 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 },
1052 {
1053 .ctl_name = VM_BLOCK_DUMP,
1054 .procname = "block_dump",
1055 .data = &block_dump,
1056 .maxlen = sizeof(block_dump),
1057 .mode = 0644,
1058 .proc_handler = &proc_dointvec,
1059 .strategy = &sysctl_intvec,
1060 .extra1 = &zero,
1061 },
1062 {
1063 .ctl_name = VM_VFS_CACHE_PRESSURE,
1064 .procname = "vfs_cache_pressure",
1065 .data = &sysctl_vfs_cache_pressure,
1066 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1067 .mode = 0644,
1068 .proc_handler = &proc_dointvec,
1069 .strategy = &sysctl_intvec,
1070 .extra1 = &zero,
1071 },
1072#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1073 {
1074 .ctl_name = VM_LEGACY_VA_LAYOUT,
1075 .procname = "legacy_va_layout",
1076 .data = &sysctl_legacy_va_layout,
1077 .maxlen = sizeof(sysctl_legacy_va_layout),
1078 .mode = 0644,
1079 .proc_handler = &proc_dointvec,
1080 .strategy = &sysctl_intvec,
1081 .extra1 = &zero,
1082 },
1083#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001084#ifdef CONFIG_NUMA
1085 {
1086 .ctl_name = VM_ZONE_RECLAIM_MODE,
1087 .procname = "zone_reclaim_mode",
1088 .data = &zone_reclaim_mode,
1089 .maxlen = sizeof(zone_reclaim_mode),
1090 .mode = 0644,
1091 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001092 .strategy = &sysctl_intvec,
1093 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001094 },
Christoph Lameter96146342006-07-03 00:24:13 -07001095 {
1096 .ctl_name = VM_MIN_UNMAPPED,
1097 .procname = "min_unmapped_ratio",
1098 .data = &sysctl_min_unmapped_ratio,
1099 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1100 .mode = 0644,
1101 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1102 .strategy = &sysctl_intvec,
1103 .extra1 = &zero,
1104 .extra2 = &one_hundred,
1105 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001106 {
1107 .ctl_name = VM_MIN_SLAB,
1108 .procname = "min_slab_ratio",
1109 .data = &sysctl_min_slab_ratio,
1110 .maxlen = sizeof(sysctl_min_slab_ratio),
1111 .mode = 0644,
1112 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1113 .strategy = &sysctl_intvec,
1114 .extra1 = &zero,
1115 .extra2 = &one_hundred,
1116 },
Christoph Lameter17436602006-01-18 17:42:32 -08001117#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001118#ifdef CONFIG_SMP
1119 {
1120 .ctl_name = CTL_UNNUMBERED,
1121 .procname = "stat_interval",
1122 .data = &sysctl_stat_interval,
1123 .maxlen = sizeof(sysctl_stat_interval),
1124 .mode = 0644,
1125 .proc_handler = &proc_dointvec_jiffies,
1126 .strategy = &sysctl_jiffies,
1127 },
1128#endif
Eric Parised032182007-06-28 15:55:21 -04001129#ifdef CONFIG_SECURITY
1130 {
1131 .ctl_name = CTL_UNNUMBERED,
1132 .procname = "mmap_min_addr",
1133 .data = &mmap_min_addr,
1134 .maxlen = sizeof(unsigned long),
1135 .mode = 0644,
1136 .proc_handler = &proc_doulongvec_minmax,
1137 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001138#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001139#ifdef CONFIG_NUMA
1140 {
1141 .ctl_name = CTL_UNNUMBERED,
1142 .procname = "numa_zonelist_order",
1143 .data = &numa_zonelist_order,
1144 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1145 .mode = 0644,
1146 .proc_handler = &numa_zonelist_order_handler,
1147 .strategy = &sysctl_string,
1148 },
1149#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001150#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001151 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001152 {
1153 .ctl_name = VM_VDSO_ENABLED,
1154 .procname = "vdso_enabled",
1155 .data = &vdso_enabled,
1156 .maxlen = sizeof(vdso_enabled),
1157 .mode = 0644,
1158 .proc_handler = &proc_dointvec,
1159 .strategy = &sysctl_intvec,
1160 .extra1 = &zero,
1161 },
1162#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001163/*
1164 * NOTE: do not add new entries to this table unless you have read
1165 * Documentation/sysctl/ctl_unnumbered.txt
1166 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 { .ctl_name = 0 }
1168};
1169
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001170#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001171static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001172 { .ctl_name = 0 }
1173};
1174#endif
1175
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001176static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 {
1178 .ctl_name = FS_NRINODE,
1179 .procname = "inode-nr",
1180 .data = &inodes_stat,
1181 .maxlen = 2*sizeof(int),
1182 .mode = 0444,
1183 .proc_handler = &proc_dointvec,
1184 },
1185 {
1186 .ctl_name = FS_STATINODE,
1187 .procname = "inode-state",
1188 .data = &inodes_stat,
1189 .maxlen = 7*sizeof(int),
1190 .mode = 0444,
1191 .proc_handler = &proc_dointvec,
1192 },
1193 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 .procname = "file-nr",
1195 .data = &files_stat,
1196 .maxlen = 3*sizeof(int),
1197 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001198 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 },
1200 {
1201 .ctl_name = FS_MAXFILE,
1202 .procname = "file-max",
1203 .data = &files_stat.max_files,
1204 .maxlen = sizeof(int),
1205 .mode = 0644,
1206 .proc_handler = &proc_dointvec,
1207 },
1208 {
1209 .ctl_name = FS_DENTRY,
1210 .procname = "dentry-state",
1211 .data = &dentry_stat,
1212 .maxlen = 6*sizeof(int),
1213 .mode = 0444,
1214 .proc_handler = &proc_dointvec,
1215 },
1216 {
1217 .ctl_name = FS_OVERFLOWUID,
1218 .procname = "overflowuid",
1219 .data = &fs_overflowuid,
1220 .maxlen = sizeof(int),
1221 .mode = 0644,
1222 .proc_handler = &proc_dointvec_minmax,
1223 .strategy = &sysctl_intvec,
1224 .extra1 = &minolduid,
1225 .extra2 = &maxolduid,
1226 },
1227 {
1228 .ctl_name = FS_OVERFLOWGID,
1229 .procname = "overflowgid",
1230 .data = &fs_overflowgid,
1231 .maxlen = sizeof(int),
1232 .mode = 0644,
1233 .proc_handler = &proc_dointvec_minmax,
1234 .strategy = &sysctl_intvec,
1235 .extra1 = &minolduid,
1236 .extra2 = &maxolduid,
1237 },
1238 {
1239 .ctl_name = FS_LEASES,
1240 .procname = "leases-enable",
1241 .data = &leases_enable,
1242 .maxlen = sizeof(int),
1243 .mode = 0644,
1244 .proc_handler = &proc_dointvec,
1245 },
1246#ifdef CONFIG_DNOTIFY
1247 {
1248 .ctl_name = FS_DIR_NOTIFY,
1249 .procname = "dir-notify-enable",
1250 .data = &dir_notify_enable,
1251 .maxlen = sizeof(int),
1252 .mode = 0644,
1253 .proc_handler = &proc_dointvec,
1254 },
1255#endif
1256#ifdef CONFIG_MMU
1257 {
1258 .ctl_name = FS_LEASE_TIME,
1259 .procname = "lease-break-time",
1260 .data = &lease_break_time,
1261 .maxlen = sizeof(int),
1262 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001263 .proc_handler = &proc_dointvec_minmax,
1264 .strategy = &sysctl_intvec,
1265 .extra1 = &zero,
1266 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 },
1268 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 .procname = "aio-nr",
1270 .data = &aio_nr,
1271 .maxlen = sizeof(aio_nr),
1272 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001273 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 },
1275 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 .procname = "aio-max-nr",
1277 .data = &aio_max_nr,
1278 .maxlen = sizeof(aio_max_nr),
1279 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001280 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001282#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001283 {
1284 .ctl_name = FS_INOTIFY,
1285 .procname = "inotify",
1286 .mode = 0555,
1287 .child = inotify_table,
1288 },
1289#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001291 {
1292 .ctl_name = KERN_SETUID_DUMPABLE,
1293 .procname = "suid_dumpable",
1294 .data = &suid_dumpable,
1295 .maxlen = sizeof(int),
1296 .mode = 0644,
1297 .proc_handler = &proc_dointvec,
1298 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001299#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1300 {
1301 .ctl_name = CTL_UNNUMBERED,
1302 .procname = "binfmt_misc",
1303 .mode = 0555,
1304 .child = binfmt_misc_table,
1305 },
1306#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001307/*
1308 * NOTE: do not add new entries to this table unless you have read
1309 * Documentation/sysctl/ctl_unnumbered.txt
1310 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 { .ctl_name = 0 }
1312};
1313
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001314static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001315#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001316 {
1317 .ctl_name = CTL_UNNUMBERED,
1318 .procname = "exception-trace",
1319 .data = &show_unhandled_signals,
1320 .maxlen = sizeof(int),
1321 .mode = 0644,
1322 .proc_handler = proc_dointvec
1323 },
1324#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 { .ctl_name = 0 }
1326};
1327
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001328static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001330};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
Al Viro330d57f2005-11-04 10:18:40 +00001332static DEFINE_SPINLOCK(sysctl_lock);
1333
1334/* called under sysctl_lock */
1335static int use_table(struct ctl_table_header *p)
1336{
1337 if (unlikely(p->unregistering))
1338 return 0;
1339 p->used++;
1340 return 1;
1341}
1342
1343/* called under sysctl_lock */
1344static void unuse_table(struct ctl_table_header *p)
1345{
1346 if (!--p->used)
1347 if (unlikely(p->unregistering))
1348 complete(p->unregistering);
1349}
1350
1351/* called under sysctl_lock, will reacquire if has to wait */
1352static void start_unregistering(struct ctl_table_header *p)
1353{
1354 /*
1355 * if p->used is 0, nobody will ever touch that entry again;
1356 * we'll eliminate all paths to it before dropping sysctl_lock
1357 */
1358 if (unlikely(p->used)) {
1359 struct completion wait;
1360 init_completion(&wait);
1361 p->unregistering = &wait;
1362 spin_unlock(&sysctl_lock);
1363 wait_for_completion(&wait);
1364 spin_lock(&sysctl_lock);
1365 }
1366 /*
1367 * do not remove from the list until nobody holds it; walking the
1368 * list in do_sysctl() relies on that.
1369 */
1370 list_del_init(&p->ctl_entry);
1371}
1372
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001373void sysctl_head_finish(struct ctl_table_header *head)
1374{
1375 if (!head)
1376 return;
1377 spin_lock(&sysctl_lock);
1378 unuse_table(head);
1379 spin_unlock(&sysctl_lock);
1380}
1381
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001382static struct list_head *
1383lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001384{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001385 struct list_head *header_list;
1386 header_list = &root->header_list;
1387 if (root->lookup)
1388 header_list = root->lookup(root, namespaces);
1389 return header_list;
1390}
1391
1392struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1393 struct ctl_table_header *prev)
1394{
1395 struct ctl_table_root *root;
1396 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001397 struct ctl_table_header *head;
1398 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001399
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001400 spin_lock(&sysctl_lock);
1401 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001402 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001403 tmp = &prev->ctl_entry;
1404 unuse_table(prev);
1405 goto next;
1406 }
1407 tmp = &root_table_header.ctl_entry;
1408 for (;;) {
1409 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1410
1411 if (!use_table(head))
1412 goto next;
1413 spin_unlock(&sysctl_lock);
1414 return head;
1415 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001416 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001417 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001418 header_list = lookup_header_list(root, namespaces);
1419 if (tmp != header_list)
1420 continue;
1421
1422 do {
1423 root = list_entry(root->root_list.next,
1424 struct ctl_table_root, root_list);
1425 if (root == &sysctl_table_root)
1426 goto out;
1427 header_list = lookup_header_list(root, namespaces);
1428 } while (list_empty(header_list));
1429 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001430 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001431out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001432 spin_unlock(&sysctl_lock);
1433 return NULL;
1434}
1435
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001436struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1437{
1438 return __sysctl_head_next(current->nsproxy, prev);
1439}
1440
1441void register_sysctl_root(struct ctl_table_root *root)
1442{
1443 spin_lock(&sysctl_lock);
1444 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1445 spin_unlock(&sysctl_lock);
1446}
1447
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001448#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1450 void __user *newval, size_t newlen)
1451{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001452 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001453 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
1455 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1456 return -ENOTDIR;
1457 if (oldval) {
1458 int old_len;
1459 if (!oldlenp || get_user(old_len, oldlenp))
1460 return -EFAULT;
1461 }
Al Viro330d57f2005-11-04 10:18:40 +00001462
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001463 for (head = sysctl_head_next(NULL); head;
1464 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001465 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001466 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001467 if (error != -ENOTDIR) {
1468 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001469 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001470 }
1471 }
Al Viro330d57f2005-11-04 10:18:40 +00001472 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
1475asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1476{
1477 struct __sysctl_args tmp;
1478 int error;
1479
1480 if (copy_from_user(&tmp, args, sizeof(tmp)))
1481 return -EFAULT;
1482
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001483 error = deprecated_sysctl_warning(&tmp);
1484 if (error)
1485 goto out;
1486
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 lock_kernel();
1488 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1489 tmp.newval, tmp.newlen);
1490 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001491out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 return error;
1493}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001494#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
1496/*
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001497 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 * some sysctl variables are readonly even to root.
1499 */
1500
1501static int test_perm(int mode, int op)
1502{
1503 if (!current->euid)
1504 mode >>= 6;
1505 else if (in_egroup_p(0))
1506 mode >>= 3;
1507 if ((mode & op & 0007) == op)
1508 return 0;
1509 return -EACCES;
1510}
1511
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001512int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
1514 int error;
1515 error = security_sysctl(table, op);
1516 if (error)
1517 return error;
1518 return test_perm(table->mode, op);
1519}
1520
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001521#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522static int parse_table(int __user *name, int nlen,
1523 void __user *oldval, size_t __user *oldlenp,
1524 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001525 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
1527 int n;
1528repeat:
1529 if (!nlen)
1530 return -ENOTDIR;
1531 if (get_user(n, name))
1532 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001533 for ( ; table->ctl_name || table->procname; table++) {
1534 if (!table->ctl_name)
1535 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001536 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 int error;
1538 if (table->child) {
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001539 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 name++;
1542 nlen--;
1543 table = table->child;
1544 goto repeat;
1545 }
1546 error = do_sysctl_strategy(table, name, nlen,
1547 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001548 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 return error;
1550 }
1551 }
1552 return -ENOTDIR;
1553}
1554
1555/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001556int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 int __user *name, int nlen,
1558 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001559 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560{
1561 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 if (oldval)
1564 op |= 004;
1565 if (newval)
1566 op |= 002;
Eric W. Biederman1ff007eb2007-02-14 00:34:11 -08001567 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 return -EPERM;
1569
1570 if (table->strategy) {
1571 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001572 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 if (rc < 0)
1574 return rc;
1575 if (rc > 0)
1576 return 0;
1577 }
1578
1579 /* If there is no strategy routine, or if the strategy returns
1580 * zero, proceed with automatic r/w */
1581 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001582 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1583 newval, newlen);
1584 if (rc < 0)
1585 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 }
1587 return 0;
1588}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001589#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001591static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1592{
1593 for (; table->ctl_name || table->procname; table++) {
1594 table->parent = parent;
1595 if (table->child)
1596 sysctl_set_parent(table, table->child);
1597 }
1598}
1599
1600static __init int sysctl_init(void)
1601{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001602 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001603 sysctl_set_parent(NULL, root_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001604 err = sysctl_check_table(current->nsproxy, root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001605 return 0;
1606}
1607
1608core_initcall(sysctl_init);
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001611 * __register_sysctl_paths - register a sysctl hierarchy
1612 * @root: List of sysctl headers to register on
1613 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001614 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 *
1617 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001618 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001620 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 *
1622 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1623 * must be unique within that level of sysctl
1624 *
1625 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1626 * enter a sysctl file
1627 *
1628 * data - a pointer to data for use by proc_handler
1629 *
1630 * maxlen - the maximum size in bytes of the data
1631 *
1632 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1633 *
1634 * child - a pointer to the child sysctl table if this entry is a directory, or
1635 * %NULL.
1636 *
1637 * proc_handler - the text handler routine (described below)
1638 *
1639 * strategy - the strategy routine (described below)
1640 *
1641 * de - for internal use by the sysctl routines
1642 *
1643 * extra1, extra2 - extra pointers usable by the proc handler routines
1644 *
1645 * Leaf nodes in the sysctl tree will be represented by a single file
1646 * under /proc; non-leaf nodes will be represented by directories.
1647 *
1648 * sysctl(2) can automatically manage read and write requests through
1649 * the sysctl table. The data and maxlen fields of the ctl_table
1650 * struct enable minimal validation of the values being written to be
1651 * performed, and the mode field allows minimal authentication.
1652 *
1653 * More sophisticated management can be enabled by the provision of a
1654 * strategy routine with the table entry. This will be called before
1655 * any automatic read or write of the data is performed.
1656 *
1657 * The strategy routine may return
1658 *
1659 * < 0 - Error occurred (error is passed to user process)
1660 *
1661 * 0 - OK - proceed with automatic read or write.
1662 *
1663 * > 0 - OK - read or write has been done by the strategy routine, so
1664 * return immediately.
1665 *
1666 * There must be a proc_handler routine for any terminal nodes
1667 * mirrored under /proc/sys (non-terminals are handled by a built-in
1668 * directory handler). Several default handlers are available to
1669 * cover common cases -
1670 *
1671 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1672 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1673 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1674 *
1675 * It is the handler's job to read the input buffer from user memory
1676 * and process it. The handler should return 0 on success.
1677 *
1678 * This routine returns %NULL on a failure to register, and a pointer
1679 * to the table header on success.
1680 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001681struct ctl_table_header *__register_sysctl_paths(
1682 struct ctl_table_root *root,
1683 struct nsproxy *namespaces,
1684 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001686 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001687 struct ctl_table_header *header;
1688 struct ctl_table *new, **prevp;
1689 unsigned int n, npath;
1690
1691 /* Count the path components */
1692 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1693 ;
1694
1695 /*
1696 * For each path component, allocate a 2-element ctl_table array.
1697 * The first array element will be filled with the sysctl entry
1698 * for this, the second will be the sentinel (ctl_name == 0).
1699 *
1700 * We allocate everything in one go so that we don't have to
1701 * worry about freeing additional memory in unregister_sysctl_table.
1702 */
1703 header = kzalloc(sizeof(struct ctl_table_header) +
1704 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1705 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001707
1708 new = (struct ctl_table *) (header + 1);
1709
1710 /* Now connect the dots */
1711 prevp = &header->ctl_table;
1712 for (n = 0; n < npath; ++n, ++path) {
1713 /* Copy the procname */
1714 new->procname = path->procname;
1715 new->ctl_name = path->ctl_name;
1716 new->mode = 0555;
1717
1718 *prevp = new;
1719 prevp = &new->child;
1720
1721 new += 2;
1722 }
1723 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001724 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001725
1726 INIT_LIST_HEAD(&header->ctl_entry);
1727 header->used = 0;
1728 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001729 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001730 sysctl_set_parent(NULL, header->ctl_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001731 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001732 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001733 return NULL;
1734 }
Al Viro330d57f2005-11-04 10:18:40 +00001735 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001736 header_list = lookup_header_list(root, namespaces);
1737 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001738 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001739
1740 return header;
1741}
1742
1743/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001744 * register_sysctl_table_path - register a sysctl table hierarchy
1745 * @path: The path to the directory the sysctl table is in.
1746 * @table: the top-level table structure
1747 *
1748 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1749 * array. A completely 0 filled entry terminates the table.
1750 *
1751 * See __register_sysctl_paths for more details.
1752 */
1753struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1754 struct ctl_table *table)
1755{
1756 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1757 path, table);
1758}
1759
1760/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001761 * register_sysctl_table - register a sysctl table hierarchy
1762 * @table: the top-level table structure
1763 *
1764 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1765 * array. A completely 0 filled entry terminates the table.
1766 *
1767 * See register_sysctl_paths for more details.
1768 */
1769struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1770{
1771 static const struct ctl_path null_path[] = { {} };
1772
1773 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774}
1775
1776/**
1777 * unregister_sysctl_table - unregister a sysctl table hierarchy
1778 * @header: the header returned from register_sysctl_table
1779 *
1780 * Unregisters the sysctl table and all children. proc entries may not
1781 * actually be removed until they are no longer used by anyone.
1782 */
1783void unregister_sysctl_table(struct ctl_table_header * header)
1784{
Al Viro330d57f2005-11-04 10:18:40 +00001785 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001786
1787 if (header == NULL)
1788 return;
1789
Al Viro330d57f2005-11-04 10:18:40 +00001790 spin_lock(&sysctl_lock);
1791 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001792 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 kfree(header);
1794}
1795
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001796#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001797struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001798{
1799 return NULL;
1800}
1801
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001802struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1803 struct ctl_table *table)
1804{
1805 return NULL;
1806}
1807
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001808void unregister_sysctl_table(struct ctl_table_header * table)
1809{
1810}
1811
1812#endif /* CONFIG_SYSCTL */
1813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814/*
1815 * /proc/sys support
1816 */
1817
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001818#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001820static int _proc_do_string(void* data, int maxlen, int write,
1821 struct file *filp, void __user *buffer,
1822 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001823{
1824 size_t len;
1825 char __user *p;
1826 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001827
1828 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001829 *lenp = 0;
1830 return 0;
1831 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001832
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001833 if (write) {
1834 len = 0;
1835 p = buffer;
1836 while (len < *lenp) {
1837 if (get_user(c, p++))
1838 return -EFAULT;
1839 if (c == 0 || c == '\n')
1840 break;
1841 len++;
1842 }
1843 if (len >= maxlen)
1844 len = maxlen-1;
1845 if(copy_from_user(data, buffer, len))
1846 return -EFAULT;
1847 ((char *) data)[len] = 0;
1848 *ppos += *lenp;
1849 } else {
1850 len = strlen(data);
1851 if (len > maxlen)
1852 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001853
1854 if (*ppos > len) {
1855 *lenp = 0;
1856 return 0;
1857 }
1858
1859 data += *ppos;
1860 len -= *ppos;
1861
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001862 if (len > *lenp)
1863 len = *lenp;
1864 if (len)
1865 if(copy_to_user(buffer, data, len))
1866 return -EFAULT;
1867 if (len < *lenp) {
1868 if(put_user('\n', ((char __user *) buffer) + len))
1869 return -EFAULT;
1870 len++;
1871 }
1872 *lenp = len;
1873 *ppos += len;
1874 }
1875 return 0;
1876}
1877
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878/**
1879 * proc_dostring - read a string sysctl
1880 * @table: the sysctl table
1881 * @write: %TRUE if this is a write to the sysctl file
1882 * @filp: the file structure
1883 * @buffer: the user buffer
1884 * @lenp: the size of the user buffer
1885 * @ppos: file position
1886 *
1887 * Reads/writes a string from/to the user buffer. If the kernel
1888 * buffer provided is not large enough to hold the string, the
1889 * string is truncated. The copied string is %NULL-terminated.
1890 * If the string is being read by the user process, it is copied
1891 * and a newline '\n' is added. It is truncated if the buffer is
1892 * not large enough.
1893 *
1894 * Returns 0 on success.
1895 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001896int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 void __user *buffer, size_t *lenp, loff_t *ppos)
1898{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001899 return _proc_do_string(table->data, table->maxlen, write, filp,
1900 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903
1904static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1905 int *valp,
1906 int write, void *data)
1907{
1908 if (write) {
1909 *valp = *negp ? -*lvalp : *lvalp;
1910 } else {
1911 int val = *valp;
1912 if (val < 0) {
1913 *negp = -1;
1914 *lvalp = (unsigned long)-val;
1915 } else {
1916 *negp = 0;
1917 *lvalp = (unsigned long)val;
1918 }
1919 }
1920 return 0;
1921}
1922
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001923static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001924 int write, struct file *filp, void __user *buffer,
1925 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1927 int write, void *data),
1928 void *data)
1929{
1930#define TMPBUFLEN 21
1931 int *i, vleft, first=1, neg, val;
1932 unsigned long lval;
1933 size_t left, len;
1934
1935 char buf[TMPBUFLEN], *p;
1936 char __user *s = buffer;
1937
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001938 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 (*ppos && !write)) {
1940 *lenp = 0;
1941 return 0;
1942 }
1943
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001944 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 vleft = table->maxlen / sizeof(*i);
1946 left = *lenp;
1947
1948 if (!conv)
1949 conv = do_proc_dointvec_conv;
1950
1951 for (; left && vleft--; i++, first=0) {
1952 if (write) {
1953 while (left) {
1954 char c;
1955 if (get_user(c, s))
1956 return -EFAULT;
1957 if (!isspace(c))
1958 break;
1959 left--;
1960 s++;
1961 }
1962 if (!left)
1963 break;
1964 neg = 0;
1965 len = left;
1966 if (len > sizeof(buf) - 1)
1967 len = sizeof(buf) - 1;
1968 if (copy_from_user(buf, s, len))
1969 return -EFAULT;
1970 buf[len] = 0;
1971 p = buf;
1972 if (*p == '-' && left > 1) {
1973 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001974 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 }
1976 if (*p < '0' || *p > '9')
1977 break;
1978
1979 lval = simple_strtoul(p, &p, 0);
1980
1981 len = p-buf;
1982 if ((len < left) && *p && !isspace(*p))
1983 break;
1984 if (neg)
1985 val = -val;
1986 s += len;
1987 left -= len;
1988
1989 if (conv(&neg, &lval, i, 1, data))
1990 break;
1991 } else {
1992 p = buf;
1993 if (!first)
1994 *p++ = '\t';
1995
1996 if (conv(&neg, &lval, i, 0, data))
1997 break;
1998
1999 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2000 len = strlen(buf);
2001 if (len > left)
2002 len = left;
2003 if(copy_to_user(s, buf, len))
2004 return -EFAULT;
2005 left -= len;
2006 s += len;
2007 }
2008 }
2009
2010 if (!write && !first && left) {
2011 if(put_user('\n', s))
2012 return -EFAULT;
2013 left--, s++;
2014 }
2015 if (write) {
2016 while (left) {
2017 char c;
2018 if (get_user(c, s++))
2019 return -EFAULT;
2020 if (!isspace(c))
2021 break;
2022 left--;
2023 }
2024 }
2025 if (write && first)
2026 return -EINVAL;
2027 *lenp -= left;
2028 *ppos += *lenp;
2029 return 0;
2030#undef TMPBUFLEN
2031}
2032
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002033static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002034 void __user *buffer, size_t *lenp, loff_t *ppos,
2035 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2036 int write, void *data),
2037 void *data)
2038{
2039 return __do_proc_dointvec(table->data, table, write, filp,
2040 buffer, lenp, ppos, conv, data);
2041}
2042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043/**
2044 * proc_dointvec - read a vector of integers
2045 * @table: the sysctl table
2046 * @write: %TRUE if this is a write to the sysctl file
2047 * @filp: the file structure
2048 * @buffer: the user buffer
2049 * @lenp: the size of the user buffer
2050 * @ppos: file position
2051 *
2052 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2053 * values from/to the user buffer, treated as an ASCII string.
2054 *
2055 * Returns 0 on success.
2056 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002057int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 void __user *buffer, size_t *lenp, loff_t *ppos)
2059{
2060 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2061 NULL,NULL);
2062}
2063
2064#define OP_SET 0
2065#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002066#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2069 int *valp,
2070 int write, void *data)
2071{
2072 int op = *(int *)data;
2073 if (write) {
2074 int val = *negp ? -*lvalp : *lvalp;
2075 switch(op) {
2076 case OP_SET: *valp = val; break;
2077 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002078 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 }
2080 } else {
2081 int val = *valp;
2082 if (val < 0) {
2083 *negp = -1;
2084 *lvalp = (unsigned long)-val;
2085 } else {
2086 *negp = 0;
2087 *lvalp = (unsigned long)val;
2088 }
2089 }
2090 return 0;
2091}
2092
Andrew Morgan72c2d582007-10-18 03:05:59 -07002093#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094/*
2095 * init may raise the set.
2096 */
Andrew Morgan72c2d582007-10-18 03:05:59 -07002097
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002098int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 void __user *buffer, size_t *lenp, loff_t *ppos)
2100{
2101 int op;
2102
Eric Paris6ff1b442007-02-10 01:43:19 -08002103 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 return -EPERM;
2105 }
2106
Serge E. Hallynb460cbc2007-10-18 23:39:52 -07002107 op = is_global_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2109 do_proc_dointvec_bset_conv,&op);
2110}
Andrew Morgan72c2d582007-10-18 03:05:59 -07002111#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002113/*
2114 * Taint values can only be increased
2115 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002116static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002117 void __user *buffer, size_t *lenp, loff_t *ppos)
2118{
2119 int op;
2120
Bastian Blank91fcd412007-04-23 14:41:14 -07002121 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002122 return -EPERM;
2123
2124 op = OP_OR;
2125 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2126 do_proc_dointvec_bset_conv,&op);
2127}
2128
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129struct do_proc_dointvec_minmax_conv_param {
2130 int *min;
2131 int *max;
2132};
2133
2134static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2135 int *valp,
2136 int write, void *data)
2137{
2138 struct do_proc_dointvec_minmax_conv_param *param = data;
2139 if (write) {
2140 int val = *negp ? -*lvalp : *lvalp;
2141 if ((param->min && *param->min > val) ||
2142 (param->max && *param->max < val))
2143 return -EINVAL;
2144 *valp = val;
2145 } else {
2146 int val = *valp;
2147 if (val < 0) {
2148 *negp = -1;
2149 *lvalp = (unsigned long)-val;
2150 } else {
2151 *negp = 0;
2152 *lvalp = (unsigned long)val;
2153 }
2154 }
2155 return 0;
2156}
2157
2158/**
2159 * proc_dointvec_minmax - read a vector of integers with min/max values
2160 * @table: the sysctl table
2161 * @write: %TRUE if this is a write to the sysctl file
2162 * @filp: the file structure
2163 * @buffer: the user buffer
2164 * @lenp: the size of the user buffer
2165 * @ppos: file position
2166 *
2167 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2168 * values from/to the user buffer, treated as an ASCII string.
2169 *
2170 * This routine will ensure the values are within the range specified by
2171 * table->extra1 (min) and table->extra2 (max).
2172 *
2173 * Returns 0 on success.
2174 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002175int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 void __user *buffer, size_t *lenp, loff_t *ppos)
2177{
2178 struct do_proc_dointvec_minmax_conv_param param = {
2179 .min = (int *) table->extra1,
2180 .max = (int *) table->extra2,
2181 };
2182 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2183 do_proc_dointvec_minmax_conv, &param);
2184}
2185
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002186static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 struct file *filp,
2188 void __user *buffer,
2189 size_t *lenp, loff_t *ppos,
2190 unsigned long convmul,
2191 unsigned long convdiv)
2192{
2193#define TMPBUFLEN 21
2194 unsigned long *i, *min, *max, val;
2195 int vleft, first=1, neg;
2196 size_t len, left;
2197 char buf[TMPBUFLEN], *p;
2198 char __user *s = buffer;
2199
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002200 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 (*ppos && !write)) {
2202 *lenp = 0;
2203 return 0;
2204 }
2205
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002206 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 min = (unsigned long *) table->extra1;
2208 max = (unsigned long *) table->extra2;
2209 vleft = table->maxlen / sizeof(unsigned long);
2210 left = *lenp;
2211
2212 for (; left && vleft--; i++, min++, max++, first=0) {
2213 if (write) {
2214 while (left) {
2215 char c;
2216 if (get_user(c, s))
2217 return -EFAULT;
2218 if (!isspace(c))
2219 break;
2220 left--;
2221 s++;
2222 }
2223 if (!left)
2224 break;
2225 neg = 0;
2226 len = left;
2227 if (len > TMPBUFLEN-1)
2228 len = TMPBUFLEN-1;
2229 if (copy_from_user(buf, s, len))
2230 return -EFAULT;
2231 buf[len] = 0;
2232 p = buf;
2233 if (*p == '-' && left > 1) {
2234 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002235 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 }
2237 if (*p < '0' || *p > '9')
2238 break;
2239 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2240 len = p-buf;
2241 if ((len < left) && *p && !isspace(*p))
2242 break;
2243 if (neg)
2244 val = -val;
2245 s += len;
2246 left -= len;
2247
2248 if(neg)
2249 continue;
2250 if ((min && val < *min) || (max && val > *max))
2251 continue;
2252 *i = val;
2253 } else {
2254 p = buf;
2255 if (!first)
2256 *p++ = '\t';
2257 sprintf(p, "%lu", convdiv * (*i) / convmul);
2258 len = strlen(buf);
2259 if (len > left)
2260 len = left;
2261 if(copy_to_user(s, buf, len))
2262 return -EFAULT;
2263 left -= len;
2264 s += len;
2265 }
2266 }
2267
2268 if (!write && !first && left) {
2269 if(put_user('\n', s))
2270 return -EFAULT;
2271 left--, s++;
2272 }
2273 if (write) {
2274 while (left) {
2275 char c;
2276 if (get_user(c, s++))
2277 return -EFAULT;
2278 if (!isspace(c))
2279 break;
2280 left--;
2281 }
2282 }
2283 if (write && first)
2284 return -EINVAL;
2285 *lenp -= left;
2286 *ppos += *lenp;
2287 return 0;
2288#undef TMPBUFLEN
2289}
2290
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002291static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002292 struct file *filp,
2293 void __user *buffer,
2294 size_t *lenp, loff_t *ppos,
2295 unsigned long convmul,
2296 unsigned long convdiv)
2297{
2298 return __do_proc_doulongvec_minmax(table->data, table, write,
2299 filp, buffer, lenp, ppos, convmul, convdiv);
2300}
2301
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302/**
2303 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2304 * @table: the sysctl table
2305 * @write: %TRUE if this is a write to the sysctl file
2306 * @filp: the file structure
2307 * @buffer: the user buffer
2308 * @lenp: the size of the user buffer
2309 * @ppos: file position
2310 *
2311 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2312 * values from/to the user buffer, treated as an ASCII string.
2313 *
2314 * This routine will ensure the values are within the range specified by
2315 * table->extra1 (min) and table->extra2 (max).
2316 *
2317 * Returns 0 on success.
2318 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002319int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 void __user *buffer, size_t *lenp, loff_t *ppos)
2321{
2322 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2323}
2324
2325/**
2326 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2327 * @table: the sysctl table
2328 * @write: %TRUE if this is a write to the sysctl file
2329 * @filp: the file structure
2330 * @buffer: the user buffer
2331 * @lenp: the size of the user buffer
2332 * @ppos: file position
2333 *
2334 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2335 * values from/to the user buffer, treated as an ASCII string. The values
2336 * are treated as milliseconds, and converted to jiffies when they are stored.
2337 *
2338 * This routine will ensure the values are within the range specified by
2339 * table->extra1 (min) and table->extra2 (max).
2340 *
2341 * Returns 0 on success.
2342 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002343int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 struct file *filp,
2345 void __user *buffer,
2346 size_t *lenp, loff_t *ppos)
2347{
2348 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2349 lenp, ppos, HZ, 1000l);
2350}
2351
2352
2353static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2354 int *valp,
2355 int write, void *data)
2356{
2357 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002358 if (*lvalp > LONG_MAX / HZ)
2359 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2361 } else {
2362 int val = *valp;
2363 unsigned long lval;
2364 if (val < 0) {
2365 *negp = -1;
2366 lval = (unsigned long)-val;
2367 } else {
2368 *negp = 0;
2369 lval = (unsigned long)val;
2370 }
2371 *lvalp = lval / HZ;
2372 }
2373 return 0;
2374}
2375
2376static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2377 int *valp,
2378 int write, void *data)
2379{
2380 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002381 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2382 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2384 } else {
2385 int val = *valp;
2386 unsigned long lval;
2387 if (val < 0) {
2388 *negp = -1;
2389 lval = (unsigned long)-val;
2390 } else {
2391 *negp = 0;
2392 lval = (unsigned long)val;
2393 }
2394 *lvalp = jiffies_to_clock_t(lval);
2395 }
2396 return 0;
2397}
2398
2399static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2400 int *valp,
2401 int write, void *data)
2402{
2403 if (write) {
2404 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2405 } else {
2406 int val = *valp;
2407 unsigned long lval;
2408 if (val < 0) {
2409 *negp = -1;
2410 lval = (unsigned long)-val;
2411 } else {
2412 *negp = 0;
2413 lval = (unsigned long)val;
2414 }
2415 *lvalp = jiffies_to_msecs(lval);
2416 }
2417 return 0;
2418}
2419
2420/**
2421 * proc_dointvec_jiffies - read a vector of integers as seconds
2422 * @table: the sysctl table
2423 * @write: %TRUE if this is a write to the sysctl file
2424 * @filp: the file structure
2425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
2427 * @ppos: file position
2428 *
2429 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2430 * values from/to the user buffer, treated as an ASCII string.
2431 * The values read are assumed to be in seconds, and are converted into
2432 * jiffies.
2433 *
2434 * Returns 0 on success.
2435 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002436int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 void __user *buffer, size_t *lenp, loff_t *ppos)
2438{
2439 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2440 do_proc_dointvec_jiffies_conv,NULL);
2441}
2442
2443/**
2444 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2445 * @table: the sysctl table
2446 * @write: %TRUE if this is a write to the sysctl file
2447 * @filp: the file structure
2448 * @buffer: the user buffer
2449 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002450 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 *
2452 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2453 * values from/to the user buffer, treated as an ASCII string.
2454 * The values read are assumed to be in 1/USER_HZ seconds, and
2455 * are converted into jiffies.
2456 *
2457 * Returns 0 on success.
2458 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002459int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 void __user *buffer, size_t *lenp, loff_t *ppos)
2461{
2462 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2463 do_proc_dointvec_userhz_jiffies_conv,NULL);
2464}
2465
2466/**
2467 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2468 * @table: the sysctl table
2469 * @write: %TRUE if this is a write to the sysctl file
2470 * @filp: the file structure
2471 * @buffer: the user buffer
2472 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002473 * @ppos: file position
2474 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 *
2476 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2477 * values from/to the user buffer, treated as an ASCII string.
2478 * The values read are assumed to be in 1/1000 seconds, and
2479 * are converted into jiffies.
2480 *
2481 * Returns 0 on success.
2482 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002483int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 void __user *buffer, size_t *lenp, loff_t *ppos)
2485{
2486 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2487 do_proc_dointvec_ms_jiffies_conv, NULL);
2488}
2489
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002490static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002491 void __user *buffer, size_t *lenp, loff_t *ppos)
2492{
2493 struct pid *new_pid;
2494 pid_t tmp;
2495 int r;
2496
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002497 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002498
2499 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2500 lenp, ppos, NULL, NULL);
2501 if (r || !write)
2502 return r;
2503
2504 new_pid = find_get_pid(tmp);
2505 if (!new_pid)
2506 return -ESRCH;
2507
2508 put_pid(xchg(&cad_pid, new_pid));
2509 return 0;
2510}
2511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512#else /* CONFIG_PROC_FS */
2513
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002514int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 void __user *buffer, size_t *lenp, loff_t *ppos)
2516{
2517 return -ENOSYS;
2518}
2519
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002520int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 void __user *buffer, size_t *lenp, loff_t *ppos)
2522{
2523 return -ENOSYS;
2524}
2525
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002526int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 void __user *buffer, size_t *lenp, loff_t *ppos)
2528{
2529 return -ENOSYS;
2530}
2531
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002532int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 void __user *buffer, size_t *lenp, loff_t *ppos)
2534{
2535 return -ENOSYS;
2536}
2537
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002538int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 void __user *buffer, size_t *lenp, loff_t *ppos)
2540{
2541 return -ENOSYS;
2542}
2543
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002544int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 void __user *buffer, size_t *lenp, loff_t *ppos)
2546{
2547 return -ENOSYS;
2548}
2549
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002550int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 void __user *buffer, size_t *lenp, loff_t *ppos)
2552{
2553 return -ENOSYS;
2554}
2555
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002556int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 void __user *buffer, size_t *lenp, loff_t *ppos)
2558{
2559 return -ENOSYS;
2560}
2561
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002562int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 struct file *filp,
2564 void __user *buffer,
2565 size_t *lenp, loff_t *ppos)
2566{
2567 return -ENOSYS;
2568}
2569
2570
2571#endif /* CONFIG_PROC_FS */
2572
2573
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002574#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575/*
2576 * General sysctl support routines
2577 */
2578
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002579/* The generic sysctl data routine (used if no strategy routine supplied) */
2580int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2581 void __user *oldval, size_t __user *oldlenp,
2582 void __user *newval, size_t newlen)
2583{
2584 size_t len;
2585
2586 /* Get out of I don't have a variable */
2587 if (!table->data || !table->maxlen)
2588 return -ENOTDIR;
2589
2590 if (oldval && oldlenp) {
2591 if (get_user(len, oldlenp))
2592 return -EFAULT;
2593 if (len) {
2594 if (len > table->maxlen)
2595 len = table->maxlen;
2596 if (copy_to_user(oldval, table->data, len))
2597 return -EFAULT;
2598 if (put_user(len, oldlenp))
2599 return -EFAULT;
2600 }
2601 }
2602
2603 if (newval && newlen) {
2604 if (newlen > table->maxlen)
2605 newlen = table->maxlen;
2606
2607 if (copy_from_user(table->data, newval, newlen))
2608 return -EFAULT;
2609 }
2610 return 1;
2611}
2612
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002614int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002616 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 if (!table->data || !table->maxlen)
2619 return -ENOTDIR;
2620
2621 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002622 size_t bufsize;
2623 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002625 if (bufsize) {
2626 size_t len = strlen(table->data), copied;
2627
2628 /* This shouldn't trigger for a well-formed sysctl */
2629 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002631
2632 /* Copy up to a max of bufsize-1 bytes of the string */
2633 copied = (len >= bufsize) ? bufsize - 1 : len;
2634
2635 if (copy_to_user(oldval, table->data, copied) ||
2636 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002638 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 return -EFAULT;
2640 }
2641 }
2642 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002643 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 if (len > table->maxlen)
2645 len = table->maxlen;
2646 if(copy_from_user(table->data, newval, len))
2647 return -EFAULT;
2648 if (len == table->maxlen)
2649 len--;
2650 ((char *) table->data)[len] = 0;
2651 }
Yi Yang82c9df82005-12-30 16:37:10 +08002652 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653}
2654
2655/*
2656 * This function makes sure that all of the integers in the vector
2657 * are between the minimum and maximum values given in the arrays
2658 * table->extra1 and table->extra2, respectively.
2659 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002660int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002662 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663{
2664
2665 if (newval && newlen) {
2666 int __user *vec = (int __user *) newval;
2667 int *min = (int *) table->extra1;
2668 int *max = (int *) table->extra2;
2669 size_t length;
2670 int i;
2671
2672 if (newlen % sizeof(int) != 0)
2673 return -EINVAL;
2674
2675 if (!table->extra1 && !table->extra2)
2676 return 0;
2677
2678 if (newlen > table->maxlen)
2679 newlen = table->maxlen;
2680 length = newlen / sizeof(int);
2681
2682 for (i = 0; i < length; i++) {
2683 int value;
2684 if (get_user(value, vec + i))
2685 return -EFAULT;
2686 if (min && value < min[i])
2687 return -EINVAL;
2688 if (max && value > max[i])
2689 return -EINVAL;
2690 }
2691 }
2692 return 0;
2693}
2694
2695/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002696int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002698 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002700 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002702
2703 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002705 if (olen) {
2706 int val;
2707
2708 if (olen < sizeof(int))
2709 return -EINVAL;
2710
2711 val = *(int *)(table->data) / HZ;
2712 if (put_user(val, (int __user *)oldval))
2713 return -EFAULT;
2714 if (put_user(sizeof(int), oldlenp))
2715 return -EFAULT;
2716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 }
2718 if (newval && newlen) {
2719 int new;
2720 if (newlen != sizeof(int))
2721 return -EINVAL;
2722 if (get_user(new, (int __user *)newval))
2723 return -EFAULT;
2724 *(int *)(table->data) = new*HZ;
2725 }
2726 return 1;
2727}
2728
2729/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002730int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002732 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002734 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002736
2737 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002739 if (olen) {
2740 int val;
2741
2742 if (olen < sizeof(int))
2743 return -EINVAL;
2744
2745 val = jiffies_to_msecs(*(int *)(table->data));
2746 if (put_user(val, (int __user *)oldval))
2747 return -EFAULT;
2748 if (put_user(sizeof(int), oldlenp))
2749 return -EFAULT;
2750 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 }
2752 if (newval && newlen) {
2753 int new;
2754 if (newlen != sizeof(int))
2755 return -EINVAL;
2756 if (get_user(new, (int __user *)newval))
2757 return -EFAULT;
2758 *(int *)(table->data) = msecs_to_jiffies(new);
2759 }
2760 return 1;
2761}
2762
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002763
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002764
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002765#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766
2767
2768asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2769{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002770 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002771 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002772
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002773 if (copy_from_user(&tmp, args, sizeof(tmp)))
2774 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002775
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002776 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002777
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002778 /* If no error reading the parameters then just -ENOSYS ... */
2779 if (!error)
2780 error = -ENOSYS;
2781
2782 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783}
2784
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002785int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2786 void __user *oldval, size_t __user *oldlenp,
2787 void __user *newval, size_t newlen)
2788{
2789 return -ENOSYS;
2790}
2791
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002792int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002794 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795{
2796 return -ENOSYS;
2797}
2798
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002799int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002801 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802{
2803 return -ENOSYS;
2804}
2805
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002806int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002808 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809{
2810 return -ENOSYS;
2811}
2812
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002813int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002815 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816{
2817 return -ENOSYS;
2818}
2819
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002820#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002822static int deprecated_sysctl_warning(struct __sysctl_args *args)
2823{
2824 static int msg_count;
2825 int name[CTL_MAXNAME];
2826 int i;
2827
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002828 /* Check args->nlen. */
2829 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2830 return -ENOTDIR;
2831
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002832 /* Read in the sysctl name for better debug message logging */
2833 for (i = 0; i < args->nlen; i++)
2834 if (get_user(name[i], args->name + i))
2835 return -EFAULT;
2836
2837 /* Ignore accesses to kernel.version */
2838 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2839 return 0;
2840
2841 if (msg_count < 5) {
2842 msg_count++;
2843 printk(KERN_INFO
2844 "warning: process `%s' used the deprecated sysctl "
2845 "system call with ", current->comm);
2846 for (i = 0; i < args->nlen; i++)
2847 printk("%d.", name[i]);
2848 printk("\n");
2849 }
2850 return 0;
2851}
2852
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853/*
2854 * No sense putting this after each symbol definition, twice,
2855 * exception granted :-)
2856 */
2857EXPORT_SYMBOL(proc_dointvec);
2858EXPORT_SYMBOL(proc_dointvec_jiffies);
2859EXPORT_SYMBOL(proc_dointvec_minmax);
2860EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2861EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2862EXPORT_SYMBOL(proc_dostring);
2863EXPORT_SYMBOL(proc_doulongvec_minmax);
2864EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2865EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002866EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867EXPORT_SYMBOL(sysctl_intvec);
2868EXPORT_SYMBOL(sysctl_jiffies);
2869EXPORT_SYMBOL(sysctl_ms_jiffies);
2870EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002871EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872EXPORT_SYMBOL(unregister_sysctl_table);