blob: ce1fa72dfed1993f8288e4772cfb44183aa07a03 [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. */
Hiroshi Doyufd608032013-04-12 12:43:43 +0300100extern int sysctl_lazy_vfree_pages;
Terje Bergstrom3e9f3d82013-12-31 13:57:55 +0200101extern int sysctl_lazy_vfree_tlb_flush_all_threshold;
Alan Coxd6e71142005-06-23 00:09:43 -0700102extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700103#ifdef CONFIG_COREDUMP
104extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700106extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max;
Rik van Rielf8ade362011-09-01 15:26:50 -0400109extern int extra_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800111extern int percpu_pagelist_fraction;
Andi Kleenbebfa102006-06-26 13:56:52 +0200112extern int compat_log;
Arjan van de Ven97455122008-01-25 21:08:34 +0100113extern int latencytop_enabled;
Al Viroeceea0b2008-05-10 10:08:32 -0400114extern int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000115#ifndef CONFIG_MMU
116extern int sysctl_nr_trim_pages;
117#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400120#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700121static int sixty = 60;
122#endif
123
Aaron Tomlin270750db2014-01-20 17:34:13 +0000124static int __maybe_unused neg_one = -1;
125
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700126static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700127static int __maybe_unused one = 1;
128static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700129static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800130static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700131static int one_hundred = 100;
Dave Youngaf913222009-09-22 16:43:33 -0700132#ifdef CONFIG_PRINTK
133static int ten_thousand = 10000;
134#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700135
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700136/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
137static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
140static int maxolduid = 65535;
141static int minolduid;
142
143static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700144static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Liu Hua80df2842014-04-07 15:38:57 -0700146/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
147#ifdef CONFIG_DETECT_HUNG_TASK
148static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
149#endif
150
Dave Youngd14f1722010-02-25 20:28:57 -0500151#ifdef CONFIG_INOTIFY_USER
152#include <linux/inotify.h>
153#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700154#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#endif
156
157#ifdef __hppa__
158extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530159#endif
160
161#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162extern int unaligned_enabled;
163#endif
164
Jes Sorensend2b176e2006-02-28 09:42:23 -0800165#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800166extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800167#endif
168
Vineet Guptab6fca722013-01-09 20:06:28 +0530169#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
170extern int no_unaligned_warning;
171#endif
172
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700173#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700174
175#define SYSCTL_WRITES_LEGACY -1
176#define SYSCTL_WRITES_WARN 0
177#define SYSCTL_WRITES_STRICT 1
178
179static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
180
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700181static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700182 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700183static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800184 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700185#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700186
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700187#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700188static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700189 void __user *buffer, size_t *lenp, loff_t *ppos);
190#endif
191
Kees Cook54b50192012-07-30 14:39:18 -0700192static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
193 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700194#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700195static int proc_dostring_coredump(struct ctl_table *table, int write,
196 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700197#endif
Kees Cook54b50192012-07-30 14:39:18 -0700198
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700199#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800200/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100201static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700202
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700203static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700204 void __user *buffer, size_t *lenp,
205 loff_t *ppos)
206{
207 int error;
208
209 error = proc_dointvec(table, write, buffer, lenp, ppos);
210 if (error)
211 return error;
212
213 if (write)
214 sysrq_toggle_support(__sysrq_enabled);
215
216 return 0;
217}
218
219#endif
220
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700221static struct ctl_table kern_table[];
222static struct ctl_table vm_table[];
223static struct ctl_table fs_table[];
224static struct ctl_table debug_table[];
225static struct ctl_table dev_table[];
226extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800227#ifdef CONFIG_EPOLL
228extern struct ctl_table epoll_table[];
229#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
232int sysctl_legacy_va_layout;
233#endif
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235/* The default sysctl tables: */
236
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800237static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 .procname = "kernel",
240 .mode = 0555,
241 .child = kern_table,
242 },
243 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 .procname = "vm",
245 .mode = 0555,
246 .child = vm_table,
247 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 .procname = "fs",
250 .mode = 0555,
251 .child = fs_table,
252 },
253 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 .procname = "debug",
255 .mode = 0555,
256 .child = debug_table,
257 },
258 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 .procname = "dev",
260 .mode = 0555,
261 .child = dev_table,
262 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700263 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264};
265
Ingo Molnar77e54a12007-07-09 18:52:00 +0200266#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100267static int min_sched_granularity_ns = 100000; /* 100 usecs */
268static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
269static int min_wakeup_granularity_ns; /* 0 usecs */
270static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200271#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100272static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
273static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200274#endif /* CONFIG_SMP */
275#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200276
Mel Gorman5e771902010-05-24 14:32:31 -0700277#ifdef CONFIG_COMPACTION
278static int min_extfrag_threshold;
279static int max_extfrag_threshold = 1000;
280#endif
281
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700282static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200283 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200284 .procname = "sched_child_runs_first",
285 .data = &sysctl_sched_child_runs_first,
286 .maxlen = sizeof(unsigned int),
287 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800288 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200289 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200290#ifdef CONFIG_SCHED_DEBUG
291 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100292 .procname = "sched_min_granularity_ns",
293 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800296 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100297 .extra1 = &min_sched_granularity_ns,
298 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299 },
300 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200301 .procname = "sched_latency_ns",
302 .data = &sysctl_sched_latency,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800305 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200306 .extra1 = &min_sched_granularity_ns,
307 .extra2 = &max_sched_granularity_ns,
308 },
309 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200310 .procname = "sched_wakeup_granularity_ns",
311 .data = &sysctl_sched_wakeup_granularity,
312 .maxlen = sizeof(unsigned int),
313 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800314 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200315 .extra1 = &min_wakeup_granularity_ns,
316 .extra2 = &max_wakeup_granularity_ns,
317 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200318#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200319 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100320 .procname = "sched_tunable_scaling",
321 .data = &sysctl_sched_tunable_scaling,
322 .maxlen = sizeof(enum sched_tunable_scaling),
323 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800324 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100325 .extra1 = &min_sched_tunable_scaling,
326 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200327 },
328 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900329 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200330 .data = &sysctl_sched_migration_cost,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800333 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200334 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100335 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100336 .procname = "sched_nr_migrate",
337 .data = &sysctl_sched_nr_migrate,
338 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100339 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800340 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100341 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530342 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900343 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200344 .data = &sysctl_sched_time_avg,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800347 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200348 },
349 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900350 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800351 .data = &sysctl_sched_shares_window,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
354 .proc_handler = proc_dointvec,
355 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200356#endif /* CONFIG_SMP */
357#ifdef CONFIG_NUMA_BALANCING
358 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200359 .procname = "numa_balancing_scan_delay_ms",
360 .data = &sysctl_numa_balancing_scan_delay,
361 .maxlen = sizeof(unsigned int),
362 .mode = 0644,
363 .proc_handler = proc_dointvec,
364 },
365 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200366 .procname = "numa_balancing_scan_period_min_ms",
367 .data = &sysctl_numa_balancing_scan_period_min,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
370 .proc_handler = proc_dointvec,
371 },
372 {
373 .procname = "numa_balancing_scan_period_max_ms",
374 .data = &sysctl_numa_balancing_scan_period_max,
375 .maxlen = sizeof(unsigned int),
376 .mode = 0644,
377 .proc_handler = proc_dointvec,
378 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200379 {
380 .procname = "numa_balancing_scan_size_mb",
381 .data = &sysctl_numa_balancing_scan_size,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400384 .proc_handler = proc_dointvec_minmax,
385 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200386 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100387 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800388 .procname = "numa_balancing",
389 .data = NULL, /* filled in by handler */
390 .maxlen = sizeof(unsigned int),
391 .mode = 0644,
392 .proc_handler = sysctl_numa_balancing,
393 .extra1 = &zero,
394 .extra2 = &one,
395 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200396#endif /* CONFIG_NUMA_BALANCING */
397#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200398 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100399 .procname = "sched_rt_period_us",
400 .data = &sysctl_sched_rt_period,
401 .maxlen = sizeof(unsigned int),
402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800403 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100404 },
405 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100406 .procname = "sched_rt_runtime_us",
407 .data = &sysctl_sched_rt_runtime,
408 .maxlen = sizeof(int),
409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800410 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100411 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600412 {
413 .procname = "sched_rr_timeslice_ms",
414 .data = &sched_rr_timeslice,
415 .maxlen = sizeof(int),
416 .mode = 0644,
417 .proc_handler = sched_rr_handler,
418 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100419#ifdef CONFIG_SCHED_AUTOGROUP
420 {
421 .procname = "sched_autogroup_enabled",
422 .data = &sysctl_sched_autogroup_enabled,
423 .maxlen = sizeof(unsigned int),
424 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800425 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100426 .extra1 = &zero,
427 .extra2 = &one,
428 },
429#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700430#ifdef CONFIG_CFS_BANDWIDTH
431 {
432 .procname = "sched_cfs_bandwidth_slice_us",
433 .data = &sysctl_sched_cfs_bandwidth_slice,
434 .maxlen = sizeof(unsigned int),
435 .mode = 0644,
436 .proc_handler = proc_dointvec_minmax,
437 .extra1 = &one,
438 },
439#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700440#ifdef CONFIG_PROVE_LOCKING
441 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700442 .procname = "prove_locking",
443 .data = &prove_locking,
444 .maxlen = sizeof(int),
445 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800446 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700447 },
448#endif
449#ifdef CONFIG_LOCK_STAT
450 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700451 .procname = "lock_stat",
452 .data = &lock_stat,
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
Ingo Molnar77e54a12007-07-09 18:52:00 +0200458 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 .procname = "panic",
460 .data = &panic_timeout,
461 .maxlen = sizeof(int),
462 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800463 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 },
Alex Kelly046d6622012-10-04 17:15:23 -0700465#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 .procname = "core_uses_pid",
468 .data = &core_uses_pid,
469 .maxlen = sizeof(int),
470 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800471 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 },
473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 .procname = "core_pattern",
475 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700476 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700478 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 },
Neil Hormana2939802009-09-23 15:56:56 -0700480 {
Neil Hormana2939802009-09-23 15:56:56 -0700481 .procname = "core_pipe_limit",
482 .data = &core_pipe_limit,
483 .maxlen = sizeof(unsigned int),
484 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800485 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700486 },
Alex Kelly046d6622012-10-04 17:15:23 -0700487#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800488#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700491 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800493 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700495 {
496 .procname = "sysctl_writes_strict",
497 .data = &sysctl_writes_strict,
498 .maxlen = sizeof(int),
499 .mode = 0644,
500 .proc_handler = proc_dointvec_minmax,
501 .extra1 = &neg_one,
502 .extra2 = &one,
503 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800504#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100505#ifdef CONFIG_LATENCYTOP
506 {
507 .procname = "latencytop",
508 .data = &latencytop_enabled,
509 .maxlen = sizeof(int),
510 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800511 .proc_handler = proc_dointvec,
Arjan van de Ven97455122008-01-25 21:08:34 +0100512 },
513#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514#ifdef CONFIG_BLK_DEV_INITRD
515 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 .procname = "real-root-dev",
517 .data = &real_root_dev,
518 .maxlen = sizeof(int),
519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800520 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 },
522#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700523 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700524 .procname = "print-fatal-signals",
525 .data = &print_fatal_signals,
526 .maxlen = sizeof(int),
527 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800528 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700529 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700530#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 .procname = "reboot-cmd",
533 .data = reboot_command,
534 .maxlen = 256,
535 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800536 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 },
538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .procname = "stop-a",
540 .data = &stop_a_enabled,
541 .maxlen = sizeof (int),
542 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800543 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 },
545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procname = "scons-poweroff",
547 .data = &scons_pwroff,
548 .maxlen = sizeof (int),
549 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800550 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
552#endif
David S. Miller08714202008-11-16 23:49:24 -0800553#ifdef CONFIG_SPARC64
554 {
David S. Miller08714202008-11-16 23:49:24 -0800555 .procname = "tsb-ratio",
556 .data = &sysctl_tsb_ratio,
557 .maxlen = sizeof (int),
558 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800559 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800560 },
561#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#ifdef __hppa__
563 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .procname = "soft-power",
565 .data = &pwrsw_enabled,
566 .maxlen = sizeof (int),
567 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800568 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530570#endif
571#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 .procname = "unaligned-trap",
574 .data = &unaligned_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 },
579#endif
580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "ctrl-alt-del",
582 .data = &C_A_D,
583 .maxlen = sizeof(int),
584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800585 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400587#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200588 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200589 .procname = "ftrace_enabled",
590 .data = &ftrace_enabled,
591 .maxlen = sizeof(int),
592 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800593 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200594 },
595#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500596#ifdef CONFIG_STACK_TRACER
597 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500598 .procname = "stack_tracer_enabled",
599 .data = &stack_tracer_enabled,
600 .maxlen = sizeof(int),
601 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800602 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500603 },
604#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400605#ifdef CONFIG_TRACING
606 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100607 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400608 .data = &ftrace_dump_on_oops,
609 .maxlen = sizeof(int),
610 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800611 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400612 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400613 {
614 .procname = "traceoff_on_warning",
615 .data = &__disable_trace_on_warning,
616 .maxlen = sizeof(__disable_trace_on_warning),
617 .mode = 0644,
618 .proc_handler = proc_dointvec,
619 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500620 {
621 .procname = "tracepoint_printk",
622 .data = &tracepoint_printk,
623 .maxlen = sizeof(tracepoint_printk),
624 .mode = 0644,
625 .proc_handler = proc_dointvec,
626 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400627#endif
Dave Young2965faa2015-09-09 15:38:55 -0700628#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800629 {
630 .procname = "kexec_load_disabled",
631 .data = &kexec_load_disabled,
632 .maxlen = sizeof(int),
633 .mode = 0644,
634 /* only handle a transition from default "0" to "1" */
635 .proc_handler = proc_dointvec_minmax,
636 .extra1 = &one,
637 .extra2 = &one,
638 },
639#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200640#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 .procname = "modprobe",
643 .data = &modprobe_path,
644 .maxlen = KMOD_PATH_LEN,
645 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800646 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 },
Kees Cook3d433212009-04-02 15:49:29 -0700648 {
Kees Cook3d433212009-04-02 15:49:29 -0700649 .procname = "modules_disabled",
650 .data = &modules_disabled,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800654 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700655 .extra1 = &one,
656 .extra2 = &one,
657 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700659#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100662 .data = &uevent_helper,
663 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800665 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 },
Michael Marineau86d56132014-04-10 14:09:31 -0700667#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668#ifdef CONFIG_CHR_DEV_SG
669 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .procname = "sg-big-buff",
671 .data = &sg_big_buff,
672 .maxlen = sizeof (int),
673 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800674 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 },
676#endif
677#ifdef CONFIG_BSD_PROCESS_ACCT
678 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 .procname = "acct",
680 .data = &acct_parm,
681 .maxlen = 3*sizeof(int),
682 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800683 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 },
685#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#ifdef CONFIG_MAGIC_SYSRQ
687 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800689 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 .maxlen = sizeof (int),
691 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700692 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 },
694#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700695#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700698 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 .maxlen = sizeof (int),
700 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800701 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700703#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700706 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 .maxlen = sizeof(int),
708 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700709 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 },
711 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 .procname = "random",
713 .mode = 0555,
714 .child = random_table,
715 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 {
Eric Paris17f60a72011-04-01 17:07:50 -0400717 .procname = "usermodehelper",
718 .mode = 0555,
719 .child = usermodehelper_table,
720 },
721 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 .procname = "overflowuid",
723 .data = &overflowuid,
724 .maxlen = sizeof(int),
725 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800726 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 .extra1 = &minolduid,
728 .extra2 = &maxolduid,
729 },
730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 .procname = "overflowgid",
732 .data = &overflowgid,
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 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800739#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740#ifdef CONFIG_MATHEMU
741 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 .procname = "ieee_emulation_warnings",
743 .data = &sysctl_ieee_emulation_warnings,
744 .maxlen = sizeof(int),
745 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800746 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 },
748#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200751 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 .maxlen = sizeof(int),
753 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800754 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 },
756#endif
757 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .procname = "pid_max",
759 .data = &pid_max,
760 .maxlen = sizeof (int),
761 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800762 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 .extra1 = &pid_max_min,
764 .extra2 = &pid_max_max,
765 },
766 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 .procname = "panic_on_oops",
768 .data = &panic_on_oops,
769 .maxlen = sizeof(int),
770 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800771 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800773#if defined CONFIG_PRINTK
774 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800775 .procname = "printk",
776 .data = &console_loglevel,
777 .maxlen = 4*sizeof(int),
778 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800779 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800780 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700783 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 .maxlen = sizeof(int),
785 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800786 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 },
788 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700790 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .maxlen = sizeof(int),
792 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800793 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 },
Dave Youngaf913222009-09-22 16:43:33 -0700795 {
Dave Youngaf913222009-09-22 16:43:33 -0700796 .procname = "printk_delay",
797 .data = &printk_delay_msec,
798 .maxlen = sizeof(int),
799 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800800 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700801 .extra1 = &zero,
802 .extra2 = &ten_thousand,
803 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800805 .procname = "dmesg_restrict",
806 .data = &dmesg_restrict,
807 .maxlen = sizeof(int),
808 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700809 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800810 .extra1 = &zero,
811 .extra2 = &one,
812 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800813 {
814 .procname = "kptr_restrict",
815 .data = &kptr_restrict,
816 .maxlen = sizeof(int),
817 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700818 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800819 .extra1 = &zero,
820 .extra2 = &two,
821 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800822#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800823 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 .procname = "ngroups_max",
825 .data = &ngroups_max,
826 .maxlen = sizeof (int),
827 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800828 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 },
Dan Ballard73efc032011-10-31 17:11:20 -0700830 {
831 .procname = "cap_last_cap",
832 .data = (void *)&cap_last_cap,
833 .maxlen = sizeof(int),
834 .mode = 0444,
835 .proc_handler = proc_dointvec,
836 },
Don Zickus58687ac2010-05-07 17:11:44 -0400837#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500838 {
Don Zickus58687ac2010-05-07 17:11:44 -0400839 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200840 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500841 .maxlen = sizeof (int),
842 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700843 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700844 .extra1 = &zero,
845 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400846 },
847 {
848 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700849 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400850 .maxlen = sizeof(int),
851 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700852 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800853 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400854 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500855 },
Don Zickus2508ce12010-05-07 17:11:46 -0400856 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700857 .procname = "nmi_watchdog",
858 .data = &nmi_watchdog_enabled,
859 .maxlen = sizeof (int),
860 .mode = 0644,
861 .proc_handler = proc_nmi_watchdog,
862 .extra1 = &zero,
863#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
864 .extra2 = &one,
865#else
866 .extra2 = &zero,
867#endif
868 },
869 {
870 .procname = "soft_watchdog",
871 .data = &soft_watchdog_enabled,
872 .maxlen = sizeof (int),
873 .mode = 0644,
874 .proc_handler = proc_soft_watchdog,
875 .extra1 = &zero,
876 .extra2 = &one,
877 },
878 {
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700879 .procname = "watchdog_cpumask",
880 .data = &watchdog_cpumask_bits,
881 .maxlen = NR_CPUS,
882 .mode = 0644,
883 .proc_handler = proc_watchdog_cpumask,
884 },
885 {
Don Zickus2508ce12010-05-07 17:11:46 -0400886 .procname = "softlockup_panic",
887 .data = &softlockup_panic,
888 .maxlen = sizeof(int),
889 .mode = 0644,
890 .proc_handler = proc_dointvec_minmax,
891 .extra1 = &zero,
892 .extra2 = &one,
893 },
Don Zickusac1f5912015-11-05 18:44:44 -0800894#ifdef CONFIG_HARDLOCKUP_DETECTOR
895 {
896 .procname = "hardlockup_panic",
897 .data = &hardlockup_panic,
898 .maxlen = sizeof(int),
899 .mode = 0644,
900 .proc_handler = proc_dointvec_minmax,
901 .extra1 = &zero,
902 .extra2 = &one,
903 },
904#endif
Aaron Tomlined235872014-06-23 13:22:05 -0700905#ifdef CONFIG_SMP
906 {
907 .procname = "softlockup_all_cpu_backtrace",
908 .data = &sysctl_softlockup_all_cpu_backtrace,
909 .maxlen = sizeof(int),
910 .mode = 0644,
911 .proc_handler = proc_dointvec_minmax,
912 .extra1 = &zero,
913 .extra2 = &one,
914 },
Jiri Kosina55537872015-11-05 18:44:41 -0800915 {
916 .procname = "hardlockup_all_cpu_backtrace",
917 .data = &sysctl_hardlockup_all_cpu_backtrace,
918 .maxlen = sizeof(int),
919 .mode = 0644,
920 .proc_handler = proc_dointvec_minmax,
921 .extra1 = &zero,
922 .extra2 = &one,
923 },
Aaron Tomlined235872014-06-23 13:22:05 -0700924#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500925#endif
926#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
927 {
928 .procname = "unknown_nmi_panic",
929 .data = &unknown_nmi_panic,
930 .maxlen = sizeof (int),
931 .mode = 0644,
932 .proc_handler = proc_dointvec,
933 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500934#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935#if defined(CONFIG_X86)
936 {
Don Zickus8da5add2006-09-26 10:52:27 +0200937 .procname = "panic_on_unrecovered_nmi",
938 .data = &panic_on_unrecovered_nmi,
939 .maxlen = sizeof(int),
940 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800941 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200942 },
943 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700944 .procname = "panic_on_io_nmi",
945 .data = &panic_on_io_nmi,
946 .maxlen = sizeof(int),
947 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800948 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700949 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900950#ifdef CONFIG_DEBUG_STACKOVERFLOW
951 {
952 .procname = "panic_on_stackoverflow",
953 .data = &sysctl_panic_on_stackoverflow,
954 .maxlen = sizeof(int),
955 .mode = 0644,
956 .proc_handler = proc_dointvec,
957 },
958#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700959 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 .procname = "bootloader_type",
961 .data = &bootloader_type,
962 .maxlen = sizeof (int),
963 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800964 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100966 {
H. Peter Anvin50312962009-05-07 16:54:11 -0700967 .procname = "bootloader_version",
968 .data = &bootloader_version,
969 .maxlen = sizeof (int),
970 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800971 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -0700972 },
973 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100974 .procname = "kstack_depth_to_print",
975 .data = &kstack_depth_to_print,
976 .maxlen = sizeof(int),
977 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800978 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +0100979 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100980 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100981 .procname = "io_delay_type",
982 .data = &io_delay_type,
983 .maxlen = sizeof(int),
984 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800985 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +0100986 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987#endif
Luke Yang7a9166e2006-02-20 18:28:07 -0800988#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 .procname = "randomize_va_space",
991 .data = &randomize_va_space,
992 .maxlen = sizeof(int),
993 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800994 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 },
Luke Yang7a9166e2006-02-20 18:28:07 -0800996#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -0800997#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700998 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -0700999 .procname = "spin_retry",
1000 .data = &spin_retry,
1001 .maxlen = sizeof (int),
1002 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001003 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001004 },
1005#endif
Len Brown673d5b42007-07-28 03:33:16 -04001006#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001007 {
Pavel Machekc255d842006-02-20 18:27:58 -08001008 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001009 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001010 .maxlen = sizeof (unsigned long),
1011 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001012 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001013 },
1014#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301015#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001016 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001017 .procname = "ignore-unaligned-usertrap",
1018 .data = &no_unaligned_warning,
1019 .maxlen = sizeof (int),
1020 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001021 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001022 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301023#endif
1024#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001025 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001026 .procname = "unaligned-dump-stack",
1027 .data = &unaligned_dump_stack,
1028 .maxlen = sizeof (int),
1029 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001030 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001031 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001032#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001033#ifdef CONFIG_DETECT_HUNG_TASK
1034 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001035 .procname = "hung_task_panic",
1036 .data = &sysctl_hung_task_panic,
1037 .maxlen = sizeof(int),
1038 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001040 .extra1 = &zero,
1041 .extra2 = &one,
1042 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001043 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001044 .procname = "hung_task_check_count",
1045 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001046 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001047 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001048 .proc_handler = proc_dointvec_minmax,
1049 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001050 },
1051 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001052 .procname = "hung_task_timeout_secs",
1053 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001054 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001055 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001056 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001057 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001058 },
1059 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001060 .procname = "hung_task_warnings",
1061 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001062 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001063 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001064 .proc_handler = proc_dointvec_minmax,
1065 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001066 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001067#endif
Andi Kleenbebfa102006-06-26 13:56:52 +02001068#ifdef CONFIG_COMPAT
1069 {
Andi Kleenbebfa102006-06-26 13:56:52 +02001070 .procname = "compat-log",
1071 .data = &compat_log,
1072 .maxlen = sizeof (int),
1073 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001074 .proc_handler = proc_dointvec,
Andi Kleenbebfa102006-06-26 13:56:52 +02001075 },
1076#endif
Ingo Molnar23f78d42006-06-27 02:54:53 -07001077#ifdef CONFIG_RT_MUTEXES
1078 {
Ingo Molnar23f78d42006-06-27 02:54:53 -07001079 .procname = "max_lock_depth",
1080 .data = &max_lock_depth,
1081 .maxlen = sizeof(int),
1082 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001083 .proc_handler = proc_dointvec,
Ingo Molnar23f78d42006-06-27 02:54:53 -07001084 },
1085#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001086 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001087 .procname = "poweroff_cmd",
1088 .data = &poweroff_cmd,
1089 .maxlen = POWEROFF_CMD_PATH_LEN,
1090 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001091 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001092 },
David Howells0b77f5b2008-04-29 01:01:32 -07001093#ifdef CONFIG_KEYS
1094 {
David Howells0b77f5b2008-04-29 01:01:32 -07001095 .procname = "keys",
1096 .mode = 0555,
1097 .child = key_sysctls,
1098 },
1099#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001100#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001101 /*
1102 * User-space scripts rely on the existence of this file
1103 * as a feature check for perf_events being enabled.
1104 *
1105 * So it's an ABI, do not remove!
1106 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001107 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001108 .procname = "perf_event_paranoid",
1109 .data = &sysctl_perf_event_paranoid,
1110 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001111 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001112 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001113 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001114 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001115 .procname = "perf_event_mlock_kb",
1116 .data = &sysctl_perf_event_mlock,
1117 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001118 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001119 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001120 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001121 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001122 .procname = "perf_event_max_sample_rate",
1123 .data = &sysctl_perf_event_sample_rate,
1124 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001125 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001126 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001127 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001128 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001129 {
1130 .procname = "perf_cpu_time_max_percent",
1131 .data = &sysctl_perf_cpu_time_max_percent,
1132 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1133 .mode = 0644,
1134 .proc_handler = perf_cpu_time_max_percent_handler,
1135 .extra1 = &zero,
1136 .extra2 = &one_hundred,
1137 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001138#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001139#ifdef CONFIG_KMEMCHECK
1140 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001141 .procname = "kmemcheck",
1142 .data = &kmemcheck_enabled,
1143 .maxlen = sizeof(int),
1144 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001145 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001146 },
1147#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001148 {
1149 .procname = "panic_on_warn",
1150 .data = &panic_on_warn,
1151 .maxlen = sizeof(int),
1152 .mode = 0644,
1153 .proc_handler = proc_dointvec_minmax,
1154 .extra1 = &zero,
1155 .extra2 = &one,
1156 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001157#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1158 {
1159 .procname = "timer_migration",
1160 .data = &sysctl_timer_migration,
1161 .maxlen = sizeof(unsigned int),
1162 .mode = 0644,
1163 .proc_handler = timer_migration_handler,
1164 },
1165#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001166#ifdef CONFIG_BPF_SYSCALL
1167 {
1168 .procname = "unprivileged_bpf_disabled",
1169 .data = &sysctl_unprivileged_bpf_disabled,
1170 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1171 .mode = 0644,
1172 /* only handle a transition from default "0" to "1" */
1173 .proc_handler = proc_dointvec_minmax,
1174 .extra1 = &one,
1175 .extra2 = &one,
1176 },
1177#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001178 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179};
1180
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001181static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 {
Hiroshi Doyufd608032013-04-12 12:43:43 +03001183 .procname = "lazy_vfree_pages",
1184 .data = &sysctl_lazy_vfree_pages,
1185 .maxlen = sizeof(sysctl_lazy_vfree_pages),
1186 .mode = 0644,
1187 .proc_handler = proc_dointvec,
1188 },
1189 {
Terje Bergstrom3e9f3d82013-12-31 13:57:55 +02001190 .procname = "lazy_vfree_tlb_flush_all_threshold",
1191 .data = &sysctl_lazy_vfree_tlb_flush_all_threshold,
1192 .maxlen = sizeof(sysctl_lazy_vfree_tlb_flush_all_threshold),
1193 .mode = 0644,
1194 .proc_handler = proc_dointvec,
1195 },
1196 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 .procname = "overcommit_memory",
1198 .data = &sysctl_overcommit_memory,
1199 .maxlen = sizeof(sysctl_overcommit_memory),
1200 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001201 .proc_handler = proc_dointvec_minmax,
1202 .extra1 = &zero,
1203 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 },
1205 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001206 .procname = "panic_on_oom",
1207 .data = &sysctl_panic_on_oom,
1208 .maxlen = sizeof(sysctl_panic_on_oom),
1209 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001210 .proc_handler = proc_dointvec_minmax,
1211 .extra1 = &zero,
1212 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001213 },
1214 {
David Rientjesfe071d72007-10-16 23:25:56 -07001215 .procname = "oom_kill_allocating_task",
1216 .data = &sysctl_oom_kill_allocating_task,
1217 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1218 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001219 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001220 },
1221 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001222 .procname = "oom_dump_tasks",
1223 .data = &sysctl_oom_dump_tasks,
1224 .maxlen = sizeof(sysctl_oom_dump_tasks),
1225 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001226 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001227 },
1228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 .procname = "overcommit_ratio",
1230 .data = &sysctl_overcommit_ratio,
1231 .maxlen = sizeof(sysctl_overcommit_ratio),
1232 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001233 .proc_handler = overcommit_ratio_handler,
1234 },
1235 {
1236 .procname = "overcommit_kbytes",
1237 .data = &sysctl_overcommit_kbytes,
1238 .maxlen = sizeof(sysctl_overcommit_kbytes),
1239 .mode = 0644,
1240 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 },
1242 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 .procname = "page-cluster",
1244 .data = &page_cluster,
1245 .maxlen = sizeof(int),
1246 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001247 .proc_handler = proc_dointvec_minmax,
1248 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 },
1250 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 .procname = "dirty_background_ratio",
1252 .data = &dirty_background_ratio,
1253 .maxlen = sizeof(dirty_background_ratio),
1254 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001255 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 .extra1 = &zero,
1257 .extra2 = &one_hundred,
1258 },
1259 {
David Rientjes2da02992009-01-06 14:39:31 -08001260 .procname = "dirty_background_bytes",
1261 .data = &dirty_background_bytes,
1262 .maxlen = sizeof(dirty_background_bytes),
1263 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001264 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001265 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001266 },
1267 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 .procname = "dirty_ratio",
1269 .data = &vm_dirty_ratio,
1270 .maxlen = sizeof(vm_dirty_ratio),
1271 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001272 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 .extra1 = &zero,
1274 .extra2 = &one_hundred,
1275 },
1276 {
David Rientjes2da02992009-01-06 14:39:31 -08001277 .procname = "dirty_bytes",
1278 .data = &vm_dirty_bytes,
1279 .maxlen = sizeof(vm_dirty_bytes),
1280 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001281 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001282 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001283 },
1284 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001286 .data = &dirty_writeback_interval,
1287 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001289 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 },
1291 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001293 .data = &dirty_expire_interval,
1294 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001296 .proc_handler = proc_dointvec_minmax,
1297 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 },
1299 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001300 .procname = "dirtytime_expire_seconds",
1301 .data = &dirtytime_expire_interval,
1302 .maxlen = sizeof(dirty_expire_interval),
1303 .mode = 0644,
1304 .proc_handler = dirtytime_interval_handler,
1305 .extra1 = &zero,
1306 },
1307 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001308 .procname = "nr_pdflush_threads",
1309 .mode = 0444 /* read-only */,
1310 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 },
1312 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 .procname = "swappiness",
1314 .data = &vm_swappiness,
1315 .maxlen = sizeof(vm_swappiness),
1316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001317 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 .extra1 = &zero,
1319 .extra2 = &one_hundred,
1320 },
1321#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001322 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001324 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 .maxlen = sizeof(unsigned long),
1326 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001327 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001328 },
1329#ifdef CONFIG_NUMA
1330 {
1331 .procname = "nr_hugepages_mempolicy",
1332 .data = NULL,
1333 .maxlen = sizeof(unsigned long),
1334 .mode = 0644,
1335 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001336 },
1337#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 .procname = "hugetlb_shm_group",
1340 .data = &sysctl_hugetlb_shm_group,
1341 .maxlen = sizeof(gid_t),
1342 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001343 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 },
Mel Gorman396faf02007-07-17 04:03:13 -07001345 {
Mel Gorman396faf02007-07-17 04:03:13 -07001346 .procname = "hugepages_treat_as_movable",
1347 .data = &hugepages_treat_as_movable,
1348 .maxlen = sizeof(int),
1349 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001350 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001351 },
Adam Litke54f9f802007-10-16 01:26:20 -07001352 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001353 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001354 .data = NULL,
1355 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001356 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001357 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001358 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359#endif
1360 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .procname = "lowmem_reserve_ratio",
1362 .data = &sysctl_lowmem_reserve_ratio,
1363 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1364 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001365 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 },
1367 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001368 .procname = "drop_caches",
1369 .data = &sysctl_drop_caches,
1370 .maxlen = sizeof(int),
1371 .mode = 0644,
1372 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001373 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001374 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001375 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001376#ifdef CONFIG_COMPACTION
1377 {
1378 .procname = "compact_memory",
1379 .data = &sysctl_compact_memory,
1380 .maxlen = sizeof(int),
1381 .mode = 0200,
1382 .proc_handler = sysctl_compaction_handler,
1383 },
Mel Gorman5e771902010-05-24 14:32:31 -07001384 {
1385 .procname = "extfrag_threshold",
1386 .data = &sysctl_extfrag_threshold,
1387 .maxlen = sizeof(int),
1388 .mode = 0644,
1389 .proc_handler = sysctl_extfrag_handler,
1390 .extra1 = &min_extfrag_threshold,
1391 .extra2 = &max_extfrag_threshold,
1392 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001393 {
1394 .procname = "compact_unevictable_allowed",
1395 .data = &sysctl_compact_unevictable_allowed,
1396 .maxlen = sizeof(int),
1397 .mode = 0644,
1398 .proc_handler = proc_dointvec,
1399 .extra1 = &zero,
1400 .extra2 = &one,
1401 },
Mel Gorman5e771902010-05-24 14:32:31 -07001402
Mel Gorman76ab0f52010-05-24 14:32:28 -07001403#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001404 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 .procname = "min_free_kbytes",
1406 .data = &min_free_kbytes,
1407 .maxlen = sizeof(min_free_kbytes),
1408 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001409 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 .extra1 = &zero,
1411 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001412 {
Rik van Rielf8ade362011-09-01 15:26:50 -04001413 .procname = "extra_free_kbytes",
1414 .data = &extra_free_kbytes,
1415 .maxlen = sizeof(extra_free_kbytes),
1416 .mode = 0644,
1417 .proc_handler = min_free_kbytes_sysctl_handler,
1418 .extra1 = &zero,
1419 },
1420 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001421 .procname = "percpu_pagelist_fraction",
1422 .data = &percpu_pagelist_fraction,
1423 .maxlen = sizeof(percpu_pagelist_fraction),
1424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001425 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001426 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001427 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428#ifdef CONFIG_MMU
1429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .procname = "max_map_count",
1431 .data = &sysctl_max_map_count,
1432 .maxlen = sizeof(sysctl_max_map_count),
1433 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001434 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001435 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001437#else
1438 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001439 .procname = "nr_trim_pages",
1440 .data = &sysctl_nr_trim_pages,
1441 .maxlen = sizeof(sysctl_nr_trim_pages),
1442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001443 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001444 .extra1 = &zero,
1445 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446#endif
1447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .procname = "laptop_mode",
1449 .data = &laptop_mode,
1450 .maxlen = sizeof(laptop_mode),
1451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001452 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 },
1454 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 .procname = "block_dump",
1456 .data = &block_dump,
1457 .maxlen = sizeof(block_dump),
1458 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001459 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 .extra1 = &zero,
1461 },
1462 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 .procname = "vfs_cache_pressure",
1464 .data = &sysctl_vfs_cache_pressure,
1465 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001467 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 .extra1 = &zero,
1469 },
1470#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1471 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 .procname = "legacy_va_layout",
1473 .data = &sysctl_legacy_va_layout,
1474 .maxlen = sizeof(sysctl_legacy_va_layout),
1475 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001476 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 .extra1 = &zero,
1478 },
1479#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001480#ifdef CONFIG_NUMA
1481 {
Christoph Lameter17436602006-01-18 17:42:32 -08001482 .procname = "zone_reclaim_mode",
1483 .data = &zone_reclaim_mode,
1484 .maxlen = sizeof(zone_reclaim_mode),
1485 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001486 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001487 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001488 },
Christoph Lameter96146342006-07-03 00:24:13 -07001489 {
Christoph Lameter96146342006-07-03 00:24:13 -07001490 .procname = "min_unmapped_ratio",
1491 .data = &sysctl_min_unmapped_ratio,
1492 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1493 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001494 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001495 .extra1 = &zero,
1496 .extra2 = &one_hundred,
1497 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001498 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001499 .procname = "min_slab_ratio",
1500 .data = &sysctl_min_slab_ratio,
1501 .maxlen = sizeof(sysctl_min_slab_ratio),
1502 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001503 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001504 .extra1 = &zero,
1505 .extra2 = &one_hundred,
1506 },
Christoph Lameter17436602006-01-18 17:42:32 -08001507#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001508#ifdef CONFIG_SMP
1509 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001510 .procname = "stat_interval",
1511 .data = &sysctl_stat_interval,
1512 .maxlen = sizeof(sysctl_stat_interval),
1513 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001514 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001515 },
1516#endif
David Howells6e141542009-12-15 19:27:45 +00001517#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001518 {
Eric Parised032182007-06-28 15:55:21 -04001519 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001520 .data = &dac_mmap_min_addr,
1521 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001522 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001523 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001524 },
David Howells6e141542009-12-15 19:27:45 +00001525#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001526#ifdef CONFIG_NUMA
1527 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001528 .procname = "numa_zonelist_order",
1529 .data = &numa_zonelist_order,
1530 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1531 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001532 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001533 },
1534#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001535#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001536 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001537 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001538 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001539#ifdef CONFIG_X86_32
1540 .data = &vdso32_enabled,
1541 .maxlen = sizeof(vdso32_enabled),
1542#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001543 .data = &vdso_enabled,
1544 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001545#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001546 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001547 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001548 .extra1 = &zero,
1549 },
1550#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001551#ifdef CONFIG_HIGHMEM
1552 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001553 .procname = "highmem_is_dirtyable",
1554 .data = &vm_highmem_is_dirtyable,
1555 .maxlen = sizeof(vm_highmem_is_dirtyable),
1556 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001557 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001558 .extra1 = &zero,
1559 .extra2 = &one,
1560 },
1561#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001562#ifdef CONFIG_MEMORY_FAILURE
1563 {
Andi Kleen6a460792009-09-16 11:50:15 +02001564 .procname = "memory_failure_early_kill",
1565 .data = &sysctl_memory_failure_early_kill,
1566 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1567 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001568 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001569 .extra1 = &zero,
1570 .extra2 = &one,
1571 },
1572 {
Andi Kleen6a460792009-09-16 11:50:15 +02001573 .procname = "memory_failure_recovery",
1574 .data = &sysctl_memory_failure_recovery,
1575 .maxlen = sizeof(sysctl_memory_failure_recovery),
1576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001577 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001578 .extra1 = &zero,
1579 .extra2 = &one,
1580 },
1581#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001582 {
1583 .procname = "user_reserve_kbytes",
1584 .data = &sysctl_user_reserve_kbytes,
1585 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1586 .mode = 0644,
1587 .proc_handler = proc_doulongvec_minmax,
1588 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001589 {
1590 .procname = "admin_reserve_kbytes",
1591 .data = &sysctl_admin_reserve_kbytes,
1592 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1593 .mode = 0644,
1594 .proc_handler = proc_doulongvec_minmax,
1595 },
dcashmand49d8872016-01-12 09:18:57 -08001596#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1597 {
1598 .procname = "mmap_rnd_bits",
1599 .data = &mmap_rnd_bits,
1600 .maxlen = sizeof(mmap_rnd_bits),
1601 .mode = 0600,
1602 .proc_handler = proc_dointvec_minmax,
1603 .extra1 = (void *)&mmap_rnd_bits_min,
1604 .extra2 = (void *)&mmap_rnd_bits_max,
1605 },
1606#endif
1607#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1608 {
1609 .procname = "mmap_rnd_compat_bits",
1610 .data = &mmap_rnd_compat_bits,
1611 .maxlen = sizeof(mmap_rnd_compat_bits),
1612 .mode = 0600,
1613 .proc_handler = proc_dointvec_minmax,
1614 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1615 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1616 },
1617#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001618 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619};
1620
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001621static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 .procname = "inode-nr",
1624 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001625 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001627 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 },
1629 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 .procname = "inode-state",
1631 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001632 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001634 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 },
1636 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 .procname = "file-nr",
1638 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001639 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001641 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 },
1643 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 .procname = "file-max",
1645 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001646 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001648 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 },
1650 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001651 .procname = "nr_open",
1652 .data = &sysctl_nr_open,
1653 .maxlen = sizeof(int),
1654 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001655 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001656 .extra1 = &sysctl_nr_open_min,
1657 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001658 },
1659 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 .procname = "dentry-state",
1661 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001662 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001664 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 },
1666 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 .procname = "overflowuid",
1668 .data = &fs_overflowuid,
1669 .maxlen = sizeof(int),
1670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001671 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 .extra1 = &minolduid,
1673 .extra2 = &maxolduid,
1674 },
1675 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 .procname = "overflowgid",
1677 .data = &fs_overflowgid,
1678 .maxlen = sizeof(int),
1679 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001680 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 .extra1 = &minolduid,
1682 .extra2 = &maxolduid,
1683 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001684#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 .procname = "leases-enable",
1687 .data = &leases_enable,
1688 .maxlen = sizeof(int),
1689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001690 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001692#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693#ifdef CONFIG_DNOTIFY
1694 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 .procname = "dir-notify-enable",
1696 .data = &dir_notify_enable,
1697 .maxlen = sizeof(int),
1698 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001699 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 },
1701#endif
1702#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001703#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 .procname = "lease-break-time",
1706 .data = &lease_break_time,
1707 .maxlen = sizeof(int),
1708 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001709 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001711#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001712#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 .procname = "aio-nr",
1715 .data = &aio_nr,
1716 .maxlen = sizeof(aio_nr),
1717 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001718 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 },
1720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 .procname = "aio-max-nr",
1722 .data = &aio_max_nr,
1723 .maxlen = sizeof(aio_max_nr),
1724 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001725 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001727#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001728#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001729 {
Robert Love0399cb02005-07-13 12:38:18 -04001730 .procname = "inotify",
1731 .mode = 0555,
1732 .child = inotify_table,
1733 },
1734#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001735#ifdef CONFIG_EPOLL
1736 {
1737 .procname = "epoll",
1738 .mode = 0555,
1739 .child = epoll_table,
1740 },
1741#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001743 {
Kees Cook800179c2012-07-25 17:29:07 -07001744 .procname = "protected_symlinks",
1745 .data = &sysctl_protected_symlinks,
1746 .maxlen = sizeof(int),
1747 .mode = 0600,
1748 .proc_handler = proc_dointvec_minmax,
1749 .extra1 = &zero,
1750 .extra2 = &one,
1751 },
1752 {
1753 .procname = "protected_hardlinks",
1754 .data = &sysctl_protected_hardlinks,
1755 .maxlen = sizeof(int),
1756 .mode = 0600,
1757 .proc_handler = proc_dointvec_minmax,
1758 .extra1 = &zero,
1759 .extra2 = &one,
1760 },
1761 {
Alan Coxd6e71142005-06-23 00:09:43 -07001762 .procname = "suid_dumpable",
1763 .data = &suid_dumpable,
1764 .maxlen = sizeof(int),
1765 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001766 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001767 .extra1 = &zero,
1768 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001769 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001770#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1771 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001772 .procname = "binfmt_misc",
1773 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001774 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001775 },
1776#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001777 {
Jens Axboeff9da692010-06-03 14:54:39 +02001778 .procname = "pipe-max-size",
1779 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001780 .maxlen = sizeof(int),
1781 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001782 .proc_handler = &pipe_proc_fn,
1783 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001784 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001785 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786};
1787
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001788static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001789#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001790 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001791 .procname = "exception-trace",
1792 .data = &show_unhandled_signals,
1793 .maxlen = sizeof(int),
1794 .mode = 0644,
1795 .proc_handler = proc_dointvec
1796 },
1797#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001798#if defined(CONFIG_OPTPROBES)
1799 {
1800 .procname = "kprobes-optimization",
1801 .data = &sysctl_kprobes_optimization,
1802 .maxlen = sizeof(int),
1803 .mode = 0644,
1804 .proc_handler = proc_kprobes_optimization_handler,
1805 .extra1 = &zero,
1806 .extra2 = &one,
1807 },
1808#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001809 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810};
1811
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001812static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001813 { }
Robert Love0eeca282005-07-12 17:06:03 -04001814};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001816int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001817{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001818 struct ctl_table_header *hdr;
1819
1820 hdr = register_sysctl_table(sysctl_base_table);
1821 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001822 return 0;
1823}
1824
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001825#endif /* CONFIG_SYSCTL */
1826
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827/*
1828 * /proc/sys support
1829 */
1830
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001831#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Kees Cookf8808302014-06-06 14:37:17 -07001833static int _proc_do_string(char *data, int maxlen, int write,
1834 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001835 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001836{
1837 size_t len;
1838 char __user *p;
1839 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001840
1841 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001842 *lenp = 0;
1843 return 0;
1844 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001845
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001846 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001847 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1848 /* Only continue writes not past the end of buffer. */
1849 len = strlen(data);
1850 if (len > maxlen - 1)
1851 len = maxlen - 1;
1852
1853 if (*ppos > len)
1854 return 0;
1855 len = *ppos;
1856 } else {
1857 /* Start writing from beginning of buffer. */
1858 len = 0;
1859 }
1860
Kees Cook2ca9bb42014-06-06 14:37:18 -07001861 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001862 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001863 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001864 if (get_user(c, p++))
1865 return -EFAULT;
1866 if (c == 0 || c == '\n')
1867 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001868 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001869 }
Kees Cookf8808302014-06-06 14:37:17 -07001870 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001871 } else {
1872 len = strlen(data);
1873 if (len > maxlen)
1874 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001875
1876 if (*ppos > len) {
1877 *lenp = 0;
1878 return 0;
1879 }
1880
1881 data += *ppos;
1882 len -= *ppos;
1883
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001884 if (len > *lenp)
1885 len = *lenp;
1886 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001887 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001888 return -EFAULT;
1889 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001890 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001891 return -EFAULT;
1892 len++;
1893 }
1894 *lenp = len;
1895 *ppos += len;
1896 }
1897 return 0;
1898}
1899
Kees Cookf4aacea2014-06-06 14:37:19 -07001900static void warn_sysctl_write(struct ctl_table *table)
1901{
1902 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1903 "This will not be supported in the future. To silence this\n"
1904 "warning, set kernel.sysctl_writes_strict = -1\n",
1905 current->comm, table->procname);
1906}
1907
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908/**
1909 * proc_dostring - read a string sysctl
1910 * @table: the sysctl table
1911 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 * @buffer: the user buffer
1913 * @lenp: the size of the user buffer
1914 * @ppos: file position
1915 *
1916 * Reads/writes a string from/to the user buffer. If the kernel
1917 * buffer provided is not large enough to hold the string, the
1918 * string is truncated. The copied string is %NULL-terminated.
1919 * If the string is being read by the user process, it is copied
1920 * and a newline '\n' is added. It is truncated if the buffer is
1921 * not large enough.
1922 *
1923 * Returns 0 on success.
1924 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001925int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 void __user *buffer, size_t *lenp, loff_t *ppos)
1927{
Kees Cookf4aacea2014-06-06 14:37:19 -07001928 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1929 warn_sysctl_write(table);
1930
Kees Cookf8808302014-06-06 14:37:17 -07001931 return _proc_do_string((char *)(table->data), table->maxlen, write,
1932 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
Amerigo Wang00b7c332010-05-05 00:26:45 +00001935static size_t proc_skip_spaces(char **buf)
1936{
1937 size_t ret;
1938 char *tmp = skip_spaces(*buf);
1939 ret = tmp - *buf;
1940 *buf = tmp;
1941 return ret;
1942}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001944static void proc_skip_char(char **buf, size_t *size, const char v)
1945{
1946 while (*size) {
1947 if (**buf != v)
1948 break;
1949 (*size)--;
1950 (*buf)++;
1951 }
1952}
1953
Amerigo Wang00b7c332010-05-05 00:26:45 +00001954#define TMPBUFLEN 22
1955/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001956 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001957 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001958 * @buf: a kernel buffer
1959 * @size: size of the kernel buffer
1960 * @val: this is where the number will be stored
1961 * @neg: set to %TRUE if number is negative
1962 * @perm_tr: a vector which contains the allowed trailers
1963 * @perm_tr_len: size of the perm_tr vector
1964 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001965 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001966 * In case of success %0 is returned and @buf and @size are updated with
1967 * the amount of bytes read. If @tr is non-NULL and a trailing
1968 * character exists (size is non-zero after returning from this
1969 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001970 */
1971static int proc_get_long(char **buf, size_t *size,
1972 unsigned long *val, bool *neg,
1973 const char *perm_tr, unsigned perm_tr_len, char *tr)
1974{
1975 int len;
1976 char *p, tmp[TMPBUFLEN];
1977
1978 if (!*size)
1979 return -EINVAL;
1980
1981 len = *size;
1982 if (len > TMPBUFLEN - 1)
1983 len = TMPBUFLEN - 1;
1984
1985 memcpy(tmp, *buf, len);
1986
1987 tmp[len] = 0;
1988 p = tmp;
1989 if (*p == '-' && *size > 1) {
1990 *neg = true;
1991 p++;
1992 } else
1993 *neg = false;
1994 if (!isdigit(*p))
1995 return -EINVAL;
1996
1997 *val = simple_strtoul(p, &p, 0);
1998
1999 len = p - tmp;
2000
2001 /* We don't know if the next char is whitespace thus we may accept
2002 * invalid integers (e.g. 1234...a) or two integers instead of one
2003 * (e.g. 123...1). So lets not allow such large numbers. */
2004 if (len == TMPBUFLEN - 1)
2005 return -EINVAL;
2006
2007 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2008 return -EINVAL;
2009
2010 if (tr && (len < *size))
2011 *tr = *p;
2012
2013 *buf += len;
2014 *size -= len;
2015
2016 return 0;
2017}
2018
2019/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002020 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002021 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002022 * @buf: the user buffer
2023 * @size: the size of the user buffer
2024 * @val: the integer to be converted
2025 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002026 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002027 * In case of success %0 is returned and @buf and @size are updated with
2028 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002029 */
2030static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2031 bool neg)
2032{
2033 int len;
2034 char tmp[TMPBUFLEN], *p = tmp;
2035
2036 sprintf(p, "%s%lu", neg ? "-" : "", val);
2037 len = strlen(tmp);
2038 if (len > *size)
2039 len = *size;
2040 if (copy_to_user(*buf, tmp, len))
2041 return -EFAULT;
2042 *size -= len;
2043 *buf += len;
2044 return 0;
2045}
2046#undef TMPBUFLEN
2047
2048static int proc_put_char(void __user **buf, size_t *size, char c)
2049{
2050 if (*size) {
2051 char __user **buffer = (char __user **)buf;
2052 if (put_user(c, *buffer))
2053 return -EFAULT;
2054 (*size)--, (*buffer)++;
2055 *buf = *buffer;
2056 }
2057 return 0;
2058}
2059
2060static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 int *valp,
2062 int write, void *data)
2063{
2064 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002065 if (*negp) {
2066 if (*lvalp > (unsigned long) INT_MAX + 1)
2067 return -EINVAL;
2068 *valp = -*lvalp;
2069 } else {
2070 if (*lvalp > (unsigned long) INT_MAX)
2071 return -EINVAL;
2072 *valp = *lvalp;
2073 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 } else {
2075 int val = *valp;
2076 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002077 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002078 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002080 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 *lvalp = (unsigned long)val;
2082 }
2083 }
2084 return 0;
2085}
2086
Amerigo Wang00b7c332010-05-05 00:26:45 +00002087static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2088
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002089static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002090 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002091 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002092 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 int write, void *data),
2094 void *data)
2095{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002096 int *i, vleft, first = 1, err = 0;
2097 unsigned long page = 0;
2098 size_t left;
2099 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Amerigo Wang00b7c332010-05-05 00:26:45 +00002101 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 *lenp = 0;
2103 return 0;
2104 }
2105
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002106 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 vleft = table->maxlen / sizeof(*i);
2108 left = *lenp;
2109
2110 if (!conv)
2111 conv = do_proc_dointvec_conv;
2112
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002114 if (*ppos) {
2115 switch (sysctl_writes_strict) {
2116 case SYSCTL_WRITES_STRICT:
2117 goto out;
2118 case SYSCTL_WRITES_WARN:
2119 warn_sysctl_write(table);
2120 break;
2121 default:
2122 break;
2123 }
2124 }
2125
Amerigo Wang00b7c332010-05-05 00:26:45 +00002126 if (left > PAGE_SIZE - 1)
2127 left = PAGE_SIZE - 1;
2128 page = __get_free_page(GFP_TEMPORARY);
2129 kbuf = (char *) page;
2130 if (!kbuf)
2131 return -ENOMEM;
2132 if (copy_from_user(kbuf, buffer, left)) {
2133 err = -EFAULT;
2134 goto free;
2135 }
2136 kbuf[left] = 0;
2137 }
2138
2139 for (; left && vleft--; i++, first=0) {
2140 unsigned long lval;
2141 bool neg;
2142
2143 if (write) {
2144 left -= proc_skip_spaces(&kbuf);
2145
J. R. Okajima563b0462010-05-25 16:10:14 -07002146 if (!left)
2147 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002148 err = proc_get_long(&kbuf, &left, &lval, &neg,
2149 proc_wspace_sep,
2150 sizeof(proc_wspace_sep), NULL);
2151 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002153 if (conv(&neg, &lval, i, 1, data)) {
2154 err = -EINVAL;
2155 break;
2156 }
2157 } else {
2158 if (conv(&neg, &lval, i, 0, data)) {
2159 err = -EINVAL;
2160 break;
2161 }
2162 if (!first)
2163 err = proc_put_char(&buffer, &left, '\t');
2164 if (err)
2165 break;
2166 err = proc_put_long(&buffer, &left, lval, neg);
2167 if (err)
2168 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 }
2170 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002171
2172 if (!write && !first && left && !err)
2173 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002174 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002175 left -= proc_skip_spaces(&kbuf);
2176free:
2177 if (write) {
2178 free_page(page);
2179 if (first)
2180 return err ? : -EINVAL;
2181 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002183out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002185 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002188static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002189 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002190 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002191 int write, void *data),
2192 void *data)
2193{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002194 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002195 buffer, lenp, ppos, conv, data);
2196}
2197
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198/**
2199 * proc_dointvec - read a vector of integers
2200 * @table: the sysctl table
2201 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 * @buffer: the user buffer
2203 * @lenp: the size of the user buffer
2204 * @ppos: file position
2205 *
2206 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2207 * values from/to the user buffer, treated as an ASCII string.
2208 *
2209 * Returns 0 on success.
2210 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002211int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 void __user *buffer, size_t *lenp, loff_t *ppos)
2213{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002214 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 NULL,NULL);
2216}
2217
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002218/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002219 * Taint values can only be increased
2220 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002221 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002222static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002223 void __user *buffer, size_t *lenp, loff_t *ppos)
2224{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002225 struct ctl_table t;
2226 unsigned long tmptaint = get_taint();
2227 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002228
Bastian Blank91fcd412007-04-23 14:41:14 -07002229 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002230 return -EPERM;
2231
Andi Kleen25ddbb12008-10-15 22:01:41 -07002232 t = *table;
2233 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002234 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002235 if (err < 0)
2236 return err;
2237
2238 if (write) {
2239 /*
2240 * Poor man's atomic or. Not worth adding a primitive
2241 * to everyone's atomic.h for this
2242 */
2243 int i;
2244 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2245 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302246 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002247 }
2248 }
2249
2250 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002251}
2252
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002253#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002254static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002255 void __user *buffer, size_t *lenp, loff_t *ppos)
2256{
2257 if (write && !capable(CAP_SYS_ADMIN))
2258 return -EPERM;
2259
2260 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2261}
2262#endif
2263
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264struct do_proc_dointvec_minmax_conv_param {
2265 int *min;
2266 int *max;
2267};
2268
Amerigo Wang00b7c332010-05-05 00:26:45 +00002269static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2270 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 int write, void *data)
2272{
2273 struct do_proc_dointvec_minmax_conv_param *param = data;
2274 if (write) {
2275 int val = *negp ? -*lvalp : *lvalp;
2276 if ((param->min && *param->min > val) ||
2277 (param->max && *param->max < val))
2278 return -EINVAL;
2279 *valp = val;
2280 } else {
2281 int val = *valp;
2282 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002283 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002284 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002286 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 *lvalp = (unsigned long)val;
2288 }
2289 }
2290 return 0;
2291}
2292
2293/**
2294 * proc_dointvec_minmax - read a vector of integers with min/max values
2295 * @table: the sysctl table
2296 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 * @buffer: the user buffer
2298 * @lenp: the size of the user buffer
2299 * @ppos: file position
2300 *
2301 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2302 * values from/to the user buffer, treated as an ASCII string.
2303 *
2304 * This routine will ensure the values are within the range specified by
2305 * table->extra1 (min) and table->extra2 (max).
2306 *
2307 * Returns 0 on success.
2308 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002309int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 void __user *buffer, size_t *lenp, loff_t *ppos)
2311{
2312 struct do_proc_dointvec_minmax_conv_param param = {
2313 .min = (int *) table->extra1,
2314 .max = (int *) table->extra2,
2315 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002316 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 do_proc_dointvec_minmax_conv, &param);
2318}
2319
Kees Cook54b50192012-07-30 14:39:18 -07002320static void validate_coredump_safety(void)
2321{
Alex Kelly046d6622012-10-04 17:15:23 -07002322#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002323 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002324 core_pattern[0] != '/' && core_pattern[0] != '|') {
2325 printk(KERN_WARNING "Unsafe core_pattern used with "\
2326 "suid_dumpable=2. Pipe handler or fully qualified "\
2327 "core dump path required.\n");
2328 }
Alex Kelly046d6622012-10-04 17:15:23 -07002329#endif
Kees Cook54b50192012-07-30 14:39:18 -07002330}
2331
2332static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2333 void __user *buffer, size_t *lenp, loff_t *ppos)
2334{
2335 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2336 if (!error)
2337 validate_coredump_safety();
2338 return error;
2339}
2340
Alex Kelly046d6622012-10-04 17:15:23 -07002341#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002342static int proc_dostring_coredump(struct ctl_table *table, int write,
2343 void __user *buffer, size_t *lenp, loff_t *ppos)
2344{
2345 int error = proc_dostring(table, write, buffer, lenp, ppos);
2346 if (!error)
2347 validate_coredump_safety();
2348 return error;
2349}
Alex Kelly046d6622012-10-04 17:15:23 -07002350#endif
Kees Cook54b50192012-07-30 14:39:18 -07002351
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002352static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 void __user *buffer,
2354 size_t *lenp, loff_t *ppos,
2355 unsigned long convmul,
2356 unsigned long convdiv)
2357{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002358 unsigned long *i, *min, *max;
2359 int vleft, first = 1, err = 0;
2360 unsigned long page = 0;
2361 size_t left;
2362 char *kbuf;
2363
2364 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 *lenp = 0;
2366 return 0;
2367 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002368
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002369 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 min = (unsigned long *) table->extra1;
2371 max = (unsigned long *) table->extra2;
2372 vleft = table->maxlen / sizeof(unsigned long);
2373 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002374
2375 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002376 if (*ppos) {
2377 switch (sysctl_writes_strict) {
2378 case SYSCTL_WRITES_STRICT:
2379 goto out;
2380 case SYSCTL_WRITES_WARN:
2381 warn_sysctl_write(table);
2382 break;
2383 default:
2384 break;
2385 }
2386 }
2387
Amerigo Wang00b7c332010-05-05 00:26:45 +00002388 if (left > PAGE_SIZE - 1)
2389 left = PAGE_SIZE - 1;
2390 page = __get_free_page(GFP_TEMPORARY);
2391 kbuf = (char *) page;
2392 if (!kbuf)
2393 return -ENOMEM;
2394 if (copy_from_user(kbuf, buffer, left)) {
2395 err = -EFAULT;
2396 goto free;
2397 }
2398 kbuf[left] = 0;
2399 }
2400
Eric Dumazet27b3d802010-10-07 12:59:29 -07002401 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002402 unsigned long val;
2403
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002405 bool neg;
2406
2407 left -= proc_skip_spaces(&kbuf);
2408
2409 err = proc_get_long(&kbuf, &left, &val, &neg,
2410 proc_wspace_sep,
2411 sizeof(proc_wspace_sep), NULL);
2412 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 break;
2414 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 continue;
2416 if ((min && val < *min) || (max && val > *max))
2417 continue;
2418 *i = val;
2419 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002420 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002421 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002422 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002423 if (err)
2424 break;
2425 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002426 err = proc_put_long(&buffer, &left, val, false);
2427 if (err)
2428 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 }
2430 }
2431
Amerigo Wang00b7c332010-05-05 00:26:45 +00002432 if (!write && !first && left && !err)
2433 err = proc_put_char(&buffer, &left, '\n');
2434 if (write && !err)
2435 left -= proc_skip_spaces(&kbuf);
2436free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002438 free_page(page);
2439 if (first)
2440 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002443out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002445 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446}
2447
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002448static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002449 void __user *buffer,
2450 size_t *lenp, loff_t *ppos,
2451 unsigned long convmul,
2452 unsigned long convdiv)
2453{
2454 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002455 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002456}
2457
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458/**
2459 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2460 * @table: the sysctl table
2461 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 * @buffer: the user buffer
2463 * @lenp: the size of the user buffer
2464 * @ppos: file position
2465 *
2466 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2467 * values from/to the user buffer, treated as an ASCII string.
2468 *
2469 * This routine will ensure the values are within the range specified by
2470 * table->extra1 (min) and table->extra2 (max).
2471 *
2472 * Returns 0 on success.
2473 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002474int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 void __user *buffer, size_t *lenp, loff_t *ppos)
2476{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002477 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478}
2479
2480/**
2481 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 * @buffer: the user buffer
2485 * @lenp: the size of the user buffer
2486 * @ppos: file position
2487 *
2488 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2489 * values from/to the user buffer, treated as an ASCII string. The values
2490 * are treated as milliseconds, and converted to jiffies when they are stored.
2491 *
2492 * This routine will ensure the values are within the range specified by
2493 * table->extra1 (min) and table->extra2 (max).
2494 *
2495 * Returns 0 on success.
2496 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002497int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 void __user *buffer,
2499 size_t *lenp, loff_t *ppos)
2500{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002501 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 lenp, ppos, HZ, 1000l);
2503}
2504
2505
Amerigo Wang00b7c332010-05-05 00:26:45 +00002506static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 int *valp,
2508 int write, void *data)
2509{
2510 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002511 if (*lvalp > LONG_MAX / HZ)
2512 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2514 } else {
2515 int val = *valp;
2516 unsigned long lval;
2517 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002518 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002519 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002521 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 lval = (unsigned long)val;
2523 }
2524 *lvalp = lval / HZ;
2525 }
2526 return 0;
2527}
2528
Amerigo Wang00b7c332010-05-05 00:26:45 +00002529static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 int *valp,
2531 int write, void *data)
2532{
2533 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002534 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2535 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2537 } else {
2538 int val = *valp;
2539 unsigned long lval;
2540 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002541 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002542 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002544 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 lval = (unsigned long)val;
2546 }
2547 *lvalp = jiffies_to_clock_t(lval);
2548 }
2549 return 0;
2550}
2551
Amerigo Wang00b7c332010-05-05 00:26:45 +00002552static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 int *valp,
2554 int write, void *data)
2555{
2556 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002557 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2558
2559 if (jif > INT_MAX)
2560 return 1;
2561 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 } else {
2563 int val = *valp;
2564 unsigned long lval;
2565 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002566 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002567 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002569 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 lval = (unsigned long)val;
2571 }
2572 *lvalp = jiffies_to_msecs(lval);
2573 }
2574 return 0;
2575}
2576
2577/**
2578 * proc_dointvec_jiffies - read a vector of integers as seconds
2579 * @table: the sysctl table
2580 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 * @buffer: the user buffer
2582 * @lenp: the size of the user buffer
2583 * @ppos: file position
2584 *
2585 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2586 * values from/to the user buffer, treated as an ASCII string.
2587 * The values read are assumed to be in seconds, and are converted into
2588 * jiffies.
2589 *
2590 * Returns 0 on success.
2591 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002592int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 void __user *buffer, size_t *lenp, loff_t *ppos)
2594{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002595 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 do_proc_dointvec_jiffies_conv,NULL);
2597}
2598
2599/**
2600 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2601 * @table: the sysctl table
2602 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 * @buffer: the user buffer
2604 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002605 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 *
2607 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2608 * values from/to the user buffer, treated as an ASCII string.
2609 * The values read are assumed to be in 1/USER_HZ seconds, and
2610 * are converted into jiffies.
2611 *
2612 * Returns 0 on success.
2613 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002614int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 void __user *buffer, size_t *lenp, loff_t *ppos)
2616{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002617 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 do_proc_dointvec_userhz_jiffies_conv,NULL);
2619}
2620
2621/**
2622 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2623 * @table: the sysctl table
2624 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 * @buffer: the user buffer
2626 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002627 * @ppos: file position
2628 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 *
2630 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2631 * values from/to the user buffer, treated as an ASCII string.
2632 * The values read are assumed to be in 1/1000 seconds, and
2633 * are converted into jiffies.
2634 *
2635 * Returns 0 on success.
2636 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002637int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 void __user *buffer, size_t *lenp, loff_t *ppos)
2639{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002640 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 do_proc_dointvec_ms_jiffies_conv, NULL);
2642}
2643
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002644static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002645 void __user *buffer, size_t *lenp, loff_t *ppos)
2646{
2647 struct pid *new_pid;
2648 pid_t tmp;
2649 int r;
2650
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002651 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002652
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002653 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002654 lenp, ppos, NULL, NULL);
2655 if (r || !write)
2656 return r;
2657
2658 new_pid = find_get_pid(tmp);
2659 if (!new_pid)
2660 return -ESRCH;
2661
2662 put_pid(xchg(&cad_pid, new_pid));
2663 return 0;
2664}
2665
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002666/**
2667 * proc_do_large_bitmap - read/write from/to a large bitmap
2668 * @table: the sysctl table
2669 * @write: %TRUE if this is a write to the sysctl file
2670 * @buffer: the user buffer
2671 * @lenp: the size of the user buffer
2672 * @ppos: file position
2673 *
2674 * The bitmap is stored at table->data and the bitmap length (in bits)
2675 * in table->maxlen.
2676 *
2677 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2678 * large bitmaps may be represented in a compact manner. Writing into
2679 * the file will clear the bitmap then update it with the given input.
2680 *
2681 * Returns 0 on success.
2682 */
2683int proc_do_large_bitmap(struct ctl_table *table, int write,
2684 void __user *buffer, size_t *lenp, loff_t *ppos)
2685{
2686 int err = 0;
2687 bool first = 1;
2688 size_t left = *lenp;
2689 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002690 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002691 unsigned long *tmp_bitmap = NULL;
2692 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2693
WANG Cong122ff242014-05-12 16:04:53 -07002694 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002695 *lenp = 0;
2696 return 0;
2697 }
2698
2699 if (write) {
2700 unsigned long page = 0;
2701 char *kbuf;
2702
2703 if (left > PAGE_SIZE - 1)
2704 left = PAGE_SIZE - 1;
2705
2706 page = __get_free_page(GFP_TEMPORARY);
2707 kbuf = (char *) page;
2708 if (!kbuf)
2709 return -ENOMEM;
2710 if (copy_from_user(kbuf, buffer, left)) {
2711 free_page(page);
2712 return -EFAULT;
2713 }
2714 kbuf[left] = 0;
2715
2716 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2717 GFP_KERNEL);
2718 if (!tmp_bitmap) {
2719 free_page(page);
2720 return -ENOMEM;
2721 }
2722 proc_skip_char(&kbuf, &left, '\n');
2723 while (!err && left) {
2724 unsigned long val_a, val_b;
2725 bool neg;
2726
2727 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2728 sizeof(tr_a), &c);
2729 if (err)
2730 break;
2731 if (val_a >= bitmap_len || neg) {
2732 err = -EINVAL;
2733 break;
2734 }
2735
2736 val_b = val_a;
2737 if (left) {
2738 kbuf++;
2739 left--;
2740 }
2741
2742 if (c == '-') {
2743 err = proc_get_long(&kbuf, &left, &val_b,
2744 &neg, tr_b, sizeof(tr_b),
2745 &c);
2746 if (err)
2747 break;
2748 if (val_b >= bitmap_len || neg ||
2749 val_a > val_b) {
2750 err = -EINVAL;
2751 break;
2752 }
2753 if (left) {
2754 kbuf++;
2755 left--;
2756 }
2757 }
2758
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002759 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002760 first = 0;
2761 proc_skip_char(&kbuf, &left, '\n');
2762 }
2763 free_page(page);
2764 } else {
2765 unsigned long bit_a, bit_b = 0;
2766
2767 while (left) {
2768 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2769 if (bit_a >= bitmap_len)
2770 break;
2771 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2772 bit_a + 1) - 1;
2773
2774 if (!first) {
2775 err = proc_put_char(&buffer, &left, ',');
2776 if (err)
2777 break;
2778 }
2779 err = proc_put_long(&buffer, &left, bit_a, false);
2780 if (err)
2781 break;
2782 if (bit_a != bit_b) {
2783 err = proc_put_char(&buffer, &left, '-');
2784 if (err)
2785 break;
2786 err = proc_put_long(&buffer, &left, bit_b, false);
2787 if (err)
2788 break;
2789 }
2790
2791 first = 0; bit_b++;
2792 }
2793 if (!err)
2794 err = proc_put_char(&buffer, &left, '\n');
2795 }
2796
2797 if (!err) {
2798 if (write) {
2799 if (*ppos)
2800 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2801 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002802 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002803 }
2804 kfree(tmp_bitmap);
2805 *lenp -= left;
2806 *ppos += *lenp;
2807 return 0;
2808 } else {
2809 kfree(tmp_bitmap);
2810 return err;
2811 }
2812}
2813
Jovi Zhang55610502011-01-12 17:00:45 -08002814#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002816int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 void __user *buffer, size_t *lenp, loff_t *ppos)
2818{
2819 return -ENOSYS;
2820}
2821
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002822int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 void __user *buffer, size_t *lenp, loff_t *ppos)
2824{
2825 return -ENOSYS;
2826}
2827
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002828int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 void __user *buffer, size_t *lenp, loff_t *ppos)
2830{
2831 return -ENOSYS;
2832}
2833
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002834int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 void __user *buffer, size_t *lenp, loff_t *ppos)
2836{
2837 return -ENOSYS;
2838}
2839
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002840int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 void __user *buffer, size_t *lenp, loff_t *ppos)
2842{
2843 return -ENOSYS;
2844}
2845
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002846int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 void __user *buffer, size_t *lenp, loff_t *ppos)
2848{
2849 return -ENOSYS;
2850}
2851
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002852int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 void __user *buffer, size_t *lenp, loff_t *ppos)
2854{
2855 return -ENOSYS;
2856}
2857
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002858int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 void __user *buffer,
2860 size_t *lenp, loff_t *ppos)
2861{
2862 return -ENOSYS;
2863}
2864
2865
Jovi Zhang55610502011-01-12 17:00:45 -08002866#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868/*
2869 * No sense putting this after each symbol definition, twice,
2870 * exception granted :-)
2871 */
2872EXPORT_SYMBOL(proc_dointvec);
2873EXPORT_SYMBOL(proc_dointvec_jiffies);
2874EXPORT_SYMBOL(proc_dointvec_minmax);
2875EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2876EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2877EXPORT_SYMBOL(proc_dostring);
2878EXPORT_SYMBOL(proc_doulongvec_minmax);
2879EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);