blob: 5faf89ac9ec0894a45eb2e35d9642d0affc5d16a [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>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020033#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#include <asm/uaccess.h>
70#include <asm/processor.h>
71
Andi Kleen29cbc782006-09-30 01:47:55 +020072#ifdef CONFIG_X86
73#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010074#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010075#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020076#endif
David Howellsd550bbd2012-03-28 18:30:03 +010077#ifdef CONFIG_SPARC
78#include <asm/setup.h>
79#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080080#ifdef CONFIG_BSD_PROCESS_ACCT
81#include <linux/acct.h>
82#endif
Dave Young4f0e0562010-03-10 15:24:09 -080083#ifdef CONFIG_RT_MUTEXES
84#include <linux/rtmutex.h>
85#endif
Dave Young2edf5e42010-03-10 15:24:10 -080086#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
87#include <linux/lockdep.h>
88#endif
Dave Young15485a42010-03-10 15:24:07 -080089#ifdef CONFIG_CHR_DEV_SG
90#include <scsi/sg.h>
91#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020092
Don Zickus58687ac2010-05-07 17:11:44 -040093#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050094#include <linux/nmi.h>
95#endif
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#if defined(CONFIG_SYSCTL)
98
99/* External variables not in a header file. */
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 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200353#endif /* CONFIG_SMP */
354#ifdef CONFIG_NUMA_BALANCING
355 {
Peter Zijlstra4b96a29b2012-10-25 14:16:47 +0200356 .procname = "numa_balancing_scan_delay_ms",
357 .data = &sysctl_numa_balancing_scan_delay,
358 .maxlen = sizeof(unsigned int),
359 .mode = 0644,
360 .proc_handler = proc_dointvec,
361 },
362 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200363 .procname = "numa_balancing_scan_period_min_ms",
364 .data = &sysctl_numa_balancing_scan_period_min,
365 .maxlen = sizeof(unsigned int),
366 .mode = 0644,
367 .proc_handler = proc_dointvec,
368 },
369 {
370 .procname = "numa_balancing_scan_period_max_ms",
371 .data = &sysctl_numa_balancing_scan_period_max,
372 .maxlen = sizeof(unsigned int),
373 .mode = 0644,
374 .proc_handler = proc_dointvec,
375 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200376 {
377 .procname = "numa_balancing_scan_size_mb",
378 .data = &sysctl_numa_balancing_scan_size,
379 .maxlen = sizeof(unsigned int),
380 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400381 .proc_handler = proc_dointvec_minmax,
382 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200383 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100384 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800385 .procname = "numa_balancing",
386 .data = NULL, /* filled in by handler */
387 .maxlen = sizeof(unsigned int),
388 .mode = 0644,
389 .proc_handler = sysctl_numa_balancing,
390 .extra1 = &zero,
391 .extra2 = &one,
392 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200393#endif /* CONFIG_NUMA_BALANCING */
394#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200395 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100396 .procname = "sched_rt_period_us",
397 .data = &sysctl_sched_rt_period,
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800400 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100401 },
402 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100403 .procname = "sched_rt_runtime_us",
404 .data = &sysctl_sched_rt_runtime,
405 .maxlen = sizeof(int),
406 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800407 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100408 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600409 {
410 .procname = "sched_rr_timeslice_ms",
411 .data = &sched_rr_timeslice,
412 .maxlen = sizeof(int),
413 .mode = 0644,
414 .proc_handler = sched_rr_handler,
415 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100416#ifdef CONFIG_SCHED_AUTOGROUP
417 {
418 .procname = "sched_autogroup_enabled",
419 .data = &sysctl_sched_autogroup_enabled,
420 .maxlen = sizeof(unsigned int),
421 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800422 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100423 .extra1 = &zero,
424 .extra2 = &one,
425 },
426#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700427#ifdef CONFIG_CFS_BANDWIDTH
428 {
429 .procname = "sched_cfs_bandwidth_slice_us",
430 .data = &sysctl_sched_cfs_bandwidth_slice,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
433 .proc_handler = proc_dointvec_minmax,
434 .extra1 = &one,
435 },
436#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700437#ifdef CONFIG_PROVE_LOCKING
438 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700439 .procname = "prove_locking",
440 .data = &prove_locking,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800443 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700444 },
445#endif
446#ifdef CONFIG_LOCK_STAT
447 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700448 .procname = "lock_stat",
449 .data = &lock_stat,
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
Ingo Molnar77e54a12007-07-09 18:52:00 +0200455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 .procname = "panic",
457 .data = &panic_timeout,
458 .maxlen = sizeof(int),
459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800460 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 },
Alex Kelly046d6622012-10-04 17:15:23 -0700462#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 .procname = "core_uses_pid",
465 .data = &core_uses_pid,
466 .maxlen = sizeof(int),
467 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800468 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 },
470 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 .procname = "core_pattern",
472 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700473 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700475 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 },
Neil Hormana2939802009-09-23 15:56:56 -0700477 {
Neil Hormana2939802009-09-23 15:56:56 -0700478 .procname = "core_pipe_limit",
479 .data = &core_pipe_limit,
480 .maxlen = sizeof(unsigned int),
481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800482 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700483 },
Alex Kelly046d6622012-10-04 17:15:23 -0700484#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800485#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700488 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800490 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700492 {
493 .procname = "sysctl_writes_strict",
494 .data = &sysctl_writes_strict,
495 .maxlen = sizeof(int),
496 .mode = 0644,
497 .proc_handler = proc_dointvec_minmax,
498 .extra1 = &neg_one,
499 .extra2 = &one,
500 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800501#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100502#ifdef CONFIG_LATENCYTOP
503 {
504 .procname = "latencytop",
505 .data = &latencytop_enabled,
506 .maxlen = sizeof(int),
507 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800508 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100509 },
510#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#ifdef CONFIG_BLK_DEV_INITRD
512 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 .procname = "real-root-dev",
514 .data = &real_root_dev,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800517 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 },
519#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700520 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700521 .procname = "print-fatal-signals",
522 .data = &print_fatal_signals,
523 .maxlen = sizeof(int),
524 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800525 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700526 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700527#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 .procname = "reboot-cmd",
530 .data = reboot_command,
531 .maxlen = 256,
532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800533 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 },
535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 .procname = "stop-a",
537 .data = &stop_a_enabled,
538 .maxlen = sizeof (int),
539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800540 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 },
542 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 .procname = "scons-poweroff",
544 .data = &scons_pwroff,
545 .maxlen = sizeof (int),
546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800547 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 },
549#endif
David S. Miller08714202008-11-16 23:49:24 -0800550#ifdef CONFIG_SPARC64
551 {
David S. Miller08714202008-11-16 23:49:24 -0800552 .procname = "tsb-ratio",
553 .data = &sysctl_tsb_ratio,
554 .maxlen = sizeof (int),
555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800557 },
558#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#ifdef __hppa__
560 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 .procname = "soft-power",
562 .data = &pwrsw_enabled,
563 .maxlen = sizeof (int),
564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800565 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530567#endif
568#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .procname = "unaligned-trap",
571 .data = &unaligned_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 },
576#endif
577 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 .procname = "ctrl-alt-del",
579 .data = &C_A_D,
580 .maxlen = sizeof(int),
581 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800582 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400584#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200585 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200586 .procname = "ftrace_enabled",
587 .data = &ftrace_enabled,
588 .maxlen = sizeof(int),
589 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800590 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200591 },
592#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500593#ifdef CONFIG_STACK_TRACER
594 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500595 .procname = "stack_tracer_enabled",
596 .data = &stack_tracer_enabled,
597 .maxlen = sizeof(int),
598 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800599 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500600 },
601#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400602#ifdef CONFIG_TRACING
603 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100604 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400605 .data = &ftrace_dump_on_oops,
606 .maxlen = sizeof(int),
607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400609 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400610 {
611 .procname = "traceoff_on_warning",
612 .data = &__disable_trace_on_warning,
613 .maxlen = sizeof(__disable_trace_on_warning),
614 .mode = 0644,
615 .proc_handler = proc_dointvec,
616 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500617 {
618 .procname = "tracepoint_printk",
619 .data = &tracepoint_printk,
620 .maxlen = sizeof(tracepoint_printk),
621 .mode = 0644,
622 .proc_handler = proc_dointvec,
623 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400624#endif
Dave Young2965faa2015-09-09 15:38:55 -0700625#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800626 {
627 .procname = "kexec_load_disabled",
628 .data = &kexec_load_disabled,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 /* only handle a transition from default "0" to "1" */
632 .proc_handler = proc_dointvec_minmax,
633 .extra1 = &one,
634 .extra2 = &one,
635 },
636#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200637#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 .procname = "modprobe",
640 .data = &modprobe_path,
641 .maxlen = KMOD_PATH_LEN,
642 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800643 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 },
Kees Cook3d433212009-04-02 15:49:29 -0700645 {
Kees Cook3d433212009-04-02 15:49:29 -0700646 .procname = "modules_disabled",
647 .data = &modules_disabled,
648 .maxlen = sizeof(int),
649 .mode = 0644,
650 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800651 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700652 .extra1 = &one,
653 .extra2 = &one,
654 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700656#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100659 .data = &uevent_helper,
660 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800662 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 },
Michael Marineau86d56132014-04-10 14:09:31 -0700664#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#ifdef CONFIG_CHR_DEV_SG
666 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 .procname = "sg-big-buff",
668 .data = &sg_big_buff,
669 .maxlen = sizeof (int),
670 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800671 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 },
673#endif
674#ifdef CONFIG_BSD_PROCESS_ACCT
675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .procname = "acct",
677 .data = &acct_parm,
678 .maxlen = 3*sizeof(int),
679 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800680 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 },
682#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683#ifdef CONFIG_MAGIC_SYSRQ
684 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800686 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .maxlen = sizeof (int),
688 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700689 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 },
691#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700692#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700695 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .maxlen = sizeof (int),
697 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800698 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700700#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700703 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 .maxlen = sizeof(int),
705 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700706 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
708 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 .procname = "random",
710 .mode = 0555,
711 .child = random_table,
712 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 {
Eric Paris17f60a72011-04-01 17:07:50 -0400714 .procname = "usermodehelper",
715 .mode = 0555,
716 .child = usermodehelper_table,
717 },
718 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 .procname = "overflowuid",
720 .data = &overflowuid,
721 .maxlen = sizeof(int),
722 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800723 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 .extra1 = &minolduid,
725 .extra2 = &maxolduid,
726 },
727 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .procname = "overflowgid",
729 .data = &overflowgid,
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 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800736#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737#ifdef CONFIG_MATHEMU
738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .procname = "ieee_emulation_warnings",
740 .data = &sysctl_ieee_emulation_warnings,
741 .maxlen = sizeof(int),
742 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800743 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 },
745#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200748 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .maxlen = sizeof(int),
750 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800751 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 },
753#endif
754 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .procname = "pid_max",
756 .data = &pid_max,
757 .maxlen = sizeof (int),
758 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800759 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 .extra1 = &pid_max_min,
761 .extra2 = &pid_max_max,
762 },
763 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .procname = "panic_on_oops",
765 .data = &panic_on_oops,
766 .maxlen = sizeof(int),
767 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800768 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800770#if defined CONFIG_PRINTK
771 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800772 .procname = "printk",
773 .data = &console_loglevel,
774 .maxlen = 4*sizeof(int),
775 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800776 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800777 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700780 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 .maxlen = sizeof(int),
782 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800783 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 },
785 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700787 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 .maxlen = sizeof(int),
789 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800790 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 },
Dave Youngaf913222009-09-22 16:43:33 -0700792 {
Dave Youngaf913222009-09-22 16:43:33 -0700793 .procname = "printk_delay",
794 .data = &printk_delay_msec,
795 .maxlen = sizeof(int),
796 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800797 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700798 .extra1 = &zero,
799 .extra2 = &ten_thousand,
800 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800802 .procname = "dmesg_restrict",
803 .data = &dmesg_restrict,
804 .maxlen = sizeof(int),
805 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700806 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800807 .extra1 = &zero,
808 .extra2 = &one,
809 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800810 {
811 .procname = "kptr_restrict",
812 .data = &kptr_restrict,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700815 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800816 .extra1 = &zero,
817 .extra2 = &two,
818 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800819#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800820 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 .procname = "ngroups_max",
822 .data = &ngroups_max,
823 .maxlen = sizeof (int),
824 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800825 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 },
Dan Ballard73efc032011-10-31 17:11:20 -0700827 {
828 .procname = "cap_last_cap",
829 .data = (void *)&cap_last_cap,
830 .maxlen = sizeof(int),
831 .mode = 0444,
832 .proc_handler = proc_dointvec,
833 },
Don Zickus58687ac2010-05-07 17:11:44 -0400834#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500835 {
Don Zickus58687ac2010-05-07 17:11:44 -0400836 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200837 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500838 .maxlen = sizeof (int),
839 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700840 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700841 .extra1 = &zero,
842 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400843 },
844 {
845 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700846 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400847 .maxlen = sizeof(int),
848 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700849 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800850 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400851 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500852 },
Don Zickus2508ce12010-05-07 17:11:46 -0400853 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700854 .procname = "nmi_watchdog",
855 .data = &nmi_watchdog_enabled,
856 .maxlen = sizeof (int),
857 .mode = 0644,
858 .proc_handler = proc_nmi_watchdog,
859 .extra1 = &zero,
860#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
861 .extra2 = &one,
862#else
863 .extra2 = &zero,
864#endif
865 },
866 {
867 .procname = "soft_watchdog",
868 .data = &soft_watchdog_enabled,
869 .maxlen = sizeof (int),
870 .mode = 0644,
871 .proc_handler = proc_soft_watchdog,
872 .extra1 = &zero,
873 .extra2 = &one,
874 },
875 {
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700876 .procname = "watchdog_cpumask",
877 .data = &watchdog_cpumask_bits,
878 .maxlen = NR_CPUS,
879 .mode = 0644,
880 .proc_handler = proc_watchdog_cpumask,
881 },
882 {
Don Zickus2508ce12010-05-07 17:11:46 -0400883 .procname = "softlockup_panic",
884 .data = &softlockup_panic,
885 .maxlen = sizeof(int),
886 .mode = 0644,
887 .proc_handler = proc_dointvec_minmax,
888 .extra1 = &zero,
889 .extra2 = &one,
890 },
Don Zickusac1f5912015-11-05 18:44:44 -0800891#ifdef CONFIG_HARDLOCKUP_DETECTOR
892 {
893 .procname = "hardlockup_panic",
894 .data = &hardlockup_panic,
895 .maxlen = sizeof(int),
896 .mode = 0644,
897 .proc_handler = proc_dointvec_minmax,
898 .extra1 = &zero,
899 .extra2 = &one,
900 },
901#endif
Aaron Tomlined235872014-06-23 13:22:05 -0700902#ifdef CONFIG_SMP
903 {
904 .procname = "softlockup_all_cpu_backtrace",
905 .data = &sysctl_softlockup_all_cpu_backtrace,
906 .maxlen = sizeof(int),
907 .mode = 0644,
908 .proc_handler = proc_dointvec_minmax,
909 .extra1 = &zero,
910 .extra2 = &one,
911 },
Jiri Kosina55537872015-11-05 18:44:41 -0800912 {
913 .procname = "hardlockup_all_cpu_backtrace",
914 .data = &sysctl_hardlockup_all_cpu_backtrace,
915 .maxlen = sizeof(int),
916 .mode = 0644,
917 .proc_handler = proc_dointvec_minmax,
918 .extra1 = &zero,
919 .extra2 = &one,
920 },
Aaron Tomlined235872014-06-23 13:22:05 -0700921#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500922#endif
923#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
924 {
925 .procname = "unknown_nmi_panic",
926 .data = &unknown_nmi_panic,
927 .maxlen = sizeof (int),
928 .mode = 0644,
929 .proc_handler = proc_dointvec,
930 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500931#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932#if defined(CONFIG_X86)
933 {
Don Zickus8da5add2006-09-26 10:52:27 +0200934 .procname = "panic_on_unrecovered_nmi",
935 .data = &panic_on_unrecovered_nmi,
936 .maxlen = sizeof(int),
937 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800938 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200939 },
940 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700941 .procname = "panic_on_io_nmi",
942 .data = &panic_on_io_nmi,
943 .maxlen = sizeof(int),
944 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800945 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700946 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900947#ifdef CONFIG_DEBUG_STACKOVERFLOW
948 {
949 .procname = "panic_on_stackoverflow",
950 .data = &sysctl_panic_on_stackoverflow,
951 .maxlen = sizeof(int),
952 .mode = 0644,
953 .proc_handler = proc_dointvec,
954 },
955#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700956 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 .procname = "bootloader_type",
958 .data = &bootloader_type,
959 .maxlen = sizeof (int),
960 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800961 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100963 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700964 .procname = "bootloader_version",
965 .data = &bootloader_version,
966 .maxlen = sizeof (int),
967 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800968 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700969 },
970 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100971 .procname = "kstack_depth_to_print",
972 .data = &kstack_depth_to_print,
973 .maxlen = sizeof(int),
974 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800975 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100976 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100977 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100978 .procname = "io_delay_type",
979 .data = &io_delay_type,
980 .maxlen = sizeof(int),
981 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800982 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100983 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800985#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 .procname = "randomize_va_space",
988 .data = &randomize_va_space,
989 .maxlen = sizeof(int),
990 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800991 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800993#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800994#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700995 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700996 .procname = "spin_retry",
997 .data = &spin_retry,
998 .maxlen = sizeof (int),
999 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001000 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001001 },
1002#endif
Len Brown673d5b42007-07-28 03:33:16 -04001003#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001004 {
Pavel Machekc255d842006-02-20 18:27:58 -08001005 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001006 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001007 .maxlen = sizeof (unsigned long),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001010 },
1011#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301012#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001013 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001014 .procname = "ignore-unaligned-usertrap",
1015 .data = &no_unaligned_warning,
1016 .maxlen = sizeof (int),
1017 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001018 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001019 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301020#endif
1021#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001022 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001023 .procname = "unaligned-dump-stack",
1024 .data = &unaligned_dump_stack,
1025 .maxlen = sizeof (int),
1026 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001027 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001028 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001029#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001030#ifdef CONFIG_DETECT_HUNG_TASK
1031 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001032 .procname = "hung_task_panic",
1033 .data = &sysctl_hung_task_panic,
1034 .maxlen = sizeof(int),
1035 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001036 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001037 .extra1 = &zero,
1038 .extra2 = &one,
1039 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001040 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001041 .procname = "hung_task_check_count",
1042 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001043 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001044 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001045 .proc_handler = proc_dointvec_minmax,
1046 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001047 },
1048 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001049 .procname = "hung_task_timeout_secs",
1050 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001051 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001052 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001054 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001055 },
1056 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001057 .procname = "hung_task_warnings",
1058 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001059 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001060 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001061 .proc_handler = proc_dointvec_minmax,
1062 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001063 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001064#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001065#ifdef CONFIG_COMPAT
1066 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001067 .procname = "compat-log",
1068 .data = &compat_log,
1069 .maxlen = sizeof (int),
1070 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001072 },
1073#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001074#ifdef CONFIG_RT_MUTEXES
1075 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001076 .procname = "max_lock_depth",
1077 .data = &max_lock_depth,
1078 .maxlen = sizeof(int),
1079 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001080 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001081 },
1082#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001083 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001084 .procname = "poweroff_cmd",
1085 .data = &poweroff_cmd,
1086 .maxlen = POWEROFF_CMD_PATH_LEN,
1087 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001088 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001089 },
David Howells0b77f5b2008-04-29 01:01:32 -07001090#ifdef CONFIG_KEYS
1091 {
David Howells0b77f5b2008-04-29 01:01:32 -07001092 .procname = "keys",
1093 .mode = 0555,
1094 .child = key_sysctls,
1095 },
1096#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001097#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001098 /*
1099 * User-space scripts rely on the existence of this file
1100 * as a feature check for perf_events being enabled.
1101 *
1102 * So it's an ABI, do not remove!
1103 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001104 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001105 .procname = "perf_event_paranoid",
1106 .data = &sysctl_perf_event_paranoid,
1107 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001108 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001109 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001110 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001111 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001112 .procname = "perf_event_mlock_kb",
1113 .data = &sysctl_perf_event_mlock,
1114 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001115 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001116 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001117 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001118 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001119 .procname = "perf_event_max_sample_rate",
1120 .data = &sysctl_perf_event_sample_rate,
1121 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001122 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001123 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001124 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001125 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001126 {
1127 .procname = "perf_cpu_time_max_percent",
1128 .data = &sysctl_perf_cpu_time_max_percent,
1129 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1130 .mode = 0644,
1131 .proc_handler = perf_cpu_time_max_percent_handler,
1132 .extra1 = &zero,
1133 .extra2 = &one_hundred,
1134 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001135#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001136#ifdef CONFIG_KMEMCHECK
1137 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001138 .procname = "kmemcheck",
1139 .data = &kmemcheck_enabled,
1140 .maxlen = sizeof(int),
1141 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001142 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001143 },
1144#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001145 {
1146 .procname = "panic_on_warn",
1147 .data = &panic_on_warn,
1148 .maxlen = sizeof(int),
1149 .mode = 0644,
1150 .proc_handler = proc_dointvec_minmax,
1151 .extra1 = &zero,
1152 .extra2 = &one,
1153 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001154#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1155 {
1156 .procname = "timer_migration",
1157 .data = &sysctl_timer_migration,
1158 .maxlen = sizeof(unsigned int),
1159 .mode = 0644,
1160 .proc_handler = timer_migration_handler,
1161 },
1162#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001163#ifdef CONFIG_BPF_SYSCALL
1164 {
1165 .procname = "unprivileged_bpf_disabled",
1166 .data = &sysctl_unprivileged_bpf_disabled,
1167 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1168 .mode = 0644,
1169 /* only handle a transition from default "0" to "1" */
1170 .proc_handler = proc_dointvec_minmax,
1171 .extra1 = &one,
1172 .extra2 = &one,
1173 },
1174#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001175 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176};
1177
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001178static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 .procname = "overcommit_memory",
1181 .data = &sysctl_overcommit_memory,
1182 .maxlen = sizeof(sysctl_overcommit_memory),
1183 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001184 .proc_handler = proc_dointvec_minmax,
1185 .extra1 = &zero,
1186 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 },
1188 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001189 .procname = "panic_on_oom",
1190 .data = &sysctl_panic_on_oom,
1191 .maxlen = sizeof(sysctl_panic_on_oom),
1192 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001193 .proc_handler = proc_dointvec_minmax,
1194 .extra1 = &zero,
1195 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001196 },
1197 {
David Rientjesfe071d72007-10-16 23:25:56 -07001198 .procname = "oom_kill_allocating_task",
1199 .data = &sysctl_oom_kill_allocating_task,
1200 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1201 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001202 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001203 },
1204 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001205 .procname = "oom_dump_tasks",
1206 .data = &sysctl_oom_dump_tasks,
1207 .maxlen = sizeof(sysctl_oom_dump_tasks),
1208 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001209 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001210 },
1211 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 .procname = "overcommit_ratio",
1213 .data = &sysctl_overcommit_ratio,
1214 .maxlen = sizeof(sysctl_overcommit_ratio),
1215 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001216 .proc_handler = overcommit_ratio_handler,
1217 },
1218 {
1219 .procname = "overcommit_kbytes",
1220 .data = &sysctl_overcommit_kbytes,
1221 .maxlen = sizeof(sysctl_overcommit_kbytes),
1222 .mode = 0644,
1223 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 },
1225 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 .procname = "page-cluster",
1227 .data = &page_cluster,
1228 .maxlen = sizeof(int),
1229 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001230 .proc_handler = proc_dointvec_minmax,
1231 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 },
1233 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 .procname = "dirty_background_ratio",
1235 .data = &dirty_background_ratio,
1236 .maxlen = sizeof(dirty_background_ratio),
1237 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001238 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 .extra1 = &zero,
1240 .extra2 = &one_hundred,
1241 },
1242 {
David Rientjes2da02992009-01-06 14:39:31 -08001243 .procname = "dirty_background_bytes",
1244 .data = &dirty_background_bytes,
1245 .maxlen = sizeof(dirty_background_bytes),
1246 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001247 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001248 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001249 },
1250 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 .procname = "dirty_ratio",
1252 .data = &vm_dirty_ratio,
1253 .maxlen = sizeof(vm_dirty_ratio),
1254 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001255 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 .extra1 = &zero,
1257 .extra2 = &one_hundred,
1258 },
1259 {
David Rientjes2da02992009-01-06 14:39:31 -08001260 .procname = "dirty_bytes",
1261 .data = &vm_dirty_bytes,
1262 .maxlen = sizeof(vm_dirty_bytes),
1263 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001264 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001265 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001266 },
1267 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001269 .data = &dirty_writeback_interval,
1270 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001272 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 },
1274 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001276 .data = &dirty_expire_interval,
1277 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001279 .proc_handler = proc_dointvec_minmax,
1280 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 },
1282 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001283 .procname = "dirtytime_expire_seconds",
1284 .data = &dirtytime_expire_interval,
1285 .maxlen = sizeof(dirty_expire_interval),
1286 .mode = 0644,
1287 .proc_handler = dirtytime_interval_handler,
1288 .extra1 = &zero,
1289 },
1290 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001291 .procname = "nr_pdflush_threads",
1292 .mode = 0444 /* read-only */,
1293 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 },
1295 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 .procname = "swappiness",
1297 .data = &vm_swappiness,
1298 .maxlen = sizeof(vm_swappiness),
1299 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001300 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 .extra1 = &zero,
1302 .extra2 = &one_hundred,
1303 },
1304#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001305 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001307 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 .maxlen = sizeof(unsigned long),
1309 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001310 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001311 },
1312#ifdef CONFIG_NUMA
1313 {
1314 .procname = "nr_hugepages_mempolicy",
1315 .data = NULL,
1316 .maxlen = sizeof(unsigned long),
1317 .mode = 0644,
1318 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001319 },
1320#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 .procname = "hugetlb_shm_group",
1323 .data = &sysctl_hugetlb_shm_group,
1324 .maxlen = sizeof(gid_t),
1325 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001326 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 },
Mel Gorman396faf02007-07-17 04:03:13 -07001328 {
Mel Gorman396faf02007-07-17 04:03:13 -07001329 .procname = "hugepages_treat_as_movable",
1330 .data = &hugepages_treat_as_movable,
1331 .maxlen = sizeof(int),
1332 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001333 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001334 },
Adam Litke54f9f802007-10-16 01:26:20 -07001335 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001336 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001337 .data = NULL,
1338 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001339 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001340 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001341 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342#endif
1343 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 .procname = "lowmem_reserve_ratio",
1345 .data = &sysctl_lowmem_reserve_ratio,
1346 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1347 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001348 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 },
1350 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001351 .procname = "drop_caches",
1352 .data = &sysctl_drop_caches,
1353 .maxlen = sizeof(int),
1354 .mode = 0644,
1355 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001356 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001357 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001358 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001359#ifdef CONFIG_COMPACTION
1360 {
1361 .procname = "compact_memory",
1362 .data = &sysctl_compact_memory,
1363 .maxlen = sizeof(int),
1364 .mode = 0200,
1365 .proc_handler = sysctl_compaction_handler,
1366 },
Mel Gorman5e771902010-05-24 14:32:31 -07001367 {
1368 .procname = "extfrag_threshold",
1369 .data = &sysctl_extfrag_threshold,
1370 .maxlen = sizeof(int),
1371 .mode = 0644,
1372 .proc_handler = sysctl_extfrag_handler,
1373 .extra1 = &min_extfrag_threshold,
1374 .extra2 = &max_extfrag_threshold,
1375 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001376 {
1377 .procname = "compact_unevictable_allowed",
1378 .data = &sysctl_compact_unevictable_allowed,
1379 .maxlen = sizeof(int),
1380 .mode = 0644,
1381 .proc_handler = proc_dointvec,
1382 .extra1 = &zero,
1383 .extra2 = &one,
1384 },
Mel Gorman5e771902010-05-24 14:32:31 -07001385
Mel Gorman76ab0f52010-05-24 14:32:28 -07001386#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001387 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .procname = "min_free_kbytes",
1389 .data = &min_free_kbytes,
1390 .maxlen = sizeof(min_free_kbytes),
1391 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001392 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 .extra1 = &zero,
1394 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001395 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001396 .procname = "percpu_pagelist_fraction",
1397 .data = &percpu_pagelist_fraction,
1398 .maxlen = sizeof(percpu_pagelist_fraction),
1399 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001400 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001401 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001402 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403#ifdef CONFIG_MMU
1404 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 .procname = "max_map_count",
1406 .data = &sysctl_max_map_count,
1407 .maxlen = sizeof(sysctl_max_map_count),
1408 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001409 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001410 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001412#else
1413 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001414 .procname = "nr_trim_pages",
1415 .data = &sysctl_nr_trim_pages,
1416 .maxlen = sizeof(sysctl_nr_trim_pages),
1417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001418 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001419 .extra1 = &zero,
1420 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421#endif
1422 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .procname = "laptop_mode",
1424 .data = &laptop_mode,
1425 .maxlen = sizeof(laptop_mode),
1426 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001427 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 },
1429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .procname = "block_dump",
1431 .data = &block_dump,
1432 .maxlen = sizeof(block_dump),
1433 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001434 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 .extra1 = &zero,
1436 },
1437 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 .procname = "vfs_cache_pressure",
1439 .data = &sysctl_vfs_cache_pressure,
1440 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1441 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001442 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 .extra1 = &zero,
1444 },
1445#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 .procname = "legacy_va_layout",
1448 .data = &sysctl_legacy_va_layout,
1449 .maxlen = sizeof(sysctl_legacy_va_layout),
1450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001451 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 .extra1 = &zero,
1453 },
1454#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001455#ifdef CONFIG_NUMA
1456 {
Christoph Lameter17436602006-01-18 17:42:32 -08001457 .procname = "zone_reclaim_mode",
1458 .data = &zone_reclaim_mode,
1459 .maxlen = sizeof(zone_reclaim_mode),
1460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001461 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001462 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001463 },
Christoph Lameter96146342006-07-03 00:24:13 -07001464 {
Christoph Lameter96146342006-07-03 00:24:13 -07001465 .procname = "min_unmapped_ratio",
1466 .data = &sysctl_min_unmapped_ratio,
1467 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001469 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001470 .extra1 = &zero,
1471 .extra2 = &one_hundred,
1472 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001473 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001474 .procname = "min_slab_ratio",
1475 .data = &sysctl_min_slab_ratio,
1476 .maxlen = sizeof(sysctl_min_slab_ratio),
1477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001478 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001479 .extra1 = &zero,
1480 .extra2 = &one_hundred,
1481 },
Christoph Lameter17436602006-01-18 17:42:32 -08001482#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001483#ifdef CONFIG_SMP
1484 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001485 .procname = "stat_interval",
1486 .data = &sysctl_stat_interval,
1487 .maxlen = sizeof(sysctl_stat_interval),
1488 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001489 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001490 },
1491#endif
David Howells6e141542009-12-15 19:27:45 +00001492#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001493 {
Eric Parised032182007-06-28 15:55:21 -04001494 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001495 .data = &dac_mmap_min_addr,
1496 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001498 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001499 },
David Howells6e141542009-12-15 19:27:45 +00001500#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001501#ifdef CONFIG_NUMA
1502 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001503 .procname = "numa_zonelist_order",
1504 .data = &numa_zonelist_order,
1505 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1506 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001507 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001508 },
1509#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001510#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001511 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001512 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001513 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001514#ifdef CONFIG_X86_32
1515 .data = &vdso32_enabled,
1516 .maxlen = sizeof(vdso32_enabled),
1517#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001518 .data = &vdso_enabled,
1519 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001520#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001521 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001522 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001523 .extra1 = &zero,
1524 },
1525#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001526#ifdef CONFIG_HIGHMEM
1527 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001528 .procname = "highmem_is_dirtyable",
1529 .data = &vm_highmem_is_dirtyable,
1530 .maxlen = sizeof(vm_highmem_is_dirtyable),
1531 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001532 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001533 .extra1 = &zero,
1534 .extra2 = &one,
1535 },
1536#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001537#ifdef CONFIG_MEMORY_FAILURE
1538 {
Andi Kleen6a460792009-09-16 11:50:15 +02001539 .procname = "memory_failure_early_kill",
1540 .data = &sysctl_memory_failure_early_kill,
1541 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001543 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001544 .extra1 = &zero,
1545 .extra2 = &one,
1546 },
1547 {
Andi Kleen6a460792009-09-16 11:50:15 +02001548 .procname = "memory_failure_recovery",
1549 .data = &sysctl_memory_failure_recovery,
1550 .maxlen = sizeof(sysctl_memory_failure_recovery),
1551 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001552 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001553 .extra1 = &zero,
1554 .extra2 = &one,
1555 },
1556#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001557 {
1558 .procname = "user_reserve_kbytes",
1559 .data = &sysctl_user_reserve_kbytes,
1560 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1561 .mode = 0644,
1562 .proc_handler = proc_doulongvec_minmax,
1563 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001564 {
1565 .procname = "admin_reserve_kbytes",
1566 .data = &sysctl_admin_reserve_kbytes,
1567 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1568 .mode = 0644,
1569 .proc_handler = proc_doulongvec_minmax,
1570 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001571 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572};
1573
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001574static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 .procname = "inode-nr",
1577 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001578 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001580 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 },
1582 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 .procname = "inode-state",
1584 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001585 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001587 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 },
1589 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 .procname = "file-nr",
1591 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001592 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001594 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 },
1596 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 .procname = "file-max",
1598 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001599 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001601 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 },
1603 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001604 .procname = "nr_open",
1605 .data = &sysctl_nr_open,
1606 .maxlen = sizeof(int),
1607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001608 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001609 .extra1 = &sysctl_nr_open_min,
1610 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001611 },
1612 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 .procname = "dentry-state",
1614 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001615 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001617 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 },
1619 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 .procname = "overflowuid",
1621 .data = &fs_overflowuid,
1622 .maxlen = sizeof(int),
1623 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001624 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 .extra1 = &minolduid,
1626 .extra2 = &maxolduid,
1627 },
1628 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 .procname = "overflowgid",
1630 .data = &fs_overflowgid,
1631 .maxlen = sizeof(int),
1632 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001633 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 .extra1 = &minolduid,
1635 .extra2 = &maxolduid,
1636 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001637#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 .procname = "leases-enable",
1640 .data = &leases_enable,
1641 .maxlen = sizeof(int),
1642 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001643 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001645#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646#ifdef CONFIG_DNOTIFY
1647 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 .procname = "dir-notify-enable",
1649 .data = &dir_notify_enable,
1650 .maxlen = sizeof(int),
1651 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001652 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 },
1654#endif
1655#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001656#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 .procname = "lease-break-time",
1659 .data = &lease_break_time,
1660 .maxlen = sizeof(int),
1661 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001662 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001664#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001665#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 .procname = "aio-nr",
1668 .data = &aio_nr,
1669 .maxlen = sizeof(aio_nr),
1670 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001671 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 },
1673 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 .procname = "aio-max-nr",
1675 .data = &aio_max_nr,
1676 .maxlen = sizeof(aio_max_nr),
1677 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001678 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001680#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001681#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001682 {
Robert Love0399cb02005-07-13 12:38:18 -04001683 .procname = "inotify",
1684 .mode = 0555,
1685 .child = inotify_table,
1686 },
1687#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001688#ifdef CONFIG_EPOLL
1689 {
1690 .procname = "epoll",
1691 .mode = 0555,
1692 .child = epoll_table,
1693 },
1694#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001696 {
Kees Cook800179c2012-07-25 17:29:07 -07001697 .procname = "protected_symlinks",
1698 .data = &sysctl_protected_symlinks,
1699 .maxlen = sizeof(int),
1700 .mode = 0600,
1701 .proc_handler = proc_dointvec_minmax,
1702 .extra1 = &zero,
1703 .extra2 = &one,
1704 },
1705 {
1706 .procname = "protected_hardlinks",
1707 .data = &sysctl_protected_hardlinks,
1708 .maxlen = sizeof(int),
1709 .mode = 0600,
1710 .proc_handler = proc_dointvec_minmax,
1711 .extra1 = &zero,
1712 .extra2 = &one,
1713 },
1714 {
Alan Coxd6e71142005-06-23 00:09:43 -07001715 .procname = "suid_dumpable",
1716 .data = &suid_dumpable,
1717 .maxlen = sizeof(int),
1718 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001719 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001720 .extra1 = &zero,
1721 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001722 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001723#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1724 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001725 .procname = "binfmt_misc",
1726 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001727 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001728 },
1729#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001730 {
Jens Axboeff9da692010-06-03 14:54:39 +02001731 .procname = "pipe-max-size",
1732 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001733 .maxlen = sizeof(int),
1734 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001735 .proc_handler = &pipe_proc_fn,
1736 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001737 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001738 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739};
1740
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001741static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001742#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001743 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001744 .procname = "exception-trace",
1745 .data = &show_unhandled_signals,
1746 .maxlen = sizeof(int),
1747 .mode = 0644,
1748 .proc_handler = proc_dointvec
1749 },
1750#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001751#if defined(CONFIG_OPTPROBES)
1752 {
1753 .procname = "kprobes-optimization",
1754 .data = &sysctl_kprobes_optimization,
1755 .maxlen = sizeof(int),
1756 .mode = 0644,
1757 .proc_handler = proc_kprobes_optimization_handler,
1758 .extra1 = &zero,
1759 .extra2 = &one,
1760 },
1761#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001762 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763};
1764
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001765static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001766 { }
Robert Love0eeca282005-07-12 17:06:03 -04001767};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001769int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001770{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001771 struct ctl_table_header *hdr;
1772
1773 hdr = register_sysctl_table(sysctl_base_table);
1774 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001775 return 0;
1776}
1777
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001778#endif /* CONFIG_SYSCTL */
1779
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780/*
1781 * /proc/sys support
1782 */
1783
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001784#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785
Kees Cookf8808302014-06-06 14:37:17 -07001786static int _proc_do_string(char *data, int maxlen, int write,
1787 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001788 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001789{
1790 size_t len;
1791 char __user *p;
1792 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001793
1794 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001795 *lenp = 0;
1796 return 0;
1797 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001798
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001799 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001800 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1801 /* Only continue writes not past the end of buffer. */
1802 len = strlen(data);
1803 if (len > maxlen - 1)
1804 len = maxlen - 1;
1805
1806 if (*ppos > len)
1807 return 0;
1808 len = *ppos;
1809 } else {
1810 /* Start writing from beginning of buffer. */
1811 len = 0;
1812 }
1813
Kees Cook2ca9bb42014-06-06 14:37:18 -07001814 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001815 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001816 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001817 if (get_user(c, p++))
1818 return -EFAULT;
1819 if (c == 0 || c == '\n')
1820 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001821 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001822 }
Kees Cookf8808302014-06-06 14:37:17 -07001823 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001824 } else {
1825 len = strlen(data);
1826 if (len > maxlen)
1827 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001828
1829 if (*ppos > len) {
1830 *lenp = 0;
1831 return 0;
1832 }
1833
1834 data += *ppos;
1835 len -= *ppos;
1836
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001837 if (len > *lenp)
1838 len = *lenp;
1839 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001840 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001841 return -EFAULT;
1842 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001843 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001844 return -EFAULT;
1845 len++;
1846 }
1847 *lenp = len;
1848 *ppos += len;
1849 }
1850 return 0;
1851}
1852
Kees Cookf4aacea2014-06-06 14:37:19 -07001853static void warn_sysctl_write(struct ctl_table *table)
1854{
1855 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1856 "This will not be supported in the future. To silence this\n"
1857 "warning, set kernel.sysctl_writes_strict = -1\n",
1858 current->comm, table->procname);
1859}
1860
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861/**
1862 * proc_dostring - read a string sysctl
1863 * @table: the sysctl table
1864 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 * @buffer: the user buffer
1866 * @lenp: the size of the user buffer
1867 * @ppos: file position
1868 *
1869 * Reads/writes a string from/to the user buffer. If the kernel
1870 * buffer provided is not large enough to hold the string, the
1871 * string is truncated. The copied string is %NULL-terminated.
1872 * If the string is being read by the user process, it is copied
1873 * and a newline '\n' is added. It is truncated if the buffer is
1874 * not large enough.
1875 *
1876 * Returns 0 on success.
1877 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001878int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 void __user *buffer, size_t *lenp, loff_t *ppos)
1880{
Kees Cookf4aacea2014-06-06 14:37:19 -07001881 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1882 warn_sysctl_write(table);
1883
Kees Cookf8808302014-06-06 14:37:17 -07001884 return _proc_do_string((char *)(table->data), table->maxlen, write,
1885 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886}
1887
Amerigo Wang00b7c332010-05-05 00:26:45 +00001888static size_t proc_skip_spaces(char **buf)
1889{
1890 size_t ret;
1891 char *tmp = skip_spaces(*buf);
1892 ret = tmp - *buf;
1893 *buf = tmp;
1894 return ret;
1895}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001897static void proc_skip_char(char **buf, size_t *size, const char v)
1898{
1899 while (*size) {
1900 if (**buf != v)
1901 break;
1902 (*size)--;
1903 (*buf)++;
1904 }
1905}
1906
Amerigo Wang00b7c332010-05-05 00:26:45 +00001907#define TMPBUFLEN 22
1908/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001909 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001910 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001911 * @buf: a kernel buffer
1912 * @size: size of the kernel buffer
1913 * @val: this is where the number will be stored
1914 * @neg: set to %TRUE if number is negative
1915 * @perm_tr: a vector which contains the allowed trailers
1916 * @perm_tr_len: size of the perm_tr vector
1917 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001918 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001919 * In case of success %0 is returned and @buf and @size are updated with
1920 * the amount of bytes read. If @tr is non-NULL and a trailing
1921 * character exists (size is non-zero after returning from this
1922 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001923 */
1924static int proc_get_long(char **buf, size_t *size,
1925 unsigned long *val, bool *neg,
1926 const char *perm_tr, unsigned perm_tr_len, char *tr)
1927{
1928 int len;
1929 char *p, tmp[TMPBUFLEN];
1930
1931 if (!*size)
1932 return -EINVAL;
1933
1934 len = *size;
1935 if (len > TMPBUFLEN - 1)
1936 len = TMPBUFLEN - 1;
1937
1938 memcpy(tmp, *buf, len);
1939
1940 tmp[len] = 0;
1941 p = tmp;
1942 if (*p == '-' && *size > 1) {
1943 *neg = true;
1944 p++;
1945 } else
1946 *neg = false;
1947 if (!isdigit(*p))
1948 return -EINVAL;
1949
1950 *val = simple_strtoul(p, &p, 0);
1951
1952 len = p - tmp;
1953
1954 /* We don't know if the next char is whitespace thus we may accept
1955 * invalid integers (e.g. 1234...a) or two integers instead of one
1956 * (e.g. 123...1). So lets not allow such large numbers. */
1957 if (len == TMPBUFLEN - 1)
1958 return -EINVAL;
1959
1960 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1961 return -EINVAL;
1962
1963 if (tr && (len < *size))
1964 *tr = *p;
1965
1966 *buf += len;
1967 *size -= len;
1968
1969 return 0;
1970}
1971
1972/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001973 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001974 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001975 * @buf: the user buffer
1976 * @size: the size of the user buffer
1977 * @val: the integer to be converted
1978 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001979 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001980 * In case of success %0 is returned and @buf and @size are updated with
1981 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001982 */
1983static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1984 bool neg)
1985{
1986 int len;
1987 char tmp[TMPBUFLEN], *p = tmp;
1988
1989 sprintf(p, "%s%lu", neg ? "-" : "", val);
1990 len = strlen(tmp);
1991 if (len > *size)
1992 len = *size;
1993 if (copy_to_user(*buf, tmp, len))
1994 return -EFAULT;
1995 *size -= len;
1996 *buf += len;
1997 return 0;
1998}
1999#undef TMPBUFLEN
2000
2001static int proc_put_char(void __user **buf, size_t *size, char c)
2002{
2003 if (*size) {
2004 char __user **buffer = (char __user **)buf;
2005 if (put_user(c, *buffer))
2006 return -EFAULT;
2007 (*size)--, (*buffer)++;
2008 *buf = *buffer;
2009 }
2010 return 0;
2011}
2012
2013static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 int *valp,
2015 int write, void *data)
2016{
2017 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002018 if (*negp) {
2019 if (*lvalp > (unsigned long) INT_MAX + 1)
2020 return -EINVAL;
2021 *valp = -*lvalp;
2022 } else {
2023 if (*lvalp > (unsigned long) INT_MAX)
2024 return -EINVAL;
2025 *valp = *lvalp;
2026 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 } else {
2028 int val = *valp;
2029 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002030 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002031 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002033 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 *lvalp = (unsigned long)val;
2035 }
2036 }
2037 return 0;
2038}
2039
Amerigo Wang00b7c332010-05-05 00:26:45 +00002040static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2041
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002042static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002043 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002044 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002045 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 int write, void *data),
2047 void *data)
2048{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002049 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002050 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002051 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
Amerigo Wang00b7c332010-05-05 00:26:45 +00002053 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 *lenp = 0;
2055 return 0;
2056 }
2057
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002058 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 vleft = table->maxlen / sizeof(*i);
2060 left = *lenp;
2061
2062 if (!conv)
2063 conv = do_proc_dointvec_conv;
2064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002066 if (*ppos) {
2067 switch (sysctl_writes_strict) {
2068 case SYSCTL_WRITES_STRICT:
2069 goto out;
2070 case SYSCTL_WRITES_WARN:
2071 warn_sysctl_write(table);
2072 break;
2073 default:
2074 break;
2075 }
2076 }
2077
Amerigo Wang00b7c332010-05-05 00:26:45 +00002078 if (left > PAGE_SIZE - 1)
2079 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002080 p = kbuf = memdup_user_nul(buffer, left);
2081 if (IS_ERR(kbuf))
2082 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002083 }
2084
2085 for (; left && vleft--; i++, first=0) {
2086 unsigned long lval;
2087 bool neg;
2088
2089 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002090 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002091
J. R. Okajima563b0462010-05-25 16:10:14 -07002092 if (!left)
2093 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002094 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002095 proc_wspace_sep,
2096 sizeof(proc_wspace_sep), NULL);
2097 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002099 if (conv(&neg, &lval, i, 1, data)) {
2100 err = -EINVAL;
2101 break;
2102 }
2103 } else {
2104 if (conv(&neg, &lval, i, 0, data)) {
2105 err = -EINVAL;
2106 break;
2107 }
2108 if (!first)
2109 err = proc_put_char(&buffer, &left, '\t');
2110 if (err)
2111 break;
2112 err = proc_put_long(&buffer, &left, lval, neg);
2113 if (err)
2114 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 }
2116 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002117
2118 if (!write && !first && left && !err)
2119 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002120 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002121 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002122 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002123 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002124 if (first)
2125 return err ? : -EINVAL;
2126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002128out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002130 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131}
2132
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002133static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002134 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002135 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002136 int write, void *data),
2137 void *data)
2138{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002139 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002140 buffer, lenp, ppos, conv, data);
2141}
2142
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143/**
2144 * proc_dointvec - read a vector of integers
2145 * @table: the sysctl table
2146 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 * @buffer: the user buffer
2148 * @lenp: the size of the user buffer
2149 * @ppos: file position
2150 *
2151 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2152 * values from/to the user buffer, treated as an ASCII string.
2153 *
2154 * Returns 0 on success.
2155 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002156int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 void __user *buffer, size_t *lenp, loff_t *ppos)
2158{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002159 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 NULL,NULL);
2161}
2162
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002163/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002164 * Taint values can only be increased
2165 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002166 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002167static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002168 void __user *buffer, size_t *lenp, loff_t *ppos)
2169{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002170 struct ctl_table t;
2171 unsigned long tmptaint = get_taint();
2172 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002173
Bastian Blank91fcd412007-04-23 14:41:14 -07002174 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002175 return -EPERM;
2176
Andi Kleen25ddbb12008-10-15 22:01:41 -07002177 t = *table;
2178 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002179 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002180 if (err < 0)
2181 return err;
2182
2183 if (write) {
2184 /*
2185 * Poor man's atomic or. Not worth adding a primitive
2186 * to everyone's atomic.h for this
2187 */
2188 int i;
2189 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2190 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302191 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002192 }
2193 }
2194
2195 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002196}
2197
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002198#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002199static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002200 void __user *buffer, size_t *lenp, loff_t *ppos)
2201{
2202 if (write && !capable(CAP_SYS_ADMIN))
2203 return -EPERM;
2204
2205 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2206}
2207#endif
2208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209struct do_proc_dointvec_minmax_conv_param {
2210 int *min;
2211 int *max;
2212};
2213
Amerigo Wang00b7c332010-05-05 00:26:45 +00002214static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2215 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 int write, void *data)
2217{
2218 struct do_proc_dointvec_minmax_conv_param *param = data;
2219 if (write) {
2220 int val = *negp ? -*lvalp : *lvalp;
2221 if ((param->min && *param->min > val) ||
2222 (param->max && *param->max < val))
2223 return -EINVAL;
2224 *valp = val;
2225 } else {
2226 int val = *valp;
2227 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002228 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002229 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002231 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 *lvalp = (unsigned long)val;
2233 }
2234 }
2235 return 0;
2236}
2237
2238/**
2239 * proc_dointvec_minmax - read a vector of integers with min/max values
2240 * @table: the sysctl table
2241 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 * @buffer: the user buffer
2243 * @lenp: the size of the user buffer
2244 * @ppos: file position
2245 *
2246 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2247 * values from/to the user buffer, treated as an ASCII string.
2248 *
2249 * This routine will ensure the values are within the range specified by
2250 * table->extra1 (min) and table->extra2 (max).
2251 *
2252 * Returns 0 on success.
2253 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002254int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 void __user *buffer, size_t *lenp, loff_t *ppos)
2256{
2257 struct do_proc_dointvec_minmax_conv_param param = {
2258 .min = (int *) table->extra1,
2259 .max = (int *) table->extra2,
2260 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002261 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 do_proc_dointvec_minmax_conv, &param);
2263}
2264
Kees Cook54b50192012-07-30 14:39:18 -07002265static void validate_coredump_safety(void)
2266{
Alex Kelly046d6622012-10-04 17:15:23 -07002267#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002268 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002269 core_pattern[0] != '/' && core_pattern[0] != '|') {
2270 printk(KERN_WARNING "Unsafe core_pattern used with "\
2271 "suid_dumpable=2. Pipe handler or fully qualified "\
2272 "core dump path required.\n");
2273 }
Alex Kelly046d6622012-10-04 17:15:23 -07002274#endif
Kees Cook54b50192012-07-30 14:39:18 -07002275}
2276
2277static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2278 void __user *buffer, size_t *lenp, loff_t *ppos)
2279{
2280 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2281 if (!error)
2282 validate_coredump_safety();
2283 return error;
2284}
2285
Alex Kelly046d6622012-10-04 17:15:23 -07002286#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002287static int proc_dostring_coredump(struct ctl_table *table, int write,
2288 void __user *buffer, size_t *lenp, loff_t *ppos)
2289{
2290 int error = proc_dostring(table, write, buffer, lenp, ppos);
2291 if (!error)
2292 validate_coredump_safety();
2293 return error;
2294}
Alex Kelly046d6622012-10-04 17:15:23 -07002295#endif
Kees Cook54b50192012-07-30 14:39:18 -07002296
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002297static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 void __user *buffer,
2299 size_t *lenp, loff_t *ppos,
2300 unsigned long convmul,
2301 unsigned long convdiv)
2302{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002303 unsigned long *i, *min, *max;
2304 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002305 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002306 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307
2308 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 *lenp = 0;
2310 return 0;
2311 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002312
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002313 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 min = (unsigned long *) table->extra1;
2315 max = (unsigned long *) table->extra2;
2316 vleft = table->maxlen / sizeof(unsigned long);
2317 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318
2319 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002320 if (*ppos) {
2321 switch (sysctl_writes_strict) {
2322 case SYSCTL_WRITES_STRICT:
2323 goto out;
2324 case SYSCTL_WRITES_WARN:
2325 warn_sysctl_write(table);
2326 break;
2327 default:
2328 break;
2329 }
2330 }
2331
Amerigo Wang00b7c332010-05-05 00:26:45 +00002332 if (left > PAGE_SIZE - 1)
2333 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002334 p = kbuf = memdup_user_nul(buffer, left);
2335 if (IS_ERR(kbuf))
2336 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002337 }
2338
Eric Dumazet27b3d802010-10-07 12:59:29 -07002339 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002340 unsigned long val;
2341
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002343 bool neg;
2344
Al Viro70f6cbb2015-12-24 00:13:10 -05002345 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002346
Al Viro70f6cbb2015-12-24 00:13:10 -05002347 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002348 proc_wspace_sep,
2349 sizeof(proc_wspace_sep), NULL);
2350 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 break;
2352 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 continue;
2354 if ((min && val < *min) || (max && val > *max))
2355 continue;
2356 *i = val;
2357 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002358 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002359 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002360 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002361 if (err)
2362 break;
2363 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002364 err = proc_put_long(&buffer, &left, val, false);
2365 if (err)
2366 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 }
2368 }
2369
Amerigo Wang00b7c332010-05-05 00:26:45 +00002370 if (!write && !first && left && !err)
2371 err = proc_put_char(&buffer, &left, '\n');
2372 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002373 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002375 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002376 if (first)
2377 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002380out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002382 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383}
2384
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002385static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002386 void __user *buffer,
2387 size_t *lenp, loff_t *ppos,
2388 unsigned long convmul,
2389 unsigned long convdiv)
2390{
2391 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002392 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002393}
2394
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395/**
2396 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2397 * @table: the sysctl table
2398 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 * @buffer: the user buffer
2400 * @lenp: the size of the user buffer
2401 * @ppos: file position
2402 *
2403 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2404 * values from/to the user buffer, treated as an ASCII string.
2405 *
2406 * This routine will ensure the values are within the range specified by
2407 * table->extra1 (min) and table->extra2 (max).
2408 *
2409 * Returns 0 on success.
2410 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002411int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 void __user *buffer, size_t *lenp, loff_t *ppos)
2413{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002414 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415}
2416
2417/**
2418 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2419 * @table: the sysctl table
2420 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 * @buffer: the user buffer
2422 * @lenp: the size of the user buffer
2423 * @ppos: file position
2424 *
2425 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2426 * values from/to the user buffer, treated as an ASCII string. The values
2427 * are treated as milliseconds, and converted to jiffies when they are stored.
2428 *
2429 * This routine will ensure the values are within the range specified by
2430 * table->extra1 (min) and table->extra2 (max).
2431 *
2432 * Returns 0 on success.
2433 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002434int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 void __user *buffer,
2436 size_t *lenp, loff_t *ppos)
2437{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002438 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 lenp, ppos, HZ, 1000l);
2440}
2441
2442
Amerigo Wang00b7c332010-05-05 00:26:45 +00002443static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 int *valp,
2445 int write, void *data)
2446{
2447 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002448 if (*lvalp > LONG_MAX / HZ)
2449 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2451 } else {
2452 int val = *valp;
2453 unsigned long lval;
2454 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002455 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002456 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002458 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 lval = (unsigned long)val;
2460 }
2461 *lvalp = lval / HZ;
2462 }
2463 return 0;
2464}
2465
Amerigo Wang00b7c332010-05-05 00:26:45 +00002466static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 int *valp,
2468 int write, void *data)
2469{
2470 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002471 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2472 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2474 } else {
2475 int val = *valp;
2476 unsigned long lval;
2477 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002478 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002479 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002481 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 lval = (unsigned long)val;
2483 }
2484 *lvalp = jiffies_to_clock_t(lval);
2485 }
2486 return 0;
2487}
2488
Amerigo Wang00b7c332010-05-05 00:26:45 +00002489static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 int *valp,
2491 int write, void *data)
2492{
2493 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002494 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2495
2496 if (jif > INT_MAX)
2497 return 1;
2498 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 } else {
2500 int val = *valp;
2501 unsigned long lval;
2502 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002503 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002504 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002506 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 lval = (unsigned long)val;
2508 }
2509 *lvalp = jiffies_to_msecs(lval);
2510 }
2511 return 0;
2512}
2513
2514/**
2515 * proc_dointvec_jiffies - read a vector of integers as seconds
2516 * @table: the sysctl table
2517 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 * @buffer: the user buffer
2519 * @lenp: the size of the user buffer
2520 * @ppos: file position
2521 *
2522 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2523 * values from/to the user buffer, treated as an ASCII string.
2524 * The values read are assumed to be in seconds, and are converted into
2525 * jiffies.
2526 *
2527 * Returns 0 on success.
2528 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002529int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 void __user *buffer, size_t *lenp, loff_t *ppos)
2531{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002532 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 do_proc_dointvec_jiffies_conv,NULL);
2534}
2535
2536/**
2537 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2538 * @table: the sysctl table
2539 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 * @buffer: the user buffer
2541 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002542 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 *
2544 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2545 * values from/to the user buffer, treated as an ASCII string.
2546 * The values read are assumed to be in 1/USER_HZ seconds, and
2547 * are converted into jiffies.
2548 *
2549 * Returns 0 on success.
2550 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002551int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 void __user *buffer, size_t *lenp, loff_t *ppos)
2553{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002554 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 do_proc_dointvec_userhz_jiffies_conv,NULL);
2556}
2557
2558/**
2559 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2560 * @table: the sysctl table
2561 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 * @buffer: the user buffer
2563 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002564 * @ppos: file position
2565 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 *
2567 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2568 * values from/to the user buffer, treated as an ASCII string.
2569 * The values read are assumed to be in 1/1000 seconds, and
2570 * are converted into jiffies.
2571 *
2572 * Returns 0 on success.
2573 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002574int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 void __user *buffer, size_t *lenp, loff_t *ppos)
2576{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002577 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 do_proc_dointvec_ms_jiffies_conv, NULL);
2579}
2580
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002581static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002582 void __user *buffer, size_t *lenp, loff_t *ppos)
2583{
2584 struct pid *new_pid;
2585 pid_t tmp;
2586 int r;
2587
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002588 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002589
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002590 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002591 lenp, ppos, NULL, NULL);
2592 if (r || !write)
2593 return r;
2594
2595 new_pid = find_get_pid(tmp);
2596 if (!new_pid)
2597 return -ESRCH;
2598
2599 put_pid(xchg(&cad_pid, new_pid));
2600 return 0;
2601}
2602
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002603/**
2604 * proc_do_large_bitmap - read/write from/to a large bitmap
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
2607 * @buffer: the user buffer
2608 * @lenp: the size of the user buffer
2609 * @ppos: file position
2610 *
2611 * The bitmap is stored at table->data and the bitmap length (in bits)
2612 * in table->maxlen.
2613 *
2614 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2615 * large bitmaps may be represented in a compact manner. Writing into
2616 * the file will clear the bitmap then update it with the given input.
2617 *
2618 * Returns 0 on success.
2619 */
2620int proc_do_large_bitmap(struct ctl_table *table, int write,
2621 void __user *buffer, size_t *lenp, loff_t *ppos)
2622{
2623 int err = 0;
2624 bool first = 1;
2625 size_t left = *lenp;
2626 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002627 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002628 unsigned long *tmp_bitmap = NULL;
2629 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2630
WANG Cong122ff242014-05-12 16:04:53 -07002631 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002632 *lenp = 0;
2633 return 0;
2634 }
2635
2636 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002637 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002638
2639 if (left > PAGE_SIZE - 1)
2640 left = PAGE_SIZE - 1;
2641
Al Viro70f6cbb2015-12-24 00:13:10 -05002642 p = kbuf = memdup_user_nul(buffer, left);
2643 if (IS_ERR(kbuf))
2644 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002645
2646 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2647 GFP_KERNEL);
2648 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002649 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002650 return -ENOMEM;
2651 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002652 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002653 while (!err && left) {
2654 unsigned long val_a, val_b;
2655 bool neg;
2656
Al Viro70f6cbb2015-12-24 00:13:10 -05002657 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002658 sizeof(tr_a), &c);
2659 if (err)
2660 break;
2661 if (val_a >= bitmap_len || neg) {
2662 err = -EINVAL;
2663 break;
2664 }
2665
2666 val_b = val_a;
2667 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002668 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002669 left--;
2670 }
2671
2672 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05002673 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002674 &neg, tr_b, sizeof(tr_b),
2675 &c);
2676 if (err)
2677 break;
2678 if (val_b >= bitmap_len || neg ||
2679 val_a > val_b) {
2680 err = -EINVAL;
2681 break;
2682 }
2683 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002684 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002685 left--;
2686 }
2687 }
2688
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002689 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002690 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05002691 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002692 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002693 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002694 } else {
2695 unsigned long bit_a, bit_b = 0;
2696
2697 while (left) {
2698 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2699 if (bit_a >= bitmap_len)
2700 break;
2701 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2702 bit_a + 1) - 1;
2703
2704 if (!first) {
2705 err = proc_put_char(&buffer, &left, ',');
2706 if (err)
2707 break;
2708 }
2709 err = proc_put_long(&buffer, &left, bit_a, false);
2710 if (err)
2711 break;
2712 if (bit_a != bit_b) {
2713 err = proc_put_char(&buffer, &left, '-');
2714 if (err)
2715 break;
2716 err = proc_put_long(&buffer, &left, bit_b, false);
2717 if (err)
2718 break;
2719 }
2720
2721 first = 0; bit_b++;
2722 }
2723 if (!err)
2724 err = proc_put_char(&buffer, &left, '\n');
2725 }
2726
2727 if (!err) {
2728 if (write) {
2729 if (*ppos)
2730 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2731 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002732 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002733 }
2734 kfree(tmp_bitmap);
2735 *lenp -= left;
2736 *ppos += *lenp;
2737 return 0;
2738 } else {
2739 kfree(tmp_bitmap);
2740 return err;
2741 }
2742}
2743
Jovi Zhang55610502011-01-12 17:00:45 -08002744#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002746int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 void __user *buffer, size_t *lenp, loff_t *ppos)
2748{
2749 return -ENOSYS;
2750}
2751
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002752int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 void __user *buffer, size_t *lenp, loff_t *ppos)
2754{
2755 return -ENOSYS;
2756}
2757
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002758int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 void __user *buffer, size_t *lenp, loff_t *ppos)
2760{
2761 return -ENOSYS;
2762}
2763
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002764int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 void __user *buffer, size_t *lenp, loff_t *ppos)
2766{
2767 return -ENOSYS;
2768}
2769
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002770int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 void __user *buffer, size_t *lenp, loff_t *ppos)
2772{
2773 return -ENOSYS;
2774}
2775
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002776int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 void __user *buffer, size_t *lenp, loff_t *ppos)
2778{
2779 return -ENOSYS;
2780}
2781
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002782int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 void __user *buffer, size_t *lenp, loff_t *ppos)
2784{
2785 return -ENOSYS;
2786}
2787
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002788int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 void __user *buffer,
2790 size_t *lenp, loff_t *ppos)
2791{
2792 return -ENOSYS;
2793}
2794
2795
Jovi Zhang55610502011-01-12 17:00:45 -08002796#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798/*
2799 * No sense putting this after each symbol definition, twice,
2800 * exception granted :-)
2801 */
2802EXPORT_SYMBOL(proc_dointvec);
2803EXPORT_SYMBOL(proc_dointvec_jiffies);
2804EXPORT_SYMBOL(proc_dointvec_minmax);
2805EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2806EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2807EXPORT_SYMBOL(proc_dostring);
2808EXPORT_SYMBOL(proc_doulongvec_minmax);
2809EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);