blob: 130c5ec9ee0b3f699c3da72617db844154ce5910 [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 *,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800136 void __user *, size_t, ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700137#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,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800144 void __user *newval, size_t newlen);
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800145
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800146#ifdef CONFIG_SYSVIPC
147static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
148 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800149 void __user *newval, size_t newlen);
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800150#endif
151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700153static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700155#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157static ctl_table root_table[];
158static struct ctl_table_header root_table_header =
159 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
160
161static ctl_table kern_table[];
162static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163static ctl_table fs_table[];
164static ctl_table debug_table[];
165static ctl_table dev_table[];
166extern ctl_table random_table[];
167#ifdef CONFIG_UNIX98_PTYS
168extern ctl_table pty_table[];
169#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700170#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400171extern ctl_table inotify_table[];
172#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
175int sysctl_legacy_va_layout;
176#endif
177
Eric W. Biedermancf9f1512006-12-08 02:39:55 -0800178static void *get_uts(ctl_table *table, int write)
179{
180 char *which = table->data;
181#ifdef CONFIG_UTS_NS
182 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
183 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
184#endif
185 if (!write)
186 down_read(&uts_sem);
187 else
188 down_write(&uts_sem);
189 return which;
190}
191
192static void put_uts(ctl_table *table, int write, void *which)
193{
194 if (!write)
195 up_read(&uts_sem);
196 else
197 up_write(&uts_sem);
198}
199
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800200#ifdef CONFIG_SYSVIPC
201static void *get_ipc(ctl_table *table, int write)
202{
203 char *which = table->data;
204 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
205 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
206 return which;
207}
208#else
209#define get_ipc(T,W) ((T)->data)
210#endif
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212/* /proc declarations: */
213
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700214#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
217static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
218static int proc_opensys(struct inode *, struct file *);
219
Helge Deller15ad7cd2006-12-06 20:40:36 -0800220const struct file_operations proc_sys_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 .open = proc_opensys,
222 .read = proc_readsys,
223 .write = proc_writesys,
224};
225
226extern struct proc_dir_entry *proc_sys_root;
227
Al Viro330d57f2005-11-04 10:18:40 +0000228static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
230#endif
231
232/* The default sysctl tables: */
233
234static ctl_table root_table[] = {
235 {
236 .ctl_name = CTL_KERN,
237 .procname = "kernel",
238 .mode = 0555,
239 .child = kern_table,
240 },
241 {
242 .ctl_name = CTL_VM,
243 .procname = "vm",
244 .mode = 0555,
245 .child = vm_table,
246 },
247#ifdef CONFIG_NET
248 {
249 .ctl_name = CTL_NET,
250 .procname = "net",
251 .mode = 0555,
252 .child = net_table,
253 },
254#endif
255 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .ctl_name = CTL_FS,
257 .procname = "fs",
258 .mode = 0555,
259 .child = fs_table,
260 },
261 {
262 .ctl_name = CTL_DEBUG,
263 .procname = "debug",
264 .mode = 0555,
265 .child = debug_table,
266 },
267 {
268 .ctl_name = CTL_DEV,
269 .procname = "dev",
270 .mode = 0555,
271 .child = dev_table,
272 },
Robert Love0eeca282005-07-12 17:06:03 -0400273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 { .ctl_name = 0 }
275};
276
277static ctl_table kern_table[] = {
278 {
279 .ctl_name = KERN_OSTYPE,
280 .procname = "ostype",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700281 .data = init_uts_ns.name.sysname,
282 .maxlen = sizeof(init_uts_ns.name.sysname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700284 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800285 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 },
287 {
288 .ctl_name = KERN_OSRELEASE,
289 .procname = "osrelease",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700290 .data = init_uts_ns.name.release,
291 .maxlen = sizeof(init_uts_ns.name.release),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700293 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800294 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 },
296 {
297 .ctl_name = KERN_VERSION,
298 .procname = "version",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700299 .data = init_uts_ns.name.version,
300 .maxlen = sizeof(init_uts_ns.name.version),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700302 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800303 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 },
305 {
306 .ctl_name = KERN_NODENAME,
307 .procname = "hostname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700308 .data = init_uts_ns.name.nodename,
309 .maxlen = sizeof(init_uts_ns.name.nodename),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700311 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800312 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 },
314 {
315 .ctl_name = KERN_DOMAINNAME,
316 .procname = "domainname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700317 .data = init_uts_ns.name.domainname,
318 .maxlen = sizeof(init_uts_ns.name.domainname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700320 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800321 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 },
323 {
324 .ctl_name = KERN_PANIC,
325 .procname = "panic",
326 .data = &panic_timeout,
327 .maxlen = sizeof(int),
328 .mode = 0644,
329 .proc_handler = &proc_dointvec,
330 },
331 {
332 .ctl_name = KERN_CORE_USES_PID,
333 .procname = "core_uses_pid",
334 .data = &core_uses_pid,
335 .maxlen = sizeof(int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
338 },
339 {
340 .ctl_name = KERN_CORE_PATTERN,
341 .procname = "core_pattern",
342 .data = core_pattern,
Andi Kleend025c9d2006-09-30 23:29:28 -0700343 .maxlen = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 .mode = 0644,
345 .proc_handler = &proc_dostring,
346 .strategy = &sysctl_string,
347 },
348 {
349 .ctl_name = KERN_TAINTED,
350 .procname = "tainted",
351 .data = &tainted,
352 .maxlen = sizeof(int),
353 .mode = 0444,
354 .proc_handler = &proc_dointvec,
355 },
356 {
357 .ctl_name = KERN_CAP_BSET,
358 .procname = "cap-bound",
359 .data = &cap_bset,
360 .maxlen = sizeof(kernel_cap_t),
361 .mode = 0600,
362 .proc_handler = &proc_dointvec_bset,
363 },
364#ifdef CONFIG_BLK_DEV_INITRD
365 {
366 .ctl_name = KERN_REALROOTDEV,
367 .procname = "real-root-dev",
368 .data = &real_root_dev,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &proc_dointvec,
372 },
373#endif
374#ifdef __sparc__
375 {
376 .ctl_name = KERN_SPARC_REBOOT,
377 .procname = "reboot-cmd",
378 .data = reboot_command,
379 .maxlen = 256,
380 .mode = 0644,
381 .proc_handler = &proc_dostring,
382 .strategy = &sysctl_string,
383 },
384 {
385 .ctl_name = KERN_SPARC_STOP_A,
386 .procname = "stop-a",
387 .data = &stop_a_enabled,
388 .maxlen = sizeof (int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
391 },
392 {
393 .ctl_name = KERN_SPARC_SCONS_PWROFF,
394 .procname = "scons-poweroff",
395 .data = &scons_pwroff,
396 .maxlen = sizeof (int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
399 },
400#endif
401#ifdef __hppa__
402 {
403 .ctl_name = KERN_HPPA_PWRSW,
404 .procname = "soft-power",
405 .data = &pwrsw_enabled,
406 .maxlen = sizeof (int),
407 .mode = 0644,
408 .proc_handler = &proc_dointvec,
409 },
410 {
411 .ctl_name = KERN_HPPA_UNALIGNED,
412 .procname = "unaligned-trap",
413 .data = &unaligned_enabled,
414 .maxlen = sizeof (int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
417 },
418#endif
419 {
420 .ctl_name = KERN_CTLALTDEL,
421 .procname = "ctrl-alt-del",
422 .data = &C_A_D,
423 .maxlen = sizeof(int),
424 .mode = 0644,
425 .proc_handler = &proc_dointvec,
426 },
427 {
428 .ctl_name = KERN_PRINTK,
429 .procname = "printk",
430 .data = &console_loglevel,
431 .maxlen = 4*sizeof(int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
434 },
435#ifdef CONFIG_KMOD
436 {
437 .ctl_name = KERN_MODPROBE,
438 .procname = "modprobe",
439 .data = &modprobe_path,
440 .maxlen = KMOD_PATH_LEN,
441 .mode = 0644,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
444 },
445#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700446#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 {
448 .ctl_name = KERN_HOTPLUG,
449 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100450 .data = &uevent_helper,
451 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 .mode = 0644,
453 .proc_handler = &proc_dostring,
454 .strategy = &sysctl_string,
455 },
456#endif
457#ifdef CONFIG_CHR_DEV_SG
458 {
459 .ctl_name = KERN_SG_BIG_BUFF,
460 .procname = "sg-big-buff",
461 .data = &sg_big_buff,
462 .maxlen = sizeof (int),
463 .mode = 0444,
464 .proc_handler = &proc_dointvec,
465 },
466#endif
467#ifdef CONFIG_BSD_PROCESS_ACCT
468 {
469 .ctl_name = KERN_ACCT,
470 .procname = "acct",
471 .data = &acct_parm,
472 .maxlen = 3*sizeof(int),
473 .mode = 0644,
474 .proc_handler = &proc_dointvec,
475 },
476#endif
477#ifdef CONFIG_SYSVIPC
478 {
479 .ctl_name = KERN_SHMMAX,
480 .procname = "shmmax",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800481 .data = &init_ipc_ns.shm_ctlmax,
482 .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800484 .proc_handler = &proc_ipc_doulongvec_minmax,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800485 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 },
487 {
488 .ctl_name = KERN_SHMALL,
489 .procname = "shmall",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800490 .data = &init_ipc_ns.shm_ctlall,
491 .maxlen = sizeof (init_ipc_ns.shm_ctlall),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800493 .proc_handler = &proc_ipc_doulongvec_minmax,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800494 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 },
496 {
497 .ctl_name = KERN_SHMMNI,
498 .procname = "shmmni",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800499 .data = &init_ipc_ns.shm_ctlmni,
500 .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800502 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800503 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 },
505 {
506 .ctl_name = KERN_MSGMAX,
507 .procname = "msgmax",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800508 .data = &init_ipc_ns.msg_ctlmax,
509 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800511 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800512 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 },
514 {
515 .ctl_name = KERN_MSGMNI,
516 .procname = "msgmni",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800517 .data = &init_ipc_ns.msg_ctlmni,
518 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800520 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800521 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 },
523 {
524 .ctl_name = KERN_MSGMNB,
525 .procname = "msgmnb",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800526 .data = &init_ipc_ns.msg_ctlmnb,
527 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800529 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800530 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 },
532 {
533 .ctl_name = KERN_SEM,
534 .procname = "sem",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800535 .data = &init_ipc_ns.sem_ctls,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 .maxlen = 4*sizeof (int),
537 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800538 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800539 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 },
541#endif
542#ifdef CONFIG_MAGIC_SYSRQ
543 {
544 .ctl_name = KERN_SYSRQ,
545 .procname = "sysrq",
546 .data = &sysrq_enabled,
547 .maxlen = sizeof (int),
548 .mode = 0644,
549 .proc_handler = &proc_dointvec,
550 },
551#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700552#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 {
554 .ctl_name = KERN_CADPID,
555 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700556 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .maxlen = sizeof (int),
558 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700559 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700561#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 {
563 .ctl_name = KERN_MAX_THREADS,
564 .procname = "threads-max",
565 .data = &max_threads,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec,
569 },
570 {
571 .ctl_name = KERN_RANDOM,
572 .procname = "random",
573 .mode = 0555,
574 .child = random_table,
575 },
576#ifdef CONFIG_UNIX98_PTYS
577 {
578 .ctl_name = KERN_PTY,
579 .procname = "pty",
580 .mode = 0555,
581 .child = pty_table,
582 },
583#endif
584 {
585 .ctl_name = KERN_OVERFLOWUID,
586 .procname = "overflowuid",
587 .data = &overflowuid,
588 .maxlen = sizeof(int),
589 .mode = 0644,
590 .proc_handler = &proc_dointvec_minmax,
591 .strategy = &sysctl_intvec,
592 .extra1 = &minolduid,
593 .extra2 = &maxolduid,
594 },
595 {
596 .ctl_name = KERN_OVERFLOWGID,
597 .procname = "overflowgid",
598 .data = &overflowgid,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec_minmax,
602 .strategy = &sysctl_intvec,
603 .extra1 = &minolduid,
604 .extra2 = &maxolduid,
605 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800606#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607#ifdef CONFIG_MATHEMU
608 {
609 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
610 .procname = "ieee_emulation_warnings",
611 .data = &sysctl_ieee_emulation_warnings,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec,
615 },
616#endif
617#ifdef CONFIG_NO_IDLE_HZ
618 {
619 .ctl_name = KERN_HZ_TIMER,
620 .procname = "hz_timer",
621 .data = &sysctl_hz_timer,
622 .maxlen = sizeof(int),
623 .mode = 0644,
624 .proc_handler = &proc_dointvec,
625 },
626#endif
627 {
628 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
629 .procname = "userprocess_debug",
630 .data = &sysctl_userprocess_debug,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
634 },
635#endif
636 {
637 .ctl_name = KERN_PIDMAX,
638 .procname = "pid_max",
639 .data = &pid_max,
640 .maxlen = sizeof (int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec_minmax,
643 .strategy = sysctl_intvec,
644 .extra1 = &pid_max_min,
645 .extra2 = &pid_max_max,
646 },
647 {
648 .ctl_name = KERN_PANIC_ON_OOPS,
649 .procname = "panic_on_oops",
650 .data = &panic_on_oops,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec,
654 },
655 {
656 .ctl_name = KERN_PRINTK_RATELIMIT,
657 .procname = "printk_ratelimit",
658 .data = &printk_ratelimit_jiffies,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = &proc_dointvec_jiffies,
662 .strategy = &sysctl_jiffies,
663 },
664 {
665 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
666 .procname = "printk_ratelimit_burst",
667 .data = &printk_ratelimit_burst,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
671 },
672 {
673 .ctl_name = KERN_NGROUPS_MAX,
674 .procname = "ngroups_max",
675 .data = &ngroups_max,
676 .maxlen = sizeof (int),
677 .mode = 0444,
678 .proc_handler = &proc_dointvec,
679 },
680#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
681 {
682 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
683 .procname = "unknown_nmi_panic",
684 .data = &unknown_nmi_panic,
685 .maxlen = sizeof (int),
686 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200687 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 },
Don Zickus407984f2006-09-26 10:52:27 +0200689 {
690 .ctl_name = KERN_NMI_WATCHDOG,
691 .procname = "nmi_watchdog",
692 .data = &nmi_watchdog_enabled,
693 .maxlen = sizeof (int),
694 .mode = 0644,
695 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 },
697#endif
698#if defined(CONFIG_X86)
699 {
Don Zickus8da5add2006-09-26 10:52:27 +0200700 .ctl_name = KERN_PANIC_ON_NMI,
701 .procname = "panic_on_unrecovered_nmi",
702 .data = &panic_on_unrecovered_nmi,
703 .maxlen = sizeof(int),
704 .mode = 0644,
705 .proc_handler = &proc_dointvec,
706 },
707 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 .ctl_name = KERN_BOOTLOADER_TYPE,
709 .procname = "bootloader_type",
710 .data = &bootloader_type,
711 .maxlen = sizeof (int),
712 .mode = 0444,
713 .proc_handler = &proc_dointvec,
714 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100715 {
716 .ctl_name = CTL_UNNUMBERED,
717 .procname = "kstack_depth_to_print",
718 .data = &kstack_depth_to_print,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
722 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800724#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 {
726 .ctl_name = KERN_RANDOMIZE,
727 .procname = "randomize_va_space",
728 .data = &randomize_va_space,
729 .maxlen = sizeof(int),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
732 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800733#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800734#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700735 {
736 .ctl_name = KERN_SPIN_RETRY,
737 .procname = "spin_retry",
738 .data = &spin_retry,
739 .maxlen = sizeof (int),
740 .mode = 0644,
741 .proc_handler = &proc_dointvec,
742 },
743#endif
Pavel Machekc255d842006-02-20 18:27:58 -0800744#ifdef CONFIG_ACPI_SLEEP
745 {
746 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
747 .procname = "acpi_video_flags",
748 .data = &acpi_video_flags,
749 .maxlen = sizeof (unsigned long),
750 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800751 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800752 },
753#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800754#ifdef CONFIG_IA64
755 {
756 .ctl_name = KERN_IA64_UNALIGNED,
757 .procname = "ignore-unaligned-usertrap",
758 .data = &no_unaligned_warning,
759 .maxlen = sizeof (int),
760 .mode = 0644,
761 .proc_handler = &proc_dointvec,
762 },
763#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200764#ifdef CONFIG_COMPAT
765 {
766 .ctl_name = KERN_COMPAT_LOG,
767 .procname = "compat-log",
768 .data = &compat_log,
769 .maxlen = sizeof (int),
770 .mode = 0644,
771 .proc_handler = &proc_dointvec,
772 },
773#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700774#ifdef CONFIG_RT_MUTEXES
775 {
776 .ctl_name = KERN_MAX_LOCK_DEPTH,
777 .procname = "max_lock_depth",
778 .data = &max_lock_depth,
779 .maxlen = sizeof(int),
780 .mode = 0644,
781 .proc_handler = &proc_dointvec,
782 },
783#endif
784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 { .ctl_name = 0 }
786};
787
788/* Constants for minimum and maximum testing in vm_table.
789 We use these as one-element integer vectors. */
790static int zero;
791static int one_hundred = 100;
792
793
794static ctl_table vm_table[] = {
795 {
796 .ctl_name = VM_OVERCOMMIT_MEMORY,
797 .procname = "overcommit_memory",
798 .data = &sysctl_overcommit_memory,
799 .maxlen = sizeof(sysctl_overcommit_memory),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
802 },
803 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700804 .ctl_name = VM_PANIC_ON_OOM,
805 .procname = "panic_on_oom",
806 .data = &sysctl_panic_on_oom,
807 .maxlen = sizeof(sysctl_panic_on_oom),
808 .mode = 0644,
809 .proc_handler = &proc_dointvec,
810 },
811 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 .ctl_name = VM_OVERCOMMIT_RATIO,
813 .procname = "overcommit_ratio",
814 .data = &sysctl_overcommit_ratio,
815 .maxlen = sizeof(sysctl_overcommit_ratio),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec,
818 },
819 {
820 .ctl_name = VM_PAGE_CLUSTER,
821 .procname = "page-cluster",
822 .data = &page_cluster,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec,
826 },
827 {
828 .ctl_name = VM_DIRTY_BACKGROUND,
829 .procname = "dirty_background_ratio",
830 .data = &dirty_background_ratio,
831 .maxlen = sizeof(dirty_background_ratio),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec_minmax,
834 .strategy = &sysctl_intvec,
835 .extra1 = &zero,
836 .extra2 = &one_hundred,
837 },
838 {
839 .ctl_name = VM_DIRTY_RATIO,
840 .procname = "dirty_ratio",
841 .data = &vm_dirty_ratio,
842 .maxlen = sizeof(vm_dirty_ratio),
843 .mode = 0644,
844 .proc_handler = &proc_dointvec_minmax,
845 .strategy = &sysctl_intvec,
846 .extra1 = &zero,
847 .extra2 = &one_hundred,
848 },
849 {
850 .ctl_name = VM_DIRTY_WB_CS,
851 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800852 .data = &dirty_writeback_interval,
853 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 .mode = 0644,
855 .proc_handler = &dirty_writeback_centisecs_handler,
856 },
857 {
858 .ctl_name = VM_DIRTY_EXPIRE_CS,
859 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800860 .data = &dirty_expire_interval,
861 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800863 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 },
865 {
866 .ctl_name = VM_NR_PDFLUSH_THREADS,
867 .procname = "nr_pdflush_threads",
868 .data = &nr_pdflush_threads,
869 .maxlen = sizeof nr_pdflush_threads,
870 .mode = 0444 /* read-only*/,
871 .proc_handler = &proc_dointvec,
872 },
873 {
874 .ctl_name = VM_SWAPPINESS,
875 .procname = "swappiness",
876 .data = &vm_swappiness,
877 .maxlen = sizeof(vm_swappiness),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec_minmax,
880 .strategy = &sysctl_intvec,
881 .extra1 = &zero,
882 .extra2 = &one_hundred,
883 },
884#ifdef CONFIG_HUGETLB_PAGE
885 {
886 .ctl_name = VM_HUGETLB_PAGES,
887 .procname = "nr_hugepages",
888 .data = &max_huge_pages,
889 .maxlen = sizeof(unsigned long),
890 .mode = 0644,
891 .proc_handler = &hugetlb_sysctl_handler,
892 .extra1 = (void *)&hugetlb_zero,
893 .extra2 = (void *)&hugetlb_infinity,
894 },
895 {
896 .ctl_name = VM_HUGETLB_GROUP,
897 .procname = "hugetlb_shm_group",
898 .data = &sysctl_hugetlb_shm_group,
899 .maxlen = sizeof(gid_t),
900 .mode = 0644,
901 .proc_handler = &proc_dointvec,
902 },
903#endif
904 {
905 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
906 .procname = "lowmem_reserve_ratio",
907 .data = &sysctl_lowmem_reserve_ratio,
908 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
909 .mode = 0644,
910 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
911 .strategy = &sysctl_intvec,
912 },
913 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800914 .ctl_name = VM_DROP_PAGECACHE,
915 .procname = "drop_caches",
916 .data = &sysctl_drop_caches,
917 .maxlen = sizeof(int),
918 .mode = 0644,
919 .proc_handler = drop_caches_sysctl_handler,
920 .strategy = &sysctl_intvec,
921 },
922 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 .ctl_name = VM_MIN_FREE_KBYTES,
924 .procname = "min_free_kbytes",
925 .data = &min_free_kbytes,
926 .maxlen = sizeof(min_free_kbytes),
927 .mode = 0644,
928 .proc_handler = &min_free_kbytes_sysctl_handler,
929 .strategy = &sysctl_intvec,
930 .extra1 = &zero,
931 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800932 {
933 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
934 .procname = "percpu_pagelist_fraction",
935 .data = &percpu_pagelist_fraction,
936 .maxlen = sizeof(percpu_pagelist_fraction),
937 .mode = 0644,
938 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
939 .strategy = &sysctl_intvec,
940 .extra1 = &min_percpu_pagelist_fract,
941 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942#ifdef CONFIG_MMU
943 {
944 .ctl_name = VM_MAX_MAP_COUNT,
945 .procname = "max_map_count",
946 .data = &sysctl_max_map_count,
947 .maxlen = sizeof(sysctl_max_map_count),
948 .mode = 0644,
949 .proc_handler = &proc_dointvec
950 },
951#endif
952 {
953 .ctl_name = VM_LAPTOP_MODE,
954 .procname = "laptop_mode",
955 .data = &laptop_mode,
956 .maxlen = sizeof(laptop_mode),
957 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800958 .proc_handler = &proc_dointvec_jiffies,
959 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 },
961 {
962 .ctl_name = VM_BLOCK_DUMP,
963 .procname = "block_dump",
964 .data = &block_dump,
965 .maxlen = sizeof(block_dump),
966 .mode = 0644,
967 .proc_handler = &proc_dointvec,
968 .strategy = &sysctl_intvec,
969 .extra1 = &zero,
970 },
971 {
972 .ctl_name = VM_VFS_CACHE_PRESSURE,
973 .procname = "vfs_cache_pressure",
974 .data = &sysctl_vfs_cache_pressure,
975 .maxlen = sizeof(sysctl_vfs_cache_pressure),
976 .mode = 0644,
977 .proc_handler = &proc_dointvec,
978 .strategy = &sysctl_intvec,
979 .extra1 = &zero,
980 },
981#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
982 {
983 .ctl_name = VM_LEGACY_VA_LAYOUT,
984 .procname = "legacy_va_layout",
985 .data = &sysctl_legacy_va_layout,
986 .maxlen = sizeof(sysctl_legacy_va_layout),
987 .mode = 0644,
988 .proc_handler = &proc_dointvec,
989 .strategy = &sysctl_intvec,
990 .extra1 = &zero,
991 },
992#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800993#ifdef CONFIG_NUMA
994 {
995 .ctl_name = VM_ZONE_RECLAIM_MODE,
996 .procname = "zone_reclaim_mode",
997 .data = &zone_reclaim_mode,
998 .maxlen = sizeof(zone_reclaim_mode),
999 .mode = 0644,
1000 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001001 .strategy = &sysctl_intvec,
1002 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001003 },
Christoph Lameter96146342006-07-03 00:24:13 -07001004 {
1005 .ctl_name = VM_MIN_UNMAPPED,
1006 .procname = "min_unmapped_ratio",
1007 .data = &sysctl_min_unmapped_ratio,
1008 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1009 .mode = 0644,
1010 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1012 .extra1 = &zero,
1013 .extra2 = &one_hundred,
1014 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001015 {
1016 .ctl_name = VM_MIN_SLAB,
1017 .procname = "min_slab_ratio",
1018 .data = &sysctl_min_slab_ratio,
1019 .maxlen = sizeof(sysctl_min_slab_ratio),
1020 .mode = 0644,
1021 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &zero,
1024 .extra2 = &one_hundred,
1025 },
Christoph Lameter17436602006-01-18 17:42:32 -08001026#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001027#ifdef CONFIG_X86_32
1028 {
1029 .ctl_name = VM_VDSO_ENABLED,
1030 .procname = "vdso_enabled",
1031 .data = &vdso_enabled,
1032 .maxlen = sizeof(vdso_enabled),
1033 .mode = 0644,
1034 .proc_handler = &proc_dointvec,
1035 .strategy = &sysctl_intvec,
1036 .extra1 = &zero,
1037 },
1038#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 { .ctl_name = 0 }
1040};
1041
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042static ctl_table fs_table[] = {
1043 {
1044 .ctl_name = FS_NRINODE,
1045 .procname = "inode-nr",
1046 .data = &inodes_stat,
1047 .maxlen = 2*sizeof(int),
1048 .mode = 0444,
1049 .proc_handler = &proc_dointvec,
1050 },
1051 {
1052 .ctl_name = FS_STATINODE,
1053 .procname = "inode-state",
1054 .data = &inodes_stat,
1055 .maxlen = 7*sizeof(int),
1056 .mode = 0444,
1057 .proc_handler = &proc_dointvec,
1058 },
1059 {
1060 .ctl_name = FS_NRFILE,
1061 .procname = "file-nr",
1062 .data = &files_stat,
1063 .maxlen = 3*sizeof(int),
1064 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001065 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 },
1067 {
1068 .ctl_name = FS_MAXFILE,
1069 .procname = "file-max",
1070 .data = &files_stat.max_files,
1071 .maxlen = sizeof(int),
1072 .mode = 0644,
1073 .proc_handler = &proc_dointvec,
1074 },
1075 {
1076 .ctl_name = FS_DENTRY,
1077 .procname = "dentry-state",
1078 .data = &dentry_stat,
1079 .maxlen = 6*sizeof(int),
1080 .mode = 0444,
1081 .proc_handler = &proc_dointvec,
1082 },
1083 {
1084 .ctl_name = FS_OVERFLOWUID,
1085 .procname = "overflowuid",
1086 .data = &fs_overflowuid,
1087 .maxlen = sizeof(int),
1088 .mode = 0644,
1089 .proc_handler = &proc_dointvec_minmax,
1090 .strategy = &sysctl_intvec,
1091 .extra1 = &minolduid,
1092 .extra2 = &maxolduid,
1093 },
1094 {
1095 .ctl_name = FS_OVERFLOWGID,
1096 .procname = "overflowgid",
1097 .data = &fs_overflowgid,
1098 .maxlen = sizeof(int),
1099 .mode = 0644,
1100 .proc_handler = &proc_dointvec_minmax,
1101 .strategy = &sysctl_intvec,
1102 .extra1 = &minolduid,
1103 .extra2 = &maxolduid,
1104 },
1105 {
1106 .ctl_name = FS_LEASES,
1107 .procname = "leases-enable",
1108 .data = &leases_enable,
1109 .maxlen = sizeof(int),
1110 .mode = 0644,
1111 .proc_handler = &proc_dointvec,
1112 },
1113#ifdef CONFIG_DNOTIFY
1114 {
1115 .ctl_name = FS_DIR_NOTIFY,
1116 .procname = "dir-notify-enable",
1117 .data = &dir_notify_enable,
1118 .maxlen = sizeof(int),
1119 .mode = 0644,
1120 .proc_handler = &proc_dointvec,
1121 },
1122#endif
1123#ifdef CONFIG_MMU
1124 {
1125 .ctl_name = FS_LEASE_TIME,
1126 .procname = "lease-break-time",
1127 .data = &lease_break_time,
1128 .maxlen = sizeof(int),
1129 .mode = 0644,
1130 .proc_handler = &proc_dointvec,
1131 },
1132 {
1133 .ctl_name = FS_AIO_NR,
1134 .procname = "aio-nr",
1135 .data = &aio_nr,
1136 .maxlen = sizeof(aio_nr),
1137 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001138 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 },
1140 {
1141 .ctl_name = FS_AIO_MAX_NR,
1142 .procname = "aio-max-nr",
1143 .data = &aio_max_nr,
1144 .maxlen = sizeof(aio_max_nr),
1145 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001146 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001148#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001149 {
1150 .ctl_name = FS_INOTIFY,
1151 .procname = "inotify",
1152 .mode = 0555,
1153 .child = inotify_table,
1154 },
1155#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001157 {
1158 .ctl_name = KERN_SETUID_DUMPABLE,
1159 .procname = "suid_dumpable",
1160 .data = &suid_dumpable,
1161 .maxlen = sizeof(int),
1162 .mode = 0644,
1163 .proc_handler = &proc_dointvec,
1164 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 { .ctl_name = 0 }
1166};
1167
1168static ctl_table debug_table[] = {
1169 { .ctl_name = 0 }
1170};
1171
1172static ctl_table dev_table[] = {
1173 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001174};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
1176extern void init_irq_proc (void);
1177
Al Viro330d57f2005-11-04 10:18:40 +00001178static DEFINE_SPINLOCK(sysctl_lock);
1179
1180/* called under sysctl_lock */
1181static int use_table(struct ctl_table_header *p)
1182{
1183 if (unlikely(p->unregistering))
1184 return 0;
1185 p->used++;
1186 return 1;
1187}
1188
1189/* called under sysctl_lock */
1190static void unuse_table(struct ctl_table_header *p)
1191{
1192 if (!--p->used)
1193 if (unlikely(p->unregistering))
1194 complete(p->unregistering);
1195}
1196
1197/* called under sysctl_lock, will reacquire if has to wait */
1198static void start_unregistering(struct ctl_table_header *p)
1199{
1200 /*
1201 * if p->used is 0, nobody will ever touch that entry again;
1202 * we'll eliminate all paths to it before dropping sysctl_lock
1203 */
1204 if (unlikely(p->used)) {
1205 struct completion wait;
1206 init_completion(&wait);
1207 p->unregistering = &wait;
1208 spin_unlock(&sysctl_lock);
1209 wait_for_completion(&wait);
1210 spin_lock(&sysctl_lock);
1211 }
1212 /*
1213 * do not remove from the list until nobody holds it; walking the
1214 * list in do_sysctl() relies on that.
1215 */
1216 list_del_init(&p->ctl_entry);
1217}
1218
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219void __init sysctl_init(void)
1220{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001221#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001222 register_proc_table(root_table, proc_sys_root, &root_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 init_irq_proc();
1224#endif
1225}
1226
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001227#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1229 void __user *newval, size_t newlen)
1230{
1231 struct list_head *tmp;
Al Viro330d57f2005-11-04 10:18:40 +00001232 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
1234 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1235 return -ENOTDIR;
1236 if (oldval) {
1237 int old_len;
1238 if (!oldlenp || get_user(old_len, oldlenp))
1239 return -EFAULT;
1240 }
Al Viro330d57f2005-11-04 10:18:40 +00001241 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 tmp = &root_table_header.ctl_entry;
1243 do {
1244 struct ctl_table_header *head =
1245 list_entry(tmp, struct ctl_table_header, ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001246
1247 if (!use_table(head))
1248 continue;
1249
1250 spin_unlock(&sysctl_lock);
1251
1252 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001253 newval, newlen, head->ctl_table);
Al Viro330d57f2005-11-04 10:18:40 +00001254
1255 spin_lock(&sysctl_lock);
1256 unuse_table(head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (error != -ENOTDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001258 break;
1259 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1260 spin_unlock(&sysctl_lock);
1261 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262}
1263
1264asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1265{
1266 struct __sysctl_args tmp;
1267 int error;
1268
1269 if (copy_from_user(&tmp, args, sizeof(tmp)))
1270 return -EFAULT;
1271
1272 lock_kernel();
1273 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1274 tmp.newval, tmp.newlen);
1275 unlock_kernel();
1276 return error;
1277}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001278#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280/*
1281 * ctl_perm does NOT grant the superuser all rights automatically, because
1282 * some sysctl variables are readonly even to root.
1283 */
1284
1285static int test_perm(int mode, int op)
1286{
1287 if (!current->euid)
1288 mode >>= 6;
1289 else if (in_egroup_p(0))
1290 mode >>= 3;
1291 if ((mode & op & 0007) == op)
1292 return 0;
1293 return -EACCES;
1294}
1295
1296static inline int ctl_perm(ctl_table *table, int op)
1297{
1298 int error;
1299 error = security_sysctl(table, op);
1300 if (error)
1301 return error;
1302 return test_perm(table->mode, op);
1303}
1304
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001305#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306static int parse_table(int __user *name, int nlen,
1307 void __user *oldval, size_t __user *oldlenp,
1308 void __user *newval, size_t newlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001309 ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310{
1311 int n;
1312repeat:
1313 if (!nlen)
1314 return -ENOTDIR;
1315 if (get_user(n, name))
1316 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001317 for ( ; table->ctl_name || table->procname; table++) {
1318 if (!table->ctl_name)
1319 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1321 int error;
1322 if (table->child) {
1323 if (ctl_perm(table, 001))
1324 return -EPERM;
1325 if (table->strategy) {
1326 error = table->strategy(
1327 table, name, nlen,
1328 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001329 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 if (error)
1331 return error;
1332 }
1333 name++;
1334 nlen--;
1335 table = table->child;
1336 goto repeat;
1337 }
1338 error = do_sysctl_strategy(table, name, nlen,
1339 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001340 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 return error;
1342 }
1343 }
1344 return -ENOTDIR;
1345}
1346
1347/* Perform the actual read/write of a sysctl table entry. */
1348int do_sysctl_strategy (ctl_table *table,
1349 int __user *name, int nlen,
1350 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001351 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352{
1353 int op = 0, rc;
1354 size_t len;
1355
1356 if (oldval)
1357 op |= 004;
1358 if (newval)
1359 op |= 002;
1360 if (ctl_perm(table, op))
1361 return -EPERM;
1362
1363 if (table->strategy) {
1364 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001365 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 if (rc < 0)
1367 return rc;
1368 if (rc > 0)
1369 return 0;
1370 }
1371
1372 /* If there is no strategy routine, or if the strategy returns
1373 * zero, proceed with automatic r/w */
1374 if (table->data && table->maxlen) {
1375 if (oldval && oldlenp) {
1376 if (get_user(len, oldlenp))
1377 return -EFAULT;
1378 if (len) {
1379 if (len > table->maxlen)
1380 len = table->maxlen;
1381 if(copy_to_user(oldval, table->data, len))
1382 return -EFAULT;
1383 if(put_user(len, oldlenp))
1384 return -EFAULT;
1385 }
1386 }
1387 if (newval && newlen) {
1388 len = newlen;
1389 if (len > table->maxlen)
1390 len = table->maxlen;
1391 if(copy_from_user(table->data, newval, len))
1392 return -EFAULT;
1393 }
1394 }
1395 return 0;
1396}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001397#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
1399/**
1400 * register_sysctl_table - register a sysctl hierarchy
1401 * @table: the top-level table structure
1402 * @insert_at_head: whether the entry should be inserted in front or at the end
1403 *
1404 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1405 * array. An entry with a ctl_name of 0 terminates the table.
1406 *
1407 * The members of the &ctl_table structure are used as follows:
1408 *
1409 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1410 * must be unique within that level of sysctl
1411 *
1412 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1413 * enter a sysctl file
1414 *
1415 * data - a pointer to data for use by proc_handler
1416 *
1417 * maxlen - the maximum size in bytes of the data
1418 *
1419 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1420 *
1421 * child - a pointer to the child sysctl table if this entry is a directory, or
1422 * %NULL.
1423 *
1424 * proc_handler - the text handler routine (described below)
1425 *
1426 * strategy - the strategy routine (described below)
1427 *
1428 * de - for internal use by the sysctl routines
1429 *
1430 * extra1, extra2 - extra pointers usable by the proc handler routines
1431 *
1432 * Leaf nodes in the sysctl tree will be represented by a single file
1433 * under /proc; non-leaf nodes will be represented by directories.
1434 *
1435 * sysctl(2) can automatically manage read and write requests through
1436 * the sysctl table. The data and maxlen fields of the ctl_table
1437 * struct enable minimal validation of the values being written to be
1438 * performed, and the mode field allows minimal authentication.
1439 *
1440 * More sophisticated management can be enabled by the provision of a
1441 * strategy routine with the table entry. This will be called before
1442 * any automatic read or write of the data is performed.
1443 *
1444 * The strategy routine may return
1445 *
1446 * < 0 - Error occurred (error is passed to user process)
1447 *
1448 * 0 - OK - proceed with automatic read or write.
1449 *
1450 * > 0 - OK - read or write has been done by the strategy routine, so
1451 * return immediately.
1452 *
1453 * There must be a proc_handler routine for any terminal nodes
1454 * mirrored under /proc/sys (non-terminals are handled by a built-in
1455 * directory handler). Several default handlers are available to
1456 * cover common cases -
1457 *
1458 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1459 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1460 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1461 *
1462 * It is the handler's job to read the input buffer from user memory
1463 * and process it. The handler should return 0 on success.
1464 *
1465 * This routine returns %NULL on a failure to register, and a pointer
1466 * to the table header on success.
1467 */
1468struct ctl_table_header *register_sysctl_table(ctl_table * table,
1469 int insert_at_head)
1470{
1471 struct ctl_table_header *tmp;
1472 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1473 if (!tmp)
1474 return NULL;
1475 tmp->ctl_table = table;
1476 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001477 tmp->used = 0;
1478 tmp->unregistering = NULL;
1479 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 if (insert_at_head)
1481 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1482 else
1483 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001484 spin_unlock(&sysctl_lock);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001485#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001486 register_proc_table(table, proc_sys_root, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487#endif
1488 return tmp;
1489}
1490
1491/**
1492 * unregister_sysctl_table - unregister a sysctl table hierarchy
1493 * @header: the header returned from register_sysctl_table
1494 *
1495 * Unregisters the sysctl table and all children. proc entries may not
1496 * actually be removed until they are no longer used by anyone.
1497 */
1498void unregister_sysctl_table(struct ctl_table_header * header)
1499{
Al Viro330d57f2005-11-04 10:18:40 +00001500 might_sleep();
1501 spin_lock(&sysctl_lock);
1502 start_unregistering(header);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001503#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 unregister_proc_table(header->ctl_table, proc_sys_root);
1505#endif
Al Viro330d57f2005-11-04 10:18:40 +00001506 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 kfree(header);
1508}
1509
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001510#else /* !CONFIG_SYSCTL */
1511struct ctl_table_header * register_sysctl_table(ctl_table * table,
1512 int insert_at_head)
1513{
1514 return NULL;
1515}
1516
1517void unregister_sysctl_table(struct ctl_table_header * table)
1518{
1519}
1520
1521#endif /* CONFIG_SYSCTL */
1522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523/*
1524 * /proc/sys support
1525 */
1526
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001527#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529/* Scan the sysctl entries in table and add them all into /proc */
Al Viro330d57f2005-11-04 10:18:40 +00001530static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
1532 struct proc_dir_entry *de;
1533 int len;
1534 mode_t mode;
1535
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001536 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 /* Can't do anything without a proc name. */
1538 if (!table->procname)
1539 continue;
1540 /* Maybe we can't do anything with it... */
1541 if (!table->proc_handler && !table->child) {
1542 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1543 table->procname);
1544 continue;
1545 }
1546
1547 len = strlen(table->procname);
1548 mode = table->mode;
1549
1550 de = NULL;
1551 if (table->proc_handler)
1552 mode |= S_IFREG;
1553 else {
1554 mode |= S_IFDIR;
1555 for (de = root->subdir; de; de = de->next) {
1556 if (proc_match(len, table->procname, de))
1557 break;
1558 }
1559 /* If the subdir exists already, de is non-NULL */
1560 }
1561
1562 if (!de) {
1563 de = create_proc_entry(table->procname, mode, root);
1564 if (!de)
1565 continue;
Al Viro330d57f2005-11-04 10:18:40 +00001566 de->set = set;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 de->data = (void *) table;
1568 if (table->proc_handler)
1569 de->proc_fops = &proc_sys_file_operations;
1570 }
1571 table->de = de;
1572 if (de->mode & S_IFDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001573 register_proc_table(table->child, de, set);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 }
1575}
1576
1577/*
1578 * Unregister a /proc sysctl table and any subdirectories.
1579 */
1580static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1581{
1582 struct proc_dir_entry *de;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001583 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 if (!(de = table->de))
1585 continue;
1586 if (de->mode & S_IFDIR) {
1587 if (!table->child) {
1588 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1589 continue;
1590 }
1591 unregister_proc_table(table->child, de);
1592
1593 /* Don't unregister directories which still have entries.. */
1594 if (de->subdir)
1595 continue;
1596 }
1597
Al Viro330d57f2005-11-04 10:18:40 +00001598 /*
1599 * In any case, mark the entry as goner; we'll keep it
1600 * around if it's busy, but we'll know to do nothing with
1601 * its fields. We are under sysctl_lock here.
1602 */
1603 de->data = NULL;
1604
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 /* Don't unregister proc entries that are still being used.. */
1606 if (atomic_read(&de->count))
1607 continue;
1608
1609 table->de = NULL;
1610 remove_proc_entry(table->procname, root);
1611 }
1612}
1613
1614static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1615 size_t count, loff_t *ppos)
1616{
1617 int op;
Josef "Jeff" Sipekf3a43f32006-12-08 02:36:43 -08001618 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 struct ctl_table *table;
1620 size_t res;
Al Viro330d57f2005-11-04 10:18:40 +00001621 ssize_t error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
Al Viro330d57f2005-11-04 10:18:40 +00001623 spin_lock(&sysctl_lock);
1624 if (de && de->data && use_table(de->set)) {
1625 /*
1626 * at that point we know that sysctl was not unregistered
1627 * and won't be until we finish
1628 */
1629 spin_unlock(&sysctl_lock);
1630 table = (struct ctl_table *) de->data;
1631 if (!table || !table->proc_handler)
1632 goto out;
1633 error = -EPERM;
1634 op = (write ? 002 : 004);
1635 if (ctl_perm(table, op))
1636 goto out;
1637
1638 /* careful: calling conventions are nasty here */
1639 res = count;
1640 error = (*table->proc_handler)(table, write, file,
1641 buf, &res, ppos);
1642 if (!error)
1643 error = res;
1644 out:
1645 spin_lock(&sysctl_lock);
1646 unuse_table(de->set);
1647 }
1648 spin_unlock(&sysctl_lock);
1649 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
1652static int proc_opensys(struct inode *inode, struct file *file)
1653{
1654 if (file->f_mode & FMODE_WRITE) {
1655 /*
1656 * sysctl entries that are not writable,
1657 * are _NOT_ writable, capabilities or not.
1658 */
1659 if (!(inode->i_mode & S_IWUSR))
1660 return -EPERM;
1661 }
1662
1663 return 0;
1664}
1665
1666static ssize_t proc_readsys(struct file * file, char __user * buf,
1667 size_t count, loff_t *ppos)
1668{
1669 return do_rw_proc(0, file, buf, count, ppos);
1670}
1671
1672static ssize_t proc_writesys(struct file * file, const char __user * buf,
1673 size_t count, loff_t *ppos)
1674{
1675 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1676}
1677
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001678static int _proc_do_string(void* data, int maxlen, int write,
1679 struct file *filp, void __user *buffer,
1680 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001681{
1682 size_t len;
1683 char __user *p;
1684 char c;
1685
1686 if (!data || !maxlen || !*lenp ||
1687 (*ppos && !write)) {
1688 *lenp = 0;
1689 return 0;
1690 }
1691
1692 if (write) {
1693 len = 0;
1694 p = buffer;
1695 while (len < *lenp) {
1696 if (get_user(c, p++))
1697 return -EFAULT;
1698 if (c == 0 || c == '\n')
1699 break;
1700 len++;
1701 }
1702 if (len >= maxlen)
1703 len = maxlen-1;
1704 if(copy_from_user(data, buffer, len))
1705 return -EFAULT;
1706 ((char *) data)[len] = 0;
1707 *ppos += *lenp;
1708 } else {
1709 len = strlen(data);
1710 if (len > maxlen)
1711 len = maxlen;
1712 if (len > *lenp)
1713 len = *lenp;
1714 if (len)
1715 if(copy_to_user(buffer, data, len))
1716 return -EFAULT;
1717 if (len < *lenp) {
1718 if(put_user('\n', ((char __user *) buffer) + len))
1719 return -EFAULT;
1720 len++;
1721 }
1722 *lenp = len;
1723 *ppos += len;
1724 }
1725 return 0;
1726}
1727
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728/**
1729 * proc_dostring - read a string sysctl
1730 * @table: the sysctl table
1731 * @write: %TRUE if this is a write to the sysctl file
1732 * @filp: the file structure
1733 * @buffer: the user buffer
1734 * @lenp: the size of the user buffer
1735 * @ppos: file position
1736 *
1737 * Reads/writes a string from/to the user buffer. If the kernel
1738 * buffer provided is not large enough to hold the string, the
1739 * string is truncated. The copied string is %NULL-terminated.
1740 * If the string is being read by the user process, it is copied
1741 * and a newline '\n' is added. It is truncated if the buffer is
1742 * not large enough.
1743 *
1744 * Returns 0 on success.
1745 */
1746int proc_dostring(ctl_table *table, int write, struct file *filp,
1747 void __user *buffer, size_t *lenp, loff_t *ppos)
1748{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001749 return _proc_do_string(table->data, table->maxlen, write, filp,
1750 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751}
1752
1753/*
1754 * Special case of dostring for the UTS structure. This has locks
1755 * to observe. Should this be in kernel/sys.c ????
1756 */
Eric W. Biedermancf9f1512006-12-08 02:39:55 -08001757
Serge E. Hallyn8218c742006-10-02 02:18:15 -07001758static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 void __user *buffer, size_t *lenp, loff_t *ppos)
1760{
1761 int r;
Eric W. Biedermancf9f1512006-12-08 02:39:55 -08001762 void *which;
1763 which = get_uts(table, write);
1764 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1765 put_uts(table, write, which);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 return r;
1767}
1768
1769static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1770 int *valp,
1771 int write, void *data)
1772{
1773 if (write) {
1774 *valp = *negp ? -*lvalp : *lvalp;
1775 } else {
1776 int val = *valp;
1777 if (val < 0) {
1778 *negp = -1;
1779 *lvalp = (unsigned long)-val;
1780 } else {
1781 *negp = 0;
1782 *lvalp = (unsigned long)val;
1783 }
1784 }
1785 return 0;
1786}
1787
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001788static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1789 int write, struct file *filp, void __user *buffer,
1790 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1792 int write, void *data),
1793 void *data)
1794{
1795#define TMPBUFLEN 21
1796 int *i, vleft, first=1, neg, val;
1797 unsigned long lval;
1798 size_t left, len;
1799
1800 char buf[TMPBUFLEN], *p;
1801 char __user *s = buffer;
1802
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001803 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 (*ppos && !write)) {
1805 *lenp = 0;
1806 return 0;
1807 }
1808
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001809 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 vleft = table->maxlen / sizeof(*i);
1811 left = *lenp;
1812
1813 if (!conv)
1814 conv = do_proc_dointvec_conv;
1815
1816 for (; left && vleft--; i++, first=0) {
1817 if (write) {
1818 while (left) {
1819 char c;
1820 if (get_user(c, s))
1821 return -EFAULT;
1822 if (!isspace(c))
1823 break;
1824 left--;
1825 s++;
1826 }
1827 if (!left)
1828 break;
1829 neg = 0;
1830 len = left;
1831 if (len > sizeof(buf) - 1)
1832 len = sizeof(buf) - 1;
1833 if (copy_from_user(buf, s, len))
1834 return -EFAULT;
1835 buf[len] = 0;
1836 p = buf;
1837 if (*p == '-' && left > 1) {
1838 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001839 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 }
1841 if (*p < '0' || *p > '9')
1842 break;
1843
1844 lval = simple_strtoul(p, &p, 0);
1845
1846 len = p-buf;
1847 if ((len < left) && *p && !isspace(*p))
1848 break;
1849 if (neg)
1850 val = -val;
1851 s += len;
1852 left -= len;
1853
1854 if (conv(&neg, &lval, i, 1, data))
1855 break;
1856 } else {
1857 p = buf;
1858 if (!first)
1859 *p++ = '\t';
1860
1861 if (conv(&neg, &lval, i, 0, data))
1862 break;
1863
1864 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1865 len = strlen(buf);
1866 if (len > left)
1867 len = left;
1868 if(copy_to_user(s, buf, len))
1869 return -EFAULT;
1870 left -= len;
1871 s += len;
1872 }
1873 }
1874
1875 if (!write && !first && left) {
1876 if(put_user('\n', s))
1877 return -EFAULT;
1878 left--, s++;
1879 }
1880 if (write) {
1881 while (left) {
1882 char c;
1883 if (get_user(c, s++))
1884 return -EFAULT;
1885 if (!isspace(c))
1886 break;
1887 left--;
1888 }
1889 }
1890 if (write && first)
1891 return -EINVAL;
1892 *lenp -= left;
1893 *ppos += *lenp;
1894 return 0;
1895#undef TMPBUFLEN
1896}
1897
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001898static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1899 void __user *buffer, size_t *lenp, loff_t *ppos,
1900 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1901 int write, void *data),
1902 void *data)
1903{
1904 return __do_proc_dointvec(table->data, table, write, filp,
1905 buffer, lenp, ppos, conv, data);
1906}
1907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908/**
1909 * proc_dointvec - read a vector of integers
1910 * @table: the sysctl table
1911 * @write: %TRUE if this is a write to the sysctl file
1912 * @filp: the file structure
1913 * @buffer: the user buffer
1914 * @lenp: the size of the user buffer
1915 * @ppos: file position
1916 *
1917 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1918 * values from/to the user buffer, treated as an ASCII string.
1919 *
1920 * Returns 0 on success.
1921 */
1922int proc_dointvec(ctl_table *table, int write, struct file *filp,
1923 void __user *buffer, size_t *lenp, loff_t *ppos)
1924{
1925 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1926 NULL,NULL);
1927}
1928
1929#define OP_SET 0
1930#define OP_AND 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
1932static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1933 int *valp,
1934 int write, void *data)
1935{
1936 int op = *(int *)data;
1937 if (write) {
1938 int val = *negp ? -*lvalp : *lvalp;
1939 switch(op) {
1940 case OP_SET: *valp = val; break;
1941 case OP_AND: *valp &= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 }
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}
Randy Dunlapd53ef072006-12-10 02:18:36 -08002398static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2399 void __user *buffer, size_t *lenp, loff_t *ppos)
2400{
2401 return -ENOSYS;
2402}
2403static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2404 struct file *filp, void __user *buffer,
2405 size_t *lenp, loff_t *ppos)
2406{
2407 return -ENOSYS;
2408}
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002409#endif
2410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411int proc_dointvec(ctl_table *table, int write, struct file *filp,
2412 void __user *buffer, size_t *lenp, loff_t *ppos)
2413{
2414 return -ENOSYS;
2415}
2416
2417int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2418 void __user *buffer, size_t *lenp, loff_t *ppos)
2419{
2420 return -ENOSYS;
2421}
2422
2423int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2424 void __user *buffer, size_t *lenp, loff_t *ppos)
2425{
2426 return -ENOSYS;
2427}
2428
2429int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2430 void __user *buffer, size_t *lenp, loff_t *ppos)
2431{
2432 return -ENOSYS;
2433}
2434
2435int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2436 void __user *buffer, size_t *lenp, loff_t *ppos)
2437{
2438 return -ENOSYS;
2439}
2440
2441int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2442 void __user *buffer, size_t *lenp, loff_t *ppos)
2443{
2444 return -ENOSYS;
2445}
2446
2447int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2448 void __user *buffer, size_t *lenp, loff_t *ppos)
2449{
2450 return -ENOSYS;
2451}
2452
2453int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2454 struct file *filp,
2455 void __user *buffer,
2456 size_t *lenp, loff_t *ppos)
2457{
2458 return -ENOSYS;
2459}
2460
2461
2462#endif /* CONFIG_PROC_FS */
2463
2464
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002465#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466/*
2467 * General sysctl support routines
2468 */
2469
2470/* The generic string strategy routine: */
2471int sysctl_string(ctl_table *table, int __user *name, int nlen,
2472 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002473 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 if (!table->data || !table->maxlen)
2476 return -ENOTDIR;
2477
2478 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002479 size_t bufsize;
2480 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002482 if (bufsize) {
2483 size_t len = strlen(table->data), copied;
2484
2485 /* This shouldn't trigger for a well-formed sysctl */
2486 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002488
2489 /* Copy up to a max of bufsize-1 bytes of the string */
2490 copied = (len >= bufsize) ? bufsize - 1 : len;
2491
2492 if (copy_to_user(oldval, table->data, copied) ||
2493 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002495 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 return -EFAULT;
2497 }
2498 }
2499 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002500 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 if (len > table->maxlen)
2502 len = table->maxlen;
2503 if(copy_from_user(table->data, newval, len))
2504 return -EFAULT;
2505 if (len == table->maxlen)
2506 len--;
2507 ((char *) table->data)[len] = 0;
2508 }
Yi Yang82c9df82005-12-30 16:37:10 +08002509 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510}
2511
2512/*
2513 * This function makes sure that all of the integers in the vector
2514 * are between the minimum and maximum values given in the arrays
2515 * table->extra1 and table->extra2, respectively.
2516 */
2517int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2518 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002519 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520{
2521
2522 if (newval && newlen) {
2523 int __user *vec = (int __user *) newval;
2524 int *min = (int *) table->extra1;
2525 int *max = (int *) table->extra2;
2526 size_t length;
2527 int i;
2528
2529 if (newlen % sizeof(int) != 0)
2530 return -EINVAL;
2531
2532 if (!table->extra1 && !table->extra2)
2533 return 0;
2534
2535 if (newlen > table->maxlen)
2536 newlen = table->maxlen;
2537 length = newlen / sizeof(int);
2538
2539 for (i = 0; i < length; i++) {
2540 int value;
2541 if (get_user(value, vec + i))
2542 return -EFAULT;
2543 if (min && value < min[i])
2544 return -EINVAL;
2545 if (max && value > max[i])
2546 return -EINVAL;
2547 }
2548 }
2549 return 0;
2550}
2551
2552/* Strategy function to convert jiffies to seconds */
2553int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2554 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002555 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
2557 if (oldval) {
2558 size_t olen;
2559 if (oldlenp) {
2560 if (get_user(olen, oldlenp))
2561 return -EFAULT;
2562 if (olen!=sizeof(int))
2563 return -EINVAL;
2564 }
2565 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2566 (oldlenp && put_user(sizeof(int),oldlenp)))
2567 return -EFAULT;
2568 }
2569 if (newval && newlen) {
2570 int new;
2571 if (newlen != sizeof(int))
2572 return -EINVAL;
2573 if (get_user(new, (int __user *)newval))
2574 return -EFAULT;
2575 *(int *)(table->data) = new*HZ;
2576 }
2577 return 1;
2578}
2579
2580/* Strategy function to convert jiffies to seconds */
2581int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2582 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002583 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584{
2585 if (oldval) {
2586 size_t olen;
2587 if (oldlenp) {
2588 if (get_user(olen, oldlenp))
2589 return -EFAULT;
2590 if (olen!=sizeof(int))
2591 return -EINVAL;
2592 }
2593 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2594 (oldlenp && put_user(sizeof(int),oldlenp)))
2595 return -EFAULT;
2596 }
2597 if (newval && newlen) {
2598 int new;
2599 if (newlen != sizeof(int))
2600 return -EINVAL;
2601 if (get_user(new, (int __user *)newval))
2602 return -EFAULT;
2603 *(int *)(table->data) = msecs_to_jiffies(new);
2604 }
2605 return 1;
2606}
2607
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002608
2609/* The generic string strategy routine: */
2610static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2611 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002612 void __user *newval, size_t newlen)
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002613{
2614 struct ctl_table uts_table;
2615 int r, write;
2616 write = newval && newlen;
2617 memcpy(&uts_table, table, sizeof(uts_table));
2618 uts_table.data = get_uts(table, write);
2619 r = sysctl_string(&uts_table, name, nlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002620 oldval, oldlenp, newval, newlen);
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002621 put_uts(table, write, uts_table.data);
2622 return r;
2623}
2624
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002625#ifdef CONFIG_SYSVIPC
2626/* The generic sysctl ipc data routine. */
2627static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2628 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002629 void __user *newval, size_t newlen)
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002630{
2631 size_t len;
2632 void *data;
2633
2634 /* Get out of I don't have a variable */
2635 if (!table->data || !table->maxlen)
2636 return -ENOTDIR;
2637
2638 data = get_ipc(table, 1);
2639 if (!data)
2640 return -ENOTDIR;
2641
2642 if (oldval && oldlenp) {
2643 if (get_user(len, oldlenp))
2644 return -EFAULT;
2645 if (len) {
2646 if (len > table->maxlen)
2647 len = table->maxlen;
2648 if (copy_to_user(oldval, data, len))
2649 return -EFAULT;
2650 if (put_user(len, oldlenp))
2651 return -EFAULT;
2652 }
2653 }
2654
2655 if (newval && newlen) {
2656 if (newlen > table->maxlen)
2657 newlen = table->maxlen;
2658
2659 if (copy_from_user(data, newval, newlen))
2660 return -EFAULT;
2661 }
2662 return 1;
2663}
2664#endif
2665
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002666#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
2668
2669asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2670{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002671 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002672 struct __sysctl_args tmp;
2673 int name[CTL_MAXNAME];
2674 int i;
2675
2676 /* Read in the sysctl name for better debug message logging */
2677 if (copy_from_user(&tmp, args, sizeof(tmp)))
2678 return -EFAULT;
2679 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2680 return -ENOTDIR;
2681 for (i = 0; i < tmp.nlen; i++)
2682 if (get_user(name[i], tmp.name + i))
2683 return -EFAULT;
2684
2685 /* Ignore accesses to kernel.version */
2686 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2687 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002688
2689 if (msg_count < 5) {
2690 msg_count++;
2691 printk(KERN_INFO
2692 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002693 "system call with ", current->comm);
2694 for (i = 0; i < tmp.nlen; i++)
2695 printk("%d.", name[i]);
2696 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002697 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002698out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 return -ENOSYS;
2700}
2701
2702int sysctl_string(ctl_table *table, int __user *name, int nlen,
2703 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002704 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705{
2706 return -ENOSYS;
2707}
2708
2709int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2710 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002711 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712{
2713 return -ENOSYS;
2714}
2715
2716int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2717 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002718 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719{
2720 return -ENOSYS;
2721}
2722
2723int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2724 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002725 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726{
2727 return -ENOSYS;
2728}
2729
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002730static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2731 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002732 void __user *newval, size_t newlen)
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002733{
2734 return -ENOSYS;
2735}
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002736static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2737 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002738 void __user *newval, size_t newlen)
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002739{
2740 return -ENOSYS;
2741}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002742#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743
2744/*
2745 * No sense putting this after each symbol definition, twice,
2746 * exception granted :-)
2747 */
2748EXPORT_SYMBOL(proc_dointvec);
2749EXPORT_SYMBOL(proc_dointvec_jiffies);
2750EXPORT_SYMBOL(proc_dointvec_minmax);
2751EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2752EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2753EXPORT_SYMBOL(proc_dostring);
2754EXPORT_SYMBOL(proc_doulongvec_minmax);
2755EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2756EXPORT_SYMBOL(register_sysctl_table);
2757EXPORT_SYMBOL(sysctl_intvec);
2758EXPORT_SYMBOL(sysctl_jiffies);
2759EXPORT_SYMBOL(sysctl_ms_jiffies);
2760EXPORT_SYMBOL(sysctl_string);
2761EXPORT_SYMBOL(unregister_sysctl_table);