blob: 6fc5e17086f4ec094780161b7c431e98debd0077 [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>
Randy.Dunlapc59ede72006-01-11 12:17:46 -080027#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
30#include <linux/capability.h>
31#include <linux/smp_lock.h>
32#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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#include <asm/uaccess.h>
50#include <asm/processor.h>
51
Dipankar Sarma529bf6b2006-03-07 21:55:35 -080052extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
53 void __user *buffer, size_t *lenp, loff_t *ppos);
54
Andi Kleen29cbc782006-09-30 01:47:55 +020055#ifdef CONFIG_X86
56#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010057#include <asm/stacktrace.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020058#endif
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;
64extern int sysctl_overcommit_memory;
65extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070066extern int sysctl_panic_on_oom;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067extern int max_threads;
68extern int sysrq_enabled;
69extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070070extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern int pid_max;
73extern int min_free_kbytes;
74extern int printk_ratelimit_jiffies;
75extern int printk_ratelimit_burst;
76extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080077extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080078extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020079extern int compat_log;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82static int maxolduid = 65535;
83static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080084static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86static int ngroups_max = NGROUPS_MAX;
87
88#ifdef CONFIG_KMOD
89extern char modprobe_path[];
90#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#ifdef CONFIG_CHR_DEV_SG
92extern int sg_big_buff;
93#endif
94#ifdef CONFIG_SYSVIPC
Kirill Korotaevfcfbd542006-10-02 02:18:23 -070095static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#endif
98
99#ifdef __sparc__
100extern char reboot_command [];
101extern int stop_a_enabled;
102extern int scons_pwroff;
103#endif
104
105#ifdef __hppa__
106extern int pwrsw_enabled;
107extern int unaligned_enabled;
108#endif
109
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800110#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#ifdef CONFIG_MATHEMU
112extern int sysctl_ieee_emulation_warnings;
113#endif
114extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700115extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#endif
117
118extern int sysctl_hz_timer;
119
120#ifdef CONFIG_BSD_PROCESS_ACCT
121extern int acct_parm[];
122#endif
123
Jes Sorensend2b176e2006-02-28 09:42:23 -0800124#ifdef CONFIG_IA64
125extern int no_unaligned_warning;
126#endif
127
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700128#ifdef CONFIG_RT_MUTEXES
129extern int max_lock_depth;
130#endif
131
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700132#ifdef CONFIG_SYSCTL_SYSCALL
133static int parse_table(int __user *, int, void __user *, size_t __user *,
134 void __user *, size_t, ctl_table *, void **);
135#endif
136
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700137static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 void __user *buffer, size_t *lenp, loff_t *ppos);
139
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700140#ifdef CONFIG_PROC_SYSCTL
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700141static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
142 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700143#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145static ctl_table root_table[];
146static struct ctl_table_header root_table_header =
147 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
148
149static ctl_table kern_table[];
150static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static ctl_table fs_table[];
152static ctl_table debug_table[];
153static ctl_table dev_table[];
154extern ctl_table random_table[];
155#ifdef CONFIG_UNIX98_PTYS
156extern ctl_table pty_table[];
157#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700158#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400159extern ctl_table inotify_table[];
160#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
163int sysctl_legacy_va_layout;
164#endif
165
166/* /proc declarations: */
167
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700168#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
171static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
172static int proc_opensys(struct inode *, struct file *);
173
174struct file_operations proc_sys_file_operations = {
175 .open = proc_opensys,
176 .read = proc_readsys,
177 .write = proc_writesys,
178};
179
180extern struct proc_dir_entry *proc_sys_root;
181
Al Viro330d57f2005-11-04 10:18:40 +0000182static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
184#endif
185
186/* The default sysctl tables: */
187
188static ctl_table root_table[] = {
189 {
190 .ctl_name = CTL_KERN,
191 .procname = "kernel",
192 .mode = 0555,
193 .child = kern_table,
194 },
195 {
196 .ctl_name = CTL_VM,
197 .procname = "vm",
198 .mode = 0555,
199 .child = vm_table,
200 },
201#ifdef CONFIG_NET
202 {
203 .ctl_name = CTL_NET,
204 .procname = "net",
205 .mode = 0555,
206 .child = net_table,
207 },
208#endif
209 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 .ctl_name = CTL_FS,
211 .procname = "fs",
212 .mode = 0555,
213 .child = fs_table,
214 },
215 {
216 .ctl_name = CTL_DEBUG,
217 .procname = "debug",
218 .mode = 0555,
219 .child = debug_table,
220 },
221 {
222 .ctl_name = CTL_DEV,
223 .procname = "dev",
224 .mode = 0555,
225 .child = dev_table,
226 },
Robert Love0eeca282005-07-12 17:06:03 -0400227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 { .ctl_name = 0 }
229};
230
231static ctl_table kern_table[] = {
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700232#ifndef CONFIG_UTS_NS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 {
234 .ctl_name = KERN_OSTYPE,
235 .procname = "ostype",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700236 .data = init_uts_ns.name.sysname,
237 .maxlen = sizeof(init_uts_ns.name.sysname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700239 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .strategy = &sysctl_string,
241 },
242 {
243 .ctl_name = KERN_OSRELEASE,
244 .procname = "osrelease",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700245 .data = init_uts_ns.name.release,
246 .maxlen = sizeof(init_uts_ns.name.release),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700248 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 .strategy = &sysctl_string,
250 },
251 {
252 .ctl_name = KERN_VERSION,
253 .procname = "version",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700254 .data = init_uts_ns.name.version,
255 .maxlen = sizeof(init_uts_ns.name.version),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700257 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 .strategy = &sysctl_string,
259 },
260 {
261 .ctl_name = KERN_NODENAME,
262 .procname = "hostname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700263 .data = init_uts_ns.name.nodename,
264 .maxlen = sizeof(init_uts_ns.name.nodename),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700266 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 .strategy = &sysctl_string,
268 },
269 {
270 .ctl_name = KERN_DOMAINNAME,
271 .procname = "domainname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700272 .data = init_uts_ns.name.domainname,
273 .maxlen = sizeof(init_uts_ns.name.domainname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700275 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 .strategy = &sysctl_string,
277 },
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700278#else /* !CONFIG_UTS_NS */
279 {
280 .ctl_name = KERN_OSTYPE,
281 .procname = "ostype",
282 .data = NULL,
283 /* could maybe use __NEW_UTS_LEN here? */
284 .maxlen = FIELD_SIZEOF(struct new_utsname, sysname),
285 .mode = 0444,
286 .proc_handler = &proc_do_uts_string,
287 .strategy = &sysctl_string,
288 },
289 {
290 .ctl_name = KERN_OSRELEASE,
291 .procname = "osrelease",
292 .data = NULL,
293 .maxlen = FIELD_SIZEOF(struct new_utsname, release),
294 .mode = 0444,
295 .proc_handler = &proc_do_uts_string,
296 .strategy = &sysctl_string,
297 },
298 {
299 .ctl_name = KERN_VERSION,
300 .procname = "version",
301 .data = NULL,
302 .maxlen = FIELD_SIZEOF(struct new_utsname, version),
303 .mode = 0444,
304 .proc_handler = &proc_do_uts_string,
305 .strategy = &sysctl_string,
306 },
307 {
308 .ctl_name = KERN_NODENAME,
309 .procname = "hostname",
310 .data = NULL,
311 .maxlen = FIELD_SIZEOF(struct new_utsname, nodename),
312 .mode = 0644,
313 .proc_handler = &proc_do_uts_string,
314 .strategy = &sysctl_string,
315 },
316 {
317 .ctl_name = KERN_DOMAINNAME,
318 .procname = "domainname",
319 .data = NULL,
320 .maxlen = FIELD_SIZEOF(struct new_utsname, domainname),
321 .mode = 0644,
322 .proc_handler = &proc_do_uts_string,
323 .strategy = &sysctl_string,
324 },
325#endif /* !CONFIG_UTS_NS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 {
327 .ctl_name = KERN_PANIC,
328 .procname = "panic",
329 .data = &panic_timeout,
330 .maxlen = sizeof(int),
331 .mode = 0644,
332 .proc_handler = &proc_dointvec,
333 },
334 {
335 .ctl_name = KERN_CORE_USES_PID,
336 .procname = "core_uses_pid",
337 .data = &core_uses_pid,
338 .maxlen = sizeof(int),
339 .mode = 0644,
340 .proc_handler = &proc_dointvec,
341 },
342 {
343 .ctl_name = KERN_CORE_PATTERN,
344 .procname = "core_pattern",
345 .data = core_pattern,
Andi Kleend025c9d2006-09-30 23:29:28 -0700346 .maxlen = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 .mode = 0644,
348 .proc_handler = &proc_dostring,
349 .strategy = &sysctl_string,
350 },
351 {
352 .ctl_name = KERN_TAINTED,
353 .procname = "tainted",
354 .data = &tainted,
355 .maxlen = sizeof(int),
356 .mode = 0444,
357 .proc_handler = &proc_dointvec,
358 },
359 {
360 .ctl_name = KERN_CAP_BSET,
361 .procname = "cap-bound",
362 .data = &cap_bset,
363 .maxlen = sizeof(kernel_cap_t),
364 .mode = 0600,
365 .proc_handler = &proc_dointvec_bset,
366 },
367#ifdef CONFIG_BLK_DEV_INITRD
368 {
369 .ctl_name = KERN_REALROOTDEV,
370 .procname = "real-root-dev",
371 .data = &real_root_dev,
372 .maxlen = sizeof(int),
373 .mode = 0644,
374 .proc_handler = &proc_dointvec,
375 },
376#endif
377#ifdef __sparc__
378 {
379 .ctl_name = KERN_SPARC_REBOOT,
380 .procname = "reboot-cmd",
381 .data = reboot_command,
382 .maxlen = 256,
383 .mode = 0644,
384 .proc_handler = &proc_dostring,
385 .strategy = &sysctl_string,
386 },
387 {
388 .ctl_name = KERN_SPARC_STOP_A,
389 .procname = "stop-a",
390 .data = &stop_a_enabled,
391 .maxlen = sizeof (int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
394 },
395 {
396 .ctl_name = KERN_SPARC_SCONS_PWROFF,
397 .procname = "scons-poweroff",
398 .data = &scons_pwroff,
399 .maxlen = sizeof (int),
400 .mode = 0644,
401 .proc_handler = &proc_dointvec,
402 },
403#endif
404#ifdef __hppa__
405 {
406 .ctl_name = KERN_HPPA_PWRSW,
407 .procname = "soft-power",
408 .data = &pwrsw_enabled,
409 .maxlen = sizeof (int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
412 },
413 {
414 .ctl_name = KERN_HPPA_UNALIGNED,
415 .procname = "unaligned-trap",
416 .data = &unaligned_enabled,
417 .maxlen = sizeof (int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
420 },
421#endif
422 {
423 .ctl_name = KERN_CTLALTDEL,
424 .procname = "ctrl-alt-del",
425 .data = &C_A_D,
426 .maxlen = sizeof(int),
427 .mode = 0644,
428 .proc_handler = &proc_dointvec,
429 },
430 {
431 .ctl_name = KERN_PRINTK,
432 .procname = "printk",
433 .data = &console_loglevel,
434 .maxlen = 4*sizeof(int),
435 .mode = 0644,
436 .proc_handler = &proc_dointvec,
437 },
438#ifdef CONFIG_KMOD
439 {
440 .ctl_name = KERN_MODPROBE,
441 .procname = "modprobe",
442 .data = &modprobe_path,
443 .maxlen = KMOD_PATH_LEN,
444 .mode = 0644,
445 .proc_handler = &proc_dostring,
446 .strategy = &sysctl_string,
447 },
448#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700449#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 {
451 .ctl_name = KERN_HOTPLUG,
452 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100453 .data = &uevent_helper,
454 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 .mode = 0644,
456 .proc_handler = &proc_dostring,
457 .strategy = &sysctl_string,
458 },
459#endif
460#ifdef CONFIG_CHR_DEV_SG
461 {
462 .ctl_name = KERN_SG_BIG_BUFF,
463 .procname = "sg-big-buff",
464 .data = &sg_big_buff,
465 .maxlen = sizeof (int),
466 .mode = 0444,
467 .proc_handler = &proc_dointvec,
468 },
469#endif
470#ifdef CONFIG_BSD_PROCESS_ACCT
471 {
472 .ctl_name = KERN_ACCT,
473 .procname = "acct",
474 .data = &acct_parm,
475 .maxlen = 3*sizeof(int),
476 .mode = 0644,
477 .proc_handler = &proc_dointvec,
478 },
479#endif
480#ifdef CONFIG_SYSVIPC
481 {
482 .ctl_name = KERN_SHMMAX,
483 .procname = "shmmax",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700484 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 .maxlen = sizeof (size_t),
486 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700487 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 },
489 {
490 .ctl_name = KERN_SHMALL,
491 .procname = "shmall",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700492 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .maxlen = sizeof (size_t),
494 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700495 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 },
497 {
498 .ctl_name = KERN_SHMMNI,
499 .procname = "shmmni",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700500 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .maxlen = sizeof (int),
502 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700503 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 },
505 {
506 .ctl_name = KERN_MSGMAX,
507 .procname = "msgmax",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700508 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .maxlen = sizeof (int),
510 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700511 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 },
513 {
514 .ctl_name = KERN_MSGMNI,
515 .procname = "msgmni",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700516 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .maxlen = sizeof (int),
518 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700519 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 },
521 {
522 .ctl_name = KERN_MSGMNB,
523 .procname = "msgmnb",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700524 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 .maxlen = sizeof (int),
526 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700527 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 },
529 {
530 .ctl_name = KERN_SEM,
531 .procname = "sem",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700532 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 .maxlen = 4*sizeof (int),
534 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700535 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 },
537#endif
538#ifdef CONFIG_MAGIC_SYSRQ
539 {
540 .ctl_name = KERN_SYSRQ,
541 .procname = "sysrq",
542 .data = &sysrq_enabled,
543 .maxlen = sizeof (int),
544 .mode = 0644,
545 .proc_handler = &proc_dointvec,
546 },
547#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700548#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 {
550 .ctl_name = KERN_CADPID,
551 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700552 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 .maxlen = sizeof (int),
554 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700555 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700557#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 {
559 .ctl_name = KERN_MAX_THREADS,
560 .procname = "threads-max",
561 .data = &max_threads,
562 .maxlen = sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
565 },
566 {
567 .ctl_name = KERN_RANDOM,
568 .procname = "random",
569 .mode = 0555,
570 .child = random_table,
571 },
572#ifdef CONFIG_UNIX98_PTYS
573 {
574 .ctl_name = KERN_PTY,
575 .procname = "pty",
576 .mode = 0555,
577 .child = pty_table,
578 },
579#endif
580 {
581 .ctl_name = KERN_OVERFLOWUID,
582 .procname = "overflowuid",
583 .data = &overflowuid,
584 .maxlen = sizeof(int),
585 .mode = 0644,
586 .proc_handler = &proc_dointvec_minmax,
587 .strategy = &sysctl_intvec,
588 .extra1 = &minolduid,
589 .extra2 = &maxolduid,
590 },
591 {
592 .ctl_name = KERN_OVERFLOWGID,
593 .procname = "overflowgid",
594 .data = &overflowgid,
595 .maxlen = sizeof(int),
596 .mode = 0644,
597 .proc_handler = &proc_dointvec_minmax,
598 .strategy = &sysctl_intvec,
599 .extra1 = &minolduid,
600 .extra2 = &maxolduid,
601 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800602#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603#ifdef CONFIG_MATHEMU
604 {
605 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
606 .procname = "ieee_emulation_warnings",
607 .data = &sysctl_ieee_emulation_warnings,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec,
611 },
612#endif
613#ifdef CONFIG_NO_IDLE_HZ
614 {
615 .ctl_name = KERN_HZ_TIMER,
616 .procname = "hz_timer",
617 .data = &sysctl_hz_timer,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec,
621 },
622#endif
623 {
624 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
625 .procname = "userprocess_debug",
626 .data = &sysctl_userprocess_debug,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = &proc_dointvec,
630 },
631#endif
632 {
633 .ctl_name = KERN_PIDMAX,
634 .procname = "pid_max",
635 .data = &pid_max,
636 .maxlen = sizeof (int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec_minmax,
639 .strategy = sysctl_intvec,
640 .extra1 = &pid_max_min,
641 .extra2 = &pid_max_max,
642 },
643 {
644 .ctl_name = KERN_PANIC_ON_OOPS,
645 .procname = "panic_on_oops",
646 .data = &panic_on_oops,
647 .maxlen = sizeof(int),
648 .mode = 0644,
649 .proc_handler = &proc_dointvec,
650 },
651 {
652 .ctl_name = KERN_PRINTK_RATELIMIT,
653 .procname = "printk_ratelimit",
654 .data = &printk_ratelimit_jiffies,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = &proc_dointvec_jiffies,
658 .strategy = &sysctl_jiffies,
659 },
660 {
661 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
662 .procname = "printk_ratelimit_burst",
663 .data = &printk_ratelimit_burst,
664 .maxlen = sizeof(int),
665 .mode = 0644,
666 .proc_handler = &proc_dointvec,
667 },
668 {
669 .ctl_name = KERN_NGROUPS_MAX,
670 .procname = "ngroups_max",
671 .data = &ngroups_max,
672 .maxlen = sizeof (int),
673 .mode = 0444,
674 .proc_handler = &proc_dointvec,
675 },
676#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
677 {
678 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
679 .procname = "unknown_nmi_panic",
680 .data = &unknown_nmi_panic,
681 .maxlen = sizeof (int),
682 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200683 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 },
Don Zickus407984f2006-09-26 10:52:27 +0200685 {
686 .ctl_name = KERN_NMI_WATCHDOG,
687 .procname = "nmi_watchdog",
688 .data = &nmi_watchdog_enabled,
689 .maxlen = sizeof (int),
690 .mode = 0644,
691 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 },
693#endif
694#if defined(CONFIG_X86)
695 {
Don Zickus8da5add2006-09-26 10:52:27 +0200696 .ctl_name = KERN_PANIC_ON_NMI,
697 .procname = "panic_on_unrecovered_nmi",
698 .data = &panic_on_unrecovered_nmi,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = &proc_dointvec,
702 },
703 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .ctl_name = KERN_BOOTLOADER_TYPE,
705 .procname = "bootloader_type",
706 .data = &bootloader_type,
707 .maxlen = sizeof (int),
708 .mode = 0444,
709 .proc_handler = &proc_dointvec,
710 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100711 {
712 .ctl_name = CTL_UNNUMBERED,
713 .procname = "kstack_depth_to_print",
714 .data = &kstack_depth_to_print,
715 .maxlen = sizeof(int),
716 .mode = 0644,
717 .proc_handler = &proc_dointvec,
718 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800720#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 {
722 .ctl_name = KERN_RANDOMIZE,
723 .procname = "randomize_va_space",
724 .data = &randomize_va_space,
725 .maxlen = sizeof(int),
726 .mode = 0644,
727 .proc_handler = &proc_dointvec,
728 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800729#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800730#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700731 {
732 .ctl_name = KERN_SPIN_RETRY,
733 .procname = "spin_retry",
734 .data = &spin_retry,
735 .maxlen = sizeof (int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
738 },
739#endif
Pavel Machekc255d842006-02-20 18:27:58 -0800740#ifdef CONFIG_ACPI_SLEEP
741 {
742 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
743 .procname = "acpi_video_flags",
744 .data = &acpi_video_flags,
745 .maxlen = sizeof (unsigned long),
746 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800747 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800748 },
749#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800750#ifdef CONFIG_IA64
751 {
752 .ctl_name = KERN_IA64_UNALIGNED,
753 .procname = "ignore-unaligned-usertrap",
754 .data = &no_unaligned_warning,
755 .maxlen = sizeof (int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
758 },
759#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200760#ifdef CONFIG_COMPAT
761 {
762 .ctl_name = KERN_COMPAT_LOG,
763 .procname = "compat-log",
764 .data = &compat_log,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
768 },
769#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700770#ifdef CONFIG_RT_MUTEXES
771 {
772 .ctl_name = KERN_MAX_LOCK_DEPTH,
773 .procname = "max_lock_depth",
774 .data = &max_lock_depth,
775 .maxlen = sizeof(int),
776 .mode = 0644,
777 .proc_handler = &proc_dointvec,
778 },
779#endif
780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 { .ctl_name = 0 }
782};
783
784/* Constants for minimum and maximum testing in vm_table.
785 We use these as one-element integer vectors. */
786static int zero;
787static int one_hundred = 100;
788
789
790static ctl_table vm_table[] = {
791 {
792 .ctl_name = VM_OVERCOMMIT_MEMORY,
793 .procname = "overcommit_memory",
794 .data = &sysctl_overcommit_memory,
795 .maxlen = sizeof(sysctl_overcommit_memory),
796 .mode = 0644,
797 .proc_handler = &proc_dointvec,
798 },
799 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700800 .ctl_name = VM_PANIC_ON_OOM,
801 .procname = "panic_on_oom",
802 .data = &sysctl_panic_on_oom,
803 .maxlen = sizeof(sysctl_panic_on_oom),
804 .mode = 0644,
805 .proc_handler = &proc_dointvec,
806 },
807 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 .ctl_name = VM_OVERCOMMIT_RATIO,
809 .procname = "overcommit_ratio",
810 .data = &sysctl_overcommit_ratio,
811 .maxlen = sizeof(sysctl_overcommit_ratio),
812 .mode = 0644,
813 .proc_handler = &proc_dointvec,
814 },
815 {
816 .ctl_name = VM_PAGE_CLUSTER,
817 .procname = "page-cluster",
818 .data = &page_cluster,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = &proc_dointvec,
822 },
823 {
824 .ctl_name = VM_DIRTY_BACKGROUND,
825 .procname = "dirty_background_ratio",
826 .data = &dirty_background_ratio,
827 .maxlen = sizeof(dirty_background_ratio),
828 .mode = 0644,
829 .proc_handler = &proc_dointvec_minmax,
830 .strategy = &sysctl_intvec,
831 .extra1 = &zero,
832 .extra2 = &one_hundred,
833 },
834 {
835 .ctl_name = VM_DIRTY_RATIO,
836 .procname = "dirty_ratio",
837 .data = &vm_dirty_ratio,
838 .maxlen = sizeof(vm_dirty_ratio),
839 .mode = 0644,
840 .proc_handler = &proc_dointvec_minmax,
841 .strategy = &sysctl_intvec,
842 .extra1 = &zero,
843 .extra2 = &one_hundred,
844 },
845 {
846 .ctl_name = VM_DIRTY_WB_CS,
847 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800848 .data = &dirty_writeback_interval,
849 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 .mode = 0644,
851 .proc_handler = &dirty_writeback_centisecs_handler,
852 },
853 {
854 .ctl_name = VM_DIRTY_EXPIRE_CS,
855 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800856 .data = &dirty_expire_interval,
857 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800859 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 },
861 {
862 .ctl_name = VM_NR_PDFLUSH_THREADS,
863 .procname = "nr_pdflush_threads",
864 .data = &nr_pdflush_threads,
865 .maxlen = sizeof nr_pdflush_threads,
866 .mode = 0444 /* read-only*/,
867 .proc_handler = &proc_dointvec,
868 },
869 {
870 .ctl_name = VM_SWAPPINESS,
871 .procname = "swappiness",
872 .data = &vm_swappiness,
873 .maxlen = sizeof(vm_swappiness),
874 .mode = 0644,
875 .proc_handler = &proc_dointvec_minmax,
876 .strategy = &sysctl_intvec,
877 .extra1 = &zero,
878 .extra2 = &one_hundred,
879 },
880#ifdef CONFIG_HUGETLB_PAGE
881 {
882 .ctl_name = VM_HUGETLB_PAGES,
883 .procname = "nr_hugepages",
884 .data = &max_huge_pages,
885 .maxlen = sizeof(unsigned long),
886 .mode = 0644,
887 .proc_handler = &hugetlb_sysctl_handler,
888 .extra1 = (void *)&hugetlb_zero,
889 .extra2 = (void *)&hugetlb_infinity,
890 },
891 {
892 .ctl_name = VM_HUGETLB_GROUP,
893 .procname = "hugetlb_shm_group",
894 .data = &sysctl_hugetlb_shm_group,
895 .maxlen = sizeof(gid_t),
896 .mode = 0644,
897 .proc_handler = &proc_dointvec,
898 },
899#endif
900 {
901 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
902 .procname = "lowmem_reserve_ratio",
903 .data = &sysctl_lowmem_reserve_ratio,
904 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
905 .mode = 0644,
906 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
907 .strategy = &sysctl_intvec,
908 },
909 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800910 .ctl_name = VM_DROP_PAGECACHE,
911 .procname = "drop_caches",
912 .data = &sysctl_drop_caches,
913 .maxlen = sizeof(int),
914 .mode = 0644,
915 .proc_handler = drop_caches_sysctl_handler,
916 .strategy = &sysctl_intvec,
917 },
918 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 .ctl_name = VM_MIN_FREE_KBYTES,
920 .procname = "min_free_kbytes",
921 .data = &min_free_kbytes,
922 .maxlen = sizeof(min_free_kbytes),
923 .mode = 0644,
924 .proc_handler = &min_free_kbytes_sysctl_handler,
925 .strategy = &sysctl_intvec,
926 .extra1 = &zero,
927 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800928 {
929 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
930 .procname = "percpu_pagelist_fraction",
931 .data = &percpu_pagelist_fraction,
932 .maxlen = sizeof(percpu_pagelist_fraction),
933 .mode = 0644,
934 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
935 .strategy = &sysctl_intvec,
936 .extra1 = &min_percpu_pagelist_fract,
937 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938#ifdef CONFIG_MMU
939 {
940 .ctl_name = VM_MAX_MAP_COUNT,
941 .procname = "max_map_count",
942 .data = &sysctl_max_map_count,
943 .maxlen = sizeof(sysctl_max_map_count),
944 .mode = 0644,
945 .proc_handler = &proc_dointvec
946 },
947#endif
948 {
949 .ctl_name = VM_LAPTOP_MODE,
950 .procname = "laptop_mode",
951 .data = &laptop_mode,
952 .maxlen = sizeof(laptop_mode),
953 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800954 .proc_handler = &proc_dointvec_jiffies,
955 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 },
957 {
958 .ctl_name = VM_BLOCK_DUMP,
959 .procname = "block_dump",
960 .data = &block_dump,
961 .maxlen = sizeof(block_dump),
962 .mode = 0644,
963 .proc_handler = &proc_dointvec,
964 .strategy = &sysctl_intvec,
965 .extra1 = &zero,
966 },
967 {
968 .ctl_name = VM_VFS_CACHE_PRESSURE,
969 .procname = "vfs_cache_pressure",
970 .data = &sysctl_vfs_cache_pressure,
971 .maxlen = sizeof(sysctl_vfs_cache_pressure),
972 .mode = 0644,
973 .proc_handler = &proc_dointvec,
974 .strategy = &sysctl_intvec,
975 .extra1 = &zero,
976 },
977#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
978 {
979 .ctl_name = VM_LEGACY_VA_LAYOUT,
980 .procname = "legacy_va_layout",
981 .data = &sysctl_legacy_va_layout,
982 .maxlen = sizeof(sysctl_legacy_va_layout),
983 .mode = 0644,
984 .proc_handler = &proc_dointvec,
985 .strategy = &sysctl_intvec,
986 .extra1 = &zero,
987 },
988#endif
989#ifdef CONFIG_SWAP
990 {
991 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
992 .procname = "swap_token_timeout",
993 .data = &swap_token_default_timeout,
994 .maxlen = sizeof(swap_token_default_timeout),
995 .mode = 0644,
996 .proc_handler = &proc_dointvec_jiffies,
997 .strategy = &sysctl_jiffies,
998 },
999#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001000#ifdef CONFIG_NUMA
1001 {
1002 .ctl_name = VM_ZONE_RECLAIM_MODE,
1003 .procname = "zone_reclaim_mode",
1004 .data = &zone_reclaim_mode,
1005 .maxlen = sizeof(zone_reclaim_mode),
1006 .mode = 0644,
1007 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001008 .strategy = &sysctl_intvec,
1009 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001010 },
Christoph Lameter96146342006-07-03 00:24:13 -07001011 {
1012 .ctl_name = VM_MIN_UNMAPPED,
1013 .procname = "min_unmapped_ratio",
1014 .data = &sysctl_min_unmapped_ratio,
1015 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1016 .mode = 0644,
1017 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1018 .strategy = &sysctl_intvec,
1019 .extra1 = &zero,
1020 .extra2 = &one_hundred,
1021 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001022 {
1023 .ctl_name = VM_MIN_SLAB,
1024 .procname = "min_slab_ratio",
1025 .data = &sysctl_min_slab_ratio,
1026 .maxlen = sizeof(sysctl_min_slab_ratio),
1027 .mode = 0644,
1028 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1029 .strategy = &sysctl_intvec,
1030 .extra1 = &zero,
1031 .extra2 = &one_hundred,
1032 },
Christoph Lameter17436602006-01-18 17:42:32 -08001033#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001034#ifdef CONFIG_X86_32
1035 {
1036 .ctl_name = VM_VDSO_ENABLED,
1037 .procname = "vdso_enabled",
1038 .data = &vdso_enabled,
1039 .maxlen = sizeof(vdso_enabled),
1040 .mode = 0644,
1041 .proc_handler = &proc_dointvec,
1042 .strategy = &sysctl_intvec,
1043 .extra1 = &zero,
1044 },
1045#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 { .ctl_name = 0 }
1047};
1048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049static ctl_table fs_table[] = {
1050 {
1051 .ctl_name = FS_NRINODE,
1052 .procname = "inode-nr",
1053 .data = &inodes_stat,
1054 .maxlen = 2*sizeof(int),
1055 .mode = 0444,
1056 .proc_handler = &proc_dointvec,
1057 },
1058 {
1059 .ctl_name = FS_STATINODE,
1060 .procname = "inode-state",
1061 .data = &inodes_stat,
1062 .maxlen = 7*sizeof(int),
1063 .mode = 0444,
1064 .proc_handler = &proc_dointvec,
1065 },
1066 {
1067 .ctl_name = FS_NRFILE,
1068 .procname = "file-nr",
1069 .data = &files_stat,
1070 .maxlen = 3*sizeof(int),
1071 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001072 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 },
1074 {
1075 .ctl_name = FS_MAXFILE,
1076 .procname = "file-max",
1077 .data = &files_stat.max_files,
1078 .maxlen = sizeof(int),
1079 .mode = 0644,
1080 .proc_handler = &proc_dointvec,
1081 },
1082 {
1083 .ctl_name = FS_DENTRY,
1084 .procname = "dentry-state",
1085 .data = &dentry_stat,
1086 .maxlen = 6*sizeof(int),
1087 .mode = 0444,
1088 .proc_handler = &proc_dointvec,
1089 },
1090 {
1091 .ctl_name = FS_OVERFLOWUID,
1092 .procname = "overflowuid",
1093 .data = &fs_overflowuid,
1094 .maxlen = sizeof(int),
1095 .mode = 0644,
1096 .proc_handler = &proc_dointvec_minmax,
1097 .strategy = &sysctl_intvec,
1098 .extra1 = &minolduid,
1099 .extra2 = &maxolduid,
1100 },
1101 {
1102 .ctl_name = FS_OVERFLOWGID,
1103 .procname = "overflowgid",
1104 .data = &fs_overflowgid,
1105 .maxlen = sizeof(int),
1106 .mode = 0644,
1107 .proc_handler = &proc_dointvec_minmax,
1108 .strategy = &sysctl_intvec,
1109 .extra1 = &minolduid,
1110 .extra2 = &maxolduid,
1111 },
1112 {
1113 .ctl_name = FS_LEASES,
1114 .procname = "leases-enable",
1115 .data = &leases_enable,
1116 .maxlen = sizeof(int),
1117 .mode = 0644,
1118 .proc_handler = &proc_dointvec,
1119 },
1120#ifdef CONFIG_DNOTIFY
1121 {
1122 .ctl_name = FS_DIR_NOTIFY,
1123 .procname = "dir-notify-enable",
1124 .data = &dir_notify_enable,
1125 .maxlen = sizeof(int),
1126 .mode = 0644,
1127 .proc_handler = &proc_dointvec,
1128 },
1129#endif
1130#ifdef CONFIG_MMU
1131 {
1132 .ctl_name = FS_LEASE_TIME,
1133 .procname = "lease-break-time",
1134 .data = &lease_break_time,
1135 .maxlen = sizeof(int),
1136 .mode = 0644,
1137 .proc_handler = &proc_dointvec,
1138 },
1139 {
1140 .ctl_name = FS_AIO_NR,
1141 .procname = "aio-nr",
1142 .data = &aio_nr,
1143 .maxlen = sizeof(aio_nr),
1144 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001145 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 },
1147 {
1148 .ctl_name = FS_AIO_MAX_NR,
1149 .procname = "aio-max-nr",
1150 .data = &aio_max_nr,
1151 .maxlen = sizeof(aio_max_nr),
1152 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001153 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001155#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001156 {
1157 .ctl_name = FS_INOTIFY,
1158 .procname = "inotify",
1159 .mode = 0555,
1160 .child = inotify_table,
1161 },
1162#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001164 {
1165 .ctl_name = KERN_SETUID_DUMPABLE,
1166 .procname = "suid_dumpable",
1167 .data = &suid_dumpable,
1168 .maxlen = sizeof(int),
1169 .mode = 0644,
1170 .proc_handler = &proc_dointvec,
1171 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 { .ctl_name = 0 }
1173};
1174
1175static ctl_table debug_table[] = {
1176 { .ctl_name = 0 }
1177};
1178
1179static ctl_table dev_table[] = {
1180 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001181};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
1183extern void init_irq_proc (void);
1184
Al Viro330d57f2005-11-04 10:18:40 +00001185static DEFINE_SPINLOCK(sysctl_lock);
1186
1187/* called under sysctl_lock */
1188static int use_table(struct ctl_table_header *p)
1189{
1190 if (unlikely(p->unregistering))
1191 return 0;
1192 p->used++;
1193 return 1;
1194}
1195
1196/* called under sysctl_lock */
1197static void unuse_table(struct ctl_table_header *p)
1198{
1199 if (!--p->used)
1200 if (unlikely(p->unregistering))
1201 complete(p->unregistering);
1202}
1203
1204/* called under sysctl_lock, will reacquire if has to wait */
1205static void start_unregistering(struct ctl_table_header *p)
1206{
1207 /*
1208 * if p->used is 0, nobody will ever touch that entry again;
1209 * we'll eliminate all paths to it before dropping sysctl_lock
1210 */
1211 if (unlikely(p->used)) {
1212 struct completion wait;
1213 init_completion(&wait);
1214 p->unregistering = &wait;
1215 spin_unlock(&sysctl_lock);
1216 wait_for_completion(&wait);
1217 spin_lock(&sysctl_lock);
1218 }
1219 /*
1220 * do not remove from the list until nobody holds it; walking the
1221 * list in do_sysctl() relies on that.
1222 */
1223 list_del_init(&p->ctl_entry);
1224}
1225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226void __init sysctl_init(void)
1227{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001228#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001229 register_proc_table(root_table, proc_sys_root, &root_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 init_irq_proc();
1231#endif
1232}
1233
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001234#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1236 void __user *newval, size_t newlen)
1237{
1238 struct list_head *tmp;
Al Viro330d57f2005-11-04 10:18:40 +00001239 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
1241 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1242 return -ENOTDIR;
1243 if (oldval) {
1244 int old_len;
1245 if (!oldlenp || get_user(old_len, oldlenp))
1246 return -EFAULT;
1247 }
Al Viro330d57f2005-11-04 10:18:40 +00001248 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 tmp = &root_table_header.ctl_entry;
1250 do {
1251 struct ctl_table_header *head =
1252 list_entry(tmp, struct ctl_table_header, ctl_entry);
1253 void *context = NULL;
Al Viro330d57f2005-11-04 10:18:40 +00001254
1255 if (!use_table(head))
1256 continue;
1257
1258 spin_unlock(&sysctl_lock);
1259
1260 error = parse_table(name, nlen, oldval, oldlenp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 newval, newlen, head->ctl_table,
1262 &context);
Jesper Juhl5a6b4542005-06-25 14:58:48 -07001263 kfree(context);
Al Viro330d57f2005-11-04 10:18:40 +00001264
1265 spin_lock(&sysctl_lock);
1266 unuse_table(head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 if (error != -ENOTDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001268 break;
1269 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1270 spin_unlock(&sysctl_lock);
1271 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
1274asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1275{
1276 struct __sysctl_args tmp;
1277 int error;
1278
1279 if (copy_from_user(&tmp, args, sizeof(tmp)))
1280 return -EFAULT;
1281
1282 lock_kernel();
1283 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1284 tmp.newval, tmp.newlen);
1285 unlock_kernel();
1286 return error;
1287}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001288#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
1290/*
1291 * ctl_perm does NOT grant the superuser all rights automatically, because
1292 * some sysctl variables are readonly even to root.
1293 */
1294
1295static int test_perm(int mode, int op)
1296{
1297 if (!current->euid)
1298 mode >>= 6;
1299 else if (in_egroup_p(0))
1300 mode >>= 3;
1301 if ((mode & op & 0007) == op)
1302 return 0;
1303 return -EACCES;
1304}
1305
1306static inline int ctl_perm(ctl_table *table, int op)
1307{
1308 int error;
1309 error = security_sysctl(table, op);
1310 if (error)
1311 return error;
1312 return test_perm(table->mode, op);
1313}
1314
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001315#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316static int parse_table(int __user *name, int nlen,
1317 void __user *oldval, size_t __user *oldlenp,
1318 void __user *newval, size_t newlen,
1319 ctl_table *table, void **context)
1320{
1321 int n;
1322repeat:
1323 if (!nlen)
1324 return -ENOTDIR;
1325 if (get_user(n, name))
1326 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001327 for ( ; table->ctl_name || table->procname; table++) {
1328 if (!table->ctl_name)
1329 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1331 int error;
1332 if (table->child) {
1333 if (ctl_perm(table, 001))
1334 return -EPERM;
1335 if (table->strategy) {
1336 error = table->strategy(
1337 table, name, nlen,
1338 oldval, oldlenp,
1339 newval, newlen, context);
1340 if (error)
1341 return error;
1342 }
1343 name++;
1344 nlen--;
1345 table = table->child;
1346 goto repeat;
1347 }
1348 error = do_sysctl_strategy(table, name, nlen,
1349 oldval, oldlenp,
1350 newval, newlen, context);
1351 return error;
1352 }
1353 }
1354 return -ENOTDIR;
1355}
1356
1357/* Perform the actual read/write of a sysctl table entry. */
1358int do_sysctl_strategy (ctl_table *table,
1359 int __user *name, int nlen,
1360 void __user *oldval, size_t __user *oldlenp,
1361 void __user *newval, size_t newlen, void **context)
1362{
1363 int op = 0, rc;
1364 size_t len;
1365
1366 if (oldval)
1367 op |= 004;
1368 if (newval)
1369 op |= 002;
1370 if (ctl_perm(table, op))
1371 return -EPERM;
1372
1373 if (table->strategy) {
1374 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1375 newval, newlen, context);
1376 if (rc < 0)
1377 return rc;
1378 if (rc > 0)
1379 return 0;
1380 }
1381
1382 /* If there is no strategy routine, or if the strategy returns
1383 * zero, proceed with automatic r/w */
1384 if (table->data && table->maxlen) {
1385 if (oldval && oldlenp) {
1386 if (get_user(len, oldlenp))
1387 return -EFAULT;
1388 if (len) {
1389 if (len > table->maxlen)
1390 len = table->maxlen;
1391 if(copy_to_user(oldval, table->data, len))
1392 return -EFAULT;
1393 if(put_user(len, oldlenp))
1394 return -EFAULT;
1395 }
1396 }
1397 if (newval && newlen) {
1398 len = newlen;
1399 if (len > table->maxlen)
1400 len = table->maxlen;
1401 if(copy_from_user(table->data, newval, len))
1402 return -EFAULT;
1403 }
1404 }
1405 return 0;
1406}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001407#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
1409/**
1410 * register_sysctl_table - register a sysctl hierarchy
1411 * @table: the top-level table structure
1412 * @insert_at_head: whether the entry should be inserted in front or at the end
1413 *
1414 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1415 * array. An entry with a ctl_name of 0 terminates the table.
1416 *
1417 * The members of the &ctl_table structure are used as follows:
1418 *
1419 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1420 * must be unique within that level of sysctl
1421 *
1422 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1423 * enter a sysctl file
1424 *
1425 * data - a pointer to data for use by proc_handler
1426 *
1427 * maxlen - the maximum size in bytes of the data
1428 *
1429 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1430 *
1431 * child - a pointer to the child sysctl table if this entry is a directory, or
1432 * %NULL.
1433 *
1434 * proc_handler - the text handler routine (described below)
1435 *
1436 * strategy - the strategy routine (described below)
1437 *
1438 * de - for internal use by the sysctl routines
1439 *
1440 * extra1, extra2 - extra pointers usable by the proc handler routines
1441 *
1442 * Leaf nodes in the sysctl tree will be represented by a single file
1443 * under /proc; non-leaf nodes will be represented by directories.
1444 *
1445 * sysctl(2) can automatically manage read and write requests through
1446 * the sysctl table. The data and maxlen fields of the ctl_table
1447 * struct enable minimal validation of the values being written to be
1448 * performed, and the mode field allows minimal authentication.
1449 *
1450 * More sophisticated management can be enabled by the provision of a
1451 * strategy routine with the table entry. This will be called before
1452 * any automatic read or write of the data is performed.
1453 *
1454 * The strategy routine may return
1455 *
1456 * < 0 - Error occurred (error is passed to user process)
1457 *
1458 * 0 - OK - proceed with automatic read or write.
1459 *
1460 * > 0 - OK - read or write has been done by the strategy routine, so
1461 * return immediately.
1462 *
1463 * There must be a proc_handler routine for any terminal nodes
1464 * mirrored under /proc/sys (non-terminals are handled by a built-in
1465 * directory handler). Several default handlers are available to
1466 * cover common cases -
1467 *
1468 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1469 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1470 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1471 *
1472 * It is the handler's job to read the input buffer from user memory
1473 * and process it. The handler should return 0 on success.
1474 *
1475 * This routine returns %NULL on a failure to register, and a pointer
1476 * to the table header on success.
1477 */
1478struct ctl_table_header *register_sysctl_table(ctl_table * table,
1479 int insert_at_head)
1480{
1481 struct ctl_table_header *tmp;
1482 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1483 if (!tmp)
1484 return NULL;
1485 tmp->ctl_table = table;
1486 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001487 tmp->used = 0;
1488 tmp->unregistering = NULL;
1489 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 if (insert_at_head)
1491 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1492 else
1493 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001494 spin_unlock(&sysctl_lock);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001495#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001496 register_proc_table(table, proc_sys_root, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497#endif
1498 return tmp;
1499}
1500
1501/**
1502 * unregister_sysctl_table - unregister a sysctl table hierarchy
1503 * @header: the header returned from register_sysctl_table
1504 *
1505 * Unregisters the sysctl table and all children. proc entries may not
1506 * actually be removed until they are no longer used by anyone.
1507 */
1508void unregister_sysctl_table(struct ctl_table_header * header)
1509{
Al Viro330d57f2005-11-04 10:18:40 +00001510 might_sleep();
1511 spin_lock(&sysctl_lock);
1512 start_unregistering(header);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001513#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 unregister_proc_table(header->ctl_table, proc_sys_root);
1515#endif
Al Viro330d57f2005-11-04 10:18:40 +00001516 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 kfree(header);
1518}
1519
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001520#else /* !CONFIG_SYSCTL */
1521struct ctl_table_header * register_sysctl_table(ctl_table * table,
1522 int insert_at_head)
1523{
1524 return NULL;
1525}
1526
1527void unregister_sysctl_table(struct ctl_table_header * table)
1528{
1529}
1530
1531#endif /* CONFIG_SYSCTL */
1532
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533/*
1534 * /proc/sys support
1535 */
1536
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001537#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
1539/* Scan the sysctl entries in table and add them all into /proc */
Al Viro330d57f2005-11-04 10:18:40 +00001540static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541{
1542 struct proc_dir_entry *de;
1543 int len;
1544 mode_t mode;
1545
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001546 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 /* Can't do anything without a proc name. */
1548 if (!table->procname)
1549 continue;
1550 /* Maybe we can't do anything with it... */
1551 if (!table->proc_handler && !table->child) {
1552 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1553 table->procname);
1554 continue;
1555 }
1556
1557 len = strlen(table->procname);
1558 mode = table->mode;
1559
1560 de = NULL;
1561 if (table->proc_handler)
1562 mode |= S_IFREG;
1563 else {
1564 mode |= S_IFDIR;
1565 for (de = root->subdir; de; de = de->next) {
1566 if (proc_match(len, table->procname, de))
1567 break;
1568 }
1569 /* If the subdir exists already, de is non-NULL */
1570 }
1571
1572 if (!de) {
1573 de = create_proc_entry(table->procname, mode, root);
1574 if (!de)
1575 continue;
Al Viro330d57f2005-11-04 10:18:40 +00001576 de->set = set;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 de->data = (void *) table;
1578 if (table->proc_handler)
1579 de->proc_fops = &proc_sys_file_operations;
1580 }
1581 table->de = de;
1582 if (de->mode & S_IFDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001583 register_proc_table(table->child, de, set);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 }
1585}
1586
1587/*
1588 * Unregister a /proc sysctl table and any subdirectories.
1589 */
1590static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1591{
1592 struct proc_dir_entry *de;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001593 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 if (!(de = table->de))
1595 continue;
1596 if (de->mode & S_IFDIR) {
1597 if (!table->child) {
1598 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1599 continue;
1600 }
1601 unregister_proc_table(table->child, de);
1602
1603 /* Don't unregister directories which still have entries.. */
1604 if (de->subdir)
1605 continue;
1606 }
1607
Al Viro330d57f2005-11-04 10:18:40 +00001608 /*
1609 * In any case, mark the entry as goner; we'll keep it
1610 * around if it's busy, but we'll know to do nothing with
1611 * its fields. We are under sysctl_lock here.
1612 */
1613 de->data = NULL;
1614
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 /* Don't unregister proc entries that are still being used.. */
1616 if (atomic_read(&de->count))
1617 continue;
1618
1619 table->de = NULL;
1620 remove_proc_entry(table->procname, root);
1621 }
1622}
1623
1624static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1625 size_t count, loff_t *ppos)
1626{
1627 int op;
Al Viro330d57f2005-11-04 10:18:40 +00001628 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 struct ctl_table *table;
1630 size_t res;
Al Viro330d57f2005-11-04 10:18:40 +00001631 ssize_t error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
Al Viro330d57f2005-11-04 10:18:40 +00001633 spin_lock(&sysctl_lock);
1634 if (de && de->data && use_table(de->set)) {
1635 /*
1636 * at that point we know that sysctl was not unregistered
1637 * and won't be until we finish
1638 */
1639 spin_unlock(&sysctl_lock);
1640 table = (struct ctl_table *) de->data;
1641 if (!table || !table->proc_handler)
1642 goto out;
1643 error = -EPERM;
1644 op = (write ? 002 : 004);
1645 if (ctl_perm(table, op))
1646 goto out;
1647
1648 /* careful: calling conventions are nasty here */
1649 res = count;
1650 error = (*table->proc_handler)(table, write, file,
1651 buf, &res, ppos);
1652 if (!error)
1653 error = res;
1654 out:
1655 spin_lock(&sysctl_lock);
1656 unuse_table(de->set);
1657 }
1658 spin_unlock(&sysctl_lock);
1659 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660}
1661
1662static int proc_opensys(struct inode *inode, struct file *file)
1663{
1664 if (file->f_mode & FMODE_WRITE) {
1665 /*
1666 * sysctl entries that are not writable,
1667 * are _NOT_ writable, capabilities or not.
1668 */
1669 if (!(inode->i_mode & S_IWUSR))
1670 return -EPERM;
1671 }
1672
1673 return 0;
1674}
1675
1676static ssize_t proc_readsys(struct file * file, char __user * buf,
1677 size_t count, loff_t *ppos)
1678{
1679 return do_rw_proc(0, file, buf, count, ppos);
1680}
1681
1682static ssize_t proc_writesys(struct file * file, const char __user * buf,
1683 size_t count, loff_t *ppos)
1684{
1685 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1686}
1687
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001688static int _proc_do_string(void* data, int maxlen, int write,
1689 struct file *filp, void __user *buffer,
1690 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001691{
1692 size_t len;
1693 char __user *p;
1694 char c;
1695
1696 if (!data || !maxlen || !*lenp ||
1697 (*ppos && !write)) {
1698 *lenp = 0;
1699 return 0;
1700 }
1701
1702 if (write) {
1703 len = 0;
1704 p = buffer;
1705 while (len < *lenp) {
1706 if (get_user(c, p++))
1707 return -EFAULT;
1708 if (c == 0 || c == '\n')
1709 break;
1710 len++;
1711 }
1712 if (len >= maxlen)
1713 len = maxlen-1;
1714 if(copy_from_user(data, buffer, len))
1715 return -EFAULT;
1716 ((char *) data)[len] = 0;
1717 *ppos += *lenp;
1718 } else {
1719 len = strlen(data);
1720 if (len > maxlen)
1721 len = maxlen;
1722 if (len > *lenp)
1723 len = *lenp;
1724 if (len)
1725 if(copy_to_user(buffer, data, len))
1726 return -EFAULT;
1727 if (len < *lenp) {
1728 if(put_user('\n', ((char __user *) buffer) + len))
1729 return -EFAULT;
1730 len++;
1731 }
1732 *lenp = len;
1733 *ppos += len;
1734 }
1735 return 0;
1736}
1737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738/**
1739 * proc_dostring - read a string sysctl
1740 * @table: the sysctl table
1741 * @write: %TRUE if this is a write to the sysctl file
1742 * @filp: the file structure
1743 * @buffer: the user buffer
1744 * @lenp: the size of the user buffer
1745 * @ppos: file position
1746 *
1747 * Reads/writes a string from/to the user buffer. If the kernel
1748 * buffer provided is not large enough to hold the string, the
1749 * string is truncated. The copied string is %NULL-terminated.
1750 * If the string is being read by the user process, it is copied
1751 * and a newline '\n' is added. It is truncated if the buffer is
1752 * not large enough.
1753 *
1754 * Returns 0 on success.
1755 */
1756int proc_dostring(ctl_table *table, int write, struct file *filp,
1757 void __user *buffer, size_t *lenp, loff_t *ppos)
1758{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001759 return _proc_do_string(table->data, table->maxlen, write, filp,
1760 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
1763/*
1764 * Special case of dostring for the UTS structure. This has locks
1765 * to observe. Should this be in kernel/sys.c ????
1766 */
1767
Serge E. Hallyn8218c742006-10-02 02:18:15 -07001768#ifndef CONFIG_UTS_NS
1769static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 void __user *buffer, size_t *lenp, loff_t *ppos)
1771{
1772 int r;
1773
1774 if (!write) {
1775 down_read(&uts_sem);
1776 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1777 up_read(&uts_sem);
1778 } else {
1779 down_write(&uts_sem);
1780 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1781 up_write(&uts_sem);
1782 }
1783 return r;
1784}
Serge E. Hallyn8218c742006-10-02 02:18:15 -07001785#else /* !CONFIG_UTS_NS */
1786static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1787 void __user *buffer, size_t *lenp, loff_t *ppos)
1788{
1789 int r;
1790 struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
1791 char* which;
1792
1793 switch (table->ctl_name) {
1794 case KERN_OSTYPE:
1795 which = uts_ns->name.sysname;
1796 break;
1797 case KERN_NODENAME:
1798 which = uts_ns->name.nodename;
1799 break;
1800 case KERN_OSRELEASE:
1801 which = uts_ns->name.release;
1802 break;
1803 case KERN_VERSION:
1804 which = uts_ns->name.version;
1805 break;
1806 case KERN_DOMAINNAME:
1807 which = uts_ns->name.domainname;
1808 break;
1809 default:
1810 r = -EINVAL;
1811 goto out;
1812 }
1813
1814 if (!write) {
1815 down_read(&uts_sem);
1816 r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
1817 up_read(&uts_sem);
1818 } else {
1819 down_write(&uts_sem);
1820 r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
1821 up_write(&uts_sem);
1822 }
1823 out:
1824 return r;
1825}
1826#endif /* !CONFIG_UTS_NS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
1828static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1829 int *valp,
1830 int write, void *data)
1831{
1832 if (write) {
1833 *valp = *negp ? -*lvalp : *lvalp;
1834 } else {
1835 int val = *valp;
1836 if (val < 0) {
1837 *negp = -1;
1838 *lvalp = (unsigned long)-val;
1839 } else {
1840 *negp = 0;
1841 *lvalp = (unsigned long)val;
1842 }
1843 }
1844 return 0;
1845}
1846
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001847static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1848 int write, struct file *filp, void __user *buffer,
1849 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1851 int write, void *data),
1852 void *data)
1853{
1854#define TMPBUFLEN 21
1855 int *i, vleft, first=1, neg, val;
1856 unsigned long lval;
1857 size_t left, len;
1858
1859 char buf[TMPBUFLEN], *p;
1860 char __user *s = buffer;
1861
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001862 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 (*ppos && !write)) {
1864 *lenp = 0;
1865 return 0;
1866 }
1867
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001868 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 vleft = table->maxlen / sizeof(*i);
1870 left = *lenp;
1871
1872 if (!conv)
1873 conv = do_proc_dointvec_conv;
1874
1875 for (; left && vleft--; i++, first=0) {
1876 if (write) {
1877 while (left) {
1878 char c;
1879 if (get_user(c, s))
1880 return -EFAULT;
1881 if (!isspace(c))
1882 break;
1883 left--;
1884 s++;
1885 }
1886 if (!left)
1887 break;
1888 neg = 0;
1889 len = left;
1890 if (len > sizeof(buf) - 1)
1891 len = sizeof(buf) - 1;
1892 if (copy_from_user(buf, s, len))
1893 return -EFAULT;
1894 buf[len] = 0;
1895 p = buf;
1896 if (*p == '-' && left > 1) {
1897 neg = 1;
1898 left--, p++;
1899 }
1900 if (*p < '0' || *p > '9')
1901 break;
1902
1903 lval = simple_strtoul(p, &p, 0);
1904
1905 len = p-buf;
1906 if ((len < left) && *p && !isspace(*p))
1907 break;
1908 if (neg)
1909 val = -val;
1910 s += len;
1911 left -= len;
1912
1913 if (conv(&neg, &lval, i, 1, data))
1914 break;
1915 } else {
1916 p = buf;
1917 if (!first)
1918 *p++ = '\t';
1919
1920 if (conv(&neg, &lval, i, 0, data))
1921 break;
1922
1923 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1924 len = strlen(buf);
1925 if (len > left)
1926 len = left;
1927 if(copy_to_user(s, buf, len))
1928 return -EFAULT;
1929 left -= len;
1930 s += len;
1931 }
1932 }
1933
1934 if (!write && !first && left) {
1935 if(put_user('\n', s))
1936 return -EFAULT;
1937 left--, s++;
1938 }
1939 if (write) {
1940 while (left) {
1941 char c;
1942 if (get_user(c, s++))
1943 return -EFAULT;
1944 if (!isspace(c))
1945 break;
1946 left--;
1947 }
1948 }
1949 if (write && first)
1950 return -EINVAL;
1951 *lenp -= left;
1952 *ppos += *lenp;
1953 return 0;
1954#undef TMPBUFLEN
1955}
1956
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001957static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1958 void __user *buffer, size_t *lenp, loff_t *ppos,
1959 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1960 int write, void *data),
1961 void *data)
1962{
1963 return __do_proc_dointvec(table->data, table, write, filp,
1964 buffer, lenp, ppos, conv, data);
1965}
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967/**
1968 * proc_dointvec - read a vector of integers
1969 * @table: the sysctl table
1970 * @write: %TRUE if this is a write to the sysctl file
1971 * @filp: the file structure
1972 * @buffer: the user buffer
1973 * @lenp: the size of the user buffer
1974 * @ppos: file position
1975 *
1976 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1977 * values from/to the user buffer, treated as an ASCII string.
1978 *
1979 * Returns 0 on success.
1980 */
1981int proc_dointvec(ctl_table *table, int write, struct file *filp,
1982 void __user *buffer, size_t *lenp, loff_t *ppos)
1983{
1984 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1985 NULL,NULL);
1986}
1987
1988#define OP_SET 0
1989#define OP_AND 1
1990#define OP_OR 2
1991#define OP_MAX 3
1992#define OP_MIN 4
1993
1994static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1995 int *valp,
1996 int write, void *data)
1997{
1998 int op = *(int *)data;
1999 if (write) {
2000 int val = *negp ? -*lvalp : *lvalp;
2001 switch(op) {
2002 case OP_SET: *valp = val; break;
2003 case OP_AND: *valp &= val; break;
2004 case OP_OR: *valp |= val; break;
2005 case OP_MAX: if(*valp < val)
2006 *valp = val;
2007 break;
2008 case OP_MIN: if(*valp > val)
2009 *valp = val;
2010 break;
2011 }
2012 } else {
2013 int val = *valp;
2014 if (val < 0) {
2015 *negp = -1;
2016 *lvalp = (unsigned long)-val;
2017 } else {
2018 *negp = 0;
2019 *lvalp = (unsigned long)val;
2020 }
2021 }
2022 return 0;
2023}
2024
2025/*
2026 * init may raise the set.
2027 */
2028
2029int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2030 void __user *buffer, size_t *lenp, loff_t *ppos)
2031{
2032 int op;
2033
2034 if (!capable(CAP_SYS_MODULE)) {
2035 return -EPERM;
2036 }
2037
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07002038 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2040 do_proc_dointvec_bset_conv,&op);
2041}
2042
2043struct do_proc_dointvec_minmax_conv_param {
2044 int *min;
2045 int *max;
2046};
2047
2048static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2049 int *valp,
2050 int write, void *data)
2051{
2052 struct do_proc_dointvec_minmax_conv_param *param = data;
2053 if (write) {
2054 int val = *negp ? -*lvalp : *lvalp;
2055 if ((param->min && *param->min > val) ||
2056 (param->max && *param->max < val))
2057 return -EINVAL;
2058 *valp = val;
2059 } else {
2060 int val = *valp;
2061 if (val < 0) {
2062 *negp = -1;
2063 *lvalp = (unsigned long)-val;
2064 } else {
2065 *negp = 0;
2066 *lvalp = (unsigned long)val;
2067 }
2068 }
2069 return 0;
2070}
2071
2072/**
2073 * proc_dointvec_minmax - read a vector of integers with min/max values
2074 * @table: the sysctl table
2075 * @write: %TRUE if this is a write to the sysctl file
2076 * @filp: the file structure
2077 * @buffer: the user buffer
2078 * @lenp: the size of the user buffer
2079 * @ppos: file position
2080 *
2081 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2082 * values from/to the user buffer, treated as an ASCII string.
2083 *
2084 * This routine will ensure the values are within the range specified by
2085 * table->extra1 (min) and table->extra2 (max).
2086 *
2087 * Returns 0 on success.
2088 */
2089int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2090 void __user *buffer, size_t *lenp, loff_t *ppos)
2091{
2092 struct do_proc_dointvec_minmax_conv_param param = {
2093 .min = (int *) table->extra1,
2094 .max = (int *) table->extra2,
2095 };
2096 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2097 do_proc_dointvec_minmax_conv, &param);
2098}
2099
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002100static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 struct file *filp,
2102 void __user *buffer,
2103 size_t *lenp, loff_t *ppos,
2104 unsigned long convmul,
2105 unsigned long convdiv)
2106{
2107#define TMPBUFLEN 21
2108 unsigned long *i, *min, *max, val;
2109 int vleft, first=1, neg;
2110 size_t len, left;
2111 char buf[TMPBUFLEN], *p;
2112 char __user *s = buffer;
2113
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002114 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 (*ppos && !write)) {
2116 *lenp = 0;
2117 return 0;
2118 }
2119
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002120 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 min = (unsigned long *) table->extra1;
2122 max = (unsigned long *) table->extra2;
2123 vleft = table->maxlen / sizeof(unsigned long);
2124 left = *lenp;
2125
2126 for (; left && vleft--; i++, min++, max++, first=0) {
2127 if (write) {
2128 while (left) {
2129 char c;
2130 if (get_user(c, s))
2131 return -EFAULT;
2132 if (!isspace(c))
2133 break;
2134 left--;
2135 s++;
2136 }
2137 if (!left)
2138 break;
2139 neg = 0;
2140 len = left;
2141 if (len > TMPBUFLEN-1)
2142 len = TMPBUFLEN-1;
2143 if (copy_from_user(buf, s, len))
2144 return -EFAULT;
2145 buf[len] = 0;
2146 p = buf;
2147 if (*p == '-' && left > 1) {
2148 neg = 1;
2149 left--, p++;
2150 }
2151 if (*p < '0' || *p > '9')
2152 break;
2153 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2154 len = p-buf;
2155 if ((len < left) && *p && !isspace(*p))
2156 break;
2157 if (neg)
2158 val = -val;
2159 s += len;
2160 left -= len;
2161
2162 if(neg)
2163 continue;
2164 if ((min && val < *min) || (max && val > *max))
2165 continue;
2166 *i = val;
2167 } else {
2168 p = buf;
2169 if (!first)
2170 *p++ = '\t';
2171 sprintf(p, "%lu", convdiv * (*i) / convmul);
2172 len = strlen(buf);
2173 if (len > left)
2174 len = left;
2175 if(copy_to_user(s, buf, len))
2176 return -EFAULT;
2177 left -= len;
2178 s += len;
2179 }
2180 }
2181
2182 if (!write && !first && left) {
2183 if(put_user('\n', s))
2184 return -EFAULT;
2185 left--, s++;
2186 }
2187 if (write) {
2188 while (left) {
2189 char c;
2190 if (get_user(c, s++))
2191 return -EFAULT;
2192 if (!isspace(c))
2193 break;
2194 left--;
2195 }
2196 }
2197 if (write && first)
2198 return -EINVAL;
2199 *lenp -= left;
2200 *ppos += *lenp;
2201 return 0;
2202#undef TMPBUFLEN
2203}
2204
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002205static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2206 struct file *filp,
2207 void __user *buffer,
2208 size_t *lenp, loff_t *ppos,
2209 unsigned long convmul,
2210 unsigned long convdiv)
2211{
2212 return __do_proc_doulongvec_minmax(table->data, table, write,
2213 filp, buffer, lenp, ppos, convmul, convdiv);
2214}
2215
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216/**
2217 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2218 * @table: the sysctl table
2219 * @write: %TRUE if this is a write to the sysctl file
2220 * @filp: the file structure
2221 * @buffer: the user buffer
2222 * @lenp: the size of the user buffer
2223 * @ppos: file position
2224 *
2225 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2226 * values from/to the user buffer, treated as an ASCII string.
2227 *
2228 * This routine will ensure the values are within the range specified by
2229 * table->extra1 (min) and table->extra2 (max).
2230 *
2231 * Returns 0 on success.
2232 */
2233int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2234 void __user *buffer, size_t *lenp, loff_t *ppos)
2235{
2236 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2237}
2238
2239/**
2240 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2241 * @table: the sysctl table
2242 * @write: %TRUE if this is a write to the sysctl file
2243 * @filp: the file structure
2244 * @buffer: the user buffer
2245 * @lenp: the size of the user buffer
2246 * @ppos: file position
2247 *
2248 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2249 * values from/to the user buffer, treated as an ASCII string. The values
2250 * are treated as milliseconds, and converted to jiffies when they are stored.
2251 *
2252 * This routine will ensure the values are within the range specified by
2253 * table->extra1 (min) and table->extra2 (max).
2254 *
2255 * Returns 0 on success.
2256 */
2257int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2258 struct file *filp,
2259 void __user *buffer,
2260 size_t *lenp, loff_t *ppos)
2261{
2262 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2263 lenp, ppos, HZ, 1000l);
2264}
2265
2266
2267static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2268 int *valp,
2269 int write, void *data)
2270{
2271 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002272 if (*lvalp > LONG_MAX / HZ)
2273 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2275 } else {
2276 int val = *valp;
2277 unsigned long lval;
2278 if (val < 0) {
2279 *negp = -1;
2280 lval = (unsigned long)-val;
2281 } else {
2282 *negp = 0;
2283 lval = (unsigned long)val;
2284 }
2285 *lvalp = lval / HZ;
2286 }
2287 return 0;
2288}
2289
2290static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2291 int *valp,
2292 int write, void *data)
2293{
2294 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002295 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2296 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2298 } else {
2299 int val = *valp;
2300 unsigned long lval;
2301 if (val < 0) {
2302 *negp = -1;
2303 lval = (unsigned long)-val;
2304 } else {
2305 *negp = 0;
2306 lval = (unsigned long)val;
2307 }
2308 *lvalp = jiffies_to_clock_t(lval);
2309 }
2310 return 0;
2311}
2312
2313static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2314 int *valp,
2315 int write, void *data)
2316{
2317 if (write) {
2318 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2319 } else {
2320 int val = *valp;
2321 unsigned long lval;
2322 if (val < 0) {
2323 *negp = -1;
2324 lval = (unsigned long)-val;
2325 } else {
2326 *negp = 0;
2327 lval = (unsigned long)val;
2328 }
2329 *lvalp = jiffies_to_msecs(lval);
2330 }
2331 return 0;
2332}
2333
2334/**
2335 * proc_dointvec_jiffies - read a vector of integers as seconds
2336 * @table: the sysctl table
2337 * @write: %TRUE if this is a write to the sysctl file
2338 * @filp: the file structure
2339 * @buffer: the user buffer
2340 * @lenp: the size of the user buffer
2341 * @ppos: file position
2342 *
2343 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2344 * values from/to the user buffer, treated as an ASCII string.
2345 * The values read are assumed to be in seconds, and are converted into
2346 * jiffies.
2347 *
2348 * Returns 0 on success.
2349 */
2350int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2351 void __user *buffer, size_t *lenp, loff_t *ppos)
2352{
2353 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2354 do_proc_dointvec_jiffies_conv,NULL);
2355}
2356
2357/**
2358 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2359 * @table: the sysctl table
2360 * @write: %TRUE if this is a write to the sysctl file
2361 * @filp: the file structure
2362 * @buffer: the user buffer
2363 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002364 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 *
2366 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2367 * values from/to the user buffer, treated as an ASCII string.
2368 * The values read are assumed to be in 1/USER_HZ seconds, and
2369 * are converted into jiffies.
2370 *
2371 * Returns 0 on success.
2372 */
2373int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2374 void __user *buffer, size_t *lenp, loff_t *ppos)
2375{
2376 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2377 do_proc_dointvec_userhz_jiffies_conv,NULL);
2378}
2379
2380/**
2381 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2382 * @table: the sysctl table
2383 * @write: %TRUE if this is a write to the sysctl file
2384 * @filp: the file structure
2385 * @buffer: the user buffer
2386 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002387 * @ppos: file position
2388 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 *
2390 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2391 * values from/to the user buffer, treated as an ASCII string.
2392 * The values read are assumed to be in 1/1000 seconds, and
2393 * are converted into jiffies.
2394 *
2395 * Returns 0 on success.
2396 */
2397int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2398 void __user *buffer, size_t *lenp, loff_t *ppos)
2399{
2400 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2401 do_proc_dointvec_ms_jiffies_conv, NULL);
2402}
2403
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002404#ifdef CONFIG_SYSVIPC
2405static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2406 void __user *buffer, size_t *lenp, loff_t *ppos)
2407{
2408 void *data;
2409 struct ipc_namespace *ns;
2410
2411 ns = current->nsproxy->ipc_ns;
2412
2413 switch (table->ctl_name) {
2414 case KERN_SHMMAX:
2415 data = &ns->shm_ctlmax;
2416 goto proc_minmax;
2417 case KERN_SHMALL:
2418 data = &ns->shm_ctlall;
2419 goto proc_minmax;
2420 case KERN_SHMMNI:
2421 data = &ns->shm_ctlmni;
2422 break;
2423 case KERN_MSGMAX:
2424 data = &ns->msg_ctlmax;
2425 break;
2426 case KERN_MSGMNI:
2427 data = &ns->msg_ctlmni;
2428 break;
2429 case KERN_MSGMNB:
2430 data = &ns->msg_ctlmnb;
2431 break;
2432 case KERN_SEM:
2433 data = &ns->sem_ctls;
2434 break;
2435 default:
2436 return -EINVAL;
2437 }
2438
2439 return __do_proc_dointvec(data, table, write, filp, buffer,
2440 lenp, ppos, NULL, NULL);
2441proc_minmax:
2442 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2443 lenp, ppos, 1l, 1l);
2444}
2445#endif
2446
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002447static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2448 void __user *buffer, size_t *lenp, loff_t *ppos)
2449{
2450 struct pid *new_pid;
2451 pid_t tmp;
2452 int r;
2453
2454 tmp = pid_nr(cad_pid);
2455
2456 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2457 lenp, ppos, NULL, NULL);
2458 if (r || !write)
2459 return r;
2460
2461 new_pid = find_get_pid(tmp);
2462 if (!new_pid)
2463 return -ESRCH;
2464
2465 put_pid(xchg(&cad_pid, new_pid));
2466 return 0;
2467}
2468
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469#else /* CONFIG_PROC_FS */
2470
2471int proc_dostring(ctl_table *table, int write, struct file *filp,
2472 void __user *buffer, size_t *lenp, loff_t *ppos)
2473{
2474 return -ENOSYS;
2475}
2476
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002477static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2478 void __user *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479{
2480 return -ENOSYS;
2481}
2482
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002483#ifdef CONFIG_SYSVIPC
2484static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2485 void __user *buffer, size_t *lenp, loff_t *ppos)
2486{
2487 return -ENOSYS;
2488}
2489#endif
2490
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491int proc_dointvec(ctl_table *table, int write, struct file *filp,
2492 void __user *buffer, size_t *lenp, loff_t *ppos)
2493{
2494 return -ENOSYS;
2495}
2496
2497int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2498 void __user *buffer, size_t *lenp, loff_t *ppos)
2499{
2500 return -ENOSYS;
2501}
2502
2503int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2504 void __user *buffer, size_t *lenp, loff_t *ppos)
2505{
2506 return -ENOSYS;
2507}
2508
2509int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2510 void __user *buffer, size_t *lenp, loff_t *ppos)
2511{
2512 return -ENOSYS;
2513}
2514
2515int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2516 void __user *buffer, size_t *lenp, loff_t *ppos)
2517{
2518 return -ENOSYS;
2519}
2520
2521int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2522 void __user *buffer, size_t *lenp, loff_t *ppos)
2523{
2524 return -ENOSYS;
2525}
2526
2527int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2528 void __user *buffer, size_t *lenp, loff_t *ppos)
2529{
2530 return -ENOSYS;
2531}
2532
2533int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2534 struct file *filp,
2535 void __user *buffer,
2536 size_t *lenp, loff_t *ppos)
2537{
2538 return -ENOSYS;
2539}
2540
2541
2542#endif /* CONFIG_PROC_FS */
2543
2544
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002545#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546/*
2547 * General sysctl support routines
2548 */
2549
2550/* The generic string strategy routine: */
2551int sysctl_string(ctl_table *table, int __user *name, int nlen,
2552 void __user *oldval, size_t __user *oldlenp,
2553 void __user *newval, size_t newlen, void **context)
2554{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 if (!table->data || !table->maxlen)
2556 return -ENOTDIR;
2557
2558 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002559 size_t bufsize;
2560 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002562 if (bufsize) {
2563 size_t len = strlen(table->data), copied;
2564
2565 /* This shouldn't trigger for a well-formed sysctl */
2566 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002568
2569 /* Copy up to a max of bufsize-1 bytes of the string */
2570 copied = (len >= bufsize) ? bufsize - 1 : len;
2571
2572 if (copy_to_user(oldval, table->data, copied) ||
2573 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002575 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 return -EFAULT;
2577 }
2578 }
2579 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002580 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 if (len > table->maxlen)
2582 len = table->maxlen;
2583 if(copy_from_user(table->data, newval, len))
2584 return -EFAULT;
2585 if (len == table->maxlen)
2586 len--;
2587 ((char *) table->data)[len] = 0;
2588 }
Yi Yang82c9df82005-12-30 16:37:10 +08002589 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590}
2591
2592/*
2593 * This function makes sure that all of the integers in the vector
2594 * are between the minimum and maximum values given in the arrays
2595 * table->extra1 and table->extra2, respectively.
2596 */
2597int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2598 void __user *oldval, size_t __user *oldlenp,
2599 void __user *newval, size_t newlen, void **context)
2600{
2601
2602 if (newval && newlen) {
2603 int __user *vec = (int __user *) newval;
2604 int *min = (int *) table->extra1;
2605 int *max = (int *) table->extra2;
2606 size_t length;
2607 int i;
2608
2609 if (newlen % sizeof(int) != 0)
2610 return -EINVAL;
2611
2612 if (!table->extra1 && !table->extra2)
2613 return 0;
2614
2615 if (newlen > table->maxlen)
2616 newlen = table->maxlen;
2617 length = newlen / sizeof(int);
2618
2619 for (i = 0; i < length; i++) {
2620 int value;
2621 if (get_user(value, vec + i))
2622 return -EFAULT;
2623 if (min && value < min[i])
2624 return -EINVAL;
2625 if (max && value > max[i])
2626 return -EINVAL;
2627 }
2628 }
2629 return 0;
2630}
2631
2632/* Strategy function to convert jiffies to seconds */
2633int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2634 void __user *oldval, size_t __user *oldlenp,
2635 void __user *newval, size_t newlen, void **context)
2636{
2637 if (oldval) {
2638 size_t olen;
2639 if (oldlenp) {
2640 if (get_user(olen, oldlenp))
2641 return -EFAULT;
2642 if (olen!=sizeof(int))
2643 return -EINVAL;
2644 }
2645 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2646 (oldlenp && put_user(sizeof(int),oldlenp)))
2647 return -EFAULT;
2648 }
2649 if (newval && newlen) {
2650 int new;
2651 if (newlen != sizeof(int))
2652 return -EINVAL;
2653 if (get_user(new, (int __user *)newval))
2654 return -EFAULT;
2655 *(int *)(table->data) = new*HZ;
2656 }
2657 return 1;
2658}
2659
2660/* Strategy function to convert jiffies to seconds */
2661int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2662 void __user *oldval, size_t __user *oldlenp,
2663 void __user *newval, size_t newlen, void **context)
2664{
2665 if (oldval) {
2666 size_t olen;
2667 if (oldlenp) {
2668 if (get_user(olen, oldlenp))
2669 return -EFAULT;
2670 if (olen!=sizeof(int))
2671 return -EINVAL;
2672 }
2673 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2674 (oldlenp && put_user(sizeof(int),oldlenp)))
2675 return -EFAULT;
2676 }
2677 if (newval && newlen) {
2678 int new;
2679 if (newlen != sizeof(int))
2680 return -EINVAL;
2681 if (get_user(new, (int __user *)newval))
2682 return -EFAULT;
2683 *(int *)(table->data) = msecs_to_jiffies(new);
2684 }
2685 return 1;
2686}
2687
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002688#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
2690
2691asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2692{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002693 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002694 struct __sysctl_args tmp;
2695 int name[CTL_MAXNAME];
2696 int i;
2697
2698 /* Read in the sysctl name for better debug message logging */
2699 if (copy_from_user(&tmp, args, sizeof(tmp)))
2700 return -EFAULT;
2701 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2702 return -ENOTDIR;
2703 for (i = 0; i < tmp.nlen; i++)
2704 if (get_user(name[i], tmp.name + i))
2705 return -EFAULT;
2706
2707 /* Ignore accesses to kernel.version */
2708 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2709 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002710
2711 if (msg_count < 5) {
2712 msg_count++;
2713 printk(KERN_INFO
2714 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002715 "system call with ", current->comm);
2716 for (i = 0; i < tmp.nlen; i++)
2717 printk("%d.", name[i]);
2718 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002719 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002720out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 return -ENOSYS;
2722}
2723
2724int sysctl_string(ctl_table *table, int __user *name, int nlen,
2725 void __user *oldval, size_t __user *oldlenp,
2726 void __user *newval, size_t newlen, void **context)
2727{
2728 return -ENOSYS;
2729}
2730
2731int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2732 void __user *oldval, size_t __user *oldlenp,
2733 void __user *newval, size_t newlen, void **context)
2734{
2735 return -ENOSYS;
2736}
2737
2738int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2739 void __user *oldval, size_t __user *oldlenp,
2740 void __user *newval, size_t newlen, void **context)
2741{
2742 return -ENOSYS;
2743}
2744
2745int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2746 void __user *oldval, size_t __user *oldlenp,
2747 void __user *newval, size_t newlen, void **context)
2748{
2749 return -ENOSYS;
2750}
2751
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002752#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
2754/*
2755 * No sense putting this after each symbol definition, twice,
2756 * exception granted :-)
2757 */
2758EXPORT_SYMBOL(proc_dointvec);
2759EXPORT_SYMBOL(proc_dointvec_jiffies);
2760EXPORT_SYMBOL(proc_dointvec_minmax);
2761EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2762EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2763EXPORT_SYMBOL(proc_dostring);
2764EXPORT_SYMBOL(proc_doulongvec_minmax);
2765EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2766EXPORT_SYMBOL(register_sysctl_table);
2767EXPORT_SYMBOL(sysctl_intvec);
2768EXPORT_SYMBOL(sysctl_jiffies);
2769EXPORT_SYMBOL(sysctl_ms_jiffies);
2770EXPORT_SYMBOL(sysctl_string);
2771EXPORT_SYMBOL(unregister_sysctl_table);