blob: 89b7d95ecf51f1dc7a796996aa3d32fc4bcf525d [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>
Andrew Morgan72c2d582007-10-18 03:05:59 -070027#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/ctype.h>
29#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/smp_lock.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070031#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#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>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070048#include <linux/reboot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <asm/uaccess.h>
51#include <asm/processor.h>
52
Andi Kleen29cbc782006-09-30 01:47:55 +020053#ifdef CONFIG_X86
54#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010055#include <asm/stacktrace.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020056#endif
57
Eric W. Biederman7058cb02007-10-18 03:05:58 -070058static int deprecated_sysctl_warning(struct __sysctl_args *args);
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;
Ingo Molnar45807a12007-07-15 23:40:10 -070064extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065extern int sysctl_overcommit_memory;
66extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070067extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070068extern int sysctl_oom_kill_allocating_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070071extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern int pid_max;
74extern int min_free_kbytes;
75extern int printk_ratelimit_jiffies;
76extern int printk_ratelimit_burst;
77extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080078extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080079extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020080extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070081extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070082extern int sysctl_stat_interval;
Peter Zijlstrabdf4c482007-07-19 01:48:15 -070083extern int audit_argv_kb;
Arjan van de Ven97455122008-01-25 21:08:34 +010084extern int latencytop_enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070086/* Constants used for minimum and maximum */
87#ifdef CONFIG_DETECT_SOFTLOCKUP
88static int one = 1;
89static int sixty = 60;
90#endif
91
92#ifdef CONFIG_MMU
93static int two = 2;
94#endif
95
96static int zero;
97static int one_hundred = 100;
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
100static int maxolduid = 65535;
101static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800102static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104static int ngroups_max = NGROUPS_MAX;
105
106#ifdef CONFIG_KMOD
107extern char modprobe_path[];
108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#ifdef CONFIG_CHR_DEV_SG
110extern int sg_big_buff;
111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113#ifdef __sparc__
114extern char reboot_command [];
115extern int stop_a_enabled;
116extern int scons_pwroff;
117#endif
118
119#ifdef __hppa__
120extern int pwrsw_enabled;
121extern int unaligned_enabled;
122#endif
123
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800124#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#ifdef CONFIG_MATHEMU
126extern int sysctl_ieee_emulation_warnings;
127#endif
128extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700129extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#endif
131
132extern int sysctl_hz_timer;
133
134#ifdef CONFIG_BSD_PROCESS_ACCT
135extern int acct_parm[];
136#endif
137
Jes Sorensend2b176e2006-02-28 09:42:23 -0800138#ifdef CONFIG_IA64
139extern int no_unaligned_warning;
140#endif
141
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700142#ifdef CONFIG_RT_MUTEXES
143extern int max_lock_depth;
144#endif
145
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700146#ifdef CONFIG_SYSCTL_SYSCALL
147static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700148 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700149#endif
150
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700153static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700154 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700155static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800156 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700158
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700159static struct ctl_table root_table[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160static struct ctl_table_header root_table_header =
161 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
162
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700163static struct ctl_table kern_table[];
164static struct ctl_table vm_table[];
165static struct ctl_table fs_table[];
166static struct ctl_table debug_table[];
167static struct ctl_table dev_table[];
168extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700169#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700170extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400171#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
174int sysctl_legacy_va_layout;
175#endif
176
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700177extern int prove_locking;
178extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/* The default sysctl tables: */
181
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700182static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 {
184 .ctl_name = CTL_KERN,
185 .procname = "kernel",
186 .mode = 0555,
187 .child = kern_table,
188 },
189 {
190 .ctl_name = CTL_VM,
191 .procname = "vm",
192 .mode = 0555,
193 .child = vm_table,
194 },
195#ifdef CONFIG_NET
196 {
197 .ctl_name = CTL_NET,
198 .procname = "net",
199 .mode = 0555,
200 .child = net_table,
201 },
202#endif
203 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 .ctl_name = CTL_FS,
205 .procname = "fs",
206 .mode = 0555,
207 .child = fs_table,
208 },
209 {
210 .ctl_name = CTL_DEBUG,
211 .procname = "debug",
212 .mode = 0555,
213 .child = debug_table,
214 },
215 {
216 .ctl_name = CTL_DEV,
217 .procname = "dev",
218 .mode = 0555,
219 .child = dev_table,
220 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700221/*
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
224 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 { .ctl_name = 0 }
226};
227
Ingo Molnar77e54a12007-07-09 18:52:00 +0200228#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100229static int min_sched_granularity_ns = 100000; /* 100 usecs */
230static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
231static int min_wakeup_granularity_ns; /* 0 usecs */
232static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200233#endif
234
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700235static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200236#ifdef CONFIG_SCHED_DEBUG
237 {
238 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100239 .procname = "sched_min_granularity_ns",
240 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200241 .maxlen = sizeof(unsigned int),
242 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100243 .proc_handler = &sched_nr_latency_handler,
244 .strategy = &sysctl_intvec,
245 .extra1 = &min_sched_granularity_ns,
246 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200247 },
248 {
249 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200250 .procname = "sched_latency_ns",
251 .data = &sysctl_sched_latency,
252 .maxlen = sizeof(unsigned int),
253 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100254 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200255 .strategy = &sysctl_intvec,
256 .extra1 = &min_sched_granularity_ns,
257 .extra2 = &max_sched_granularity_ns,
258 },
259 {
260 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200261 .procname = "sched_wakeup_granularity_ns",
262 .data = &sysctl_sched_wakeup_granularity,
263 .maxlen = sizeof(unsigned int),
264 .mode = 0644,
265 .proc_handler = &proc_dointvec_minmax,
266 .strategy = &sysctl_intvec,
267 .extra1 = &min_wakeup_granularity_ns,
268 .extra2 = &max_wakeup_granularity_ns,
269 },
270 {
271 .ctl_name = CTL_UNNUMBERED,
272 .procname = "sched_batch_wakeup_granularity_ns",
273 .data = &sysctl_sched_batch_wakeup_granularity,
274 .maxlen = sizeof(unsigned int),
275 .mode = 0644,
276 .proc_handler = &proc_dointvec_minmax,
277 .strategy = &sysctl_intvec,
278 .extra1 = &min_wakeup_granularity_ns,
279 .extra2 = &max_wakeup_granularity_ns,
280 },
281 {
282 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200283 .procname = "sched_child_runs_first",
284 .data = &sysctl_sched_child_runs_first,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = &proc_dointvec,
288 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200289 {
290 .ctl_name = CTL_UNNUMBERED,
291 .procname = "sched_features",
292 .data = &sysctl_sched_features,
293 .maxlen = sizeof(unsigned int),
294 .mode = 0644,
295 .proc_handler = &proc_dointvec,
296 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200297 {
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_migration_cost",
300 .data = &sysctl_sched_migration_cost,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
303 .proc_handler = &proc_dointvec,
304 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100305 {
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_nr_migrate",
308 .data = &sysctl_sched_nr_migrate,
309 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100310 .mode = 0644,
311 .proc_handler = &proc_dointvec,
312 },
313 {
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_rt_period_ms",
316 .data = &sysctl_sched_rt_period,
317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
319 .proc_handler = &proc_dointvec,
320 },
321 {
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_rt_ratio",
324 .data = &sysctl_sched_rt_ratio,
325 .maxlen = sizeof(unsigned int),
326 .mode = 0644,
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100327 .proc_handler = &proc_dointvec,
328 },
Srivatsa Vaddagiri6b2d7702008-01-25 21:08:00 +0100329#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
330 {
331 .ctl_name = CTL_UNNUMBERED,
332 .procname = "sched_min_bal_int_shares",
333 .data = &sysctl_sched_min_bal_int_shares,
334 .maxlen = sizeof(unsigned int),
335 .mode = 0644,
336 .proc_handler = &proc_dointvec,
337 },
338 {
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "sched_max_bal_int_shares",
341 .data = &sysctl_sched_max_bal_int_shares,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = &proc_dointvec,
345 },
346#endif
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200347#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200348 {
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "sched_compat_yield",
351 .data = &sysctl_sched_compat_yield,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
355 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700356#ifdef CONFIG_PROVE_LOCKING
357 {
358 .ctl_name = CTL_UNNUMBERED,
359 .procname = "prove_locking",
360 .data = &prove_locking,
361 .maxlen = sizeof(int),
362 .mode = 0644,
363 .proc_handler = &proc_dointvec,
364 },
365#endif
366#ifdef CONFIG_LOCK_STAT
367 {
368 .ctl_name = CTL_UNNUMBERED,
369 .procname = "lock_stat",
370 .data = &lock_stat,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = &proc_dointvec,
374 },
375#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200376 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 .ctl_name = KERN_PANIC,
378 .procname = "panic",
379 .data = &panic_timeout,
380 .maxlen = sizeof(int),
381 .mode = 0644,
382 .proc_handler = &proc_dointvec,
383 },
384 {
385 .ctl_name = KERN_CORE_USES_PID,
386 .procname = "core_uses_pid",
387 .data = &core_uses_pid,
388 .maxlen = sizeof(int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
391 },
Peter Zijlstrabdf4c482007-07-19 01:48:15 -0700392#ifdef CONFIG_AUDITSYSCALL
393 {
394 .ctl_name = CTL_UNNUMBERED,
395 .procname = "audit_argv_kb",
396 .data = &audit_argv_kb,
397 .maxlen = sizeof(int),
398 .mode = 0644,
399 .proc_handler = &proc_dointvec,
400 },
401#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 {
403 .ctl_name = KERN_CORE_PATTERN,
404 .procname = "core_pattern",
405 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700406 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 .mode = 0644,
408 .proc_handler = &proc_dostring,
409 .strategy = &sysctl_string,
410 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800411#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 .procname = "tainted",
414 .data = &tainted,
415 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800416 .mode = 0644,
417 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800419#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100420#ifdef CONFIG_LATENCYTOP
421 {
422 .procname = "latencytop",
423 .data = &latencytop_enabled,
424 .maxlen = sizeof(int),
425 .mode = 0644,
426 .proc_handler = &proc_dointvec,
427 },
428#endif
Andrew Morgan72c2d582007-10-18 03:05:59 -0700429#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 .procname = "cap-bound",
432 .data = &cap_bset,
433 .maxlen = sizeof(kernel_cap_t),
434 .mode = 0600,
435 .proc_handler = &proc_dointvec_bset,
436 },
Andrew Morgan72c2d582007-10-18 03:05:59 -0700437#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438#ifdef CONFIG_BLK_DEV_INITRD
439 {
440 .ctl_name = KERN_REALROOTDEV,
441 .procname = "real-root-dev",
442 .data = &real_root_dev,
443 .maxlen = sizeof(int),
444 .mode = 0644,
445 .proc_handler = &proc_dointvec,
446 },
447#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700448 {
449 .ctl_name = CTL_UNNUMBERED,
450 .procname = "print-fatal-signals",
451 .data = &print_fatal_signals,
452 .maxlen = sizeof(int),
453 .mode = 0644,
454 .proc_handler = &proc_dointvec,
455 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#ifdef __sparc__
457 {
458 .ctl_name = KERN_SPARC_REBOOT,
459 .procname = "reboot-cmd",
460 .data = reboot_command,
461 .maxlen = 256,
462 .mode = 0644,
463 .proc_handler = &proc_dostring,
464 .strategy = &sysctl_string,
465 },
466 {
467 .ctl_name = KERN_SPARC_STOP_A,
468 .procname = "stop-a",
469 .data = &stop_a_enabled,
470 .maxlen = sizeof (int),
471 .mode = 0644,
472 .proc_handler = &proc_dointvec,
473 },
474 {
475 .ctl_name = KERN_SPARC_SCONS_PWROFF,
476 .procname = "scons-poweroff",
477 .data = &scons_pwroff,
478 .maxlen = sizeof (int),
479 .mode = 0644,
480 .proc_handler = &proc_dointvec,
481 },
482#endif
483#ifdef __hppa__
484 {
485 .ctl_name = KERN_HPPA_PWRSW,
486 .procname = "soft-power",
487 .data = &pwrsw_enabled,
488 .maxlen = sizeof (int),
489 .mode = 0644,
490 .proc_handler = &proc_dointvec,
491 },
492 {
493 .ctl_name = KERN_HPPA_UNALIGNED,
494 .procname = "unaligned-trap",
495 .data = &unaligned_enabled,
496 .maxlen = sizeof (int),
497 .mode = 0644,
498 .proc_handler = &proc_dointvec,
499 },
500#endif
501 {
502 .ctl_name = KERN_CTLALTDEL,
503 .procname = "ctrl-alt-del",
504 .data = &C_A_D,
505 .maxlen = sizeof(int),
506 .mode = 0644,
507 .proc_handler = &proc_dointvec,
508 },
509 {
510 .ctl_name = KERN_PRINTK,
511 .procname = "printk",
512 .data = &console_loglevel,
513 .maxlen = 4*sizeof(int),
514 .mode = 0644,
515 .proc_handler = &proc_dointvec,
516 },
517#ifdef CONFIG_KMOD
518 {
519 .ctl_name = KERN_MODPROBE,
520 .procname = "modprobe",
521 .data = &modprobe_path,
522 .maxlen = KMOD_PATH_LEN,
523 .mode = 0644,
524 .proc_handler = &proc_dostring,
525 .strategy = &sysctl_string,
526 },
527#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700528#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 {
530 .ctl_name = KERN_HOTPLUG,
531 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100532 .data = &uevent_helper,
533 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 .mode = 0644,
535 .proc_handler = &proc_dostring,
536 .strategy = &sysctl_string,
537 },
538#endif
539#ifdef CONFIG_CHR_DEV_SG
540 {
541 .ctl_name = KERN_SG_BIG_BUFF,
542 .procname = "sg-big-buff",
543 .data = &sg_big_buff,
544 .maxlen = sizeof (int),
545 .mode = 0444,
546 .proc_handler = &proc_dointvec,
547 },
548#endif
549#ifdef CONFIG_BSD_PROCESS_ACCT
550 {
551 .ctl_name = KERN_ACCT,
552 .procname = "acct",
553 .data = &acct_parm,
554 .maxlen = 3*sizeof(int),
555 .mode = 0644,
556 .proc_handler = &proc_dointvec,
557 },
558#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#ifdef CONFIG_MAGIC_SYSRQ
560 {
561 .ctl_name = KERN_SYSRQ,
562 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800563 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .maxlen = sizeof (int),
565 .mode = 0644,
566 .proc_handler = &proc_dointvec,
567 },
568#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700569#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700572 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .maxlen = sizeof (int),
574 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700575 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700577#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 {
579 .ctl_name = KERN_MAX_THREADS,
580 .procname = "threads-max",
581 .data = &max_threads,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = &proc_dointvec,
585 },
586 {
587 .ctl_name = KERN_RANDOM,
588 .procname = "random",
589 .mode = 0555,
590 .child = random_table,
591 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 {
593 .ctl_name = KERN_OVERFLOWUID,
594 .procname = "overflowuid",
595 .data = &overflowuid,
596 .maxlen = sizeof(int),
597 .mode = 0644,
598 .proc_handler = &proc_dointvec_minmax,
599 .strategy = &sysctl_intvec,
600 .extra1 = &minolduid,
601 .extra2 = &maxolduid,
602 },
603 {
604 .ctl_name = KERN_OVERFLOWGID,
605 .procname = "overflowgid",
606 .data = &overflowgid,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec_minmax,
610 .strategy = &sysctl_intvec,
611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
613 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800614#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#ifdef CONFIG_MATHEMU
616 {
617 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
618 .procname = "ieee_emulation_warnings",
619 .data = &sysctl_ieee_emulation_warnings,
620 .maxlen = sizeof(int),
621 .mode = 0644,
622 .proc_handler = &proc_dointvec,
623 },
624#endif
625#ifdef CONFIG_NO_IDLE_HZ
626 {
627 .ctl_name = KERN_HZ_TIMER,
628 .procname = "hz_timer",
629 .data = &sysctl_hz_timer,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec,
633 },
634#endif
635 {
636 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
637 .procname = "userprocess_debug",
638 .data = &sysctl_userprocess_debug,
639 .maxlen = sizeof(int),
640 .mode = 0644,
641 .proc_handler = &proc_dointvec,
642 },
643#endif
644 {
645 .ctl_name = KERN_PIDMAX,
646 .procname = "pid_max",
647 .data = &pid_max,
648 .maxlen = sizeof (int),
649 .mode = 0644,
650 .proc_handler = &proc_dointvec_minmax,
651 .strategy = sysctl_intvec,
652 .extra1 = &pid_max_min,
653 .extra2 = &pid_max_max,
654 },
655 {
656 .ctl_name = KERN_PANIC_ON_OOPS,
657 .procname = "panic_on_oops",
658 .data = &panic_on_oops,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = &proc_dointvec,
662 },
663 {
664 .ctl_name = KERN_PRINTK_RATELIMIT,
665 .procname = "printk_ratelimit",
666 .data = &printk_ratelimit_jiffies,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = &proc_dointvec_jiffies,
670 .strategy = &sysctl_jiffies,
671 },
672 {
673 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
674 .procname = "printk_ratelimit_burst",
675 .data = &printk_ratelimit_burst,
676 .maxlen = sizeof(int),
677 .mode = 0644,
678 .proc_handler = &proc_dointvec,
679 },
680 {
681 .ctl_name = KERN_NGROUPS_MAX,
682 .procname = "ngroups_max",
683 .data = &ngroups_max,
684 .maxlen = sizeof (int),
685 .mode = 0444,
686 .proc_handler = &proc_dointvec,
687 },
688#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
689 {
690 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
691 .procname = "unknown_nmi_panic",
692 .data = &unknown_nmi_panic,
693 .maxlen = sizeof (int),
694 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200695 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 },
Don Zickus407984f2006-09-26 10:52:27 +0200697 {
Don Zickus407984f2006-09-26 10:52:27 +0200698 .procname = "nmi_watchdog",
699 .data = &nmi_watchdog_enabled,
700 .maxlen = sizeof (int),
701 .mode = 0644,
702 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 },
704#endif
705#if defined(CONFIG_X86)
706 {
Don Zickus8da5add2006-09-26 10:52:27 +0200707 .ctl_name = KERN_PANIC_ON_NMI,
708 .procname = "panic_on_unrecovered_nmi",
709 .data = &panic_on_unrecovered_nmi,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
714 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 .ctl_name = KERN_BOOTLOADER_TYPE,
716 .procname = "bootloader_type",
717 .data = &bootloader_type,
718 .maxlen = sizeof (int),
719 .mode = 0444,
720 .proc_handler = &proc_dointvec,
721 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100722 {
723 .ctl_name = CTL_UNNUMBERED,
724 .procname = "kstack_depth_to_print",
725 .data = &kstack_depth_to_print,
726 .maxlen = sizeof(int),
727 .mode = 0644,
728 .proc_handler = &proc_dointvec,
729 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800731#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 {
733 .ctl_name = KERN_RANDOMIZE,
734 .procname = "randomize_va_space",
735 .data = &randomize_va_space,
736 .maxlen = sizeof(int),
737 .mode = 0644,
738 .proc_handler = &proc_dointvec,
739 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800740#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800741#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700742 {
743 .ctl_name = KERN_SPIN_RETRY,
744 .procname = "spin_retry",
745 .data = &spin_retry,
746 .maxlen = sizeof (int),
747 .mode = 0644,
748 .proc_handler = &proc_dointvec,
749 },
750#endif
Len Brown673d5b42007-07-28 03:33:16 -0400751#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800752 {
Pavel Machekc255d842006-02-20 18:27:58 -0800753 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700754 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800755 .maxlen = sizeof (unsigned long),
756 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800757 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800758 },
759#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800760#ifdef CONFIG_IA64
761 {
762 .ctl_name = KERN_IA64_UNALIGNED,
763 .procname = "ignore-unaligned-usertrap",
764 .data = &no_unaligned_warning,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
768 },
769#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700770#ifdef CONFIG_DETECT_SOFTLOCKUP
771 {
772 .ctl_name = CTL_UNNUMBERED,
773 .procname = "softlockup_thresh",
774 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100775 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700776 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100777 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700778 .strategy = &sysctl_intvec,
779 .extra1 = &one,
780 .extra2 = &sixty,
781 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100782 {
783 .ctl_name = CTL_UNNUMBERED,
784 .procname = "hung_task_check_count",
785 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100786 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100787 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100788 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100789 .strategy = &sysctl_intvec,
790 },
791 {
792 .ctl_name = CTL_UNNUMBERED,
793 .procname = "hung_task_timeout_secs",
794 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100795 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100796 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100797 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100798 .strategy = &sysctl_intvec,
799 },
800 {
801 .ctl_name = CTL_UNNUMBERED,
802 .procname = "hung_task_warnings",
803 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100804 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100805 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100806 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100807 .strategy = &sysctl_intvec,
808 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700809#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200810#ifdef CONFIG_COMPAT
811 {
812 .ctl_name = KERN_COMPAT_LOG,
813 .procname = "compat-log",
814 .data = &compat_log,
815 .maxlen = sizeof (int),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec,
818 },
819#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700820#ifdef CONFIG_RT_MUTEXES
821 {
822 .ctl_name = KERN_MAX_LOCK_DEPTH,
823 .procname = "max_lock_depth",
824 .data = &max_lock_depth,
825 .maxlen = sizeof(int),
826 .mode = 0644,
827 .proc_handler = &proc_dointvec,
828 },
829#endif
Kees Cook5096add2007-05-08 00:26:04 -0700830#ifdef CONFIG_PROC_FS
831 {
832 .ctl_name = CTL_UNNUMBERED,
833 .procname = "maps_protect",
834 .data = &maps_protect,
835 .maxlen = sizeof(int),
836 .mode = 0644,
837 .proc_handler = &proc_dointvec,
838 },
839#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700840 {
841 .ctl_name = CTL_UNNUMBERED,
842 .procname = "poweroff_cmd",
843 .data = &poweroff_cmd,
844 .maxlen = POWEROFF_CMD_PATH_LEN,
845 .mode = 0644,
846 .proc_handler = &proc_dostring,
847 .strategy = &sysctl_string,
848 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700849/*
850 * NOTE: do not add new entries to this table unless you have read
851 * Documentation/sysctl/ctl_unnumbered.txt
852 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 { .ctl_name = 0 }
854};
855
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700856static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 {
858 .ctl_name = VM_OVERCOMMIT_MEMORY,
859 .procname = "overcommit_memory",
860 .data = &sysctl_overcommit_memory,
861 .maxlen = sizeof(sysctl_overcommit_memory),
862 .mode = 0644,
863 .proc_handler = &proc_dointvec,
864 },
865 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700866 .ctl_name = VM_PANIC_ON_OOM,
867 .procname = "panic_on_oom",
868 .data = &sysctl_panic_on_oom,
869 .maxlen = sizeof(sysctl_panic_on_oom),
870 .mode = 0644,
871 .proc_handler = &proc_dointvec,
872 },
873 {
David Rientjesfe071d72007-10-16 23:25:56 -0700874 .ctl_name = CTL_UNNUMBERED,
875 .procname = "oom_kill_allocating_task",
876 .data = &sysctl_oom_kill_allocating_task,
877 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec,
880 },
881 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 .ctl_name = VM_OVERCOMMIT_RATIO,
883 .procname = "overcommit_ratio",
884 .data = &sysctl_overcommit_ratio,
885 .maxlen = sizeof(sysctl_overcommit_ratio),
886 .mode = 0644,
887 .proc_handler = &proc_dointvec,
888 },
889 {
890 .ctl_name = VM_PAGE_CLUSTER,
891 .procname = "page-cluster",
892 .data = &page_cluster,
893 .maxlen = sizeof(int),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec,
896 },
897 {
898 .ctl_name = VM_DIRTY_BACKGROUND,
899 .procname = "dirty_background_ratio",
900 .data = &dirty_background_ratio,
901 .maxlen = sizeof(dirty_background_ratio),
902 .mode = 0644,
903 .proc_handler = &proc_dointvec_minmax,
904 .strategy = &sysctl_intvec,
905 .extra1 = &zero,
906 .extra2 = &one_hundred,
907 },
908 {
909 .ctl_name = VM_DIRTY_RATIO,
910 .procname = "dirty_ratio",
911 .data = &vm_dirty_ratio,
912 .maxlen = sizeof(vm_dirty_ratio),
913 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700914 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 .strategy = &sysctl_intvec,
916 .extra1 = &zero,
917 .extra2 = &one_hundred,
918 },
919 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800921 .data = &dirty_writeback_interval,
922 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 .mode = 0644,
924 .proc_handler = &dirty_writeback_centisecs_handler,
925 },
926 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800928 .data = &dirty_expire_interval,
929 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800931 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 },
933 {
934 .ctl_name = VM_NR_PDFLUSH_THREADS,
935 .procname = "nr_pdflush_threads",
936 .data = &nr_pdflush_threads,
937 .maxlen = sizeof nr_pdflush_threads,
938 .mode = 0444 /* read-only*/,
939 .proc_handler = &proc_dointvec,
940 },
941 {
942 .ctl_name = VM_SWAPPINESS,
943 .procname = "swappiness",
944 .data = &vm_swappiness,
945 .maxlen = sizeof(vm_swappiness),
946 .mode = 0644,
947 .proc_handler = &proc_dointvec_minmax,
948 .strategy = &sysctl_intvec,
949 .extra1 = &zero,
950 .extra2 = &one_hundred,
951 },
952#ifdef CONFIG_HUGETLB_PAGE
953 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 .procname = "nr_hugepages",
955 .data = &max_huge_pages,
956 .maxlen = sizeof(unsigned long),
957 .mode = 0644,
958 .proc_handler = &hugetlb_sysctl_handler,
959 .extra1 = (void *)&hugetlb_zero,
960 .extra2 = (void *)&hugetlb_infinity,
961 },
962 {
963 .ctl_name = VM_HUGETLB_GROUP,
964 .procname = "hugetlb_shm_group",
965 .data = &sysctl_hugetlb_shm_group,
966 .maxlen = sizeof(gid_t),
967 .mode = 0644,
968 .proc_handler = &proc_dointvec,
969 },
Mel Gorman396faf02007-07-17 04:03:13 -0700970 {
971 .ctl_name = CTL_UNNUMBERED,
972 .procname = "hugepages_treat_as_movable",
973 .data = &hugepages_treat_as_movable,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = &hugetlb_treat_movable_handler,
977 },
Adam Litke54f9f802007-10-16 01:26:20 -0700978 {
979 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800980 .procname = "nr_overcommit_hugepages",
981 .data = &nr_overcommit_huge_pages,
982 .maxlen = sizeof(nr_overcommit_huge_pages),
983 .mode = 0644,
984 .proc_handler = &proc_doulongvec_minmax,
985 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986#endif
987 {
988 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
989 .procname = "lowmem_reserve_ratio",
990 .data = &sysctl_lowmem_reserve_ratio,
991 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
992 .mode = 0644,
993 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
994 .strategy = &sysctl_intvec,
995 },
996 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800997 .ctl_name = VM_DROP_PAGECACHE,
998 .procname = "drop_caches",
999 .data = &sysctl_drop_caches,
1000 .maxlen = sizeof(int),
1001 .mode = 0644,
1002 .proc_handler = drop_caches_sysctl_handler,
1003 .strategy = &sysctl_intvec,
1004 },
1005 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 .ctl_name = VM_MIN_FREE_KBYTES,
1007 .procname = "min_free_kbytes",
1008 .data = &min_free_kbytes,
1009 .maxlen = sizeof(min_free_kbytes),
1010 .mode = 0644,
1011 .proc_handler = &min_free_kbytes_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1013 .extra1 = &zero,
1014 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001015 {
1016 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1017 .procname = "percpu_pagelist_fraction",
1018 .data = &percpu_pagelist_fraction,
1019 .maxlen = sizeof(percpu_pagelist_fraction),
1020 .mode = 0644,
1021 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &min_percpu_pagelist_fract,
1024 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025#ifdef CONFIG_MMU
1026 {
1027 .ctl_name = VM_MAX_MAP_COUNT,
1028 .procname = "max_map_count",
1029 .data = &sysctl_max_map_count,
1030 .maxlen = sizeof(sysctl_max_map_count),
1031 .mode = 0644,
1032 .proc_handler = &proc_dointvec
1033 },
1034#endif
1035 {
1036 .ctl_name = VM_LAPTOP_MODE,
1037 .procname = "laptop_mode",
1038 .data = &laptop_mode,
1039 .maxlen = sizeof(laptop_mode),
1040 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001041 .proc_handler = &proc_dointvec_jiffies,
1042 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 },
1044 {
1045 .ctl_name = VM_BLOCK_DUMP,
1046 .procname = "block_dump",
1047 .data = &block_dump,
1048 .maxlen = sizeof(block_dump),
1049 .mode = 0644,
1050 .proc_handler = &proc_dointvec,
1051 .strategy = &sysctl_intvec,
1052 .extra1 = &zero,
1053 },
1054 {
1055 .ctl_name = VM_VFS_CACHE_PRESSURE,
1056 .procname = "vfs_cache_pressure",
1057 .data = &sysctl_vfs_cache_pressure,
1058 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1059 .mode = 0644,
1060 .proc_handler = &proc_dointvec,
1061 .strategy = &sysctl_intvec,
1062 .extra1 = &zero,
1063 },
1064#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1065 {
1066 .ctl_name = VM_LEGACY_VA_LAYOUT,
1067 .procname = "legacy_va_layout",
1068 .data = &sysctl_legacy_va_layout,
1069 .maxlen = sizeof(sysctl_legacy_va_layout),
1070 .mode = 0644,
1071 .proc_handler = &proc_dointvec,
1072 .strategy = &sysctl_intvec,
1073 .extra1 = &zero,
1074 },
1075#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001076#ifdef CONFIG_NUMA
1077 {
1078 .ctl_name = VM_ZONE_RECLAIM_MODE,
1079 .procname = "zone_reclaim_mode",
1080 .data = &zone_reclaim_mode,
1081 .maxlen = sizeof(zone_reclaim_mode),
1082 .mode = 0644,
1083 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001084 .strategy = &sysctl_intvec,
1085 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001086 },
Christoph Lameter96146342006-07-03 00:24:13 -07001087 {
1088 .ctl_name = VM_MIN_UNMAPPED,
1089 .procname = "min_unmapped_ratio",
1090 .data = &sysctl_min_unmapped_ratio,
1091 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1092 .mode = 0644,
1093 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1094 .strategy = &sysctl_intvec,
1095 .extra1 = &zero,
1096 .extra2 = &one_hundred,
1097 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001098 {
1099 .ctl_name = VM_MIN_SLAB,
1100 .procname = "min_slab_ratio",
1101 .data = &sysctl_min_slab_ratio,
1102 .maxlen = sizeof(sysctl_min_slab_ratio),
1103 .mode = 0644,
1104 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1105 .strategy = &sysctl_intvec,
1106 .extra1 = &zero,
1107 .extra2 = &one_hundred,
1108 },
Christoph Lameter17436602006-01-18 17:42:32 -08001109#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001110#ifdef CONFIG_SMP
1111 {
1112 .ctl_name = CTL_UNNUMBERED,
1113 .procname = "stat_interval",
1114 .data = &sysctl_stat_interval,
1115 .maxlen = sizeof(sysctl_stat_interval),
1116 .mode = 0644,
1117 .proc_handler = &proc_dointvec_jiffies,
1118 .strategy = &sysctl_jiffies,
1119 },
1120#endif
Eric Parised032182007-06-28 15:55:21 -04001121#ifdef CONFIG_SECURITY
1122 {
1123 .ctl_name = CTL_UNNUMBERED,
1124 .procname = "mmap_min_addr",
1125 .data = &mmap_min_addr,
1126 .maxlen = sizeof(unsigned long),
1127 .mode = 0644,
1128 .proc_handler = &proc_doulongvec_minmax,
1129 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001130#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001131#ifdef CONFIG_NUMA
1132 {
1133 .ctl_name = CTL_UNNUMBERED,
1134 .procname = "numa_zonelist_order",
1135 .data = &numa_zonelist_order,
1136 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1137 .mode = 0644,
1138 .proc_handler = &numa_zonelist_order_handler,
1139 .strategy = &sysctl_string,
1140 },
1141#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001142#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001143 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001144 {
1145 .ctl_name = VM_VDSO_ENABLED,
1146 .procname = "vdso_enabled",
1147 .data = &vdso_enabled,
1148 .maxlen = sizeof(vdso_enabled),
1149 .mode = 0644,
1150 .proc_handler = &proc_dointvec,
1151 .strategy = &sysctl_intvec,
1152 .extra1 = &zero,
1153 },
1154#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001155/*
1156 * NOTE: do not add new entries to this table unless you have read
1157 * Documentation/sysctl/ctl_unnumbered.txt
1158 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 { .ctl_name = 0 }
1160};
1161
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001162#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001163static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001164 { .ctl_name = 0 }
1165};
1166#endif
1167
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001168static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 {
1170 .ctl_name = FS_NRINODE,
1171 .procname = "inode-nr",
1172 .data = &inodes_stat,
1173 .maxlen = 2*sizeof(int),
1174 .mode = 0444,
1175 .proc_handler = &proc_dointvec,
1176 },
1177 {
1178 .ctl_name = FS_STATINODE,
1179 .procname = "inode-state",
1180 .data = &inodes_stat,
1181 .maxlen = 7*sizeof(int),
1182 .mode = 0444,
1183 .proc_handler = &proc_dointvec,
1184 },
1185 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 .procname = "file-nr",
1187 .data = &files_stat,
1188 .maxlen = 3*sizeof(int),
1189 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001190 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 },
1192 {
1193 .ctl_name = FS_MAXFILE,
1194 .procname = "file-max",
1195 .data = &files_stat.max_files,
1196 .maxlen = sizeof(int),
1197 .mode = 0644,
1198 .proc_handler = &proc_dointvec,
1199 },
1200 {
1201 .ctl_name = FS_DENTRY,
1202 .procname = "dentry-state",
1203 .data = &dentry_stat,
1204 .maxlen = 6*sizeof(int),
1205 .mode = 0444,
1206 .proc_handler = &proc_dointvec,
1207 },
1208 {
1209 .ctl_name = FS_OVERFLOWUID,
1210 .procname = "overflowuid",
1211 .data = &fs_overflowuid,
1212 .maxlen = sizeof(int),
1213 .mode = 0644,
1214 .proc_handler = &proc_dointvec_minmax,
1215 .strategy = &sysctl_intvec,
1216 .extra1 = &minolduid,
1217 .extra2 = &maxolduid,
1218 },
1219 {
1220 .ctl_name = FS_OVERFLOWGID,
1221 .procname = "overflowgid",
1222 .data = &fs_overflowgid,
1223 .maxlen = sizeof(int),
1224 .mode = 0644,
1225 .proc_handler = &proc_dointvec_minmax,
1226 .strategy = &sysctl_intvec,
1227 .extra1 = &minolduid,
1228 .extra2 = &maxolduid,
1229 },
1230 {
1231 .ctl_name = FS_LEASES,
1232 .procname = "leases-enable",
1233 .data = &leases_enable,
1234 .maxlen = sizeof(int),
1235 .mode = 0644,
1236 .proc_handler = &proc_dointvec,
1237 },
1238#ifdef CONFIG_DNOTIFY
1239 {
1240 .ctl_name = FS_DIR_NOTIFY,
1241 .procname = "dir-notify-enable",
1242 .data = &dir_notify_enable,
1243 .maxlen = sizeof(int),
1244 .mode = 0644,
1245 .proc_handler = &proc_dointvec,
1246 },
1247#endif
1248#ifdef CONFIG_MMU
1249 {
1250 .ctl_name = FS_LEASE_TIME,
1251 .procname = "lease-break-time",
1252 .data = &lease_break_time,
1253 .maxlen = sizeof(int),
1254 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001255 .proc_handler = &proc_dointvec_minmax,
1256 .strategy = &sysctl_intvec,
1257 .extra1 = &zero,
1258 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 },
1260 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 .procname = "aio-nr",
1262 .data = &aio_nr,
1263 .maxlen = sizeof(aio_nr),
1264 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001265 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 },
1267 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 .procname = "aio-max-nr",
1269 .data = &aio_max_nr,
1270 .maxlen = sizeof(aio_max_nr),
1271 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001272 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001274#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001275 {
1276 .ctl_name = FS_INOTIFY,
1277 .procname = "inotify",
1278 .mode = 0555,
1279 .child = inotify_table,
1280 },
1281#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001283 {
1284 .ctl_name = KERN_SETUID_DUMPABLE,
1285 .procname = "suid_dumpable",
1286 .data = &suid_dumpable,
1287 .maxlen = sizeof(int),
1288 .mode = 0644,
1289 .proc_handler = &proc_dointvec,
1290 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001291#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1292 {
1293 .ctl_name = CTL_UNNUMBERED,
1294 .procname = "binfmt_misc",
1295 .mode = 0555,
1296 .child = binfmt_misc_table,
1297 },
1298#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001299/*
1300 * NOTE: do not add new entries to this table unless you have read
1301 * Documentation/sysctl/ctl_unnumbered.txt
1302 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 { .ctl_name = 0 }
1304};
1305
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001306static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001307#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001308 {
1309 .ctl_name = CTL_UNNUMBERED,
1310 .procname = "exception-trace",
1311 .data = &show_unhandled_signals,
1312 .maxlen = sizeof(int),
1313 .mode = 0644,
1314 .proc_handler = proc_dointvec
1315 },
1316#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 { .ctl_name = 0 }
1318};
1319
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001320static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001322};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323
Al Viro330d57f2005-11-04 10:18:40 +00001324static DEFINE_SPINLOCK(sysctl_lock);
1325
1326/* called under sysctl_lock */
1327static int use_table(struct ctl_table_header *p)
1328{
1329 if (unlikely(p->unregistering))
1330 return 0;
1331 p->used++;
1332 return 1;
1333}
1334
1335/* called under sysctl_lock */
1336static void unuse_table(struct ctl_table_header *p)
1337{
1338 if (!--p->used)
1339 if (unlikely(p->unregistering))
1340 complete(p->unregistering);
1341}
1342
1343/* called under sysctl_lock, will reacquire if has to wait */
1344static void start_unregistering(struct ctl_table_header *p)
1345{
1346 /*
1347 * if p->used is 0, nobody will ever touch that entry again;
1348 * we'll eliminate all paths to it before dropping sysctl_lock
1349 */
1350 if (unlikely(p->used)) {
1351 struct completion wait;
1352 init_completion(&wait);
1353 p->unregistering = &wait;
1354 spin_unlock(&sysctl_lock);
1355 wait_for_completion(&wait);
1356 spin_lock(&sysctl_lock);
1357 }
1358 /*
1359 * do not remove from the list until nobody holds it; walking the
1360 * list in do_sysctl() relies on that.
1361 */
1362 list_del_init(&p->ctl_entry);
1363}
1364
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001365void sysctl_head_finish(struct ctl_table_header *head)
1366{
1367 if (!head)
1368 return;
1369 spin_lock(&sysctl_lock);
1370 unuse_table(head);
1371 spin_unlock(&sysctl_lock);
1372}
1373
1374struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1375{
1376 struct ctl_table_header *head;
1377 struct list_head *tmp;
1378 spin_lock(&sysctl_lock);
1379 if (prev) {
1380 tmp = &prev->ctl_entry;
1381 unuse_table(prev);
1382 goto next;
1383 }
1384 tmp = &root_table_header.ctl_entry;
1385 for (;;) {
1386 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1387
1388 if (!use_table(head))
1389 goto next;
1390 spin_unlock(&sysctl_lock);
1391 return head;
1392 next:
1393 tmp = tmp->next;
1394 if (tmp == &root_table_header.ctl_entry)
1395 break;
1396 }
1397 spin_unlock(&sysctl_lock);
1398 return NULL;
1399}
1400
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001401#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1403 void __user *newval, size_t newlen)
1404{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001405 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001406 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
1408 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1409 return -ENOTDIR;
1410 if (oldval) {
1411 int old_len;
1412 if (!oldlenp || get_user(old_len, oldlenp))
1413 return -EFAULT;
1414 }
Al Viro330d57f2005-11-04 10:18:40 +00001415
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001416 for (head = sysctl_head_next(NULL); head;
1417 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001418 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001419 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001420 if (error != -ENOTDIR) {
1421 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001422 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001423 }
1424 }
Al Viro330d57f2005-11-04 10:18:40 +00001425 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426}
1427
1428asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1429{
1430 struct __sysctl_args tmp;
1431 int error;
1432
1433 if (copy_from_user(&tmp, args, sizeof(tmp)))
1434 return -EFAULT;
1435
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001436 error = deprecated_sysctl_warning(&tmp);
1437 if (error)
1438 goto out;
1439
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 lock_kernel();
1441 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1442 tmp.newval, tmp.newlen);
1443 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001444out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 return error;
1446}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001447#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
1449/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001450 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 * some sysctl variables are readonly even to root.
1452 */
1453
1454static int test_perm(int mode, int op)
1455{
1456 if (!current->euid)
1457 mode >>= 6;
1458 else if (in_egroup_p(0))
1459 mode >>= 3;
1460 if ((mode & op & 0007) == op)
1461 return 0;
1462 return -EACCES;
1463}
1464
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001465int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466{
1467 int error;
1468 error = security_sysctl(table, op);
1469 if (error)
1470 return error;
1471 return test_perm(table->mode, op);
1472}
1473
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001474#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475static int parse_table(int __user *name, int nlen,
1476 void __user *oldval, size_t __user *oldlenp,
1477 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001478 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
1480 int n;
1481repeat:
1482 if (!nlen)
1483 return -ENOTDIR;
1484 if (get_user(n, name))
1485 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001486 for ( ; table->ctl_name || table->procname; table++) {
1487 if (!table->ctl_name)
1488 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001489 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 int error;
1491 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001492 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 name++;
1495 nlen--;
1496 table = table->child;
1497 goto repeat;
1498 }
1499 error = do_sysctl_strategy(table, name, nlen,
1500 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001501 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 return error;
1503 }
1504 }
1505 return -ENOTDIR;
1506}
1507
1508/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001509int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 int __user *name, int nlen,
1511 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001512 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
1514 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
1516 if (oldval)
1517 op |= 004;
1518 if (newval)
1519 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001520 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 return -EPERM;
1522
1523 if (table->strategy) {
1524 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001525 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 if (rc < 0)
1527 return rc;
1528 if (rc > 0)
1529 return 0;
1530 }
1531
1532 /* If there is no strategy routine, or if the strategy returns
1533 * zero, proceed with automatic r/w */
1534 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001535 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1536 newval, newlen);
1537 if (rc < 0)
1538 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 }
1540 return 0;
1541}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001542#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001544static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1545{
1546 for (; table->ctl_name || table->procname; table++) {
1547 table->parent = parent;
1548 if (table->child)
1549 sysctl_set_parent(table, table->child);
1550 }
1551}
1552
1553static __init int sysctl_init(void)
1554{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001555 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001556 sysctl_set_parent(NULL, root_table);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001557 err = sysctl_check_table(root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001558 return 0;
1559}
1560
1561core_initcall(sysctl_init);
1562
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001564 * register_sysctl_paths - register a sysctl hierarchy
1565 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 *
1568 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001569 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001571 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 *
1573 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1574 * must be unique within that level of sysctl
1575 *
1576 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1577 * enter a sysctl file
1578 *
1579 * data - a pointer to data for use by proc_handler
1580 *
1581 * maxlen - the maximum size in bytes of the data
1582 *
1583 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1584 *
1585 * child - a pointer to the child sysctl table if this entry is a directory, or
1586 * %NULL.
1587 *
1588 * proc_handler - the text handler routine (described below)
1589 *
1590 * strategy - the strategy routine (described below)
1591 *
1592 * de - for internal use by the sysctl routines
1593 *
1594 * extra1, extra2 - extra pointers usable by the proc handler routines
1595 *
1596 * Leaf nodes in the sysctl tree will be represented by a single file
1597 * under /proc; non-leaf nodes will be represented by directories.
1598 *
1599 * sysctl(2) can automatically manage read and write requests through
1600 * the sysctl table. The data and maxlen fields of the ctl_table
1601 * struct enable minimal validation of the values being written to be
1602 * performed, and the mode field allows minimal authentication.
1603 *
1604 * More sophisticated management can be enabled by the provision of a
1605 * strategy routine with the table entry. This will be called before
1606 * any automatic read or write of the data is performed.
1607 *
1608 * The strategy routine may return
1609 *
1610 * < 0 - Error occurred (error is passed to user process)
1611 *
1612 * 0 - OK - proceed with automatic read or write.
1613 *
1614 * > 0 - OK - read or write has been done by the strategy routine, so
1615 * return immediately.
1616 *
1617 * There must be a proc_handler routine for any terminal nodes
1618 * mirrored under /proc/sys (non-terminals are handled by a built-in
1619 * directory handler). Several default handlers are available to
1620 * cover common cases -
1621 *
1622 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1623 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1624 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1625 *
1626 * It is the handler's job to read the input buffer from user memory
1627 * and process it. The handler should return 0 on success.
1628 *
1629 * This routine returns %NULL on a failure to register, and a pointer
1630 * to the table header on success.
1631 */
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001632struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1633 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001635 struct ctl_table_header *header;
1636 struct ctl_table *new, **prevp;
1637 unsigned int n, npath;
1638
1639 /* Count the path components */
1640 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1641 ;
1642
1643 /*
1644 * For each path component, allocate a 2-element ctl_table array.
1645 * The first array element will be filled with the sysctl entry
1646 * for this, the second will be the sentinel (ctl_name == 0).
1647 *
1648 * We allocate everything in one go so that we don't have to
1649 * worry about freeing additional memory in unregister_sysctl_table.
1650 */
1651 header = kzalloc(sizeof(struct ctl_table_header) +
1652 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1653 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001655
1656 new = (struct ctl_table *) (header + 1);
1657
1658 /* Now connect the dots */
1659 prevp = &header->ctl_table;
1660 for (n = 0; n < npath; ++n, ++path) {
1661 /* Copy the procname */
1662 new->procname = path->procname;
1663 new->ctl_name = path->ctl_name;
1664 new->mode = 0555;
1665
1666 *prevp = new;
1667 prevp = &new->child;
1668
1669 new += 2;
1670 }
1671 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001672 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001673
1674 INIT_LIST_HEAD(&header->ctl_entry);
1675 header->used = 0;
1676 header->unregistering = NULL;
1677 sysctl_set_parent(NULL, header->ctl_table);
1678 if (sysctl_check_table(header->ctl_table)) {
1679 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001680 return NULL;
1681 }
Al Viro330d57f2005-11-04 10:18:40 +00001682 spin_lock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001683 list_add_tail(&header->ctl_entry, &root_table_header.ctl_entry);
Al Viro330d57f2005-11-04 10:18:40 +00001684 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001685
1686 return header;
1687}
1688
1689/**
1690 * register_sysctl_table - register a sysctl table hierarchy
1691 * @table: the top-level table structure
1692 *
1693 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1694 * array. A completely 0 filled entry terminates the table.
1695 *
1696 * See register_sysctl_paths for more details.
1697 */
1698struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1699{
1700 static const struct ctl_path null_path[] = { {} };
1701
1702 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703}
1704
1705/**
1706 * unregister_sysctl_table - unregister a sysctl table hierarchy
1707 * @header: the header returned from register_sysctl_table
1708 *
1709 * Unregisters the sysctl table and all children. proc entries may not
1710 * actually be removed until they are no longer used by anyone.
1711 */
1712void unregister_sysctl_table(struct ctl_table_header * header)
1713{
Al Viro330d57f2005-11-04 10:18:40 +00001714 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001715
1716 if (header == NULL)
1717 return;
1718
Al Viro330d57f2005-11-04 10:18:40 +00001719 spin_lock(&sysctl_lock);
1720 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001721 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 kfree(header);
1723}
1724
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001725#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001726struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001727{
1728 return NULL;
1729}
1730
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001731struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1732 struct ctl_table *table)
1733{
1734 return NULL;
1735}
1736
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001737void unregister_sysctl_table(struct ctl_table_header * table)
1738{
1739}
1740
1741#endif /* CONFIG_SYSCTL */
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743/*
1744 * /proc/sys support
1745 */
1746
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001747#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001749static int _proc_do_string(void* data, int maxlen, int write,
1750 struct file *filp, void __user *buffer,
1751 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001752{
1753 size_t len;
1754 char __user *p;
1755 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001756
1757 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001758 *lenp = 0;
1759 return 0;
1760 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001761
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001762 if (write) {
1763 len = 0;
1764 p = buffer;
1765 while (len < *lenp) {
1766 if (get_user(c, p++))
1767 return -EFAULT;
1768 if (c == 0 || c == '\n')
1769 break;
1770 len++;
1771 }
1772 if (len >= maxlen)
1773 len = maxlen-1;
1774 if(copy_from_user(data, buffer, len))
1775 return -EFAULT;
1776 ((char *) data)[len] = 0;
1777 *ppos += *lenp;
1778 } else {
1779 len = strlen(data);
1780 if (len > maxlen)
1781 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001782
1783 if (*ppos > len) {
1784 *lenp = 0;
1785 return 0;
1786 }
1787
1788 data += *ppos;
1789 len -= *ppos;
1790
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001791 if (len > *lenp)
1792 len = *lenp;
1793 if (len)
1794 if(copy_to_user(buffer, data, len))
1795 return -EFAULT;
1796 if (len < *lenp) {
1797 if(put_user('\n', ((char __user *) buffer) + len))
1798 return -EFAULT;
1799 len++;
1800 }
1801 *lenp = len;
1802 *ppos += len;
1803 }
1804 return 0;
1805}
1806
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807/**
1808 * proc_dostring - read a string sysctl
1809 * @table: the sysctl table
1810 * @write: %TRUE if this is a write to the sysctl file
1811 * @filp: the file structure
1812 * @buffer: the user buffer
1813 * @lenp: the size of the user buffer
1814 * @ppos: file position
1815 *
1816 * Reads/writes a string from/to the user buffer. If the kernel
1817 * buffer provided is not large enough to hold the string, the
1818 * string is truncated. The copied string is %NULL-terminated.
1819 * If the string is being read by the user process, it is copied
1820 * and a newline '\n' is added. It is truncated if the buffer is
1821 * not large enough.
1822 *
1823 * Returns 0 on success.
1824 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001825int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 void __user *buffer, size_t *lenp, loff_t *ppos)
1827{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001828 return _proc_do_string(table->data, table->maxlen, write, filp,
1829 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830}
1831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
1833static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1834 int *valp,
1835 int write, void *data)
1836{
1837 if (write) {
1838 *valp = *negp ? -*lvalp : *lvalp;
1839 } else {
1840 int val = *valp;
1841 if (val < 0) {
1842 *negp = -1;
1843 *lvalp = (unsigned long)-val;
1844 } else {
1845 *negp = 0;
1846 *lvalp = (unsigned long)val;
1847 }
1848 }
1849 return 0;
1850}
1851
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001852static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001853 int write, struct file *filp, void __user *buffer,
1854 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1856 int write, void *data),
1857 void *data)
1858{
1859#define TMPBUFLEN 21
1860 int *i, vleft, first=1, neg, val;
1861 unsigned long lval;
1862 size_t left, len;
1863
1864 char buf[TMPBUFLEN], *p;
1865 char __user *s = buffer;
1866
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001867 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 (*ppos && !write)) {
1869 *lenp = 0;
1870 return 0;
1871 }
1872
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001873 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 vleft = table->maxlen / sizeof(*i);
1875 left = *lenp;
1876
1877 if (!conv)
1878 conv = do_proc_dointvec_conv;
1879
1880 for (; left && vleft--; i++, first=0) {
1881 if (write) {
1882 while (left) {
1883 char c;
1884 if (get_user(c, s))
1885 return -EFAULT;
1886 if (!isspace(c))
1887 break;
1888 left--;
1889 s++;
1890 }
1891 if (!left)
1892 break;
1893 neg = 0;
1894 len = left;
1895 if (len > sizeof(buf) - 1)
1896 len = sizeof(buf) - 1;
1897 if (copy_from_user(buf, s, len))
1898 return -EFAULT;
1899 buf[len] = 0;
1900 p = buf;
1901 if (*p == '-' && left > 1) {
1902 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001903 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 }
1905 if (*p < '0' || *p > '9')
1906 break;
1907
1908 lval = simple_strtoul(p, &p, 0);
1909
1910 len = p-buf;
1911 if ((len < left) && *p && !isspace(*p))
1912 break;
1913 if (neg)
1914 val = -val;
1915 s += len;
1916 left -= len;
1917
1918 if (conv(&neg, &lval, i, 1, data))
1919 break;
1920 } else {
1921 p = buf;
1922 if (!first)
1923 *p++ = '\t';
1924
1925 if (conv(&neg, &lval, i, 0, data))
1926 break;
1927
1928 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1929 len = strlen(buf);
1930 if (len > left)
1931 len = left;
1932 if(copy_to_user(s, buf, len))
1933 return -EFAULT;
1934 left -= len;
1935 s += len;
1936 }
1937 }
1938
1939 if (!write && !first && left) {
1940 if(put_user('\n', s))
1941 return -EFAULT;
1942 left--, s++;
1943 }
1944 if (write) {
1945 while (left) {
1946 char c;
1947 if (get_user(c, s++))
1948 return -EFAULT;
1949 if (!isspace(c))
1950 break;
1951 left--;
1952 }
1953 }
1954 if (write && first)
1955 return -EINVAL;
1956 *lenp -= left;
1957 *ppos += *lenp;
1958 return 0;
1959#undef TMPBUFLEN
1960}
1961
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001962static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001963 void __user *buffer, size_t *lenp, loff_t *ppos,
1964 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1965 int write, void *data),
1966 void *data)
1967{
1968 return __do_proc_dointvec(table->data, table, write, filp,
1969 buffer, lenp, ppos, conv, data);
1970}
1971
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972/**
1973 * proc_dointvec - read a vector of integers
1974 * @table: the sysctl table
1975 * @write: %TRUE if this is a write to the sysctl file
1976 * @filp: the file structure
1977 * @buffer: the user buffer
1978 * @lenp: the size of the user buffer
1979 * @ppos: file position
1980 *
1981 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1982 * values from/to the user buffer, treated as an ASCII string.
1983 *
1984 * Returns 0 on success.
1985 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001986int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 void __user *buffer, size_t *lenp, loff_t *ppos)
1988{
1989 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1990 NULL,NULL);
1991}
1992
1993#define OP_SET 0
1994#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08001995#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
1997static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1998 int *valp,
1999 int write, void *data)
2000{
2001 int op = *(int *)data;
2002 if (write) {
2003 int val = *negp ? -*lvalp : *lvalp;
2004 switch(op) {
2005 case OP_SET: *valp = val; break;
2006 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002007 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 }
2009 } else {
2010 int val = *valp;
2011 if (val < 0) {
2012 *negp = -1;
2013 *lvalp = (unsigned long)-val;
2014 } else {
2015 *negp = 0;
2016 *lvalp = (unsigned long)val;
2017 }
2018 }
2019 return 0;
2020}
2021
Andrew Morgan72c2d582007-10-18 03:05:59 -07002022#ifdef CONFIG_SECURITY_CAPABILITIES
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023/*
2024 * init may raise the set.
2025 */
Andrew Morgan72c2d582007-10-18 03:05:59 -07002026
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002027int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 void __user *buffer, size_t *lenp, loff_t *ppos)
2029{
2030 int op;
2031
Eric Paris6ff1b442007-02-10 01:43:19 -08002032 if (write && !capable(CAP_SYS_MODULE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 return -EPERM;
2034 }
2035
Serge E. Hallynb460cbc2007-10-18 23:39:52 -07002036 op = is_global_init(current) ? OP_SET : OP_AND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2038 do_proc_dointvec_bset_conv,&op);
2039}
Andrew Morgan72c2d582007-10-18 03:05:59 -07002040#endif /* def CONFIG_SECURITY_CAPABILITIES */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002042/*
2043 * Taint values can only be increased
2044 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002045static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002046 void __user *buffer, size_t *lenp, loff_t *ppos)
2047{
2048 int op;
2049
Bastian Blank91fcd412007-04-23 14:41:14 -07002050 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002051 return -EPERM;
2052
2053 op = OP_OR;
2054 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2055 do_proc_dointvec_bset_conv,&op);
2056}
2057
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058struct do_proc_dointvec_minmax_conv_param {
2059 int *min;
2060 int *max;
2061};
2062
2063static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2064 int *valp,
2065 int write, void *data)
2066{
2067 struct do_proc_dointvec_minmax_conv_param *param = data;
2068 if (write) {
2069 int val = *negp ? -*lvalp : *lvalp;
2070 if ((param->min && *param->min > val) ||
2071 (param->max && *param->max < val))
2072 return -EINVAL;
2073 *valp = val;
2074 } else {
2075 int val = *valp;
2076 if (val < 0) {
2077 *negp = -1;
2078 *lvalp = (unsigned long)-val;
2079 } else {
2080 *negp = 0;
2081 *lvalp = (unsigned long)val;
2082 }
2083 }
2084 return 0;
2085}
2086
2087/**
2088 * proc_dointvec_minmax - read a vector of integers with min/max values
2089 * @table: the sysctl table
2090 * @write: %TRUE if this is a write to the sysctl file
2091 * @filp: the file structure
2092 * @buffer: the user buffer
2093 * @lenp: the size of the user buffer
2094 * @ppos: file position
2095 *
2096 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2097 * values from/to the user buffer, treated as an ASCII string.
2098 *
2099 * This routine will ensure the values are within the range specified by
2100 * table->extra1 (min) and table->extra2 (max).
2101 *
2102 * Returns 0 on success.
2103 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002104int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 void __user *buffer, size_t *lenp, loff_t *ppos)
2106{
2107 struct do_proc_dointvec_minmax_conv_param param = {
2108 .min = (int *) table->extra1,
2109 .max = (int *) table->extra2,
2110 };
2111 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2112 do_proc_dointvec_minmax_conv, &param);
2113}
2114
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002115static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 struct file *filp,
2117 void __user *buffer,
2118 size_t *lenp, loff_t *ppos,
2119 unsigned long convmul,
2120 unsigned long convdiv)
2121{
2122#define TMPBUFLEN 21
2123 unsigned long *i, *min, *max, val;
2124 int vleft, first=1, neg;
2125 size_t len, left;
2126 char buf[TMPBUFLEN], *p;
2127 char __user *s = buffer;
2128
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002129 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 (*ppos && !write)) {
2131 *lenp = 0;
2132 return 0;
2133 }
2134
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002135 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 min = (unsigned long *) table->extra1;
2137 max = (unsigned long *) table->extra2;
2138 vleft = table->maxlen / sizeof(unsigned long);
2139 left = *lenp;
2140
2141 for (; left && vleft--; i++, min++, max++, first=0) {
2142 if (write) {
2143 while (left) {
2144 char c;
2145 if (get_user(c, s))
2146 return -EFAULT;
2147 if (!isspace(c))
2148 break;
2149 left--;
2150 s++;
2151 }
2152 if (!left)
2153 break;
2154 neg = 0;
2155 len = left;
2156 if (len > TMPBUFLEN-1)
2157 len = TMPBUFLEN-1;
2158 if (copy_from_user(buf, s, len))
2159 return -EFAULT;
2160 buf[len] = 0;
2161 p = buf;
2162 if (*p == '-' && left > 1) {
2163 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002164 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 }
2166 if (*p < '0' || *p > '9')
2167 break;
2168 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2169 len = p-buf;
2170 if ((len < left) && *p && !isspace(*p))
2171 break;
2172 if (neg)
2173 val = -val;
2174 s += len;
2175 left -= len;
2176
2177 if(neg)
2178 continue;
2179 if ((min && val < *min) || (max && val > *max))
2180 continue;
2181 *i = val;
2182 } else {
2183 p = buf;
2184 if (!first)
2185 *p++ = '\t';
2186 sprintf(p, "%lu", convdiv * (*i) / convmul);
2187 len = strlen(buf);
2188 if (len > left)
2189 len = left;
2190 if(copy_to_user(s, buf, len))
2191 return -EFAULT;
2192 left -= len;
2193 s += len;
2194 }
2195 }
2196
2197 if (!write && !first && left) {
2198 if(put_user('\n', s))
2199 return -EFAULT;
2200 left--, s++;
2201 }
2202 if (write) {
2203 while (left) {
2204 char c;
2205 if (get_user(c, s++))
2206 return -EFAULT;
2207 if (!isspace(c))
2208 break;
2209 left--;
2210 }
2211 }
2212 if (write && first)
2213 return -EINVAL;
2214 *lenp -= left;
2215 *ppos += *lenp;
2216 return 0;
2217#undef TMPBUFLEN
2218}
2219
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002220static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002221 struct file *filp,
2222 void __user *buffer,
2223 size_t *lenp, loff_t *ppos,
2224 unsigned long convmul,
2225 unsigned long convdiv)
2226{
2227 return __do_proc_doulongvec_minmax(table->data, table, write,
2228 filp, buffer, lenp, ppos, convmul, convdiv);
2229}
2230
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231/**
2232 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2233 * @table: the sysctl table
2234 * @write: %TRUE if this is a write to the sysctl file
2235 * @filp: the file structure
2236 * @buffer: the user buffer
2237 * @lenp: the size of the user buffer
2238 * @ppos: file position
2239 *
2240 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2241 * values from/to the user buffer, treated as an ASCII string.
2242 *
2243 * This routine will ensure the values are within the range specified by
2244 * table->extra1 (min) and table->extra2 (max).
2245 *
2246 * Returns 0 on success.
2247 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002248int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 void __user *buffer, size_t *lenp, loff_t *ppos)
2250{
2251 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2252}
2253
2254/**
2255 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2256 * @table: the sysctl table
2257 * @write: %TRUE if this is a write to the sysctl file
2258 * @filp: the file structure
2259 * @buffer: the user buffer
2260 * @lenp: the size of the user buffer
2261 * @ppos: file position
2262 *
2263 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2264 * values from/to the user buffer, treated as an ASCII string. The values
2265 * are treated as milliseconds, and converted to jiffies when they are stored.
2266 *
2267 * This routine will ensure the values are within the range specified by
2268 * table->extra1 (min) and table->extra2 (max).
2269 *
2270 * Returns 0 on success.
2271 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002272int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 struct file *filp,
2274 void __user *buffer,
2275 size_t *lenp, loff_t *ppos)
2276{
2277 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2278 lenp, ppos, HZ, 1000l);
2279}
2280
2281
2282static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2283 int *valp,
2284 int write, void *data)
2285{
2286 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002287 if (*lvalp > LONG_MAX / HZ)
2288 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2290 } else {
2291 int val = *valp;
2292 unsigned long lval;
2293 if (val < 0) {
2294 *negp = -1;
2295 lval = (unsigned long)-val;
2296 } else {
2297 *negp = 0;
2298 lval = (unsigned long)val;
2299 }
2300 *lvalp = lval / HZ;
2301 }
2302 return 0;
2303}
2304
2305static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2306 int *valp,
2307 int write, void *data)
2308{
2309 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002310 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2311 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2313 } else {
2314 int val = *valp;
2315 unsigned long lval;
2316 if (val < 0) {
2317 *negp = -1;
2318 lval = (unsigned long)-val;
2319 } else {
2320 *negp = 0;
2321 lval = (unsigned long)val;
2322 }
2323 *lvalp = jiffies_to_clock_t(lval);
2324 }
2325 return 0;
2326}
2327
2328static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2329 int *valp,
2330 int write, void *data)
2331{
2332 if (write) {
2333 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2334 } else {
2335 int val = *valp;
2336 unsigned long lval;
2337 if (val < 0) {
2338 *negp = -1;
2339 lval = (unsigned long)-val;
2340 } else {
2341 *negp = 0;
2342 lval = (unsigned long)val;
2343 }
2344 *lvalp = jiffies_to_msecs(lval);
2345 }
2346 return 0;
2347}
2348
2349/**
2350 * proc_dointvec_jiffies - read a vector of integers as seconds
2351 * @table: the sysctl table
2352 * @write: %TRUE if this is a write to the sysctl file
2353 * @filp: the file structure
2354 * @buffer: the user buffer
2355 * @lenp: the size of the user buffer
2356 * @ppos: file position
2357 *
2358 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2359 * values from/to the user buffer, treated as an ASCII string.
2360 * The values read are assumed to be in seconds, and are converted into
2361 * jiffies.
2362 *
2363 * Returns 0 on success.
2364 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002365int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 void __user *buffer, size_t *lenp, loff_t *ppos)
2367{
2368 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2369 do_proc_dointvec_jiffies_conv,NULL);
2370}
2371
2372/**
2373 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2374 * @table: the sysctl table
2375 * @write: %TRUE if this is a write to the sysctl file
2376 * @filp: the file structure
2377 * @buffer: the user buffer
2378 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002379 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 *
2381 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2382 * values from/to the user buffer, treated as an ASCII string.
2383 * The values read are assumed to be in 1/USER_HZ seconds, and
2384 * are converted into jiffies.
2385 *
2386 * Returns 0 on success.
2387 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002388int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 void __user *buffer, size_t *lenp, loff_t *ppos)
2390{
2391 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2392 do_proc_dointvec_userhz_jiffies_conv,NULL);
2393}
2394
2395/**
2396 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2397 * @table: the sysctl table
2398 * @write: %TRUE if this is a write to the sysctl file
2399 * @filp: the file structure
2400 * @buffer: the user buffer
2401 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002402 * @ppos: file position
2403 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 *
2405 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2406 * values from/to the user buffer, treated as an ASCII string.
2407 * The values read are assumed to be in 1/1000 seconds, and
2408 * are converted into jiffies.
2409 *
2410 * Returns 0 on success.
2411 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002412int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 void __user *buffer, size_t *lenp, loff_t *ppos)
2414{
2415 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2416 do_proc_dointvec_ms_jiffies_conv, NULL);
2417}
2418
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002419static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002420 void __user *buffer, size_t *lenp, loff_t *ppos)
2421{
2422 struct pid *new_pid;
2423 pid_t tmp;
2424 int r;
2425
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002426 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002427
2428 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2429 lenp, ppos, NULL, NULL);
2430 if (r || !write)
2431 return r;
2432
2433 new_pid = find_get_pid(tmp);
2434 if (!new_pid)
2435 return -ESRCH;
2436
2437 put_pid(xchg(&cad_pid, new_pid));
2438 return 0;
2439}
2440
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441#else /* CONFIG_PROC_FS */
2442
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002443int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 void __user *buffer, size_t *lenp, loff_t *ppos)
2445{
2446 return -ENOSYS;
2447}
2448
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002449int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 void __user *buffer, size_t *lenp, loff_t *ppos)
2451{
2452 return -ENOSYS;
2453}
2454
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002455int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 void __user *buffer, size_t *lenp, loff_t *ppos)
2457{
2458 return -ENOSYS;
2459}
2460
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002461int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 void __user *buffer, size_t *lenp, loff_t *ppos)
2463{
2464 return -ENOSYS;
2465}
2466
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002467int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 void __user *buffer, size_t *lenp, loff_t *ppos)
2469{
2470 return -ENOSYS;
2471}
2472
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002473int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 void __user *buffer, size_t *lenp, loff_t *ppos)
2475{
2476 return -ENOSYS;
2477}
2478
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002479int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 void __user *buffer, size_t *lenp, loff_t *ppos)
2481{
2482 return -ENOSYS;
2483}
2484
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002485int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 void __user *buffer, size_t *lenp, loff_t *ppos)
2487{
2488 return -ENOSYS;
2489}
2490
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002491int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 struct file *filp,
2493 void __user *buffer,
2494 size_t *lenp, loff_t *ppos)
2495{
2496 return -ENOSYS;
2497}
2498
2499
2500#endif /* CONFIG_PROC_FS */
2501
2502
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002503#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504/*
2505 * General sysctl support routines
2506 */
2507
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002508/* The generic sysctl data routine (used if no strategy routine supplied) */
2509int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2510 void __user *oldval, size_t __user *oldlenp,
2511 void __user *newval, size_t newlen)
2512{
2513 size_t len;
2514
2515 /* Get out of I don't have a variable */
2516 if (!table->data || !table->maxlen)
2517 return -ENOTDIR;
2518
2519 if (oldval && oldlenp) {
2520 if (get_user(len, oldlenp))
2521 return -EFAULT;
2522 if (len) {
2523 if (len > table->maxlen)
2524 len = table->maxlen;
2525 if (copy_to_user(oldval, table->data, len))
2526 return -EFAULT;
2527 if (put_user(len, oldlenp))
2528 return -EFAULT;
2529 }
2530 }
2531
2532 if (newval && newlen) {
2533 if (newlen > table->maxlen)
2534 newlen = table->maxlen;
2535
2536 if (copy_from_user(table->data, newval, newlen))
2537 return -EFAULT;
2538 }
2539 return 1;
2540}
2541
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002543int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002545 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 if (!table->data || !table->maxlen)
2548 return -ENOTDIR;
2549
2550 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002551 size_t bufsize;
2552 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002554 if (bufsize) {
2555 size_t len = strlen(table->data), copied;
2556
2557 /* This shouldn't trigger for a well-formed sysctl */
2558 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002560
2561 /* Copy up to a max of bufsize-1 bytes of the string */
2562 copied = (len >= bufsize) ? bufsize - 1 : len;
2563
2564 if (copy_to_user(oldval, table->data, copied) ||
2565 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002567 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 return -EFAULT;
2569 }
2570 }
2571 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002572 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 if (len > table->maxlen)
2574 len = table->maxlen;
2575 if(copy_from_user(table->data, newval, len))
2576 return -EFAULT;
2577 if (len == table->maxlen)
2578 len--;
2579 ((char *) table->data)[len] = 0;
2580 }
Yi Yang82c9df82005-12-30 16:37:10 +08002581 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582}
2583
2584/*
2585 * This function makes sure that all of the integers in the vector
2586 * are between the minimum and maximum values given in the arrays
2587 * table->extra1 and table->extra2, respectively.
2588 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002589int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002591 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592{
2593
2594 if (newval && newlen) {
2595 int __user *vec = (int __user *) newval;
2596 int *min = (int *) table->extra1;
2597 int *max = (int *) table->extra2;
2598 size_t length;
2599 int i;
2600
2601 if (newlen % sizeof(int) != 0)
2602 return -EINVAL;
2603
2604 if (!table->extra1 && !table->extra2)
2605 return 0;
2606
2607 if (newlen > table->maxlen)
2608 newlen = table->maxlen;
2609 length = newlen / sizeof(int);
2610
2611 for (i = 0; i < length; i++) {
2612 int value;
2613 if (get_user(value, vec + i))
2614 return -EFAULT;
2615 if (min && value < min[i])
2616 return -EINVAL;
2617 if (max && value > max[i])
2618 return -EINVAL;
2619 }
2620 }
2621 return 0;
2622}
2623
2624/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002625int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002627 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002629 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002631
2632 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002634 if (olen) {
2635 int val;
2636
2637 if (olen < sizeof(int))
2638 return -EINVAL;
2639
2640 val = *(int *)(table->data) / HZ;
2641 if (put_user(val, (int __user *)oldval))
2642 return -EFAULT;
2643 if (put_user(sizeof(int), oldlenp))
2644 return -EFAULT;
2645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 }
2647 if (newval && newlen) {
2648 int new;
2649 if (newlen != sizeof(int))
2650 return -EINVAL;
2651 if (get_user(new, (int __user *)newval))
2652 return -EFAULT;
2653 *(int *)(table->data) = new*HZ;
2654 }
2655 return 1;
2656}
2657
2658/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002659int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002661 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002663 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002665
2666 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002668 if (olen) {
2669 int val;
2670
2671 if (olen < sizeof(int))
2672 return -EINVAL;
2673
2674 val = jiffies_to_msecs(*(int *)(table->data));
2675 if (put_user(val, (int __user *)oldval))
2676 return -EFAULT;
2677 if (put_user(sizeof(int), oldlenp))
2678 return -EFAULT;
2679 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 }
2681 if (newval && newlen) {
2682 int new;
2683 if (newlen != sizeof(int))
2684 return -EINVAL;
2685 if (get_user(new, (int __user *)newval))
2686 return -EFAULT;
2687 *(int *)(table->data) = msecs_to_jiffies(new);
2688 }
2689 return 1;
2690}
2691
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002692
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002693
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002694#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
2696
2697asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2698{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002699 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002700 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002701
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002702 if (copy_from_user(&tmp, args, sizeof(tmp)))
2703 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002704
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002705 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002706
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002707 /* If no error reading the parameters then just -ENOSYS ... */
2708 if (!error)
2709 error = -ENOSYS;
2710
2711 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712}
2713
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002714int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2715 void __user *oldval, size_t __user *oldlenp,
2716 void __user *newval, size_t newlen)
2717{
2718 return -ENOSYS;
2719}
2720
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002721int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002723 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724{
2725 return -ENOSYS;
2726}
2727
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002728int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002730 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731{
2732 return -ENOSYS;
2733}
2734
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002735int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002737 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738{
2739 return -ENOSYS;
2740}
2741
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002742int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002744 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745{
2746 return -ENOSYS;
2747}
2748
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002749#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002751static int deprecated_sysctl_warning(struct __sysctl_args *args)
2752{
2753 static int msg_count;
2754 int name[CTL_MAXNAME];
2755 int i;
2756
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002757 /* Check args->nlen. */
2758 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2759 return -ENOTDIR;
2760
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002761 /* Read in the sysctl name for better debug message logging */
2762 for (i = 0; i < args->nlen; i++)
2763 if (get_user(name[i], args->name + i))
2764 return -EFAULT;
2765
2766 /* Ignore accesses to kernel.version */
2767 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2768 return 0;
2769
2770 if (msg_count < 5) {
2771 msg_count++;
2772 printk(KERN_INFO
2773 "warning: process `%s' used the deprecated sysctl "
2774 "system call with ", current->comm);
2775 for (i = 0; i < args->nlen; i++)
2776 printk("%d.", name[i]);
2777 printk("\n");
2778 }
2779 return 0;
2780}
2781
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782/*
2783 * No sense putting this after each symbol definition, twice,
2784 * exception granted :-)
2785 */
2786EXPORT_SYMBOL(proc_dointvec);
2787EXPORT_SYMBOL(proc_dointvec_jiffies);
2788EXPORT_SYMBOL(proc_dointvec_minmax);
2789EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2790EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2791EXPORT_SYMBOL(proc_dostring);
2792EXPORT_SYMBOL(proc_doulongvec_minmax);
2793EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2794EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002795EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796EXPORT_SYMBOL(sysctl_intvec);
2797EXPORT_SYMBOL(sysctl_jiffies);
2798EXPORT_SYMBOL(sysctl_ms_jiffies);
2799EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002800EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801EXPORT_SYMBOL(unregister_sysctl_table);