blob: 462b3d18d820a7e49580e8c385336fed271a0c1e [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>
Eric W. Biedermand2921682016-09-28 00:27:17 -050068#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70#include <asm/uaccess.h>
71#include <asm/processor.h>
72
Andi Kleen29cbc782006-09-30 01:47:55 +020073#ifdef CONFIG_X86
74#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010075#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010076#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020077#endif
David Howellsd550bbd2012-03-28 18:30:03 +010078#ifdef CONFIG_SPARC
79#include <asm/setup.h>
80#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080081#ifdef CONFIG_BSD_PROCESS_ACCT
82#include <linux/acct.h>
83#endif
Dave Young4f0e0562010-03-10 15:24:09 -080084#ifdef CONFIG_RT_MUTEXES
85#include <linux/rtmutex.h>
86#endif
Dave Young2edf5e42010-03-10 15:24:10 -080087#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
88#include <linux/lockdep.h>
89#endif
Dave Young15485a42010-03-10 15:24:07 -080090#ifdef CONFIG_CHR_DEV_SG
91#include <scsi/sg.h>
92#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020093
Don Zickus58687ac2010-05-07 17:11:44 -040094#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050095#include <linux/nmi.h>
96#endif
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#if defined(CONFIG_SYSCTL)
99
100/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700101extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700102#ifdef CONFIG_COREDUMP
103extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700105extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700106#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800109extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100110extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300111extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000112#ifndef CONFIG_MMU
113extern int sysctl_nr_trim_pages;
114#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700116/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400117#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118static int sixty = 60;
119#endif
120
Aaron Tomlin270750db2014-01-20 17:34:13 +0000121static int __maybe_unused neg_one = -1;
122
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700123static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700124static int __maybe_unused one = 1;
125static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700126static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800127static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700128static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700129static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700130#ifdef CONFIG_PRINTK
131static int ten_thousand = 10000;
132#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300133#ifdef CONFIG_PERF_EVENTS
134static int six_hundred_forty_kb = 640 * 1024;
135#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700136
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700137/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141static int maxolduid = 65535;
142static int minolduid;
143
144static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700145static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Liu Hua80df2842014-04-07 15:38:57 -0700147/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
148#ifdef CONFIG_DETECT_HUNG_TASK
149static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
150#endif
151
Dave Youngd14f1722010-02-25 20:28:57 -0500152#ifdef CONFIG_INOTIFY_USER
153#include <linux/inotify.h>
154#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700155#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#endif
157
158#ifdef __hppa__
159extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530160#endif
161
162#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163extern int unaligned_enabled;
164#endif
165
Jes Sorensend2b176e2006-02-28 09:42:23 -0800166#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800167extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800168#endif
169
Vineet Guptab6fca722013-01-09 20:06:28 +0530170#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
171extern int no_unaligned_warning;
172#endif
173
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700174#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700175
176#define SYSCTL_WRITES_LEGACY -1
177#define SYSCTL_WRITES_WARN 0
178#define SYSCTL_WRITES_STRICT 1
179
Kees Cook41662f52016-01-20 15:00:45 -0800180static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700181
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700182static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700183 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700184static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800185 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700186#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700187
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700188#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700189static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700190 void __user *buffer, size_t *lenp, loff_t *ppos);
191#endif
192
Kees Cook54b50192012-07-30 14:39:18 -0700193static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
194 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700195#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700196static int proc_dostring_coredump(struct ctl_table *table, int write,
197 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700198#endif
Kees Cook54b50192012-07-30 14:39:18 -0700199
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700200#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800201/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100202static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700203
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700204static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700205 void __user *buffer, size_t *lenp,
206 loff_t *ppos)
207{
208 int error;
209
210 error = proc_dointvec(table, write, buffer, lenp, ppos);
211 if (error)
212 return error;
213
214 if (write)
215 sysrq_toggle_support(__sysrq_enabled);
216
217 return 0;
218}
219
220#endif
221
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700222static struct ctl_table kern_table[];
223static struct ctl_table vm_table[];
224static struct ctl_table fs_table[];
225static struct ctl_table debug_table[];
226static struct ctl_table dev_table[];
227extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800228#ifdef CONFIG_EPOLL
229extern struct ctl_table epoll_table[];
230#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
233int sysctl_legacy_va_layout;
234#endif
235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236/* The default sysctl tables: */
237
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800238static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 .procname = "kernel",
241 .mode = 0555,
242 .child = kern_table,
243 },
244 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 .procname = "vm",
246 .mode = 0555,
247 .child = vm_table,
248 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 .procname = "fs",
251 .mode = 0555,
252 .child = fs_table,
253 },
254 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 .procname = "debug",
256 .mode = 0555,
257 .child = debug_table,
258 },
259 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 .procname = "dev",
261 .mode = 0555,
262 .child = dev_table,
263 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700264 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265};
266
Ingo Molnar77e54a12007-07-09 18:52:00 +0200267#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100268static int min_sched_granularity_ns = 100000; /* 100 usecs */
269static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
270static int min_wakeup_granularity_ns; /* 0 usecs */
271static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200272#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100273static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
274static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200275#endif /* CONFIG_SMP */
276#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200277
Mel Gorman5e771902010-05-24 14:32:31 -0700278#ifdef CONFIG_COMPACTION
279static int min_extfrag_threshold;
280static int max_extfrag_threshold = 1000;
281#endif
282
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700283static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200284 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200285 .procname = "sched_child_runs_first",
286 .data = &sysctl_sched_child_runs_first,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800289 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200290 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200291#ifdef CONFIG_SCHED_DEBUG
292 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100293 .procname = "sched_min_granularity_ns",
294 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800297 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200300 },
301 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200302 .procname = "sched_latency_ns",
303 .data = &sysctl_sched_latency,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800306 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200307 .extra1 = &min_sched_granularity_ns,
308 .extra2 = &max_sched_granularity_ns,
309 },
310 {
Juri Lelli1931b932016-07-29 14:04:11 +0100311 .procname = "sched_is_big_little",
312 .data = &sysctl_sched_is_big_little,
313 .maxlen = sizeof(unsigned int),
314 .mode = 0644,
315 .proc_handler = proc_dointvec,
316 },
Srivatsa Vaddagiri26c21542016-05-31 09:08:38 -0700317#ifdef CONFIG_SCHED_WALT
318 {
319 .procname = "sched_use_walt_cpu_util",
320 .data = &sysctl_sched_use_walt_cpu_util,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
323 .proc_handler = proc_dointvec,
324 },
325 {
326 .procname = "sched_use_walt_task_util",
327 .data = &sysctl_sched_use_walt_task_util,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
330 .proc_handler = proc_dointvec,
331 },
332 {
333 .procname = "sched_walt_init_task_load_pct",
334 .data = &sysctl_sched_walt_init_task_load_pct,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = proc_dointvec,
338 },
Srinath Sridharan3a73c962016-07-22 13:21:15 +0100339 {
340 .procname = "sched_walt_cpu_high_irqload",
341 .data = &sysctl_sched_walt_cpu_high_irqload,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = proc_dointvec,
345 },
Srivatsa Vaddagiri26c21542016-05-31 09:08:38 -0700346#endif
Juri Lelli1931b932016-07-29 14:04:11 +0100347 {
348 .procname = "sched_sync_hint_enable",
349 .data = &sysctl_sched_sync_hint_enable,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
352 .proc_handler = proc_dointvec,
353 },
354 {
Todd Kjosc6a6f3b2016-03-11 16:44:16 -0800355 .procname = "sched_initial_task_util",
356 .data = &sysctl_sched_initial_task_util,
357 .maxlen = sizeof(unsigned int),
358 .mode = 0644,
359 .proc_handler = proc_dointvec,
360 },
361 {
Srinath Sridharanbf47bdd2016-07-14 09:57:29 +0100362 .procname = "sched_cstate_aware",
363 .data = &sysctl_sched_cstate_aware,
364 .maxlen = sizeof(unsigned int),
365 .mode = 0644,
366 .proc_handler = proc_dointvec,
367 },
368 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200369 .procname = "sched_wakeup_granularity_ns",
370 .data = &sysctl_sched_wakeup_granularity,
371 .maxlen = sizeof(unsigned int),
372 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800373 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200374 .extra1 = &min_wakeup_granularity_ns,
375 .extra2 = &max_wakeup_granularity_ns,
376 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200377#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200378 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100379 .procname = "sched_tunable_scaling",
380 .data = &sysctl_sched_tunable_scaling,
381 .maxlen = sizeof(enum sched_tunable_scaling),
382 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800383 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100384 .extra1 = &min_sched_tunable_scaling,
385 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200386 },
387 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900388 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200389 .data = &sysctl_sched_migration_cost,
390 .maxlen = sizeof(unsigned int),
391 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800392 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200393 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100394 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100395 .procname = "sched_nr_migrate",
396 .data = &sysctl_sched_nr_migrate,
397 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100398 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800399 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100400 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530401 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900402 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200403 .data = &sysctl_sched_time_avg,
404 .maxlen = sizeof(unsigned int),
405 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800406 .proc_handler = proc_dointvec,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200407 },
408 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900409 .procname = "sched_shares_window_ns",
Paul Turnera7a4f8a2010-11-15 15:47:06 -0800410 .data = &sysctl_sched_shares_window,
411 .maxlen = sizeof(unsigned int),
412 .mode = 0644,
413 .proc_handler = proc_dointvec,
414 },
Mel Gormancb251762016-02-05 09:08:36 +0000415#ifdef CONFIG_SCHEDSTATS
416 {
417 .procname = "sched_schedstats",
418 .data = NULL,
419 .maxlen = sizeof(unsigned int),
420 .mode = 0644,
421 .proc_handler = sysctl_schedstats,
422 .extra1 = &zero,
423 .extra2 = &one,
424 },
425#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200426#endif /* CONFIG_SMP */
427#ifdef CONFIG_NUMA_BALANCING
428 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200429 .procname = "numa_balancing_scan_delay_ms",
430 .data = &sysctl_numa_balancing_scan_delay,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
433 .proc_handler = proc_dointvec,
434 },
435 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200436 .procname = "numa_balancing_scan_period_min_ms",
437 .data = &sysctl_numa_balancing_scan_period_min,
438 .maxlen = sizeof(unsigned int),
439 .mode = 0644,
440 .proc_handler = proc_dointvec,
441 },
442 {
443 .procname = "numa_balancing_scan_period_max_ms",
444 .data = &sysctl_numa_balancing_scan_period_max,
445 .maxlen = sizeof(unsigned int),
446 .mode = 0644,
447 .proc_handler = proc_dointvec,
448 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200449 {
450 .procname = "numa_balancing_scan_size_mb",
451 .data = &sysctl_numa_balancing_scan_size,
452 .maxlen = sizeof(unsigned int),
453 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400454 .proc_handler = proc_dointvec_minmax,
455 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200456 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100457 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800458 .procname = "numa_balancing",
459 .data = NULL, /* filled in by handler */
460 .maxlen = sizeof(unsigned int),
461 .mode = 0644,
462 .proc_handler = sysctl_numa_balancing,
463 .extra1 = &zero,
464 .extra2 = &one,
465 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200466#endif /* CONFIG_NUMA_BALANCING */
467#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200468 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100469 .procname = "sched_rt_period_us",
470 .data = &sysctl_sched_rt_period,
471 .maxlen = sizeof(unsigned int),
472 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800473 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100474 },
475 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100476 .procname = "sched_rt_runtime_us",
477 .data = &sysctl_sched_rt_runtime,
478 .maxlen = sizeof(int),
479 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800480 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100481 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600482 {
483 .procname = "sched_rr_timeslice_ms",
484 .data = &sched_rr_timeslice,
485 .maxlen = sizeof(int),
486 .mode = 0644,
487 .proc_handler = sched_rr_handler,
488 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100489#ifdef CONFIG_SCHED_AUTOGROUP
490 {
491 .procname = "sched_autogroup_enabled",
492 .data = &sysctl_sched_autogroup_enabled,
493 .maxlen = sizeof(unsigned int),
494 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800495 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100496 .extra1 = &zero,
497 .extra2 = &one,
498 },
499#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700500#ifdef CONFIG_CFS_BANDWIDTH
501 {
502 .procname = "sched_cfs_bandwidth_slice_us",
503 .data = &sysctl_sched_cfs_bandwidth_slice,
504 .maxlen = sizeof(unsigned int),
505 .mode = 0644,
506 .proc_handler = proc_dointvec_minmax,
507 .extra1 = &one,
508 },
509#endif
Patrick Bellasi69fa4c72015-06-22 18:11:44 +0100510#ifdef CONFIG_SCHED_TUNE
511 {
512 .procname = "sched_cfs_boost",
513 .data = &sysctl_sched_cfs_boost,
514 .maxlen = sizeof(sysctl_sched_cfs_boost),
Patrick Bellasiae710302015-06-23 09:17:54 +0100515#ifdef CONFIG_CGROUP_SCHEDTUNE
516 .mode = 0444,
517#else
Patrick Bellasi69fa4c72015-06-22 18:11:44 +0100518 .mode = 0644,
Patrick Bellasiae710302015-06-23 09:17:54 +0100519#endif
Patrick Bellasi69fa4c72015-06-22 18:11:44 +0100520 .proc_handler = &sysctl_sched_cfs_boost_handler,
521 .extra1 = &zero,
522 .extra2 = &one_hundred,
523 },
524#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700525#ifdef CONFIG_PROVE_LOCKING
526 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700527 .procname = "prove_locking",
528 .data = &prove_locking,
529 .maxlen = sizeof(int),
530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800531 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700532 },
533#endif
534#ifdef CONFIG_LOCK_STAT
535 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700536 .procname = "lock_stat",
537 .data = &lock_stat,
538 .maxlen = sizeof(int),
539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800540 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700541 },
542#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .procname = "panic",
545 .data = &panic_timeout,
546 .maxlen = sizeof(int),
547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800548 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 },
Alex Kelly046d6622012-10-04 17:15:23 -0700550#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 .procname = "core_uses_pid",
553 .data = &core_uses_pid,
554 .maxlen = sizeof(int),
555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 },
558 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 .procname = "core_pattern",
560 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700561 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700563 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 },
Neil Hormana2939802009-09-23 15:56:56 -0700565 {
Neil Hormana2939802009-09-23 15:56:56 -0700566 .procname = "core_pipe_limit",
567 .data = &core_pipe_limit,
568 .maxlen = sizeof(unsigned int),
569 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800570 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700571 },
Alex Kelly046d6622012-10-04 17:15:23 -0700572#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800573#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700576 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800577 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800578 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700580 {
581 .procname = "sysctl_writes_strict",
582 .data = &sysctl_writes_strict,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = proc_dointvec_minmax,
586 .extra1 = &neg_one,
587 .extra2 = &one,
588 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800589#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100590#ifdef CONFIG_LATENCYTOP
591 {
592 .procname = "latencytop",
593 .data = &latencytop_enabled,
594 .maxlen = sizeof(int),
595 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000596 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100597 },
598#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#ifdef CONFIG_BLK_DEV_INITRD
600 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .procname = "real-root-dev",
602 .data = &real_root_dev,
603 .maxlen = sizeof(int),
604 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800605 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 },
607#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700608 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700609 .procname = "print-fatal-signals",
610 .data = &print_fatal_signals,
611 .maxlen = sizeof(int),
612 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800613 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700614 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700615#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 .procname = "reboot-cmd",
618 .data = reboot_command,
619 .maxlen = 256,
620 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800621 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 },
623 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 .procname = "stop-a",
625 .data = &stop_a_enabled,
626 .maxlen = sizeof (int),
627 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800628 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 },
630 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .procname = "scons-poweroff",
632 .data = &scons_pwroff,
633 .maxlen = sizeof (int),
634 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800635 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 },
637#endif
David S. Miller08714202008-11-16 23:49:24 -0800638#ifdef CONFIG_SPARC64
639 {
David S. Miller08714202008-11-16 23:49:24 -0800640 .procname = "tsb-ratio",
641 .data = &sysctl_tsb_ratio,
642 .maxlen = sizeof (int),
643 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800644 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800645 },
646#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647#ifdef __hppa__
648 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 .procname = "soft-power",
650 .data = &pwrsw_enabled,
651 .maxlen = sizeof (int),
652 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800653 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530655#endif
656#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 .procname = "unaligned-trap",
659 .data = &unaligned_enabled,
660 .maxlen = sizeof (int),
661 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800662 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 },
664#endif
665 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 .procname = "ctrl-alt-del",
667 .data = &C_A_D,
668 .maxlen = sizeof(int),
669 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800670 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400672#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200673 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200674 .procname = "ftrace_enabled",
675 .data = &ftrace_enabled,
676 .maxlen = sizeof(int),
677 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800678 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200679 },
680#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500681#ifdef CONFIG_STACK_TRACER
682 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500683 .procname = "stack_tracer_enabled",
684 .data = &stack_tracer_enabled,
685 .maxlen = sizeof(int),
686 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800687 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500688 },
689#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400690#ifdef CONFIG_TRACING
691 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100692 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400693 .data = &ftrace_dump_on_oops,
694 .maxlen = sizeof(int),
695 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800696 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400697 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400698 {
699 .procname = "traceoff_on_warning",
700 .data = &__disable_trace_on_warning,
701 .maxlen = sizeof(__disable_trace_on_warning),
702 .mode = 0644,
703 .proc_handler = proc_dointvec,
704 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500705 {
706 .procname = "tracepoint_printk",
707 .data = &tracepoint_printk,
708 .maxlen = sizeof(tracepoint_printk),
709 .mode = 0644,
710 .proc_handler = proc_dointvec,
711 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400712#endif
Dave Young2965faa2015-09-09 15:38:55 -0700713#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800714 {
715 .procname = "kexec_load_disabled",
716 .data = &kexec_load_disabled,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 /* only handle a transition from default "0" to "1" */
720 .proc_handler = proc_dointvec_minmax,
721 .extra1 = &one,
722 .extra2 = &one,
723 },
724#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200725#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 .procname = "modprobe",
728 .data = &modprobe_path,
729 .maxlen = KMOD_PATH_LEN,
730 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800731 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 },
Kees Cook3d433212009-04-02 15:49:29 -0700733 {
Kees Cook3d433212009-04-02 15:49:29 -0700734 .procname = "modules_disabled",
735 .data = &modules_disabled,
736 .maxlen = sizeof(int),
737 .mode = 0644,
738 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800739 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700740 .extra1 = &one,
741 .extra2 = &one,
742 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700744#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100747 .data = &uevent_helper,
748 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800750 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 },
Michael Marineau86d56132014-04-10 14:09:31 -0700752#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753#ifdef CONFIG_CHR_DEV_SG
754 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .procname = "sg-big-buff",
756 .data = &sg_big_buff,
757 .maxlen = sizeof (int),
758 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800759 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 },
761#endif
762#ifdef CONFIG_BSD_PROCESS_ACCT
763 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .procname = "acct",
765 .data = &acct_parm,
766 .maxlen = 3*sizeof(int),
767 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800768 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 },
770#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771#ifdef CONFIG_MAGIC_SYSRQ
772 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800774 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 .maxlen = sizeof (int),
776 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700777 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 },
779#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700780#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700783 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 .maxlen = sizeof (int),
785 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800786 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700788#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700791 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .maxlen = sizeof(int),
793 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700794 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 },
796 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 .procname = "random",
798 .mode = 0555,
799 .child = random_table,
800 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 {
Eric Paris17f60a72011-04-01 17:07:50 -0400802 .procname = "usermodehelper",
803 .mode = 0555,
804 .child = usermodehelper_table,
805 },
806 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 .procname = "overflowuid",
808 .data = &overflowuid,
809 .maxlen = sizeof(int),
810 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800811 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 .extra1 = &minolduid,
813 .extra2 = &maxolduid,
814 },
815 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 .procname = "overflowgid",
817 .data = &overflowgid,
818 .maxlen = sizeof(int),
819 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800820 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 .extra1 = &minolduid,
822 .extra2 = &maxolduid,
823 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800824#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825#ifdef CONFIG_MATHEMU
826 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 .procname = "ieee_emulation_warnings",
828 .data = &sysctl_ieee_emulation_warnings,
829 .maxlen = sizeof(int),
830 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800831 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 },
833#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200836 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 .maxlen = sizeof(int),
838 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800839 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 },
841#endif
842 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 .procname = "pid_max",
844 .data = &pid_max,
845 .maxlen = sizeof (int),
846 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800847 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 .extra1 = &pid_max_min,
849 .extra2 = &pid_max_max,
850 },
851 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 .procname = "panic_on_oops",
853 .data = &panic_on_oops,
854 .maxlen = sizeof(int),
855 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800856 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800858#if defined CONFIG_PRINTK
859 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800860 .procname = "printk",
861 .data = &console_loglevel,
862 .maxlen = 4*sizeof(int),
863 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800864 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800865 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700868 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 .maxlen = sizeof(int),
870 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800871 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 },
873 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700875 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 .maxlen = sizeof(int),
877 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800878 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 },
Dave Youngaf913222009-09-22 16:43:33 -0700880 {
Dave Youngaf913222009-09-22 16:43:33 -0700881 .procname = "printk_delay",
882 .data = &printk_delay_msec,
883 .maxlen = sizeof(int),
884 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800885 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700886 .extra1 = &zero,
887 .extra2 = &ten_thousand,
888 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700890 .procname = "printk_devkmsg",
891 .data = devkmsg_log_str,
892 .maxlen = DEVKMSG_STR_MAX_SIZE,
893 .mode = 0644,
894 .proc_handler = devkmsg_sysctl_set_loglvl,
895 },
896 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800897 .procname = "dmesg_restrict",
898 .data = &dmesg_restrict,
899 .maxlen = sizeof(int),
900 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700901 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800902 .extra1 = &zero,
903 .extra2 = &one,
904 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800905 {
906 .procname = "kptr_restrict",
907 .data = &kptr_restrict,
908 .maxlen = sizeof(int),
909 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700910 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800911 .extra1 = &zero,
912 .extra2 = &two,
913 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800914#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800915 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 .procname = "ngroups_max",
917 .data = &ngroups_max,
918 .maxlen = sizeof (int),
919 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800920 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 },
Dan Ballard73efc032011-10-31 17:11:20 -0700922 {
923 .procname = "cap_last_cap",
924 .data = (void *)&cap_last_cap,
925 .maxlen = sizeof(int),
926 .mode = 0444,
927 .proc_handler = proc_dointvec,
928 },
Don Zickus58687ac2010-05-07 17:11:44 -0400929#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500930 {
Don Zickus58687ac2010-05-07 17:11:44 -0400931 .procname = "watchdog",
Frederic Weisbecker3c00ea82013-05-19 20:45:15 +0200932 .data = &watchdog_user_enabled,
Don Zickus504d7cf2010-02-12 17:19:19 -0500933 .maxlen = sizeof (int),
934 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700935 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700936 .extra1 = &zero,
937 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400938 },
939 {
940 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700941 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400942 .maxlen = sizeof(int),
943 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700944 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800945 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400946 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500947 },
Don Zickus2508ce12010-05-07 17:11:46 -0400948 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700949 .procname = "nmi_watchdog",
950 .data = &nmi_watchdog_enabled,
951 .maxlen = sizeof (int),
952 .mode = 0644,
953 .proc_handler = proc_nmi_watchdog,
954 .extra1 = &zero,
955#if defined(CONFIG_HAVE_NMI_WATCHDOG) || defined(CONFIG_HARDLOCKUP_DETECTOR)
956 .extra2 = &one,
957#else
958 .extra2 = &zero,
959#endif
960 },
961 {
962 .procname = "soft_watchdog",
963 .data = &soft_watchdog_enabled,
964 .maxlen = sizeof (int),
965 .mode = 0644,
966 .proc_handler = proc_soft_watchdog,
967 .extra1 = &zero,
968 .extra2 = &one,
969 },
970 {
Chris Metcalffe4ba3c2015-06-24 16:55:45 -0700971 .procname = "watchdog_cpumask",
972 .data = &watchdog_cpumask_bits,
973 .maxlen = NR_CPUS,
974 .mode = 0644,
975 .proc_handler = proc_watchdog_cpumask,
976 },
977 {
Don Zickus2508ce12010-05-07 17:11:46 -0400978 .procname = "softlockup_panic",
979 .data = &softlockup_panic,
980 .maxlen = sizeof(int),
981 .mode = 0644,
982 .proc_handler = proc_dointvec_minmax,
983 .extra1 = &zero,
984 .extra2 = &one,
985 },
Don Zickusac1f5912015-11-05 18:44:44 -0800986#ifdef CONFIG_HARDLOCKUP_DETECTOR
987 {
988 .procname = "hardlockup_panic",
989 .data = &hardlockup_panic,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = proc_dointvec_minmax,
993 .extra1 = &zero,
994 .extra2 = &one,
995 },
996#endif
Aaron Tomlined235872014-06-23 13:22:05 -0700997#ifdef CONFIG_SMP
998 {
999 .procname = "softlockup_all_cpu_backtrace",
1000 .data = &sysctl_softlockup_all_cpu_backtrace,
1001 .maxlen = sizeof(int),
1002 .mode = 0644,
1003 .proc_handler = proc_dointvec_minmax,
1004 .extra1 = &zero,
1005 .extra2 = &one,
1006 },
Jiri Kosina55537872015-11-05 18:44:41 -08001007 {
1008 .procname = "hardlockup_all_cpu_backtrace",
1009 .data = &sysctl_hardlockup_all_cpu_backtrace,
1010 .maxlen = sizeof(int),
1011 .mode = 0644,
1012 .proc_handler = proc_dointvec_minmax,
1013 .extra1 = &zero,
1014 .extra2 = &one,
1015 },
Aaron Tomlined235872014-06-23 13:22:05 -07001016#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -05001017#endif
1018#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1019 {
1020 .procname = "unknown_nmi_panic",
1021 .data = &unknown_nmi_panic,
1022 .maxlen = sizeof (int),
1023 .mode = 0644,
1024 .proc_handler = proc_dointvec,
1025 },
Don Zickus504d7cf2010-02-12 17:19:19 -05001026#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027#if defined(CONFIG_X86)
1028 {
Don Zickus8da5add2006-09-26 10:52:27 +02001029 .procname = "panic_on_unrecovered_nmi",
1030 .data = &panic_on_unrecovered_nmi,
1031 .maxlen = sizeof(int),
1032 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001033 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001034 },
1035 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001036 .procname = "panic_on_io_nmi",
1037 .data = &panic_on_io_nmi,
1038 .maxlen = sizeof(int),
1039 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001040 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001041 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001042#ifdef CONFIG_DEBUG_STACKOVERFLOW
1043 {
1044 .procname = "panic_on_stackoverflow",
1045 .data = &sysctl_panic_on_stackoverflow,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
1048 .proc_handler = proc_dointvec,
1049 },
1050#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001051 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 .procname = "bootloader_type",
1053 .data = &bootloader_type,
1054 .maxlen = sizeof (int),
1055 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001056 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001058 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001059 .procname = "bootloader_version",
1060 .data = &bootloader_version,
1061 .maxlen = sizeof (int),
1062 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001063 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001064 },
1065 {
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001066 .procname = "kstack_depth_to_print",
1067 .data = &kstack_depth_to_print,
1068 .maxlen = sizeof(int),
1069 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001070 .proc_handler = proc_dointvec,
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001071 },
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001072 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001073 .procname = "io_delay_type",
1074 .data = &io_delay_type,
1075 .maxlen = sizeof(int),
1076 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001077 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001078 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001080#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 .procname = "randomize_va_space",
1083 .data = &randomize_va_space,
1084 .maxlen = sizeof(int),
1085 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001086 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001088#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001089#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001090 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001091 .procname = "spin_retry",
1092 .data = &spin_retry,
1093 .maxlen = sizeof (int),
1094 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001095 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001096 },
1097#endif
Len Brown673d5b42007-07-28 03:33:16 -04001098#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001099 {
Pavel Machekc255d842006-02-20 18:27:58 -08001100 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001101 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001102 .maxlen = sizeof (unsigned long),
1103 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001104 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001105 },
1106#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301107#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001108 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001109 .procname = "ignore-unaligned-usertrap",
1110 .data = &no_unaligned_warning,
1111 .maxlen = sizeof (int),
1112 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001113 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001114 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301115#endif
1116#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001117 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001118 .procname = "unaligned-dump-stack",
1119 .data = &unaligned_dump_stack,
1120 .maxlen = sizeof (int),
1121 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001122 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001123 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001124#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001125#ifdef CONFIG_DETECT_HUNG_TASK
1126 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001127 .procname = "hung_task_panic",
1128 .data = &sysctl_hung_task_panic,
1129 .maxlen = sizeof(int),
1130 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001131 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001132 .extra1 = &zero,
1133 .extra2 = &one,
1134 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001135 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001136 .procname = "hung_task_check_count",
1137 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001138 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001139 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001140 .proc_handler = proc_dointvec_minmax,
1141 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001142 },
1143 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001144 .procname = "hung_task_timeout_secs",
1145 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001146 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001147 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001148 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001149 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001150 },
1151 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001152 .procname = "hung_task_warnings",
1153 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001154 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001155 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001156 .proc_handler = proc_dointvec_minmax,
1157 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001158 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001159#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001160#ifdef CONFIG_RT_MUTEXES
1161 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001162 .procname = "max_lock_depth",
1163 .data = &max_lock_depth,
1164 .maxlen = sizeof(int),
1165 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001166 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001167 },
1168#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001169 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001170 .procname = "poweroff_cmd",
1171 .data = &poweroff_cmd,
1172 .maxlen = POWEROFF_CMD_PATH_LEN,
1173 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001174 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001175 },
David Howells0b77f5b2008-04-29 01:01:32 -07001176#ifdef CONFIG_KEYS
1177 {
David Howells0b77f5b2008-04-29 01:01:32 -07001178 .procname = "keys",
1179 .mode = 0555,
1180 .child = key_sysctls,
1181 },
1182#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001183#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001184 /*
1185 * User-space scripts rely on the existence of this file
1186 * as a feature check for perf_events being enabled.
1187 *
1188 * So it's an ABI, do not remove!
1189 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001190 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001191 .procname = "perf_event_paranoid",
1192 .data = &sysctl_perf_event_paranoid,
1193 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001194 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001195 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001196 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001197 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001198 .procname = "perf_event_mlock_kb",
1199 .data = &sysctl_perf_event_mlock,
1200 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001201 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001202 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001203 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001204 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001205 .procname = "perf_event_max_sample_rate",
1206 .data = &sysctl_perf_event_sample_rate,
1207 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001208 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001209 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001210 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001211 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001212 {
1213 .procname = "perf_cpu_time_max_percent",
1214 .data = &sysctl_perf_cpu_time_max_percent,
1215 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1216 .mode = 0644,
1217 .proc_handler = perf_cpu_time_max_percent_handler,
1218 .extra1 = &zero,
1219 .extra2 = &one_hundred,
1220 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001221 {
1222 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001223 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001224 .maxlen = sizeof(sysctl_perf_event_max_stack),
1225 .mode = 0644,
1226 .proc_handler = perf_event_max_stack_handler,
1227 .extra1 = &zero,
1228 .extra2 = &six_hundred_forty_kb,
1229 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001230 {
1231 .procname = "perf_event_max_contexts_per_stack",
1232 .data = &sysctl_perf_event_max_contexts_per_stack,
1233 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1234 .mode = 0644,
1235 .proc_handler = perf_event_max_stack_handler,
1236 .extra1 = &zero,
1237 .extra2 = &one_thousand,
1238 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001239#endif
Vegard Nossumdfec0722008-04-04 00:51:41 +02001240#ifdef CONFIG_KMEMCHECK
1241 {
Vegard Nossumdfec0722008-04-04 00:51:41 +02001242 .procname = "kmemcheck",
1243 .data = &kmemcheck_enabled,
1244 .maxlen = sizeof(int),
1245 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001246 .proc_handler = proc_dointvec,
Vegard Nossumdfec0722008-04-04 00:51:41 +02001247 },
1248#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001249 {
1250 .procname = "panic_on_warn",
1251 .data = &panic_on_warn,
1252 .maxlen = sizeof(int),
1253 .mode = 0644,
1254 .proc_handler = proc_dointvec_minmax,
1255 .extra1 = &zero,
1256 .extra2 = &one,
1257 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001258#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1259 {
1260 .procname = "timer_migration",
1261 .data = &sysctl_timer_migration,
1262 .maxlen = sizeof(unsigned int),
1263 .mode = 0644,
1264 .proc_handler = timer_migration_handler,
1265 },
1266#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001267#ifdef CONFIG_BPF_SYSCALL
1268 {
1269 .procname = "unprivileged_bpf_disabled",
1270 .data = &sysctl_unprivileged_bpf_disabled,
1271 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1272 .mode = 0644,
1273 /* only handle a transition from default "0" to "1" */
1274 .proc_handler = proc_dointvec_minmax,
1275 .extra1 = &one,
1276 .extra2 = &one,
1277 },
1278#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001279#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1280 {
1281 .procname = "panic_on_rcu_stall",
1282 .data = &sysctl_panic_on_rcu_stall,
1283 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1284 .mode = 0644,
1285 .proc_handler = proc_dointvec_minmax,
1286 .extra1 = &zero,
1287 .extra2 = &one,
1288 },
1289#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001290 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291};
1292
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001293static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 .procname = "overcommit_memory",
1296 .data = &sysctl_overcommit_memory,
1297 .maxlen = sizeof(sysctl_overcommit_memory),
1298 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001299 .proc_handler = proc_dointvec_minmax,
1300 .extra1 = &zero,
1301 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 },
1303 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001304 .procname = "panic_on_oom",
1305 .data = &sysctl_panic_on_oom,
1306 .maxlen = sizeof(sysctl_panic_on_oom),
1307 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001308 .proc_handler = proc_dointvec_minmax,
1309 .extra1 = &zero,
1310 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001311 },
1312 {
David Rientjesfe071d72007-10-16 23:25:56 -07001313 .procname = "oom_kill_allocating_task",
1314 .data = &sysctl_oom_kill_allocating_task,
1315 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001317 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001318 },
1319 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001320 .procname = "oom_dump_tasks",
1321 .data = &sysctl_oom_dump_tasks,
1322 .maxlen = sizeof(sysctl_oom_dump_tasks),
1323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001324 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001325 },
1326 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 .procname = "overcommit_ratio",
1328 .data = &sysctl_overcommit_ratio,
1329 .maxlen = sizeof(sysctl_overcommit_ratio),
1330 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001331 .proc_handler = overcommit_ratio_handler,
1332 },
1333 {
1334 .procname = "overcommit_kbytes",
1335 .data = &sysctl_overcommit_kbytes,
1336 .maxlen = sizeof(sysctl_overcommit_kbytes),
1337 .mode = 0644,
1338 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 },
1340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .procname = "page-cluster",
1342 .data = &page_cluster,
1343 .maxlen = sizeof(int),
1344 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001345 .proc_handler = proc_dointvec_minmax,
1346 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 },
1348 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 .procname = "dirty_background_ratio",
1350 .data = &dirty_background_ratio,
1351 .maxlen = sizeof(dirty_background_ratio),
1352 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001353 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 .extra1 = &zero,
1355 .extra2 = &one_hundred,
1356 },
1357 {
David Rientjes2da02992009-01-06 14:39:31 -08001358 .procname = "dirty_background_bytes",
1359 .data = &dirty_background_bytes,
1360 .maxlen = sizeof(dirty_background_bytes),
1361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001362 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001363 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001364 },
1365 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 .procname = "dirty_ratio",
1367 .data = &vm_dirty_ratio,
1368 .maxlen = sizeof(vm_dirty_ratio),
1369 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001370 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 .extra1 = &zero,
1372 .extra2 = &one_hundred,
1373 },
1374 {
David Rientjes2da02992009-01-06 14:39:31 -08001375 .procname = "dirty_bytes",
1376 .data = &vm_dirty_bytes,
1377 .maxlen = sizeof(vm_dirty_bytes),
1378 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001379 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001380 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001381 },
1382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001384 .data = &dirty_writeback_interval,
1385 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 },
1389 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001391 .data = &dirty_expire_interval,
1392 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001394 .proc_handler = proc_dointvec_minmax,
1395 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 },
1397 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001398 .procname = "dirtytime_expire_seconds",
1399 .data = &dirtytime_expire_interval,
1400 .maxlen = sizeof(dirty_expire_interval),
1401 .mode = 0644,
1402 .proc_handler = dirtytime_interval_handler,
1403 .extra1 = &zero,
1404 },
1405 {
Wanpeng Li3965c9a2012-07-31 16:41:52 -07001406 .procname = "nr_pdflush_threads",
1407 .mode = 0444 /* read-only */,
1408 .proc_handler = pdflush_proc_obsolete,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 },
1410 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 .procname = "swappiness",
1412 .data = &vm_swappiness,
1413 .maxlen = sizeof(vm_swappiness),
1414 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001415 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 .extra1 = &zero,
1417 .extra2 = &one_hundred,
1418 },
1419#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001420 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001422 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 .maxlen = sizeof(unsigned long),
1424 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001425 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001426 },
1427#ifdef CONFIG_NUMA
1428 {
1429 .procname = "nr_hugepages_mempolicy",
1430 .data = NULL,
1431 .maxlen = sizeof(unsigned long),
1432 .mode = 0644,
1433 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001434 },
1435#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 .procname = "hugetlb_shm_group",
1438 .data = &sysctl_hugetlb_shm_group,
1439 .maxlen = sizeof(gid_t),
1440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001441 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 },
Mel Gorman396faf02007-07-17 04:03:13 -07001443 {
Mel Gorman396faf02007-07-17 04:03:13 -07001444 .procname = "hugepages_treat_as_movable",
1445 .data = &hugepages_treat_as_movable,
1446 .maxlen = sizeof(int),
1447 .mode = 0644,
Naoya Horiguchi86cdb462013-09-11 14:22:13 -07001448 .proc_handler = proc_dointvec,
Mel Gorman396faf02007-07-17 04:03:13 -07001449 },
Adam Litke54f9f802007-10-16 01:26:20 -07001450 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001451 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001452 .data = NULL,
1453 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001454 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001455 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001456 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457#endif
1458 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 .procname = "lowmem_reserve_ratio",
1460 .data = &sysctl_lowmem_reserve_ratio,
1461 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1462 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001463 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 },
1465 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001466 .procname = "drop_caches",
1467 .data = &sysctl_drop_caches,
1468 .maxlen = sizeof(int),
1469 .mode = 0644,
1470 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001471 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001472 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001473 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001474#ifdef CONFIG_COMPACTION
1475 {
1476 .procname = "compact_memory",
1477 .data = &sysctl_compact_memory,
1478 .maxlen = sizeof(int),
1479 .mode = 0200,
1480 .proc_handler = sysctl_compaction_handler,
1481 },
Mel Gorman5e771902010-05-24 14:32:31 -07001482 {
1483 .procname = "extfrag_threshold",
1484 .data = &sysctl_extfrag_threshold,
1485 .maxlen = sizeof(int),
1486 .mode = 0644,
1487 .proc_handler = sysctl_extfrag_handler,
1488 .extra1 = &min_extfrag_threshold,
1489 .extra2 = &max_extfrag_threshold,
1490 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001491 {
1492 .procname = "compact_unevictable_allowed",
1493 .data = &sysctl_compact_unevictable_allowed,
1494 .maxlen = sizeof(int),
1495 .mode = 0644,
1496 .proc_handler = proc_dointvec,
1497 .extra1 = &zero,
1498 .extra2 = &one,
1499 },
Mel Gorman5e771902010-05-24 14:32:31 -07001500
Mel Gorman76ab0f52010-05-24 14:32:28 -07001501#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001502 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 .procname = "min_free_kbytes",
1504 .data = &min_free_kbytes,
1505 .maxlen = sizeof(min_free_kbytes),
1506 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001507 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 .extra1 = &zero,
1509 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001510 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001511 .procname = "watermark_scale_factor",
1512 .data = &watermark_scale_factor,
1513 .maxlen = sizeof(watermark_scale_factor),
1514 .mode = 0644,
1515 .proc_handler = watermark_scale_factor_sysctl_handler,
1516 .extra1 = &one,
1517 .extra2 = &one_thousand,
1518 },
1519 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001520 .procname = "percpu_pagelist_fraction",
1521 .data = &percpu_pagelist_fraction,
1522 .maxlen = sizeof(percpu_pagelist_fraction),
1523 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001524 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001525 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001526 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527#ifdef CONFIG_MMU
1528 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 .procname = "max_map_count",
1530 .data = &sysctl_max_map_count,
1531 .maxlen = sizeof(sysctl_max_map_count),
1532 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001533 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001534 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001536#else
1537 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001538 .procname = "nr_trim_pages",
1539 .data = &sysctl_nr_trim_pages,
1540 .maxlen = sizeof(sysctl_nr_trim_pages),
1541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001542 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001543 .extra1 = &zero,
1544 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545#endif
1546 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 .procname = "laptop_mode",
1548 .data = &laptop_mode,
1549 .maxlen = sizeof(laptop_mode),
1550 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001551 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 },
1553 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 .procname = "block_dump",
1555 .data = &block_dump,
1556 .maxlen = sizeof(block_dump),
1557 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001558 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 .extra1 = &zero,
1560 },
1561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 .procname = "vfs_cache_pressure",
1563 .data = &sysctl_vfs_cache_pressure,
1564 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001566 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 .extra1 = &zero,
1568 },
1569#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1570 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 .procname = "legacy_va_layout",
1572 .data = &sysctl_legacy_va_layout,
1573 .maxlen = sizeof(sysctl_legacy_va_layout),
1574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001575 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 .extra1 = &zero,
1577 },
1578#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001579#ifdef CONFIG_NUMA
1580 {
Christoph Lameter17436602006-01-18 17:42:32 -08001581 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001582 .data = &node_reclaim_mode,
1583 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001585 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001586 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001587 },
Christoph Lameter96146342006-07-03 00:24:13 -07001588 {
Christoph Lameter96146342006-07-03 00:24:13 -07001589 .procname = "min_unmapped_ratio",
1590 .data = &sysctl_min_unmapped_ratio,
1591 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1592 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001593 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001594 .extra1 = &zero,
1595 .extra2 = &one_hundred,
1596 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001597 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001598 .procname = "min_slab_ratio",
1599 .data = &sysctl_min_slab_ratio,
1600 .maxlen = sizeof(sysctl_min_slab_ratio),
1601 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001602 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001603 .extra1 = &zero,
1604 .extra2 = &one_hundred,
1605 },
Christoph Lameter17436602006-01-18 17:42:32 -08001606#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001607#ifdef CONFIG_SMP
1608 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001609 .procname = "stat_interval",
1610 .data = &sysctl_stat_interval,
1611 .maxlen = sizeof(sysctl_stat_interval),
1612 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001613 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001614 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001615 {
1616 .procname = "stat_refresh",
1617 .data = NULL,
1618 .maxlen = 0,
1619 .mode = 0600,
1620 .proc_handler = vmstat_refresh,
1621 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001622#endif
David Howells6e141542009-12-15 19:27:45 +00001623#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001624 {
Eric Parised032182007-06-28 15:55:21 -04001625 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001626 .data = &dac_mmap_min_addr,
1627 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001628 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001629 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001630 },
David Howells6e141542009-12-15 19:27:45 +00001631#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001632#ifdef CONFIG_NUMA
1633 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001634 .procname = "numa_zonelist_order",
1635 .data = &numa_zonelist_order,
1636 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1637 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001638 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001639 },
1640#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001641#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001642 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001643 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001644 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001645#ifdef CONFIG_X86_32
1646 .data = &vdso32_enabled,
1647 .maxlen = sizeof(vdso32_enabled),
1648#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001649 .data = &vdso_enabled,
1650 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001651#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001652 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001653 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001654 .extra1 = &zero,
1655 },
1656#endif
Bron Gondwana195cf452008-02-04 22:29:20 -08001657#ifdef CONFIG_HIGHMEM
1658 {
Bron Gondwana195cf452008-02-04 22:29:20 -08001659 .procname = "highmem_is_dirtyable",
1660 .data = &vm_highmem_is_dirtyable,
1661 .maxlen = sizeof(vm_highmem_is_dirtyable),
1662 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001663 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf452008-02-04 22:29:20 -08001664 .extra1 = &zero,
1665 .extra2 = &one,
1666 },
1667#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001668#ifdef CONFIG_MEMORY_FAILURE
1669 {
Andi Kleen6a460792009-09-16 11:50:15 +02001670 .procname = "memory_failure_early_kill",
1671 .data = &sysctl_memory_failure_early_kill,
1672 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1673 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001674 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001675 .extra1 = &zero,
1676 .extra2 = &one,
1677 },
1678 {
Andi Kleen6a460792009-09-16 11:50:15 +02001679 .procname = "memory_failure_recovery",
1680 .data = &sysctl_memory_failure_recovery,
1681 .maxlen = sizeof(sysctl_memory_failure_recovery),
1682 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001683 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001684 .extra1 = &zero,
1685 .extra2 = &one,
1686 },
1687#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001688 {
1689 .procname = "user_reserve_kbytes",
1690 .data = &sysctl_user_reserve_kbytes,
1691 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1692 .mode = 0644,
1693 .proc_handler = proc_doulongvec_minmax,
1694 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001695 {
1696 .procname = "admin_reserve_kbytes",
1697 .data = &sysctl_admin_reserve_kbytes,
1698 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1699 .mode = 0644,
1700 .proc_handler = proc_doulongvec_minmax,
1701 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001702#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1703 {
1704 .procname = "mmap_rnd_bits",
1705 .data = &mmap_rnd_bits,
1706 .maxlen = sizeof(mmap_rnd_bits),
1707 .mode = 0600,
1708 .proc_handler = proc_dointvec_minmax,
1709 .extra1 = (void *)&mmap_rnd_bits_min,
1710 .extra2 = (void *)&mmap_rnd_bits_max,
1711 },
1712#endif
1713#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1714 {
1715 .procname = "mmap_rnd_compat_bits",
1716 .data = &mmap_rnd_compat_bits,
1717 .maxlen = sizeof(mmap_rnd_compat_bits),
1718 .mode = 0600,
1719 .proc_handler = proc_dointvec_minmax,
1720 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1721 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1722 },
1723#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001724 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725};
1726
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001727static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 .procname = "inode-nr",
1730 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001731 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001733 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 },
1735 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 .procname = "inode-state",
1737 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001738 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001740 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 },
1742 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 .procname = "file-nr",
1744 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001745 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001747 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 },
1749 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 .procname = "file-max",
1751 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001752 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001754 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 },
1756 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001757 .procname = "nr_open",
1758 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001759 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001760 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001761 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001762 .extra1 = &sysctl_nr_open_min,
1763 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001764 },
1765 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 .procname = "dentry-state",
1767 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001768 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001770 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 },
1772 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 .procname = "overflowuid",
1774 .data = &fs_overflowuid,
1775 .maxlen = sizeof(int),
1776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001777 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 .extra1 = &minolduid,
1779 .extra2 = &maxolduid,
1780 },
1781 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 .procname = "overflowgid",
1783 .data = &fs_overflowgid,
1784 .maxlen = sizeof(int),
1785 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001786 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 .extra1 = &minolduid,
1788 .extra2 = &maxolduid,
1789 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001790#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 .procname = "leases-enable",
1793 .data = &leases_enable,
1794 .maxlen = sizeof(int),
1795 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001796 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001798#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799#ifdef CONFIG_DNOTIFY
1800 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 .procname = "dir-notify-enable",
1802 .data = &dir_notify_enable,
1803 .maxlen = sizeof(int),
1804 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001805 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 },
1807#endif
1808#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001809#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 .procname = "lease-break-time",
1812 .data = &lease_break_time,
1813 .maxlen = sizeof(int),
1814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001815 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001817#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001818#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 .procname = "aio-nr",
1821 .data = &aio_nr,
1822 .maxlen = sizeof(aio_nr),
1823 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001824 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 },
1826 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 .procname = "aio-max-nr",
1828 .data = &aio_max_nr,
1829 .maxlen = sizeof(aio_max_nr),
1830 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001831 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001833#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001834#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001835 {
Robert Love0399cb02005-07-13 12:38:18 -04001836 .procname = "inotify",
1837 .mode = 0555,
1838 .child = inotify_table,
1839 },
1840#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001841#ifdef CONFIG_EPOLL
1842 {
1843 .procname = "epoll",
1844 .mode = 0555,
1845 .child = epoll_table,
1846 },
1847#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001849 {
Kees Cook800179c2012-07-25 17:29:07 -07001850 .procname = "protected_symlinks",
1851 .data = &sysctl_protected_symlinks,
1852 .maxlen = sizeof(int),
1853 .mode = 0600,
1854 .proc_handler = proc_dointvec_minmax,
1855 .extra1 = &zero,
1856 .extra2 = &one,
1857 },
1858 {
1859 .procname = "protected_hardlinks",
1860 .data = &sysctl_protected_hardlinks,
1861 .maxlen = sizeof(int),
1862 .mode = 0600,
1863 .proc_handler = proc_dointvec_minmax,
1864 .extra1 = &zero,
1865 .extra2 = &one,
1866 },
1867 {
Alan Coxd6e71142005-06-23 00:09:43 -07001868 .procname = "suid_dumpable",
1869 .data = &suid_dumpable,
1870 .maxlen = sizeof(int),
1871 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001872 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001873 .extra1 = &zero,
1874 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001875 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001876#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1877 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001878 .procname = "binfmt_misc",
1879 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001880 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001881 },
1882#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001883 {
Jens Axboeff9da692010-06-03 14:54:39 +02001884 .procname = "pipe-max-size",
1885 .data = &pipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001886 .maxlen = sizeof(int),
1887 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001888 .proc_handler = &pipe_proc_fn,
1889 .extra1 = &pipe_min_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001890 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001891 {
1892 .procname = "pipe-user-pages-hard",
1893 .data = &pipe_user_pages_hard,
1894 .maxlen = sizeof(pipe_user_pages_hard),
1895 .mode = 0644,
1896 .proc_handler = proc_doulongvec_minmax,
1897 },
1898 {
1899 .procname = "pipe-user-pages-soft",
1900 .data = &pipe_user_pages_soft,
1901 .maxlen = sizeof(pipe_user_pages_soft),
1902 .mode = 0644,
1903 .proc_handler = proc_doulongvec_minmax,
1904 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001905 {
1906 .procname = "mount-max",
1907 .data = &sysctl_mount_max,
1908 .maxlen = sizeof(unsigned int),
1909 .mode = 0644,
1910 .proc_handler = proc_dointvec_minmax,
1911 .extra1 = &one,
1912 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001913 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914};
1915
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001916static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001917#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001918 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001919 .procname = "exception-trace",
1920 .data = &show_unhandled_signals,
1921 .maxlen = sizeof(int),
1922 .mode = 0644,
1923 .proc_handler = proc_dointvec
1924 },
1925#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001926#if defined(CONFIG_OPTPROBES)
1927 {
1928 .procname = "kprobes-optimization",
1929 .data = &sysctl_kprobes_optimization,
1930 .maxlen = sizeof(int),
1931 .mode = 0644,
1932 .proc_handler = proc_kprobes_optimization_handler,
1933 .extra1 = &zero,
1934 .extra2 = &one,
1935 },
1936#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001937 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938};
1939
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001940static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001941 { }
Robert Love0eeca282005-07-12 17:06:03 -04001942};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001944int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001945{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001946 struct ctl_table_header *hdr;
1947
1948 hdr = register_sysctl_table(sysctl_base_table);
1949 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001950 return 0;
1951}
1952
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001953#endif /* CONFIG_SYSCTL */
1954
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955/*
1956 * /proc/sys support
1957 */
1958
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001959#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Kees Cookf8808302014-06-06 14:37:17 -07001961static int _proc_do_string(char *data, int maxlen, int write,
1962 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001963 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001964{
1965 size_t len;
1966 char __user *p;
1967 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001968
1969 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001970 *lenp = 0;
1971 return 0;
1972 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001973
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001974 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001975 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1976 /* Only continue writes not past the end of buffer. */
1977 len = strlen(data);
1978 if (len > maxlen - 1)
1979 len = maxlen - 1;
1980
1981 if (*ppos > len)
1982 return 0;
1983 len = *ppos;
1984 } else {
1985 /* Start writing from beginning of buffer. */
1986 len = 0;
1987 }
1988
Kees Cook2ca9bb42014-06-06 14:37:18 -07001989 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001990 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001991 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001992 if (get_user(c, p++))
1993 return -EFAULT;
1994 if (c == 0 || c == '\n')
1995 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001996 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001997 }
Kees Cookf8808302014-06-06 14:37:17 -07001998 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001999 } else {
2000 len = strlen(data);
2001 if (len > maxlen)
2002 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002003
2004 if (*ppos > len) {
2005 *lenp = 0;
2006 return 0;
2007 }
2008
2009 data += *ppos;
2010 len -= *ppos;
2011
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002012 if (len > *lenp)
2013 len = *lenp;
2014 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002015 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002016 return -EFAULT;
2017 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002018 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002019 return -EFAULT;
2020 len++;
2021 }
2022 *lenp = len;
2023 *ppos += len;
2024 }
2025 return 0;
2026}
2027
Kees Cookf4aacea2014-06-06 14:37:19 -07002028static void warn_sysctl_write(struct ctl_table *table)
2029{
2030 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2031 "This will not be supported in the future. To silence this\n"
2032 "warning, set kernel.sysctl_writes_strict = -1\n",
2033 current->comm, table->procname);
2034}
2035
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036/**
2037 * proc_dostring - read a string sysctl
2038 * @table: the sysctl table
2039 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 * @buffer: the user buffer
2041 * @lenp: the size of the user buffer
2042 * @ppos: file position
2043 *
2044 * Reads/writes a string from/to the user buffer. If the kernel
2045 * buffer provided is not large enough to hold the string, the
2046 * string is truncated. The copied string is %NULL-terminated.
2047 * If the string is being read by the user process, it is copied
2048 * and a newline '\n' is added. It is truncated if the buffer is
2049 * not large enough.
2050 *
2051 * Returns 0 on success.
2052 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002053int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 void __user *buffer, size_t *lenp, loff_t *ppos)
2055{
Kees Cookf4aacea2014-06-06 14:37:19 -07002056 if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
2057 warn_sysctl_write(table);
2058
Kees Cookf8808302014-06-06 14:37:17 -07002059 return _proc_do_string((char *)(table->data), table->maxlen, write,
2060 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061}
2062
Amerigo Wang00b7c332010-05-05 00:26:45 +00002063static size_t proc_skip_spaces(char **buf)
2064{
2065 size_t ret;
2066 char *tmp = skip_spaces(*buf);
2067 ret = tmp - *buf;
2068 *buf = tmp;
2069 return ret;
2070}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002072static void proc_skip_char(char **buf, size_t *size, const char v)
2073{
2074 while (*size) {
2075 if (**buf != v)
2076 break;
2077 (*size)--;
2078 (*buf)++;
2079 }
2080}
2081
Amerigo Wang00b7c332010-05-05 00:26:45 +00002082#define TMPBUFLEN 22
2083/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002084 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002085 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002086 * @buf: a kernel buffer
2087 * @size: size of the kernel buffer
2088 * @val: this is where the number will be stored
2089 * @neg: set to %TRUE if number is negative
2090 * @perm_tr: a vector which contains the allowed trailers
2091 * @perm_tr_len: size of the perm_tr vector
2092 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002093 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002094 * In case of success %0 is returned and @buf and @size are updated with
2095 * the amount of bytes read. If @tr is non-NULL and a trailing
2096 * character exists (size is non-zero after returning from this
2097 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002098 */
2099static int proc_get_long(char **buf, size_t *size,
2100 unsigned long *val, bool *neg,
2101 const char *perm_tr, unsigned perm_tr_len, char *tr)
2102{
2103 int len;
2104 char *p, tmp[TMPBUFLEN];
2105
2106 if (!*size)
2107 return -EINVAL;
2108
2109 len = *size;
2110 if (len > TMPBUFLEN - 1)
2111 len = TMPBUFLEN - 1;
2112
2113 memcpy(tmp, *buf, len);
2114
2115 tmp[len] = 0;
2116 p = tmp;
2117 if (*p == '-' && *size > 1) {
2118 *neg = true;
2119 p++;
2120 } else
2121 *neg = false;
2122 if (!isdigit(*p))
2123 return -EINVAL;
2124
2125 *val = simple_strtoul(p, &p, 0);
2126
2127 len = p - tmp;
2128
2129 /* We don't know if the next char is whitespace thus we may accept
2130 * invalid integers (e.g. 1234...a) or two integers instead of one
2131 * (e.g. 123...1). So lets not allow such large numbers. */
2132 if (len == TMPBUFLEN - 1)
2133 return -EINVAL;
2134
2135 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2136 return -EINVAL;
2137
2138 if (tr && (len < *size))
2139 *tr = *p;
2140
2141 *buf += len;
2142 *size -= len;
2143
2144 return 0;
2145}
2146
2147/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002148 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002149 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002150 * @buf: the user buffer
2151 * @size: the size of the user buffer
2152 * @val: the integer to be converted
2153 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002154 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002155 * In case of success %0 is returned and @buf and @size are updated with
2156 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002157 */
2158static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2159 bool neg)
2160{
2161 int len;
2162 char tmp[TMPBUFLEN], *p = tmp;
2163
2164 sprintf(p, "%s%lu", neg ? "-" : "", val);
2165 len = strlen(tmp);
2166 if (len > *size)
2167 len = *size;
2168 if (copy_to_user(*buf, tmp, len))
2169 return -EFAULT;
2170 *size -= len;
2171 *buf += len;
2172 return 0;
2173}
2174#undef TMPBUFLEN
2175
2176static int proc_put_char(void __user **buf, size_t *size, char c)
2177{
2178 if (*size) {
2179 char __user **buffer = (char __user **)buf;
2180 if (put_user(c, *buffer))
2181 return -EFAULT;
2182 (*size)--, (*buffer)++;
2183 *buf = *buffer;
2184 }
2185 return 0;
2186}
2187
2188static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 int *valp,
2190 int write, void *data)
2191{
2192 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002193 if (*negp) {
2194 if (*lvalp > (unsigned long) INT_MAX + 1)
2195 return -EINVAL;
2196 *valp = -*lvalp;
2197 } else {
2198 if (*lvalp > (unsigned long) INT_MAX)
2199 return -EINVAL;
2200 *valp = *lvalp;
2201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 } else {
2203 int val = *valp;
2204 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002205 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002206 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002208 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 *lvalp = (unsigned long)val;
2210 }
2211 }
2212 return 0;
2213}
2214
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002215static int do_proc_douintvec_conv(bool *negp, unsigned long *lvalp,
2216 int *valp,
2217 int write, void *data)
2218{
2219 if (write) {
2220 if (*negp)
2221 return -EINVAL;
Liping Zhang7bdacd32017-04-07 23:51:07 +08002222 if (*lvalp > UINT_MAX)
2223 return -EINVAL;
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002224 *valp = *lvalp;
2225 } else {
2226 unsigned int val = *valp;
Liping Zhang3a20c572017-04-07 23:51:06 +08002227 *negp = false;
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002228 *lvalp = (unsigned long)val;
2229 }
2230 return 0;
2231}
2232
Amerigo Wang00b7c332010-05-05 00:26:45 +00002233static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2234
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002235static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002236 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002237 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002238 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 int write, void *data),
2240 void *data)
2241{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002242 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002243 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002244 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Amerigo Wang00b7c332010-05-05 00:26:45 +00002246 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 *lenp = 0;
2248 return 0;
2249 }
2250
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002251 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 vleft = table->maxlen / sizeof(*i);
2253 left = *lenp;
2254
2255 if (!conv)
2256 conv = do_proc_dointvec_conv;
2257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002259 if (*ppos) {
2260 switch (sysctl_writes_strict) {
2261 case SYSCTL_WRITES_STRICT:
2262 goto out;
2263 case SYSCTL_WRITES_WARN:
2264 warn_sysctl_write(table);
2265 break;
2266 default:
2267 break;
2268 }
2269 }
2270
Amerigo Wang00b7c332010-05-05 00:26:45 +00002271 if (left > PAGE_SIZE - 1)
2272 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002273 p = kbuf = memdup_user_nul(buffer, left);
2274 if (IS_ERR(kbuf))
2275 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002276 }
2277
2278 for (; left && vleft--; i++, first=0) {
2279 unsigned long lval;
2280 bool neg;
2281
2282 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002283 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002284
J. R. Okajima563b0462010-05-25 16:10:14 -07002285 if (!left)
2286 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002287 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002288 proc_wspace_sep,
2289 sizeof(proc_wspace_sep), NULL);
2290 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002292 if (conv(&neg, &lval, i, 1, data)) {
2293 err = -EINVAL;
2294 break;
2295 }
2296 } else {
2297 if (conv(&neg, &lval, i, 0, data)) {
2298 err = -EINVAL;
2299 break;
2300 }
2301 if (!first)
2302 err = proc_put_char(&buffer, &left, '\t');
2303 if (err)
2304 break;
2305 err = proc_put_long(&buffer, &left, lval, neg);
2306 if (err)
2307 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 }
2309 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002310
2311 if (!write && !first && left && !err)
2312 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002313 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002314 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002315 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002316 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002317 if (first)
2318 return err ? : -EINVAL;
2319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002321out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002323 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324}
2325
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002326static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002327 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002328 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002329 int write, void *data),
2330 void *data)
2331{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002332 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002333 buffer, lenp, ppos, conv, data);
2334}
2335
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336/**
2337 * proc_dointvec - read a vector of integers
2338 * @table: the sysctl table
2339 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 * @buffer: the user buffer
2341 * @lenp: the size of the user buffer
2342 * @ppos: file position
2343 *
2344 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2345 * values from/to the user buffer, treated as an ASCII string.
2346 *
2347 * Returns 0 on success.
2348 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002349int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 void __user *buffer, size_t *lenp, loff_t *ppos)
2351{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002352 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2353}
2354
2355/**
2356 * proc_douintvec - read a vector of unsigned integers
2357 * @table: the sysctl table
2358 * @write: %TRUE if this is a write to the sysctl file
2359 * @buffer: the user buffer
2360 * @lenp: the size of the user buffer
2361 * @ppos: file position
2362 *
2363 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2364 * values from/to the user buffer, treated as an ASCII string.
2365 *
2366 * Returns 0 on success.
2367 */
2368int proc_douintvec(struct ctl_table *table, int write,
2369 void __user *buffer, size_t *lenp, loff_t *ppos)
2370{
2371 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2372 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373}
2374
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002375/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002376 * Taint values can only be increased
2377 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002378 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002379static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002380 void __user *buffer, size_t *lenp, loff_t *ppos)
2381{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002382 struct ctl_table t;
2383 unsigned long tmptaint = get_taint();
2384 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002385
Bastian Blank91fcd412007-04-23 14:41:14 -07002386 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002387 return -EPERM;
2388
Andi Kleen25ddbb12008-10-15 22:01:41 -07002389 t = *table;
2390 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002391 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002392 if (err < 0)
2393 return err;
2394
2395 if (write) {
2396 /*
2397 * Poor man's atomic or. Not worth adding a primitive
2398 * to everyone's atomic.h for this
2399 */
2400 int i;
2401 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2402 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302403 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002404 }
2405 }
2406
2407 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002408}
2409
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002410#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002411static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002412 void __user *buffer, size_t *lenp, loff_t *ppos)
2413{
2414 if (write && !capable(CAP_SYS_ADMIN))
2415 return -EPERM;
2416
2417 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2418}
2419#endif
2420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421struct do_proc_dointvec_minmax_conv_param {
2422 int *min;
2423 int *max;
2424};
2425
Amerigo Wang00b7c332010-05-05 00:26:45 +00002426static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2427 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 int write, void *data)
2429{
2430 struct do_proc_dointvec_minmax_conv_param *param = data;
2431 if (write) {
2432 int val = *negp ? -*lvalp : *lvalp;
2433 if ((param->min && *param->min > val) ||
2434 (param->max && *param->max < val))
2435 return -EINVAL;
2436 *valp = val;
2437 } else {
2438 int val = *valp;
2439 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002440 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002441 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002443 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 *lvalp = (unsigned long)val;
2445 }
2446 }
2447 return 0;
2448}
2449
2450/**
2451 * proc_dointvec_minmax - read a vector of integers with min/max values
2452 * @table: the sysctl table
2453 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 * @buffer: the user buffer
2455 * @lenp: the size of the user buffer
2456 * @ppos: file position
2457 *
2458 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2459 * values from/to the user buffer, treated as an ASCII string.
2460 *
2461 * This routine will ensure the values are within the range specified by
2462 * table->extra1 (min) and table->extra2 (max).
2463 *
2464 * Returns 0 on success.
2465 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002466int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 void __user *buffer, size_t *lenp, loff_t *ppos)
2468{
2469 struct do_proc_dointvec_minmax_conv_param param = {
2470 .min = (int *) table->extra1,
2471 .max = (int *) table->extra2,
2472 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002473 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 do_proc_dointvec_minmax_conv, &param);
2475}
2476
Kees Cook54b50192012-07-30 14:39:18 -07002477static void validate_coredump_safety(void)
2478{
Alex Kelly046d6622012-10-04 17:15:23 -07002479#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002480 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002481 core_pattern[0] != '/' && core_pattern[0] != '|') {
2482 printk(KERN_WARNING "Unsafe core_pattern used with "\
2483 "suid_dumpable=2. Pipe handler or fully qualified "\
2484 "core dump path required.\n");
2485 }
Alex Kelly046d6622012-10-04 17:15:23 -07002486#endif
Kees Cook54b50192012-07-30 14:39:18 -07002487}
2488
2489static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2490 void __user *buffer, size_t *lenp, loff_t *ppos)
2491{
2492 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2493 if (!error)
2494 validate_coredump_safety();
2495 return error;
2496}
2497
Alex Kelly046d6622012-10-04 17:15:23 -07002498#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002499static int proc_dostring_coredump(struct ctl_table *table, int write,
2500 void __user *buffer, size_t *lenp, loff_t *ppos)
2501{
2502 int error = proc_dostring(table, write, buffer, lenp, ppos);
2503 if (!error)
2504 validate_coredump_safety();
2505 return error;
2506}
Alex Kelly046d6622012-10-04 17:15:23 -07002507#endif
Kees Cook54b50192012-07-30 14:39:18 -07002508
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002509static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 void __user *buffer,
2511 size_t *lenp, loff_t *ppos,
2512 unsigned long convmul,
2513 unsigned long convdiv)
2514{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002515 unsigned long *i, *min, *max;
2516 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002517 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002518 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002519
2520 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 *lenp = 0;
2522 return 0;
2523 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002524
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002525 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 min = (unsigned long *) table->extra1;
2527 max = (unsigned long *) table->extra2;
2528 vleft = table->maxlen / sizeof(unsigned long);
2529 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002530
2531 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002532 if (*ppos) {
2533 switch (sysctl_writes_strict) {
2534 case SYSCTL_WRITES_STRICT:
2535 goto out;
2536 case SYSCTL_WRITES_WARN:
2537 warn_sysctl_write(table);
2538 break;
2539 default:
2540 break;
2541 }
2542 }
2543
Amerigo Wang00b7c332010-05-05 00:26:45 +00002544 if (left > PAGE_SIZE - 1)
2545 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002546 p = kbuf = memdup_user_nul(buffer, left);
2547 if (IS_ERR(kbuf))
2548 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002549 }
2550
Eric Dumazet27b3d802010-10-07 12:59:29 -07002551 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002552 unsigned long val;
2553
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002555 bool neg;
2556
Al Viro70f6cbb2015-12-24 00:13:10 -05002557 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002558
Al Viro70f6cbb2015-12-24 00:13:10 -05002559 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002560 proc_wspace_sep,
2561 sizeof(proc_wspace_sep), NULL);
2562 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 break;
2564 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 continue;
Eric Dumazet03707d62017-01-25 18:20:55 -08002566 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 if ((min && val < *min) || (max && val > *max))
2568 continue;
2569 *i = val;
2570 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002571 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002572 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002573 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002574 if (err)
2575 break;
2576 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002577 err = proc_put_long(&buffer, &left, val, false);
2578 if (err)
2579 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 }
2581 }
2582
Amerigo Wang00b7c332010-05-05 00:26:45 +00002583 if (!write && !first && left && !err)
2584 err = proc_put_char(&buffer, &left, '\n');
2585 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002586 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002588 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002589 if (first)
2590 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002593out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002595 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596}
2597
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002598static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002599 void __user *buffer,
2600 size_t *lenp, loff_t *ppos,
2601 unsigned long convmul,
2602 unsigned long convdiv)
2603{
2604 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002605 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002606}
2607
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608/**
2609 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2610 * @table: the sysctl table
2611 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 * @buffer: the user buffer
2613 * @lenp: the size of the user buffer
2614 * @ppos: file position
2615 *
2616 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2617 * values from/to the user buffer, treated as an ASCII string.
2618 *
2619 * This routine will ensure the values are within the range specified by
2620 * table->extra1 (min) and table->extra2 (max).
2621 *
2622 * Returns 0 on success.
2623 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002624int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 void __user *buffer, size_t *lenp, loff_t *ppos)
2626{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002627 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628}
2629
2630/**
2631 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2632 * @table: the sysctl table
2633 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 * @buffer: the user buffer
2635 * @lenp: the size of the user buffer
2636 * @ppos: file position
2637 *
2638 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2639 * values from/to the user buffer, treated as an ASCII string. The values
2640 * are treated as milliseconds, and converted to jiffies when they are stored.
2641 *
2642 * This routine will ensure the values are within the range specified by
2643 * table->extra1 (min) and table->extra2 (max).
2644 *
2645 * Returns 0 on success.
2646 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002647int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 void __user *buffer,
2649 size_t *lenp, loff_t *ppos)
2650{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002651 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 lenp, ppos, HZ, 1000l);
2653}
2654
2655
Amerigo Wang00b7c332010-05-05 00:26:45 +00002656static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 int *valp,
2658 int write, void *data)
2659{
2660 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002661 if (*lvalp > LONG_MAX / HZ)
2662 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2664 } else {
2665 int val = *valp;
2666 unsigned long lval;
2667 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002668 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002669 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002671 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 lval = (unsigned long)val;
2673 }
2674 *lvalp = lval / HZ;
2675 }
2676 return 0;
2677}
2678
Amerigo Wang00b7c332010-05-05 00:26:45 +00002679static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 int *valp,
2681 int write, void *data)
2682{
2683 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002684 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2685 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2687 } else {
2688 int val = *valp;
2689 unsigned long lval;
2690 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002691 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002692 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002694 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 lval = (unsigned long)val;
2696 }
2697 *lvalp = jiffies_to_clock_t(lval);
2698 }
2699 return 0;
2700}
2701
Amerigo Wang00b7c332010-05-05 00:26:45 +00002702static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 int *valp,
2704 int write, void *data)
2705{
2706 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002707 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2708
2709 if (jif > INT_MAX)
2710 return 1;
2711 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 } else {
2713 int val = *valp;
2714 unsigned long lval;
2715 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002716 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002717 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002719 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 lval = (unsigned long)val;
2721 }
2722 *lvalp = jiffies_to_msecs(lval);
2723 }
2724 return 0;
2725}
2726
2727/**
2728 * proc_dointvec_jiffies - read a vector of integers as seconds
2729 * @table: the sysctl table
2730 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 * @buffer: the user buffer
2732 * @lenp: the size of the user buffer
2733 * @ppos: file position
2734 *
2735 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2736 * values from/to the user buffer, treated as an ASCII string.
2737 * The values read are assumed to be in seconds, and are converted into
2738 * jiffies.
2739 *
2740 * Returns 0 on success.
2741 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002742int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 void __user *buffer, size_t *lenp, loff_t *ppos)
2744{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002745 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 do_proc_dointvec_jiffies_conv,NULL);
2747}
2748
2749/**
2750 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2751 * @table: the sysctl table
2752 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 * @buffer: the user buffer
2754 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002755 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 *
2757 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2758 * values from/to the user buffer, treated as an ASCII string.
2759 * The values read are assumed to be in 1/USER_HZ seconds, and
2760 * are converted into jiffies.
2761 *
2762 * Returns 0 on success.
2763 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002764int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 void __user *buffer, size_t *lenp, loff_t *ppos)
2766{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002767 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 do_proc_dointvec_userhz_jiffies_conv,NULL);
2769}
2770
2771/**
2772 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2773 * @table: the sysctl table
2774 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 * @buffer: the user buffer
2776 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002777 * @ppos: file position
2778 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 *
2780 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2781 * values from/to the user buffer, treated as an ASCII string.
2782 * The values read are assumed to be in 1/1000 seconds, and
2783 * are converted into jiffies.
2784 *
2785 * Returns 0 on success.
2786 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002787int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 void __user *buffer, size_t *lenp, loff_t *ppos)
2789{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002790 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 do_proc_dointvec_ms_jiffies_conv, NULL);
2792}
2793
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002794static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002795 void __user *buffer, size_t *lenp, loff_t *ppos)
2796{
2797 struct pid *new_pid;
2798 pid_t tmp;
2799 int r;
2800
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002801 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002802
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002803 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002804 lenp, ppos, NULL, NULL);
2805 if (r || !write)
2806 return r;
2807
2808 new_pid = find_get_pid(tmp);
2809 if (!new_pid)
2810 return -ESRCH;
2811
2812 put_pid(xchg(&cad_pid, new_pid));
2813 return 0;
2814}
2815
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002816/**
2817 * proc_do_large_bitmap - read/write from/to a large bitmap
2818 * @table: the sysctl table
2819 * @write: %TRUE if this is a write to the sysctl file
2820 * @buffer: the user buffer
2821 * @lenp: the size of the user buffer
2822 * @ppos: file position
2823 *
2824 * The bitmap is stored at table->data and the bitmap length (in bits)
2825 * in table->maxlen.
2826 *
2827 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2828 * large bitmaps may be represented in a compact manner. Writing into
2829 * the file will clear the bitmap then update it with the given input.
2830 *
2831 * Returns 0 on success.
2832 */
2833int proc_do_large_bitmap(struct ctl_table *table, int write,
2834 void __user *buffer, size_t *lenp, loff_t *ppos)
2835{
2836 int err = 0;
2837 bool first = 1;
2838 size_t left = *lenp;
2839 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07002840 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002841 unsigned long *tmp_bitmap = NULL;
2842 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2843
WANG Cong122ff242014-05-12 16:04:53 -07002844 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002845 *lenp = 0;
2846 return 0;
2847 }
2848
2849 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002850 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002851
2852 if (left > PAGE_SIZE - 1)
2853 left = PAGE_SIZE - 1;
2854
Al Viro70f6cbb2015-12-24 00:13:10 -05002855 p = kbuf = memdup_user_nul(buffer, left);
2856 if (IS_ERR(kbuf))
2857 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002858
2859 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2860 GFP_KERNEL);
2861 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002862 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002863 return -ENOMEM;
2864 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002865 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002866 while (!err && left) {
2867 unsigned long val_a, val_b;
2868 bool neg;
2869
Al Viro70f6cbb2015-12-24 00:13:10 -05002870 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002871 sizeof(tr_a), &c);
2872 if (err)
2873 break;
2874 if (val_a >= bitmap_len || neg) {
2875 err = -EINVAL;
2876 break;
2877 }
2878
2879 val_b = val_a;
2880 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002881 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002882 left--;
2883 }
2884
2885 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05002886 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002887 &neg, tr_b, sizeof(tr_b),
2888 &c);
2889 if (err)
2890 break;
2891 if (val_b >= bitmap_len || neg ||
2892 val_a > val_b) {
2893 err = -EINVAL;
2894 break;
2895 }
2896 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002897 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002898 left--;
2899 }
2900 }
2901
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002902 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002903 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05002904 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002905 }
Al Viro70f6cbb2015-12-24 00:13:10 -05002906 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002907 } else {
2908 unsigned long bit_a, bit_b = 0;
2909
2910 while (left) {
2911 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2912 if (bit_a >= bitmap_len)
2913 break;
2914 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2915 bit_a + 1) - 1;
2916
2917 if (!first) {
2918 err = proc_put_char(&buffer, &left, ',');
2919 if (err)
2920 break;
2921 }
2922 err = proc_put_long(&buffer, &left, bit_a, false);
2923 if (err)
2924 break;
2925 if (bit_a != bit_b) {
2926 err = proc_put_char(&buffer, &left, '-');
2927 if (err)
2928 break;
2929 err = proc_put_long(&buffer, &left, bit_b, false);
2930 if (err)
2931 break;
2932 }
2933
2934 first = 0; bit_b++;
2935 }
2936 if (!err)
2937 err = proc_put_char(&buffer, &left, '\n');
2938 }
2939
2940 if (!err) {
2941 if (write) {
2942 if (*ppos)
2943 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2944 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07002945 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002946 }
2947 kfree(tmp_bitmap);
2948 *lenp -= left;
2949 *ppos += *lenp;
2950 return 0;
2951 } else {
2952 kfree(tmp_bitmap);
2953 return err;
2954 }
2955}
2956
Jovi Zhang55610502011-01-12 17:00:45 -08002957#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002959int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 void __user *buffer, size_t *lenp, loff_t *ppos)
2961{
2962 return -ENOSYS;
2963}
2964
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002965int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 void __user *buffer, size_t *lenp, loff_t *ppos)
2967{
2968 return -ENOSYS;
2969}
2970
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002971int proc_douintvec(struct ctl_table *table, int write,
2972 void __user *buffer, size_t *lenp, loff_t *ppos)
2973{
2974 return -ENOSYS;
2975}
2976
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002977int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 void __user *buffer, size_t *lenp, loff_t *ppos)
2979{
2980 return -ENOSYS;
2981}
2982
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002983int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 void __user *buffer, size_t *lenp, loff_t *ppos)
2985{
2986 return -ENOSYS;
2987}
2988
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002989int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 void __user *buffer, size_t *lenp, loff_t *ppos)
2991{
2992 return -ENOSYS;
2993}
2994
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002995int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 void __user *buffer, size_t *lenp, loff_t *ppos)
2997{
2998 return -ENOSYS;
2999}
3000
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003001int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 void __user *buffer, size_t *lenp, loff_t *ppos)
3003{
3004 return -ENOSYS;
3005}
3006
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003007int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 void __user *buffer,
3009 size_t *lenp, loff_t *ppos)
3010{
3011 return -ENOSYS;
3012}
3013
3014
Jovi Zhang55610502011-01-12 17:00:45 -08003015#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017/*
3018 * No sense putting this after each symbol definition, twice,
3019 * exception granted :-)
3020 */
3021EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003022EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023EXPORT_SYMBOL(proc_dointvec_jiffies);
3024EXPORT_SYMBOL(proc_dointvec_minmax);
3025EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3026EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3027EXPORT_SYMBOL(proc_dostring);
3028EXPORT_SYMBOL(proc_doulongvec_minmax);
3029EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);