blob: 4c93486b45d1285dc82d65b027cf308dd14c87ff [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>
Dave Youngd33ed522010-03-10 15:23:59 -080026#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070028#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020030#include <linux/kmemcheck.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>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020039#include <linux/ratelimit.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070042#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/times.h>
44#include <linux/limits.h>
45#include <linux/dcache.h>
46#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070047#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080048#include <linux/nfs_fs.h>
49#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070050#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020051#include <linux/ftrace.h>
David Howells12e22c52009-04-03 16:42:35 +010052#include <linux/slow-work.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020053#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050054#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020055#include <linux/pipe_fs_i.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#include <asm/uaccess.h>
58#include <asm/processor.h>
59
Andi Kleen29cbc782006-09-30 01:47:55 +020060#ifdef CONFIG_X86
61#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010062#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010063#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020064#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080065#ifdef CONFIG_BSD_PROCESS_ACCT
66#include <linux/acct.h>
67#endif
Dave Young4f0e0562010-03-10 15:24:09 -080068#ifdef CONFIG_RT_MUTEXES
69#include <linux/rtmutex.h>
70#endif
Dave Young2edf5e42010-03-10 15:24:10 -080071#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
72#include <linux/lockdep.h>
73#endif
Dave Young15485a42010-03-10 15:24:07 -080074#ifdef CONFIG_CHR_DEV_SG
75#include <scsi/sg.h>
76#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020077
Eric W. Biederman7058cb02007-10-18 03:05:58 -070078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#if defined(CONFIG_SYSCTL)
80
81/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern int sysctl_overcommit_memory;
83extern int sysctl_overcommit_ratio;
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -070084extern int sysctl_panic_on_oom;
David Rientjesfe071d72007-10-16 23:25:56 -070085extern int sysctl_oom_kill_allocating_task;
David Rientjesfef1bdd2008-02-07 00:14:07 -080086extern int sysctl_oom_dump_tasks;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087extern int max_threads;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088extern int core_uses_pid;
Alan Coxd6e71142005-06-23 00:09:43 -070089extern int suid_dumpable;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -070091extern unsigned int core_pipe_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092extern int pid_max;
93extern int min_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern int pid_max_min, pid_max_max;
Andrew Morton9d0243b2006-01-08 01:00:39 -080095extern int sysctl_drop_caches;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -080096extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +020097extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +010098extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -040099extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000100#ifndef CONFIG_MMU
101extern int sysctl_nr_trim_pages;
102#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200103#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200104extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700107/* Constants used for minimum and maximum */
Bron Gondwana195cf4532008-02-04 22:29:20 -0800108#ifdef CONFIG_DETECT_SOFTLOCKUP
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700109static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200110static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111#endif
112
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700114static int __maybe_unused one = 1;
115static int __maybe_unused two = 2;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800116static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700118#ifdef CONFIG_PRINTK
119static int ten_thousand = 10000;
120#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700121
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700122/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
123static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
126static int maxolduid = 65535;
127static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800128static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130static int ngroups_max = NGROUPS_MAX;
131
David S. Miller72c57ed2008-09-11 23:29:54 -0700132#ifdef CONFIG_SPARC
David S. Miller17f04fb2008-09-11 23:33:53 -0700133#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#endif
135
David S. Miller08714202008-11-16 23:49:24 -0800136#ifdef CONFIG_SPARC64
137extern int sysctl_tsb_ratio;
138#endif
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#ifdef __hppa__
141extern int pwrsw_enabled;
142extern int unaligned_enabled;
143#endif
144
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800145#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef CONFIG_MATHEMU
147extern int sysctl_ieee_emulation_warnings;
148#endif
149extern int sysctl_userprocess_debug;
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700150extern int spin_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif
152
Jes Sorensend2b176e2006-02-28 09:42:23 -0800153#ifdef CONFIG_IA64
154extern int no_unaligned_warning;
Doug Chapman88fc2412009-01-15 10:38:56 -0800155extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800156#endif
157
Ingo Molnar3fff4c42009-09-22 16:18:09 +0200158extern struct ratelimit_state printk_ratelimit_state;
159
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700160#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700161static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700162 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700163static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800164 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700165#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700166
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700167#ifdef CONFIG_MAGIC_SYSRQ
168static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
169
170static int sysrq_sysctl_handler(ctl_table *table, int write,
171 void __user *buffer, size_t *lenp,
172 loff_t *ppos)
173{
174 int error;
175
176 error = proc_dointvec(table, write, buffer, lenp, ppos);
177 if (error)
178 return error;
179
180 if (write)
181 sysrq_toggle_support(__sysrq_enabled);
182
183 return 0;
184}
185
186#endif
187
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700188static struct ctl_table root_table[];
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100189static struct ctl_table_root sysctl_table_root;
190static struct ctl_table_header root_table_header = {
Al Virob380b0d2008-09-04 17:05:57 +0100191 .count = 1,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100192 .ctl_table = root_table,
Al Viro73455092008-07-14 21:22:20 -0400193 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100194 .root = &sysctl_table_root,
Al Viro73455092008-07-14 21:22:20 -0400195 .set = &sysctl_table_root.default_set,
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100196};
197static struct ctl_table_root sysctl_table_root = {
198 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
Al Viro73455092008-07-14 21:22:20 -0400199 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +1100200};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700202static struct ctl_table kern_table[];
203static struct ctl_table vm_table[];
204static struct ctl_table fs_table[];
205static struct ctl_table debug_table[];
206static struct ctl_table dev_table[];
207extern struct ctl_table random_table[];
Amy Griffis2d9048e2006-06-01 13:10:59 -0700208#ifdef CONFIG_INOTIFY_USER
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700209extern struct ctl_table inotify_table[];
Robert Love0399cb02005-07-13 12:38:18 -0400210#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -0800211#ifdef CONFIG_EPOLL
212extern struct ctl_table epoll_table[];
213#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
216int sysctl_legacy_va_layout;
217#endif
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219/* The default sysctl tables: */
220
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700221static struct ctl_table root_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 .procname = "kernel",
224 .mode = 0555,
225 .child = kern_table,
226 },
227 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 .procname = "vm",
229 .mode = 0555,
230 .child = vm_table,
231 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 .procname = "fs",
234 .mode = 0555,
235 .child = fs_table,
236 },
237 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 .procname = "debug",
239 .mode = 0555,
240 .child = debug_table,
241 },
242 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 .procname = "dev",
244 .mode = 0555,
245 .child = dev_table,
246 },
Andrew Morton2be7fe02007-07-15 23:41:21 -0700247/*
248 * NOTE: do not add new entries to this table unless you have read
249 * Documentation/sysctl/ctl_unnumbered.txt
250 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700251 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252};
253
Ingo Molnar77e54a12007-07-09 18:52:00 +0200254#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100255static int min_sched_granularity_ns = 100000; /* 100 usecs */
256static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
257static int min_wakeup_granularity_ns; /* 0 usecs */
258static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100259static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
260static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100261static int min_sched_shares_ratelimit = 100000; /* 100 usec */
262static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200263#endif
264
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700265static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200266 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200267 .procname = "sched_child_runs_first",
268 .data = &sysctl_sched_child_runs_first,
269 .maxlen = sizeof(unsigned int),
270 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800271 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200272 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200273#ifdef CONFIG_SCHED_DEBUG
274 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100275 .procname = "sched_min_granularity_ns",
276 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800279 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100280 .extra1 = &min_sched_granularity_ns,
281 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200282 },
283 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200284 .procname = "sched_latency_ns",
285 .data = &sysctl_sched_latency,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800288 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
291 },
292 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200293 .procname = "sched_wakeup_granularity_ns",
294 .data = &sysctl_sched_wakeup_granularity,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800297 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200298 .extra1 = &min_wakeup_granularity_ns,
299 .extra2 = &max_wakeup_granularity_ns,
300 },
301 {
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200302 .procname = "sched_shares_ratelimit",
303 .data = &sysctl_sched_shares_ratelimit,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800306 .proc_handler = sched_proc_update_handler,
Christian Ehrhardtacb4a842009-11-30 12:16:48 +0100307 .extra1 = &min_sched_shares_ratelimit,
308 .extra2 = &max_sched_shares_ratelimit,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200309 },
310 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100311 .procname = "sched_tunable_scaling",
312 .data = &sysctl_sched_tunable_scaling,
313 .maxlen = sizeof(enum sched_tunable_scaling),
314 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800315 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100316 .extra1 = &min_sched_tunable_scaling,
317 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200318 },
319 {
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200320 .procname = "sched_shares_thresh",
321 .data = &sysctl_sched_shares_thresh,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800324 .proc_handler = proc_dointvec_minmax,
Peter Zijlstraffda12a2008-10-17 19:27:02 +0200325 .extra1 = &zero,
326 },
327 {
Ingo Molnarda84d962007-10-15 17:00:18 +0200328 .procname = "sched_migration_cost",
329 .data = &sysctl_sched_migration_cost,
330 .maxlen = sizeof(unsigned int),
331 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800332 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200333 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100334 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100335 .procname = "sched_nr_migrate",
336 .data = &sysctl_sched_nr_migrate,
337 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100338 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800339 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100340 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530341 {
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200342 .procname = "sched_time_avg",
343 .data = &sysctl_sched_time_avg,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800346 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200347 },
348 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530349 .procname = "timer_migration",
350 .data = &sysctl_timer_migration,
351 .maxlen = sizeof(unsigned int),
352 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800353 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530354 .extra1 = &zero,
355 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530356 },
Peter Zijlstra1fc84aa2007-08-25 18:41:52 +0200357#endif
Ingo Molnar1799e352007-09-19 23:34:46 +0200358 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100359 .procname = "sched_rt_period_us",
360 .data = &sysctl_sched_rt_period,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800363 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100364 },
365 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100366 .procname = "sched_rt_runtime_us",
367 .data = &sysctl_sched_rt_runtime,
368 .maxlen = sizeof(int),
369 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800370 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100371 },
372 {
Ingo Molnar1799e352007-09-19 23:34:46 +0200373 .procname = "sched_compat_yield",
374 .data = &sysctl_sched_compat_yield,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800377 .proc_handler = proc_dointvec,
Ingo Molnar1799e352007-09-19 23:34:46 +0200378 },
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700379#ifdef CONFIG_PROVE_LOCKING
380 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700381 .procname = "prove_locking",
382 .data = &prove_locking,
383 .maxlen = sizeof(int),
384 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800385 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700386 },
387#endif
388#ifdef CONFIG_LOCK_STAT
389 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700390 .procname = "lock_stat",
391 .data = &lock_stat,
392 .maxlen = sizeof(int),
393 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800394 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700395 },
396#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 .procname = "panic",
399 .data = &panic_timeout,
400 .maxlen = sizeof(int),
401 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800402 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 },
404 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 .procname = "core_uses_pid",
406 .data = &core_uses_pid,
407 .maxlen = sizeof(int),
408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800409 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 },
411 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 .procname = "core_pattern",
413 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700414 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800416 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 },
Neil Hormana2939802009-09-23 15:56:56 -0700418 {
Neil Hormana2939802009-09-23 15:56:56 -0700419 .procname = "core_pipe_limit",
420 .data = &core_pipe_limit,
421 .maxlen = sizeof(unsigned int),
422 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800423 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700424 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800425#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700428 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800430 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800432#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100433#ifdef CONFIG_LATENCYTOP
434 {
435 .procname = "latencytop",
436 .data = &latencytop_enabled,
437 .maxlen = sizeof(int),
438 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800439 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100440 },
441#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442#ifdef CONFIG_BLK_DEV_INITRD
443 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 .procname = "real-root-dev",
445 .data = &real_root_dev,
446 .maxlen = sizeof(int),
447 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800448 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 },
450#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700451 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700452 .procname = "print-fatal-signals",
453 .data = &print_fatal_signals,
454 .maxlen = sizeof(int),
455 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800456 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700457 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700458#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .procname = "reboot-cmd",
461 .data = reboot_command,
462 .maxlen = 256,
463 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800464 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 },
466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 .procname = "stop-a",
468 .data = &stop_a_enabled,
469 .maxlen = sizeof (int),
470 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800471 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 },
473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "scons-poweroff",
475 .data = &scons_pwroff,
476 .maxlen = sizeof (int),
477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800478 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
480#endif
David S. Miller08714202008-11-16 23:49:24 -0800481#ifdef CONFIG_SPARC64
482 {
David S. Miller08714202008-11-16 23:49:24 -0800483 .procname = "tsb-ratio",
484 .data = &sysctl_tsb_ratio,
485 .maxlen = sizeof (int),
486 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800487 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800488 },
489#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490#ifdef __hppa__
491 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 .procname = "soft-power",
493 .data = &pwrsw_enabled,
494 .maxlen = sizeof (int),
495 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800496 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 },
498 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 .procname = "unaligned-trap",
500 .data = &unaligned_enabled,
501 .maxlen = sizeof (int),
502 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800503 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 },
505#endif
506 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .procname = "ctrl-alt-del",
508 .data = &C_A_D,
509 .maxlen = sizeof(int),
510 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800511 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400513#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200514 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200515 .procname = "ftrace_enabled",
516 .data = &ftrace_enabled,
517 .maxlen = sizeof(int),
518 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800519 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200520 },
521#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500522#ifdef CONFIG_STACK_TRACER
523 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500524 .procname = "stack_tracer_enabled",
525 .data = &stack_tracer_enabled,
526 .maxlen = sizeof(int),
527 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800528 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500529 },
530#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400531#ifdef CONFIG_TRACING
532 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100533 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400534 .data = &ftrace_dump_on_oops,
535 .maxlen = sizeof(int),
536 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800537 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400538 },
539#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200540#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 .procname = "modprobe",
543 .data = &modprobe_path,
544 .maxlen = KMOD_PATH_LEN,
545 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800546 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 },
Kees Cook3d433212009-04-02 15:49:29 -0700548 {
Kees Cook3d433212009-04-02 15:49:29 -0700549 .procname = "modules_disabled",
550 .data = &modules_disabled,
551 .maxlen = sizeof(int),
552 .mode = 0644,
553 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800554 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700555 .extra1 = &one,
556 .extra2 = &one,
557 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#endif
Andrew Morton57ae2502006-06-23 02:05:47 -0700559#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100562 .data = &uevent_helper,
563 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800565 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 },
567#endif
568#ifdef CONFIG_CHR_DEV_SG
569 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .procname = "sg-big-buff",
571 .data = &sg_big_buff,
572 .maxlen = sizeof (int),
573 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800574 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 },
576#endif
577#ifdef CONFIG_BSD_PROCESS_ACCT
578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "acct",
580 .data = &acct_parm,
581 .maxlen = 3*sizeof(int),
582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800583 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#ifdef CONFIG_MAGIC_SYSRQ
587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800589 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 .maxlen = sizeof (int),
591 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700592 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 },
594#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700595#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700598 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .maxlen = sizeof (int),
600 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800601 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700603#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 .procname = "threads-max",
606 .data = &max_threads,
607 .maxlen = sizeof(int),
608 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800609 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 },
611 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 .procname = "random",
613 .mode = 0555,
614 .child = random_table,
615 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 .procname = "overflowuid",
618 .data = &overflowuid,
619 .maxlen = sizeof(int),
620 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800621 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
624 },
625 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 .procname = "overflowgid",
627 .data = &overflowgid,
628 .maxlen = sizeof(int),
629 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800630 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .extra1 = &minolduid,
632 .extra2 = &maxolduid,
633 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800634#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#ifdef CONFIG_MATHEMU
636 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 .procname = "ieee_emulation_warnings",
638 .data = &sysctl_ieee_emulation_warnings,
639 .maxlen = sizeof(int),
640 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800641 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 },
643#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200646 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 .maxlen = sizeof(int),
648 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800649 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 },
651#endif
652 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 .procname = "pid_max",
654 .data = &pid_max,
655 .maxlen = sizeof (int),
656 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800657 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .extra1 = &pid_max_min,
659 .extra2 = &pid_max_max,
660 },
661 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 .procname = "panic_on_oops",
663 .data = &panic_on_oops,
664 .maxlen = sizeof(int),
665 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800666 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800668#if defined CONFIG_PRINTK
669 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800670 .procname = "printk",
671 .data = &console_loglevel,
672 .maxlen = 4*sizeof(int),
673 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800674 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800675 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700678 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 .maxlen = sizeof(int),
680 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800681 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 },
683 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700685 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .maxlen = sizeof(int),
687 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800688 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 },
Dave Youngaf913222009-09-22 16:43:33 -0700690 {
Dave Youngaf913222009-09-22 16:43:33 -0700691 .procname = "printk_delay",
692 .data = &printk_delay_msec,
693 .maxlen = sizeof(int),
694 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800695 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700696 .extra1 = &zero,
697 .extra2 = &ten_thousand,
698 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800699#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 .procname = "ngroups_max",
702 .data = &ngroups_max,
703 .maxlen = sizeof (int),
704 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800705 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 },
707#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
708 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 .procname = "unknown_nmi_panic",
710 .data = &unknown_nmi_panic,
711 .maxlen = sizeof (int),
712 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800713 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 },
Don Zickus407984f2006-09-26 10:52:27 +0200715 {
Don Zickus407984f2006-09-26 10:52:27 +0200716 .procname = "nmi_watchdog",
717 .data = &nmi_watchdog_enabled,
718 .maxlen = sizeof (int),
719 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800720 .proc_handler = proc_nmi_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 },
722#endif
723#if defined(CONFIG_X86)
724 {
Don Zickus8da5add2006-09-26 10:52:27 +0200725 .procname = "panic_on_unrecovered_nmi",
726 .data = &panic_on_unrecovered_nmi,
727 .maxlen = sizeof(int),
728 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800729 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200730 },
731 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700732 .procname = "panic_on_io_nmi",
733 .data = &panic_on_io_nmi,
734 .maxlen = sizeof(int),
735 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800736 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700737 },
738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .procname = "bootloader_type",
740 .data = &bootloader_type,
741 .maxlen = sizeof (int),
742 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800743 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100745 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700746 .procname = "bootloader_version",
747 .data = &bootloader_version,
748 .maxlen = sizeof (int),
749 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800750 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700751 },
752 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100753 .procname = "kstack_depth_to_print",
754 .data = &kstack_depth_to_print,
755 .maxlen = sizeof(int),
756 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800757 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100758 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100759 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100760 .procname = "io_delay_type",
761 .data = &io_delay_type,
762 .maxlen = sizeof(int),
763 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800764 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100765 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800767#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .procname = "randomize_va_space",
770 .data = &randomize_va_space,
771 .maxlen = sizeof(int),
772 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800773 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800775#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800776#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700777 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700778 .procname = "spin_retry",
779 .data = &spin_retry,
780 .maxlen = sizeof (int),
781 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800782 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700783 },
784#endif
Len Brown673d5b42007-07-28 03:33:16 -0400785#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800786 {
Pavel Machekc255d842006-02-20 18:27:58 -0800787 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700788 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800789 .maxlen = sizeof (unsigned long),
790 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800792 },
793#endif
Jes Sorensend2b176e2006-02-28 09:42:23 -0800794#ifdef CONFIG_IA64
795 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800796 .procname = "ignore-unaligned-usertrap",
797 .data = &no_unaligned_warning,
798 .maxlen = sizeof (int),
799 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800800 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800801 },
Doug Chapman88fc2412009-01-15 10:38:56 -0800802 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800803 .procname = "unaligned-dump-stack",
804 .data = &unaligned_dump_stack,
805 .maxlen = sizeof (int),
806 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800807 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800808 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800809#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700810#ifdef CONFIG_DETECT_SOFTLOCKUP
811 {
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200812 .procname = "softlockup_panic",
813 .data = &softlockup_panic,
814 .maxlen = sizeof(int),
815 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800816 .proc_handler = proc_dointvec_minmax,
Ingo Molnar9c44bc02008-05-12 21:21:04 +0200817 .extra1 = &zero,
818 .extra2 = &one,
819 },
820 {
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700821 .procname = "softlockup_thresh",
822 .data = &softlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200823 .maxlen = sizeof(int),
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700824 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800825 .proc_handler = proc_dosoftlockup_thresh,
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200826 .extra1 = &neg_one,
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700827 .extra2 = &sixty,
828 },
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800829#endif
830#ifdef CONFIG_DETECT_HUNG_TASK
831 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800832 .procname = "hung_task_panic",
833 .data = &sysctl_hung_task_panic,
834 .maxlen = sizeof(int),
835 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800836 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800837 .extra1 = &zero,
838 .extra2 = &one,
839 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100840 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100841 .procname = "hung_task_check_count",
842 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100843 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100844 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800845 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100846 },
847 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100848 .procname = "hung_task_timeout_secs",
849 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100850 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100851 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800852 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100853 },
854 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100855 .procname = "hung_task_warnings",
856 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100857 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100858 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800859 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100860 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700861#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200862#ifdef CONFIG_COMPAT
863 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200864 .procname = "compat-log",
865 .data = &compat_log,
866 .maxlen = sizeof (int),
867 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800868 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200869 },
870#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700871#ifdef CONFIG_RT_MUTEXES
872 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700873 .procname = "max_lock_depth",
874 .data = &max_lock_depth,
875 .maxlen = sizeof(int),
876 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800877 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700878 },
879#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700880 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700881 .procname = "poweroff_cmd",
882 .data = &poweroff_cmd,
883 .maxlen = POWEROFF_CMD_PATH_LEN,
884 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800885 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -0700886 },
David Howells0b77f5b2008-04-29 01:01:32 -0700887#ifdef CONFIG_KEYS
888 {
David Howells0b77f5b2008-04-29 01:01:32 -0700889 .procname = "keys",
890 .mode = 0555,
891 .child = key_sysctls,
892 },
893#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700894#ifdef CONFIG_RCU_TORTURE_TEST
895 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700896 .procname = "rcutorture_runnable",
897 .data = &rcutorture_runnable,
898 .maxlen = sizeof(int),
899 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800900 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -0700901 },
902#endif
David Howells12e22c52009-04-03 16:42:35 +0100903#ifdef CONFIG_SLOW_WORK
904 {
David Howells12e22c52009-04-03 16:42:35 +0100905 .procname = "slow-work",
906 .mode = 0555,
907 .child = slow_work_sysctls,
908 },
909#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200910#ifdef CONFIG_PERF_EVENTS
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200911 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200912 .procname = "perf_event_paranoid",
913 .data = &sysctl_perf_event_paranoid,
914 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200915 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800916 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200917 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200918 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200919 .procname = "perf_event_mlock_kb",
920 .data = &sysctl_perf_event_mlock,
921 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200922 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800923 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +0200924 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200925 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +0200926 .procname = "perf_event_max_sample_rate",
927 .data = &sysctl_perf_event_sample_rate,
928 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200929 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800930 .proc_handler = proc_dointvec,
Peter Zijlstraa78ac322009-05-25 17:39:05 +0200931 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +0200932#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +0200933#ifdef CONFIG_KMEMCHECK
934 {
Vegard Nossumdfec0722008-04-04 00:51:41 +0200935 .procname = "kmemcheck",
936 .data = &kmemcheck_enabled,
937 .maxlen = sizeof(int),
938 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800939 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +0200940 },
941#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200942#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200943 {
Jens Axboe5e605b62009-08-05 09:07:21 +0200944 .procname = "blk_iopoll",
945 .data = &blk_iopoll_enabled,
946 .maxlen = sizeof(int),
947 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800948 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +0200949 },
Jens Axboecb684b52009-09-15 21:53:11 +0200950#endif
Andrew Mortoned2c12f2007-07-19 01:50:35 -0700951/*
952 * NOTE: do not add new entries to this table unless you have read
953 * Documentation/sysctl/ctl_unnumbered.txt
954 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700955 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956};
957
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700958static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 .procname = "overcommit_memory",
961 .data = &sysctl_overcommit_memory,
962 .maxlen = sizeof(sysctl_overcommit_memory),
963 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800964 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 },
966 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700967 .procname = "panic_on_oom",
968 .data = &sysctl_panic_on_oom,
969 .maxlen = sizeof(sysctl_panic_on_oom),
970 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800971 .proc_handler = proc_dointvec,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -0700972 },
973 {
David Rientjesfe071d72007-10-16 23:25:56 -0700974 .procname = "oom_kill_allocating_task",
975 .data = &sysctl_oom_kill_allocating_task,
976 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
977 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800978 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -0700979 },
980 {
David Rientjesfef1bdd2008-02-07 00:14:07 -0800981 .procname = "oom_dump_tasks",
982 .data = &sysctl_oom_dump_tasks,
983 .maxlen = sizeof(sysctl_oom_dump_tasks),
984 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800985 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -0800986 },
987 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 .procname = "overcommit_ratio",
989 .data = &sysctl_overcommit_ratio,
990 .maxlen = sizeof(sysctl_overcommit_ratio),
991 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800992 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 },
994 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 .procname = "page-cluster",
996 .data = &page_cluster,
997 .maxlen = sizeof(int),
998 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800999 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 },
1001 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 .procname = "dirty_background_ratio",
1003 .data = &dirty_background_ratio,
1004 .maxlen = sizeof(dirty_background_ratio),
1005 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001006 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 .extra1 = &zero,
1008 .extra2 = &one_hundred,
1009 },
1010 {
David Rientjes2da02992009-01-06 14:39:31 -08001011 .procname = "dirty_background_bytes",
1012 .data = &dirty_background_bytes,
1013 .maxlen = sizeof(dirty_background_bytes),
1014 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001015 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001016 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001017 },
1018 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .procname = "dirty_ratio",
1020 .data = &vm_dirty_ratio,
1021 .maxlen = sizeof(vm_dirty_ratio),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 .extra1 = &zero,
1025 .extra2 = &one_hundred,
1026 },
1027 {
David Rientjes2da02992009-01-06 14:39:31 -08001028 .procname = "dirty_bytes",
1029 .data = &vm_dirty_bytes,
1030 .maxlen = sizeof(vm_dirty_bytes),
1031 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001033 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001034 },
1035 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001037 .data = &dirty_writeback_interval,
1038 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001040 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 },
1042 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001044 .data = &dirty_expire_interval,
1045 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001047 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 },
1049 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 .procname = "nr_pdflush_threads",
1051 .data = &nr_pdflush_threads,
1052 .maxlen = sizeof nr_pdflush_threads,
1053 .mode = 0444 /* read-only*/,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001054 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 },
1056 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 .procname = "swappiness",
1058 .data = &vm_swappiness,
1059 .maxlen = sizeof(vm_swappiness),
1060 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001061 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 .extra1 = &zero,
1063 .extra2 = &one_hundred,
1064 },
1065#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001066 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001068 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 .maxlen = sizeof(unsigned long),
1070 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 .extra1 = (void *)&hugetlb_zero,
1073 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001074 },
1075#ifdef CONFIG_NUMA
1076 {
1077 .procname = "nr_hugepages_mempolicy",
1078 .data = NULL,
1079 .maxlen = sizeof(unsigned long),
1080 .mode = 0644,
1081 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1082 .extra1 = (void *)&hugetlb_zero,
1083 .extra2 = (void *)&hugetlb_infinity,
1084 },
1085#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 .procname = "hugetlb_shm_group",
1088 .data = &sysctl_hugetlb_shm_group,
1089 .maxlen = sizeof(gid_t),
1090 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001091 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 },
Mel Gorman396faf02007-07-17 04:03:13 -07001093 {
Mel Gorman396faf02007-07-17 04:03:13 -07001094 .procname = "hugepages_treat_as_movable",
1095 .data = &hugepages_treat_as_movable,
1096 .maxlen = sizeof(int),
1097 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001098 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001099 },
Adam Litke54f9f802007-10-16 01:26:20 -07001100 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001101 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001102 .data = NULL,
1103 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001104 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001105 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001106 .extra1 = (void *)&hugetlb_zero,
1107 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001108 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109#endif
1110 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 .procname = "lowmem_reserve_ratio",
1112 .data = &sysctl_lowmem_reserve_ratio,
1113 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1114 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001115 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 },
1117 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001118 .procname = "drop_caches",
1119 .data = &sysctl_drop_caches,
1120 .maxlen = sizeof(int),
1121 .mode = 0644,
1122 .proc_handler = drop_caches_sysctl_handler,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001123 },
1124 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 .procname = "min_free_kbytes",
1126 .data = &min_free_kbytes,
1127 .maxlen = sizeof(min_free_kbytes),
1128 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001129 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 .extra1 = &zero,
1131 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001132 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001133 .procname = "percpu_pagelist_fraction",
1134 .data = &percpu_pagelist_fraction,
1135 .maxlen = sizeof(percpu_pagelist_fraction),
1136 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001137 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001138 .extra1 = &min_percpu_pagelist_fract,
1139 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140#ifdef CONFIG_MMU
1141 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 .procname = "max_map_count",
1143 .data = &sysctl_max_map_count,
1144 .maxlen = sizeof(sysctl_max_map_count),
1145 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001146 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001147 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001149#else
1150 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001151 .procname = "nr_trim_pages",
1152 .data = &sysctl_nr_trim_pages,
1153 .maxlen = sizeof(sysctl_nr_trim_pages),
1154 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001155 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001156 .extra1 = &zero,
1157 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158#endif
1159 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 .procname = "laptop_mode",
1161 .data = &laptop_mode,
1162 .maxlen = sizeof(laptop_mode),
1163 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001164 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 },
1166 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 .procname = "block_dump",
1168 .data = &block_dump,
1169 .maxlen = sizeof(block_dump),
1170 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001171 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 .extra1 = &zero,
1173 },
1174 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 .procname = "vfs_cache_pressure",
1176 .data = &sysctl_vfs_cache_pressure,
1177 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1178 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001179 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 .extra1 = &zero,
1181 },
1182#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1183 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 .procname = "legacy_va_layout",
1185 .data = &sysctl_legacy_va_layout,
1186 .maxlen = sizeof(sysctl_legacy_va_layout),
1187 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001188 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 .extra1 = &zero,
1190 },
1191#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001192#ifdef CONFIG_NUMA
1193 {
Christoph Lameter17436602006-01-18 17:42:32 -08001194 .procname = "zone_reclaim_mode",
1195 .data = &zone_reclaim_mode,
1196 .maxlen = sizeof(zone_reclaim_mode),
1197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001198 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001199 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001200 },
Christoph Lameter96146342006-07-03 00:24:13 -07001201 {
Christoph Lameter96146342006-07-03 00:24:13 -07001202 .procname = "min_unmapped_ratio",
1203 .data = &sysctl_min_unmapped_ratio,
1204 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001206 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001207 .extra1 = &zero,
1208 .extra2 = &one_hundred,
1209 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001210 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001211 .procname = "min_slab_ratio",
1212 .data = &sysctl_min_slab_ratio,
1213 .maxlen = sizeof(sysctl_min_slab_ratio),
1214 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001215 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001216 .extra1 = &zero,
1217 .extra2 = &one_hundred,
1218 },
Christoph Lameter17436602006-01-18 17:42:32 -08001219#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001220#ifdef CONFIG_SMP
1221 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001222 .procname = "stat_interval",
1223 .data = &sysctl_stat_interval,
1224 .maxlen = sizeof(sysctl_stat_interval),
1225 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001226 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001227 },
1228#endif
David Howells6e141542009-12-15 19:27:45 +00001229#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001230 {
Eric Parised032182007-06-28 15:55:21 -04001231 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001232 .data = &dac_mmap_min_addr,
1233 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001234 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001235 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001236 },
David Howells6e141542009-12-15 19:27:45 +00001237#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001238#ifdef CONFIG_NUMA
1239 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001240 .procname = "numa_zonelist_order",
1241 .data = &numa_zonelist_order,
1242 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1243 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001244 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001245 },
1246#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001247#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001248 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001249 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001250 .procname = "vdso_enabled",
1251 .data = &vdso_enabled,
1252 .maxlen = sizeof(vdso_enabled),
1253 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001254 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001255 .extra1 = &zero,
1256 },
1257#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001258#ifdef CONFIG_HIGHMEM
1259 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001260 .procname = "highmem_is_dirtyable",
1261 .data = &vm_highmem_is_dirtyable,
1262 .maxlen = sizeof(vm_highmem_is_dirtyable),
1263 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001264 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001265 .extra1 = &zero,
1266 .extra2 = &one,
1267 },
1268#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001269 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001270 .procname = "scan_unevictable_pages",
1271 .data = &scan_unevictable_pages,
1272 .maxlen = sizeof(scan_unevictable_pages),
1273 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001274 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001275 },
Andi Kleen6a460792009-09-16 11:50:15 +02001276#ifdef CONFIG_MEMORY_FAILURE
1277 {
Andi Kleen6a460792009-09-16 11:50:15 +02001278 .procname = "memory_failure_early_kill",
1279 .data = &sysctl_memory_failure_early_kill,
1280 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001283 .extra1 = &zero,
1284 .extra2 = &one,
1285 },
1286 {
Andi Kleen6a460792009-09-16 11:50:15 +02001287 .procname = "memory_failure_recovery",
1288 .data = &sysctl_memory_failure_recovery,
1289 .maxlen = sizeof(sysctl_memory_failure_recovery),
1290 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001291 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001292 .extra1 = &zero,
1293 .extra2 = &one,
1294 },
1295#endif
1296
Andrew Morton2be7fe02007-07-15 23:41:21 -07001297/*
1298 * NOTE: do not add new entries to this table unless you have read
1299 * Documentation/sysctl/ctl_unnumbered.txt
1300 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001301 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302};
1303
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001304#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001305static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001306 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001307};
1308#endif
1309
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001310static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 .procname = "inode-nr",
1313 .data = &inodes_stat,
1314 .maxlen = 2*sizeof(int),
1315 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001316 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 },
1318 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 .procname = "inode-state",
1320 .data = &inodes_stat,
1321 .maxlen = 7*sizeof(int),
1322 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001323 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 },
1325 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 .procname = "file-nr",
1327 .data = &files_stat,
1328 .maxlen = 3*sizeof(int),
1329 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001330 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 },
1332 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 .procname = "file-max",
1334 .data = &files_stat.max_files,
1335 .maxlen = sizeof(int),
1336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001337 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 },
1339 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001340 .procname = "nr_open",
1341 .data = &sysctl_nr_open,
1342 .maxlen = sizeof(int),
1343 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001344 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001345 .extra1 = &sysctl_nr_open_min,
1346 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001347 },
1348 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 .procname = "dentry-state",
1350 .data = &dentry_stat,
1351 .maxlen = 6*sizeof(int),
1352 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001353 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 },
1355 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 .procname = "overflowuid",
1357 .data = &fs_overflowuid,
1358 .maxlen = sizeof(int),
1359 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001360 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .extra1 = &minolduid,
1362 .extra2 = &maxolduid,
1363 },
1364 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 .procname = "overflowgid",
1366 .data = &fs_overflowgid,
1367 .maxlen = sizeof(int),
1368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001369 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 .extra1 = &minolduid,
1371 .extra2 = &maxolduid,
1372 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001373#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 .procname = "leases-enable",
1376 .data = &leases_enable,
1377 .maxlen = sizeof(int),
1378 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001379 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001381#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382#ifdef CONFIG_DNOTIFY
1383 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 .procname = "dir-notify-enable",
1385 .data = &dir_notify_enable,
1386 .maxlen = sizeof(int),
1387 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001388 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 },
1390#endif
1391#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001392#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .procname = "lease-break-time",
1395 .data = &lease_break_time,
1396 .maxlen = sizeof(int),
1397 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001398 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001400#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001401#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .procname = "aio-nr",
1404 .data = &aio_nr,
1405 .maxlen = sizeof(aio_nr),
1406 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001407 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 },
1409 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 .procname = "aio-max-nr",
1411 .data = &aio_max_nr,
1412 .maxlen = sizeof(aio_max_nr),
1413 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001414 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001416#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001417#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001418 {
Robert Love0399cb02005-07-13 12:38:18 -04001419 .procname = "inotify",
1420 .mode = 0555,
1421 .child = inotify_table,
1422 },
1423#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001424#ifdef CONFIG_EPOLL
1425 {
1426 .procname = "epoll",
1427 .mode = 0555,
1428 .child = epoll_table,
1429 },
1430#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001432 {
Alan Coxd6e71142005-06-23 00:09:43 -07001433 .procname = "suid_dumpable",
1434 .data = &suid_dumpable,
1435 .maxlen = sizeof(int),
1436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001437 .proc_handler = proc_dointvec_minmax,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001438 .extra1 = &zero,
1439 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001440 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001441#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1442 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001443 .procname = "binfmt_misc",
1444 .mode = 0555,
1445 .child = binfmt_misc_table,
1446 },
1447#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001448 {
1449 .procname = "pipe-max-pages",
1450 .data = &pipe_max_pages,
1451 .maxlen = sizeof(int),
1452 .mode = 0644,
1453 .proc_handler = &proc_dointvec_minmax,
1454 .extra1 = &two,
1455 },
Andrew Morton2be7fe02007-07-15 23:41:21 -07001456/*
1457 * NOTE: do not add new entries to this table unless you have read
1458 * Documentation/sysctl/ctl_unnumbered.txt
1459 */
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001460 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461};
1462
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001463static struct ctl_table debug_table[] = {
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001464#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1465 defined(CONFIG_S390)
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001466 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001467 .procname = "exception-trace",
1468 .data = &show_unhandled_signals,
1469 .maxlen = sizeof(int),
1470 .mode = 0644,
1471 .proc_handler = proc_dointvec
1472 },
1473#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001474#if defined(CONFIG_OPTPROBES)
1475 {
1476 .procname = "kprobes-optimization",
1477 .data = &sysctl_kprobes_optimization,
1478 .maxlen = sizeof(int),
1479 .mode = 0644,
1480 .proc_handler = proc_kprobes_optimization_handler,
1481 .extra1 = &zero,
1482 .extra2 = &one,
1483 },
1484#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001485 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486};
1487
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001488static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001489 { }
Robert Love0eeca282005-07-12 17:06:03 -04001490};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Al Viro330d57f2005-11-04 10:18:40 +00001492static DEFINE_SPINLOCK(sysctl_lock);
1493
1494/* called under sysctl_lock */
1495static int use_table(struct ctl_table_header *p)
1496{
1497 if (unlikely(p->unregistering))
1498 return 0;
1499 p->used++;
1500 return 1;
1501}
1502
1503/* called under sysctl_lock */
1504static void unuse_table(struct ctl_table_header *p)
1505{
1506 if (!--p->used)
1507 if (unlikely(p->unregistering))
1508 complete(p->unregistering);
1509}
1510
1511/* called under sysctl_lock, will reacquire if has to wait */
1512static void start_unregistering(struct ctl_table_header *p)
1513{
1514 /*
1515 * if p->used is 0, nobody will ever touch that entry again;
1516 * we'll eliminate all paths to it before dropping sysctl_lock
1517 */
1518 if (unlikely(p->used)) {
1519 struct completion wait;
1520 init_completion(&wait);
1521 p->unregistering = &wait;
1522 spin_unlock(&sysctl_lock);
1523 wait_for_completion(&wait);
1524 spin_lock(&sysctl_lock);
Al Virof7e6ced2008-07-15 01:44:23 -04001525 } else {
1526 /* anything non-NULL; we'll never dereference it */
1527 p->unregistering = ERR_PTR(-EINVAL);
Al Viro330d57f2005-11-04 10:18:40 +00001528 }
1529 /*
1530 * do not remove from the list until nobody holds it; walking the
1531 * list in do_sysctl() relies on that.
1532 */
1533 list_del_init(&p->ctl_entry);
1534}
1535
Al Virof7e6ced2008-07-15 01:44:23 -04001536void sysctl_head_get(struct ctl_table_header *head)
1537{
1538 spin_lock(&sysctl_lock);
1539 head->count++;
1540 spin_unlock(&sysctl_lock);
1541}
1542
1543void sysctl_head_put(struct ctl_table_header *head)
1544{
1545 spin_lock(&sysctl_lock);
1546 if (!--head->count)
1547 kfree(head);
1548 spin_unlock(&sysctl_lock);
1549}
1550
1551struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1552{
1553 if (!head)
1554 BUG();
1555 spin_lock(&sysctl_lock);
1556 if (!use_table(head))
1557 head = ERR_PTR(-ENOENT);
1558 spin_unlock(&sysctl_lock);
1559 return head;
1560}
1561
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001562void sysctl_head_finish(struct ctl_table_header *head)
1563{
1564 if (!head)
1565 return;
1566 spin_lock(&sysctl_lock);
1567 unuse_table(head);
1568 spin_unlock(&sysctl_lock);
1569}
1570
Al Viro73455092008-07-14 21:22:20 -04001571static struct ctl_table_set *
1572lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1573{
1574 struct ctl_table_set *set = &root->default_set;
1575 if (root->lookup)
1576 set = root->lookup(root, namespaces);
1577 return set;
1578}
1579
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001580static struct list_head *
1581lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001582{
Al Viro73455092008-07-14 21:22:20 -04001583 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1584 return &set->list;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001585}
1586
1587struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1588 struct ctl_table_header *prev)
1589{
1590 struct ctl_table_root *root;
1591 struct list_head *header_list;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001592 struct ctl_table_header *head;
1593 struct list_head *tmp;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001594
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001595 spin_lock(&sysctl_lock);
1596 if (prev) {
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001597 head = prev;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001598 tmp = &prev->ctl_entry;
1599 unuse_table(prev);
1600 goto next;
1601 }
1602 tmp = &root_table_header.ctl_entry;
1603 for (;;) {
1604 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1605
1606 if (!use_table(head))
1607 goto next;
1608 spin_unlock(&sysctl_lock);
1609 return head;
1610 next:
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001611 root = head->root;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001612 tmp = tmp->next;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001613 header_list = lookup_header_list(root, namespaces);
1614 if (tmp != header_list)
1615 continue;
1616
1617 do {
1618 root = list_entry(root->root_list.next,
1619 struct ctl_table_root, root_list);
1620 if (root == &sysctl_table_root)
1621 goto out;
1622 header_list = lookup_header_list(root, namespaces);
1623 } while (list_empty(header_list));
1624 tmp = header_list->next;
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001625 }
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001626out:
Eric W. Biederman805b5d52007-02-14 00:34:11 -08001627 spin_unlock(&sysctl_lock);
1628 return NULL;
1629}
1630
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001631struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1632{
1633 return __sysctl_head_next(current->nsproxy, prev);
1634}
1635
1636void register_sysctl_root(struct ctl_table_root *root)
1637{
1638 spin_lock(&sysctl_lock);
1639 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1640 spin_unlock(&sysctl_lock);
1641}
1642
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643/*
Eric W. Biederman1ff007e2007-02-14 00:34:11 -08001644 * sysctl_perm does NOT grant the superuser all rights automatically, because
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 * some sysctl variables are readonly even to root.
1646 */
1647
1648static int test_perm(int mode, int op)
1649{
David Howells76aac0e2008-11-14 10:39:12 +11001650 if (!current_euid())
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 mode >>= 6;
1652 else if (in_egroup_p(0))
1653 mode >>= 3;
Al Viroe6305c42008-07-15 21:03:57 -04001654 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 return 0;
1656 return -EACCES;
1657}
1658
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001659int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
1661 int error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001662 int mode;
1663
Al Viroe6305c42008-07-15 21:03:57 -04001664 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 if (error)
1666 return error;
Pavel Emelyanovd7321cd2008-04-29 01:02:44 -07001667
1668 if (root->permissions)
1669 mode = root->permissions(root, current->nsproxy, table);
1670 else
1671 mode = table->mode;
1672
1673 return test_perm(mode, op);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674}
1675
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001676static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1677{
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001678 for (; table->procname; table++) {
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001679 table->parent = parent;
1680 if (table->child)
1681 sysctl_set_parent(table, table->child);
1682 }
1683}
1684
1685static __init int sysctl_init(void)
1686{
1687 sysctl_set_parent(NULL, root_table);
Holger Schurig88f458e2008-04-29 01:02:36 -07001688#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1689 {
1690 int err;
1691 err = sysctl_check_table(current->nsproxy, root_table);
1692 }
1693#endif
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001694 return 0;
1695}
1696
1697core_initcall(sysctl_init);
1698
Al Virobfbcf032008-07-27 06:31:22 +01001699static struct ctl_table *is_branch_in(struct ctl_table *branch,
1700 struct ctl_table *table)
Al Viroae7edec2008-07-15 06:33:31 -04001701{
1702 struct ctl_table *p;
1703 const char *s = branch->procname;
1704
1705 /* branch should have named subdirectory as its first element */
1706 if (!s || !branch->child)
Al Virobfbcf032008-07-27 06:31:22 +01001707 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001708
1709 /* ... and nothing else */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001710 if (branch[1].procname)
Al Virobfbcf032008-07-27 06:31:22 +01001711 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001712
1713 /* table should contain subdirectory with the same name */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001714 for (p = table; p->procname; p++) {
Al Viroae7edec2008-07-15 06:33:31 -04001715 if (!p->child)
1716 continue;
1717 if (p->procname && strcmp(p->procname, s) == 0)
Al Virobfbcf032008-07-27 06:31:22 +01001718 return p;
Al Viroae7edec2008-07-15 06:33:31 -04001719 }
Al Virobfbcf032008-07-27 06:31:22 +01001720 return NULL;
Al Viroae7edec2008-07-15 06:33:31 -04001721}
1722
1723/* see if attaching q to p would be an improvement */
1724static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1725{
1726 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
Al Virobfbcf032008-07-27 06:31:22 +01001727 struct ctl_table *next;
Al Viroae7edec2008-07-15 06:33:31 -04001728 int is_better = 0;
1729 int not_in_parent = !p->attached_by;
1730
Al Virobfbcf032008-07-27 06:31:22 +01001731 while ((next = is_branch_in(by, to)) != NULL) {
Al Viroae7edec2008-07-15 06:33:31 -04001732 if (by == q->attached_by)
1733 is_better = 1;
1734 if (to == p->attached_by)
1735 not_in_parent = 1;
1736 by = by->child;
Al Virobfbcf032008-07-27 06:31:22 +01001737 to = next->child;
Al Viroae7edec2008-07-15 06:33:31 -04001738 }
1739
1740 if (is_better && not_in_parent) {
1741 q->attached_by = by;
1742 q->attached_to = to;
1743 q->parent = p;
1744 }
1745}
1746
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001748 * __register_sysctl_paths - register a sysctl hierarchy
1749 * @root: List of sysctl headers to register on
1750 * @namespaces: Data to compute which lists of sysctl entries are visible
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001751 * @path: The path to the directory the sysctl table is in.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 * @table: the top-level table structure
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 *
1754 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001755 * array. A completely 0 filled entry terminates the table.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 *
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001757 * The members of the &struct ctl_table structure are used as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1760 * enter a sysctl file
1761 *
1762 * data - a pointer to data for use by proc_handler
1763 *
1764 * maxlen - the maximum size in bytes of the data
1765 *
1766 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1767 *
1768 * child - a pointer to the child sysctl table if this entry is a directory, or
1769 * %NULL.
1770 *
1771 * proc_handler - the text handler routine (described below)
1772 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 * de - for internal use by the sysctl routines
1774 *
1775 * extra1, extra2 - extra pointers usable by the proc handler routines
1776 *
1777 * Leaf nodes in the sysctl tree will be represented by a single file
1778 * under /proc; non-leaf nodes will be represented by directories.
1779 *
1780 * sysctl(2) can automatically manage read and write requests through
1781 * the sysctl table. The data and maxlen fields of the ctl_table
1782 * struct enable minimal validation of the values being written to be
1783 * performed, and the mode field allows minimal authentication.
1784 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 * There must be a proc_handler routine for any terminal nodes
1786 * mirrored under /proc/sys (non-terminals are handled by a built-in
1787 * directory handler). Several default handlers are available to
1788 * cover common cases -
1789 *
1790 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1791 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1792 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1793 *
1794 * It is the handler's job to read the input buffer from user memory
1795 * and process it. The handler should return 0 on success.
1796 *
1797 * This routine returns %NULL on a failure to register, and a pointer
1798 * to the table header on success.
1799 */
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001800struct ctl_table_header *__register_sysctl_paths(
1801 struct ctl_table_root *root,
1802 struct nsproxy *namespaces,
1803 const struct ctl_path *path, struct ctl_table *table)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804{
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001805 struct ctl_table_header *header;
1806 struct ctl_table *new, **prevp;
1807 unsigned int n, npath;
Al Viroae7edec2008-07-15 06:33:31 -04001808 struct ctl_table_set *set;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001809
1810 /* Count the path components */
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001811 for (npath = 0; path[npath].procname; ++npath)
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001812 ;
1813
1814 /*
1815 * For each path component, allocate a 2-element ctl_table array.
1816 * The first array element will be filled with the sysctl entry
Eric W. Biederman2315ffa2009-04-03 03:18:02 -07001817 * for this, the second will be the sentinel (procname == 0).
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001818 *
1819 * We allocate everything in one go so that we don't have to
1820 * worry about freeing additional memory in unregister_sysctl_table.
1821 */
1822 header = kzalloc(sizeof(struct ctl_table_header) +
1823 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1824 if (!header)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 return NULL;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001826
1827 new = (struct ctl_table *) (header + 1);
1828
1829 /* Now connect the dots */
1830 prevp = &header->ctl_table;
1831 for (n = 0; n < npath; ++n, ++path) {
1832 /* Copy the procname */
1833 new->procname = path->procname;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001834 new->mode = 0555;
1835
1836 *prevp = new;
1837 prevp = &new->child;
1838
1839 new += 2;
1840 }
1841 *prevp = table;
Eric W. Biederman23eb06d2007-11-30 23:52:10 +11001842 header->ctl_table_arg = table;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001843
1844 INIT_LIST_HEAD(&header->ctl_entry);
1845 header->used = 0;
1846 header->unregistering = NULL;
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001847 header->root = root;
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001848 sysctl_set_parent(NULL, header->ctl_table);
Al Virof7e6ced2008-07-15 01:44:23 -04001849 header->count = 1;
Holger Schurig88f458e2008-04-29 01:02:36 -07001850#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001851 if (sysctl_check_table(namespaces, header->ctl_table)) {
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001852 kfree(header);
Eric W. Biedermanfc6cd252007-10-18 03:05:54 -07001853 return NULL;
1854 }
Holger Schurig88f458e2008-04-29 01:02:36 -07001855#endif
Al Viro330d57f2005-11-04 10:18:40 +00001856 spin_lock(&sysctl_lock);
Al Viro73455092008-07-14 21:22:20 -04001857 header->set = lookup_header_set(root, namespaces);
Al Viroae7edec2008-07-15 06:33:31 -04001858 header->attached_by = header->ctl_table;
1859 header->attached_to = root_table;
1860 header->parent = &root_table_header;
1861 for (set = header->set; set; set = set->parent) {
1862 struct ctl_table_header *p;
1863 list_for_each_entry(p, &set->list, ctl_entry) {
1864 if (p->unregistering)
1865 continue;
1866 try_attach(p, header);
1867 }
1868 }
1869 header->parent->count++;
Al Viro73455092008-07-14 21:22:20 -04001870 list_add_tail(&header->ctl_entry, &header->set->list);
Al Viro330d57f2005-11-04 10:18:40 +00001871 spin_unlock(&sysctl_lock);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001872
1873 return header;
1874}
1875
1876/**
Eric W. Biedermane51b6ba2007-11-30 23:54:00 +11001877 * register_sysctl_table_path - register a sysctl table hierarchy
1878 * @path: The path to the directory the sysctl table is in.
1879 * @table: the top-level table structure
1880 *
1881 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1882 * array. A completely 0 filled entry terminates the table.
1883 *
1884 * See __register_sysctl_paths for more details.
1885 */
1886struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1887 struct ctl_table *table)
1888{
1889 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1890 path, table);
1891}
1892
1893/**
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001894 * register_sysctl_table - register a sysctl table hierarchy
1895 * @table: the top-level table structure
1896 *
1897 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1898 * array. A completely 0 filled entry terminates the table.
1899 *
1900 * See register_sysctl_paths for more details.
1901 */
1902struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1903{
1904 static const struct ctl_path null_path[] = { {} };
1905
1906 return register_sysctl_paths(null_path, table);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907}
1908
1909/**
1910 * unregister_sysctl_table - unregister a sysctl table hierarchy
1911 * @header: the header returned from register_sysctl_table
1912 *
1913 * Unregisters the sysctl table and all children. proc entries may not
1914 * actually be removed until they are no longer used by anyone.
1915 */
1916void unregister_sysctl_table(struct ctl_table_header * header)
1917{
Al Viro330d57f2005-11-04 10:18:40 +00001918 might_sleep();
Pavel Emelyanovf1dad162007-12-04 23:45:24 -08001919
1920 if (header == NULL)
1921 return;
1922
Al Viro330d57f2005-11-04 10:18:40 +00001923 spin_lock(&sysctl_lock);
1924 start_unregistering(header);
Al Viroae7edec2008-07-15 06:33:31 -04001925 if (!--header->parent->count) {
1926 WARN_ON(1);
1927 kfree(header->parent);
1928 }
Al Virof7e6ced2008-07-15 01:44:23 -04001929 if (!--header->count)
1930 kfree(header);
Al Viro330d57f2005-11-04 10:18:40 +00001931 spin_unlock(&sysctl_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932}
1933
Al Viro9043476f2008-07-15 08:54:06 -04001934int sysctl_is_seen(struct ctl_table_header *p)
1935{
1936 struct ctl_table_set *set = p->set;
1937 int res;
1938 spin_lock(&sysctl_lock);
1939 if (p->unregistering)
1940 res = 0;
1941 else if (!set->is_seen)
1942 res = 1;
1943 else
1944 res = set->is_seen(set);
1945 spin_unlock(&sysctl_lock);
1946 return res;
1947}
1948
Al Viro73455092008-07-14 21:22:20 -04001949void setup_sysctl_set(struct ctl_table_set *p,
1950 struct ctl_table_set *parent,
1951 int (*is_seen)(struct ctl_table_set *))
1952{
1953 INIT_LIST_HEAD(&p->list);
1954 p->parent = parent ? parent : &sysctl_table_root.default_set;
1955 p->is_seen = is_seen;
1956}
1957
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001958#else /* !CONFIG_SYSCTL */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001959struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001960{
1961 return NULL;
1962}
1963
Eric W. Biederman29e796f2007-11-30 23:50:18 +11001964struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1965 struct ctl_table *table)
1966{
1967 return NULL;
1968}
1969
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001970void unregister_sysctl_table(struct ctl_table_header * table)
1971{
1972}
1973
Al Viro73455092008-07-14 21:22:20 -04001974void setup_sysctl_set(struct ctl_table_set *p,
1975 struct ctl_table_set *parent,
1976 int (*is_seen)(struct ctl_table_set *))
1977{
1978}
1979
Al Virof7e6ced2008-07-15 01:44:23 -04001980void sysctl_head_put(struct ctl_table_header *head)
1981{
1982}
1983
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001984#endif /* CONFIG_SYSCTL */
1985
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986/*
1987 * /proc/sys support
1988 */
1989
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001990#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001992static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001993 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001994 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001995{
1996 size_t len;
1997 char __user *p;
1998 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001999
2000 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002001 *lenp = 0;
2002 return 0;
2003 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002004
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002005 if (write) {
2006 len = 0;
2007 p = buffer;
2008 while (len < *lenp) {
2009 if (get_user(c, p++))
2010 return -EFAULT;
2011 if (c == 0 || c == '\n')
2012 break;
2013 len++;
2014 }
2015 if (len >= maxlen)
2016 len = maxlen-1;
2017 if(copy_from_user(data, buffer, len))
2018 return -EFAULT;
2019 ((char *) data)[len] = 0;
2020 *ppos += *lenp;
2021 } else {
2022 len = strlen(data);
2023 if (len > maxlen)
2024 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002025
2026 if (*ppos > len) {
2027 *lenp = 0;
2028 return 0;
2029 }
2030
2031 data += *ppos;
2032 len -= *ppos;
2033
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002034 if (len > *lenp)
2035 len = *lenp;
2036 if (len)
2037 if(copy_to_user(buffer, data, len))
2038 return -EFAULT;
2039 if (len < *lenp) {
2040 if(put_user('\n', ((char __user *) buffer) + len))
2041 return -EFAULT;
2042 len++;
2043 }
2044 *lenp = len;
2045 *ppos += len;
2046 }
2047 return 0;
2048}
2049
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050/**
2051 * proc_dostring - read a string sysctl
2052 * @table: the sysctl table
2053 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 * @buffer: the user buffer
2055 * @lenp: the size of the user buffer
2056 * @ppos: file position
2057 *
2058 * Reads/writes a string from/to the user buffer. If the kernel
2059 * buffer provided is not large enough to hold the string, the
2060 * string is truncated. The copied string is %NULL-terminated.
2061 * If the string is being read by the user process, it is copied
2062 * and a newline '\n' is added. It is truncated if the buffer is
2063 * not large enough.
2064 *
2065 * Returns 0 on success.
2066 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002067int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 void __user *buffer, size_t *lenp, loff_t *ppos)
2069{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002070 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002071 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072}
2073
Amerigo Wang00b7c332010-05-05 00:26:45 +00002074static size_t proc_skip_spaces(char **buf)
2075{
2076 size_t ret;
2077 char *tmp = skip_spaces(*buf);
2078 ret = tmp - *buf;
2079 *buf = tmp;
2080 return ret;
2081}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002083static void proc_skip_char(char **buf, size_t *size, const char v)
2084{
2085 while (*size) {
2086 if (**buf != v)
2087 break;
2088 (*size)--;
2089 (*buf)++;
2090 }
2091}
2092
Amerigo Wang00b7c332010-05-05 00:26:45 +00002093#define TMPBUFLEN 22
2094/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002095 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002096 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002097 * @buf: a kernel buffer
2098 * @size: size of the kernel buffer
2099 * @val: this is where the number will be stored
2100 * @neg: set to %TRUE if number is negative
2101 * @perm_tr: a vector which contains the allowed trailers
2102 * @perm_tr_len: size of the perm_tr vector
2103 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002104 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002105 * In case of success %0 is returned and @buf and @size are updated with
2106 * the amount of bytes read. If @tr is non-NULL and a trailing
2107 * character exists (size is non-zero after returning from this
2108 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002109 */
2110static int proc_get_long(char **buf, size_t *size,
2111 unsigned long *val, bool *neg,
2112 const char *perm_tr, unsigned perm_tr_len, char *tr)
2113{
2114 int len;
2115 char *p, tmp[TMPBUFLEN];
2116
2117 if (!*size)
2118 return -EINVAL;
2119
2120 len = *size;
2121 if (len > TMPBUFLEN - 1)
2122 len = TMPBUFLEN - 1;
2123
2124 memcpy(tmp, *buf, len);
2125
2126 tmp[len] = 0;
2127 p = tmp;
2128 if (*p == '-' && *size > 1) {
2129 *neg = true;
2130 p++;
2131 } else
2132 *neg = false;
2133 if (!isdigit(*p))
2134 return -EINVAL;
2135
2136 *val = simple_strtoul(p, &p, 0);
2137
2138 len = p - tmp;
2139
2140 /* We don't know if the next char is whitespace thus we may accept
2141 * invalid integers (e.g. 1234...a) or two integers instead of one
2142 * (e.g. 123...1). So lets not allow such large numbers. */
2143 if (len == TMPBUFLEN - 1)
2144 return -EINVAL;
2145
2146 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2147 return -EINVAL;
2148
2149 if (tr && (len < *size))
2150 *tr = *p;
2151
2152 *buf += len;
2153 *size -= len;
2154
2155 return 0;
2156}
2157
2158/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002159 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002160 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002161 * @buf: the user buffer
2162 * @size: the size of the user buffer
2163 * @val: the integer to be converted
2164 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002165 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002166 * In case of success %0 is returned and @buf and @size are updated with
2167 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002168 */
2169static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2170 bool neg)
2171{
2172 int len;
2173 char tmp[TMPBUFLEN], *p = tmp;
2174
2175 sprintf(p, "%s%lu", neg ? "-" : "", val);
2176 len = strlen(tmp);
2177 if (len > *size)
2178 len = *size;
2179 if (copy_to_user(*buf, tmp, len))
2180 return -EFAULT;
2181 *size -= len;
2182 *buf += len;
2183 return 0;
2184}
2185#undef TMPBUFLEN
2186
2187static int proc_put_char(void __user **buf, size_t *size, char c)
2188{
2189 if (*size) {
2190 char __user **buffer = (char __user **)buf;
2191 if (put_user(c, *buffer))
2192 return -EFAULT;
2193 (*size)--, (*buffer)++;
2194 *buf = *buffer;
2195 }
2196 return 0;
2197}
2198
2199static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 int *valp,
2201 int write, void *data)
2202{
2203 if (write) {
2204 *valp = *negp ? -*lvalp : *lvalp;
2205 } else {
2206 int val = *valp;
2207 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002208 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 *lvalp = (unsigned long)-val;
2210 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002211 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 *lvalp = (unsigned long)val;
2213 }
2214 }
2215 return 0;
2216}
2217
Amerigo Wang00b7c332010-05-05 00:26:45 +00002218static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2219
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002220static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002221 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002222 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002223 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 int write, void *data),
2225 void *data)
2226{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002227 int *i, vleft, first = 1, err = 0;
2228 unsigned long page = 0;
2229 size_t left;
2230 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Amerigo Wang00b7c332010-05-05 00:26:45 +00002232 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 *lenp = 0;
2234 return 0;
2235 }
2236
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002237 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 vleft = table->maxlen / sizeof(*i);
2239 left = *lenp;
2240
2241 if (!conv)
2242 conv = do_proc_dointvec_conv;
2243
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002245 if (left > PAGE_SIZE - 1)
2246 left = PAGE_SIZE - 1;
2247 page = __get_free_page(GFP_TEMPORARY);
2248 kbuf = (char *) page;
2249 if (!kbuf)
2250 return -ENOMEM;
2251 if (copy_from_user(kbuf, buffer, left)) {
2252 err = -EFAULT;
2253 goto free;
2254 }
2255 kbuf[left] = 0;
2256 }
2257
2258 for (; left && vleft--; i++, first=0) {
2259 unsigned long lval;
2260 bool neg;
2261
2262 if (write) {
2263 left -= proc_skip_spaces(&kbuf);
2264
2265 err = proc_get_long(&kbuf, &left, &lval, &neg,
2266 proc_wspace_sep,
2267 sizeof(proc_wspace_sep), NULL);
2268 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270 if (conv(&neg, &lval, i, 1, data)) {
2271 err = -EINVAL;
2272 break;
2273 }
2274 } else {
2275 if (conv(&neg, &lval, i, 0, data)) {
2276 err = -EINVAL;
2277 break;
2278 }
2279 if (!first)
2280 err = proc_put_char(&buffer, &left, '\t');
2281 if (err)
2282 break;
2283 err = proc_put_long(&buffer, &left, lval, neg);
2284 if (err)
2285 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 }
2287 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002288
2289 if (!write && !first && left && !err)
2290 err = proc_put_char(&buffer, &left, '\n');
2291 if (write && !err)
2292 left -= proc_skip_spaces(&kbuf);
2293free:
2294 if (write) {
2295 free_page(page);
2296 if (first)
2297 return err ? : -EINVAL;
2298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 *lenp -= left;
2300 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002301 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302}
2303
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002304static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002305 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002306 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002307 int write, void *data),
2308 void *data)
2309{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002310 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002311 buffer, lenp, ppos, conv, data);
2312}
2313
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314/**
2315 * proc_dointvec - read a vector of integers
2316 * @table: the sysctl table
2317 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2321 *
2322 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2323 * values from/to the user buffer, treated as an ASCII string.
2324 *
2325 * Returns 0 on success.
2326 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002327int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 void __user *buffer, size_t *lenp, loff_t *ppos)
2329{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002330 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 NULL,NULL);
2332}
2333
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002334/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002335 * Taint values can only be increased
2336 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002337 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002338static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002339 void __user *buffer, size_t *lenp, loff_t *ppos)
2340{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002341 struct ctl_table t;
2342 unsigned long tmptaint = get_taint();
2343 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002344
Bastian Blank91fcd412007-04-23 14:41:14 -07002345 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002346 return -EPERM;
2347
Andi Kleen25ddbb12008-10-15 22:01:41 -07002348 t = *table;
2349 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002350 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002351 if (err < 0)
2352 return err;
2353
2354 if (write) {
2355 /*
2356 * Poor man's atomic or. Not worth adding a primitive
2357 * to everyone's atomic.h for this
2358 */
2359 int i;
2360 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2361 if ((tmptaint >> i) & 1)
2362 add_taint(i);
2363 }
2364 }
2365
2366 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002367}
2368
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369struct do_proc_dointvec_minmax_conv_param {
2370 int *min;
2371 int *max;
2372};
2373
Amerigo Wang00b7c332010-05-05 00:26:45 +00002374static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2375 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 int write, void *data)
2377{
2378 struct do_proc_dointvec_minmax_conv_param *param = data;
2379 if (write) {
2380 int val = *negp ? -*lvalp : *lvalp;
2381 if ((param->min && *param->min > val) ||
2382 (param->max && *param->max < val))
2383 return -EINVAL;
2384 *valp = val;
2385 } else {
2386 int val = *valp;
2387 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002388 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 *lvalp = (unsigned long)-val;
2390 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002391 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 *lvalp = (unsigned long)val;
2393 }
2394 }
2395 return 0;
2396}
2397
2398/**
2399 * proc_dointvec_minmax - read a vector of integers with min/max values
2400 * @table: the sysctl table
2401 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 * @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 *
2409 * This routine will ensure the values are within the range specified by
2410 * table->extra1 (min) and table->extra2 (max).
2411 *
2412 * Returns 0 on success.
2413 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002414int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 void __user *buffer, size_t *lenp, loff_t *ppos)
2416{
2417 struct do_proc_dointvec_minmax_conv_param param = {
2418 .min = (int *) table->extra1,
2419 .max = (int *) table->extra2,
2420 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002421 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 do_proc_dointvec_minmax_conv, &param);
2423}
2424
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002425static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 void __user *buffer,
2427 size_t *lenp, loff_t *ppos,
2428 unsigned long convmul,
2429 unsigned long convdiv)
2430{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002431 unsigned long *i, *min, *max;
2432 int vleft, first = 1, err = 0;
2433 unsigned long page = 0;
2434 size_t left;
2435 char *kbuf;
2436
2437 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 *lenp = 0;
2439 return 0;
2440 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002441
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002442 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 min = (unsigned long *) table->extra1;
2444 max = (unsigned long *) table->extra2;
2445 vleft = table->maxlen / sizeof(unsigned long);
2446 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002447
2448 if (write) {
2449 if (left > PAGE_SIZE - 1)
2450 left = PAGE_SIZE - 1;
2451 page = __get_free_page(GFP_TEMPORARY);
2452 kbuf = (char *) page;
2453 if (!kbuf)
2454 return -ENOMEM;
2455 if (copy_from_user(kbuf, buffer, left)) {
2456 err = -EFAULT;
2457 goto free;
2458 }
2459 kbuf[left] = 0;
2460 }
2461
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 for (; left && vleft--; i++, min++, max++, first=0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002463 unsigned long val;
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002466 bool neg;
2467
2468 left -= proc_skip_spaces(&kbuf);
2469
2470 err = proc_get_long(&kbuf, &left, &val, &neg,
2471 proc_wspace_sep,
2472 sizeof(proc_wspace_sep), NULL);
2473 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 break;
2475 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 continue;
2477 if ((min && val < *min) || (max && val > *max))
2478 continue;
2479 *i = val;
2480 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002481 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002483 err = proc_put_char(&buffer, &left, '\t');
2484 err = proc_put_long(&buffer, &left, val, false);
2485 if (err)
2486 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 }
2488 }
2489
Amerigo Wang00b7c332010-05-05 00:26:45 +00002490 if (!write && !first && left && !err)
2491 err = proc_put_char(&buffer, &left, '\n');
2492 if (write && !err)
2493 left -= proc_skip_spaces(&kbuf);
2494free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002496 free_page(page);
2497 if (first)
2498 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 *lenp -= left;
2501 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002502 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503}
2504
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002505static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002506 void __user *buffer,
2507 size_t *lenp, loff_t *ppos,
2508 unsigned long convmul,
2509 unsigned long convdiv)
2510{
2511 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002512 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002513}
2514
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515/**
2516 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2517 * @table: the sysctl table
2518 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 * @buffer: the user buffer
2520 * @lenp: the size of the user buffer
2521 * @ppos: file position
2522 *
2523 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2524 * values from/to the user buffer, treated as an ASCII string.
2525 *
2526 * This routine will ensure the values are within the range specified by
2527 * table->extra1 (min) and table->extra2 (max).
2528 *
2529 * Returns 0 on success.
2530 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002531int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 void __user *buffer, size_t *lenp, loff_t *ppos)
2533{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002534 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537/**
2538 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2539 * @table: the sysctl table
2540 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 * @buffer: the user buffer
2542 * @lenp: the size of the user buffer
2543 * @ppos: file position
2544 *
2545 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2546 * values from/to the user buffer, treated as an ASCII string. The values
2547 * are treated as milliseconds, and converted to jiffies when they are stored.
2548 *
2549 * This routine will ensure the values are within the range specified by
2550 * table->extra1 (min) and table->extra2 (max).
2551 *
2552 * Returns 0 on success.
2553 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002554int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 void __user *buffer,
2556 size_t *lenp, loff_t *ppos)
2557{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002558 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 lenp, ppos, HZ, 1000l);
2560}
2561
2562
Amerigo Wang00b7c332010-05-05 00:26:45 +00002563static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 int *valp,
2565 int write, void *data)
2566{
2567 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002568 if (*lvalp > LONG_MAX / HZ)
2569 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2571 } else {
2572 int val = *valp;
2573 unsigned long lval;
2574 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002575 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 lval = (unsigned long)-val;
2577 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002578 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 lval = (unsigned long)val;
2580 }
2581 *lvalp = lval / HZ;
2582 }
2583 return 0;
2584}
2585
Amerigo Wang00b7c332010-05-05 00:26:45 +00002586static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 int *valp,
2588 int write, void *data)
2589{
2590 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002591 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2592 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2594 } else {
2595 int val = *valp;
2596 unsigned long lval;
2597 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002598 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 lval = (unsigned long)-val;
2600 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002601 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 lval = (unsigned long)val;
2603 }
2604 *lvalp = jiffies_to_clock_t(lval);
2605 }
2606 return 0;
2607}
2608
Amerigo Wang00b7c332010-05-05 00:26:45 +00002609static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 int *valp,
2611 int write, void *data)
2612{
2613 if (write) {
2614 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2615 } else {
2616 int val = *valp;
2617 unsigned long lval;
2618 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002619 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 lval = (unsigned long)-val;
2621 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002622 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 lval = (unsigned long)val;
2624 }
2625 *lvalp = jiffies_to_msecs(lval);
2626 }
2627 return 0;
2628}
2629
2630/**
2631 * proc_dointvec_jiffies - read a vector of integers as seconds
2632 * @table: the sysctl table
2633 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 * @buffer: the user buffer
2635 * @lenp: the size of the user buffer
2636 * @ppos: file position
2637 *
2638 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2639 * values from/to the user buffer, treated as an ASCII string.
2640 * The values read are assumed to be in seconds, and are converted into
2641 * jiffies.
2642 *
2643 * Returns 0 on success.
2644 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002645int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 void __user *buffer, size_t *lenp, loff_t *ppos)
2647{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002648 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 do_proc_dointvec_jiffies_conv,NULL);
2650}
2651
2652/**
2653 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2654 * @table: the sysctl table
2655 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 * @buffer: the user buffer
2657 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002658 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 *
2660 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2661 * values from/to the user buffer, treated as an ASCII string.
2662 * The values read are assumed to be in 1/USER_HZ seconds, and
2663 * are converted into jiffies.
2664 *
2665 * Returns 0 on success.
2666 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002667int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 void __user *buffer, size_t *lenp, loff_t *ppos)
2669{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002670 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 do_proc_dointvec_userhz_jiffies_conv,NULL);
2672}
2673
2674/**
2675 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2676 * @table: the sysctl table
2677 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 * @buffer: the user buffer
2679 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002680 * @ppos: file position
2681 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 *
2683 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2684 * values from/to the user buffer, treated as an ASCII string.
2685 * The values read are assumed to be in 1/1000 seconds, and
2686 * are converted into jiffies.
2687 *
2688 * Returns 0 on success.
2689 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002690int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 void __user *buffer, size_t *lenp, loff_t *ppos)
2692{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002693 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 do_proc_dointvec_ms_jiffies_conv, NULL);
2695}
2696
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002697static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002698 void __user *buffer, size_t *lenp, loff_t *ppos)
2699{
2700 struct pid *new_pid;
2701 pid_t tmp;
2702 int r;
2703
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002704 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002705
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002706 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002707 lenp, ppos, NULL, NULL);
2708 if (r || !write)
2709 return r;
2710
2711 new_pid = find_get_pid(tmp);
2712 if (!new_pid)
2713 return -ESRCH;
2714
2715 put_pid(xchg(&cad_pid, new_pid));
2716 return 0;
2717}
2718
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002719/**
2720 * proc_do_large_bitmap - read/write from/to a large bitmap
2721 * @table: the sysctl table
2722 * @write: %TRUE if this is a write to the sysctl file
2723 * @buffer: the user buffer
2724 * @lenp: the size of the user buffer
2725 * @ppos: file position
2726 *
2727 * The bitmap is stored at table->data and the bitmap length (in bits)
2728 * in table->maxlen.
2729 *
2730 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2731 * large bitmaps may be represented in a compact manner. Writing into
2732 * the file will clear the bitmap then update it with the given input.
2733 *
2734 * Returns 0 on success.
2735 */
2736int proc_do_large_bitmap(struct ctl_table *table, int write,
2737 void __user *buffer, size_t *lenp, loff_t *ppos)
2738{
2739 int err = 0;
2740 bool first = 1;
2741 size_t left = *lenp;
2742 unsigned long bitmap_len = table->maxlen;
2743 unsigned long *bitmap = (unsigned long *) table->data;
2744 unsigned long *tmp_bitmap = NULL;
2745 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2746
2747 if (!bitmap_len || !left || (*ppos && !write)) {
2748 *lenp = 0;
2749 return 0;
2750 }
2751
2752 if (write) {
2753 unsigned long page = 0;
2754 char *kbuf;
2755
2756 if (left > PAGE_SIZE - 1)
2757 left = PAGE_SIZE - 1;
2758
2759 page = __get_free_page(GFP_TEMPORARY);
2760 kbuf = (char *) page;
2761 if (!kbuf)
2762 return -ENOMEM;
2763 if (copy_from_user(kbuf, buffer, left)) {
2764 free_page(page);
2765 return -EFAULT;
2766 }
2767 kbuf[left] = 0;
2768
2769 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2770 GFP_KERNEL);
2771 if (!tmp_bitmap) {
2772 free_page(page);
2773 return -ENOMEM;
2774 }
2775 proc_skip_char(&kbuf, &left, '\n');
2776 while (!err && left) {
2777 unsigned long val_a, val_b;
2778 bool neg;
2779
2780 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2781 sizeof(tr_a), &c);
2782 if (err)
2783 break;
2784 if (val_a >= bitmap_len || neg) {
2785 err = -EINVAL;
2786 break;
2787 }
2788
2789 val_b = val_a;
2790 if (left) {
2791 kbuf++;
2792 left--;
2793 }
2794
2795 if (c == '-') {
2796 err = proc_get_long(&kbuf, &left, &val_b,
2797 &neg, tr_b, sizeof(tr_b),
2798 &c);
2799 if (err)
2800 break;
2801 if (val_b >= bitmap_len || neg ||
2802 val_a > val_b) {
2803 err = -EINVAL;
2804 break;
2805 }
2806 if (left) {
2807 kbuf++;
2808 left--;
2809 }
2810 }
2811
2812 while (val_a <= val_b)
2813 set_bit(val_a++, tmp_bitmap);
2814
2815 first = 0;
2816 proc_skip_char(&kbuf, &left, '\n');
2817 }
2818 free_page(page);
2819 } else {
2820 unsigned long bit_a, bit_b = 0;
2821
2822 while (left) {
2823 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2824 if (bit_a >= bitmap_len)
2825 break;
2826 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2827 bit_a + 1) - 1;
2828
2829 if (!first) {
2830 err = proc_put_char(&buffer, &left, ',');
2831 if (err)
2832 break;
2833 }
2834 err = proc_put_long(&buffer, &left, bit_a, false);
2835 if (err)
2836 break;
2837 if (bit_a != bit_b) {
2838 err = proc_put_char(&buffer, &left, '-');
2839 if (err)
2840 break;
2841 err = proc_put_long(&buffer, &left, bit_b, false);
2842 if (err)
2843 break;
2844 }
2845
2846 first = 0; bit_b++;
2847 }
2848 if (!err)
2849 err = proc_put_char(&buffer, &left, '\n');
2850 }
2851
2852 if (!err) {
2853 if (write) {
2854 if (*ppos)
2855 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2856 else
2857 memcpy(bitmap, tmp_bitmap,
2858 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2859 }
2860 kfree(tmp_bitmap);
2861 *lenp -= left;
2862 *ppos += *lenp;
2863 return 0;
2864 } else {
2865 kfree(tmp_bitmap);
2866 return err;
2867 }
2868}
2869
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870#else /* CONFIG_PROC_FS */
2871
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002872int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 void __user *buffer, size_t *lenp, loff_t *ppos)
2874{
2875 return -ENOSYS;
2876}
2877
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002878int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 void __user *buffer, size_t *lenp, loff_t *ppos)
2880{
2881 return -ENOSYS;
2882}
2883
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002884int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 void __user *buffer, size_t *lenp, loff_t *ppos)
2886{
2887 return -ENOSYS;
2888}
2889
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002890int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 void __user *buffer, size_t *lenp, loff_t *ppos)
2892{
2893 return -ENOSYS;
2894}
2895
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002896int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 void __user *buffer, size_t *lenp, loff_t *ppos)
2898{
2899 return -ENOSYS;
2900}
2901
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002902int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 void __user *buffer, size_t *lenp, loff_t *ppos)
2904{
2905 return -ENOSYS;
2906}
2907
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002908int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 void __user *buffer, size_t *lenp, loff_t *ppos)
2910{
2911 return -ENOSYS;
2912}
2913
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002914int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 void __user *buffer,
2916 size_t *lenp, loff_t *ppos)
2917{
2918 return -ENOSYS;
2919}
2920
2921
2922#endif /* CONFIG_PROC_FS */
2923
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924/*
2925 * No sense putting this after each symbol definition, twice,
2926 * exception granted :-)
2927 */
2928EXPORT_SYMBOL(proc_dointvec);
2929EXPORT_SYMBOL(proc_dointvec_jiffies);
2930EXPORT_SYMBOL(proc_dointvec_minmax);
2931EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2932EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2933EXPORT_SYMBOL(proc_dostring);
2934EXPORT_SYMBOL(proc_doulongvec_minmax);
2935EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2936EXPORT_SYMBOL(register_sysctl_table);
Eric W. Biederman29e796f2007-11-30 23:50:18 +11002937EXPORT_SYMBOL(register_sysctl_paths);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938EXPORT_SYMBOL(unregister_sysctl_table);