blob: f5102fabef7f525f6c79d66756336c262e465caa [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
Kees Cook41662f52016-01-20 15:00:45 -0800176static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700177
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 },
Mel Gormancb251762016-02-05 09:08:36 +0000353#ifdef CONFIG_SCHEDSTATS
354 {
355 .procname = "sched_schedstats",
356 .data = NULL,
357 .maxlen = sizeof(unsigned int),
358 .mode = 0644,
359 .proc_handler = sysctl_schedstats,
360 .extra1 = &zero,
361 .extra2 = &one,
362 },
363#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200364#endif /* CONFIG_SMP */
365#ifdef CONFIG_NUMA_BALANCING
366 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200367 .procname = "numa_balancing_scan_delay_ms",
368 .data = &sysctl_numa_balancing_scan_delay,
369 .maxlen = sizeof(unsigned int),
370 .mode = 0644,
371 .proc_handler = proc_dointvec,
372 },
373 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200374 .procname = "numa_balancing_scan_period_min_ms",
375 .data = &sysctl_numa_balancing_scan_period_min,
376 .maxlen = sizeof(unsigned int),
377 .mode = 0644,
378 .proc_handler = proc_dointvec,
379 },
380 {
381 .procname = "numa_balancing_scan_period_max_ms",
382 .data = &sysctl_numa_balancing_scan_period_max,
383 .maxlen = sizeof(unsigned int),
384 .mode = 0644,
385 .proc_handler = proc_dointvec,
386 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200387 {
388 .procname = "numa_balancing_scan_size_mb",
389 .data = &sysctl_numa_balancing_scan_size,
390 .maxlen = sizeof(unsigned int),
391 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400392 .proc_handler = proc_dointvec_minmax,
393 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200394 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100395 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800396 .procname = "numa_balancing",
397 .data = NULL, /* filled in by handler */
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
400 .proc_handler = sysctl_numa_balancing,
401 .extra1 = &zero,
402 .extra2 = &one,
403 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200404#endif /* CONFIG_NUMA_BALANCING */
405#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200406 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100407 .procname = "sched_rt_period_us",
408 .data = &sysctl_sched_rt_period,
409 .maxlen = sizeof(unsigned int),
410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800411 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100412 },
413 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100414 .procname = "sched_rt_runtime_us",
415 .data = &sysctl_sched_rt_runtime,
416 .maxlen = sizeof(int),
417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800418 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100419 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600420 {
421 .procname = "sched_rr_timeslice_ms",
422 .data = &sched_rr_timeslice,
423 .maxlen = sizeof(int),
424 .mode = 0644,
425 .proc_handler = sched_rr_handler,
426 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100427#ifdef CONFIG_SCHED_AUTOGROUP
428 {
429 .procname = "sched_autogroup_enabled",
430 .data = &sysctl_sched_autogroup_enabled,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800433 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100434 .extra1 = &zero,
435 .extra2 = &one,
436 },
437#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700438#ifdef CONFIG_CFS_BANDWIDTH
439 {
440 .procname = "sched_cfs_bandwidth_slice_us",
441 .data = &sysctl_sched_cfs_bandwidth_slice,
442 .maxlen = sizeof(unsigned int),
443 .mode = 0644,
444 .proc_handler = proc_dointvec_minmax,
445 .extra1 = &one,
446 },
447#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700448#ifdef CONFIG_PROVE_LOCKING
449 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700450 .procname = "prove_locking",
451 .data = &prove_locking,
452 .maxlen = sizeof(int),
453 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800454 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700455 },
456#endif
457#ifdef CONFIG_LOCK_STAT
458 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700459 .procname = "lock_stat",
460 .data = &lock_stat,
461 .maxlen = sizeof(int),
462 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800463 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700464 },
465#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 .procname = "panic",
468 .data = &panic_timeout,
469 .maxlen = sizeof(int),
470 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800471 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 },
Alex Kelly046d6622012-10-04 17:15:23 -0700473#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .procname = "core_uses_pid",
476 .data = &core_uses_pid,
477 .maxlen = sizeof(int),
478 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800479 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 },
481 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 .procname = "core_pattern",
483 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700484 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700486 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 },
Neil Hormana2939802009-09-23 15:56:56 -0700488 {
Neil Hormana2939802009-09-23 15:56:56 -0700489 .procname = "core_pipe_limit",
490 .data = &core_pipe_limit,
491 .maxlen = sizeof(unsigned int),
492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800493 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700494 },
Alex Kelly046d6622012-10-04 17:15:23 -0700495#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800496#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700499 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800500 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800501 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700503 {
504 .procname = "sysctl_writes_strict",
505 .data = &sysctl_writes_strict,
506 .maxlen = sizeof(int),
507 .mode = 0644,
508 .proc_handler = proc_dointvec_minmax,
509 .extra1 = &neg_one,
510 .extra2 = &one,
511 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800512#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100513#ifdef CONFIG_LATENCYTOP
514 {
515 .procname = "latencytop",
516 .data = &latencytop_enabled,
517 .maxlen = sizeof(int),
518 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000519 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100520 },
521#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522#ifdef CONFIG_BLK_DEV_INITRD
523 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 .procname = "real-root-dev",
525 .data = &real_root_dev,
526 .maxlen = sizeof(int),
527 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800528 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 },
530#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700531 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700532 .procname = "print-fatal-signals",
533 .data = &print_fatal_signals,
534 .maxlen = sizeof(int),
535 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800536 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700537 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700538#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 .procname = "reboot-cmd",
541 .data = reboot_command,
542 .maxlen = 256,
543 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800544 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 },
546 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 .procname = "stop-a",
548 .data = &stop_a_enabled,
549 .maxlen = sizeof (int),
550 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800551 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 },
553 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 .procname = "scons-poweroff",
555 .data = &scons_pwroff,
556 .maxlen = sizeof (int),
557 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800558 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 },
560#endif
David S. Miller08714202008-11-16 23:49:24 -0800561#ifdef CONFIG_SPARC64
562 {
David S. Miller08714202008-11-16 23:49:24 -0800563 .procname = "tsb-ratio",
564 .data = &sysctl_tsb_ratio,
565 .maxlen = sizeof (int),
566 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800567 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800568 },
569#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570#ifdef __hppa__
571 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .procname = "soft-power",
573 .data = &pwrsw_enabled,
574 .maxlen = sizeof (int),
575 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800576 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530578#endif
579#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "unaligned-trap",
582 .data = &unaligned_enabled,
583 .maxlen = sizeof (int),
584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800585 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
587#endif
588 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 .procname = "ctrl-alt-del",
590 .data = &C_A_D,
591 .maxlen = sizeof(int),
592 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800593 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400595#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200596 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200597 .procname = "ftrace_enabled",
598 .data = &ftrace_enabled,
599 .maxlen = sizeof(int),
600 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800601 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200602 },
603#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500604#ifdef CONFIG_STACK_TRACER
605 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500606 .procname = "stack_tracer_enabled",
607 .data = &stack_tracer_enabled,
608 .maxlen = sizeof(int),
609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800610 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500611 },
612#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400613#ifdef CONFIG_TRACING
614 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100615 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400616 .data = &ftrace_dump_on_oops,
617 .maxlen = sizeof(int),
618 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800619 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400620 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400621 {
622 .procname = "traceoff_on_warning",
623 .data = &__disable_trace_on_warning,
624 .maxlen = sizeof(__disable_trace_on_warning),
625 .mode = 0644,
626 .proc_handler = proc_dointvec,
627 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500628 {
629 .procname = "tracepoint_printk",
630 .data = &tracepoint_printk,
631 .maxlen = sizeof(tracepoint_printk),
632 .mode = 0644,
633 .proc_handler = proc_dointvec,
634 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400635#endif
Dave Young2965faa2015-09-09 15:38:55 -0700636#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800637 {
638 .procname = "kexec_load_disabled",
639 .data = &kexec_load_disabled,
640 .maxlen = sizeof(int),
641 .mode = 0644,
642 /* only handle a transition from default "0" to "1" */
643 .proc_handler = proc_dointvec_minmax,
644 .extra1 = &one,
645 .extra2 = &one,
646 },
647#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200648#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 .procname = "modprobe",
651 .data = &modprobe_path,
652 .maxlen = KMOD_PATH_LEN,
653 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800654 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 },
Kees Cook3d433212009-04-02 15:49:29 -0700656 {
Kees Cook3d433212009-04-02 15:49:29 -0700657 .procname = "modules_disabled",
658 .data = &modules_disabled,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800662 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700663 .extra1 = &one,
664 .extra2 = &one,
665 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700667#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100670 .data = &uevent_helper,
671 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800673 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 },
Michael Marineau86d56132014-04-10 14:09:31 -0700675#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676#ifdef CONFIG_CHR_DEV_SG
677 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 .procname = "sg-big-buff",
679 .data = &sg_big_buff,
680 .maxlen = sizeof (int),
681 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800682 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 },
684#endif
685#ifdef CONFIG_BSD_PROCESS_ACCT
686 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 .procname = "acct",
688 .data = &acct_parm,
689 .maxlen = 3*sizeof(int),
690 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800691 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 },
693#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694#ifdef CONFIG_MAGIC_SYSRQ
695 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800697 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .maxlen = sizeof (int),
699 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700700 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 },
702#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700703#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700706 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 .maxlen = sizeof (int),
708 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800709 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700711#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700714 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 .maxlen = sizeof(int),
716 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700717 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 },
719 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 .procname = "random",
721 .mode = 0555,
722 .child = random_table,
723 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 {
Eric Paris17f60a72011-04-01 17:07:50 -0400725 .procname = "usermodehelper",
726 .mode = 0555,
727 .child = usermodehelper_table,
728 },
729 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 .procname = "overflowuid",
731 .data = &overflowuid,
732 .maxlen = sizeof(int),
733 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800734 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 .extra1 = &minolduid,
736 .extra2 = &maxolduid,
737 },
738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .procname = "overflowgid",
740 .data = &overflowgid,
741 .maxlen = sizeof(int),
742 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800743 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 .extra1 = &minolduid,
745 .extra2 = &maxolduid,
746 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800747#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748#ifdef CONFIG_MATHEMU
749 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .procname = "ieee_emulation_warnings",
751 .data = &sysctl_ieee_emulation_warnings,
752 .maxlen = sizeof(int),
753 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800754 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 },
756#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200759 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 .maxlen = sizeof(int),
761 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800762 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 },
764#endif
765 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 .procname = "pid_max",
767 .data = &pid_max,
768 .maxlen = sizeof (int),
769 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800770 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 .extra1 = &pid_max_min,
772 .extra2 = &pid_max_max,
773 },
774 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 .procname = "panic_on_oops",
776 .data = &panic_on_oops,
777 .maxlen = sizeof(int),
778 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800779 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800781#if defined CONFIG_PRINTK
782 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800783 .procname = "printk",
784 .data = &console_loglevel,
785 .maxlen = 4*sizeof(int),
786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800787 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800788 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700791 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .maxlen = sizeof(int),
793 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800794 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 },
796 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700798 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 .maxlen = sizeof(int),
800 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 },
Dave Youngaf913222009-09-22 16:43:33 -0700803 {
Dave Youngaf913222009-09-22 16:43:33 -0700804 .procname = "printk_delay",
805 .data = &printk_delay_msec,
806 .maxlen = sizeof(int),
807 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800808 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700809 .extra1 = &zero,
810 .extra2 = &ten_thousand,
811 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800813 .procname = "dmesg_restrict",
814 .data = &dmesg_restrict,
815 .maxlen = sizeof(int),
816 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700817 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800818 .extra1 = &zero,
819 .extra2 = &one,
820 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800821 {
822 .procname = "kptr_restrict",
823 .data = &kptr_restrict,
824 .maxlen = sizeof(int),
825 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700826 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800827 .extra1 = &zero,
828 .extra2 = &two,
829 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800830#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800831 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 .procname = "ngroups_max",
833 .data = &ngroups_max,
834 .maxlen = sizeof (int),
835 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800836 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 },
Dan Ballard73efc032011-10-31 17:11:20 -0700838 {
839 .procname = "cap_last_cap",
840 .data = (void *)&cap_last_cap,
841 .maxlen = sizeof(int),
842 .mode = 0444,
843 .proc_handler = proc_dointvec,
844 },
Don Zickus58687ac2010-05-07 17:11:44 -0400845#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500846 {
Don Zickus58687ac2010-05-07 17:11:44 -0400847 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200848 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500849 .maxlen = sizeof (int),
850 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700851 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700852 .extra1 = &zero,
853 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400854 },
855 {
856 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700857 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400858 .maxlen = sizeof(int),
859 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700860 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800861 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400862 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500863 },
Don Zickus2508ce12010-05-07 17:11:46 -0400864 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700865 .procname = "nmi_watchdog",
866 .data = &nmi_watchdog_enabled,
867 .maxlen = sizeof (int),
868 .mode = 0644,
869 .proc_handler = proc_nmi_watchdog,
870 .extra1 = &zero,
871#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
872 .extra2 = &one,
873#else
874 .extra2 = &zero,
875#endif
876 },
877 {
878 .procname = "soft_watchdog",
879 .data = &soft_watchdog_enabled,
880 .maxlen = sizeof (int),
881 .mode = 0644,
882 .proc_handler = proc_soft_watchdog,
883 .extra1 = &zero,
884 .extra2 = &one,
885 },
886 {
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700887 .procname = "watchdog_cpumask",
888 .data = &watchdog_cpumask_bits,
889 .maxlen = NR_CPUS,
890 .mode = 0644,
891 .proc_handler = proc_watchdog_cpumask,
892 },
893 {
Don Zickus2508ce12010-05-07 17:11:46 -0400894 .procname = "softlockup_panic",
895 .data = &softlockup_panic,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = proc_dointvec_minmax,
899 .extra1 = &zero,
900 .extra2 = &one,
901 },
Don Zickusac1f5912015-11-05 18:44:44 -0800902#ifdef CONFIG_HARDLOCKUP_DETECTOR
903 {
904 .procname = "hardlockup_panic",
905 .data = &hardlockup_panic,
906 .maxlen = sizeof(int),
907 .mode = 0644,
908 .proc_handler = proc_dointvec_minmax,
909 .extra1 = &zero,
910 .extra2 = &one,
911 },
912#endif
Aaron Tomlined235872014-06-23 13:22:05 -0700913#ifdef CONFIG_SMP
914 {
915 .procname = "softlockup_all_cpu_backtrace",
916 .data = &sysctl_softlockup_all_cpu_backtrace,
917 .maxlen = sizeof(int),
918 .mode = 0644,
919 .proc_handler = proc_dointvec_minmax,
920 .extra1 = &zero,
921 .extra2 = &one,
922 },
Jiri Kosina55537872015-11-05 18:44:41 -0800923 {
924 .procname = "hardlockup_all_cpu_backtrace",
925 .data = &sysctl_hardlockup_all_cpu_backtrace,
926 .maxlen = sizeof(int),
927 .mode = 0644,
928 .proc_handler = proc_dointvec_minmax,
929 .extra1 = &zero,
930 .extra2 = &one,
931 },
Aaron Tomlined235872014-06-23 13:22:05 -0700932#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500933#endif
934#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
935 {
936 .procname = "unknown_nmi_panic",
937 .data = &unknown_nmi_panic,
938 .maxlen = sizeof (int),
939 .mode = 0644,
940 .proc_handler = proc_dointvec,
941 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500942#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943#if defined(CONFIG_X86)
944 {
Don Zickus8da5add2006-09-26 10:52:27 +0200945 .procname = "panic_on_unrecovered_nmi",
946 .data = &panic_on_unrecovered_nmi,
947 .maxlen = sizeof(int),
948 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800949 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200950 },
951 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700952 .procname = "panic_on_io_nmi",
953 .data = &panic_on_io_nmi,
954 .maxlen = sizeof(int),
955 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800956 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700957 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900958#ifdef CONFIG_DEBUG_STACKOVERFLOW
959 {
960 .procname = "panic_on_stackoverflow",
961 .data = &sysctl_panic_on_stackoverflow,
962 .maxlen = sizeof(int),
963 .mode = 0644,
964 .proc_handler = proc_dointvec,
965 },
966#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700967 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 .procname = "bootloader_type",
969 .data = &bootloader_type,
970 .maxlen = sizeof (int),
971 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800972 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100974 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700975 .procname = "bootloader_version",
976 .data = &bootloader_version,
977 .maxlen = sizeof (int),
978 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800979 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700980 },
981 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100982 .procname = "kstack_depth_to_print",
983 .data = &kstack_depth_to_print,
984 .maxlen = sizeof(int),
985 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800986 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100987 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100988 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100989 .procname = "io_delay_type",
990 .data = &io_delay_type,
991 .maxlen = sizeof(int),
992 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800993 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100994 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800996#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 .procname = "randomize_va_space",
999 .data = &randomize_va_space,
1000 .maxlen = sizeof(int),
1001 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001002 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001004#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001005#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001006 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001007 .procname = "spin_retry",
1008 .data = &spin_retry,
1009 .maxlen = sizeof (int),
1010 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001011 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001012 },
1013#endif
Len Brown673d5b42007-07-28 03:33:16 -04001014#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001015 {
Pavel Machekc255d842006-02-20 18:27:58 -08001016 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001017 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001018 .maxlen = sizeof (unsigned long),
1019 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001020 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001021 },
1022#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301023#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001024 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001025 .procname = "ignore-unaligned-usertrap",
1026 .data = &no_unaligned_warning,
1027 .maxlen = sizeof (int),
1028 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001029 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001030 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301031#endif
1032#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001033 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001034 .procname = "unaligned-dump-stack",
1035 .data = &unaligned_dump_stack,
1036 .maxlen = sizeof (int),
1037 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001038 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001039 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001040#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001041#ifdef CONFIG_DETECT_HUNG_TASK
1042 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001043 .procname = "hung_task_panic",
1044 .data = &sysctl_hung_task_panic,
1045 .maxlen = sizeof(int),
1046 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001047 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001048 .extra1 = &zero,
1049 .extra2 = &one,
1050 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001051 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001052 .procname = "hung_task_check_count",
1053 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001054 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001055 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001056 .proc_handler = proc_dointvec_minmax,
1057 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001058 },
1059 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001060 .procname = "hung_task_timeout_secs",
1061 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001062 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001065 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001066 },
1067 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001068 .procname = "hung_task_warnings",
1069 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001070 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001071 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001072 .proc_handler = proc_dointvec_minmax,
1073 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001074 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001075#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001076#ifdef CONFIG_COMPAT
1077 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001078 .procname = "compat-log",
1079 .data = &compat_log,
1080 .maxlen = sizeof (int),
1081 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001082 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001083 },
1084#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001085#ifdef CONFIG_RT_MUTEXES
1086 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001087 .procname = "max_lock_depth",
1088 .data = &max_lock_depth,
1089 .maxlen = sizeof(int),
1090 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001091 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001092 },
1093#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001094 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001095 .procname = "poweroff_cmd",
1096 .data = &poweroff_cmd,
1097 .maxlen = POWEROFF_CMD_PATH_LEN,
1098 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001099 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001100 },
David Howells0b77f5b2008-04-29 01:01:32 -07001101#ifdef CONFIG_KEYS
1102 {
David Howells0b77f5b2008-04-29 01:01:32 -07001103 .procname = "keys",
1104 .mode = 0555,
1105 .child = key_sysctls,
1106 },
1107#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001108#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001109 /*
1110 * User-space scripts rely on the existence of this file
1111 * as a feature check for perf_events being enabled.
1112 *
1113 * So it's an ABI, do not remove!
1114 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001115 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001116 .procname = "perf_event_paranoid",
1117 .data = &sysctl_perf_event_paranoid,
1118 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001119 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001120 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001121 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001122 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001123 .procname = "perf_event_mlock_kb",
1124 .data = &sysctl_perf_event_mlock,
1125 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001126 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001127 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001128 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001129 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001130 .procname = "perf_event_max_sample_rate",
1131 .data = &sysctl_perf_event_sample_rate,
1132 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001133 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001134 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001135 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001136 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001137 {
1138 .procname = "perf_cpu_time_max_percent",
1139 .data = &sysctl_perf_cpu_time_max_percent,
1140 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1141 .mode = 0644,
1142 .proc_handler = perf_cpu_time_max_percent_handler,
1143 .extra1 = &zero,
1144 .extra2 = &one_hundred,
1145 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001146#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001147#ifdef CONFIG_KMEMCHECK
1148 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001149 .procname = "kmemcheck",
1150 .data = &kmemcheck_enabled,
1151 .maxlen = sizeof(int),
1152 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001153 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001154 },
1155#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001156 {
1157 .procname = "panic_on_warn",
1158 .data = &panic_on_warn,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = proc_dointvec_minmax,
1162 .extra1 = &zero,
1163 .extra2 = &one,
1164 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001165#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1166 {
1167 .procname = "timer_migration",
1168 .data = &sysctl_timer_migration,
1169 .maxlen = sizeof(unsigned int),
1170 .mode = 0644,
1171 .proc_handler = timer_migration_handler,
1172 },
1173#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001174#ifdef CONFIG_BPF_SYSCALL
1175 {
1176 .procname = "unprivileged_bpf_disabled",
1177 .data = &sysctl_unprivileged_bpf_disabled,
1178 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1179 .mode = 0644,
1180 /* only handle a transition from default "0" to "1" */
1181 .proc_handler = proc_dointvec_minmax,
1182 .extra1 = &one,
1183 .extra2 = &one,
1184 },
1185#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001186 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187};
1188
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001189static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 .procname = "overcommit_memory",
1192 .data = &sysctl_overcommit_memory,
1193 .maxlen = sizeof(sysctl_overcommit_memory),
1194 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001195 .proc_handler = proc_dointvec_minmax,
1196 .extra1 = &zero,
1197 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 },
1199 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001200 .procname = "panic_on_oom",
1201 .data = &sysctl_panic_on_oom,
1202 .maxlen = sizeof(sysctl_panic_on_oom),
1203 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001204 .proc_handler = proc_dointvec_minmax,
1205 .extra1 = &zero,
1206 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001207 },
1208 {
David Rientjesfe071d72007-10-16 23:25:56 -07001209 .procname = "oom_kill_allocating_task",
1210 .data = &sysctl_oom_kill_allocating_task,
1211 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1212 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001213 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001214 },
1215 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001216 .procname = "oom_dump_tasks",
1217 .data = &sysctl_oom_dump_tasks,
1218 .maxlen = sizeof(sysctl_oom_dump_tasks),
1219 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001220 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001221 },
1222 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 .procname = "overcommit_ratio",
1224 .data = &sysctl_overcommit_ratio,
1225 .maxlen = sizeof(sysctl_overcommit_ratio),
1226 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001227 .proc_handler = overcommit_ratio_handler,
1228 },
1229 {
1230 .procname = "overcommit_kbytes",
1231 .data = &sysctl_overcommit_kbytes,
1232 .maxlen = sizeof(sysctl_overcommit_kbytes),
1233 .mode = 0644,
1234 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 },
1236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 .procname = "page-cluster",
1238 .data = &page_cluster,
1239 .maxlen = sizeof(int),
1240 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001241 .proc_handler = proc_dointvec_minmax,
1242 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 },
1244 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 .procname = "dirty_background_ratio",
1246 .data = &dirty_background_ratio,
1247 .maxlen = sizeof(dirty_background_ratio),
1248 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001249 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 .extra1 = &zero,
1251 .extra2 = &one_hundred,
1252 },
1253 {
David Rientjes2da02992009-01-06 14:39:31 -08001254 .procname = "dirty_background_bytes",
1255 .data = &dirty_background_bytes,
1256 .maxlen = sizeof(dirty_background_bytes),
1257 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001258 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001259 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001260 },
1261 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 .procname = "dirty_ratio",
1263 .data = &vm_dirty_ratio,
1264 .maxlen = sizeof(vm_dirty_ratio),
1265 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001266 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 .extra1 = &zero,
1268 .extra2 = &one_hundred,
1269 },
1270 {
David Rientjes2da02992009-01-06 14:39:31 -08001271 .procname = "dirty_bytes",
1272 .data = &vm_dirty_bytes,
1273 .maxlen = sizeof(vm_dirty_bytes),
1274 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001275 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001276 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001277 },
1278 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001280 .data = &dirty_writeback_interval,
1281 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001283 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 },
1285 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001287 .data = &dirty_expire_interval,
1288 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001290 .proc_handler = proc_dointvec_minmax,
1291 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 },
1293 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001294 .procname = "dirtytime_expire_seconds",
1295 .data = &dirtytime_expire_interval,
1296 .maxlen = sizeof(dirty_expire_interval),
1297 .mode = 0644,
1298 .proc_handler = dirtytime_interval_handler,
1299 .extra1 = &zero,
1300 },
1301 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001302 .procname = "nr_pdflush_threads",
1303 .mode = 0444 /* read-only */,
1304 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 },
1306 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 .procname = "swappiness",
1308 .data = &vm_swappiness,
1309 .maxlen = sizeof(vm_swappiness),
1310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001311 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 .extra1 = &zero,
1313 .extra2 = &one_hundred,
1314 },
1315#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001316 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001318 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 .maxlen = sizeof(unsigned long),
1320 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001321 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001322 },
1323#ifdef CONFIG_NUMA
1324 {
1325 .procname = "nr_hugepages_mempolicy",
1326 .data = NULL,
1327 .maxlen = sizeof(unsigned long),
1328 .mode = 0644,
1329 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001330 },
1331#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 .procname = "hugetlb_shm_group",
1334 .data = &sysctl_hugetlb_shm_group,
1335 .maxlen = sizeof(gid_t),
1336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001337 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 },
Mel Gorman396faf02007-07-17 04:03:13 -07001339 {
Mel Gorman396faf02007-07-17 04:03:13 -07001340 .procname = "hugepages_treat_as_movable",
1341 .data = &hugepages_treat_as_movable,
1342 .maxlen = sizeof(int),
1343 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001344 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001345 },
Adam Litke54f9f802007-10-16 01:26:20 -07001346 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001347 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001348 .data = NULL,
1349 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001350 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001351 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001352 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353#endif
1354 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 .procname = "lowmem_reserve_ratio",
1356 .data = &sysctl_lowmem_reserve_ratio,
1357 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1358 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001359 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 },
1361 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001362 .procname = "drop_caches",
1363 .data = &sysctl_drop_caches,
1364 .maxlen = sizeof(int),
1365 .mode = 0644,
1366 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001367 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001368 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001369 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001370#ifdef CONFIG_COMPACTION
1371 {
1372 .procname = "compact_memory",
1373 .data = &sysctl_compact_memory,
1374 .maxlen = sizeof(int),
1375 .mode = 0200,
1376 .proc_handler = sysctl_compaction_handler,
1377 },
Mel Gorman5e771902010-05-24 14:32:31 -07001378 {
1379 .procname = "extfrag_threshold",
1380 .data = &sysctl_extfrag_threshold,
1381 .maxlen = sizeof(int),
1382 .mode = 0644,
1383 .proc_handler = sysctl_extfrag_handler,
1384 .extra1 = &min_extfrag_threshold,
1385 .extra2 = &max_extfrag_threshold,
1386 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001387 {
1388 .procname = "compact_unevictable_allowed",
1389 .data = &sysctl_compact_unevictable_allowed,
1390 .maxlen = sizeof(int),
1391 .mode = 0644,
1392 .proc_handler = proc_dointvec,
1393 .extra1 = &zero,
1394 .extra2 = &one,
1395 },
Mel Gorman5e771902010-05-24 14:32:31 -07001396
Mel Gorman76ab0f52010-05-24 14:32:28 -07001397#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "min_free_kbytes",
1400 .data = &min_free_kbytes,
1401 .maxlen = sizeof(min_free_kbytes),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 .extra1 = &zero,
1405 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001406 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001407 .procname = "percpu_pagelist_fraction",
1408 .data = &percpu_pagelist_fraction,
1409 .maxlen = sizeof(percpu_pagelist_fraction),
1410 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001411 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001412 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001413 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414#ifdef CONFIG_MMU
1415 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 .procname = "max_map_count",
1417 .data = &sysctl_max_map_count,
1418 .maxlen = sizeof(sysctl_max_map_count),
1419 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001420 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001421 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001423#else
1424 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001425 .procname = "nr_trim_pages",
1426 .data = &sysctl_nr_trim_pages,
1427 .maxlen = sizeof(sysctl_nr_trim_pages),
1428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001429 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001430 .extra1 = &zero,
1431 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432#endif
1433 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 .procname = "laptop_mode",
1435 .data = &laptop_mode,
1436 .maxlen = sizeof(laptop_mode),
1437 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001438 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 },
1440 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 .procname = "block_dump",
1442 .data = &block_dump,
1443 .maxlen = sizeof(block_dump),
1444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001445 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 .extra1 = &zero,
1447 },
1448 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 .procname = "vfs_cache_pressure",
1450 .data = &sysctl_vfs_cache_pressure,
1451 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1452 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001453 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 .extra1 = &zero,
1455 },
1456#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1457 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 .procname = "legacy_va_layout",
1459 .data = &sysctl_legacy_va_layout,
1460 .maxlen = sizeof(sysctl_legacy_va_layout),
1461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001462 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 .extra1 = &zero,
1464 },
1465#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001466#ifdef CONFIG_NUMA
1467 {
Christoph Lameter17436602006-01-18 17:42:32 -08001468 .procname = "zone_reclaim_mode",
1469 .data = &zone_reclaim_mode,
1470 .maxlen = sizeof(zone_reclaim_mode),
1471 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001472 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001473 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001474 },
Christoph Lameter96146342006-07-03 00:24:13 -07001475 {
Christoph Lameter96146342006-07-03 00:24:13 -07001476 .procname = "min_unmapped_ratio",
1477 .data = &sysctl_min_unmapped_ratio,
1478 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001480 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001481 .extra1 = &zero,
1482 .extra2 = &one_hundred,
1483 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001484 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001485 .procname = "min_slab_ratio",
1486 .data = &sysctl_min_slab_ratio,
1487 .maxlen = sizeof(sysctl_min_slab_ratio),
1488 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001489 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001490 .extra1 = &zero,
1491 .extra2 = &one_hundred,
1492 },
Christoph Lameter17436602006-01-18 17:42:32 -08001493#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001494#ifdef CONFIG_SMP
1495 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001496 .procname = "stat_interval",
1497 .data = &sysctl_stat_interval,
1498 .maxlen = sizeof(sysctl_stat_interval),
1499 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001500 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001501 },
1502#endif
David Howells6e141542009-12-15 19:27:45 +00001503#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001504 {
Eric Parised032182007-06-28 15:55:21 -04001505 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001506 .data = &dac_mmap_min_addr,
1507 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001508 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001509 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001510 },
David Howells6e141542009-12-15 19:27:45 +00001511#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001512#ifdef CONFIG_NUMA
1513 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001514 .procname = "numa_zonelist_order",
1515 .data = &numa_zonelist_order,
1516 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001518 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001519 },
1520#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001521#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001522 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001523 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001524 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001525#ifdef CONFIG_X86_32
1526 .data = &vdso32_enabled,
1527 .maxlen = sizeof(vdso32_enabled),
1528#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001529 .data = &vdso_enabled,
1530 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001531#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001533 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001534 .extra1 = &zero,
1535 },
1536#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001537#ifdef CONFIG_HIGHMEM
1538 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001539 .procname = "highmem_is_dirtyable",
1540 .data = &vm_highmem_is_dirtyable,
1541 .maxlen = sizeof(vm_highmem_is_dirtyable),
1542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001543 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001544 .extra1 = &zero,
1545 .extra2 = &one,
1546 },
1547#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001548#ifdef CONFIG_MEMORY_FAILURE
1549 {
Andi Kleen6a460792009-09-16 11:50:15 +02001550 .procname = "memory_failure_early_kill",
1551 .data = &sysctl_memory_failure_early_kill,
1552 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1553 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001554 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001555 .extra1 = &zero,
1556 .extra2 = &one,
1557 },
1558 {
Andi Kleen6a460792009-09-16 11:50:15 +02001559 .procname = "memory_failure_recovery",
1560 .data = &sysctl_memory_failure_recovery,
1561 .maxlen = sizeof(sysctl_memory_failure_recovery),
1562 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001563 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001564 .extra1 = &zero,
1565 .extra2 = &one,
1566 },
1567#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001568 {
1569 .procname = "user_reserve_kbytes",
1570 .data = &sysctl_user_reserve_kbytes,
1571 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1572 .mode = 0644,
1573 .proc_handler = proc_doulongvec_minmax,
1574 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001575 {
1576 .procname = "admin_reserve_kbytes",
1577 .data = &sysctl_admin_reserve_kbytes,
1578 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1579 .mode = 0644,
1580 .proc_handler = proc_doulongvec_minmax,
1581 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001582#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1583 {
1584 .procname = "mmap_rnd_bits",
1585 .data = &mmap_rnd_bits,
1586 .maxlen = sizeof(mmap_rnd_bits),
1587 .mode = 0600,
1588 .proc_handler = proc_dointvec_minmax,
1589 .extra1 = (void *)&mmap_rnd_bits_min,
1590 .extra2 = (void *)&mmap_rnd_bits_max,
1591 },
1592#endif
1593#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1594 {
1595 .procname = "mmap_rnd_compat_bits",
1596 .data = &mmap_rnd_compat_bits,
1597 .maxlen = sizeof(mmap_rnd_compat_bits),
1598 .mode = 0600,
1599 .proc_handler = proc_dointvec_minmax,
1600 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1601 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1602 },
1603#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001604 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605};
1606
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001607static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 .procname = "inode-nr",
1610 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001611 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001613 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 },
1615 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 .procname = "inode-state",
1617 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001618 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001620 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 },
1622 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 .procname = "file-nr",
1624 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001625 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001627 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 },
1629 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 .procname = "file-max",
1631 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001632 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001634 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 },
1636 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001637 .procname = "nr_open",
1638 .data = &sysctl_nr_open,
1639 .maxlen = sizeof(int),
1640 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001641 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001642 .extra1 = &sysctl_nr_open_min,
1643 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001644 },
1645 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 .procname = "dentry-state",
1647 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001648 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001650 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 },
1652 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 .procname = "overflowuid",
1654 .data = &fs_overflowuid,
1655 .maxlen = sizeof(int),
1656 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001657 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 .extra1 = &minolduid,
1659 .extra2 = &maxolduid,
1660 },
1661 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 .procname = "overflowgid",
1663 .data = &fs_overflowgid,
1664 .maxlen = sizeof(int),
1665 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001666 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 .extra1 = &minolduid,
1668 .extra2 = &maxolduid,
1669 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001670#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 .procname = "leases-enable",
1673 .data = &leases_enable,
1674 .maxlen = sizeof(int),
1675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001676 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001678#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679#ifdef CONFIG_DNOTIFY
1680 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 .procname = "dir-notify-enable",
1682 .data = &dir_notify_enable,
1683 .maxlen = sizeof(int),
1684 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001685 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 },
1687#endif
1688#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001689#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 .procname = "lease-break-time",
1692 .data = &lease_break_time,
1693 .maxlen = sizeof(int),
1694 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001695 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001697#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001698#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 .procname = "aio-nr",
1701 .data = &aio_nr,
1702 .maxlen = sizeof(aio_nr),
1703 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001704 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 },
1706 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 .procname = "aio-max-nr",
1708 .data = &aio_max_nr,
1709 .maxlen = sizeof(aio_max_nr),
1710 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001711 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001713#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001714#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001715 {
Robert Love0399cb02005-07-13 12:38:18 -04001716 .procname = "inotify",
1717 .mode = 0555,
1718 .child = inotify_table,
1719 },
1720#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001721#ifdef CONFIG_EPOLL
1722 {
1723 .procname = "epoll",
1724 .mode = 0555,
1725 .child = epoll_table,
1726 },
1727#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001729 {
Kees Cook800179c2012-07-25 17:29:07 -07001730 .procname = "protected_symlinks",
1731 .data = &sysctl_protected_symlinks,
1732 .maxlen = sizeof(int),
1733 .mode = 0600,
1734 .proc_handler = proc_dointvec_minmax,
1735 .extra1 = &zero,
1736 .extra2 = &one,
1737 },
1738 {
1739 .procname = "protected_hardlinks",
1740 .data = &sysctl_protected_hardlinks,
1741 .maxlen = sizeof(int),
1742 .mode = 0600,
1743 .proc_handler = proc_dointvec_minmax,
1744 .extra1 = &zero,
1745 .extra2 = &one,
1746 },
1747 {
Alan Coxd6e71142005-06-23 00:09:43 -07001748 .procname = "suid_dumpable",
1749 .data = &suid_dumpable,
1750 .maxlen = sizeof(int),
1751 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001752 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001753 .extra1 = &zero,
1754 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001755 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001756#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1757 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001758 .procname = "binfmt_misc",
1759 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001760 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001761 },
1762#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001763 {
Jens Axboeff9da692010-06-03 14:54:39 +02001764 .procname = "pipe-max-size",
1765 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001766 .maxlen = sizeof(int),
1767 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001768 .proc_handler = &pipe_proc_fn,
1769 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001770 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001771 {
1772 .procname = "pipe-user-pages-hard",
1773 .data = &pipe_user_pages_hard,
1774 .maxlen = sizeof(pipe_user_pages_hard),
1775 .mode = 0644,
1776 .proc_handler = proc_doulongvec_minmax,
1777 },
1778 {
1779 .procname = "pipe-user-pages-soft",
1780 .data = &pipe_user_pages_soft,
1781 .maxlen = sizeof(pipe_user_pages_soft),
1782 .mode = 0644,
1783 .proc_handler = proc_doulongvec_minmax,
1784 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001785 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786};
1787
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001788static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001789#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001790 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001791 .procname = "exception-trace",
1792 .data = &show_unhandled_signals,
1793 .maxlen = sizeof(int),
1794 .mode = 0644,
1795 .proc_handler = proc_dointvec
1796 },
1797#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001798#if defined(CONFIG_OPTPROBES)
1799 {
1800 .procname = "kprobes-optimization",
1801 .data = &sysctl_kprobes_optimization,
1802 .maxlen = sizeof(int),
1803 .mode = 0644,
1804 .proc_handler = proc_kprobes_optimization_handler,
1805 .extra1 = &zero,
1806 .extra2 = &one,
1807 },
1808#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001809 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810};
1811
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001812static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001813 { }
Robert Love0eeca282005-07-12 17:06:03 -04001814};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001816int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001817{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001818 struct ctl_table_header *hdr;
1819
1820 hdr = register_sysctl_table(sysctl_base_table);
1821 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001822 return 0;
1823}
1824
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001825#endif /* CONFIG_SYSCTL */
1826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827/*
1828 * /proc/sys support
1829 */
1830
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001831#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Kees Cookf8808302014-06-06 14:37:17 -07001833static int _proc_do_string(char *data, int maxlen, int write,
1834 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001835 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001836{
1837 size_t len;
1838 char __user *p;
1839 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001840
1841 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001842 *lenp = 0;
1843 return 0;
1844 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001845
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001846 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001847 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1848 /* Only continue writes not past the end of buffer. */
1849 len = strlen(data);
1850 if (len > maxlen - 1)
1851 len = maxlen - 1;
1852
1853 if (*ppos > len)
1854 return 0;
1855 len = *ppos;
1856 } else {
1857 /* Start writing from beginning of buffer. */
1858 len = 0;
1859 }
1860
Kees Cook2ca9bb42014-06-06 14:37:18 -07001861 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001862 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001863 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001864 if (get_user(c, p++))
1865 return -EFAULT;
1866 if (c == 0 || c == '\n')
1867 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001868 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001869 }
Kees Cookf8808302014-06-06 14:37:17 -07001870 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001871 } else {
1872 len = strlen(data);
1873 if (len > maxlen)
1874 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001875
1876 if (*ppos > len) {
1877 *lenp = 0;
1878 return 0;
1879 }
1880
1881 data += *ppos;
1882 len -= *ppos;
1883
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001884 if (len > *lenp)
1885 len = *lenp;
1886 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001887 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001888 return -EFAULT;
1889 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001890 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001891 return -EFAULT;
1892 len++;
1893 }
1894 *lenp = len;
1895 *ppos += len;
1896 }
1897 return 0;
1898}
1899
Kees Cookf4aacea2014-06-06 14:37:19 -07001900static void warn_sysctl_write(struct ctl_table *table)
1901{
1902 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1903 "This will not be supported in the future. To silence this\n"
1904 "warning, set kernel.sysctl_writes_strict = -1\n",
1905 current->comm, table->procname);
1906}
1907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908/**
1909 * proc_dostring - read a string sysctl
1910 * @table: the sysctl table
1911 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 * @buffer: the user buffer
1913 * @lenp: the size of the user buffer
1914 * @ppos: file position
1915 *
1916 * Reads/writes a string from/to the user buffer. If the kernel
1917 * buffer provided is not large enough to hold the string, the
1918 * string is truncated. The copied string is %NULL-terminated.
1919 * If the string is being read by the user process, it is copied
1920 * and a newline '\n' is added. It is truncated if the buffer is
1921 * not large enough.
1922 *
1923 * Returns 0 on success.
1924 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001925int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 void __user *buffer, size_t *lenp, loff_t *ppos)
1927{
Kees Cookf4aacea2014-06-06 14:37:19 -07001928 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1929 warn_sysctl_write(table);
1930
Kees Cookf8808302014-06-06 14:37:17 -07001931 return _proc_do_string((char *)(table->data), table->maxlen, write,
1932 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
Amerigo Wang00b7c332010-05-05 00:26:45 +00001935static size_t proc_skip_spaces(char **buf)
1936{
1937 size_t ret;
1938 char *tmp = skip_spaces(*buf);
1939 ret = tmp - *buf;
1940 *buf = tmp;
1941 return ret;
1942}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001944static void proc_skip_char(char **buf, size_t *size, const char v)
1945{
1946 while (*size) {
1947 if (**buf != v)
1948 break;
1949 (*size)--;
1950 (*buf)++;
1951 }
1952}
1953
Amerigo Wang00b7c332010-05-05 00:26:45 +00001954#define TMPBUFLEN 22
1955/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001956 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001957 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001958 * @buf: a kernel buffer
1959 * @size: size of the kernel buffer
1960 * @val: this is where the number will be stored
1961 * @neg: set to %TRUE if number is negative
1962 * @perm_tr: a vector which contains the allowed trailers
1963 * @perm_tr_len: size of the perm_tr vector
1964 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001965 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001966 * In case of success %0 is returned and @buf and @size are updated with
1967 * the amount of bytes read. If @tr is non-NULL and a trailing
1968 * character exists (size is non-zero after returning from this
1969 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001970 */
1971static int proc_get_long(char **buf, size_t *size,
1972 unsigned long *val, bool *neg,
1973 const char *perm_tr, unsigned perm_tr_len, char *tr)
1974{
1975 int len;
1976 char *p, tmp[TMPBUFLEN];
1977
1978 if (!*size)
1979 return -EINVAL;
1980
1981 len = *size;
1982 if (len > TMPBUFLEN - 1)
1983 len = TMPBUFLEN - 1;
1984
1985 memcpy(tmp, *buf, len);
1986
1987 tmp[len] = 0;
1988 p = tmp;
1989 if (*p == '-' && *size > 1) {
1990 *neg = true;
1991 p++;
1992 } else
1993 *neg = false;
1994 if (!isdigit(*p))
1995 return -EINVAL;
1996
1997 *val = simple_strtoul(p, &p, 0);
1998
1999 len = p - tmp;
2000
2001 /* We don't know if the next char is whitespace thus we may accept
2002 * invalid integers (e.g. 1234...a) or two integers instead of one
2003 * (e.g. 123...1). So lets not allow such large numbers. */
2004 if (len == TMPBUFLEN - 1)
2005 return -EINVAL;
2006
2007 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2008 return -EINVAL;
2009
2010 if (tr && (len < *size))
2011 *tr = *p;
2012
2013 *buf += len;
2014 *size -= len;
2015
2016 return 0;
2017}
2018
2019/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002020 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002021 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002022 * @buf: the user buffer
2023 * @size: the size of the user buffer
2024 * @val: the integer to be converted
2025 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002026 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002027 * In case of success %0 is returned and @buf and @size are updated with
2028 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002029 */
2030static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2031 bool neg)
2032{
2033 int len;
2034 char tmp[TMPBUFLEN], *p = tmp;
2035
2036 sprintf(p, "%s%lu", neg ? "-" : "", val);
2037 len = strlen(tmp);
2038 if (len > *size)
2039 len = *size;
2040 if (copy_to_user(*buf, tmp, len))
2041 return -EFAULT;
2042 *size -= len;
2043 *buf += len;
2044 return 0;
2045}
2046#undef TMPBUFLEN
2047
2048static int proc_put_char(void __user **buf, size_t *size, char c)
2049{
2050 if (*size) {
2051 char __user **buffer = (char __user **)buf;
2052 if (put_user(c, *buffer))
2053 return -EFAULT;
2054 (*size)--, (*buffer)++;
2055 *buf = *buffer;
2056 }
2057 return 0;
2058}
2059
2060static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 int *valp,
2062 int write, void *data)
2063{
2064 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002065 if (*negp) {
2066 if (*lvalp > (unsigned long) INT_MAX + 1)
2067 return -EINVAL;
2068 *valp = -*lvalp;
2069 } else {
2070 if (*lvalp > (unsigned long) INT_MAX)
2071 return -EINVAL;
2072 *valp = *lvalp;
2073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 } else {
2075 int val = *valp;
2076 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002077 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002078 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002080 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 *lvalp = (unsigned long)val;
2082 }
2083 }
2084 return 0;
2085}
2086
Amerigo Wang00b7c332010-05-05 00:26:45 +00002087static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2088
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002089static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002090 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002091 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002092 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 int write, void *data),
2094 void *data)
2095{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002096 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002097 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002098 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Amerigo Wang00b7c332010-05-05 00:26:45 +00002100 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 *lenp = 0;
2102 return 0;
2103 }
2104
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002105 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 vleft = table->maxlen / sizeof(*i);
2107 left = *lenp;
2108
2109 if (!conv)
2110 conv = do_proc_dointvec_conv;
2111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002113 if (*ppos) {
2114 switch (sysctl_writes_strict) {
2115 case SYSCTL_WRITES_STRICT:
2116 goto out;
2117 case SYSCTL_WRITES_WARN:
2118 warn_sysctl_write(table);
2119 break;
2120 default:
2121 break;
2122 }
2123 }
2124
Amerigo Wang00b7c332010-05-05 00:26:45 +00002125 if (left > PAGE_SIZE - 1)
2126 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002127 p = kbuf = memdup_user_nul(buffer, left);
2128 if (IS_ERR(kbuf))
2129 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002130 }
2131
2132 for (; left && vleft--; i++, first=0) {
2133 unsigned long lval;
2134 bool neg;
2135
2136 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002137 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002138
J. R. Okajima563b0462010-05-25 16:10:14 -07002139 if (!left)
2140 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002141 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002142 proc_wspace_sep,
2143 sizeof(proc_wspace_sep), NULL);
2144 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002146 if (conv(&neg, &lval, i, 1, data)) {
2147 err = -EINVAL;
2148 break;
2149 }
2150 } else {
2151 if (conv(&neg, &lval, i, 0, data)) {
2152 err = -EINVAL;
2153 break;
2154 }
2155 if (!first)
2156 err = proc_put_char(&buffer, &left, '\t');
2157 if (err)
2158 break;
2159 err = proc_put_long(&buffer, &left, lval, neg);
2160 if (err)
2161 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 }
2163 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002164
2165 if (!write && !first && left && !err)
2166 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002167 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002168 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002169 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002170 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002171 if (first)
2172 return err ? : -EINVAL;
2173 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002175out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002177 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178}
2179
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002180static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002181 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002182 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002183 int write, void *data),
2184 void *data)
2185{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002186 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002187 buffer, lenp, ppos, conv, data);
2188}
2189
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190/**
2191 * proc_dointvec - read a vector of integers
2192 * @table: the sysctl table
2193 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 * @buffer: the user buffer
2195 * @lenp: the size of the user buffer
2196 * @ppos: file position
2197 *
2198 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2199 * values from/to the user buffer, treated as an ASCII string.
2200 *
2201 * Returns 0 on success.
2202 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002203int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 void __user *buffer, size_t *lenp, loff_t *ppos)
2205{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002206 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 NULL,NULL);
2208}
2209
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002210/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002211 * Taint values can only be increased
2212 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002213 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002214static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002215 void __user *buffer, size_t *lenp, loff_t *ppos)
2216{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002217 struct ctl_table t;
2218 unsigned long tmptaint = get_taint();
2219 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002220
Bastian Blank91fcd412007-04-23 14:41:14 -07002221 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002222 return -EPERM;
2223
Andi Kleen25ddbb12008-10-15 22:01:41 -07002224 t = *table;
2225 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002226 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002227 if (err < 0)
2228 return err;
2229
2230 if (write) {
2231 /*
2232 * Poor man's atomic or. Not worth adding a primitive
2233 * to everyone's atomic.h for this
2234 */
2235 int i;
2236 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2237 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302238 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002239 }
2240 }
2241
2242 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002243}
2244
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002245#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002246static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002247 void __user *buffer, size_t *lenp, loff_t *ppos)
2248{
2249 if (write && !capable(CAP_SYS_ADMIN))
2250 return -EPERM;
2251
2252 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2253}
2254#endif
2255
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256struct do_proc_dointvec_minmax_conv_param {
2257 int *min;
2258 int *max;
2259};
2260
Amerigo Wang00b7c332010-05-05 00:26:45 +00002261static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2262 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 int write, void *data)
2264{
2265 struct do_proc_dointvec_minmax_conv_param *param = data;
2266 if (write) {
2267 int val = *negp ? -*lvalp : *lvalp;
2268 if ((param->min && *param->min > val) ||
2269 (param->max && *param->max < val))
2270 return -EINVAL;
2271 *valp = val;
2272 } else {
2273 int val = *valp;
2274 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002275 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002276 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002278 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 *lvalp = (unsigned long)val;
2280 }
2281 }
2282 return 0;
2283}
2284
2285/**
2286 * proc_dointvec_minmax - read a vector of integers with min/max values
2287 * @table: the sysctl table
2288 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 * @buffer: the user buffer
2290 * @lenp: the size of the user buffer
2291 * @ppos: file position
2292 *
2293 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2294 * values from/to the user buffer, treated as an ASCII string.
2295 *
2296 * This routine will ensure the values are within the range specified by
2297 * table->extra1 (min) and table->extra2 (max).
2298 *
2299 * Returns 0 on success.
2300 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002301int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 void __user *buffer, size_t *lenp, loff_t *ppos)
2303{
2304 struct do_proc_dointvec_minmax_conv_param param = {
2305 .min = (int *) table->extra1,
2306 .max = (int *) table->extra2,
2307 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002308 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 do_proc_dointvec_minmax_conv, &param);
2310}
2311
Kees Cook54b50192012-07-30 14:39:18 -07002312static void validate_coredump_safety(void)
2313{
Alex Kelly046d6622012-10-04 17:15:23 -07002314#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002315 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002316 core_pattern[0] != '/' && core_pattern[0] != '|') {
2317 printk(KERN_WARNING "Unsafe core_pattern used with "\
2318 "suid_dumpable=2. Pipe handler or fully qualified "\
2319 "core dump path required.\n");
2320 }
Alex Kelly046d6622012-10-04 17:15:23 -07002321#endif
Kees Cook54b50192012-07-30 14:39:18 -07002322}
2323
2324static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2325 void __user *buffer, size_t *lenp, loff_t *ppos)
2326{
2327 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2328 if (!error)
2329 validate_coredump_safety();
2330 return error;
2331}
2332
Alex Kelly046d6622012-10-04 17:15:23 -07002333#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002334static int proc_dostring_coredump(struct ctl_table *table, int write,
2335 void __user *buffer, size_t *lenp, loff_t *ppos)
2336{
2337 int error = proc_dostring(table, write, buffer, lenp, ppos);
2338 if (!error)
2339 validate_coredump_safety();
2340 return error;
2341}
Alex Kelly046d6622012-10-04 17:15:23 -07002342#endif
Kees Cook54b50192012-07-30 14:39:18 -07002343
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002344static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 void __user *buffer,
2346 size_t *lenp, loff_t *ppos,
2347 unsigned long convmul,
2348 unsigned long convdiv)
2349{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002350 unsigned long *i, *min, *max;
2351 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002352 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002353 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002354
2355 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 *lenp = 0;
2357 return 0;
2358 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002359
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002360 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 min = (unsigned long *) table->extra1;
2362 max = (unsigned long *) table->extra2;
2363 vleft = table->maxlen / sizeof(unsigned long);
2364 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002365
2366 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002367 if (*ppos) {
2368 switch (sysctl_writes_strict) {
2369 case SYSCTL_WRITES_STRICT:
2370 goto out;
2371 case SYSCTL_WRITES_WARN:
2372 warn_sysctl_write(table);
2373 break;
2374 default:
2375 break;
2376 }
2377 }
2378
Amerigo Wang00b7c332010-05-05 00:26:45 +00002379 if (left > PAGE_SIZE - 1)
2380 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002381 p = kbuf = memdup_user_nul(buffer, left);
2382 if (IS_ERR(kbuf))
2383 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002384 }
2385
Eric Dumazet27b3d802010-10-07 12:59:29 -07002386 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002387 unsigned long val;
2388
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002390 bool neg;
2391
Al Viro70f6cbb2015-12-24 00:13:10 -05002392 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002393
Al Viro70f6cbb2015-12-24 00:13:10 -05002394 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002395 proc_wspace_sep,
2396 sizeof(proc_wspace_sep), NULL);
2397 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 break;
2399 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 continue;
2401 if ((min && val < *min) || (max && val > *max))
2402 continue;
2403 *i = val;
2404 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002405 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002406 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002407 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002408 if (err)
2409 break;
2410 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002411 err = proc_put_long(&buffer, &left, val, false);
2412 if (err)
2413 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 }
2415 }
2416
Amerigo Wang00b7c332010-05-05 00:26:45 +00002417 if (!write && !first && left && !err)
2418 err = proc_put_char(&buffer, &left, '\n');
2419 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002420 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002422 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002423 if (first)
2424 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002427out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002429 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430}
2431
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002432static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002433 void __user *buffer,
2434 size_t *lenp, loff_t *ppos,
2435 unsigned long convmul,
2436 unsigned long convdiv)
2437{
2438 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002439 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002440}
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442/**
2443 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2444 * @table: the sysctl table
2445 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2449 *
2450 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2451 * values from/to the user buffer, treated as an ASCII string.
2452 *
2453 * This routine will ensure the values are within the range specified by
2454 * table->extra1 (min) and table->extra2 (max).
2455 *
2456 * Returns 0 on success.
2457 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002458int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 void __user *buffer, size_t *lenp, loff_t *ppos)
2460{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002461 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
2464/**
2465 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2466 * @table: the sysctl table
2467 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 * @buffer: the user buffer
2469 * @lenp: the size of the user buffer
2470 * @ppos: file position
2471 *
2472 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2473 * values from/to the user buffer, treated as an ASCII string. The values
2474 * are treated as milliseconds, and converted to jiffies when they are stored.
2475 *
2476 * This routine will ensure the values are within the range specified by
2477 * table->extra1 (min) and table->extra2 (max).
2478 *
2479 * Returns 0 on success.
2480 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002481int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 void __user *buffer,
2483 size_t *lenp, loff_t *ppos)
2484{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002485 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 lenp, ppos, HZ, 1000l);
2487}
2488
2489
Amerigo Wang00b7c332010-05-05 00:26:45 +00002490static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 int *valp,
2492 int write, void *data)
2493{
2494 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002495 if (*lvalp > LONG_MAX / HZ)
2496 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2498 } else {
2499 int val = *valp;
2500 unsigned long lval;
2501 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002502 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002503 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002505 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 lval = (unsigned long)val;
2507 }
2508 *lvalp = lval / HZ;
2509 }
2510 return 0;
2511}
2512
Amerigo Wang00b7c332010-05-05 00:26:45 +00002513static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 int *valp,
2515 int write, void *data)
2516{
2517 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002518 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2519 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2521 } else {
2522 int val = *valp;
2523 unsigned long lval;
2524 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002525 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002526 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002528 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 lval = (unsigned long)val;
2530 }
2531 *lvalp = jiffies_to_clock_t(lval);
2532 }
2533 return 0;
2534}
2535
Amerigo Wang00b7c332010-05-05 00:26:45 +00002536static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 int *valp,
2538 int write, void *data)
2539{
2540 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002541 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2542
2543 if (jif > INT_MAX)
2544 return 1;
2545 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 } else {
2547 int val = *valp;
2548 unsigned long lval;
2549 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002550 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002551 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002553 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 lval = (unsigned long)val;
2555 }
2556 *lvalp = jiffies_to_msecs(lval);
2557 }
2558 return 0;
2559}
2560
2561/**
2562 * proc_dointvec_jiffies - read a vector of integers as seconds
2563 * @table: the sysctl table
2564 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 * @buffer: the user buffer
2566 * @lenp: the size of the user buffer
2567 * @ppos: file position
2568 *
2569 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2570 * values from/to the user buffer, treated as an ASCII string.
2571 * The values read are assumed to be in seconds, and are converted into
2572 * jiffies.
2573 *
2574 * Returns 0 on success.
2575 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002576int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 void __user *buffer, size_t *lenp, loff_t *ppos)
2578{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002579 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 do_proc_dointvec_jiffies_conv,NULL);
2581}
2582
2583/**
2584 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2585 * @table: the sysctl table
2586 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 * @buffer: the user buffer
2588 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002589 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 *
2591 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2592 * values from/to the user buffer, treated as an ASCII string.
2593 * The values read are assumed to be in 1/USER_HZ seconds, and
2594 * are converted into jiffies.
2595 *
2596 * Returns 0 on success.
2597 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002598int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 void __user *buffer, size_t *lenp, loff_t *ppos)
2600{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002601 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 do_proc_dointvec_userhz_jiffies_conv,NULL);
2603}
2604
2605/**
2606 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2607 * @table: the sysctl table
2608 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 * @buffer: the user buffer
2610 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002611 * @ppos: file position
2612 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 *
2614 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2615 * values from/to the user buffer, treated as an ASCII string.
2616 * The values read are assumed to be in 1/1000 seconds, and
2617 * are converted into jiffies.
2618 *
2619 * Returns 0 on success.
2620 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002621int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 void __user *buffer, size_t *lenp, loff_t *ppos)
2623{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002624 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 do_proc_dointvec_ms_jiffies_conv, NULL);
2626}
2627
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002628static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002629 void __user *buffer, size_t *lenp, loff_t *ppos)
2630{
2631 struct pid *new_pid;
2632 pid_t tmp;
2633 int r;
2634
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002635 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002636
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002637 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002638 lenp, ppos, NULL, NULL);
2639 if (r || !write)
2640 return r;
2641
2642 new_pid = find_get_pid(tmp);
2643 if (!new_pid)
2644 return -ESRCH;
2645
2646 put_pid(xchg(&cad_pid, new_pid));
2647 return 0;
2648}
2649
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002650/**
2651 * proc_do_large_bitmap - read/write from/to a large bitmap
2652 * @table: the sysctl table
2653 * @write: %TRUE if this is a write to the sysctl file
2654 * @buffer: the user buffer
2655 * @lenp: the size of the user buffer
2656 * @ppos: file position
2657 *
2658 * The bitmap is stored at table->data and the bitmap length (in bits)
2659 * in table->maxlen.
2660 *
2661 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2662 * large bitmaps may be represented in a compact manner. Writing into
2663 * the file will clear the bitmap then update it with the given input.
2664 *
2665 * Returns 0 on success.
2666 */
2667int proc_do_large_bitmap(struct ctl_table *table, int write,
2668 void __user *buffer, size_t *lenp, loff_t *ppos)
2669{
2670 int err = 0;
2671 bool first = 1;
2672 size_t left = *lenp;
2673 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002674 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002675 unsigned long *tmp_bitmap = NULL;
2676 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2677
WANG Cong122ff242014-05-12 16:04:53 -07002678 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002679 *lenp = 0;
2680 return 0;
2681 }
2682
2683 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002684 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002685
2686 if (left > PAGE_SIZE - 1)
2687 left = PAGE_SIZE - 1;
2688
Al Viro70f6cbb2015-12-24 00:13:10 -05002689 p = kbuf = memdup_user_nul(buffer, left);
2690 if (IS_ERR(kbuf))
2691 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002692
2693 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2694 GFP_KERNEL);
2695 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002696 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002697 return -ENOMEM;
2698 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002699 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002700 while (!err && left) {
2701 unsigned long val_a, val_b;
2702 bool neg;
2703
Al Viro70f6cbb2015-12-24 00:13:10 -05002704 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002705 sizeof(tr_a), &c);
2706 if (err)
2707 break;
2708 if (val_a >= bitmap_len || neg) {
2709 err = -EINVAL;
2710 break;
2711 }
2712
2713 val_b = val_a;
2714 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002715 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002716 left--;
2717 }
2718
2719 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05002720 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002721 &neg, tr_b, sizeof(tr_b),
2722 &c);
2723 if (err)
2724 break;
2725 if (val_b >= bitmap_len || neg ||
2726 val_a > val_b) {
2727 err = -EINVAL;
2728 break;
2729 }
2730 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002731 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002732 left--;
2733 }
2734 }
2735
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002736 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002737 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05002738 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002739 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002740 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002741 } else {
2742 unsigned long bit_a, bit_b = 0;
2743
2744 while (left) {
2745 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2746 if (bit_a >= bitmap_len)
2747 break;
2748 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2749 bit_a + 1) - 1;
2750
2751 if (!first) {
2752 err = proc_put_char(&buffer, &left, ',');
2753 if (err)
2754 break;
2755 }
2756 err = proc_put_long(&buffer, &left, bit_a, false);
2757 if (err)
2758 break;
2759 if (bit_a != bit_b) {
2760 err = proc_put_char(&buffer, &left, '-');
2761 if (err)
2762 break;
2763 err = proc_put_long(&buffer, &left, bit_b, false);
2764 if (err)
2765 break;
2766 }
2767
2768 first = 0; bit_b++;
2769 }
2770 if (!err)
2771 err = proc_put_char(&buffer, &left, '\n');
2772 }
2773
2774 if (!err) {
2775 if (write) {
2776 if (*ppos)
2777 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2778 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002779 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002780 }
2781 kfree(tmp_bitmap);
2782 *lenp -= left;
2783 *ppos += *lenp;
2784 return 0;
2785 } else {
2786 kfree(tmp_bitmap);
2787 return err;
2788 }
2789}
2790
Jovi Zhang55610502011-01-12 17:00:45 -08002791#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002793int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 void __user *buffer, size_t *lenp, loff_t *ppos)
2795{
2796 return -ENOSYS;
2797}
2798
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002799int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 void __user *buffer, size_t *lenp, loff_t *ppos)
2801{
2802 return -ENOSYS;
2803}
2804
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002805int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 void __user *buffer, size_t *lenp, loff_t *ppos)
2807{
2808 return -ENOSYS;
2809}
2810
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002811int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 void __user *buffer, size_t *lenp, loff_t *ppos)
2813{
2814 return -ENOSYS;
2815}
2816
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002817int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 void __user *buffer, size_t *lenp, loff_t *ppos)
2819{
2820 return -ENOSYS;
2821}
2822
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002823int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 void __user *buffer, size_t *lenp, loff_t *ppos)
2825{
2826 return -ENOSYS;
2827}
2828
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002829int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 void __user *buffer, size_t *lenp, loff_t *ppos)
2831{
2832 return -ENOSYS;
2833}
2834
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002835int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 void __user *buffer,
2837 size_t *lenp, loff_t *ppos)
2838{
2839 return -ENOSYS;
2840}
2841
2842
Jovi Zhang55610502011-01-12 17:00:45 -08002843#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845/*
2846 * No sense putting this after each symbol definition, twice,
2847 * exception granted :-)
2848 */
2849EXPORT_SYMBOL(proc_dointvec);
2850EXPORT_SYMBOL(proc_dointvec_jiffies);
2851EXPORT_SYMBOL(proc_dointvec_minmax);
2852EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2853EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2854EXPORT_SYMBOL(proc_dostring);
2855EXPORT_SYMBOL(proc_doulongvec_minmax);
2856EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);