blob: 725587f10667eef64326263941bea17b7fb82cf1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12 * Horn.
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16 * Wendling.
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Vegard Nossumdfec0722008-04-04 00:51:41 +020033#include <linux/kmemcheck.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#include <asm/uaccess.h>
70#include <asm/processor.h>
71
Andi Kleen29cbc782006-09-30 01:47:55 +020072#ifdef CONFIG_X86
73#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010074#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010075#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020076#endif
David Howellsd550bbd2012-03-28 18:30:03 +010077#ifdef CONFIG_SPARC
78#include <asm/setup.h>
79#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080080#ifdef CONFIG_BSD_PROCESS_ACCT
81#include <linux/acct.h>
82#endif
Dave Young4f0e0562010-03-10 15:24:09 -080083#ifdef CONFIG_RT_MUTEXES
84#include <linux/rtmutex.h>
85#endif
Dave Young2edf5e42010-03-10 15:24:10 -080086#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
87#include <linux/lockdep.h>
88#endif
Dave Young15485a42010-03-10 15:24:07 -080089#ifdef CONFIG_CHR_DEV_SG
90#include <scsi/sg.h>
91#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020092
Don Zickus58687ac2010-05-07 17:11:44 -040093#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050094#include <linux/nmi.h>
95#endif
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#if defined(CONFIG_SYSCTL)
98
99/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700100extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700101#ifdef CONFIG_COREDUMP
102extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700104extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700105#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800108extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200109extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100110extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400111extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000112#ifndef CONFIG_MMU
113extern int sysctl_nr_trim_pages;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400117#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int sixty = 60;
119#endif
120
Aaron Tomlin270750db2014-01-20 17:34:13 +0000121static int __maybe_unused neg_one = -1;
122
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700123static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700124static int __maybe_unused one = 1;
125static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700126static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800127static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700128static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700129static int one_thousand = 1000;
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
Kees Cook41662f52016-01-20 15:00:45 -0800177static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700178
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 },
Mel Gormancb251762016-02-05 09:08:36 +0000354#ifdef CONFIG_SCHEDSTATS
355 {
356 .procname = "sched_schedstats",
357 .data = NULL,
358 .maxlen = sizeof(unsigned int),
359 .mode = 0644,
360 .proc_handler = sysctl_schedstats,
361 .extra1 = &zero,
362 .extra2 = &one,
363 },
364#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200365#endif /* CONFIG_SMP */
366#ifdef CONFIG_NUMA_BALANCING
367 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200368 .procname = "numa_balancing_scan_delay_ms",
369 .data = &sysctl_numa_balancing_scan_delay,
370 .maxlen = sizeof(unsigned int),
371 .mode = 0644,
372 .proc_handler = proc_dointvec,
373 },
374 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200375 .procname = "numa_balancing_scan_period_min_ms",
376 .data = &sysctl_numa_balancing_scan_period_min,
377 .maxlen = sizeof(unsigned int),
378 .mode = 0644,
379 .proc_handler = proc_dointvec,
380 },
381 {
382 .procname = "numa_balancing_scan_period_max_ms",
383 .data = &sysctl_numa_balancing_scan_period_max,
384 .maxlen = sizeof(unsigned int),
385 .mode = 0644,
386 .proc_handler = proc_dointvec,
387 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200388 {
389 .procname = "numa_balancing_scan_size_mb",
390 .data = &sysctl_numa_balancing_scan_size,
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400393 .proc_handler = proc_dointvec_minmax,
394 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200395 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100396 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800397 .procname = "numa_balancing",
398 .data = NULL, /* filled in by handler */
399 .maxlen = sizeof(unsigned int),
400 .mode = 0644,
401 .proc_handler = sysctl_numa_balancing,
402 .extra1 = &zero,
403 .extra2 = &one,
404 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200405#endif /* CONFIG_NUMA_BALANCING */
406#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200407 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100408 .procname = "sched_rt_period_us",
409 .data = &sysctl_sched_rt_period,
410 .maxlen = sizeof(unsigned int),
411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800412 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100413 },
414 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100415 .procname = "sched_rt_runtime_us",
416 .data = &sysctl_sched_rt_runtime,
417 .maxlen = sizeof(int),
418 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800419 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100420 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600421 {
422 .procname = "sched_rr_timeslice_ms",
423 .data = &sched_rr_timeslice,
424 .maxlen = sizeof(int),
425 .mode = 0644,
426 .proc_handler = sched_rr_handler,
427 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100428#ifdef CONFIG_SCHED_AUTOGROUP
429 {
430 .procname = "sched_autogroup_enabled",
431 .data = &sysctl_sched_autogroup_enabled,
432 .maxlen = sizeof(unsigned int),
433 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800434 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100435 .extra1 = &zero,
436 .extra2 = &one,
437 },
438#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700439#ifdef CONFIG_CFS_BANDWIDTH
440 {
441 .procname = "sched_cfs_bandwidth_slice_us",
442 .data = &sysctl_sched_cfs_bandwidth_slice,
443 .maxlen = sizeof(unsigned int),
444 .mode = 0644,
445 .proc_handler = proc_dointvec_minmax,
446 .extra1 = &one,
447 },
448#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700449#ifdef CONFIG_PROVE_LOCKING
450 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700451 .procname = "prove_locking",
452 .data = &prove_locking,
453 .maxlen = sizeof(int),
454 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800455 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700456 },
457#endif
458#ifdef CONFIG_LOCK_STAT
459 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700460 .procname = "lock_stat",
461 .data = &lock_stat,
462 .maxlen = sizeof(int),
463 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800464 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700465 },
466#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200467 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 .procname = "panic",
469 .data = &panic_timeout,
470 .maxlen = sizeof(int),
471 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800472 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 },
Alex Kelly046d6622012-10-04 17:15:23 -0700474#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 .procname = "core_uses_pid",
477 .data = &core_uses_pid,
478 .maxlen = sizeof(int),
479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800480 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 },
482 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 .procname = "core_pattern",
484 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700485 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700487 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 },
Neil Hormana2939802009-09-23 15:56:56 -0700489 {
Neil Hormana2939802009-09-23 15:56:56 -0700490 .procname = "core_pipe_limit",
491 .data = &core_pipe_limit,
492 .maxlen = sizeof(unsigned int),
493 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800494 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700495 },
Alex Kelly046d6622012-10-04 17:15:23 -0700496#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800497#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700500 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800501 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800502 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700504 {
505 .procname = "sysctl_writes_strict",
506 .data = &sysctl_writes_strict,
507 .maxlen = sizeof(int),
508 .mode = 0644,
509 .proc_handler = proc_dointvec_minmax,
510 .extra1 = &neg_one,
511 .extra2 = &one,
512 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800513#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100514#ifdef CONFIG_LATENCYTOP
515 {
516 .procname = "latencytop",
517 .data = &latencytop_enabled,
518 .maxlen = sizeof(int),
519 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000520 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100521 },
522#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523#ifdef CONFIG_BLK_DEV_INITRD
524 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 .procname = "real-root-dev",
526 .data = &real_root_dev,
527 .maxlen = sizeof(int),
528 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800529 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 },
531#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700532 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700533 .procname = "print-fatal-signals",
534 .data = &print_fatal_signals,
535 .maxlen = sizeof(int),
536 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800537 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700538 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700539#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 .procname = "reboot-cmd",
542 .data = reboot_command,
543 .maxlen = 256,
544 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800545 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 },
547 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 .procname = "stop-a",
549 .data = &stop_a_enabled,
550 .maxlen = sizeof (int),
551 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800552 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 },
554 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 .procname = "scons-poweroff",
556 .data = &scons_pwroff,
557 .maxlen = sizeof (int),
558 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800559 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 },
561#endif
David S. Miller08714202008-11-16 23:49:24 -0800562#ifdef CONFIG_SPARC64
563 {
David S. Miller08714202008-11-16 23:49:24 -0800564 .procname = "tsb-ratio",
565 .data = &sysctl_tsb_ratio,
566 .maxlen = sizeof (int),
567 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800568 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800569 },
570#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571#ifdef __hppa__
572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .procname = "soft-power",
574 .data = &pwrsw_enabled,
575 .maxlen = sizeof (int),
576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530579#endif
580#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 .procname = "unaligned-trap",
583 .data = &unaligned_enabled,
584 .maxlen = sizeof (int),
585 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800586 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 },
588#endif
589 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 .procname = "ctrl-alt-del",
591 .data = &C_A_D,
592 .maxlen = sizeof(int),
593 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800594 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400596#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200597 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200598 .procname = "ftrace_enabled",
599 .data = &ftrace_enabled,
600 .maxlen = sizeof(int),
601 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800602 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200603 },
604#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500605#ifdef CONFIG_STACK_TRACER
606 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500607 .procname = "stack_tracer_enabled",
608 .data = &stack_tracer_enabled,
609 .maxlen = sizeof(int),
610 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800611 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500612 },
613#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400614#ifdef CONFIG_TRACING
615 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100616 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400617 .data = &ftrace_dump_on_oops,
618 .maxlen = sizeof(int),
619 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800620 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400621 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400622 {
623 .procname = "traceoff_on_warning",
624 .data = &__disable_trace_on_warning,
625 .maxlen = sizeof(__disable_trace_on_warning),
626 .mode = 0644,
627 .proc_handler = proc_dointvec,
628 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500629 {
630 .procname = "tracepoint_printk",
631 .data = &tracepoint_printk,
632 .maxlen = sizeof(tracepoint_printk),
633 .mode = 0644,
634 .proc_handler = proc_dointvec,
635 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400636#endif
Dave Young2965faa2015-09-09 15:38:55 -0700637#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800638 {
639 .procname = "kexec_load_disabled",
640 .data = &kexec_load_disabled,
641 .maxlen = sizeof(int),
642 .mode = 0644,
643 /* only handle a transition from default "0" to "1" */
644 .proc_handler = proc_dointvec_minmax,
645 .extra1 = &one,
646 .extra2 = &one,
647 },
648#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200649#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 .procname = "modprobe",
652 .data = &modprobe_path,
653 .maxlen = KMOD_PATH_LEN,
654 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800655 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 },
Kees Cook3d433212009-04-02 15:49:29 -0700657 {
Kees Cook3d433212009-04-02 15:49:29 -0700658 .procname = "modules_disabled",
659 .data = &modules_disabled,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800663 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700664 .extra1 = &one,
665 .extra2 = &one,
666 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700668#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100671 .data = &uevent_helper,
672 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800674 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 },
Michael Marineau86d56132014-04-10 14:09:31 -0700676#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677#ifdef CONFIG_CHR_DEV_SG
678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 .procname = "sg-big-buff",
680 .data = &sg_big_buff,
681 .maxlen = sizeof (int),
682 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800683 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 },
685#endif
686#ifdef CONFIG_BSD_PROCESS_ACCT
687 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .procname = "acct",
689 .data = &acct_parm,
690 .maxlen = 3*sizeof(int),
691 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800692 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 },
694#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#ifdef CONFIG_MAGIC_SYSRQ
696 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800698 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 .maxlen = sizeof (int),
700 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700701 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 },
703#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700704#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700707 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 .maxlen = sizeof (int),
709 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800710 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700712#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700715 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 .maxlen = sizeof(int),
717 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700718 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 },
720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .procname = "random",
722 .mode = 0555,
723 .child = random_table,
724 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 {
Eric Paris17f60a72011-04-01 17:07:50 -0400726 .procname = "usermodehelper",
727 .mode = 0555,
728 .child = usermodehelper_table,
729 },
730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .procname = "overflowuid",
732 .data = &overflowuid,
733 .maxlen = sizeof(int),
734 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800735 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 .extra1 = &minolduid,
737 .extra2 = &maxolduid,
738 },
739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .procname = "overflowgid",
741 .data = &overflowgid,
742 .maxlen = sizeof(int),
743 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800744 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .extra1 = &minolduid,
746 .extra2 = &maxolduid,
747 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800748#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#ifdef CONFIG_MATHEMU
750 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 .procname = "ieee_emulation_warnings",
752 .data = &sysctl_ieee_emulation_warnings,
753 .maxlen = sizeof(int),
754 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800755 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 },
757#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200760 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 .maxlen = sizeof(int),
762 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800763 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 },
765#endif
766 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 .procname = "pid_max",
768 .data = &pid_max,
769 .maxlen = sizeof (int),
770 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800771 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 .extra1 = &pid_max_min,
773 .extra2 = &pid_max_max,
774 },
775 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 .procname = "panic_on_oops",
777 .data = &panic_on_oops,
778 .maxlen = sizeof(int),
779 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800780 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800782#if defined CONFIG_PRINTK
783 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800784 .procname = "printk",
785 .data = &console_loglevel,
786 .maxlen = 4*sizeof(int),
787 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800788 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800789 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700792 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 .maxlen = sizeof(int),
794 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800795 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 },
797 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700799 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 .maxlen = sizeof(int),
801 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800802 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 },
Dave Youngaf913222009-09-22 16:43:33 -0700804 {
Dave Youngaf913222009-09-22 16:43:33 -0700805 .procname = "printk_delay",
806 .data = &printk_delay_msec,
807 .maxlen = sizeof(int),
808 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800809 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700810 .extra1 = &zero,
811 .extra2 = &ten_thousand,
812 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800814 .procname = "dmesg_restrict",
815 .data = &dmesg_restrict,
816 .maxlen = sizeof(int),
817 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700818 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800819 .extra1 = &zero,
820 .extra2 = &one,
821 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800822 {
823 .procname = "kptr_restrict",
824 .data = &kptr_restrict,
825 .maxlen = sizeof(int),
826 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700827 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800828 .extra1 = &zero,
829 .extra2 = &two,
830 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800831#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800832 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 .procname = "ngroups_max",
834 .data = &ngroups_max,
835 .maxlen = sizeof (int),
836 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800837 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 },
Dan Ballard73efc032011-10-31 17:11:20 -0700839 {
840 .procname = "cap_last_cap",
841 .data = (void *)&cap_last_cap,
842 .maxlen = sizeof(int),
843 .mode = 0444,
844 .proc_handler = proc_dointvec,
845 },
Don Zickus58687ac2010-05-07 17:11:44 -0400846#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500847 {
Don Zickus58687ac2010-05-07 17:11:44 -0400848 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200849 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500850 .maxlen = sizeof (int),
851 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700852 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700853 .extra1 = &zero,
854 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400855 },
856 {
857 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700858 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400859 .maxlen = sizeof(int),
860 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700861 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800862 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400863 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500864 },
Don Zickus2508ce12010-05-07 17:11:46 -0400865 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700866 .procname = "nmi_watchdog",
867 .data = &nmi_watchdog_enabled,
868 .maxlen = sizeof (int),
869 .mode = 0644,
870 .proc_handler = proc_nmi_watchdog,
871 .extra1 = &zero,
872#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
873 .extra2 = &one,
874#else
875 .extra2 = &zero,
876#endif
877 },
878 {
879 .procname = "soft_watchdog",
880 .data = &soft_watchdog_enabled,
881 .maxlen = sizeof (int),
882 .mode = 0644,
883 .proc_handler = proc_soft_watchdog,
884 .extra1 = &zero,
885 .extra2 = &one,
886 },
887 {
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700888 .procname = "watchdog_cpumask",
889 .data = &watchdog_cpumask_bits,
890 .maxlen = NR_CPUS,
891 .mode = 0644,
892 .proc_handler = proc_watchdog_cpumask,
893 },
894 {
Don Zickus2508ce12010-05-07 17:11:46 -0400895 .procname = "softlockup_panic",
896 .data = &softlockup_panic,
897 .maxlen = sizeof(int),
898 .mode = 0644,
899 .proc_handler = proc_dointvec_minmax,
900 .extra1 = &zero,
901 .extra2 = &one,
902 },
Don Zickusac1f5912015-11-05 18:44:44 -0800903#ifdef CONFIG_HARDLOCKUP_DETECTOR
904 {
905 .procname = "hardlockup_panic",
906 .data = &hardlockup_panic,
907 .maxlen = sizeof(int),
908 .mode = 0644,
909 .proc_handler = proc_dointvec_minmax,
910 .extra1 = &zero,
911 .extra2 = &one,
912 },
913#endif
Aaron Tomlined235872014-06-23 13:22:05 -0700914#ifdef CONFIG_SMP
915 {
916 .procname = "softlockup_all_cpu_backtrace",
917 .data = &sysctl_softlockup_all_cpu_backtrace,
918 .maxlen = sizeof(int),
919 .mode = 0644,
920 .proc_handler = proc_dointvec_minmax,
921 .extra1 = &zero,
922 .extra2 = &one,
923 },
Jiri Kosina55537872015-11-05 18:44:41 -0800924 {
925 .procname = "hardlockup_all_cpu_backtrace",
926 .data = &sysctl_hardlockup_all_cpu_backtrace,
927 .maxlen = sizeof(int),
928 .mode = 0644,
929 .proc_handler = proc_dointvec_minmax,
930 .extra1 = &zero,
931 .extra2 = &one,
932 },
Aaron Tomlined235872014-06-23 13:22:05 -0700933#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500934#endif
935#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
936 {
937 .procname = "unknown_nmi_panic",
938 .data = &unknown_nmi_panic,
939 .maxlen = sizeof (int),
940 .mode = 0644,
941 .proc_handler = proc_dointvec,
942 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500943#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944#if defined(CONFIG_X86)
945 {
Don Zickus8da5add2006-09-26 10:52:27 +0200946 .procname = "panic_on_unrecovered_nmi",
947 .data = &panic_on_unrecovered_nmi,
948 .maxlen = sizeof(int),
949 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800950 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200951 },
952 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700953 .procname = "panic_on_io_nmi",
954 .data = &panic_on_io_nmi,
955 .maxlen = sizeof(int),
956 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800957 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700958 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900959#ifdef CONFIG_DEBUG_STACKOVERFLOW
960 {
961 .procname = "panic_on_stackoverflow",
962 .data = &sysctl_panic_on_stackoverflow,
963 .maxlen = sizeof(int),
964 .mode = 0644,
965 .proc_handler = proc_dointvec,
966 },
967#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700968 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 .procname = "bootloader_type",
970 .data = &bootloader_type,
971 .maxlen = sizeof (int),
972 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800973 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100975 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700976 .procname = "bootloader_version",
977 .data = &bootloader_version,
978 .maxlen = sizeof (int),
979 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800980 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700981 },
982 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100983 .procname = "kstack_depth_to_print",
984 .data = &kstack_depth_to_print,
985 .maxlen = sizeof(int),
986 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800987 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100988 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100989 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100990 .procname = "io_delay_type",
991 .data = &io_delay_type,
992 .maxlen = sizeof(int),
993 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800994 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100995 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800997#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 .procname = "randomize_va_space",
1000 .data = &randomize_va_space,
1001 .maxlen = sizeof(int),
1002 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001003 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001005#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001006#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001007 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001008 .procname = "spin_retry",
1009 .data = &spin_retry,
1010 .maxlen = sizeof (int),
1011 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001012 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001013 },
1014#endif
Len Brown673d5b42007-07-28 03:33:16 -04001015#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001016 {
Pavel Machekc255d842006-02-20 18:27:58 -08001017 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001018 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001019 .maxlen = sizeof (unsigned long),
1020 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001021 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001022 },
1023#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301024#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001025 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001026 .procname = "ignore-unaligned-usertrap",
1027 .data = &no_unaligned_warning,
1028 .maxlen = sizeof (int),
1029 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001030 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001031 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301032#endif
1033#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001034 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001035 .procname = "unaligned-dump-stack",
1036 .data = &unaligned_dump_stack,
1037 .maxlen = sizeof (int),
1038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001040 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001041#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001042#ifdef CONFIG_DETECT_HUNG_TASK
1043 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001044 .procname = "hung_task_panic",
1045 .data = &sysctl_hung_task_panic,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001048 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001049 .extra1 = &zero,
1050 .extra2 = &one,
1051 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001052 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001053 .procname = "hung_task_check_count",
1054 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001055 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001056 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001057 .proc_handler = proc_dointvec_minmax,
1058 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001059 },
1060 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001061 .procname = "hung_task_timeout_secs",
1062 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001063 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001064 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001065 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001066 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001067 },
1068 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001069 .procname = "hung_task_warnings",
1070 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001071 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001072 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001073 .proc_handler = proc_dointvec_minmax,
1074 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001075 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001076#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001077#ifdef CONFIG_COMPAT
1078 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001079 .procname = "compat-log",
1080 .data = &compat_log,
1081 .maxlen = sizeof (int),
1082 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001083 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001084 },
1085#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001086#ifdef CONFIG_RT_MUTEXES
1087 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001088 .procname = "max_lock_depth",
1089 .data = &max_lock_depth,
1090 .maxlen = sizeof(int),
1091 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001092 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001093 },
1094#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001095 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001096 .procname = "poweroff_cmd",
1097 .data = &poweroff_cmd,
1098 .maxlen = POWEROFF_CMD_PATH_LEN,
1099 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001100 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001101 },
David Howells0b77f5b2008-04-29 01:01:32 -07001102#ifdef CONFIG_KEYS
1103 {
David Howells0b77f5b2008-04-29 01:01:32 -07001104 .procname = "keys",
1105 .mode = 0555,
1106 .child = key_sysctls,
1107 },
1108#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001109#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001110 /*
1111 * User-space scripts rely on the existence of this file
1112 * as a feature check for perf_events being enabled.
1113 *
1114 * So it's an ABI, do not remove!
1115 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001116 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001117 .procname = "perf_event_paranoid",
1118 .data = &sysctl_perf_event_paranoid,
1119 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001120 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001121 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001122 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001123 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001124 .procname = "perf_event_mlock_kb",
1125 .data = &sysctl_perf_event_mlock,
1126 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001127 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001128 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001129 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001130 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001131 .procname = "perf_event_max_sample_rate",
1132 .data = &sysctl_perf_event_sample_rate,
1133 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001134 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001135 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001136 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001137 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001138 {
1139 .procname = "perf_cpu_time_max_percent",
1140 .data = &sysctl_perf_cpu_time_max_percent,
1141 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1142 .mode = 0644,
1143 .proc_handler = perf_cpu_time_max_percent_handler,
1144 .extra1 = &zero,
1145 .extra2 = &one_hundred,
1146 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001147#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001148#ifdef CONFIG_KMEMCHECK
1149 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001150 .procname = "kmemcheck",
1151 .data = &kmemcheck_enabled,
1152 .maxlen = sizeof(int),
1153 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001154 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001155 },
1156#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001157 {
1158 .procname = "panic_on_warn",
1159 .data = &panic_on_warn,
1160 .maxlen = sizeof(int),
1161 .mode = 0644,
1162 .proc_handler = proc_dointvec_minmax,
1163 .extra1 = &zero,
1164 .extra2 = &one,
1165 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001166#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1167 {
1168 .procname = "timer_migration",
1169 .data = &sysctl_timer_migration,
1170 .maxlen = sizeof(unsigned int),
1171 .mode = 0644,
1172 .proc_handler = timer_migration_handler,
1173 },
1174#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001175#ifdef CONFIG_BPF_SYSCALL
1176 {
1177 .procname = "unprivileged_bpf_disabled",
1178 .data = &sysctl_unprivileged_bpf_disabled,
1179 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1180 .mode = 0644,
1181 /* only handle a transition from default "0" to "1" */
1182 .proc_handler = proc_dointvec_minmax,
1183 .extra1 = &one,
1184 .extra2 = &one,
1185 },
1186#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001187 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188};
1189
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001190static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 .procname = "overcommit_memory",
1193 .data = &sysctl_overcommit_memory,
1194 .maxlen = sizeof(sysctl_overcommit_memory),
1195 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001196 .proc_handler = proc_dointvec_minmax,
1197 .extra1 = &zero,
1198 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 },
1200 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001201 .procname = "panic_on_oom",
1202 .data = &sysctl_panic_on_oom,
1203 .maxlen = sizeof(sysctl_panic_on_oom),
1204 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001205 .proc_handler = proc_dointvec_minmax,
1206 .extra1 = &zero,
1207 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001208 },
1209 {
David Rientjesfe071d72007-10-16 23:25:56 -07001210 .procname = "oom_kill_allocating_task",
1211 .data = &sysctl_oom_kill_allocating_task,
1212 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1213 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001214 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001215 },
1216 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001217 .procname = "oom_dump_tasks",
1218 .data = &sysctl_oom_dump_tasks,
1219 .maxlen = sizeof(sysctl_oom_dump_tasks),
1220 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001221 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001222 },
1223 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 .procname = "overcommit_ratio",
1225 .data = &sysctl_overcommit_ratio,
1226 .maxlen = sizeof(sysctl_overcommit_ratio),
1227 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001228 .proc_handler = overcommit_ratio_handler,
1229 },
1230 {
1231 .procname = "overcommit_kbytes",
1232 .data = &sysctl_overcommit_kbytes,
1233 .maxlen = sizeof(sysctl_overcommit_kbytes),
1234 .mode = 0644,
1235 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 },
1237 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 .procname = "page-cluster",
1239 .data = &page_cluster,
1240 .maxlen = sizeof(int),
1241 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001242 .proc_handler = proc_dointvec_minmax,
1243 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 },
1245 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 .procname = "dirty_background_ratio",
1247 .data = &dirty_background_ratio,
1248 .maxlen = sizeof(dirty_background_ratio),
1249 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001250 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 .extra1 = &zero,
1252 .extra2 = &one_hundred,
1253 },
1254 {
David Rientjes2da02992009-01-06 14:39:31 -08001255 .procname = "dirty_background_bytes",
1256 .data = &dirty_background_bytes,
1257 .maxlen = sizeof(dirty_background_bytes),
1258 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001259 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001260 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001261 },
1262 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 .procname = "dirty_ratio",
1264 .data = &vm_dirty_ratio,
1265 .maxlen = sizeof(vm_dirty_ratio),
1266 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001267 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 .extra1 = &zero,
1269 .extra2 = &one_hundred,
1270 },
1271 {
David Rientjes2da02992009-01-06 14:39:31 -08001272 .procname = "dirty_bytes",
1273 .data = &vm_dirty_bytes,
1274 .maxlen = sizeof(vm_dirty_bytes),
1275 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001276 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001277 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001278 },
1279 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001281 .data = &dirty_writeback_interval,
1282 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001284 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 },
1286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001288 .data = &dirty_expire_interval,
1289 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001291 .proc_handler = proc_dointvec_minmax,
1292 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 },
1294 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001295 .procname = "dirtytime_expire_seconds",
1296 .data = &dirtytime_expire_interval,
1297 .maxlen = sizeof(dirty_expire_interval),
1298 .mode = 0644,
1299 .proc_handler = dirtytime_interval_handler,
1300 .extra1 = &zero,
1301 },
1302 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001303 .procname = "nr_pdflush_threads",
1304 .mode = 0444 /* read-only */,
1305 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 },
1307 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 .procname = "swappiness",
1309 .data = &vm_swappiness,
1310 .maxlen = sizeof(vm_swappiness),
1311 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001312 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 .extra1 = &zero,
1314 .extra2 = &one_hundred,
1315 },
1316#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001317 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001319 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 .maxlen = sizeof(unsigned long),
1321 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001322 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001323 },
1324#ifdef CONFIG_NUMA
1325 {
1326 .procname = "nr_hugepages_mempolicy",
1327 .data = NULL,
1328 .maxlen = sizeof(unsigned long),
1329 .mode = 0644,
1330 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001331 },
1332#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 .procname = "hugetlb_shm_group",
1335 .data = &sysctl_hugetlb_shm_group,
1336 .maxlen = sizeof(gid_t),
1337 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001338 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 },
Mel Gorman396faf02007-07-17 04:03:13 -07001340 {
Mel Gorman396faf02007-07-17 04:03:13 -07001341 .procname = "hugepages_treat_as_movable",
1342 .data = &hugepages_treat_as_movable,
1343 .maxlen = sizeof(int),
1344 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001345 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001346 },
Adam Litke54f9f802007-10-16 01:26:20 -07001347 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001348 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001349 .data = NULL,
1350 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001353 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354#endif
1355 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 .procname = "lowmem_reserve_ratio",
1357 .data = &sysctl_lowmem_reserve_ratio,
1358 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1359 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001360 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 },
1362 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001363 .procname = "drop_caches",
1364 .data = &sysctl_drop_caches,
1365 .maxlen = sizeof(int),
1366 .mode = 0644,
1367 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001368 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001369 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001370 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001371#ifdef CONFIG_COMPACTION
1372 {
1373 .procname = "compact_memory",
1374 .data = &sysctl_compact_memory,
1375 .maxlen = sizeof(int),
1376 .mode = 0200,
1377 .proc_handler = sysctl_compaction_handler,
1378 },
Mel Gorman5e771902010-05-24 14:32:31 -07001379 {
1380 .procname = "extfrag_threshold",
1381 .data = &sysctl_extfrag_threshold,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = sysctl_extfrag_handler,
1385 .extra1 = &min_extfrag_threshold,
1386 .extra2 = &max_extfrag_threshold,
1387 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001388 {
1389 .procname = "compact_unevictable_allowed",
1390 .data = &sysctl_compact_unevictable_allowed,
1391 .maxlen = sizeof(int),
1392 .mode = 0644,
1393 .proc_handler = proc_dointvec,
1394 .extra1 = &zero,
1395 .extra2 = &one,
1396 },
Mel Gorman5e771902010-05-24 14:32:31 -07001397
Mel Gorman76ab0f52010-05-24 14:32:28 -07001398#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001399 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 .procname = "min_free_kbytes",
1401 .data = &min_free_kbytes,
1402 .maxlen = sizeof(min_free_kbytes),
1403 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001404 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 .extra1 = &zero,
1406 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001407 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001408 .procname = "watermark_scale_factor",
1409 .data = &watermark_scale_factor,
1410 .maxlen = sizeof(watermark_scale_factor),
1411 .mode = 0644,
1412 .proc_handler = watermark_scale_factor_sysctl_handler,
1413 .extra1 = &one,
1414 .extra2 = &one_thousand,
1415 },
1416 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001417 .procname = "percpu_pagelist_fraction",
1418 .data = &percpu_pagelist_fraction,
1419 .maxlen = sizeof(percpu_pagelist_fraction),
1420 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001421 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001422 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001423 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424#ifdef CONFIG_MMU
1425 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 .procname = "max_map_count",
1427 .data = &sysctl_max_map_count,
1428 .maxlen = sizeof(sysctl_max_map_count),
1429 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001430 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001431 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001433#else
1434 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001435 .procname = "nr_trim_pages",
1436 .data = &sysctl_nr_trim_pages,
1437 .maxlen = sizeof(sysctl_nr_trim_pages),
1438 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001439 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001440 .extra1 = &zero,
1441 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442#endif
1443 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 .procname = "laptop_mode",
1445 .data = &laptop_mode,
1446 .maxlen = sizeof(laptop_mode),
1447 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001448 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 },
1450 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 .procname = "block_dump",
1452 .data = &block_dump,
1453 .maxlen = sizeof(block_dump),
1454 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001455 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 .extra1 = &zero,
1457 },
1458 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 .procname = "vfs_cache_pressure",
1460 .data = &sysctl_vfs_cache_pressure,
1461 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1462 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001463 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 .extra1 = &zero,
1465 },
1466#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1467 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 .procname = "legacy_va_layout",
1469 .data = &sysctl_legacy_va_layout,
1470 .maxlen = sizeof(sysctl_legacy_va_layout),
1471 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001472 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 .extra1 = &zero,
1474 },
1475#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001476#ifdef CONFIG_NUMA
1477 {
Christoph Lameter17436602006-01-18 17:42:32 -08001478 .procname = "zone_reclaim_mode",
1479 .data = &zone_reclaim_mode,
1480 .maxlen = sizeof(zone_reclaim_mode),
1481 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001482 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001483 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001484 },
Christoph Lameter96146342006-07-03 00:24:13 -07001485 {
Christoph Lameter96146342006-07-03 00:24:13 -07001486 .procname = "min_unmapped_ratio",
1487 .data = &sysctl_min_unmapped_ratio,
1488 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001490 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001491 .extra1 = &zero,
1492 .extra2 = &one_hundred,
1493 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001494 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001495 .procname = "min_slab_ratio",
1496 .data = &sysctl_min_slab_ratio,
1497 .maxlen = sizeof(sysctl_min_slab_ratio),
1498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001499 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001500 .extra1 = &zero,
1501 .extra2 = &one_hundred,
1502 },
Christoph Lameter17436602006-01-18 17:42:32 -08001503#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001504#ifdef CONFIG_SMP
1505 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001506 .procname = "stat_interval",
1507 .data = &sysctl_stat_interval,
1508 .maxlen = sizeof(sysctl_stat_interval),
1509 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001510 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001511 },
1512#endif
David Howells6e141542009-12-15 19:27:45 +00001513#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001514 {
Eric Parised032182007-06-28 15:55:21 -04001515 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001516 .data = &dac_mmap_min_addr,
1517 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001518 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001519 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001520 },
David Howells6e141542009-12-15 19:27:45 +00001521#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001522#ifdef CONFIG_NUMA
1523 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001524 .procname = "numa_zonelist_order",
1525 .data = &numa_zonelist_order,
1526 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1527 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001528 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001529 },
1530#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001531#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001532 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001533 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001534 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001535#ifdef CONFIG_X86_32
1536 .data = &vdso32_enabled,
1537 .maxlen = sizeof(vdso32_enabled),
1538#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001539 .data = &vdso_enabled,
1540 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001541#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001543 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001544 .extra1 = &zero,
1545 },
1546#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001547#ifdef CONFIG_HIGHMEM
1548 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001549 .procname = "highmem_is_dirtyable",
1550 .data = &vm_highmem_is_dirtyable,
1551 .maxlen = sizeof(vm_highmem_is_dirtyable),
1552 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001553 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001554 .extra1 = &zero,
1555 .extra2 = &one,
1556 },
1557#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001558#ifdef CONFIG_MEMORY_FAILURE
1559 {
Andi Kleen6a460792009-09-16 11:50:15 +02001560 .procname = "memory_failure_early_kill",
1561 .data = &sysctl_memory_failure_early_kill,
1562 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1563 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001564 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001565 .extra1 = &zero,
1566 .extra2 = &one,
1567 },
1568 {
Andi Kleen6a460792009-09-16 11:50:15 +02001569 .procname = "memory_failure_recovery",
1570 .data = &sysctl_memory_failure_recovery,
1571 .maxlen = sizeof(sysctl_memory_failure_recovery),
1572 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001573 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001574 .extra1 = &zero,
1575 .extra2 = &one,
1576 },
1577#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001578 {
1579 .procname = "user_reserve_kbytes",
1580 .data = &sysctl_user_reserve_kbytes,
1581 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1582 .mode = 0644,
1583 .proc_handler = proc_doulongvec_minmax,
1584 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001585 {
1586 .procname = "admin_reserve_kbytes",
1587 .data = &sysctl_admin_reserve_kbytes,
1588 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1589 .mode = 0644,
1590 .proc_handler = proc_doulongvec_minmax,
1591 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001592#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1593 {
1594 .procname = "mmap_rnd_bits",
1595 .data = &mmap_rnd_bits,
1596 .maxlen = sizeof(mmap_rnd_bits),
1597 .mode = 0600,
1598 .proc_handler = proc_dointvec_minmax,
1599 .extra1 = (void *)&mmap_rnd_bits_min,
1600 .extra2 = (void *)&mmap_rnd_bits_max,
1601 },
1602#endif
1603#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1604 {
1605 .procname = "mmap_rnd_compat_bits",
1606 .data = &mmap_rnd_compat_bits,
1607 .maxlen = sizeof(mmap_rnd_compat_bits),
1608 .mode = 0600,
1609 .proc_handler = proc_dointvec_minmax,
1610 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1611 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1612 },
1613#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001614 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615};
1616
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001617static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 .procname = "inode-nr",
1620 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001621 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001623 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 },
1625 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 .procname = "inode-state",
1627 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001628 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001630 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 },
1632 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 .procname = "file-nr",
1634 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001635 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001637 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 },
1639 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 .procname = "file-max",
1641 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001642 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001644 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 },
1646 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001647 .procname = "nr_open",
1648 .data = &sysctl_nr_open,
1649 .maxlen = sizeof(int),
1650 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001651 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001652 .extra1 = &sysctl_nr_open_min,
1653 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001654 },
1655 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 .procname = "dentry-state",
1657 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001658 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001660 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 },
1662 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 .procname = "overflowuid",
1664 .data = &fs_overflowuid,
1665 .maxlen = sizeof(int),
1666 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001667 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 .extra1 = &minolduid,
1669 .extra2 = &maxolduid,
1670 },
1671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 .procname = "overflowgid",
1673 .data = &fs_overflowgid,
1674 .maxlen = sizeof(int),
1675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001676 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 .extra1 = &minolduid,
1678 .extra2 = &maxolduid,
1679 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001680#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 .procname = "leases-enable",
1683 .data = &leases_enable,
1684 .maxlen = sizeof(int),
1685 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001686 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001688#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689#ifdef CONFIG_DNOTIFY
1690 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 .procname = "dir-notify-enable",
1692 .data = &dir_notify_enable,
1693 .maxlen = sizeof(int),
1694 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001695 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 },
1697#endif
1698#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001699#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 .procname = "lease-break-time",
1702 .data = &lease_break_time,
1703 .maxlen = sizeof(int),
1704 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001705 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001707#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001708#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 .procname = "aio-nr",
1711 .data = &aio_nr,
1712 .maxlen = sizeof(aio_nr),
1713 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001714 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 },
1716 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 .procname = "aio-max-nr",
1718 .data = &aio_max_nr,
1719 .maxlen = sizeof(aio_max_nr),
1720 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001721 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001723#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001724#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001725 {
Robert Love0399cb02005-07-13 12:38:18 -04001726 .procname = "inotify",
1727 .mode = 0555,
1728 .child = inotify_table,
1729 },
1730#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001731#ifdef CONFIG_EPOLL
1732 {
1733 .procname = "epoll",
1734 .mode = 0555,
1735 .child = epoll_table,
1736 },
1737#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001739 {
Kees Cook800179c2012-07-25 17:29:07 -07001740 .procname = "protected_symlinks",
1741 .data = &sysctl_protected_symlinks,
1742 .maxlen = sizeof(int),
1743 .mode = 0600,
1744 .proc_handler = proc_dointvec_minmax,
1745 .extra1 = &zero,
1746 .extra2 = &one,
1747 },
1748 {
1749 .procname = "protected_hardlinks",
1750 .data = &sysctl_protected_hardlinks,
1751 .maxlen = sizeof(int),
1752 .mode = 0600,
1753 .proc_handler = proc_dointvec_minmax,
1754 .extra1 = &zero,
1755 .extra2 = &one,
1756 },
1757 {
Alan Coxd6e71142005-06-23 00:09:43 -07001758 .procname = "suid_dumpable",
1759 .data = &suid_dumpable,
1760 .maxlen = sizeof(int),
1761 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001762 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001763 .extra1 = &zero,
1764 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001765 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001766#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1767 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001768 .procname = "binfmt_misc",
1769 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001770 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001771 },
1772#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001773 {
Jens Axboeff9da692010-06-03 14:54:39 +02001774 .procname = "pipe-max-size",
1775 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001776 .maxlen = sizeof(int),
1777 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001778 .proc_handler = &pipe_proc_fn,
1779 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001780 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001781 {
1782 .procname = "pipe-user-pages-hard",
1783 .data = &pipe_user_pages_hard,
1784 .maxlen = sizeof(pipe_user_pages_hard),
1785 .mode = 0644,
1786 .proc_handler = proc_doulongvec_minmax,
1787 },
1788 {
1789 .procname = "pipe-user-pages-soft",
1790 .data = &pipe_user_pages_soft,
1791 .maxlen = sizeof(pipe_user_pages_soft),
1792 .mode = 0644,
1793 .proc_handler = proc_doulongvec_minmax,
1794 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001795 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796};
1797
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001798static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001799#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001800 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001801 .procname = "exception-trace",
1802 .data = &show_unhandled_signals,
1803 .maxlen = sizeof(int),
1804 .mode = 0644,
1805 .proc_handler = proc_dointvec
1806 },
1807#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001808#if defined(CONFIG_OPTPROBES)
1809 {
1810 .procname = "kprobes-optimization",
1811 .data = &sysctl_kprobes_optimization,
1812 .maxlen = sizeof(int),
1813 .mode = 0644,
1814 .proc_handler = proc_kprobes_optimization_handler,
1815 .extra1 = &zero,
1816 .extra2 = &one,
1817 },
1818#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001819 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820};
1821
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001822static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001823 { }
Robert Love0eeca282005-07-12 17:06:03 -04001824};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001826int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001827{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001828 struct ctl_table_header *hdr;
1829
1830 hdr = register_sysctl_table(sysctl_base_table);
1831 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001832 return 0;
1833}
1834
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001835#endif /* CONFIG_SYSCTL */
1836
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837/*
1838 * /proc/sys support
1839 */
1840
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001841#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
Kees Cookf8808302014-06-06 14:37:17 -07001843static int _proc_do_string(char *data, int maxlen, int write,
1844 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001845 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001846{
1847 size_t len;
1848 char __user *p;
1849 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001850
1851 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001852 *lenp = 0;
1853 return 0;
1854 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001855
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001856 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001857 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1858 /* Only continue writes not past the end of buffer. */
1859 len = strlen(data);
1860 if (len > maxlen - 1)
1861 len = maxlen - 1;
1862
1863 if (*ppos > len)
1864 return 0;
1865 len = *ppos;
1866 } else {
1867 /* Start writing from beginning of buffer. */
1868 len = 0;
1869 }
1870
Kees Cook2ca9bb42014-06-06 14:37:18 -07001871 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001872 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001873 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001874 if (get_user(c, p++))
1875 return -EFAULT;
1876 if (c == 0 || c == '\n')
1877 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001878 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001879 }
Kees Cookf8808302014-06-06 14:37:17 -07001880 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001881 } else {
1882 len = strlen(data);
1883 if (len > maxlen)
1884 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001885
1886 if (*ppos > len) {
1887 *lenp = 0;
1888 return 0;
1889 }
1890
1891 data += *ppos;
1892 len -= *ppos;
1893
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001894 if (len > *lenp)
1895 len = *lenp;
1896 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001897 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001898 return -EFAULT;
1899 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001900 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001901 return -EFAULT;
1902 len++;
1903 }
1904 *lenp = len;
1905 *ppos += len;
1906 }
1907 return 0;
1908}
1909
Kees Cookf4aacea2014-06-06 14:37:19 -07001910static void warn_sysctl_write(struct ctl_table *table)
1911{
1912 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1913 "This will not be supported in the future. To silence this\n"
1914 "warning, set kernel.sysctl_writes_strict = -1\n",
1915 current->comm, table->procname);
1916}
1917
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918/**
1919 * proc_dostring - read a string sysctl
1920 * @table: the sysctl table
1921 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 * @buffer: the user buffer
1923 * @lenp: the size of the user buffer
1924 * @ppos: file position
1925 *
1926 * Reads/writes a string from/to the user buffer. If the kernel
1927 * buffer provided is not large enough to hold the string, the
1928 * string is truncated. The copied string is %NULL-terminated.
1929 * If the string is being read by the user process, it is copied
1930 * and a newline '\n' is added. It is truncated if the buffer is
1931 * not large enough.
1932 *
1933 * Returns 0 on success.
1934 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001935int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 void __user *buffer, size_t *lenp, loff_t *ppos)
1937{
Kees Cookf4aacea2014-06-06 14:37:19 -07001938 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1939 warn_sysctl_write(table);
1940
Kees Cookf8808302014-06-06 14:37:17 -07001941 return _proc_do_string((char *)(table->data), table->maxlen, write,
1942 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943}
1944
Amerigo Wang00b7c332010-05-05 00:26:45 +00001945static size_t proc_skip_spaces(char **buf)
1946{
1947 size_t ret;
1948 char *tmp = skip_spaces(*buf);
1949 ret = tmp - *buf;
1950 *buf = tmp;
1951 return ret;
1952}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001954static void proc_skip_char(char **buf, size_t *size, const char v)
1955{
1956 while (*size) {
1957 if (**buf != v)
1958 break;
1959 (*size)--;
1960 (*buf)++;
1961 }
1962}
1963
Amerigo Wang00b7c332010-05-05 00:26:45 +00001964#define TMPBUFLEN 22
1965/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001966 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001967 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001968 * @buf: a kernel buffer
1969 * @size: size of the kernel buffer
1970 * @val: this is where the number will be stored
1971 * @neg: set to %TRUE if number is negative
1972 * @perm_tr: a vector which contains the allowed trailers
1973 * @perm_tr_len: size of the perm_tr vector
1974 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001975 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001976 * In case of success %0 is returned and @buf and @size are updated with
1977 * the amount of bytes read. If @tr is non-NULL and a trailing
1978 * character exists (size is non-zero after returning from this
1979 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001980 */
1981static int proc_get_long(char **buf, size_t *size,
1982 unsigned long *val, bool *neg,
1983 const char *perm_tr, unsigned perm_tr_len, char *tr)
1984{
1985 int len;
1986 char *p, tmp[TMPBUFLEN];
1987
1988 if (!*size)
1989 return -EINVAL;
1990
1991 len = *size;
1992 if (len > TMPBUFLEN - 1)
1993 len = TMPBUFLEN - 1;
1994
1995 memcpy(tmp, *buf, len);
1996
1997 tmp[len] = 0;
1998 p = tmp;
1999 if (*p == '-' && *size > 1) {
2000 *neg = true;
2001 p++;
2002 } else
2003 *neg = false;
2004 if (!isdigit(*p))
2005 return -EINVAL;
2006
2007 *val = simple_strtoul(p, &p, 0);
2008
2009 len = p - tmp;
2010
2011 /* We don't know if the next char is whitespace thus we may accept
2012 * invalid integers (e.g. 1234...a) or two integers instead of one
2013 * (e.g. 123...1). So lets not allow such large numbers. */
2014 if (len == TMPBUFLEN - 1)
2015 return -EINVAL;
2016
2017 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2018 return -EINVAL;
2019
2020 if (tr && (len < *size))
2021 *tr = *p;
2022
2023 *buf += len;
2024 *size -= len;
2025
2026 return 0;
2027}
2028
2029/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002030 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002031 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002032 * @buf: the user buffer
2033 * @size: the size of the user buffer
2034 * @val: the integer to be converted
2035 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002036 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002037 * In case of success %0 is returned and @buf and @size are updated with
2038 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002039 */
2040static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2041 bool neg)
2042{
2043 int len;
2044 char tmp[TMPBUFLEN], *p = tmp;
2045
2046 sprintf(p, "%s%lu", neg ? "-" : "", val);
2047 len = strlen(tmp);
2048 if (len > *size)
2049 len = *size;
2050 if (copy_to_user(*buf, tmp, len))
2051 return -EFAULT;
2052 *size -= len;
2053 *buf += len;
2054 return 0;
2055}
2056#undef TMPBUFLEN
2057
2058static int proc_put_char(void __user **buf, size_t *size, char c)
2059{
2060 if (*size) {
2061 char __user **buffer = (char __user **)buf;
2062 if (put_user(c, *buffer))
2063 return -EFAULT;
2064 (*size)--, (*buffer)++;
2065 *buf = *buffer;
2066 }
2067 return 0;
2068}
2069
2070static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 int *valp,
2072 int write, void *data)
2073{
2074 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002075 if (*negp) {
2076 if (*lvalp > (unsigned long) INT_MAX + 1)
2077 return -EINVAL;
2078 *valp = -*lvalp;
2079 } else {
2080 if (*lvalp > (unsigned long) INT_MAX)
2081 return -EINVAL;
2082 *valp = *lvalp;
2083 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 } else {
2085 int val = *valp;
2086 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002087 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002088 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002090 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 *lvalp = (unsigned long)val;
2092 }
2093 }
2094 return 0;
2095}
2096
Amerigo Wang00b7c332010-05-05 00:26:45 +00002097static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2098
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002099static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002100 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002101 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002102 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 int write, void *data),
2104 void *data)
2105{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002106 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002107 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002108 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
Amerigo Wang00b7c332010-05-05 00:26:45 +00002110 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 *lenp = 0;
2112 return 0;
2113 }
2114
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002115 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 vleft = table->maxlen / sizeof(*i);
2117 left = *lenp;
2118
2119 if (!conv)
2120 conv = do_proc_dointvec_conv;
2121
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002123 if (*ppos) {
2124 switch (sysctl_writes_strict) {
2125 case SYSCTL_WRITES_STRICT:
2126 goto out;
2127 case SYSCTL_WRITES_WARN:
2128 warn_sysctl_write(table);
2129 break;
2130 default:
2131 break;
2132 }
2133 }
2134
Amerigo Wang00b7c332010-05-05 00:26:45 +00002135 if (left > PAGE_SIZE - 1)
2136 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002137 p = kbuf = memdup_user_nul(buffer, left);
2138 if (IS_ERR(kbuf))
2139 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002140 }
2141
2142 for (; left && vleft--; i++, first=0) {
2143 unsigned long lval;
2144 bool neg;
2145
2146 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002147 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002148
J. R. Okajima563b0462010-05-25 16:10:14 -07002149 if (!left)
2150 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002151 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002152 proc_wspace_sep,
2153 sizeof(proc_wspace_sep), NULL);
2154 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002156 if (conv(&neg, &lval, i, 1, data)) {
2157 err = -EINVAL;
2158 break;
2159 }
2160 } else {
2161 if (conv(&neg, &lval, i, 0, data)) {
2162 err = -EINVAL;
2163 break;
2164 }
2165 if (!first)
2166 err = proc_put_char(&buffer, &left, '\t');
2167 if (err)
2168 break;
2169 err = proc_put_long(&buffer, &left, lval, neg);
2170 if (err)
2171 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 }
2173 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002174
2175 if (!write && !first && left && !err)
2176 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002177 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002178 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002179 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002180 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002181 if (first)
2182 return err ? : -EINVAL;
2183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002185out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002187 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188}
2189
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002190static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002191 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002192 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002193 int write, void *data),
2194 void *data)
2195{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002196 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002197 buffer, lenp, ppos, conv, data);
2198}
2199
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200/**
2201 * proc_dointvec - read a vector of integers
2202 * @table: the sysctl table
2203 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 * @buffer: the user buffer
2205 * @lenp: the size of the user buffer
2206 * @ppos: file position
2207 *
2208 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2209 * values from/to the user buffer, treated as an ASCII string.
2210 *
2211 * Returns 0 on success.
2212 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002213int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 void __user *buffer, size_t *lenp, loff_t *ppos)
2215{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002216 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 NULL,NULL);
2218}
2219
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002220/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002221 * Taint values can only be increased
2222 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002223 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002224static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002225 void __user *buffer, size_t *lenp, loff_t *ppos)
2226{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002227 struct ctl_table t;
2228 unsigned long tmptaint = get_taint();
2229 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002230
Bastian Blank91fcd412007-04-23 14:41:14 -07002231 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002232 return -EPERM;
2233
Andi Kleen25ddbb12008-10-15 22:01:41 -07002234 t = *table;
2235 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002236 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002237 if (err < 0)
2238 return err;
2239
2240 if (write) {
2241 /*
2242 * Poor man's atomic or. Not worth adding a primitive
2243 * to everyone's atomic.h for this
2244 */
2245 int i;
2246 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2247 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302248 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002249 }
2250 }
2251
2252 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002253}
2254
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002255#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002256static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002257 void __user *buffer, size_t *lenp, loff_t *ppos)
2258{
2259 if (write && !capable(CAP_SYS_ADMIN))
2260 return -EPERM;
2261
2262 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2263}
2264#endif
2265
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266struct do_proc_dointvec_minmax_conv_param {
2267 int *min;
2268 int *max;
2269};
2270
Amerigo Wang00b7c332010-05-05 00:26:45 +00002271static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2272 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 int write, void *data)
2274{
2275 struct do_proc_dointvec_minmax_conv_param *param = data;
2276 if (write) {
2277 int val = *negp ? -*lvalp : *lvalp;
2278 if ((param->min && *param->min > val) ||
2279 (param->max && *param->max < val))
2280 return -EINVAL;
2281 *valp = val;
2282 } else {
2283 int val = *valp;
2284 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002285 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002286 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002288 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 *lvalp = (unsigned long)val;
2290 }
2291 }
2292 return 0;
2293}
2294
2295/**
2296 * proc_dointvec_minmax - read a vector of integers with min/max values
2297 * @table: the sysctl table
2298 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 * @buffer: the user buffer
2300 * @lenp: the size of the user buffer
2301 * @ppos: file position
2302 *
2303 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2304 * values from/to the user buffer, treated as an ASCII string.
2305 *
2306 * This routine will ensure the values are within the range specified by
2307 * table->extra1 (min) and table->extra2 (max).
2308 *
2309 * Returns 0 on success.
2310 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002311int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 void __user *buffer, size_t *lenp, loff_t *ppos)
2313{
2314 struct do_proc_dointvec_minmax_conv_param param = {
2315 .min = (int *) table->extra1,
2316 .max = (int *) table->extra2,
2317 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002318 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 do_proc_dointvec_minmax_conv, &param);
2320}
2321
Kees Cook54b50192012-07-30 14:39:18 -07002322static void validate_coredump_safety(void)
2323{
Alex Kelly046d6622012-10-04 17:15:23 -07002324#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002325 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002326 core_pattern[0] != '/' && core_pattern[0] != '|') {
2327 printk(KERN_WARNING "Unsafe core_pattern used with "\
2328 "suid_dumpable=2. Pipe handler or fully qualified "\
2329 "core dump path required.\n");
2330 }
Alex Kelly046d6622012-10-04 17:15:23 -07002331#endif
Kees Cook54b50192012-07-30 14:39:18 -07002332}
2333
2334static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2335 void __user *buffer, size_t *lenp, loff_t *ppos)
2336{
2337 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2338 if (!error)
2339 validate_coredump_safety();
2340 return error;
2341}
2342
Alex Kelly046d6622012-10-04 17:15:23 -07002343#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002344static int proc_dostring_coredump(struct ctl_table *table, int write,
2345 void __user *buffer, size_t *lenp, loff_t *ppos)
2346{
2347 int error = proc_dostring(table, write, buffer, lenp, ppos);
2348 if (!error)
2349 validate_coredump_safety();
2350 return error;
2351}
Alex Kelly046d6622012-10-04 17:15:23 -07002352#endif
Kees Cook54b50192012-07-30 14:39:18 -07002353
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002354static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 void __user *buffer,
2356 size_t *lenp, loff_t *ppos,
2357 unsigned long convmul,
2358 unsigned long convdiv)
2359{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002360 unsigned long *i, *min, *max;
2361 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002362 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002363 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002364
2365 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 *lenp = 0;
2367 return 0;
2368 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002369
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002370 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 min = (unsigned long *) table->extra1;
2372 max = (unsigned long *) table->extra2;
2373 vleft = table->maxlen / sizeof(unsigned long);
2374 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002375
2376 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002377 if (*ppos) {
2378 switch (sysctl_writes_strict) {
2379 case SYSCTL_WRITES_STRICT:
2380 goto out;
2381 case SYSCTL_WRITES_WARN:
2382 warn_sysctl_write(table);
2383 break;
2384 default:
2385 break;
2386 }
2387 }
2388
Amerigo Wang00b7c332010-05-05 00:26:45 +00002389 if (left > PAGE_SIZE - 1)
2390 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002391 p = kbuf = memdup_user_nul(buffer, left);
2392 if (IS_ERR(kbuf))
2393 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002394 }
2395
Eric Dumazet27b3d802010-10-07 12:59:29 -07002396 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002397 unsigned long val;
2398
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002400 bool neg;
2401
Al Viro70f6cbb2015-12-24 00:13:10 -05002402 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002403
Al Viro70f6cbb2015-12-24 00:13:10 -05002404 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002405 proc_wspace_sep,
2406 sizeof(proc_wspace_sep), NULL);
2407 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 break;
2409 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 continue;
2411 if ((min && val < *min) || (max && val > *max))
2412 continue;
2413 *i = val;
2414 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002415 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002416 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002417 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002418 if (err)
2419 break;
2420 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002421 err = proc_put_long(&buffer, &left, val, false);
2422 if (err)
2423 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 }
2425 }
2426
Amerigo Wang00b7c332010-05-05 00:26:45 +00002427 if (!write && !first && left && !err)
2428 err = proc_put_char(&buffer, &left, '\n');
2429 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002430 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002432 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002433 if (first)
2434 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002437out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002439 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440}
2441
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002442static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002443 void __user *buffer,
2444 size_t *lenp, loff_t *ppos,
2445 unsigned long convmul,
2446 unsigned long convdiv)
2447{
2448 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002449 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002450}
2451
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452/**
2453 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2454 * @table: the sysctl table
2455 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 * @buffer: the user buffer
2457 * @lenp: the size of the user buffer
2458 * @ppos: file position
2459 *
2460 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2461 * values from/to the user buffer, treated as an ASCII string.
2462 *
2463 * This routine will ensure the values are within the range specified by
2464 * table->extra1 (min) and table->extra2 (max).
2465 *
2466 * Returns 0 on success.
2467 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002468int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 void __user *buffer, size_t *lenp, loff_t *ppos)
2470{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002471 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472}
2473
2474/**
2475 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2476 * @table: the sysctl table
2477 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 * @buffer: the user buffer
2479 * @lenp: the size of the user buffer
2480 * @ppos: file position
2481 *
2482 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2483 * values from/to the user buffer, treated as an ASCII string. The values
2484 * are treated as milliseconds, and converted to jiffies when they are stored.
2485 *
2486 * This routine will ensure the values are within the range specified by
2487 * table->extra1 (min) and table->extra2 (max).
2488 *
2489 * Returns 0 on success.
2490 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002491int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 void __user *buffer,
2493 size_t *lenp, loff_t *ppos)
2494{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002495 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 lenp, ppos, HZ, 1000l);
2497}
2498
2499
Amerigo Wang00b7c332010-05-05 00:26:45 +00002500static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 int *valp,
2502 int write, void *data)
2503{
2504 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002505 if (*lvalp > LONG_MAX / HZ)
2506 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2508 } else {
2509 int val = *valp;
2510 unsigned long lval;
2511 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002512 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002513 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002515 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 lval = (unsigned long)val;
2517 }
2518 *lvalp = lval / HZ;
2519 }
2520 return 0;
2521}
2522
Amerigo Wang00b7c332010-05-05 00:26:45 +00002523static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 int *valp,
2525 int write, void *data)
2526{
2527 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002528 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2529 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2531 } else {
2532 int val = *valp;
2533 unsigned long lval;
2534 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002535 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002536 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002538 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 lval = (unsigned long)val;
2540 }
2541 *lvalp = jiffies_to_clock_t(lval);
2542 }
2543 return 0;
2544}
2545
Amerigo Wang00b7c332010-05-05 00:26:45 +00002546static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 int *valp,
2548 int write, void *data)
2549{
2550 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002551 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2552
2553 if (jif > INT_MAX)
2554 return 1;
2555 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 } else {
2557 int val = *valp;
2558 unsigned long lval;
2559 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002560 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002561 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002563 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 lval = (unsigned long)val;
2565 }
2566 *lvalp = jiffies_to_msecs(lval);
2567 }
2568 return 0;
2569}
2570
2571/**
2572 * proc_dointvec_jiffies - read a vector of integers as seconds
2573 * @table: the sysctl table
2574 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 * @buffer: the user buffer
2576 * @lenp: the size of the user buffer
2577 * @ppos: file position
2578 *
2579 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2580 * values from/to the user buffer, treated as an ASCII string.
2581 * The values read are assumed to be in seconds, and are converted into
2582 * jiffies.
2583 *
2584 * Returns 0 on success.
2585 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002586int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 void __user *buffer, size_t *lenp, loff_t *ppos)
2588{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002589 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 do_proc_dointvec_jiffies_conv,NULL);
2591}
2592
2593/**
2594 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2595 * @table: the sysctl table
2596 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 * @buffer: the user buffer
2598 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002599 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 *
2601 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2602 * values from/to the user buffer, treated as an ASCII string.
2603 * The values read are assumed to be in 1/USER_HZ seconds, and
2604 * are converted into jiffies.
2605 *
2606 * Returns 0 on success.
2607 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002608int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 void __user *buffer, size_t *lenp, loff_t *ppos)
2610{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002611 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 do_proc_dointvec_userhz_jiffies_conv,NULL);
2613}
2614
2615/**
2616 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2617 * @table: the sysctl table
2618 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 * @buffer: the user buffer
2620 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002621 * @ppos: file position
2622 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 *
2624 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2625 * values from/to the user buffer, treated as an ASCII string.
2626 * The values read are assumed to be in 1/1000 seconds, and
2627 * are converted into jiffies.
2628 *
2629 * Returns 0 on success.
2630 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002631int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 void __user *buffer, size_t *lenp, loff_t *ppos)
2633{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002634 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 do_proc_dointvec_ms_jiffies_conv, NULL);
2636}
2637
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002638static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002639 void __user *buffer, size_t *lenp, loff_t *ppos)
2640{
2641 struct pid *new_pid;
2642 pid_t tmp;
2643 int r;
2644
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002645 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002646
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002647 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002648 lenp, ppos, NULL, NULL);
2649 if (r || !write)
2650 return r;
2651
2652 new_pid = find_get_pid(tmp);
2653 if (!new_pid)
2654 return -ESRCH;
2655
2656 put_pid(xchg(&cad_pid, new_pid));
2657 return 0;
2658}
2659
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002660/**
2661 * proc_do_large_bitmap - read/write from/to a large bitmap
2662 * @table: the sysctl table
2663 * @write: %TRUE if this is a write to the sysctl file
2664 * @buffer: the user buffer
2665 * @lenp: the size of the user buffer
2666 * @ppos: file position
2667 *
2668 * The bitmap is stored at table->data and the bitmap length (in bits)
2669 * in table->maxlen.
2670 *
2671 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2672 * large bitmaps may be represented in a compact manner. Writing into
2673 * the file will clear the bitmap then update it with the given input.
2674 *
2675 * Returns 0 on success.
2676 */
2677int proc_do_large_bitmap(struct ctl_table *table, int write,
2678 void __user *buffer, size_t *lenp, loff_t *ppos)
2679{
2680 int err = 0;
2681 bool first = 1;
2682 size_t left = *lenp;
2683 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002684 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002685 unsigned long *tmp_bitmap = NULL;
2686 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2687
WANG Cong122ff242014-05-12 16:04:53 -07002688 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002689 *lenp = 0;
2690 return 0;
2691 }
2692
2693 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002694 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002695
2696 if (left > PAGE_SIZE - 1)
2697 left = PAGE_SIZE - 1;
2698
Al Viro70f6cbb2015-12-24 00:13:10 -05002699 p = kbuf = memdup_user_nul(buffer, left);
2700 if (IS_ERR(kbuf))
2701 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002702
2703 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2704 GFP_KERNEL);
2705 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002706 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002707 return -ENOMEM;
2708 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002709 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002710 while (!err && left) {
2711 unsigned long val_a, val_b;
2712 bool neg;
2713
Al Viro70f6cbb2015-12-24 00:13:10 -05002714 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002715 sizeof(tr_a), &c);
2716 if (err)
2717 break;
2718 if (val_a >= bitmap_len || neg) {
2719 err = -EINVAL;
2720 break;
2721 }
2722
2723 val_b = val_a;
2724 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002725 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002726 left--;
2727 }
2728
2729 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05002730 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002731 &neg, tr_b, sizeof(tr_b),
2732 &c);
2733 if (err)
2734 break;
2735 if (val_b >= bitmap_len || neg ||
2736 val_a > val_b) {
2737 err = -EINVAL;
2738 break;
2739 }
2740 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002741 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002742 left--;
2743 }
2744 }
2745
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002746 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002747 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05002748 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002749 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002750 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002751 } else {
2752 unsigned long bit_a, bit_b = 0;
2753
2754 while (left) {
2755 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2756 if (bit_a >= bitmap_len)
2757 break;
2758 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2759 bit_a + 1) - 1;
2760
2761 if (!first) {
2762 err = proc_put_char(&buffer, &left, ',');
2763 if (err)
2764 break;
2765 }
2766 err = proc_put_long(&buffer, &left, bit_a, false);
2767 if (err)
2768 break;
2769 if (bit_a != bit_b) {
2770 err = proc_put_char(&buffer, &left, '-');
2771 if (err)
2772 break;
2773 err = proc_put_long(&buffer, &left, bit_b, false);
2774 if (err)
2775 break;
2776 }
2777
2778 first = 0; bit_b++;
2779 }
2780 if (!err)
2781 err = proc_put_char(&buffer, &left, '\n');
2782 }
2783
2784 if (!err) {
2785 if (write) {
2786 if (*ppos)
2787 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2788 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002789 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002790 }
2791 kfree(tmp_bitmap);
2792 *lenp -= left;
2793 *ppos += *lenp;
2794 return 0;
2795 } else {
2796 kfree(tmp_bitmap);
2797 return err;
2798 }
2799}
2800
Jovi Zhang55610502011-01-12 17:00:45 -08002801#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002803int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 void __user *buffer, size_t *lenp, loff_t *ppos)
2805{
2806 return -ENOSYS;
2807}
2808
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002809int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 void __user *buffer, size_t *lenp, loff_t *ppos)
2811{
2812 return -ENOSYS;
2813}
2814
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002815int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 void __user *buffer, size_t *lenp, loff_t *ppos)
2817{
2818 return -ENOSYS;
2819}
2820
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002821int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 void __user *buffer, size_t *lenp, loff_t *ppos)
2823{
2824 return -ENOSYS;
2825}
2826
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002827int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 void __user *buffer, size_t *lenp, loff_t *ppos)
2829{
2830 return -ENOSYS;
2831}
2832
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002833int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 void __user *buffer, size_t *lenp, loff_t *ppos)
2835{
2836 return -ENOSYS;
2837}
2838
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002839int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 void __user *buffer, size_t *lenp, loff_t *ppos)
2841{
2842 return -ENOSYS;
2843}
2844
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002845int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 void __user *buffer,
2847 size_t *lenp, loff_t *ppos)
2848{
2849 return -ENOSYS;
2850}
2851
2852
Jovi Zhang55610502011-01-12 17:00:45 -08002853#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855/*
2856 * No sense putting this after each symbol definition, twice,
2857 * exception granted :-)
2858 */
2859EXPORT_SYMBOL(proc_dointvec);
2860EXPORT_SYMBOL(proc_dointvec_jiffies);
2861EXPORT_SYMBOL(proc_dointvec_minmax);
2862EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2863EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2864EXPORT_SYMBOL(proc_dostring);
2865EXPORT_SYMBOL(proc_doulongvec_minmax);
2866EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);