blob: 8bff2c18fb5ae1f697cd764feb4d7fb963309f83 [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>
57#endif
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#if defined(CONFIG_SYSCTL)
60
61/* External variables not in a header file. */
62extern int C_A_D;
63extern int sysctl_overcommit_memory;
64extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070065extern int sysctl_panic_on_oom;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern int max_threads;
67extern int sysrq_enabled;
68extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070069extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int pid_max;
72extern int min_free_kbytes;
73extern int printk_ratelimit_jiffies;
74extern int printk_ratelimit_burst;
75extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080076extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080077extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020078extern int compat_log;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Linus Torvalds1da177e2005-04-16 15:20:36 -070080/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
81static int maxolduid = 65535;
82static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080083static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85static int ngroups_max = NGROUPS_MAX;
86
87#ifdef CONFIG_KMOD
88extern char modprobe_path[];
89#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#ifdef CONFIG_CHR_DEV_SG
91extern int sg_big_buff;
92#endif
93#ifdef CONFIG_SYSVIPC
Kirill Korotaevfcfbd542006-10-02 02:18:23 -070094static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
95 void __user *buffer, size_t *lenp, loff_t *ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#endif
97
98#ifdef __sparc__
99extern char reboot_command [];
100extern int stop_a_enabled;
101extern int scons_pwroff;
102#endif
103
104#ifdef __hppa__
105extern int pwrsw_enabled;
106extern int unaligned_enabled;
107#endif
108
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800109#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#ifdef CONFIG_MATHEMU
111extern int sysctl_ieee_emulation_warnings;
112#endif
113extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700114extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#endif
116
117extern int sysctl_hz_timer;
118
119#ifdef CONFIG_BSD_PROCESS_ACCT
120extern int acct_parm[];
121#endif
122
Jes Sorensend2b176e2006-02-28 09:42:23 -0800123#ifdef CONFIG_IA64
124extern int no_unaligned_warning;
125#endif
126
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700127#ifdef CONFIG_RT_MUTEXES
128extern int max_lock_depth;
129#endif
130
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700131#ifdef CONFIG_SYSCTL_SYSCALL
132static int parse_table(int __user *, int, void __user *, size_t __user *,
133 void __user *, size_t, ctl_table *, void **);
134#endif
135
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700136static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 void __user *buffer, size_t *lenp, loff_t *ppos);
138
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700139#ifdef CONFIG_PROC_SYSCTL
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700140static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
141 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700142#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144static ctl_table root_table[];
145static struct ctl_table_header root_table_header =
146 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
147
148static ctl_table kern_table[];
149static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150static ctl_table fs_table[];
151static ctl_table debug_table[];
152static ctl_table dev_table[];
153extern ctl_table random_table[];
154#ifdef CONFIG_UNIX98_PTYS
155extern ctl_table pty_table[];
156#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700157#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400158extern ctl_table inotify_table[];
159#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
162int sysctl_legacy_va_layout;
163#endif
164
165/* /proc declarations: */
166
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700167#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
170static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
171static int proc_opensys(struct inode *, struct file *);
172
173struct file_operations proc_sys_file_operations = {
174 .open = proc_opensys,
175 .read = proc_readsys,
176 .write = proc_writesys,
177};
178
179extern struct proc_dir_entry *proc_sys_root;
180
Al Viro330d57f2005-11-04 10:18:40 +0000181static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
183#endif
184
185/* The default sysctl tables: */
186
187static ctl_table root_table[] = {
188 {
189 .ctl_name = CTL_KERN,
190 .procname = "kernel",
191 .mode = 0555,
192 .child = kern_table,
193 },
194 {
195 .ctl_name = CTL_VM,
196 .procname = "vm",
197 .mode = 0555,
198 .child = vm_table,
199 },
200#ifdef CONFIG_NET
201 {
202 .ctl_name = CTL_NET,
203 .procname = "net",
204 .mode = 0555,
205 .child = net_table,
206 },
207#endif
208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 .ctl_name = CTL_FS,
210 .procname = "fs",
211 .mode = 0555,
212 .child = fs_table,
213 },
214 {
215 .ctl_name = CTL_DEBUG,
216 .procname = "debug",
217 .mode = 0555,
218 .child = debug_table,
219 },
220 {
221 .ctl_name = CTL_DEV,
222 .procname = "dev",
223 .mode = 0555,
224 .child = dev_table,
225 },
Robert Love0eeca282005-07-12 17:06:03 -0400226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 { .ctl_name = 0 }
228};
229
230static ctl_table kern_table[] = {
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700231#ifndef CONFIG_UTS_NS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 {
233 .ctl_name = KERN_OSTYPE,
234 .procname = "ostype",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700235 .data = init_uts_ns.name.sysname,
236 .maxlen = sizeof(init_uts_ns.name.sysname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700238 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 .strategy = &sysctl_string,
240 },
241 {
242 .ctl_name = KERN_OSRELEASE,
243 .procname = "osrelease",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700244 .data = init_uts_ns.name.release,
245 .maxlen = sizeof(init_uts_ns.name.release),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700247 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 .strategy = &sysctl_string,
249 },
250 {
251 .ctl_name = KERN_VERSION,
252 .procname = "version",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700253 .data = init_uts_ns.name.version,
254 .maxlen = sizeof(init_uts_ns.name.version),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700256 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 .strategy = &sysctl_string,
258 },
259 {
260 .ctl_name = KERN_NODENAME,
261 .procname = "hostname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700262 .data = init_uts_ns.name.nodename,
263 .maxlen = sizeof(init_uts_ns.name.nodename),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700265 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 .strategy = &sysctl_string,
267 },
268 {
269 .ctl_name = KERN_DOMAINNAME,
270 .procname = "domainname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700271 .data = init_uts_ns.name.domainname,
272 .maxlen = sizeof(init_uts_ns.name.domainname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700274 .proc_handler = &proc_do_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 .strategy = &sysctl_string,
276 },
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700277#else /* !CONFIG_UTS_NS */
278 {
279 .ctl_name = KERN_OSTYPE,
280 .procname = "ostype",
281 .data = NULL,
282 /* could maybe use __NEW_UTS_LEN here? */
283 .maxlen = FIELD_SIZEOF(struct new_utsname, sysname),
284 .mode = 0444,
285 .proc_handler = &proc_do_uts_string,
286 .strategy = &sysctl_string,
287 },
288 {
289 .ctl_name = KERN_OSRELEASE,
290 .procname = "osrelease",
291 .data = NULL,
292 .maxlen = FIELD_SIZEOF(struct new_utsname, release),
293 .mode = 0444,
294 .proc_handler = &proc_do_uts_string,
295 .strategy = &sysctl_string,
296 },
297 {
298 .ctl_name = KERN_VERSION,
299 .procname = "version",
300 .data = NULL,
301 .maxlen = FIELD_SIZEOF(struct new_utsname, version),
302 .mode = 0444,
303 .proc_handler = &proc_do_uts_string,
304 .strategy = &sysctl_string,
305 },
306 {
307 .ctl_name = KERN_NODENAME,
308 .procname = "hostname",
309 .data = NULL,
310 .maxlen = FIELD_SIZEOF(struct new_utsname, nodename),
311 .mode = 0644,
312 .proc_handler = &proc_do_uts_string,
313 .strategy = &sysctl_string,
314 },
315 {
316 .ctl_name = KERN_DOMAINNAME,
317 .procname = "domainname",
318 .data = NULL,
319 .maxlen = FIELD_SIZEOF(struct new_utsname, domainname),
320 .mode = 0644,
321 .proc_handler = &proc_do_uts_string,
322 .strategy = &sysctl_string,
323 },
324#endif /* !CONFIG_UTS_NS */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 {
326 .ctl_name = KERN_PANIC,
327 .procname = "panic",
328 .data = &panic_timeout,
329 .maxlen = sizeof(int),
330 .mode = 0644,
331 .proc_handler = &proc_dointvec,
332 },
333 {
334 .ctl_name = KERN_CORE_USES_PID,
335 .procname = "core_uses_pid",
336 .data = &core_uses_pid,
337 .maxlen = sizeof(int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341 {
342 .ctl_name = KERN_CORE_PATTERN,
343 .procname = "core_pattern",
344 .data = core_pattern,
Andi Kleend025c9d2006-09-30 23:29:28 -0700345 .maxlen = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 .mode = 0644,
347 .proc_handler = &proc_dostring,
348 .strategy = &sysctl_string,
349 },
350 {
351 .ctl_name = KERN_TAINTED,
352 .procname = "tainted",
353 .data = &tainted,
354 .maxlen = sizeof(int),
355 .mode = 0444,
356 .proc_handler = &proc_dointvec,
357 },
358 {
359 .ctl_name = KERN_CAP_BSET,
360 .procname = "cap-bound",
361 .data = &cap_bset,
362 .maxlen = sizeof(kernel_cap_t),
363 .mode = 0600,
364 .proc_handler = &proc_dointvec_bset,
365 },
366#ifdef CONFIG_BLK_DEV_INITRD
367 {
368 .ctl_name = KERN_REALROOTDEV,
369 .procname = "real-root-dev",
370 .data = &real_root_dev,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = &proc_dointvec,
374 },
375#endif
376#ifdef __sparc__
377 {
378 .ctl_name = KERN_SPARC_REBOOT,
379 .procname = "reboot-cmd",
380 .data = reboot_command,
381 .maxlen = 256,
382 .mode = 0644,
383 .proc_handler = &proc_dostring,
384 .strategy = &sysctl_string,
385 },
386 {
387 .ctl_name = KERN_SPARC_STOP_A,
388 .procname = "stop-a",
389 .data = &stop_a_enabled,
390 .maxlen = sizeof (int),
391 .mode = 0644,
392 .proc_handler = &proc_dointvec,
393 },
394 {
395 .ctl_name = KERN_SPARC_SCONS_PWROFF,
396 .procname = "scons-poweroff",
397 .data = &scons_pwroff,
398 .maxlen = sizeof (int),
399 .mode = 0644,
400 .proc_handler = &proc_dointvec,
401 },
402#endif
403#ifdef __hppa__
404 {
405 .ctl_name = KERN_HPPA_PWRSW,
406 .procname = "soft-power",
407 .data = &pwrsw_enabled,
408 .maxlen = sizeof (int),
409 .mode = 0644,
410 .proc_handler = &proc_dointvec,
411 },
412 {
413 .ctl_name = KERN_HPPA_UNALIGNED,
414 .procname = "unaligned-trap",
415 .data = &unaligned_enabled,
416 .maxlen = sizeof (int),
417 .mode = 0644,
418 .proc_handler = &proc_dointvec,
419 },
420#endif
421 {
422 .ctl_name = KERN_CTLALTDEL,
423 .procname = "ctrl-alt-del",
424 .data = &C_A_D,
425 .maxlen = sizeof(int),
426 .mode = 0644,
427 .proc_handler = &proc_dointvec,
428 },
429 {
430 .ctl_name = KERN_PRINTK,
431 .procname = "printk",
432 .data = &console_loglevel,
433 .maxlen = 4*sizeof(int),
434 .mode = 0644,
435 .proc_handler = &proc_dointvec,
436 },
437#ifdef CONFIG_KMOD
438 {
439 .ctl_name = KERN_MODPROBE,
440 .procname = "modprobe",
441 .data = &modprobe_path,
442 .maxlen = KMOD_PATH_LEN,
443 .mode = 0644,
444 .proc_handler = &proc_dostring,
445 .strategy = &sysctl_string,
446 },
447#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700448#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 {
450 .ctl_name = KERN_HOTPLUG,
451 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100452 .data = &uevent_helper,
453 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 .mode = 0644,
455 .proc_handler = &proc_dostring,
456 .strategy = &sysctl_string,
457 },
458#endif
459#ifdef CONFIG_CHR_DEV_SG
460 {
461 .ctl_name = KERN_SG_BIG_BUFF,
462 .procname = "sg-big-buff",
463 .data = &sg_big_buff,
464 .maxlen = sizeof (int),
465 .mode = 0444,
466 .proc_handler = &proc_dointvec,
467 },
468#endif
469#ifdef CONFIG_BSD_PROCESS_ACCT
470 {
471 .ctl_name = KERN_ACCT,
472 .procname = "acct",
473 .data = &acct_parm,
474 .maxlen = 3*sizeof(int),
475 .mode = 0644,
476 .proc_handler = &proc_dointvec,
477 },
478#endif
479#ifdef CONFIG_SYSVIPC
480 {
481 .ctl_name = KERN_SHMMAX,
482 .procname = "shmmax",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700483 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 .maxlen = sizeof (size_t),
485 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700486 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 },
488 {
489 .ctl_name = KERN_SHMALL,
490 .procname = "shmall",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700491 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 .maxlen = sizeof (size_t),
493 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700494 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 },
496 {
497 .ctl_name = KERN_SHMMNI,
498 .procname = "shmmni",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700499 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .maxlen = sizeof (int),
501 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700502 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 },
504 {
505 .ctl_name = KERN_MSGMAX,
506 .procname = "msgmax",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700507 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .maxlen = sizeof (int),
509 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700510 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 },
512 {
513 .ctl_name = KERN_MSGMNI,
514 .procname = "msgmni",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700515 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 .maxlen = sizeof (int),
517 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700518 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 },
520 {
521 .ctl_name = KERN_MSGMNB,
522 .procname = "msgmnb",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700523 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 .maxlen = sizeof (int),
525 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700526 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
528 {
529 .ctl_name = KERN_SEM,
530 .procname = "sem",
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700531 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 .maxlen = 4*sizeof (int),
533 .mode = 0644,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700534 .proc_handler = &proc_do_ipc_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 },
536#endif
537#ifdef CONFIG_MAGIC_SYSRQ
538 {
539 .ctl_name = KERN_SYSRQ,
540 .procname = "sysrq",
541 .data = &sysrq_enabled,
542 .maxlen = sizeof (int),
543 .mode = 0644,
544 .proc_handler = &proc_dointvec,
545 },
546#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700547#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 {
549 .ctl_name = KERN_CADPID,
550 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700551 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 .maxlen = sizeof (int),
553 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700554 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700556#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 {
558 .ctl_name = KERN_MAX_THREADS,
559 .procname = "threads-max",
560 .data = &max_threads,
561 .maxlen = sizeof(int),
562 .mode = 0644,
563 .proc_handler = &proc_dointvec,
564 },
565 {
566 .ctl_name = KERN_RANDOM,
567 .procname = "random",
568 .mode = 0555,
569 .child = random_table,
570 },
571#ifdef CONFIG_UNIX98_PTYS
572 {
573 .ctl_name = KERN_PTY,
574 .procname = "pty",
575 .mode = 0555,
576 .child = pty_table,
577 },
578#endif
579 {
580 .ctl_name = KERN_OVERFLOWUID,
581 .procname = "overflowuid",
582 .data = &overflowuid,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec_minmax,
586 .strategy = &sysctl_intvec,
587 .extra1 = &minolduid,
588 .extra2 = &maxolduid,
589 },
590 {
591 .ctl_name = KERN_OVERFLOWGID,
592 .procname = "overflowgid",
593 .data = &overflowgid,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec_minmax,
597 .strategy = &sysctl_intvec,
598 .extra1 = &minolduid,
599 .extra2 = &maxolduid,
600 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800601#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602#ifdef CONFIG_MATHEMU
603 {
604 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
605 .procname = "ieee_emulation_warnings",
606 .data = &sysctl_ieee_emulation_warnings,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec,
610 },
611#endif
612#ifdef CONFIG_NO_IDLE_HZ
613 {
614 .ctl_name = KERN_HZ_TIMER,
615 .procname = "hz_timer",
616 .data = &sysctl_hz_timer,
617 .maxlen = sizeof(int),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec,
620 },
621#endif
622 {
623 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
624 .procname = "userprocess_debug",
625 .data = &sysctl_userprocess_debug,
626 .maxlen = sizeof(int),
627 .mode = 0644,
628 .proc_handler = &proc_dointvec,
629 },
630#endif
631 {
632 .ctl_name = KERN_PIDMAX,
633 .procname = "pid_max",
634 .data = &pid_max,
635 .maxlen = sizeof (int),
636 .mode = 0644,
637 .proc_handler = &proc_dointvec_minmax,
638 .strategy = sysctl_intvec,
639 .extra1 = &pid_max_min,
640 .extra2 = &pid_max_max,
641 },
642 {
643 .ctl_name = KERN_PANIC_ON_OOPS,
644 .procname = "panic_on_oops",
645 .data = &panic_on_oops,
646 .maxlen = sizeof(int),
647 .mode = 0644,
648 .proc_handler = &proc_dointvec,
649 },
650 {
651 .ctl_name = KERN_PRINTK_RATELIMIT,
652 .procname = "printk_ratelimit",
653 .data = &printk_ratelimit_jiffies,
654 .maxlen = sizeof(int),
655 .mode = 0644,
656 .proc_handler = &proc_dointvec_jiffies,
657 .strategy = &sysctl_jiffies,
658 },
659 {
660 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
661 .procname = "printk_ratelimit_burst",
662 .data = &printk_ratelimit_burst,
663 .maxlen = sizeof(int),
664 .mode = 0644,
665 .proc_handler = &proc_dointvec,
666 },
667 {
668 .ctl_name = KERN_NGROUPS_MAX,
669 .procname = "ngroups_max",
670 .data = &ngroups_max,
671 .maxlen = sizeof (int),
672 .mode = 0444,
673 .proc_handler = &proc_dointvec,
674 },
675#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
676 {
677 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
678 .procname = "unknown_nmi_panic",
679 .data = &unknown_nmi_panic,
680 .maxlen = sizeof (int),
681 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200682 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 },
Don Zickus407984f2006-09-26 10:52:27 +0200684 {
685 .ctl_name = KERN_NMI_WATCHDOG,
686 .procname = "nmi_watchdog",
687 .data = &nmi_watchdog_enabled,
688 .maxlen = sizeof (int),
689 .mode = 0644,
690 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 },
692#endif
693#if defined(CONFIG_X86)
694 {
Don Zickus8da5add2006-09-26 10:52:27 +0200695 .ctl_name = KERN_PANIC_ON_NMI,
696 .procname = "panic_on_unrecovered_nmi",
697 .data = &panic_on_unrecovered_nmi,
698 .maxlen = sizeof(int),
699 .mode = 0644,
700 .proc_handler = &proc_dointvec,
701 },
702 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 .ctl_name = KERN_BOOTLOADER_TYPE,
704 .procname = "bootloader_type",
705 .data = &bootloader_type,
706 .maxlen = sizeof (int),
707 .mode = 0444,
708 .proc_handler = &proc_dointvec,
709 },
710#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800711#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 {
713 .ctl_name = KERN_RANDOMIZE,
714 .procname = "randomize_va_space",
715 .data = &randomize_va_space,
716 .maxlen = sizeof(int),
717 .mode = 0644,
718 .proc_handler = &proc_dointvec,
719 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800720#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800721#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700722 {
723 .ctl_name = KERN_SPIN_RETRY,
724 .procname = "spin_retry",
725 .data = &spin_retry,
726 .maxlen = sizeof (int),
727 .mode = 0644,
728 .proc_handler = &proc_dointvec,
729 },
730#endif
Pavel Machekc255d842006-02-20 18:27:58 -0800731#ifdef CONFIG_ACPI_SLEEP
732 {
733 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
734 .procname = "acpi_video_flags",
735 .data = &acpi_video_flags,
736 .maxlen = sizeof (unsigned long),
737 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800738 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800739 },
740#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800741#ifdef CONFIG_IA64
742 {
743 .ctl_name = KERN_IA64_UNALIGNED,
744 .procname = "ignore-unaligned-usertrap",
745 .data = &no_unaligned_warning,
746 .maxlen = sizeof (int),
747 .mode = 0644,
748 .proc_handler = &proc_dointvec,
749 },
750#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200751#ifdef CONFIG_COMPAT
752 {
753 .ctl_name = KERN_COMPAT_LOG,
754 .procname = "compat-log",
755 .data = &compat_log,
756 .maxlen = sizeof (int),
757 .mode = 0644,
758 .proc_handler = &proc_dointvec,
759 },
760#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700761#ifdef CONFIG_RT_MUTEXES
762 {
763 .ctl_name = KERN_MAX_LOCK_DEPTH,
764 .procname = "max_lock_depth",
765 .data = &max_lock_depth,
766 .maxlen = sizeof(int),
767 .mode = 0644,
768 .proc_handler = &proc_dointvec,
769 },
770#endif
771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 { .ctl_name = 0 }
773};
774
775/* Constants for minimum and maximum testing in vm_table.
776 We use these as one-element integer vectors. */
777static int zero;
778static int one_hundred = 100;
779
780
781static ctl_table vm_table[] = {
782 {
783 .ctl_name = VM_OVERCOMMIT_MEMORY,
784 .procname = "overcommit_memory",
785 .data = &sysctl_overcommit_memory,
786 .maxlen = sizeof(sysctl_overcommit_memory),
787 .mode = 0644,
788 .proc_handler = &proc_dointvec,
789 },
790 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700791 .ctl_name = VM_PANIC_ON_OOM,
792 .procname = "panic_on_oom",
793 .data = &sysctl_panic_on_oom,
794 .maxlen = sizeof(sysctl_panic_on_oom),
795 .mode = 0644,
796 .proc_handler = &proc_dointvec,
797 },
798 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .ctl_name = VM_OVERCOMMIT_RATIO,
800 .procname = "overcommit_ratio",
801 .data = &sysctl_overcommit_ratio,
802 .maxlen = sizeof(sysctl_overcommit_ratio),
803 .mode = 0644,
804 .proc_handler = &proc_dointvec,
805 },
806 {
807 .ctl_name = VM_PAGE_CLUSTER,
808 .procname = "page-cluster",
809 .data = &page_cluster,
810 .maxlen = sizeof(int),
811 .mode = 0644,
812 .proc_handler = &proc_dointvec,
813 },
814 {
815 .ctl_name = VM_DIRTY_BACKGROUND,
816 .procname = "dirty_background_ratio",
817 .data = &dirty_background_ratio,
818 .maxlen = sizeof(dirty_background_ratio),
819 .mode = 0644,
820 .proc_handler = &proc_dointvec_minmax,
821 .strategy = &sysctl_intvec,
822 .extra1 = &zero,
823 .extra2 = &one_hundred,
824 },
825 {
826 .ctl_name = VM_DIRTY_RATIO,
827 .procname = "dirty_ratio",
828 .data = &vm_dirty_ratio,
829 .maxlen = sizeof(vm_dirty_ratio),
830 .mode = 0644,
831 .proc_handler = &proc_dointvec_minmax,
832 .strategy = &sysctl_intvec,
833 .extra1 = &zero,
834 .extra2 = &one_hundred,
835 },
836 {
837 .ctl_name = VM_DIRTY_WB_CS,
838 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800839 .data = &dirty_writeback_interval,
840 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 .mode = 0644,
842 .proc_handler = &dirty_writeback_centisecs_handler,
843 },
844 {
845 .ctl_name = VM_DIRTY_EXPIRE_CS,
846 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800847 .data = &dirty_expire_interval,
848 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800850 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 },
852 {
853 .ctl_name = VM_NR_PDFLUSH_THREADS,
854 .procname = "nr_pdflush_threads",
855 .data = &nr_pdflush_threads,
856 .maxlen = sizeof nr_pdflush_threads,
857 .mode = 0444 /* read-only*/,
858 .proc_handler = &proc_dointvec,
859 },
860 {
861 .ctl_name = VM_SWAPPINESS,
862 .procname = "swappiness",
863 .data = &vm_swappiness,
864 .maxlen = sizeof(vm_swappiness),
865 .mode = 0644,
866 .proc_handler = &proc_dointvec_minmax,
867 .strategy = &sysctl_intvec,
868 .extra1 = &zero,
869 .extra2 = &one_hundred,
870 },
871#ifdef CONFIG_HUGETLB_PAGE
872 {
873 .ctl_name = VM_HUGETLB_PAGES,
874 .procname = "nr_hugepages",
875 .data = &max_huge_pages,
876 .maxlen = sizeof(unsigned long),
877 .mode = 0644,
878 .proc_handler = &hugetlb_sysctl_handler,
879 .extra1 = (void *)&hugetlb_zero,
880 .extra2 = (void *)&hugetlb_infinity,
881 },
882 {
883 .ctl_name = VM_HUGETLB_GROUP,
884 .procname = "hugetlb_shm_group",
885 .data = &sysctl_hugetlb_shm_group,
886 .maxlen = sizeof(gid_t),
887 .mode = 0644,
888 .proc_handler = &proc_dointvec,
889 },
890#endif
891 {
892 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
893 .procname = "lowmem_reserve_ratio",
894 .data = &sysctl_lowmem_reserve_ratio,
895 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
896 .mode = 0644,
897 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
898 .strategy = &sysctl_intvec,
899 },
900 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800901 .ctl_name = VM_DROP_PAGECACHE,
902 .procname = "drop_caches",
903 .data = &sysctl_drop_caches,
904 .maxlen = sizeof(int),
905 .mode = 0644,
906 .proc_handler = drop_caches_sysctl_handler,
907 .strategy = &sysctl_intvec,
908 },
909 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .ctl_name = VM_MIN_FREE_KBYTES,
911 .procname = "min_free_kbytes",
912 .data = &min_free_kbytes,
913 .maxlen = sizeof(min_free_kbytes),
914 .mode = 0644,
915 .proc_handler = &min_free_kbytes_sysctl_handler,
916 .strategy = &sysctl_intvec,
917 .extra1 = &zero,
918 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800919 {
920 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
921 .procname = "percpu_pagelist_fraction",
922 .data = &percpu_pagelist_fraction,
923 .maxlen = sizeof(percpu_pagelist_fraction),
924 .mode = 0644,
925 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
926 .strategy = &sysctl_intvec,
927 .extra1 = &min_percpu_pagelist_fract,
928 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929#ifdef CONFIG_MMU
930 {
931 .ctl_name = VM_MAX_MAP_COUNT,
932 .procname = "max_map_count",
933 .data = &sysctl_max_map_count,
934 .maxlen = sizeof(sysctl_max_map_count),
935 .mode = 0644,
936 .proc_handler = &proc_dointvec
937 },
938#endif
939 {
940 .ctl_name = VM_LAPTOP_MODE,
941 .procname = "laptop_mode",
942 .data = &laptop_mode,
943 .maxlen = sizeof(laptop_mode),
944 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800945 .proc_handler = &proc_dointvec_jiffies,
946 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 },
948 {
949 .ctl_name = VM_BLOCK_DUMP,
950 .procname = "block_dump",
951 .data = &block_dump,
952 .maxlen = sizeof(block_dump),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
955 .strategy = &sysctl_intvec,
956 .extra1 = &zero,
957 },
958 {
959 .ctl_name = VM_VFS_CACHE_PRESSURE,
960 .procname = "vfs_cache_pressure",
961 .data = &sysctl_vfs_cache_pressure,
962 .maxlen = sizeof(sysctl_vfs_cache_pressure),
963 .mode = 0644,
964 .proc_handler = &proc_dointvec,
965 .strategy = &sysctl_intvec,
966 .extra1 = &zero,
967 },
968#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
969 {
970 .ctl_name = VM_LEGACY_VA_LAYOUT,
971 .procname = "legacy_va_layout",
972 .data = &sysctl_legacy_va_layout,
973 .maxlen = sizeof(sysctl_legacy_va_layout),
974 .mode = 0644,
975 .proc_handler = &proc_dointvec,
976 .strategy = &sysctl_intvec,
977 .extra1 = &zero,
978 },
979#endif
980#ifdef CONFIG_SWAP
981 {
982 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
983 .procname = "swap_token_timeout",
984 .data = &swap_token_default_timeout,
985 .maxlen = sizeof(swap_token_default_timeout),
986 .mode = 0644,
987 .proc_handler = &proc_dointvec_jiffies,
988 .strategy = &sysctl_jiffies,
989 },
990#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800991#ifdef CONFIG_NUMA
992 {
993 .ctl_name = VM_ZONE_RECLAIM_MODE,
994 .procname = "zone_reclaim_mode",
995 .data = &zone_reclaim_mode,
996 .maxlen = sizeof(zone_reclaim_mode),
997 .mode = 0644,
998 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -0800999 .strategy = &sysctl_intvec,
1000 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001001 },
Christoph Lameter96146342006-07-03 00:24:13 -07001002 {
1003 .ctl_name = VM_MIN_UNMAPPED,
1004 .procname = "min_unmapped_ratio",
1005 .data = &sysctl_min_unmapped_ratio,
1006 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1007 .mode = 0644,
1008 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1009 .strategy = &sysctl_intvec,
1010 .extra1 = &zero,
1011 .extra2 = &one_hundred,
1012 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001013 {
1014 .ctl_name = VM_MIN_SLAB,
1015 .procname = "min_slab_ratio",
1016 .data = &sysctl_min_slab_ratio,
1017 .maxlen = sizeof(sysctl_min_slab_ratio),
1018 .mode = 0644,
1019 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1021 .extra1 = &zero,
1022 .extra2 = &one_hundred,
1023 },
Christoph Lameter17436602006-01-18 17:42:32 -08001024#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001025#ifdef CONFIG_X86_32
1026 {
1027 .ctl_name = VM_VDSO_ENABLED,
1028 .procname = "vdso_enabled",
1029 .data = &vdso_enabled,
1030 .maxlen = sizeof(vdso_enabled),
1031 .mode = 0644,
1032 .proc_handler = &proc_dointvec,
1033 .strategy = &sysctl_intvec,
1034 .extra1 = &zero,
1035 },
1036#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 { .ctl_name = 0 }
1038};
1039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040static ctl_table fs_table[] = {
1041 {
1042 .ctl_name = FS_NRINODE,
1043 .procname = "inode-nr",
1044 .data = &inodes_stat,
1045 .maxlen = 2*sizeof(int),
1046 .mode = 0444,
1047 .proc_handler = &proc_dointvec,
1048 },
1049 {
1050 .ctl_name = FS_STATINODE,
1051 .procname = "inode-state",
1052 .data = &inodes_stat,
1053 .maxlen = 7*sizeof(int),
1054 .mode = 0444,
1055 .proc_handler = &proc_dointvec,
1056 },
1057 {
1058 .ctl_name = FS_NRFILE,
1059 .procname = "file-nr",
1060 .data = &files_stat,
1061 .maxlen = 3*sizeof(int),
1062 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001063 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 },
1065 {
1066 .ctl_name = FS_MAXFILE,
1067 .procname = "file-max",
1068 .data = &files_stat.max_files,
1069 .maxlen = sizeof(int),
1070 .mode = 0644,
1071 .proc_handler = &proc_dointvec,
1072 },
1073 {
1074 .ctl_name = FS_DENTRY,
1075 .procname = "dentry-state",
1076 .data = &dentry_stat,
1077 .maxlen = 6*sizeof(int),
1078 .mode = 0444,
1079 .proc_handler = &proc_dointvec,
1080 },
1081 {
1082 .ctl_name = FS_OVERFLOWUID,
1083 .procname = "overflowuid",
1084 .data = &fs_overflowuid,
1085 .maxlen = sizeof(int),
1086 .mode = 0644,
1087 .proc_handler = &proc_dointvec_minmax,
1088 .strategy = &sysctl_intvec,
1089 .extra1 = &minolduid,
1090 .extra2 = &maxolduid,
1091 },
1092 {
1093 .ctl_name = FS_OVERFLOWGID,
1094 .procname = "overflowgid",
1095 .data = &fs_overflowgid,
1096 .maxlen = sizeof(int),
1097 .mode = 0644,
1098 .proc_handler = &proc_dointvec_minmax,
1099 .strategy = &sysctl_intvec,
1100 .extra1 = &minolduid,
1101 .extra2 = &maxolduid,
1102 },
1103 {
1104 .ctl_name = FS_LEASES,
1105 .procname = "leases-enable",
1106 .data = &leases_enable,
1107 .maxlen = sizeof(int),
1108 .mode = 0644,
1109 .proc_handler = &proc_dointvec,
1110 },
1111#ifdef CONFIG_DNOTIFY
1112 {
1113 .ctl_name = FS_DIR_NOTIFY,
1114 .procname = "dir-notify-enable",
1115 .data = &dir_notify_enable,
1116 .maxlen = sizeof(int),
1117 .mode = 0644,
1118 .proc_handler = &proc_dointvec,
1119 },
1120#endif
1121#ifdef CONFIG_MMU
1122 {
1123 .ctl_name = FS_LEASE_TIME,
1124 .procname = "lease-break-time",
1125 .data = &lease_break_time,
1126 .maxlen = sizeof(int),
1127 .mode = 0644,
1128 .proc_handler = &proc_dointvec,
1129 },
1130 {
1131 .ctl_name = FS_AIO_NR,
1132 .procname = "aio-nr",
1133 .data = &aio_nr,
1134 .maxlen = sizeof(aio_nr),
1135 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001136 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 },
1138 {
1139 .ctl_name = FS_AIO_MAX_NR,
1140 .procname = "aio-max-nr",
1141 .data = &aio_max_nr,
1142 .maxlen = sizeof(aio_max_nr),
1143 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001144 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001146#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001147 {
1148 .ctl_name = FS_INOTIFY,
1149 .procname = "inotify",
1150 .mode = 0555,
1151 .child = inotify_table,
1152 },
1153#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001155 {
1156 .ctl_name = KERN_SETUID_DUMPABLE,
1157 .procname = "suid_dumpable",
1158 .data = &suid_dumpable,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = &proc_dointvec,
1162 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 { .ctl_name = 0 }
1164};
1165
1166static ctl_table debug_table[] = {
1167 { .ctl_name = 0 }
1168};
1169
1170static ctl_table dev_table[] = {
1171 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001172};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174extern void init_irq_proc (void);
1175
Al Viro330d57f2005-11-04 10:18:40 +00001176static DEFINE_SPINLOCK(sysctl_lock);
1177
1178/* called under sysctl_lock */
1179static int use_table(struct ctl_table_header *p)
1180{
1181 if (unlikely(p->unregistering))
1182 return 0;
1183 p->used++;
1184 return 1;
1185}
1186
1187/* called under sysctl_lock */
1188static void unuse_table(struct ctl_table_header *p)
1189{
1190 if (!--p->used)
1191 if (unlikely(p->unregistering))
1192 complete(p->unregistering);
1193}
1194
1195/* called under sysctl_lock, will reacquire if has to wait */
1196static void start_unregistering(struct ctl_table_header *p)
1197{
1198 /*
1199 * if p->used is 0, nobody will ever touch that entry again;
1200 * we'll eliminate all paths to it before dropping sysctl_lock
1201 */
1202 if (unlikely(p->used)) {
1203 struct completion wait;
1204 init_completion(&wait);
1205 p->unregistering = &wait;
1206 spin_unlock(&sysctl_lock);
1207 wait_for_completion(&wait);
1208 spin_lock(&sysctl_lock);
1209 }
1210 /*
1211 * do not remove from the list until nobody holds it; walking the
1212 * list in do_sysctl() relies on that.
1213 */
1214 list_del_init(&p->ctl_entry);
1215}
1216
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217void __init sysctl_init(void)
1218{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001219#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001220 register_proc_table(root_table, proc_sys_root, &root_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 init_irq_proc();
1222#endif
1223}
1224
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001225#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1227 void __user *newval, size_t newlen)
1228{
1229 struct list_head *tmp;
Al Viro330d57f2005-11-04 10:18:40 +00001230 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1233 return -ENOTDIR;
1234 if (oldval) {
1235 int old_len;
1236 if (!oldlenp || get_user(old_len, oldlenp))
1237 return -EFAULT;
1238 }
Al Viro330d57f2005-11-04 10:18:40 +00001239 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 tmp = &root_table_header.ctl_entry;
1241 do {
1242 struct ctl_table_header *head =
1243 list_entry(tmp, struct ctl_table_header, ctl_entry);
1244 void *context = NULL;
Al Viro330d57f2005-11-04 10:18:40 +00001245
1246 if (!use_table(head))
1247 continue;
1248
1249 spin_unlock(&sysctl_lock);
1250
1251 error = parse_table(name, nlen, oldval, oldlenp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 newval, newlen, head->ctl_table,
1253 &context);
Jesper Juhl5a6b4542005-06-25 14:58:48 -07001254 kfree(context);
Al Viro330d57f2005-11-04 10:18:40 +00001255
1256 spin_lock(&sysctl_lock);
1257 unuse_table(head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 if (error != -ENOTDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001259 break;
1260 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1261 spin_unlock(&sysctl_lock);
1262 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263}
1264
1265asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1266{
1267 struct __sysctl_args tmp;
1268 int error;
1269
1270 if (copy_from_user(&tmp, args, sizeof(tmp)))
1271 return -EFAULT;
1272
1273 lock_kernel();
1274 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1275 tmp.newval, tmp.newlen);
1276 unlock_kernel();
1277 return error;
1278}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001279#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
1281/*
1282 * ctl_perm does NOT grant the superuser all rights automatically, because
1283 * some sysctl variables are readonly even to root.
1284 */
1285
1286static int test_perm(int mode, int op)
1287{
1288 if (!current->euid)
1289 mode >>= 6;
1290 else if (in_egroup_p(0))
1291 mode >>= 3;
1292 if ((mode & op & 0007) == op)
1293 return 0;
1294 return -EACCES;
1295}
1296
1297static inline int ctl_perm(ctl_table *table, int op)
1298{
1299 int error;
1300 error = security_sysctl(table, op);
1301 if (error)
1302 return error;
1303 return test_perm(table->mode, op);
1304}
1305
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001306#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307static int parse_table(int __user *name, int nlen,
1308 void __user *oldval, size_t __user *oldlenp,
1309 void __user *newval, size_t newlen,
1310 ctl_table *table, void **context)
1311{
1312 int n;
1313repeat:
1314 if (!nlen)
1315 return -ENOTDIR;
1316 if (get_user(n, name))
1317 return -EFAULT;
1318 for ( ; table->ctl_name; table++) {
1319 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1320 int error;
1321 if (table->child) {
1322 if (ctl_perm(table, 001))
1323 return -EPERM;
1324 if (table->strategy) {
1325 error = table->strategy(
1326 table, name, nlen,
1327 oldval, oldlenp,
1328 newval, newlen, context);
1329 if (error)
1330 return error;
1331 }
1332 name++;
1333 nlen--;
1334 table = table->child;
1335 goto repeat;
1336 }
1337 error = do_sysctl_strategy(table, name, nlen,
1338 oldval, oldlenp,
1339 newval, newlen, context);
1340 return error;
1341 }
1342 }
1343 return -ENOTDIR;
1344}
1345
1346/* Perform the actual read/write of a sysctl table entry. */
1347int do_sysctl_strategy (ctl_table *table,
1348 int __user *name, int nlen,
1349 void __user *oldval, size_t __user *oldlenp,
1350 void __user *newval, size_t newlen, void **context)
1351{
1352 int op = 0, rc;
1353 size_t len;
1354
1355 if (oldval)
1356 op |= 004;
1357 if (newval)
1358 op |= 002;
1359 if (ctl_perm(table, op))
1360 return -EPERM;
1361
1362 if (table->strategy) {
1363 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1364 newval, newlen, context);
1365 if (rc < 0)
1366 return rc;
1367 if (rc > 0)
1368 return 0;
1369 }
1370
1371 /* If there is no strategy routine, or if the strategy returns
1372 * zero, proceed with automatic r/w */
1373 if (table->data && table->maxlen) {
1374 if (oldval && oldlenp) {
1375 if (get_user(len, oldlenp))
1376 return -EFAULT;
1377 if (len) {
1378 if (len > table->maxlen)
1379 len = table->maxlen;
1380 if(copy_to_user(oldval, table->data, len))
1381 return -EFAULT;
1382 if(put_user(len, oldlenp))
1383 return -EFAULT;
1384 }
1385 }
1386 if (newval && newlen) {
1387 len = newlen;
1388 if (len > table->maxlen)
1389 len = table->maxlen;
1390 if(copy_from_user(table->data, newval, len))
1391 return -EFAULT;
1392 }
1393 }
1394 return 0;
1395}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001396#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398/**
1399 * register_sysctl_table - register a sysctl hierarchy
1400 * @table: the top-level table structure
1401 * @insert_at_head: whether the entry should be inserted in front or at the end
1402 *
1403 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1404 * array. An entry with a ctl_name of 0 terminates the table.
1405 *
1406 * The members of the &ctl_table structure are used as follows:
1407 *
1408 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1409 * must be unique within that level of sysctl
1410 *
1411 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1412 * enter a sysctl file
1413 *
1414 * data - a pointer to data for use by proc_handler
1415 *
1416 * maxlen - the maximum size in bytes of the data
1417 *
1418 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1419 *
1420 * child - a pointer to the child sysctl table if this entry is a directory, or
1421 * %NULL.
1422 *
1423 * proc_handler - the text handler routine (described below)
1424 *
1425 * strategy - the strategy routine (described below)
1426 *
1427 * de - for internal use by the sysctl routines
1428 *
1429 * extra1, extra2 - extra pointers usable by the proc handler routines
1430 *
1431 * Leaf nodes in the sysctl tree will be represented by a single file
1432 * under /proc; non-leaf nodes will be represented by directories.
1433 *
1434 * sysctl(2) can automatically manage read and write requests through
1435 * the sysctl table. The data and maxlen fields of the ctl_table
1436 * struct enable minimal validation of the values being written to be
1437 * performed, and the mode field allows minimal authentication.
1438 *
1439 * More sophisticated management can be enabled by the provision of a
1440 * strategy routine with the table entry. This will be called before
1441 * any automatic read or write of the data is performed.
1442 *
1443 * The strategy routine may return
1444 *
1445 * < 0 - Error occurred (error is passed to user process)
1446 *
1447 * 0 - OK - proceed with automatic read or write.
1448 *
1449 * > 0 - OK - read or write has been done by the strategy routine, so
1450 * return immediately.
1451 *
1452 * There must be a proc_handler routine for any terminal nodes
1453 * mirrored under /proc/sys (non-terminals are handled by a built-in
1454 * directory handler). Several default handlers are available to
1455 * cover common cases -
1456 *
1457 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1458 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1459 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1460 *
1461 * It is the handler's job to read the input buffer from user memory
1462 * and process it. The handler should return 0 on success.
1463 *
1464 * This routine returns %NULL on a failure to register, and a pointer
1465 * to the table header on success.
1466 */
1467struct ctl_table_header *register_sysctl_table(ctl_table * table,
1468 int insert_at_head)
1469{
1470 struct ctl_table_header *tmp;
1471 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1472 if (!tmp)
1473 return NULL;
1474 tmp->ctl_table = table;
1475 INIT_LIST_HEAD(&tmp->ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001476 tmp->used = 0;
1477 tmp->unregistering = NULL;
1478 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 if (insert_at_head)
1480 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1481 else
1482 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001483 spin_unlock(&sysctl_lock);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001484#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001485 register_proc_table(table, proc_sys_root, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486#endif
1487 return tmp;
1488}
1489
1490/**
1491 * unregister_sysctl_table - unregister a sysctl table hierarchy
1492 * @header: the header returned from register_sysctl_table
1493 *
1494 * Unregisters the sysctl table and all children. proc entries may not
1495 * actually be removed until they are no longer used by anyone.
1496 */
1497void unregister_sysctl_table(struct ctl_table_header * header)
1498{
Al Viro330d57f2005-11-04 10:18:40 +00001499 might_sleep();
1500 spin_lock(&sysctl_lock);
1501 start_unregistering(header);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001502#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 unregister_proc_table(header->ctl_table, proc_sys_root);
1504#endif
Al Viro330d57f2005-11-04 10:18:40 +00001505 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 kfree(header);
1507}
1508
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001509#else /* !CONFIG_SYSCTL */
1510struct ctl_table_header * register_sysctl_table(ctl_table * table,
1511 int insert_at_head)
1512{
1513 return NULL;
1514}
1515
1516void unregister_sysctl_table(struct ctl_table_header * table)
1517{
1518}
1519
1520#endif /* CONFIG_SYSCTL */
1521
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522/*
1523 * /proc/sys support
1524 */
1525
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001526#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528/* Scan the sysctl entries in table and add them all into /proc */
Al Viro330d57f2005-11-04 10:18:40 +00001529static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530{
1531 struct proc_dir_entry *de;
1532 int len;
1533 mode_t mode;
1534
1535 for (; table->ctl_name; table++) {
1536 /* Can't do anything without a proc name. */
1537 if (!table->procname)
1538 continue;
1539 /* Maybe we can't do anything with it... */
1540 if (!table->proc_handler && !table->child) {
1541 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1542 table->procname);
1543 continue;
1544 }
1545
1546 len = strlen(table->procname);
1547 mode = table->mode;
1548
1549 de = NULL;
1550 if (table->proc_handler)
1551 mode |= S_IFREG;
1552 else {
1553 mode |= S_IFDIR;
1554 for (de = root->subdir; de; de = de->next) {
1555 if (proc_match(len, table->procname, de))
1556 break;
1557 }
1558 /* If the subdir exists already, de is non-NULL */
1559 }
1560
1561 if (!de) {
1562 de = create_proc_entry(table->procname, mode, root);
1563 if (!de)
1564 continue;
Al Viro330d57f2005-11-04 10:18:40 +00001565 de->set = set;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 de->data = (void *) table;
1567 if (table->proc_handler)
1568 de->proc_fops = &proc_sys_file_operations;
1569 }
1570 table->de = de;
1571 if (de->mode & S_IFDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001572 register_proc_table(table->child, de, set);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 }
1574}
1575
1576/*
1577 * Unregister a /proc sysctl table and any subdirectories.
1578 */
1579static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1580{
1581 struct proc_dir_entry *de;
1582 for (; table->ctl_name; table++) {
1583 if (!(de = table->de))
1584 continue;
1585 if (de->mode & S_IFDIR) {
1586 if (!table->child) {
1587 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1588 continue;
1589 }
1590 unregister_proc_table(table->child, de);
1591
1592 /* Don't unregister directories which still have entries.. */
1593 if (de->subdir)
1594 continue;
1595 }
1596
Al Viro330d57f2005-11-04 10:18:40 +00001597 /*
1598 * In any case, mark the entry as goner; we'll keep it
1599 * around if it's busy, but we'll know to do nothing with
1600 * its fields. We are under sysctl_lock here.
1601 */
1602 de->data = NULL;
1603
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 /* Don't unregister proc entries that are still being used.. */
1605 if (atomic_read(&de->count))
1606 continue;
1607
1608 table->de = NULL;
1609 remove_proc_entry(table->procname, root);
1610 }
1611}
1612
1613static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1614 size_t count, loff_t *ppos)
1615{
1616 int op;
Al Viro330d57f2005-11-04 10:18:40 +00001617 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 struct ctl_table *table;
1619 size_t res;
Al Viro330d57f2005-11-04 10:18:40 +00001620 ssize_t error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
Al Viro330d57f2005-11-04 10:18:40 +00001622 spin_lock(&sysctl_lock);
1623 if (de && de->data && use_table(de->set)) {
1624 /*
1625 * at that point we know that sysctl was not unregistered
1626 * and won't be until we finish
1627 */
1628 spin_unlock(&sysctl_lock);
1629 table = (struct ctl_table *) de->data;
1630 if (!table || !table->proc_handler)
1631 goto out;
1632 error = -EPERM;
1633 op = (write ? 002 : 004);
1634 if (ctl_perm(table, op))
1635 goto out;
1636
1637 /* careful: calling conventions are nasty here */
1638 res = count;
1639 error = (*table->proc_handler)(table, write, file,
1640 buf, &res, ppos);
1641 if (!error)
1642 error = res;
1643 out:
1644 spin_lock(&sysctl_lock);
1645 unuse_table(de->set);
1646 }
1647 spin_unlock(&sysctl_lock);
1648 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649}
1650
1651static int proc_opensys(struct inode *inode, struct file *file)
1652{
1653 if (file->f_mode & FMODE_WRITE) {
1654 /*
1655 * sysctl entries that are not writable,
1656 * are _NOT_ writable, capabilities or not.
1657 */
1658 if (!(inode->i_mode & S_IWUSR))
1659 return -EPERM;
1660 }
1661
1662 return 0;
1663}
1664
1665static ssize_t proc_readsys(struct file * file, char __user * buf,
1666 size_t count, loff_t *ppos)
1667{
1668 return do_rw_proc(0, file, buf, count, ppos);
1669}
1670
1671static ssize_t proc_writesys(struct file * file, const char __user * buf,
1672 size_t count, loff_t *ppos)
1673{
1674 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1675}
1676
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001677static int _proc_do_string(void* data, int maxlen, int write,
1678 struct file *filp, void __user *buffer,
1679 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001680{
1681 size_t len;
1682 char __user *p;
1683 char c;
1684
1685 if (!data || !maxlen || !*lenp ||
1686 (*ppos && !write)) {
1687 *lenp = 0;
1688 return 0;
1689 }
1690
1691 if (write) {
1692 len = 0;
1693 p = buffer;
1694 while (len < *lenp) {
1695 if (get_user(c, p++))
1696 return -EFAULT;
1697 if (c == 0 || c == '\n')
1698 break;
1699 len++;
1700 }
1701 if (len >= maxlen)
1702 len = maxlen-1;
1703 if(copy_from_user(data, buffer, len))
1704 return -EFAULT;
1705 ((char *) data)[len] = 0;
1706 *ppos += *lenp;
1707 } else {
1708 len = strlen(data);
1709 if (len > maxlen)
1710 len = maxlen;
1711 if (len > *lenp)
1712 len = *lenp;
1713 if (len)
1714 if(copy_to_user(buffer, data, len))
1715 return -EFAULT;
1716 if (len < *lenp) {
1717 if(put_user('\n', ((char __user *) buffer) + len))
1718 return -EFAULT;
1719 len++;
1720 }
1721 *lenp = len;
1722 *ppos += len;
1723 }
1724 return 0;
1725}
1726
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727/**
1728 * proc_dostring - read a string sysctl
1729 * @table: the sysctl table
1730 * @write: %TRUE if this is a write to the sysctl file
1731 * @filp: the file structure
1732 * @buffer: the user buffer
1733 * @lenp: the size of the user buffer
1734 * @ppos: file position
1735 *
1736 * Reads/writes a string from/to the user buffer. If the kernel
1737 * buffer provided is not large enough to hold the string, the
1738 * string is truncated. The copied string is %NULL-terminated.
1739 * If the string is being read by the user process, it is copied
1740 * and a newline '\n' is added. It is truncated if the buffer is
1741 * not large enough.
1742 *
1743 * Returns 0 on success.
1744 */
1745int proc_dostring(ctl_table *table, int write, struct file *filp,
1746 void __user *buffer, size_t *lenp, loff_t *ppos)
1747{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001748 return _proc_do_string(table->data, table->maxlen, write, filp,
1749 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750}
1751
1752/*
1753 * Special case of dostring for the UTS structure. This has locks
1754 * to observe. Should this be in kernel/sys.c ????
1755 */
1756
Serge E. Hallyn8218c742006-10-02 02:18:15 -07001757#ifndef CONFIG_UTS_NS
1758static 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;
1762
1763 if (!write) {
1764 down_read(&uts_sem);
1765 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1766 up_read(&uts_sem);
1767 } else {
1768 down_write(&uts_sem);
1769 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1770 up_write(&uts_sem);
1771 }
1772 return r;
1773}
Serge E. Hallyn8218c742006-10-02 02:18:15 -07001774#else /* !CONFIG_UTS_NS */
1775static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1776 void __user *buffer, size_t *lenp, loff_t *ppos)
1777{
1778 int r;
1779 struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
1780 char* which;
1781
1782 switch (table->ctl_name) {
1783 case KERN_OSTYPE:
1784 which = uts_ns->name.sysname;
1785 break;
1786 case KERN_NODENAME:
1787 which = uts_ns->name.nodename;
1788 break;
1789 case KERN_OSRELEASE:
1790 which = uts_ns->name.release;
1791 break;
1792 case KERN_VERSION:
1793 which = uts_ns->name.version;
1794 break;
1795 case KERN_DOMAINNAME:
1796 which = uts_ns->name.domainname;
1797 break;
1798 default:
1799 r = -EINVAL;
1800 goto out;
1801 }
1802
1803 if (!write) {
1804 down_read(&uts_sem);
1805 r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
1806 up_read(&uts_sem);
1807 } else {
1808 down_write(&uts_sem);
1809 r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
1810 up_write(&uts_sem);
1811 }
1812 out:
1813 return r;
1814}
1815#endif /* !CONFIG_UTS_NS */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
1817static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1818 int *valp,
1819 int write, void *data)
1820{
1821 if (write) {
1822 *valp = *negp ? -*lvalp : *lvalp;
1823 } else {
1824 int val = *valp;
1825 if (val < 0) {
1826 *negp = -1;
1827 *lvalp = (unsigned long)-val;
1828 } else {
1829 *negp = 0;
1830 *lvalp = (unsigned long)val;
1831 }
1832 }
1833 return 0;
1834}
1835
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001836static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1837 int write, struct file *filp, void __user *buffer,
1838 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1840 int write, void *data),
1841 void *data)
1842{
1843#define TMPBUFLEN 21
1844 int *i, vleft, first=1, neg, val;
1845 unsigned long lval;
1846 size_t left, len;
1847
1848 char buf[TMPBUFLEN], *p;
1849 char __user *s = buffer;
1850
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001851 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 (*ppos && !write)) {
1853 *lenp = 0;
1854 return 0;
1855 }
1856
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001857 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 vleft = table->maxlen / sizeof(*i);
1859 left = *lenp;
1860
1861 if (!conv)
1862 conv = do_proc_dointvec_conv;
1863
1864 for (; left && vleft--; i++, first=0) {
1865 if (write) {
1866 while (left) {
1867 char c;
1868 if (get_user(c, s))
1869 return -EFAULT;
1870 if (!isspace(c))
1871 break;
1872 left--;
1873 s++;
1874 }
1875 if (!left)
1876 break;
1877 neg = 0;
1878 len = left;
1879 if (len > sizeof(buf) - 1)
1880 len = sizeof(buf) - 1;
1881 if (copy_from_user(buf, s, len))
1882 return -EFAULT;
1883 buf[len] = 0;
1884 p = buf;
1885 if (*p == '-' && left > 1) {
1886 neg = 1;
1887 left--, p++;
1888 }
1889 if (*p < '0' || *p > '9')
1890 break;
1891
1892 lval = simple_strtoul(p, &p, 0);
1893
1894 len = p-buf;
1895 if ((len < left) && *p && !isspace(*p))
1896 break;
1897 if (neg)
1898 val = -val;
1899 s += len;
1900 left -= len;
1901
1902 if (conv(&neg, &lval, i, 1, data))
1903 break;
1904 } else {
1905 p = buf;
1906 if (!first)
1907 *p++ = '\t';
1908
1909 if (conv(&neg, &lval, i, 0, data))
1910 break;
1911
1912 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1913 len = strlen(buf);
1914 if (len > left)
1915 len = left;
1916 if(copy_to_user(s, buf, len))
1917 return -EFAULT;
1918 left -= len;
1919 s += len;
1920 }
1921 }
1922
1923 if (!write && !first && left) {
1924 if(put_user('\n', s))
1925 return -EFAULT;
1926 left--, s++;
1927 }
1928 if (write) {
1929 while (left) {
1930 char c;
1931 if (get_user(c, s++))
1932 return -EFAULT;
1933 if (!isspace(c))
1934 break;
1935 left--;
1936 }
1937 }
1938 if (write && first)
1939 return -EINVAL;
1940 *lenp -= left;
1941 *ppos += *lenp;
1942 return 0;
1943#undef TMPBUFLEN
1944}
1945
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001946static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1947 void __user *buffer, size_t *lenp, loff_t *ppos,
1948 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1949 int write, void *data),
1950 void *data)
1951{
1952 return __do_proc_dointvec(table->data, table, write, filp,
1953 buffer, lenp, ppos, conv, data);
1954}
1955
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956/**
1957 * proc_dointvec - read a vector of integers
1958 * @table: the sysctl table
1959 * @write: %TRUE if this is a write to the sysctl file
1960 * @filp: the file structure
1961 * @buffer: the user buffer
1962 * @lenp: the size of the user buffer
1963 * @ppos: file position
1964 *
1965 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1966 * values from/to the user buffer, treated as an ASCII string.
1967 *
1968 * Returns 0 on success.
1969 */
1970int proc_dointvec(ctl_table *table, int write, struct file *filp,
1971 void __user *buffer, size_t *lenp, loff_t *ppos)
1972{
1973 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1974 NULL,NULL);
1975}
1976
1977#define OP_SET 0
1978#define OP_AND 1
1979#define OP_OR 2
1980#define OP_MAX 3
1981#define OP_MIN 4
1982
1983static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1984 int *valp,
1985 int write, void *data)
1986{
1987 int op = *(int *)data;
1988 if (write) {
1989 int val = *negp ? -*lvalp : *lvalp;
1990 switch(op) {
1991 case OP_SET: *valp = val; break;
1992 case OP_AND: *valp &= val; break;
1993 case OP_OR: *valp |= val; break;
1994 case OP_MAX: if(*valp < val)
1995 *valp = val;
1996 break;
1997 case OP_MIN: if(*valp > val)
1998 *valp = val;
1999 break;
2000 }
2001 } else {
2002 int val = *valp;
2003 if (val < 0) {
2004 *negp = -1;
2005 *lvalp = (unsigned long)-val;
2006 } else {
2007 *negp = 0;
2008 *lvalp = (unsigned long)val;
2009 }
2010 }
2011 return 0;
2012}
2013
2014/*
2015 * init may raise the set.
2016 */
2017
2018int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2019 void __user *buffer, size_t *lenp, loff_t *ppos)
2020{
2021 int op;
2022
2023 if (!capable(CAP_SYS_MODULE)) {
2024 return -EPERM;
2025 }
2026
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07002027 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2029 do_proc_dointvec_bset_conv,&op);
2030}
2031
2032struct do_proc_dointvec_minmax_conv_param {
2033 int *min;
2034 int *max;
2035};
2036
2037static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2038 int *valp,
2039 int write, void *data)
2040{
2041 struct do_proc_dointvec_minmax_conv_param *param = data;
2042 if (write) {
2043 int val = *negp ? -*lvalp : *lvalp;
2044 if ((param->min && *param->min > val) ||
2045 (param->max && *param->max < val))
2046 return -EINVAL;
2047 *valp = val;
2048 } else {
2049 int val = *valp;
2050 if (val < 0) {
2051 *negp = -1;
2052 *lvalp = (unsigned long)-val;
2053 } else {
2054 *negp = 0;
2055 *lvalp = (unsigned long)val;
2056 }
2057 }
2058 return 0;
2059}
2060
2061/**
2062 * proc_dointvec_minmax - read a vector of integers with min/max values
2063 * @table: the sysctl table
2064 * @write: %TRUE if this is a write to the sysctl file
2065 * @filp: the file structure
2066 * @buffer: the user buffer
2067 * @lenp: the size of the user buffer
2068 * @ppos: file position
2069 *
2070 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2071 * values from/to the user buffer, treated as an ASCII string.
2072 *
2073 * This routine will ensure the values are within the range specified by
2074 * table->extra1 (min) and table->extra2 (max).
2075 *
2076 * Returns 0 on success.
2077 */
2078int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2079 void __user *buffer, size_t *lenp, loff_t *ppos)
2080{
2081 struct do_proc_dointvec_minmax_conv_param param = {
2082 .min = (int *) table->extra1,
2083 .max = (int *) table->extra2,
2084 };
2085 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2086 do_proc_dointvec_minmax_conv, &param);
2087}
2088
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002089static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 struct file *filp,
2091 void __user *buffer,
2092 size_t *lenp, loff_t *ppos,
2093 unsigned long convmul,
2094 unsigned long convdiv)
2095{
2096#define TMPBUFLEN 21
2097 unsigned long *i, *min, *max, val;
2098 int vleft, first=1, neg;
2099 size_t len, left;
2100 char buf[TMPBUFLEN], *p;
2101 char __user *s = buffer;
2102
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002103 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 (*ppos && !write)) {
2105 *lenp = 0;
2106 return 0;
2107 }
2108
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002109 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 min = (unsigned long *) table->extra1;
2111 max = (unsigned long *) table->extra2;
2112 vleft = table->maxlen / sizeof(unsigned long);
2113 left = *lenp;
2114
2115 for (; left && vleft--; i++, min++, max++, first=0) {
2116 if (write) {
2117 while (left) {
2118 char c;
2119 if (get_user(c, s))
2120 return -EFAULT;
2121 if (!isspace(c))
2122 break;
2123 left--;
2124 s++;
2125 }
2126 if (!left)
2127 break;
2128 neg = 0;
2129 len = left;
2130 if (len > TMPBUFLEN-1)
2131 len = TMPBUFLEN-1;
2132 if (copy_from_user(buf, s, len))
2133 return -EFAULT;
2134 buf[len] = 0;
2135 p = buf;
2136 if (*p == '-' && left > 1) {
2137 neg = 1;
2138 left--, p++;
2139 }
2140 if (*p < '0' || *p > '9')
2141 break;
2142 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2143 len = p-buf;
2144 if ((len < left) && *p && !isspace(*p))
2145 break;
2146 if (neg)
2147 val = -val;
2148 s += len;
2149 left -= len;
2150
2151 if(neg)
2152 continue;
2153 if ((min && val < *min) || (max && val > *max))
2154 continue;
2155 *i = val;
2156 } else {
2157 p = buf;
2158 if (!first)
2159 *p++ = '\t';
2160 sprintf(p, "%lu", convdiv * (*i) / convmul);
2161 len = strlen(buf);
2162 if (len > left)
2163 len = left;
2164 if(copy_to_user(s, buf, len))
2165 return -EFAULT;
2166 left -= len;
2167 s += len;
2168 }
2169 }
2170
2171 if (!write && !first && left) {
2172 if(put_user('\n', s))
2173 return -EFAULT;
2174 left--, s++;
2175 }
2176 if (write) {
2177 while (left) {
2178 char c;
2179 if (get_user(c, s++))
2180 return -EFAULT;
2181 if (!isspace(c))
2182 break;
2183 left--;
2184 }
2185 }
2186 if (write && first)
2187 return -EINVAL;
2188 *lenp -= left;
2189 *ppos += *lenp;
2190 return 0;
2191#undef TMPBUFLEN
2192}
2193
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002194static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2195 struct file *filp,
2196 void __user *buffer,
2197 size_t *lenp, loff_t *ppos,
2198 unsigned long convmul,
2199 unsigned long convdiv)
2200{
2201 return __do_proc_doulongvec_minmax(table->data, table, write,
2202 filp, buffer, lenp, ppos, convmul, convdiv);
2203}
2204
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205/**
2206 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2207 * @table: the sysctl table
2208 * @write: %TRUE if this is a write to the sysctl file
2209 * @filp: the file structure
2210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2213 *
2214 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2215 * values from/to the user buffer, treated as an ASCII string.
2216 *
2217 * This routine will ensure the values are within the range specified by
2218 * table->extra1 (min) and table->extra2 (max).
2219 *
2220 * Returns 0 on success.
2221 */
2222int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2223 void __user *buffer, size_t *lenp, loff_t *ppos)
2224{
2225 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2226}
2227
2228/**
2229 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2230 * @table: the sysctl table
2231 * @write: %TRUE if this is a write to the sysctl file
2232 * @filp: the file structure
2233 * @buffer: the user buffer
2234 * @lenp: the size of the user buffer
2235 * @ppos: file position
2236 *
2237 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2238 * values from/to the user buffer, treated as an ASCII string. The values
2239 * are treated as milliseconds, and converted to jiffies when they are stored.
2240 *
2241 * This routine will ensure the values are within the range specified by
2242 * table->extra1 (min) and table->extra2 (max).
2243 *
2244 * Returns 0 on success.
2245 */
2246int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2247 struct file *filp,
2248 void __user *buffer,
2249 size_t *lenp, loff_t *ppos)
2250{
2251 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2252 lenp, ppos, HZ, 1000l);
2253}
2254
2255
2256static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2257 int *valp,
2258 int write, void *data)
2259{
2260 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002261 if (*lvalp > LONG_MAX / HZ)
2262 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2264 } else {
2265 int val = *valp;
2266 unsigned long lval;
2267 if (val < 0) {
2268 *negp = -1;
2269 lval = (unsigned long)-val;
2270 } else {
2271 *negp = 0;
2272 lval = (unsigned long)val;
2273 }
2274 *lvalp = lval / HZ;
2275 }
2276 return 0;
2277}
2278
2279static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2280 int *valp,
2281 int write, void *data)
2282{
2283 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002284 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2285 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2287 } else {
2288 int val = *valp;
2289 unsigned long lval;
2290 if (val < 0) {
2291 *negp = -1;
2292 lval = (unsigned long)-val;
2293 } else {
2294 *negp = 0;
2295 lval = (unsigned long)val;
2296 }
2297 *lvalp = jiffies_to_clock_t(lval);
2298 }
2299 return 0;
2300}
2301
2302static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2303 int *valp,
2304 int write, void *data)
2305{
2306 if (write) {
2307 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2308 } else {
2309 int val = *valp;
2310 unsigned long lval;
2311 if (val < 0) {
2312 *negp = -1;
2313 lval = (unsigned long)-val;
2314 } else {
2315 *negp = 0;
2316 lval = (unsigned long)val;
2317 }
2318 *lvalp = jiffies_to_msecs(lval);
2319 }
2320 return 0;
2321}
2322
2323/**
2324 * proc_dointvec_jiffies - read a vector of integers as seconds
2325 * @table: the sysctl table
2326 * @write: %TRUE if this is a write to the sysctl file
2327 * @filp: the file structure
2328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2331 *
2332 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2333 * values from/to the user buffer, treated as an ASCII string.
2334 * The values read are assumed to be in seconds, and are converted into
2335 * jiffies.
2336 *
2337 * Returns 0 on success.
2338 */
2339int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2340 void __user *buffer, size_t *lenp, loff_t *ppos)
2341{
2342 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2343 do_proc_dointvec_jiffies_conv,NULL);
2344}
2345
2346/**
2347 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2348 * @table: the sysctl table
2349 * @write: %TRUE if this is a write to the sysctl file
2350 * @filp: the file structure
2351 * @buffer: the user buffer
2352 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002353 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 *
2355 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2356 * values from/to the user buffer, treated as an ASCII string.
2357 * The values read are assumed to be in 1/USER_HZ seconds, and
2358 * are converted into jiffies.
2359 *
2360 * Returns 0 on success.
2361 */
2362int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2363 void __user *buffer, size_t *lenp, loff_t *ppos)
2364{
2365 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2366 do_proc_dointvec_userhz_jiffies_conv,NULL);
2367}
2368
2369/**
2370 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2371 * @table: the sysctl table
2372 * @write: %TRUE if this is a write to the sysctl file
2373 * @filp: the file structure
2374 * @buffer: the user buffer
2375 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002376 * @ppos: file position
2377 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 *
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2381 * The values read are assumed to be in 1/1000 seconds, and
2382 * are converted into jiffies.
2383 *
2384 * Returns 0 on success.
2385 */
2386int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
2388{
2389 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2390 do_proc_dointvec_ms_jiffies_conv, NULL);
2391}
2392
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002393#ifdef CONFIG_SYSVIPC
2394static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2395 void __user *buffer, size_t *lenp, loff_t *ppos)
2396{
2397 void *data;
2398 struct ipc_namespace *ns;
2399
2400 ns = current->nsproxy->ipc_ns;
2401
2402 switch (table->ctl_name) {
2403 case KERN_SHMMAX:
2404 data = &ns->shm_ctlmax;
2405 goto proc_minmax;
2406 case KERN_SHMALL:
2407 data = &ns->shm_ctlall;
2408 goto proc_minmax;
2409 case KERN_SHMMNI:
2410 data = &ns->shm_ctlmni;
2411 break;
2412 case KERN_MSGMAX:
2413 data = &ns->msg_ctlmax;
2414 break;
2415 case KERN_MSGMNI:
2416 data = &ns->msg_ctlmni;
2417 break;
2418 case KERN_MSGMNB:
2419 data = &ns->msg_ctlmnb;
2420 break;
2421 case KERN_SEM:
2422 data = &ns->sem_ctls;
2423 break;
2424 default:
2425 return -EINVAL;
2426 }
2427
2428 return __do_proc_dointvec(data, table, write, filp, buffer,
2429 lenp, ppos, NULL, NULL);
2430proc_minmax:
2431 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2432 lenp, ppos, 1l, 1l);
2433}
2434#endif
2435
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002436static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2437 void __user *buffer, size_t *lenp, loff_t *ppos)
2438{
2439 struct pid *new_pid;
2440 pid_t tmp;
2441 int r;
2442
2443 tmp = pid_nr(cad_pid);
2444
2445 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2446 lenp, ppos, NULL, NULL);
2447 if (r || !write)
2448 return r;
2449
2450 new_pid = find_get_pid(tmp);
2451 if (!new_pid)
2452 return -ESRCH;
2453
2454 put_pid(xchg(&cad_pid, new_pid));
2455 return 0;
2456}
2457
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458#else /* CONFIG_PROC_FS */
2459
2460int proc_dostring(ctl_table *table, int write, struct file *filp,
2461 void __user *buffer, size_t *lenp, loff_t *ppos)
2462{
2463 return -ENOSYS;
2464}
2465
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002466static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2467 void __user *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468{
2469 return -ENOSYS;
2470}
2471
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002472#ifdef CONFIG_SYSVIPC
2473static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2474 void __user *buffer, size_t *lenp, loff_t *ppos)
2475{
2476 return -ENOSYS;
2477}
2478#endif
2479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480int proc_dointvec(ctl_table *table, int write, struct file *filp,
2481 void __user *buffer, size_t *lenp, loff_t *ppos)
2482{
2483 return -ENOSYS;
2484}
2485
2486int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2487 void __user *buffer, size_t *lenp, loff_t *ppos)
2488{
2489 return -ENOSYS;
2490}
2491
2492int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2493 void __user *buffer, size_t *lenp, loff_t *ppos)
2494{
2495 return -ENOSYS;
2496}
2497
2498int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2499 void __user *buffer, size_t *lenp, loff_t *ppos)
2500{
2501 return -ENOSYS;
2502}
2503
2504int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2505 void __user *buffer, size_t *lenp, loff_t *ppos)
2506{
2507 return -ENOSYS;
2508}
2509
2510int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2511 void __user *buffer, size_t *lenp, loff_t *ppos)
2512{
2513 return -ENOSYS;
2514}
2515
2516int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2517 void __user *buffer, size_t *lenp, loff_t *ppos)
2518{
2519 return -ENOSYS;
2520}
2521
2522int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2523 struct file *filp,
2524 void __user *buffer,
2525 size_t *lenp, loff_t *ppos)
2526{
2527 return -ENOSYS;
2528}
2529
2530
2531#endif /* CONFIG_PROC_FS */
2532
2533
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002534#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535/*
2536 * General sysctl support routines
2537 */
2538
2539/* The generic string strategy routine: */
2540int sysctl_string(ctl_table *table, int __user *name, int nlen,
2541 void __user *oldval, size_t __user *oldlenp,
2542 void __user *newval, size_t newlen, void **context)
2543{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 if (!table->data || !table->maxlen)
2545 return -ENOTDIR;
2546
2547 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002548 size_t bufsize;
2549 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002551 if (bufsize) {
2552 size_t len = strlen(table->data), copied;
2553
2554 /* This shouldn't trigger for a well-formed sysctl */
2555 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002557
2558 /* Copy up to a max of bufsize-1 bytes of the string */
2559 copied = (len >= bufsize) ? bufsize - 1 : len;
2560
2561 if (copy_to_user(oldval, table->data, copied) ||
2562 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002564 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 return -EFAULT;
2566 }
2567 }
2568 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002569 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 if (len > table->maxlen)
2571 len = table->maxlen;
2572 if(copy_from_user(table->data, newval, len))
2573 return -EFAULT;
2574 if (len == table->maxlen)
2575 len--;
2576 ((char *) table->data)[len] = 0;
2577 }
Yi Yang82c9df82005-12-30 16:37:10 +08002578 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579}
2580
2581/*
2582 * This function makes sure that all of the integers in the vector
2583 * are between the minimum and maximum values given in the arrays
2584 * table->extra1 and table->extra2, respectively.
2585 */
2586int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp,
2588 void __user *newval, size_t newlen, void **context)
2589{
2590
2591 if (newval && newlen) {
2592 int __user *vec = (int __user *) newval;
2593 int *min = (int *) table->extra1;
2594 int *max = (int *) table->extra2;
2595 size_t length;
2596 int i;
2597
2598 if (newlen % sizeof(int) != 0)
2599 return -EINVAL;
2600
2601 if (!table->extra1 && !table->extra2)
2602 return 0;
2603
2604 if (newlen > table->maxlen)
2605 newlen = table->maxlen;
2606 length = newlen / sizeof(int);
2607
2608 for (i = 0; i < length; i++) {
2609 int value;
2610 if (get_user(value, vec + i))
2611 return -EFAULT;
2612 if (min && value < min[i])
2613 return -EINVAL;
2614 if (max && value > max[i])
2615 return -EINVAL;
2616 }
2617 }
2618 return 0;
2619}
2620
2621/* Strategy function to convert jiffies to seconds */
2622int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2623 void __user *oldval, size_t __user *oldlenp,
2624 void __user *newval, size_t newlen, void **context)
2625{
2626 if (oldval) {
2627 size_t olen;
2628 if (oldlenp) {
2629 if (get_user(olen, oldlenp))
2630 return -EFAULT;
2631 if (olen!=sizeof(int))
2632 return -EINVAL;
2633 }
2634 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2635 (oldlenp && put_user(sizeof(int),oldlenp)))
2636 return -EFAULT;
2637 }
2638 if (newval && newlen) {
2639 int new;
2640 if (newlen != sizeof(int))
2641 return -EINVAL;
2642 if (get_user(new, (int __user *)newval))
2643 return -EFAULT;
2644 *(int *)(table->data) = new*HZ;
2645 }
2646 return 1;
2647}
2648
2649/* Strategy function to convert jiffies to seconds */
2650int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2651 void __user *oldval, size_t __user *oldlenp,
2652 void __user *newval, size_t newlen, void **context)
2653{
2654 if (oldval) {
2655 size_t olen;
2656 if (oldlenp) {
2657 if (get_user(olen, oldlenp))
2658 return -EFAULT;
2659 if (olen!=sizeof(int))
2660 return -EINVAL;
2661 }
2662 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2663 (oldlenp && put_user(sizeof(int),oldlenp)))
2664 return -EFAULT;
2665 }
2666 if (newval && newlen) {
2667 int new;
2668 if (newlen != sizeof(int))
2669 return -EINVAL;
2670 if (get_user(new, (int __user *)newval))
2671 return -EFAULT;
2672 *(int *)(table->data) = msecs_to_jiffies(new);
2673 }
2674 return 1;
2675}
2676
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002677#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678
2679
2680asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2681{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002682 static int msg_count;
2683
2684 if (msg_count < 5) {
2685 msg_count++;
2686 printk(KERN_INFO
2687 "warning: process `%s' used the removed sysctl "
2688 "system call\n", current->comm);
2689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 return -ENOSYS;
2691}
2692
2693int sysctl_string(ctl_table *table, int __user *name, int nlen,
2694 void __user *oldval, size_t __user *oldlenp,
2695 void __user *newval, size_t newlen, void **context)
2696{
2697 return -ENOSYS;
2698}
2699
2700int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2701 void __user *oldval, size_t __user *oldlenp,
2702 void __user *newval, size_t newlen, void **context)
2703{
2704 return -ENOSYS;
2705}
2706
2707int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2708 void __user *oldval, size_t __user *oldlenp,
2709 void __user *newval, size_t newlen, void **context)
2710{
2711 return -ENOSYS;
2712}
2713
2714int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2715 void __user *oldval, size_t __user *oldlenp,
2716 void __user *newval, size_t newlen, void **context)
2717{
2718 return -ENOSYS;
2719}
2720
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002721#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
2723/*
2724 * No sense putting this after each symbol definition, twice,
2725 * exception granted :-)
2726 */
2727EXPORT_SYMBOL(proc_dointvec);
2728EXPORT_SYMBOL(proc_dointvec_jiffies);
2729EXPORT_SYMBOL(proc_dointvec_minmax);
2730EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2731EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2732EXPORT_SYMBOL(proc_dostring);
2733EXPORT_SYMBOL(proc_doulongvec_minmax);
2734EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2735EXPORT_SYMBOL(register_sysctl_table);
2736EXPORT_SYMBOL(sysctl_intvec);
2737EXPORT_SYMBOL(sysctl_jiffies);
2738EXPORT_SYMBOL(sysctl_ms_jiffies);
2739EXPORT_SYMBOL(sysctl_string);
2740EXPORT_SYMBOL(unregister_sysctl_table);