blob: 5b0f18c12800ee79f588764b241d42ecfeb969a4 [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>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070026#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080027#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080028#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070030#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020032#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66#include <asm/uaccess.h>
67#include <asm/processor.h>
68
Andi Kleen29cbc782006-09-30 01:47:55 +020069#ifdef CONFIG_X86
70#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010071#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010072#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020073#endif
David Howellsd550bbd2012-03-28 18:30:03 +010074#ifdef CONFIG_SPARC
75#include <asm/setup.h>
76#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080077#ifdef CONFIG_BSD_PROCESS_ACCT
78#include <linux/acct.h>
79#endif
Dave Young4f0e0562010-03-10 15:24:09 -080080#ifdef CONFIG_RT_MUTEXES
81#include <linux/rtmutex.h>
82#endif
Dave Young2edf5e42010-03-10 15:24:10 -080083#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
84#include <linux/lockdep.h>
85#endif
Dave Young15485a42010-03-10 15:24:07 -080086#ifdef CONFIG_CHR_DEV_SG
87#include <scsi/sg.h>
88#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020089
Don Zickus58687ac2010-05-07 17:11:44 -040090#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050091#include <linux/nmi.h>
92#endif
93
Eric W. Biederman7058cb02007-10-18 03:05:58 -070094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#if defined(CONFIG_SYSCTL)
96
97/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098extern int sysctl_overcommit_memory;
99extern int sysctl_overcommit_ratio;
100extern int max_threads;
Alan Coxd6e71142005-06-23 00:09:43 -0700101extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700102#ifdef CONFIG_COREDUMP
103extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700105extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700106#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200110extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100111extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400112extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000113#ifndef CONFIG_MMU
114extern int sysctl_nr_trim_pages;
115#endif
Jens Axboecb684b52009-09-15 21:53:11 +0200116#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +0200117extern int blk_iopoll_enabled;
Jens Axboecb684b52009-09-15 21:53:11 +0200118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400121#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122static int sixty = 60;
Dimitri Sivanich9383d962008-05-12 21:21:14 +0200123static int neg_one = -1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124#endif
125
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700126static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700127static int __maybe_unused one = 1;
128static int __maybe_unused two = 2;
Petr Holasekcb16e952011-03-23 16:43:09 -0700129static int __maybe_unused three = 3;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800130static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700131static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700132#ifdef CONFIG_PRINTK
133static int ten_thousand = 10000;
134#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700135
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700136/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
137static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
140static int maxolduid = 65535;
141static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800142static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700145static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Dave Youngd14f1722010-02-25 20:28:57 -0500147#ifdef CONFIG_INOTIFY_USER
148#include <linux/inotify.h>
149#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700150#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151#endif
152
David S. Miller08714202008-11-16 23:49:24 -0800153#ifdef CONFIG_SPARC64
154extern int sysctl_tsb_ratio;
155#endif
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#ifdef __hppa__
158extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530159#endif
160
161#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162extern int unaligned_enabled;
163#endif
164
Jes Sorensend2b176e2006-02-28 09:42:23 -0800165#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800166extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800167#endif
168
Vineet Guptab6fca722013-01-09 20:06:28 +0530169#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
170extern int no_unaligned_warning;
171#endif
172
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700173#ifdef CONFIG_PROC_SYSCTL
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700174static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700175 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700176static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800177 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700178#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700179
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700180#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700181static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700182 void __user *buffer, size_t *lenp, loff_t *ppos);
183#endif
184
Kees Cook54b50192012-07-30 14:39:18 -0700185static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
186 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700187#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700188static int proc_dostring_coredump(struct ctl_table *table, int write,
189 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700190#endif
Kees Cook54b50192012-07-30 14:39:18 -0700191
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700192#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800193/* Note: sysrq code uses it's own private copy */
194static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700195
196static int sysrq_sysctl_handler(ctl_table *table, int write,
197 void __user *buffer, size_t *lenp,
198 loff_t *ppos)
199{
200 int error;
201
202 error = proc_dointvec(table, write, buffer, lenp, ppos);
203 if (error)
204 return error;
205
206 if (write)
207 sysrq_toggle_support(__sysrq_enabled);
208
209 return 0;
210}
211
212#endif
213
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700214static struct ctl_table kern_table[];
215static struct ctl_table vm_table[];
216static struct ctl_table fs_table[];
217static struct ctl_table debug_table[];
218static struct ctl_table dev_table[];
219extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800220#ifdef CONFIG_EPOLL
221extern struct ctl_table epoll_table[];
222#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
225int sysctl_legacy_va_layout;
226#endif
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228/* The default sysctl tables: */
229
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800230static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 .procname = "kernel",
233 .mode = 0555,
234 .child = kern_table,
235 },
236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "vm",
238 .mode = 0555,
239 .child = vm_table,
240 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .procname = "fs",
243 .mode = 0555,
244 .child = fs_table,
245 },
246 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .procname = "debug",
248 .mode = 0555,
249 .child = debug_table,
250 },
251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 .procname = "dev",
253 .mode = 0555,
254 .child = dev_table,
255 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700256 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257};
258
Ingo Molnar77e54a12007-07-09 18:52:00 +0200259#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100260static int min_sched_granularity_ns = 100000; /* 100 usecs */
261static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
262static int min_wakeup_granularity_ns; /* 0 usecs */
263static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200264#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100265static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
266static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200267#endif /* CONFIG_SMP */
268#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200269
Mel Gorman5e771902010-05-24 14:32:31 -0700270#ifdef CONFIG_COMPACTION
271static int min_extfrag_threshold;
272static int max_extfrag_threshold = 1000;
273#endif
274
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700275static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200276 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200277 .procname = "sched_child_runs_first",
278 .data = &sysctl_sched_child_runs_first,
279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800281 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200282 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200283#ifdef CONFIG_SCHED_DEBUG
284 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100285 .procname = "sched_min_granularity_ns",
286 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800289 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292 },
293 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200294 .procname = "sched_latency_ns",
295 .data = &sysctl_sched_latency,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800298 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
301 },
302 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200303 .procname = "sched_wakeup_granularity_ns",
304 .data = &sysctl_sched_wakeup_granularity,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800307 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200308 .extra1 = &min_wakeup_granularity_ns,
309 .extra2 = &max_wakeup_granularity_ns,
310 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200311#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200312 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100313 .procname = "sched_tunable_scaling",
314 .data = &sysctl_sched_tunable_scaling,
315 .maxlen = sizeof(enum sched_tunable_scaling),
316 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800317 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100318 .extra1 = &min_sched_tunable_scaling,
319 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200320 },
321 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900322 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200323 .data = &sysctl_sched_migration_cost,
324 .maxlen = sizeof(unsigned int),
325 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800326 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200327 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100328 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100329 .procname = "sched_nr_migrate",
330 .data = &sysctl_sched_nr_migrate,
331 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800333 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100334 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530335 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900336 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200337 .data = &sysctl_sched_time_avg,
338 .maxlen = sizeof(unsigned int),
339 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800340 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200341 },
342 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900343 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800344 .data = &sysctl_sched_shares_window,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
347 .proc_handler = proc_dointvec,
348 },
349 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530350 .procname = "timer_migration",
351 .data = &sysctl_timer_migration,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800354 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530355 .extra1 = &zero,
356 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530357 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200358#endif /* CONFIG_SMP */
359#ifdef CONFIG_NUMA_BALANCING
360 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200361 .procname = "numa_balancing_scan_delay_ms",
362 .data = &sysctl_numa_balancing_scan_delay,
363 .maxlen = sizeof(unsigned int),
364 .mode = 0644,
365 .proc_handler = proc_dointvec,
366 },
367 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200368 .procname = "numa_balancing_scan_period_min_ms",
369 .data = &sysctl_numa_balancing_scan_period_min,
370 .maxlen = sizeof(unsigned int),
371 .mode = 0644,
372 .proc_handler = proc_dointvec,
373 },
374 {
Mel Gormanb8593bf2012-11-21 01:18:23 +0000375 .procname = "numa_balancing_scan_period_reset",
376 .data = &sysctl_numa_balancing_scan_period_reset,
377 .maxlen = sizeof(unsigned int),
378 .mode = 0644,
379 .proc_handler = proc_dointvec,
380 },
381 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200382 .procname = "numa_balancing_scan_period_max_ms",
383 .data = &sysctl_numa_balancing_scan_period_max,
384 .maxlen = sizeof(unsigned int),
385 .mode = 0644,
386 .proc_handler = proc_dointvec,
387 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200388 {
389 .procname = "numa_balancing_scan_size_mb",
390 .data = &sysctl_numa_balancing_scan_size,
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
393 .proc_handler = proc_dointvec,
394 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200395#endif /* CONFIG_NUMA_BALANCING */
396#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200397 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100398 .procname = "sched_rt_period_us",
399 .data = &sysctl_sched_rt_period,
400 .maxlen = sizeof(unsigned int),
401 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800402 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100403 },
404 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100405 .procname = "sched_rt_runtime_us",
406 .data = &sysctl_sched_rt_runtime,
407 .maxlen = sizeof(int),
408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800409 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100410 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600411 {
412 .procname = "sched_rr_timeslice_ms",
413 .data = &sched_rr_timeslice,
414 .maxlen = sizeof(int),
415 .mode = 0644,
416 .proc_handler = sched_rr_handler,
417 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100418#ifdef CONFIG_SCHED_AUTOGROUP
419 {
420 .procname = "sched_autogroup_enabled",
421 .data = &sysctl_sched_autogroup_enabled,
422 .maxlen = sizeof(unsigned int),
423 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800424 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100425 .extra1 = &zero,
426 .extra2 = &one,
427 },
428#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700429#ifdef CONFIG_CFS_BANDWIDTH
430 {
431 .procname = "sched_cfs_bandwidth_slice_us",
432 .data = &sysctl_sched_cfs_bandwidth_slice,
433 .maxlen = sizeof(unsigned int),
434 .mode = 0644,
435 .proc_handler = proc_dointvec_minmax,
436 .extra1 = &one,
437 },
438#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700439#ifdef CONFIG_PROVE_LOCKING
440 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700441 .procname = "prove_locking",
442 .data = &prove_locking,
443 .maxlen = sizeof(int),
444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800445 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700446 },
447#endif
448#ifdef CONFIG_LOCK_STAT
449 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700450 .procname = "lock_stat",
451 .data = &lock_stat,
452 .maxlen = sizeof(int),
453 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800454 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700455 },
456#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200457 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 .procname = "panic",
459 .data = &panic_timeout,
460 .maxlen = sizeof(int),
461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800462 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 },
Alex Kelly046d6622012-10-04 17:15:23 -0700464#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 .procname = "core_uses_pid",
467 .data = &core_uses_pid,
468 .maxlen = sizeof(int),
469 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800470 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 },
472 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .procname = "core_pattern",
474 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700475 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700477 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 },
Neil Hormana2939802009-09-23 15:56:56 -0700479 {
Neil Hormana2939802009-09-23 15:56:56 -0700480 .procname = "core_pipe_limit",
481 .data = &core_pipe_limit,
482 .maxlen = sizeof(unsigned int),
483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800484 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700485 },
Alex Kelly046d6622012-10-04 17:15:23 -0700486#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800487#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700490 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800491 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800492 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800494#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100495#ifdef CONFIG_LATENCYTOP
496 {
497 .procname = "latencytop",
498 .data = &latencytop_enabled,
499 .maxlen = sizeof(int),
500 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800501 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100502 },
503#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504#ifdef CONFIG_BLK_DEV_INITRD
505 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 .procname = "real-root-dev",
507 .data = &real_root_dev,
508 .maxlen = sizeof(int),
509 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800510 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 },
512#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700513 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700514 .procname = "print-fatal-signals",
515 .data = &print_fatal_signals,
516 .maxlen = sizeof(int),
517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800518 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700519 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700520#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .procname = "reboot-cmd",
523 .data = reboot_command,
524 .maxlen = 256,
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
528 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 .procname = "stop-a",
530 .data = &stop_a_enabled,
531 .maxlen = sizeof (int),
532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800533 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 },
535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 .procname = "scons-poweroff",
537 .data = &scons_pwroff,
538 .maxlen = sizeof (int),
539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800540 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 },
542#endif
David S. Miller08714202008-11-16 23:49:24 -0800543#ifdef CONFIG_SPARC64
544 {
David S. Miller08714202008-11-16 23:49:24 -0800545 .procname = "tsb-ratio",
546 .data = &sysctl_tsb_ratio,
547 .maxlen = sizeof (int),
548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800549 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800550 },
551#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552#ifdef __hppa__
553 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 .procname = "soft-power",
555 .data = &pwrsw_enabled,
556 .maxlen = sizeof (int),
557 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800558 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530560#endif
561#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 .procname = "unaligned-trap",
564 .data = &unaligned_enabled,
565 .maxlen = sizeof (int),
566 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800567 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 },
569#endif
570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .procname = "ctrl-alt-del",
572 .data = &C_A_D,
573 .maxlen = sizeof(int),
574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800575 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400577#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200578 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200579 .procname = "ftrace_enabled",
580 .data = &ftrace_enabled,
581 .maxlen = sizeof(int),
582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800583 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200584 },
585#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500586#ifdef CONFIG_STACK_TRACER
587 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500588 .procname = "stack_tracer_enabled",
589 .data = &stack_tracer_enabled,
590 .maxlen = sizeof(int),
591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800592 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500593 },
594#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400595#ifdef CONFIG_TRACING
596 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100597 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400598 .data = &ftrace_dump_on_oops,
599 .maxlen = sizeof(int),
600 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800601 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400602 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400603 {
604 .procname = "traceoff_on_warning",
605 .data = &__disable_trace_on_warning,
606 .maxlen = sizeof(__disable_trace_on_warning),
607 .mode = 0644,
608 .proc_handler = proc_dointvec,
609 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400610#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200611#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 .procname = "modprobe",
614 .data = &modprobe_path,
615 .maxlen = KMOD_PATH_LEN,
616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800617 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 },
Kees Cook3d433212009-04-02 15:49:29 -0700619 {
Kees Cook3d433212009-04-02 15:49:29 -0700620 .procname = "modules_disabled",
621 .data = &modules_disabled,
622 .maxlen = sizeof(int),
623 .mode = 0644,
624 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800625 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700626 .extra1 = &one,
627 .extra2 = &one,
628 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629#endif
Bill Pemberton3b572b52012-11-19 13:19:29 -0500630
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100633 .data = &uevent_helper,
634 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800636 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 },
Bill Pemberton3b572b52012-11-19 13:19:29 -0500638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#ifdef CONFIG_CHR_DEV_SG
640 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .procname = "sg-big-buff",
642 .data = &sg_big_buff,
643 .maxlen = sizeof (int),
644 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800645 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 },
647#endif
648#ifdef CONFIG_BSD_PROCESS_ACCT
649 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 .procname = "acct",
651 .data = &acct_parm,
652 .maxlen = 3*sizeof(int),
653 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800654 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 },
656#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657#ifdef CONFIG_MAGIC_SYSRQ
658 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800660 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 .maxlen = sizeof (int),
662 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700663 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 },
665#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700666#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700669 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .maxlen = sizeof (int),
671 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800672 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700674#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .procname = "threads-max",
677 .data = &max_threads,
678 .maxlen = sizeof(int),
679 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800680 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 },
682 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 .procname = "random",
684 .mode = 0555,
685 .child = random_table,
686 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 {
Eric Paris17f60a72011-04-01 17:07:50 -0400688 .procname = "usermodehelper",
689 .mode = 0555,
690 .child = usermodehelper_table,
691 },
692 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 .procname = "overflowuid",
694 .data = &overflowuid,
695 .maxlen = sizeof(int),
696 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800697 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .extra1 = &minolduid,
699 .extra2 = &maxolduid,
700 },
701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .procname = "overflowgid",
703 .data = &overflowgid,
704 .maxlen = sizeof(int),
705 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800706 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 .extra1 = &minolduid,
708 .extra2 = &maxolduid,
709 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800710#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711#ifdef CONFIG_MATHEMU
712 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 .procname = "ieee_emulation_warnings",
714 .data = &sysctl_ieee_emulation_warnings,
715 .maxlen = sizeof(int),
716 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800717 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 },
719#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200722 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .maxlen = sizeof(int),
724 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800725 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 },
727#endif
728 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .procname = "pid_max",
730 .data = &pid_max,
731 .maxlen = sizeof (int),
732 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800733 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .extra1 = &pid_max_min,
735 .extra2 = &pid_max_max,
736 },
737 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 .procname = "panic_on_oops",
739 .data = &panic_on_oops,
740 .maxlen = sizeof(int),
741 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800742 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800744#if defined CONFIG_PRINTK
745 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800746 .procname = "printk",
747 .data = &console_loglevel,
748 .maxlen = 4*sizeof(int),
749 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800750 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800751 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700754 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .maxlen = sizeof(int),
756 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800757 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 },
759 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700761 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 .maxlen = sizeof(int),
763 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800764 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 },
Dave Youngaf913222009-09-22 16:43:33 -0700766 {
Dave Youngaf913222009-09-22 16:43:33 -0700767 .procname = "printk_delay",
768 .data = &printk_delay_msec,
769 .maxlen = sizeof(int),
770 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800771 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700772 .extra1 = &zero,
773 .extra2 = &ten_thousand,
774 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800776 .procname = "dmesg_restrict",
777 .data = &dmesg_restrict,
778 .maxlen = sizeof(int),
779 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700780 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800781 .extra1 = &zero,
782 .extra2 = &one,
783 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800784 {
785 .procname = "kptr_restrict",
786 .data = &kptr_restrict,
787 .maxlen = sizeof(int),
788 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700789 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800790 .extra1 = &zero,
791 .extra2 = &two,
792 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800793#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 .procname = "ngroups_max",
796 .data = &ngroups_max,
797 .maxlen = sizeof (int),
798 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 },
Dan Ballard73efc032011-10-31 17:11:20 -0700801 {
802 .procname = "cap_last_cap",
803 .data = (void *)&cap_last_cap,
804 .maxlen = sizeof(int),
805 .mode = 0444,
806 .proc_handler = proc_dointvec,
807 },
Don Zickus58687ac2010-05-07 17:11:44 -0400808#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500809 {
Don Zickus58687ac2010-05-07 17:11:44 -0400810 .procname = "watchdog",
811 .data = &watchdog_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500812 .maxlen = sizeof (int),
813 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700814 .proc_handler = proc_dowatchdog,
815 .extra1 = &zero,
816 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400817 },
818 {
819 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700820 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400821 .maxlen = sizeof(int),
822 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700823 .proc_handler = proc_dowatchdog,
Don Zickus58687ac2010-05-07 17:11:44 -0400824 .extra1 = &neg_one,
825 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500826 },
Don Zickus2508ce12010-05-07 17:11:46 -0400827 {
828 .procname = "softlockup_panic",
829 .data = &softlockup_panic,
830 .maxlen = sizeof(int),
831 .mode = 0644,
832 .proc_handler = proc_dointvec_minmax,
833 .extra1 = &zero,
834 .extra2 = &one,
835 },
Don Zickus5dc30552010-11-29 17:07:17 -0500836 {
837 .procname = "nmi_watchdog",
838 .data = &watchdog_enabled,
839 .maxlen = sizeof (int),
840 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700841 .proc_handler = proc_dowatchdog,
842 .extra1 = &zero,
843 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500844 },
845#endif
846#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
847 {
848 .procname = "unknown_nmi_panic",
849 .data = &unknown_nmi_panic,
850 .maxlen = sizeof (int),
851 .mode = 0644,
852 .proc_handler = proc_dointvec,
853 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500854#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855#if defined(CONFIG_X86)
856 {
Don Zickus8da5add2006-09-26 10:52:27 +0200857 .procname = "panic_on_unrecovered_nmi",
858 .data = &panic_on_unrecovered_nmi,
859 .maxlen = sizeof(int),
860 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800861 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200862 },
863 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700864 .procname = "panic_on_io_nmi",
865 .data = &panic_on_io_nmi,
866 .maxlen = sizeof(int),
867 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800868 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700869 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900870#ifdef CONFIG_DEBUG_STACKOVERFLOW
871 {
872 .procname = "panic_on_stackoverflow",
873 .data = &sysctl_panic_on_stackoverflow,
874 .maxlen = sizeof(int),
875 .mode = 0644,
876 .proc_handler = proc_dointvec,
877 },
878#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700879 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 .procname = "bootloader_type",
881 .data = &bootloader_type,
882 .maxlen = sizeof (int),
883 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800884 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100886 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700887 .procname = "bootloader_version",
888 .data = &bootloader_version,
889 .maxlen = sizeof (int),
890 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800891 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700892 },
893 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100894 .procname = "kstack_depth_to_print",
895 .data = &kstack_depth_to_print,
896 .maxlen = sizeof(int),
897 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800898 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100899 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100900 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100901 .procname = "io_delay_type",
902 .data = &io_delay_type,
903 .maxlen = sizeof(int),
904 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800905 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100906 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800908#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 .procname = "randomize_va_space",
911 .data = &randomize_va_space,
912 .maxlen = sizeof(int),
913 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800914 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800916#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800917#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700918 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700919 .procname = "spin_retry",
920 .data = &spin_retry,
921 .maxlen = sizeof (int),
922 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800923 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700924 },
925#endif
Len Brown673d5b42007-07-28 03:33:16 -0400926#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800927 {
Pavel Machekc255d842006-02-20 18:27:58 -0800928 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700929 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800930 .maxlen = sizeof (unsigned long),
931 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800932 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800933 },
934#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530935#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -0800936 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800937 .procname = "ignore-unaligned-usertrap",
938 .data = &no_unaligned_warning,
939 .maxlen = sizeof (int),
940 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800941 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800942 },
Vineet Guptab6fca722013-01-09 20:06:28 +0530943#endif
944#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800945 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800946 .procname = "unaligned-dump-stack",
947 .data = &unaligned_dump_stack,
948 .maxlen = sizeof (int),
949 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800950 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800951 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800952#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800953#ifdef CONFIG_DETECT_HUNG_TASK
954 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800955 .procname = "hung_task_panic",
956 .data = &sysctl_hung_task_panic,
957 .maxlen = sizeof(int),
958 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800959 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800960 .extra1 = &zero,
961 .extra2 = &one,
962 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100963 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100964 .procname = "hung_task_check_count",
965 .data = &sysctl_hung_task_check_count,
Ingo Molnar90739082008-01-25 21:08:34 +0100966 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100967 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800968 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100969 },
970 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100971 .procname = "hung_task_timeout_secs",
972 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +0100973 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100974 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800975 .proc_handler = proc_dohung_task_timeout_secs,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100976 },
977 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100978 .procname = "hung_task_warnings",
979 .data = &sysctl_hung_task_warnings,
Ingo Molnar90739082008-01-25 21:08:34 +0100980 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100981 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800982 .proc_handler = proc_doulongvec_minmax,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100983 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700984#endif
Andi Kleenbebfa102006-06-26 13:56:52 +0200985#ifdef CONFIG_COMPAT
986 {
Andi Kleenbebfa102006-06-26 13:56:52 +0200987 .procname = "compat-log",
988 .data = &compat_log,
989 .maxlen = sizeof (int),
990 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800991 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +0200992 },
993#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700994#ifdef CONFIG_RT_MUTEXES
995 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -0700996 .procname = "max_lock_depth",
997 .data = &max_lock_depth,
998 .maxlen = sizeof(int),
999 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001000 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001001 },
1002#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001003 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001004 .procname = "poweroff_cmd",
1005 .data = &poweroff_cmd,
1006 .maxlen = POWEROFF_CMD_PATH_LEN,
1007 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001008 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001009 },
David Howells0b77f5b2008-04-29 01:01:32 -07001010#ifdef CONFIG_KEYS
1011 {
David Howells0b77f5b2008-04-29 01:01:32 -07001012 .procname = "keys",
1013 .mode = 0555,
1014 .child = key_sysctls,
1015 },
1016#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001017#ifdef CONFIG_RCU_TORTURE_TEST
1018 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001019 .procname = "rcutorture_runnable",
1020 .data = &rcutorture_runnable,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001024 },
1025#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001026#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001027 /*
1028 * User-space scripts rely on the existence of this file
1029 * as a feature check for perf_events being enabled.
1030 *
1031 * So it's an ABI, do not remove!
1032 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001033 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001034 .procname = "perf_event_paranoid",
1035 .data = &sysctl_perf_event_paranoid,
1036 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001037 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001038 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001039 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001040 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001041 .procname = "perf_event_mlock_kb",
1042 .data = &sysctl_perf_event_mlock,
1043 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001044 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001045 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001046 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001047 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001048 .procname = "perf_event_max_sample_rate",
1049 .data = &sysctl_perf_event_sample_rate,
1050 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001051 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001052 .proc_handler = perf_proc_update_handler,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001053 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001054#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001055#ifdef CONFIG_KMEMCHECK
1056 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001057 .procname = "kmemcheck",
1058 .data = &kmemcheck_enabled,
1059 .maxlen = sizeof(int),
1060 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001061 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001062 },
1063#endif
Jens Axboecb684b52009-09-15 21:53:11 +02001064#ifdef CONFIG_BLOCK
Jens Axboe5e605b62009-08-05 09:07:21 +02001065 {
Jens Axboe5e605b62009-08-05 09:07:21 +02001066 .procname = "blk_iopoll",
1067 .data = &blk_iopoll_enabled,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = proc_dointvec,
Jens Axboe5e605b62009-08-05 09:07:21 +02001071 },
Jens Axboecb684b52009-09-15 21:53:11 +02001072#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001073 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074};
1075
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001076static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 .procname = "overcommit_memory",
1079 .data = &sysctl_overcommit_memory,
1080 .maxlen = sizeof(sysctl_overcommit_memory),
1081 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001082 .proc_handler = proc_dointvec_minmax,
1083 .extra1 = &zero,
1084 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 },
1086 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001087 .procname = "panic_on_oom",
1088 .data = &sysctl_panic_on_oom,
1089 .maxlen = sizeof(sysctl_panic_on_oom),
1090 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001091 .proc_handler = proc_dointvec_minmax,
1092 .extra1 = &zero,
1093 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001094 },
1095 {
David Rientjesfe071d72007-10-16 23:25:56 -07001096 .procname = "oom_kill_allocating_task",
1097 .data = &sysctl_oom_kill_allocating_task,
1098 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1099 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001100 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001101 },
1102 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001103 .procname = "oom_dump_tasks",
1104 .data = &sysctl_oom_dump_tasks,
1105 .maxlen = sizeof(sysctl_oom_dump_tasks),
1106 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001107 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001108 },
1109 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .procname = "overcommit_ratio",
1111 .data = &sysctl_overcommit_ratio,
1112 .maxlen = sizeof(sysctl_overcommit_ratio),
1113 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001114 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 },
1116 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 .procname = "page-cluster",
1118 .data = &page_cluster,
1119 .maxlen = sizeof(int),
1120 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001121 .proc_handler = proc_dointvec_minmax,
1122 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 },
1124 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 .procname = "dirty_background_ratio",
1126 .data = &dirty_background_ratio,
1127 .maxlen = sizeof(dirty_background_ratio),
1128 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001129 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 .extra1 = &zero,
1131 .extra2 = &one_hundred,
1132 },
1133 {
David Rientjes2da02992009-01-06 14:39:31 -08001134 .procname = "dirty_background_bytes",
1135 .data = &dirty_background_bytes,
1136 .maxlen = sizeof(dirty_background_bytes),
1137 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001138 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001139 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001140 },
1141 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 .procname = "dirty_ratio",
1143 .data = &vm_dirty_ratio,
1144 .maxlen = sizeof(vm_dirty_ratio),
1145 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001146 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 .extra1 = &zero,
1148 .extra2 = &one_hundred,
1149 },
1150 {
David Rientjes2da02992009-01-06 14:39:31 -08001151 .procname = "dirty_bytes",
1152 .data = &vm_dirty_bytes,
1153 .maxlen = sizeof(vm_dirty_bytes),
1154 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001155 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001156 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001157 },
1158 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001160 .data = &dirty_writeback_interval,
1161 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001163 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 },
1165 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001167 .data = &dirty_expire_interval,
1168 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001170 .proc_handler = proc_dointvec_minmax,
1171 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 },
1173 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001174 .procname = "nr_pdflush_threads",
1175 .mode = 0444 /* read-only */,
1176 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 },
1178 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 .procname = "swappiness",
1180 .data = &vm_swappiness,
1181 .maxlen = sizeof(vm_swappiness),
1182 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001183 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 .extra1 = &zero,
1185 .extra2 = &one_hundred,
1186 },
1187#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001188 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001190 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 .maxlen = sizeof(unsigned long),
1192 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001193 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 .extra1 = (void *)&hugetlb_zero,
1195 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001196 },
1197#ifdef CONFIG_NUMA
1198 {
1199 .procname = "nr_hugepages_mempolicy",
1200 .data = NULL,
1201 .maxlen = sizeof(unsigned long),
1202 .mode = 0644,
1203 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1204 .extra1 = (void *)&hugetlb_zero,
1205 .extra2 = (void *)&hugetlb_infinity,
1206 },
1207#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 .procname = "hugetlb_shm_group",
1210 .data = &sysctl_hugetlb_shm_group,
1211 .maxlen = sizeof(gid_t),
1212 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001213 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 },
Mel Gorman396faf02007-07-17 04:03:13 -07001215 {
Mel Gorman396faf02007-07-17 04:03:13 -07001216 .procname = "hugepages_treat_as_movable",
1217 .data = &hugepages_treat_as_movable,
1218 .maxlen = sizeof(int),
1219 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001220 .proc_handler = hugetlb_treat_movable_handler,
Mel Gorman396faf02007-07-17 04:03:13 -07001221 },
Adam Litke54f9f802007-10-16 01:26:20 -07001222 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001223 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001224 .data = NULL,
1225 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001226 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001227 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001228 .extra1 = (void *)&hugetlb_zero,
1229 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001230 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231#endif
1232 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 .procname = "lowmem_reserve_ratio",
1234 .data = &sysctl_lowmem_reserve_ratio,
1235 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1236 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001237 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 },
1239 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001240 .procname = "drop_caches",
1241 .data = &sysctl_drop_caches,
1242 .maxlen = sizeof(int),
1243 .mode = 0644,
1244 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001245 .extra1 = &one,
1246 .extra2 = &three,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001247 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001248#ifdef CONFIG_COMPACTION
1249 {
1250 .procname = "compact_memory",
1251 .data = &sysctl_compact_memory,
1252 .maxlen = sizeof(int),
1253 .mode = 0200,
1254 .proc_handler = sysctl_compaction_handler,
1255 },
Mel Gorman5e771902010-05-24 14:32:31 -07001256 {
1257 .procname = "extfrag_threshold",
1258 .data = &sysctl_extfrag_threshold,
1259 .maxlen = sizeof(int),
1260 .mode = 0644,
1261 .proc_handler = sysctl_extfrag_handler,
1262 .extra1 = &min_extfrag_threshold,
1263 .extra2 = &max_extfrag_threshold,
1264 },
1265
Mel Gorman76ab0f52010-05-24 14:32:28 -07001266#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001267 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 .procname = "min_free_kbytes",
1269 .data = &min_free_kbytes,
1270 .maxlen = sizeof(min_free_kbytes),
1271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001272 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 .extra1 = &zero,
1274 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001275 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001276 .procname = "percpu_pagelist_fraction",
1277 .data = &percpu_pagelist_fraction,
1278 .maxlen = sizeof(percpu_pagelist_fraction),
1279 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001280 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001281 .extra1 = &min_percpu_pagelist_fract,
1282 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283#ifdef CONFIG_MMU
1284 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 .procname = "max_map_count",
1286 .data = &sysctl_max_map_count,
1287 .maxlen = sizeof(sysctl_max_map_count),
1288 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001289 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001290 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001292#else
1293 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001294 .procname = "nr_trim_pages",
1295 .data = &sysctl_nr_trim_pages,
1296 .maxlen = sizeof(sysctl_nr_trim_pages),
1297 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001298 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001299 .extra1 = &zero,
1300 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301#endif
1302 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 .procname = "laptop_mode",
1304 .data = &laptop_mode,
1305 .maxlen = sizeof(laptop_mode),
1306 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001307 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 },
1309 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 .procname = "block_dump",
1311 .data = &block_dump,
1312 .maxlen = sizeof(block_dump),
1313 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001314 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 .extra1 = &zero,
1316 },
1317 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 .procname = "vfs_cache_pressure",
1319 .data = &sysctl_vfs_cache_pressure,
1320 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1321 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001322 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 .extra1 = &zero,
1324 },
1325#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1326 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 .procname = "legacy_va_layout",
1328 .data = &sysctl_legacy_va_layout,
1329 .maxlen = sizeof(sysctl_legacy_va_layout),
1330 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001331 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 .extra1 = &zero,
1333 },
1334#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001335#ifdef CONFIG_NUMA
1336 {
Christoph Lameter17436602006-01-18 17:42:32 -08001337 .procname = "zone_reclaim_mode",
1338 .data = &zone_reclaim_mode,
1339 .maxlen = sizeof(zone_reclaim_mode),
1340 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001341 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001342 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001343 },
Christoph Lameter96146342006-07-03 00:24:13 -07001344 {
Christoph Lameter96146342006-07-03 00:24:13 -07001345 .procname = "min_unmapped_ratio",
1346 .data = &sysctl_min_unmapped_ratio,
1347 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001349 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001350 .extra1 = &zero,
1351 .extra2 = &one_hundred,
1352 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001353 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001354 .procname = "min_slab_ratio",
1355 .data = &sysctl_min_slab_ratio,
1356 .maxlen = sizeof(sysctl_min_slab_ratio),
1357 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001358 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001359 .extra1 = &zero,
1360 .extra2 = &one_hundred,
1361 },
Christoph Lameter17436602006-01-18 17:42:32 -08001362#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001363#ifdef CONFIG_SMP
1364 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001365 .procname = "stat_interval",
1366 .data = &sysctl_stat_interval,
1367 .maxlen = sizeof(sysctl_stat_interval),
1368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001369 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001370 },
1371#endif
David Howells6e141542009-12-15 19:27:45 +00001372#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001373 {
Eric Parised032182007-06-28 15:55:21 -04001374 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001375 .data = &dac_mmap_min_addr,
1376 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001377 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001378 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001379 },
David Howells6e141542009-12-15 19:27:45 +00001380#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001381#ifdef CONFIG_NUMA
1382 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001383 .procname = "numa_zonelist_order",
1384 .data = &numa_zonelist_order,
1385 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001388 },
1389#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001390#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001391 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001392 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001393 .procname = "vdso_enabled",
1394 .data = &vdso_enabled,
1395 .maxlen = sizeof(vdso_enabled),
1396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001397 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001398 .extra1 = &zero,
1399 },
1400#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001401#ifdef CONFIG_HIGHMEM
1402 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001403 .procname = "highmem_is_dirtyable",
1404 .data = &vm_highmem_is_dirtyable,
1405 .maxlen = sizeof(vm_highmem_is_dirtyable),
1406 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001407 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001408 .extra1 = &zero,
1409 .extra2 = &one,
1410 },
1411#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001412 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001413 .procname = "scan_unevictable_pages",
1414 .data = &scan_unevictable_pages,
1415 .maxlen = sizeof(scan_unevictable_pages),
1416 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001417 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001418 },
Andi Kleen6a460792009-09-16 11:50:15 +02001419#ifdef CONFIG_MEMORY_FAILURE
1420 {
Andi Kleen6a460792009-09-16 11:50:15 +02001421 .procname = "memory_failure_early_kill",
1422 .data = &sysctl_memory_failure_early_kill,
1423 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001425 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001426 .extra1 = &zero,
1427 .extra2 = &one,
1428 },
1429 {
Andi Kleen6a460792009-09-16 11:50:15 +02001430 .procname = "memory_failure_recovery",
1431 .data = &sysctl_memory_failure_recovery,
1432 .maxlen = sizeof(sysctl_memory_failure_recovery),
1433 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001434 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001435 .extra1 = &zero,
1436 .extra2 = &one,
1437 },
1438#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001439 {
1440 .procname = "user_reserve_kbytes",
1441 .data = &sysctl_user_reserve_kbytes,
1442 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1443 .mode = 0644,
1444 .proc_handler = proc_doulongvec_minmax,
1445 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001446 {
1447 .procname = "admin_reserve_kbytes",
1448 .data = &sysctl_admin_reserve_kbytes,
1449 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1450 .mode = 0644,
1451 .proc_handler = proc_doulongvec_minmax,
1452 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001453 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454};
1455
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001456#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001457static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001458 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001459};
1460#endif
1461
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001462static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 .procname = "inode-nr",
1465 .data = &inodes_stat,
1466 .maxlen = 2*sizeof(int),
1467 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001468 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 },
1470 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 .procname = "inode-state",
1472 .data = &inodes_stat,
1473 .maxlen = 7*sizeof(int),
1474 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001475 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 },
1477 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 .procname = "file-nr",
1479 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001480 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001482 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 },
1484 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 .procname = "file-max",
1486 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001487 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001489 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 },
1491 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001492 .procname = "nr_open",
1493 .data = &sysctl_nr_open,
1494 .maxlen = sizeof(int),
1495 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001496 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001497 .extra1 = &sysctl_nr_open_min,
1498 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001499 },
1500 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 .procname = "dentry-state",
1502 .data = &dentry_stat,
1503 .maxlen = 6*sizeof(int),
1504 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001505 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 },
1507 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 .procname = "overflowuid",
1509 .data = &fs_overflowuid,
1510 .maxlen = sizeof(int),
1511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001512 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 .extra1 = &minolduid,
1514 .extra2 = &maxolduid,
1515 },
1516 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 .procname = "overflowgid",
1518 .data = &fs_overflowgid,
1519 .maxlen = sizeof(int),
1520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001521 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 .extra1 = &minolduid,
1523 .extra2 = &maxolduid,
1524 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001525#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 .procname = "leases-enable",
1528 .data = &leases_enable,
1529 .maxlen = sizeof(int),
1530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001531 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001533#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534#ifdef CONFIG_DNOTIFY
1535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 .procname = "dir-notify-enable",
1537 .data = &dir_notify_enable,
1538 .maxlen = sizeof(int),
1539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001540 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 },
1542#endif
1543#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001544#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 .procname = "lease-break-time",
1547 .data = &lease_break_time,
1548 .maxlen = sizeof(int),
1549 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001550 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001552#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001553#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 .procname = "aio-nr",
1556 .data = &aio_nr,
1557 .maxlen = sizeof(aio_nr),
1558 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001559 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 },
1561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 .procname = "aio-max-nr",
1563 .data = &aio_max_nr,
1564 .maxlen = sizeof(aio_max_nr),
1565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001566 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001568#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001569#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001570 {
Robert Love0399cb02005-07-13 12:38:18 -04001571 .procname = "inotify",
1572 .mode = 0555,
1573 .child = inotify_table,
1574 },
1575#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001576#ifdef CONFIG_EPOLL
1577 {
1578 .procname = "epoll",
1579 .mode = 0555,
1580 .child = epoll_table,
1581 },
1582#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001584 {
Kees Cook800179c2012-07-25 17:29:07 -07001585 .procname = "protected_symlinks",
1586 .data = &sysctl_protected_symlinks,
1587 .maxlen = sizeof(int),
1588 .mode = 0600,
1589 .proc_handler = proc_dointvec_minmax,
1590 .extra1 = &zero,
1591 .extra2 = &one,
1592 },
1593 {
1594 .procname = "protected_hardlinks",
1595 .data = &sysctl_protected_hardlinks,
1596 .maxlen = sizeof(int),
1597 .mode = 0600,
1598 .proc_handler = proc_dointvec_minmax,
1599 .extra1 = &zero,
1600 .extra2 = &one,
1601 },
1602 {
Alan Coxd6e71142005-06-23 00:09:43 -07001603 .procname = "suid_dumpable",
1604 .data = &suid_dumpable,
1605 .maxlen = sizeof(int),
1606 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001607 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001608 .extra1 = &zero,
1609 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001610 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001611#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1612 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001613 .procname = "binfmt_misc",
1614 .mode = 0555,
1615 .child = binfmt_misc_table,
1616 },
1617#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001618 {
Jens Axboeff9da692010-06-03 14:54:39 +02001619 .procname = "pipe-max-size",
1620 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001621 .maxlen = sizeof(int),
1622 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001623 .proc_handler = &pipe_proc_fn,
1624 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001625 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001626 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627};
1628
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001629static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001630#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001631 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001632 .procname = "exception-trace",
1633 .data = &show_unhandled_signals,
1634 .maxlen = sizeof(int),
1635 .mode = 0644,
1636 .proc_handler = proc_dointvec
1637 },
1638#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001639#if defined(CONFIG_OPTPROBES)
1640 {
1641 .procname = "kprobes-optimization",
1642 .data = &sysctl_kprobes_optimization,
1643 .maxlen = sizeof(int),
1644 .mode = 0644,
1645 .proc_handler = proc_kprobes_optimization_handler,
1646 .extra1 = &zero,
1647 .extra2 = &one,
1648 },
1649#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001650 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651};
1652
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001653static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001654 { }
Robert Love0eeca282005-07-12 17:06:03 -04001655};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001657int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001658{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001659 struct ctl_table_header *hdr;
1660
1661 hdr = register_sysctl_table(sysctl_base_table);
1662 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001663 return 0;
1664}
1665
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001666#endif /* CONFIG_SYSCTL */
1667
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668/*
1669 * /proc/sys support
1670 */
1671
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001672#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001674static int _proc_do_string(void* data, int maxlen, int write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001675 void __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001676 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001677{
1678 size_t len;
1679 char __user *p;
1680 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001681
1682 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001683 *lenp = 0;
1684 return 0;
1685 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001686
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001687 if (write) {
1688 len = 0;
1689 p = buffer;
1690 while (len < *lenp) {
1691 if (get_user(c, p++))
1692 return -EFAULT;
1693 if (c == 0 || c == '\n')
1694 break;
1695 len++;
1696 }
1697 if (len >= maxlen)
1698 len = maxlen-1;
1699 if(copy_from_user(data, buffer, len))
1700 return -EFAULT;
1701 ((char *) data)[len] = 0;
1702 *ppos += *lenp;
1703 } else {
1704 len = strlen(data);
1705 if (len > maxlen)
1706 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001707
1708 if (*ppos > len) {
1709 *lenp = 0;
1710 return 0;
1711 }
1712
1713 data += *ppos;
1714 len -= *ppos;
1715
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001716 if (len > *lenp)
1717 len = *lenp;
1718 if (len)
1719 if(copy_to_user(buffer, data, len))
1720 return -EFAULT;
1721 if (len < *lenp) {
1722 if(put_user('\n', ((char __user *) buffer) + len))
1723 return -EFAULT;
1724 len++;
1725 }
1726 *lenp = len;
1727 *ppos += len;
1728 }
1729 return 0;
1730}
1731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732/**
1733 * proc_dostring - read a string sysctl
1734 * @table: the sysctl table
1735 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 * @buffer: the user buffer
1737 * @lenp: the size of the user buffer
1738 * @ppos: file position
1739 *
1740 * Reads/writes a string from/to the user buffer. If the kernel
1741 * buffer provided is not large enough to hold the string, the
1742 * string is truncated. The copied string is %NULL-terminated.
1743 * If the string is being read by the user process, it is copied
1744 * and a newline '\n' is added. It is truncated if the buffer is
1745 * not large enough.
1746 *
1747 * Returns 0 on success.
1748 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001749int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 void __user *buffer, size_t *lenp, loff_t *ppos)
1751{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001752 return _proc_do_string(table->data, table->maxlen, write,
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001753 buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754}
1755
Amerigo Wang00b7c332010-05-05 00:26:45 +00001756static size_t proc_skip_spaces(char **buf)
1757{
1758 size_t ret;
1759 char *tmp = skip_spaces(*buf);
1760 ret = tmp - *buf;
1761 *buf = tmp;
1762 return ret;
1763}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001765static void proc_skip_char(char **buf, size_t *size, const char v)
1766{
1767 while (*size) {
1768 if (**buf != v)
1769 break;
1770 (*size)--;
1771 (*buf)++;
1772 }
1773}
1774
Amerigo Wang00b7c332010-05-05 00:26:45 +00001775#define TMPBUFLEN 22
1776/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001777 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001778 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001779 * @buf: a kernel buffer
1780 * @size: size of the kernel buffer
1781 * @val: this is where the number will be stored
1782 * @neg: set to %TRUE if number is negative
1783 * @perm_tr: a vector which contains the allowed trailers
1784 * @perm_tr_len: size of the perm_tr vector
1785 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001786 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001787 * In case of success %0 is returned and @buf and @size are updated with
1788 * the amount of bytes read. If @tr is non-NULL and a trailing
1789 * character exists (size is non-zero after returning from this
1790 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001791 */
1792static int proc_get_long(char **buf, size_t *size,
1793 unsigned long *val, bool *neg,
1794 const char *perm_tr, unsigned perm_tr_len, char *tr)
1795{
1796 int len;
1797 char *p, tmp[TMPBUFLEN];
1798
1799 if (!*size)
1800 return -EINVAL;
1801
1802 len = *size;
1803 if (len > TMPBUFLEN - 1)
1804 len = TMPBUFLEN - 1;
1805
1806 memcpy(tmp, *buf, len);
1807
1808 tmp[len] = 0;
1809 p = tmp;
1810 if (*p == '-' && *size > 1) {
1811 *neg = true;
1812 p++;
1813 } else
1814 *neg = false;
1815 if (!isdigit(*p))
1816 return -EINVAL;
1817
1818 *val = simple_strtoul(p, &p, 0);
1819
1820 len = p - tmp;
1821
1822 /* We don't know if the next char is whitespace thus we may accept
1823 * invalid integers (e.g. 1234...a) or two integers instead of one
1824 * (e.g. 123...1). So lets not allow such large numbers. */
1825 if (len == TMPBUFLEN - 1)
1826 return -EINVAL;
1827
1828 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1829 return -EINVAL;
1830
1831 if (tr && (len < *size))
1832 *tr = *p;
1833
1834 *buf += len;
1835 *size -= len;
1836
1837 return 0;
1838}
1839
1840/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001841 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001842 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001843 * @buf: the user buffer
1844 * @size: the size of the user buffer
1845 * @val: the integer to be converted
1846 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001847 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001848 * In case of success %0 is returned and @buf and @size are updated with
1849 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001850 */
1851static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1852 bool neg)
1853{
1854 int len;
1855 char tmp[TMPBUFLEN], *p = tmp;
1856
1857 sprintf(p, "%s%lu", neg ? "-" : "", val);
1858 len = strlen(tmp);
1859 if (len > *size)
1860 len = *size;
1861 if (copy_to_user(*buf, tmp, len))
1862 return -EFAULT;
1863 *size -= len;
1864 *buf += len;
1865 return 0;
1866}
1867#undef TMPBUFLEN
1868
1869static int proc_put_char(void __user **buf, size_t *size, char c)
1870{
1871 if (*size) {
1872 char __user **buffer = (char __user **)buf;
1873 if (put_user(c, *buffer))
1874 return -EFAULT;
1875 (*size)--, (*buffer)++;
1876 *buf = *buffer;
1877 }
1878 return 0;
1879}
1880
1881static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 int *valp,
1883 int write, void *data)
1884{
1885 if (write) {
1886 *valp = *negp ? -*lvalp : *lvalp;
1887 } else {
1888 int val = *valp;
1889 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001890 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 *lvalp = (unsigned long)-val;
1892 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001893 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 *lvalp = (unsigned long)val;
1895 }
1896 }
1897 return 0;
1898}
1899
Amerigo Wang00b7c332010-05-05 00:26:45 +00001900static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1901
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001902static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001903 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001904 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001905 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 int write, void *data),
1907 void *data)
1908{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001909 int *i, vleft, first = 1, err = 0;
1910 unsigned long page = 0;
1911 size_t left;
1912 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Amerigo Wang00b7c332010-05-05 00:26:45 +00001914 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 *lenp = 0;
1916 return 0;
1917 }
1918
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001919 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 vleft = table->maxlen / sizeof(*i);
1921 left = *lenp;
1922
1923 if (!conv)
1924 conv = do_proc_dointvec_conv;
1925
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001927 if (left > PAGE_SIZE - 1)
1928 left = PAGE_SIZE - 1;
1929 page = __get_free_page(GFP_TEMPORARY);
1930 kbuf = (char *) page;
1931 if (!kbuf)
1932 return -ENOMEM;
1933 if (copy_from_user(kbuf, buffer, left)) {
1934 err = -EFAULT;
1935 goto free;
1936 }
1937 kbuf[left] = 0;
1938 }
1939
1940 for (; left && vleft--; i++, first=0) {
1941 unsigned long lval;
1942 bool neg;
1943
1944 if (write) {
1945 left -= proc_skip_spaces(&kbuf);
1946
J. R. Okajima563b0462010-05-25 16:10:14 -07001947 if (!left)
1948 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001949 err = proc_get_long(&kbuf, &left, &lval, &neg,
1950 proc_wspace_sep,
1951 sizeof(proc_wspace_sep), NULL);
1952 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001954 if (conv(&neg, &lval, i, 1, data)) {
1955 err = -EINVAL;
1956 break;
1957 }
1958 } else {
1959 if (conv(&neg, &lval, i, 0, data)) {
1960 err = -EINVAL;
1961 break;
1962 }
1963 if (!first)
1964 err = proc_put_char(&buffer, &left, '\t');
1965 if (err)
1966 break;
1967 err = proc_put_long(&buffer, &left, lval, neg);
1968 if (err)
1969 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 }
1971 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00001972
1973 if (!write && !first && left && !err)
1974 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07001975 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00001976 left -= proc_skip_spaces(&kbuf);
1977free:
1978 if (write) {
1979 free_page(page);
1980 if (first)
1981 return err ? : -EINVAL;
1982 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 *lenp -= left;
1984 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001985 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986}
1987
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001988static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001989 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001990 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001991 int write, void *data),
1992 void *data)
1993{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001994 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001995 buffer, lenp, ppos, conv, data);
1996}
1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998/**
1999 * proc_dointvec - read a vector of integers
2000 * @table: the sysctl table
2001 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 * @buffer: the user buffer
2003 * @lenp: the size of the user buffer
2004 * @ppos: file position
2005 *
2006 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2007 * values from/to the user buffer, treated as an ASCII string.
2008 *
2009 * Returns 0 on success.
2010 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002011int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 void __user *buffer, size_t *lenp, loff_t *ppos)
2013{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002014 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 NULL,NULL);
2016}
2017
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002018/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002019 * Taint values can only be increased
2020 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002021 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002022static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002023 void __user *buffer, size_t *lenp, loff_t *ppos)
2024{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002025 struct ctl_table t;
2026 unsigned long tmptaint = get_taint();
2027 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002028
Bastian Blank91fcd412007-04-23 14:41:14 -07002029 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002030 return -EPERM;
2031
Andi Kleen25ddbb12008-10-15 22:01:41 -07002032 t = *table;
2033 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002034 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002035 if (err < 0)
2036 return err;
2037
2038 if (write) {
2039 /*
2040 * Poor man's atomic or. Not worth adding a primitive
2041 * to everyone's atomic.h for this
2042 */
2043 int i;
2044 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2045 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302046 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002047 }
2048 }
2049
2050 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002051}
2052
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002053#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002054static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002055 void __user *buffer, size_t *lenp, loff_t *ppos)
2056{
2057 if (write && !capable(CAP_SYS_ADMIN))
2058 return -EPERM;
2059
2060 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2061}
2062#endif
2063
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064struct do_proc_dointvec_minmax_conv_param {
2065 int *min;
2066 int *max;
2067};
2068
Amerigo Wang00b7c332010-05-05 00:26:45 +00002069static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2070 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 int write, void *data)
2072{
2073 struct do_proc_dointvec_minmax_conv_param *param = data;
2074 if (write) {
2075 int val = *negp ? -*lvalp : *lvalp;
2076 if ((param->min && *param->min > val) ||
2077 (param->max && *param->max < val))
2078 return -EINVAL;
2079 *valp = val;
2080 } else {
2081 int val = *valp;
2082 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002083 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 *lvalp = (unsigned long)-val;
2085 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002086 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 *lvalp = (unsigned long)val;
2088 }
2089 }
2090 return 0;
2091}
2092
2093/**
2094 * proc_dointvec_minmax - read a vector of integers with min/max values
2095 * @table: the sysctl table
2096 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 * @buffer: the user buffer
2098 * @lenp: the size of the user buffer
2099 * @ppos: file position
2100 *
2101 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2102 * values from/to the user buffer, treated as an ASCII string.
2103 *
2104 * This routine will ensure the values are within the range specified by
2105 * table->extra1 (min) and table->extra2 (max).
2106 *
2107 * Returns 0 on success.
2108 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002109int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 void __user *buffer, size_t *lenp, loff_t *ppos)
2111{
2112 struct do_proc_dointvec_minmax_conv_param param = {
2113 .min = (int *) table->extra1,
2114 .max = (int *) table->extra2,
2115 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002116 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 do_proc_dointvec_minmax_conv, &param);
2118}
2119
Kees Cook54b50192012-07-30 14:39:18 -07002120static void validate_coredump_safety(void)
2121{
Alex Kelly046d6622012-10-04 17:15:23 -07002122#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002123 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002124 core_pattern[0] != '/' && core_pattern[0] != '|') {
2125 printk(KERN_WARNING "Unsafe core_pattern used with "\
2126 "suid_dumpable=2. Pipe handler or fully qualified "\
2127 "core dump path required.\n");
2128 }
Alex Kelly046d6622012-10-04 17:15:23 -07002129#endif
Kees Cook54b50192012-07-30 14:39:18 -07002130}
2131
2132static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2133 void __user *buffer, size_t *lenp, loff_t *ppos)
2134{
2135 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2136 if (!error)
2137 validate_coredump_safety();
2138 return error;
2139}
2140
Alex Kelly046d6622012-10-04 17:15:23 -07002141#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002142static int proc_dostring_coredump(struct ctl_table *table, int write,
2143 void __user *buffer, size_t *lenp, loff_t *ppos)
2144{
2145 int error = proc_dostring(table, write, buffer, lenp, ppos);
2146 if (!error)
2147 validate_coredump_safety();
2148 return error;
2149}
Alex Kelly046d6622012-10-04 17:15:23 -07002150#endif
Kees Cook54b50192012-07-30 14:39:18 -07002151
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002152static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 void __user *buffer,
2154 size_t *lenp, loff_t *ppos,
2155 unsigned long convmul,
2156 unsigned long convdiv)
2157{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002158 unsigned long *i, *min, *max;
2159 int vleft, first = 1, err = 0;
2160 unsigned long page = 0;
2161 size_t left;
2162 char *kbuf;
2163
2164 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 *lenp = 0;
2166 return 0;
2167 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002168
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002169 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 min = (unsigned long *) table->extra1;
2171 max = (unsigned long *) table->extra2;
2172 vleft = table->maxlen / sizeof(unsigned long);
2173 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002174
2175 if (write) {
2176 if (left > PAGE_SIZE - 1)
2177 left = PAGE_SIZE - 1;
2178 page = __get_free_page(GFP_TEMPORARY);
2179 kbuf = (char *) page;
2180 if (!kbuf)
2181 return -ENOMEM;
2182 if (copy_from_user(kbuf, buffer, left)) {
2183 err = -EFAULT;
2184 goto free;
2185 }
2186 kbuf[left] = 0;
2187 }
2188
Eric Dumazet27b3d802010-10-07 12:59:29 -07002189 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002190 unsigned long val;
2191
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002193 bool neg;
2194
2195 left -= proc_skip_spaces(&kbuf);
2196
2197 err = proc_get_long(&kbuf, &left, &val, &neg,
2198 proc_wspace_sep,
2199 sizeof(proc_wspace_sep), NULL);
2200 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 break;
2202 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 continue;
2204 if ((min && val < *min) || (max && val > *max))
2205 continue;
2206 *i = val;
2207 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002208 val = convdiv * (*i) / convmul;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 if (!first)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002210 err = proc_put_char(&buffer, &left, '\t');
2211 err = proc_put_long(&buffer, &left, val, false);
2212 if (err)
2213 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 }
2215 }
2216
Amerigo Wang00b7c332010-05-05 00:26:45 +00002217 if (!write && !first && left && !err)
2218 err = proc_put_char(&buffer, &left, '\n');
2219 if (write && !err)
2220 left -= proc_skip_spaces(&kbuf);
2221free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002223 free_page(page);
2224 if (first)
2225 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 *lenp -= left;
2228 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002229 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230}
2231
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002232static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002233 void __user *buffer,
2234 size_t *lenp, loff_t *ppos,
2235 unsigned long convmul,
2236 unsigned long convdiv)
2237{
2238 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002239 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002240}
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242/**
2243 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2244 * @table: the sysctl table
2245 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 * @buffer: the user buffer
2247 * @lenp: the size of the user buffer
2248 * @ppos: file position
2249 *
2250 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2251 * values from/to the user buffer, treated as an ASCII string.
2252 *
2253 * This routine will ensure the values are within the range specified by
2254 * table->extra1 (min) and table->extra2 (max).
2255 *
2256 * Returns 0 on success.
2257 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002258int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 void __user *buffer, size_t *lenp, loff_t *ppos)
2260{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002261 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262}
2263
2264/**
2265 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 * @buffer: the user buffer
2269 * @lenp: the size of the user buffer
2270 * @ppos: file position
2271 *
2272 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2273 * values from/to the user buffer, treated as an ASCII string. The values
2274 * are treated as milliseconds, and converted to jiffies when they are stored.
2275 *
2276 * This routine will ensure the values are within the range specified by
2277 * table->extra1 (min) and table->extra2 (max).
2278 *
2279 * Returns 0 on success.
2280 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002281int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 void __user *buffer,
2283 size_t *lenp, loff_t *ppos)
2284{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002285 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 lenp, ppos, HZ, 1000l);
2287}
2288
2289
Amerigo Wang00b7c332010-05-05 00:26:45 +00002290static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 int *valp,
2292 int write, void *data)
2293{
2294 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002295 if (*lvalp > LONG_MAX / HZ)
2296 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2298 } else {
2299 int val = *valp;
2300 unsigned long lval;
2301 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002302 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 lval = (unsigned long)-val;
2304 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002305 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 lval = (unsigned long)val;
2307 }
2308 *lvalp = lval / HZ;
2309 }
2310 return 0;
2311}
2312
Amerigo Wang00b7c332010-05-05 00:26:45 +00002313static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 int *valp,
2315 int write, void *data)
2316{
2317 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002318 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2319 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2321 } else {
2322 int val = *valp;
2323 unsigned long lval;
2324 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 lval = (unsigned long)-val;
2327 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002328 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 lval = (unsigned long)val;
2330 }
2331 *lvalp = jiffies_to_clock_t(lval);
2332 }
2333 return 0;
2334}
2335
Amerigo Wang00b7c332010-05-05 00:26:45 +00002336static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 int *valp,
2338 int write, void *data)
2339{
2340 if (write) {
2341 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2342 } else {
2343 int val = *valp;
2344 unsigned long lval;
2345 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002346 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 lval = (unsigned long)-val;
2348 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002349 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 lval = (unsigned long)val;
2351 }
2352 *lvalp = jiffies_to_msecs(lval);
2353 }
2354 return 0;
2355}
2356
2357/**
2358 * proc_dointvec_jiffies - read a vector of integers as seconds
2359 * @table: the sysctl table
2360 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 * @buffer: the user buffer
2362 * @lenp: the size of the user buffer
2363 * @ppos: file position
2364 *
2365 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2366 * values from/to the user buffer, treated as an ASCII string.
2367 * The values read are assumed to be in seconds, and are converted into
2368 * jiffies.
2369 *
2370 * Returns 0 on success.
2371 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002372int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 void __user *buffer, size_t *lenp, loff_t *ppos)
2374{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002375 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 do_proc_dointvec_jiffies_conv,NULL);
2377}
2378
2379/**
2380 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2381 * @table: the sysctl table
2382 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 * @buffer: the user buffer
2384 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002385 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 *
2387 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2388 * values from/to the user buffer, treated as an ASCII string.
2389 * The values read are assumed to be in 1/USER_HZ seconds, and
2390 * are converted into jiffies.
2391 *
2392 * Returns 0 on success.
2393 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002394int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 void __user *buffer, size_t *lenp, loff_t *ppos)
2396{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002397 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 do_proc_dointvec_userhz_jiffies_conv,NULL);
2399}
2400
2401/**
2402 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2403 * @table: the sysctl table
2404 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 * @buffer: the user buffer
2406 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002407 * @ppos: file position
2408 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 *
2410 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2411 * values from/to the user buffer, treated as an ASCII string.
2412 * The values read are assumed to be in 1/1000 seconds, and
2413 * are converted into jiffies.
2414 *
2415 * Returns 0 on success.
2416 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002417int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 void __user *buffer, size_t *lenp, loff_t *ppos)
2419{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002420 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 do_proc_dointvec_ms_jiffies_conv, NULL);
2422}
2423
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002424static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002425 void __user *buffer, size_t *lenp, loff_t *ppos)
2426{
2427 struct pid *new_pid;
2428 pid_t tmp;
2429 int r;
2430
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002431 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002432
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002433 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002434 lenp, ppos, NULL, NULL);
2435 if (r || !write)
2436 return r;
2437
2438 new_pid = find_get_pid(tmp);
2439 if (!new_pid)
2440 return -ESRCH;
2441
2442 put_pid(xchg(&cad_pid, new_pid));
2443 return 0;
2444}
2445
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002446/**
2447 * proc_do_large_bitmap - read/write from/to a large bitmap
2448 * @table: the sysctl table
2449 * @write: %TRUE if this is a write to the sysctl file
2450 * @buffer: the user buffer
2451 * @lenp: the size of the user buffer
2452 * @ppos: file position
2453 *
2454 * The bitmap is stored at table->data and the bitmap length (in bits)
2455 * in table->maxlen.
2456 *
2457 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2458 * large bitmaps may be represented in a compact manner. Writing into
2459 * the file will clear the bitmap then update it with the given input.
2460 *
2461 * Returns 0 on success.
2462 */
2463int proc_do_large_bitmap(struct ctl_table *table, int write,
2464 void __user *buffer, size_t *lenp, loff_t *ppos)
2465{
2466 int err = 0;
2467 bool first = 1;
2468 size_t left = *lenp;
2469 unsigned long bitmap_len = table->maxlen;
2470 unsigned long *bitmap = (unsigned long *) table->data;
2471 unsigned long *tmp_bitmap = NULL;
2472 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2473
2474 if (!bitmap_len || !left || (*ppos && !write)) {
2475 *lenp = 0;
2476 return 0;
2477 }
2478
2479 if (write) {
2480 unsigned long page = 0;
2481 char *kbuf;
2482
2483 if (left > PAGE_SIZE - 1)
2484 left = PAGE_SIZE - 1;
2485
2486 page = __get_free_page(GFP_TEMPORARY);
2487 kbuf = (char *) page;
2488 if (!kbuf)
2489 return -ENOMEM;
2490 if (copy_from_user(kbuf, buffer, left)) {
2491 free_page(page);
2492 return -EFAULT;
2493 }
2494 kbuf[left] = 0;
2495
2496 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2497 GFP_KERNEL);
2498 if (!tmp_bitmap) {
2499 free_page(page);
2500 return -ENOMEM;
2501 }
2502 proc_skip_char(&kbuf, &left, '\n');
2503 while (!err && left) {
2504 unsigned long val_a, val_b;
2505 bool neg;
2506
2507 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2508 sizeof(tr_a), &c);
2509 if (err)
2510 break;
2511 if (val_a >= bitmap_len || neg) {
2512 err = -EINVAL;
2513 break;
2514 }
2515
2516 val_b = val_a;
2517 if (left) {
2518 kbuf++;
2519 left--;
2520 }
2521
2522 if (c == '-') {
2523 err = proc_get_long(&kbuf, &left, &val_b,
2524 &neg, tr_b, sizeof(tr_b),
2525 &c);
2526 if (err)
2527 break;
2528 if (val_b >= bitmap_len || neg ||
2529 val_a > val_b) {
2530 err = -EINVAL;
2531 break;
2532 }
2533 if (left) {
2534 kbuf++;
2535 left--;
2536 }
2537 }
2538
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002539 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002540 first = 0;
2541 proc_skip_char(&kbuf, &left, '\n');
2542 }
2543 free_page(page);
2544 } else {
2545 unsigned long bit_a, bit_b = 0;
2546
2547 while (left) {
2548 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2549 if (bit_a >= bitmap_len)
2550 break;
2551 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2552 bit_a + 1) - 1;
2553
2554 if (!first) {
2555 err = proc_put_char(&buffer, &left, ',');
2556 if (err)
2557 break;
2558 }
2559 err = proc_put_long(&buffer, &left, bit_a, false);
2560 if (err)
2561 break;
2562 if (bit_a != bit_b) {
2563 err = proc_put_char(&buffer, &left, '-');
2564 if (err)
2565 break;
2566 err = proc_put_long(&buffer, &left, bit_b, false);
2567 if (err)
2568 break;
2569 }
2570
2571 first = 0; bit_b++;
2572 }
2573 if (!err)
2574 err = proc_put_char(&buffer, &left, '\n');
2575 }
2576
2577 if (!err) {
2578 if (write) {
2579 if (*ppos)
2580 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2581 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002582 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002583 }
2584 kfree(tmp_bitmap);
2585 *lenp -= left;
2586 *ppos += *lenp;
2587 return 0;
2588 } else {
2589 kfree(tmp_bitmap);
2590 return err;
2591 }
2592}
2593
Jovi Zhang55610502011-01-12 17:00:45 -08002594#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002596int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 void __user *buffer, size_t *lenp, loff_t *ppos)
2598{
2599 return -ENOSYS;
2600}
2601
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002602int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 void __user *buffer, size_t *lenp, loff_t *ppos)
2604{
2605 return -ENOSYS;
2606}
2607
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002608int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 void __user *buffer, size_t *lenp, loff_t *ppos)
2610{
2611 return -ENOSYS;
2612}
2613
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002614int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 void __user *buffer, size_t *lenp, loff_t *ppos)
2616{
2617 return -ENOSYS;
2618}
2619
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002620int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 void __user *buffer, size_t *lenp, loff_t *ppos)
2622{
2623 return -ENOSYS;
2624}
2625
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002626int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 void __user *buffer, size_t *lenp, loff_t *ppos)
2628{
2629 return -ENOSYS;
2630}
2631
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002632int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 void __user *buffer, size_t *lenp, loff_t *ppos)
2634{
2635 return -ENOSYS;
2636}
2637
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002638int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 void __user *buffer,
2640 size_t *lenp, loff_t *ppos)
2641{
2642 return -ENOSYS;
2643}
2644
2645
Jovi Zhang55610502011-01-12 17:00:45 -08002646#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648/*
2649 * No sense putting this after each symbol definition, twice,
2650 * exception granted :-)
2651 */
2652EXPORT_SYMBOL(proc_dointvec);
2653EXPORT_SYMBOL(proc_dointvec_jiffies);
2654EXPORT_SYMBOL(proc_dointvec_minmax);
2655EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2656EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2657EXPORT_SYMBOL(proc_dostring);
2658EXPORT_SYMBOL(proc_doulongvec_minmax);
2659EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);