blob: 35bfe0c1360b793a572bdc541e88c77c90ffa2e5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020033#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#include <asm/uaccess.h>
70#include <asm/processor.h>
71
Andi Kleen29cbc782006-09-30 01:47:55 +020072#ifdef CONFIG_X86
73#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010074#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010075#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020076#endif
David Howellsd550bbd2012-03-28 18:30:03 +010077#ifdef CONFIG_SPARC
78#include <asm/setup.h>
79#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080080#ifdef CONFIG_BSD_PROCESS_ACCT
81#include <linux/acct.h>
82#endif
Dave Young4f0e0562010-03-10 15:24:09 -080083#ifdef CONFIG_RT_MUTEXES
84#include <linux/rtmutex.h>
85#endif
Dave Young2edf5e42010-03-10 15:24:10 -080086#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
87#include <linux/lockdep.h>
88#endif
Dave Young15485a42010-03-10 15:24:07 -080089#ifdef CONFIG_CHR_DEV_SG
90#include <scsi/sg.h>
91#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020092
Don Zickus58687ac2010-05-07 17:11:44 -040093#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050094#include <linux/nmi.h>
95#endif
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#if defined(CONFIG_SYSCTL)
98
99/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700100extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700101#ifdef CONFIG_COREDUMP
102extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700104extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern int pid_max;
Rik van Rielf8ade362011-09-01 15:26:50 -0400107extern int extra_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200110extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100111extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400112extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000113#ifndef CONFIG_MMU
114extern int sysctl_nr_trim_pages;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400118#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int sixty = 60;
120#endif
121
Aaron Tomlin270750db2014-01-20 17:34:13 +0000122static int __maybe_unused neg_one = -1;
123
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700125static int __maybe_unused one = 1;
126static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700127static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800128static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700130#ifdef CONFIG_PRINTK
131static int ten_thousand = 10000;
132#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700133
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700134/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
135static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
138static int maxolduid = 65535;
139static int minolduid;
140
141static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700142static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Liu Hua80df2842014-04-07 15:38:57 -0700144/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
145#ifdef CONFIG_DETECT_HUNG_TASK
146static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
147#endif
148
Dave Youngd14f1722010-02-25 20:28:57 -0500149#ifdef CONFIG_INOTIFY_USER
150#include <linux/inotify.h>
151#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700152#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif
154
155#ifdef __hppa__
156extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530157#endif
158
159#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160extern int unaligned_enabled;
161#endif
162
Jes Sorensend2b176e2006-02-28 09:42:23 -0800163#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800164extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800165#endif
166
Vineet Guptab6fca722013-01-09 20:06:28 +0530167#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
168extern int no_unaligned_warning;
169#endif
170
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700171#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700172
173#define SYSCTL_WRITES_LEGACY -1
174#define SYSCTL_WRITES_WARN 0
175#define SYSCTL_WRITES_STRICT 1
176
177static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
178
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700179static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700180 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700181static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800182 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700183#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700184
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700185#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700186static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700187 void __user *buffer, size_t *lenp, loff_t *ppos);
188#endif
189
Kees Cook54b50192012-07-30 14:39:18 -0700190static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
191 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700192#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700193static int proc_dostring_coredump(struct ctl_table *table, int write,
194 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700195#endif
Kees Cook54b50192012-07-30 14:39:18 -0700196
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700197#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800198/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100199static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700200
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700201static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700202 void __user *buffer, size_t *lenp,
203 loff_t *ppos)
204{
205 int error;
206
207 error = proc_dointvec(table, write, buffer, lenp, ppos);
208 if (error)
209 return error;
210
211 if (write)
212 sysrq_toggle_support(__sysrq_enabled);
213
214 return 0;
215}
216
217#endif
218
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700219static struct ctl_table kern_table[];
220static struct ctl_table vm_table[];
221static struct ctl_table fs_table[];
222static struct ctl_table debug_table[];
223static struct ctl_table dev_table[];
224extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800225#ifdef CONFIG_EPOLL
226extern struct ctl_table epoll_table[];
227#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
230int sysctl_legacy_va_layout;
231#endif
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233/* The default sysctl tables: */
234
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800235static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 .procname = "kernel",
238 .mode = 0555,
239 .child = kern_table,
240 },
241 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 .procname = "vm",
243 .mode = 0555,
244 .child = vm_table,
245 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 .procname = "fs",
248 .mode = 0555,
249 .child = fs_table,
250 },
251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 .procname = "debug",
253 .mode = 0555,
254 .child = debug_table,
255 },
256 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 .procname = "dev",
258 .mode = 0555,
259 .child = dev_table,
260 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700261 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262};
263
Ingo Molnar77e54a12007-07-09 18:52:00 +0200264#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100265static int min_sched_granularity_ns = 100000; /* 100 usecs */
266static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
267static int min_wakeup_granularity_ns; /* 0 usecs */
268static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200269#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100270static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
271static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200272#endif /* CONFIG_SMP */
273#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200274
Mel Gorman5e771902010-05-24 14:32:31 -0700275#ifdef CONFIG_COMPACTION
276static int min_extfrag_threshold;
277static int max_extfrag_threshold = 1000;
278#endif
279
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700280static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200281 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800286 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200287 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200288#ifdef CONFIG_SCHED_DEBUG
289 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100290 .procname = "sched_min_granularity_ns",
291 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800294 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200297 },
298 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200299 .procname = "sched_latency_ns",
300 .data = &sysctl_sched_latency,
301 .maxlen = sizeof(unsigned int),
302 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800303 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200304 .extra1 = &min_sched_granularity_ns,
305 .extra2 = &max_sched_granularity_ns,
306 },
307 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200308 .procname = "sched_wakeup_granularity_ns",
309 .data = &sysctl_sched_wakeup_granularity,
310 .maxlen = sizeof(unsigned int),
311 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800312 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200313 .extra1 = &min_wakeup_granularity_ns,
314 .extra2 = &max_wakeup_granularity_ns,
315 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200316#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200317 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100318 .procname = "sched_tunable_scaling",
319 .data = &sysctl_sched_tunable_scaling,
320 .maxlen = sizeof(enum sched_tunable_scaling),
321 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800322 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100323 .extra1 = &min_sched_tunable_scaling,
324 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200325 },
326 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900327 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200328 .data = &sysctl_sched_migration_cost,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800331 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200332 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100333 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100334 .procname = "sched_nr_migrate",
335 .data = &sysctl_sched_nr_migrate,
336 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100337 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800338 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100339 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530340 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900341 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200342 .data = &sysctl_sched_time_avg,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800345 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200346 },
347 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900348 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800349 .data = &sysctl_sched_shares_window,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec,
353 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200354#endif /* CONFIG_SMP */
355#ifdef CONFIG_NUMA_BALANCING
356 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200357 .procname = "numa_balancing_scan_delay_ms",
358 .data = &sysctl_numa_balancing_scan_delay,
359 .maxlen = sizeof(unsigned int),
360 .mode = 0644,
361 .proc_handler = proc_dointvec,
362 },
363 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200364 .procname = "numa_balancing_scan_period_min_ms",
365 .data = &sysctl_numa_balancing_scan_period_min,
366 .maxlen = sizeof(unsigned int),
367 .mode = 0644,
368 .proc_handler = proc_dointvec,
369 },
370 {
371 .procname = "numa_balancing_scan_period_max_ms",
372 .data = &sysctl_numa_balancing_scan_period_max,
373 .maxlen = sizeof(unsigned int),
374 .mode = 0644,
375 .proc_handler = proc_dointvec,
376 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200377 {
378 .procname = "numa_balancing_scan_size_mb",
379 .data = &sysctl_numa_balancing_scan_size,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400382 .proc_handler = proc_dointvec_minmax,
383 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200384 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100385 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800386 .procname = "numa_balancing",
387 .data = NULL, /* filled in by handler */
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
390 .proc_handler = sysctl_numa_balancing,
391 .extra1 = &zero,
392 .extra2 = &one,
393 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200394#endif /* CONFIG_NUMA_BALANCING */
395#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200396 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100397 .procname = "sched_rt_period_us",
398 .data = &sysctl_sched_rt_period,
399 .maxlen = sizeof(unsigned int),
400 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800401 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100402 },
403 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100404 .procname = "sched_rt_runtime_us",
405 .data = &sysctl_sched_rt_runtime,
406 .maxlen = sizeof(int),
407 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800408 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100409 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600410 {
411 .procname = "sched_rr_timeslice_ms",
412 .data = &sched_rr_timeslice,
413 .maxlen = sizeof(int),
414 .mode = 0644,
415 .proc_handler = sched_rr_handler,
416 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100417#ifdef CONFIG_SCHED_AUTOGROUP
418 {
419 .procname = "sched_autogroup_enabled",
420 .data = &sysctl_sched_autogroup_enabled,
421 .maxlen = sizeof(unsigned int),
422 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800423 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100424 .extra1 = &zero,
425 .extra2 = &one,
426 },
427#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700428#ifdef CONFIG_CFS_BANDWIDTH
429 {
430 .procname = "sched_cfs_bandwidth_slice_us",
431 .data = &sysctl_sched_cfs_bandwidth_slice,
432 .maxlen = sizeof(unsigned int),
433 .mode = 0644,
434 .proc_handler = proc_dointvec_minmax,
435 .extra1 = &one,
436 },
437#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700438#ifdef CONFIG_PROVE_LOCKING
439 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700440 .procname = "prove_locking",
441 .data = &prove_locking,
442 .maxlen = sizeof(int),
443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800444 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700445 },
446#endif
447#ifdef CONFIG_LOCK_STAT
448 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700449 .procname = "lock_stat",
450 .data = &lock_stat,
451 .maxlen = sizeof(int),
452 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800453 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700454 },
455#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200456 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 .procname = "panic",
458 .data = &panic_timeout,
459 .maxlen = sizeof(int),
460 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800461 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 },
Alex Kelly046d6622012-10-04 17:15:23 -0700463#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 .procname = "core_uses_pid",
466 .data = &core_uses_pid,
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 },
471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 .procname = "core_pattern",
473 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700474 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700476 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 },
Neil Hormana2939802009-09-23 15:56:56 -0700478 {
Neil Hormana2939802009-09-23 15:56:56 -0700479 .procname = "core_pipe_limit",
480 .data = &core_pipe_limit,
481 .maxlen = sizeof(unsigned int),
482 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800483 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700484 },
Alex Kelly046d6622012-10-04 17:15:23 -0700485#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800486#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700489 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700493 {
494 .procname = "sysctl_writes_strict",
495 .data = &sysctl_writes_strict,
496 .maxlen = sizeof(int),
497 .mode = 0644,
498 .proc_handler = proc_dointvec_minmax,
499 .extra1 = &neg_one,
500 .extra2 = &one,
501 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800502#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100503#ifdef CONFIG_LATENCYTOP
504 {
505 .procname = "latencytop",
506 .data = &latencytop_enabled,
507 .maxlen = sizeof(int),
508 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800509 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100510 },
511#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#ifdef CONFIG_BLK_DEV_INITRD
513 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 .procname = "real-root-dev",
515 .data = &real_root_dev,
516 .maxlen = sizeof(int),
517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800518 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 },
520#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700521 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700522 .procname = "print-fatal-signals",
523 .data = &print_fatal_signals,
524 .maxlen = sizeof(int),
525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700527 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700528#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 .procname = "reboot-cmd",
531 .data = reboot_command,
532 .maxlen = 256,
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 },
536 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 .procname = "stop-a",
538 .data = &stop_a_enabled,
539 .maxlen = sizeof (int),
540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800541 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 },
543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .procname = "scons-poweroff",
545 .data = &scons_pwroff,
546 .maxlen = sizeof (int),
547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800548 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 },
550#endif
David S. Miller08714202008-11-16 23:49:24 -0800551#ifdef CONFIG_SPARC64
552 {
David S. Miller08714202008-11-16 23:49:24 -0800553 .procname = "tsb-ratio",
554 .data = &sysctl_tsb_ratio,
555 .maxlen = sizeof (int),
556 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800557 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800558 },
559#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#ifdef __hppa__
561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .procname = "soft-power",
563 .data = &pwrsw_enabled,
564 .maxlen = sizeof (int),
565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800566 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530568#endif
569#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 .procname = "unaligned-trap",
572 .data = &unaligned_enabled,
573 .maxlen = sizeof (int),
574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800575 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 },
577#endif
578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "ctrl-alt-del",
580 .data = &C_A_D,
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 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400585#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200586 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200587 .procname = "ftrace_enabled",
588 .data = &ftrace_enabled,
589 .maxlen = sizeof(int),
590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800591 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200592 },
593#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500594#ifdef CONFIG_STACK_TRACER
595 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500596 .procname = "stack_tracer_enabled",
597 .data = &stack_tracer_enabled,
598 .maxlen = sizeof(int),
599 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800600 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500601 },
602#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400603#ifdef CONFIG_TRACING
604 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100605 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400606 .data = &ftrace_dump_on_oops,
607 .maxlen = sizeof(int),
608 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800609 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400610 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400611 {
612 .procname = "traceoff_on_warning",
613 .data = &__disable_trace_on_warning,
614 .maxlen = sizeof(__disable_trace_on_warning),
615 .mode = 0644,
616 .proc_handler = proc_dointvec,
617 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500618 {
619 .procname = "tracepoint_printk",
620 .data = &tracepoint_printk,
621 .maxlen = sizeof(tracepoint_printk),
622 .mode = 0644,
623 .proc_handler = proc_dointvec,
624 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400625#endif
Dave Young2965faa2015-09-09 15:38:55 -0700626#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800627 {
628 .procname = "kexec_load_disabled",
629 .data = &kexec_load_disabled,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 /* only handle a transition from default "0" to "1" */
633 .proc_handler = proc_dointvec_minmax,
634 .extra1 = &one,
635 .extra2 = &one,
636 },
637#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200638#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 .procname = "modprobe",
641 .data = &modprobe_path,
642 .maxlen = KMOD_PATH_LEN,
643 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800644 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 },
Kees Cook3d433212009-04-02 15:49:29 -0700646 {
Kees Cook3d433212009-04-02 15:49:29 -0700647 .procname = "modules_disabled",
648 .data = &modules_disabled,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800652 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700653 .extra1 = &one,
654 .extra2 = &one,
655 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700657#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100660 .data = &uevent_helper,
661 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800663 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 },
Michael Marineau86d56132014-04-10 14:09:31 -0700665#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666#ifdef CONFIG_CHR_DEV_SG
667 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 .procname = "sg-big-buff",
669 .data = &sg_big_buff,
670 .maxlen = sizeof (int),
671 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800672 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 },
674#endif
675#ifdef CONFIG_BSD_PROCESS_ACCT
676 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .procname = "acct",
678 .data = &acct_parm,
679 .maxlen = 3*sizeof(int),
680 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800681 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 },
683#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684#ifdef CONFIG_MAGIC_SYSRQ
685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800687 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .maxlen = sizeof (int),
689 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700690 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 },
692#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700693#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700696 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .maxlen = sizeof (int),
698 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800699 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700701#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700704 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .maxlen = sizeof(int),
706 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700707 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 },
709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .procname = "random",
711 .mode = 0555,
712 .child = random_table,
713 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 {
Eric Paris17f60a72011-04-01 17:07:50 -0400715 .procname = "usermodehelper",
716 .mode = 0555,
717 .child = usermodehelper_table,
718 },
719 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 .procname = "overflowuid",
721 .data = &overflowuid,
722 .maxlen = sizeof(int),
723 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800724 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .extra1 = &minolduid,
726 .extra2 = &maxolduid,
727 },
728 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .procname = "overflowgid",
730 .data = &overflowgid,
731 .maxlen = sizeof(int),
732 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800733 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .extra1 = &minolduid,
735 .extra2 = &maxolduid,
736 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800737#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738#ifdef CONFIG_MATHEMU
739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .procname = "ieee_emulation_warnings",
741 .data = &sysctl_ieee_emulation_warnings,
742 .maxlen = sizeof(int),
743 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800744 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 },
746#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200749 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .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
755 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 .procname = "pid_max",
757 .data = &pid_max,
758 .maxlen = sizeof (int),
759 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800760 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 .extra1 = &pid_max_min,
762 .extra2 = &pid_max_max,
763 },
764 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 .procname = "panic_on_oops",
766 .data = &panic_on_oops,
767 .maxlen = sizeof(int),
768 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800769 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800771#if defined CONFIG_PRINTK
772 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800773 .procname = "printk",
774 .data = &console_loglevel,
775 .maxlen = 4*sizeof(int),
776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800777 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800778 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700781 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 .maxlen = sizeof(int),
783 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800784 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 },
786 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700788 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .maxlen = sizeof(int),
790 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 },
Dave Youngaf913222009-09-22 16:43:33 -0700793 {
Dave Youngaf913222009-09-22 16:43:33 -0700794 .procname = "printk_delay",
795 .data = &printk_delay_msec,
796 .maxlen = sizeof(int),
797 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800798 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700799 .extra1 = &zero,
800 .extra2 = &ten_thousand,
801 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800803 .procname = "dmesg_restrict",
804 .data = &dmesg_restrict,
805 .maxlen = sizeof(int),
806 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700807 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800808 .extra1 = &zero,
809 .extra2 = &one,
810 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800811 {
812 .procname = "kptr_restrict",
813 .data = &kptr_restrict,
814 .maxlen = sizeof(int),
815 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700816 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800817 .extra1 = &zero,
818 .extra2 = &two,
819 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800820#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800821 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 .procname = "ngroups_max",
823 .data = &ngroups_max,
824 .maxlen = sizeof (int),
825 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800826 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 },
Dan Ballard73efc032011-10-31 17:11:20 -0700828 {
829 .procname = "cap_last_cap",
830 .data = (void *)&cap_last_cap,
831 .maxlen = sizeof(int),
832 .mode = 0444,
833 .proc_handler = proc_dointvec,
834 },
Don Zickus58687ac2010-05-07 17:11:44 -0400835#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500836 {
Don Zickus58687ac2010-05-07 17:11:44 -0400837 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200838 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500839 .maxlen = sizeof (int),
840 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700841 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700842 .extra1 = &zero,
843 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400844 },
845 {
846 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700847 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400848 .maxlen = sizeof(int),
849 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700850 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800851 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400852 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500853 },
Don Zickus2508ce12010-05-07 17:11:46 -0400854 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700855 .procname = "nmi_watchdog",
856 .data = &nmi_watchdog_enabled,
857 .maxlen = sizeof (int),
858 .mode = 0644,
859 .proc_handler = proc_nmi_watchdog,
860 .extra1 = &zero,
861#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
862 .extra2 = &one,
863#else
864 .extra2 = &zero,
865#endif
866 },
867 {
868 .procname = "soft_watchdog",
869 .data = &soft_watchdog_enabled,
870 .maxlen = sizeof (int),
871 .mode = 0644,
872 .proc_handler = proc_soft_watchdog,
873 .extra1 = &zero,
874 .extra2 = &one,
875 },
876 {
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700877 .procname = "watchdog_cpumask",
878 .data = &watchdog_cpumask_bits,
879 .maxlen = NR_CPUS,
880 .mode = 0644,
881 .proc_handler = proc_watchdog_cpumask,
882 },
883 {
Don Zickus2508ce12010-05-07 17:11:46 -0400884 .procname = "softlockup_panic",
885 .data = &softlockup_panic,
886 .maxlen = sizeof(int),
887 .mode = 0644,
888 .proc_handler = proc_dointvec_minmax,
889 .extra1 = &zero,
890 .extra2 = &one,
891 },
Don Zickusac1f5912015-11-05 18:44:44 -0800892#ifdef CONFIG_HARDLOCKUP_DETECTOR
893 {
894 .procname = "hardlockup_panic",
895 .data = &hardlockup_panic,
896 .maxlen = sizeof(int),
897 .mode = 0644,
898 .proc_handler = proc_dointvec_minmax,
899 .extra1 = &zero,
900 .extra2 = &one,
901 },
902#endif
Aaron Tomlined235872014-06-23 13:22:05 -0700903#ifdef CONFIG_SMP
904 {
905 .procname = "softlockup_all_cpu_backtrace",
906 .data = &sysctl_softlockup_all_cpu_backtrace,
907 .maxlen = sizeof(int),
908 .mode = 0644,
909 .proc_handler = proc_dointvec_minmax,
910 .extra1 = &zero,
911 .extra2 = &one,
912 },
Jiri Kosina55537872015-11-05 18:44:41 -0800913 {
914 .procname = "hardlockup_all_cpu_backtrace",
915 .data = &sysctl_hardlockup_all_cpu_backtrace,
916 .maxlen = sizeof(int),
917 .mode = 0644,
918 .proc_handler = proc_dointvec_minmax,
919 .extra1 = &zero,
920 .extra2 = &one,
921 },
Aaron Tomlined235872014-06-23 13:22:05 -0700922#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500923#endif
924#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
925 {
926 .procname = "unknown_nmi_panic",
927 .data = &unknown_nmi_panic,
928 .maxlen = sizeof (int),
929 .mode = 0644,
930 .proc_handler = proc_dointvec,
931 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500932#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933#if defined(CONFIG_X86)
934 {
Don Zickus8da5add2006-09-26 10:52:27 +0200935 .procname = "panic_on_unrecovered_nmi",
936 .data = &panic_on_unrecovered_nmi,
937 .maxlen = sizeof(int),
938 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800939 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200940 },
941 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700942 .procname = "panic_on_io_nmi",
943 .data = &panic_on_io_nmi,
944 .maxlen = sizeof(int),
945 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800946 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700947 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900948#ifdef CONFIG_DEBUG_STACKOVERFLOW
949 {
950 .procname = "panic_on_stackoverflow",
951 .data = &sysctl_panic_on_stackoverflow,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = proc_dointvec,
955 },
956#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700957 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 .procname = "bootloader_type",
959 .data = &bootloader_type,
960 .maxlen = sizeof (int),
961 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800962 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100964 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700965 .procname = "bootloader_version",
966 .data = &bootloader_version,
967 .maxlen = sizeof (int),
968 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800969 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700970 },
971 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100972 .procname = "kstack_depth_to_print",
973 .data = &kstack_depth_to_print,
974 .maxlen = sizeof(int),
975 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800976 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100977 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100978 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100979 .procname = "io_delay_type",
980 .data = &io_delay_type,
981 .maxlen = sizeof(int),
982 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800983 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100984 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800986#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 .procname = "randomize_va_space",
989 .data = &randomize_va_space,
990 .maxlen = sizeof(int),
991 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800992 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800994#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800995#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700996 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700997 .procname = "spin_retry",
998 .data = &spin_retry,
999 .maxlen = sizeof (int),
1000 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001001 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001002 },
1003#endif
Len Brown673d5b42007-07-28 03:33:16 -04001004#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001005 {
Pavel Machekc255d842006-02-20 18:27:58 -08001006 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001007 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001008 .maxlen = sizeof (unsigned long),
1009 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001010 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001011 },
1012#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301013#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001014 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001015 .procname = "ignore-unaligned-usertrap",
1016 .data = &no_unaligned_warning,
1017 .maxlen = sizeof (int),
1018 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001019 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001020 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301021#endif
1022#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001023 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001024 .procname = "unaligned-dump-stack",
1025 .data = &unaligned_dump_stack,
1026 .maxlen = sizeof (int),
1027 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001028 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001029 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001030#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001031#ifdef CONFIG_DETECT_HUNG_TASK
1032 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001033 .procname = "hung_task_panic",
1034 .data = &sysctl_hung_task_panic,
1035 .maxlen = sizeof(int),
1036 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001037 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001038 .extra1 = &zero,
1039 .extra2 = &one,
1040 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001041 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001042 .procname = "hung_task_check_count",
1043 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001044 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001045 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001046 .proc_handler = proc_dointvec_minmax,
1047 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001048 },
1049 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001050 .procname = "hung_task_timeout_secs",
1051 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001052 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001053 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001054 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001055 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001056 },
1057 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001058 .procname = "hung_task_warnings",
1059 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001060 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001061 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001062 .proc_handler = proc_dointvec_minmax,
1063 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001064 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001065#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001066#ifdef CONFIG_COMPAT
1067 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001068 .procname = "compat-log",
1069 .data = &compat_log,
1070 .maxlen = sizeof (int),
1071 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001072 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001073 },
1074#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -07001075#ifdef CONFIG_RT_MUTEXES
1076 {
Ingo Molnar23f78d42006-06-27 02:54:53 -07001077 .procname = "max_lock_depth",
1078 .data = &max_lock_depth,
1079 .maxlen = sizeof(int),
1080 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001081 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -07001082 },
1083#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001084 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001085 .procname = "poweroff_cmd",
1086 .data = &poweroff_cmd,
1087 .maxlen = POWEROFF_CMD_PATH_LEN,
1088 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001089 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001090 },
David Howells0b77f5b2008-04-29 01:01:32 -07001091#ifdef CONFIG_KEYS
1092 {
David Howells0b77f5b2008-04-29 01:01:32 -07001093 .procname = "keys",
1094 .mode = 0555,
1095 .child = key_sysctls,
1096 },
1097#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001098#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001099 /*
1100 * User-space scripts rely on the existence of this file
1101 * as a feature check for perf_events being enabled.
1102 *
1103 * So it's an ABI, do not remove!
1104 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001105 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001106 .procname = "perf_event_paranoid",
1107 .data = &sysctl_perf_event_paranoid,
1108 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001109 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001110 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001111 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001112 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001113 .procname = "perf_event_mlock_kb",
1114 .data = &sysctl_perf_event_mlock,
1115 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001116 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001117 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001118 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001119 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001120 .procname = "perf_event_max_sample_rate",
1121 .data = &sysctl_perf_event_sample_rate,
1122 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001123 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001124 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001125 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001126 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001127 {
1128 .procname = "perf_cpu_time_max_percent",
1129 .data = &sysctl_perf_cpu_time_max_percent,
1130 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1131 .mode = 0644,
1132 .proc_handler = perf_cpu_time_max_percent_handler,
1133 .extra1 = &zero,
1134 .extra2 = &one_hundred,
1135 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001136#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001137#ifdef CONFIG_KMEMCHECK
1138 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001139 .procname = "kmemcheck",
1140 .data = &kmemcheck_enabled,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001143 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001144 },
1145#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001146 {
1147 .procname = "panic_on_warn",
1148 .data = &panic_on_warn,
1149 .maxlen = sizeof(int),
1150 .mode = 0644,
1151 .proc_handler = proc_dointvec_minmax,
1152 .extra1 = &zero,
1153 .extra2 = &one,
1154 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001155#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1156 {
1157 .procname = "timer_migration",
1158 .data = &sysctl_timer_migration,
1159 .maxlen = sizeof(unsigned int),
1160 .mode = 0644,
1161 .proc_handler = timer_migration_handler,
1162 },
1163#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001164#ifdef CONFIG_BPF_SYSCALL
1165 {
1166 .procname = "unprivileged_bpf_disabled",
1167 .data = &sysctl_unprivileged_bpf_disabled,
1168 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1169 .mode = 0644,
1170 /* only handle a transition from default "0" to "1" */
1171 .proc_handler = proc_dointvec_minmax,
1172 .extra1 = &one,
1173 .extra2 = &one,
1174 },
1175#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001176 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177};
1178
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001179static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 .procname = "overcommit_memory",
1182 .data = &sysctl_overcommit_memory,
1183 .maxlen = sizeof(sysctl_overcommit_memory),
1184 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001185 .proc_handler = proc_dointvec_minmax,
1186 .extra1 = &zero,
1187 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 },
1189 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001190 .procname = "panic_on_oom",
1191 .data = &sysctl_panic_on_oom,
1192 .maxlen = sizeof(sysctl_panic_on_oom),
1193 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001194 .proc_handler = proc_dointvec_minmax,
1195 .extra1 = &zero,
1196 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001197 },
1198 {
David Rientjesfe071d72007-10-16 23:25:56 -07001199 .procname = "oom_kill_allocating_task",
1200 .data = &sysctl_oom_kill_allocating_task,
1201 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1202 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001203 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001204 },
1205 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001206 .procname = "oom_dump_tasks",
1207 .data = &sysctl_oom_dump_tasks,
1208 .maxlen = sizeof(sysctl_oom_dump_tasks),
1209 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001210 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001211 },
1212 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 .procname = "overcommit_ratio",
1214 .data = &sysctl_overcommit_ratio,
1215 .maxlen = sizeof(sysctl_overcommit_ratio),
1216 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001217 .proc_handler = overcommit_ratio_handler,
1218 },
1219 {
1220 .procname = "overcommit_kbytes",
1221 .data = &sysctl_overcommit_kbytes,
1222 .maxlen = sizeof(sysctl_overcommit_kbytes),
1223 .mode = 0644,
1224 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 },
1226 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 .procname = "page-cluster",
1228 .data = &page_cluster,
1229 .maxlen = sizeof(int),
1230 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001231 .proc_handler = proc_dointvec_minmax,
1232 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 },
1234 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 .procname = "dirty_background_ratio",
1236 .data = &dirty_background_ratio,
1237 .maxlen = sizeof(dirty_background_ratio),
1238 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001239 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 .extra1 = &zero,
1241 .extra2 = &one_hundred,
1242 },
1243 {
David Rientjes2da02992009-01-06 14:39:31 -08001244 .procname = "dirty_background_bytes",
1245 .data = &dirty_background_bytes,
1246 .maxlen = sizeof(dirty_background_bytes),
1247 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001248 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001249 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001250 },
1251 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 .procname = "dirty_ratio",
1253 .data = &vm_dirty_ratio,
1254 .maxlen = sizeof(vm_dirty_ratio),
1255 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001256 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 .extra1 = &zero,
1258 .extra2 = &one_hundred,
1259 },
1260 {
David Rientjes2da02992009-01-06 14:39:31 -08001261 .procname = "dirty_bytes",
1262 .data = &vm_dirty_bytes,
1263 .maxlen = sizeof(vm_dirty_bytes),
1264 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001265 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001266 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001267 },
1268 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001270 .data = &dirty_writeback_interval,
1271 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001273 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 },
1275 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001277 .data = &dirty_expire_interval,
1278 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001280 .proc_handler = proc_dointvec_minmax,
1281 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 },
1283 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001284 .procname = "dirtytime_expire_seconds",
1285 .data = &dirtytime_expire_interval,
1286 .maxlen = sizeof(dirty_expire_interval),
1287 .mode = 0644,
1288 .proc_handler = dirtytime_interval_handler,
1289 .extra1 = &zero,
1290 },
1291 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001292 .procname = "nr_pdflush_threads",
1293 .mode = 0444 /* read-only */,
1294 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 },
1296 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 .procname = "swappiness",
1298 .data = &vm_swappiness,
1299 .maxlen = sizeof(vm_swappiness),
1300 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001301 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 .extra1 = &zero,
1303 .extra2 = &one_hundred,
1304 },
1305#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001306 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001308 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 .maxlen = sizeof(unsigned long),
1310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001311 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001312 },
1313#ifdef CONFIG_NUMA
1314 {
1315 .procname = "nr_hugepages_mempolicy",
1316 .data = NULL,
1317 .maxlen = sizeof(unsigned long),
1318 .mode = 0644,
1319 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001320 },
1321#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 .procname = "hugetlb_shm_group",
1324 .data = &sysctl_hugetlb_shm_group,
1325 .maxlen = sizeof(gid_t),
1326 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001327 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 },
Mel Gorman396faf02007-07-17 04:03:13 -07001329 {
Mel Gorman396faf02007-07-17 04:03:13 -07001330 .procname = "hugepages_treat_as_movable",
1331 .data = &hugepages_treat_as_movable,
1332 .maxlen = sizeof(int),
1333 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001334 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001335 },
Adam Litke54f9f802007-10-16 01:26:20 -07001336 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001337 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001338 .data = NULL,
1339 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001340 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001341 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001342 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343#endif
1344 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 .procname = "lowmem_reserve_ratio",
1346 .data = &sysctl_lowmem_reserve_ratio,
1347 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001349 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 },
1351 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001352 .procname = "drop_caches",
1353 .data = &sysctl_drop_caches,
1354 .maxlen = sizeof(int),
1355 .mode = 0644,
1356 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001357 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001358 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001359 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001360#ifdef CONFIG_COMPACTION
1361 {
1362 .procname = "compact_memory",
1363 .data = &sysctl_compact_memory,
1364 .maxlen = sizeof(int),
1365 .mode = 0200,
1366 .proc_handler = sysctl_compaction_handler,
1367 },
Mel Gorman5e771902010-05-24 14:32:31 -07001368 {
1369 .procname = "extfrag_threshold",
1370 .data = &sysctl_extfrag_threshold,
1371 .maxlen = sizeof(int),
1372 .mode = 0644,
1373 .proc_handler = sysctl_extfrag_handler,
1374 .extra1 = &min_extfrag_threshold,
1375 .extra2 = &max_extfrag_threshold,
1376 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001377 {
1378 .procname = "compact_unevictable_allowed",
1379 .data = &sysctl_compact_unevictable_allowed,
1380 .maxlen = sizeof(int),
1381 .mode = 0644,
1382 .proc_handler = proc_dointvec,
1383 .extra1 = &zero,
1384 .extra2 = &one,
1385 },
Mel Gorman5e771902010-05-24 14:32:31 -07001386
Mel Gorman76ab0f52010-05-24 14:32:28 -07001387#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001388 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 .procname = "min_free_kbytes",
1390 .data = &min_free_kbytes,
1391 .maxlen = sizeof(min_free_kbytes),
1392 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001393 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 .extra1 = &zero,
1395 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001396 {
Rik van Rielf8ade362011-09-01 15:26:50 -04001397 .procname = "extra_free_kbytes",
1398 .data = &extra_free_kbytes,
1399 .maxlen = sizeof(extra_free_kbytes),
1400 .mode = 0644,
1401 .proc_handler = min_free_kbytes_sysctl_handler,
1402 .extra1 = &zero,
1403 },
1404 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001405 .procname = "percpu_pagelist_fraction",
1406 .data = &percpu_pagelist_fraction,
1407 .maxlen = sizeof(percpu_pagelist_fraction),
1408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001409 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001410 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001411 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412#ifdef CONFIG_MMU
1413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .procname = "max_map_count",
1415 .data = &sysctl_max_map_count,
1416 .maxlen = sizeof(sysctl_max_map_count),
1417 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001418 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001419 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001421#else
1422 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001423 .procname = "nr_trim_pages",
1424 .data = &sysctl_nr_trim_pages,
1425 .maxlen = sizeof(sysctl_nr_trim_pages),
1426 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001427 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001428 .extra1 = &zero,
1429 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430#endif
1431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 .procname = "laptop_mode",
1433 .data = &laptop_mode,
1434 .maxlen = sizeof(laptop_mode),
1435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001436 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 },
1438 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 .procname = "block_dump",
1440 .data = &block_dump,
1441 .maxlen = sizeof(block_dump),
1442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001443 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 .extra1 = &zero,
1445 },
1446 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 .procname = "vfs_cache_pressure",
1448 .data = &sysctl_vfs_cache_pressure,
1449 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001451 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 .extra1 = &zero,
1453 },
1454#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 .procname = "legacy_va_layout",
1457 .data = &sysctl_legacy_va_layout,
1458 .maxlen = sizeof(sysctl_legacy_va_layout),
1459 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001460 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 .extra1 = &zero,
1462 },
1463#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001464#ifdef CONFIG_NUMA
1465 {
Christoph Lameter17436602006-01-18 17:42:32 -08001466 .procname = "zone_reclaim_mode",
1467 .data = &zone_reclaim_mode,
1468 .maxlen = sizeof(zone_reclaim_mode),
1469 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001470 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001471 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001472 },
Christoph Lameter96146342006-07-03 00:24:13 -07001473 {
Christoph Lameter96146342006-07-03 00:24:13 -07001474 .procname = "min_unmapped_ratio",
1475 .data = &sysctl_min_unmapped_ratio,
1476 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001478 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001479 .extra1 = &zero,
1480 .extra2 = &one_hundred,
1481 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001482 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001483 .procname = "min_slab_ratio",
1484 .data = &sysctl_min_slab_ratio,
1485 .maxlen = sizeof(sysctl_min_slab_ratio),
1486 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001487 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001488 .extra1 = &zero,
1489 .extra2 = &one_hundred,
1490 },
Christoph Lameter17436602006-01-18 17:42:32 -08001491#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001492#ifdef CONFIG_SMP
1493 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001494 .procname = "stat_interval",
1495 .data = &sysctl_stat_interval,
1496 .maxlen = sizeof(sysctl_stat_interval),
1497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001498 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001499 },
1500#endif
David Howells6e141542009-12-15 19:27:45 +00001501#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001502 {
Eric Parised032182007-06-28 15:55:21 -04001503 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001504 .data = &dac_mmap_min_addr,
1505 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001506 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001507 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001508 },
David Howells6e141542009-12-15 19:27:45 +00001509#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001510#ifdef CONFIG_NUMA
1511 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001512 .procname = "numa_zonelist_order",
1513 .data = &numa_zonelist_order,
1514 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1515 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001516 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001517 },
1518#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001519#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001520 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001521 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001522 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001523#ifdef CONFIG_X86_32
1524 .data = &vdso32_enabled,
1525 .maxlen = sizeof(vdso32_enabled),
1526#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001527 .data = &vdso_enabled,
1528 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001529#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001531 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001532 .extra1 = &zero,
1533 },
1534#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001535#ifdef CONFIG_HIGHMEM
1536 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001537 .procname = "highmem_is_dirtyable",
1538 .data = &vm_highmem_is_dirtyable,
1539 .maxlen = sizeof(vm_highmem_is_dirtyable),
1540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001541 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001542 .extra1 = &zero,
1543 .extra2 = &one,
1544 },
1545#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001546#ifdef CONFIG_MEMORY_FAILURE
1547 {
Andi Kleen6a460792009-09-16 11:50:15 +02001548 .procname = "memory_failure_early_kill",
1549 .data = &sysctl_memory_failure_early_kill,
1550 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1551 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001552 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001553 .extra1 = &zero,
1554 .extra2 = &one,
1555 },
1556 {
Andi Kleen6a460792009-09-16 11:50:15 +02001557 .procname = "memory_failure_recovery",
1558 .data = &sysctl_memory_failure_recovery,
1559 .maxlen = sizeof(sysctl_memory_failure_recovery),
1560 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001561 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001562 .extra1 = &zero,
1563 .extra2 = &one,
1564 },
1565#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001566 {
1567 .procname = "user_reserve_kbytes",
1568 .data = &sysctl_user_reserve_kbytes,
1569 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1570 .mode = 0644,
1571 .proc_handler = proc_doulongvec_minmax,
1572 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001573 {
1574 .procname = "admin_reserve_kbytes",
1575 .data = &sysctl_admin_reserve_kbytes,
1576 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1577 .mode = 0644,
1578 .proc_handler = proc_doulongvec_minmax,
1579 },
dcashmand49d8872016-01-12 09:18:57 -08001580#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1581 {
1582 .procname = "mmap_rnd_bits",
1583 .data = &mmap_rnd_bits,
1584 .maxlen = sizeof(mmap_rnd_bits),
1585 .mode = 0600,
1586 .proc_handler = proc_dointvec_minmax,
1587 .extra1 = (void *)&mmap_rnd_bits_min,
1588 .extra2 = (void *)&mmap_rnd_bits_max,
1589 },
1590#endif
1591#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1592 {
1593 .procname = "mmap_rnd_compat_bits",
1594 .data = &mmap_rnd_compat_bits,
1595 .maxlen = sizeof(mmap_rnd_compat_bits),
1596 .mode = 0600,
1597 .proc_handler = proc_dointvec_minmax,
1598 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1599 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1600 },
1601#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001602 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603};
1604
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001605static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 .procname = "inode-nr",
1608 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001609 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001611 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 },
1613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 .procname = "inode-state",
1615 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001616 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001618 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 },
1620 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 .procname = "file-nr",
1622 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001623 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001625 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 },
1627 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 .procname = "file-max",
1629 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001630 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001632 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 },
1634 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001635 .procname = "nr_open",
1636 .data = &sysctl_nr_open,
1637 .maxlen = sizeof(int),
1638 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001639 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001640 .extra1 = &sysctl_nr_open_min,
1641 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001642 },
1643 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 .procname = "dentry-state",
1645 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001646 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001648 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 },
1650 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 .procname = "overflowuid",
1652 .data = &fs_overflowuid,
1653 .maxlen = sizeof(int),
1654 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001655 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 .extra1 = &minolduid,
1657 .extra2 = &maxolduid,
1658 },
1659 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 .procname = "overflowgid",
1661 .data = &fs_overflowgid,
1662 .maxlen = sizeof(int),
1663 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001664 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 .extra1 = &minolduid,
1666 .extra2 = &maxolduid,
1667 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001668#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 .procname = "leases-enable",
1671 .data = &leases_enable,
1672 .maxlen = sizeof(int),
1673 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001674 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001676#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677#ifdef CONFIG_DNOTIFY
1678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 .procname = "dir-notify-enable",
1680 .data = &dir_notify_enable,
1681 .maxlen = sizeof(int),
1682 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001683 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 },
1685#endif
1686#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001687#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 .procname = "lease-break-time",
1690 .data = &lease_break_time,
1691 .maxlen = sizeof(int),
1692 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001693 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001695#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001696#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 .procname = "aio-nr",
1699 .data = &aio_nr,
1700 .maxlen = sizeof(aio_nr),
1701 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001702 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 },
1704 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 .procname = "aio-max-nr",
1706 .data = &aio_max_nr,
1707 .maxlen = sizeof(aio_max_nr),
1708 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001709 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001711#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001712#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001713 {
Robert Love0399cb02005-07-13 12:38:18 -04001714 .procname = "inotify",
1715 .mode = 0555,
1716 .child = inotify_table,
1717 },
1718#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001719#ifdef CONFIG_EPOLL
1720 {
1721 .procname = "epoll",
1722 .mode = 0555,
1723 .child = epoll_table,
1724 },
1725#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001727 {
Kees Cook800179c2012-07-25 17:29:07 -07001728 .procname = "protected_symlinks",
1729 .data = &sysctl_protected_symlinks,
1730 .maxlen = sizeof(int),
1731 .mode = 0600,
1732 .proc_handler = proc_dointvec_minmax,
1733 .extra1 = &zero,
1734 .extra2 = &one,
1735 },
1736 {
1737 .procname = "protected_hardlinks",
1738 .data = &sysctl_protected_hardlinks,
1739 .maxlen = sizeof(int),
1740 .mode = 0600,
1741 .proc_handler = proc_dointvec_minmax,
1742 .extra1 = &zero,
1743 .extra2 = &one,
1744 },
1745 {
Alan Coxd6e71142005-06-23 00:09:43 -07001746 .procname = "suid_dumpable",
1747 .data = &suid_dumpable,
1748 .maxlen = sizeof(int),
1749 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001750 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001751 .extra1 = &zero,
1752 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001753 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001754#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1755 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001756 .procname = "binfmt_misc",
1757 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001758 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001759 },
1760#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001761 {
Jens Axboeff9da692010-06-03 14:54:39 +02001762 .procname = "pipe-max-size",
1763 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001764 .maxlen = sizeof(int),
1765 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001766 .proc_handler = &pipe_proc_fn,
1767 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001768 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001769 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770};
1771
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001772static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001773#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001774 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001775 .procname = "exception-trace",
1776 .data = &show_unhandled_signals,
1777 .maxlen = sizeof(int),
1778 .mode = 0644,
1779 .proc_handler = proc_dointvec
1780 },
1781#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001782#if defined(CONFIG_OPTPROBES)
1783 {
1784 .procname = "kprobes-optimization",
1785 .data = &sysctl_kprobes_optimization,
1786 .maxlen = sizeof(int),
1787 .mode = 0644,
1788 .proc_handler = proc_kprobes_optimization_handler,
1789 .extra1 = &zero,
1790 .extra2 = &one,
1791 },
1792#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001793 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794};
1795
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001796static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001797 { }
Robert Love0eeca282005-07-12 17:06:03 -04001798};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001800int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001801{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001802 struct ctl_table_header *hdr;
1803
1804 hdr = register_sysctl_table(sysctl_base_table);
1805 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001806 return 0;
1807}
1808
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001809#endif /* CONFIG_SYSCTL */
1810
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811/*
1812 * /proc/sys support
1813 */
1814
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001815#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
Kees Cookf8808302014-06-06 14:37:17 -07001817static int _proc_do_string(char *data, int maxlen, int write,
1818 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001819 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001820{
1821 size_t len;
1822 char __user *p;
1823 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001824
1825 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001826 *lenp = 0;
1827 return 0;
1828 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001829
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001830 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001831 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1832 /* Only continue writes not past the end of buffer. */
1833 len = strlen(data);
1834 if (len > maxlen - 1)
1835 len = maxlen - 1;
1836
1837 if (*ppos > len)
1838 return 0;
1839 len = *ppos;
1840 } else {
1841 /* Start writing from beginning of buffer. */
1842 len = 0;
1843 }
1844
Kees Cook2ca9bb42014-06-06 14:37:18 -07001845 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001846 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001847 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001848 if (get_user(c, p++))
1849 return -EFAULT;
1850 if (c == 0 || c == '\n')
1851 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001852 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001853 }
Kees Cookf8808302014-06-06 14:37:17 -07001854 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001855 } else {
1856 len = strlen(data);
1857 if (len > maxlen)
1858 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001859
1860 if (*ppos > len) {
1861 *lenp = 0;
1862 return 0;
1863 }
1864
1865 data += *ppos;
1866 len -= *ppos;
1867
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001868 if (len > *lenp)
1869 len = *lenp;
1870 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001871 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001872 return -EFAULT;
1873 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001874 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001875 return -EFAULT;
1876 len++;
1877 }
1878 *lenp = len;
1879 *ppos += len;
1880 }
1881 return 0;
1882}
1883
Kees Cookf4aacea2014-06-06 14:37:19 -07001884static void warn_sysctl_write(struct ctl_table *table)
1885{
1886 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1887 "This will not be supported in the future. To silence this\n"
1888 "warning, set kernel.sysctl_writes_strict = -1\n",
1889 current->comm, table->procname);
1890}
1891
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892/**
1893 * proc_dostring - read a string sysctl
1894 * @table: the sysctl table
1895 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 * @buffer: the user buffer
1897 * @lenp: the size of the user buffer
1898 * @ppos: file position
1899 *
1900 * Reads/writes a string from/to the user buffer. If the kernel
1901 * buffer provided is not large enough to hold the string, the
1902 * string is truncated. The copied string is %NULL-terminated.
1903 * If the string is being read by the user process, it is copied
1904 * and a newline '\n' is added. It is truncated if the buffer is
1905 * not large enough.
1906 *
1907 * Returns 0 on success.
1908 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001909int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 void __user *buffer, size_t *lenp, loff_t *ppos)
1911{
Kees Cookf4aacea2014-06-06 14:37:19 -07001912 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1913 warn_sysctl_write(table);
1914
Kees Cookf8808302014-06-06 14:37:17 -07001915 return _proc_do_string((char *)(table->data), table->maxlen, write,
1916 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917}
1918
Amerigo Wang00b7c332010-05-05 00:26:45 +00001919static size_t proc_skip_spaces(char **buf)
1920{
1921 size_t ret;
1922 char *tmp = skip_spaces(*buf);
1923 ret = tmp - *buf;
1924 *buf = tmp;
1925 return ret;
1926}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001928static void proc_skip_char(char **buf, size_t *size, const char v)
1929{
1930 while (*size) {
1931 if (**buf != v)
1932 break;
1933 (*size)--;
1934 (*buf)++;
1935 }
1936}
1937
Amerigo Wang00b7c332010-05-05 00:26:45 +00001938#define TMPBUFLEN 22
1939/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001940 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001941 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001942 * @buf: a kernel buffer
1943 * @size: size of the kernel buffer
1944 * @val: this is where the number will be stored
1945 * @neg: set to %TRUE if number is negative
1946 * @perm_tr: a vector which contains the allowed trailers
1947 * @perm_tr_len: size of the perm_tr vector
1948 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001949 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001950 * In case of success %0 is returned and @buf and @size are updated with
1951 * the amount of bytes read. If @tr is non-NULL and a trailing
1952 * character exists (size is non-zero after returning from this
1953 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001954 */
1955static int proc_get_long(char **buf, size_t *size,
1956 unsigned long *val, bool *neg,
1957 const char *perm_tr, unsigned perm_tr_len, char *tr)
1958{
1959 int len;
1960 char *p, tmp[TMPBUFLEN];
1961
1962 if (!*size)
1963 return -EINVAL;
1964
1965 len = *size;
1966 if (len > TMPBUFLEN - 1)
1967 len = TMPBUFLEN - 1;
1968
1969 memcpy(tmp, *buf, len);
1970
1971 tmp[len] = 0;
1972 p = tmp;
1973 if (*p == '-' && *size > 1) {
1974 *neg = true;
1975 p++;
1976 } else
1977 *neg = false;
1978 if (!isdigit(*p))
1979 return -EINVAL;
1980
1981 *val = simple_strtoul(p, &p, 0);
1982
1983 len = p - tmp;
1984
1985 /* We don't know if the next char is whitespace thus we may accept
1986 * invalid integers (e.g. 1234...a) or two integers instead of one
1987 * (e.g. 123...1). So lets not allow such large numbers. */
1988 if (len == TMPBUFLEN - 1)
1989 return -EINVAL;
1990
1991 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1992 return -EINVAL;
1993
1994 if (tr && (len < *size))
1995 *tr = *p;
1996
1997 *buf += len;
1998 *size -= len;
1999
2000 return 0;
2001}
2002
2003/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002004 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002005 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002006 * @buf: the user buffer
2007 * @size: the size of the user buffer
2008 * @val: the integer to be converted
2009 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002010 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002011 * In case of success %0 is returned and @buf and @size are updated with
2012 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002013 */
2014static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2015 bool neg)
2016{
2017 int len;
2018 char tmp[TMPBUFLEN], *p = tmp;
2019
2020 sprintf(p, "%s%lu", neg ? "-" : "", val);
2021 len = strlen(tmp);
2022 if (len > *size)
2023 len = *size;
2024 if (copy_to_user(*buf, tmp, len))
2025 return -EFAULT;
2026 *size -= len;
2027 *buf += len;
2028 return 0;
2029}
2030#undef TMPBUFLEN
2031
2032static int proc_put_char(void __user **buf, size_t *size, char c)
2033{
2034 if (*size) {
2035 char __user **buffer = (char __user **)buf;
2036 if (put_user(c, *buffer))
2037 return -EFAULT;
2038 (*size)--, (*buffer)++;
2039 *buf = *buffer;
2040 }
2041 return 0;
2042}
2043
2044static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 int *valp,
2046 int write, void *data)
2047{
2048 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002049 if (*negp) {
2050 if (*lvalp > (unsigned long) INT_MAX + 1)
2051 return -EINVAL;
2052 *valp = -*lvalp;
2053 } else {
2054 if (*lvalp > (unsigned long) INT_MAX)
2055 return -EINVAL;
2056 *valp = *lvalp;
2057 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 } else {
2059 int val = *valp;
2060 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002061 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002062 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002064 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 *lvalp = (unsigned long)val;
2066 }
2067 }
2068 return 0;
2069}
2070
Amerigo Wang00b7c332010-05-05 00:26:45 +00002071static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2072
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002073static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002074 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002075 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002076 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 int write, void *data),
2078 void *data)
2079{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002080 int *i, vleft, first = 1, err = 0;
2081 unsigned long page = 0;
2082 size_t left;
2083 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Amerigo Wang00b7c332010-05-05 00:26:45 +00002085 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 *lenp = 0;
2087 return 0;
2088 }
2089
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002090 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 vleft = table->maxlen / sizeof(*i);
2092 left = *lenp;
2093
2094 if (!conv)
2095 conv = do_proc_dointvec_conv;
2096
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002098 if (*ppos) {
2099 switch (sysctl_writes_strict) {
2100 case SYSCTL_WRITES_STRICT:
2101 goto out;
2102 case SYSCTL_WRITES_WARN:
2103 warn_sysctl_write(table);
2104 break;
2105 default:
2106 break;
2107 }
2108 }
2109
Amerigo Wang00b7c332010-05-05 00:26:45 +00002110 if (left > PAGE_SIZE - 1)
2111 left = PAGE_SIZE - 1;
2112 page = __get_free_page(GFP_TEMPORARY);
2113 kbuf = (char *) page;
2114 if (!kbuf)
2115 return -ENOMEM;
2116 if (copy_from_user(kbuf, buffer, left)) {
2117 err = -EFAULT;
2118 goto free;
2119 }
2120 kbuf[left] = 0;
2121 }
2122
2123 for (; left && vleft--; i++, first=0) {
2124 unsigned long lval;
2125 bool neg;
2126
2127 if (write) {
2128 left -= proc_skip_spaces(&kbuf);
2129
J. R. Okajima563b0462010-05-25 16:10:14 -07002130 if (!left)
2131 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002132 err = proc_get_long(&kbuf, &left, &lval, &neg,
2133 proc_wspace_sep,
2134 sizeof(proc_wspace_sep), NULL);
2135 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002137 if (conv(&neg, &lval, i, 1, data)) {
2138 err = -EINVAL;
2139 break;
2140 }
2141 } else {
2142 if (conv(&neg, &lval, i, 0, data)) {
2143 err = -EINVAL;
2144 break;
2145 }
2146 if (!first)
2147 err = proc_put_char(&buffer, &left, '\t');
2148 if (err)
2149 break;
2150 err = proc_put_long(&buffer, &left, lval, neg);
2151 if (err)
2152 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 }
2154 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002155
2156 if (!write && !first && left && !err)
2157 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002158 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002159 left -= proc_skip_spaces(&kbuf);
2160free:
2161 if (write) {
2162 free_page(page);
2163 if (first)
2164 return err ? : -EINVAL;
2165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002167out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002169 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170}
2171
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002172static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002173 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002174 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002175 int write, void *data),
2176 void *data)
2177{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002178 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002179 buffer, lenp, ppos, conv, data);
2180}
2181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182/**
2183 * proc_dointvec - read a vector of integers
2184 * @table: the sysctl table
2185 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 * @buffer: the user buffer
2187 * @lenp: the size of the user buffer
2188 * @ppos: file position
2189 *
2190 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2191 * values from/to the user buffer, treated as an ASCII string.
2192 *
2193 * Returns 0 on success.
2194 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002195int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 void __user *buffer, size_t *lenp, loff_t *ppos)
2197{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002198 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 NULL,NULL);
2200}
2201
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002202/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002203 * Taint values can only be increased
2204 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002205 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002206static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002207 void __user *buffer, size_t *lenp, loff_t *ppos)
2208{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002209 struct ctl_table t;
2210 unsigned long tmptaint = get_taint();
2211 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002212
Bastian Blank91fcd412007-04-23 14:41:14 -07002213 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002214 return -EPERM;
2215
Andi Kleen25ddbb12008-10-15 22:01:41 -07002216 t = *table;
2217 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002218 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002219 if (err < 0)
2220 return err;
2221
2222 if (write) {
2223 /*
2224 * Poor man's atomic or. Not worth adding a primitive
2225 * to everyone's atomic.h for this
2226 */
2227 int i;
2228 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2229 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302230 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002231 }
2232 }
2233
2234 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002235}
2236
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002237#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002238static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002239 void __user *buffer, size_t *lenp, loff_t *ppos)
2240{
2241 if (write && !capable(CAP_SYS_ADMIN))
2242 return -EPERM;
2243
2244 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2245}
2246#endif
2247
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248struct do_proc_dointvec_minmax_conv_param {
2249 int *min;
2250 int *max;
2251};
2252
Amerigo Wang00b7c332010-05-05 00:26:45 +00002253static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2254 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 int write, void *data)
2256{
2257 struct do_proc_dointvec_minmax_conv_param *param = data;
2258 if (write) {
2259 int val = *negp ? -*lvalp : *lvalp;
2260 if ((param->min && *param->min > val) ||
2261 (param->max && *param->max < val))
2262 return -EINVAL;
2263 *valp = val;
2264 } else {
2265 int val = *valp;
2266 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002267 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002268 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 *lvalp = (unsigned long)val;
2272 }
2273 }
2274 return 0;
2275}
2276
2277/**
2278 * proc_dointvec_minmax - read a vector of integers with min/max values
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 * @buffer: the user buffer
2282 * @lenp: the size of the user buffer
2283 * @ppos: file position
2284 *
2285 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2286 * values from/to the user buffer, treated as an ASCII string.
2287 *
2288 * This routine will ensure the values are within the range specified by
2289 * table->extra1 (min) and table->extra2 (max).
2290 *
2291 * Returns 0 on success.
2292 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002293int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 void __user *buffer, size_t *lenp, loff_t *ppos)
2295{
2296 struct do_proc_dointvec_minmax_conv_param param = {
2297 .min = (int *) table->extra1,
2298 .max = (int *) table->extra2,
2299 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002300 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 do_proc_dointvec_minmax_conv, &param);
2302}
2303
Kees Cook54b50192012-07-30 14:39:18 -07002304static void validate_coredump_safety(void)
2305{
Alex Kelly046d6622012-10-04 17:15:23 -07002306#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002307 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002308 core_pattern[0] != '/' && core_pattern[0] != '|') {
2309 printk(KERN_WARNING "Unsafe core_pattern used with "\
2310 "suid_dumpable=2. Pipe handler or fully qualified "\
2311 "core dump path required.\n");
2312 }
Alex Kelly046d6622012-10-04 17:15:23 -07002313#endif
Kees Cook54b50192012-07-30 14:39:18 -07002314}
2315
2316static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2317 void __user *buffer, size_t *lenp, loff_t *ppos)
2318{
2319 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2320 if (!error)
2321 validate_coredump_safety();
2322 return error;
2323}
2324
Alex Kelly046d6622012-10-04 17:15:23 -07002325#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002326static int proc_dostring_coredump(struct ctl_table *table, int write,
2327 void __user *buffer, size_t *lenp, loff_t *ppos)
2328{
2329 int error = proc_dostring(table, write, buffer, lenp, ppos);
2330 if (!error)
2331 validate_coredump_safety();
2332 return error;
2333}
Alex Kelly046d6622012-10-04 17:15:23 -07002334#endif
Kees Cook54b50192012-07-30 14:39:18 -07002335
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002336static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 void __user *buffer,
2338 size_t *lenp, loff_t *ppos,
2339 unsigned long convmul,
2340 unsigned long convdiv)
2341{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002342 unsigned long *i, *min, *max;
2343 int vleft, first = 1, err = 0;
2344 unsigned long page = 0;
2345 size_t left;
2346 char *kbuf;
2347
2348 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 *lenp = 0;
2350 return 0;
2351 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002352
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002353 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 min = (unsigned long *) table->extra1;
2355 max = (unsigned long *) table->extra2;
2356 vleft = table->maxlen / sizeof(unsigned long);
2357 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002358
2359 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002360 if (*ppos) {
2361 switch (sysctl_writes_strict) {
2362 case SYSCTL_WRITES_STRICT:
2363 goto out;
2364 case SYSCTL_WRITES_WARN:
2365 warn_sysctl_write(table);
2366 break;
2367 default:
2368 break;
2369 }
2370 }
2371
Amerigo Wang00b7c332010-05-05 00:26:45 +00002372 if (left > PAGE_SIZE - 1)
2373 left = PAGE_SIZE - 1;
2374 page = __get_free_page(GFP_TEMPORARY);
2375 kbuf = (char *) page;
2376 if (!kbuf)
2377 return -ENOMEM;
2378 if (copy_from_user(kbuf, buffer, left)) {
2379 err = -EFAULT;
2380 goto free;
2381 }
2382 kbuf[left] = 0;
2383 }
2384
Eric Dumazet27b3d802010-10-07 12:59:29 -07002385 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002386 unsigned long val;
2387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002389 bool neg;
2390
2391 left -= proc_skip_spaces(&kbuf);
2392
2393 err = proc_get_long(&kbuf, &left, &val, &neg,
2394 proc_wspace_sep,
2395 sizeof(proc_wspace_sep), NULL);
2396 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 break;
2398 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 continue;
2400 if ((min && val < *min) || (max && val > *max))
2401 continue;
2402 *i = val;
2403 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002404 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002405 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002406 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002407 if (err)
2408 break;
2409 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002410 err = proc_put_long(&buffer, &left, val, false);
2411 if (err)
2412 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 }
2414 }
2415
Amerigo Wang00b7c332010-05-05 00:26:45 +00002416 if (!write && !first && left && !err)
2417 err = proc_put_char(&buffer, &left, '\n');
2418 if (write && !err)
2419 left -= proc_skip_spaces(&kbuf);
2420free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002422 free_page(page);
2423 if (first)
2424 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002427out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002429 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430}
2431
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002432static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002433 void __user *buffer,
2434 size_t *lenp, loff_t *ppos,
2435 unsigned long convmul,
2436 unsigned long convdiv)
2437{
2438 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002439 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002440}
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442/**
2443 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2444 * @table: the sysctl table
2445 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2449 *
2450 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2451 * values from/to the user buffer, treated as an ASCII string.
2452 *
2453 * This routine will ensure the values are within the range specified by
2454 * table->extra1 (min) and table->extra2 (max).
2455 *
2456 * Returns 0 on success.
2457 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002458int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 void __user *buffer, size_t *lenp, loff_t *ppos)
2460{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002461 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462}
2463
2464/**
2465 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2466 * @table: the sysctl table
2467 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 * @buffer: the user buffer
2469 * @lenp: the size of the user buffer
2470 * @ppos: file position
2471 *
2472 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2473 * values from/to the user buffer, treated as an ASCII string. The values
2474 * are treated as milliseconds, and converted to jiffies when they are stored.
2475 *
2476 * This routine will ensure the values are within the range specified by
2477 * table->extra1 (min) and table->extra2 (max).
2478 *
2479 * Returns 0 on success.
2480 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002481int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 void __user *buffer,
2483 size_t *lenp, loff_t *ppos)
2484{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002485 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 lenp, ppos, HZ, 1000l);
2487}
2488
2489
Amerigo Wang00b7c332010-05-05 00:26:45 +00002490static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 int *valp,
2492 int write, void *data)
2493{
2494 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002495 if (*lvalp > LONG_MAX / HZ)
2496 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2498 } else {
2499 int val = *valp;
2500 unsigned long lval;
2501 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002502 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002503 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002505 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 lval = (unsigned long)val;
2507 }
2508 *lvalp = lval / HZ;
2509 }
2510 return 0;
2511}
2512
Amerigo Wang00b7c332010-05-05 00:26:45 +00002513static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 int *valp,
2515 int write, void *data)
2516{
2517 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002518 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2519 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2521 } else {
2522 int val = *valp;
2523 unsigned long lval;
2524 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002525 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002526 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002528 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 lval = (unsigned long)val;
2530 }
2531 *lvalp = jiffies_to_clock_t(lval);
2532 }
2533 return 0;
2534}
2535
Amerigo Wang00b7c332010-05-05 00:26:45 +00002536static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 int *valp,
2538 int write, void *data)
2539{
2540 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002541 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2542
2543 if (jif > INT_MAX)
2544 return 1;
2545 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 } else {
2547 int val = *valp;
2548 unsigned long lval;
2549 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002550 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002551 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002553 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 lval = (unsigned long)val;
2555 }
2556 *lvalp = jiffies_to_msecs(lval);
2557 }
2558 return 0;
2559}
2560
2561/**
2562 * proc_dointvec_jiffies - read a vector of integers as seconds
2563 * @table: the sysctl table
2564 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 * @buffer: the user buffer
2566 * @lenp: the size of the user buffer
2567 * @ppos: file position
2568 *
2569 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2570 * values from/to the user buffer, treated as an ASCII string.
2571 * The values read are assumed to be in seconds, and are converted into
2572 * jiffies.
2573 *
2574 * Returns 0 on success.
2575 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002576int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 void __user *buffer, size_t *lenp, loff_t *ppos)
2578{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002579 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 do_proc_dointvec_jiffies_conv,NULL);
2581}
2582
2583/**
2584 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2585 * @table: the sysctl table
2586 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 * @buffer: the user buffer
2588 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002589 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 *
2591 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2592 * values from/to the user buffer, treated as an ASCII string.
2593 * The values read are assumed to be in 1/USER_HZ seconds, and
2594 * are converted into jiffies.
2595 *
2596 * Returns 0 on success.
2597 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002598int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 void __user *buffer, size_t *lenp, loff_t *ppos)
2600{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002601 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 do_proc_dointvec_userhz_jiffies_conv,NULL);
2603}
2604
2605/**
2606 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2607 * @table: the sysctl table
2608 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 * @buffer: the user buffer
2610 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002611 * @ppos: file position
2612 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 *
2614 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2615 * values from/to the user buffer, treated as an ASCII string.
2616 * The values read are assumed to be in 1/1000 seconds, and
2617 * are converted into jiffies.
2618 *
2619 * Returns 0 on success.
2620 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002621int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 void __user *buffer, size_t *lenp, loff_t *ppos)
2623{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002624 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 do_proc_dointvec_ms_jiffies_conv, NULL);
2626}
2627
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002628static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002629 void __user *buffer, size_t *lenp, loff_t *ppos)
2630{
2631 struct pid *new_pid;
2632 pid_t tmp;
2633 int r;
2634
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002635 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002636
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002637 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002638 lenp, ppos, NULL, NULL);
2639 if (r || !write)
2640 return r;
2641
2642 new_pid = find_get_pid(tmp);
2643 if (!new_pid)
2644 return -ESRCH;
2645
2646 put_pid(xchg(&cad_pid, new_pid));
2647 return 0;
2648}
2649
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002650/**
2651 * proc_do_large_bitmap - read/write from/to a large bitmap
2652 * @table: the sysctl table
2653 * @write: %TRUE if this is a write to the sysctl file
2654 * @buffer: the user buffer
2655 * @lenp: the size of the user buffer
2656 * @ppos: file position
2657 *
2658 * The bitmap is stored at table->data and the bitmap length (in bits)
2659 * in table->maxlen.
2660 *
2661 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2662 * large bitmaps may be represented in a compact manner. Writing into
2663 * the file will clear the bitmap then update it with the given input.
2664 *
2665 * Returns 0 on success.
2666 */
2667int proc_do_large_bitmap(struct ctl_table *table, int write,
2668 void __user *buffer, size_t *lenp, loff_t *ppos)
2669{
2670 int err = 0;
2671 bool first = 1;
2672 size_t left = *lenp;
2673 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002674 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002675 unsigned long *tmp_bitmap = NULL;
2676 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2677
WANG Cong122ff242014-05-12 16:04:53 -07002678 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002679 *lenp = 0;
2680 return 0;
2681 }
2682
2683 if (write) {
2684 unsigned long page = 0;
2685 char *kbuf;
2686
2687 if (left > PAGE_SIZE - 1)
2688 left = PAGE_SIZE - 1;
2689
2690 page = __get_free_page(GFP_TEMPORARY);
2691 kbuf = (char *) page;
2692 if (!kbuf)
2693 return -ENOMEM;
2694 if (copy_from_user(kbuf, buffer, left)) {
2695 free_page(page);
2696 return -EFAULT;
2697 }
2698 kbuf[left] = 0;
2699
2700 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2701 GFP_KERNEL);
2702 if (!tmp_bitmap) {
2703 free_page(page);
2704 return -ENOMEM;
2705 }
2706 proc_skip_char(&kbuf, &left, '\n');
2707 while (!err && left) {
2708 unsigned long val_a, val_b;
2709 bool neg;
2710
2711 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2712 sizeof(tr_a), &c);
2713 if (err)
2714 break;
2715 if (val_a >= bitmap_len || neg) {
2716 err = -EINVAL;
2717 break;
2718 }
2719
2720 val_b = val_a;
2721 if (left) {
2722 kbuf++;
2723 left--;
2724 }
2725
2726 if (c == '-') {
2727 err = proc_get_long(&kbuf, &left, &val_b,
2728 &neg, tr_b, sizeof(tr_b),
2729 &c);
2730 if (err)
2731 break;
2732 if (val_b >= bitmap_len || neg ||
2733 val_a > val_b) {
2734 err = -EINVAL;
2735 break;
2736 }
2737 if (left) {
2738 kbuf++;
2739 left--;
2740 }
2741 }
2742
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002743 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002744 first = 0;
2745 proc_skip_char(&kbuf, &left, '\n');
2746 }
2747 free_page(page);
2748 } else {
2749 unsigned long bit_a, bit_b = 0;
2750
2751 while (left) {
2752 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2753 if (bit_a >= bitmap_len)
2754 break;
2755 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2756 bit_a + 1) - 1;
2757
2758 if (!first) {
2759 err = proc_put_char(&buffer, &left, ',');
2760 if (err)
2761 break;
2762 }
2763 err = proc_put_long(&buffer, &left, bit_a, false);
2764 if (err)
2765 break;
2766 if (bit_a != bit_b) {
2767 err = proc_put_char(&buffer, &left, '-');
2768 if (err)
2769 break;
2770 err = proc_put_long(&buffer, &left, bit_b, false);
2771 if (err)
2772 break;
2773 }
2774
2775 first = 0; bit_b++;
2776 }
2777 if (!err)
2778 err = proc_put_char(&buffer, &left, '\n');
2779 }
2780
2781 if (!err) {
2782 if (write) {
2783 if (*ppos)
2784 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2785 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002786 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002787 }
2788 kfree(tmp_bitmap);
2789 *lenp -= left;
2790 *ppos += *lenp;
2791 return 0;
2792 } else {
2793 kfree(tmp_bitmap);
2794 return err;
2795 }
2796}
2797
Jovi Zhang55610502011-01-12 17:00:45 -08002798#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002800int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 void __user *buffer, size_t *lenp, loff_t *ppos)
2802{
2803 return -ENOSYS;
2804}
2805
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002806int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 void __user *buffer, size_t *lenp, loff_t *ppos)
2808{
2809 return -ENOSYS;
2810}
2811
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002812int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 void __user *buffer, size_t *lenp, loff_t *ppos)
2814{
2815 return -ENOSYS;
2816}
2817
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002818int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 void __user *buffer, size_t *lenp, loff_t *ppos)
2820{
2821 return -ENOSYS;
2822}
2823
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002824int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 void __user *buffer, size_t *lenp, loff_t *ppos)
2826{
2827 return -ENOSYS;
2828}
2829
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002830int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 void __user *buffer, size_t *lenp, loff_t *ppos)
2832{
2833 return -ENOSYS;
2834}
2835
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002836int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 void __user *buffer, size_t *lenp, loff_t *ppos)
2838{
2839 return -ENOSYS;
2840}
2841
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002842int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 void __user *buffer,
2844 size_t *lenp, loff_t *ppos)
2845{
2846 return -ENOSYS;
2847}
2848
2849
Jovi Zhang55610502011-01-12 17:00:45 -08002850#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852/*
2853 * No sense putting this after each symbol definition, twice,
2854 * exception granted :-)
2855 */
2856EXPORT_SYMBOL(proc_dointvec);
2857EXPORT_SYMBOL(proc_dointvec_jiffies);
2858EXPORT_SYMBOL(proc_dointvec_minmax);
2859EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2860EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2861EXPORT_SYMBOL(proc_dostring);
2862EXPORT_SYMBOL(proc_doulongvec_minmax);
2863EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);