blob: 5e2ad5bf88e280fdbc83b61a380909555e121a71 [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>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010056#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020057#endif
58
Eric W. Biederman7058cb02007-10-18 03:05:58 -070059static int deprecated_sysctl_warning(struct __sysctl_args *args);
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#if defined(CONFIG_SYSCTL)
62
63/* External variables not in a header file. */
64extern int C_A_D;
Ingo Molnar45807a12007-07-15 23:40:10 -070065extern int print_fatal_signals;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066extern int sysctl_overcommit_memory;
67extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070068extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070069extern int sysctl_oom_kill_allocating_task;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070072extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern char core_pattern[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern int pid_max;
75extern int min_free_kbytes;
76extern int printk_ratelimit_jiffies;
77extern int printk_ratelimit_burst;
78extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080079extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080080extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020081extern int compat_log;
Kees Cook5096add2007-05-08 00:26:04 -070082extern int maps_protect;
Christoph Lameter77461ab2007-05-09 02:35:13 -070083extern int sysctl_stat_interval;
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 */
Bron Gondwana195cf452008-02-04 22:29:20 -080087#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070088static int one = 1;
Bron Gondwana195cf452008-02-04 22:29:20 -080089#endif
90
91#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -070092static int sixty = 60;
93#endif
94
95#ifdef CONFIG_MMU
96static int two = 2;
97#endif
98
99static int zero;
100static int one_hundred = 100;
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
103static int maxolduid = 65535;
104static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800105static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107static int ngroups_max = NGROUPS_MAX;
108
109#ifdef CONFIG_KMOD
110extern char modprobe_path[];
111#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#ifdef CONFIG_CHR_DEV_SG
113extern int sg_big_buff;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116#ifdef __sparc__
117extern char reboot_command [];
118extern int stop_a_enabled;
119extern int scons_pwroff;
120#endif
121
122#ifdef __hppa__
123extern int pwrsw_enabled;
124extern int unaligned_enabled;
125#endif
126
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800127#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#ifdef CONFIG_MATHEMU
129extern int sysctl_ieee_emulation_warnings;
130#endif
131extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700132extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#endif
134
135extern int sysctl_hz_timer;
136
137#ifdef CONFIG_BSD_PROCESS_ACCT
138extern int acct_parm[];
139#endif
140
Jes Sorensend2b176e2006-02-28 09:42:23 -0800141#ifdef CONFIG_IA64
142extern int no_unaligned_warning;
143#endif
144
Ingo Molnar23f78d42006-06-27 02:54:53 -0700145#ifdef CONFIG_RT_MUTEXES
146extern int max_lock_depth;
147#endif
148
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700149#ifdef CONFIG_SYSCTL_SYSCALL
150static int parse_table(int __user *, int, void __user *, size_t __user *,
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700151 void __user *, size_t, struct ctl_table *);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700152#endif
153
Eric W. Biederman6b49a252006-12-08 02:39:57 -0800154
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700155#ifdef CONFIG_PROC_SYSCTL
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700156static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700157 void __user *buffer, size_t *lenp, loff_t *ppos);
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700158static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800159 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700160#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700161
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700162static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100163static struct ctl_table_root sysctl_table_root;
164static struct ctl_table_header root_table_header = {
165 .ctl_table = root_table,
166 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
167 .root = &sysctl_table_root,
168};
169static struct ctl_table_root sysctl_table_root = {
170 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
171 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
172};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700174static struct ctl_table kern_table[];
175static struct ctl_table vm_table[];
176static struct ctl_table fs_table[];
177static struct ctl_table debug_table[];
178static struct ctl_table dev_table[];
179extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700180#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700181extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400182#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
185int sysctl_legacy_va_layout;
186#endif
187
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700188extern int prove_locking;
189extern int lock_stat;
Eric W. Biederman9bc9a6b2006-12-08 02:39:56 -0800190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191/* The default sysctl tables: */
192
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700193static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 {
195 .ctl_name = CTL_KERN,
196 .procname = "kernel",
197 .mode = 0555,
198 .child = kern_table,
199 },
200 {
201 .ctl_name = CTL_VM,
202 .procname = "vm",
203 .mode = 0555,
204 .child = vm_table,
205 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 .ctl_name = CTL_FS,
208 .procname = "fs",
209 .mode = 0555,
210 .child = fs_table,
211 },
212 {
213 .ctl_name = CTL_DEBUG,
214 .procname = "debug",
215 .mode = 0555,
216 .child = debug_table,
217 },
218 {
219 .ctl_name = CTL_DEV,
220 .procname = "dev",
221 .mode = 0555,
222 .child = dev_table,
223 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700224/*
225 * NOTE: do not add new entries to this table unless you have read
226 * Documentation/sysctl/ctl_unnumbered.txt
227 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 { .ctl_name = 0 }
229};
230
Ingo Molnar77e54a12007-07-09 18:52:00 +0200231#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100232static int min_sched_granularity_ns = 100000; /* 100 usecs */
233static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
234static int min_wakeup_granularity_ns; /* 0 usecs */
235static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200236#endif
237
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700238static struct ctl_table kern_table[] = {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200239#ifdef CONFIG_SCHED_DEBUG
240 {
241 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100242 .procname = "sched_min_granularity_ns",
243 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200244 .maxlen = sizeof(unsigned int),
245 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100246 .proc_handler = &sched_nr_latency_handler,
247 .strategy = &sysctl_intvec,
248 .extra1 = &min_sched_granularity_ns,
249 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200250 },
251 {
252 .ctl_name = CTL_UNNUMBERED,
Peter Zijlstra21805082007-08-25 18:41:53 +0200253 .procname = "sched_latency_ns",
254 .data = &sysctl_sched_latency,
255 .maxlen = sizeof(unsigned int),
256 .mode = 0644,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100257 .proc_handler = &sched_nr_latency_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200258 .strategy = &sysctl_intvec,
259 .extra1 = &min_sched_granularity_ns,
260 .extra2 = &max_sched_granularity_ns,
261 },
262 {
263 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200264 .procname = "sched_wakeup_granularity_ns",
265 .data = &sysctl_sched_wakeup_granularity,
266 .maxlen = sizeof(unsigned int),
267 .mode = 0644,
268 .proc_handler = &proc_dointvec_minmax,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_wakeup_granularity_ns,
271 .extra2 = &max_wakeup_granularity_ns,
272 },
273 {
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_batch_wakeup_granularity_ns",
276 .data = &sysctl_sched_batch_wakeup_granularity,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = &proc_dointvec_minmax,
280 .strategy = &sysctl_intvec,
281 .extra1 = &min_wakeup_granularity_ns,
282 .extra2 = &max_wakeup_granularity_ns,
283 },
284 {
285 .ctl_name = CTL_UNNUMBERED,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec,
291 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200292 {
293 .ctl_name = CTL_UNNUMBERED,
294 .procname = "sched_features",
295 .data = &sysctl_sched_features,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
298 .proc_handler = &proc_dointvec,
299 },
Ingo Molnarda84d962007-10-15 17:00:18 +0200300 {
301 .ctl_name = CTL_UNNUMBERED,
302 .procname = "sched_migration_cost",
303 .data = &sysctl_sched_migration_cost,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = &proc_dointvec,
307 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100308 {
309 .ctl_name = CTL_UNNUMBERED,
310 .procname = "sched_nr_migrate",
311 .data = &sysctl_sched_nr_migrate,
312 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100313 .mode = 0644,
314 .proc_handler = &proc_dointvec,
315 },
316 {
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "sched_rt_period_ms",
319 .data = &sysctl_sched_rt_period,
320 .maxlen = sizeof(unsigned int),
321 .mode = 0644,
322 .proc_handler = &proc_dointvec,
323 },
324 {
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_rt_ratio",
327 .data = &sysctl_sched_rt_ratio,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100330 .proc_handler = &proc_dointvec,
331 },
Srivatsa Vaddagiri6b2d7702008-01-25 21:08:00 +0100332#if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP)
333 {
334 .ctl_name = CTL_UNNUMBERED,
335 .procname = "sched_min_bal_int_shares",
336 .data = &sysctl_sched_min_bal_int_shares,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
340 },
341 {
342 .ctl_name = CTL_UNNUMBERED,
343 .procname = "sched_max_bal_int_shares",
344 .data = &sysctl_sched_max_bal_int_shares,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
348 },
349#endif
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200350#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200351 {
352 .ctl_name = CTL_UNNUMBERED,
353 .procname = "sched_compat_yield",
354 .data = &sysctl_sched_compat_yield,
355 .maxlen = sizeof(unsigned int),
356 .mode = 0644,
357 .proc_handler = &proc_dointvec,
358 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700359#ifdef CONFIG_PROVE_LOCKING
360 {
361 .ctl_name = CTL_UNNUMBERED,
362 .procname = "prove_locking",
363 .data = &prove_locking,
364 .maxlen = sizeof(int),
365 .mode = 0644,
366 .proc_handler = &proc_dointvec,
367 },
368#endif
369#ifdef CONFIG_LOCK_STAT
370 {
371 .ctl_name = CTL_UNNUMBERED,
372 .procname = "lock_stat",
373 .data = &lock_stat,
374 .maxlen = sizeof(int),
375 .mode = 0644,
376 .proc_handler = &proc_dointvec,
377 },
378#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200379 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 .ctl_name = KERN_PANIC,
381 .procname = "panic",
382 .data = &panic_timeout,
383 .maxlen = sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
386 },
387 {
388 .ctl_name = KERN_CORE_USES_PID,
389 .procname = "core_uses_pid",
390 .data = &core_uses_pid,
391 .maxlen = sizeof(int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
394 },
395 {
396 .ctl_name = KERN_CORE_PATTERN,
397 .procname = "core_pattern",
398 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700399 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 .mode = 0644,
401 .proc_handler = &proc_dostring,
402 .strategy = &sysctl_string,
403 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800404#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 .procname = "tainted",
407 .data = &tainted,
408 .maxlen = sizeof(int),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800409 .mode = 0644,
410 .proc_handler = &proc_dointvec_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800412#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100413#ifdef CONFIG_LATENCYTOP
414 {
415 .procname = "latencytop",
416 .data = &latencytop_enabled,
417 .maxlen = sizeof(int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
420 },
421#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#ifdef CONFIG_BLK_DEV_INITRD
423 {
424 .ctl_name = KERN_REALROOTDEV,
425 .procname = "real-root-dev",
426 .data = &real_root_dev,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
430 },
431#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700432 {
433 .ctl_name = CTL_UNNUMBERED,
434 .procname = "print-fatal-signals",
435 .data = &print_fatal_signals,
436 .maxlen = sizeof(int),
437 .mode = 0644,
438 .proc_handler = &proc_dointvec,
439 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#ifdef __sparc__
441 {
442 .ctl_name = KERN_SPARC_REBOOT,
443 .procname = "reboot-cmd",
444 .data = reboot_command,
445 .maxlen = 256,
446 .mode = 0644,
447 .proc_handler = &proc_dostring,
448 .strategy = &sysctl_string,
449 },
450 {
451 .ctl_name = KERN_SPARC_STOP_A,
452 .procname = "stop-a",
453 .data = &stop_a_enabled,
454 .maxlen = sizeof (int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
457 },
458 {
459 .ctl_name = KERN_SPARC_SCONS_PWROFF,
460 .procname = "scons-poweroff",
461 .data = &scons_pwroff,
462 .maxlen = sizeof (int),
463 .mode = 0644,
464 .proc_handler = &proc_dointvec,
465 },
466#endif
467#ifdef __hppa__
468 {
469 .ctl_name = KERN_HPPA_PWRSW,
470 .procname = "soft-power",
471 .data = &pwrsw_enabled,
472 .maxlen = sizeof (int),
473 .mode = 0644,
474 .proc_handler = &proc_dointvec,
475 },
476 {
477 .ctl_name = KERN_HPPA_UNALIGNED,
478 .procname = "unaligned-trap",
479 .data = &unaligned_enabled,
480 .maxlen = sizeof (int),
481 .mode = 0644,
482 .proc_handler = &proc_dointvec,
483 },
484#endif
485 {
486 .ctl_name = KERN_CTLALTDEL,
487 .procname = "ctrl-alt-del",
488 .data = &C_A_D,
489 .maxlen = sizeof(int),
490 .mode = 0644,
491 .proc_handler = &proc_dointvec,
492 },
493 {
494 .ctl_name = KERN_PRINTK,
495 .procname = "printk",
496 .data = &console_loglevel,
497 .maxlen = 4*sizeof(int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
500 },
501#ifdef CONFIG_KMOD
502 {
503 .ctl_name = KERN_MODPROBE,
504 .procname = "modprobe",
505 .data = &modprobe_path,
506 .maxlen = KMOD_PATH_LEN,
507 .mode = 0644,
508 .proc_handler = &proc_dostring,
509 .strategy = &sysctl_string,
510 },
511#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700512#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 {
514 .ctl_name = KERN_HOTPLUG,
515 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100516 .data = &uevent_helper,
517 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .mode = 0644,
519 .proc_handler = &proc_dostring,
520 .strategy = &sysctl_string,
521 },
522#endif
523#ifdef CONFIG_CHR_DEV_SG
524 {
525 .ctl_name = KERN_SG_BIG_BUFF,
526 .procname = "sg-big-buff",
527 .data = &sg_big_buff,
528 .maxlen = sizeof (int),
529 .mode = 0444,
530 .proc_handler = &proc_dointvec,
531 },
532#endif
533#ifdef CONFIG_BSD_PROCESS_ACCT
534 {
535 .ctl_name = KERN_ACCT,
536 .procname = "acct",
537 .data = &acct_parm,
538 .maxlen = 3*sizeof(int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec,
541 },
542#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543#ifdef CONFIG_MAGIC_SYSRQ
544 {
545 .ctl_name = KERN_SYSRQ,
546 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800547 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 .maxlen = sizeof (int),
549 .mode = 0644,
550 .proc_handler = &proc_dointvec,
551 },
552#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700553#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700556 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 .maxlen = sizeof (int),
558 .mode = 0600,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700559 .proc_handler = &proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700561#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 {
563 .ctl_name = KERN_MAX_THREADS,
564 .procname = "threads-max",
565 .data = &max_threads,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec,
569 },
570 {
571 .ctl_name = KERN_RANDOM,
572 .procname = "random",
573 .mode = 0555,
574 .child = random_table,
575 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 {
577 .ctl_name = KERN_OVERFLOWUID,
578 .procname = "overflowuid",
579 .data = &overflowuid,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 .proc_handler = &proc_dointvec_minmax,
583 .strategy = &sysctl_intvec,
584 .extra1 = &minolduid,
585 .extra2 = &maxolduid,
586 },
587 {
588 .ctl_name = KERN_OVERFLOWGID,
589 .procname = "overflowgid",
590 .data = &overflowgid,
591 .maxlen = sizeof(int),
592 .mode = 0644,
593 .proc_handler = &proc_dointvec_minmax,
594 .strategy = &sysctl_intvec,
595 .extra1 = &minolduid,
596 .extra2 = &maxolduid,
597 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800598#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#ifdef CONFIG_MATHEMU
600 {
601 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
602 .procname = "ieee_emulation_warnings",
603 .data = &sysctl_ieee_emulation_warnings,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec,
607 },
608#endif
609#ifdef CONFIG_NO_IDLE_HZ
610 {
611 .ctl_name = KERN_HZ_TIMER,
612 .procname = "hz_timer",
613 .data = &sysctl_hz_timer,
614 .maxlen = sizeof(int),
615 .mode = 0644,
616 .proc_handler = &proc_dointvec,
617 },
618#endif
619 {
620 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
621 .procname = "userprocess_debug",
622 .data = &sysctl_userprocess_debug,
623 .maxlen = sizeof(int),
624 .mode = 0644,
625 .proc_handler = &proc_dointvec,
626 },
627#endif
628 {
629 .ctl_name = KERN_PIDMAX,
630 .procname = "pid_max",
631 .data = &pid_max,
632 .maxlen = sizeof (int),
633 .mode = 0644,
634 .proc_handler = &proc_dointvec_minmax,
635 .strategy = sysctl_intvec,
636 .extra1 = &pid_max_min,
637 .extra2 = &pid_max_max,
638 },
639 {
640 .ctl_name = KERN_PANIC_ON_OOPS,
641 .procname = "panic_on_oops",
642 .data = &panic_on_oops,
643 .maxlen = sizeof(int),
644 .mode = 0644,
645 .proc_handler = &proc_dointvec,
646 },
647 {
648 .ctl_name = KERN_PRINTK_RATELIMIT,
649 .procname = "printk_ratelimit",
650 .data = &printk_ratelimit_jiffies,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec_jiffies,
654 .strategy = &sysctl_jiffies,
655 },
656 {
657 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
658 .procname = "printk_ratelimit_burst",
659 .data = &printk_ratelimit_burst,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec,
663 },
664 {
665 .ctl_name = KERN_NGROUPS_MAX,
666 .procname = "ngroups_max",
667 .data = &ngroups_max,
668 .maxlen = sizeof (int),
669 .mode = 0444,
670 .proc_handler = &proc_dointvec,
671 },
672#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
673 {
674 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
675 .procname = "unknown_nmi_panic",
676 .data = &unknown_nmi_panic,
677 .maxlen = sizeof (int),
678 .mode = 0644,
Don Zickus2fbe7b22006-09-26 10:52:27 +0200679 .proc_handler = &proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 },
Don Zickus407984f2006-09-26 10:52:27 +0200681 {
Don Zickus407984f2006-09-26 10:52:27 +0200682 .procname = "nmi_watchdog",
683 .data = &nmi_watchdog_enabled,
684 .maxlen = sizeof (int),
685 .mode = 0644,
686 .proc_handler = &proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 },
688#endif
689#if defined(CONFIG_X86)
690 {
Don Zickus8da5add2006-09-26 10:52:27 +0200691 .ctl_name = KERN_PANIC_ON_NMI,
692 .procname = "panic_on_unrecovered_nmi",
693 .data = &panic_on_unrecovered_nmi,
694 .maxlen = sizeof(int),
695 .mode = 0644,
696 .proc_handler = &proc_dointvec,
697 },
698 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 .ctl_name = KERN_BOOTLOADER_TYPE,
700 .procname = "bootloader_type",
701 .data = &bootloader_type,
702 .maxlen = sizeof (int),
703 .mode = 0444,
704 .proc_handler = &proc_dointvec,
705 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100706 {
707 .ctl_name = CTL_UNNUMBERED,
708 .procname = "kstack_depth_to_print",
709 .data = &kstack_depth_to_print,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
713 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100714 {
715 .ctl_name = CTL_UNNUMBERED,
716 .procname = "io_delay_type",
717 .data = &io_delay_type,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
721 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800723#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 {
725 .ctl_name = KERN_RANDOMIZE,
726 .procname = "randomize_va_space",
727 .data = &randomize_va_space,
728 .maxlen = sizeof(int),
729 .mode = 0644,
730 .proc_handler = &proc_dointvec,
731 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800732#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800733#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700734 {
735 .ctl_name = KERN_SPIN_RETRY,
736 .procname = "spin_retry",
737 .data = &spin_retry,
738 .maxlen = sizeof (int),
739 .mode = 0644,
740 .proc_handler = &proc_dointvec,
741 },
742#endif
Len Brown673d5b42007-07-28 03:33:16 -0400743#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800744 {
Pavel Machekc255d842006-02-20 18:27:58 -0800745 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700746 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800747 .maxlen = sizeof (unsigned long),
748 .mode = 0644,
Stefan Seyfried7f99f062006-03-02 02:54:34 -0800749 .proc_handler = &proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800750 },
751#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800752#ifdef CONFIG_IA64
753 {
754 .ctl_name = KERN_IA64_UNALIGNED,
755 .procname = "ignore-unaligned-usertrap",
756 .data = &no_unaligned_warning,
757 .maxlen = sizeof (int),
758 .mode = 0644,
759 .proc_handler = &proc_dointvec,
760 },
761#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700762#ifdef CONFIG_DETECT_SOFTLOCKUP
763 {
764 .ctl_name = CTL_UNNUMBERED,
765 .procname = "softlockup_thresh",
766 .data = &softlockup_thresh,
Ingo Molnar90739082008-01-25 21:08:34 +0100767 .maxlen = sizeof(unsigned long),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700768 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100769 .proc_handler = &proc_doulongvec_minmax,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700770 .strategy = &sysctl_intvec,
771 .extra1 = &one,
772 .extra2 = &sixty,
773 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100774 {
775 .ctl_name = CTL_UNNUMBERED,
776 .procname = "hung_task_check_count",
777 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100778 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100779 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100780 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100781 .strategy = &sysctl_intvec,
782 },
783 {
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "hung_task_timeout_secs",
786 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100787 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100788 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100789 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100790 .strategy = &sysctl_intvec,
791 },
792 {
793 .ctl_name = CTL_UNNUMBERED,
794 .procname = "hung_task_warnings",
795 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100796 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100797 .mode = 0644,
Ingo Molnar90739082008-01-25 21:08:34 +0100798 .proc_handler = &proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100799 .strategy = &sysctl_intvec,
800 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700801#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200802#ifdef CONFIG_COMPAT
803 {
804 .ctl_name = KERN_COMPAT_LOG,
805 .procname = "compat-log",
806 .data = &compat_log,
807 .maxlen = sizeof (int),
808 .mode = 0644,
809 .proc_handler = &proc_dointvec,
810 },
811#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -0700812#ifdef CONFIG_RT_MUTEXES
813 {
814 .ctl_name = KERN_MAX_LOCK_DEPTH,
815 .procname = "max_lock_depth",
816 .data = &max_lock_depth,
817 .maxlen = sizeof(int),
818 .mode = 0644,
819 .proc_handler = &proc_dointvec,
820 },
821#endif
Kees Cook5096add2007-05-08 00:26:04 -0700822#ifdef CONFIG_PROC_FS
823 {
824 .ctl_name = CTL_UNNUMBERED,
825 .procname = "maps_protect",
826 .data = &maps_protect,
827 .maxlen = sizeof(int),
828 .mode = 0644,
829 .proc_handler = &proc_dointvec,
830 },
831#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700832 {
833 .ctl_name = CTL_UNNUMBERED,
834 .procname = "poweroff_cmd",
835 .data = &poweroff_cmd,
836 .maxlen = POWEROFF_CMD_PATH_LEN,
837 .mode = 0644,
838 .proc_handler = &proc_dostring,
839 .strategy = &sysctl_string,
840 },
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700841/*
842 * NOTE: do not add new entries to this table unless you have read
843 * Documentation/sysctl/ctl_unnumbered.txt
844 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 { .ctl_name = 0 }
846};
847
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700848static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 {
850 .ctl_name = VM_OVERCOMMIT_MEMORY,
851 .procname = "overcommit_memory",
852 .data = &sysctl_overcommit_memory,
853 .maxlen = sizeof(sysctl_overcommit_memory),
854 .mode = 0644,
855 .proc_handler = &proc_dointvec,
856 },
857 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700858 .ctl_name = VM_PANIC_ON_OOM,
859 .procname = "panic_on_oom",
860 .data = &sysctl_panic_on_oom,
861 .maxlen = sizeof(sysctl_panic_on_oom),
862 .mode = 0644,
863 .proc_handler = &proc_dointvec,
864 },
865 {
David Rientjesfe071d72007-10-16 23:25:56 -0700866 .ctl_name = CTL_UNNUMBERED,
867 .procname = "oom_kill_allocating_task",
868 .data = &sysctl_oom_kill_allocating_task,
869 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
870 .mode = 0644,
871 .proc_handler = &proc_dointvec,
872 },
873 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 .ctl_name = VM_OVERCOMMIT_RATIO,
875 .procname = "overcommit_ratio",
876 .data = &sysctl_overcommit_ratio,
877 .maxlen = sizeof(sysctl_overcommit_ratio),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec,
880 },
881 {
882 .ctl_name = VM_PAGE_CLUSTER,
883 .procname = "page-cluster",
884 .data = &page_cluster,
885 .maxlen = sizeof(int),
886 .mode = 0644,
887 .proc_handler = &proc_dointvec,
888 },
889 {
890 .ctl_name = VM_DIRTY_BACKGROUND,
891 .procname = "dirty_background_ratio",
892 .data = &dirty_background_ratio,
893 .maxlen = sizeof(dirty_background_ratio),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec_minmax,
896 .strategy = &sysctl_intvec,
897 .extra1 = &zero,
898 .extra2 = &one_hundred,
899 },
900 {
901 .ctl_name = VM_DIRTY_RATIO,
902 .procname = "dirty_ratio",
903 .data = &vm_dirty_ratio,
904 .maxlen = sizeof(vm_dirty_ratio),
905 .mode = 0644,
Peter Zijlstra04fbfdc2007-10-16 23:25:50 -0700906 .proc_handler = &dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 .strategy = &sysctl_intvec,
908 .extra1 = &zero,
909 .extra2 = &one_hundred,
910 },
911 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800913 .data = &dirty_writeback_interval,
914 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 .mode = 0644,
916 .proc_handler = &dirty_writeback_centisecs_handler,
917 },
918 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -0800920 .data = &dirty_expire_interval,
921 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 .mode = 0644,
Bart Samwelf6ef9432006-03-24 03:15:48 -0800923 .proc_handler = &proc_dointvec_userhz_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 },
925 {
926 .ctl_name = VM_NR_PDFLUSH_THREADS,
927 .procname = "nr_pdflush_threads",
928 .data = &nr_pdflush_threads,
929 .maxlen = sizeof nr_pdflush_threads,
930 .mode = 0444 /* read-only*/,
931 .proc_handler = &proc_dointvec,
932 },
933 {
934 .ctl_name = VM_SWAPPINESS,
935 .procname = "swappiness",
936 .data = &vm_swappiness,
937 .maxlen = sizeof(vm_swappiness),
938 .mode = 0644,
939 .proc_handler = &proc_dointvec_minmax,
940 .strategy = &sysctl_intvec,
941 .extra1 = &zero,
942 .extra2 = &one_hundred,
943 },
944#ifdef CONFIG_HUGETLB_PAGE
945 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 .procname = "nr_hugepages",
947 .data = &max_huge_pages,
948 .maxlen = sizeof(unsigned long),
949 .mode = 0644,
950 .proc_handler = &hugetlb_sysctl_handler,
951 .extra1 = (void *)&hugetlb_zero,
952 .extra2 = (void *)&hugetlb_infinity,
953 },
954 {
955 .ctl_name = VM_HUGETLB_GROUP,
956 .procname = "hugetlb_shm_group",
957 .data = &sysctl_hugetlb_shm_group,
958 .maxlen = sizeof(gid_t),
959 .mode = 0644,
960 .proc_handler = &proc_dointvec,
961 },
Mel Gorman396faf02007-07-17 04:03:13 -0700962 {
963 .ctl_name = CTL_UNNUMBERED,
964 .procname = "hugepages_treat_as_movable",
965 .data = &hugepages_treat_as_movable,
966 .maxlen = sizeof(int),
967 .mode = 0644,
968 .proc_handler = &hugetlb_treat_movable_handler,
969 },
Adam Litke54f9f802007-10-16 01:26:20 -0700970 {
971 .ctl_name = CTL_UNNUMBERED,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -0800972 .procname = "nr_overcommit_hugepages",
973 .data = &nr_overcommit_huge_pages,
974 .maxlen = sizeof(nr_overcommit_huge_pages),
975 .mode = 0644,
976 .proc_handler = &proc_doulongvec_minmax,
977 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978#endif
979 {
980 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
981 .procname = "lowmem_reserve_ratio",
982 .data = &sysctl_lowmem_reserve_ratio,
983 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
984 .mode = 0644,
985 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
986 .strategy = &sysctl_intvec,
987 },
988 {
Andrew Morton9d0243b2006-01-08 01:00:39 -0800989 .ctl_name = VM_DROP_PAGECACHE,
990 .procname = "drop_caches",
991 .data = &sysctl_drop_caches,
992 .maxlen = sizeof(int),
993 .mode = 0644,
994 .proc_handler = drop_caches_sysctl_handler,
995 .strategy = &sysctl_intvec,
996 },
997 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 .ctl_name = VM_MIN_FREE_KBYTES,
999 .procname = "min_free_kbytes",
1000 .data = &min_free_kbytes,
1001 .maxlen = sizeof(min_free_kbytes),
1002 .mode = 0644,
1003 .proc_handler = &min_free_kbytes_sysctl_handler,
1004 .strategy = &sysctl_intvec,
1005 .extra1 = &zero,
1006 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001007 {
1008 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1009 .procname = "percpu_pagelist_fraction",
1010 .data = &percpu_pagelist_fraction,
1011 .maxlen = sizeof(percpu_pagelist_fraction),
1012 .mode = 0644,
1013 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1014 .strategy = &sysctl_intvec,
1015 .extra1 = &min_percpu_pagelist_fract,
1016 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017#ifdef CONFIG_MMU
1018 {
1019 .ctl_name = VM_MAX_MAP_COUNT,
1020 .procname = "max_map_count",
1021 .data = &sysctl_max_map_count,
1022 .maxlen = sizeof(sysctl_max_map_count),
1023 .mode = 0644,
1024 .proc_handler = &proc_dointvec
1025 },
1026#endif
1027 {
1028 .ctl_name = VM_LAPTOP_MODE,
1029 .procname = "laptop_mode",
1030 .data = &laptop_mode,
1031 .maxlen = sizeof(laptop_mode),
1032 .mode = 0644,
Bart Samweled5b43f2006-03-24 03:15:49 -08001033 .proc_handler = &proc_dointvec_jiffies,
1034 .strategy = &sysctl_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 },
1036 {
1037 .ctl_name = VM_BLOCK_DUMP,
1038 .procname = "block_dump",
1039 .data = &block_dump,
1040 .maxlen = sizeof(block_dump),
1041 .mode = 0644,
1042 .proc_handler = &proc_dointvec,
1043 .strategy = &sysctl_intvec,
1044 .extra1 = &zero,
1045 },
1046 {
1047 .ctl_name = VM_VFS_CACHE_PRESSURE,
1048 .procname = "vfs_cache_pressure",
1049 .data = &sysctl_vfs_cache_pressure,
1050 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1051 .mode = 0644,
1052 .proc_handler = &proc_dointvec,
1053 .strategy = &sysctl_intvec,
1054 .extra1 = &zero,
1055 },
1056#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1057 {
1058 .ctl_name = VM_LEGACY_VA_LAYOUT,
1059 .procname = "legacy_va_layout",
1060 .data = &sysctl_legacy_va_layout,
1061 .maxlen = sizeof(sysctl_legacy_va_layout),
1062 .mode = 0644,
1063 .proc_handler = &proc_dointvec,
1064 .strategy = &sysctl_intvec,
1065 .extra1 = &zero,
1066 },
1067#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001068#ifdef CONFIG_NUMA
1069 {
1070 .ctl_name = VM_ZONE_RECLAIM_MODE,
1071 .procname = "zone_reclaim_mode",
1072 .data = &zone_reclaim_mode,
1073 .maxlen = sizeof(zone_reclaim_mode),
1074 .mode = 0644,
1075 .proc_handler = &proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001076 .strategy = &sysctl_intvec,
1077 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001078 },
Christoph Lameter96146342006-07-03 00:24:13 -07001079 {
1080 .ctl_name = VM_MIN_UNMAPPED,
1081 .procname = "min_unmapped_ratio",
1082 .data = &sysctl_min_unmapped_ratio,
1083 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1084 .mode = 0644,
1085 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1086 .strategy = &sysctl_intvec,
1087 .extra1 = &zero,
1088 .extra2 = &one_hundred,
1089 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001090 {
1091 .ctl_name = VM_MIN_SLAB,
1092 .procname = "min_slab_ratio",
1093 .data = &sysctl_min_slab_ratio,
1094 .maxlen = sizeof(sysctl_min_slab_ratio),
1095 .mode = 0644,
1096 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1097 .strategy = &sysctl_intvec,
1098 .extra1 = &zero,
1099 .extra2 = &one_hundred,
1100 },
Christoph Lameter17436602006-01-18 17:42:32 -08001101#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001102#ifdef CONFIG_SMP
1103 {
1104 .ctl_name = CTL_UNNUMBERED,
1105 .procname = "stat_interval",
1106 .data = &sysctl_stat_interval,
1107 .maxlen = sizeof(sysctl_stat_interval),
1108 .mode = 0644,
1109 .proc_handler = &proc_dointvec_jiffies,
1110 .strategy = &sysctl_jiffies,
1111 },
1112#endif
Eric Parised032182007-06-28 15:55:21 -04001113#ifdef CONFIG_SECURITY
1114 {
1115 .ctl_name = CTL_UNNUMBERED,
1116 .procname = "mmap_min_addr",
1117 .data = &mmap_min_addr,
1118 .maxlen = sizeof(unsigned long),
1119 .mode = 0644,
1120 .proc_handler = &proc_doulongvec_minmax,
1121 },
Lee Schermerhorn8daec962007-08-10 13:00:51 -07001122#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001123#ifdef CONFIG_NUMA
1124 {
1125 .ctl_name = CTL_UNNUMBERED,
1126 .procname = "numa_zonelist_order",
1127 .data = &numa_zonelist_order,
1128 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1129 .mode = 0644,
1130 .proc_handler = &numa_zonelist_order_handler,
1131 .strategy = &sysctl_string,
1132 },
1133#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001134#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001135 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001136 {
1137 .ctl_name = VM_VDSO_ENABLED,
1138 .procname = "vdso_enabled",
1139 .data = &vdso_enabled,
1140 .maxlen = sizeof(vdso_enabled),
1141 .mode = 0644,
1142 .proc_handler = &proc_dointvec,
1143 .strategy = &sysctl_intvec,
1144 .extra1 = &zero,
1145 },
1146#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001147#ifdef CONFIG_HIGHMEM
1148 {
1149 .ctl_name = CTL_UNNUMBERED,
1150 .procname = "highmem_is_dirtyable",
1151 .data = &vm_highmem_is_dirtyable,
1152 .maxlen = sizeof(vm_highmem_is_dirtyable),
1153 .mode = 0644,
1154 .proc_handler = &proc_dointvec_minmax,
1155 .strategy = &sysctl_intvec,
1156 .extra1 = &zero,
1157 .extra2 = &one,
1158 },
1159#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001160/*
1161 * NOTE: do not add new entries to this table unless you have read
1162 * Documentation/sysctl/ctl_unnumbered.txt
1163 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 { .ctl_name = 0 }
1165};
1166
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001167#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001168static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001169 { .ctl_name = 0 }
1170};
1171#endif
1172
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001173static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 {
1175 .ctl_name = FS_NRINODE,
1176 .procname = "inode-nr",
1177 .data = &inodes_stat,
1178 .maxlen = 2*sizeof(int),
1179 .mode = 0444,
1180 .proc_handler = &proc_dointvec,
1181 },
1182 {
1183 .ctl_name = FS_STATINODE,
1184 .procname = "inode-state",
1185 .data = &inodes_stat,
1186 .maxlen = 7*sizeof(int),
1187 .mode = 0444,
1188 .proc_handler = &proc_dointvec,
1189 },
1190 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 .procname = "file-nr",
1192 .data = &files_stat,
1193 .maxlen = 3*sizeof(int),
1194 .mode = 0444,
Dipankar Sarma529bf6b2006-03-07 21:55:35 -08001195 .proc_handler = &proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 },
1197 {
1198 .ctl_name = FS_MAXFILE,
1199 .procname = "file-max",
1200 .data = &files_stat.max_files,
1201 .maxlen = sizeof(int),
1202 .mode = 0644,
1203 .proc_handler = &proc_dointvec,
1204 },
1205 {
1206 .ctl_name = FS_DENTRY,
1207 .procname = "dentry-state",
1208 .data = &dentry_stat,
1209 .maxlen = 6*sizeof(int),
1210 .mode = 0444,
1211 .proc_handler = &proc_dointvec,
1212 },
1213 {
1214 .ctl_name = FS_OVERFLOWUID,
1215 .procname = "overflowuid",
1216 .data = &fs_overflowuid,
1217 .maxlen = sizeof(int),
1218 .mode = 0644,
1219 .proc_handler = &proc_dointvec_minmax,
1220 .strategy = &sysctl_intvec,
1221 .extra1 = &minolduid,
1222 .extra2 = &maxolduid,
1223 },
1224 {
1225 .ctl_name = FS_OVERFLOWGID,
1226 .procname = "overflowgid",
1227 .data = &fs_overflowgid,
1228 .maxlen = sizeof(int),
1229 .mode = 0644,
1230 .proc_handler = &proc_dointvec_minmax,
1231 .strategy = &sysctl_intvec,
1232 .extra1 = &minolduid,
1233 .extra2 = &maxolduid,
1234 },
1235 {
1236 .ctl_name = FS_LEASES,
1237 .procname = "leases-enable",
1238 .data = &leases_enable,
1239 .maxlen = sizeof(int),
1240 .mode = 0644,
1241 .proc_handler = &proc_dointvec,
1242 },
1243#ifdef CONFIG_DNOTIFY
1244 {
1245 .ctl_name = FS_DIR_NOTIFY,
1246 .procname = "dir-notify-enable",
1247 .data = &dir_notify_enable,
1248 .maxlen = sizeof(int),
1249 .mode = 0644,
1250 .proc_handler = &proc_dointvec,
1251 },
1252#endif
1253#ifdef CONFIG_MMU
1254 {
1255 .ctl_name = FS_LEASE_TIME,
1256 .procname = "lease-break-time",
1257 .data = &lease_break_time,
1258 .maxlen = sizeof(int),
1259 .mode = 0644,
Kawai, Hidehiro76fdbb22007-07-19 01:48:26 -07001260 .proc_handler = &proc_dointvec_minmax,
1261 .strategy = &sysctl_intvec,
1262 .extra1 = &zero,
1263 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 },
1265 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 .procname = "aio-nr",
1267 .data = &aio_nr,
1268 .maxlen = sizeof(aio_nr),
1269 .mode = 0444,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001270 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 },
1272 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 .procname = "aio-max-nr",
1274 .data = &aio_max_nr,
1275 .maxlen = sizeof(aio_max_nr),
1276 .mode = 0644,
Zach Brownd55b5fd2005-11-07 00:59:31 -08001277 .proc_handler = &proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 },
Amy Griffis2d9048e2006-06-01 13:10:59 -07001279#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001280 {
1281 .ctl_name = FS_INOTIFY,
1282 .procname = "inotify",
1283 .mode = 0555,
1284 .child = inotify_table,
1285 },
1286#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001288 {
1289 .ctl_name = KERN_SETUID_DUMPABLE,
1290 .procname = "suid_dumpable",
1291 .data = &suid_dumpable,
1292 .maxlen = sizeof(int),
1293 .mode = 0644,
1294 .proc_handler = &proc_dointvec,
1295 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001296#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1297 {
1298 .ctl_name = CTL_UNNUMBERED,
1299 .procname = "binfmt_misc",
1300 .mode = 0555,
1301 .child = binfmt_misc_table,
1302 },
1303#endif
Andrew Morton2be7fe02007-07-15 23:41:21 -07001304/*
1305 * NOTE: do not add new entries to this table unless you have read
1306 * Documentation/sysctl/ctl_unnumbered.txt
1307 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 { .ctl_name = 0 }
1309};
1310
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001311static struct ctl_table debug_table[] = {
Olof Johanssond0c3d532007-10-12 10:20:07 +10001312#if defined(CONFIG_X86) || defined(CONFIG_PPC)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001313 {
1314 .ctl_name = CTL_UNNUMBERED,
1315 .procname = "exception-trace",
1316 .data = &show_unhandled_signals,
1317 .maxlen = sizeof(int),
1318 .mode = 0644,
1319 .proc_handler = proc_dointvec
1320 },
1321#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 { .ctl_name = 0 }
1323};
1324
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001325static struct ctl_table dev_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 { .ctl_name = 0 }
Robert Love0eeca282005-07-12 17:06:03 -04001327};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Al Viro330d57f2005-11-04 10:18:40 +00001329static DEFINE_SPINLOCK(sysctl_lock);
1330
1331/* called under sysctl_lock */
1332static int use_table(struct ctl_table_header *p)
1333{
1334 if (unlikely(p->unregistering))
1335 return 0;
1336 p->used++;
1337 return 1;
1338}
1339
1340/* called under sysctl_lock */
1341static void unuse_table(struct ctl_table_header *p)
1342{
1343 if (!--p->used)
1344 if (unlikely(p->unregistering))
1345 complete(p->unregistering);
1346}
1347
1348/* called under sysctl_lock, will reacquire if has to wait */
1349static void start_unregistering(struct ctl_table_header *p)
1350{
1351 /*
1352 * if p->used is 0, nobody will ever touch that entry again;
1353 * we'll eliminate all paths to it before dropping sysctl_lock
1354 */
1355 if (unlikely(p->used)) {
1356 struct completion wait;
1357 init_completion(&wait);
1358 p->unregistering = &wait;
1359 spin_unlock(&sysctl_lock);
1360 wait_for_completion(&wait);
1361 spin_lock(&sysctl_lock);
1362 }
1363 /*
1364 * do not remove from the list until nobody holds it; walking the
1365 * list in do_sysctl() relies on that.
1366 */
1367 list_del_init(&p->ctl_entry);
1368}
1369
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001370void sysctl_head_finish(struct ctl_table_header *head)
1371{
1372 if (!head)
1373 return;
1374 spin_lock(&sysctl_lock);
1375 unuse_table(head);
1376 spin_unlock(&sysctl_lock);
1377}
1378
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001379static struct list_head *
1380lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001381{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001382 struct list_head *header_list;
1383 header_list = &root->header_list;
1384 if (root->lookup)
1385 header_list = root->lookup(root, namespaces);
1386 return header_list;
1387}
1388
1389struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1390 struct ctl_table_header *prev)
1391{
1392 struct ctl_table_root *root;
1393 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001394 struct ctl_table_header *head;
1395 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001396
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001397 spin_lock(&sysctl_lock);
1398 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001399 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001400 tmp = &prev->ctl_entry;
1401 unuse_table(prev);
1402 goto next;
1403 }
1404 tmp = &root_table_header.ctl_entry;
1405 for (;;) {
1406 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1407
1408 if (!use_table(head))
1409 goto next;
1410 spin_unlock(&sysctl_lock);
1411 return head;
1412 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001413 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001414 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001415 header_list = lookup_header_list(root, namespaces);
1416 if (tmp != header_list)
1417 continue;
1418
1419 do {
1420 root = list_entry(root->root_list.next,
1421 struct ctl_table_root, root_list);
1422 if (root == &sysctl_table_root)
1423 goto out;
1424 header_list = lookup_header_list(root, namespaces);
1425 } while (list_empty(header_list));
1426 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001427 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001428out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001429 spin_unlock(&sysctl_lock);
1430 return NULL;
1431}
1432
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001433struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1434{
1435 return __sysctl_head_next(current->nsproxy, prev);
1436}
1437
1438void register_sysctl_root(struct ctl_table_root *root)
1439{
1440 spin_lock(&sysctl_lock);
1441 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1442 spin_unlock(&sysctl_lock);
1443}
1444
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001445#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1447 void __user *newval, size_t newlen)
1448{
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001449 struct ctl_table_header *head;
Al Viro330d57f2005-11-04 10:18:40 +00001450 int error = -ENOTDIR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
1452 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1453 return -ENOTDIR;
1454 if (oldval) {
1455 int old_len;
1456 if (!oldlenp || get_user(old_len, oldlenp))
1457 return -EFAULT;
1458 }
Al Viro330d57f2005-11-04 10:18:40 +00001459
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001460 for (head = sysctl_head_next(NULL); head;
1461 head = sysctl_head_next(head)) {
Al Viro330d57f2005-11-04 10:18:40 +00001462 error = parse_table(name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001463 newval, newlen, head->ctl_table);
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001464 if (error != -ENOTDIR) {
1465 sysctl_head_finish(head);
Al Viro330d57f2005-11-04 10:18:40 +00001466 break;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001467 }
1468 }
Al Viro330d57f2005-11-04 10:18:40 +00001469 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470}
1471
1472asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1473{
1474 struct __sysctl_args tmp;
1475 int error;
1476
1477 if (copy_from_user(&tmp, args, sizeof(tmp)))
1478 return -EFAULT;
1479
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001480 error = deprecated_sysctl_warning(&tmp);
1481 if (error)
1482 goto out;
1483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 lock_kernel();
1485 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1486 tmp.newval, tmp.newlen);
1487 unlock_kernel();
Eric W. Biederman7058cb02007-10-18 03:05:58 -07001488out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 return error;
1490}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001491#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001494 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 * some sysctl variables are readonly even to root.
1496 */
1497
1498static int test_perm(int mode, int op)
1499{
1500 if (!current->euid)
1501 mode >>= 6;
1502 else if (in_egroup_p(0))
1503 mode >>= 3;
1504 if ((mode & op & 0007) == op)
1505 return 0;
1506 return -EACCES;
1507}
1508
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001509int sysctl_perm(struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
1511 int error;
1512 error = security_sysctl(table, op);
1513 if (error)
1514 return error;
1515 return test_perm(table->mode, op);
1516}
1517
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001518#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519static int parse_table(int __user *name, int nlen,
1520 void __user *oldval, size_t __user *oldlenp,
1521 void __user *newval, size_t newlen,
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001522 struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
1524 int n;
1525repeat:
1526 if (!nlen)
1527 return -ENOTDIR;
1528 if (get_user(n, name))
1529 return -EFAULT;
Eric W. Biedermand99f1602006-11-05 23:52:12 -08001530 for ( ; table->ctl_name || table->procname; table++) {
1531 if (!table->ctl_name)
1532 continue;
Eric W. Biederman6703ddf2007-02-14 00:34:07 -08001533 if (n == table->ctl_name) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 int error;
1535 if (table->child) {
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001536 if (sysctl_perm(table, 001))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 name++;
1539 nlen--;
1540 table = table->child;
1541 goto repeat;
1542 }
1543 error = do_sysctl_strategy(table, name, nlen,
1544 oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001545 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 return error;
1547 }
1548 }
1549 return -ENOTDIR;
1550}
1551
1552/* Perform the actual read/write of a sysctl table entry. */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001553int do_sysctl_strategy (struct ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 int __user *name, int nlen,
1555 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001556 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
1558 int op = 0, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560 if (oldval)
1561 op |= 004;
1562 if (newval)
1563 op |= 002;
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001564 if (sysctl_perm(table, op))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 return -EPERM;
1566
1567 if (table->strategy) {
1568 rc = table->strategy(table, name, nlen, oldval, oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08001569 newval, newlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 if (rc < 0)
1571 return rc;
1572 if (rc > 0)
1573 return 0;
1574 }
1575
1576 /* If there is no strategy routine, or if the strategy returns
1577 * zero, proceed with automatic r/w */
1578 if (table->data && table->maxlen) {
Eric W. Biederman49a0c452007-10-18 03:05:23 -07001579 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1580 newval, newlen);
1581 if (rc < 0)
1582 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 }
1584 return 0;
1585}
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001586#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001588static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1589{
1590 for (; table->ctl_name || table->procname; table++) {
1591 table->parent = parent;
1592 if (table->child)
1593 sysctl_set_parent(table, table->child);
1594 }
1595}
1596
1597static __init int sysctl_init(void)
1598{
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001599 int err;
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001600 sysctl_set_parent(NULL, root_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001601 err = sysctl_check_table(current->nsproxy, root_table);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001602 return 0;
1603}
1604
1605core_initcall(sysctl_init);
1606
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001608 * __register_sysctl_paths - register a sysctl hierarchy
1609 * @root: List of sysctl headers to register on
1610 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001611 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 *
1614 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001615 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001617 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 *
1619 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1620 * must be unique within that level of sysctl
1621 *
1622 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1623 * enter a sysctl file
1624 *
1625 * data - a pointer to data for use by proc_handler
1626 *
1627 * maxlen - the maximum size in bytes of the data
1628 *
1629 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1630 *
1631 * child - a pointer to the child sysctl table if this entry is a directory, or
1632 * %NULL.
1633 *
1634 * proc_handler - the text handler routine (described below)
1635 *
1636 * strategy - the strategy routine (described below)
1637 *
1638 * de - for internal use by the sysctl routines
1639 *
1640 * extra1, extra2 - extra pointers usable by the proc handler routines
1641 *
1642 * Leaf nodes in the sysctl tree will be represented by a single file
1643 * under /proc; non-leaf nodes will be represented by directories.
1644 *
1645 * sysctl(2) can automatically manage read and write requests through
1646 * the sysctl table. The data and maxlen fields of the ctl_table
1647 * struct enable minimal validation of the values being written to be
1648 * performed, and the mode field allows minimal authentication.
1649 *
1650 * More sophisticated management can be enabled by the provision of a
1651 * strategy routine with the table entry. This will be called before
1652 * any automatic read or write of the data is performed.
1653 *
1654 * The strategy routine may return
1655 *
1656 * < 0 - Error occurred (error is passed to user process)
1657 *
1658 * 0 - OK - proceed with automatic read or write.
1659 *
1660 * > 0 - OK - read or write has been done by the strategy routine, so
1661 * return immediately.
1662 *
1663 * There must be a proc_handler routine for any terminal nodes
1664 * mirrored under /proc/sys (non-terminals are handled by a built-in
1665 * directory handler). Several default handlers are available to
1666 * cover common cases -
1667 *
1668 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1669 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1670 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1671 *
1672 * It is the handler's job to read the input buffer from user memory
1673 * and process it. The handler should return 0 on success.
1674 *
1675 * This routine returns %NULL on a failure to register, and a pointer
1676 * to the table header on success.
1677 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001678struct ctl_table_header *__register_sysctl_paths(
1679 struct ctl_table_root *root,
1680 struct nsproxy *namespaces,
1681 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001683 struct list_head *header_list;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001684 struct ctl_table_header *header;
1685 struct ctl_table *new, **prevp;
1686 unsigned int n, npath;
1687
1688 /* Count the path components */
1689 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1690 ;
1691
1692 /*
1693 * For each path component, allocate a 2-element ctl_table array.
1694 * The first array element will be filled with the sysctl entry
1695 * for this, the second will be the sentinel (ctl_name == 0).
1696 *
1697 * We allocate everything in one go so that we don't have to
1698 * worry about freeing additional memory in unregister_sysctl_table.
1699 */
1700 header = kzalloc(sizeof(struct ctl_table_header) +
1701 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1702 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001704
1705 new = (struct ctl_table *) (header + 1);
1706
1707 /* Now connect the dots */
1708 prevp = &header->ctl_table;
1709 for (n = 0; n < npath; ++n, ++path) {
1710 /* Copy the procname */
1711 new->procname = path->procname;
1712 new->ctl_name = path->ctl_name;
1713 new->mode = 0555;
1714
1715 *prevp = new;
1716 prevp = &new->child;
1717
1718 new += 2;
1719 }
1720 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001721 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001722
1723 INIT_LIST_HEAD(&header->ctl_entry);
1724 header->used = 0;
1725 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001726 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001727 sysctl_set_parent(NULL, header->ctl_table);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001728 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001729 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001730 return NULL;
1731 }
Al Viro330d57f2005-11-04 10:18:40 +00001732 spin_lock(&sysctl_lock);
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001733 header_list = lookup_header_list(root, namespaces);
1734 list_add_tail(&header->ctl_entry, header_list);
Al Viro330d57f2005-11-04 10:18:40 +00001735 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001736
1737 return header;
1738}
1739
1740/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001741 * register_sysctl_table_path - register a sysctl table hierarchy
1742 * @path: The path to the directory the sysctl table is in.
1743 * @table: the top-level table structure
1744 *
1745 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1746 * array. A completely 0 filled entry terminates the table.
1747 *
1748 * See __register_sysctl_paths for more details.
1749 */
1750struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1751 struct ctl_table *table)
1752{
1753 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1754 path, table);
1755}
1756
1757/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001758 * register_sysctl_table - register a sysctl table hierarchy
1759 * @table: the top-level table structure
1760 *
1761 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1762 * array. A completely 0 filled entry terminates the table.
1763 *
1764 * See register_sysctl_paths for more details.
1765 */
1766struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1767{
1768 static const struct ctl_path null_path[] = { {} };
1769
1770 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771}
1772
1773/**
1774 * unregister_sysctl_table - unregister a sysctl table hierarchy
1775 * @header: the header returned from register_sysctl_table
1776 *
1777 * Unregisters the sysctl table and all children. proc entries may not
1778 * actually be removed until they are no longer used by anyone.
1779 */
1780void unregister_sysctl_table(struct ctl_table_header * header)
1781{
Al Viro330d57f2005-11-04 10:18:40 +00001782 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001783
1784 if (header == NULL)
1785 return;
1786
Al Viro330d57f2005-11-04 10:18:40 +00001787 spin_lock(&sysctl_lock);
1788 start_unregistering(header);
Al Viro330d57f2005-11-04 10:18:40 +00001789 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 kfree(header);
1791}
1792
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001793#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001794struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001795{
1796 return NULL;
1797}
1798
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001799struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1800 struct ctl_table *table)
1801{
1802 return NULL;
1803}
1804
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001805void unregister_sysctl_table(struct ctl_table_header * table)
1806{
1807}
1808
1809#endif /* CONFIG_SYSCTL */
1810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811/*
1812 * /proc/sys support
1813 */
1814
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001815#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001817static int _proc_do_string(void* data, int maxlen, int write,
1818 struct file *filp, void __user *buffer,
1819 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001820{
1821 size_t len;
1822 char __user *p;
1823 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001824
1825 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001826 *lenp = 0;
1827 return 0;
1828 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001829
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001830 if (write) {
1831 len = 0;
1832 p = buffer;
1833 while (len < *lenp) {
1834 if (get_user(c, p++))
1835 return -EFAULT;
1836 if (c == 0 || c == '\n')
1837 break;
1838 len++;
1839 }
1840 if (len >= maxlen)
1841 len = maxlen-1;
1842 if(copy_from_user(data, buffer, len))
1843 return -EFAULT;
1844 ((char *) data)[len] = 0;
1845 *ppos += *lenp;
1846 } else {
1847 len = strlen(data);
1848 if (len > maxlen)
1849 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001850
1851 if (*ppos > len) {
1852 *lenp = 0;
1853 return 0;
1854 }
1855
1856 data += *ppos;
1857 len -= *ppos;
1858
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001859 if (len > *lenp)
1860 len = *lenp;
1861 if (len)
1862 if(copy_to_user(buffer, data, len))
1863 return -EFAULT;
1864 if (len < *lenp) {
1865 if(put_user('\n', ((char __user *) buffer) + len))
1866 return -EFAULT;
1867 len++;
1868 }
1869 *lenp = len;
1870 *ppos += len;
1871 }
1872 return 0;
1873}
1874
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875/**
1876 * proc_dostring - read a string sysctl
1877 * @table: the sysctl table
1878 * @write: %TRUE if this is a write to the sysctl file
1879 * @filp: the file structure
1880 * @buffer: the user buffer
1881 * @lenp: the size of the user buffer
1882 * @ppos: file position
1883 *
1884 * Reads/writes a string from/to the user buffer. If the kernel
1885 * buffer provided is not large enough to hold the string, the
1886 * string is truncated. The copied string is %NULL-terminated.
1887 * If the string is being read by the user process, it is copied
1888 * and a newline '\n' is added. It is truncated if the buffer is
1889 * not large enough.
1890 *
1891 * Returns 0 on success.
1892 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001893int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 void __user *buffer, size_t *lenp, loff_t *ppos)
1895{
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001896 return _proc_do_string(table->data, table->maxlen, write, filp,
1897 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898}
1899
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
1901static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1902 int *valp,
1903 int write, void *data)
1904{
1905 if (write) {
1906 *valp = *negp ? -*lvalp : *lvalp;
1907 } else {
1908 int val = *valp;
1909 if (val < 0) {
1910 *negp = -1;
1911 *lvalp = (unsigned long)-val;
1912 } else {
1913 *negp = 0;
1914 *lvalp = (unsigned long)val;
1915 }
1916 }
1917 return 0;
1918}
1919
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001920static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001921 int write, struct file *filp, void __user *buffer,
1922 size_t *lenp, loff_t *ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1924 int write, void *data),
1925 void *data)
1926{
1927#define TMPBUFLEN 21
1928 int *i, vleft, first=1, neg, val;
1929 unsigned long lval;
1930 size_t left, len;
1931
1932 char buf[TMPBUFLEN], *p;
1933 char __user *s = buffer;
1934
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001935 if (!tbl_data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 (*ppos && !write)) {
1937 *lenp = 0;
1938 return 0;
1939 }
1940
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001941 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 vleft = table->maxlen / sizeof(*i);
1943 left = *lenp;
1944
1945 if (!conv)
1946 conv = do_proc_dointvec_conv;
1947
1948 for (; left && vleft--; i++, first=0) {
1949 if (write) {
1950 while (left) {
1951 char c;
1952 if (get_user(c, s))
1953 return -EFAULT;
1954 if (!isspace(c))
1955 break;
1956 left--;
1957 s++;
1958 }
1959 if (!left)
1960 break;
1961 neg = 0;
1962 len = left;
1963 if (len > sizeof(buf) - 1)
1964 len = sizeof(buf) - 1;
1965 if (copy_from_user(buf, s, len))
1966 return -EFAULT;
1967 buf[len] = 0;
1968 p = buf;
1969 if (*p == '-' && left > 1) {
1970 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08001971 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 }
1973 if (*p < '0' || *p > '9')
1974 break;
1975
1976 lval = simple_strtoul(p, &p, 0);
1977
1978 len = p-buf;
1979 if ((len < left) && *p && !isspace(*p))
1980 break;
1981 if (neg)
1982 val = -val;
1983 s += len;
1984 left -= len;
1985
1986 if (conv(&neg, &lval, i, 1, data))
1987 break;
1988 } else {
1989 p = buf;
1990 if (!first)
1991 *p++ = '\t';
1992
1993 if (conv(&neg, &lval, i, 0, data))
1994 break;
1995
1996 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1997 len = strlen(buf);
1998 if (len > left)
1999 len = left;
2000 if(copy_to_user(s, buf, len))
2001 return -EFAULT;
2002 left -= len;
2003 s += len;
2004 }
2005 }
2006
2007 if (!write && !first && left) {
2008 if(put_user('\n', s))
2009 return -EFAULT;
2010 left--, s++;
2011 }
2012 if (write) {
2013 while (left) {
2014 char c;
2015 if (get_user(c, s++))
2016 return -EFAULT;
2017 if (!isspace(c))
2018 break;
2019 left--;
2020 }
2021 }
2022 if (write && first)
2023 return -EINVAL;
2024 *lenp -= left;
2025 *ppos += *lenp;
2026 return 0;
2027#undef TMPBUFLEN
2028}
2029
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002030static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002031 void __user *buffer, size_t *lenp, loff_t *ppos,
2032 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2033 int write, void *data),
2034 void *data)
2035{
2036 return __do_proc_dointvec(table->data, table, write, filp,
2037 buffer, lenp, ppos, conv, data);
2038}
2039
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040/**
2041 * proc_dointvec - read a vector of integers
2042 * @table: the sysctl table
2043 * @write: %TRUE if this is a write to the sysctl file
2044 * @filp: the file structure
2045 * @buffer: the user buffer
2046 * @lenp: the size of the user buffer
2047 * @ppos: file position
2048 *
2049 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2050 * values from/to the user buffer, treated as an ASCII string.
2051 *
2052 * Returns 0 on success.
2053 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002054int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 void __user *buffer, size_t *lenp, loff_t *ppos)
2056{
2057 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2058 NULL,NULL);
2059}
2060
2061#define OP_SET 0
2062#define OP_AND 1
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002063#define OP_OR 2
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2066 int *valp,
2067 int write, void *data)
2068{
2069 int op = *(int *)data;
2070 if (write) {
2071 int val = *negp ? -*lvalp : *lvalp;
2072 switch(op) {
2073 case OP_SET: *valp = val; break;
2074 case OP_AND: *valp &= val; break;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002075 case OP_OR: *valp |= val; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 }
2077 } else {
2078 int val = *valp;
2079 if (val < 0) {
2080 *negp = -1;
2081 *lvalp = (unsigned long)-val;
2082 } else {
2083 *negp = 0;
2084 *lvalp = (unsigned long)val;
2085 }
2086 }
2087 return 0;
2088}
2089
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002090/*
2091 * Taint values can only be increased
2092 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002093static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002094 void __user *buffer, size_t *lenp, loff_t *ppos)
2095{
2096 int op;
2097
Bastian Blank91fcd412007-04-23 14:41:14 -07002098 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002099 return -EPERM;
2100
2101 op = OP_OR;
2102 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2103 do_proc_dointvec_bset_conv,&op);
2104}
2105
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106struct do_proc_dointvec_minmax_conv_param {
2107 int *min;
2108 int *max;
2109};
2110
2111static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2112 int *valp,
2113 int write, void *data)
2114{
2115 struct do_proc_dointvec_minmax_conv_param *param = data;
2116 if (write) {
2117 int val = *negp ? -*lvalp : *lvalp;
2118 if ((param->min && *param->min > val) ||
2119 (param->max && *param->max < val))
2120 return -EINVAL;
2121 *valp = val;
2122 } else {
2123 int val = *valp;
2124 if (val < 0) {
2125 *negp = -1;
2126 *lvalp = (unsigned long)-val;
2127 } else {
2128 *negp = 0;
2129 *lvalp = (unsigned long)val;
2130 }
2131 }
2132 return 0;
2133}
2134
2135/**
2136 * proc_dointvec_minmax - read a vector of integers with min/max values
2137 * @table: the sysctl table
2138 * @write: %TRUE if this is a write to the sysctl file
2139 * @filp: the file structure
2140 * @buffer: the user buffer
2141 * @lenp: the size of the user buffer
2142 * @ppos: file position
2143 *
2144 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2145 * values from/to the user buffer, treated as an ASCII string.
2146 *
2147 * This routine will ensure the values are within the range specified by
2148 * table->extra1 (min) and table->extra2 (max).
2149 *
2150 * Returns 0 on success.
2151 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002152int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 void __user *buffer, size_t *lenp, loff_t *ppos)
2154{
2155 struct do_proc_dointvec_minmax_conv_param param = {
2156 .min = (int *) table->extra1,
2157 .max = (int *) table->extra2,
2158 };
2159 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2160 do_proc_dointvec_minmax_conv, &param);
2161}
2162
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002163static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 struct file *filp,
2165 void __user *buffer,
2166 size_t *lenp, loff_t *ppos,
2167 unsigned long convmul,
2168 unsigned long convdiv)
2169{
2170#define TMPBUFLEN 21
2171 unsigned long *i, *min, *max, val;
2172 int vleft, first=1, neg;
2173 size_t len, left;
2174 char buf[TMPBUFLEN], *p;
2175 char __user *s = buffer;
2176
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002177 if (!data || !table->maxlen || !*lenp ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 (*ppos && !write)) {
2179 *lenp = 0;
2180 return 0;
2181 }
2182
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002183 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 min = (unsigned long *) table->extra1;
2185 max = (unsigned long *) table->extra2;
2186 vleft = table->maxlen / sizeof(unsigned long);
2187 left = *lenp;
2188
2189 for (; left && vleft--; i++, min++, max++, first=0) {
2190 if (write) {
2191 while (left) {
2192 char c;
2193 if (get_user(c, s))
2194 return -EFAULT;
2195 if (!isspace(c))
2196 break;
2197 left--;
2198 s++;
2199 }
2200 if (!left)
2201 break;
2202 neg = 0;
2203 len = left;
2204 if (len > TMPBUFLEN-1)
2205 len = TMPBUFLEN-1;
2206 if (copy_from_user(buf, s, len))
2207 return -EFAULT;
2208 buf[len] = 0;
2209 p = buf;
2210 if (*p == '-' && left > 1) {
2211 neg = 1;
BP, Praveenbd9b0ba2006-12-06 20:39:09 -08002212 p++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 }
2214 if (*p < '0' || *p > '9')
2215 break;
2216 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2217 len = p-buf;
2218 if ((len < left) && *p && !isspace(*p))
2219 break;
2220 if (neg)
2221 val = -val;
2222 s += len;
2223 left -= len;
2224
2225 if(neg)
2226 continue;
2227 if ((min && val < *min) || (max && val > *max))
2228 continue;
2229 *i = val;
2230 } else {
2231 p = buf;
2232 if (!first)
2233 *p++ = '\t';
2234 sprintf(p, "%lu", convdiv * (*i) / convmul);
2235 len = strlen(buf);
2236 if (len > left)
2237 len = left;
2238 if(copy_to_user(s, buf, len))
2239 return -EFAULT;
2240 left -= len;
2241 s += len;
2242 }
2243 }
2244
2245 if (!write && !first && left) {
2246 if(put_user('\n', s))
2247 return -EFAULT;
2248 left--, s++;
2249 }
2250 if (write) {
2251 while (left) {
2252 char c;
2253 if (get_user(c, s++))
2254 return -EFAULT;
2255 if (!isspace(c))
2256 break;
2257 left--;
2258 }
2259 }
2260 if (write && first)
2261 return -EINVAL;
2262 *lenp -= left;
2263 *ppos += *lenp;
2264 return 0;
2265#undef TMPBUFLEN
2266}
2267
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002268static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002269 struct file *filp,
2270 void __user *buffer,
2271 size_t *lenp, loff_t *ppos,
2272 unsigned long convmul,
2273 unsigned long convdiv)
2274{
2275 return __do_proc_doulongvec_minmax(table->data, table, write,
2276 filp, buffer, lenp, ppos, convmul, convdiv);
2277}
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279/**
2280 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2281 * @table: the sysctl table
2282 * @write: %TRUE if this is a write to the sysctl file
2283 * @filp: the file structure
2284 * @buffer: the user buffer
2285 * @lenp: the size of the user buffer
2286 * @ppos: file position
2287 *
2288 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2289 * values from/to the user buffer, treated as an ASCII string.
2290 *
2291 * This routine will ensure the values are within the range specified by
2292 * table->extra1 (min) and table->extra2 (max).
2293 *
2294 * Returns 0 on success.
2295 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002296int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 void __user *buffer, size_t *lenp, loff_t *ppos)
2298{
2299 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2300}
2301
2302/**
2303 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2304 * @table: the sysctl table
2305 * @write: %TRUE if this is a write to the sysctl file
2306 * @filp: the file structure
2307 * @buffer: the user buffer
2308 * @lenp: the size of the user buffer
2309 * @ppos: file position
2310 *
2311 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2312 * values from/to the user buffer, treated as an ASCII string. The values
2313 * are treated as milliseconds, and converted to jiffies when they are stored.
2314 *
2315 * This routine will ensure the values are within the range specified by
2316 * table->extra1 (min) and table->extra2 (max).
2317 *
2318 * Returns 0 on success.
2319 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002320int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 struct file *filp,
2322 void __user *buffer,
2323 size_t *lenp, loff_t *ppos)
2324{
2325 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2326 lenp, ppos, HZ, 1000l);
2327}
2328
2329
2330static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2331 int *valp,
2332 int write, void *data)
2333{
2334 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002335 if (*lvalp > LONG_MAX / HZ)
2336 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2338 } else {
2339 int val = *valp;
2340 unsigned long lval;
2341 if (val < 0) {
2342 *negp = -1;
2343 lval = (unsigned long)-val;
2344 } else {
2345 *negp = 0;
2346 lval = (unsigned long)val;
2347 }
2348 *lvalp = lval / HZ;
2349 }
2350 return 0;
2351}
2352
2353static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2354 int *valp,
2355 int write, void *data)
2356{
2357 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002358 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2359 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2361 } else {
2362 int val = *valp;
2363 unsigned long lval;
2364 if (val < 0) {
2365 *negp = -1;
2366 lval = (unsigned long)-val;
2367 } else {
2368 *negp = 0;
2369 lval = (unsigned long)val;
2370 }
2371 *lvalp = jiffies_to_clock_t(lval);
2372 }
2373 return 0;
2374}
2375
2376static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2377 int *valp,
2378 int write, void *data)
2379{
2380 if (write) {
2381 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2382 } else {
2383 int val = *valp;
2384 unsigned long lval;
2385 if (val < 0) {
2386 *negp = -1;
2387 lval = (unsigned long)-val;
2388 } else {
2389 *negp = 0;
2390 lval = (unsigned long)val;
2391 }
2392 *lvalp = jiffies_to_msecs(lval);
2393 }
2394 return 0;
2395}
2396
2397/**
2398 * proc_dointvec_jiffies - read a vector of integers as seconds
2399 * @table: the sysctl table
2400 * @write: %TRUE if this is a write to the sysctl file
2401 * @filp: the file structure
2402 * @buffer: the user buffer
2403 * @lenp: the size of the user buffer
2404 * @ppos: file position
2405 *
2406 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2407 * values from/to the user buffer, treated as an ASCII string.
2408 * The values read are assumed to be in seconds, and are converted into
2409 * jiffies.
2410 *
2411 * Returns 0 on success.
2412 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002413int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 void __user *buffer, size_t *lenp, loff_t *ppos)
2415{
2416 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2417 do_proc_dointvec_jiffies_conv,NULL);
2418}
2419
2420/**
2421 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2422 * @table: the sysctl table
2423 * @write: %TRUE if this is a write to the sysctl file
2424 * @filp: the file structure
2425 * @buffer: the user buffer
2426 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002427 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 *
2429 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2430 * values from/to the user buffer, treated as an ASCII string.
2431 * The values read are assumed to be in 1/USER_HZ seconds, and
2432 * are converted into jiffies.
2433 *
2434 * Returns 0 on success.
2435 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002436int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 void __user *buffer, size_t *lenp, loff_t *ppos)
2438{
2439 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2440 do_proc_dointvec_userhz_jiffies_conv,NULL);
2441}
2442
2443/**
2444 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2445 * @table: the sysctl table
2446 * @write: %TRUE if this is a write to the sysctl file
2447 * @filp: the file structure
2448 * @buffer: the user buffer
2449 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002450 * @ppos: file position
2451 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 *
2453 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2454 * values from/to the user buffer, treated as an ASCII string.
2455 * The values read are assumed to be in 1/1000 seconds, and
2456 * are converted into jiffies.
2457 *
2458 * Returns 0 on success.
2459 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002460int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 void __user *buffer, size_t *lenp, loff_t *ppos)
2462{
2463 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2464 do_proc_dointvec_ms_jiffies_conv, NULL);
2465}
2466
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002467static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002468 void __user *buffer, size_t *lenp, loff_t *ppos)
2469{
2470 struct pid *new_pid;
2471 pid_t tmp;
2472 int r;
2473
Pavel Emelyanovb4888932007-10-18 23:40:14 -07002474 tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002475
2476 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2477 lenp, ppos, NULL, NULL);
2478 if (r || !write)
2479 return r;
2480
2481 new_pid = find_get_pid(tmp);
2482 if (!new_pid)
2483 return -ESRCH;
2484
2485 put_pid(xchg(&cad_pid, new_pid));
2486 return 0;
2487}
2488
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489#else /* CONFIG_PROC_FS */
2490
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002491int proc_dostring(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 void __user *buffer, size_t *lenp, loff_t *ppos)
2493{
2494 return -ENOSYS;
2495}
2496
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002497int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 void __user *buffer, size_t *lenp, loff_t *ppos)
2499{
2500 return -ENOSYS;
2501}
2502
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002503int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 void __user *buffer, size_t *lenp, loff_t *ppos)
2505{
2506 return -ENOSYS;
2507}
2508
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002509int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 void __user *buffer, size_t *lenp, loff_t *ppos)
2511{
2512 return -ENOSYS;
2513}
2514
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002515int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 void __user *buffer, size_t *lenp, loff_t *ppos)
2517{
2518 return -ENOSYS;
2519}
2520
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002521int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 void __user *buffer, size_t *lenp, loff_t *ppos)
2523{
2524 return -ENOSYS;
2525}
2526
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002527int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 void __user *buffer, size_t *lenp, loff_t *ppos)
2529{
2530 return -ENOSYS;
2531}
2532
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002533int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 struct file *filp,
2535 void __user *buffer,
2536 size_t *lenp, loff_t *ppos)
2537{
2538 return -ENOSYS;
2539}
2540
2541
2542#endif /* CONFIG_PROC_FS */
2543
2544
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002545#ifdef CONFIG_SYSCTL_SYSCALL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546/*
2547 * General sysctl support routines
2548 */
2549
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002550/* The generic sysctl data routine (used if no strategy routine supplied) */
2551int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2552 void __user *oldval, size_t __user *oldlenp,
2553 void __user *newval, size_t newlen)
2554{
2555 size_t len;
2556
2557 /* Get out of I don't have a variable */
2558 if (!table->data || !table->maxlen)
2559 return -ENOTDIR;
2560
2561 if (oldval && oldlenp) {
2562 if (get_user(len, oldlenp))
2563 return -EFAULT;
2564 if (len) {
2565 if (len > table->maxlen)
2566 len = table->maxlen;
2567 if (copy_to_user(oldval, table->data, len))
2568 return -EFAULT;
2569 if (put_user(len, oldlenp))
2570 return -EFAULT;
2571 }
2572 }
2573
2574 if (newval && newlen) {
2575 if (newlen > table->maxlen)
2576 newlen = table->maxlen;
2577
2578 if (copy_from_user(table->data, newval, newlen))
2579 return -EFAULT;
2580 }
2581 return 1;
2582}
2583
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584/* The generic string strategy routine: */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002585int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002587 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 if (!table->data || !table->maxlen)
2590 return -ENOTDIR;
2591
2592 if (oldval && oldlenp) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002593 size_t bufsize;
2594 if (get_user(bufsize, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002596 if (bufsize) {
2597 size_t len = strlen(table->data), copied;
2598
2599 /* This shouldn't trigger for a well-formed sysctl */
2600 if (len > table->maxlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 len = table->maxlen;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002602
2603 /* Copy up to a max of bufsize-1 bytes of the string */
2604 copied = (len >= bufsize) ? bufsize - 1 : len;
2605
2606 if (copy_to_user(oldval, table->data, copied) ||
2607 put_user(0, (char __user *)(oldval + copied)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 return -EFAULT;
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002609 if (put_user(len, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 return -EFAULT;
2611 }
2612 }
2613 if (newval && newlen) {
Linus Torvaldsde9e0072005-12-31 17:00:29 -08002614 size_t len = newlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 if (len > table->maxlen)
2616 len = table->maxlen;
2617 if(copy_from_user(table->data, newval, len))
2618 return -EFAULT;
2619 if (len == table->maxlen)
2620 len--;
2621 ((char *) table->data)[len] = 0;
2622 }
Yi Yang82c9df82005-12-30 16:37:10 +08002623 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624}
2625
2626/*
2627 * This function makes sure that all of the integers in the vector
2628 * are between the minimum and maximum values given in the arrays
2629 * table->extra1 and table->extra2, respectively.
2630 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002631int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002633 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634{
2635
2636 if (newval && newlen) {
2637 int __user *vec = (int __user *) newval;
2638 int *min = (int *) table->extra1;
2639 int *max = (int *) table->extra2;
2640 size_t length;
2641 int i;
2642
2643 if (newlen % sizeof(int) != 0)
2644 return -EINVAL;
2645
2646 if (!table->extra1 && !table->extra2)
2647 return 0;
2648
2649 if (newlen > table->maxlen)
2650 newlen = table->maxlen;
2651 length = newlen / sizeof(int);
2652
2653 for (i = 0; i < length; i++) {
2654 int value;
2655 if (get_user(value, vec + i))
2656 return -EFAULT;
2657 if (min && value < min[i])
2658 return -EINVAL;
2659 if (max && value > max[i])
2660 return -EINVAL;
2661 }
2662 }
2663 return 0;
2664}
2665
2666/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002667int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002669 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002671 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002673
2674 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002676 if (olen) {
2677 int val;
2678
2679 if (olen < sizeof(int))
2680 return -EINVAL;
2681
2682 val = *(int *)(table->data) / HZ;
2683 if (put_user(val, (int __user *)oldval))
2684 return -EFAULT;
2685 if (put_user(sizeof(int), oldlenp))
2686 return -EFAULT;
2687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 }
2689 if (newval && newlen) {
2690 int new;
2691 if (newlen != sizeof(int))
2692 return -EINVAL;
2693 if (get_user(new, (int __user *)newval))
2694 return -EFAULT;
2695 *(int *)(table->data) = new*HZ;
2696 }
2697 return 1;
2698}
2699
2700/* Strategy function to convert jiffies to seconds */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002701int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002703 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704{
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002705 if (oldval && oldlenp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 size_t olen;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002707
2708 if (get_user(olen, oldlenp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 return -EFAULT;
Alexey Dobriyan3ee75ac2007-02-10 01:44:39 -08002710 if (olen) {
2711 int val;
2712
2713 if (olen < sizeof(int))
2714 return -EINVAL;
2715
2716 val = jiffies_to_msecs(*(int *)(table->data));
2717 if (put_user(val, (int __user *)oldval))
2718 return -EFAULT;
2719 if (put_user(sizeof(int), oldlenp))
2720 return -EFAULT;
2721 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 }
2723 if (newval && newlen) {
2724 int new;
2725 if (newlen != sizeof(int))
2726 return -EINVAL;
2727 if (get_user(new, (int __user *)newval))
2728 return -EFAULT;
2729 *(int *)(table->data) = msecs_to_jiffies(new);
2730 }
2731 return 1;
2732}
2733
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002734
Eric W. Biedermanc4b8b762006-12-08 02:39:55 -08002735
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002736#else /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
2738
2739asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2740{
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002741 struct __sysctl_args tmp;
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002742 int error;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002743
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002744 if (copy_from_user(&tmp, args, sizeof(tmp)))
2745 return -EFAULT;
Eric W. Biederman0e009be2006-11-05 23:52:11 -08002746
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002747 error = deprecated_sysctl_warning(&tmp);
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002748
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002749 /* If no error reading the parameters then just -ENOSYS ... */
2750 if (!error)
2751 error = -ENOSYS;
2752
2753 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754}
2755
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002756int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2757 void __user *oldval, size_t __user *oldlenp,
2758 void __user *newval, size_t newlen)
2759{
2760 return -ENOSYS;
2761}
2762
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002763int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002765 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766{
2767 return -ENOSYS;
2768}
2769
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002770int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002772 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773{
2774 return -ENOSYS;
2775}
2776
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002777int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002779 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780{
2781 return -ENOSYS;
2782}
2783
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002784int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -08002786 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787{
2788 return -ENOSYS;
2789}
2790
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002791#endif /* CONFIG_SYSCTL_SYSCALL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002793static int deprecated_sysctl_warning(struct __sysctl_args *args)
2794{
2795 static int msg_count;
2796 int name[CTL_MAXNAME];
2797 int i;
2798
Tetsuo Handa6fc48af2007-11-14 16:58:38 -08002799 /* Check args->nlen. */
2800 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2801 return -ENOTDIR;
2802
Eric W. Biederman7058cb02007-10-18 03:05:58 -07002803 /* Read in the sysctl name for better debug message logging */
2804 for (i = 0; i < args->nlen; i++)
2805 if (get_user(name[i], args->name + i))
2806 return -EFAULT;
2807
2808 /* Ignore accesses to kernel.version */
2809 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2810 return 0;
2811
2812 if (msg_count < 5) {
2813 msg_count++;
2814 printk(KERN_INFO
2815 "warning: process `%s' used the deprecated sysctl "
2816 "system call with ", current->comm);
2817 for (i = 0; i < args->nlen; i++)
2818 printk("%d.", name[i]);
2819 printk("\n");
2820 }
2821 return 0;
2822}
2823
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824/*
2825 * No sense putting this after each symbol definition, twice,
2826 * exception granted :-)
2827 */
2828EXPORT_SYMBOL(proc_dointvec);
2829EXPORT_SYMBOL(proc_dointvec_jiffies);
2830EXPORT_SYMBOL(proc_dointvec_minmax);
2831EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2832EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2833EXPORT_SYMBOL(proc_dostring);
2834EXPORT_SYMBOL(proc_doulongvec_minmax);
2835EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2836EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002837EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838EXPORT_SYMBOL(sysctl_intvec);
2839EXPORT_SYMBOL(sysctl_jiffies);
2840EXPORT_SYMBOL(sysctl_ms_jiffies);
2841EXPORT_SYMBOL(sysctl_string);
Eric W. Biederman49a0c452007-10-18 03:05:23 -07002842EXPORT_SYMBOL(sysctl_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843EXPORT_SYMBOL(unregister_sysctl_table);