blob: 16ef870fa75ad1a1a205dda2c5c3d40ab9dc0d55 [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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068extern 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
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -080094static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
95 void __user *buffer, size_t *lenp, loff_t *ppos);
96static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -070097 void __user *buffer, size_t *lenp, loff_t *ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#endif
99
100#ifdef __sparc__
101extern char reboot_command [];
102extern int stop_a_enabled;
103extern int scons_pwroff;
104#endif
105
106#ifdef __hppa__
107extern int pwrsw_enabled;
108extern int unaligned_enabled;
109#endif
110
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800111#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#ifdef CONFIG_MATHEMU
113extern int sysctl_ieee_emulation_warnings;
114#endif
115extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700116extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif
118
119extern int sysctl_hz_timer;
120
121#ifdef CONFIG_BSD_PROCESS_ACCT
122extern int acct_parm[];
123#endif
124
Jes Sorensend2b176e2006-02-28 09:42:23 -0800125#ifdef CONFIG_IA64
126extern int no_unaligned_warning;
127#endif
128
Ingo Molnar23f78d42006-06-27 02:54:53 -0700129#ifdef CONFIG_RT_MUTEXES
130extern int max_lock_depth;
131#endif
132
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700133#ifdef CONFIG_SYSCTL_SYSCALL
134static int parse_table(int __user *, int, void __user *, size_t __user *,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800135 void __user *, size_t, ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700136#endif
137
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700138static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 void __user *buffer, size_t *lenp, loff_t *ppos);
140
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800141static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
142 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800143 void __user *newval, size_t newlen);
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800144
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800145#ifdef CONFIG_SYSVIPC
146static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
147 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800148 void __user *newval, size_t newlen);
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800149#endif
150
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700151#ifdef CONFIG_PROC_SYSCTL
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700152static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700154#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static ctl_table root_table[];
157static struct ctl_table_header root_table_header =
158 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
159
160static ctl_table kern_table[];
161static ctl_table vm_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162static ctl_table fs_table[];
163static ctl_table debug_table[];
164static ctl_table dev_table[];
165extern ctl_table random_table[];
166#ifdef CONFIG_UNIX98_PTYS
167extern ctl_table pty_table[];
168#endif
Amy Griffis2d9048e2006-06-01 13:10:59 -0700169#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -0400170extern ctl_table inotify_table[];
171#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
174int sysctl_legacy_va_layout;
175#endif
176
Eric W. Biedermancf9f1512006-12-08 02:39:55 -0800177static void *get_uts(ctl_table *table, int write)
178{
179 char *which = table->data;
180#ifdef CONFIG_UTS_NS
181 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
182 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
183#endif
184 if (!write)
185 down_read(&uts_sem);
186 else
187 down_write(&uts_sem);
188 return which;
189}
190
191static void put_uts(ctl_table *table, int write, void *which)
192{
193 if (!write)
194 up_read(&uts_sem);
195 else
196 up_write(&uts_sem);
197}
198
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800199#ifdef CONFIG_SYSVIPC
200static void *get_ipc(ctl_table *table, int write)
201{
202 char *which = table->data;
203 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
204 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
205 return which;
206}
207#else
208#define get_ipc(T,W) ((T)->data)
209#endif
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/* /proc declarations: */
212
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700213#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
216static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
217static int proc_opensys(struct inode *, struct file *);
218
Helge Deller15ad7cd2006-12-06 20:40:36 -0800219const struct file_operations proc_sys_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 .open = proc_opensys,
221 .read = proc_readsys,
222 .write = proc_writesys,
223};
224
225extern struct proc_dir_entry *proc_sys_root;
226
Al Viro330d57f2005-11-04 10:18:40 +0000227static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
229#endif
230
231/* The default sysctl tables: */
232
233static ctl_table root_table[] = {
234 {
235 .ctl_name = CTL_KERN,
236 .procname = "kernel",
237 .mode = 0555,
238 .child = kern_table,
239 },
240 {
241 .ctl_name = CTL_VM,
242 .procname = "vm",
243 .mode = 0555,
244 .child = vm_table,
245 },
246#ifdef CONFIG_NET
247 {
248 .ctl_name = CTL_NET,
249 .procname = "net",
250 .mode = 0555,
251 .child = net_table,
252 },
253#endif
254 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 .ctl_name = CTL_FS,
256 .procname = "fs",
257 .mode = 0555,
258 .child = fs_table,
259 },
260 {
261 .ctl_name = CTL_DEBUG,
262 .procname = "debug",
263 .mode = 0555,
264 .child = debug_table,
265 },
266 {
267 .ctl_name = CTL_DEV,
268 .procname = "dev",
269 .mode = 0555,
270 .child = dev_table,
271 },
Robert Love0eeca282005-07-12 17:06:03 -0400272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 { .ctl_name = 0 }
274};
275
276static ctl_table kern_table[] = {
277 {
278 .ctl_name = KERN_OSTYPE,
279 .procname = "ostype",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700280 .data = init_uts_ns.name.sysname,
281 .maxlen = sizeof(init_uts_ns.name.sysname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700283 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800284 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 },
286 {
287 .ctl_name = KERN_OSRELEASE,
288 .procname = "osrelease",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700289 .data = init_uts_ns.name.release,
290 .maxlen = sizeof(init_uts_ns.name.release),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700292 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800293 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 },
295 {
296 .ctl_name = KERN_VERSION,
297 .procname = "version",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700298 .data = init_uts_ns.name.version,
299 .maxlen = sizeof(init_uts_ns.name.version),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 .mode = 0444,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700301 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800302 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 },
304 {
305 .ctl_name = KERN_NODENAME,
306 .procname = "hostname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700307 .data = init_uts_ns.name.nodename,
308 .maxlen = sizeof(init_uts_ns.name.nodename),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700310 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800311 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 },
313 {
314 .ctl_name = KERN_DOMAINNAME,
315 .procname = "domainname",
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700316 .data = init_uts_ns.name.domainname,
317 .maxlen = sizeof(init_uts_ns.name.domainname),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 .mode = 0644,
Serge E. Hallyn8218c742006-10-02 02:18:15 -0700319 .proc_handler = &proc_do_uts_string,
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -0800320 .strategy = &sysctl_uts_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 },
322 {
323 .ctl_name = KERN_PANIC,
324 .procname = "panic",
325 .data = &panic_timeout,
326 .maxlen = sizeof(int),
327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
329 },
330 {
331 .ctl_name = KERN_CORE_USES_PID,
332 .procname = "core_uses_pid",
333 .data = &core_uses_pid,
334 .maxlen = sizeof(int),
335 .mode = 0644,
336 .proc_handler = &proc_dointvec,
337 },
338 {
339 .ctl_name = KERN_CORE_PATTERN,
340 .procname = "core_pattern",
341 .data = core_pattern,
Andi Kleend025c9d2006-09-30 23:29:28 -0700342 .maxlen = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 .mode = 0644,
344 .proc_handler = &proc_dostring,
345 .strategy = &sysctl_string,
346 },
347 {
348 .ctl_name = KERN_TAINTED,
349 .procname = "tainted",
350 .data = &tainted,
351 .maxlen = sizeof(int),
352 .mode = 0444,
353 .proc_handler = &proc_dointvec,
354 },
355 {
356 .ctl_name = KERN_CAP_BSET,
357 .procname = "cap-bound",
358 .data = &cap_bset,
359 .maxlen = sizeof(kernel_cap_t),
360 .mode = 0600,
361 .proc_handler = &proc_dointvec_bset,
362 },
363#ifdef CONFIG_BLK_DEV_INITRD
364 {
365 .ctl_name = KERN_REALROOTDEV,
366 .procname = "real-root-dev",
367 .data = &real_root_dev,
368 .maxlen = sizeof(int),
369 .mode = 0644,
370 .proc_handler = &proc_dointvec,
371 },
372#endif
373#ifdef __sparc__
374 {
375 .ctl_name = KERN_SPARC_REBOOT,
376 .procname = "reboot-cmd",
377 .data = reboot_command,
378 .maxlen = 256,
379 .mode = 0644,
380 .proc_handler = &proc_dostring,
381 .strategy = &sysctl_string,
382 },
383 {
384 .ctl_name = KERN_SPARC_STOP_A,
385 .procname = "stop-a",
386 .data = &stop_a_enabled,
387 .maxlen = sizeof (int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
390 },
391 {
392 .ctl_name = KERN_SPARC_SCONS_PWROFF,
393 .procname = "scons-poweroff",
394 .data = &scons_pwroff,
395 .maxlen = sizeof (int),
396 .mode = 0644,
397 .proc_handler = &proc_dointvec,
398 },
399#endif
400#ifdef __hppa__
401 {
402 .ctl_name = KERN_HPPA_PWRSW,
403 .procname = "soft-power",
404 .data = &pwrsw_enabled,
405 .maxlen = sizeof (int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec,
408 },
409 {
410 .ctl_name = KERN_HPPA_UNALIGNED,
411 .procname = "unaligned-trap",
412 .data = &unaligned_enabled,
413 .maxlen = sizeof (int),
414 .mode = 0644,
415 .proc_handler = &proc_dointvec,
416 },
417#endif
418 {
419 .ctl_name = KERN_CTLALTDEL,
420 .procname = "ctrl-alt-del",
421 .data = &C_A_D,
422 .maxlen = sizeof(int),
423 .mode = 0644,
424 .proc_handler = &proc_dointvec,
425 },
426 {
427 .ctl_name = KERN_PRINTK,
428 .procname = "printk",
429 .data = &console_loglevel,
430 .maxlen = 4*sizeof(int),
431 .mode = 0644,
432 .proc_handler = &proc_dointvec,
433 },
434#ifdef CONFIG_KMOD
435 {
436 .ctl_name = KERN_MODPROBE,
437 .procname = "modprobe",
438 .data = &modprobe_path,
439 .maxlen = KMOD_PATH_LEN,
440 .mode = 0644,
441 .proc_handler = &proc_dostring,
442 .strategy = &sysctl_string,
443 },
444#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700445#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 {
447 .ctl_name = KERN_HOTPLUG,
448 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100449 .data = &uevent_helper,
450 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 .mode = 0644,
452 .proc_handler = &proc_dostring,
453 .strategy = &sysctl_string,
454 },
455#endif
456#ifdef CONFIG_CHR_DEV_SG
457 {
458 .ctl_name = KERN_SG_BIG_BUFF,
459 .procname = "sg-big-buff",
460 .data = &sg_big_buff,
461 .maxlen = sizeof (int),
462 .mode = 0444,
463 .proc_handler = &proc_dointvec,
464 },
465#endif
466#ifdef CONFIG_BSD_PROCESS_ACCT
467 {
468 .ctl_name = KERN_ACCT,
469 .procname = "acct",
470 .data = &acct_parm,
471 .maxlen = 3*sizeof(int),
472 .mode = 0644,
473 .proc_handler = &proc_dointvec,
474 },
475#endif
476#ifdef CONFIG_SYSVIPC
477 {
478 .ctl_name = KERN_SHMMAX,
479 .procname = "shmmax",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800480 .data = &init_ipc_ns.shm_ctlmax,
481 .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800483 .proc_handler = &proc_ipc_doulongvec_minmax,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800484 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 },
486 {
487 .ctl_name = KERN_SHMALL,
488 .procname = "shmall",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800489 .data = &init_ipc_ns.shm_ctlall,
490 .maxlen = sizeof (init_ipc_ns.shm_ctlall),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800492 .proc_handler = &proc_ipc_doulongvec_minmax,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800493 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 },
495 {
496 .ctl_name = KERN_SHMMNI,
497 .procname = "shmmni",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800498 .data = &init_ipc_ns.shm_ctlmni,
499 .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800501 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800502 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 },
504 {
505 .ctl_name = KERN_MSGMAX,
506 .procname = "msgmax",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800507 .data = &init_ipc_ns.msg_ctlmax,
508 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800510 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800511 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 },
513 {
514 .ctl_name = KERN_MSGMNI,
515 .procname = "msgmni",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800516 .data = &init_ipc_ns.msg_ctlmni,
517 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800519 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800520 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 },
522 {
523 .ctl_name = KERN_MSGMNB,
524 .procname = "msgmnb",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800525 .data = &init_ipc_ns.msg_ctlmnb,
526 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800528 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800529 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 },
531 {
532 .ctl_name = KERN_SEM,
533 .procname = "sem",
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800534 .data = &init_ipc_ns.sem_ctls,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 .maxlen = 4*sizeof (int),
536 .mode = 0644,
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800537 .proc_handler = &proc_ipc_dointvec,
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800538 .strategy = sysctl_ipc_data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 },
540#endif
541#ifdef CONFIG_MAGIC_SYSRQ
542 {
543 .ctl_name = KERN_SYSRQ,
544 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800545 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .maxlen = sizeof (int),
547 .mode = 0644,
548 .proc_handler = &proc_dointvec,
549 },
550#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700551#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 {
553 .ctl_name = KERN_CADPID,
554 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700555 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 .maxlen = sizeof (int),
557 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700558 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700560#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 {
562 .ctl_name = KERN_MAX_THREADS,
563 .procname = "threads-max",
564 .data = &max_threads,
565 .maxlen = sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
568 },
569 {
570 .ctl_name = KERN_RANDOM,
571 .procname = "random",
572 .mode = 0555,
573 .child = random_table,
574 },
575#ifdef CONFIG_UNIX98_PTYS
576 {
577 .ctl_name = KERN_PTY,
578 .procname = "pty",
579 .mode = 0555,
580 .child = pty_table,
581 },
582#endif
583 {
584 .ctl_name = KERN_OVERFLOWUID,
585 .procname = "overflowuid",
586 .data = &overflowuid,
587 .maxlen = sizeof(int),
588 .mode = 0644,
589 .proc_handler = &proc_dointvec_minmax,
590 .strategy = &sysctl_intvec,
591 .extra1 = &minolduid,
592 .extra2 = &maxolduid,
593 },
594 {
595 .ctl_name = KERN_OVERFLOWGID,
596 .procname = "overflowgid",
597 .data = &overflowgid,
598 .maxlen = sizeof(int),
599 .mode = 0644,
600 .proc_handler = &proc_dointvec_minmax,
601 .strategy = &sysctl_intvec,
602 .extra1 = &minolduid,
603 .extra2 = &maxolduid,
604 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800605#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#ifdef CONFIG_MATHEMU
607 {
608 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
609 .procname = "ieee_emulation_warnings",
610 .data = &sysctl_ieee_emulation_warnings,
611 .maxlen = sizeof(int),
612 .mode = 0644,
613 .proc_handler = &proc_dointvec,
614 },
615#endif
616#ifdef CONFIG_NO_IDLE_HZ
617 {
618 .ctl_name = KERN_HZ_TIMER,
619 .procname = "hz_timer",
620 .data = &sysctl_hz_timer,
621 .maxlen = sizeof(int),
622 .mode = 0644,
623 .proc_handler = &proc_dointvec,
624 },
625#endif
626 {
627 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
628 .procname = "userprocess_debug",
629 .data = &sysctl_userprocess_debug,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec,
633 },
634#endif
635 {
636 .ctl_name = KERN_PIDMAX,
637 .procname = "pid_max",
638 .data = &pid_max,
639 .maxlen = sizeof (int),
640 .mode = 0644,
641 .proc_handler = &proc_dointvec_minmax,
642 .strategy = sysctl_intvec,
643 .extra1 = &pid_max_min,
644 .extra2 = &pid_max_max,
645 },
646 {
647 .ctl_name = KERN_PANIC_ON_OOPS,
648 .procname = "panic_on_oops",
649 .data = &panic_on_oops,
650 .maxlen = sizeof(int),
651 .mode = 0644,
652 .proc_handler = &proc_dointvec,
653 },
654 {
655 .ctl_name = KERN_PRINTK_RATELIMIT,
656 .procname = "printk_ratelimit",
657 .data = &printk_ratelimit_jiffies,
658 .maxlen = sizeof(int),
659 .mode = 0644,
660 .proc_handler = &proc_dointvec_jiffies,
661 .strategy = &sysctl_jiffies,
662 },
663 {
664 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
665 .procname = "printk_ratelimit_burst",
666 .data = &printk_ratelimit_burst,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = &proc_dointvec,
670 },
671 {
672 .ctl_name = KERN_NGROUPS_MAX,
673 .procname = "ngroups_max",
674 .data = &ngroups_max,
675 .maxlen = sizeof (int),
676 .mode = 0444,
677 .proc_handler = &proc_dointvec,
678 },
679#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
680 {
681 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
682 .procname = "unknown_nmi_panic",
683 .data = &unknown_nmi_panic,
684 .maxlen = sizeof (int),
685 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200686 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 },
Don Zickus407984f2006-09-26 10:52:27 +0200688 {
689 .ctl_name = KERN_NMI_WATCHDOG,
690 .procname = "nmi_watchdog",
691 .data = &nmi_watchdog_enabled,
692 .maxlen = sizeof (int),
693 .mode = 0644,
694 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 },
696#endif
697#if defined(CONFIG_X86)
698 {
Don Zickus8da5add2006-09-26 10:52:27 +0200699 .ctl_name = KERN_PANIC_ON_NMI,
700 .procname = "panic_on_unrecovered_nmi",
701 .data = &panic_on_unrecovered_nmi,
702 .maxlen = sizeof(int),
703 .mode = 0644,
704 .proc_handler = &proc_dointvec,
705 },
706 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 .ctl_name = KERN_BOOTLOADER_TYPE,
708 .procname = "bootloader_type",
709 .data = &bootloader_type,
710 .maxlen = sizeof (int),
711 .mode = 0444,
712 .proc_handler = &proc_dointvec,
713 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100714 {
715 .ctl_name = CTL_UNNUMBERED,
716 .procname = "kstack_depth_to_print",
717 .data = &kstack_depth_to_print,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
721 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800723#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 {
725 .ctl_name = KERN_RANDOMIZE,
726 .procname = "randomize_va_space",
727 .data = &randomize_va_space,
728 .maxlen = sizeof(int),
729 .mode = 0644,
730 .proc_handler = &proc_dointvec,
731 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800732#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800733#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700734 {
735 .ctl_name = KERN_SPIN_RETRY,
736 .procname = "spin_retry",
737 .data = &spin_retry,
738 .maxlen = sizeof (int),
739 .mode = 0644,
740 .proc_handler = &proc_dointvec,
741 },
742#endif
Pavel Machekc255d842006-02-20 18:27:58 -0800743#ifdef CONFIG_ACPI_SLEEP
744 {
745 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
746 .procname = "acpi_video_flags",
747 .data = &acpi_video_flags,
748 .maxlen = sizeof (unsigned long),
749 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800750 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800751 },
752#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800753#ifdef CONFIG_IA64
754 {
755 .ctl_name = KERN_IA64_UNALIGNED,
756 .procname = "ignore-unaligned-usertrap",
757 .data = &no_unaligned_warning,
758 .maxlen = sizeof (int),
759 .mode = 0644,
760 .proc_handler = &proc_dointvec,
761 },
762#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200763#ifdef CONFIG_COMPAT
764 {
765 .ctl_name = KERN_COMPAT_LOG,
766 .procname = "compat-log",
767 .data = &compat_log,
768 .maxlen = sizeof (int),
769 .mode = 0644,
770 .proc_handler = &proc_dointvec,
771 },
772#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700773#ifdef CONFIG_RT_MUTEXES
774 {
775 .ctl_name = KERN_MAX_LOCK_DEPTH,
776 .procname = "max_lock_depth",
777 .data = &max_lock_depth,
778 .maxlen = sizeof(int),
779 .mode = 0644,
780 .proc_handler = &proc_dointvec,
781 },
782#endif
783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 { .ctl_name = 0 }
785};
786
787/* Constants for minimum and maximum testing in vm_table.
788 We use these as one-element integer vectors. */
789static int zero;
790static int one_hundred = 100;
791
792
793static ctl_table vm_table[] = {
794 {
795 .ctl_name = VM_OVERCOMMIT_MEMORY,
796 .procname = "overcommit_memory",
797 .data = &sysctl_overcommit_memory,
798 .maxlen = sizeof(sysctl_overcommit_memory),
799 .mode = 0644,
800 .proc_handler = &proc_dointvec,
801 },
802 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700803 .ctl_name = VM_PANIC_ON_OOM,
804 .procname = "panic_on_oom",
805 .data = &sysctl_panic_on_oom,
806 .maxlen = sizeof(sysctl_panic_on_oom),
807 .mode = 0644,
808 .proc_handler = &proc_dointvec,
809 },
810 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .ctl_name = VM_OVERCOMMIT_RATIO,
812 .procname = "overcommit_ratio",
813 .data = &sysctl_overcommit_ratio,
814 .maxlen = sizeof(sysctl_overcommit_ratio),
815 .mode = 0644,
816 .proc_handler = &proc_dointvec,
817 },
818 {
819 .ctl_name = VM_PAGE_CLUSTER,
820 .procname = "page-cluster",
821 .data = &page_cluster,
822 .maxlen = sizeof(int),
823 .mode = 0644,
824 .proc_handler = &proc_dointvec,
825 },
826 {
827 .ctl_name = VM_DIRTY_BACKGROUND,
828 .procname = "dirty_background_ratio",
829 .data = &dirty_background_ratio,
830 .maxlen = sizeof(dirty_background_ratio),
831 .mode = 0644,
832 .proc_handler = &proc_dointvec_minmax,
833 .strategy = &sysctl_intvec,
834 .extra1 = &zero,
835 .extra2 = &one_hundred,
836 },
837 {
838 .ctl_name = VM_DIRTY_RATIO,
839 .procname = "dirty_ratio",
840 .data = &vm_dirty_ratio,
841 .maxlen = sizeof(vm_dirty_ratio),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec_minmax,
844 .strategy = &sysctl_intvec,
845 .extra1 = &zero,
846 .extra2 = &one_hundred,
847 },
848 {
849 .ctl_name = VM_DIRTY_WB_CS,
850 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800851 .data = &dirty_writeback_interval,
852 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 .mode = 0644,
854 .proc_handler = &dirty_writeback_centisecs_handler,
855 },
856 {
857 .ctl_name = VM_DIRTY_EXPIRE_CS,
858 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800859 .data = &dirty_expire_interval,
860 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800862 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 },
864 {
865 .ctl_name = VM_NR_PDFLUSH_THREADS,
866 .procname = "nr_pdflush_threads",
867 .data = &nr_pdflush_threads,
868 .maxlen = sizeof nr_pdflush_threads,
869 .mode = 0444 /* read-only*/,
870 .proc_handler = &proc_dointvec,
871 },
872 {
873 .ctl_name = VM_SWAPPINESS,
874 .procname = "swappiness",
875 .data = &vm_swappiness,
876 .maxlen = sizeof(vm_swappiness),
877 .mode = 0644,
878 .proc_handler = &proc_dointvec_minmax,
879 .strategy = &sysctl_intvec,
880 .extra1 = &zero,
881 .extra2 = &one_hundred,
882 },
883#ifdef CONFIG_HUGETLB_PAGE
884 {
885 .ctl_name = VM_HUGETLB_PAGES,
886 .procname = "nr_hugepages",
887 .data = &max_huge_pages,
888 .maxlen = sizeof(unsigned long),
889 .mode = 0644,
890 .proc_handler = &hugetlb_sysctl_handler,
891 .extra1 = (void *)&hugetlb_zero,
892 .extra2 = (void *)&hugetlb_infinity,
893 },
894 {
895 .ctl_name = VM_HUGETLB_GROUP,
896 .procname = "hugetlb_shm_group",
897 .data = &sysctl_hugetlb_shm_group,
898 .maxlen = sizeof(gid_t),
899 .mode = 0644,
900 .proc_handler = &proc_dointvec,
901 },
902#endif
903 {
904 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
905 .procname = "lowmem_reserve_ratio",
906 .data = &sysctl_lowmem_reserve_ratio,
907 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
908 .mode = 0644,
909 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
910 .strategy = &sysctl_intvec,
911 },
912 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800913 .ctl_name = VM_DROP_PAGECACHE,
914 .procname = "drop_caches",
915 .data = &sysctl_drop_caches,
916 .maxlen = sizeof(int),
917 .mode = 0644,
918 .proc_handler = drop_caches_sysctl_handler,
919 .strategy = &sysctl_intvec,
920 },
921 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 .ctl_name = VM_MIN_FREE_KBYTES,
923 .procname = "min_free_kbytes",
924 .data = &min_free_kbytes,
925 .maxlen = sizeof(min_free_kbytes),
926 .mode = 0644,
927 .proc_handler = &min_free_kbytes_sysctl_handler,
928 .strategy = &sysctl_intvec,
929 .extra1 = &zero,
930 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800931 {
932 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
933 .procname = "percpu_pagelist_fraction",
934 .data = &percpu_pagelist_fraction,
935 .maxlen = sizeof(percpu_pagelist_fraction),
936 .mode = 0644,
937 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
938 .strategy = &sysctl_intvec,
939 .extra1 = &min_percpu_pagelist_fract,
940 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941#ifdef CONFIG_MMU
942 {
943 .ctl_name = VM_MAX_MAP_COUNT,
944 .procname = "max_map_count",
945 .data = &sysctl_max_map_count,
946 .maxlen = sizeof(sysctl_max_map_count),
947 .mode = 0644,
948 .proc_handler = &proc_dointvec
949 },
950#endif
951 {
952 .ctl_name = VM_LAPTOP_MODE,
953 .procname = "laptop_mode",
954 .data = &laptop_mode,
955 .maxlen = sizeof(laptop_mode),
956 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -0800957 .proc_handler = &proc_dointvec_jiffies,
958 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 },
960 {
961 .ctl_name = VM_BLOCK_DUMP,
962 .procname = "block_dump",
963 .data = &block_dump,
964 .maxlen = sizeof(block_dump),
965 .mode = 0644,
966 .proc_handler = &proc_dointvec,
967 .strategy = &sysctl_intvec,
968 .extra1 = &zero,
969 },
970 {
971 .ctl_name = VM_VFS_CACHE_PRESSURE,
972 .procname = "vfs_cache_pressure",
973 .data = &sysctl_vfs_cache_pressure,
974 .maxlen = sizeof(sysctl_vfs_cache_pressure),
975 .mode = 0644,
976 .proc_handler = &proc_dointvec,
977 .strategy = &sysctl_intvec,
978 .extra1 = &zero,
979 },
980#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
981 {
982 .ctl_name = VM_LEGACY_VA_LAYOUT,
983 .procname = "legacy_va_layout",
984 .data = &sysctl_legacy_va_layout,
985 .maxlen = sizeof(sysctl_legacy_va_layout),
986 .mode = 0644,
987 .proc_handler = &proc_dointvec,
988 .strategy = &sysctl_intvec,
989 .extra1 = &zero,
990 },
991#endif
Christoph Lameter17436602006-01-18 17:42:32 -0800992#ifdef CONFIG_NUMA
993 {
994 .ctl_name = VM_ZONE_RECLAIM_MODE,
995 .procname = "zone_reclaim_mode",
996 .data = &zone_reclaim_mode,
997 .maxlen = sizeof(zone_reclaim_mode),
998 .mode = 0644,
999 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001000 .strategy = &sysctl_intvec,
1001 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001002 },
Christoph Lameter96146342006-07-03 00:24:13 -07001003 {
1004 .ctl_name = VM_MIN_UNMAPPED,
1005 .procname = "min_unmapped_ratio",
1006 .data = &sysctl_min_unmapped_ratio,
1007 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1008 .mode = 0644,
1009 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1010 .strategy = &sysctl_intvec,
1011 .extra1 = &zero,
1012 .extra2 = &one_hundred,
1013 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001014 {
1015 .ctl_name = VM_MIN_SLAB,
1016 .procname = "min_slab_ratio",
1017 .data = &sysctl_min_slab_ratio,
1018 .maxlen = sizeof(sysctl_min_slab_ratio),
1019 .mode = 0644,
1020 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1021 .strategy = &sysctl_intvec,
1022 .extra1 = &zero,
1023 .extra2 = &one_hundred,
1024 },
Christoph Lameter17436602006-01-18 17:42:32 -08001025#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001026#ifdef CONFIG_X86_32
1027 {
1028 .ctl_name = VM_VDSO_ENABLED,
1029 .procname = "vdso_enabled",
1030 .data = &vdso_enabled,
1031 .maxlen = sizeof(vdso_enabled),
1032 .mode = 0644,
1033 .proc_handler = &proc_dointvec,
1034 .strategy = &sysctl_intvec,
1035 .extra1 = &zero,
1036 },
1037#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 { .ctl_name = 0 }
1039};
1040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041static ctl_table fs_table[] = {
1042 {
1043 .ctl_name = FS_NRINODE,
1044 .procname = "inode-nr",
1045 .data = &inodes_stat,
1046 .maxlen = 2*sizeof(int),
1047 .mode = 0444,
1048 .proc_handler = &proc_dointvec,
1049 },
1050 {
1051 .ctl_name = FS_STATINODE,
1052 .procname = "inode-state",
1053 .data = &inodes_stat,
1054 .maxlen = 7*sizeof(int),
1055 .mode = 0444,
1056 .proc_handler = &proc_dointvec,
1057 },
1058 {
1059 .ctl_name = FS_NRFILE,
1060 .procname = "file-nr",
1061 .data = &files_stat,
1062 .maxlen = 3*sizeof(int),
1063 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001064 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 },
1066 {
1067 .ctl_name = FS_MAXFILE,
1068 .procname = "file-max",
1069 .data = &files_stat.max_files,
1070 .maxlen = sizeof(int),
1071 .mode = 0644,
1072 .proc_handler = &proc_dointvec,
1073 },
1074 {
1075 .ctl_name = FS_DENTRY,
1076 .procname = "dentry-state",
1077 .data = &dentry_stat,
1078 .maxlen = 6*sizeof(int),
1079 .mode = 0444,
1080 .proc_handler = &proc_dointvec,
1081 },
1082 {
1083 .ctl_name = FS_OVERFLOWUID,
1084 .procname = "overflowuid",
1085 .data = &fs_overflowuid,
1086 .maxlen = sizeof(int),
1087 .mode = 0644,
1088 .proc_handler = &proc_dointvec_minmax,
1089 .strategy = &sysctl_intvec,
1090 .extra1 = &minolduid,
1091 .extra2 = &maxolduid,
1092 },
1093 {
1094 .ctl_name = FS_OVERFLOWGID,
1095 .procname = "overflowgid",
1096 .data = &fs_overflowgid,
1097 .maxlen = sizeof(int),
1098 .mode = 0644,
1099 .proc_handler = &proc_dointvec_minmax,
1100 .strategy = &sysctl_intvec,
1101 .extra1 = &minolduid,
1102 .extra2 = &maxolduid,
1103 },
1104 {
1105 .ctl_name = FS_LEASES,
1106 .procname = "leases-enable",
1107 .data = &leases_enable,
1108 .maxlen = sizeof(int),
1109 .mode = 0644,
1110 .proc_handler = &proc_dointvec,
1111 },
1112#ifdef CONFIG_DNOTIFY
1113 {
1114 .ctl_name = FS_DIR_NOTIFY,
1115 .procname = "dir-notify-enable",
1116 .data = &dir_notify_enable,
1117 .maxlen = sizeof(int),
1118 .mode = 0644,
1119 .proc_handler = &proc_dointvec,
1120 },
1121#endif
1122#ifdef CONFIG_MMU
1123 {
1124 .ctl_name = FS_LEASE_TIME,
1125 .procname = "lease-break-time",
1126 .data = &lease_break_time,
1127 .maxlen = sizeof(int),
1128 .mode = 0644,
1129 .proc_handler = &proc_dointvec,
1130 },
1131 {
1132 .ctl_name = FS_AIO_NR,
1133 .procname = "aio-nr",
1134 .data = &aio_nr,
1135 .maxlen = sizeof(aio_nr),
1136 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001137 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 },
1139 {
1140 .ctl_name = FS_AIO_MAX_NR,
1141 .procname = "aio-max-nr",
1142 .data = &aio_max_nr,
1143 .maxlen = sizeof(aio_max_nr),
1144 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001145 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001147#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001148 {
1149 .ctl_name = FS_INOTIFY,
1150 .procname = "inotify",
1151 .mode = 0555,
1152 .child = inotify_table,
1153 },
1154#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001156 {
1157 .ctl_name = KERN_SETUID_DUMPABLE,
1158 .procname = "suid_dumpable",
1159 .data = &suid_dumpable,
1160 .maxlen = sizeof(int),
1161 .mode = 0644,
1162 .proc_handler = &proc_dointvec,
1163 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 { .ctl_name = 0 }
1165};
1166
1167static ctl_table debug_table[] = {
1168 { .ctl_name = 0 }
1169};
1170
1171static ctl_table dev_table[] = {
1172 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001173};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
1175extern void init_irq_proc (void);
1176
Al Viro330d57f2005-11-04 10:18:40 +00001177static DEFINE_SPINLOCK(sysctl_lock);
1178
1179/* called under sysctl_lock */
1180static int use_table(struct ctl_table_header *p)
1181{
1182 if (unlikely(p->unregistering))
1183 return 0;
1184 p->used++;
1185 return 1;
1186}
1187
1188/* called under sysctl_lock */
1189static void unuse_table(struct ctl_table_header *p)
1190{
1191 if (!--p->used)
1192 if (unlikely(p->unregistering))
1193 complete(p->unregistering);
1194}
1195
1196/* called under sysctl_lock, will reacquire if has to wait */
1197static void start_unregistering(struct ctl_table_header *p)
1198{
1199 /*
1200 * if p->used is 0, nobody will ever touch that entry again;
1201 * we'll eliminate all paths to it before dropping sysctl_lock
1202 */
1203 if (unlikely(p->used)) {
1204 struct completion wait;
1205 init_completion(&wait);
1206 p->unregistering = &wait;
1207 spin_unlock(&sysctl_lock);
1208 wait_for_completion(&wait);
1209 spin_lock(&sysctl_lock);
1210 }
1211 /*
1212 * do not remove from the list until nobody holds it; walking the
1213 * list in do_sysctl() relies on that.
1214 */
1215 list_del_init(&p->ctl_entry);
1216}
1217
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218void __init sysctl_init(void)
1219{
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001220#ifdef CONFIG_PROC_SYSCTL
Al Viro330d57f2005-11-04 10:18:40 +00001221 register_proc_table(root_table, proc_sys_root, &root_table_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 init_irq_proc();
1223#endif
1224}
1225
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001226#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1228 void __user *newval, size_t newlen)
1229{
1230 struct list_head *tmp;
Al Viro330d57f2005-11-04 10:18:40 +00001231 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1234 return -ENOTDIR;
1235 if (oldval) {
1236 int old_len;
1237 if (!oldlenp || get_user(old_len, oldlenp))
1238 return -EFAULT;
1239 }
Al Viro330d57f2005-11-04 10:18:40 +00001240 spin_lock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 tmp = &root_table_header.ctl_entry;
1242 do {
1243 struct ctl_table_header *head =
1244 list_entry(tmp, struct ctl_table_header, ctl_entry);
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,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001252 newval, newlen, head->ctl_table);
Al Viro330d57f2005-11-04 10:18:40 +00001253
1254 spin_lock(&sysctl_lock);
1255 unuse_table(head);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 if (error != -ENOTDIR)
Al Viro330d57f2005-11-04 10:18:40 +00001257 break;
1258 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1259 spin_unlock(&sysctl_lock);
1260 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261}
1262
1263asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1264{
1265 struct __sysctl_args tmp;
1266 int error;
1267
1268 if (copy_from_user(&tmp, args, sizeof(tmp)))
1269 return -EFAULT;
1270
1271 lock_kernel();
1272 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1273 tmp.newval, tmp.newlen);
1274 unlock_kernel();
1275 return error;
1276}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001277#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
1279/*
1280 * ctl_perm does NOT grant the superuser all rights automatically, because
1281 * some sysctl variables are readonly even to root.
1282 */
1283
1284static int test_perm(int mode, int op)
1285{
1286 if (!current->euid)
1287 mode >>= 6;
1288 else if (in_egroup_p(0))
1289 mode >>= 3;
1290 if ((mode & op & 0007) == op)
1291 return 0;
1292 return -EACCES;
1293}
1294
1295static inline int ctl_perm(ctl_table *table, int op)
1296{
1297 int error;
1298 error = security_sysctl(table, op);
1299 if (error)
1300 return error;
1301 return test_perm(table->mode, op);
1302}
1303
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001304#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305static int parse_table(int __user *name, int nlen,
1306 void __user *oldval, size_t __user *oldlenp,
1307 void __user *newval, size_t newlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001308 ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
1310 int n;
1311repeat:
1312 if (!nlen)
1313 return -ENOTDIR;
1314 if (get_user(n, name))
1315 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001316 for ( ; table->ctl_name || table->procname; table++) {
1317 if (!table->ctl_name)
1318 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 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,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001328 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 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,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001339 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 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,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001350 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
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,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001364 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 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
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001535 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 /* 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;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001582 for (; table->ctl_name || table->procname; table++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 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;
Josef "Jeff" Sipekf3a43f32006-12-08 02:36:43 -08001617 struct proc_dir_entry *de = PDE(file->f_path.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 */
Eric W. Biedermancf9f1512006-12-08 02:39:55 -08001756
Serge E. Hallyn8218c742006-10-02 02:18:15 -07001757static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 void __user *buffer, size_t *lenp, loff_t *ppos)
1759{
1760 int r;
Eric W. Biedermancf9f1512006-12-08 02:39:55 -08001761 void *which;
1762 which = get_uts(table, write);
1763 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1764 put_uts(table, write, which);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 return r;
1766}
1767
1768static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1769 int *valp,
1770 int write, void *data)
1771{
1772 if (write) {
1773 *valp = *negp ? -*lvalp : *lvalp;
1774 } else {
1775 int val = *valp;
1776 if (val < 0) {
1777 *negp = -1;
1778 *lvalp = (unsigned long)-val;
1779 } else {
1780 *negp = 0;
1781 *lvalp = (unsigned long)val;
1782 }
1783 }
1784 return 0;
1785}
1786
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001787static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1788 int write, struct file *filp, void __user *buffer,
1789 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1791 int write, void *data),
1792 void *data)
1793{
1794#define TMPBUFLEN 21
1795 int *i, vleft, first=1, neg, val;
1796 unsigned long lval;
1797 size_t left, len;
1798
1799 char buf[TMPBUFLEN], *p;
1800 char __user *s = buffer;
1801
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001802 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 (*ppos && !write)) {
1804 *lenp = 0;
1805 return 0;
1806 }
1807
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001808 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 vleft = table->maxlen / sizeof(*i);
1810 left = *lenp;
1811
1812 if (!conv)
1813 conv = do_proc_dointvec_conv;
1814
1815 for (; left && vleft--; i++, first=0) {
1816 if (write) {
1817 while (left) {
1818 char c;
1819 if (get_user(c, s))
1820 return -EFAULT;
1821 if (!isspace(c))
1822 break;
1823 left--;
1824 s++;
1825 }
1826 if (!left)
1827 break;
1828 neg = 0;
1829 len = left;
1830 if (len > sizeof(buf) - 1)
1831 len = sizeof(buf) - 1;
1832 if (copy_from_user(buf, s, len))
1833 return -EFAULT;
1834 buf[len] = 0;
1835 p = buf;
1836 if (*p == '-' && left > 1) {
1837 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001838 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 }
1840 if (*p < '0' || *p > '9')
1841 break;
1842
1843 lval = simple_strtoul(p, &p, 0);
1844
1845 len = p-buf;
1846 if ((len < left) && *p && !isspace(*p))
1847 break;
1848 if (neg)
1849 val = -val;
1850 s += len;
1851 left -= len;
1852
1853 if (conv(&neg, &lval, i, 1, data))
1854 break;
1855 } else {
1856 p = buf;
1857 if (!first)
1858 *p++ = '\t';
1859
1860 if (conv(&neg, &lval, i, 0, data))
1861 break;
1862
1863 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1864 len = strlen(buf);
1865 if (len > left)
1866 len = left;
1867 if(copy_to_user(s, buf, len))
1868 return -EFAULT;
1869 left -= len;
1870 s += len;
1871 }
1872 }
1873
1874 if (!write && !first && left) {
1875 if(put_user('\n', s))
1876 return -EFAULT;
1877 left--, s++;
1878 }
1879 if (write) {
1880 while (left) {
1881 char c;
1882 if (get_user(c, s++))
1883 return -EFAULT;
1884 if (!isspace(c))
1885 break;
1886 left--;
1887 }
1888 }
1889 if (write && first)
1890 return -EINVAL;
1891 *lenp -= left;
1892 *ppos += *lenp;
1893 return 0;
1894#undef TMPBUFLEN
1895}
1896
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001897static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1898 void __user *buffer, size_t *lenp, loff_t *ppos,
1899 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1900 int write, void *data),
1901 void *data)
1902{
1903 return __do_proc_dointvec(table->data, table, write, filp,
1904 buffer, lenp, ppos, conv, data);
1905}
1906
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907/**
1908 * proc_dointvec - read a vector of integers
1909 * @table: the sysctl table
1910 * @write: %TRUE if this is a write to the sysctl file
1911 * @filp: the file structure
1912 * @buffer: the user buffer
1913 * @lenp: the size of the user buffer
1914 * @ppos: file position
1915 *
1916 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1917 * values from/to the user buffer, treated as an ASCII string.
1918 *
1919 * Returns 0 on success.
1920 */
1921int proc_dointvec(ctl_table *table, int write, struct file *filp,
1922 void __user *buffer, size_t *lenp, loff_t *ppos)
1923{
1924 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1925 NULL,NULL);
1926}
1927
1928#define OP_SET 0
1929#define OP_AND 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930
1931static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1932 int *valp,
1933 int write, void *data)
1934{
1935 int op = *(int *)data;
1936 if (write) {
1937 int val = *negp ? -*lvalp : *lvalp;
1938 switch(op) {
1939 case OP_SET: *valp = val; break;
1940 case OP_AND: *valp &= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 }
1942 } else {
1943 int val = *valp;
1944 if (val < 0) {
1945 *negp = -1;
1946 *lvalp = (unsigned long)-val;
1947 } else {
1948 *negp = 0;
1949 *lvalp = (unsigned long)val;
1950 }
1951 }
1952 return 0;
1953}
1954
1955/*
1956 * init may raise the set.
1957 */
1958
1959int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1960 void __user *buffer, size_t *lenp, loff_t *ppos)
1961{
1962 int op;
1963
Eric Paris6ff1b442007-02-10 01:43:19 -08001964 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 return -EPERM;
1966 }
1967
Sukadev Bhattiproluf400e192006-09-29 02:00:07 -07001968 op = is_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1970 do_proc_dointvec_bset_conv,&op);
1971}
1972
1973struct do_proc_dointvec_minmax_conv_param {
1974 int *min;
1975 int *max;
1976};
1977
1978static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1979 int *valp,
1980 int write, void *data)
1981{
1982 struct do_proc_dointvec_minmax_conv_param *param = data;
1983 if (write) {
1984 int val = *negp ? -*lvalp : *lvalp;
1985 if ((param->min && *param->min > val) ||
1986 (param->max && *param->max < val))
1987 return -EINVAL;
1988 *valp = val;
1989 } else {
1990 int val = *valp;
1991 if (val < 0) {
1992 *negp = -1;
1993 *lvalp = (unsigned long)-val;
1994 } else {
1995 *negp = 0;
1996 *lvalp = (unsigned long)val;
1997 }
1998 }
1999 return 0;
2000}
2001
2002/**
2003 * proc_dointvec_minmax - read a vector of integers with min/max values
2004 * @table: the sysctl table
2005 * @write: %TRUE if this is a write to the sysctl file
2006 * @filp: the file structure
2007 * @buffer: the user buffer
2008 * @lenp: the size of the user buffer
2009 * @ppos: file position
2010 *
2011 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2012 * values from/to the user buffer, treated as an ASCII string.
2013 *
2014 * This routine will ensure the values are within the range specified by
2015 * table->extra1 (min) and table->extra2 (max).
2016 *
2017 * Returns 0 on success.
2018 */
2019int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2020 void __user *buffer, size_t *lenp, loff_t *ppos)
2021{
2022 struct do_proc_dointvec_minmax_conv_param param = {
2023 .min = (int *) table->extra1,
2024 .max = (int *) table->extra2,
2025 };
2026 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2027 do_proc_dointvec_minmax_conv, &param);
2028}
2029
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002030static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 struct file *filp,
2032 void __user *buffer,
2033 size_t *lenp, loff_t *ppos,
2034 unsigned long convmul,
2035 unsigned long convdiv)
2036{
2037#define TMPBUFLEN 21
2038 unsigned long *i, *min, *max, val;
2039 int vleft, first=1, neg;
2040 size_t len, left;
2041 char buf[TMPBUFLEN], *p;
2042 char __user *s = buffer;
2043
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002044 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 (*ppos && !write)) {
2046 *lenp = 0;
2047 return 0;
2048 }
2049
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002050 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 min = (unsigned long *) table->extra1;
2052 max = (unsigned long *) table->extra2;
2053 vleft = table->maxlen / sizeof(unsigned long);
2054 left = *lenp;
2055
2056 for (; left && vleft--; i++, min++, max++, first=0) {
2057 if (write) {
2058 while (left) {
2059 char c;
2060 if (get_user(c, s))
2061 return -EFAULT;
2062 if (!isspace(c))
2063 break;
2064 left--;
2065 s++;
2066 }
2067 if (!left)
2068 break;
2069 neg = 0;
2070 len = left;
2071 if (len > TMPBUFLEN-1)
2072 len = TMPBUFLEN-1;
2073 if (copy_from_user(buf, s, len))
2074 return -EFAULT;
2075 buf[len] = 0;
2076 p = buf;
2077 if (*p == '-' && left > 1) {
2078 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002079 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 }
2081 if (*p < '0' || *p > '9')
2082 break;
2083 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2084 len = p-buf;
2085 if ((len < left) && *p && !isspace(*p))
2086 break;
2087 if (neg)
2088 val = -val;
2089 s += len;
2090 left -= len;
2091
2092 if(neg)
2093 continue;
2094 if ((min && val < *min) || (max && val > *max))
2095 continue;
2096 *i = val;
2097 } else {
2098 p = buf;
2099 if (!first)
2100 *p++ = '\t';
2101 sprintf(p, "%lu", convdiv * (*i) / convmul);
2102 len = strlen(buf);
2103 if (len > left)
2104 len = left;
2105 if(copy_to_user(s, buf, len))
2106 return -EFAULT;
2107 left -= len;
2108 s += len;
2109 }
2110 }
2111
2112 if (!write && !first && left) {
2113 if(put_user('\n', s))
2114 return -EFAULT;
2115 left--, s++;
2116 }
2117 if (write) {
2118 while (left) {
2119 char c;
2120 if (get_user(c, s++))
2121 return -EFAULT;
2122 if (!isspace(c))
2123 break;
2124 left--;
2125 }
2126 }
2127 if (write && first)
2128 return -EINVAL;
2129 *lenp -= left;
2130 *ppos += *lenp;
2131 return 0;
2132#undef TMPBUFLEN
2133}
2134
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002135static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2136 struct file *filp,
2137 void __user *buffer,
2138 size_t *lenp, loff_t *ppos,
2139 unsigned long convmul,
2140 unsigned long convdiv)
2141{
2142 return __do_proc_doulongvec_minmax(table->data, table, write,
2143 filp, buffer, lenp, ppos, convmul, convdiv);
2144}
2145
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146/**
2147 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2148 * @table: the sysctl table
2149 * @write: %TRUE if this is a write to the sysctl file
2150 * @filp: the file structure
2151 * @buffer: the user buffer
2152 * @lenp: the size of the user buffer
2153 * @ppos: file position
2154 *
2155 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2156 * values from/to the user buffer, treated as an ASCII string.
2157 *
2158 * This routine will ensure the values are within the range specified by
2159 * table->extra1 (min) and table->extra2 (max).
2160 *
2161 * Returns 0 on success.
2162 */
2163int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2164 void __user *buffer, size_t *lenp, loff_t *ppos)
2165{
2166 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2167}
2168
2169/**
2170 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2171 * @table: the sysctl table
2172 * @write: %TRUE if this is a write to the sysctl file
2173 * @filp: the file structure
2174 * @buffer: the user buffer
2175 * @lenp: the size of the user buffer
2176 * @ppos: file position
2177 *
2178 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2179 * values from/to the user buffer, treated as an ASCII string. The values
2180 * are treated as milliseconds, and converted to jiffies when they are stored.
2181 *
2182 * This routine will ensure the values are within the range specified by
2183 * table->extra1 (min) and table->extra2 (max).
2184 *
2185 * Returns 0 on success.
2186 */
2187int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2188 struct file *filp,
2189 void __user *buffer,
2190 size_t *lenp, loff_t *ppos)
2191{
2192 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2193 lenp, ppos, HZ, 1000l);
2194}
2195
2196
2197static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2198 int *valp,
2199 int write, void *data)
2200{
2201 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002202 if (*lvalp > LONG_MAX / HZ)
2203 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2205 } else {
2206 int val = *valp;
2207 unsigned long lval;
2208 if (val < 0) {
2209 *negp = -1;
2210 lval = (unsigned long)-val;
2211 } else {
2212 *negp = 0;
2213 lval = (unsigned long)val;
2214 }
2215 *lvalp = lval / HZ;
2216 }
2217 return 0;
2218}
2219
2220static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2221 int *valp,
2222 int write, void *data)
2223{
2224 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002225 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2226 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2228 } else {
2229 int val = *valp;
2230 unsigned long lval;
2231 if (val < 0) {
2232 *negp = -1;
2233 lval = (unsigned long)-val;
2234 } else {
2235 *negp = 0;
2236 lval = (unsigned long)val;
2237 }
2238 *lvalp = jiffies_to_clock_t(lval);
2239 }
2240 return 0;
2241}
2242
2243static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2244 int *valp,
2245 int write, void *data)
2246{
2247 if (write) {
2248 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2249 } else {
2250 int val = *valp;
2251 unsigned long lval;
2252 if (val < 0) {
2253 *negp = -1;
2254 lval = (unsigned long)-val;
2255 } else {
2256 *negp = 0;
2257 lval = (unsigned long)val;
2258 }
2259 *lvalp = jiffies_to_msecs(lval);
2260 }
2261 return 0;
2262}
2263
2264/**
2265 * proc_dointvec_jiffies - read a vector of integers as seconds
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
2268 * @filp: the file structure
2269 * @buffer: the user buffer
2270 * @lenp: the size of the user buffer
2271 * @ppos: file position
2272 *
2273 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2274 * values from/to the user buffer, treated as an ASCII string.
2275 * The values read are assumed to be in seconds, and are converted into
2276 * jiffies.
2277 *
2278 * Returns 0 on success.
2279 */
2280int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2281 void __user *buffer, size_t *lenp, loff_t *ppos)
2282{
2283 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2284 do_proc_dointvec_jiffies_conv,NULL);
2285}
2286
2287/**
2288 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2289 * @table: the sysctl table
2290 * @write: %TRUE if this is a write to the sysctl file
2291 * @filp: the file structure
2292 * @buffer: the user buffer
2293 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002294 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 *
2296 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2297 * values from/to the user buffer, treated as an ASCII string.
2298 * The values read are assumed to be in 1/USER_HZ seconds, and
2299 * are converted into jiffies.
2300 *
2301 * Returns 0 on success.
2302 */
2303int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2304 void __user *buffer, size_t *lenp, loff_t *ppos)
2305{
2306 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2307 do_proc_dointvec_userhz_jiffies_conv,NULL);
2308}
2309
2310/**
2311 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2312 * @table: the sysctl table
2313 * @write: %TRUE if this is a write to the sysctl file
2314 * @filp: the file structure
2315 * @buffer: the user buffer
2316 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002317 * @ppos: file position
2318 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 *
2320 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2321 * values from/to the user buffer, treated as an ASCII string.
2322 * The values read are assumed to be in 1/1000 seconds, and
2323 * are converted into jiffies.
2324 *
2325 * Returns 0 on success.
2326 */
2327int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2328 void __user *buffer, size_t *lenp, loff_t *ppos)
2329{
2330 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2331 do_proc_dointvec_ms_jiffies_conv, NULL);
2332}
2333
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002334#ifdef CONFIG_SYSVIPC
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002335static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2336 void __user *buffer, size_t *lenp, loff_t *ppos)
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002337{
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002338 void *which;
2339 which = get_ipc(table, write);
2340 return __do_proc_dointvec(which, table, write, filp, buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002341 lenp, ppos, NULL, NULL);
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002342}
2343
2344static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2345 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2346{
2347 void *which;
2348 which = get_ipc(table, write);
2349 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002350 lenp, ppos, 1l, 1l);
2351}
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -08002352
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002353#endif
2354
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002355static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2356 void __user *buffer, size_t *lenp, loff_t *ppos)
2357{
2358 struct pid *new_pid;
2359 pid_t tmp;
2360 int r;
2361
2362 tmp = pid_nr(cad_pid);
2363
2364 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2365 lenp, ppos, NULL, NULL);
2366 if (r || !write)
2367 return r;
2368
2369 new_pid = find_get_pid(tmp);
2370 if (!new_pid)
2371 return -ESRCH;
2372
2373 put_pid(xchg(&cad_pid, new_pid));
2374 return 0;
2375}
2376
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377#else /* CONFIG_PROC_FS */
2378
2379int proc_dostring(ctl_table *table, int write, struct file *filp,
2380 void __user *buffer, size_t *lenp, loff_t *ppos)
2381{
2382 return -ENOSYS;
2383}
2384
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002385static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2386 void __user *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387{
2388 return -ENOSYS;
2389}
2390
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002391#ifdef CONFIG_SYSVIPC
2392static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2393 void __user *buffer, size_t *lenp, loff_t *ppos)
2394{
2395 return -ENOSYS;
2396}
Randy Dunlapd53ef072006-12-10 02:18:36 -08002397static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2398 void __user *buffer, size_t *lenp, loff_t *ppos)
2399{
2400 return -ENOSYS;
2401}
2402static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2403 struct file *filp, void __user *buffer,
2404 size_t *lenp, loff_t *ppos)
2405{
2406 return -ENOSYS;
2407}
Serge E. Hallyn8218c742006-10-02 02:18:15 -07002408#endif
2409
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410int proc_dointvec(ctl_table *table, int write, struct file *filp,
2411 void __user *buffer, size_t *lenp, loff_t *ppos)
2412{
2413 return -ENOSYS;
2414}
2415
2416int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2417 void __user *buffer, size_t *lenp, loff_t *ppos)
2418{
2419 return -ENOSYS;
2420}
2421
2422int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2423 void __user *buffer, size_t *lenp, loff_t *ppos)
2424{
2425 return -ENOSYS;
2426}
2427
2428int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2429 void __user *buffer, size_t *lenp, loff_t *ppos)
2430{
2431 return -ENOSYS;
2432}
2433
2434int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2436{
2437 return -ENOSYS;
2438}
2439
2440int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2441 void __user *buffer, size_t *lenp, loff_t *ppos)
2442{
2443 return -ENOSYS;
2444}
2445
2446int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2447 void __user *buffer, size_t *lenp, loff_t *ppos)
2448{
2449 return -ENOSYS;
2450}
2451
2452int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2453 struct file *filp,
2454 void __user *buffer,
2455 size_t *lenp, loff_t *ppos)
2456{
2457 return -ENOSYS;
2458}
2459
2460
2461#endif /* CONFIG_PROC_FS */
2462
2463
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002464#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465/*
2466 * General sysctl support routines
2467 */
2468
2469/* The generic string strategy routine: */
2470int sysctl_string(ctl_table *table, int __user *name, int nlen,
2471 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002472 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 if (!table->data || !table->maxlen)
2475 return -ENOTDIR;
2476
2477 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002478 size_t bufsize;
2479 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002481 if (bufsize) {
2482 size_t len = strlen(table->data), copied;
2483
2484 /* This shouldn't trigger for a well-formed sysctl */
2485 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002487
2488 /* Copy up to a max of bufsize-1 bytes of the string */
2489 copied = (len >= bufsize) ? bufsize - 1 : len;
2490
2491 if (copy_to_user(oldval, table->data, copied) ||
2492 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002494 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 return -EFAULT;
2496 }
2497 }
2498 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002499 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 if (len > table->maxlen)
2501 len = table->maxlen;
2502 if(copy_from_user(table->data, newval, len))
2503 return -EFAULT;
2504 if (len == table->maxlen)
2505 len--;
2506 ((char *) table->data)[len] = 0;
2507 }
Yi Yang82c9df82005-12-30 16:37:10 +08002508 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509}
2510
2511/*
2512 * This function makes sure that all of the integers in the vector
2513 * are between the minimum and maximum values given in the arrays
2514 * table->extra1 and table->extra2, respectively.
2515 */
2516int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2517 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002518 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519{
2520
2521 if (newval && newlen) {
2522 int __user *vec = (int __user *) newval;
2523 int *min = (int *) table->extra1;
2524 int *max = (int *) table->extra2;
2525 size_t length;
2526 int i;
2527
2528 if (newlen % sizeof(int) != 0)
2529 return -EINVAL;
2530
2531 if (!table->extra1 && !table->extra2)
2532 return 0;
2533
2534 if (newlen > table->maxlen)
2535 newlen = table->maxlen;
2536 length = newlen / sizeof(int);
2537
2538 for (i = 0; i < length; i++) {
2539 int value;
2540 if (get_user(value, vec + i))
2541 return -EFAULT;
2542 if (min && value < min[i])
2543 return -EINVAL;
2544 if (max && value > max[i])
2545 return -EINVAL;
2546 }
2547 }
2548 return 0;
2549}
2550
2551/* Strategy function to convert jiffies to seconds */
2552int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2553 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002554 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002556 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002558
2559 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002561 if (olen) {
2562 int val;
2563
2564 if (olen < sizeof(int))
2565 return -EINVAL;
2566
2567 val = *(int *)(table->data) / HZ;
2568 if (put_user(val, (int __user *)oldval))
2569 return -EFAULT;
2570 if (put_user(sizeof(int), oldlenp))
2571 return -EFAULT;
2572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 }
2574 if (newval && newlen) {
2575 int new;
2576 if (newlen != sizeof(int))
2577 return -EINVAL;
2578 if (get_user(new, (int __user *)newval))
2579 return -EFAULT;
2580 *(int *)(table->data) = new*HZ;
2581 }
2582 return 1;
2583}
2584
2585/* Strategy function to convert jiffies to seconds */
2586int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002588 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002590 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002592
2593 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002595 if (olen) {
2596 int val;
2597
2598 if (olen < sizeof(int))
2599 return -EINVAL;
2600
2601 val = jiffies_to_msecs(*(int *)(table->data));
2602 if (put_user(val, (int __user *)oldval))
2603 return -EFAULT;
2604 if (put_user(sizeof(int), oldlenp))
2605 return -EFAULT;
2606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 }
2608 if (newval && newlen) {
2609 int new;
2610 if (newlen != sizeof(int))
2611 return -EINVAL;
2612 if (get_user(new, (int __user *)newval))
2613 return -EFAULT;
2614 *(int *)(table->data) = msecs_to_jiffies(new);
2615 }
2616 return 1;
2617}
2618
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002619
2620/* The generic string strategy routine: */
2621static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2622 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002623 void __user *newval, size_t newlen)
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002624{
2625 struct ctl_table uts_table;
2626 int r, write;
2627 write = newval && newlen;
2628 memcpy(&uts_table, table, sizeof(uts_table));
2629 uts_table.data = get_uts(table, write);
2630 r = sysctl_string(&uts_table, name, nlen,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002631 oldval, oldlenp, newval, newlen);
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002632 put_uts(table, write, uts_table.data);
2633 return r;
2634}
2635
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002636#ifdef CONFIG_SYSVIPC
2637/* The generic sysctl ipc data routine. */
2638static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2639 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002640 void __user *newval, size_t newlen)
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002641{
2642 size_t len;
2643 void *data;
2644
2645 /* Get out of I don't have a variable */
2646 if (!table->data || !table->maxlen)
2647 return -ENOTDIR;
2648
2649 data = get_ipc(table, 1);
2650 if (!data)
2651 return -ENOTDIR;
2652
2653 if (oldval && oldlenp) {
2654 if (get_user(len, oldlenp))
2655 return -EFAULT;
2656 if (len) {
2657 if (len > table->maxlen)
2658 len = table->maxlen;
2659 if (copy_to_user(oldval, data, len))
2660 return -EFAULT;
2661 if (put_user(len, oldlenp))
2662 return -EFAULT;
2663 }
2664 }
2665
2666 if (newval && newlen) {
2667 if (newlen > table->maxlen)
2668 newlen = table->maxlen;
2669
2670 if (copy_from_user(data, newval, newlen))
2671 return -EFAULT;
2672 }
2673 return 1;
2674}
2675#endif
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;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002683 struct __sysctl_args tmp;
2684 int name[CTL_MAXNAME];
2685 int i;
2686
2687 /* Read in the sysctl name for better debug message logging */
2688 if (copy_from_user(&tmp, args, sizeof(tmp)))
2689 return -EFAULT;
2690 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2691 return -ENOTDIR;
2692 for (i = 0; i < tmp.nlen; i++)
2693 if (get_user(name[i], tmp.name + i))
2694 return -EFAULT;
2695
2696 /* Ignore accesses to kernel.version */
2697 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2698 goto out;
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002699
2700 if (msg_count < 5) {
2701 msg_count++;
2702 printk(KERN_INFO
2703 "warning: process `%s' used the removed sysctl "
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002704 "system call with ", current->comm);
2705 for (i = 0; i < tmp.nlen; i++)
2706 printk("%d.", name[i]);
2707 printk("\n");
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002708 }
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002709out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 return -ENOSYS;
2711}
2712
2713int sysctl_string(ctl_table *table, int __user *name, int nlen,
2714 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002715 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716{
2717 return -ENOSYS;
2718}
2719
2720int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2721 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002722 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723{
2724 return -ENOSYS;
2725}
2726
2727int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2728 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002729 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730{
2731 return -ENOSYS;
2732}
2733
2734int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2735 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002736 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737{
2738 return -ENOSYS;
2739}
2740
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002741static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2742 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002743 void __user *newval, size_t newlen)
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002744{
2745 return -ENOSYS;
2746}
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002747static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2748 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002749 void __user *newval, size_t newlen)
Eric W. Biederman6b49a252006-12-08 02:39:57 -08002750{
2751 return -ENOSYS;
2752}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002753#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754
2755/*
2756 * No sense putting this after each symbol definition, twice,
2757 * exception granted :-)
2758 */
2759EXPORT_SYMBOL(proc_dointvec);
2760EXPORT_SYMBOL(proc_dointvec_jiffies);
2761EXPORT_SYMBOL(proc_dointvec_minmax);
2762EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2763EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2764EXPORT_SYMBOL(proc_dostring);
2765EXPORT_SYMBOL(proc_doulongvec_minmax);
2766EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2767EXPORT_SYMBOL(register_sysctl_table);
2768EXPORT_SYMBOL(sysctl_intvec);
2769EXPORT_SYMBOL(sysctl_jiffies);
2770EXPORT_SYMBOL(sysctl_ms_jiffies);
2771EXPORT_SYMBOL(sysctl_string);
2772EXPORT_SYMBOL(unregister_sysctl_table);