blob: 245e7dcc3741a59c051c4d0dad0ca953071d6991 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/mm.h>
23#include <linux/swap.h>
24#include <linux/slab.h>
25#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070026#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080027#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080028#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070030#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020032#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Kees Cook79847542014-01-23 15:55:59 -080065#include <linux/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include <asm/uaccess.h>
68#include <asm/processor.h>
69
Andi Kleen29cbc782006-09-30 01:47:55 +020070#ifdef CONFIG_X86
71#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010072#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010073#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020074#endif
David Howellsd550bbd2012-03-28 18:30:03 +010075#ifdef CONFIG_SPARC
76#include <asm/setup.h>
77#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080078#ifdef CONFIG_BSD_PROCESS_ACCT
79#include <linux/acct.h>
80#endif
Dave Young4f0e0562010-03-10 15:24:09 -080081#ifdef CONFIG_RT_MUTEXES
82#include <linux/rtmutex.h>
83#endif
Dave Young2edf5e42010-03-10 15:24:10 -080084#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
85#include <linux/lockdep.h>
86#endif
Dave Young15485a42010-03-10 15:24:07 -080087#ifdef CONFIG_CHR_DEV_SG
88#include <scsi/sg.h>
89#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020090
Don Zickus58687ac2010-05-07 17:11:44 -040091#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050092#include <linux/nmi.h>
93#endif
94
Eric W. Biederman7058cb02007-10-18 03:05:58 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#if defined(CONFIG_SYSCTL)
97
98/* External variables not in a header file. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070099extern int max_threads;
Alan Coxd6e71142005-06-23 00:09:43 -0700100extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700101#ifdef CONFIG_COREDUMP
102extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700104extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800108extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200109extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100110extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400111extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000112#ifndef CONFIG_MMU
113extern int sysctl_nr_trim_pages;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400117#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int sixty = 60;
119#endif
120
Aaron Tomlin270750db2014-01-20 17:34:13 +0000121static int __maybe_unused neg_one = -1;
122
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700123static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700124static int __maybe_unused one = 1;
125static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700126static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800127static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700128static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700129#ifdef CONFIG_PRINTK
130static int ten_thousand = 10000;
131#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700132
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700133/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
134static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
137static int maxolduid = 65535;
138static int minolduid;
139
140static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700141static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Liu Hua80df2842014-04-07 15:38:57 -0700143/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
144#ifdef CONFIG_DETECT_HUNG_TASK
145static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
146#endif
147
Dave Youngd14f1722010-02-25 20:28:57 -0500148#ifdef CONFIG_INOTIFY_USER
149#include <linux/inotify.h>
150#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700151#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#endif
153
154#ifdef __hppa__
155extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530156#endif
157
158#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159extern int unaligned_enabled;
160#endif
161
Jes Sorensend2b176e2006-02-28 09:42:23 -0800162#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800163extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800164#endif
165
Vineet Guptab6fca722013-01-09 20:06:28 +0530166#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
167extern int no_unaligned_warning;
168#endif
169
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700170#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700171
172#define SYSCTL_WRITES_LEGACY -1
173#define SYSCTL_WRITES_WARN 0
174#define SYSCTL_WRITES_STRICT 1
175
176static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
177
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700178static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700179 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700180static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800181 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700182#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700183
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700184#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700185static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700186 void __user *buffer, size_t *lenp, loff_t *ppos);
187#endif
188
Kees Cook54b50192012-07-30 14:39:18 -0700189static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
190 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700191#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700192static int proc_dostring_coredump(struct ctl_table *table, int write,
193 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700194#endif
Kees Cook54b50192012-07-30 14:39:18 -0700195
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700196#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800197/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100198static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700199
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700200static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700201 void __user *buffer, size_t *lenp,
202 loff_t *ppos)
203{
204 int error;
205
206 error = proc_dointvec(table, write, buffer, lenp, ppos);
207 if (error)
208 return error;
209
210 if (write)
211 sysrq_toggle_support(__sysrq_enabled);
212
213 return 0;
214}
215
216#endif
217
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700218static struct ctl_table kern_table[];
219static struct ctl_table vm_table[];
220static struct ctl_table fs_table[];
221static struct ctl_table debug_table[];
222static struct ctl_table dev_table[];
223extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800224#ifdef CONFIG_EPOLL
225extern struct ctl_table epoll_table[];
226#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
229int sysctl_legacy_va_layout;
230#endif
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232/* The default sysctl tables: */
233
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800234static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 .procname = "kernel",
237 .mode = 0555,
238 .child = kern_table,
239 },
240 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .procname = "vm",
242 .mode = 0555,
243 .child = vm_table,
244 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 .procname = "fs",
247 .mode = 0555,
248 .child = fs_table,
249 },
250 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 .procname = "debug",
252 .mode = 0555,
253 .child = debug_table,
254 },
255 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .procname = "dev",
257 .mode = 0555,
258 .child = dev_table,
259 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700260 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261};
262
Ingo Molnar77e54a12007-07-09 18:52:00 +0200263#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100264static int min_sched_granularity_ns = 100000; /* 100 usecs */
265static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
266static int min_wakeup_granularity_ns; /* 0 usecs */
267static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200268#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100269static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
270static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200271#endif /* CONFIG_SMP */
272#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200273
Mel Gorman5e771902010-05-24 14:32:31 -0700274#ifdef CONFIG_COMPACTION
275static int min_extfrag_threshold;
276static int max_extfrag_threshold = 1000;
277#endif
278
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700279static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200280 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200281 .procname = "sched_child_runs_first",
282 .data = &sysctl_sched_child_runs_first,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800285 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200286 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200287#ifdef CONFIG_SCHED_DEBUG
288 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100289 .procname = "sched_min_granularity_ns",
290 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800293 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200296 },
297 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200298 .procname = "sched_latency_ns",
299 .data = &sysctl_sched_latency,
300 .maxlen = sizeof(unsigned int),
301 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800302 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200303 .extra1 = &min_sched_granularity_ns,
304 .extra2 = &max_sched_granularity_ns,
305 },
306 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200307 .procname = "sched_wakeup_granularity_ns",
308 .data = &sysctl_sched_wakeup_granularity,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800311 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200312 .extra1 = &min_wakeup_granularity_ns,
313 .extra2 = &max_wakeup_granularity_ns,
314 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200315#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200316 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100317 .procname = "sched_tunable_scaling",
318 .data = &sysctl_sched_tunable_scaling,
319 .maxlen = sizeof(enum sched_tunable_scaling),
320 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800321 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100322 .extra1 = &min_sched_tunable_scaling,
323 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200324 },
325 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900326 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200327 .data = &sysctl_sched_migration_cost,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800330 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200331 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100332 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100333 .procname = "sched_nr_migrate",
334 .data = &sysctl_sched_nr_migrate,
335 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800337 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100338 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530339 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900340 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200341 .data = &sysctl_sched_time_avg,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800344 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200345 },
346 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900347 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800348 .data = &sysctl_sched_shares_window,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
351 .proc_handler = proc_dointvec,
352 },
353 {
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530354 .procname = "timer_migration",
355 .data = &sysctl_timer_migration,
356 .maxlen = sizeof(unsigned int),
357 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800358 .proc_handler = proc_dointvec_minmax,
Arun R Bharadwajbfdb4d92009-06-23 10:00:58 +0530359 .extra1 = &zero,
360 .extra2 = &one,
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530361 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200362#endif /* CONFIG_SMP */
363#ifdef CONFIG_NUMA_BALANCING
364 {
Peter Zijlstra4b96a29b2012-10-25 14:16:47 +0200365 .procname = "numa_balancing_scan_delay_ms",
366 .data = &sysctl_numa_balancing_scan_delay,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
369 .proc_handler = proc_dointvec,
370 },
371 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200372 .procname = "numa_balancing_scan_period_min_ms",
373 .data = &sysctl_numa_balancing_scan_period_min,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
376 .proc_handler = proc_dointvec,
377 },
378 {
379 .procname = "numa_balancing_scan_period_max_ms",
380 .data = &sysctl_numa_balancing_scan_period_max,
381 .maxlen = sizeof(unsigned int),
382 .mode = 0644,
383 .proc_handler = proc_dointvec,
384 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200385 {
386 .procname = "numa_balancing_scan_size_mb",
387 .data = &sysctl_numa_balancing_scan_size,
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400390 .proc_handler = proc_dointvec_minmax,
391 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200392 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100393 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800394 .procname = "numa_balancing",
395 .data = NULL, /* filled in by handler */
396 .maxlen = sizeof(unsigned int),
397 .mode = 0644,
398 .proc_handler = sysctl_numa_balancing,
399 .extra1 = &zero,
400 .extra2 = &one,
401 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200402#endif /* CONFIG_NUMA_BALANCING */
403#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200404 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100405 .procname = "sched_rt_period_us",
406 .data = &sysctl_sched_rt_period,
407 .maxlen = sizeof(unsigned int),
408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800409 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100410 },
411 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100412 .procname = "sched_rt_runtime_us",
413 .data = &sysctl_sched_rt_runtime,
414 .maxlen = sizeof(int),
415 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800416 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100417 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600418 {
419 .procname = "sched_rr_timeslice_ms",
420 .data = &sched_rr_timeslice,
421 .maxlen = sizeof(int),
422 .mode = 0644,
423 .proc_handler = sched_rr_handler,
424 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100425#ifdef CONFIG_SCHED_AUTOGROUP
426 {
427 .procname = "sched_autogroup_enabled",
428 .data = &sysctl_sched_autogroup_enabled,
429 .maxlen = sizeof(unsigned int),
430 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800431 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100432 .extra1 = &zero,
433 .extra2 = &one,
434 },
435#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700436#ifdef CONFIG_CFS_BANDWIDTH
437 {
438 .procname = "sched_cfs_bandwidth_slice_us",
439 .data = &sysctl_sched_cfs_bandwidth_slice,
440 .maxlen = sizeof(unsigned int),
441 .mode = 0644,
442 .proc_handler = proc_dointvec_minmax,
443 .extra1 = &one,
444 },
445#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700446#ifdef CONFIG_PROVE_LOCKING
447 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700448 .procname = "prove_locking",
449 .data = &prove_locking,
450 .maxlen = sizeof(int),
451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800452 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700453 },
454#endif
455#ifdef CONFIG_LOCK_STAT
456 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700457 .procname = "lock_stat",
458 .data = &lock_stat,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800461 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700462 },
463#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200464 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .procname = "panic",
466 .data = &panic_timeout,
467 .maxlen = sizeof(int),
468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800469 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 },
Alex Kelly046d6622012-10-04 17:15:23 -0700471#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 .procname = "core_uses_pid",
474 .data = &core_uses_pid,
475 .maxlen = sizeof(int),
476 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800477 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 },
479 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 .procname = "core_pattern",
481 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700482 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700484 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 },
Neil Hormana2939802009-09-23 15:56:56 -0700486 {
Neil Hormana2939802009-09-23 15:56:56 -0700487 .procname = "core_pipe_limit",
488 .data = &core_pipe_limit,
489 .maxlen = sizeof(unsigned int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700492 },
Alex Kelly046d6622012-10-04 17:15:23 -0700493#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800494#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700497 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800499 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700501 {
502 .procname = "sysctl_writes_strict",
503 .data = &sysctl_writes_strict,
504 .maxlen = sizeof(int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &neg_one,
508 .extra2 = &one,
509 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800510#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100511#ifdef CONFIG_LATENCYTOP
512 {
513 .procname = "latencytop",
514 .data = &latencytop_enabled,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800517 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100518 },
519#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520#ifdef CONFIG_BLK_DEV_INITRD
521 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .procname = "real-root-dev",
523 .data = &real_root_dev,
524 .maxlen = sizeof(int),
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
528#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700529 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700530 .procname = "print-fatal-signals",
531 .data = &print_fatal_signals,
532 .maxlen = sizeof(int),
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700535 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700536#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 .procname = "reboot-cmd",
539 .data = reboot_command,
540 .maxlen = 256,
541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800542 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 },
544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 .procname = "stop-a",
546 .data = &stop_a_enabled,
547 .maxlen = sizeof (int),
548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800549 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 },
551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 .procname = "scons-poweroff",
553 .data = &scons_pwroff,
554 .maxlen = sizeof (int),
555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 },
558#endif
David S. Miller08714202008-11-16 23:49:24 -0800559#ifdef CONFIG_SPARC64
560 {
David S. Miller08714202008-11-16 23:49:24 -0800561 .procname = "tsb-ratio",
562 .data = &sysctl_tsb_ratio,
563 .maxlen = sizeof (int),
564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800565 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800566 },
567#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568#ifdef __hppa__
569 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 .procname = "soft-power",
571 .data = &pwrsw_enabled,
572 .maxlen = sizeof (int),
573 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800574 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530576#endif
577#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "unaligned-trap",
580 .data = &unaligned_enabled,
581 .maxlen = sizeof (int),
582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800583 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
585#endif
586 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .procname = "ctrl-alt-del",
588 .data = &C_A_D,
589 .maxlen = sizeof(int),
590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800591 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400593#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200594 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200595 .procname = "ftrace_enabled",
596 .data = &ftrace_enabled,
597 .maxlen = sizeof(int),
598 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800599 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200600 },
601#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500602#ifdef CONFIG_STACK_TRACER
603 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500604 .procname = "stack_tracer_enabled",
605 .data = &stack_tracer_enabled,
606 .maxlen = sizeof(int),
607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500609 },
610#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400611#ifdef CONFIG_TRACING
612 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100613 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400614 .data = &ftrace_dump_on_oops,
615 .maxlen = sizeof(int),
616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800617 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400618 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400619 {
620 .procname = "traceoff_on_warning",
621 .data = &__disable_trace_on_warning,
622 .maxlen = sizeof(__disable_trace_on_warning),
623 .mode = 0644,
624 .proc_handler = proc_dointvec,
625 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500626 {
627 .procname = "tracepoint_printk",
628 .data = &tracepoint_printk,
629 .maxlen = sizeof(tracepoint_printk),
630 .mode = 0644,
631 .proc_handler = proc_dointvec,
632 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400633#endif
Kees Cook79847542014-01-23 15:55:59 -0800634#ifdef CONFIG_KEXEC
635 {
636 .procname = "kexec_load_disabled",
637 .data = &kexec_load_disabled,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 /* only handle a transition from default "0" to "1" */
641 .proc_handler = proc_dointvec_minmax,
642 .extra1 = &one,
643 .extra2 = &one,
644 },
645#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200646#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 .procname = "modprobe",
649 .data = &modprobe_path,
650 .maxlen = KMOD_PATH_LEN,
651 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800652 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 },
Kees Cook3d433212009-04-02 15:49:29 -0700654 {
Kees Cook3d433212009-04-02 15:49:29 -0700655 .procname = "modules_disabled",
656 .data = &modules_disabled,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800660 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700661 .extra1 = &one,
662 .extra2 = &one,
663 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700665#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100668 .data = &uevent_helper,
669 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800671 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 },
Michael Marineau86d56132014-04-10 14:09:31 -0700673#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674#ifdef CONFIG_CHR_DEV_SG
675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 .procname = "sg-big-buff",
677 .data = &sg_big_buff,
678 .maxlen = sizeof (int),
679 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800680 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 },
682#endif
683#ifdef CONFIG_BSD_PROCESS_ACCT
684 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 .procname = "acct",
686 .data = &acct_parm,
687 .maxlen = 3*sizeof(int),
688 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800689 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 },
691#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692#ifdef CONFIG_MAGIC_SYSRQ
693 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800695 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .maxlen = sizeof (int),
697 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700698 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 },
700#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700701#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700704 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .maxlen = sizeof (int),
706 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800707 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700709#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 .procname = "threads-max",
712 .data = &max_threads,
713 .maxlen = sizeof(int),
714 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800715 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 },
717 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 .procname = "random",
719 .mode = 0555,
720 .child = random_table,
721 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 {
Eric Paris17f60a72011-04-01 17:07:50 -0400723 .procname = "usermodehelper",
724 .mode = 0555,
725 .child = usermodehelper_table,
726 },
727 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .procname = "overflowuid",
729 .data = &overflowuid,
730 .maxlen = sizeof(int),
731 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800732 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 .extra1 = &minolduid,
734 .extra2 = &maxolduid,
735 },
736 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 .procname = "overflowgid",
738 .data = &overflowgid,
739 .maxlen = sizeof(int),
740 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800741 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 .extra1 = &minolduid,
743 .extra2 = &maxolduid,
744 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800745#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#ifdef CONFIG_MATHEMU
747 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .procname = "ieee_emulation_warnings",
749 .data = &sysctl_ieee_emulation_warnings,
750 .maxlen = sizeof(int),
751 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800752 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 },
754#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200757 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .maxlen = sizeof(int),
759 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800760 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 },
762#endif
763 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .procname = "pid_max",
765 .data = &pid_max,
766 .maxlen = sizeof (int),
767 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800768 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .extra1 = &pid_max_min,
770 .extra2 = &pid_max_max,
771 },
772 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 .procname = "panic_on_oops",
774 .data = &panic_on_oops,
775 .maxlen = sizeof(int),
776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800777 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800779#if defined CONFIG_PRINTK
780 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800781 .procname = "printk",
782 .data = &console_loglevel,
783 .maxlen = 4*sizeof(int),
784 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800785 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800786 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700789 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .maxlen = sizeof(int),
791 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800792 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 },
794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700796 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 .maxlen = sizeof(int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 },
Dave Youngaf913222009-09-22 16:43:33 -0700801 {
Dave Youngaf913222009-09-22 16:43:33 -0700802 .procname = "printk_delay",
803 .data = &printk_delay_msec,
804 .maxlen = sizeof(int),
805 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800806 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700807 .extra1 = &zero,
808 .extra2 = &ten_thousand,
809 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800811 .procname = "dmesg_restrict",
812 .data = &dmesg_restrict,
813 .maxlen = sizeof(int),
814 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700815 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800816 .extra1 = &zero,
817 .extra2 = &one,
818 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800819 {
820 .procname = "kptr_restrict",
821 .data = &kptr_restrict,
822 .maxlen = sizeof(int),
823 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700824 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800825 .extra1 = &zero,
826 .extra2 = &two,
827 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800828#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800829 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 .procname = "ngroups_max",
831 .data = &ngroups_max,
832 .maxlen = sizeof (int),
833 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800834 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 },
Dan Ballard73efc032011-10-31 17:11:20 -0700836 {
837 .procname = "cap_last_cap",
838 .data = (void *)&cap_last_cap,
839 .maxlen = sizeof(int),
840 .mode = 0444,
841 .proc_handler = proc_dointvec,
842 },
Don Zickus58687ac2010-05-07 17:11:44 -0400843#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500844 {
Don Zickus58687ac2010-05-07 17:11:44 -0400845 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200846 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500847 .maxlen = sizeof (int),
848 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700849 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700850 .extra1 = &zero,
851 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400852 },
853 {
854 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700855 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400856 .maxlen = sizeof(int),
857 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700858 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800859 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400860 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500861 },
Don Zickus2508ce12010-05-07 17:11:46 -0400862 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700863 .procname = "nmi_watchdog",
864 .data = &nmi_watchdog_enabled,
865 .maxlen = sizeof (int),
866 .mode = 0644,
867 .proc_handler = proc_nmi_watchdog,
868 .extra1 = &zero,
869#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
870 .extra2 = &one,
871#else
872 .extra2 = &zero,
873#endif
874 },
875 {
876 .procname = "soft_watchdog",
877 .data = &soft_watchdog_enabled,
878 .maxlen = sizeof (int),
879 .mode = 0644,
880 .proc_handler = proc_soft_watchdog,
881 .extra1 = &zero,
882 .extra2 = &one,
883 },
884 {
Don Zickus2508ce12010-05-07 17:11:46 -0400885 .procname = "softlockup_panic",
886 .data = &softlockup_panic,
887 .maxlen = sizeof(int),
888 .mode = 0644,
889 .proc_handler = proc_dointvec_minmax,
890 .extra1 = &zero,
891 .extra2 = &one,
892 },
Aaron Tomlined235872014-06-23 13:22:05 -0700893#ifdef CONFIG_SMP
894 {
895 .procname = "softlockup_all_cpu_backtrace",
896 .data = &sysctl_softlockup_all_cpu_backtrace,
897 .maxlen = sizeof(int),
898 .mode = 0644,
899 .proc_handler = proc_dointvec_minmax,
900 .extra1 = &zero,
901 .extra2 = &one,
902 },
903#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500904#endif
905#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
906 {
907 .procname = "unknown_nmi_panic",
908 .data = &unknown_nmi_panic,
909 .maxlen = sizeof (int),
910 .mode = 0644,
911 .proc_handler = proc_dointvec,
912 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500913#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914#if defined(CONFIG_X86)
915 {
Don Zickus8da5add2006-09-26 10:52:27 +0200916 .procname = "panic_on_unrecovered_nmi",
917 .data = &panic_on_unrecovered_nmi,
918 .maxlen = sizeof(int),
919 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800920 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200921 },
922 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700923 .procname = "panic_on_io_nmi",
924 .data = &panic_on_io_nmi,
925 .maxlen = sizeof(int),
926 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800927 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700928 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900929#ifdef CONFIG_DEBUG_STACKOVERFLOW
930 {
931 .procname = "panic_on_stackoverflow",
932 .data = &sysctl_panic_on_stackoverflow,
933 .maxlen = sizeof(int),
934 .mode = 0644,
935 .proc_handler = proc_dointvec,
936 },
937#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700938 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 .procname = "bootloader_type",
940 .data = &bootloader_type,
941 .maxlen = sizeof (int),
942 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800943 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100945 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700946 .procname = "bootloader_version",
947 .data = &bootloader_version,
948 .maxlen = sizeof (int),
949 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800950 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700951 },
952 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100953 .procname = "kstack_depth_to_print",
954 .data = &kstack_depth_to_print,
955 .maxlen = sizeof(int),
956 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800957 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100958 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100959 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100960 .procname = "io_delay_type",
961 .data = &io_delay_type,
962 .maxlen = sizeof(int),
963 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800964 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100965 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800967#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 .procname = "randomize_va_space",
970 .data = &randomize_va_space,
971 .maxlen = sizeof(int),
972 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800973 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800975#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800976#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700977 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700978 .procname = "spin_retry",
979 .data = &spin_retry,
980 .maxlen = sizeof (int),
981 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800982 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700983 },
984#endif
Len Brown673d5b42007-07-28 03:33:16 -0400985#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -0800986 {
Pavel Machekc255d842006-02-20 18:27:58 -0800987 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -0700988 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -0800989 .maxlen = sizeof (unsigned long),
990 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800991 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -0800992 },
993#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530994#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -0800995 {
Jes Sorensend2b176e2006-02-28 09:42:23 -0800996 .procname = "ignore-unaligned-usertrap",
997 .data = &no_unaligned_warning,
998 .maxlen = sizeof (int),
999 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001000 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001001 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301002#endif
1003#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001004 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001005 .procname = "unaligned-dump-stack",
1006 .data = &unaligned_dump_stack,
1007 .maxlen = sizeof (int),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001010 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001011#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001012#ifdef CONFIG_DETECT_HUNG_TASK
1013 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001014 .procname = "hung_task_panic",
1015 .data = &sysctl_hung_task_panic,
1016 .maxlen = sizeof(int),
1017 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001018 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001019 .extra1 = &zero,
1020 .extra2 = &one,
1021 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001022 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001023 .procname = "hung_task_check_count",
1024 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001025 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001026 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001027 .proc_handler = proc_dointvec_minmax,
1028 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001029 },
1030 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001031 .procname = "hung_task_timeout_secs",
1032 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001033 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001034 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001035 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001036 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001037 },
1038 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001039 .procname = "hung_task_warnings",
1040 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001041 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001042 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001043 .proc_handler = proc_dointvec_minmax,
1044 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001045 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001046#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001047#ifdef CONFIG_COMPAT
1048 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001049 .procname = "compat-log",
1050 .data = &compat_log,
1051 .maxlen = sizeof (int),
1052 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001054 },
1055#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001056#ifdef CONFIG_RT_MUTEXES
1057 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001058 .procname = "max_lock_depth",
1059 .data = &max_lock_depth,
1060 .maxlen = sizeof(int),
1061 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001062 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001063 },
1064#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001065 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001066 .procname = "poweroff_cmd",
1067 .data = &poweroff_cmd,
1068 .maxlen = POWEROFF_CMD_PATH_LEN,
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001071 },
David Howells0b77f5b2008-04-29 01:01:32 -07001072#ifdef CONFIG_KEYS
1073 {
David Howells0b77f5b2008-04-29 01:01:32 -07001074 .procname = "keys",
1075 .mode = 0555,
1076 .child = key_sysctls,
1077 },
1078#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001079#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001080 /*
1081 * User-space scripts rely on the existence of this file
1082 * as a feature check for perf_events being enabled.
1083 *
1084 * So it's an ABI, do not remove!
1085 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001086 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001087 .procname = "perf_event_paranoid",
1088 .data = &sysctl_perf_event_paranoid,
1089 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001090 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001091 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001092 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001093 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001094 .procname = "perf_event_mlock_kb",
1095 .data = &sysctl_perf_event_mlock,
1096 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001097 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001098 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001099 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001100 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001101 .procname = "perf_event_max_sample_rate",
1102 .data = &sysctl_perf_event_sample_rate,
1103 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001104 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001105 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001106 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001107 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001108 {
1109 .procname = "perf_cpu_time_max_percent",
1110 .data = &sysctl_perf_cpu_time_max_percent,
1111 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1112 .mode = 0644,
1113 .proc_handler = perf_cpu_time_max_percent_handler,
1114 .extra1 = &zero,
1115 .extra2 = &one_hundred,
1116 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001117#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001118#ifdef CONFIG_KMEMCHECK
1119 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001120 .procname = "kmemcheck",
1121 .data = &kmemcheck_enabled,
1122 .maxlen = sizeof(int),
1123 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001124 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001125 },
1126#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001127 {
1128 .procname = "panic_on_warn",
1129 .data = &panic_on_warn,
1130 .maxlen = sizeof(int),
1131 .mode = 0644,
1132 .proc_handler = proc_dointvec_minmax,
1133 .extra1 = &zero,
1134 .extra2 = &one,
1135 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001136 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137};
1138
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001139static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 .procname = "overcommit_memory",
1142 .data = &sysctl_overcommit_memory,
1143 .maxlen = sizeof(sysctl_overcommit_memory),
1144 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001145 .proc_handler = proc_dointvec_minmax,
1146 .extra1 = &zero,
1147 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 },
1149 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001150 .procname = "panic_on_oom",
1151 .data = &sysctl_panic_on_oom,
1152 .maxlen = sizeof(sysctl_panic_on_oom),
1153 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001154 .proc_handler = proc_dointvec_minmax,
1155 .extra1 = &zero,
1156 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001157 },
1158 {
David Rientjesfe071d72007-10-16 23:25:56 -07001159 .procname = "oom_kill_allocating_task",
1160 .data = &sysctl_oom_kill_allocating_task,
1161 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1162 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001163 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001164 },
1165 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001166 .procname = "oom_dump_tasks",
1167 .data = &sysctl_oom_dump_tasks,
1168 .maxlen = sizeof(sysctl_oom_dump_tasks),
1169 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001170 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001171 },
1172 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 .procname = "overcommit_ratio",
1174 .data = &sysctl_overcommit_ratio,
1175 .maxlen = sizeof(sysctl_overcommit_ratio),
1176 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001177 .proc_handler = overcommit_ratio_handler,
1178 },
1179 {
1180 .procname = "overcommit_kbytes",
1181 .data = &sysctl_overcommit_kbytes,
1182 .maxlen = sizeof(sysctl_overcommit_kbytes),
1183 .mode = 0644,
1184 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 },
1186 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 .procname = "page-cluster",
1188 .data = &page_cluster,
1189 .maxlen = sizeof(int),
1190 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001191 .proc_handler = proc_dointvec_minmax,
1192 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 },
1194 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 .procname = "dirty_background_ratio",
1196 .data = &dirty_background_ratio,
1197 .maxlen = sizeof(dirty_background_ratio),
1198 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001199 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 .extra1 = &zero,
1201 .extra2 = &one_hundred,
1202 },
1203 {
David Rientjes2da02992009-01-06 14:39:31 -08001204 .procname = "dirty_background_bytes",
1205 .data = &dirty_background_bytes,
1206 .maxlen = sizeof(dirty_background_bytes),
1207 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001208 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001209 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001210 },
1211 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 .procname = "dirty_ratio",
1213 .data = &vm_dirty_ratio,
1214 .maxlen = sizeof(vm_dirty_ratio),
1215 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001216 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 .extra1 = &zero,
1218 .extra2 = &one_hundred,
1219 },
1220 {
David Rientjes2da02992009-01-06 14:39:31 -08001221 .procname = "dirty_bytes",
1222 .data = &vm_dirty_bytes,
1223 .maxlen = sizeof(vm_dirty_bytes),
1224 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001225 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001226 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001227 },
1228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001230 .data = &dirty_writeback_interval,
1231 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001233 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 },
1235 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001237 .data = &dirty_expire_interval,
1238 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001240 .proc_handler = proc_dointvec_minmax,
1241 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 },
1243 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001244 .procname = "dirtytime_expire_seconds",
1245 .data = &dirtytime_expire_interval,
1246 .maxlen = sizeof(dirty_expire_interval),
1247 .mode = 0644,
1248 .proc_handler = dirtytime_interval_handler,
1249 .extra1 = &zero,
1250 },
1251 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001252 .procname = "nr_pdflush_threads",
1253 .mode = 0444 /* read-only */,
1254 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 },
1256 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 .procname = "swappiness",
1258 .data = &vm_swappiness,
1259 .maxlen = sizeof(vm_swappiness),
1260 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001261 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 .extra1 = &zero,
1263 .extra2 = &one_hundred,
1264 },
1265#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001266 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001268 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 .maxlen = sizeof(unsigned long),
1270 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001271 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001272 },
1273#ifdef CONFIG_NUMA
1274 {
1275 .procname = "nr_hugepages_mempolicy",
1276 .data = NULL,
1277 .maxlen = sizeof(unsigned long),
1278 .mode = 0644,
1279 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001280 },
1281#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 .procname = "hugetlb_shm_group",
1284 .data = &sysctl_hugetlb_shm_group,
1285 .maxlen = sizeof(gid_t),
1286 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001287 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 },
Mel Gorman396faf02007-07-17 04:03:13 -07001289 {
Mel Gorman396faf02007-07-17 04:03:13 -07001290 .procname = "hugepages_treat_as_movable",
1291 .data = &hugepages_treat_as_movable,
1292 .maxlen = sizeof(int),
1293 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001294 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001295 },
Adam Litke54f9f802007-10-16 01:26:20 -07001296 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001297 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001298 .data = NULL,
1299 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001300 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001301 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001302 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303#endif
1304 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 .procname = "lowmem_reserve_ratio",
1306 .data = &sysctl_lowmem_reserve_ratio,
1307 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1308 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001309 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 },
1311 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001312 .procname = "drop_caches",
1313 .data = &sysctl_drop_caches,
1314 .maxlen = sizeof(int),
1315 .mode = 0644,
1316 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001317 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001318 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001319 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001320#ifdef CONFIG_COMPACTION
1321 {
1322 .procname = "compact_memory",
1323 .data = &sysctl_compact_memory,
1324 .maxlen = sizeof(int),
1325 .mode = 0200,
1326 .proc_handler = sysctl_compaction_handler,
1327 },
Mel Gorman5e771902010-05-24 14:32:31 -07001328 {
1329 .procname = "extfrag_threshold",
1330 .data = &sysctl_extfrag_threshold,
1331 .maxlen = sizeof(int),
1332 .mode = 0644,
1333 .proc_handler = sysctl_extfrag_handler,
1334 .extra1 = &min_extfrag_threshold,
1335 .extra2 = &max_extfrag_threshold,
1336 },
1337
Mel Gorman76ab0f52010-05-24 14:32:28 -07001338#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001339 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 .procname = "min_free_kbytes",
1341 .data = &min_free_kbytes,
1342 .maxlen = sizeof(min_free_kbytes),
1343 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001344 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 .extra1 = &zero,
1346 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001347 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001348 .procname = "percpu_pagelist_fraction",
1349 .data = &percpu_pagelist_fraction,
1350 .maxlen = sizeof(percpu_pagelist_fraction),
1351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001353 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001354 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355#ifdef CONFIG_MMU
1356 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 .procname = "max_map_count",
1358 .data = &sysctl_max_map_count,
1359 .maxlen = sizeof(sysctl_max_map_count),
1360 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001361 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001362 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001364#else
1365 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001366 .procname = "nr_trim_pages",
1367 .data = &sysctl_nr_trim_pages,
1368 .maxlen = sizeof(sysctl_nr_trim_pages),
1369 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001370 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001371 .extra1 = &zero,
1372 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373#endif
1374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 .procname = "laptop_mode",
1376 .data = &laptop_mode,
1377 .maxlen = sizeof(laptop_mode),
1378 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001379 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 },
1381 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 .procname = "block_dump",
1383 .data = &block_dump,
1384 .maxlen = sizeof(block_dump),
1385 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001386 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 .extra1 = &zero,
1388 },
1389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .procname = "vfs_cache_pressure",
1391 .data = &sysctl_vfs_cache_pressure,
1392 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1393 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001394 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .extra1 = &zero,
1396 },
1397#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "legacy_va_layout",
1400 .data = &sysctl_legacy_va_layout,
1401 .maxlen = sizeof(sysctl_legacy_va_layout),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 .extra1 = &zero,
1405 },
1406#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001407#ifdef CONFIG_NUMA
1408 {
Christoph Lameter17436602006-01-18 17:42:32 -08001409 .procname = "zone_reclaim_mode",
1410 .data = &zone_reclaim_mode,
1411 .maxlen = sizeof(zone_reclaim_mode),
1412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001413 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001414 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001415 },
Christoph Lameter96146342006-07-03 00:24:13 -07001416 {
Christoph Lameter96146342006-07-03 00:24:13 -07001417 .procname = "min_unmapped_ratio",
1418 .data = &sysctl_min_unmapped_ratio,
1419 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001422 .extra1 = &zero,
1423 .extra2 = &one_hundred,
1424 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001425 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001426 .procname = "min_slab_ratio",
1427 .data = &sysctl_min_slab_ratio,
1428 .maxlen = sizeof(sysctl_min_slab_ratio),
1429 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001430 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001431 .extra1 = &zero,
1432 .extra2 = &one_hundred,
1433 },
Christoph Lameter17436602006-01-18 17:42:32 -08001434#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001435#ifdef CONFIG_SMP
1436 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001437 .procname = "stat_interval",
1438 .data = &sysctl_stat_interval,
1439 .maxlen = sizeof(sysctl_stat_interval),
1440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001441 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001442 },
1443#endif
David Howells6e141542009-12-15 19:27:45 +00001444#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001445 {
Eric Parised032182007-06-28 15:55:21 -04001446 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001447 .data = &dac_mmap_min_addr,
1448 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001449 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001450 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001451 },
David Howells6e141542009-12-15 19:27:45 +00001452#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001453#ifdef CONFIG_NUMA
1454 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001455 .procname = "numa_zonelist_order",
1456 .data = &numa_zonelist_order,
1457 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1458 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001459 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001460 },
1461#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001462#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001463 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001464 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001465 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001466#ifdef CONFIG_X86_32
1467 .data = &vdso32_enabled,
1468 .maxlen = sizeof(vdso32_enabled),
1469#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001470 .data = &vdso_enabled,
1471 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001472#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001473 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001474 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001475 .extra1 = &zero,
1476 },
1477#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001478#ifdef CONFIG_HIGHMEM
1479 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001480 .procname = "highmem_is_dirtyable",
1481 .data = &vm_highmem_is_dirtyable,
1482 .maxlen = sizeof(vm_highmem_is_dirtyable),
1483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001484 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001485 .extra1 = &zero,
1486 .extra2 = &one,
1487 },
1488#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001489#ifdef CONFIG_MEMORY_FAILURE
1490 {
Andi Kleen6a460792009-09-16 11:50:15 +02001491 .procname = "memory_failure_early_kill",
1492 .data = &sysctl_memory_failure_early_kill,
1493 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1494 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001495 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001496 .extra1 = &zero,
1497 .extra2 = &one,
1498 },
1499 {
Andi Kleen6a460792009-09-16 11:50:15 +02001500 .procname = "memory_failure_recovery",
1501 .data = &sysctl_memory_failure_recovery,
1502 .maxlen = sizeof(sysctl_memory_failure_recovery),
1503 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001504 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001505 .extra1 = &zero,
1506 .extra2 = &one,
1507 },
1508#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001509 {
1510 .procname = "user_reserve_kbytes",
1511 .data = &sysctl_user_reserve_kbytes,
1512 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1513 .mode = 0644,
1514 .proc_handler = proc_doulongvec_minmax,
1515 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001516 {
1517 .procname = "admin_reserve_kbytes",
1518 .data = &sysctl_admin_reserve_kbytes,
1519 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1520 .mode = 0644,
1521 .proc_handler = proc_doulongvec_minmax,
1522 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001523 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524};
1525
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001526#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001527static struct ctl_table binfmt_misc_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001528 { }
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001529};
1530#endif
1531
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001532static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 .procname = "inode-nr",
1535 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001536 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001538 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 },
1540 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 .procname = "inode-state",
1542 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001543 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001545 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 },
1547 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 .procname = "file-nr",
1549 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001550 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001552 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 },
1554 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 .procname = "file-max",
1556 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001557 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001559 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 },
1561 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001562 .procname = "nr_open",
1563 .data = &sysctl_nr_open,
1564 .maxlen = sizeof(int),
1565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001566 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001567 .extra1 = &sysctl_nr_open_min,
1568 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001569 },
1570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 .procname = "dentry-state",
1572 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001573 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001575 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 },
1577 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 .procname = "overflowuid",
1579 .data = &fs_overflowuid,
1580 .maxlen = sizeof(int),
1581 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001582 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 .extra1 = &minolduid,
1584 .extra2 = &maxolduid,
1585 },
1586 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 .procname = "overflowgid",
1588 .data = &fs_overflowgid,
1589 .maxlen = sizeof(int),
1590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001591 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 .extra1 = &minolduid,
1593 .extra2 = &maxolduid,
1594 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001595#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 .procname = "leases-enable",
1598 .data = &leases_enable,
1599 .maxlen = sizeof(int),
1600 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001601 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001603#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604#ifdef CONFIG_DNOTIFY
1605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 .procname = "dir-notify-enable",
1607 .data = &dir_notify_enable,
1608 .maxlen = sizeof(int),
1609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001610 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 },
1612#endif
1613#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001614#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 .procname = "lease-break-time",
1617 .data = &lease_break_time,
1618 .maxlen = sizeof(int),
1619 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001620 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001622#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001623#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 .procname = "aio-nr",
1626 .data = &aio_nr,
1627 .maxlen = sizeof(aio_nr),
1628 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001629 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 },
1631 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 .procname = "aio-max-nr",
1633 .data = &aio_max_nr,
1634 .maxlen = sizeof(aio_max_nr),
1635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001636 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001638#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001639#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001640 {
Robert Love0399cb02005-07-13 12:38:18 -04001641 .procname = "inotify",
1642 .mode = 0555,
1643 .child = inotify_table,
1644 },
1645#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001646#ifdef CONFIG_EPOLL
1647 {
1648 .procname = "epoll",
1649 .mode = 0555,
1650 .child = epoll_table,
1651 },
1652#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001654 {
Kees Cook800179c2012-07-25 17:29:07 -07001655 .procname = "protected_symlinks",
1656 .data = &sysctl_protected_symlinks,
1657 .maxlen = sizeof(int),
1658 .mode = 0600,
1659 .proc_handler = proc_dointvec_minmax,
1660 .extra1 = &zero,
1661 .extra2 = &one,
1662 },
1663 {
1664 .procname = "protected_hardlinks",
1665 .data = &sysctl_protected_hardlinks,
1666 .maxlen = sizeof(int),
1667 .mode = 0600,
1668 .proc_handler = proc_dointvec_minmax,
1669 .extra1 = &zero,
1670 .extra2 = &one,
1671 },
1672 {
Alan Coxd6e71142005-06-23 00:09:43 -07001673 .procname = "suid_dumpable",
1674 .data = &suid_dumpable,
1675 .maxlen = sizeof(int),
1676 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001677 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001678 .extra1 = &zero,
1679 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001680 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001681#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1682 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001683 .procname = "binfmt_misc",
1684 .mode = 0555,
1685 .child = binfmt_misc_table,
1686 },
1687#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001688 {
Jens Axboeff9da692010-06-03 14:54:39 +02001689 .procname = "pipe-max-size",
1690 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001691 .maxlen = sizeof(int),
1692 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001693 .proc_handler = &pipe_proc_fn,
1694 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001695 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001696 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697};
1698
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001699static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001700#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001701 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001702 .procname = "exception-trace",
1703 .data = &show_unhandled_signals,
1704 .maxlen = sizeof(int),
1705 .mode = 0644,
1706 .proc_handler = proc_dointvec
1707 },
1708#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001709#if defined(CONFIG_OPTPROBES)
1710 {
1711 .procname = "kprobes-optimization",
1712 .data = &sysctl_kprobes_optimization,
1713 .maxlen = sizeof(int),
1714 .mode = 0644,
1715 .proc_handler = proc_kprobes_optimization_handler,
1716 .extra1 = &zero,
1717 .extra2 = &one,
1718 },
1719#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001720 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721};
1722
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001723static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001724 { }
Robert Love0eeca282005-07-12 17:06:03 -04001725};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001727int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001728{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001729 struct ctl_table_header *hdr;
1730
1731 hdr = register_sysctl_table(sysctl_base_table);
1732 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001733 return 0;
1734}
1735
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001736#endif /* CONFIG_SYSCTL */
1737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738/*
1739 * /proc/sys support
1740 */
1741
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001742#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
Kees Cookf8808302014-06-06 14:37:17 -07001744static int _proc_do_string(char *data, int maxlen, int write,
1745 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001746 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001747{
1748 size_t len;
1749 char __user *p;
1750 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001751
1752 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001753 *lenp = 0;
1754 return 0;
1755 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001756
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001757 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001758 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1759 /* Only continue writes not past the end of buffer. */
1760 len = strlen(data);
1761 if (len > maxlen - 1)
1762 len = maxlen - 1;
1763
1764 if (*ppos > len)
1765 return 0;
1766 len = *ppos;
1767 } else {
1768 /* Start writing from beginning of buffer. */
1769 len = 0;
1770 }
1771
Kees Cook2ca9bb42014-06-06 14:37:18 -07001772 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001773 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001774 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001775 if (get_user(c, p++))
1776 return -EFAULT;
1777 if (c == 0 || c == '\n')
1778 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001779 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001780 }
Kees Cookf8808302014-06-06 14:37:17 -07001781 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001782 } else {
1783 len = strlen(data);
1784 if (len > maxlen)
1785 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001786
1787 if (*ppos > len) {
1788 *lenp = 0;
1789 return 0;
1790 }
1791
1792 data += *ppos;
1793 len -= *ppos;
1794
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001795 if (len > *lenp)
1796 len = *lenp;
1797 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001798 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001799 return -EFAULT;
1800 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001801 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001802 return -EFAULT;
1803 len++;
1804 }
1805 *lenp = len;
1806 *ppos += len;
1807 }
1808 return 0;
1809}
1810
Kees Cookf4aacea2014-06-06 14:37:19 -07001811static void warn_sysctl_write(struct ctl_table *table)
1812{
1813 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1814 "This will not be supported in the future. To silence this\n"
1815 "warning, set kernel.sysctl_writes_strict = -1\n",
1816 current->comm, table->procname);
1817}
1818
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819/**
1820 * proc_dostring - read a string sysctl
1821 * @table: the sysctl table
1822 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 * @buffer: the user buffer
1824 * @lenp: the size of the user buffer
1825 * @ppos: file position
1826 *
1827 * Reads/writes a string from/to the user buffer. If the kernel
1828 * buffer provided is not large enough to hold the string, the
1829 * string is truncated. The copied string is %NULL-terminated.
1830 * If the string is being read by the user process, it is copied
1831 * and a newline '\n' is added. It is truncated if the buffer is
1832 * not large enough.
1833 *
1834 * Returns 0 on success.
1835 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001836int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 void __user *buffer, size_t *lenp, loff_t *ppos)
1838{
Kees Cookf4aacea2014-06-06 14:37:19 -07001839 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1840 warn_sysctl_write(table);
1841
Kees Cookf8808302014-06-06 14:37:17 -07001842 return _proc_do_string((char *)(table->data), table->maxlen, write,
1843 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844}
1845
Amerigo Wang00b7c332010-05-05 00:26:45 +00001846static size_t proc_skip_spaces(char **buf)
1847{
1848 size_t ret;
1849 char *tmp = skip_spaces(*buf);
1850 ret = tmp - *buf;
1851 *buf = tmp;
1852 return ret;
1853}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001855static void proc_skip_char(char **buf, size_t *size, const char v)
1856{
1857 while (*size) {
1858 if (**buf != v)
1859 break;
1860 (*size)--;
1861 (*buf)++;
1862 }
1863}
1864
Amerigo Wang00b7c332010-05-05 00:26:45 +00001865#define TMPBUFLEN 22
1866/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001867 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001868 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001869 * @buf: a kernel buffer
1870 * @size: size of the kernel buffer
1871 * @val: this is where the number will be stored
1872 * @neg: set to %TRUE if number is negative
1873 * @perm_tr: a vector which contains the allowed trailers
1874 * @perm_tr_len: size of the perm_tr vector
1875 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001876 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001877 * In case of success %0 is returned and @buf and @size are updated with
1878 * the amount of bytes read. If @tr is non-NULL and a trailing
1879 * character exists (size is non-zero after returning from this
1880 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001881 */
1882static int proc_get_long(char **buf, size_t *size,
1883 unsigned long *val, bool *neg,
1884 const char *perm_tr, unsigned perm_tr_len, char *tr)
1885{
1886 int len;
1887 char *p, tmp[TMPBUFLEN];
1888
1889 if (!*size)
1890 return -EINVAL;
1891
1892 len = *size;
1893 if (len > TMPBUFLEN - 1)
1894 len = TMPBUFLEN - 1;
1895
1896 memcpy(tmp, *buf, len);
1897
1898 tmp[len] = 0;
1899 p = tmp;
1900 if (*p == '-' && *size > 1) {
1901 *neg = true;
1902 p++;
1903 } else
1904 *neg = false;
1905 if (!isdigit(*p))
1906 return -EINVAL;
1907
1908 *val = simple_strtoul(p, &p, 0);
1909
1910 len = p - tmp;
1911
1912 /* We don't know if the next char is whitespace thus we may accept
1913 * invalid integers (e.g. 1234...a) or two integers instead of one
1914 * (e.g. 123...1). So lets not allow such large numbers. */
1915 if (len == TMPBUFLEN - 1)
1916 return -EINVAL;
1917
1918 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1919 return -EINVAL;
1920
1921 if (tr && (len < *size))
1922 *tr = *p;
1923
1924 *buf += len;
1925 *size -= len;
1926
1927 return 0;
1928}
1929
1930/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001931 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00001932 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001933 * @buf: the user buffer
1934 * @size: the size of the user buffer
1935 * @val: the integer to be converted
1936 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00001937 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001938 * In case of success %0 is returned and @buf and @size are updated with
1939 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001940 */
1941static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1942 bool neg)
1943{
1944 int len;
1945 char tmp[TMPBUFLEN], *p = tmp;
1946
1947 sprintf(p, "%s%lu", neg ? "-" : "", val);
1948 len = strlen(tmp);
1949 if (len > *size)
1950 len = *size;
1951 if (copy_to_user(*buf, tmp, len))
1952 return -EFAULT;
1953 *size -= len;
1954 *buf += len;
1955 return 0;
1956}
1957#undef TMPBUFLEN
1958
1959static int proc_put_char(void __user **buf, size_t *size, char c)
1960{
1961 if (*size) {
1962 char __user **buffer = (char __user **)buf;
1963 if (put_user(c, *buffer))
1964 return -EFAULT;
1965 (*size)--, (*buffer)++;
1966 *buf = *buffer;
1967 }
1968 return 0;
1969}
1970
1971static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 int *valp,
1973 int write, void *data)
1974{
1975 if (write) {
1976 *valp = *negp ? -*lvalp : *lvalp;
1977 } else {
1978 int val = *valp;
1979 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001980 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 *lvalp = (unsigned long)-val;
1982 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001983 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 *lvalp = (unsigned long)val;
1985 }
1986 }
1987 return 0;
1988}
1989
Amerigo Wang00b7c332010-05-05 00:26:45 +00001990static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1991
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001992static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001993 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001994 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001995 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 int write, void *data),
1997 void *data)
1998{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001999 int *i, vleft, first = 1, err = 0;
2000 unsigned long page = 0;
2001 size_t left;
2002 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Amerigo Wang00b7c332010-05-05 00:26:45 +00002004 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 *lenp = 0;
2006 return 0;
2007 }
2008
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002009 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 vleft = table->maxlen / sizeof(*i);
2011 left = *lenp;
2012
2013 if (!conv)
2014 conv = do_proc_dointvec_conv;
2015
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002017 if (*ppos) {
2018 switch (sysctl_writes_strict) {
2019 case SYSCTL_WRITES_STRICT:
2020 goto out;
2021 case SYSCTL_WRITES_WARN:
2022 warn_sysctl_write(table);
2023 break;
2024 default:
2025 break;
2026 }
2027 }
2028
Amerigo Wang00b7c332010-05-05 00:26:45 +00002029 if (left > PAGE_SIZE - 1)
2030 left = PAGE_SIZE - 1;
2031 page = __get_free_page(GFP_TEMPORARY);
2032 kbuf = (char *) page;
2033 if (!kbuf)
2034 return -ENOMEM;
2035 if (copy_from_user(kbuf, buffer, left)) {
2036 err = -EFAULT;
2037 goto free;
2038 }
2039 kbuf[left] = 0;
2040 }
2041
2042 for (; left && vleft--; i++, first=0) {
2043 unsigned long lval;
2044 bool neg;
2045
2046 if (write) {
2047 left -= proc_skip_spaces(&kbuf);
2048
J. R. Okajima563b0462010-05-25 16:10:14 -07002049 if (!left)
2050 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002051 err = proc_get_long(&kbuf, &left, &lval, &neg,
2052 proc_wspace_sep,
2053 sizeof(proc_wspace_sep), NULL);
2054 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002056 if (conv(&neg, &lval, i, 1, data)) {
2057 err = -EINVAL;
2058 break;
2059 }
2060 } else {
2061 if (conv(&neg, &lval, i, 0, data)) {
2062 err = -EINVAL;
2063 break;
2064 }
2065 if (!first)
2066 err = proc_put_char(&buffer, &left, '\t');
2067 if (err)
2068 break;
2069 err = proc_put_long(&buffer, &left, lval, neg);
2070 if (err)
2071 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 }
2073 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002074
2075 if (!write && !first && left && !err)
2076 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002077 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002078 left -= proc_skip_spaces(&kbuf);
2079free:
2080 if (write) {
2081 free_page(page);
2082 if (first)
2083 return err ? : -EINVAL;
2084 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002086out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002088 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002091static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002092 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002093 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002094 int write, void *data),
2095 void *data)
2096{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002097 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002098 buffer, lenp, ppos, conv, data);
2099}
2100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101/**
2102 * proc_dointvec - read a vector of integers
2103 * @table: the sysctl table
2104 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 * @buffer: the user buffer
2106 * @lenp: the size of the user buffer
2107 * @ppos: file position
2108 *
2109 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2110 * values from/to the user buffer, treated as an ASCII string.
2111 *
2112 * Returns 0 on success.
2113 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002114int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 void __user *buffer, size_t *lenp, loff_t *ppos)
2116{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002117 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 NULL,NULL);
2119}
2120
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002121/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002122 * Taint values can only be increased
2123 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002124 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002125static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002126 void __user *buffer, size_t *lenp, loff_t *ppos)
2127{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002128 struct ctl_table t;
2129 unsigned long tmptaint = get_taint();
2130 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002131
Bastian Blank91fcd412007-04-23 14:41:14 -07002132 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002133 return -EPERM;
2134
Andi Kleen25ddbb12008-10-15 22:01:41 -07002135 t = *table;
2136 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002137 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002138 if (err < 0)
2139 return err;
2140
2141 if (write) {
2142 /*
2143 * Poor man's atomic or. Not worth adding a primitive
2144 * to everyone's atomic.h for this
2145 */
2146 int i;
2147 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2148 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302149 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002150 }
2151 }
2152
2153 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002154}
2155
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002156#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002157static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002158 void __user *buffer, size_t *lenp, loff_t *ppos)
2159{
2160 if (write && !capable(CAP_SYS_ADMIN))
2161 return -EPERM;
2162
2163 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2164}
2165#endif
2166
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167struct do_proc_dointvec_minmax_conv_param {
2168 int *min;
2169 int *max;
2170};
2171
Amerigo Wang00b7c332010-05-05 00:26:45 +00002172static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2173 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 int write, void *data)
2175{
2176 struct do_proc_dointvec_minmax_conv_param *param = data;
2177 if (write) {
2178 int val = *negp ? -*lvalp : *lvalp;
2179 if ((param->min && *param->min > val) ||
2180 (param->max && *param->max < val))
2181 return -EINVAL;
2182 *valp = val;
2183 } else {
2184 int val = *valp;
2185 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002186 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 *lvalp = (unsigned long)-val;
2188 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002189 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 *lvalp = (unsigned long)val;
2191 }
2192 }
2193 return 0;
2194}
2195
2196/**
2197 * proc_dointvec_minmax - read a vector of integers with min/max values
2198 * @table: the sysctl table
2199 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 * @buffer: the user buffer
2201 * @lenp: the size of the user buffer
2202 * @ppos: file position
2203 *
2204 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2205 * values from/to the user buffer, treated as an ASCII string.
2206 *
2207 * This routine will ensure the values are within the range specified by
2208 * table->extra1 (min) and table->extra2 (max).
2209 *
2210 * Returns 0 on success.
2211 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002212int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 void __user *buffer, size_t *lenp, loff_t *ppos)
2214{
2215 struct do_proc_dointvec_minmax_conv_param param = {
2216 .min = (int *) table->extra1,
2217 .max = (int *) table->extra2,
2218 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002219 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 do_proc_dointvec_minmax_conv, &param);
2221}
2222
Kees Cook54b50192012-07-30 14:39:18 -07002223static void validate_coredump_safety(void)
2224{
Alex Kelly046d6622012-10-04 17:15:23 -07002225#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002226 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002227 core_pattern[0] != '/' && core_pattern[0] != '|') {
2228 printk(KERN_WARNING "Unsafe core_pattern used with "\
2229 "suid_dumpable=2. Pipe handler or fully qualified "\
2230 "core dump path required.\n");
2231 }
Alex Kelly046d6622012-10-04 17:15:23 -07002232#endif
Kees Cook54b50192012-07-30 14:39:18 -07002233}
2234
2235static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2236 void __user *buffer, size_t *lenp, loff_t *ppos)
2237{
2238 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2239 if (!error)
2240 validate_coredump_safety();
2241 return error;
2242}
2243
Alex Kelly046d6622012-10-04 17:15:23 -07002244#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002245static int proc_dostring_coredump(struct ctl_table *table, int write,
2246 void __user *buffer, size_t *lenp, loff_t *ppos)
2247{
2248 int error = proc_dostring(table, write, buffer, lenp, ppos);
2249 if (!error)
2250 validate_coredump_safety();
2251 return error;
2252}
Alex Kelly046d6622012-10-04 17:15:23 -07002253#endif
Kees Cook54b50192012-07-30 14:39:18 -07002254
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002255static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 void __user *buffer,
2257 size_t *lenp, loff_t *ppos,
2258 unsigned long convmul,
2259 unsigned long convdiv)
2260{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002261 unsigned long *i, *min, *max;
2262 int vleft, first = 1, err = 0;
2263 unsigned long page = 0;
2264 size_t left;
2265 char *kbuf;
2266
2267 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 *lenp = 0;
2269 return 0;
2270 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002271
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002272 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 min = (unsigned long *) table->extra1;
2274 max = (unsigned long *) table->extra2;
2275 vleft = table->maxlen / sizeof(unsigned long);
2276 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002277
2278 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002279 if (*ppos) {
2280 switch (sysctl_writes_strict) {
2281 case SYSCTL_WRITES_STRICT:
2282 goto out;
2283 case SYSCTL_WRITES_WARN:
2284 warn_sysctl_write(table);
2285 break;
2286 default:
2287 break;
2288 }
2289 }
2290
Amerigo Wang00b7c332010-05-05 00:26:45 +00002291 if (left > PAGE_SIZE - 1)
2292 left = PAGE_SIZE - 1;
2293 page = __get_free_page(GFP_TEMPORARY);
2294 kbuf = (char *) page;
2295 if (!kbuf)
2296 return -ENOMEM;
2297 if (copy_from_user(kbuf, buffer, left)) {
2298 err = -EFAULT;
2299 goto free;
2300 }
2301 kbuf[left] = 0;
2302 }
2303
Eric Dumazet27b3d802010-10-07 12:59:29 -07002304 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002305 unsigned long val;
2306
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002308 bool neg;
2309
2310 left -= proc_skip_spaces(&kbuf);
2311
2312 err = proc_get_long(&kbuf, &left, &val, &neg,
2313 proc_wspace_sep,
2314 sizeof(proc_wspace_sep), NULL);
2315 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 break;
2317 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 continue;
2319 if ((min && val < *min) || (max && val > *max))
2320 continue;
2321 *i = val;
2322 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002323 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002324 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002326 if (err)
2327 break;
2328 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002329 err = proc_put_long(&buffer, &left, val, false);
2330 if (err)
2331 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 }
2333 }
2334
Amerigo Wang00b7c332010-05-05 00:26:45 +00002335 if (!write && !first && left && !err)
2336 err = proc_put_char(&buffer, &left, '\n');
2337 if (write && !err)
2338 left -= proc_skip_spaces(&kbuf);
2339free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002341 free_page(page);
2342 if (first)
2343 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002346out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002348 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349}
2350
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002351static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002352 void __user *buffer,
2353 size_t *lenp, loff_t *ppos,
2354 unsigned long convmul,
2355 unsigned long convdiv)
2356{
2357 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002358 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002359}
2360
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361/**
2362 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2363 * @table: the sysctl table
2364 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 * @buffer: the user buffer
2366 * @lenp: the size of the user buffer
2367 * @ppos: file position
2368 *
2369 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2370 * values from/to the user buffer, treated as an ASCII string.
2371 *
2372 * This routine will ensure the values are within the range specified by
2373 * table->extra1 (min) and table->extra2 (max).
2374 *
2375 * Returns 0 on success.
2376 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002377int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 void __user *buffer, size_t *lenp, loff_t *ppos)
2379{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002380 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381}
2382
2383/**
2384 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2385 * @table: the sysctl table
2386 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 * @buffer: the user buffer
2388 * @lenp: the size of the user buffer
2389 * @ppos: file position
2390 *
2391 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2392 * values from/to the user buffer, treated as an ASCII string. The values
2393 * are treated as milliseconds, and converted to jiffies when they are stored.
2394 *
2395 * This routine will ensure the values are within the range specified by
2396 * table->extra1 (min) and table->extra2 (max).
2397 *
2398 * Returns 0 on success.
2399 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002400int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 void __user *buffer,
2402 size_t *lenp, loff_t *ppos)
2403{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002404 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 lenp, ppos, HZ, 1000l);
2406}
2407
2408
Amerigo Wang00b7c332010-05-05 00:26:45 +00002409static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 int *valp,
2411 int write, void *data)
2412{
2413 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002414 if (*lvalp > LONG_MAX / HZ)
2415 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2417 } else {
2418 int val = *valp;
2419 unsigned long lval;
2420 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002421 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 lval = (unsigned long)-val;
2423 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002424 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 lval = (unsigned long)val;
2426 }
2427 *lvalp = lval / HZ;
2428 }
2429 return 0;
2430}
2431
Amerigo Wang00b7c332010-05-05 00:26:45 +00002432static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 int *valp,
2434 int write, void *data)
2435{
2436 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002437 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2438 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2440 } else {
2441 int val = *valp;
2442 unsigned long lval;
2443 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002444 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 lval = (unsigned long)-val;
2446 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002447 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 lval = (unsigned long)val;
2449 }
2450 *lvalp = jiffies_to_clock_t(lval);
2451 }
2452 return 0;
2453}
2454
Amerigo Wang00b7c332010-05-05 00:26:45 +00002455static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 int *valp,
2457 int write, void *data)
2458{
2459 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002460 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2461
2462 if (jif > INT_MAX)
2463 return 1;
2464 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 } else {
2466 int val = *valp;
2467 unsigned long lval;
2468 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002469 *negp = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 lval = (unsigned long)-val;
2471 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002472 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 lval = (unsigned long)val;
2474 }
2475 *lvalp = jiffies_to_msecs(lval);
2476 }
2477 return 0;
2478}
2479
2480/**
2481 * proc_dointvec_jiffies - read a vector of integers as seconds
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 * @buffer: the user buffer
2485 * @lenp: the size of the user buffer
2486 * @ppos: file position
2487 *
2488 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2489 * values from/to the user buffer, treated as an ASCII string.
2490 * The values read are assumed to be in seconds, and are converted into
2491 * jiffies.
2492 *
2493 * Returns 0 on success.
2494 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002495int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 void __user *buffer, size_t *lenp, loff_t *ppos)
2497{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002498 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 do_proc_dointvec_jiffies_conv,NULL);
2500}
2501
2502/**
2503 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2504 * @table: the sysctl table
2505 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 * @buffer: the user buffer
2507 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002508 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 *
2510 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2511 * values from/to the user buffer, treated as an ASCII string.
2512 * The values read are assumed to be in 1/USER_HZ seconds, and
2513 * are converted into jiffies.
2514 *
2515 * Returns 0 on success.
2516 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002517int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 void __user *buffer, size_t *lenp, loff_t *ppos)
2519{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002520 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 do_proc_dointvec_userhz_jiffies_conv,NULL);
2522}
2523
2524/**
2525 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2526 * @table: the sysctl table
2527 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 * @buffer: the user buffer
2529 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002530 * @ppos: file position
2531 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 *
2533 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2534 * values from/to the user buffer, treated as an ASCII string.
2535 * The values read are assumed to be in 1/1000 seconds, and
2536 * are converted into jiffies.
2537 *
2538 * Returns 0 on success.
2539 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002540int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 void __user *buffer, size_t *lenp, loff_t *ppos)
2542{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002543 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 do_proc_dointvec_ms_jiffies_conv, NULL);
2545}
2546
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002547static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002548 void __user *buffer, size_t *lenp, loff_t *ppos)
2549{
2550 struct pid *new_pid;
2551 pid_t tmp;
2552 int r;
2553
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002554 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002555
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002556 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002557 lenp, ppos, NULL, NULL);
2558 if (r || !write)
2559 return r;
2560
2561 new_pid = find_get_pid(tmp);
2562 if (!new_pid)
2563 return -ESRCH;
2564
2565 put_pid(xchg(&cad_pid, new_pid));
2566 return 0;
2567}
2568
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002569/**
2570 * proc_do_large_bitmap - read/write from/to a large bitmap
2571 * @table: the sysctl table
2572 * @write: %TRUE if this is a write to the sysctl file
2573 * @buffer: the user buffer
2574 * @lenp: the size of the user buffer
2575 * @ppos: file position
2576 *
2577 * The bitmap is stored at table->data and the bitmap length (in bits)
2578 * in table->maxlen.
2579 *
2580 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2581 * large bitmaps may be represented in a compact manner. Writing into
2582 * the file will clear the bitmap then update it with the given input.
2583 *
2584 * Returns 0 on success.
2585 */
2586int proc_do_large_bitmap(struct ctl_table *table, int write,
2587 void __user *buffer, size_t *lenp, loff_t *ppos)
2588{
2589 int err = 0;
2590 bool first = 1;
2591 size_t left = *lenp;
2592 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002593 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002594 unsigned long *tmp_bitmap = NULL;
2595 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2596
WANG Cong122ff242014-05-12 16:04:53 -07002597 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002598 *lenp = 0;
2599 return 0;
2600 }
2601
2602 if (write) {
2603 unsigned long page = 0;
2604 char *kbuf;
2605
2606 if (left > PAGE_SIZE - 1)
2607 left = PAGE_SIZE - 1;
2608
2609 page = __get_free_page(GFP_TEMPORARY);
2610 kbuf = (char *) page;
2611 if (!kbuf)
2612 return -ENOMEM;
2613 if (copy_from_user(kbuf, buffer, left)) {
2614 free_page(page);
2615 return -EFAULT;
2616 }
2617 kbuf[left] = 0;
2618
2619 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2620 GFP_KERNEL);
2621 if (!tmp_bitmap) {
2622 free_page(page);
2623 return -ENOMEM;
2624 }
2625 proc_skip_char(&kbuf, &left, '\n');
2626 while (!err && left) {
2627 unsigned long val_a, val_b;
2628 bool neg;
2629
2630 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2631 sizeof(tr_a), &c);
2632 if (err)
2633 break;
2634 if (val_a >= bitmap_len || neg) {
2635 err = -EINVAL;
2636 break;
2637 }
2638
2639 val_b = val_a;
2640 if (left) {
2641 kbuf++;
2642 left--;
2643 }
2644
2645 if (c == '-') {
2646 err = proc_get_long(&kbuf, &left, &val_b,
2647 &neg, tr_b, sizeof(tr_b),
2648 &c);
2649 if (err)
2650 break;
2651 if (val_b >= bitmap_len || neg ||
2652 val_a > val_b) {
2653 err = -EINVAL;
2654 break;
2655 }
2656 if (left) {
2657 kbuf++;
2658 left--;
2659 }
2660 }
2661
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002662 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002663 first = 0;
2664 proc_skip_char(&kbuf, &left, '\n');
2665 }
2666 free_page(page);
2667 } else {
2668 unsigned long bit_a, bit_b = 0;
2669
2670 while (left) {
2671 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2672 if (bit_a >= bitmap_len)
2673 break;
2674 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2675 bit_a + 1) - 1;
2676
2677 if (!first) {
2678 err = proc_put_char(&buffer, &left, ',');
2679 if (err)
2680 break;
2681 }
2682 err = proc_put_long(&buffer, &left, bit_a, false);
2683 if (err)
2684 break;
2685 if (bit_a != bit_b) {
2686 err = proc_put_char(&buffer, &left, '-');
2687 if (err)
2688 break;
2689 err = proc_put_long(&buffer, &left, bit_b, false);
2690 if (err)
2691 break;
2692 }
2693
2694 first = 0; bit_b++;
2695 }
2696 if (!err)
2697 err = proc_put_char(&buffer, &left, '\n');
2698 }
2699
2700 if (!err) {
2701 if (write) {
2702 if (*ppos)
2703 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2704 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002705 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002706 }
2707 kfree(tmp_bitmap);
2708 *lenp -= left;
2709 *ppos += *lenp;
2710 return 0;
2711 } else {
2712 kfree(tmp_bitmap);
2713 return err;
2714 }
2715}
2716
Jovi Zhang55610502011-01-12 17:00:45 -08002717#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002719int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 void __user *buffer, size_t *lenp, loff_t *ppos)
2721{
2722 return -ENOSYS;
2723}
2724
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002725int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 void __user *buffer, size_t *lenp, loff_t *ppos)
2727{
2728 return -ENOSYS;
2729}
2730
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002731int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 void __user *buffer, size_t *lenp, loff_t *ppos)
2733{
2734 return -ENOSYS;
2735}
2736
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002737int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 void __user *buffer, size_t *lenp, loff_t *ppos)
2739{
2740 return -ENOSYS;
2741}
2742
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002743int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 void __user *buffer, size_t *lenp, loff_t *ppos)
2745{
2746 return -ENOSYS;
2747}
2748
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002749int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 void __user *buffer, size_t *lenp, loff_t *ppos)
2751{
2752 return -ENOSYS;
2753}
2754
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002755int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 void __user *buffer, size_t *lenp, loff_t *ppos)
2757{
2758 return -ENOSYS;
2759}
2760
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002761int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 void __user *buffer,
2763 size_t *lenp, loff_t *ppos)
2764{
2765 return -ENOSYS;
2766}
2767
2768
Jovi Zhang55610502011-01-12 17:00:45 -08002769#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771/*
2772 * No sense putting this after each symbol definition, twice,
2773 * exception granted :-)
2774 */
2775EXPORT_SYMBOL(proc_dointvec);
2776EXPORT_SYMBOL(proc_dointvec_jiffies);
2777EXPORT_SYMBOL(proc_dointvec_minmax);
2778EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2779EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2780EXPORT_SYMBOL(proc_dostring);
2781EXPORT_SYMBOL(proc_doulongvec_minmax);
2782EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);