blob: db19e3e2aa4bd000d96af8d3380af60148a01b10 [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>
Kees Cook79847542014-01-23 15:55:59 -080065#include <linux/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include <asm/uaccess.h>
68#include <asm/processor.h>
69
Andi Kleen29cbc782006-09-30 01:47:55 +020070#ifdef CONFIG_X86
71#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010072#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010073#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020074#endif
David Howellsd550bbd2012-03-28 18:30:03 +010075#ifdef CONFIG_SPARC
76#include <asm/setup.h>
77#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080078#ifdef CONFIG_BSD_PROCESS_ACCT
79#include <linux/acct.h>
80#endif
Dave Young4f0e0562010-03-10 15:24:09 -080081#ifdef CONFIG_RT_MUTEXES
82#include <linux/rtmutex.h>
83#endif
Dave Young2edf5e42010-03-10 15:24:10 -080084#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85#include <linux/lockdep.h>
86#endif
Dave Young15485a42010-03-10 15:24:07 -080087#ifdef CONFIG_CHR_DEV_SG
88#include <scsi/sg.h>
89#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020090
Don Zickus58687ac2010-05-07 17:11:44 -040091#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050092#include <linux/nmi.h>
93#endif
94
Eric W. Biederman7058cb02007-10-18 03:05:58 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#if defined(CONFIG_SYSCTL)
97
98/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099extern int max_threads;
Alan Coxd6e71142005-06-23 00:09:43 -0700100extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700101#ifdef CONFIG_COREDUMP
102extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700104extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800108extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200109extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100110extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400111extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000112#ifndef CONFIG_MMU
113extern int sysctl_nr_trim_pages;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400117#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int sixty = 60;
119#endif
120
Aaron Tomlin270750db2014-01-20 17:34:13 +0000121static int __maybe_unused neg_one = -1;
122
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700123static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700124static int __maybe_unused one = 1;
125static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700126static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800127static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700128static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700129#ifdef CONFIG_PRINTK
130static int ten_thousand = 10000;
131#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700132
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700133/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137static int maxolduid = 65535;
138static int minolduid;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800139static int min_percpu_pagelist_fract = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700142static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Liu Hua80df2842014-04-07 15:38:57 -0700144/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
145#ifdef CONFIG_DETECT_HUNG_TASK
146static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
147#endif
148
Dave Youngd14f1722010-02-25 20:28:57 -0500149#ifdef CONFIG_INOTIFY_USER
150#include <linux/inotify.h>
151#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700152#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif
154
David S. Miller08714202008-11-16 23:49:24 -0800155#ifdef CONFIG_SPARC64
156extern int sysctl_tsb_ratio;
157#endif
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#ifdef __hppa__
160extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530161#endif
162
163#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164extern int unaligned_enabled;
165#endif
166
Jes Sorensend2b176e2006-02-28 09:42:23 -0800167#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800168extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800169#endif
170
Vineet Guptab6fca722013-01-09 20:06:28 +0530171#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172extern int no_unaligned_warning;
173#endif
174
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700175#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700176
177#define SYSCTL_WRITES_LEGACY -1
178#define SYSCTL_WRITES_WARN 0
179#define SYSCTL_WRITES_STRICT 1
180
181static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
182
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700183static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700184 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700185static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800186 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700187#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700188
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700189#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700190static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700191 void __user *buffer, size_t *lenp, loff_t *ppos);
192#endif
193
Kees Cook54b50192012-07-30 14:39:18 -0700194static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
195 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700196#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700197static int proc_dostring_coredump(struct ctl_table *table, int write,
198 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700199#endif
Kees Cook54b50192012-07-30 14:39:18 -0700200
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700201#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800202/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100203static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700204
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700205static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700206 void __user *buffer, size_t *lenp,
207 loff_t *ppos)
208{
209 int error;
210
211 error = proc_dointvec(table, write, buffer, lenp, ppos);
212 if (error)
213 return error;
214
215 if (write)
216 sysrq_toggle_support(__sysrq_enabled);
217
218 return 0;
219}
220
221#endif
222
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700223static struct ctl_table kern_table[];
224static struct ctl_table vm_table[];
225static struct ctl_table fs_table[];
226static struct ctl_table debug_table[];
227static struct ctl_table dev_table[];
228extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800229#ifdef CONFIG_EPOLL
230extern struct ctl_table epoll_table[];
231#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
234int sysctl_legacy_va_layout;
235#endif
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237/* The default sysctl tables: */
238
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800239static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .procname = "kernel",
242 .mode = 0555,
243 .child = kern_table,
244 },
245 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .procname = "vm",
247 .mode = 0555,
248 .child = vm_table,
249 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 .procname = "fs",
252 .mode = 0555,
253 .child = fs_table,
254 },
255 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .procname = "debug",
257 .mode = 0555,
258 .child = debug_table,
259 },
260 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 .procname = "dev",
262 .mode = 0555,
263 .child = dev_table,
264 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700265 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266};
267
Ingo Molnar77e54a12007-07-09 18:52:00 +0200268#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100269static int min_sched_granularity_ns = 100000; /* 100 usecs */
270static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
271static int min_wakeup_granularity_ns; /* 0 usecs */
272static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200273#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100274static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
275static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200276#endif /* CONFIG_SMP */
277#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200278
Mel Gorman5e771902010-05-24 14:32:31 -0700279#ifdef CONFIG_COMPACTION
280static int min_extfrag_threshold;
281static int max_extfrag_threshold = 1000;
282#endif
283
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700284static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200285 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200286 .procname = "sched_child_runs_first",
287 .data = &sysctl_sched_child_runs_first,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800290 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200291 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292#ifdef CONFIG_SCHED_DEBUG
293 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100294 .procname = "sched_min_granularity_ns",
295 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800298 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100299 .extra1 = &min_sched_granularity_ns,
300 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200301 },
302 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200303 .procname = "sched_latency_ns",
304 .data = &sysctl_sched_latency,
305 .maxlen = sizeof(unsigned int),
306 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800307 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200308 .extra1 = &min_sched_granularity_ns,
309 .extra2 = &max_sched_granularity_ns,
310 },
311 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200312 .procname = "sched_wakeup_granularity_ns",
313 .data = &sysctl_sched_wakeup_granularity,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800316 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200317 .extra1 = &min_wakeup_granularity_ns,
318 .extra2 = &max_wakeup_granularity_ns,
319 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200320#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200321 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100322 .procname = "sched_tunable_scaling",
323 .data = &sysctl_sched_tunable_scaling,
324 .maxlen = sizeof(enum sched_tunable_scaling),
325 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800326 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100327 .extra1 = &min_sched_tunable_scaling,
328 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200329 },
330 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900331 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200332 .data = &sysctl_sched_migration_cost,
333 .maxlen = sizeof(unsigned int),
334 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800335 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200336 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100337 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100338 .procname = "sched_nr_migrate",
339 .data = &sysctl_sched_nr_migrate,
340 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100341 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800342 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100343 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530344 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900345 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200346 .data = &sysctl_sched_time_avg,
347 .maxlen = sizeof(unsigned int),
348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800349 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200350 },
351 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900352 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800353 .data = &sysctl_sched_shares_window,
354 .maxlen = sizeof(unsigned int),
355 .mode = 0644,
356 .proc_handler = proc_dointvec,
357 },
358 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530359 .procname = "timer_migration",
360 .data = &sysctl_timer_migration,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800363 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530364 .extra1 = &zero,
365 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530366 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200367#endif /* CONFIG_SMP */
368#ifdef CONFIG_NUMA_BALANCING
369 {
Peter Zijlstra4b96a29b2012-10-25 14:16:47 +0200370 .procname = "numa_balancing_scan_delay_ms",
371 .data = &sysctl_numa_balancing_scan_delay,
372 .maxlen = sizeof(unsigned int),
373 .mode = 0644,
374 .proc_handler = proc_dointvec,
375 },
376 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200377 .procname = "numa_balancing_scan_period_min_ms",
378 .data = &sysctl_numa_balancing_scan_period_min,
379 .maxlen = sizeof(unsigned int),
380 .mode = 0644,
381 .proc_handler = proc_dointvec,
382 },
383 {
384 .procname = "numa_balancing_scan_period_max_ms",
385 .data = &sysctl_numa_balancing_scan_period_max,
386 .maxlen = sizeof(unsigned int),
387 .mode = 0644,
388 .proc_handler = proc_dointvec,
389 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200390 {
391 .procname = "numa_balancing_scan_size_mb",
392 .data = &sysctl_numa_balancing_scan_size,
393 .maxlen = sizeof(unsigned int),
394 .mode = 0644,
395 .proc_handler = proc_dointvec,
396 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100397 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800398 .procname = "numa_balancing",
399 .data = NULL, /* filled in by handler */
400 .maxlen = sizeof(unsigned int),
401 .mode = 0644,
402 .proc_handler = sysctl_numa_balancing,
403 .extra1 = &zero,
404 .extra2 = &one,
405 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200406#endif /* CONFIG_NUMA_BALANCING */
407#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200408 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100409 .procname = "sched_rt_period_us",
410 .data = &sysctl_sched_rt_period,
411 .maxlen = sizeof(unsigned int),
412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800413 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100414 },
415 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100416 .procname = "sched_rt_runtime_us",
417 .data = &sysctl_sched_rt_runtime,
418 .maxlen = sizeof(int),
419 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800420 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100421 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600422 {
423 .procname = "sched_rr_timeslice_ms",
424 .data = &sched_rr_timeslice,
425 .maxlen = sizeof(int),
426 .mode = 0644,
427 .proc_handler = sched_rr_handler,
428 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100429#ifdef CONFIG_SCHED_AUTOGROUP
430 {
431 .procname = "sched_autogroup_enabled",
432 .data = &sysctl_sched_autogroup_enabled,
433 .maxlen = sizeof(unsigned int),
434 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800435 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100436 .extra1 = &zero,
437 .extra2 = &one,
438 },
439#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700440#ifdef CONFIG_CFS_BANDWIDTH
441 {
442 .procname = "sched_cfs_bandwidth_slice_us",
443 .data = &sysctl_sched_cfs_bandwidth_slice,
444 .maxlen = sizeof(unsigned int),
445 .mode = 0644,
446 .proc_handler = proc_dointvec_minmax,
447 .extra1 = &one,
448 },
449#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700450#ifdef CONFIG_PROVE_LOCKING
451 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700452 .procname = "prove_locking",
453 .data = &prove_locking,
454 .maxlen = sizeof(int),
455 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800456 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700457 },
458#endif
459#ifdef CONFIG_LOCK_STAT
460 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700461 .procname = "lock_stat",
462 .data = &lock_stat,
463 .maxlen = sizeof(int),
464 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800465 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700466 },
467#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200468 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 .procname = "panic",
470 .data = &panic_timeout,
471 .maxlen = sizeof(int),
472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800473 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 },
Alex Kelly046d6622012-10-04 17:15:23 -0700475#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .procname = "core_uses_pid",
478 .data = &core_uses_pid,
479 .maxlen = sizeof(int),
480 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800481 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 },
483 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 .procname = "core_pattern",
485 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700486 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700488 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 },
Neil Hormana2939802009-09-23 15:56:56 -0700490 {
Neil Hormana2939802009-09-23 15:56:56 -0700491 .procname = "core_pipe_limit",
492 .data = &core_pipe_limit,
493 .maxlen = sizeof(unsigned int),
494 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800495 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700496 },
Alex Kelly046d6622012-10-04 17:15:23 -0700497#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800498#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700501 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800502 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800503 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700505 {
506 .procname = "sysctl_writes_strict",
507 .data = &sysctl_writes_strict,
508 .maxlen = sizeof(int),
509 .mode = 0644,
510 .proc_handler = proc_dointvec_minmax,
511 .extra1 = &neg_one,
512 .extra2 = &one,
513 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800514#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100515#ifdef CONFIG_LATENCYTOP
516 {
517 .procname = "latencytop",
518 .data = &latencytop_enabled,
519 .maxlen = sizeof(int),
520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800521 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100522 },
523#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524#ifdef CONFIG_BLK_DEV_INITRD
525 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 .procname = "real-root-dev",
527 .data = &real_root_dev,
528 .maxlen = sizeof(int),
529 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800530 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 },
532#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700533 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700534 .procname = "print-fatal-signals",
535 .data = &print_fatal_signals,
536 .maxlen = sizeof(int),
537 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800538 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700539 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700540#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 .procname = "reboot-cmd",
543 .data = reboot_command,
544 .maxlen = 256,
545 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800546 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 },
548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 .procname = "stop-a",
550 .data = &stop_a_enabled,
551 .maxlen = sizeof (int),
552 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800553 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 },
555 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 .procname = "scons-poweroff",
557 .data = &scons_pwroff,
558 .maxlen = sizeof (int),
559 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800560 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 },
562#endif
David S. Miller08714202008-11-16 23:49:24 -0800563#ifdef CONFIG_SPARC64
564 {
David S. Miller08714202008-11-16 23:49:24 -0800565 .procname = "tsb-ratio",
566 .data = &sysctl_tsb_ratio,
567 .maxlen = sizeof (int),
568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800569 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800570 },
571#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#ifdef __hppa__
573 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .procname = "soft-power",
575 .data = &pwrsw_enabled,
576 .maxlen = sizeof (int),
577 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800578 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530580#endif
581#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 .procname = "unaligned-trap",
584 .data = &unaligned_enabled,
585 .maxlen = sizeof (int),
586 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800587 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 },
589#endif
590 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 .procname = "ctrl-alt-del",
592 .data = &C_A_D,
593 .maxlen = sizeof(int),
594 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800595 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400597#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200598 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200599 .procname = "ftrace_enabled",
600 .data = &ftrace_enabled,
601 .maxlen = sizeof(int),
602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800603 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200604 },
605#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500606#ifdef CONFIG_STACK_TRACER
607 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500608 .procname = "stack_tracer_enabled",
609 .data = &stack_tracer_enabled,
610 .maxlen = sizeof(int),
611 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800612 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500613 },
614#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400615#ifdef CONFIG_TRACING
616 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100617 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400618 .data = &ftrace_dump_on_oops,
619 .maxlen = sizeof(int),
620 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800621 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400622 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400623 {
624 .procname = "traceoff_on_warning",
625 .data = &__disable_trace_on_warning,
626 .maxlen = sizeof(__disable_trace_on_warning),
627 .mode = 0644,
628 .proc_handler = proc_dointvec,
629 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400630#endif
Kees Cook79847542014-01-23 15:55:59 -0800631#ifdef CONFIG_KEXEC
632 {
633 .procname = "kexec_load_disabled",
634 .data = &kexec_load_disabled,
635 .maxlen = sizeof(int),
636 .mode = 0644,
637 /* only handle a transition from default "0" to "1" */
638 .proc_handler = proc_dointvec_minmax,
639 .extra1 = &one,
640 .extra2 = &one,
641 },
642#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200643#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 .procname = "modprobe",
646 .data = &modprobe_path,
647 .maxlen = KMOD_PATH_LEN,
648 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800649 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 },
Kees Cook3d433212009-04-02 15:49:29 -0700651 {
Kees Cook3d433212009-04-02 15:49:29 -0700652 .procname = "modules_disabled",
653 .data = &modules_disabled,
654 .maxlen = sizeof(int),
655 .mode = 0644,
656 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800657 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700658 .extra1 = &one,
659 .extra2 = &one,
660 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700662#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100665 .data = &uevent_helper,
666 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800668 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 },
Michael Marineau86d56132014-04-10 14:09:31 -0700670#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671#ifdef CONFIG_CHR_DEV_SG
672 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 .procname = "sg-big-buff",
674 .data = &sg_big_buff,
675 .maxlen = sizeof (int),
676 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800677 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 },
679#endif
680#ifdef CONFIG_BSD_PROCESS_ACCT
681 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 .procname = "acct",
683 .data = &acct_parm,
684 .maxlen = 3*sizeof(int),
685 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800686 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 },
688#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689#ifdef CONFIG_MAGIC_SYSRQ
690 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800692 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 .maxlen = sizeof (int),
694 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700695 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 },
697#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700698#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700701 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .maxlen = sizeof (int),
703 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800704 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700706#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 .procname = "threads-max",
709 .data = &max_threads,
710 .maxlen = sizeof(int),
711 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800712 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 },
714 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 .procname = "random",
716 .mode = 0555,
717 .child = random_table,
718 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 {
Eric Paris17f60a72011-04-01 17:07:50 -0400720 .procname = "usermodehelper",
721 .mode = 0555,
722 .child = usermodehelper_table,
723 },
724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .procname = "overflowuid",
726 .data = &overflowuid,
727 .maxlen = sizeof(int),
728 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800729 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 .extra1 = &minolduid,
731 .extra2 = &maxolduid,
732 },
733 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .procname = "overflowgid",
735 .data = &overflowgid,
736 .maxlen = sizeof(int),
737 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800738 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .extra1 = &minolduid,
740 .extra2 = &maxolduid,
741 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800742#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743#ifdef CONFIG_MATHEMU
744 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .procname = "ieee_emulation_warnings",
746 .data = &sysctl_ieee_emulation_warnings,
747 .maxlen = sizeof(int),
748 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800749 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 },
751#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200754 .data = &show_unhandled_signals,
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,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 },
759#endif
760 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 .procname = "pid_max",
762 .data = &pid_max,
763 .maxlen = sizeof (int),
764 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800765 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 .extra1 = &pid_max_min,
767 .extra2 = &pid_max_max,
768 },
769 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 .procname = "panic_on_oops",
771 .data = &panic_on_oops,
772 .maxlen = sizeof(int),
773 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800774 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800776#if defined CONFIG_PRINTK
777 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800778 .procname = "printk",
779 .data = &console_loglevel,
780 .maxlen = 4*sizeof(int),
781 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800782 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800783 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700786 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .maxlen = sizeof(int),
788 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800789 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 },
791 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700793 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .maxlen = sizeof(int),
795 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800796 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 },
Dave Youngaf913222009-09-22 16:43:33 -0700798 {
Dave Youngaf913222009-09-22 16:43:33 -0700799 .procname = "printk_delay",
800 .data = &printk_delay_msec,
801 .maxlen = sizeof(int),
802 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800803 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700804 .extra1 = &zero,
805 .extra2 = &ten_thousand,
806 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800808 .procname = "dmesg_restrict",
809 .data = &dmesg_restrict,
810 .maxlen = sizeof(int),
811 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700812 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800813 .extra1 = &zero,
814 .extra2 = &one,
815 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800816 {
817 .procname = "kptr_restrict",
818 .data = &kptr_restrict,
819 .maxlen = sizeof(int),
820 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700821 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800822 .extra1 = &zero,
823 .extra2 = &two,
824 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800825#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800826 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 .procname = "ngroups_max",
828 .data = &ngroups_max,
829 .maxlen = sizeof (int),
830 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800831 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 },
Dan Ballard73efc032011-10-31 17:11:20 -0700833 {
834 .procname = "cap_last_cap",
835 .data = (void *)&cap_last_cap,
836 .maxlen = sizeof(int),
837 .mode = 0444,
838 .proc_handler = proc_dointvec,
839 },
Don Zickus58687ac2010-05-07 17:11:44 -0400840#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500841 {
Don Zickus58687ac2010-05-07 17:11:44 -0400842 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200843 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500844 .maxlen = sizeof (int),
845 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700846 .proc_handler = proc_dowatchdog,
847 .extra1 = &zero,
848 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400849 },
850 {
851 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700852 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400853 .maxlen = sizeof(int),
854 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700855 .proc_handler = proc_dowatchdog,
Li Zefana6572f82013-05-17 10:31:04 +0800856 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400857 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500858 },
Don Zickus2508ce12010-05-07 17:11:46 -0400859 {
860 .procname = "softlockup_panic",
861 .data = &softlockup_panic,
862 .maxlen = sizeof(int),
863 .mode = 0644,
864 .proc_handler = proc_dointvec_minmax,
865 .extra1 = &zero,
866 .extra2 = &one,
867 },
Don Zickus5dc30552010-11-29 17:07:17 -0500868 {
869 .procname = "nmi_watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200870 .data = &watchdog_user_enabled,
Don Zickus5dc30552010-11-29 17:07:17 -0500871 .maxlen = sizeof (int),
872 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700873 .proc_handler = proc_dowatchdog,
874 .extra1 = &zero,
875 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500876 },
877#endif
878#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
879 {
880 .procname = "unknown_nmi_panic",
881 .data = &unknown_nmi_panic,
882 .maxlen = sizeof (int),
883 .mode = 0644,
884 .proc_handler = proc_dointvec,
885 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500886#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887#if defined(CONFIG_X86)
888 {
Don Zickus8da5add2006-09-26 10:52:27 +0200889 .procname = "panic_on_unrecovered_nmi",
890 .data = &panic_on_unrecovered_nmi,
891 .maxlen = sizeof(int),
892 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800893 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200894 },
895 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700896 .procname = "panic_on_io_nmi",
897 .data = &panic_on_io_nmi,
898 .maxlen = sizeof(int),
899 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800900 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700901 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900902#ifdef CONFIG_DEBUG_STACKOVERFLOW
903 {
904 .procname = "panic_on_stackoverflow",
905 .data = &sysctl_panic_on_stackoverflow,
906 .maxlen = sizeof(int),
907 .mode = 0644,
908 .proc_handler = proc_dointvec,
909 },
910#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700911 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 .procname = "bootloader_type",
913 .data = &bootloader_type,
914 .maxlen = sizeof (int),
915 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800916 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100918 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700919 .procname = "bootloader_version",
920 .data = &bootloader_version,
921 .maxlen = sizeof (int),
922 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800923 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700924 },
925 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100926 .procname = "kstack_depth_to_print",
927 .data = &kstack_depth_to_print,
928 .maxlen = sizeof(int),
929 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800930 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100931 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100932 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100933 .procname = "io_delay_type",
934 .data = &io_delay_type,
935 .maxlen = sizeof(int),
936 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800937 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100938 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800940#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 .procname = "randomize_va_space",
943 .data = &randomize_va_space,
944 .maxlen = sizeof(int),
945 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800946 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800948#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800949#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700950 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700951 .procname = "spin_retry",
952 .data = &spin_retry,
953 .maxlen = sizeof (int),
954 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800955 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700956 },
957#endif
Len Brown673d5b42007-07-28 03:33:16 -0400958#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800959 {
Pavel Machekc255d842006-02-20 18:27:58 -0800960 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700961 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800962 .maxlen = sizeof (unsigned long),
963 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800964 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800965 },
966#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530967#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -0800968 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800969 .procname = "ignore-unaligned-usertrap",
970 .data = &no_unaligned_warning,
971 .maxlen = sizeof (int),
972 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800973 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800974 },
Vineet Guptab6fca722013-01-09 20:06:28 +0530975#endif
976#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800977 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800978 .procname = "unaligned-dump-stack",
979 .data = &unaligned_dump_stack,
980 .maxlen = sizeof (int),
981 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800982 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800983 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800984#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800985#ifdef CONFIG_DETECT_HUNG_TASK
986 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800987 .procname = "hung_task_panic",
988 .data = &sysctl_hung_task_panic,
989 .maxlen = sizeof(int),
990 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800991 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800992 .extra1 = &zero,
993 .extra2 = &one,
994 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100995 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100996 .procname = "hung_task_check_count",
997 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +0800998 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +0100999 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001000 .proc_handler = proc_dointvec_minmax,
1001 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001002 },
1003 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001004 .procname = "hung_task_timeout_secs",
1005 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001006 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001007 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001008 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001009 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001010 },
1011 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001012 .procname = "hung_task_warnings",
1013 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001014 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001015 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001016 .proc_handler = proc_dointvec_minmax,
1017 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001018 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001019#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001020#ifdef CONFIG_COMPAT
1021 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001022 .procname = "compat-log",
1023 .data = &compat_log,
1024 .maxlen = sizeof (int),
1025 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001026 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001027 },
1028#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001029#ifdef CONFIG_RT_MUTEXES
1030 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001031 .procname = "max_lock_depth",
1032 .data = &max_lock_depth,
1033 .maxlen = sizeof(int),
1034 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001035 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001036 },
1037#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001038 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001039 .procname = "poweroff_cmd",
1040 .data = &poweroff_cmd,
1041 .maxlen = POWEROFF_CMD_PATH_LEN,
1042 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001043 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001044 },
David Howells0b77f5b2008-04-29 01:01:32 -07001045#ifdef CONFIG_KEYS
1046 {
David Howells0b77f5b2008-04-29 01:01:32 -07001047 .procname = "keys",
1048 .mode = 0555,
1049 .child = key_sysctls,
1050 },
1051#endif
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001052#ifdef CONFIG_RCU_TORTURE_TEST
1053 {
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001054 .procname = "rcutorture_runnable",
1055 .data = &rcutorture_runnable,
1056 .maxlen = sizeof(int),
1057 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001058 .proc_handler = proc_dointvec,
Paul E. McKenney31a72bc2008-06-18 09:26:49 -07001059 },
1060#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001061#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001062 /*
1063 * User-space scripts rely on the existence of this file
1064 * as a feature check for perf_events being enabled.
1065 *
1066 * So it's an ABI, do not remove!
1067 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001068 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001069 .procname = "perf_event_paranoid",
1070 .data = &sysctl_perf_event_paranoid,
1071 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001072 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001073 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001074 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001075 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001076 .procname = "perf_event_mlock_kb",
1077 .data = &sysctl_perf_event_mlock,
1078 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001079 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001080 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001081 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001082 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001083 .procname = "perf_event_max_sample_rate",
1084 .data = &sysctl_perf_event_sample_rate,
1085 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001086 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001087 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001088 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001089 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001090 {
1091 .procname = "perf_cpu_time_max_percent",
1092 .data = &sysctl_perf_cpu_time_max_percent,
1093 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1094 .mode = 0644,
1095 .proc_handler = perf_cpu_time_max_percent_handler,
1096 .extra1 = &zero,
1097 .extra2 = &one_hundred,
1098 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001099#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001100#ifdef CONFIG_KMEMCHECK
1101 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001102 .procname = "kmemcheck",
1103 .data = &kmemcheck_enabled,
1104 .maxlen = sizeof(int),
1105 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001106 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001107 },
1108#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001109 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110};
1111
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001112static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 .procname = "overcommit_memory",
1115 .data = &sysctl_overcommit_memory,
1116 .maxlen = sizeof(sysctl_overcommit_memory),
1117 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001118 .proc_handler = proc_dointvec_minmax,
1119 .extra1 = &zero,
1120 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 },
1122 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001123 .procname = "panic_on_oom",
1124 .data = &sysctl_panic_on_oom,
1125 .maxlen = sizeof(sysctl_panic_on_oom),
1126 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001127 .proc_handler = proc_dointvec_minmax,
1128 .extra1 = &zero,
1129 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001130 },
1131 {
David Rientjesfe071d72007-10-16 23:25:56 -07001132 .procname = "oom_kill_allocating_task",
1133 .data = &sysctl_oom_kill_allocating_task,
1134 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1135 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001136 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001137 },
1138 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001139 .procname = "oom_dump_tasks",
1140 .data = &sysctl_oom_dump_tasks,
1141 .maxlen = sizeof(sysctl_oom_dump_tasks),
1142 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001143 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001144 },
1145 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 .procname = "overcommit_ratio",
1147 .data = &sysctl_overcommit_ratio,
1148 .maxlen = sizeof(sysctl_overcommit_ratio),
1149 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001150 .proc_handler = overcommit_ratio_handler,
1151 },
1152 {
1153 .procname = "overcommit_kbytes",
1154 .data = &sysctl_overcommit_kbytes,
1155 .maxlen = sizeof(sysctl_overcommit_kbytes),
1156 .mode = 0644,
1157 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 },
1159 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 .procname = "page-cluster",
1161 .data = &page_cluster,
1162 .maxlen = sizeof(int),
1163 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001164 .proc_handler = proc_dointvec_minmax,
1165 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 },
1167 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 .procname = "dirty_background_ratio",
1169 .data = &dirty_background_ratio,
1170 .maxlen = sizeof(dirty_background_ratio),
1171 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001172 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 .extra1 = &zero,
1174 .extra2 = &one_hundred,
1175 },
1176 {
David Rientjes2da02992009-01-06 14:39:31 -08001177 .procname = "dirty_background_bytes",
1178 .data = &dirty_background_bytes,
1179 .maxlen = sizeof(dirty_background_bytes),
1180 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001181 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001182 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001183 },
1184 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 .procname = "dirty_ratio",
1186 .data = &vm_dirty_ratio,
1187 .maxlen = sizeof(vm_dirty_ratio),
1188 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001189 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 .extra1 = &zero,
1191 .extra2 = &one_hundred,
1192 },
1193 {
David Rientjes2da02992009-01-06 14:39:31 -08001194 .procname = "dirty_bytes",
1195 .data = &vm_dirty_bytes,
1196 .maxlen = sizeof(vm_dirty_bytes),
1197 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001198 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001199 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001200 },
1201 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001203 .data = &dirty_writeback_interval,
1204 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001206 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 },
1208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001210 .data = &dirty_expire_interval,
1211 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001213 .proc_handler = proc_dointvec_minmax,
1214 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 },
1216 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001217 .procname = "nr_pdflush_threads",
1218 .mode = 0444 /* read-only */,
1219 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 },
1221 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 .procname = "swappiness",
1223 .data = &vm_swappiness,
1224 .maxlen = sizeof(vm_swappiness),
1225 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001226 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .extra1 = &zero,
1228 .extra2 = &one_hundred,
1229 },
1230#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001231 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001233 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 .maxlen = sizeof(unsigned long),
1235 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001236 .proc_handler = hugetlb_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 .extra1 = (void *)&hugetlb_zero,
1238 .extra2 = (void *)&hugetlb_infinity,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001239 },
1240#ifdef CONFIG_NUMA
1241 {
1242 .procname = "nr_hugepages_mempolicy",
1243 .data = NULL,
1244 .maxlen = sizeof(unsigned long),
1245 .mode = 0644,
1246 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1247 .extra1 = (void *)&hugetlb_zero,
1248 .extra2 = (void *)&hugetlb_infinity,
1249 },
1250#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 .procname = "hugetlb_shm_group",
1253 .data = &sysctl_hugetlb_shm_group,
1254 .maxlen = sizeof(gid_t),
1255 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001256 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 },
Mel Gorman396faf02007-07-17 04:03:13 -07001258 {
Mel Gorman396faf02007-07-17 04:03:13 -07001259 .procname = "hugepages_treat_as_movable",
1260 .data = &hugepages_treat_as_movable,
1261 .maxlen = sizeof(int),
1262 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001263 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001264 },
Adam Litke54f9f802007-10-16 01:26:20 -07001265 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001266 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001267 .data = NULL,
1268 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001269 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001270 .proc_handler = hugetlb_overcommit_handler,
Andi Kleene5ff2152008-07-23 21:27:42 -07001271 .extra1 = (void *)&hugetlb_zero,
1272 .extra2 = (void *)&hugetlb_infinity,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001273 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274#endif
1275 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 .procname = "lowmem_reserve_ratio",
1277 .data = &sysctl_lowmem_reserve_ratio,
1278 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1279 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001280 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 },
1282 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001283 .procname = "drop_caches",
1284 .data = &sysctl_drop_caches,
1285 .maxlen = sizeof(int),
1286 .mode = 0644,
1287 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001288 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001289 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001290 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001291#ifdef CONFIG_COMPACTION
1292 {
1293 .procname = "compact_memory",
1294 .data = &sysctl_compact_memory,
1295 .maxlen = sizeof(int),
1296 .mode = 0200,
1297 .proc_handler = sysctl_compaction_handler,
1298 },
Mel Gorman5e771902010-05-24 14:32:31 -07001299 {
1300 .procname = "extfrag_threshold",
1301 .data = &sysctl_extfrag_threshold,
1302 .maxlen = sizeof(int),
1303 .mode = 0644,
1304 .proc_handler = sysctl_extfrag_handler,
1305 .extra1 = &min_extfrag_threshold,
1306 .extra2 = &max_extfrag_threshold,
1307 },
1308
Mel Gorman76ab0f52010-05-24 14:32:28 -07001309#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001310 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 .procname = "min_free_kbytes",
1312 .data = &min_free_kbytes,
1313 .maxlen = sizeof(min_free_kbytes),
1314 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001315 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 .extra1 = &zero,
1317 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001318 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001319 .procname = "percpu_pagelist_fraction",
1320 .data = &percpu_pagelist_fraction,
1321 .maxlen = sizeof(percpu_pagelist_fraction),
1322 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001323 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001324 .extra1 = &min_percpu_pagelist_fract,
1325 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326#ifdef CONFIG_MMU
1327 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 .procname = "max_map_count",
1329 .data = &sysctl_max_map_count,
1330 .maxlen = sizeof(sysctl_max_map_count),
1331 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001332 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001333 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001335#else
1336 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001337 .procname = "nr_trim_pages",
1338 .data = &sysctl_nr_trim_pages,
1339 .maxlen = sizeof(sysctl_nr_trim_pages),
1340 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001341 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001342 .extra1 = &zero,
1343 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344#endif
1345 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 .procname = "laptop_mode",
1347 .data = &laptop_mode,
1348 .maxlen = sizeof(laptop_mode),
1349 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001350 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 },
1352 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 .procname = "block_dump",
1354 .data = &block_dump,
1355 .maxlen = sizeof(block_dump),
1356 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001357 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 .extra1 = &zero,
1359 },
1360 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .procname = "vfs_cache_pressure",
1362 .data = &sysctl_vfs_cache_pressure,
1363 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1364 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001365 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 .extra1 = &zero,
1367 },
1368#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1369 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 .procname = "legacy_va_layout",
1371 .data = &sysctl_legacy_va_layout,
1372 .maxlen = sizeof(sysctl_legacy_va_layout),
1373 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001374 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 .extra1 = &zero,
1376 },
1377#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001378#ifdef CONFIG_NUMA
1379 {
Christoph Lameter17436602006-01-18 17:42:32 -08001380 .procname = "zone_reclaim_mode",
1381 .data = &zone_reclaim_mode,
1382 .maxlen = sizeof(zone_reclaim_mode),
1383 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001384 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001385 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001386 },
Christoph Lameter96146342006-07-03 00:24:13 -07001387 {
Christoph Lameter96146342006-07-03 00:24:13 -07001388 .procname = "min_unmapped_ratio",
1389 .data = &sysctl_min_unmapped_ratio,
1390 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1391 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001392 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001393 .extra1 = &zero,
1394 .extra2 = &one_hundred,
1395 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001396 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001397 .procname = "min_slab_ratio",
1398 .data = &sysctl_min_slab_ratio,
1399 .maxlen = sizeof(sysctl_min_slab_ratio),
1400 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001401 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001402 .extra1 = &zero,
1403 .extra2 = &one_hundred,
1404 },
Christoph Lameter17436602006-01-18 17:42:32 -08001405#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001406#ifdef CONFIG_SMP
1407 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001408 .procname = "stat_interval",
1409 .data = &sysctl_stat_interval,
1410 .maxlen = sizeof(sysctl_stat_interval),
1411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001412 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001413 },
1414#endif
David Howells6e141542009-12-15 19:27:45 +00001415#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001416 {
Eric Parised032182007-06-28 15:55:21 -04001417 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001418 .data = &dac_mmap_min_addr,
1419 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001422 },
David Howells6e141542009-12-15 19:27:45 +00001423#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001424#ifdef CONFIG_NUMA
1425 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001426 .procname = "numa_zonelist_order",
1427 .data = &numa_zonelist_order,
1428 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001430 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001431 },
1432#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001433#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001434 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001435 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001436 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001437#ifdef CONFIG_X86_32
1438 .data = &vdso32_enabled,
1439 .maxlen = sizeof(vdso32_enabled),
1440#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001441 .data = &vdso_enabled,
1442 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001443#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001445 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001446 .extra1 = &zero,
1447 },
1448#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001449#ifdef CONFIG_HIGHMEM
1450 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001451 .procname = "highmem_is_dirtyable",
1452 .data = &vm_highmem_is_dirtyable,
1453 .maxlen = sizeof(vm_highmem_is_dirtyable),
1454 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001455 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001456 .extra1 = &zero,
1457 .extra2 = &one,
1458 },
1459#endif
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001460 {
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001461 .procname = "scan_unevictable_pages",
1462 .data = &scan_unevictable_pages,
1463 .maxlen = sizeof(scan_unevictable_pages),
1464 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001465 .proc_handler = scan_unevictable_handler,
Peter Zijlstra4be6f6b2009-04-13 14:39:33 -07001466 },
Andi Kleen6a460792009-09-16 11:50:15 +02001467#ifdef CONFIG_MEMORY_FAILURE
1468 {
Andi Kleen6a460792009-09-16 11:50:15 +02001469 .procname = "memory_failure_early_kill",
1470 .data = &sysctl_memory_failure_early_kill,
1471 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001473 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001474 .extra1 = &zero,
1475 .extra2 = &one,
1476 },
1477 {
Andi Kleen6a460792009-09-16 11:50:15 +02001478 .procname = "memory_failure_recovery",
1479 .data = &sysctl_memory_failure_recovery,
1480 .maxlen = sizeof(sysctl_memory_failure_recovery),
1481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001482 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001483 .extra1 = &zero,
1484 .extra2 = &one,
1485 },
1486#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001487 {
1488 .procname = "user_reserve_kbytes",
1489 .data = &sysctl_user_reserve_kbytes,
1490 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1491 .mode = 0644,
1492 .proc_handler = proc_doulongvec_minmax,
1493 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001494 {
1495 .procname = "admin_reserve_kbytes",
1496 .data = &sysctl_admin_reserve_kbytes,
1497 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1498 .mode = 0644,
1499 .proc_handler = proc_doulongvec_minmax,
1500 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001501 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502};
1503
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001504#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001505static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001506 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001507};
1508#endif
1509
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001510static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 .procname = "inode-nr",
1513 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001514 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001516 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 },
1518 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 .procname = "inode-state",
1520 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001521 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001523 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 },
1525 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 .procname = "file-nr",
1527 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001528 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001530 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 },
1532 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 .procname = "file-max",
1534 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001535 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001537 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 },
1539 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001540 .procname = "nr_open",
1541 .data = &sysctl_nr_open,
1542 .maxlen = sizeof(int),
1543 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001544 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001545 .extra1 = &sysctl_nr_open_min,
1546 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001547 },
1548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 .procname = "dentry-state",
1550 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001551 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001553 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 },
1555 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 .procname = "overflowuid",
1557 .data = &fs_overflowuid,
1558 .maxlen = sizeof(int),
1559 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001560 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 .extra1 = &minolduid,
1562 .extra2 = &maxolduid,
1563 },
1564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 .procname = "overflowgid",
1566 .data = &fs_overflowgid,
1567 .maxlen = sizeof(int),
1568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001569 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 .extra1 = &minolduid,
1571 .extra2 = &maxolduid,
1572 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001573#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 .procname = "leases-enable",
1576 .data = &leases_enable,
1577 .maxlen = sizeof(int),
1578 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001579 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001581#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582#ifdef CONFIG_DNOTIFY
1583 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 .procname = "dir-notify-enable",
1585 .data = &dir_notify_enable,
1586 .maxlen = sizeof(int),
1587 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001588 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 },
1590#endif
1591#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001592#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 .procname = "lease-break-time",
1595 .data = &lease_break_time,
1596 .maxlen = sizeof(int),
1597 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001598 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001600#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001601#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 .procname = "aio-nr",
1604 .data = &aio_nr,
1605 .maxlen = sizeof(aio_nr),
1606 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001607 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 },
1609 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 .procname = "aio-max-nr",
1611 .data = &aio_max_nr,
1612 .maxlen = sizeof(aio_max_nr),
1613 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001614 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001616#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001617#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001618 {
Robert Love0399cb02005-07-13 12:38:18 -04001619 .procname = "inotify",
1620 .mode = 0555,
1621 .child = inotify_table,
1622 },
1623#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001624#ifdef CONFIG_EPOLL
1625 {
1626 .procname = "epoll",
1627 .mode = 0555,
1628 .child = epoll_table,
1629 },
1630#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001632 {
Kees Cook800179c2012-07-25 17:29:07 -07001633 .procname = "protected_symlinks",
1634 .data = &sysctl_protected_symlinks,
1635 .maxlen = sizeof(int),
1636 .mode = 0600,
1637 .proc_handler = proc_dointvec_minmax,
1638 .extra1 = &zero,
1639 .extra2 = &one,
1640 },
1641 {
1642 .procname = "protected_hardlinks",
1643 .data = &sysctl_protected_hardlinks,
1644 .maxlen = sizeof(int),
1645 .mode = 0600,
1646 .proc_handler = proc_dointvec_minmax,
1647 .extra1 = &zero,
1648 .extra2 = &one,
1649 },
1650 {
Alan Coxd6e71142005-06-23 00:09:43 -07001651 .procname = "suid_dumpable",
1652 .data = &suid_dumpable,
1653 .maxlen = sizeof(int),
1654 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001655 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001656 .extra1 = &zero,
1657 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001658 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001659#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1660 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001661 .procname = "binfmt_misc",
1662 .mode = 0555,
1663 .child = binfmt_misc_table,
1664 },
1665#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001666 {
Jens Axboeff9da692010-06-03 14:54:39 +02001667 .procname = "pipe-max-size",
1668 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001669 .maxlen = sizeof(int),
1670 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001671 .proc_handler = &pipe_proc_fn,
1672 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001673 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001674 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675};
1676
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001677static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001678#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001679 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001680 .procname = "exception-trace",
1681 .data = &show_unhandled_signals,
1682 .maxlen = sizeof(int),
1683 .mode = 0644,
1684 .proc_handler = proc_dointvec
1685 },
1686#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001687#if defined(CONFIG_OPTPROBES)
1688 {
1689 .procname = "kprobes-optimization",
1690 .data = &sysctl_kprobes_optimization,
1691 .maxlen = sizeof(int),
1692 .mode = 0644,
1693 .proc_handler = proc_kprobes_optimization_handler,
1694 .extra1 = &zero,
1695 .extra2 = &one,
1696 },
1697#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001698 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699};
1700
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001701static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001702 { }
Robert Love0eeca282005-07-12 17:06:03 -04001703};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001705int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001706{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001707 struct ctl_table_header *hdr;
1708
1709 hdr = register_sysctl_table(sysctl_base_table);
1710 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001711 return 0;
1712}
1713
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001714#endif /* CONFIG_SYSCTL */
1715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716/*
1717 * /proc/sys support
1718 */
1719
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001720#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
Kees Cookf8808302014-06-06 14:37:17 -07001722static int _proc_do_string(char *data, int maxlen, int write,
1723 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001724 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001725{
1726 size_t len;
1727 char __user *p;
1728 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001729
1730 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001731 *lenp = 0;
1732 return 0;
1733 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001734
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001735 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001736 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1737 /* Only continue writes not past the end of buffer. */
1738 len = strlen(data);
1739 if (len > maxlen - 1)
1740 len = maxlen - 1;
1741
1742 if (*ppos > len)
1743 return 0;
1744 len = *ppos;
1745 } else {
1746 /* Start writing from beginning of buffer. */
1747 len = 0;
1748 }
1749
Kees Cook2ca9bb42014-06-06 14:37:18 -07001750 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001751 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001752 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001753 if (get_user(c, p++))
1754 return -EFAULT;
1755 if (c == 0 || c == '\n')
1756 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001757 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001758 }
Kees Cookf8808302014-06-06 14:37:17 -07001759 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001760 } else {
1761 len = strlen(data);
1762 if (len > maxlen)
1763 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001764
1765 if (*ppos > len) {
1766 *lenp = 0;
1767 return 0;
1768 }
1769
1770 data += *ppos;
1771 len -= *ppos;
1772
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001773 if (len > *lenp)
1774 len = *lenp;
1775 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001776 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001777 return -EFAULT;
1778 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001779 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001780 return -EFAULT;
1781 len++;
1782 }
1783 *lenp = len;
1784 *ppos += len;
1785 }
1786 return 0;
1787}
1788
Kees Cookf4aacea2014-06-06 14:37:19 -07001789static void warn_sysctl_write(struct ctl_table *table)
1790{
1791 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1792 "This will not be supported in the future. To silence this\n"
1793 "warning, set kernel.sysctl_writes_strict = -1\n",
1794 current->comm, table->procname);
1795}
1796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797/**
1798 * proc_dostring - read a string sysctl
1799 * @table: the sysctl table
1800 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 * @buffer: the user buffer
1802 * @lenp: the size of the user buffer
1803 * @ppos: file position
1804 *
1805 * Reads/writes a string from/to the user buffer. If the kernel
1806 * buffer provided is not large enough to hold the string, the
1807 * string is truncated. The copied string is %NULL-terminated.
1808 * If the string is being read by the user process, it is copied
1809 * and a newline '\n' is added. It is truncated if the buffer is
1810 * not large enough.
1811 *
1812 * Returns 0 on success.
1813 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001814int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 void __user *buffer, size_t *lenp, loff_t *ppos)
1816{
Kees Cookf4aacea2014-06-06 14:37:19 -07001817 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1818 warn_sysctl_write(table);
1819
Kees Cookf8808302014-06-06 14:37:17 -07001820 return _proc_do_string((char *)(table->data), table->maxlen, write,
1821 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822}
1823
Amerigo Wang00b7c332010-05-05 00:26:45 +00001824static size_t proc_skip_spaces(char **buf)
1825{
1826 size_t ret;
1827 char *tmp = skip_spaces(*buf);
1828 ret = tmp - *buf;
1829 *buf = tmp;
1830 return ret;
1831}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001833static void proc_skip_char(char **buf, size_t *size, const char v)
1834{
1835 while (*size) {
1836 if (**buf != v)
1837 break;
1838 (*size)--;
1839 (*buf)++;
1840 }
1841}
1842
Amerigo Wang00b7c332010-05-05 00:26:45 +00001843#define TMPBUFLEN 22
1844/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001845 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001846 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001847 * @buf: a kernel buffer
1848 * @size: size of the kernel buffer
1849 * @val: this is where the number will be stored
1850 * @neg: set to %TRUE if number is negative
1851 * @perm_tr: a vector which contains the allowed trailers
1852 * @perm_tr_len: size of the perm_tr vector
1853 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001854 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001855 * In case of success %0 is returned and @buf and @size are updated with
1856 * the amount of bytes read. If @tr is non-NULL and a trailing
1857 * character exists (size is non-zero after returning from this
1858 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001859 */
1860static int proc_get_long(char **buf, size_t *size,
1861 unsigned long *val, bool *neg,
1862 const char *perm_tr, unsigned perm_tr_len, char *tr)
1863{
1864 int len;
1865 char *p, tmp[TMPBUFLEN];
1866
1867 if (!*size)
1868 return -EINVAL;
1869
1870 len = *size;
1871 if (len > TMPBUFLEN - 1)
1872 len = TMPBUFLEN - 1;
1873
1874 memcpy(tmp, *buf, len);
1875
1876 tmp[len] = 0;
1877 p = tmp;
1878 if (*p == '-' && *size > 1) {
1879 *neg = true;
1880 p++;
1881 } else
1882 *neg = false;
1883 if (!isdigit(*p))
1884 return -EINVAL;
1885
1886 *val = simple_strtoul(p, &p, 0);
1887
1888 len = p - tmp;
1889
1890 /* We don't know if the next char is whitespace thus we may accept
1891 * invalid integers (e.g. 1234...a) or two integers instead of one
1892 * (e.g. 123...1). So lets not allow such large numbers. */
1893 if (len == TMPBUFLEN - 1)
1894 return -EINVAL;
1895
1896 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1897 return -EINVAL;
1898
1899 if (tr && (len < *size))
1900 *tr = *p;
1901
1902 *buf += len;
1903 *size -= len;
1904
1905 return 0;
1906}
1907
1908/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001909 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001910 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001911 * @buf: the user buffer
1912 * @size: the size of the user buffer
1913 * @val: the integer to be converted
1914 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001915 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001916 * In case of success %0 is returned and @buf and @size are updated with
1917 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001918 */
1919static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1920 bool neg)
1921{
1922 int len;
1923 char tmp[TMPBUFLEN], *p = tmp;
1924
1925 sprintf(p, "%s%lu", neg ? "-" : "", val);
1926 len = strlen(tmp);
1927 if (len > *size)
1928 len = *size;
1929 if (copy_to_user(*buf, tmp, len))
1930 return -EFAULT;
1931 *size -= len;
1932 *buf += len;
1933 return 0;
1934}
1935#undef TMPBUFLEN
1936
1937static int proc_put_char(void __user **buf, size_t *size, char c)
1938{
1939 if (*size) {
1940 char __user **buffer = (char __user **)buf;
1941 if (put_user(c, *buffer))
1942 return -EFAULT;
1943 (*size)--, (*buffer)++;
1944 *buf = *buffer;
1945 }
1946 return 0;
1947}
1948
1949static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 int *valp,
1951 int write, void *data)
1952{
1953 if (write) {
1954 *valp = *negp ? -*lvalp : *lvalp;
1955 } else {
1956 int val = *valp;
1957 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001958 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 *lvalp = (unsigned long)-val;
1960 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001961 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 *lvalp = (unsigned long)val;
1963 }
1964 }
1965 return 0;
1966}
1967
Amerigo Wang00b7c332010-05-05 00:26:45 +00001968static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1969
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001970static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001971 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001972 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001973 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 int write, void *data),
1975 void *data)
1976{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001977 int *i, vleft, first = 1, err = 0;
1978 unsigned long page = 0;
1979 size_t left;
1980 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Amerigo Wang00b7c332010-05-05 00:26:45 +00001982 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 *lenp = 0;
1984 return 0;
1985 }
1986
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001987 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 vleft = table->maxlen / sizeof(*i);
1989 left = *lenp;
1990
1991 if (!conv)
1992 conv = do_proc_dointvec_conv;
1993
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001995 if (*ppos) {
1996 switch (sysctl_writes_strict) {
1997 case SYSCTL_WRITES_STRICT:
1998 goto out;
1999 case SYSCTL_WRITES_WARN:
2000 warn_sysctl_write(table);
2001 break;
2002 default:
2003 break;
2004 }
2005 }
2006
Amerigo Wang00b7c332010-05-05 00:26:45 +00002007 if (left > PAGE_SIZE - 1)
2008 left = PAGE_SIZE - 1;
2009 page = __get_free_page(GFP_TEMPORARY);
2010 kbuf = (char *) page;
2011 if (!kbuf)
2012 return -ENOMEM;
2013 if (copy_from_user(kbuf, buffer, left)) {
2014 err = -EFAULT;
2015 goto free;
2016 }
2017 kbuf[left] = 0;
2018 }
2019
2020 for (; left && vleft--; i++, first=0) {
2021 unsigned long lval;
2022 bool neg;
2023
2024 if (write) {
2025 left -= proc_skip_spaces(&kbuf);
2026
J. R. Okajima563b0462010-05-25 16:10:14 -07002027 if (!left)
2028 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002029 err = proc_get_long(&kbuf, &left, &lval, &neg,
2030 proc_wspace_sep,
2031 sizeof(proc_wspace_sep), NULL);
2032 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002034 if (conv(&neg, &lval, i, 1, data)) {
2035 err = -EINVAL;
2036 break;
2037 }
2038 } else {
2039 if (conv(&neg, &lval, i, 0, data)) {
2040 err = -EINVAL;
2041 break;
2042 }
2043 if (!first)
2044 err = proc_put_char(&buffer, &left, '\t');
2045 if (err)
2046 break;
2047 err = proc_put_long(&buffer, &left, lval, neg);
2048 if (err)
2049 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 }
2051 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002052
2053 if (!write && !first && left && !err)
2054 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002055 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002056 left -= proc_skip_spaces(&kbuf);
2057free:
2058 if (write) {
2059 free_page(page);
2060 if (first)
2061 return err ? : -EINVAL;
2062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002064out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002066 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067}
2068
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002069static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002070 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002071 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002072 int write, void *data),
2073 void *data)
2074{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002075 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002076 buffer, lenp, ppos, conv, data);
2077}
2078
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079/**
2080 * proc_dointvec - read a vector of integers
2081 * @table: the sysctl table
2082 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 * @buffer: the user buffer
2084 * @lenp: the size of the user buffer
2085 * @ppos: file position
2086 *
2087 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2088 * values from/to the user buffer, treated as an ASCII string.
2089 *
2090 * Returns 0 on success.
2091 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002092int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 void __user *buffer, size_t *lenp, loff_t *ppos)
2094{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002095 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 NULL,NULL);
2097}
2098
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002099/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002100 * Taint values can only be increased
2101 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002102 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002103static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002104 void __user *buffer, size_t *lenp, loff_t *ppos)
2105{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002106 struct ctl_table t;
2107 unsigned long tmptaint = get_taint();
2108 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002109
Bastian Blank91fcd412007-04-23 14:41:14 -07002110 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002111 return -EPERM;
2112
Andi Kleen25ddbb12008-10-15 22:01:41 -07002113 t = *table;
2114 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002115 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002116 if (err < 0)
2117 return err;
2118
2119 if (write) {
2120 /*
2121 * Poor man's atomic or. Not worth adding a primitive
2122 * to everyone's atomic.h for this
2123 */
2124 int i;
2125 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2126 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302127 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002128 }
2129 }
2130
2131 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002132}
2133
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002134#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002135static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002136 void __user *buffer, size_t *lenp, loff_t *ppos)
2137{
2138 if (write && !capable(CAP_SYS_ADMIN))
2139 return -EPERM;
2140
2141 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2142}
2143#endif
2144
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145struct do_proc_dointvec_minmax_conv_param {
2146 int *min;
2147 int *max;
2148};
2149
Amerigo Wang00b7c332010-05-05 00:26:45 +00002150static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2151 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 int write, void *data)
2153{
2154 struct do_proc_dointvec_minmax_conv_param *param = data;
2155 if (write) {
2156 int val = *negp ? -*lvalp : *lvalp;
2157 if ((param->min && *param->min > val) ||
2158 (param->max && *param->max < val))
2159 return -EINVAL;
2160 *valp = val;
2161 } else {
2162 int val = *valp;
2163 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002164 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 *lvalp = (unsigned long)-val;
2166 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002167 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 *lvalp = (unsigned long)val;
2169 }
2170 }
2171 return 0;
2172}
2173
2174/**
2175 * proc_dointvec_minmax - read a vector of integers with min/max values
2176 * @table: the sysctl table
2177 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 * @buffer: the user buffer
2179 * @lenp: the size of the user buffer
2180 * @ppos: file position
2181 *
2182 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2183 * values from/to the user buffer, treated as an ASCII string.
2184 *
2185 * This routine will ensure the values are within the range specified by
2186 * table->extra1 (min) and table->extra2 (max).
2187 *
2188 * Returns 0 on success.
2189 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002190int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 void __user *buffer, size_t *lenp, loff_t *ppos)
2192{
2193 struct do_proc_dointvec_minmax_conv_param param = {
2194 .min = (int *) table->extra1,
2195 .max = (int *) table->extra2,
2196 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002197 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 do_proc_dointvec_minmax_conv, &param);
2199}
2200
Kees Cook54b50192012-07-30 14:39:18 -07002201static void validate_coredump_safety(void)
2202{
Alex Kelly046d6622012-10-04 17:15:23 -07002203#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002204 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002205 core_pattern[0] != '/' && core_pattern[0] != '|') {
2206 printk(KERN_WARNING "Unsafe core_pattern used with "\
2207 "suid_dumpable=2. Pipe handler or fully qualified "\
2208 "core dump path required.\n");
2209 }
Alex Kelly046d6622012-10-04 17:15:23 -07002210#endif
Kees Cook54b50192012-07-30 14:39:18 -07002211}
2212
2213static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2214 void __user *buffer, size_t *lenp, loff_t *ppos)
2215{
2216 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2217 if (!error)
2218 validate_coredump_safety();
2219 return error;
2220}
2221
Alex Kelly046d6622012-10-04 17:15:23 -07002222#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002223static int proc_dostring_coredump(struct ctl_table *table, int write,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2225{
2226 int error = proc_dostring(table, write, buffer, lenp, ppos);
2227 if (!error)
2228 validate_coredump_safety();
2229 return error;
2230}
Alex Kelly046d6622012-10-04 17:15:23 -07002231#endif
Kees Cook54b50192012-07-30 14:39:18 -07002232
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002233static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 void __user *buffer,
2235 size_t *lenp, loff_t *ppos,
2236 unsigned long convmul,
2237 unsigned long convdiv)
2238{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002239 unsigned long *i, *min, *max;
2240 int vleft, first = 1, err = 0;
2241 unsigned long page = 0;
2242 size_t left;
2243 char *kbuf;
2244
2245 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 *lenp = 0;
2247 return 0;
2248 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002249
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002250 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 min = (unsigned long *) table->extra1;
2252 max = (unsigned long *) table->extra2;
2253 vleft = table->maxlen / sizeof(unsigned long);
2254 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002255
2256 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002257 if (*ppos) {
2258 switch (sysctl_writes_strict) {
2259 case SYSCTL_WRITES_STRICT:
2260 goto out;
2261 case SYSCTL_WRITES_WARN:
2262 warn_sysctl_write(table);
2263 break;
2264 default:
2265 break;
2266 }
2267 }
2268
Amerigo Wang00b7c332010-05-05 00:26:45 +00002269 if (left > PAGE_SIZE - 1)
2270 left = PAGE_SIZE - 1;
2271 page = __get_free_page(GFP_TEMPORARY);
2272 kbuf = (char *) page;
2273 if (!kbuf)
2274 return -ENOMEM;
2275 if (copy_from_user(kbuf, buffer, left)) {
2276 err = -EFAULT;
2277 goto free;
2278 }
2279 kbuf[left] = 0;
2280 }
2281
Eric Dumazet27b3d802010-10-07 12:59:29 -07002282 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002283 unsigned long val;
2284
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002286 bool neg;
2287
2288 left -= proc_skip_spaces(&kbuf);
2289
2290 err = proc_get_long(&kbuf, &left, &val, &neg,
2291 proc_wspace_sep,
2292 sizeof(proc_wspace_sep), NULL);
2293 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 break;
2295 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 continue;
2297 if ((min && val < *min) || (max && val > *max))
2298 continue;
2299 *i = val;
2300 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002301 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002302 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002303 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002304 if (err)
2305 break;
2306 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307 err = proc_put_long(&buffer, &left, val, false);
2308 if (err)
2309 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 }
2311 }
2312
Amerigo Wang00b7c332010-05-05 00:26:45 +00002313 if (!write && !first && left && !err)
2314 err = proc_put_char(&buffer, &left, '\n');
2315 if (write && !err)
2316 left -= proc_skip_spaces(&kbuf);
2317free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002319 free_page(page);
2320 if (first)
2321 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002324out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002326 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327}
2328
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002329static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002330 void __user *buffer,
2331 size_t *lenp, loff_t *ppos,
2332 unsigned long convmul,
2333 unsigned long convdiv)
2334{
2335 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002336 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002337}
2338
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339/**
2340 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2341 * @table: the sysctl table
2342 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 * @buffer: the user buffer
2344 * @lenp: the size of the user buffer
2345 * @ppos: file position
2346 *
2347 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2348 * values from/to the user buffer, treated as an ASCII string.
2349 *
2350 * This routine will ensure the values are within the range specified by
2351 * table->extra1 (min) and table->extra2 (max).
2352 *
2353 * Returns 0 on success.
2354 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002355int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 void __user *buffer, size_t *lenp, loff_t *ppos)
2357{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002358 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359}
2360
2361/**
2362 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2363 * @table: the sysctl table
2364 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 * @buffer: the user buffer
2366 * @lenp: the size of the user buffer
2367 * @ppos: file position
2368 *
2369 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2370 * values from/to the user buffer, treated as an ASCII string. The values
2371 * are treated as milliseconds, and converted to jiffies when they are stored.
2372 *
2373 * This routine will ensure the values are within the range specified by
2374 * table->extra1 (min) and table->extra2 (max).
2375 *
2376 * Returns 0 on success.
2377 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002378int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 void __user *buffer,
2380 size_t *lenp, loff_t *ppos)
2381{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002382 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 lenp, ppos, HZ, 1000l);
2384}
2385
2386
Amerigo Wang00b7c332010-05-05 00:26:45 +00002387static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 int *valp,
2389 int write, void *data)
2390{
2391 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002392 if (*lvalp > LONG_MAX / HZ)
2393 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2395 } else {
2396 int val = *valp;
2397 unsigned long lval;
2398 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002399 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 lval = (unsigned long)-val;
2401 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002402 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 lval = (unsigned long)val;
2404 }
2405 *lvalp = lval / HZ;
2406 }
2407 return 0;
2408}
2409
Amerigo Wang00b7c332010-05-05 00:26:45 +00002410static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 int *valp,
2412 int write, void *data)
2413{
2414 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002415 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2416 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2418 } else {
2419 int val = *valp;
2420 unsigned long lval;
2421 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002422 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 lval = (unsigned long)-val;
2424 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002425 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 lval = (unsigned long)val;
2427 }
2428 *lvalp = jiffies_to_clock_t(lval);
2429 }
2430 return 0;
2431}
2432
Amerigo Wang00b7c332010-05-05 00:26:45 +00002433static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 int *valp,
2435 int write, void *data)
2436{
2437 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002438 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2439
2440 if (jif > INT_MAX)
2441 return 1;
2442 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 } else {
2444 int val = *valp;
2445 unsigned long lval;
2446 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002447 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 lval = (unsigned long)-val;
2449 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002450 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 lval = (unsigned long)val;
2452 }
2453 *lvalp = jiffies_to_msecs(lval);
2454 }
2455 return 0;
2456}
2457
2458/**
2459 * proc_dointvec_jiffies - read a vector of integers as seconds
2460 * @table: the sysctl table
2461 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 * @buffer: the user buffer
2463 * @lenp: the size of the user buffer
2464 * @ppos: file position
2465 *
2466 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2467 * values from/to the user buffer, treated as an ASCII string.
2468 * The values read are assumed to be in seconds, and are converted into
2469 * jiffies.
2470 *
2471 * Returns 0 on success.
2472 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002473int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 void __user *buffer, size_t *lenp, loff_t *ppos)
2475{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002476 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 do_proc_dointvec_jiffies_conv,NULL);
2478}
2479
2480/**
2481 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 * @buffer: the user buffer
2485 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002486 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 *
2488 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2489 * values from/to the user buffer, treated as an ASCII string.
2490 * The values read are assumed to be in 1/USER_HZ seconds, and
2491 * are converted into jiffies.
2492 *
2493 * Returns 0 on success.
2494 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002495int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 void __user *buffer, size_t *lenp, loff_t *ppos)
2497{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002498 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 do_proc_dointvec_userhz_jiffies_conv,NULL);
2500}
2501
2502/**
2503 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2504 * @table: the sysctl table
2505 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 * @buffer: the user buffer
2507 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002508 * @ppos: file position
2509 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 *
2511 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2512 * values from/to the user buffer, treated as an ASCII string.
2513 * The values read are assumed to be in 1/1000 seconds, and
2514 * are converted into jiffies.
2515 *
2516 * Returns 0 on success.
2517 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002518int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 void __user *buffer, size_t *lenp, loff_t *ppos)
2520{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002521 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 do_proc_dointvec_ms_jiffies_conv, NULL);
2523}
2524
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002525static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002526 void __user *buffer, size_t *lenp, loff_t *ppos)
2527{
2528 struct pid *new_pid;
2529 pid_t tmp;
2530 int r;
2531
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002532 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002533
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002534 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002535 lenp, ppos, NULL, NULL);
2536 if (r || !write)
2537 return r;
2538
2539 new_pid = find_get_pid(tmp);
2540 if (!new_pid)
2541 return -ESRCH;
2542
2543 put_pid(xchg(&cad_pid, new_pid));
2544 return 0;
2545}
2546
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002547/**
2548 * proc_do_large_bitmap - read/write from/to a large bitmap
2549 * @table: the sysctl table
2550 * @write: %TRUE if this is a write to the sysctl file
2551 * @buffer: the user buffer
2552 * @lenp: the size of the user buffer
2553 * @ppos: file position
2554 *
2555 * The bitmap is stored at table->data and the bitmap length (in bits)
2556 * in table->maxlen.
2557 *
2558 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2559 * large bitmaps may be represented in a compact manner. Writing into
2560 * the file will clear the bitmap then update it with the given input.
2561 *
2562 * Returns 0 on success.
2563 */
2564int proc_do_large_bitmap(struct ctl_table *table, int write,
2565 void __user *buffer, size_t *lenp, loff_t *ppos)
2566{
2567 int err = 0;
2568 bool first = 1;
2569 size_t left = *lenp;
2570 unsigned long bitmap_len = table->maxlen;
2571 unsigned long *bitmap = (unsigned long *) table->data;
2572 unsigned long *tmp_bitmap = NULL;
2573 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2574
2575 if (!bitmap_len || !left || (*ppos && !write)) {
2576 *lenp = 0;
2577 return 0;
2578 }
2579
2580 if (write) {
2581 unsigned long page = 0;
2582 char *kbuf;
2583
2584 if (left > PAGE_SIZE - 1)
2585 left = PAGE_SIZE - 1;
2586
2587 page = __get_free_page(GFP_TEMPORARY);
2588 kbuf = (char *) page;
2589 if (!kbuf)
2590 return -ENOMEM;
2591 if (copy_from_user(kbuf, buffer, left)) {
2592 free_page(page);
2593 return -EFAULT;
2594 }
2595 kbuf[left] = 0;
2596
2597 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2598 GFP_KERNEL);
2599 if (!tmp_bitmap) {
2600 free_page(page);
2601 return -ENOMEM;
2602 }
2603 proc_skip_char(&kbuf, &left, '\n');
2604 while (!err && left) {
2605 unsigned long val_a, val_b;
2606 bool neg;
2607
2608 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2609 sizeof(tr_a), &c);
2610 if (err)
2611 break;
2612 if (val_a >= bitmap_len || neg) {
2613 err = -EINVAL;
2614 break;
2615 }
2616
2617 val_b = val_a;
2618 if (left) {
2619 kbuf++;
2620 left--;
2621 }
2622
2623 if (c == '-') {
2624 err = proc_get_long(&kbuf, &left, &val_b,
2625 &neg, tr_b, sizeof(tr_b),
2626 &c);
2627 if (err)
2628 break;
2629 if (val_b >= bitmap_len || neg ||
2630 val_a > val_b) {
2631 err = -EINVAL;
2632 break;
2633 }
2634 if (left) {
2635 kbuf++;
2636 left--;
2637 }
2638 }
2639
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002640 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002641 first = 0;
2642 proc_skip_char(&kbuf, &left, '\n');
2643 }
2644 free_page(page);
2645 } else {
2646 unsigned long bit_a, bit_b = 0;
2647
2648 while (left) {
2649 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2650 if (bit_a >= bitmap_len)
2651 break;
2652 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2653 bit_a + 1) - 1;
2654
2655 if (!first) {
2656 err = proc_put_char(&buffer, &left, ',');
2657 if (err)
2658 break;
2659 }
2660 err = proc_put_long(&buffer, &left, bit_a, false);
2661 if (err)
2662 break;
2663 if (bit_a != bit_b) {
2664 err = proc_put_char(&buffer, &left, '-');
2665 if (err)
2666 break;
2667 err = proc_put_long(&buffer, &left, bit_b, false);
2668 if (err)
2669 break;
2670 }
2671
2672 first = 0; bit_b++;
2673 }
2674 if (!err)
2675 err = proc_put_char(&buffer, &left, '\n');
2676 }
2677
2678 if (!err) {
2679 if (write) {
2680 if (*ppos)
2681 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2682 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002683 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002684 }
2685 kfree(tmp_bitmap);
2686 *lenp -= left;
2687 *ppos += *lenp;
2688 return 0;
2689 } else {
2690 kfree(tmp_bitmap);
2691 return err;
2692 }
2693}
2694
Jovi Zhang55610502011-01-12 17:00:45 -08002695#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002697int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 void __user *buffer, size_t *lenp, loff_t *ppos)
2699{
2700 return -ENOSYS;
2701}
2702
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002703int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 void __user *buffer, size_t *lenp, loff_t *ppos)
2705{
2706 return -ENOSYS;
2707}
2708
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002709int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 void __user *buffer, size_t *lenp, loff_t *ppos)
2711{
2712 return -ENOSYS;
2713}
2714
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002715int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 void __user *buffer, size_t *lenp, loff_t *ppos)
2717{
2718 return -ENOSYS;
2719}
2720
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002721int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 void __user *buffer, size_t *lenp, loff_t *ppos)
2723{
2724 return -ENOSYS;
2725}
2726
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002727int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 void __user *buffer, size_t *lenp, loff_t *ppos)
2729{
2730 return -ENOSYS;
2731}
2732
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002733int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 void __user *buffer, size_t *lenp, loff_t *ppos)
2735{
2736 return -ENOSYS;
2737}
2738
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002739int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 void __user *buffer,
2741 size_t *lenp, loff_t *ppos)
2742{
2743 return -ENOSYS;
2744}
2745
2746
Jovi Zhang55610502011-01-12 17:00:45 -08002747#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749/*
2750 * No sense putting this after each symbol definition, twice,
2751 * exception granted :-)
2752 */
2753EXPORT_SYMBOL(proc_dointvec);
2754EXPORT_SYMBOL(proc_dointvec_jiffies);
2755EXPORT_SYMBOL(proc_dointvec_minmax);
2756EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2757EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2758EXPORT_SYMBOL(proc_dostring);
2759EXPORT_SYMBOL(proc_doulongvec_minmax);
2760EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);