blob: 025fcb3c66f87ce7b81c6dc6b3271dc28cbd5085 [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
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,
149 void __user *newval, size_t newlen, void **context);
150#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);
1246 void *context = NULL;
Al Viro330d57f2005-11-04 10:18:40 +00001247
1248 if (!use_table(head))
1249 continue;
1250
1251 spin_unlock(&sysctl_lock);
1252
1253 error = parse_table(name, nlen, oldval, oldlenp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 newval, newlen, head->ctl_table,
1255 &context);
Jesper Juhl5a6b4542005-06-25 14:58:48 -07001256 kfree(context);
Al Viro330d57f2005-11-04 10:18:40 +00001257
1258 spin_lock(&sysctl_lock);
1259 unuse_table(head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 if (error != -ENOTDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001261 break;
1262 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1263 spin_unlock(&sysctl_lock);
1264 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
1267asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1268{
1269 struct __sysctl_args tmp;
1270 int error;
1271
1272 if (copy_from_user(&tmp, args, sizeof(tmp)))
1273 return -EFAULT;
1274
1275 lock_kernel();
1276 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1277 tmp.newval, tmp.newlen);
1278 unlock_kernel();
1279 return error;
1280}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001281#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
1283/*
1284 * ctl_perm does NOT grant the superuser all rights automatically, because
1285 * some sysctl variables are readonly even to root.
1286 */
1287
1288static int test_perm(int mode, int op)
1289{
1290 if (!current->euid)
1291 mode >>= 6;
1292 else if (in_egroup_p(0))
1293 mode >>= 3;
1294 if ((mode & op & 0007) == op)
1295 return 0;
1296 return -EACCES;
1297}
1298
1299static inline int ctl_perm(ctl_table *table, int op)
1300{
1301 int error;
1302 error = security_sysctl(table, op);
1303 if (error)
1304 return error;
1305 return test_perm(table->mode, op);
1306}
1307
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001308#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309static int parse_table(int __user *name, int nlen,
1310 void __user *oldval, size_t __user *oldlenp,
1311 void __user *newval, size_t newlen,
1312 ctl_table *table, void **context)
1313{
1314 int n;
1315repeat:
1316 if (!nlen)
1317 return -ENOTDIR;
1318 if (get_user(n, name))
1319 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001320 for ( ; table->ctl_name || table->procname; table++) {
1321 if (!table->ctl_name)
1322 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1324 int error;
1325 if (table->child) {
1326 if (ctl_perm(table, 001))
1327 return -EPERM;
1328 if (table->strategy) {
1329 error = table->strategy(
1330 table, name, nlen,
1331 oldval, oldlenp,
1332 newval, newlen, context);
1333 if (error)
1334 return error;
1335 }
1336 name++;
1337 nlen--;
1338 table = table->child;
1339 goto repeat;
1340 }
1341 error = do_sysctl_strategy(table, name, nlen,
1342 oldval, oldlenp,
1343 newval, newlen, context);
1344 return error;
1345 }
1346 }
1347 return -ENOTDIR;
1348}
1349
1350/* Perform the actual read/write of a sysctl table entry. */
1351int do_sysctl_strategy (ctl_table *table,
1352 int __user *name, int nlen,
1353 void __user *oldval, size_t __user *oldlenp,
1354 void __user *newval, size_t newlen, void **context)
1355{
1356 int op = 0, rc;
1357 size_t len;
1358
1359 if (oldval)
1360 op |= 004;
1361 if (newval)
1362 op |= 002;
1363 if (ctl_perm(table, op))
1364 return -EPERM;
1365
1366 if (table->strategy) {
1367 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1368 newval, newlen, context);
1369 if (rc < 0)
1370 return rc;
1371 if (rc > 0)
1372 return 0;
1373 }
1374
1375 /* If there is no strategy routine, or if the strategy returns
1376 * zero, proceed with automatic r/w */
1377 if (table->data && table->maxlen) {
1378 if (oldval && oldlenp) {
1379 if (get_user(len, oldlenp))
1380 return -EFAULT;
1381 if (len) {
1382 if (len > table->maxlen)
1383 len = table->maxlen;
1384 if(copy_to_user(oldval, table->data, len))
1385 return -EFAULT;
1386 if(put_user(len, oldlenp))
1387 return -EFAULT;
1388 }
1389 }
1390 if (newval && newlen) {
1391 len = newlen;
1392 if (len > table->maxlen)
1393 len = table->maxlen;
1394 if(copy_from_user(table->data, newval, len))
1395 return -EFAULT;
1396 }
1397 }
1398 return 0;
1399}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001400#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
1402/**
1403 * register_sysctl_table - register a sysctl hierarchy
1404 * @table: the top-level table structure
1405 * @insert_at_head: whether the entry should be inserted in front or at the end
1406 *
1407 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1408 * array. An entry with a ctl_name of 0 terminates the table.
1409 *
1410 * The members of the &ctl_table structure are used as follows:
1411 *
1412 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1413 * must be unique within that level of sysctl
1414 *
1415 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1416 * enter a sysctl file
1417 *
1418 * data - a pointer to data for use by proc_handler
1419 *
1420 * maxlen - the maximum size in bytes of the data
1421 *
1422 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1423 *
1424 * child - a pointer to the child sysctl table if this entry is a directory, or
1425 * %NULL.
1426 *
1427 * proc_handler - the text handler routine (described below)
1428 *
1429 * strategy - the strategy routine (described below)
1430 *
1431 * de - for internal use by the sysctl routines
1432 *
1433 * extra1, extra2 - extra pointers usable by the proc handler routines
1434 *
1435 * Leaf nodes in the sysctl tree will be represented by a single file
1436 * under /proc; non-leaf nodes will be represented by directories.
1437 *
1438 * sysctl(2) can automatically manage read and write requests through
1439 * the sysctl table. The data and maxlen fields of the ctl_table
1440 * struct enable minimal validation of the values being written to be
1441 * performed, and the mode field allows minimal authentication.
1442 *
1443 * More sophisticated management can be enabled by the provision of a
1444 * strategy routine with the table entry. This will be called before
1445 * any automatic read or write of the data is performed.
1446 *
1447 * The strategy routine may return
1448 *
1449 * < 0 - Error occurred (error is passed to user process)
1450 *
1451 * 0 - OK - proceed with automatic read or write.
1452 *
1453 * > 0 - OK - read or write has been done by the strategy routine, so
1454 * return immediately.
1455 *
1456 * There must be a proc_handler routine for any terminal nodes
1457 * mirrored under /proc/sys (non-terminals are handled by a built-in
1458 * directory handler). Several default handlers are available to
1459 * cover common cases -
1460 *
1461 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1462 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1463 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1464 *
1465 * It is the handler's job to read the input buffer from user memory
1466 * and process it. The handler should return 0 on success.
1467 *
1468 * This routine returns %NULL on a failure to register, and a pointer
1469 * to the table header on success.
1470 */
1471struct ctl_table_header *register_sysctl_table(ctl_table * table,
1472 int insert_at_head)
1473{
1474 struct ctl_table_header *tmp;
1475 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1476 if (!tmp)
1477 return NULL;
1478 tmp->ctl_table = table;
1479 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001480 tmp->used = 0;
1481 tmp->unregistering = NULL;
1482 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 if (insert_at_head)
1484 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1485 else
1486 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001487 spin_unlock(&sysctl_lock);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001488#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001489 register_proc_table(table, proc_sys_root, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490#endif
1491 return tmp;
1492}
1493
1494/**
1495 * unregister_sysctl_table - unregister a sysctl table hierarchy
1496 * @header: the header returned from register_sysctl_table
1497 *
1498 * Unregisters the sysctl table and all children. proc entries may not
1499 * actually be removed until they are no longer used by anyone.
1500 */
1501void unregister_sysctl_table(struct ctl_table_header * header)
1502{
Al Viro330d57f2005-11-04 10:18:40 +00001503 might_sleep();
1504 spin_lock(&sysctl_lock);
1505 start_unregistering(header);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001506#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 unregister_proc_table(header->ctl_table, proc_sys_root);
1508#endif
Al Viro330d57f2005-11-04 10:18:40 +00001509 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 kfree(header);
1511}
1512
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001513#else /* !CONFIG_SYSCTL */
1514struct ctl_table_header * register_sysctl_table(ctl_table * table,
1515 int insert_at_head)
1516{
1517 return NULL;
1518}
1519
1520void unregister_sysctl_table(struct ctl_table_header * table)
1521{
1522}
1523
1524#endif /* CONFIG_SYSCTL */
1525
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526/*
1527 * /proc/sys support
1528 */
1529
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001530#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
1532/* Scan the sysctl entries in table and add them all into /proc */
Al Viro330d57f2005-11-04 10:18:40 +00001533static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534{
1535 struct proc_dir_entry *de;
1536 int len;
1537 mode_t mode;
1538
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001539 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 /* Can't do anything without a proc name. */
1541 if (!table->procname)
1542 continue;
1543 /* Maybe we can't do anything with it... */
1544 if (!table->proc_handler && !table->child) {
1545 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1546 table->procname);
1547 continue;
1548 }
1549
1550 len = strlen(table->procname);
1551 mode = table->mode;
1552
1553 de = NULL;
1554 if (table->proc_handler)
1555 mode |= S_IFREG;
1556 else {
1557 mode |= S_IFDIR;
1558 for (de = root->subdir; de; de = de->next) {
1559 if (proc_match(len, table->procname, de))
1560 break;
1561 }
1562 /* If the subdir exists already, de is non-NULL */
1563 }
1564
1565 if (!de) {
1566 de = create_proc_entry(table->procname, mode, root);
1567 if (!de)
1568 continue;
Al Viro330d57f2005-11-04 10:18:40 +00001569 de->set = set;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 de->data = (void *) table;
1571 if (table->proc_handler)
1572 de->proc_fops = &proc_sys_file_operations;
1573 }
1574 table->de = de;
1575 if (de->mode & S_IFDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001576 register_proc_table(table->child, de, set);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 }
1578}
1579
1580/*
1581 * Unregister a /proc sysctl table and any subdirectories.
1582 */
1583static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1584{
1585 struct proc_dir_entry *de;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001586 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 if (!(de = table->de))
1588 continue;
1589 if (de->mode & S_IFDIR) {
1590 if (!table->child) {
1591 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1592 continue;
1593 }
1594 unregister_proc_table(table->child, de);
1595
1596 /* Don't unregister directories which still have entries.. */
1597 if (de->subdir)
1598 continue;
1599 }
1600
Al Viro330d57f2005-11-04 10:18:40 +00001601 /*
1602 * In any case, mark the entry as goner; we'll keep it
1603 * around if it's busy, but we'll know to do nothing with
1604 * its fields. We are under sysctl_lock here.
1605 */
1606 de->data = NULL;
1607
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 /* Don't unregister proc entries that are still being used.. */
1609 if (atomic_read(&de->count))
1610 continue;
1611
1612 table->de = NULL;
1613 remove_proc_entry(table->procname, root);
1614 }
1615}
1616
1617static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1618 size_t count, loff_t *ppos)
1619{
1620 int op;
Josef "Jeff" Sipekf3a43f32006-12-08 02:36:43 -08001621 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 struct ctl_table *table;
1623 size_t res;
Al Viro330d57f2005-11-04 10:18:40 +00001624 ssize_t error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Al Viro330d57f2005-11-04 10:18:40 +00001626 spin_lock(&sysctl_lock);
1627 if (de && de->data && use_table(de->set)) {
1628 /*
1629 * at that point we know that sysctl was not unregistered
1630 * and won't be until we finish
1631 */
1632 spin_unlock(&sysctl_lock);
1633 table = (struct ctl_table *) de->data;
1634 if (!table || !table->proc_handler)
1635 goto out;
1636 error = -EPERM;
1637 op = (write ? 002 : 004);
1638 if (ctl_perm(table, op))
1639 goto out;
1640
1641 /* careful: calling conventions are nasty here */
1642 res = count;
1643 error = (*table->proc_handler)(table, write, file,
1644 buf, &res, ppos);
1645 if (!error)
1646 error = res;
1647 out:
1648 spin_lock(&sysctl_lock);
1649 unuse_table(de->set);
1650 }
1651 spin_unlock(&sysctl_lock);
1652 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
1655static int proc_opensys(struct inode *inode, struct file *file)
1656{
1657 if (file->f_mode & FMODE_WRITE) {
1658 /*
1659 * sysctl entries that are not writable,
1660 * are _NOT_ writable, capabilities or not.
1661 */
1662 if (!(inode->i_mode & S_IWUSR))
1663 return -EPERM;
1664 }
1665
1666 return 0;
1667}
1668
1669static ssize_t proc_readsys(struct file * file, char __user * buf,
1670 size_t count, loff_t *ppos)
1671{
1672 return do_rw_proc(0, file, buf, count, ppos);
1673}
1674
1675static ssize_t proc_writesys(struct file * file, const char __user * buf,
1676 size_t count, loff_t *ppos)
1677{
1678 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1679}
1680
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001681static int _proc_do_string(void* data, int maxlen, int write,
1682 struct file *filp, void __user *buffer,
1683 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001684{
1685 size_t len;
1686 char __user *p;
1687 char c;
1688
1689 if (!data || !maxlen || !*lenp ||
1690 (*ppos && !write)) {
1691 *lenp = 0;
1692 return 0;
1693 }
1694
1695 if (write) {
1696 len = 0;
1697 p = buffer;
1698 while (len < *lenp) {
1699 if (get_user(c, p++))
1700 return -EFAULT;
1701 if (c == 0 || c == '\n')
1702 break;
1703 len++;
1704 }
1705 if (len >= maxlen)
1706 len = maxlen-1;
1707 if(copy_from_user(data, buffer, len))
1708 return -EFAULT;
1709 ((char *) data)[len] = 0;
1710 *ppos += *lenp;
1711 } else {
1712 len = strlen(data);
1713 if (len > maxlen)
1714 len = maxlen;
1715 if (len > *lenp)
1716 len = *lenp;
1717 if (len)
1718 if(copy_to_user(buffer, data, len))
1719 return -EFAULT;
1720 if (len < *lenp) {
1721 if(put_user('\n', ((char __user *) buffer) + len))
1722 return -EFAULT;
1723 len++;
1724 }
1725 *lenp = len;
1726 *ppos += len;
1727 }
1728 return 0;
1729}
1730
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731/**
1732 * proc_dostring - read a string sysctl
1733 * @table: the sysctl table
1734 * @write: %TRUE if this is a write to the sysctl file
1735 * @filp: the file structure
1736 * @buffer: the user buffer
1737 * @lenp: the size of the user buffer
1738 * @ppos: file position
1739 *
1740 * Reads/writes a string from/to the user buffer. If the kernel
1741 * buffer provided is not large enough to hold the string, the
1742 * string is truncated. The copied string is %NULL-terminated.
1743 * If the string is being read by the user process, it is copied
1744 * and a newline '\n' is added. It is truncated if the buffer is
1745 * not large enough.
1746 *
1747 * Returns 0 on success.
1748 */
1749int proc_dostring(ctl_table *table, int write, struct file *filp,
1750 void __user *buffer, size_t *lenp, loff_t *ppos)
1751{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001752 return _proc_do_string(table->data, table->maxlen, write, filp,
1753 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754}
1755
1756/*
1757 * Special case of dostring for the UTS structure. This has locks
1758 * to observe. Should this be in kernel/sys.c ????
1759 */
Eric W. Biedermancf9f1512006-12-08 02:39:55 -08001760
Serge E. Hallyn8218c742006-10-02 02:18:15 -07001761static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 void __user *buffer, size_t *lenp, loff_t *ppos)
1763{
1764 int r;
Eric W. Biedermancf9f1512006-12-08 02:39:55 -08001765 void *which;
1766 which = get_uts(table, write);
1767 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1768 put_uts(table, write, which);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 return r;
1770}
1771
1772static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1773 int *valp,
1774 int write, void *data)
1775{
1776 if (write) {
1777 *valp = *negp ? -*lvalp : *lvalp;
1778 } else {
1779 int val = *valp;
1780 if (val < 0) {
1781 *negp = -1;
1782 *lvalp = (unsigned long)-val;
1783 } else {
1784 *negp = 0;
1785 *lvalp = (unsigned long)val;
1786 }
1787 }
1788 return 0;
1789}
1790
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001791static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1792 int write, struct file *filp, void __user *buffer,
1793 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1795 int write, void *data),
1796 void *data)
1797{
1798#define TMPBUFLEN 21
1799 int *i, vleft, first=1, neg, val;
1800 unsigned long lval;
1801 size_t left, len;
1802
1803 char buf[TMPBUFLEN], *p;
1804 char __user *s = buffer;
1805
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001806 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 (*ppos && !write)) {
1808 *lenp = 0;
1809 return 0;
1810 }
1811
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001812 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 vleft = table->maxlen / sizeof(*i);
1814 left = *lenp;
1815
1816 if (!conv)
1817 conv = do_proc_dointvec_conv;
1818
1819 for (; left && vleft--; i++, first=0) {
1820 if (write) {
1821 while (left) {
1822 char c;
1823 if (get_user(c, s))
1824 return -EFAULT;
1825 if (!isspace(c))
1826 break;
1827 left--;
1828 s++;
1829 }
1830 if (!left)
1831 break;
1832 neg = 0;
1833 len = left;
1834 if (len > sizeof(buf) - 1)
1835 len = sizeof(buf) - 1;
1836 if (copy_from_user(buf, s, len))
1837 return -EFAULT;
1838 buf[len] = 0;
1839 p = buf;
1840 if (*p == '-' && left > 1) {
1841 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001842 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 }
1844 if (*p < '0' || *p > '9')
1845 break;
1846
1847 lval = simple_strtoul(p, &p, 0);
1848
1849 len = p-buf;
1850 if ((len < left) && *p && !isspace(*p))
1851 break;
1852 if (neg)
1853 val = -val;
1854 s += len;
1855 left -= len;
1856
1857 if (conv(&neg, &lval, i, 1, data))
1858 break;
1859 } else {
1860 p = buf;
1861 if (!first)
1862 *p++ = '\t';
1863
1864 if (conv(&neg, &lval, i, 0, data))
1865 break;
1866
1867 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1868 len = strlen(buf);
1869 if (len > left)
1870 len = left;
1871 if(copy_to_user(s, buf, len))
1872 return -EFAULT;
1873 left -= len;
1874 s += len;
1875 }
1876 }
1877
1878 if (!write && !first && left) {
1879 if(put_user('\n', s))
1880 return -EFAULT;
1881 left--, s++;
1882 }
1883 if (write) {
1884 while (left) {
1885 char c;
1886 if (get_user(c, s++))
1887 return -EFAULT;
1888 if (!isspace(c))
1889 break;
1890 left--;
1891 }
1892 }
1893 if (write && first)
1894 return -EINVAL;
1895 *lenp -= left;
1896 *ppos += *lenp;
1897 return 0;
1898#undef TMPBUFLEN
1899}
1900
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001901static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1902 void __user *buffer, size_t *lenp, loff_t *ppos,
1903 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1904 int write, void *data),
1905 void *data)
1906{
1907 return __do_proc_dointvec(table->data, table, write, filp,
1908 buffer, lenp, ppos, conv, data);
1909}
1910
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911/**
1912 * proc_dointvec - read a vector of integers
1913 * @table: the sysctl table
1914 * @write: %TRUE if this is a write to the sysctl file
1915 * @filp: the file structure
1916 * @buffer: the user buffer
1917 * @lenp: the size of the user buffer
1918 * @ppos: file position
1919 *
1920 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1921 * values from/to the user buffer, treated as an ASCII string.
1922 *
1923 * Returns 0 on success.
1924 */
1925int proc_dointvec(ctl_table *table, int write, struct file *filp,
1926 void __user *buffer, size_t *lenp, loff_t *ppos)
1927{
1928 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1929 NULL,NULL);
1930}
1931
1932#define OP_SET 0
1933#define OP_AND 1
1934#define OP_OR 2
1935#define OP_MAX 3
1936#define OP_MIN 4
1937
1938static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1939 int *valp,
1940 int write, void *data)
1941{
1942 int op = *(int *)data;
1943 if (write) {
1944 int val = *negp ? -*lvalp : *lvalp;
1945 switch(op) {
1946 case OP_SET: *valp = val; break;
1947 case OP_AND: *valp &= val; break;
1948 case OP_OR: *valp |= val; break;
1949 case OP_MAX: if(*valp < val)
1950 *valp = val;
1951 break;
1952 case OP_MIN: if(*valp > val)
1953 *valp = val;
1954 break;
1955 }
1956 } else {
1957 int val = *valp;
1958 if (val < 0) {
1959 *negp = -1;
1960 *lvalp = (unsigned long)-val;
1961 } else {
1962 *negp = 0;
1963 *lvalp = (unsigned long)val;
1964 }
1965 }
1966 return 0;
1967}
1968
1969/*
1970 * init may raise the set.
1971 */
1972
1973int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1974 void __user *buffer, size_t *lenp, loff_t *ppos)
1975{
1976 int op;
1977
1978 if (!capable(CAP_SYS_MODULE)) {
1979 return -EPERM;
1980 }
1981
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001982 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1984 do_proc_dointvec_bset_conv,&op);
1985}
1986
1987struct do_proc_dointvec_minmax_conv_param {
1988 int *min;
1989 int *max;
1990};
1991
1992static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1993 int *valp,
1994 int write, void *data)
1995{
1996 struct do_proc_dointvec_minmax_conv_param *param = data;
1997 if (write) {
1998 int val = *negp ? -*lvalp : *lvalp;
1999 if ((param->min && *param->min > val) ||
2000 (param->max && *param->max < val))
2001 return -EINVAL;
2002 *valp = val;
2003 } else {
2004 int val = *valp;
2005 if (val < 0) {
2006 *negp = -1;
2007 *lvalp = (unsigned long)-val;
2008 } else {
2009 *negp = 0;
2010 *lvalp = (unsigned long)val;
2011 }
2012 }
2013 return 0;
2014}
2015
2016/**
2017 * proc_dointvec_minmax - read a vector of integers with min/max values
2018 * @table: the sysctl table
2019 * @write: %TRUE if this is a write to the sysctl file
2020 * @filp: the file structure
2021 * @buffer: the user buffer
2022 * @lenp: the size of the user buffer
2023 * @ppos: file position
2024 *
2025 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2026 * values from/to the user buffer, treated as an ASCII string.
2027 *
2028 * This routine will ensure the values are within the range specified by
2029 * table->extra1 (min) and table->extra2 (max).
2030 *
2031 * Returns 0 on success.
2032 */
2033int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2034 void __user *buffer, size_t *lenp, loff_t *ppos)
2035{
2036 struct do_proc_dointvec_minmax_conv_param param = {
2037 .min = (int *) table->extra1,
2038 .max = (int *) table->extra2,
2039 };
2040 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2041 do_proc_dointvec_minmax_conv, &param);
2042}
2043
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002044static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 struct file *filp,
2046 void __user *buffer,
2047 size_t *lenp, loff_t *ppos,
2048 unsigned long convmul,
2049 unsigned long convdiv)
2050{
2051#define TMPBUFLEN 21
2052 unsigned long *i, *min, *max, val;
2053 int vleft, first=1, neg;
2054 size_t len, left;
2055 char buf[TMPBUFLEN], *p;
2056 char __user *s = buffer;
2057
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002058 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 (*ppos && !write)) {
2060 *lenp = 0;
2061 return 0;
2062 }
2063
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002064 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 min = (unsigned long *) table->extra1;
2066 max = (unsigned long *) table->extra2;
2067 vleft = table->maxlen / sizeof(unsigned long);
2068 left = *lenp;
2069
2070 for (; left && vleft--; i++, min++, max++, first=0) {
2071 if (write) {
2072 while (left) {
2073 char c;
2074 if (get_user(c, s))
2075 return -EFAULT;
2076 if (!isspace(c))
2077 break;
2078 left--;
2079 s++;
2080 }
2081 if (!left)
2082 break;
2083 neg = 0;
2084 len = left;
2085 if (len > TMPBUFLEN-1)
2086 len = TMPBUFLEN-1;
2087 if (copy_from_user(buf, s, len))
2088 return -EFAULT;
2089 buf[len] = 0;
2090 p = buf;
2091 if (*p == '-' && left > 1) {
2092 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002093 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 }
2095 if (*p < '0' || *p > '9')
2096 break;
2097 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2098 len = p-buf;
2099 if ((len < left) && *p && !isspace(*p))
2100 break;
2101 if (neg)
2102 val = -val;
2103 s += len;
2104 left -= len;
2105
2106 if(neg)
2107 continue;
2108 if ((min && val < *min) || (max && val > *max))
2109 continue;
2110 *i = val;
2111 } else {
2112 p = buf;
2113 if (!first)
2114 *p++ = '\t';
2115 sprintf(p, "%lu", convdiv * (*i) / convmul);
2116 len = strlen(buf);
2117 if (len > left)
2118 len = left;
2119 if(copy_to_user(s, buf, len))
2120 return -EFAULT;
2121 left -= len;
2122 s += len;
2123 }
2124 }
2125
2126 if (!write && !first && left) {
2127 if(put_user('\n', s))
2128 return -EFAULT;
2129 left--, s++;
2130 }
2131 if (write) {
2132 while (left) {
2133 char c;
2134 if (get_user(c, s++))
2135 return -EFAULT;
2136 if (!isspace(c))
2137 break;
2138 left--;
2139 }
2140 }
2141 if (write && first)
2142 return -EINVAL;
2143 *lenp -= left;
2144 *ppos += *lenp;
2145 return 0;
2146#undef TMPBUFLEN
2147}
2148
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002149static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2150 struct file *filp,
2151 void __user *buffer,
2152 size_t *lenp, loff_t *ppos,
2153 unsigned long convmul,
2154 unsigned long convdiv)
2155{
2156 return __do_proc_doulongvec_minmax(table->data, table, write,
2157 filp, buffer, lenp, ppos, convmul, convdiv);
2158}
2159
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160/**
2161 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2162 * @table: the sysctl table
2163 * @write: %TRUE if this is a write to the sysctl file
2164 * @filp: the file structure
2165 * @buffer: the user buffer
2166 * @lenp: the size of the user buffer
2167 * @ppos: file position
2168 *
2169 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2170 * values from/to the user buffer, treated as an ASCII string.
2171 *
2172 * This routine will ensure the values are within the range specified by
2173 * table->extra1 (min) and table->extra2 (max).
2174 *
2175 * Returns 0 on success.
2176 */
2177int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2178 void __user *buffer, size_t *lenp, loff_t *ppos)
2179{
2180 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2181}
2182
2183/**
2184 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2185 * @table: the sysctl table
2186 * @write: %TRUE if this is a write to the sysctl file
2187 * @filp: the file structure
2188 * @buffer: the user buffer
2189 * @lenp: the size of the user buffer
2190 * @ppos: file position
2191 *
2192 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2193 * values from/to the user buffer, treated as an ASCII string. The values
2194 * are treated as milliseconds, and converted to jiffies when they are stored.
2195 *
2196 * This routine will ensure the values are within the range specified by
2197 * table->extra1 (min) and table->extra2 (max).
2198 *
2199 * Returns 0 on success.
2200 */
2201int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2202 struct file *filp,
2203 void __user *buffer,
2204 size_t *lenp, loff_t *ppos)
2205{
2206 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2207 lenp, ppos, HZ, 1000l);
2208}
2209
2210
2211static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2212 int *valp,
2213 int write, void *data)
2214{
2215 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002216 if (*lvalp > LONG_MAX / HZ)
2217 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2219 } else {
2220 int val = *valp;
2221 unsigned long lval;
2222 if (val < 0) {
2223 *negp = -1;
2224 lval = (unsigned long)-val;
2225 } else {
2226 *negp = 0;
2227 lval = (unsigned long)val;
2228 }
2229 *lvalp = lval / HZ;
2230 }
2231 return 0;
2232}
2233
2234static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2235 int *valp,
2236 int write, void *data)
2237{
2238 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002239 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2240 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2242 } else {
2243 int val = *valp;
2244 unsigned long lval;
2245 if (val < 0) {
2246 *negp = -1;
2247 lval = (unsigned long)-val;
2248 } else {
2249 *negp = 0;
2250 lval = (unsigned long)val;
2251 }
2252 *lvalp = jiffies_to_clock_t(lval);
2253 }
2254 return 0;
2255}
2256
2257static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2258 int *valp,
2259 int write, void *data)
2260{
2261 if (write) {
2262 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2263 } else {
2264 int val = *valp;
2265 unsigned long lval;
2266 if (val < 0) {
2267 *negp = -1;
2268 lval = (unsigned long)-val;
2269 } else {
2270 *negp = 0;
2271 lval = (unsigned long)val;
2272 }
2273 *lvalp = jiffies_to_msecs(lval);
2274 }
2275 return 0;
2276}
2277
2278/**
2279 * proc_dointvec_jiffies - read a vector of integers as seconds
2280 * @table: the sysctl table
2281 * @write: %TRUE if this is a write to the sysctl file
2282 * @filp: the file structure
2283 * @buffer: the user buffer
2284 * @lenp: the size of the user buffer
2285 * @ppos: file position
2286 *
2287 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2288 * values from/to the user buffer, treated as an ASCII string.
2289 * The values read are assumed to be in seconds, and are converted into
2290 * jiffies.
2291 *
2292 * Returns 0 on success.
2293 */
2294int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2295 void __user *buffer, size_t *lenp, loff_t *ppos)
2296{
2297 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2298 do_proc_dointvec_jiffies_conv,NULL);
2299}
2300
2301/**
2302 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2303 * @table: the sysctl table
2304 * @write: %TRUE if this is a write to the sysctl file
2305 * @filp: the file structure
2306 * @buffer: the user buffer
2307 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002308 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 *
2310 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2311 * values from/to the user buffer, treated as an ASCII string.
2312 * The values read are assumed to be in 1/USER_HZ seconds, and
2313 * are converted into jiffies.
2314 *
2315 * Returns 0 on success.
2316 */
2317int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2318 void __user *buffer, size_t *lenp, loff_t *ppos)
2319{
2320 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2321 do_proc_dointvec_userhz_jiffies_conv,NULL);
2322}
2323
2324/**
2325 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2326 * @table: the sysctl table
2327 * @write: %TRUE if this is a write to the sysctl file
2328 * @filp: the file structure
2329 * @buffer: the user buffer
2330 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002331 * @ppos: file position
2332 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 *
2334 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2335 * values from/to the user buffer, treated as an ASCII string.
2336 * The values read are assumed to be in 1/1000 seconds, and
2337 * are converted into jiffies.
2338 *
2339 * Returns 0 on success.
2340 */
2341int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2342 void __user *buffer, size_t *lenp, loff_t *ppos)
2343{
2344 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2345 do_proc_dointvec_ms_jiffies_conv, NULL);
2346}
2347
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002348#ifdef CONFIG_SYSVIPC
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002349static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2350 void __user *buffer, size_t *lenp, loff_t *ppos)
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002351{
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002352 void *which;
2353 which = get_ipc(table, write);
2354 return __do_proc_dointvec(which, table, write, filp, buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002355 lenp, ppos, NULL, NULL);
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002356}
2357
2358static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2359 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2360{
2361 void *which;
2362 which = get_ipc(table, write);
2363 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002364 lenp, ppos, 1l, 1l);
2365}
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002366
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002367#endif
2368
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002369static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2370 void __user *buffer, size_t *lenp, loff_t *ppos)
2371{
2372 struct pid *new_pid;
2373 pid_t tmp;
2374 int r;
2375
2376 tmp = pid_nr(cad_pid);
2377
2378 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2379 lenp, ppos, NULL, NULL);
2380 if (r || !write)
2381 return r;
2382
2383 new_pid = find_get_pid(tmp);
2384 if (!new_pid)
2385 return -ESRCH;
2386
2387 put_pid(xchg(&cad_pid, new_pid));
2388 return 0;
2389}
2390
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391#else /* CONFIG_PROC_FS */
2392
2393int proc_dostring(ctl_table *table, int write, struct file *filp,
2394 void __user *buffer, size_t *lenp, loff_t *ppos)
2395{
2396 return -ENOSYS;
2397}
2398
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002399static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2400 void __user *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401{
2402 return -ENOSYS;
2403}
2404
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002405#ifdef CONFIG_SYSVIPC
2406static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2407 void __user *buffer, size_t *lenp, loff_t *ppos)
2408{
2409 return -ENOSYS;
2410}
2411#endif
2412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413int proc_dointvec(ctl_table *table, int write, struct file *filp,
2414 void __user *buffer, size_t *lenp, loff_t *ppos)
2415{
2416 return -ENOSYS;
2417}
2418
2419int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2420 void __user *buffer, size_t *lenp, loff_t *ppos)
2421{
2422 return -ENOSYS;
2423}
2424
2425int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2426 void __user *buffer, size_t *lenp, loff_t *ppos)
2427{
2428 return -ENOSYS;
2429}
2430
2431int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2432 void __user *buffer, size_t *lenp, loff_t *ppos)
2433{
2434 return -ENOSYS;
2435}
2436
2437int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2438 void __user *buffer, size_t *lenp, loff_t *ppos)
2439{
2440 return -ENOSYS;
2441}
2442
2443int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2444 void __user *buffer, size_t *lenp, loff_t *ppos)
2445{
2446 return -ENOSYS;
2447}
2448
2449int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2450 void __user *buffer, size_t *lenp, loff_t *ppos)
2451{
2452 return -ENOSYS;
2453}
2454
2455int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2456 struct file *filp,
2457 void __user *buffer,
2458 size_t *lenp, loff_t *ppos)
2459{
2460 return -ENOSYS;
2461}
2462
2463
2464#endif /* CONFIG_PROC_FS */
2465
2466
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002467#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468/*
2469 * General sysctl support routines
2470 */
2471
2472/* The generic string strategy routine: */
2473int sysctl_string(ctl_table *table, int __user *name, int nlen,
2474 void __user *oldval, size_t __user *oldlenp,
2475 void __user *newval, size_t newlen, void **context)
2476{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 if (!table->data || !table->maxlen)
2478 return -ENOTDIR;
2479
2480 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002481 size_t bufsize;
2482 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002484 if (bufsize) {
2485 size_t len = strlen(table->data), copied;
2486
2487 /* This shouldn't trigger for a well-formed sysctl */
2488 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002490
2491 /* Copy up to a max of bufsize-1 bytes of the string */
2492 copied = (len >= bufsize) ? bufsize - 1 : len;
2493
2494 if (copy_to_user(oldval, table->data, copied) ||
2495 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002497 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 return -EFAULT;
2499 }
2500 }
2501 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002502 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 if (len > table->maxlen)
2504 len = table->maxlen;
2505 if(copy_from_user(table->data, newval, len))
2506 return -EFAULT;
2507 if (len == table->maxlen)
2508 len--;
2509 ((char *) table->data)[len] = 0;
2510 }
Yi Yang82c9df82005-12-30 16:37:10 +08002511 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512}
2513
2514/*
2515 * This function makes sure that all of the integers in the vector
2516 * are between the minimum and maximum values given in the arrays
2517 * table->extra1 and table->extra2, respectively.
2518 */
2519int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2520 void __user *oldval, size_t __user *oldlenp,
2521 void __user *newval, size_t newlen, void **context)
2522{
2523
2524 if (newval && newlen) {
2525 int __user *vec = (int __user *) newval;
2526 int *min = (int *) table->extra1;
2527 int *max = (int *) table->extra2;
2528 size_t length;
2529 int i;
2530
2531 if (newlen % sizeof(int) != 0)
2532 return -EINVAL;
2533
2534 if (!table->extra1 && !table->extra2)
2535 return 0;
2536
2537 if (newlen > table->maxlen)
2538 newlen = table->maxlen;
2539 length = newlen / sizeof(int);
2540
2541 for (i = 0; i < length; i++) {
2542 int value;
2543 if (get_user(value, vec + i))
2544 return -EFAULT;
2545 if (min && value < min[i])
2546 return -EINVAL;
2547 if (max && value > max[i])
2548 return -EINVAL;
2549 }
2550 }
2551 return 0;
2552}
2553
2554/* Strategy function to convert jiffies to seconds */
2555int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2556 void __user *oldval, size_t __user *oldlenp,
2557 void __user *newval, size_t newlen, void **context)
2558{
2559 if (oldval) {
2560 size_t olen;
2561 if (oldlenp) {
2562 if (get_user(olen, oldlenp))
2563 return -EFAULT;
2564 if (olen!=sizeof(int))
2565 return -EINVAL;
2566 }
2567 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2568 (oldlenp && put_user(sizeof(int),oldlenp)))
2569 return -EFAULT;
2570 }
2571 if (newval && newlen) {
2572 int new;
2573 if (newlen != sizeof(int))
2574 return -EINVAL;
2575 if (get_user(new, (int __user *)newval))
2576 return -EFAULT;
2577 *(int *)(table->data) = new*HZ;
2578 }
2579 return 1;
2580}
2581
2582/* Strategy function to convert jiffies to seconds */
2583int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2584 void __user *oldval, size_t __user *oldlenp,
2585 void __user *newval, size_t newlen, void **context)
2586{
2587 if (oldval) {
2588 size_t olen;
2589 if (oldlenp) {
2590 if (get_user(olen, oldlenp))
2591 return -EFAULT;
2592 if (olen!=sizeof(int))
2593 return -EINVAL;
2594 }
2595 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2596 (oldlenp && put_user(sizeof(int),oldlenp)))
2597 return -EFAULT;
2598 }
2599 if (newval && newlen) {
2600 int new;
2601 if (newlen != sizeof(int))
2602 return -EINVAL;
2603 if (get_user(new, (int __user *)newval))
2604 return -EFAULT;
2605 *(int *)(table->data) = msecs_to_jiffies(new);
2606 }
2607 return 1;
2608}
2609
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002610
2611/* The generic string strategy routine: */
2612static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2613 void __user *oldval, size_t __user *oldlenp,
2614 void __user *newval, size_t newlen, void **context)
2615{
2616 struct ctl_table uts_table;
2617 int r, write;
2618 write = newval && newlen;
2619 memcpy(&uts_table, table, sizeof(uts_table));
2620 uts_table.data = get_uts(table, write);
2621 r = sysctl_string(&uts_table, name, nlen,
2622 oldval, oldlenp, newval, newlen, context);
2623 put_uts(table, write, uts_table.data);
2624 return r;
2625}
2626
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002627#ifdef CONFIG_SYSVIPC
2628/* The generic sysctl ipc data routine. */
2629static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2630 void __user *oldval, size_t __user *oldlenp,
2631 void __user *newval, size_t newlen, void **context)
2632{
2633 size_t len;
2634 void *data;
2635
2636 /* Get out of I don't have a variable */
2637 if (!table->data || !table->maxlen)
2638 return -ENOTDIR;
2639
2640 data = get_ipc(table, 1);
2641 if (!data)
2642 return -ENOTDIR;
2643
2644 if (oldval && oldlenp) {
2645 if (get_user(len, oldlenp))
2646 return -EFAULT;
2647 if (len) {
2648 if (len > table->maxlen)
2649 len = table->maxlen;
2650 if (copy_to_user(oldval, data, len))
2651 return -EFAULT;
2652 if (put_user(len, oldlenp))
2653 return -EFAULT;
2654 }
2655 }
2656
2657 if (newval && newlen) {
2658 if (newlen > table->maxlen)
2659 newlen = table->maxlen;
2660
2661 if (copy_from_user(data, newval, newlen))
2662 return -EFAULT;
2663 }
2664 return 1;
2665}
2666#endif
2667
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002668#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
2670
2671asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2672{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002673 static int msg_count;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002674 struct __sysctl_args tmp;
2675 int name[CTL_MAXNAME];
2676 int i;
2677
2678 /* Read in the sysctl name for better debug message logging */
2679 if (copy_from_user(&tmp, args, sizeof(tmp)))
2680 return -EFAULT;
2681 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2682 return -ENOTDIR;
2683 for (i = 0; i < tmp.nlen; i++)
2684 if (get_user(name[i], tmp.name + i))
2685 return -EFAULT;
2686
2687 /* Ignore accesses to kernel.version */
2688 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2689 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002690
2691 if (msg_count < 5) {
2692 msg_count++;
2693 printk(KERN_INFO
2694 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002695 "system call with ", current->comm);
2696 for (i = 0; i < tmp.nlen; i++)
2697 printk("%d.", name[i]);
2698 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002699 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002700out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 return -ENOSYS;
2702}
2703
2704int sysctl_string(ctl_table *table, int __user *name, int nlen,
2705 void __user *oldval, size_t __user *oldlenp,
2706 void __user *newval, size_t newlen, void **context)
2707{
2708 return -ENOSYS;
2709}
2710
2711int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2712 void __user *oldval, size_t __user *oldlenp,
2713 void __user *newval, size_t newlen, void **context)
2714{
2715 return -ENOSYS;
2716}
2717
2718int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2719 void __user *oldval, size_t __user *oldlenp,
2720 void __user *newval, size_t newlen, void **context)
2721{
2722 return -ENOSYS;
2723}
2724
2725int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2726 void __user *oldval, size_t __user *oldlenp,
2727 void __user *newval, size_t newlen, void **context)
2728{
2729 return -ENOSYS;
2730}
2731
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002732static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2733 void __user *oldval, size_t __user *oldlenp,
2734 void __user *newval, size_t newlen, void **context)
2735{
2736 return -ENOSYS;
2737}
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002738static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2739 void __user *oldval, size_t __user *oldlenp,
2740 void __user *newval, size_t newlen, void **context)
2741{
2742 return -ENOSYS;
2743}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002744#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
2746/*
2747 * No sense putting this after each symbol definition, twice,
2748 * exception granted :-)
2749 */
2750EXPORT_SYMBOL(proc_dointvec);
2751EXPORT_SYMBOL(proc_dointvec_jiffies);
2752EXPORT_SYMBOL(proc_dointvec_minmax);
2753EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2754EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2755EXPORT_SYMBOL(proc_dostring);
2756EXPORT_SYMBOL(proc_doulongvec_minmax);
2757EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2758EXPORT_SYMBOL(register_sysctl_table);
2759EXPORT_SYMBOL(sysctl_intvec);
2760EXPORT_SYMBOL(sysctl_jiffies);
2761EXPORT_SYMBOL(sysctl_ms_jiffies);
2762EXPORT_SYMBOL(sysctl_string);
2763EXPORT_SYMBOL(unregister_sysctl_table);