blob: 137c7f69b2642f8a74c916bfaa6cf973db663431 [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;
139
140static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700141static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Liu Hua80df2842014-04-07 15:38:57 -0700143/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
144#ifdef CONFIG_DETECT_HUNG_TASK
145static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
146#endif
147
Dave Youngd14f1722010-02-25 20:28:57 -0500148#ifdef CONFIG_INOTIFY_USER
149#include <linux/inotify.h>
150#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700151#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#endif
153
154#ifdef __hppa__
155extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530156#endif
157
158#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159extern int unaligned_enabled;
160#endif
161
Jes Sorensend2b176e2006-02-28 09:42:23 -0800162#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800163extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800164#endif
165
Vineet Guptab6fca722013-01-09 20:06:28 +0530166#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
167extern int no_unaligned_warning;
168#endif
169
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700170#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700171
172#define SYSCTL_WRITES_LEGACY -1
173#define SYSCTL_WRITES_WARN 0
174#define SYSCTL_WRITES_STRICT 1
175
176static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
177
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700178static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700179 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700180static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800181 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700182#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700183
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700184#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700185static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700186 void __user *buffer, size_t *lenp, loff_t *ppos);
187#endif
188
Kees Cook54b50192012-07-30 14:39:18 -0700189static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
190 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700191#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700192static int proc_dostring_coredump(struct ctl_table *table, int write,
193 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700194#endif
Kees Cook54b50192012-07-30 14:39:18 -0700195
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700196#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800197/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100198static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700199
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700200static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700201 void __user *buffer, size_t *lenp,
202 loff_t *ppos)
203{
204 int error;
205
206 error = proc_dointvec(table, write, buffer, lenp, ppos);
207 if (error)
208 return error;
209
210 if (write)
211 sysrq_toggle_support(__sysrq_enabled);
212
213 return 0;
214}
215
216#endif
217
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700218static struct ctl_table kern_table[];
219static struct ctl_table vm_table[];
220static struct ctl_table fs_table[];
221static struct ctl_table debug_table[];
222static struct ctl_table dev_table[];
223extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800224#ifdef CONFIG_EPOLL
225extern struct ctl_table epoll_table[];
226#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
229int sysctl_legacy_va_layout;
230#endif
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232/* The default sysctl tables: */
233
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800234static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 .procname = "kernel",
237 .mode = 0555,
238 .child = kern_table,
239 },
240 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .procname = "vm",
242 .mode = 0555,
243 .child = vm_table,
244 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .procname = "fs",
247 .mode = 0555,
248 .child = fs_table,
249 },
250 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 .procname = "debug",
252 .mode = 0555,
253 .child = debug_table,
254 },
255 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .procname = "dev",
257 .mode = 0555,
258 .child = dev_table,
259 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700260 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261};
262
Ingo Molnar77e54a12007-07-09 18:52:00 +0200263#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100264static int min_sched_granularity_ns = 100000; /* 100 usecs */
265static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
266static int min_wakeup_granularity_ns; /* 0 usecs */
267static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200268#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100269static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
270static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200271#endif /* CONFIG_SMP */
272#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200273
Mel Gorman5e771902010-05-24 14:32:31 -0700274#ifdef CONFIG_COMPACTION
275static int min_extfrag_threshold;
276static int max_extfrag_threshold = 1000;
277#endif
278
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700279static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200280 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200281 .procname = "sched_child_runs_first",
282 .data = &sysctl_sched_child_runs_first,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800285 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200286 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200287#ifdef CONFIG_SCHED_DEBUG
288 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100289 .procname = "sched_min_granularity_ns",
290 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800293 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200296 },
297 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200298 .procname = "sched_latency_ns",
299 .data = &sysctl_sched_latency,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800302 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200303 .extra1 = &min_sched_granularity_ns,
304 .extra2 = &max_sched_granularity_ns,
305 },
306 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200307 .procname = "sched_wakeup_granularity_ns",
308 .data = &sysctl_sched_wakeup_granularity,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800311 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200312 .extra1 = &min_wakeup_granularity_ns,
313 .extra2 = &max_wakeup_granularity_ns,
314 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200315#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200316 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100317 .procname = "sched_tunable_scaling",
318 .data = &sysctl_sched_tunable_scaling,
319 .maxlen = sizeof(enum sched_tunable_scaling),
320 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800321 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100322 .extra1 = &min_sched_tunable_scaling,
323 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200324 },
325 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900326 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200327 .data = &sysctl_sched_migration_cost,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800330 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200331 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100332 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100333 .procname = "sched_nr_migrate",
334 .data = &sysctl_sched_nr_migrate,
335 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800337 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100338 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530339 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900340 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200341 .data = &sysctl_sched_time_avg,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800344 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200345 },
346 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900347 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800348 .data = &sysctl_sched_shares_window,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
351 .proc_handler = proc_dointvec,
352 },
353 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530354 .procname = "timer_migration",
355 .data = &sysctl_timer_migration,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800358 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530359 .extra1 = &zero,
360 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530361 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200362#endif /* CONFIG_SMP */
363#ifdef CONFIG_NUMA_BALANCING
364 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200365 .procname = "numa_balancing_scan_delay_ms",
366 .data = &sysctl_numa_balancing_scan_delay,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
369 .proc_handler = proc_dointvec,
370 },
371 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200372 .procname = "numa_balancing_scan_period_min_ms",
373 .data = &sysctl_numa_balancing_scan_period_min,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
376 .proc_handler = proc_dointvec,
377 },
378 {
379 .procname = "numa_balancing_scan_period_max_ms",
380 .data = &sysctl_numa_balancing_scan_period_max,
381 .maxlen = sizeof(unsigned int),
382 .mode = 0644,
383 .proc_handler = proc_dointvec,
384 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200385 {
386 .procname = "numa_balancing_scan_size_mb",
387 .data = &sysctl_numa_balancing_scan_size,
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400390 .proc_handler = proc_dointvec_minmax,
391 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200392 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100393 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800394 .procname = "numa_balancing",
395 .data = NULL, /* filled in by handler */
396 .maxlen = sizeof(unsigned int),
397 .mode = 0644,
398 .proc_handler = sysctl_numa_balancing,
399 .extra1 = &zero,
400 .extra2 = &one,
401 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200402#endif /* CONFIG_NUMA_BALANCING */
403#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200404 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100405 .procname = "sched_rt_period_us",
406 .data = &sysctl_sched_rt_period,
407 .maxlen = sizeof(unsigned int),
408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800409 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100410 },
411 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100412 .procname = "sched_rt_runtime_us",
413 .data = &sysctl_sched_rt_runtime,
414 .maxlen = sizeof(int),
415 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800416 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100417 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600418 {
419 .procname = "sched_rr_timeslice_ms",
420 .data = &sched_rr_timeslice,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = sched_rr_handler,
424 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100425#ifdef CONFIG_SCHED_AUTOGROUP
426 {
427 .procname = "sched_autogroup_enabled",
428 .data = &sysctl_sched_autogroup_enabled,
429 .maxlen = sizeof(unsigned int),
430 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800431 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100432 .extra1 = &zero,
433 .extra2 = &one,
434 },
435#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700436#ifdef CONFIG_CFS_BANDWIDTH
437 {
438 .procname = "sched_cfs_bandwidth_slice_us",
439 .data = &sysctl_sched_cfs_bandwidth_slice,
440 .maxlen = sizeof(unsigned int),
441 .mode = 0644,
442 .proc_handler = proc_dointvec_minmax,
443 .extra1 = &one,
444 },
445#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700446#ifdef CONFIG_PROVE_LOCKING
447 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700448 .procname = "prove_locking",
449 .data = &prove_locking,
450 .maxlen = sizeof(int),
451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800452 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700453 },
454#endif
455#ifdef CONFIG_LOCK_STAT
456 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700457 .procname = "lock_stat",
458 .data = &lock_stat,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800461 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700462 },
463#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200464 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .procname = "panic",
466 .data = &panic_timeout,
467 .maxlen = sizeof(int),
468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800469 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 },
Alex Kelly046d6622012-10-04 17:15:23 -0700471#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .procname = "core_uses_pid",
474 .data = &core_uses_pid,
475 .maxlen = sizeof(int),
476 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800477 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 },
479 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .procname = "core_pattern",
481 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700482 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700484 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 },
Neil Hormana2939802009-09-23 15:56:56 -0700486 {
Neil Hormana2939802009-09-23 15:56:56 -0700487 .procname = "core_pipe_limit",
488 .data = &core_pipe_limit,
489 .maxlen = sizeof(unsigned int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700492 },
Alex Kelly046d6622012-10-04 17:15:23 -0700493#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800494#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700497 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800499 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700501 {
502 .procname = "sysctl_writes_strict",
503 .data = &sysctl_writes_strict,
504 .maxlen = sizeof(int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &neg_one,
508 .extra2 = &one,
509 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800510#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100511#ifdef CONFIG_LATENCYTOP
512 {
513 .procname = "latencytop",
514 .data = &latencytop_enabled,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800517 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100518 },
519#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#ifdef CONFIG_BLK_DEV_INITRD
521 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .procname = "real-root-dev",
523 .data = &real_root_dev,
524 .maxlen = sizeof(int),
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
528#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700529 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700530 .procname = "print-fatal-signals",
531 .data = &print_fatal_signals,
532 .maxlen = sizeof(int),
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700535 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700536#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 .procname = "reboot-cmd",
539 .data = reboot_command,
540 .maxlen = 256,
541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800542 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 },
544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .procname = "stop-a",
546 .data = &stop_a_enabled,
547 .maxlen = sizeof (int),
548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800549 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 },
551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 .procname = "scons-poweroff",
553 .data = &scons_pwroff,
554 .maxlen = sizeof (int),
555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 },
558#endif
David S. Miller08714202008-11-16 23:49:24 -0800559#ifdef CONFIG_SPARC64
560 {
David S. Miller08714202008-11-16 23:49:24 -0800561 .procname = "tsb-ratio",
562 .data = &sysctl_tsb_ratio,
563 .maxlen = sizeof (int),
564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800565 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800566 },
567#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#ifdef __hppa__
569 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .procname = "soft-power",
571 .data = &pwrsw_enabled,
572 .maxlen = sizeof (int),
573 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800574 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530576#endif
577#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "unaligned-trap",
580 .data = &unaligned_enabled,
581 .maxlen = sizeof (int),
582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800583 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
585#endif
586 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .procname = "ctrl-alt-del",
588 .data = &C_A_D,
589 .maxlen = sizeof(int),
590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800591 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400593#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200594 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200595 .procname = "ftrace_enabled",
596 .data = &ftrace_enabled,
597 .maxlen = sizeof(int),
598 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800599 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200600 },
601#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500602#ifdef CONFIG_STACK_TRACER
603 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500604 .procname = "stack_tracer_enabled",
605 .data = &stack_tracer_enabled,
606 .maxlen = sizeof(int),
607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500609 },
610#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400611#ifdef CONFIG_TRACING
612 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100613 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400614 .data = &ftrace_dump_on_oops,
615 .maxlen = sizeof(int),
616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800617 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400618 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400619 {
620 .procname = "traceoff_on_warning",
621 .data = &__disable_trace_on_warning,
622 .maxlen = sizeof(__disable_trace_on_warning),
623 .mode = 0644,
624 .proc_handler = proc_dointvec,
625 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500626 {
627 .procname = "tracepoint_printk",
628 .data = &tracepoint_printk,
629 .maxlen = sizeof(tracepoint_printk),
630 .mode = 0644,
631 .proc_handler = proc_dointvec,
632 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400633#endif
Kees Cook79847542014-01-23 15:55:59 -0800634#ifdef CONFIG_KEXEC
635 {
636 .procname = "kexec_load_disabled",
637 .data = &kexec_load_disabled,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 /* only handle a transition from default "0" to "1" */
641 .proc_handler = proc_dointvec_minmax,
642 .extra1 = &one,
643 .extra2 = &one,
644 },
645#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200646#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 .procname = "modprobe",
649 .data = &modprobe_path,
650 .maxlen = KMOD_PATH_LEN,
651 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800652 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 },
Kees Cook3d433212009-04-02 15:49:29 -0700654 {
Kees Cook3d433212009-04-02 15:49:29 -0700655 .procname = "modules_disabled",
656 .data = &modules_disabled,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800660 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700661 .extra1 = &one,
662 .extra2 = &one,
663 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700665#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100668 .data = &uevent_helper,
669 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800671 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 },
Michael Marineau86d56132014-04-10 14:09:31 -0700673#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#ifdef CONFIG_CHR_DEV_SG
675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .procname = "sg-big-buff",
677 .data = &sg_big_buff,
678 .maxlen = sizeof (int),
679 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800680 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 },
682#endif
683#ifdef CONFIG_BSD_PROCESS_ACCT
684 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .procname = "acct",
686 .data = &acct_parm,
687 .maxlen = 3*sizeof(int),
688 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800689 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 },
691#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692#ifdef CONFIG_MAGIC_SYSRQ
693 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800695 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .maxlen = sizeof (int),
697 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700698 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 },
700#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700701#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700704 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .maxlen = sizeof (int),
706 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800707 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700709#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 .procname = "threads-max",
712 .data = &max_threads,
713 .maxlen = sizeof(int),
714 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800715 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 },
717 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 .procname = "random",
719 .mode = 0555,
720 .child = random_table,
721 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 {
Eric Paris17f60a72011-04-01 17:07:50 -0400723 .procname = "usermodehelper",
724 .mode = 0555,
725 .child = usermodehelper_table,
726 },
727 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .procname = "overflowuid",
729 .data = &overflowuid,
730 .maxlen = sizeof(int),
731 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800732 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 .extra1 = &minolduid,
734 .extra2 = &maxolduid,
735 },
736 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 .procname = "overflowgid",
738 .data = &overflowgid,
739 .maxlen = sizeof(int),
740 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800741 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 .extra1 = &minolduid,
743 .extra2 = &maxolduid,
744 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800745#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#ifdef CONFIG_MATHEMU
747 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .procname = "ieee_emulation_warnings",
749 .data = &sysctl_ieee_emulation_warnings,
750 .maxlen = sizeof(int),
751 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800752 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 },
754#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200757 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .maxlen = sizeof(int),
759 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800760 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 },
762#endif
763 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .procname = "pid_max",
765 .data = &pid_max,
766 .maxlen = sizeof (int),
767 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800768 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .extra1 = &pid_max_min,
770 .extra2 = &pid_max_max,
771 },
772 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 .procname = "panic_on_oops",
774 .data = &panic_on_oops,
775 .maxlen = sizeof(int),
776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800777 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800779#if defined CONFIG_PRINTK
780 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800781 .procname = "printk",
782 .data = &console_loglevel,
783 .maxlen = 4*sizeof(int),
784 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800785 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800786 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700789 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .maxlen = sizeof(int),
791 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800792 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 },
794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700796 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 .maxlen = sizeof(int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 },
Dave Youngaf913222009-09-22 16:43:33 -0700801 {
Dave Youngaf913222009-09-22 16:43:33 -0700802 .procname = "printk_delay",
803 .data = &printk_delay_msec,
804 .maxlen = sizeof(int),
805 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800806 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700807 .extra1 = &zero,
808 .extra2 = &ten_thousand,
809 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800811 .procname = "dmesg_restrict",
812 .data = &dmesg_restrict,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700815 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800816 .extra1 = &zero,
817 .extra2 = &one,
818 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800819 {
820 .procname = "kptr_restrict",
821 .data = &kptr_restrict,
822 .maxlen = sizeof(int),
823 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700824 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800825 .extra1 = &zero,
826 .extra2 = &two,
827 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800828#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800829 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 .procname = "ngroups_max",
831 .data = &ngroups_max,
832 .maxlen = sizeof (int),
833 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800834 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 },
Dan Ballard73efc032011-10-31 17:11:20 -0700836 {
837 .procname = "cap_last_cap",
838 .data = (void *)&cap_last_cap,
839 .maxlen = sizeof(int),
840 .mode = 0444,
841 .proc_handler = proc_dointvec,
842 },
Don Zickus58687ac2010-05-07 17:11:44 -0400843#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500844 {
Don Zickus58687ac2010-05-07 17:11:44 -0400845 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200846 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500847 .maxlen = sizeof (int),
848 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700849 .proc_handler = proc_dowatchdog,
850 .extra1 = &zero,
851 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400852 },
853 {
854 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700855 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400856 .maxlen = sizeof(int),
857 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700858 .proc_handler = proc_dowatchdog,
Li Zefana6572f82013-05-17 10:31:04 +0800859 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400860 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500861 },
Don Zickus2508ce12010-05-07 17:11:46 -0400862 {
863 .procname = "softlockup_panic",
864 .data = &softlockup_panic,
865 .maxlen = sizeof(int),
866 .mode = 0644,
867 .proc_handler = proc_dointvec_minmax,
868 .extra1 = &zero,
869 .extra2 = &one,
870 },
Aaron Tomlined235872014-06-23 13:22:05 -0700871#ifdef CONFIG_SMP
872 {
873 .procname = "softlockup_all_cpu_backtrace",
874 .data = &sysctl_softlockup_all_cpu_backtrace,
875 .maxlen = sizeof(int),
876 .mode = 0644,
877 .proc_handler = proc_dointvec_minmax,
878 .extra1 = &zero,
879 .extra2 = &one,
880 },
881#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500882 {
883 .procname = "nmi_watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200884 .data = &watchdog_user_enabled,
Don Zickus5dc30552010-11-29 17:07:17 -0500885 .maxlen = sizeof (int),
886 .mode = 0644,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700887 .proc_handler = proc_dowatchdog,
888 .extra1 = &zero,
889 .extra2 = &one,
Don Zickus5dc30552010-11-29 17:07:17 -0500890 },
891#endif
892#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
893 {
894 .procname = "unknown_nmi_panic",
895 .data = &unknown_nmi_panic,
896 .maxlen = sizeof (int),
897 .mode = 0644,
898 .proc_handler = proc_dointvec,
899 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500900#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901#if defined(CONFIG_X86)
902 {
Don Zickus8da5add2006-09-26 10:52:27 +0200903 .procname = "panic_on_unrecovered_nmi",
904 .data = &panic_on_unrecovered_nmi,
905 .maxlen = sizeof(int),
906 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800907 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200908 },
909 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700910 .procname = "panic_on_io_nmi",
911 .data = &panic_on_io_nmi,
912 .maxlen = sizeof(int),
913 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800914 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700915 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900916#ifdef CONFIG_DEBUG_STACKOVERFLOW
917 {
918 .procname = "panic_on_stackoverflow",
919 .data = &sysctl_panic_on_stackoverflow,
920 .maxlen = sizeof(int),
921 .mode = 0644,
922 .proc_handler = proc_dointvec,
923 },
924#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700925 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 .procname = "bootloader_type",
927 .data = &bootloader_type,
928 .maxlen = sizeof (int),
929 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800930 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100932 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700933 .procname = "bootloader_version",
934 .data = &bootloader_version,
935 .maxlen = sizeof (int),
936 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800937 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700938 },
939 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100940 .procname = "kstack_depth_to_print",
941 .data = &kstack_depth_to_print,
942 .maxlen = sizeof(int),
943 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800944 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100945 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100946 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100947 .procname = "io_delay_type",
948 .data = &io_delay_type,
949 .maxlen = sizeof(int),
950 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800951 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100952 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800954#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 .procname = "randomize_va_space",
957 .data = &randomize_va_space,
958 .maxlen = sizeof(int),
959 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800960 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800962#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800963#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700964 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700965 .procname = "spin_retry",
966 .data = &spin_retry,
967 .maxlen = sizeof (int),
968 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800969 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700970 },
971#endif
Len Brown673d5b42007-07-28 03:33:16 -0400972#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800973 {
Pavel Machekc255d842006-02-20 18:27:58 -0800974 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700975 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800976 .maxlen = sizeof (unsigned long),
977 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800978 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800979 },
980#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530981#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -0800982 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800983 .procname = "ignore-unaligned-usertrap",
984 .data = &no_unaligned_warning,
985 .maxlen = sizeof (int),
986 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800987 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -0800988 },
Vineet Guptab6fca722013-01-09 20:06:28 +0530989#endif
990#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800991 {
Doug Chapman88fc2412009-01-15 10:38:56 -0800992 .procname = "unaligned-dump-stack",
993 .data = &unaligned_dump_stack,
994 .maxlen = sizeof (int),
995 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800996 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -0800997 },
Jes Sorensend2b176e2006-02-28 09:42:23 -0800998#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -0800999#ifdef CONFIG_DETECT_HUNG_TASK
1000 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001001 .procname = "hung_task_panic",
1002 .data = &sysctl_hung_task_panic,
1003 .maxlen = sizeof(int),
1004 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001005 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001006 .extra1 = &zero,
1007 .extra2 = &one,
1008 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001009 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001010 .procname = "hung_task_check_count",
1011 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001012 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001013 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001014 .proc_handler = proc_dointvec_minmax,
1015 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001016 },
1017 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001018 .procname = "hung_task_timeout_secs",
1019 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001020 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001021 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001022 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001023 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001024 },
1025 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001026 .procname = "hung_task_warnings",
1027 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001028 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001029 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001030 .proc_handler = proc_dointvec_minmax,
1031 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001032 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001033#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001034#ifdef CONFIG_COMPAT
1035 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001036 .procname = "compat-log",
1037 .data = &compat_log,
1038 .maxlen = sizeof (int),
1039 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001040 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001041 },
1042#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001043#ifdef CONFIG_RT_MUTEXES
1044 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001045 .procname = "max_lock_depth",
1046 .data = &max_lock_depth,
1047 .maxlen = sizeof(int),
1048 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001049 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001050 },
1051#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001052 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001053 .procname = "poweroff_cmd",
1054 .data = &poweroff_cmd,
1055 .maxlen = POWEROFF_CMD_PATH_LEN,
1056 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001057 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001058 },
David Howells0b77f5b2008-04-29 01:01:32 -07001059#ifdef CONFIG_KEYS
1060 {
David Howells0b77f5b2008-04-29 01:01:32 -07001061 .procname = "keys",
1062 .mode = 0555,
1063 .child = key_sysctls,
1064 },
1065#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001066#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001067 /*
1068 * User-space scripts rely on the existence of this file
1069 * as a feature check for perf_events being enabled.
1070 *
1071 * So it's an ABI, do not remove!
1072 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001073 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001074 .procname = "perf_event_paranoid",
1075 .data = &sysctl_perf_event_paranoid,
1076 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001079 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001080 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001081 .procname = "perf_event_mlock_kb",
1082 .data = &sysctl_perf_event_mlock,
1083 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001084 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001085 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001086 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001087 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001088 .procname = "perf_event_max_sample_rate",
1089 .data = &sysctl_perf_event_sample_rate,
1090 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001091 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001092 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001093 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001094 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001095 {
1096 .procname = "perf_cpu_time_max_percent",
1097 .data = &sysctl_perf_cpu_time_max_percent,
1098 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1099 .mode = 0644,
1100 .proc_handler = perf_cpu_time_max_percent_handler,
1101 .extra1 = &zero,
1102 .extra2 = &one_hundred,
1103 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001104#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001105#ifdef CONFIG_KMEMCHECK
1106 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001107 .procname = "kmemcheck",
1108 .data = &kmemcheck_enabled,
1109 .maxlen = sizeof(int),
1110 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001111 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001112 },
1113#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001114 {
1115 .procname = "panic_on_warn",
1116 .data = &panic_on_warn,
1117 .maxlen = sizeof(int),
1118 .mode = 0644,
1119 .proc_handler = proc_dointvec_minmax,
1120 .extra1 = &zero,
1121 .extra2 = &one,
1122 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001123 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124};
1125
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001126static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 .procname = "overcommit_memory",
1129 .data = &sysctl_overcommit_memory,
1130 .maxlen = sizeof(sysctl_overcommit_memory),
1131 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001132 .proc_handler = proc_dointvec_minmax,
1133 .extra1 = &zero,
1134 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 },
1136 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001137 .procname = "panic_on_oom",
1138 .data = &sysctl_panic_on_oom,
1139 .maxlen = sizeof(sysctl_panic_on_oom),
1140 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001141 .proc_handler = proc_dointvec_minmax,
1142 .extra1 = &zero,
1143 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001144 },
1145 {
David Rientjesfe071d72007-10-16 23:25:56 -07001146 .procname = "oom_kill_allocating_task",
1147 .data = &sysctl_oom_kill_allocating_task,
1148 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1149 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001150 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001151 },
1152 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001153 .procname = "oom_dump_tasks",
1154 .data = &sysctl_oom_dump_tasks,
1155 .maxlen = sizeof(sysctl_oom_dump_tasks),
1156 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001157 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001158 },
1159 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 .procname = "overcommit_ratio",
1161 .data = &sysctl_overcommit_ratio,
1162 .maxlen = sizeof(sysctl_overcommit_ratio),
1163 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001164 .proc_handler = overcommit_ratio_handler,
1165 },
1166 {
1167 .procname = "overcommit_kbytes",
1168 .data = &sysctl_overcommit_kbytes,
1169 .maxlen = sizeof(sysctl_overcommit_kbytes),
1170 .mode = 0644,
1171 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 },
1173 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 .procname = "page-cluster",
1175 .data = &page_cluster,
1176 .maxlen = sizeof(int),
1177 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001178 .proc_handler = proc_dointvec_minmax,
1179 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 },
1181 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 .procname = "dirty_background_ratio",
1183 .data = &dirty_background_ratio,
1184 .maxlen = sizeof(dirty_background_ratio),
1185 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001186 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 .extra1 = &zero,
1188 .extra2 = &one_hundred,
1189 },
1190 {
David Rientjes2da02992009-01-06 14:39:31 -08001191 .procname = "dirty_background_bytes",
1192 .data = &dirty_background_bytes,
1193 .maxlen = sizeof(dirty_background_bytes),
1194 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001195 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001196 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001197 },
1198 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 .procname = "dirty_ratio",
1200 .data = &vm_dirty_ratio,
1201 .maxlen = sizeof(vm_dirty_ratio),
1202 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001203 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 .extra1 = &zero,
1205 .extra2 = &one_hundred,
1206 },
1207 {
David Rientjes2da02992009-01-06 14:39:31 -08001208 .procname = "dirty_bytes",
1209 .data = &vm_dirty_bytes,
1210 .maxlen = sizeof(vm_dirty_bytes),
1211 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001212 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001213 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001214 },
1215 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001217 .data = &dirty_writeback_interval,
1218 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001220 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 },
1222 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001224 .data = &dirty_expire_interval,
1225 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001227 .proc_handler = proc_dointvec_minmax,
1228 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 },
1230 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001231 .procname = "nr_pdflush_threads",
1232 .mode = 0444 /* read-only */,
1233 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 },
1235 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 .procname = "swappiness",
1237 .data = &vm_swappiness,
1238 .maxlen = sizeof(vm_swappiness),
1239 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001240 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 .extra1 = &zero,
1242 .extra2 = &one_hundred,
1243 },
1244#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001245 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001247 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 .maxlen = sizeof(unsigned long),
1249 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001250 .proc_handler = hugetlb_sysctl_handler,
David Rientjesed4d4902014-08-06 16:06:54 -07001251 .extra1 = &zero,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001252 },
1253#ifdef CONFIG_NUMA
1254 {
1255 .procname = "nr_hugepages_mempolicy",
1256 .data = NULL,
1257 .maxlen = sizeof(unsigned long),
1258 .mode = 0644,
1259 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
David Rientjesed4d4902014-08-06 16:06:54 -07001260 .extra1 = &zero,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001261 },
1262#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 .procname = "hugetlb_shm_group",
1265 .data = &sysctl_hugetlb_shm_group,
1266 .maxlen = sizeof(gid_t),
1267 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001268 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 },
Mel Gorman396faf02007-07-17 04:03:13 -07001270 {
Mel Gorman396faf02007-07-17 04:03:13 -07001271 .procname = "hugepages_treat_as_movable",
1272 .data = &hugepages_treat_as_movable,
1273 .maxlen = sizeof(int),
1274 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001275 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001276 },
Adam Litke54f9f802007-10-16 01:26:20 -07001277 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001278 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001279 .data = NULL,
1280 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = hugetlb_overcommit_handler,
David Rientjesed4d4902014-08-06 16:06:54 -07001283 .extra1 = &zero,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001284 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285#endif
1286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 .procname = "lowmem_reserve_ratio",
1288 .data = &sysctl_lowmem_reserve_ratio,
1289 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1290 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001291 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 },
1293 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001294 .procname = "drop_caches",
1295 .data = &sysctl_drop_caches,
1296 .maxlen = sizeof(int),
1297 .mode = 0644,
1298 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001299 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001300 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001301 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001302#ifdef CONFIG_COMPACTION
1303 {
1304 .procname = "compact_memory",
1305 .data = &sysctl_compact_memory,
1306 .maxlen = sizeof(int),
1307 .mode = 0200,
1308 .proc_handler = sysctl_compaction_handler,
1309 },
Mel Gorman5e771902010-05-24 14:32:31 -07001310 {
1311 .procname = "extfrag_threshold",
1312 .data = &sysctl_extfrag_threshold,
1313 .maxlen = sizeof(int),
1314 .mode = 0644,
1315 .proc_handler = sysctl_extfrag_handler,
1316 .extra1 = &min_extfrag_threshold,
1317 .extra2 = &max_extfrag_threshold,
1318 },
1319
Mel Gorman76ab0f52010-05-24 14:32:28 -07001320#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001321 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 .procname = "min_free_kbytes",
1323 .data = &min_free_kbytes,
1324 .maxlen = sizeof(min_free_kbytes),
1325 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001326 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 .extra1 = &zero,
1328 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001329 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001330 .procname = "percpu_pagelist_fraction",
1331 .data = &percpu_pagelist_fraction,
1332 .maxlen = sizeof(percpu_pagelist_fraction),
1333 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001334 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001335 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001336 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337#ifdef CONFIG_MMU
1338 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 .procname = "max_map_count",
1340 .data = &sysctl_max_map_count,
1341 .maxlen = sizeof(sysctl_max_map_count),
1342 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001343 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001344 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001346#else
1347 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001348 .procname = "nr_trim_pages",
1349 .data = &sysctl_nr_trim_pages,
1350 .maxlen = sizeof(sysctl_nr_trim_pages),
1351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001353 .extra1 = &zero,
1354 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355#endif
1356 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 .procname = "laptop_mode",
1358 .data = &laptop_mode,
1359 .maxlen = sizeof(laptop_mode),
1360 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001361 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 },
1363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .procname = "block_dump",
1365 .data = &block_dump,
1366 .maxlen = sizeof(block_dump),
1367 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001368 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .extra1 = &zero,
1370 },
1371 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 .procname = "vfs_cache_pressure",
1373 .data = &sysctl_vfs_cache_pressure,
1374 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1375 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001376 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 .extra1 = &zero,
1378 },
1379#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1380 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 .procname = "legacy_va_layout",
1382 .data = &sysctl_legacy_va_layout,
1383 .maxlen = sizeof(sysctl_legacy_va_layout),
1384 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001385 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .extra1 = &zero,
1387 },
1388#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001389#ifdef CONFIG_NUMA
1390 {
Christoph Lameter17436602006-01-18 17:42:32 -08001391 .procname = "zone_reclaim_mode",
1392 .data = &zone_reclaim_mode,
1393 .maxlen = sizeof(zone_reclaim_mode),
1394 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001395 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001396 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001397 },
Christoph Lameter96146342006-07-03 00:24:13 -07001398 {
Christoph Lameter96146342006-07-03 00:24:13 -07001399 .procname = "min_unmapped_ratio",
1400 .data = &sysctl_min_unmapped_ratio,
1401 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001404 .extra1 = &zero,
1405 .extra2 = &one_hundred,
1406 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001407 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001408 .procname = "min_slab_ratio",
1409 .data = &sysctl_min_slab_ratio,
1410 .maxlen = sizeof(sysctl_min_slab_ratio),
1411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001412 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001413 .extra1 = &zero,
1414 .extra2 = &one_hundred,
1415 },
Christoph Lameter17436602006-01-18 17:42:32 -08001416#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001417#ifdef CONFIG_SMP
1418 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001419 .procname = "stat_interval",
1420 .data = &sysctl_stat_interval,
1421 .maxlen = sizeof(sysctl_stat_interval),
1422 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001423 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001424 },
1425#endif
David Howells6e141542009-12-15 19:27:45 +00001426#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001427 {
Eric Parised032182007-06-28 15:55:21 -04001428 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001429 .data = &dac_mmap_min_addr,
1430 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001431 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001432 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001433 },
David Howells6e141542009-12-15 19:27:45 +00001434#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001435#ifdef CONFIG_NUMA
1436 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001437 .procname = "numa_zonelist_order",
1438 .data = &numa_zonelist_order,
1439 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001441 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001442 },
1443#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001444#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001445 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001446 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001447 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001448#ifdef CONFIG_X86_32
1449 .data = &vdso32_enabled,
1450 .maxlen = sizeof(vdso32_enabled),
1451#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001452 .data = &vdso_enabled,
1453 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001454#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001455 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001456 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001457 .extra1 = &zero,
1458 },
1459#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001460#ifdef CONFIG_HIGHMEM
1461 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001462 .procname = "highmem_is_dirtyable",
1463 .data = &vm_highmem_is_dirtyable,
1464 .maxlen = sizeof(vm_highmem_is_dirtyable),
1465 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001466 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001467 .extra1 = &zero,
1468 .extra2 = &one,
1469 },
1470#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001471#ifdef CONFIG_MEMORY_FAILURE
1472 {
Andi Kleen6a460792009-09-16 11:50:15 +02001473 .procname = "memory_failure_early_kill",
1474 .data = &sysctl_memory_failure_early_kill,
1475 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1476 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001477 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001478 .extra1 = &zero,
1479 .extra2 = &one,
1480 },
1481 {
Andi Kleen6a460792009-09-16 11:50:15 +02001482 .procname = "memory_failure_recovery",
1483 .data = &sysctl_memory_failure_recovery,
1484 .maxlen = sizeof(sysctl_memory_failure_recovery),
1485 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001486 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001487 .extra1 = &zero,
1488 .extra2 = &one,
1489 },
1490#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001491 {
1492 .procname = "user_reserve_kbytes",
1493 .data = &sysctl_user_reserve_kbytes,
1494 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1495 .mode = 0644,
1496 .proc_handler = proc_doulongvec_minmax,
1497 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001498 {
1499 .procname = "admin_reserve_kbytes",
1500 .data = &sysctl_admin_reserve_kbytes,
1501 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1502 .mode = 0644,
1503 .proc_handler = proc_doulongvec_minmax,
1504 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001505 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506};
1507
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001508#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001509static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001510 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001511};
1512#endif
1513
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001514static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 .procname = "inode-nr",
1517 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001518 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001520 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 },
1522 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 .procname = "inode-state",
1524 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001525 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001527 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 },
1529 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 .procname = "file-nr",
1531 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001532 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001534 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 },
1536 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 .procname = "file-max",
1538 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001539 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001541 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 },
1543 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001544 .procname = "nr_open",
1545 .data = &sysctl_nr_open,
1546 .maxlen = sizeof(int),
1547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001548 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001549 .extra1 = &sysctl_nr_open_min,
1550 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001551 },
1552 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 .procname = "dentry-state",
1554 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001555 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001557 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 },
1559 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 .procname = "overflowuid",
1561 .data = &fs_overflowuid,
1562 .maxlen = sizeof(int),
1563 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001564 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 .extra1 = &minolduid,
1566 .extra2 = &maxolduid,
1567 },
1568 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 .procname = "overflowgid",
1570 .data = &fs_overflowgid,
1571 .maxlen = sizeof(int),
1572 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001573 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 .extra1 = &minolduid,
1575 .extra2 = &maxolduid,
1576 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001577#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 .procname = "leases-enable",
1580 .data = &leases_enable,
1581 .maxlen = sizeof(int),
1582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001583 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586#ifdef CONFIG_DNOTIFY
1587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 .procname = "dir-notify-enable",
1589 .data = &dir_notify_enable,
1590 .maxlen = sizeof(int),
1591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001592 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 },
1594#endif
1595#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001596#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 .procname = "lease-break-time",
1599 .data = &lease_break_time,
1600 .maxlen = sizeof(int),
1601 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001602 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001604#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001605#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 .procname = "aio-nr",
1608 .data = &aio_nr,
1609 .maxlen = sizeof(aio_nr),
1610 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001611 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 },
1613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 .procname = "aio-max-nr",
1615 .data = &aio_max_nr,
1616 .maxlen = sizeof(aio_max_nr),
1617 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001618 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001620#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001621#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001622 {
Robert Love0399cb02005-07-13 12:38:18 -04001623 .procname = "inotify",
1624 .mode = 0555,
1625 .child = inotify_table,
1626 },
1627#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001628#ifdef CONFIG_EPOLL
1629 {
1630 .procname = "epoll",
1631 .mode = 0555,
1632 .child = epoll_table,
1633 },
1634#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001636 {
Kees Cook800179c2012-07-25 17:29:07 -07001637 .procname = "protected_symlinks",
1638 .data = &sysctl_protected_symlinks,
1639 .maxlen = sizeof(int),
1640 .mode = 0600,
1641 .proc_handler = proc_dointvec_minmax,
1642 .extra1 = &zero,
1643 .extra2 = &one,
1644 },
1645 {
1646 .procname = "protected_hardlinks",
1647 .data = &sysctl_protected_hardlinks,
1648 .maxlen = sizeof(int),
1649 .mode = 0600,
1650 .proc_handler = proc_dointvec_minmax,
1651 .extra1 = &zero,
1652 .extra2 = &one,
1653 },
1654 {
Alan Coxd6e71142005-06-23 00:09:43 -07001655 .procname = "suid_dumpable",
1656 .data = &suid_dumpable,
1657 .maxlen = sizeof(int),
1658 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001659 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001660 .extra1 = &zero,
1661 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001662 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001663#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1664 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001665 .procname = "binfmt_misc",
1666 .mode = 0555,
1667 .child = binfmt_misc_table,
1668 },
1669#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001670 {
Jens Axboeff9da692010-06-03 14:54:39 +02001671 .procname = "pipe-max-size",
1672 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001673 .maxlen = sizeof(int),
1674 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001675 .proc_handler = &pipe_proc_fn,
1676 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001677 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001678 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679};
1680
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001681static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001682#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001683 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001684 .procname = "exception-trace",
1685 .data = &show_unhandled_signals,
1686 .maxlen = sizeof(int),
1687 .mode = 0644,
1688 .proc_handler = proc_dointvec
1689 },
1690#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001691#if defined(CONFIG_OPTPROBES)
1692 {
1693 .procname = "kprobes-optimization",
1694 .data = &sysctl_kprobes_optimization,
1695 .maxlen = sizeof(int),
1696 .mode = 0644,
1697 .proc_handler = proc_kprobes_optimization_handler,
1698 .extra1 = &zero,
1699 .extra2 = &one,
1700 },
1701#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001702 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703};
1704
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001705static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001706 { }
Robert Love0eeca282005-07-12 17:06:03 -04001707};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001709int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001710{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001711 struct ctl_table_header *hdr;
1712
1713 hdr = register_sysctl_table(sysctl_base_table);
1714 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001715 return 0;
1716}
1717
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001718#endif /* CONFIG_SYSCTL */
1719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720/*
1721 * /proc/sys support
1722 */
1723
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001724#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Kees Cookf8808302014-06-06 14:37:17 -07001726static int _proc_do_string(char *data, int maxlen, int write,
1727 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001728 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001729{
1730 size_t len;
1731 char __user *p;
1732 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001733
1734 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001735 *lenp = 0;
1736 return 0;
1737 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001738
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001739 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001740 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1741 /* Only continue writes not past the end of buffer. */
1742 len = strlen(data);
1743 if (len > maxlen - 1)
1744 len = maxlen - 1;
1745
1746 if (*ppos > len)
1747 return 0;
1748 len = *ppos;
1749 } else {
1750 /* Start writing from beginning of buffer. */
1751 len = 0;
1752 }
1753
Kees Cook2ca9bb42014-06-06 14:37:18 -07001754 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001755 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001756 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001757 if (get_user(c, p++))
1758 return -EFAULT;
1759 if (c == 0 || c == '\n')
1760 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001761 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001762 }
Kees Cookf8808302014-06-06 14:37:17 -07001763 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001764 } else {
1765 len = strlen(data);
1766 if (len > maxlen)
1767 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001768
1769 if (*ppos > len) {
1770 *lenp = 0;
1771 return 0;
1772 }
1773
1774 data += *ppos;
1775 len -= *ppos;
1776
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001777 if (len > *lenp)
1778 len = *lenp;
1779 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001780 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001781 return -EFAULT;
1782 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001783 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001784 return -EFAULT;
1785 len++;
1786 }
1787 *lenp = len;
1788 *ppos += len;
1789 }
1790 return 0;
1791}
1792
Kees Cookf4aacea2014-06-06 14:37:19 -07001793static void warn_sysctl_write(struct ctl_table *table)
1794{
1795 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1796 "This will not be supported in the future. To silence this\n"
1797 "warning, set kernel.sysctl_writes_strict = -1\n",
1798 current->comm, table->procname);
1799}
1800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801/**
1802 * proc_dostring - read a string sysctl
1803 * @table: the sysctl table
1804 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 * @buffer: the user buffer
1806 * @lenp: the size of the user buffer
1807 * @ppos: file position
1808 *
1809 * Reads/writes a string from/to the user buffer. If the kernel
1810 * buffer provided is not large enough to hold the string, the
1811 * string is truncated. The copied string is %NULL-terminated.
1812 * If the string is being read by the user process, it is copied
1813 * and a newline '\n' is added. It is truncated if the buffer is
1814 * not large enough.
1815 *
1816 * Returns 0 on success.
1817 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001818int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 void __user *buffer, size_t *lenp, loff_t *ppos)
1820{
Kees Cookf4aacea2014-06-06 14:37:19 -07001821 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1822 warn_sysctl_write(table);
1823
Kees Cookf8808302014-06-06 14:37:17 -07001824 return _proc_do_string((char *)(table->data), table->maxlen, write,
1825 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826}
1827
Amerigo Wang00b7c332010-05-05 00:26:45 +00001828static size_t proc_skip_spaces(char **buf)
1829{
1830 size_t ret;
1831 char *tmp = skip_spaces(*buf);
1832 ret = tmp - *buf;
1833 *buf = tmp;
1834 return ret;
1835}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001837static void proc_skip_char(char **buf, size_t *size, const char v)
1838{
1839 while (*size) {
1840 if (**buf != v)
1841 break;
1842 (*size)--;
1843 (*buf)++;
1844 }
1845}
1846
Amerigo Wang00b7c332010-05-05 00:26:45 +00001847#define TMPBUFLEN 22
1848/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001849 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001850 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001851 * @buf: a kernel buffer
1852 * @size: size of the kernel buffer
1853 * @val: this is where the number will be stored
1854 * @neg: set to %TRUE if number is negative
1855 * @perm_tr: a vector which contains the allowed trailers
1856 * @perm_tr_len: size of the perm_tr vector
1857 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001858 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001859 * In case of success %0 is returned and @buf and @size are updated with
1860 * the amount of bytes read. If @tr is non-NULL and a trailing
1861 * character exists (size is non-zero after returning from this
1862 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001863 */
1864static int proc_get_long(char **buf, size_t *size,
1865 unsigned long *val, bool *neg,
1866 const char *perm_tr, unsigned perm_tr_len, char *tr)
1867{
1868 int len;
1869 char *p, tmp[TMPBUFLEN];
1870
1871 if (!*size)
1872 return -EINVAL;
1873
1874 len = *size;
1875 if (len > TMPBUFLEN - 1)
1876 len = TMPBUFLEN - 1;
1877
1878 memcpy(tmp, *buf, len);
1879
1880 tmp[len] = 0;
1881 p = tmp;
1882 if (*p == '-' && *size > 1) {
1883 *neg = true;
1884 p++;
1885 } else
1886 *neg = false;
1887 if (!isdigit(*p))
1888 return -EINVAL;
1889
1890 *val = simple_strtoul(p, &p, 0);
1891
1892 len = p - tmp;
1893
1894 /* We don't know if the next char is whitespace thus we may accept
1895 * invalid integers (e.g. 1234...a) or two integers instead of one
1896 * (e.g. 123...1). So lets not allow such large numbers. */
1897 if (len == TMPBUFLEN - 1)
1898 return -EINVAL;
1899
1900 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1901 return -EINVAL;
1902
1903 if (tr && (len < *size))
1904 *tr = *p;
1905
1906 *buf += len;
1907 *size -= len;
1908
1909 return 0;
1910}
1911
1912/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001913 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001914 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001915 * @buf: the user buffer
1916 * @size: the size of the user buffer
1917 * @val: the integer to be converted
1918 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001919 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001920 * In case of success %0 is returned and @buf and @size are updated with
1921 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001922 */
1923static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1924 bool neg)
1925{
1926 int len;
1927 char tmp[TMPBUFLEN], *p = tmp;
1928
1929 sprintf(p, "%s%lu", neg ? "-" : "", val);
1930 len = strlen(tmp);
1931 if (len > *size)
1932 len = *size;
1933 if (copy_to_user(*buf, tmp, len))
1934 return -EFAULT;
1935 *size -= len;
1936 *buf += len;
1937 return 0;
1938}
1939#undef TMPBUFLEN
1940
1941static int proc_put_char(void __user **buf, size_t *size, char c)
1942{
1943 if (*size) {
1944 char __user **buffer = (char __user **)buf;
1945 if (put_user(c, *buffer))
1946 return -EFAULT;
1947 (*size)--, (*buffer)++;
1948 *buf = *buffer;
1949 }
1950 return 0;
1951}
1952
1953static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 int *valp,
1955 int write, void *data)
1956{
1957 if (write) {
1958 *valp = *negp ? -*lvalp : *lvalp;
1959 } else {
1960 int val = *valp;
1961 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001962 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 *lvalp = (unsigned long)-val;
1964 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001965 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 *lvalp = (unsigned long)val;
1967 }
1968 }
1969 return 0;
1970}
1971
Amerigo Wang00b7c332010-05-05 00:26:45 +00001972static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1973
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001974static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001975 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001976 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001977 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 int write, void *data),
1979 void *data)
1980{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001981 int *i, vleft, first = 1, err = 0;
1982 unsigned long page = 0;
1983 size_t left;
1984 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
Amerigo Wang00b7c332010-05-05 00:26:45 +00001986 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 *lenp = 0;
1988 return 0;
1989 }
1990
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001991 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 vleft = table->maxlen / sizeof(*i);
1993 left = *lenp;
1994
1995 if (!conv)
1996 conv = do_proc_dointvec_conv;
1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001999 if (*ppos) {
2000 switch (sysctl_writes_strict) {
2001 case SYSCTL_WRITES_STRICT:
2002 goto out;
2003 case SYSCTL_WRITES_WARN:
2004 warn_sysctl_write(table);
2005 break;
2006 default:
2007 break;
2008 }
2009 }
2010
Amerigo Wang00b7c332010-05-05 00:26:45 +00002011 if (left > PAGE_SIZE - 1)
2012 left = PAGE_SIZE - 1;
2013 page = __get_free_page(GFP_TEMPORARY);
2014 kbuf = (char *) page;
2015 if (!kbuf)
2016 return -ENOMEM;
2017 if (copy_from_user(kbuf, buffer, left)) {
2018 err = -EFAULT;
2019 goto free;
2020 }
2021 kbuf[left] = 0;
2022 }
2023
2024 for (; left && vleft--; i++, first=0) {
2025 unsigned long lval;
2026 bool neg;
2027
2028 if (write) {
2029 left -= proc_skip_spaces(&kbuf);
2030
J. R. Okajima563b0462010-05-25 16:10:14 -07002031 if (!left)
2032 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002033 err = proc_get_long(&kbuf, &left, &lval, &neg,
2034 proc_wspace_sep,
2035 sizeof(proc_wspace_sep), NULL);
2036 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002038 if (conv(&neg, &lval, i, 1, data)) {
2039 err = -EINVAL;
2040 break;
2041 }
2042 } else {
2043 if (conv(&neg, &lval, i, 0, data)) {
2044 err = -EINVAL;
2045 break;
2046 }
2047 if (!first)
2048 err = proc_put_char(&buffer, &left, '\t');
2049 if (err)
2050 break;
2051 err = proc_put_long(&buffer, &left, lval, neg);
2052 if (err)
2053 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 }
2055 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002056
2057 if (!write && !first && left && !err)
2058 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002059 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002060 left -= proc_skip_spaces(&kbuf);
2061free:
2062 if (write) {
2063 free_page(page);
2064 if (first)
2065 return err ? : -EINVAL;
2066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002068out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002070 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071}
2072
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002073static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002074 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002075 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002076 int write, void *data),
2077 void *data)
2078{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002079 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002080 buffer, lenp, ppos, conv, data);
2081}
2082
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083/**
2084 * proc_dointvec - read a vector of integers
2085 * @table: the sysctl table
2086 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 * @buffer: the user buffer
2088 * @lenp: the size of the user buffer
2089 * @ppos: file position
2090 *
2091 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2092 * values from/to the user buffer, treated as an ASCII string.
2093 *
2094 * Returns 0 on success.
2095 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002096int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 void __user *buffer, size_t *lenp, loff_t *ppos)
2098{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002099 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 NULL,NULL);
2101}
2102
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002103/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002104 * Taint values can only be increased
2105 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002106 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002107static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002108 void __user *buffer, size_t *lenp, loff_t *ppos)
2109{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002110 struct ctl_table t;
2111 unsigned long tmptaint = get_taint();
2112 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002113
Bastian Blank91fcd412007-04-23 14:41:14 -07002114 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002115 return -EPERM;
2116
Andi Kleen25ddbb12008-10-15 22:01:41 -07002117 t = *table;
2118 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002119 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002120 if (err < 0)
2121 return err;
2122
2123 if (write) {
2124 /*
2125 * Poor man's atomic or. Not worth adding a primitive
2126 * to everyone's atomic.h for this
2127 */
2128 int i;
2129 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2130 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302131 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002132 }
2133 }
2134
2135 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002136}
2137
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002138#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002139static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002140 void __user *buffer, size_t *lenp, loff_t *ppos)
2141{
2142 if (write && !capable(CAP_SYS_ADMIN))
2143 return -EPERM;
2144
2145 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2146}
2147#endif
2148
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149struct do_proc_dointvec_minmax_conv_param {
2150 int *min;
2151 int *max;
2152};
2153
Amerigo Wang00b7c332010-05-05 00:26:45 +00002154static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2155 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 int write, void *data)
2157{
2158 struct do_proc_dointvec_minmax_conv_param *param = data;
2159 if (write) {
2160 int val = *negp ? -*lvalp : *lvalp;
2161 if ((param->min && *param->min > val) ||
2162 (param->max && *param->max < val))
2163 return -EINVAL;
2164 *valp = val;
2165 } else {
2166 int val = *valp;
2167 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002168 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 *lvalp = (unsigned long)-val;
2170 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002171 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 *lvalp = (unsigned long)val;
2173 }
2174 }
2175 return 0;
2176}
2177
2178/**
2179 * proc_dointvec_minmax - read a vector of integers with min/max values
2180 * @table: the sysctl table
2181 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 * @buffer: the user buffer
2183 * @lenp: the size of the user buffer
2184 * @ppos: file position
2185 *
2186 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2187 * values from/to the user buffer, treated as an ASCII string.
2188 *
2189 * This routine will ensure the values are within the range specified by
2190 * table->extra1 (min) and table->extra2 (max).
2191 *
2192 * Returns 0 on success.
2193 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002194int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 void __user *buffer, size_t *lenp, loff_t *ppos)
2196{
2197 struct do_proc_dointvec_minmax_conv_param param = {
2198 .min = (int *) table->extra1,
2199 .max = (int *) table->extra2,
2200 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002201 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 do_proc_dointvec_minmax_conv, &param);
2203}
2204
Kees Cook54b50192012-07-30 14:39:18 -07002205static void validate_coredump_safety(void)
2206{
Alex Kelly046d6622012-10-04 17:15:23 -07002207#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002208 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002209 core_pattern[0] != '/' && core_pattern[0] != '|') {
2210 printk(KERN_WARNING "Unsafe core_pattern used with "\
2211 "suid_dumpable=2. Pipe handler or fully qualified "\
2212 "core dump path required.\n");
2213 }
Alex Kelly046d6622012-10-04 17:15:23 -07002214#endif
Kees Cook54b50192012-07-30 14:39:18 -07002215}
2216
2217static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2218 void __user *buffer, size_t *lenp, loff_t *ppos)
2219{
2220 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2221 if (!error)
2222 validate_coredump_safety();
2223 return error;
2224}
2225
Alex Kelly046d6622012-10-04 17:15:23 -07002226#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002227static int proc_dostring_coredump(struct ctl_table *table, int write,
2228 void __user *buffer, size_t *lenp, loff_t *ppos)
2229{
2230 int error = proc_dostring(table, write, buffer, lenp, ppos);
2231 if (!error)
2232 validate_coredump_safety();
2233 return error;
2234}
Alex Kelly046d6622012-10-04 17:15:23 -07002235#endif
Kees Cook54b50192012-07-30 14:39:18 -07002236
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002237static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 void __user *buffer,
2239 size_t *lenp, loff_t *ppos,
2240 unsigned long convmul,
2241 unsigned long convdiv)
2242{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002243 unsigned long *i, *min, *max;
2244 int vleft, first = 1, err = 0;
2245 unsigned long page = 0;
2246 size_t left;
2247 char *kbuf;
2248
2249 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 *lenp = 0;
2251 return 0;
2252 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002253
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002254 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 min = (unsigned long *) table->extra1;
2256 max = (unsigned long *) table->extra2;
2257 vleft = table->maxlen / sizeof(unsigned long);
2258 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002259
2260 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002261 if (*ppos) {
2262 switch (sysctl_writes_strict) {
2263 case SYSCTL_WRITES_STRICT:
2264 goto out;
2265 case SYSCTL_WRITES_WARN:
2266 warn_sysctl_write(table);
2267 break;
2268 default:
2269 break;
2270 }
2271 }
2272
Amerigo Wang00b7c332010-05-05 00:26:45 +00002273 if (left > PAGE_SIZE - 1)
2274 left = PAGE_SIZE - 1;
2275 page = __get_free_page(GFP_TEMPORARY);
2276 kbuf = (char *) page;
2277 if (!kbuf)
2278 return -ENOMEM;
2279 if (copy_from_user(kbuf, buffer, left)) {
2280 err = -EFAULT;
2281 goto free;
2282 }
2283 kbuf[left] = 0;
2284 }
2285
Eric Dumazet27b3d802010-10-07 12:59:29 -07002286 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002287 unsigned long val;
2288
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002290 bool neg;
2291
2292 left -= proc_skip_spaces(&kbuf);
2293
2294 err = proc_get_long(&kbuf, &left, &val, &neg,
2295 proc_wspace_sep,
2296 sizeof(proc_wspace_sep), NULL);
2297 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 break;
2299 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 continue;
2301 if ((min && val < *min) || (max && val > *max))
2302 continue;
2303 *i = val;
2304 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002305 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002306 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002308 if (err)
2309 break;
2310 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002311 err = proc_put_long(&buffer, &left, val, false);
2312 if (err)
2313 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 }
2315 }
2316
Amerigo Wang00b7c332010-05-05 00:26:45 +00002317 if (!write && !first && left && !err)
2318 err = proc_put_char(&buffer, &left, '\n');
2319 if (write && !err)
2320 left -= proc_skip_spaces(&kbuf);
2321free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002323 free_page(page);
2324 if (first)
2325 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002328out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002330 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002333static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002334 void __user *buffer,
2335 size_t *lenp, loff_t *ppos,
2336 unsigned long convmul,
2337 unsigned long convdiv)
2338{
2339 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002340 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002341}
2342
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343/**
2344 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2345 * @table: the sysctl table
2346 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 * @buffer: the user buffer
2348 * @lenp: the size of the user buffer
2349 * @ppos: file position
2350 *
2351 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2352 * values from/to the user buffer, treated as an ASCII string.
2353 *
2354 * This routine will ensure the values are within the range specified by
2355 * table->extra1 (min) and table->extra2 (max).
2356 *
2357 * Returns 0 on success.
2358 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002359int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 void __user *buffer, size_t *lenp, loff_t *ppos)
2361{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002362 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363}
2364
2365/**
2366 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2367 * @table: the sysctl table
2368 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 * @buffer: the user buffer
2370 * @lenp: the size of the user buffer
2371 * @ppos: file position
2372 *
2373 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2374 * values from/to the user buffer, treated as an ASCII string. The values
2375 * are treated as milliseconds, and converted to jiffies when they are stored.
2376 *
2377 * This routine will ensure the values are within the range specified by
2378 * table->extra1 (min) and table->extra2 (max).
2379 *
2380 * Returns 0 on success.
2381 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002382int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 void __user *buffer,
2384 size_t *lenp, loff_t *ppos)
2385{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002386 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 lenp, ppos, HZ, 1000l);
2388}
2389
2390
Amerigo Wang00b7c332010-05-05 00:26:45 +00002391static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 int *valp,
2393 int write, void *data)
2394{
2395 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002396 if (*lvalp > LONG_MAX / HZ)
2397 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2399 } else {
2400 int val = *valp;
2401 unsigned long lval;
2402 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002403 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 lval = (unsigned long)-val;
2405 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002406 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 lval = (unsigned long)val;
2408 }
2409 *lvalp = lval / HZ;
2410 }
2411 return 0;
2412}
2413
Amerigo Wang00b7c332010-05-05 00:26:45 +00002414static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 int *valp,
2416 int write, void *data)
2417{
2418 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002419 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2420 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2422 } else {
2423 int val = *valp;
2424 unsigned long lval;
2425 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002426 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 lval = (unsigned long)-val;
2428 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002429 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 lval = (unsigned long)val;
2431 }
2432 *lvalp = jiffies_to_clock_t(lval);
2433 }
2434 return 0;
2435}
2436
Amerigo Wang00b7c332010-05-05 00:26:45 +00002437static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 int *valp,
2439 int write, void *data)
2440{
2441 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002442 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2443
2444 if (jif > INT_MAX)
2445 return 1;
2446 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 } else {
2448 int val = *valp;
2449 unsigned long lval;
2450 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002451 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 lval = (unsigned long)-val;
2453 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002454 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 lval = (unsigned long)val;
2456 }
2457 *lvalp = jiffies_to_msecs(lval);
2458 }
2459 return 0;
2460}
2461
2462/**
2463 * proc_dointvec_jiffies - read a vector of integers as seconds
2464 * @table: the sysctl table
2465 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 * @buffer: the user buffer
2467 * @lenp: the size of the user buffer
2468 * @ppos: file position
2469 *
2470 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2471 * values from/to the user buffer, treated as an ASCII string.
2472 * The values read are assumed to be in seconds, and are converted into
2473 * jiffies.
2474 *
2475 * Returns 0 on success.
2476 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002477int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 void __user *buffer, size_t *lenp, loff_t *ppos)
2479{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002480 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 do_proc_dointvec_jiffies_conv,NULL);
2482}
2483
2484/**
2485 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2486 * @table: the sysctl table
2487 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 * @buffer: the user buffer
2489 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002490 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 *
2492 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2493 * values from/to the user buffer, treated as an ASCII string.
2494 * The values read are assumed to be in 1/USER_HZ seconds, and
2495 * are converted into jiffies.
2496 *
2497 * Returns 0 on success.
2498 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002499int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 void __user *buffer, size_t *lenp, loff_t *ppos)
2501{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002502 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 do_proc_dointvec_userhz_jiffies_conv,NULL);
2504}
2505
2506/**
2507 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2508 * @table: the sysctl table
2509 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 * @buffer: the user buffer
2511 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002512 * @ppos: file position
2513 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 *
2515 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2516 * values from/to the user buffer, treated as an ASCII string.
2517 * The values read are assumed to be in 1/1000 seconds, and
2518 * are converted into jiffies.
2519 *
2520 * Returns 0 on success.
2521 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002522int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 void __user *buffer, size_t *lenp, loff_t *ppos)
2524{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002525 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 do_proc_dointvec_ms_jiffies_conv, NULL);
2527}
2528
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002529static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002530 void __user *buffer, size_t *lenp, loff_t *ppos)
2531{
2532 struct pid *new_pid;
2533 pid_t tmp;
2534 int r;
2535
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002536 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002537
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002538 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002539 lenp, ppos, NULL, NULL);
2540 if (r || !write)
2541 return r;
2542
2543 new_pid = find_get_pid(tmp);
2544 if (!new_pid)
2545 return -ESRCH;
2546
2547 put_pid(xchg(&cad_pid, new_pid));
2548 return 0;
2549}
2550
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002551/**
2552 * proc_do_large_bitmap - read/write from/to a large bitmap
2553 * @table: the sysctl table
2554 * @write: %TRUE if this is a write to the sysctl file
2555 * @buffer: the user buffer
2556 * @lenp: the size of the user buffer
2557 * @ppos: file position
2558 *
2559 * The bitmap is stored at table->data and the bitmap length (in bits)
2560 * in table->maxlen.
2561 *
2562 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2563 * large bitmaps may be represented in a compact manner. Writing into
2564 * the file will clear the bitmap then update it with the given input.
2565 *
2566 * Returns 0 on success.
2567 */
2568int proc_do_large_bitmap(struct ctl_table *table, int write,
2569 void __user *buffer, size_t *lenp, loff_t *ppos)
2570{
2571 int err = 0;
2572 bool first = 1;
2573 size_t left = *lenp;
2574 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002575 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002576 unsigned long *tmp_bitmap = NULL;
2577 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2578
WANG Cong122ff242014-05-12 16:04:53 -07002579 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002580 *lenp = 0;
2581 return 0;
2582 }
2583
2584 if (write) {
2585 unsigned long page = 0;
2586 char *kbuf;
2587
2588 if (left > PAGE_SIZE - 1)
2589 left = PAGE_SIZE - 1;
2590
2591 page = __get_free_page(GFP_TEMPORARY);
2592 kbuf = (char *) page;
2593 if (!kbuf)
2594 return -ENOMEM;
2595 if (copy_from_user(kbuf, buffer, left)) {
2596 free_page(page);
2597 return -EFAULT;
2598 }
2599 kbuf[left] = 0;
2600
2601 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2602 GFP_KERNEL);
2603 if (!tmp_bitmap) {
2604 free_page(page);
2605 return -ENOMEM;
2606 }
2607 proc_skip_char(&kbuf, &left, '\n');
2608 while (!err && left) {
2609 unsigned long val_a, val_b;
2610 bool neg;
2611
2612 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2613 sizeof(tr_a), &c);
2614 if (err)
2615 break;
2616 if (val_a >= bitmap_len || neg) {
2617 err = -EINVAL;
2618 break;
2619 }
2620
2621 val_b = val_a;
2622 if (left) {
2623 kbuf++;
2624 left--;
2625 }
2626
2627 if (c == '-') {
2628 err = proc_get_long(&kbuf, &left, &val_b,
2629 &neg, tr_b, sizeof(tr_b),
2630 &c);
2631 if (err)
2632 break;
2633 if (val_b >= bitmap_len || neg ||
2634 val_a > val_b) {
2635 err = -EINVAL;
2636 break;
2637 }
2638 if (left) {
2639 kbuf++;
2640 left--;
2641 }
2642 }
2643
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002644 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002645 first = 0;
2646 proc_skip_char(&kbuf, &left, '\n');
2647 }
2648 free_page(page);
2649 } else {
2650 unsigned long bit_a, bit_b = 0;
2651
2652 while (left) {
2653 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2654 if (bit_a >= bitmap_len)
2655 break;
2656 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2657 bit_a + 1) - 1;
2658
2659 if (!first) {
2660 err = proc_put_char(&buffer, &left, ',');
2661 if (err)
2662 break;
2663 }
2664 err = proc_put_long(&buffer, &left, bit_a, false);
2665 if (err)
2666 break;
2667 if (bit_a != bit_b) {
2668 err = proc_put_char(&buffer, &left, '-');
2669 if (err)
2670 break;
2671 err = proc_put_long(&buffer, &left, bit_b, false);
2672 if (err)
2673 break;
2674 }
2675
2676 first = 0; bit_b++;
2677 }
2678 if (!err)
2679 err = proc_put_char(&buffer, &left, '\n');
2680 }
2681
2682 if (!err) {
2683 if (write) {
2684 if (*ppos)
2685 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2686 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002687 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002688 }
2689 kfree(tmp_bitmap);
2690 *lenp -= left;
2691 *ppos += *lenp;
2692 return 0;
2693 } else {
2694 kfree(tmp_bitmap);
2695 return err;
2696 }
2697}
2698
Jovi Zhang55610502011-01-12 17:00:45 -08002699#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002701int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 void __user *buffer, size_t *lenp, loff_t *ppos)
2703{
2704 return -ENOSYS;
2705}
2706
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002707int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 void __user *buffer, size_t *lenp, loff_t *ppos)
2709{
2710 return -ENOSYS;
2711}
2712
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002713int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 void __user *buffer, size_t *lenp, loff_t *ppos)
2715{
2716 return -ENOSYS;
2717}
2718
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002719int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 void __user *buffer, size_t *lenp, loff_t *ppos)
2721{
2722 return -ENOSYS;
2723}
2724
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002725int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 void __user *buffer, size_t *lenp, loff_t *ppos)
2727{
2728 return -ENOSYS;
2729}
2730
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002731int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 void __user *buffer, size_t *lenp, loff_t *ppos)
2733{
2734 return -ENOSYS;
2735}
2736
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002737int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 void __user *buffer, size_t *lenp, loff_t *ppos)
2739{
2740 return -ENOSYS;
2741}
2742
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002743int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 void __user *buffer,
2745 size_t *lenp, loff_t *ppos)
2746{
2747 return -ENOSYS;
2748}
2749
2750
Jovi Zhang55610502011-01-12 17:00:45 -08002751#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753/*
2754 * No sense putting this after each symbol definition, twice,
2755 * exception granted :-)
2756 */
2757EXPORT_SYMBOL(proc_dointvec);
2758EXPORT_SYMBOL(proc_dointvec_jiffies);
2759EXPORT_SYMBOL(proc_dointvec_minmax);
2760EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2761EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2762EXPORT_SYMBOL(proc_dostring);
2763EXPORT_SYMBOL(proc_doulongvec_minmax);
2764EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);