blob: 10474a63a111ca17c630cd729ee4134fe0ebd968 [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
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -080095static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos);
97static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -070098 void __user *buffer, size_t *lenp, loff_t *ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#endif
100
101#ifdef __sparc__
102extern char reboot_command [];
103extern int stop_a_enabled;
104extern int scons_pwroff;
105#endif
106
107#ifdef __hppa__
108extern int pwrsw_enabled;
109extern int unaligned_enabled;
110#endif
111
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800112#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#ifdef CONFIG_MATHEMU
114extern int sysctl_ieee_emulation_warnings;
115#endif
116extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700117extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#endif
119
120extern int sysctl_hz_timer;
121
122#ifdef CONFIG_BSD_PROCESS_ACCT
123extern int acct_parm[];
124#endif
125
Jes Sorensend2b176e2006-02-28 09:42:23 -0800126#ifdef CONFIG_IA64
127extern int no_unaligned_warning;
128#endif
129
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700130#ifdef CONFIG_RT_MUTEXES
131extern int max_lock_depth;
132#endif
133
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700134#ifdef CONFIG_SYSCTL_SYSCALL
135static int parse_table(int __user *, int, void __user *, size_t __user *,
136 void __user *, size_t, ctl_table *, void **);
137#endif
138
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700139static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 void __user *buffer, size_t *lenp, loff_t *ppos);
141
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800142static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
143 void __user *oldval, size_t __user *oldlenp,
144 void __user *newval, size_t newlen, void **context);
145
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700146#ifdef CONFIG_PROC_SYSCTL
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700147static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
148 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700149#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151static ctl_table root_table[];
152static struct ctl_table_header root_table_header =
153 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
154
155static ctl_table kern_table[];
156static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157static ctl_table fs_table[];
158static ctl_table debug_table[];
159static ctl_table dev_table[];
160extern ctl_table random_table[];
161#ifdef CONFIG_UNIX98_PTYS
162extern ctl_table pty_table[];
163#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700164#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400165extern ctl_table inotify_table[];
166#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
169int sysctl_legacy_va_layout;
170#endif
171
Eric W. Biedermancf9f1512006-12-08 02:39:55 -0800172static void *get_uts(ctl_table *table, int write)
173{
174 char *which = table->data;
175#ifdef CONFIG_UTS_NS
176 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
177 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
178#endif
179 if (!write)
180 down_read(&uts_sem);
181 else
182 down_write(&uts_sem);
183 return which;
184}
185
186static void put_uts(ctl_table *table, int write, void *which)
187{
188 if (!write)
189 up_read(&uts_sem);
190 else
191 up_write(&uts_sem);
192}
193
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800194#ifdef CONFIG_SYSVIPC
195static void *get_ipc(ctl_table *table, int write)
196{
197 char *which = table->data;
198 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
199 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
200 return which;
201}
202#else
203#define get_ipc(T,W) ((T)->data)
204#endif
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/* /proc declarations: */
207
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700208#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
211static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
212static int proc_opensys(struct inode *, struct file *);
213
Helge Deller15ad7cd2006-12-06 20:40:36 -0800214const struct file_operations proc_sys_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 .open = proc_opensys,
216 .read = proc_readsys,
217 .write = proc_writesys,
218};
219
220extern struct proc_dir_entry *proc_sys_root;
221
Al Viro330d57f2005-11-04 10:18:40 +0000222static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
224#endif
225
226/* The default sysctl tables: */
227
228static ctl_table root_table[] = {
229 {
230 .ctl_name = CTL_KERN,
231 .procname = "kernel",
232 .mode = 0555,
233 .child = kern_table,
234 },
235 {
236 .ctl_name = CTL_VM,
237 .procname = "vm",
238 .mode = 0555,
239 .child = vm_table,
240 },
241#ifdef CONFIG_NET
242 {
243 .ctl_name = CTL_NET,
244 .procname = "net",
245 .mode = 0555,
246 .child = net_table,
247 },
248#endif
249 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .ctl_name = CTL_FS,
251 .procname = "fs",
252 .mode = 0555,
253 .child = fs_table,
254 },
255 {
256 .ctl_name = CTL_DEBUG,
257 .procname = "debug",
258 .mode = 0555,
259 .child = debug_table,
260 },
261 {
262 .ctl_name = CTL_DEV,
263 .procname = "dev",
264 .mode = 0555,
265 .child = dev_table,
266 },
Robert Love0eeca282005-07-12 17:06:03 -0400267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 { .ctl_name = 0 }
269};
270
271static ctl_table kern_table[] = {
272 {
273 .ctl_name = KERN_OSTYPE,
274 .procname = "ostype",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700275 .data = init_uts_ns.name.sysname,
276 .maxlen = sizeof(init_uts_ns.name.sysname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700278 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800279 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 },
281 {
282 .ctl_name = KERN_OSRELEASE,
283 .procname = "osrelease",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700284 .data = init_uts_ns.name.release,
285 .maxlen = sizeof(init_uts_ns.name.release),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700287 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800288 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 },
290 {
291 .ctl_name = KERN_VERSION,
292 .procname = "version",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700293 .data = init_uts_ns.name.version,
294 .maxlen = sizeof(init_uts_ns.name.version),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700296 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800297 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 },
299 {
300 .ctl_name = KERN_NODENAME,
301 .procname = "hostname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700302 .data = init_uts_ns.name.nodename,
303 .maxlen = sizeof(init_uts_ns.name.nodename),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700305 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800306 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 },
308 {
309 .ctl_name = KERN_DOMAINNAME,
310 .procname = "domainname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700311 .data = init_uts_ns.name.domainname,
312 .maxlen = sizeof(init_uts_ns.name.domainname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700314 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800315 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 },
317 {
318 .ctl_name = KERN_PANIC,
319 .procname = "panic",
320 .data = &panic_timeout,
321 .maxlen = sizeof(int),
322 .mode = 0644,
323 .proc_handler = &proc_dointvec,
324 },
325 {
326 .ctl_name = KERN_CORE_USES_PID,
327 .procname = "core_uses_pid",
328 .data = &core_uses_pid,
329 .maxlen = sizeof(int),
330 .mode = 0644,
331 .proc_handler = &proc_dointvec,
332 },
333 {
334 .ctl_name = KERN_CORE_PATTERN,
335 .procname = "core_pattern",
336 .data = core_pattern,
Andi Kleend025c9d2006-09-30 23:29:28 -0700337 .maxlen = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 .mode = 0644,
339 .proc_handler = &proc_dostring,
340 .strategy = &sysctl_string,
341 },
342 {
343 .ctl_name = KERN_TAINTED,
344 .procname = "tainted",
345 .data = &tainted,
346 .maxlen = sizeof(int),
347 .mode = 0444,
348 .proc_handler = &proc_dointvec,
349 },
350 {
351 .ctl_name = KERN_CAP_BSET,
352 .procname = "cap-bound",
353 .data = &cap_bset,
354 .maxlen = sizeof(kernel_cap_t),
355 .mode = 0600,
356 .proc_handler = &proc_dointvec_bset,
357 },
358#ifdef CONFIG_BLK_DEV_INITRD
359 {
360 .ctl_name = KERN_REALROOTDEV,
361 .procname = "real-root-dev",
362 .data = &real_root_dev,
363 .maxlen = sizeof(int),
364 .mode = 0644,
365 .proc_handler = &proc_dointvec,
366 },
367#endif
368#ifdef __sparc__
369 {
370 .ctl_name = KERN_SPARC_REBOOT,
371 .procname = "reboot-cmd",
372 .data = reboot_command,
373 .maxlen = 256,
374 .mode = 0644,
375 .proc_handler = &proc_dostring,
376 .strategy = &sysctl_string,
377 },
378 {
379 .ctl_name = KERN_SPARC_STOP_A,
380 .procname = "stop-a",
381 .data = &stop_a_enabled,
382 .maxlen = sizeof (int),
383 .mode = 0644,
384 .proc_handler = &proc_dointvec,
385 },
386 {
387 .ctl_name = KERN_SPARC_SCONS_PWROFF,
388 .procname = "scons-poweroff",
389 .data = &scons_pwroff,
390 .maxlen = sizeof (int),
391 .mode = 0644,
392 .proc_handler = &proc_dointvec,
393 },
394#endif
395#ifdef __hppa__
396 {
397 .ctl_name = KERN_HPPA_PWRSW,
398 .procname = "soft-power",
399 .data = &pwrsw_enabled,
400 .maxlen = sizeof (int),
401 .mode = 0644,
402 .proc_handler = &proc_dointvec,
403 },
404 {
405 .ctl_name = KERN_HPPA_UNALIGNED,
406 .procname = "unaligned-trap",
407 .data = &unaligned_enabled,
408 .maxlen = sizeof (int),
409 .mode = 0644,
410 .proc_handler = &proc_dointvec,
411 },
412#endif
413 {
414 .ctl_name = KERN_CTLALTDEL,
415 .procname = "ctrl-alt-del",
416 .data = &C_A_D,
417 .maxlen = sizeof(int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
420 },
421 {
422 .ctl_name = KERN_PRINTK,
423 .procname = "printk",
424 .data = &console_loglevel,
425 .maxlen = 4*sizeof(int),
426 .mode = 0644,
427 .proc_handler = &proc_dointvec,
428 },
429#ifdef CONFIG_KMOD
430 {
431 .ctl_name = KERN_MODPROBE,
432 .procname = "modprobe",
433 .data = &modprobe_path,
434 .maxlen = KMOD_PATH_LEN,
435 .mode = 0644,
436 .proc_handler = &proc_dostring,
437 .strategy = &sysctl_string,
438 },
439#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700440#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 {
442 .ctl_name = KERN_HOTPLUG,
443 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100444 .data = &uevent_helper,
445 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 .mode = 0644,
447 .proc_handler = &proc_dostring,
448 .strategy = &sysctl_string,
449 },
450#endif
451#ifdef CONFIG_CHR_DEV_SG
452 {
453 .ctl_name = KERN_SG_BIG_BUFF,
454 .procname = "sg-big-buff",
455 .data = &sg_big_buff,
456 .maxlen = sizeof (int),
457 .mode = 0444,
458 .proc_handler = &proc_dointvec,
459 },
460#endif
461#ifdef CONFIG_BSD_PROCESS_ACCT
462 {
463 .ctl_name = KERN_ACCT,
464 .procname = "acct",
465 .data = &acct_parm,
466 .maxlen = 3*sizeof(int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
469 },
470#endif
471#ifdef CONFIG_SYSVIPC
472 {
473 .ctl_name = KERN_SHMMAX,
474 .procname = "shmmax",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800475 .data = &init_ipc_ns.shm_ctlmax,
476 .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800478 .proc_handler = &proc_ipc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
480 {
481 .ctl_name = KERN_SHMALL,
482 .procname = "shmall",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800483 .data = &init_ipc_ns.shm_ctlall,
484 .maxlen = sizeof (init_ipc_ns.shm_ctlall),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800486 .proc_handler = &proc_ipc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 },
488 {
489 .ctl_name = KERN_SHMMNI,
490 .procname = "shmmni",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800491 .data = &init_ipc_ns.shm_ctlmni,
492 .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800494 .proc_handler = &proc_ipc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 },
496 {
497 .ctl_name = KERN_MSGMAX,
498 .procname = "msgmax",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800499 .data = &init_ipc_ns.msg_ctlmax,
500 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800502 .proc_handler = &proc_ipc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 },
504 {
505 .ctl_name = KERN_MSGMNI,
506 .procname = "msgmni",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800507 .data = &init_ipc_ns.msg_ctlmni,
508 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800510 .proc_handler = &proc_ipc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 },
512 {
513 .ctl_name = KERN_MSGMNB,
514 .procname = "msgmnb",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800515 .data = &init_ipc_ns.msg_ctlmnb,
516 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800518 .proc_handler = &proc_ipc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 },
520 {
521 .ctl_name = KERN_SEM,
522 .procname = "sem",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800523 .data = &init_ipc_ns.sem_ctls,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 .maxlen = 4*sizeof (int),
525 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800526 .proc_handler = &proc_ipc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
528#endif
529#ifdef CONFIG_MAGIC_SYSRQ
530 {
531 .ctl_name = KERN_SYSRQ,
532 .procname = "sysrq",
533 .data = &sysrq_enabled,
534 .maxlen = sizeof (int),
535 .mode = 0644,
536 .proc_handler = &proc_dointvec,
537 },
538#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700539#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
541 .ctl_name = KERN_CADPID,
542 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700543 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .maxlen = sizeof (int),
545 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700546 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700548#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 {
550 .ctl_name = KERN_MAX_THREADS,
551 .procname = "threads-max",
552 .data = &max_threads,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 .proc_handler = &proc_dointvec,
556 },
557 {
558 .ctl_name = KERN_RANDOM,
559 .procname = "random",
560 .mode = 0555,
561 .child = random_table,
562 },
563#ifdef CONFIG_UNIX98_PTYS
564 {
565 .ctl_name = KERN_PTY,
566 .procname = "pty",
567 .mode = 0555,
568 .child = pty_table,
569 },
570#endif
571 {
572 .ctl_name = KERN_OVERFLOWUID,
573 .procname = "overflowuid",
574 .data = &overflowuid,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec_minmax,
578 .strategy = &sysctl_intvec,
579 .extra1 = &minolduid,
580 .extra2 = &maxolduid,
581 },
582 {
583 .ctl_name = KERN_OVERFLOWGID,
584 .procname = "overflowgid",
585 .data = &overflowgid,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 .proc_handler = &proc_dointvec_minmax,
589 .strategy = &sysctl_intvec,
590 .extra1 = &minolduid,
591 .extra2 = &maxolduid,
592 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800593#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#ifdef CONFIG_MATHEMU
595 {
596 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
597 .procname = "ieee_emulation_warnings",
598 .data = &sysctl_ieee_emulation_warnings,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec,
602 },
603#endif
604#ifdef CONFIG_NO_IDLE_HZ
605 {
606 .ctl_name = KERN_HZ_TIMER,
607 .procname = "hz_timer",
608 .data = &sysctl_hz_timer,
609 .maxlen = sizeof(int),
610 .mode = 0644,
611 .proc_handler = &proc_dointvec,
612 },
613#endif
614 {
615 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
616 .procname = "userprocess_debug",
617 .data = &sysctl_userprocess_debug,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec,
621 },
622#endif
623 {
624 .ctl_name = KERN_PIDMAX,
625 .procname = "pid_max",
626 .data = &pid_max,
627 .maxlen = sizeof (int),
628 .mode = 0644,
629 .proc_handler = &proc_dointvec_minmax,
630 .strategy = sysctl_intvec,
631 .extra1 = &pid_max_min,
632 .extra2 = &pid_max_max,
633 },
634 {
635 .ctl_name = KERN_PANIC_ON_OOPS,
636 .procname = "panic_on_oops",
637 .data = &panic_on_oops,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 .proc_handler = &proc_dointvec,
641 },
642 {
643 .ctl_name = KERN_PRINTK_RATELIMIT,
644 .procname = "printk_ratelimit",
645 .data = &printk_ratelimit_jiffies,
646 .maxlen = sizeof(int),
647 .mode = 0644,
648 .proc_handler = &proc_dointvec_jiffies,
649 .strategy = &sysctl_jiffies,
650 },
651 {
652 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
653 .procname = "printk_ratelimit_burst",
654 .data = &printk_ratelimit_burst,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = &proc_dointvec,
658 },
659 {
660 .ctl_name = KERN_NGROUPS_MAX,
661 .procname = "ngroups_max",
662 .data = &ngroups_max,
663 .maxlen = sizeof (int),
664 .mode = 0444,
665 .proc_handler = &proc_dointvec,
666 },
667#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
668 {
669 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
670 .procname = "unknown_nmi_panic",
671 .data = &unknown_nmi_panic,
672 .maxlen = sizeof (int),
673 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200674 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 },
Don Zickus407984f2006-09-26 10:52:27 +0200676 {
677 .ctl_name = KERN_NMI_WATCHDOG,
678 .procname = "nmi_watchdog",
679 .data = &nmi_watchdog_enabled,
680 .maxlen = sizeof (int),
681 .mode = 0644,
682 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 },
684#endif
685#if defined(CONFIG_X86)
686 {
Don Zickus8da5add2006-09-26 10:52:27 +0200687 .ctl_name = KERN_PANIC_ON_NMI,
688 .procname = "panic_on_unrecovered_nmi",
689 .data = &panic_on_unrecovered_nmi,
690 .maxlen = sizeof(int),
691 .mode = 0644,
692 .proc_handler = &proc_dointvec,
693 },
694 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .ctl_name = KERN_BOOTLOADER_TYPE,
696 .procname = "bootloader_type",
697 .data = &bootloader_type,
698 .maxlen = sizeof (int),
699 .mode = 0444,
700 .proc_handler = &proc_dointvec,
701 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100702 {
703 .ctl_name = CTL_UNNUMBERED,
704 .procname = "kstack_depth_to_print",
705 .data = &kstack_depth_to_print,
706 .maxlen = sizeof(int),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec,
709 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800711#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 {
713 .ctl_name = KERN_RANDOMIZE,
714 .procname = "randomize_va_space",
715 .data = &randomize_va_space,
716 .maxlen = sizeof(int),
717 .mode = 0644,
718 .proc_handler = &proc_dointvec,
719 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800720#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800721#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700722 {
723 .ctl_name = KERN_SPIN_RETRY,
724 .procname = "spin_retry",
725 .data = &spin_retry,
726 .maxlen = sizeof (int),
727 .mode = 0644,
728 .proc_handler = &proc_dointvec,
729 },
730#endif
Pavel Machekc255d842006-02-20 18:27:58 -0800731#ifdef CONFIG_ACPI_SLEEP
732 {
733 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
734 .procname = "acpi_video_flags",
735 .data = &acpi_video_flags,
736 .maxlen = sizeof (unsigned long),
737 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800738 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800739 },
740#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800741#ifdef CONFIG_IA64
742 {
743 .ctl_name = KERN_IA64_UNALIGNED,
744 .procname = "ignore-unaligned-usertrap",
745 .data = &no_unaligned_warning,
746 .maxlen = sizeof (int),
747 .mode = 0644,
748 .proc_handler = &proc_dointvec,
749 },
750#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200751#ifdef CONFIG_COMPAT
752 {
753 .ctl_name = KERN_COMPAT_LOG,
754 .procname = "compat-log",
755 .data = &compat_log,
756 .maxlen = sizeof (int),
757 .mode = 0644,
758 .proc_handler = &proc_dointvec,
759 },
760#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700761#ifdef CONFIG_RT_MUTEXES
762 {
763 .ctl_name = KERN_MAX_LOCK_DEPTH,
764 .procname = "max_lock_depth",
765 .data = &max_lock_depth,
766 .maxlen = sizeof(int),
767 .mode = 0644,
768 .proc_handler = &proc_dointvec,
769 },
770#endif
771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 { .ctl_name = 0 }
773};
774
775/* Constants for minimum and maximum testing in vm_table.
776 We use these as one-element integer vectors. */
777static int zero;
778static int one_hundred = 100;
779
780
781static ctl_table vm_table[] = {
782 {
783 .ctl_name = VM_OVERCOMMIT_MEMORY,
784 .procname = "overcommit_memory",
785 .data = &sysctl_overcommit_memory,
786 .maxlen = sizeof(sysctl_overcommit_memory),
787 .mode = 0644,
788 .proc_handler = &proc_dointvec,
789 },
790 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700791 .ctl_name = VM_PANIC_ON_OOM,
792 .procname = "panic_on_oom",
793 .data = &sysctl_panic_on_oom,
794 .maxlen = sizeof(sysctl_panic_on_oom),
795 .mode = 0644,
796 .proc_handler = &proc_dointvec,
797 },
798 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .ctl_name = VM_OVERCOMMIT_RATIO,
800 .procname = "overcommit_ratio",
801 .data = &sysctl_overcommit_ratio,
802 .maxlen = sizeof(sysctl_overcommit_ratio),
803 .mode = 0644,
804 .proc_handler = &proc_dointvec,
805 },
806 {
807 .ctl_name = VM_PAGE_CLUSTER,
808 .procname = "page-cluster",
809 .data = &page_cluster,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = &proc_dointvec,
813 },
814 {
815 .ctl_name = VM_DIRTY_BACKGROUND,
816 .procname = "dirty_background_ratio",
817 .data = &dirty_background_ratio,
818 .maxlen = sizeof(dirty_background_ratio),
819 .mode = 0644,
820 .proc_handler = &proc_dointvec_minmax,
821 .strategy = &sysctl_intvec,
822 .extra1 = &zero,
823 .extra2 = &one_hundred,
824 },
825 {
826 .ctl_name = VM_DIRTY_RATIO,
827 .procname = "dirty_ratio",
828 .data = &vm_dirty_ratio,
829 .maxlen = sizeof(vm_dirty_ratio),
830 .mode = 0644,
831 .proc_handler = &proc_dointvec_minmax,
832 .strategy = &sysctl_intvec,
833 .extra1 = &zero,
834 .extra2 = &one_hundred,
835 },
836 {
837 .ctl_name = VM_DIRTY_WB_CS,
838 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800839 .data = &dirty_writeback_interval,
840 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 .mode = 0644,
842 .proc_handler = &dirty_writeback_centisecs_handler,
843 },
844 {
845 .ctl_name = VM_DIRTY_EXPIRE_CS,
846 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800847 .data = &dirty_expire_interval,
848 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800850 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 },
852 {
853 .ctl_name = VM_NR_PDFLUSH_THREADS,
854 .procname = "nr_pdflush_threads",
855 .data = &nr_pdflush_threads,
856 .maxlen = sizeof nr_pdflush_threads,
857 .mode = 0444 /* read-only*/,
858 .proc_handler = &proc_dointvec,
859 },
860 {
861 .ctl_name = VM_SWAPPINESS,
862 .procname = "swappiness",
863 .data = &vm_swappiness,
864 .maxlen = sizeof(vm_swappiness),
865 .mode = 0644,
866 .proc_handler = &proc_dointvec_minmax,
867 .strategy = &sysctl_intvec,
868 .extra1 = &zero,
869 .extra2 = &one_hundred,
870 },
871#ifdef CONFIG_HUGETLB_PAGE
872 {
873 .ctl_name = VM_HUGETLB_PAGES,
874 .procname = "nr_hugepages",
875 .data = &max_huge_pages,
876 .maxlen = sizeof(unsigned long),
877 .mode = 0644,
878 .proc_handler = &hugetlb_sysctl_handler,
879 .extra1 = (void *)&hugetlb_zero,
880 .extra2 = (void *)&hugetlb_infinity,
881 },
882 {
883 .ctl_name = VM_HUGETLB_GROUP,
884 .procname = "hugetlb_shm_group",
885 .data = &sysctl_hugetlb_shm_group,
886 .maxlen = sizeof(gid_t),
887 .mode = 0644,
888 .proc_handler = &proc_dointvec,
889 },
890#endif
891 {
892 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
893 .procname = "lowmem_reserve_ratio",
894 .data = &sysctl_lowmem_reserve_ratio,
895 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
896 .mode = 0644,
897 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
898 .strategy = &sysctl_intvec,
899 },
900 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800901 .ctl_name = VM_DROP_PAGECACHE,
902 .procname = "drop_caches",
903 .data = &sysctl_drop_caches,
904 .maxlen = sizeof(int),
905 .mode = 0644,
906 .proc_handler = drop_caches_sysctl_handler,
907 .strategy = &sysctl_intvec,
908 },
909 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .ctl_name = VM_MIN_FREE_KBYTES,
911 .procname = "min_free_kbytes",
912 .data = &min_free_kbytes,
913 .maxlen = sizeof(min_free_kbytes),
914 .mode = 0644,
915 .proc_handler = &min_free_kbytes_sysctl_handler,
916 .strategy = &sysctl_intvec,
917 .extra1 = &zero,
918 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800919 {
920 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
921 .procname = "percpu_pagelist_fraction",
922 .data = &percpu_pagelist_fraction,
923 .maxlen = sizeof(percpu_pagelist_fraction),
924 .mode = 0644,
925 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
926 .strategy = &sysctl_intvec,
927 .extra1 = &min_percpu_pagelist_fract,
928 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929#ifdef CONFIG_MMU
930 {
931 .ctl_name = VM_MAX_MAP_COUNT,
932 .procname = "max_map_count",
933 .data = &sysctl_max_map_count,
934 .maxlen = sizeof(sysctl_max_map_count),
935 .mode = 0644,
936 .proc_handler = &proc_dointvec
937 },
938#endif
939 {
940 .ctl_name = VM_LAPTOP_MODE,
941 .procname = "laptop_mode",
942 .data = &laptop_mode,
943 .maxlen = sizeof(laptop_mode),
944 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800945 .proc_handler = &proc_dointvec_jiffies,
946 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 },
948 {
949 .ctl_name = VM_BLOCK_DUMP,
950 .procname = "block_dump",
951 .data = &block_dump,
952 .maxlen = sizeof(block_dump),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
955 .strategy = &sysctl_intvec,
956 .extra1 = &zero,
957 },
958 {
959 .ctl_name = VM_VFS_CACHE_PRESSURE,
960 .procname = "vfs_cache_pressure",
961 .data = &sysctl_vfs_cache_pressure,
962 .maxlen = sizeof(sysctl_vfs_cache_pressure),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 .strategy = &sysctl_intvec,
966 .extra1 = &zero,
967 },
968#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
969 {
970 .ctl_name = VM_LEGACY_VA_LAYOUT,
971 .procname = "legacy_va_layout",
972 .data = &sysctl_legacy_va_layout,
973 .maxlen = sizeof(sysctl_legacy_va_layout),
974 .mode = 0644,
975 .proc_handler = &proc_dointvec,
976 .strategy = &sysctl_intvec,
977 .extra1 = &zero,
978 },
979#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800980#ifdef CONFIG_NUMA
981 {
982 .ctl_name = VM_ZONE_RECLAIM_MODE,
983 .procname = "zone_reclaim_mode",
984 .data = &zone_reclaim_mode,
985 .maxlen = sizeof(zone_reclaim_mode),
986 .mode = 0644,
987 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -0800988 .strategy = &sysctl_intvec,
989 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -0800990 },
Christoph Lameter96146342006-07-03 00:24:13 -0700991 {
992 .ctl_name = VM_MIN_UNMAPPED,
993 .procname = "min_unmapped_ratio",
994 .data = &sysctl_min_unmapped_ratio,
995 .maxlen = sizeof(sysctl_min_unmapped_ratio),
996 .mode = 0644,
997 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
998 .strategy = &sysctl_intvec,
999 .extra1 = &zero,
1000 .extra2 = &one_hundred,
1001 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001002 {
1003 .ctl_name = VM_MIN_SLAB,
1004 .procname = "min_slab_ratio",
1005 .data = &sysctl_min_slab_ratio,
1006 .maxlen = sizeof(sysctl_min_slab_ratio),
1007 .mode = 0644,
1008 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1009 .strategy = &sysctl_intvec,
1010 .extra1 = &zero,
1011 .extra2 = &one_hundred,
1012 },
Christoph Lameter17436602006-01-18 17:42:32 -08001013#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001014#ifdef CONFIG_X86_32
1015 {
1016 .ctl_name = VM_VDSO_ENABLED,
1017 .procname = "vdso_enabled",
1018 .data = &vdso_enabled,
1019 .maxlen = sizeof(vdso_enabled),
1020 .mode = 0644,
1021 .proc_handler = &proc_dointvec,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &zero,
1024 },
1025#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 { .ctl_name = 0 }
1027};
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029static ctl_table fs_table[] = {
1030 {
1031 .ctl_name = FS_NRINODE,
1032 .procname = "inode-nr",
1033 .data = &inodes_stat,
1034 .maxlen = 2*sizeof(int),
1035 .mode = 0444,
1036 .proc_handler = &proc_dointvec,
1037 },
1038 {
1039 .ctl_name = FS_STATINODE,
1040 .procname = "inode-state",
1041 .data = &inodes_stat,
1042 .maxlen = 7*sizeof(int),
1043 .mode = 0444,
1044 .proc_handler = &proc_dointvec,
1045 },
1046 {
1047 .ctl_name = FS_NRFILE,
1048 .procname = "file-nr",
1049 .data = &files_stat,
1050 .maxlen = 3*sizeof(int),
1051 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001052 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 },
1054 {
1055 .ctl_name = FS_MAXFILE,
1056 .procname = "file-max",
1057 .data = &files_stat.max_files,
1058 .maxlen = sizeof(int),
1059 .mode = 0644,
1060 .proc_handler = &proc_dointvec,
1061 },
1062 {
1063 .ctl_name = FS_DENTRY,
1064 .procname = "dentry-state",
1065 .data = &dentry_stat,
1066 .maxlen = 6*sizeof(int),
1067 .mode = 0444,
1068 .proc_handler = &proc_dointvec,
1069 },
1070 {
1071 .ctl_name = FS_OVERFLOWUID,
1072 .procname = "overflowuid",
1073 .data = &fs_overflowuid,
1074 .maxlen = sizeof(int),
1075 .mode = 0644,
1076 .proc_handler = &proc_dointvec_minmax,
1077 .strategy = &sysctl_intvec,
1078 .extra1 = &minolduid,
1079 .extra2 = &maxolduid,
1080 },
1081 {
1082 .ctl_name = FS_OVERFLOWGID,
1083 .procname = "overflowgid",
1084 .data = &fs_overflowgid,
1085 .maxlen = sizeof(int),
1086 .mode = 0644,
1087 .proc_handler = &proc_dointvec_minmax,
1088 .strategy = &sysctl_intvec,
1089 .extra1 = &minolduid,
1090 .extra2 = &maxolduid,
1091 },
1092 {
1093 .ctl_name = FS_LEASES,
1094 .procname = "leases-enable",
1095 .data = &leases_enable,
1096 .maxlen = sizeof(int),
1097 .mode = 0644,
1098 .proc_handler = &proc_dointvec,
1099 },
1100#ifdef CONFIG_DNOTIFY
1101 {
1102 .ctl_name = FS_DIR_NOTIFY,
1103 .procname = "dir-notify-enable",
1104 .data = &dir_notify_enable,
1105 .maxlen = sizeof(int),
1106 .mode = 0644,
1107 .proc_handler = &proc_dointvec,
1108 },
1109#endif
1110#ifdef CONFIG_MMU
1111 {
1112 .ctl_name = FS_LEASE_TIME,
1113 .procname = "lease-break-time",
1114 .data = &lease_break_time,
1115 .maxlen = sizeof(int),
1116 .mode = 0644,
1117 .proc_handler = &proc_dointvec,
1118 },
1119 {
1120 .ctl_name = FS_AIO_NR,
1121 .procname = "aio-nr",
1122 .data = &aio_nr,
1123 .maxlen = sizeof(aio_nr),
1124 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001125 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 },
1127 {
1128 .ctl_name = FS_AIO_MAX_NR,
1129 .procname = "aio-max-nr",
1130 .data = &aio_max_nr,
1131 .maxlen = sizeof(aio_max_nr),
1132 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001133 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001135#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001136 {
1137 .ctl_name = FS_INOTIFY,
1138 .procname = "inotify",
1139 .mode = 0555,
1140 .child = inotify_table,
1141 },
1142#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001144 {
1145 .ctl_name = KERN_SETUID_DUMPABLE,
1146 .procname = "suid_dumpable",
1147 .data = &suid_dumpable,
1148 .maxlen = sizeof(int),
1149 .mode = 0644,
1150 .proc_handler = &proc_dointvec,
1151 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 { .ctl_name = 0 }
1153};
1154
1155static ctl_table debug_table[] = {
1156 { .ctl_name = 0 }
1157};
1158
1159static ctl_table dev_table[] = {
1160 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001161};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163extern void init_irq_proc (void);
1164
Al Viro330d57f2005-11-04 10:18:40 +00001165static DEFINE_SPINLOCK(sysctl_lock);
1166
1167/* called under sysctl_lock */
1168static int use_table(struct ctl_table_header *p)
1169{
1170 if (unlikely(p->unregistering))
1171 return 0;
1172 p->used++;
1173 return 1;
1174}
1175
1176/* called under sysctl_lock */
1177static void unuse_table(struct ctl_table_header *p)
1178{
1179 if (!--p->used)
1180 if (unlikely(p->unregistering))
1181 complete(p->unregistering);
1182}
1183
1184/* called under sysctl_lock, will reacquire if has to wait */
1185static void start_unregistering(struct ctl_table_header *p)
1186{
1187 /*
1188 * if p->used is 0, nobody will ever touch that entry again;
1189 * we'll eliminate all paths to it before dropping sysctl_lock
1190 */
1191 if (unlikely(p->used)) {
1192 struct completion wait;
1193 init_completion(&wait);
1194 p->unregistering = &wait;
1195 spin_unlock(&sysctl_lock);
1196 wait_for_completion(&wait);
1197 spin_lock(&sysctl_lock);
1198 }
1199 /*
1200 * do not remove from the list until nobody holds it; walking the
1201 * list in do_sysctl() relies on that.
1202 */
1203 list_del_init(&p->ctl_entry);
1204}
1205
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206void __init sysctl_init(void)
1207{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001208#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001209 register_proc_table(root_table, proc_sys_root, &root_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 init_irq_proc();
1211#endif
1212}
1213
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001214#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1216 void __user *newval, size_t newlen)
1217{
1218 struct list_head *tmp;
Al Viro330d57f2005-11-04 10:18:40 +00001219 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1222 return -ENOTDIR;
1223 if (oldval) {
1224 int old_len;
1225 if (!oldlenp || get_user(old_len, oldlenp))
1226 return -EFAULT;
1227 }
Al Viro330d57f2005-11-04 10:18:40 +00001228 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 tmp = &root_table_header.ctl_entry;
1230 do {
1231 struct ctl_table_header *head =
1232 list_entry(tmp, struct ctl_table_header, ctl_entry);
1233 void *context = NULL;
Al Viro330d57f2005-11-04 10:18:40 +00001234
1235 if (!use_table(head))
1236 continue;
1237
1238 spin_unlock(&sysctl_lock);
1239
1240 error = parse_table(name, nlen, oldval, oldlenp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 newval, newlen, head->ctl_table,
1242 &context);
Jesper Juhl5a6b4542005-06-25 14:58:48 -07001243 kfree(context);
Al Viro330d57f2005-11-04 10:18:40 +00001244
1245 spin_lock(&sysctl_lock);
1246 unuse_table(head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 if (error != -ENOTDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001248 break;
1249 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1250 spin_unlock(&sysctl_lock);
1251 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
1254asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1255{
1256 struct __sysctl_args tmp;
1257 int error;
1258
1259 if (copy_from_user(&tmp, args, sizeof(tmp)))
1260 return -EFAULT;
1261
1262 lock_kernel();
1263 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1264 tmp.newval, tmp.newlen);
1265 unlock_kernel();
1266 return error;
1267}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001268#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
1270/*
1271 * ctl_perm does NOT grant the superuser all rights automatically, because
1272 * some sysctl variables are readonly even to root.
1273 */
1274
1275static int test_perm(int mode, int op)
1276{
1277 if (!current->euid)
1278 mode >>= 6;
1279 else if (in_egroup_p(0))
1280 mode >>= 3;
1281 if ((mode & op & 0007) == op)
1282 return 0;
1283 return -EACCES;
1284}
1285
1286static inline int ctl_perm(ctl_table *table, int op)
1287{
1288 int error;
1289 error = security_sysctl(table, op);
1290 if (error)
1291 return error;
1292 return test_perm(table->mode, op);
1293}
1294
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001295#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296static int parse_table(int __user *name, int nlen,
1297 void __user *oldval, size_t __user *oldlenp,
1298 void __user *newval, size_t newlen,
1299 ctl_table *table, void **context)
1300{
1301 int n;
1302repeat:
1303 if (!nlen)
1304 return -ENOTDIR;
1305 if (get_user(n, name))
1306 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001307 for ( ; table->ctl_name || table->procname; table++) {
1308 if (!table->ctl_name)
1309 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1311 int error;
1312 if (table->child) {
1313 if (ctl_perm(table, 001))
1314 return -EPERM;
1315 if (table->strategy) {
1316 error = table->strategy(
1317 table, name, nlen,
1318 oldval, oldlenp,
1319 newval, newlen, context);
1320 if (error)
1321 return error;
1322 }
1323 name++;
1324 nlen--;
1325 table = table->child;
1326 goto repeat;
1327 }
1328 error = do_sysctl_strategy(table, name, nlen,
1329 oldval, oldlenp,
1330 newval, newlen, context);
1331 return error;
1332 }
1333 }
1334 return -ENOTDIR;
1335}
1336
1337/* Perform the actual read/write of a sysctl table entry. */
1338int do_sysctl_strategy (ctl_table *table,
1339 int __user *name, int nlen,
1340 void __user *oldval, size_t __user *oldlenp,
1341 void __user *newval, size_t newlen, void **context)
1342{
1343 int op = 0, rc;
1344 size_t len;
1345
1346 if (oldval)
1347 op |= 004;
1348 if (newval)
1349 op |= 002;
1350 if (ctl_perm(table, op))
1351 return -EPERM;
1352
1353 if (table->strategy) {
1354 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1355 newval, newlen, context);
1356 if (rc < 0)
1357 return rc;
1358 if (rc > 0)
1359 return 0;
1360 }
1361
1362 /* If there is no strategy routine, or if the strategy returns
1363 * zero, proceed with automatic r/w */
1364 if (table->data && table->maxlen) {
1365 if (oldval && oldlenp) {
1366 if (get_user(len, oldlenp))
1367 return -EFAULT;
1368 if (len) {
1369 if (len > table->maxlen)
1370 len = table->maxlen;
1371 if(copy_to_user(oldval, table->data, len))
1372 return -EFAULT;
1373 if(put_user(len, oldlenp))
1374 return -EFAULT;
1375 }
1376 }
1377 if (newval && newlen) {
1378 len = newlen;
1379 if (len > table->maxlen)
1380 len = table->maxlen;
1381 if(copy_from_user(table->data, newval, len))
1382 return -EFAULT;
1383 }
1384 }
1385 return 0;
1386}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001387#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389/**
1390 * register_sysctl_table - register a sysctl hierarchy
1391 * @table: the top-level table structure
1392 * @insert_at_head: whether the entry should be inserted in front or at the end
1393 *
1394 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1395 * array. An entry with a ctl_name of 0 terminates the table.
1396 *
1397 * The members of the &ctl_table structure are used as follows:
1398 *
1399 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1400 * must be unique within that level of sysctl
1401 *
1402 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1403 * enter a sysctl file
1404 *
1405 * data - a pointer to data for use by proc_handler
1406 *
1407 * maxlen - the maximum size in bytes of the data
1408 *
1409 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1410 *
1411 * child - a pointer to the child sysctl table if this entry is a directory, or
1412 * %NULL.
1413 *
1414 * proc_handler - the text handler routine (described below)
1415 *
1416 * strategy - the strategy routine (described below)
1417 *
1418 * de - for internal use by the sysctl routines
1419 *
1420 * extra1, extra2 - extra pointers usable by the proc handler routines
1421 *
1422 * Leaf nodes in the sysctl tree will be represented by a single file
1423 * under /proc; non-leaf nodes will be represented by directories.
1424 *
1425 * sysctl(2) can automatically manage read and write requests through
1426 * the sysctl table. The data and maxlen fields of the ctl_table
1427 * struct enable minimal validation of the values being written to be
1428 * performed, and the mode field allows minimal authentication.
1429 *
1430 * More sophisticated management can be enabled by the provision of a
1431 * strategy routine with the table entry. This will be called before
1432 * any automatic read or write of the data is performed.
1433 *
1434 * The strategy routine may return
1435 *
1436 * < 0 - Error occurred (error is passed to user process)
1437 *
1438 * 0 - OK - proceed with automatic read or write.
1439 *
1440 * > 0 - OK - read or write has been done by the strategy routine, so
1441 * return immediately.
1442 *
1443 * There must be a proc_handler routine for any terminal nodes
1444 * mirrored under /proc/sys (non-terminals are handled by a built-in
1445 * directory handler). Several default handlers are available to
1446 * cover common cases -
1447 *
1448 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1449 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1450 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1451 *
1452 * It is the handler's job to read the input buffer from user memory
1453 * and process it. The handler should return 0 on success.
1454 *
1455 * This routine returns %NULL on a failure to register, and a pointer
1456 * to the table header on success.
1457 */
1458struct ctl_table_header *register_sysctl_table(ctl_table * table,
1459 int insert_at_head)
1460{
1461 struct ctl_table_header *tmp;
1462 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1463 if (!tmp)
1464 return NULL;
1465 tmp->ctl_table = table;
1466 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001467 tmp->used = 0;
1468 tmp->unregistering = NULL;
1469 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 if (insert_at_head)
1471 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1472 else
1473 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001474 spin_unlock(&sysctl_lock);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001475#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001476 register_proc_table(table, proc_sys_root, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477#endif
1478 return tmp;
1479}
1480
1481/**
1482 * unregister_sysctl_table - unregister a sysctl table hierarchy
1483 * @header: the header returned from register_sysctl_table
1484 *
1485 * Unregisters the sysctl table and all children. proc entries may not
1486 * actually be removed until they are no longer used by anyone.
1487 */
1488void unregister_sysctl_table(struct ctl_table_header * header)
1489{
Al Viro330d57f2005-11-04 10:18:40 +00001490 might_sleep();
1491 spin_lock(&sysctl_lock);
1492 start_unregistering(header);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001493#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 unregister_proc_table(header->ctl_table, proc_sys_root);
1495#endif
Al Viro330d57f2005-11-04 10:18:40 +00001496 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 kfree(header);
1498}
1499
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001500#else /* !CONFIG_SYSCTL */
1501struct ctl_table_header * register_sysctl_table(ctl_table * table,
1502 int insert_at_head)
1503{
1504 return NULL;
1505}
1506
1507void unregister_sysctl_table(struct ctl_table_header * table)
1508{
1509}
1510
1511#endif /* CONFIG_SYSCTL */
1512
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513/*
1514 * /proc/sys support
1515 */
1516
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001517#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519/* Scan the sysctl entries in table and add them all into /proc */
Al Viro330d57f2005-11-04 10:18:40 +00001520static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
1522 struct proc_dir_entry *de;
1523 int len;
1524 mode_t mode;
1525
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001526 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 /* Can't do anything without a proc name. */
1528 if (!table->procname)
1529 continue;
1530 /* Maybe we can't do anything with it... */
1531 if (!table->proc_handler && !table->child) {
1532 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1533 table->procname);
1534 continue;
1535 }
1536
1537 len = strlen(table->procname);
1538 mode = table->mode;
1539
1540 de = NULL;
1541 if (table->proc_handler)
1542 mode |= S_IFREG;
1543 else {
1544 mode |= S_IFDIR;
1545 for (de = root->subdir; de; de = de->next) {
1546 if (proc_match(len, table->procname, de))
1547 break;
1548 }
1549 /* If the subdir exists already, de is non-NULL */
1550 }
1551
1552 if (!de) {
1553 de = create_proc_entry(table->procname, mode, root);
1554 if (!de)
1555 continue;
Al Viro330d57f2005-11-04 10:18:40 +00001556 de->set = set;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 de->data = (void *) table;
1558 if (table->proc_handler)
1559 de->proc_fops = &proc_sys_file_operations;
1560 }
1561 table->de = de;
1562 if (de->mode & S_IFDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001563 register_proc_table(table->child, de, set);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 }
1565}
1566
1567/*
1568 * Unregister a /proc sysctl table and any subdirectories.
1569 */
1570static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1571{
1572 struct proc_dir_entry *de;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001573 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 if (!(de = table->de))
1575 continue;
1576 if (de->mode & S_IFDIR) {
1577 if (!table->child) {
1578 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1579 continue;
1580 }
1581 unregister_proc_table(table->child, de);
1582
1583 /* Don't unregister directories which still have entries.. */
1584 if (de->subdir)
1585 continue;
1586 }
1587
Al Viro330d57f2005-11-04 10:18:40 +00001588 /*
1589 * In any case, mark the entry as goner; we'll keep it
1590 * around if it's busy, but we'll know to do nothing with
1591 * its fields. We are under sysctl_lock here.
1592 */
1593 de->data = NULL;
1594
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 /* Don't unregister proc entries that are still being used.. */
1596 if (atomic_read(&de->count))
1597 continue;
1598
1599 table->de = NULL;
1600 remove_proc_entry(table->procname, root);
1601 }
1602}
1603
1604static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1605 size_t count, loff_t *ppos)
1606{
1607 int op;
Josef "Jeff" Sipekf3a43f32006-12-08 02:36:43 -08001608 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 struct ctl_table *table;
1610 size_t res;
Al Viro330d57f2005-11-04 10:18:40 +00001611 ssize_t error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Al Viro330d57f2005-11-04 10:18:40 +00001613 spin_lock(&sysctl_lock);
1614 if (de && de->data && use_table(de->set)) {
1615 /*
1616 * at that point we know that sysctl was not unregistered
1617 * and won't be until we finish
1618 */
1619 spin_unlock(&sysctl_lock);
1620 table = (struct ctl_table *) de->data;
1621 if (!table || !table->proc_handler)
1622 goto out;
1623 error = -EPERM;
1624 op = (write ? 002 : 004);
1625 if (ctl_perm(table, op))
1626 goto out;
1627
1628 /* careful: calling conventions are nasty here */
1629 res = count;
1630 error = (*table->proc_handler)(table, write, file,
1631 buf, &res, ppos);
1632 if (!error)
1633 error = res;
1634 out:
1635 spin_lock(&sysctl_lock);
1636 unuse_table(de->set);
1637 }
1638 spin_unlock(&sysctl_lock);
1639 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
1642static int proc_opensys(struct inode *inode, struct file *file)
1643{
1644 if (file->f_mode & FMODE_WRITE) {
1645 /*
1646 * sysctl entries that are not writable,
1647 * are _NOT_ writable, capabilities or not.
1648 */
1649 if (!(inode->i_mode & S_IWUSR))
1650 return -EPERM;
1651 }
1652
1653 return 0;
1654}
1655
1656static ssize_t proc_readsys(struct file * file, char __user * buf,
1657 size_t count, loff_t *ppos)
1658{
1659 return do_rw_proc(0, file, buf, count, ppos);
1660}
1661
1662static ssize_t proc_writesys(struct file * file, const char __user * buf,
1663 size_t count, loff_t *ppos)
1664{
1665 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1666}
1667
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001668static int _proc_do_string(void* data, int maxlen, int write,
1669 struct file *filp, void __user *buffer,
1670 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001671{
1672 size_t len;
1673 char __user *p;
1674 char c;
1675
1676 if (!data || !maxlen || !*lenp ||
1677 (*ppos && !write)) {
1678 *lenp = 0;
1679 return 0;
1680 }
1681
1682 if (write) {
1683 len = 0;
1684 p = buffer;
1685 while (len < *lenp) {
1686 if (get_user(c, p++))
1687 return -EFAULT;
1688 if (c == 0 || c == '\n')
1689 break;
1690 len++;
1691 }
1692 if (len >= maxlen)
1693 len = maxlen-1;
1694 if(copy_from_user(data, buffer, len))
1695 return -EFAULT;
1696 ((char *) data)[len] = 0;
1697 *ppos += *lenp;
1698 } else {
1699 len = strlen(data);
1700 if (len > maxlen)
1701 len = maxlen;
1702 if (len > *lenp)
1703 len = *lenp;
1704 if (len)
1705 if(copy_to_user(buffer, data, len))
1706 return -EFAULT;
1707 if (len < *lenp) {
1708 if(put_user('\n', ((char __user *) buffer) + len))
1709 return -EFAULT;
1710 len++;
1711 }
1712 *lenp = len;
1713 *ppos += len;
1714 }
1715 return 0;
1716}
1717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718/**
1719 * proc_dostring - read a string sysctl
1720 * @table: the sysctl table
1721 * @write: %TRUE if this is a write to the sysctl file
1722 * @filp: the file structure
1723 * @buffer: the user buffer
1724 * @lenp: the size of the user buffer
1725 * @ppos: file position
1726 *
1727 * Reads/writes a string from/to the user buffer. If the kernel
1728 * buffer provided is not large enough to hold the string, the
1729 * string is truncated. The copied string is %NULL-terminated.
1730 * If the string is being read by the user process, it is copied
1731 * and a newline '\n' is added. It is truncated if the buffer is
1732 * not large enough.
1733 *
1734 * Returns 0 on success.
1735 */
1736int proc_dostring(ctl_table *table, int write, struct file *filp,
1737 void __user *buffer, size_t *lenp, loff_t *ppos)
1738{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001739 return _proc_do_string(table->data, table->maxlen, write, filp,
1740 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741}
1742
1743/*
1744 * Special case of dostring for the UTS structure. This has locks
1745 * to observe. Should this be in kernel/sys.c ????
1746 */
Eric W. Biedermancf9f1512006-12-08 02:39:55 -08001747
Serge E. Hallyn8218c742006-10-02 02:18:15 -07001748static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 void __user *buffer, size_t *lenp, loff_t *ppos)
1750{
1751 int r;
Eric W. Biedermancf9f1512006-12-08 02:39:55 -08001752 void *which;
1753 which = get_uts(table, write);
1754 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1755 put_uts(table, write, which);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 return r;
1757}
1758
1759static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1760 int *valp,
1761 int write, void *data)
1762{
1763 if (write) {
1764 *valp = *negp ? -*lvalp : *lvalp;
1765 } else {
1766 int val = *valp;
1767 if (val < 0) {
1768 *negp = -1;
1769 *lvalp = (unsigned long)-val;
1770 } else {
1771 *negp = 0;
1772 *lvalp = (unsigned long)val;
1773 }
1774 }
1775 return 0;
1776}
1777
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001778static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1779 int write, struct file *filp, void __user *buffer,
1780 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1782 int write, void *data),
1783 void *data)
1784{
1785#define TMPBUFLEN 21
1786 int *i, vleft, first=1, neg, val;
1787 unsigned long lval;
1788 size_t left, len;
1789
1790 char buf[TMPBUFLEN], *p;
1791 char __user *s = buffer;
1792
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001793 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 (*ppos && !write)) {
1795 *lenp = 0;
1796 return 0;
1797 }
1798
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001799 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 vleft = table->maxlen / sizeof(*i);
1801 left = *lenp;
1802
1803 if (!conv)
1804 conv = do_proc_dointvec_conv;
1805
1806 for (; left && vleft--; i++, first=0) {
1807 if (write) {
1808 while (left) {
1809 char c;
1810 if (get_user(c, s))
1811 return -EFAULT;
1812 if (!isspace(c))
1813 break;
1814 left--;
1815 s++;
1816 }
1817 if (!left)
1818 break;
1819 neg = 0;
1820 len = left;
1821 if (len > sizeof(buf) - 1)
1822 len = sizeof(buf) - 1;
1823 if (copy_from_user(buf, s, len))
1824 return -EFAULT;
1825 buf[len] = 0;
1826 p = buf;
1827 if (*p == '-' && left > 1) {
1828 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001829 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 }
1831 if (*p < '0' || *p > '9')
1832 break;
1833
1834 lval = simple_strtoul(p, &p, 0);
1835
1836 len = p-buf;
1837 if ((len < left) && *p && !isspace(*p))
1838 break;
1839 if (neg)
1840 val = -val;
1841 s += len;
1842 left -= len;
1843
1844 if (conv(&neg, &lval, i, 1, data))
1845 break;
1846 } else {
1847 p = buf;
1848 if (!first)
1849 *p++ = '\t';
1850
1851 if (conv(&neg, &lval, i, 0, data))
1852 break;
1853
1854 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1855 len = strlen(buf);
1856 if (len > left)
1857 len = left;
1858 if(copy_to_user(s, buf, len))
1859 return -EFAULT;
1860 left -= len;
1861 s += len;
1862 }
1863 }
1864
1865 if (!write && !first && left) {
1866 if(put_user('\n', s))
1867 return -EFAULT;
1868 left--, s++;
1869 }
1870 if (write) {
1871 while (left) {
1872 char c;
1873 if (get_user(c, s++))
1874 return -EFAULT;
1875 if (!isspace(c))
1876 break;
1877 left--;
1878 }
1879 }
1880 if (write && first)
1881 return -EINVAL;
1882 *lenp -= left;
1883 *ppos += *lenp;
1884 return 0;
1885#undef TMPBUFLEN
1886}
1887
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001888static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1889 void __user *buffer, size_t *lenp, loff_t *ppos,
1890 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1891 int write, void *data),
1892 void *data)
1893{
1894 return __do_proc_dointvec(table->data, table, write, filp,
1895 buffer, lenp, ppos, conv, data);
1896}
1897
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898/**
1899 * proc_dointvec - read a vector of integers
1900 * @table: the sysctl table
1901 * @write: %TRUE if this is a write to the sysctl file
1902 * @filp: the file structure
1903 * @buffer: the user buffer
1904 * @lenp: the size of the user buffer
1905 * @ppos: file position
1906 *
1907 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1908 * values from/to the user buffer, treated as an ASCII string.
1909 *
1910 * Returns 0 on success.
1911 */
1912int proc_dointvec(ctl_table *table, int write, struct file *filp,
1913 void __user *buffer, size_t *lenp, loff_t *ppos)
1914{
1915 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1916 NULL,NULL);
1917}
1918
1919#define OP_SET 0
1920#define OP_AND 1
1921#define OP_OR 2
1922#define OP_MAX 3
1923#define OP_MIN 4
1924
1925static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1926 int *valp,
1927 int write, void *data)
1928{
1929 int op = *(int *)data;
1930 if (write) {
1931 int val = *negp ? -*lvalp : *lvalp;
1932 switch(op) {
1933 case OP_SET: *valp = val; break;
1934 case OP_AND: *valp &= val; break;
1935 case OP_OR: *valp |= val; break;
1936 case OP_MAX: if(*valp < val)
1937 *valp = val;
1938 break;
1939 case OP_MIN: if(*valp > val)
1940 *valp = val;
1941 break;
1942 }
1943 } else {
1944 int val = *valp;
1945 if (val < 0) {
1946 *negp = -1;
1947 *lvalp = (unsigned long)-val;
1948 } else {
1949 *negp = 0;
1950 *lvalp = (unsigned long)val;
1951 }
1952 }
1953 return 0;
1954}
1955
1956/*
1957 * init may raise the set.
1958 */
1959
1960int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1961 void __user *buffer, size_t *lenp, loff_t *ppos)
1962{
1963 int op;
1964
1965 if (!capable(CAP_SYS_MODULE)) {
1966 return -EPERM;
1967 }
1968
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001969 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1971 do_proc_dointvec_bset_conv,&op);
1972}
1973
1974struct do_proc_dointvec_minmax_conv_param {
1975 int *min;
1976 int *max;
1977};
1978
1979static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1980 int *valp,
1981 int write, void *data)
1982{
1983 struct do_proc_dointvec_minmax_conv_param *param = data;
1984 if (write) {
1985 int val = *negp ? -*lvalp : *lvalp;
1986 if ((param->min && *param->min > val) ||
1987 (param->max && *param->max < val))
1988 return -EINVAL;
1989 *valp = val;
1990 } else {
1991 int val = *valp;
1992 if (val < 0) {
1993 *negp = -1;
1994 *lvalp = (unsigned long)-val;
1995 } else {
1996 *negp = 0;
1997 *lvalp = (unsigned long)val;
1998 }
1999 }
2000 return 0;
2001}
2002
2003/**
2004 * proc_dointvec_minmax - read a vector of integers with min/max values
2005 * @table: the sysctl table
2006 * @write: %TRUE if this is a write to the sysctl file
2007 * @filp: the file structure
2008 * @buffer: the user buffer
2009 * @lenp: the size of the user buffer
2010 * @ppos: file position
2011 *
2012 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2013 * values from/to the user buffer, treated as an ASCII string.
2014 *
2015 * This routine will ensure the values are within the range specified by
2016 * table->extra1 (min) and table->extra2 (max).
2017 *
2018 * Returns 0 on success.
2019 */
2020int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2021 void __user *buffer, size_t *lenp, loff_t *ppos)
2022{
2023 struct do_proc_dointvec_minmax_conv_param param = {
2024 .min = (int *) table->extra1,
2025 .max = (int *) table->extra2,
2026 };
2027 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2028 do_proc_dointvec_minmax_conv, &param);
2029}
2030
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002031static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 struct file *filp,
2033 void __user *buffer,
2034 size_t *lenp, loff_t *ppos,
2035 unsigned long convmul,
2036 unsigned long convdiv)
2037{
2038#define TMPBUFLEN 21
2039 unsigned long *i, *min, *max, val;
2040 int vleft, first=1, neg;
2041 size_t len, left;
2042 char buf[TMPBUFLEN], *p;
2043 char __user *s = buffer;
2044
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002045 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 (*ppos && !write)) {
2047 *lenp = 0;
2048 return 0;
2049 }
2050
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002051 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 min = (unsigned long *) table->extra1;
2053 max = (unsigned long *) table->extra2;
2054 vleft = table->maxlen / sizeof(unsigned long);
2055 left = *lenp;
2056
2057 for (; left && vleft--; i++, min++, max++, first=0) {
2058 if (write) {
2059 while (left) {
2060 char c;
2061 if (get_user(c, s))
2062 return -EFAULT;
2063 if (!isspace(c))
2064 break;
2065 left--;
2066 s++;
2067 }
2068 if (!left)
2069 break;
2070 neg = 0;
2071 len = left;
2072 if (len > TMPBUFLEN-1)
2073 len = TMPBUFLEN-1;
2074 if (copy_from_user(buf, s, len))
2075 return -EFAULT;
2076 buf[len] = 0;
2077 p = buf;
2078 if (*p == '-' && left > 1) {
2079 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002080 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 }
2082 if (*p < '0' || *p > '9')
2083 break;
2084 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2085 len = p-buf;
2086 if ((len < left) && *p && !isspace(*p))
2087 break;
2088 if (neg)
2089 val = -val;
2090 s += len;
2091 left -= len;
2092
2093 if(neg)
2094 continue;
2095 if ((min && val < *min) || (max && val > *max))
2096 continue;
2097 *i = val;
2098 } else {
2099 p = buf;
2100 if (!first)
2101 *p++ = '\t';
2102 sprintf(p, "%lu", convdiv * (*i) / convmul);
2103 len = strlen(buf);
2104 if (len > left)
2105 len = left;
2106 if(copy_to_user(s, buf, len))
2107 return -EFAULT;
2108 left -= len;
2109 s += len;
2110 }
2111 }
2112
2113 if (!write && !first && left) {
2114 if(put_user('\n', s))
2115 return -EFAULT;
2116 left--, s++;
2117 }
2118 if (write) {
2119 while (left) {
2120 char c;
2121 if (get_user(c, s++))
2122 return -EFAULT;
2123 if (!isspace(c))
2124 break;
2125 left--;
2126 }
2127 }
2128 if (write && first)
2129 return -EINVAL;
2130 *lenp -= left;
2131 *ppos += *lenp;
2132 return 0;
2133#undef TMPBUFLEN
2134}
2135
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002136static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2137 struct file *filp,
2138 void __user *buffer,
2139 size_t *lenp, loff_t *ppos,
2140 unsigned long convmul,
2141 unsigned long convdiv)
2142{
2143 return __do_proc_doulongvec_minmax(table->data, table, write,
2144 filp, buffer, lenp, ppos, convmul, convdiv);
2145}
2146
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147/**
2148 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2149 * @table: the sysctl table
2150 * @write: %TRUE if this is a write to the sysctl file
2151 * @filp: the file structure
2152 * @buffer: the user buffer
2153 * @lenp: the size of the user buffer
2154 * @ppos: file position
2155 *
2156 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2157 * values from/to the user buffer, treated as an ASCII string.
2158 *
2159 * This routine will ensure the values are within the range specified by
2160 * table->extra1 (min) and table->extra2 (max).
2161 *
2162 * Returns 0 on success.
2163 */
2164int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2165 void __user *buffer, size_t *lenp, loff_t *ppos)
2166{
2167 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2168}
2169
2170/**
2171 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2172 * @table: the sysctl table
2173 * @write: %TRUE if this is a write to the sysctl file
2174 * @filp: the file structure
2175 * @buffer: the user buffer
2176 * @lenp: the size of the user buffer
2177 * @ppos: file position
2178 *
2179 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2180 * values from/to the user buffer, treated as an ASCII string. The values
2181 * are treated as milliseconds, and converted to jiffies when they are stored.
2182 *
2183 * This routine will ensure the values are within the range specified by
2184 * table->extra1 (min) and table->extra2 (max).
2185 *
2186 * Returns 0 on success.
2187 */
2188int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2189 struct file *filp,
2190 void __user *buffer,
2191 size_t *lenp, loff_t *ppos)
2192{
2193 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2194 lenp, ppos, HZ, 1000l);
2195}
2196
2197
2198static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2199 int *valp,
2200 int write, void *data)
2201{
2202 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002203 if (*lvalp > LONG_MAX / HZ)
2204 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2206 } else {
2207 int val = *valp;
2208 unsigned long lval;
2209 if (val < 0) {
2210 *negp = -1;
2211 lval = (unsigned long)-val;
2212 } else {
2213 *negp = 0;
2214 lval = (unsigned long)val;
2215 }
2216 *lvalp = lval / HZ;
2217 }
2218 return 0;
2219}
2220
2221static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2222 int *valp,
2223 int write, void *data)
2224{
2225 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002226 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2227 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2229 } else {
2230 int val = *valp;
2231 unsigned long lval;
2232 if (val < 0) {
2233 *negp = -1;
2234 lval = (unsigned long)-val;
2235 } else {
2236 *negp = 0;
2237 lval = (unsigned long)val;
2238 }
2239 *lvalp = jiffies_to_clock_t(lval);
2240 }
2241 return 0;
2242}
2243
2244static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2245 int *valp,
2246 int write, void *data)
2247{
2248 if (write) {
2249 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2250 } else {
2251 int val = *valp;
2252 unsigned long lval;
2253 if (val < 0) {
2254 *negp = -1;
2255 lval = (unsigned long)-val;
2256 } else {
2257 *negp = 0;
2258 lval = (unsigned long)val;
2259 }
2260 *lvalp = jiffies_to_msecs(lval);
2261 }
2262 return 0;
2263}
2264
2265/**
2266 * proc_dointvec_jiffies - read a vector of integers as seconds
2267 * @table: the sysctl table
2268 * @write: %TRUE if this is a write to the sysctl file
2269 * @filp: the file structure
2270 * @buffer: the user buffer
2271 * @lenp: the size of the user buffer
2272 * @ppos: file position
2273 *
2274 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2275 * values from/to the user buffer, treated as an ASCII string.
2276 * The values read are assumed to be in seconds, and are converted into
2277 * jiffies.
2278 *
2279 * Returns 0 on success.
2280 */
2281int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2283{
2284 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2285 do_proc_dointvec_jiffies_conv,NULL);
2286}
2287
2288/**
2289 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2290 * @table: the sysctl table
2291 * @write: %TRUE if this is a write to the sysctl file
2292 * @filp: the file structure
2293 * @buffer: the user buffer
2294 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002295 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 *
2297 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2298 * values from/to the user buffer, treated as an ASCII string.
2299 * The values read are assumed to be in 1/USER_HZ seconds, and
2300 * are converted into jiffies.
2301 *
2302 * Returns 0 on success.
2303 */
2304int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2306{
2307 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2308 do_proc_dointvec_userhz_jiffies_conv,NULL);
2309}
2310
2311/**
2312 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2313 * @table: the sysctl table
2314 * @write: %TRUE if this is a write to the sysctl file
2315 * @filp: the file structure
2316 * @buffer: the user buffer
2317 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002318 * @ppos: file position
2319 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 *
2321 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2322 * values from/to the user buffer, treated as an ASCII string.
2323 * The values read are assumed to be in 1/1000 seconds, and
2324 * are converted into jiffies.
2325 *
2326 * Returns 0 on success.
2327 */
2328int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2329 void __user *buffer, size_t *lenp, loff_t *ppos)
2330{
2331 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2332 do_proc_dointvec_ms_jiffies_conv, NULL);
2333}
2334
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002335#ifdef CONFIG_SYSVIPC
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002336static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2337 void __user *buffer, size_t *lenp, loff_t *ppos)
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002338{
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002339 void *which;
2340 which = get_ipc(table, write);
2341 return __do_proc_dointvec(which, table, write, filp, buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002342 lenp, ppos, NULL, NULL);
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002343}
2344
2345static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2346 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2347{
2348 void *which;
2349 which = get_ipc(table, write);
2350 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002351 lenp, ppos, 1l, 1l);
2352}
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002353
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002354#endif
2355
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002356static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2357 void __user *buffer, size_t *lenp, loff_t *ppos)
2358{
2359 struct pid *new_pid;
2360 pid_t tmp;
2361 int r;
2362
2363 tmp = pid_nr(cad_pid);
2364
2365 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2366 lenp, ppos, NULL, NULL);
2367 if (r || !write)
2368 return r;
2369
2370 new_pid = find_get_pid(tmp);
2371 if (!new_pid)
2372 return -ESRCH;
2373
2374 put_pid(xchg(&cad_pid, new_pid));
2375 return 0;
2376}
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378#else /* CONFIG_PROC_FS */
2379
2380int proc_dostring(ctl_table *table, int write, struct file *filp,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2382{
2383 return -ENOSYS;
2384}
2385
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002386static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388{
2389 return -ENOSYS;
2390}
2391
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002392#ifdef CONFIG_SYSVIPC
2393static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2394 void __user *buffer, size_t *lenp, loff_t *ppos)
2395{
2396 return -ENOSYS;
2397}
2398#endif
2399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400int proc_dointvec(ctl_table *table, int write, struct file *filp,
2401 void __user *buffer, size_t *lenp, loff_t *ppos)
2402{
2403 return -ENOSYS;
2404}
2405
2406int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2407 void __user *buffer, size_t *lenp, loff_t *ppos)
2408{
2409 return -ENOSYS;
2410}
2411
2412int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2413 void __user *buffer, size_t *lenp, loff_t *ppos)
2414{
2415 return -ENOSYS;
2416}
2417
2418int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2419 void __user *buffer, size_t *lenp, loff_t *ppos)
2420{
2421 return -ENOSYS;
2422}
2423
2424int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2426{
2427 return -ENOSYS;
2428}
2429
2430int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2431 void __user *buffer, size_t *lenp, loff_t *ppos)
2432{
2433 return -ENOSYS;
2434}
2435
2436int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2437 void __user *buffer, size_t *lenp, loff_t *ppos)
2438{
2439 return -ENOSYS;
2440}
2441
2442int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2443 struct file *filp,
2444 void __user *buffer,
2445 size_t *lenp, loff_t *ppos)
2446{
2447 return -ENOSYS;
2448}
2449
2450
2451#endif /* CONFIG_PROC_FS */
2452
2453
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002454#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455/*
2456 * General sysctl support routines
2457 */
2458
2459/* The generic string strategy routine: */
2460int sysctl_string(ctl_table *table, int __user *name, int nlen,
2461 void __user *oldval, size_t __user *oldlenp,
2462 void __user *newval, size_t newlen, void **context)
2463{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 if (!table->data || !table->maxlen)
2465 return -ENOTDIR;
2466
2467 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002468 size_t bufsize;
2469 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002471 if (bufsize) {
2472 size_t len = strlen(table->data), copied;
2473
2474 /* This shouldn't trigger for a well-formed sysctl */
2475 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002477
2478 /* Copy up to a max of bufsize-1 bytes of the string */
2479 copied = (len >= bufsize) ? bufsize - 1 : len;
2480
2481 if (copy_to_user(oldval, table->data, copied) ||
2482 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002484 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 return -EFAULT;
2486 }
2487 }
2488 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002489 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 if (len > table->maxlen)
2491 len = table->maxlen;
2492 if(copy_from_user(table->data, newval, len))
2493 return -EFAULT;
2494 if (len == table->maxlen)
2495 len--;
2496 ((char *) table->data)[len] = 0;
2497 }
Yi Yang82c9df82005-12-30 16:37:10 +08002498 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499}
2500
2501/*
2502 * This function makes sure that all of the integers in the vector
2503 * are between the minimum and maximum values given in the arrays
2504 * table->extra1 and table->extra2, respectively.
2505 */
2506int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2507 void __user *oldval, size_t __user *oldlenp,
2508 void __user *newval, size_t newlen, void **context)
2509{
2510
2511 if (newval && newlen) {
2512 int __user *vec = (int __user *) newval;
2513 int *min = (int *) table->extra1;
2514 int *max = (int *) table->extra2;
2515 size_t length;
2516 int i;
2517
2518 if (newlen % sizeof(int) != 0)
2519 return -EINVAL;
2520
2521 if (!table->extra1 && !table->extra2)
2522 return 0;
2523
2524 if (newlen > table->maxlen)
2525 newlen = table->maxlen;
2526 length = newlen / sizeof(int);
2527
2528 for (i = 0; i < length; i++) {
2529 int value;
2530 if (get_user(value, vec + i))
2531 return -EFAULT;
2532 if (min && value < min[i])
2533 return -EINVAL;
2534 if (max && value > max[i])
2535 return -EINVAL;
2536 }
2537 }
2538 return 0;
2539}
2540
2541/* Strategy function to convert jiffies to seconds */
2542int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2543 void __user *oldval, size_t __user *oldlenp,
2544 void __user *newval, size_t newlen, void **context)
2545{
2546 if (oldval) {
2547 size_t olen;
2548 if (oldlenp) {
2549 if (get_user(olen, oldlenp))
2550 return -EFAULT;
2551 if (olen!=sizeof(int))
2552 return -EINVAL;
2553 }
2554 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2555 (oldlenp && put_user(sizeof(int),oldlenp)))
2556 return -EFAULT;
2557 }
2558 if (newval && newlen) {
2559 int new;
2560 if (newlen != sizeof(int))
2561 return -EINVAL;
2562 if (get_user(new, (int __user *)newval))
2563 return -EFAULT;
2564 *(int *)(table->data) = new*HZ;
2565 }
2566 return 1;
2567}
2568
2569/* Strategy function to convert jiffies to seconds */
2570int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2571 void __user *oldval, size_t __user *oldlenp,
2572 void __user *newval, size_t newlen, void **context)
2573{
2574 if (oldval) {
2575 size_t olen;
2576 if (oldlenp) {
2577 if (get_user(olen, oldlenp))
2578 return -EFAULT;
2579 if (olen!=sizeof(int))
2580 return -EINVAL;
2581 }
2582 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2583 (oldlenp && put_user(sizeof(int),oldlenp)))
2584 return -EFAULT;
2585 }
2586 if (newval && newlen) {
2587 int new;
2588 if (newlen != sizeof(int))
2589 return -EINVAL;
2590 if (get_user(new, (int __user *)newval))
2591 return -EFAULT;
2592 *(int *)(table->data) = msecs_to_jiffies(new);
2593 }
2594 return 1;
2595}
2596
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002597
2598/* The generic string strategy routine: */
2599static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2600 void __user *oldval, size_t __user *oldlenp,
2601 void __user *newval, size_t newlen, void **context)
2602{
2603 struct ctl_table uts_table;
2604 int r, write;
2605 write = newval && newlen;
2606 memcpy(&uts_table, table, sizeof(uts_table));
2607 uts_table.data = get_uts(table, write);
2608 r = sysctl_string(&uts_table, name, nlen,
2609 oldval, oldlenp, newval, newlen, context);
2610 put_uts(table, write, uts_table.data);
2611 return r;
2612}
2613
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002614#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615
2616
2617asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2618{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002619 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002620 struct __sysctl_args tmp;
2621 int name[CTL_MAXNAME];
2622 int i;
2623
2624 /* Read in the sysctl name for better debug message logging */
2625 if (copy_from_user(&tmp, args, sizeof(tmp)))
2626 return -EFAULT;
2627 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2628 return -ENOTDIR;
2629 for (i = 0; i < tmp.nlen; i++)
2630 if (get_user(name[i], tmp.name + i))
2631 return -EFAULT;
2632
2633 /* Ignore accesses to kernel.version */
2634 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2635 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002636
2637 if (msg_count < 5) {
2638 msg_count++;
2639 printk(KERN_INFO
2640 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002641 "system call with ", current->comm);
2642 for (i = 0; i < tmp.nlen; i++)
2643 printk("%d.", name[i]);
2644 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002645 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002646out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 return -ENOSYS;
2648}
2649
2650int sysctl_string(ctl_table *table, int __user *name, int nlen,
2651 void __user *oldval, size_t __user *oldlenp,
2652 void __user *newval, size_t newlen, void **context)
2653{
2654 return -ENOSYS;
2655}
2656
2657int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2658 void __user *oldval, size_t __user *oldlenp,
2659 void __user *newval, size_t newlen, void **context)
2660{
2661 return -ENOSYS;
2662}
2663
2664int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2665 void __user *oldval, size_t __user *oldlenp,
2666 void __user *newval, size_t newlen, void **context)
2667{
2668 return -ENOSYS;
2669}
2670
2671int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2672 void __user *oldval, size_t __user *oldlenp,
2673 void __user *newval, size_t newlen, void **context)
2674{
2675 return -ENOSYS;
2676}
2677
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002678static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2679 void __user *oldval, size_t __user *oldlenp,
2680 void __user *newval, size_t newlen, void **context)
2681{
2682 return -ENOSYS;
2683}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002684#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685
2686/*
2687 * No sense putting this after each symbol definition, twice,
2688 * exception granted :-)
2689 */
2690EXPORT_SYMBOL(proc_dointvec);
2691EXPORT_SYMBOL(proc_dointvec_jiffies);
2692EXPORT_SYMBOL(proc_dointvec_minmax);
2693EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2694EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2695EXPORT_SYMBOL(proc_dostring);
2696EXPORT_SYMBOL(proc_doulongvec_minmax);
2697EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2698EXPORT_SYMBOL(register_sysctl_table);
2699EXPORT_SYMBOL(sysctl_intvec);
2700EXPORT_SYMBOL(sysctl_jiffies);
2701EXPORT_SYMBOL(sysctl_ms_jiffies);
2702EXPORT_SYMBOL(sysctl_string);
2703EXPORT_SYMBOL(unregister_sysctl_table);