blob: 40fe07609dd98f7c4dfbb99827f691a6221d4654 [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 },
Willy Tarreau5662d152016-01-18 16:36:09 +01001785 {
1786 .procname = "pipe-user-pages-hard",
1787 .data = &pipe_user_pages_hard,
1788 .maxlen = sizeof(pipe_user_pages_hard),
1789 .mode = 0644,
1790 .proc_handler = proc_doulongvec_minmax,
1791 },
1792 {
1793 .procname = "pipe-user-pages-soft",
1794 .data = &pipe_user_pages_soft,
1795 .maxlen = sizeof(pipe_user_pages_soft),
1796 .mode = 0644,
1797 .proc_handler = proc_doulongvec_minmax,
1798 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001799 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800};
1801
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001802static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001803#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001804 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001805 .procname = "exception-trace",
1806 .data = &show_unhandled_signals,
1807 .maxlen = sizeof(int),
1808 .mode = 0644,
1809 .proc_handler = proc_dointvec
1810 },
1811#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001812#if defined(CONFIG_OPTPROBES)
1813 {
1814 .procname = "kprobes-optimization",
1815 .data = &sysctl_kprobes_optimization,
1816 .maxlen = sizeof(int),
1817 .mode = 0644,
1818 .proc_handler = proc_kprobes_optimization_handler,
1819 .extra1 = &zero,
1820 .extra2 = &one,
1821 },
1822#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001823 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824};
1825
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001826static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001827 { }
Robert Love0eeca282005-07-12 17:06:03 -04001828};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001830int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001831{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001832 struct ctl_table_header *hdr;
1833
1834 hdr = register_sysctl_table(sysctl_base_table);
1835 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001836 return 0;
1837}
1838
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001839#endif /* CONFIG_SYSCTL */
1840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841/*
1842 * /proc/sys support
1843 */
1844
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001845#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
Kees Cookf8808302014-06-06 14:37:17 -07001847static int _proc_do_string(char *data, int maxlen, int write,
1848 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001849 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001850{
1851 size_t len;
1852 char __user *p;
1853 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001854
1855 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001856 *lenp = 0;
1857 return 0;
1858 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001859
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001860 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001861 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1862 /* Only continue writes not past the end of buffer. */
1863 len = strlen(data);
1864 if (len > maxlen - 1)
1865 len = maxlen - 1;
1866
1867 if (*ppos > len)
1868 return 0;
1869 len = *ppos;
1870 } else {
1871 /* Start writing from beginning of buffer. */
1872 len = 0;
1873 }
1874
Kees Cook2ca9bb42014-06-06 14:37:18 -07001875 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001876 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001877 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001878 if (get_user(c, p++))
1879 return -EFAULT;
1880 if (c == 0 || c == '\n')
1881 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001882 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001883 }
Kees Cookf8808302014-06-06 14:37:17 -07001884 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001885 } else {
1886 len = strlen(data);
1887 if (len > maxlen)
1888 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001889
1890 if (*ppos > len) {
1891 *lenp = 0;
1892 return 0;
1893 }
1894
1895 data += *ppos;
1896 len -= *ppos;
1897
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001898 if (len > *lenp)
1899 len = *lenp;
1900 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001901 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001902 return -EFAULT;
1903 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001904 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001905 return -EFAULT;
1906 len++;
1907 }
1908 *lenp = len;
1909 *ppos += len;
1910 }
1911 return 0;
1912}
1913
Kees Cookf4aacea2014-06-06 14:37:19 -07001914static void warn_sysctl_write(struct ctl_table *table)
1915{
1916 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1917 "This will not be supported in the future. To silence this\n"
1918 "warning, set kernel.sysctl_writes_strict = -1\n",
1919 current->comm, table->procname);
1920}
1921
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922/**
1923 * proc_dostring - read a string sysctl
1924 * @table: the sysctl table
1925 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 * @buffer: the user buffer
1927 * @lenp: the size of the user buffer
1928 * @ppos: file position
1929 *
1930 * Reads/writes a string from/to the user buffer. If the kernel
1931 * buffer provided is not large enough to hold the string, the
1932 * string is truncated. The copied string is %NULL-terminated.
1933 * If the string is being read by the user process, it is copied
1934 * and a newline '\n' is added. It is truncated if the buffer is
1935 * not large enough.
1936 *
1937 * Returns 0 on success.
1938 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001939int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 void __user *buffer, size_t *lenp, loff_t *ppos)
1941{
Kees Cookf4aacea2014-06-06 14:37:19 -07001942 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1943 warn_sysctl_write(table);
1944
Kees Cookf8808302014-06-06 14:37:17 -07001945 return _proc_do_string((char *)(table->data), table->maxlen, write,
1946 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947}
1948
Amerigo Wang00b7c332010-05-05 00:26:45 +00001949static size_t proc_skip_spaces(char **buf)
1950{
1951 size_t ret;
1952 char *tmp = skip_spaces(*buf);
1953 ret = tmp - *buf;
1954 *buf = tmp;
1955 return ret;
1956}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001958static void proc_skip_char(char **buf, size_t *size, const char v)
1959{
1960 while (*size) {
1961 if (**buf != v)
1962 break;
1963 (*size)--;
1964 (*buf)++;
1965 }
1966}
1967
Amerigo Wang00b7c332010-05-05 00:26:45 +00001968#define TMPBUFLEN 22
1969/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001970 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00001971 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001972 * @buf: a kernel buffer
1973 * @size: size of the kernel buffer
1974 * @val: this is where the number will be stored
1975 * @neg: set to %TRUE if number is negative
1976 * @perm_tr: a vector which contains the allowed trailers
1977 * @perm_tr_len: size of the perm_tr vector
1978 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00001979 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07001980 * In case of success %0 is returned and @buf and @size are updated with
1981 * the amount of bytes read. If @tr is non-NULL and a trailing
1982 * character exists (size is non-zero after returning from this
1983 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00001984 */
1985static int proc_get_long(char **buf, size_t *size,
1986 unsigned long *val, bool *neg,
1987 const char *perm_tr, unsigned perm_tr_len, char *tr)
1988{
1989 int len;
1990 char *p, tmp[TMPBUFLEN];
1991
1992 if (!*size)
1993 return -EINVAL;
1994
1995 len = *size;
1996 if (len > TMPBUFLEN - 1)
1997 len = TMPBUFLEN - 1;
1998
1999 memcpy(tmp, *buf, len);
2000
2001 tmp[len] = 0;
2002 p = tmp;
2003 if (*p == '-' && *size > 1) {
2004 *neg = true;
2005 p++;
2006 } else
2007 *neg = false;
2008 if (!isdigit(*p))
2009 return -EINVAL;
2010
2011 *val = simple_strtoul(p, &p, 0);
2012
2013 len = p - tmp;
2014
2015 /* We don't know if the next char is whitespace thus we may accept
2016 * invalid integers (e.g. 1234...a) or two integers instead of one
2017 * (e.g. 123...1). So lets not allow such large numbers. */
2018 if (len == TMPBUFLEN - 1)
2019 return -EINVAL;
2020
2021 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2022 return -EINVAL;
2023
2024 if (tr && (len < *size))
2025 *tr = *p;
2026
2027 *buf += len;
2028 *size -= len;
2029
2030 return 0;
2031}
2032
2033/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002034 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002035 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002036 * @buf: the user buffer
2037 * @size: the size of the user buffer
2038 * @val: the integer to be converted
2039 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002040 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002041 * In case of success %0 is returned and @buf and @size are updated with
2042 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002043 */
2044static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2045 bool neg)
2046{
2047 int len;
2048 char tmp[TMPBUFLEN], *p = tmp;
2049
2050 sprintf(p, "%s%lu", neg ? "-" : "", val);
2051 len = strlen(tmp);
2052 if (len > *size)
2053 len = *size;
2054 if (copy_to_user(*buf, tmp, len))
2055 return -EFAULT;
2056 *size -= len;
2057 *buf += len;
2058 return 0;
2059}
2060#undef TMPBUFLEN
2061
2062static int proc_put_char(void __user **buf, size_t *size, char c)
2063{
2064 if (*size) {
2065 char __user **buffer = (char __user **)buf;
2066 if (put_user(c, *buffer))
2067 return -EFAULT;
2068 (*size)--, (*buffer)++;
2069 *buf = *buffer;
2070 }
2071 return 0;
2072}
2073
2074static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 int *valp,
2076 int write, void *data)
2077{
2078 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002079 if (*negp) {
2080 if (*lvalp > (unsigned long) INT_MAX + 1)
2081 return -EINVAL;
2082 *valp = -*lvalp;
2083 } else {
2084 if (*lvalp > (unsigned long) INT_MAX)
2085 return -EINVAL;
2086 *valp = *lvalp;
2087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 } else {
2089 int val = *valp;
2090 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002091 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002092 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002094 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 *lvalp = (unsigned long)val;
2096 }
2097 }
2098 return 0;
2099}
2100
Subash Abhinov Kasiviswanathan990bd102016-08-25 15:16:51 -07002101static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2102 int *valp,
2103 int write, void *data)
2104{
2105 if (write) {
2106 if (*negp)
2107 return -EINVAL;
2108 *valp = *lvalp;
2109 } else {
2110 unsigned int val = *valp;
2111 *lvalp = (unsigned long)val;
2112 }
2113 return 0;
2114}
2115
Amerigo Wang00b7c332010-05-05 00:26:45 +00002116static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2117
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002118static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002119 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002120 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002121 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 int write, void *data),
2123 void *data)
2124{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002125 int *i, vleft, first = 1, err = 0;
2126 unsigned long page = 0;
2127 size_t left;
2128 char *kbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Amerigo Wang00b7c332010-05-05 00:26:45 +00002130 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 *lenp = 0;
2132 return 0;
2133 }
2134
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002135 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 vleft = table->maxlen / sizeof(*i);
2137 left = *lenp;
2138
2139 if (!conv)
2140 conv = do_proc_dointvec_conv;
2141
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002143 if (*ppos) {
2144 switch (sysctl_writes_strict) {
2145 case SYSCTL_WRITES_STRICT:
2146 goto out;
2147 case SYSCTL_WRITES_WARN:
2148 warn_sysctl_write(table);
2149 break;
2150 default:
2151 break;
2152 }
2153 }
2154
Amerigo Wang00b7c332010-05-05 00:26:45 +00002155 if (left > PAGE_SIZE - 1)
2156 left = PAGE_SIZE - 1;
2157 page = __get_free_page(GFP_TEMPORARY);
2158 kbuf = (char *) page;
2159 if (!kbuf)
2160 return -ENOMEM;
2161 if (copy_from_user(kbuf, buffer, left)) {
2162 err = -EFAULT;
2163 goto free;
2164 }
2165 kbuf[left] = 0;
2166 }
2167
2168 for (; left && vleft--; i++, first=0) {
2169 unsigned long lval;
2170 bool neg;
2171
2172 if (write) {
2173 left -= proc_skip_spaces(&kbuf);
2174
J. R. Okajima563b0462010-05-25 16:10:14 -07002175 if (!left)
2176 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002177 err = proc_get_long(&kbuf, &left, &lval, &neg,
2178 proc_wspace_sep,
2179 sizeof(proc_wspace_sep), NULL);
2180 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002182 if (conv(&neg, &lval, i, 1, data)) {
2183 err = -EINVAL;
2184 break;
2185 }
2186 } else {
2187 if (conv(&neg, &lval, i, 0, data)) {
2188 err = -EINVAL;
2189 break;
2190 }
2191 if (!first)
2192 err = proc_put_char(&buffer, &left, '\t');
2193 if (err)
2194 break;
2195 err = proc_put_long(&buffer, &left, lval, neg);
2196 if (err)
2197 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 }
2199 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002200
2201 if (!write && !first && left && !err)
2202 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002203 if (write && !err && left)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002204 left -= proc_skip_spaces(&kbuf);
2205free:
2206 if (write) {
2207 free_page(page);
2208 if (first)
2209 return err ? : -EINVAL;
2210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002212out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002214 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215}
2216
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002217static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002218 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002219 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002220 int write, void *data),
2221 void *data)
2222{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002223 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002224 buffer, lenp, ppos, conv, data);
2225}
2226
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227/**
2228 * proc_dointvec - read a vector of integers
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 * @buffer: the user buffer
2232 * @lenp: the size of the user buffer
2233 * @ppos: file position
2234 *
2235 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2236 * values from/to the user buffer, treated as an ASCII string.
2237 *
2238 * Returns 0 on success.
2239 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002240int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 void __user *buffer, size_t *lenp, loff_t *ppos)
2242{
Subash Abhinov Kasiviswanathan990bd102016-08-25 15:16:51 -07002243 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2244}
2245
2246/**
2247 * proc_douintvec - read a vector of unsigned integers
2248 * @table: the sysctl table
2249 * @write: %TRUE if this is a write to the sysctl file
2250 * @buffer: the user buffer
2251 * @lenp: the size of the user buffer
2252 * @ppos: file position
2253 *
2254 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2255 * values from/to the user buffer, treated as an ASCII string.
2256 *
2257 * Returns 0 on success.
2258 */
2259int proc_douintvec(struct ctl_table *table, int write,
2260 void __user *buffer, size_t *lenp, loff_t *ppos)
2261{
2262 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2263 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264}
2265
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002266/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002267 * Taint values can only be increased
2268 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002269 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002270static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002271 void __user *buffer, size_t *lenp, loff_t *ppos)
2272{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002273 struct ctl_table t;
2274 unsigned long tmptaint = get_taint();
2275 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002276
Bastian Blank91fcd412007-04-23 14:41:14 -07002277 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002278 return -EPERM;
2279
Andi Kleen25ddbb12008-10-15 22:01:41 -07002280 t = *table;
2281 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002282 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002283 if (err < 0)
2284 return err;
2285
2286 if (write) {
2287 /*
2288 * Poor man's atomic or. Not worth adding a primitive
2289 * to everyone's atomic.h for this
2290 */
2291 int i;
2292 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2293 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302294 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002295 }
2296 }
2297
2298 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002299}
2300
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002301#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002302static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002303 void __user *buffer, size_t *lenp, loff_t *ppos)
2304{
2305 if (write && !capable(CAP_SYS_ADMIN))
2306 return -EPERM;
2307
2308 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2309}
2310#endif
2311
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312struct do_proc_dointvec_minmax_conv_param {
2313 int *min;
2314 int *max;
2315};
2316
Amerigo Wang00b7c332010-05-05 00:26:45 +00002317static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2318 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 int write, void *data)
2320{
2321 struct do_proc_dointvec_minmax_conv_param *param = data;
2322 if (write) {
2323 int val = *negp ? -*lvalp : *lvalp;
2324 if ((param->min && *param->min > val) ||
2325 (param->max && *param->max < val))
2326 return -EINVAL;
2327 *valp = val;
2328 } else {
2329 int val = *valp;
2330 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002331 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002332 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002334 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 *lvalp = (unsigned long)val;
2336 }
2337 }
2338 return 0;
2339}
2340
2341/**
2342 * proc_dointvec_minmax - read a vector of integers with min/max values
2343 * @table: the sysctl table
2344 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 * @buffer: the user buffer
2346 * @lenp: the size of the user buffer
2347 * @ppos: file position
2348 *
2349 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2350 * values from/to the user buffer, treated as an ASCII string.
2351 *
2352 * This routine will ensure the values are within the range specified by
2353 * table->extra1 (min) and table->extra2 (max).
2354 *
2355 * Returns 0 on success.
2356 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002357int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 void __user *buffer, size_t *lenp, loff_t *ppos)
2359{
2360 struct do_proc_dointvec_minmax_conv_param param = {
2361 .min = (int *) table->extra1,
2362 .max = (int *) table->extra2,
2363 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002364 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 do_proc_dointvec_minmax_conv, &param);
2366}
2367
Kees Cook54b50192012-07-30 14:39:18 -07002368static void validate_coredump_safety(void)
2369{
Alex Kelly046d6622012-10-04 17:15:23 -07002370#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002371 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002372 core_pattern[0] != '/' && core_pattern[0] != '|') {
2373 printk(KERN_WARNING "Unsafe core_pattern used with "\
2374 "suid_dumpable=2. Pipe handler or fully qualified "\
2375 "core dump path required.\n");
2376 }
Alex Kelly046d6622012-10-04 17:15:23 -07002377#endif
Kees Cook54b50192012-07-30 14:39:18 -07002378}
2379
2380static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2382{
2383 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2384 if (!error)
2385 validate_coredump_safety();
2386 return error;
2387}
2388
Alex Kelly046d6622012-10-04 17:15:23 -07002389#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002390static int proc_dostring_coredump(struct ctl_table *table, int write,
2391 void __user *buffer, size_t *lenp, loff_t *ppos)
2392{
2393 int error = proc_dostring(table, write, buffer, lenp, ppos);
2394 if (!error)
2395 validate_coredump_safety();
2396 return error;
2397}
Alex Kelly046d6622012-10-04 17:15:23 -07002398#endif
Kees Cook54b50192012-07-30 14:39:18 -07002399
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002400static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 void __user *buffer,
2402 size_t *lenp, loff_t *ppos,
2403 unsigned long convmul,
2404 unsigned long convdiv)
2405{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002406 unsigned long *i, *min, *max;
2407 int vleft, first = 1, err = 0;
2408 unsigned long page = 0;
2409 size_t left;
2410 char *kbuf;
2411
2412 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 *lenp = 0;
2414 return 0;
2415 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002416
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002417 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 min = (unsigned long *) table->extra1;
2419 max = (unsigned long *) table->extra2;
2420 vleft = table->maxlen / sizeof(unsigned long);
2421 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002422
2423 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002424 if (*ppos) {
2425 switch (sysctl_writes_strict) {
2426 case SYSCTL_WRITES_STRICT:
2427 goto out;
2428 case SYSCTL_WRITES_WARN:
2429 warn_sysctl_write(table);
2430 break;
2431 default:
2432 break;
2433 }
2434 }
2435
Amerigo Wang00b7c332010-05-05 00:26:45 +00002436 if (left > PAGE_SIZE - 1)
2437 left = PAGE_SIZE - 1;
2438 page = __get_free_page(GFP_TEMPORARY);
2439 kbuf = (char *) page;
2440 if (!kbuf)
2441 return -ENOMEM;
2442 if (copy_from_user(kbuf, buffer, left)) {
2443 err = -EFAULT;
2444 goto free;
2445 }
2446 kbuf[left] = 0;
2447 }
2448
Eric Dumazet27b3d802010-10-07 12:59:29 -07002449 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002450 unsigned long val;
2451
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002453 bool neg;
2454
2455 left -= proc_skip_spaces(&kbuf);
2456
2457 err = proc_get_long(&kbuf, &left, &val, &neg,
2458 proc_wspace_sep,
2459 sizeof(proc_wspace_sep), NULL);
2460 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 break;
2462 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 continue;
2464 if ((min && val < *min) || (max && val > *max))
2465 continue;
2466 *i = val;
2467 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002468 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002469 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002470 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002471 if (err)
2472 break;
2473 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002474 err = proc_put_long(&buffer, &left, val, false);
2475 if (err)
2476 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 }
2478 }
2479
Amerigo Wang00b7c332010-05-05 00:26:45 +00002480 if (!write && !first && left && !err)
2481 err = proc_put_char(&buffer, &left, '\n');
2482 if (write && !err)
2483 left -= proc_skip_spaces(&kbuf);
2484free:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002486 free_page(page);
2487 if (first)
2488 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002491out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002493 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494}
2495
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002496static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002497 void __user *buffer,
2498 size_t *lenp, loff_t *ppos,
2499 unsigned long convmul,
2500 unsigned long convdiv)
2501{
2502 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002503 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002504}
2505
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506/**
2507 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2508 * @table: the sysctl table
2509 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 * @buffer: the user buffer
2511 * @lenp: the size of the user buffer
2512 * @ppos: file position
2513 *
2514 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2515 * values from/to the user buffer, treated as an ASCII string.
2516 *
2517 * This routine will ensure the values are within the range specified by
2518 * table->extra1 (min) and table->extra2 (max).
2519 *
2520 * Returns 0 on success.
2521 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002522int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 void __user *buffer, size_t *lenp, loff_t *ppos)
2524{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002525 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526}
2527
2528/**
2529 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2530 * @table: the sysctl table
2531 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 * @buffer: the user buffer
2533 * @lenp: the size of the user buffer
2534 * @ppos: file position
2535 *
2536 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2537 * values from/to the user buffer, treated as an ASCII string. The values
2538 * are treated as milliseconds, and converted to jiffies when they are stored.
2539 *
2540 * This routine will ensure the values are within the range specified by
2541 * table->extra1 (min) and table->extra2 (max).
2542 *
2543 * Returns 0 on success.
2544 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002545int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 void __user *buffer,
2547 size_t *lenp, loff_t *ppos)
2548{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002549 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 lenp, ppos, HZ, 1000l);
2551}
2552
2553
Amerigo Wang00b7c332010-05-05 00:26:45 +00002554static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 int *valp,
2556 int write, void *data)
2557{
2558 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002559 if (*lvalp > LONG_MAX / HZ)
2560 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2562 } 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 = lval / HZ;
2573 }
2574 return 0;
2575}
2576
Amerigo Wang00b7c332010-05-05 00:26:45 +00002577static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 int *valp,
2579 int write, void *data)
2580{
2581 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002582 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2583 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2585 } else {
2586 int val = *valp;
2587 unsigned long lval;
2588 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002589 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002590 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002592 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 lval = (unsigned long)val;
2594 }
2595 *lvalp = jiffies_to_clock_t(lval);
2596 }
2597 return 0;
2598}
2599
Amerigo Wang00b7c332010-05-05 00:26:45 +00002600static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 int *valp,
2602 int write, void *data)
2603{
2604 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002605 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2606
2607 if (jif > INT_MAX)
2608 return 1;
2609 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 } else {
2611 int val = *valp;
2612 unsigned long lval;
2613 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002614 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002615 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002617 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 lval = (unsigned long)val;
2619 }
2620 *lvalp = jiffies_to_msecs(lval);
2621 }
2622 return 0;
2623}
2624
2625/**
2626 * proc_dointvec_jiffies - read a vector of integers as seconds
2627 * @table: the sysctl table
2628 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 * @buffer: the user buffer
2630 * @lenp: the size of the user buffer
2631 * @ppos: file position
2632 *
2633 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2634 * values from/to the user buffer, treated as an ASCII string.
2635 * The values read are assumed to be in seconds, and are converted into
2636 * jiffies.
2637 *
2638 * Returns 0 on success.
2639 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002640int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 void __user *buffer, size_t *lenp, loff_t *ppos)
2642{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002643 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 do_proc_dointvec_jiffies_conv,NULL);
2645}
2646
2647/**
2648 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2649 * @table: the sysctl table
2650 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 * @buffer: the user buffer
2652 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002653 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 *
2655 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2656 * values from/to the user buffer, treated as an ASCII string.
2657 * The values read are assumed to be in 1/USER_HZ seconds, and
2658 * are converted into jiffies.
2659 *
2660 * Returns 0 on success.
2661 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002662int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 void __user *buffer, size_t *lenp, loff_t *ppos)
2664{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002665 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 do_proc_dointvec_userhz_jiffies_conv,NULL);
2667}
2668
2669/**
2670 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2671 * @table: the sysctl table
2672 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 * @buffer: the user buffer
2674 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002675 * @ppos: file position
2676 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 *
2678 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2679 * values from/to the user buffer, treated as an ASCII string.
2680 * The values read are assumed to be in 1/1000 seconds, and
2681 * are converted into jiffies.
2682 *
2683 * Returns 0 on success.
2684 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002685int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 void __user *buffer, size_t *lenp, loff_t *ppos)
2687{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002688 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 do_proc_dointvec_ms_jiffies_conv, NULL);
2690}
2691
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002692static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002693 void __user *buffer, size_t *lenp, loff_t *ppos)
2694{
2695 struct pid *new_pid;
2696 pid_t tmp;
2697 int r;
2698
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002699 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002700
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002701 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002702 lenp, ppos, NULL, NULL);
2703 if (r || !write)
2704 return r;
2705
2706 new_pid = find_get_pid(tmp);
2707 if (!new_pid)
2708 return -ESRCH;
2709
2710 put_pid(xchg(&cad_pid, new_pid));
2711 return 0;
2712}
2713
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002714/**
2715 * proc_do_large_bitmap - read/write from/to a large bitmap
2716 * @table: the sysctl table
2717 * @write: %TRUE if this is a write to the sysctl file
2718 * @buffer: the user buffer
2719 * @lenp: the size of the user buffer
2720 * @ppos: file position
2721 *
2722 * The bitmap is stored at table->data and the bitmap length (in bits)
2723 * in table->maxlen.
2724 *
2725 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2726 * large bitmaps may be represented in a compact manner. Writing into
2727 * the file will clear the bitmap then update it with the given input.
2728 *
2729 * Returns 0 on success.
2730 */
2731int proc_do_large_bitmap(struct ctl_table *table, int write,
2732 void __user *buffer, size_t *lenp, loff_t *ppos)
2733{
2734 int err = 0;
2735 bool first = 1;
2736 size_t left = *lenp;
2737 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002738 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002739 unsigned long *tmp_bitmap = NULL;
2740 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2741
WANG Cong122ff242014-05-12 16:04:53 -07002742 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002743 *lenp = 0;
2744 return 0;
2745 }
2746
2747 if (write) {
2748 unsigned long page = 0;
2749 char *kbuf;
2750
2751 if (left > PAGE_SIZE - 1)
2752 left = PAGE_SIZE - 1;
2753
2754 page = __get_free_page(GFP_TEMPORARY);
2755 kbuf = (char *) page;
2756 if (!kbuf)
2757 return -ENOMEM;
2758 if (copy_from_user(kbuf, buffer, left)) {
2759 free_page(page);
2760 return -EFAULT;
2761 }
2762 kbuf[left] = 0;
2763
2764 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2765 GFP_KERNEL);
2766 if (!tmp_bitmap) {
2767 free_page(page);
2768 return -ENOMEM;
2769 }
2770 proc_skip_char(&kbuf, &left, '\n');
2771 while (!err && left) {
2772 unsigned long val_a, val_b;
2773 bool neg;
2774
2775 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2776 sizeof(tr_a), &c);
2777 if (err)
2778 break;
2779 if (val_a >= bitmap_len || neg) {
2780 err = -EINVAL;
2781 break;
2782 }
2783
2784 val_b = val_a;
2785 if (left) {
2786 kbuf++;
2787 left--;
2788 }
2789
2790 if (c == '-') {
2791 err = proc_get_long(&kbuf, &left, &val_b,
2792 &neg, tr_b, sizeof(tr_b),
2793 &c);
2794 if (err)
2795 break;
2796 if (val_b >= bitmap_len || neg ||
2797 val_a > val_b) {
2798 err = -EINVAL;
2799 break;
2800 }
2801 if (left) {
2802 kbuf++;
2803 left--;
2804 }
2805 }
2806
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002807 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002808 first = 0;
2809 proc_skip_char(&kbuf, &left, '\n');
2810 }
2811 free_page(page);
2812 } else {
2813 unsigned long bit_a, bit_b = 0;
2814
2815 while (left) {
2816 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2817 if (bit_a >= bitmap_len)
2818 break;
2819 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2820 bit_a + 1) - 1;
2821
2822 if (!first) {
2823 err = proc_put_char(&buffer, &left, ',');
2824 if (err)
2825 break;
2826 }
2827 err = proc_put_long(&buffer, &left, bit_a, false);
2828 if (err)
2829 break;
2830 if (bit_a != bit_b) {
2831 err = proc_put_char(&buffer, &left, '-');
2832 if (err)
2833 break;
2834 err = proc_put_long(&buffer, &left, bit_b, false);
2835 if (err)
2836 break;
2837 }
2838
2839 first = 0; bit_b++;
2840 }
2841 if (!err)
2842 err = proc_put_char(&buffer, &left, '\n');
2843 }
2844
2845 if (!err) {
2846 if (write) {
2847 if (*ppos)
2848 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2849 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002850 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002851 }
2852 kfree(tmp_bitmap);
2853 *lenp -= left;
2854 *ppos += *lenp;
2855 return 0;
2856 } else {
2857 kfree(tmp_bitmap);
2858 return err;
2859 }
2860}
2861
Jovi Zhang55610502011-01-12 17:00:45 -08002862#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002864int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 void __user *buffer, size_t *lenp, loff_t *ppos)
2866{
2867 return -ENOSYS;
2868}
2869
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002870int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 void __user *buffer, size_t *lenp, loff_t *ppos)
2872{
2873 return -ENOSYS;
2874}
2875
Subash Abhinov Kasiviswanathan990bd102016-08-25 15:16:51 -07002876int proc_douintvec(struct ctl_table *table, int write,
2877 void __user *buffer, size_t *lenp, loff_t *ppos)
2878{
2879 return -ENOSYS;
2880}
2881
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002882int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 void __user *buffer, size_t *lenp, loff_t *ppos)
2884{
2885 return -ENOSYS;
2886}
2887
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002888int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 void __user *buffer, size_t *lenp, loff_t *ppos)
2890{
2891 return -ENOSYS;
2892}
2893
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002894int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 void __user *buffer, size_t *lenp, loff_t *ppos)
2896{
2897 return -ENOSYS;
2898}
2899
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002900int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 void __user *buffer, size_t *lenp, loff_t *ppos)
2902{
2903 return -ENOSYS;
2904}
2905
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002906int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 void __user *buffer, size_t *lenp, loff_t *ppos)
2908{
2909 return -ENOSYS;
2910}
2911
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002912int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 void __user *buffer,
2914 size_t *lenp, loff_t *ppos)
2915{
2916 return -ENOSYS;
2917}
2918
2919
Jovi Zhang55610502011-01-12 17:00:45 -08002920#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922/*
2923 * No sense putting this after each symbol definition, twice,
2924 * exception granted :-)
2925 */
2926EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathan990bd102016-08-25 15:16:51 -07002927EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928EXPORT_SYMBOL(proc_dointvec_jiffies);
2929EXPORT_SYMBOL(proc_dointvec_minmax);
2930EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2931EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2932EXPORT_SYMBOL(proc_dostring);
2933EXPORT_SYMBOL(proc_doulongvec_minmax);
2934EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);