blob: f21375aa6cf65d35998c54b10fe0ac498f301f8d [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>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010065#include <linux/sched/coredump.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>
Joe Lawrence7a8d1812017-11-17 15:29:24 -080069#include <linux/pipe_fs_i.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080071#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <asm/processor.h>
73
Andi Kleen29cbc782006-09-30 01:47:55 +020074#ifdef CONFIG_X86
75#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010076#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010077#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020078#endif
David Howellsd550bbd2012-03-28 18:30:03 +010079#ifdef CONFIG_SPARC
80#include <asm/setup.h>
81#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080082#ifdef CONFIG_BSD_PROCESS_ACCT
83#include <linux/acct.h>
84#endif
Dave Young4f0e0562010-03-10 15:24:09 -080085#ifdef CONFIG_RT_MUTEXES
86#include <linux/rtmutex.h>
87#endif
Dave Young2edf5e42010-03-10 15:24:10 -080088#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89#include <linux/lockdep.h>
90#endif
Dave Young15485a42010-03-10 15:24:07 -080091#ifdef CONFIG_CHR_DEV_SG
92#include <scsi/sg.h>
93#endif
Andi Kleen29cbc782006-09-30 01:47:55 +020094
Don Zickus58687ac2010-05-07 17:11:44 -040095#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050096#include <linux/nmi.h>
97#endif
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#if defined(CONFIG_SYSCTL)
100
101/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700102extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700103#ifdef CONFIG_COREDUMP
104extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700106extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700107#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800110extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100111extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300112extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000113#ifndef CONFIG_MMU
114extern int sysctl_nr_trim_pages;
115#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700117/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400118#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700119static int sixty = 60;
120#endif
121
Aaron Tomlin270750db2014-01-20 17:34:13 +0000122static int __maybe_unused neg_one = -1;
123
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700125static int __maybe_unused one = 1;
126static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700127static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800128static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700130static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700131#ifdef CONFIG_PRINTK
132static int ten_thousand = 10000;
133#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300134#ifdef CONFIG_PERF_EVENTS
135static int six_hundred_forty_kb = 640 * 1024;
136#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700137
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700138/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
139static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
142static int maxolduid = 65535;
143static int minolduid;
144
145static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700146static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Liu Hua80df2842014-04-07 15:38:57 -0700148/*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
149#ifdef CONFIG_DETECT_HUNG_TASK
150static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
151#endif
152
Dave Youngd14f1722010-02-25 20:28:57 -0500153#ifdef CONFIG_INOTIFY_USER
154#include <linux/inotify.h>
155#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700156#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#endif
158
159#ifdef __hppa__
160extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530161#endif
162
163#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164extern int unaligned_enabled;
165#endif
166
Jes Sorensend2b176e2006-02-28 09:42:23 -0800167#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800168extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800169#endif
170
Vineet Guptab6fca722013-01-09 20:06:28 +0530171#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
172extern int no_unaligned_warning;
173#endif
174
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700175#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700176
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700177/**
178 * enum sysctl_writes_mode - supported sysctl write modes
179 *
180 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
181 * to be written, and multiple writes on the same sysctl file descriptor
182 * will rewrite the sysctl value, regardless of file position. No warning
183 * is issued when the initial position is not 0.
184 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
185 * not 0.
186 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
187 * file position 0 and the value must be fully contained in the buffer
188 * sent to the write syscall. If dealing with strings respect the file
189 * position, but restrict this to the max length of the buffer, anything
190 * passed the max lenght will be ignored. Multiple writes will append
191 * to the buffer.
192 *
193 * These write modes control how current file position affects the behavior of
194 * updating sysctl values through the proc interface on each write.
195 */
196enum sysctl_writes_mode {
197 SYSCTL_WRITES_LEGACY = -1,
198 SYSCTL_WRITES_WARN = 0,
199 SYSCTL_WRITES_STRICT = 1,
200};
Kees Cookf4aacea2014-06-06 14:37:19 -0700201
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700202static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700203
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700204static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700205 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700206static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800207 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700208#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700209
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700210#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700211static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700212 void __user *buffer, size_t *lenp, loff_t *ppos);
213#endif
214
Kees Cook54b50192012-07-30 14:39:18 -0700215static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
216 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700217#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700218static int proc_dostring_coredump(struct ctl_table *table, int write,
219 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700220#endif
Kees Cook54b50192012-07-30 14:39:18 -0700221
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700222#ifdef CONFIG_MAGIC_SYSRQ
Andy Whitcroft8c6a98b2011-01-24 09:31:38 -0800223/* Note: sysrq code uses it's own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100224static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700225
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700226static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700227 void __user *buffer, size_t *lenp,
228 loff_t *ppos)
229{
230 int error;
231
232 error = proc_dointvec(table, write, buffer, lenp, ppos);
233 if (error)
234 return error;
235
236 if (write)
237 sysrq_toggle_support(__sysrq_enabled);
238
239 return 0;
240}
241
242#endif
243
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700244static struct ctl_table kern_table[];
245static struct ctl_table vm_table[];
246static struct ctl_table fs_table[];
247static struct ctl_table debug_table[];
248static struct ctl_table dev_table[];
249extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800250#ifdef CONFIG_EPOLL
251extern struct ctl_table epoll_table[];
252#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
255int sysctl_legacy_va_layout;
256#endif
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/* The default sysctl tables: */
259
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800260static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 .procname = "kernel",
263 .mode = 0555,
264 .child = kern_table,
265 },
266 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 .procname = "vm",
268 .mode = 0555,
269 .child = vm_table,
270 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 .procname = "fs",
273 .mode = 0555,
274 .child = fs_table,
275 },
276 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .procname = "debug",
278 .mode = 0555,
279 .child = debug_table,
280 },
281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .procname = "dev",
283 .mode = 0555,
284 .child = dev_table,
285 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700286 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287};
288
Ingo Molnar77e54a12007-07-09 18:52:00 +0200289#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100290static int min_sched_granularity_ns = 100000; /* 100 usecs */
291static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
292static int min_wakeup_granularity_ns; /* 0 usecs */
293static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200294#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100295static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
296static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200297#endif /* CONFIG_SMP */
298#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299
Mel Gorman5e771902010-05-24 14:32:31 -0700300#ifdef CONFIG_COMPACTION
301static int min_extfrag_threshold;
302static int max_extfrag_threshold = 1000;
303#endif
304
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700305static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200306 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200307 .procname = "sched_child_runs_first",
308 .data = &sysctl_sched_child_runs_first,
309 .maxlen = sizeof(unsigned int),
310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800311 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200312 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200313#ifdef CONFIG_SCHED_DEBUG
314 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100315 .procname = "sched_min_granularity_ns",
316 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200317 .maxlen = sizeof(unsigned int),
318 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800319 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100320 .extra1 = &min_sched_granularity_ns,
321 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200322 },
323 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200324 .procname = "sched_latency_ns",
325 .data = &sysctl_sched_latency,
326 .maxlen = sizeof(unsigned int),
327 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800328 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200329 .extra1 = &min_sched_granularity_ns,
330 .extra2 = &max_sched_granularity_ns,
331 },
332 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200333 .procname = "sched_wakeup_granularity_ns",
334 .data = &sysctl_sched_wakeup_granularity,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800337 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200338 .extra1 = &min_wakeup_granularity_ns,
339 .extra2 = &max_wakeup_granularity_ns,
340 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200341#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200342 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100343 .procname = "sched_tunable_scaling",
344 .data = &sysctl_sched_tunable_scaling,
345 .maxlen = sizeof(enum sched_tunable_scaling),
346 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800347 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100348 .extra1 = &min_sched_tunable_scaling,
349 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200350 },
351 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900352 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200353 .data = &sysctl_sched_migration_cost,
354 .maxlen = sizeof(unsigned int),
355 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800356 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200357 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100358 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100359 .procname = "sched_nr_migrate",
360 .data = &sysctl_sched_nr_migrate,
361 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800363 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100364 },
Arun R Bharadwajcd1bb942009-04-16 12:15:34 +0530365 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900366 .procname = "sched_time_avg_ms",
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200367 .data = &sysctl_sched_time_avg,
368 .maxlen = sizeof(unsigned int),
369 .mode = 0644,
Ethan Zhao5ccba442017-09-04 13:59:34 +0800370 .proc_handler = proc_dointvec_minmax,
371 .extra1 = &one,
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200372 },
Mel Gormancb251762016-02-05 09:08:36 +0000373#ifdef CONFIG_SCHEDSTATS
374 {
375 .procname = "sched_schedstats",
376 .data = NULL,
377 .maxlen = sizeof(unsigned int),
378 .mode = 0644,
379 .proc_handler = sysctl_schedstats,
380 .extra1 = &zero,
381 .extra2 = &one,
382 },
383#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200384#endif /* CONFIG_SMP */
385#ifdef CONFIG_NUMA_BALANCING
386 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200387 .procname = "numa_balancing_scan_delay_ms",
388 .data = &sysctl_numa_balancing_scan_delay,
389 .maxlen = sizeof(unsigned int),
390 .mode = 0644,
391 .proc_handler = proc_dointvec,
392 },
393 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200394 .procname = "numa_balancing_scan_period_min_ms",
395 .data = &sysctl_numa_balancing_scan_period_min,
396 .maxlen = sizeof(unsigned int),
397 .mode = 0644,
398 .proc_handler = proc_dointvec,
399 },
400 {
401 .procname = "numa_balancing_scan_period_max_ms",
402 .data = &sysctl_numa_balancing_scan_period_max,
403 .maxlen = sizeof(unsigned int),
404 .mode = 0644,
405 .proc_handler = proc_dointvec,
406 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200407 {
408 .procname = "numa_balancing_scan_size_mb",
409 .data = &sysctl_numa_balancing_scan_size,
410 .maxlen = sizeof(unsigned int),
411 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400412 .proc_handler = proc_dointvec_minmax,
413 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200414 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100415 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800416 .procname = "numa_balancing",
417 .data = NULL, /* filled in by handler */
418 .maxlen = sizeof(unsigned int),
419 .mode = 0644,
420 .proc_handler = sysctl_numa_balancing,
421 .extra1 = &zero,
422 .extra2 = &one,
423 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200424#endif /* CONFIG_NUMA_BALANCING */
425#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200426 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100427 .procname = "sched_rt_period_us",
428 .data = &sysctl_sched_rt_period,
429 .maxlen = sizeof(unsigned int),
430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800431 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100432 },
433 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100434 .procname = "sched_rt_runtime_us",
435 .data = &sysctl_sched_rt_runtime,
436 .maxlen = sizeof(int),
437 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800438 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100439 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600440 {
441 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800442 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600443 .maxlen = sizeof(int),
444 .mode = 0644,
445 .proc_handler = sched_rr_handler,
446 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100447#ifdef CONFIG_SCHED_AUTOGROUP
448 {
449 .procname = "sched_autogroup_enabled",
450 .data = &sysctl_sched_autogroup_enabled,
451 .maxlen = sizeof(unsigned int),
452 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800453 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100454 .extra1 = &zero,
455 .extra2 = &one,
456 },
457#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700458#ifdef CONFIG_CFS_BANDWIDTH
459 {
460 .procname = "sched_cfs_bandwidth_slice_us",
461 .data = &sysctl_sched_cfs_bandwidth_slice,
462 .maxlen = sizeof(unsigned int),
463 .mode = 0644,
464 .proc_handler = proc_dointvec_minmax,
465 .extra1 = &one,
466 },
467#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700468#ifdef CONFIG_PROVE_LOCKING
469 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700470 .procname = "prove_locking",
471 .data = &prove_locking,
472 .maxlen = sizeof(int),
473 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800474 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700475 },
476#endif
477#ifdef CONFIG_LOCK_STAT
478 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700479 .procname = "lock_stat",
480 .data = &lock_stat,
481 .maxlen = sizeof(int),
482 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800483 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700484 },
485#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200486 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 .procname = "panic",
488 .data = &panic_timeout,
489 .maxlen = sizeof(int),
490 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800491 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 },
Alex Kelly046d6622012-10-04 17:15:23 -0700493#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 .procname = "core_uses_pid",
496 .data = &core_uses_pid,
497 .maxlen = sizeof(int),
498 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800499 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 },
501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .procname = "core_pattern",
503 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700504 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700506 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 },
Neil Hormana2939802009-09-23 15:56:56 -0700508 {
Neil Hormana2939802009-09-23 15:56:56 -0700509 .procname = "core_pipe_limit",
510 .data = &core_pipe_limit,
511 .maxlen = sizeof(unsigned int),
512 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800513 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700514 },
Alex Kelly046d6622012-10-04 17:15:23 -0700515#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800516#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700519 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800521 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700523 {
524 .procname = "sysctl_writes_strict",
525 .data = &sysctl_writes_strict,
526 .maxlen = sizeof(int),
527 .mode = 0644,
528 .proc_handler = proc_dointvec_minmax,
529 .extra1 = &neg_one,
530 .extra2 = &one,
531 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800532#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100533#ifdef CONFIG_LATENCYTOP
534 {
535 .procname = "latencytop",
536 .data = &latencytop_enabled,
537 .maxlen = sizeof(int),
538 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000539 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100540 },
541#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542#ifdef CONFIG_BLK_DEV_INITRD
543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 .procname = "real-root-dev",
545 .data = &real_root_dev,
546 .maxlen = sizeof(int),
547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800548 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 },
550#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700551 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700552 .procname = "print-fatal-signals",
553 .data = &print_fatal_signals,
554 .maxlen = sizeof(int),
555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800556 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700557 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700558#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 .procname = "reboot-cmd",
561 .data = reboot_command,
562 .maxlen = 256,
563 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800564 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 },
566 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 .procname = "stop-a",
568 .data = &stop_a_enabled,
569 .maxlen = sizeof (int),
570 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800571 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 },
573 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .procname = "scons-poweroff",
575 .data = &scons_pwroff,
576 .maxlen = sizeof (int),
577 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800578 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 },
580#endif
David S. Miller08714202008-11-16 23:49:24 -0800581#ifdef CONFIG_SPARC64
582 {
David S. Miller08714202008-11-16 23:49:24 -0800583 .procname = "tsb-ratio",
584 .data = &sysctl_tsb_ratio,
585 .maxlen = sizeof (int),
586 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800587 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800588 },
589#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590#ifdef __hppa__
591 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .procname = "soft-power",
593 .data = &pwrsw_enabled,
594 .maxlen = sizeof (int),
595 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800596 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530598#endif
599#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .procname = "unaligned-trap",
602 .data = &unaligned_enabled,
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
608 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .procname = "ctrl-alt-del",
610 .data = &C_A_D,
611 .maxlen = sizeof(int),
612 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800613 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400615#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200616 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200617 .procname = "ftrace_enabled",
618 .data = &ftrace_enabled,
619 .maxlen = sizeof(int),
620 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800621 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200622 },
623#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500624#ifdef CONFIG_STACK_TRACER
625 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500626 .procname = "stack_tracer_enabled",
627 .data = &stack_tracer_enabled,
628 .maxlen = sizeof(int),
629 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800630 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500631 },
632#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400633#ifdef CONFIG_TRACING
634 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100635 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400636 .data = &ftrace_dump_on_oops,
637 .maxlen = sizeof(int),
638 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800639 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400640 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400641 {
642 .procname = "traceoff_on_warning",
643 .data = &__disable_trace_on_warning,
644 .maxlen = sizeof(__disable_trace_on_warning),
645 .mode = 0644,
646 .proc_handler = proc_dointvec,
647 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500648 {
649 .procname = "tracepoint_printk",
650 .data = &tracepoint_printk,
651 .maxlen = sizeof(tracepoint_printk),
652 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500653 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500654 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400655#endif
Dave Young2965faa2015-09-09 15:38:55 -0700656#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800657 {
658 .procname = "kexec_load_disabled",
659 .data = &kexec_load_disabled,
660 .maxlen = sizeof(int),
661 .mode = 0644,
662 /* only handle a transition from default "0" to "1" */
663 .proc_handler = proc_dointvec_minmax,
664 .extra1 = &one,
665 .extra2 = &one,
666 },
667#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200668#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 .procname = "modprobe",
671 .data = &modprobe_path,
672 .maxlen = KMOD_PATH_LEN,
673 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800674 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 },
Kees Cook3d433212009-04-02 15:49:29 -0700676 {
Kees Cook3d433212009-04-02 15:49:29 -0700677 .procname = "modules_disabled",
678 .data = &modules_disabled,
679 .maxlen = sizeof(int),
680 .mode = 0644,
681 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800682 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700683 .extra1 = &one,
684 .extra2 = &one,
685 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700687#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100690 .data = &uevent_helper,
691 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800693 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 },
Michael Marineau86d56132014-04-10 14:09:31 -0700695#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696#ifdef CONFIG_CHR_DEV_SG
697 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 .procname = "sg-big-buff",
699 .data = &sg_big_buff,
700 .maxlen = sizeof (int),
701 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800702 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 },
704#endif
705#ifdef CONFIG_BSD_PROCESS_ACCT
706 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 .procname = "acct",
708 .data = &acct_parm,
709 .maxlen = 3*sizeof(int),
710 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800711 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 },
713#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#ifdef CONFIG_MAGIC_SYSRQ
715 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800717 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 .maxlen = sizeof (int),
719 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700720 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 },
722#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700723#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700726 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 .maxlen = sizeof (int),
728 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800729 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700731#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700734 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 .maxlen = sizeof(int),
736 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700737 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 },
739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .procname = "random",
741 .mode = 0555,
742 .child = random_table,
743 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 {
Eric Paris17f60a72011-04-01 17:07:50 -0400745 .procname = "usermodehelper",
746 .mode = 0555,
747 .child = usermodehelper_table,
748 },
749 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .procname = "overflowuid",
751 .data = &overflowuid,
752 .maxlen = sizeof(int),
753 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800754 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .extra1 = &minolduid,
756 .extra2 = &maxolduid,
757 },
758 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 .procname = "overflowgid",
760 .data = &overflowgid,
761 .maxlen = sizeof(int),
762 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800763 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .extra1 = &minolduid,
765 .extra2 = &maxolduid,
766 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800767#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768#ifdef CONFIG_MATHEMU
769 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 .procname = "ieee_emulation_warnings",
771 .data = &sysctl_ieee_emulation_warnings,
772 .maxlen = sizeof(int),
773 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800774 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 },
776#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200779 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 .maxlen = sizeof(int),
781 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800782 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 },
784#endif
785 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 .procname = "pid_max",
787 .data = &pid_max,
788 .maxlen = sizeof (int),
789 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800790 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .extra1 = &pid_max_min,
792 .extra2 = &pid_max_max,
793 },
794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 .procname = "panic_on_oops",
796 .data = &panic_on_oops,
797 .maxlen = sizeof(int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800801#if defined CONFIG_PRINTK
802 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800803 .procname = "printk",
804 .data = &console_loglevel,
805 .maxlen = 4*sizeof(int),
806 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800807 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800808 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700811 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 .maxlen = sizeof(int),
813 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800814 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 },
816 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700818 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 .maxlen = sizeof(int),
820 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800821 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 },
Dave Youngaf913222009-09-22 16:43:33 -0700823 {
Dave Youngaf913222009-09-22 16:43:33 -0700824 .procname = "printk_delay",
825 .data = &printk_delay_msec,
826 .maxlen = sizeof(int),
827 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800828 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700829 .extra1 = &zero,
830 .extra2 = &ten_thousand,
831 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700833 .procname = "printk_devkmsg",
834 .data = devkmsg_log_str,
835 .maxlen = DEVKMSG_STR_MAX_SIZE,
836 .mode = 0644,
837 .proc_handler = devkmsg_sysctl_set_loglvl,
838 },
839 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800840 .procname = "dmesg_restrict",
841 .data = &dmesg_restrict,
842 .maxlen = sizeof(int),
843 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700844 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800845 .extra1 = &zero,
846 .extra2 = &one,
847 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800848 {
849 .procname = "kptr_restrict",
850 .data = &kptr_restrict,
851 .maxlen = sizeof(int),
852 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700853 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800854 .extra1 = &zero,
855 .extra2 = &two,
856 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800857#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800858 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 .procname = "ngroups_max",
860 .data = &ngroups_max,
861 .maxlen = sizeof (int),
862 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800863 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 },
Dan Ballard73efc032011-10-31 17:11:20 -0700865 {
866 .procname = "cap_last_cap",
867 .data = (void *)&cap_last_cap,
868 .maxlen = sizeof(int),
869 .mode = 0444,
870 .proc_handler = proc_dointvec,
871 },
Don Zickus58687ac2010-05-07 17:11:44 -0400872#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500873 {
Don Zickus58687ac2010-05-07 17:11:44 -0400874 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200875 .data = &watchdog_user_enabled,
876 .maxlen = sizeof(int),
877 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700878 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700879 .extra1 = &zero,
880 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400881 },
882 {
883 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700884 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400885 .maxlen = sizeof(int),
886 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700887 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800888 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400889 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500890 },
Don Zickus2508ce12010-05-07 17:11:46 -0400891 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700892 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200893 .data = &nmi_watchdog_user_enabled,
894 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200895 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700896 .proc_handler = proc_nmi_watchdog,
897 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700898 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700899 },
900 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700901 .procname = "watchdog_cpumask",
902 .data = &watchdog_cpumask_bits,
903 .maxlen = NR_CPUS,
904 .mode = 0644,
905 .proc_handler = proc_watchdog_cpumask,
906 },
907#ifdef CONFIG_SOFTLOCKUP_DETECTOR
908 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700909 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200910 .data = &soft_watchdog_user_enabled,
911 .maxlen = sizeof(int),
912 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700913 .proc_handler = proc_soft_watchdog,
914 .extra1 = &zero,
915 .extra2 = &one,
916 },
917 {
Don Zickus2508ce12010-05-07 17:11:46 -0400918 .procname = "softlockup_panic",
919 .data = &softlockup_panic,
920 .maxlen = sizeof(int),
921 .mode = 0644,
922 .proc_handler = proc_dointvec_minmax,
923 .extra1 = &zero,
924 .extra2 = &one,
925 },
Aaron Tomlined235872014-06-23 13:22:05 -0700926#ifdef CONFIG_SMP
927 {
928 .procname = "softlockup_all_cpu_backtrace",
929 .data = &sysctl_softlockup_all_cpu_backtrace,
930 .maxlen = sizeof(int),
931 .mode = 0644,
932 .proc_handler = proc_dointvec_minmax,
933 .extra1 = &zero,
934 .extra2 = &one,
935 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700936#endif /* CONFIG_SMP */
937#endif
938#ifdef CONFIG_HARDLOCKUP_DETECTOR
939 {
940 .procname = "hardlockup_panic",
941 .data = &hardlockup_panic,
942 .maxlen = sizeof(int),
943 .mode = 0644,
944 .proc_handler = proc_dointvec_minmax,
945 .extra1 = &zero,
946 .extra2 = &one,
947 },
948#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800949 {
950 .procname = "hardlockup_all_cpu_backtrace",
951 .data = &sysctl_hardlockup_all_cpu_backtrace,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = proc_dointvec_minmax,
955 .extra1 = &zero,
956 .extra2 = &one,
957 },
Aaron Tomlined235872014-06-23 13:22:05 -0700958#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500959#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700960#endif
961
Don Zickus5dc30552010-11-29 17:07:17 -0500962#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
963 {
964 .procname = "unknown_nmi_panic",
965 .data = &unknown_nmi_panic,
966 .maxlen = sizeof (int),
967 .mode = 0644,
968 .proc_handler = proc_dointvec,
969 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500970#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971#if defined(CONFIG_X86)
972 {
Don Zickus8da5add2006-09-26 10:52:27 +0200973 .procname = "panic_on_unrecovered_nmi",
974 .data = &panic_on_unrecovered_nmi,
975 .maxlen = sizeof(int),
976 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800977 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200978 },
979 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700980 .procname = "panic_on_io_nmi",
981 .data = &panic_on_io_nmi,
982 .maxlen = sizeof(int),
983 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800984 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700985 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900986#ifdef CONFIG_DEBUG_STACKOVERFLOW
987 {
988 .procname = "panic_on_stackoverflow",
989 .data = &sysctl_panic_on_stackoverflow,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = proc_dointvec,
993 },
994#endif
Kurt Garloff5211a242009-06-24 14:32:11 -0700995 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 .procname = "bootloader_type",
997 .data = &bootloader_type,
998 .maxlen = sizeof (int),
999 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001000 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001002 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001003 .procname = "bootloader_version",
1004 .data = &bootloader_version,
1005 .maxlen = sizeof (int),
1006 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001007 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001008 },
1009 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001010 .procname = "io_delay_type",
1011 .data = &io_delay_type,
1012 .maxlen = sizeof(int),
1013 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001014 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001015 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001017#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 .procname = "randomize_va_space",
1020 .data = &randomize_va_space,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001025#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001026#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001027 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001028 .procname = "spin_retry",
1029 .data = &spin_retry,
1030 .maxlen = sizeof (int),
1031 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001033 },
1034#endif
Len Brown673d5b42007-07-28 03:33:16 -04001035#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001036 {
Pavel Machekc255d842006-02-20 18:27:58 -08001037 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001038 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001039 .maxlen = sizeof (unsigned long),
1040 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001042 },
1043#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301044#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001045 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001046 .procname = "ignore-unaligned-usertrap",
1047 .data = &no_unaligned_warning,
1048 .maxlen = sizeof (int),
1049 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001050 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001051 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301052#endif
1053#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001054 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001055 .procname = "unaligned-dump-stack",
1056 .data = &unaligned_dump_stack,
1057 .maxlen = sizeof (int),
1058 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001059 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001060 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001061#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001062#ifdef CONFIG_DETECT_HUNG_TASK
1063 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001064 .procname = "hung_task_panic",
1065 .data = &sysctl_hung_task_panic,
1066 .maxlen = sizeof(int),
1067 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001068 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001069 .extra1 = &zero,
1070 .extra2 = &one,
1071 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001072 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001073 .procname = "hung_task_check_count",
1074 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001075 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001076 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001077 .proc_handler = proc_dointvec_minmax,
1078 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001079 },
1080 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001081 .procname = "hung_task_timeout_secs",
1082 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001083 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001084 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001085 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001086 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001087 },
1088 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001089 .procname = "hung_task_warnings",
1090 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001091 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001092 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001093 .proc_handler = proc_dointvec_minmax,
1094 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001095 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001096#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001097#ifdef CONFIG_RT_MUTEXES
1098 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001099 .procname = "max_lock_depth",
1100 .data = &max_lock_depth,
1101 .maxlen = sizeof(int),
1102 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001103 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001104 },
1105#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001106 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001107 .procname = "poweroff_cmd",
1108 .data = &poweroff_cmd,
1109 .maxlen = POWEROFF_CMD_PATH_LEN,
1110 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001111 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001112 },
David Howells0b77f5b2008-04-29 01:01:32 -07001113#ifdef CONFIG_KEYS
1114 {
David Howells0b77f5b2008-04-29 01:01:32 -07001115 .procname = "keys",
1116 .mode = 0555,
1117 .child = key_sysctls,
1118 },
1119#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001120#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001121 /*
1122 * User-space scripts rely on the existence of this file
1123 * as a feature check for perf_events being enabled.
1124 *
1125 * So it's an ABI, do not remove!
1126 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001127 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001128 .procname = "perf_event_paranoid",
1129 .data = &sysctl_perf_event_paranoid,
1130 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001131 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001132 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001133 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001134 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001135 .procname = "perf_event_mlock_kb",
1136 .data = &sysctl_perf_event_mlock,
1137 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001138 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001139 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001140 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001141 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001142 .procname = "perf_event_max_sample_rate",
1143 .data = &sysctl_perf_event_sample_rate,
1144 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001145 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001146 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001147 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001148 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001149 {
1150 .procname = "perf_cpu_time_max_percent",
1151 .data = &sysctl_perf_cpu_time_max_percent,
1152 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1153 .mode = 0644,
1154 .proc_handler = perf_cpu_time_max_percent_handler,
1155 .extra1 = &zero,
1156 .extra2 = &one_hundred,
1157 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001158 {
1159 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001160 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001161 .maxlen = sizeof(sysctl_perf_event_max_stack),
1162 .mode = 0644,
1163 .proc_handler = perf_event_max_stack_handler,
1164 .extra1 = &zero,
1165 .extra2 = &six_hundred_forty_kb,
1166 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001167 {
1168 .procname = "perf_event_max_contexts_per_stack",
1169 .data = &sysctl_perf_event_max_contexts_per_stack,
1170 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1171 .mode = 0644,
1172 .proc_handler = perf_event_max_stack_handler,
1173 .extra1 = &zero,
1174 .extra2 = &one_thousand,
1175 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001176#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001177 {
1178 .procname = "panic_on_warn",
1179 .data = &panic_on_warn,
1180 .maxlen = sizeof(int),
1181 .mode = 0644,
1182 .proc_handler = proc_dointvec_minmax,
1183 .extra1 = &zero,
1184 .extra2 = &one,
1185 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001186#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1187 {
1188 .procname = "timer_migration",
1189 .data = &sysctl_timer_migration,
1190 .maxlen = sizeof(unsigned int),
1191 .mode = 0644,
1192 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001193 .extra1 = &zero,
1194 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001195 },
1196#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001197#ifdef CONFIG_BPF_SYSCALL
1198 {
1199 .procname = "unprivileged_bpf_disabled",
1200 .data = &sysctl_unprivileged_bpf_disabled,
1201 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1202 .mode = 0644,
1203 /* only handle a transition from default "0" to "1" */
1204 .proc_handler = proc_dointvec_minmax,
1205 .extra1 = &one,
1206 .extra2 = &one,
1207 },
1208#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001209#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1210 {
1211 .procname = "panic_on_rcu_stall",
1212 .data = &sysctl_panic_on_rcu_stall,
1213 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1214 .mode = 0644,
1215 .proc_handler = proc_dointvec_minmax,
1216 .extra1 = &zero,
1217 .extra2 = &one,
1218 },
1219#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001220 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221};
1222
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001223static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 .procname = "overcommit_memory",
1226 .data = &sysctl_overcommit_memory,
1227 .maxlen = sizeof(sysctl_overcommit_memory),
1228 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001229 .proc_handler = proc_dointvec_minmax,
1230 .extra1 = &zero,
1231 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 },
1233 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001234 .procname = "panic_on_oom",
1235 .data = &sysctl_panic_on_oom,
1236 .maxlen = sizeof(sysctl_panic_on_oom),
1237 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001238 .proc_handler = proc_dointvec_minmax,
1239 .extra1 = &zero,
1240 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001241 },
1242 {
David Rientjesfe071d72007-10-16 23:25:56 -07001243 .procname = "oom_kill_allocating_task",
1244 .data = &sysctl_oom_kill_allocating_task,
1245 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1246 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001247 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001248 },
1249 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001250 .procname = "oom_dump_tasks",
1251 .data = &sysctl_oom_dump_tasks,
1252 .maxlen = sizeof(sysctl_oom_dump_tasks),
1253 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001254 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001255 },
1256 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 .procname = "overcommit_ratio",
1258 .data = &sysctl_overcommit_ratio,
1259 .maxlen = sizeof(sysctl_overcommit_ratio),
1260 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001261 .proc_handler = overcommit_ratio_handler,
1262 },
1263 {
1264 .procname = "overcommit_kbytes",
1265 .data = &sysctl_overcommit_kbytes,
1266 .maxlen = sizeof(sysctl_overcommit_kbytes),
1267 .mode = 0644,
1268 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 },
1270 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 .procname = "page-cluster",
1272 .data = &page_cluster,
1273 .maxlen = sizeof(int),
1274 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001275 .proc_handler = proc_dointvec_minmax,
1276 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 },
1278 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 .procname = "dirty_background_ratio",
1280 .data = &dirty_background_ratio,
1281 .maxlen = sizeof(dirty_background_ratio),
1282 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001283 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 .extra1 = &zero,
1285 .extra2 = &one_hundred,
1286 },
1287 {
David Rientjes2da02992009-01-06 14:39:31 -08001288 .procname = "dirty_background_bytes",
1289 .data = &dirty_background_bytes,
1290 .maxlen = sizeof(dirty_background_bytes),
1291 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001292 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001293 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001294 },
1295 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 .procname = "dirty_ratio",
1297 .data = &vm_dirty_ratio,
1298 .maxlen = sizeof(vm_dirty_ratio),
1299 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001300 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 .extra1 = &zero,
1302 .extra2 = &one_hundred,
1303 },
1304 {
David Rientjes2da02992009-01-06 14:39:31 -08001305 .procname = "dirty_bytes",
1306 .data = &vm_dirty_bytes,
1307 .maxlen = sizeof(vm_dirty_bytes),
1308 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001309 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001310 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001311 },
1312 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001314 .data = &dirty_writeback_interval,
1315 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001317 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 },
1319 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001321 .data = &dirty_expire_interval,
1322 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001324 .proc_handler = proc_dointvec_minmax,
1325 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 },
1327 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001328 .procname = "dirtytime_expire_seconds",
1329 .data = &dirtytime_expire_interval,
1330 .maxlen = sizeof(dirty_expire_interval),
1331 .mode = 0644,
1332 .proc_handler = dirtytime_interval_handler,
1333 .extra1 = &zero,
1334 },
1335 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 .procname = "swappiness",
1337 .data = &vm_swappiness,
1338 .maxlen = sizeof(vm_swappiness),
1339 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001340 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .extra1 = &zero,
1342 .extra2 = &one_hundred,
1343 },
1344#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001345 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001347 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .maxlen = sizeof(unsigned long),
1349 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001350 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001351 },
1352#ifdef CONFIG_NUMA
1353 {
1354 .procname = "nr_hugepages_mempolicy",
1355 .data = NULL,
1356 .maxlen = sizeof(unsigned long),
1357 .mode = 0644,
1358 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001359 },
Kemi Wang45180852017-11-15 17:38:22 -08001360 {
1361 .procname = "numa_stat",
1362 .data = &sysctl_vm_numa_stat,
1363 .maxlen = sizeof(int),
1364 .mode = 0644,
1365 .proc_handler = sysctl_vm_numa_stat_handler,
1366 .extra1 = &zero,
1367 .extra2 = &one,
1368 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001369#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 .procname = "hugetlb_shm_group",
1372 .data = &sysctl_hugetlb_shm_group,
1373 .maxlen = sizeof(gid_t),
1374 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001375 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 },
Adam Litke54f9f802007-10-16 01:26:20 -07001377 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001378 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001379 .data = NULL,
1380 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001381 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001382 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001383 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384#endif
1385 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .procname = "lowmem_reserve_ratio",
1387 .data = &sysctl_lowmem_reserve_ratio,
1388 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1389 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001390 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 },
1392 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001393 .procname = "drop_caches",
1394 .data = &sysctl_drop_caches,
1395 .maxlen = sizeof(int),
1396 .mode = 0644,
1397 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001398 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001399 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001400 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001401#ifdef CONFIG_COMPACTION
1402 {
1403 .procname = "compact_memory",
1404 .data = &sysctl_compact_memory,
1405 .maxlen = sizeof(int),
1406 .mode = 0200,
1407 .proc_handler = sysctl_compaction_handler,
1408 },
Mel Gorman5e771902010-05-24 14:32:31 -07001409 {
1410 .procname = "extfrag_threshold",
1411 .data = &sysctl_extfrag_threshold,
1412 .maxlen = sizeof(int),
1413 .mode = 0644,
1414 .proc_handler = sysctl_extfrag_handler,
1415 .extra1 = &min_extfrag_threshold,
1416 .extra2 = &max_extfrag_threshold,
1417 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001418 {
1419 .procname = "compact_unevictable_allowed",
1420 .data = &sysctl_compact_unevictable_allowed,
1421 .maxlen = sizeof(int),
1422 .mode = 0644,
1423 .proc_handler = proc_dointvec,
1424 .extra1 = &zero,
1425 .extra2 = &one,
1426 },
Mel Gorman5e771902010-05-24 14:32:31 -07001427
Mel Gorman76ab0f52010-05-24 14:32:28 -07001428#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001429 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .procname = "min_free_kbytes",
1431 .data = &min_free_kbytes,
1432 .maxlen = sizeof(min_free_kbytes),
1433 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001434 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 .extra1 = &zero,
1436 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001437 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001438 .procname = "watermark_scale_factor",
1439 .data = &watermark_scale_factor,
1440 .maxlen = sizeof(watermark_scale_factor),
1441 .mode = 0644,
1442 .proc_handler = watermark_scale_factor_sysctl_handler,
1443 .extra1 = &one,
1444 .extra2 = &one_thousand,
1445 },
1446 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001447 .procname = "percpu_pagelist_fraction",
1448 .data = &percpu_pagelist_fraction,
1449 .maxlen = sizeof(percpu_pagelist_fraction),
1450 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001451 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001452 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001453 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454#ifdef CONFIG_MMU
1455 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 .procname = "max_map_count",
1457 .data = &sysctl_max_map_count,
1458 .maxlen = sizeof(sysctl_max_map_count),
1459 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001460 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001461 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001463#else
1464 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001465 .procname = "nr_trim_pages",
1466 .data = &sysctl_nr_trim_pages,
1467 .maxlen = sizeof(sysctl_nr_trim_pages),
1468 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001469 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001470 .extra1 = &zero,
1471 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472#endif
1473 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 .procname = "laptop_mode",
1475 .data = &laptop_mode,
1476 .maxlen = sizeof(laptop_mode),
1477 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001478 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 },
1480 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 .procname = "block_dump",
1482 .data = &block_dump,
1483 .maxlen = sizeof(block_dump),
1484 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001485 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 .extra1 = &zero,
1487 },
1488 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 .procname = "vfs_cache_pressure",
1490 .data = &sysctl_vfs_cache_pressure,
1491 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001493 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 .extra1 = &zero,
1495 },
1496#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1497 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 .procname = "legacy_va_layout",
1499 .data = &sysctl_legacy_va_layout,
1500 .maxlen = sizeof(sysctl_legacy_va_layout),
1501 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001502 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 .extra1 = &zero,
1504 },
1505#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001506#ifdef CONFIG_NUMA
1507 {
Christoph Lameter17436602006-01-18 17:42:32 -08001508 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001509 .data = &node_reclaim_mode,
1510 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001512 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001513 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001514 },
Christoph Lameter96146342006-07-03 00:24:13 -07001515 {
Christoph Lameter96146342006-07-03 00:24:13 -07001516 .procname = "min_unmapped_ratio",
1517 .data = &sysctl_min_unmapped_ratio,
1518 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001520 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001521 .extra1 = &zero,
1522 .extra2 = &one_hundred,
1523 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001524 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001525 .procname = "min_slab_ratio",
1526 .data = &sysctl_min_slab_ratio,
1527 .maxlen = sizeof(sysctl_min_slab_ratio),
1528 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001529 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001530 .extra1 = &zero,
1531 .extra2 = &one_hundred,
1532 },
Christoph Lameter17436602006-01-18 17:42:32 -08001533#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001534#ifdef CONFIG_SMP
1535 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001536 .procname = "stat_interval",
1537 .data = &sysctl_stat_interval,
1538 .maxlen = sizeof(sysctl_stat_interval),
1539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001540 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001541 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001542 {
1543 .procname = "stat_refresh",
1544 .data = NULL,
1545 .maxlen = 0,
1546 .mode = 0600,
1547 .proc_handler = vmstat_refresh,
1548 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001549#endif
David Howells6e141542009-12-15 19:27:45 +00001550#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001551 {
Eric Parised032182007-06-28 15:55:21 -04001552 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001553 .data = &dac_mmap_min_addr,
1554 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001556 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001557 },
David Howells6e141542009-12-15 19:27:45 +00001558#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001559#ifdef CONFIG_NUMA
1560 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001561 .procname = "numa_zonelist_order",
1562 .data = &numa_zonelist_order,
1563 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001565 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001566 },
1567#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001568#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001569 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001570 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001571 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001572#ifdef CONFIG_X86_32
1573 .data = &vdso32_enabled,
1574 .maxlen = sizeof(vdso32_enabled),
1575#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001576 .data = &vdso_enabled,
1577 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001578#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001579 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001580 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001581 .extra1 = &zero,
1582 },
1583#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001584#ifdef CONFIG_HIGHMEM
1585 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001586 .procname = "highmem_is_dirtyable",
1587 .data = &vm_highmem_is_dirtyable,
1588 .maxlen = sizeof(vm_highmem_is_dirtyable),
1589 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001590 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001591 .extra1 = &zero,
1592 .extra2 = &one,
1593 },
1594#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001595#ifdef CONFIG_MEMORY_FAILURE
1596 {
Andi Kleen6a460792009-09-16 11:50:15 +02001597 .procname = "memory_failure_early_kill",
1598 .data = &sysctl_memory_failure_early_kill,
1599 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1600 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001601 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001602 .extra1 = &zero,
1603 .extra2 = &one,
1604 },
1605 {
Andi Kleen6a460792009-09-16 11:50:15 +02001606 .procname = "memory_failure_recovery",
1607 .data = &sysctl_memory_failure_recovery,
1608 .maxlen = sizeof(sysctl_memory_failure_recovery),
1609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001610 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001611 .extra1 = &zero,
1612 .extra2 = &one,
1613 },
1614#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001615 {
1616 .procname = "user_reserve_kbytes",
1617 .data = &sysctl_user_reserve_kbytes,
1618 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1619 .mode = 0644,
1620 .proc_handler = proc_doulongvec_minmax,
1621 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001622 {
1623 .procname = "admin_reserve_kbytes",
1624 .data = &sysctl_admin_reserve_kbytes,
1625 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1626 .mode = 0644,
1627 .proc_handler = proc_doulongvec_minmax,
1628 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001629#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1630 {
1631 .procname = "mmap_rnd_bits",
1632 .data = &mmap_rnd_bits,
1633 .maxlen = sizeof(mmap_rnd_bits),
1634 .mode = 0600,
1635 .proc_handler = proc_dointvec_minmax,
1636 .extra1 = (void *)&mmap_rnd_bits_min,
1637 .extra2 = (void *)&mmap_rnd_bits_max,
1638 },
1639#endif
1640#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1641 {
1642 .procname = "mmap_rnd_compat_bits",
1643 .data = &mmap_rnd_compat_bits,
1644 .maxlen = sizeof(mmap_rnd_compat_bits),
1645 .mode = 0600,
1646 .proc_handler = proc_dointvec_minmax,
1647 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1648 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1649 },
1650#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001651 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652};
1653
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001654static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 .procname = "inode-nr",
1657 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001658 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001660 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 },
1662 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 .procname = "inode-state",
1664 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001665 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001667 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 },
1669 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 .procname = "file-nr",
1671 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001672 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001674 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 },
1676 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 .procname = "file-max",
1678 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001679 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001681 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 },
1683 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001684 .procname = "nr_open",
1685 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001686 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001687 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001688 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001689 .extra1 = &sysctl_nr_open_min,
1690 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001691 },
1692 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 .procname = "dentry-state",
1694 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001695 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001697 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 },
1699 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 .procname = "overflowuid",
1701 .data = &fs_overflowuid,
1702 .maxlen = sizeof(int),
1703 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001704 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 .extra1 = &minolduid,
1706 .extra2 = &maxolduid,
1707 },
1708 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 .procname = "overflowgid",
1710 .data = &fs_overflowgid,
1711 .maxlen = sizeof(int),
1712 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001713 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 .extra1 = &minolduid,
1715 .extra2 = &maxolduid,
1716 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001717#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 .procname = "leases-enable",
1720 .data = &leases_enable,
1721 .maxlen = sizeof(int),
1722 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001723 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001725#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726#ifdef CONFIG_DNOTIFY
1727 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 .procname = "dir-notify-enable",
1729 .data = &dir_notify_enable,
1730 .maxlen = sizeof(int),
1731 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001732 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 },
1734#endif
1735#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001736#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 .procname = "lease-break-time",
1739 .data = &lease_break_time,
1740 .maxlen = sizeof(int),
1741 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001742 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001744#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001745#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 .procname = "aio-nr",
1748 .data = &aio_nr,
1749 .maxlen = sizeof(aio_nr),
1750 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001751 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 },
1753 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 .procname = "aio-max-nr",
1755 .data = &aio_max_nr,
1756 .maxlen = sizeof(aio_max_nr),
1757 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001758 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001760#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001761#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001762 {
Robert Love0399cb02005-07-13 12:38:18 -04001763 .procname = "inotify",
1764 .mode = 0555,
1765 .child = inotify_table,
1766 },
1767#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001768#ifdef CONFIG_EPOLL
1769 {
1770 .procname = "epoll",
1771 .mode = 0555,
1772 .child = epoll_table,
1773 },
1774#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001776 {
Kees Cook800179c2012-07-25 17:29:07 -07001777 .procname = "protected_symlinks",
1778 .data = &sysctl_protected_symlinks,
1779 .maxlen = sizeof(int),
1780 .mode = 0600,
1781 .proc_handler = proc_dointvec_minmax,
1782 .extra1 = &zero,
1783 .extra2 = &one,
1784 },
1785 {
1786 .procname = "protected_hardlinks",
1787 .data = &sysctl_protected_hardlinks,
1788 .maxlen = sizeof(int),
1789 .mode = 0600,
1790 .proc_handler = proc_dointvec_minmax,
1791 .extra1 = &zero,
1792 .extra2 = &one,
1793 },
1794 {
Alan Coxd6e71142005-06-23 00:09:43 -07001795 .procname = "suid_dumpable",
1796 .data = &suid_dumpable,
1797 .maxlen = sizeof(int),
1798 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001799 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001800 .extra1 = &zero,
1801 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001802 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001803#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1804 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001805 .procname = "binfmt_misc",
1806 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001807 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001808 },
1809#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001810 {
Jens Axboeff9da692010-06-03 14:54:39 +02001811 .procname = "pipe-max-size",
1812 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001813 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001814 .mode = 0644,
Jens Axboeff9da692010-06-03 14:54:39 +02001815 .proc_handler = &pipe_proc_fn,
Jens Axboeb492e952010-05-19 21:03:16 +02001816 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001817 {
1818 .procname = "pipe-user-pages-hard",
1819 .data = &pipe_user_pages_hard,
1820 .maxlen = sizeof(pipe_user_pages_hard),
1821 .mode = 0644,
1822 .proc_handler = proc_doulongvec_minmax,
1823 },
1824 {
1825 .procname = "pipe-user-pages-soft",
1826 .data = &pipe_user_pages_soft,
1827 .maxlen = sizeof(pipe_user_pages_soft),
1828 .mode = 0644,
1829 .proc_handler = proc_doulongvec_minmax,
1830 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001831 {
1832 .procname = "mount-max",
1833 .data = &sysctl_mount_max,
1834 .maxlen = sizeof(unsigned int),
1835 .mode = 0644,
1836 .proc_handler = proc_dointvec_minmax,
1837 .extra1 = &one,
1838 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001839 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840};
1841
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001842static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001843#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001844 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001845 .procname = "exception-trace",
1846 .data = &show_unhandled_signals,
1847 .maxlen = sizeof(int),
1848 .mode = 0644,
1849 .proc_handler = proc_dointvec
1850 },
1851#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001852#if defined(CONFIG_OPTPROBES)
1853 {
1854 .procname = "kprobes-optimization",
1855 .data = &sysctl_kprobes_optimization,
1856 .maxlen = sizeof(int),
1857 .mode = 0644,
1858 .proc_handler = proc_kprobes_optimization_handler,
1859 .extra1 = &zero,
1860 .extra2 = &one,
1861 },
1862#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001863 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864};
1865
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001866static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001867 { }
Robert Love0eeca282005-07-12 17:06:03 -04001868};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001870int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001871{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001872 struct ctl_table_header *hdr;
1873
1874 hdr = register_sysctl_table(sysctl_base_table);
1875 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001876 return 0;
1877}
1878
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001879#endif /* CONFIG_SYSCTL */
1880
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881/*
1882 * /proc/sys support
1883 */
1884
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001885#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Kees Cookf8808302014-06-06 14:37:17 -07001887static int _proc_do_string(char *data, int maxlen, int write,
1888 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001889 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001890{
1891 size_t len;
1892 char __user *p;
1893 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001894
1895 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001896 *lenp = 0;
1897 return 0;
1898 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001899
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001900 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001901 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1902 /* Only continue writes not past the end of buffer. */
1903 len = strlen(data);
1904 if (len > maxlen - 1)
1905 len = maxlen - 1;
1906
1907 if (*ppos > len)
1908 return 0;
1909 len = *ppos;
1910 } else {
1911 /* Start writing from beginning of buffer. */
1912 len = 0;
1913 }
1914
Kees Cook2ca9bb42014-06-06 14:37:18 -07001915 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001916 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001917 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001918 if (get_user(c, p++))
1919 return -EFAULT;
1920 if (c == 0 || c == '\n')
1921 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001922 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001923 }
Kees Cookf8808302014-06-06 14:37:17 -07001924 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001925 } else {
1926 len = strlen(data);
1927 if (len > maxlen)
1928 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001929
1930 if (*ppos > len) {
1931 *lenp = 0;
1932 return 0;
1933 }
1934
1935 data += *ppos;
1936 len -= *ppos;
1937
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001938 if (len > *lenp)
1939 len = *lenp;
1940 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001941 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001942 return -EFAULT;
1943 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001944 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001945 return -EFAULT;
1946 len++;
1947 }
1948 *lenp = len;
1949 *ppos += len;
1950 }
1951 return 0;
1952}
1953
Kees Cookf4aacea2014-06-06 14:37:19 -07001954static void warn_sysctl_write(struct ctl_table *table)
1955{
1956 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1957 "This will not be supported in the future. To silence this\n"
1958 "warning, set kernel.sysctl_writes_strict = -1\n",
1959 current->comm, table->procname);
1960}
1961
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962/**
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001963 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1964 * @ppos: file position
1965 * @table: the sysctl table
1966 *
1967 * Returns true if the first position is non-zero and the sysctl_writes_strict
1968 * mode indicates this is not allowed for numeric input types. String proc
1969 * hadlers can ignore the return value.
1970 */
1971static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
1972 struct ctl_table *table)
1973{
1974 if (!*ppos)
1975 return false;
1976
1977 switch (sysctl_writes_strict) {
1978 case SYSCTL_WRITES_STRICT:
1979 return true;
1980 case SYSCTL_WRITES_WARN:
1981 warn_sysctl_write(table);
1982 return false;
1983 default:
1984 return false;
1985 }
1986}
1987
1988/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 * proc_dostring - read a string sysctl
1990 * @table: the sysctl table
1991 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 * @buffer: the user buffer
1993 * @lenp: the size of the user buffer
1994 * @ppos: file position
1995 *
1996 * Reads/writes a string from/to the user buffer. If the kernel
1997 * buffer provided is not large enough to hold the string, the
1998 * string is truncated. The copied string is %NULL-terminated.
1999 * If the string is being read by the user process, it is copied
2000 * and a newline '\n' is added. It is truncated if the buffer is
2001 * not large enough.
2002 *
2003 * Returns 0 on success.
2004 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002005int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 void __user *buffer, size_t *lenp, loff_t *ppos)
2007{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002008 if (write)
2009 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002010
Kees Cookf8808302014-06-06 14:37:17 -07002011 return _proc_do_string((char *)(table->data), table->maxlen, write,
2012 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013}
2014
Amerigo Wang00b7c332010-05-05 00:26:45 +00002015static size_t proc_skip_spaces(char **buf)
2016{
2017 size_t ret;
2018 char *tmp = skip_spaces(*buf);
2019 ret = tmp - *buf;
2020 *buf = tmp;
2021 return ret;
2022}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002024static void proc_skip_char(char **buf, size_t *size, const char v)
2025{
2026 while (*size) {
2027 if (**buf != v)
2028 break;
2029 (*size)--;
2030 (*buf)++;
2031 }
2032}
2033
Amerigo Wang00b7c332010-05-05 00:26:45 +00002034#define TMPBUFLEN 22
2035/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002036 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002037 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002038 * @buf: a kernel buffer
2039 * @size: size of the kernel buffer
2040 * @val: this is where the number will be stored
2041 * @neg: set to %TRUE if number is negative
2042 * @perm_tr: a vector which contains the allowed trailers
2043 * @perm_tr_len: size of the perm_tr vector
2044 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002045 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002046 * In case of success %0 is returned and @buf and @size are updated with
2047 * the amount of bytes read. If @tr is non-NULL and a trailing
2048 * character exists (size is non-zero after returning from this
2049 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002050 */
2051static int proc_get_long(char **buf, size_t *size,
2052 unsigned long *val, bool *neg,
2053 const char *perm_tr, unsigned perm_tr_len, char *tr)
2054{
2055 int len;
2056 char *p, tmp[TMPBUFLEN];
2057
2058 if (!*size)
2059 return -EINVAL;
2060
2061 len = *size;
2062 if (len > TMPBUFLEN - 1)
2063 len = TMPBUFLEN - 1;
2064
2065 memcpy(tmp, *buf, len);
2066
2067 tmp[len] = 0;
2068 p = tmp;
2069 if (*p == '-' && *size > 1) {
2070 *neg = true;
2071 p++;
2072 } else
2073 *neg = false;
2074 if (!isdigit(*p))
2075 return -EINVAL;
2076
2077 *val = simple_strtoul(p, &p, 0);
2078
2079 len = p - tmp;
2080
2081 /* We don't know if the next char is whitespace thus we may accept
2082 * invalid integers (e.g. 1234...a) or two integers instead of one
2083 * (e.g. 123...1). So lets not allow such large numbers. */
2084 if (len == TMPBUFLEN - 1)
2085 return -EINVAL;
2086
2087 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2088 return -EINVAL;
2089
2090 if (tr && (len < *size))
2091 *tr = *p;
2092
2093 *buf += len;
2094 *size -= len;
2095
2096 return 0;
2097}
2098
2099/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002100 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002101 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002102 * @buf: the user buffer
2103 * @size: the size of the user buffer
2104 * @val: the integer to be converted
2105 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002106 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002107 * In case of success %0 is returned and @buf and @size are updated with
2108 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002109 */
2110static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2111 bool neg)
2112{
2113 int len;
2114 char tmp[TMPBUFLEN], *p = tmp;
2115
2116 sprintf(p, "%s%lu", neg ? "-" : "", val);
2117 len = strlen(tmp);
2118 if (len > *size)
2119 len = *size;
2120 if (copy_to_user(*buf, tmp, len))
2121 return -EFAULT;
2122 *size -= len;
2123 *buf += len;
2124 return 0;
2125}
2126#undef TMPBUFLEN
2127
2128static int proc_put_char(void __user **buf, size_t *size, char c)
2129{
2130 if (*size) {
2131 char __user **buffer = (char __user **)buf;
2132 if (put_user(c, *buffer))
2133 return -EFAULT;
2134 (*size)--, (*buffer)++;
2135 *buf = *buffer;
2136 }
2137 return 0;
2138}
2139
2140static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 int *valp,
2142 int write, void *data)
2143{
2144 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002145 if (*negp) {
2146 if (*lvalp > (unsigned long) INT_MAX + 1)
2147 return -EINVAL;
2148 *valp = -*lvalp;
2149 } else {
2150 if (*lvalp > (unsigned long) INT_MAX)
2151 return -EINVAL;
2152 *valp = *lvalp;
2153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 } else {
2155 int val = *valp;
2156 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002157 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002158 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002160 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 *lvalp = (unsigned long)val;
2162 }
2163 }
2164 return 0;
2165}
2166
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002167static int do_proc_douintvec_conv(unsigned long *lvalp,
2168 unsigned int *valp,
2169 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002170{
2171 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002172 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002173 return -EINVAL;
2174 *valp = *lvalp;
2175 } else {
2176 unsigned int val = *valp;
2177 *lvalp = (unsigned long)val;
2178 }
2179 return 0;
2180}
2181
Amerigo Wang00b7c332010-05-05 00:26:45 +00002182static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2183
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002184static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002185 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002186 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002187 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 int write, void *data),
2189 void *data)
2190{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002191 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002192 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002193 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Amerigo Wang00b7c332010-05-05 00:26:45 +00002195 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 *lenp = 0;
2197 return 0;
2198 }
2199
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002200 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 vleft = table->maxlen / sizeof(*i);
2202 left = *lenp;
2203
2204 if (!conv)
2205 conv = do_proc_dointvec_conv;
2206
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002208 if (proc_first_pos_non_zero_ignore(ppos, table))
2209 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002210
Amerigo Wang00b7c332010-05-05 00:26:45 +00002211 if (left > PAGE_SIZE - 1)
2212 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002213 p = kbuf = memdup_user_nul(buffer, left);
2214 if (IS_ERR(kbuf))
2215 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002216 }
2217
2218 for (; left && vleft--; i++, first=0) {
2219 unsigned long lval;
2220 bool neg;
2221
2222 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002223 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002224
J. R. Okajima563b0462010-05-25 16:10:14 -07002225 if (!left)
2226 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002227 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002228 proc_wspace_sep,
2229 sizeof(proc_wspace_sep), NULL);
2230 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002232 if (conv(&neg, &lval, i, 1, data)) {
2233 err = -EINVAL;
2234 break;
2235 }
2236 } else {
2237 if (conv(&neg, &lval, i, 0, data)) {
2238 err = -EINVAL;
2239 break;
2240 }
2241 if (!first)
2242 err = proc_put_char(&buffer, &left, '\t');
2243 if (err)
2244 break;
2245 err = proc_put_long(&buffer, &left, lval, neg);
2246 if (err)
2247 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 }
2249 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002250
2251 if (!write && !first && left && !err)
2252 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002253 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002254 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002255 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002256 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002257 if (first)
2258 return err ? : -EINVAL;
2259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002261out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002263 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264}
2265
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002266static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002267 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002269 int write, void *data),
2270 void *data)
2271{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002272 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002273 buffer, lenp, ppos, conv, data);
2274}
2275
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002276static int do_proc_douintvec_w(unsigned int *tbl_data,
2277 struct ctl_table *table,
2278 void __user *buffer,
2279 size_t *lenp, loff_t *ppos,
2280 int (*conv)(unsigned long *lvalp,
2281 unsigned int *valp,
2282 int write, void *data),
2283 void *data)
2284{
2285 unsigned long lval;
2286 int err = 0;
2287 size_t left;
2288 bool neg;
2289 char *kbuf = NULL, *p;
2290
2291 left = *lenp;
2292
2293 if (proc_first_pos_non_zero_ignore(ppos, table))
2294 goto bail_early;
2295
2296 if (left > PAGE_SIZE - 1)
2297 left = PAGE_SIZE - 1;
2298
2299 p = kbuf = memdup_user_nul(buffer, left);
2300 if (IS_ERR(kbuf))
2301 return -EINVAL;
2302
2303 left -= proc_skip_spaces(&p);
2304 if (!left) {
2305 err = -EINVAL;
2306 goto out_free;
2307 }
2308
2309 err = proc_get_long(&p, &left, &lval, &neg,
2310 proc_wspace_sep,
2311 sizeof(proc_wspace_sep), NULL);
2312 if (err || neg) {
2313 err = -EINVAL;
2314 goto out_free;
2315 }
2316
2317 if (conv(&lval, tbl_data, 1, data)) {
2318 err = -EINVAL;
2319 goto out_free;
2320 }
2321
2322 if (!err && left)
2323 left -= proc_skip_spaces(&p);
2324
2325out_free:
2326 kfree(kbuf);
2327 if (err)
2328 return -EINVAL;
2329
2330 return 0;
2331
2332 /* This is in keeping with old __do_proc_dointvec() */
2333bail_early:
2334 *ppos += *lenp;
2335 return err;
2336}
2337
2338static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2339 size_t *lenp, loff_t *ppos,
2340 int (*conv)(unsigned long *lvalp,
2341 unsigned int *valp,
2342 int write, void *data),
2343 void *data)
2344{
2345 unsigned long lval;
2346 int err = 0;
2347 size_t left;
2348
2349 left = *lenp;
2350
2351 if (conv(&lval, tbl_data, 0, data)) {
2352 err = -EINVAL;
2353 goto out;
2354 }
2355
2356 err = proc_put_long(&buffer, &left, lval, false);
2357 if (err || !left)
2358 goto out;
2359
2360 err = proc_put_char(&buffer, &left, '\n');
2361
2362out:
2363 *lenp -= left;
2364 *ppos += *lenp;
2365
2366 return err;
2367}
2368
2369static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2370 int write, void __user *buffer,
2371 size_t *lenp, loff_t *ppos,
2372 int (*conv)(unsigned long *lvalp,
2373 unsigned int *valp,
2374 int write, void *data),
2375 void *data)
2376{
2377 unsigned int *i, vleft;
2378
2379 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2380 *lenp = 0;
2381 return 0;
2382 }
2383
2384 i = (unsigned int *) tbl_data;
2385 vleft = table->maxlen / sizeof(*i);
2386
2387 /*
2388 * Arrays are not supported, keep this simple. *Do not* add
2389 * support for them.
2390 */
2391 if (vleft != 1) {
2392 *lenp = 0;
2393 return -EINVAL;
2394 }
2395
2396 if (!conv)
2397 conv = do_proc_douintvec_conv;
2398
2399 if (write)
2400 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2401 conv, data);
2402 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2403}
2404
2405static int do_proc_douintvec(struct ctl_table *table, int write,
2406 void __user *buffer, size_t *lenp, loff_t *ppos,
2407 int (*conv)(unsigned long *lvalp,
2408 unsigned int *valp,
2409 int write, void *data),
2410 void *data)
2411{
2412 return __do_proc_douintvec(table->data, table, write,
2413 buffer, lenp, ppos, conv, data);
2414}
2415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416/**
2417 * proc_dointvec - read a vector of integers
2418 * @table: the sysctl table
2419 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 * @buffer: the user buffer
2421 * @lenp: the size of the user buffer
2422 * @ppos: file position
2423 *
2424 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2425 * values from/to the user buffer, treated as an ASCII string.
2426 *
2427 * Returns 0 on success.
2428 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002429int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 void __user *buffer, size_t *lenp, loff_t *ppos)
2431{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002432 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2433}
2434
2435/**
2436 * proc_douintvec - read a vector of unsigned integers
2437 * @table: the sysctl table
2438 * @write: %TRUE if this is a write to the sysctl file
2439 * @buffer: the user buffer
2440 * @lenp: the size of the user buffer
2441 * @ppos: file position
2442 *
2443 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2444 * values from/to the user buffer, treated as an ASCII string.
2445 *
2446 * Returns 0 on success.
2447 */
2448int proc_douintvec(struct ctl_table *table, int write,
2449 void __user *buffer, size_t *lenp, loff_t *ppos)
2450{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002451 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2452 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453}
2454
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002455/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002456 * Taint values can only be increased
2457 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002458 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002459static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002460 void __user *buffer, size_t *lenp, loff_t *ppos)
2461{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002462 struct ctl_table t;
2463 unsigned long tmptaint = get_taint();
2464 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002465
Bastian Blank91fcd412007-04-23 14:41:14 -07002466 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002467 return -EPERM;
2468
Andi Kleen25ddbb12008-10-15 22:01:41 -07002469 t = *table;
2470 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002471 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002472 if (err < 0)
2473 return err;
2474
2475 if (write) {
2476 /*
2477 * Poor man's atomic or. Not worth adding a primitive
2478 * to everyone's atomic.h for this
2479 */
2480 int i;
2481 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2482 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302483 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002484 }
2485 }
2486
2487 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002488}
2489
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002490#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002491static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002492 void __user *buffer, size_t *lenp, loff_t *ppos)
2493{
2494 if (write && !capable(CAP_SYS_ADMIN))
2495 return -EPERM;
2496
2497 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2498}
2499#endif
2500
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501struct do_proc_dointvec_minmax_conv_param {
2502 int *min;
2503 int *max;
2504};
2505
Amerigo Wang00b7c332010-05-05 00:26:45 +00002506static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2507 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 int write, void *data)
2509{
2510 struct do_proc_dointvec_minmax_conv_param *param = data;
2511 if (write) {
2512 int val = *negp ? -*lvalp : *lvalp;
2513 if ((param->min && *param->min > val) ||
2514 (param->max && *param->max < val))
2515 return -EINVAL;
2516 *valp = val;
2517 } else {
2518 int val = *valp;
2519 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002520 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002521 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002523 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 *lvalp = (unsigned long)val;
2525 }
2526 }
2527 return 0;
2528}
2529
2530/**
2531 * proc_dointvec_minmax - read a vector of integers with min/max values
2532 * @table: the sysctl table
2533 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 * @buffer: the user buffer
2535 * @lenp: the size of the user buffer
2536 * @ppos: file position
2537 *
2538 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2539 * values from/to the user buffer, treated as an ASCII string.
2540 *
2541 * This routine will ensure the values are within the range specified by
2542 * table->extra1 (min) and table->extra2 (max).
2543 *
2544 * Returns 0 on success.
2545 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002546int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 void __user *buffer, size_t *lenp, loff_t *ppos)
2548{
2549 struct do_proc_dointvec_minmax_conv_param param = {
2550 .min = (int *) table->extra1,
2551 .max = (int *) table->extra2,
2552 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002553 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 do_proc_dointvec_minmax_conv, &param);
2555}
2556
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002557struct do_proc_douintvec_minmax_conv_param {
2558 unsigned int *min;
2559 unsigned int *max;
2560};
2561
2562static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2563 unsigned int *valp,
2564 int write, void *data)
2565{
2566 struct do_proc_douintvec_minmax_conv_param *param = data;
2567
2568 if (write) {
2569 unsigned int val = *lvalp;
2570
Joe Lawrencefb910c42017-11-17 15:29:28 -08002571 if (*lvalp > UINT_MAX)
2572 return -EINVAL;
2573
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002574 if ((param->min && *param->min > val) ||
2575 (param->max && *param->max < val))
2576 return -ERANGE;
2577
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002578 *valp = val;
2579 } else {
2580 unsigned int val = *valp;
2581 *lvalp = (unsigned long) val;
2582 }
2583
2584 return 0;
2585}
2586
2587/**
2588 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2589 * @table: the sysctl table
2590 * @write: %TRUE if this is a write to the sysctl file
2591 * @buffer: the user buffer
2592 * @lenp: the size of the user buffer
2593 * @ppos: file position
2594 *
2595 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2596 * values from/to the user buffer, treated as an ASCII string. Negative
2597 * strings are not allowed.
2598 *
2599 * This routine will ensure the values are within the range specified by
2600 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2601 * check for UINT_MAX to avoid having to support wrap around uses from
2602 * userspace.
2603 *
2604 * Returns 0 on success.
2605 */
2606int proc_douintvec_minmax(struct ctl_table *table, int write,
2607 void __user *buffer, size_t *lenp, loff_t *ppos)
2608{
2609 struct do_proc_douintvec_minmax_conv_param param = {
2610 .min = (unsigned int *) table->extra1,
2611 .max = (unsigned int *) table->extra2,
2612 };
2613 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2614 do_proc_douintvec_minmax_conv, &param);
2615}
2616
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002617static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2618 unsigned int *valp,
2619 int write, void *data)
2620{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002621 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002622 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002623
Joe Lawrencefb910c42017-11-17 15:29:28 -08002624 if (*lvalp > UINT_MAX)
2625 return -EINVAL;
2626
2627 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002628 if (val == 0)
2629 return -EINVAL;
2630
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002631 *valp = val;
2632 } else {
2633 unsigned int val = *valp;
2634 *lvalp = (unsigned long) val;
2635 }
2636
2637 return 0;
2638}
2639
2640int proc_dopipe_max_size(struct ctl_table *table, int write,
2641 void __user *buffer, size_t *lenp, loff_t *ppos)
2642{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002643 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002644 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002645}
2646
Kees Cook54b50192012-07-30 14:39:18 -07002647static void validate_coredump_safety(void)
2648{
Alex Kelly046d6622012-10-04 17:15:23 -07002649#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002650 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002651 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002652 printk(KERN_WARNING
2653"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2654"Pipe handler or fully qualified core dump path required.\n"
2655"Set kernel.core_pattern before fs.suid_dumpable.\n"
2656 );
Kees Cook54b50192012-07-30 14:39:18 -07002657 }
Alex Kelly046d6622012-10-04 17:15:23 -07002658#endif
Kees Cook54b50192012-07-30 14:39:18 -07002659}
2660
2661static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2662 void __user *buffer, size_t *lenp, loff_t *ppos)
2663{
2664 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2665 if (!error)
2666 validate_coredump_safety();
2667 return error;
2668}
2669
Alex Kelly046d6622012-10-04 17:15:23 -07002670#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002671static int proc_dostring_coredump(struct ctl_table *table, int write,
2672 void __user *buffer, size_t *lenp, loff_t *ppos)
2673{
2674 int error = proc_dostring(table, write, buffer, lenp, ppos);
2675 if (!error)
2676 validate_coredump_safety();
2677 return error;
2678}
Alex Kelly046d6622012-10-04 17:15:23 -07002679#endif
Kees Cook54b50192012-07-30 14:39:18 -07002680
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002681static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 void __user *buffer,
2683 size_t *lenp, loff_t *ppos,
2684 unsigned long convmul,
2685 unsigned long convdiv)
2686{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002687 unsigned long *i, *min, *max;
2688 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002689 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002690 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002691
2692 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 *lenp = 0;
2694 return 0;
2695 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002696
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002697 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 min = (unsigned long *) table->extra1;
2699 max = (unsigned long *) table->extra2;
2700 vleft = table->maxlen / sizeof(unsigned long);
2701 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002702
2703 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002704 if (proc_first_pos_non_zero_ignore(ppos, table))
2705 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002706
Amerigo Wang00b7c332010-05-05 00:26:45 +00002707 if (left > PAGE_SIZE - 1)
2708 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002709 p = kbuf = memdup_user_nul(buffer, left);
2710 if (IS_ERR(kbuf))
2711 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002712 }
2713
Eric Dumazet27b3d802010-10-07 12:59:29 -07002714 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002715 unsigned long val;
2716
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002718 bool neg;
2719
Al Viro70f6cbb2015-12-24 00:13:10 -05002720 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002721
Al Viro70f6cbb2015-12-24 00:13:10 -05002722 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002723 proc_wspace_sep,
2724 sizeof(proc_wspace_sep), NULL);
2725 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 break;
2727 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002729 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 if ((min && val < *min) || (max && val > *max))
2731 continue;
2732 *i = val;
2733 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002734 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002735 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002736 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002737 if (err)
2738 break;
2739 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002740 err = proc_put_long(&buffer, &left, val, false);
2741 if (err)
2742 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 }
2744 }
2745
Amerigo Wang00b7c332010-05-05 00:26:45 +00002746 if (!write && !first && left && !err)
2747 err = proc_put_char(&buffer, &left, '\n');
2748 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002749 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002751 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002752 if (first)
2753 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002756out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002758 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759}
2760
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002761static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002762 void __user *buffer,
2763 size_t *lenp, loff_t *ppos,
2764 unsigned long convmul,
2765 unsigned long convdiv)
2766{
2767 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002768 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002769}
2770
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771/**
2772 * proc_doulongvec_minmax - read a vector of long integers with min/max values
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
2777 * @ppos: file position
2778 *
2779 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2780 * values from/to the user buffer, treated as an ASCII string.
2781 *
2782 * This routine will ensure the values are within the range specified by
2783 * table->extra1 (min) and table->extra2 (max).
2784 *
2785 * Returns 0 on success.
2786 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002787int proc_doulongvec_minmax(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_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791}
2792
2793/**
2794 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2795 * @table: the sysctl table
2796 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 * @buffer: the user buffer
2798 * @lenp: the size of the user buffer
2799 * @ppos: file position
2800 *
2801 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2802 * values from/to the user buffer, treated as an ASCII string. The values
2803 * are treated as milliseconds, and converted to jiffies when they are stored.
2804 *
2805 * This routine will ensure the values are within the range specified by
2806 * table->extra1 (min) and table->extra2 (max).
2807 *
2808 * Returns 0 on success.
2809 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002810int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 void __user *buffer,
2812 size_t *lenp, loff_t *ppos)
2813{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002814 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 lenp, ppos, HZ, 1000l);
2816}
2817
2818
Amerigo Wang00b7c332010-05-05 00:26:45 +00002819static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 int *valp,
2821 int write, void *data)
2822{
2823 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002824 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002825 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2827 } else {
2828 int val = *valp;
2829 unsigned long lval;
2830 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002831 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002832 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002834 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 lval = (unsigned long)val;
2836 }
2837 *lvalp = lval / HZ;
2838 }
2839 return 0;
2840}
2841
Amerigo Wang00b7c332010-05-05 00:26:45 +00002842static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 int *valp,
2844 int write, void *data)
2845{
2846 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002847 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2848 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2850 } else {
2851 int val = *valp;
2852 unsigned long lval;
2853 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002854 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002855 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002857 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 lval = (unsigned long)val;
2859 }
2860 *lvalp = jiffies_to_clock_t(lval);
2861 }
2862 return 0;
2863}
2864
Amerigo Wang00b7c332010-05-05 00:26:45 +00002865static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 int *valp,
2867 int write, void *data)
2868{
2869 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002870 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2871
2872 if (jif > INT_MAX)
2873 return 1;
2874 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 } else {
2876 int val = *valp;
2877 unsigned long lval;
2878 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002879 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002880 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002882 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 lval = (unsigned long)val;
2884 }
2885 *lvalp = jiffies_to_msecs(lval);
2886 }
2887 return 0;
2888}
2889
2890/**
2891 * proc_dointvec_jiffies - read a vector of integers as seconds
2892 * @table: the sysctl table
2893 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 * @buffer: the user buffer
2895 * @lenp: the size of the user buffer
2896 * @ppos: file position
2897 *
2898 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2899 * values from/to the user buffer, treated as an ASCII string.
2900 * The values read are assumed to be in seconds, and are converted into
2901 * jiffies.
2902 *
2903 * Returns 0 on success.
2904 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002905int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 void __user *buffer, size_t *lenp, loff_t *ppos)
2907{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002908 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 do_proc_dointvec_jiffies_conv,NULL);
2910}
2911
2912/**
2913 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2914 * @table: the sysctl table
2915 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 * @buffer: the user buffer
2917 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002918 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 *
2920 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2921 * values from/to the user buffer, treated as an ASCII string.
2922 * The values read are assumed to be in 1/USER_HZ seconds, and
2923 * are converted into jiffies.
2924 *
2925 * Returns 0 on success.
2926 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002927int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 void __user *buffer, size_t *lenp, loff_t *ppos)
2929{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002930 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 do_proc_dointvec_userhz_jiffies_conv,NULL);
2932}
2933
2934/**
2935 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2936 * @table: the sysctl table
2937 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 * @buffer: the user buffer
2939 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07002940 * @ppos: file position
2941 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 *
2943 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2944 * values from/to the user buffer, treated as an ASCII string.
2945 * The values read are assumed to be in 1/1000 seconds, and
2946 * are converted into jiffies.
2947 *
2948 * Returns 0 on success.
2949 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002950int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 void __user *buffer, size_t *lenp, loff_t *ppos)
2952{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002953 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 do_proc_dointvec_ms_jiffies_conv, NULL);
2955}
2956
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002957static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002958 void __user *buffer, size_t *lenp, loff_t *ppos)
2959{
2960 struct pid *new_pid;
2961 pid_t tmp;
2962 int r;
2963
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08002964 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002965
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002966 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07002967 lenp, ppos, NULL, NULL);
2968 if (r || !write)
2969 return r;
2970
2971 new_pid = find_get_pid(tmp);
2972 if (!new_pid)
2973 return -ESRCH;
2974
2975 put_pid(xchg(&cad_pid, new_pid));
2976 return 0;
2977}
2978
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002979/**
2980 * proc_do_large_bitmap - read/write from/to a large bitmap
2981 * @table: the sysctl table
2982 * @write: %TRUE if this is a write to the sysctl file
2983 * @buffer: the user buffer
2984 * @lenp: the size of the user buffer
2985 * @ppos: file position
2986 *
2987 * The bitmap is stored at table->data and the bitmap length (in bits)
2988 * in table->maxlen.
2989 *
2990 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2991 * large bitmaps may be represented in a compact manner. Writing into
2992 * the file will clear the bitmap then update it with the given input.
2993 *
2994 * Returns 0 on success.
2995 */
2996int proc_do_large_bitmap(struct ctl_table *table, int write,
2997 void __user *buffer, size_t *lenp, loff_t *ppos)
2998{
2999 int err = 0;
3000 bool first = 1;
3001 size_t left = *lenp;
3002 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003003 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003004 unsigned long *tmp_bitmap = NULL;
3005 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3006
WANG Cong122ff242014-05-12 16:04:53 -07003007 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003008 *lenp = 0;
3009 return 0;
3010 }
3011
3012 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003013 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003014
3015 if (left > PAGE_SIZE - 1)
3016 left = PAGE_SIZE - 1;
3017
Al Viro70f6cbb2015-12-24 00:13:10 -05003018 p = kbuf = memdup_user_nul(buffer, left);
3019 if (IS_ERR(kbuf))
3020 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003021
3022 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
3023 GFP_KERNEL);
3024 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003025 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003026 return -ENOMEM;
3027 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003028 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003029 while (!err && left) {
3030 unsigned long val_a, val_b;
3031 bool neg;
3032
Al Viro70f6cbb2015-12-24 00:13:10 -05003033 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003034 sizeof(tr_a), &c);
3035 if (err)
3036 break;
3037 if (val_a >= bitmap_len || neg) {
3038 err = -EINVAL;
3039 break;
3040 }
3041
3042 val_b = val_a;
3043 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003044 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003045 left--;
3046 }
3047
3048 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003049 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003050 &neg, tr_b, sizeof(tr_b),
3051 &c);
3052 if (err)
3053 break;
3054 if (val_b >= bitmap_len || neg ||
3055 val_a > val_b) {
3056 err = -EINVAL;
3057 break;
3058 }
3059 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003060 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003061 left--;
3062 }
3063 }
3064
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003065 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003066 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003067 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003068 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003069 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003070 } else {
3071 unsigned long bit_a, bit_b = 0;
3072
3073 while (left) {
3074 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3075 if (bit_a >= bitmap_len)
3076 break;
3077 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3078 bit_a + 1) - 1;
3079
3080 if (!first) {
3081 err = proc_put_char(&buffer, &left, ',');
3082 if (err)
3083 break;
3084 }
3085 err = proc_put_long(&buffer, &left, bit_a, false);
3086 if (err)
3087 break;
3088 if (bit_a != bit_b) {
3089 err = proc_put_char(&buffer, &left, '-');
3090 if (err)
3091 break;
3092 err = proc_put_long(&buffer, &left, bit_b, false);
3093 if (err)
3094 break;
3095 }
3096
3097 first = 0; bit_b++;
3098 }
3099 if (!err)
3100 err = proc_put_char(&buffer, &left, '\n');
3101 }
3102
3103 if (!err) {
3104 if (write) {
3105 if (*ppos)
3106 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3107 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003108 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003109 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003110 *lenp -= left;
3111 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003112 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003113
3114 kfree(tmp_bitmap);
3115 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003116}
3117
Jovi Zhang55610502011-01-12 17:00:45 -08003118#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003120int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 void __user *buffer, size_t *lenp, loff_t *ppos)
3122{
3123 return -ENOSYS;
3124}
3125
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003126int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 void __user *buffer, size_t *lenp, loff_t *ppos)
3128{
3129 return -ENOSYS;
3130}
3131
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003132int proc_douintvec(struct ctl_table *table, int write,
3133 void __user *buffer, size_t *lenp, loff_t *ppos)
3134{
3135 return -ENOSYS;
3136}
3137
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003138int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 void __user *buffer, size_t *lenp, loff_t *ppos)
3140{
3141 return -ENOSYS;
3142}
3143
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003144int proc_douintvec_minmax(struct ctl_table *table, int write,
3145 void __user *buffer, size_t *lenp, loff_t *ppos)
3146{
3147 return -ENOSYS;
3148}
3149
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003150int proc_dopipe_max_size(struct ctl_table *table, int write,
3151 void __user *buffer, size_t *lenp, loff_t *ppos)
3152{
3153 return -ENOSYS;
3154}
3155
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003156int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 void __user *buffer, size_t *lenp, loff_t *ppos)
3158{
3159 return -ENOSYS;
3160}
3161
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003162int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 void __user *buffer, size_t *lenp, loff_t *ppos)
3164{
3165 return -ENOSYS;
3166}
3167
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003168int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 void __user *buffer, size_t *lenp, loff_t *ppos)
3170{
3171 return -ENOSYS;
3172}
3173
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003174int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 void __user *buffer, size_t *lenp, loff_t *ppos)
3176{
3177 return -ENOSYS;
3178}
3179
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003180int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 void __user *buffer,
3182 size_t *lenp, loff_t *ppos)
3183{
3184 return -ENOSYS;
3185}
3186
3187
Jovi Zhang55610502011-01-12 17:00:45 -08003188#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190/*
3191 * No sense putting this after each symbol definition, twice,
3192 * exception granted :-)
3193 */
3194EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003195EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196EXPORT_SYMBOL(proc_dointvec_jiffies);
3197EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003198EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003199EXPORT_SYMBOL_GPL(proc_dopipe_max_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3201EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3202EXPORT_SYMBOL(proc_dostring);
3203EXPORT_SYMBOL(proc_doulongvec_minmax);
3204EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);