blob: 1877ebe85c95984de1fc62510589ade9a354e701 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Christian Brauner7f2923c2019-03-07 16:29:40 -080070#include "../lib/kstrtox.h"
71
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080072#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include <asm/processor.h>
74
Andi Kleen29cbc782006-09-30 01:47:55 +020075#ifdef CONFIG_X86
76#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010077#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010078#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020079#endif
David Howellsd550bbd2012-03-28 18:30:03 +010080#ifdef CONFIG_SPARC
81#include <asm/setup.h>
82#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080083#ifdef CONFIG_BSD_PROCESS_ACCT
84#include <linux/acct.h>
85#endif
Dave Young4f0e0562010-03-10 15:24:09 -080086#ifdef CONFIG_RT_MUTEXES
87#include <linux/rtmutex.h>
88#endif
Dave Young2edf5e42010-03-10 15:24:10 -080089#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
90#include <linux/lockdep.h>
91#endif
Dave Young15485a42010-03-10 15:24:07 -080092#ifdef CONFIG_CHR_DEV_SG
93#include <scsi/sg.h>
94#endif
Alexander Popov964c9df2018-08-17 01:17:03 +030095#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
96#include <linux/stackleak.h>
97#endif
Don Zickus58687ac2010-05-07 17:11:44 -040098#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050099#include <linux/nmi.h>
100#endif
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#if defined(CONFIG_SYSCTL)
103
104/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700105extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700106#ifdef CONFIG_COREDUMP
107extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700109extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800113extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100114extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300115extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000116#ifndef CONFIG_MMU
117extern int sysctl_nr_trim_pages;
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400121#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122static int sixty = 60;
123#endif
124
Aaron Tomlin270750db2014-01-20 17:34:13 +0000125static int __maybe_unused neg_one = -1;
126
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700127static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700128static int __maybe_unused one = 1;
129static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700130static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800131static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700132static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700133static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700134#ifdef CONFIG_PRINTK
135static int ten_thousand = 10000;
136#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300137#ifdef CONFIG_PERF_EVENTS
138static int six_hundred_forty_kb = 640 * 1024;
139#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700140
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700141/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
142static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
145static int maxolduid = 65535;
146static int minolduid;
147
148static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700149static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700151/*
152 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
153 * and hung_task_check_interval_secs
154 */
Liu Hua80df2842014-04-07 15:38:57 -0700155#ifdef CONFIG_DETECT_HUNG_TASK
156static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
157#endif
158
Dave Youngd14f1722010-02-25 20:28:57 -0500159#ifdef CONFIG_INOTIFY_USER
160#include <linux/inotify.h>
161#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700162#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#endif
164
165#ifdef __hppa__
166extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530167#endif
168
169#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170extern int unaligned_enabled;
171#endif
172
Jes Sorensend2b176e2006-02-28 09:42:23 -0800173#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800174extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800175#endif
176
Vineet Guptab6fca722013-01-09 20:06:28 +0530177#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
178extern int no_unaligned_warning;
179#endif
180
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700181#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700182
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700183/**
184 * enum sysctl_writes_mode - supported sysctl write modes
185 *
186 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
187 * to be written, and multiple writes on the same sysctl file descriptor
188 * will rewrite the sysctl value, regardless of file position. No warning
189 * is issued when the initial position is not 0.
190 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
191 * not 0.
192 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
193 * file position 0 and the value must be fully contained in the buffer
194 * sent to the write syscall. If dealing with strings respect the file
195 * position, but restrict this to the max length of the buffer, anything
196 * passed the max lenght will be ignored. Multiple writes will append
197 * to the buffer.
198 *
199 * These write modes control how current file position affects the behavior of
200 * updating sysctl values through the proc interface on each write.
201 */
202enum sysctl_writes_mode {
203 SYSCTL_WRITES_LEGACY = -1,
204 SYSCTL_WRITES_WARN = 0,
205 SYSCTL_WRITES_STRICT = 1,
206};
Kees Cookf4aacea2014-06-06 14:37:19 -0700207
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700208static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700209
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700210static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700211 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700212static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800213 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700214#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700215
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700216#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700217static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700218 void __user *buffer, size_t *lenp, loff_t *ppos);
219#endif
220
Kees Cook54b50192012-07-30 14:39:18 -0700221static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
222 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700223#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700224static int proc_dostring_coredump(struct ctl_table *table, int write,
225 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700226#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800227static int proc_dopipe_max_size(struct ctl_table *table, int write,
228 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -0800229#ifdef CONFIG_BPF_SYSCALL
Alexei Starovoitov492ecee2019-02-25 14:28:39 -0800230static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
231 void __user *buffer, size_t *lenp,
232 loff_t *ppos);
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -0800233#endif
Kees Cook54b50192012-07-30 14:39:18 -0700234
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700235#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700236/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100237static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700238
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700239static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700240 void __user *buffer, size_t *lenp,
241 loff_t *ppos)
242{
243 int error;
244
245 error = proc_dointvec(table, write, buffer, lenp, ppos);
246 if (error)
247 return error;
248
249 if (write)
250 sysrq_toggle_support(__sysrq_enabled);
251
252 return 0;
253}
254
255#endif
256
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700257static struct ctl_table kern_table[];
258static struct ctl_table vm_table[];
259static struct ctl_table fs_table[];
260static struct ctl_table debug_table[];
261static struct ctl_table dev_table[];
262extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800263#ifdef CONFIG_EPOLL
264extern struct ctl_table epoll_table[];
265#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800267#ifdef CONFIG_FW_LOADER_USER_HELPER
268extern struct ctl_table firmware_config_table[];
269#endif
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
272int sysctl_legacy_va_layout;
273#endif
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275/* The default sysctl tables: */
276
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800277static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 .procname = "kernel",
280 .mode = 0555,
281 .child = kern_table,
282 },
283 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 .procname = "vm",
285 .mode = 0555,
286 .child = vm_table,
287 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 .procname = "fs",
290 .mode = 0555,
291 .child = fs_table,
292 },
293 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 .procname = "debug",
295 .mode = 0555,
296 .child = debug_table,
297 },
298 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 .procname = "dev",
300 .mode = 0555,
301 .child = dev_table,
302 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700303 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304};
305
Ingo Molnar77e54a12007-07-09 18:52:00 +0200306#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100307static int min_sched_granularity_ns = 100000; /* 100 usecs */
308static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
309static int min_wakeup_granularity_ns; /* 0 usecs */
310static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200311#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100312static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
313static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200314#endif /* CONFIG_SMP */
315#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200316
Mel Gorman5e771902010-05-24 14:32:31 -0700317#ifdef CONFIG_COMPACTION
318static int min_extfrag_threshold;
319static int max_extfrag_threshold = 1000;
320#endif
321
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700322static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200323 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200324 .procname = "sched_child_runs_first",
325 .data = &sysctl_sched_child_runs_first,
326 .maxlen = sizeof(unsigned int),
327 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800328 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200329 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200330#ifdef CONFIG_SCHED_DEBUG
331 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100332 .procname = "sched_min_granularity_ns",
333 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200334 .maxlen = sizeof(unsigned int),
335 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800336 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100337 .extra1 = &min_sched_granularity_ns,
338 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200339 },
340 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200341 .procname = "sched_latency_ns",
342 .data = &sysctl_sched_latency,
343 .maxlen = sizeof(unsigned int),
344 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800345 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200346 .extra1 = &min_sched_granularity_ns,
347 .extra2 = &max_sched_granularity_ns,
348 },
349 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200350 .procname = "sched_wakeup_granularity_ns",
351 .data = &sysctl_sched_wakeup_granularity,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800354 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200355 .extra1 = &min_wakeup_granularity_ns,
356 .extra2 = &max_wakeup_granularity_ns,
357 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200358#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200359 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100360 .procname = "sched_tunable_scaling",
361 .data = &sysctl_sched_tunable_scaling,
362 .maxlen = sizeof(enum sched_tunable_scaling),
363 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800364 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100365 .extra1 = &min_sched_tunable_scaling,
366 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200367 },
368 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900369 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200370 .data = &sysctl_sched_migration_cost,
371 .maxlen = sizeof(unsigned int),
372 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800373 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200374 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100375 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100376 .procname = "sched_nr_migrate",
377 .data = &sysctl_sched_nr_migrate,
378 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800380 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100381 },
Mel Gormancb251762016-02-05 09:08:36 +0000382#ifdef CONFIG_SCHEDSTATS
383 {
384 .procname = "sched_schedstats",
385 .data = NULL,
386 .maxlen = sizeof(unsigned int),
387 .mode = 0644,
388 .proc_handler = sysctl_schedstats,
389 .extra1 = &zero,
390 .extra2 = &one,
391 },
392#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200393#endif /* CONFIG_SMP */
394#ifdef CONFIG_NUMA_BALANCING
395 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200396 .procname = "numa_balancing_scan_delay_ms",
397 .data = &sysctl_numa_balancing_scan_delay,
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
400 .proc_handler = proc_dointvec,
401 },
402 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200403 .procname = "numa_balancing_scan_period_min_ms",
404 .data = &sysctl_numa_balancing_scan_period_min,
405 .maxlen = sizeof(unsigned int),
406 .mode = 0644,
407 .proc_handler = proc_dointvec,
408 },
409 {
410 .procname = "numa_balancing_scan_period_max_ms",
411 .data = &sysctl_numa_balancing_scan_period_max,
412 .maxlen = sizeof(unsigned int),
413 .mode = 0644,
414 .proc_handler = proc_dointvec,
415 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200416 {
417 .procname = "numa_balancing_scan_size_mb",
418 .data = &sysctl_numa_balancing_scan_size,
419 .maxlen = sizeof(unsigned int),
420 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400421 .proc_handler = proc_dointvec_minmax,
422 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200423 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100424 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800425 .procname = "numa_balancing",
426 .data = NULL, /* filled in by handler */
427 .maxlen = sizeof(unsigned int),
428 .mode = 0644,
429 .proc_handler = sysctl_numa_balancing,
430 .extra1 = &zero,
431 .extra2 = &one,
432 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200433#endif /* CONFIG_NUMA_BALANCING */
434#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200435 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100436 .procname = "sched_rt_period_us",
437 .data = &sysctl_sched_rt_period,
438 .maxlen = sizeof(unsigned int),
439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800440 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100441 },
442 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100443 .procname = "sched_rt_runtime_us",
444 .data = &sysctl_sched_rt_runtime,
445 .maxlen = sizeof(int),
446 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800447 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100448 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600449 {
450 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800451 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600452 .maxlen = sizeof(int),
453 .mode = 0644,
454 .proc_handler = sched_rr_handler,
455 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100456#ifdef CONFIG_SCHED_AUTOGROUP
457 {
458 .procname = "sched_autogroup_enabled",
459 .data = &sysctl_sched_autogroup_enabled,
460 .maxlen = sizeof(unsigned int),
461 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800462 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100463 .extra1 = &zero,
464 .extra2 = &one,
465 },
466#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700467#ifdef CONFIG_CFS_BANDWIDTH
468 {
469 .procname = "sched_cfs_bandwidth_slice_us",
470 .data = &sysctl_sched_cfs_bandwidth_slice,
471 .maxlen = sizeof(unsigned int),
472 .mode = 0644,
473 .proc_handler = proc_dointvec_minmax,
474 .extra1 = &one,
475 },
476#endif
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000477#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
478 {
479 .procname = "sched_energy_aware",
480 .data = &sysctl_sched_energy_aware,
481 .maxlen = sizeof(unsigned int),
482 .mode = 0644,
483 .proc_handler = sched_energy_aware_handler,
484 .extra1 = &zero,
485 .extra2 = &one,
486 },
487#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700488#ifdef CONFIG_PROVE_LOCKING
489 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700490 .procname = "prove_locking",
491 .data = &prove_locking,
492 .maxlen = sizeof(int),
493 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800494 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700495 },
496#endif
497#ifdef CONFIG_LOCK_STAT
498 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700499 .procname = "lock_stat",
500 .data = &lock_stat,
501 .maxlen = sizeof(int),
502 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800503 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700504 },
505#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200506 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .procname = "panic",
508 .data = &panic_timeout,
509 .maxlen = sizeof(int),
510 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800511 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 },
Alex Kelly046d6622012-10-04 17:15:23 -0700513#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 .procname = "core_uses_pid",
516 .data = &core_uses_pid,
517 .maxlen = sizeof(int),
518 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800519 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 },
521 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 .procname = "core_pattern",
523 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700524 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700526 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
Neil Hormana2939802009-09-23 15:56:56 -0700528 {
Neil Hormana2939802009-09-23 15:56:56 -0700529 .procname = "core_pipe_limit",
530 .data = &core_pipe_limit,
531 .maxlen = sizeof(unsigned int),
532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800533 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700534 },
Alex Kelly046d6622012-10-04 17:15:23 -0700535#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800536#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700539 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800540 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800541 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700543 {
544 .procname = "sysctl_writes_strict",
545 .data = &sysctl_writes_strict,
546 .maxlen = sizeof(int),
547 .mode = 0644,
548 .proc_handler = proc_dointvec_minmax,
549 .extra1 = &neg_one,
550 .extra2 = &one,
551 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800552#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100553#ifdef CONFIG_LATENCYTOP
554 {
555 .procname = "latencytop",
556 .data = &latencytop_enabled,
557 .maxlen = sizeof(int),
558 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000559 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100560 },
561#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562#ifdef CONFIG_BLK_DEV_INITRD
563 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 .procname = "real-root-dev",
565 .data = &real_root_dev,
566 .maxlen = sizeof(int),
567 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800568 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 },
570#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700571 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700572 .procname = "print-fatal-signals",
573 .data = &print_fatal_signals,
574 .maxlen = sizeof(int),
575 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800576 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700577 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700578#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 .procname = "reboot-cmd",
581 .data = reboot_command,
582 .maxlen = 256,
583 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800584 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 },
586 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 .procname = "stop-a",
588 .data = &stop_a_enabled,
589 .maxlen = sizeof (int),
590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800591 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 },
593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .procname = "scons-poweroff",
595 .data = &scons_pwroff,
596 .maxlen = sizeof (int),
597 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800598 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 },
600#endif
David S. Miller08714202008-11-16 23:49:24 -0800601#ifdef CONFIG_SPARC64
602 {
David S. Miller08714202008-11-16 23:49:24 -0800603 .procname = "tsb-ratio",
604 .data = &sysctl_tsb_ratio,
605 .maxlen = sizeof (int),
606 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800607 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800608 },
609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#ifdef __hppa__
611 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 .procname = "soft-power",
613 .data = &pwrsw_enabled,
614 .maxlen = sizeof (int),
615 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800616 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530618#endif
619#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 .procname = "unaligned-trap",
622 .data = &unaligned_enabled,
623 .maxlen = sizeof (int),
624 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800625 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 },
627#endif
628 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 .procname = "ctrl-alt-del",
630 .data = &C_A_D,
631 .maxlen = sizeof(int),
632 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800633 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400635#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200636 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200637 .procname = "ftrace_enabled",
638 .data = &ftrace_enabled,
639 .maxlen = sizeof(int),
640 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800641 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200642 },
643#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500644#ifdef CONFIG_STACK_TRACER
645 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500646 .procname = "stack_tracer_enabled",
647 .data = &stack_tracer_enabled,
648 .maxlen = sizeof(int),
649 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800650 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500651 },
652#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400653#ifdef CONFIG_TRACING
654 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100655 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400656 .data = &ftrace_dump_on_oops,
657 .maxlen = sizeof(int),
658 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800659 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400660 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400661 {
662 .procname = "traceoff_on_warning",
663 .data = &__disable_trace_on_warning,
664 .maxlen = sizeof(__disable_trace_on_warning),
665 .mode = 0644,
666 .proc_handler = proc_dointvec,
667 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500668 {
669 .procname = "tracepoint_printk",
670 .data = &tracepoint_printk,
671 .maxlen = sizeof(tracepoint_printk),
672 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500673 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500674 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400675#endif
Dave Young2965faa2015-09-09 15:38:55 -0700676#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800677 {
678 .procname = "kexec_load_disabled",
679 .data = &kexec_load_disabled,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 /* only handle a transition from default "0" to "1" */
683 .proc_handler = proc_dointvec_minmax,
684 .extra1 = &one,
685 .extra2 = &one,
686 },
687#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200688#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 .procname = "modprobe",
691 .data = &modprobe_path,
692 .maxlen = KMOD_PATH_LEN,
693 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800694 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 },
Kees Cook3d433212009-04-02 15:49:29 -0700696 {
Kees Cook3d433212009-04-02 15:49:29 -0700697 .procname = "modules_disabled",
698 .data = &modules_disabled,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800702 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700703 .extra1 = &one,
704 .extra2 = &one,
705 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700707#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100710 .data = &uevent_helper,
711 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800713 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 },
Michael Marineau86d56132014-04-10 14:09:31 -0700715#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716#ifdef CONFIG_CHR_DEV_SG
717 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 .procname = "sg-big-buff",
719 .data = &sg_big_buff,
720 .maxlen = sizeof (int),
721 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800722 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 },
724#endif
725#ifdef CONFIG_BSD_PROCESS_ACCT
726 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 .procname = "acct",
728 .data = &acct_parm,
729 .maxlen = 3*sizeof(int),
730 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800731 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 },
733#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734#ifdef CONFIG_MAGIC_SYSRQ
735 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800737 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 .maxlen = sizeof (int),
739 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700740 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 },
742#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700743#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700746 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 .maxlen = sizeof (int),
748 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800749 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700751#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700754 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 .maxlen = sizeof(int),
756 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700757 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 },
759 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 .procname = "random",
761 .mode = 0555,
762 .child = random_table,
763 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 {
Eric Paris17f60a72011-04-01 17:07:50 -0400765 .procname = "usermodehelper",
766 .mode = 0555,
767 .child = usermodehelper_table,
768 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800769#ifdef CONFIG_FW_LOADER_USER_HELPER
770 {
771 .procname = "firmware_config",
772 .mode = 0555,
773 .child = firmware_config_table,
774 },
775#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400776 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 .procname = "overflowuid",
778 .data = &overflowuid,
779 .maxlen = sizeof(int),
780 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800781 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 .extra1 = &minolduid,
783 .extra2 = &maxolduid,
784 },
785 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 .procname = "overflowgid",
787 .data = &overflowgid,
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 = &minolduid,
792 .extra2 = &maxolduid,
793 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800794#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795#ifdef CONFIG_MATHEMU
796 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 .procname = "ieee_emulation_warnings",
798 .data = &sysctl_ieee_emulation_warnings,
799 .maxlen = sizeof(int),
800 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800801 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 },
803#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200806 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 .maxlen = sizeof(int),
808 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800809 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 },
811#endif
812 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 .procname = "pid_max",
814 .data = &pid_max,
815 .maxlen = sizeof (int),
816 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800817 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 .extra1 = &pid_max_min,
819 .extra2 = &pid_max_max,
820 },
821 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 .procname = "panic_on_oops",
823 .data = &panic_on_oops,
824 .maxlen = sizeof(int),
825 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800826 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 },
Feng Tang81c9d432019-01-03 15:28:20 -0800828 {
829 .procname = "panic_print",
830 .data = &panic_print,
831 .maxlen = sizeof(unsigned long),
832 .mode = 0644,
833 .proc_handler = proc_doulongvec_minmax,
834 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800835#if defined CONFIG_PRINTK
836 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800837 .procname = "printk",
838 .data = &console_loglevel,
839 .maxlen = 4*sizeof(int),
840 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800841 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800842 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700845 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 .maxlen = sizeof(int),
847 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800848 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 },
850 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700852 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 .maxlen = sizeof(int),
854 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800855 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 },
Dave Youngaf913222009-09-22 16:43:33 -0700857 {
Dave Youngaf913222009-09-22 16:43:33 -0700858 .procname = "printk_delay",
859 .data = &printk_delay_msec,
860 .maxlen = sizeof(int),
861 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800862 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700863 .extra1 = &zero,
864 .extra2 = &ten_thousand,
865 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700867 .procname = "printk_devkmsg",
868 .data = devkmsg_log_str,
869 .maxlen = DEVKMSG_STR_MAX_SIZE,
870 .mode = 0644,
871 .proc_handler = devkmsg_sysctl_set_loglvl,
872 },
873 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800874 .procname = "dmesg_restrict",
875 .data = &dmesg_restrict,
876 .maxlen = sizeof(int),
877 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700878 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800879 .extra1 = &zero,
880 .extra2 = &one,
881 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800882 {
883 .procname = "kptr_restrict",
884 .data = &kptr_restrict,
885 .maxlen = sizeof(int),
886 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700887 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800888 .extra1 = &zero,
889 .extra2 = &two,
890 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800891#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800892 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 .procname = "ngroups_max",
894 .data = &ngroups_max,
895 .maxlen = sizeof (int),
896 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800897 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 },
Dan Ballard73efc032011-10-31 17:11:20 -0700899 {
900 .procname = "cap_last_cap",
901 .data = (void *)&cap_last_cap,
902 .maxlen = sizeof(int),
903 .mode = 0444,
904 .proc_handler = proc_dointvec,
905 },
Don Zickus58687ac2010-05-07 17:11:44 -0400906#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500907 {
Don Zickus58687ac2010-05-07 17:11:44 -0400908 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200909 .data = &watchdog_user_enabled,
910 .maxlen = sizeof(int),
911 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700912 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700913 .extra1 = &zero,
914 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400915 },
916 {
917 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700918 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400919 .maxlen = sizeof(int),
920 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700921 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800922 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400923 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500924 },
Don Zickus2508ce12010-05-07 17:11:46 -0400925 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700926 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200927 .data = &nmi_watchdog_user_enabled,
928 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200929 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700930 .proc_handler = proc_nmi_watchdog,
931 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700932 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700933 },
934 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700935 .procname = "watchdog_cpumask",
936 .data = &watchdog_cpumask_bits,
937 .maxlen = NR_CPUS,
938 .mode = 0644,
939 .proc_handler = proc_watchdog_cpumask,
940 },
941#ifdef CONFIG_SOFTLOCKUP_DETECTOR
942 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700943 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200944 .data = &soft_watchdog_user_enabled,
945 .maxlen = sizeof(int),
946 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700947 .proc_handler = proc_soft_watchdog,
948 .extra1 = &zero,
949 .extra2 = &one,
950 },
951 {
Don Zickus2508ce12010-05-07 17:11:46 -0400952 .procname = "softlockup_panic",
953 .data = &softlockup_panic,
954 .maxlen = sizeof(int),
955 .mode = 0644,
956 .proc_handler = proc_dointvec_minmax,
957 .extra1 = &zero,
958 .extra2 = &one,
959 },
Aaron Tomlined235872014-06-23 13:22:05 -0700960#ifdef CONFIG_SMP
961 {
962 .procname = "softlockup_all_cpu_backtrace",
963 .data = &sysctl_softlockup_all_cpu_backtrace,
964 .maxlen = sizeof(int),
965 .mode = 0644,
966 .proc_handler = proc_dointvec_minmax,
967 .extra1 = &zero,
968 .extra2 = &one,
969 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700970#endif /* CONFIG_SMP */
971#endif
972#ifdef CONFIG_HARDLOCKUP_DETECTOR
973 {
974 .procname = "hardlockup_panic",
975 .data = &hardlockup_panic,
976 .maxlen = sizeof(int),
977 .mode = 0644,
978 .proc_handler = proc_dointvec_minmax,
979 .extra1 = &zero,
980 .extra2 = &one,
981 },
982#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800983 {
984 .procname = "hardlockup_all_cpu_backtrace",
985 .data = &sysctl_hardlockup_all_cpu_backtrace,
986 .maxlen = sizeof(int),
987 .mode = 0644,
988 .proc_handler = proc_dointvec_minmax,
989 .extra1 = &zero,
990 .extra2 = &one,
991 },
Aaron Tomlined235872014-06-23 13:22:05 -0700992#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500993#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700994#endif
995
Don Zickus5dc30552010-11-29 17:07:17 -0500996#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
997 {
998 .procname = "unknown_nmi_panic",
999 .data = &unknown_nmi_panic,
1000 .maxlen = sizeof (int),
1001 .mode = 0644,
1002 .proc_handler = proc_dointvec,
1003 },
Don Zickus504d7cf2010-02-12 17:19:19 -05001004#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005#if defined(CONFIG_X86)
1006 {
Don Zickus8da5add2006-09-26 10:52:27 +02001007 .procname = "panic_on_unrecovered_nmi",
1008 .data = &panic_on_unrecovered_nmi,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001011 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001012 },
1013 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001014 .procname = "panic_on_io_nmi",
1015 .data = &panic_on_io_nmi,
1016 .maxlen = sizeof(int),
1017 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001018 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001019 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001020#ifdef CONFIG_DEBUG_STACKOVERFLOW
1021 {
1022 .procname = "panic_on_stackoverflow",
1023 .data = &sysctl_panic_on_stackoverflow,
1024 .maxlen = sizeof(int),
1025 .mode = 0644,
1026 .proc_handler = proc_dointvec,
1027 },
1028#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001029 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 .procname = "bootloader_type",
1031 .data = &bootloader_type,
1032 .maxlen = sizeof (int),
1033 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001034 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001036 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001037 .procname = "bootloader_version",
1038 .data = &bootloader_version,
1039 .maxlen = sizeof (int),
1040 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001042 },
1043 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001044 .procname = "io_delay_type",
1045 .data = &io_delay_type,
1046 .maxlen = sizeof(int),
1047 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001048 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001049 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001051#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 .procname = "randomize_va_space",
1054 .data = &randomize_va_space,
1055 .maxlen = sizeof(int),
1056 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001057 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001059#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001060#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001061 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001062 .procname = "spin_retry",
1063 .data = &spin_retry,
1064 .maxlen = sizeof (int),
1065 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001066 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001067 },
1068#endif
Len Brown673d5b42007-07-28 03:33:16 -04001069#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001070 {
Pavel Machekc255d842006-02-20 18:27:58 -08001071 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001072 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001073 .maxlen = sizeof (unsigned long),
1074 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001075 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001076 },
1077#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301078#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001079 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001080 .procname = "ignore-unaligned-usertrap",
1081 .data = &no_unaligned_warning,
1082 .maxlen = sizeof (int),
1083 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001084 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001085 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301086#endif
1087#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001088 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001089 .procname = "unaligned-dump-stack",
1090 .data = &unaligned_dump_stack,
1091 .maxlen = sizeof (int),
1092 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001093 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001094 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001095#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001096#ifdef CONFIG_DETECT_HUNG_TASK
1097 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001098 .procname = "hung_task_panic",
1099 .data = &sysctl_hung_task_panic,
1100 .maxlen = sizeof(int),
1101 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001102 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001103 .extra1 = &zero,
1104 .extra2 = &one,
1105 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001106 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001107 .procname = "hung_task_check_count",
1108 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001109 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001110 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001111 .proc_handler = proc_dointvec_minmax,
1112 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001113 },
1114 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001115 .procname = "hung_task_timeout_secs",
1116 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001117 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001118 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001119 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001120 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001121 },
1122 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001123 .procname = "hung_task_check_interval_secs",
1124 .data = &sysctl_hung_task_check_interval_secs,
1125 .maxlen = sizeof(unsigned long),
1126 .mode = 0644,
1127 .proc_handler = proc_dohung_task_timeout_secs,
1128 .extra2 = &hung_task_timeout_max,
1129 },
1130 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001131 .procname = "hung_task_warnings",
1132 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001133 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001134 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001135 .proc_handler = proc_dointvec_minmax,
1136 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001137 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001138#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001139#ifdef CONFIG_RT_MUTEXES
1140 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001141 .procname = "max_lock_depth",
1142 .data = &max_lock_depth,
1143 .maxlen = sizeof(int),
1144 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001145 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001146 },
1147#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001148 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001149 .procname = "poweroff_cmd",
1150 .data = &poweroff_cmd,
1151 .maxlen = POWEROFF_CMD_PATH_LEN,
1152 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001153 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001154 },
David Howells0b77f5b2008-04-29 01:01:32 -07001155#ifdef CONFIG_KEYS
1156 {
David Howells0b77f5b2008-04-29 01:01:32 -07001157 .procname = "keys",
1158 .mode = 0555,
1159 .child = key_sysctls,
1160 },
1161#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001162#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001163 /*
1164 * User-space scripts rely on the existence of this file
1165 * as a feature check for perf_events being enabled.
1166 *
1167 * So it's an ABI, do not remove!
1168 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001169 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001170 .procname = "perf_event_paranoid",
1171 .data = &sysctl_perf_event_paranoid,
1172 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001173 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001174 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001175 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001176 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001177 .procname = "perf_event_mlock_kb",
1178 .data = &sysctl_perf_event_mlock,
1179 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001180 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001181 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001182 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001183 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001184 .procname = "perf_event_max_sample_rate",
1185 .data = &sysctl_perf_event_sample_rate,
1186 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001187 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001188 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001189 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001190 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001191 {
1192 .procname = "perf_cpu_time_max_percent",
1193 .data = &sysctl_perf_cpu_time_max_percent,
1194 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1195 .mode = 0644,
1196 .proc_handler = perf_cpu_time_max_percent_handler,
1197 .extra1 = &zero,
1198 .extra2 = &one_hundred,
1199 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001200 {
1201 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001202 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001203 .maxlen = sizeof(sysctl_perf_event_max_stack),
1204 .mode = 0644,
1205 .proc_handler = perf_event_max_stack_handler,
1206 .extra1 = &zero,
1207 .extra2 = &six_hundred_forty_kb,
1208 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001209 {
1210 .procname = "perf_event_max_contexts_per_stack",
1211 .data = &sysctl_perf_event_max_contexts_per_stack,
1212 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1213 .mode = 0644,
1214 .proc_handler = perf_event_max_stack_handler,
1215 .extra1 = &zero,
1216 .extra2 = &one_thousand,
1217 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001218#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001219 {
1220 .procname = "panic_on_warn",
1221 .data = &panic_on_warn,
1222 .maxlen = sizeof(int),
1223 .mode = 0644,
1224 .proc_handler = proc_dointvec_minmax,
1225 .extra1 = &zero,
1226 .extra2 = &one,
1227 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001228#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1229 {
1230 .procname = "timer_migration",
1231 .data = &sysctl_timer_migration,
1232 .maxlen = sizeof(unsigned int),
1233 .mode = 0644,
1234 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001235 .extra1 = &zero,
1236 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001237 },
1238#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001239#ifdef CONFIG_BPF_SYSCALL
1240 {
1241 .procname = "unprivileged_bpf_disabled",
1242 .data = &sysctl_unprivileged_bpf_disabled,
1243 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1244 .mode = 0644,
1245 /* only handle a transition from default "0" to "1" */
1246 .proc_handler = proc_dointvec_minmax,
1247 .extra1 = &one,
1248 .extra2 = &one,
1249 },
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001250 {
1251 .procname = "bpf_stats_enabled",
1252 .data = &sysctl_bpf_stats_enabled,
1253 .maxlen = sizeof(sysctl_bpf_stats_enabled),
1254 .mode = 0644,
1255 .proc_handler = proc_dointvec_minmax_bpf_stats,
1256 .extra1 = &zero,
1257 .extra2 = &one,
1258 },
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08001259#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001260#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1261 {
1262 .procname = "panic_on_rcu_stall",
1263 .data = &sysctl_panic_on_rcu_stall,
1264 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1265 .mode = 0644,
1266 .proc_handler = proc_dointvec_minmax,
1267 .extra1 = &zero,
1268 .extra2 = &one,
1269 },
1270#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001271#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1272 {
1273 .procname = "stack_erasing",
1274 .data = NULL,
1275 .maxlen = sizeof(int),
1276 .mode = 0600,
1277 .proc_handler = stack_erasing_sysctl,
1278 .extra1 = &zero,
1279 .extra2 = &one,
1280 },
1281#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001282 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283};
1284
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001285static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 .procname = "overcommit_memory",
1288 .data = &sysctl_overcommit_memory,
1289 .maxlen = sizeof(sysctl_overcommit_memory),
1290 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001291 .proc_handler = proc_dointvec_minmax,
1292 .extra1 = &zero,
1293 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 },
1295 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001296 .procname = "panic_on_oom",
1297 .data = &sysctl_panic_on_oom,
1298 .maxlen = sizeof(sysctl_panic_on_oom),
1299 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001300 .proc_handler = proc_dointvec_minmax,
1301 .extra1 = &zero,
1302 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001303 },
1304 {
David Rientjesfe071d72007-10-16 23:25:56 -07001305 .procname = "oom_kill_allocating_task",
1306 .data = &sysctl_oom_kill_allocating_task,
1307 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1308 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001309 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001310 },
1311 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001312 .procname = "oom_dump_tasks",
1313 .data = &sysctl_oom_dump_tasks,
1314 .maxlen = sizeof(sysctl_oom_dump_tasks),
1315 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001316 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001317 },
1318 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 .procname = "overcommit_ratio",
1320 .data = &sysctl_overcommit_ratio,
1321 .maxlen = sizeof(sysctl_overcommit_ratio),
1322 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001323 .proc_handler = overcommit_ratio_handler,
1324 },
1325 {
1326 .procname = "overcommit_kbytes",
1327 .data = &sysctl_overcommit_kbytes,
1328 .maxlen = sizeof(sysctl_overcommit_kbytes),
1329 .mode = 0644,
1330 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 },
1332 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 .procname = "page-cluster",
1334 .data = &page_cluster,
1335 .maxlen = sizeof(int),
1336 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001337 .proc_handler = proc_dointvec_minmax,
1338 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 },
1340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .procname = "dirty_background_ratio",
1342 .data = &dirty_background_ratio,
1343 .maxlen = sizeof(dirty_background_ratio),
1344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001345 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 .extra1 = &zero,
1347 .extra2 = &one_hundred,
1348 },
1349 {
David Rientjes2da02992009-01-06 14:39:31 -08001350 .procname = "dirty_background_bytes",
1351 .data = &dirty_background_bytes,
1352 .maxlen = sizeof(dirty_background_bytes),
1353 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001354 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001355 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001356 },
1357 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 .procname = "dirty_ratio",
1359 .data = &vm_dirty_ratio,
1360 .maxlen = sizeof(vm_dirty_ratio),
1361 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001362 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 .extra1 = &zero,
1364 .extra2 = &one_hundred,
1365 },
1366 {
David Rientjes2da02992009-01-06 14:39:31 -08001367 .procname = "dirty_bytes",
1368 .data = &vm_dirty_bytes,
1369 .maxlen = sizeof(vm_dirty_bytes),
1370 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001371 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001372 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001373 },
1374 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001376 .data = &dirty_writeback_interval,
1377 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001379 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 },
1381 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001383 .data = &dirty_expire_interval,
1384 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001386 .proc_handler = proc_dointvec_minmax,
1387 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 },
1389 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001390 .procname = "dirtytime_expire_seconds",
1391 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001392 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001393 .mode = 0644,
1394 .proc_handler = dirtytime_interval_handler,
1395 .extra1 = &zero,
1396 },
1397 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 .procname = "swappiness",
1399 .data = &vm_swappiness,
1400 .maxlen = sizeof(vm_swappiness),
1401 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001402 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 .extra1 = &zero,
1404 .extra2 = &one_hundred,
1405 },
1406#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001409 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 .maxlen = sizeof(unsigned long),
1411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001412 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001413 },
1414#ifdef CONFIG_NUMA
1415 {
1416 .procname = "nr_hugepages_mempolicy",
1417 .data = NULL,
1418 .maxlen = sizeof(unsigned long),
1419 .mode = 0644,
1420 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001421 },
Kemi Wang45180852017-11-15 17:38:22 -08001422 {
1423 .procname = "numa_stat",
1424 .data = &sysctl_vm_numa_stat,
1425 .maxlen = sizeof(int),
1426 .mode = 0644,
1427 .proc_handler = sysctl_vm_numa_stat_handler,
1428 .extra1 = &zero,
1429 .extra2 = &one,
1430 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001431#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 .procname = "hugetlb_shm_group",
1434 .data = &sysctl_hugetlb_shm_group,
1435 .maxlen = sizeof(gid_t),
1436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001437 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 },
Adam Litke54f9f802007-10-16 01:26:20 -07001439 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001440 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001441 .data = NULL,
1442 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001443 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001444 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001445 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446#endif
1447 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 .procname = "lowmem_reserve_ratio",
1449 .data = &sysctl_lowmem_reserve_ratio,
1450 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1451 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001452 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 },
1454 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001455 .procname = "drop_caches",
1456 .data = &sysctl_drop_caches,
1457 .maxlen = sizeof(int),
1458 .mode = 0644,
1459 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001460 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001461 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001462 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001463#ifdef CONFIG_COMPACTION
1464 {
1465 .procname = "compact_memory",
1466 .data = &sysctl_compact_memory,
1467 .maxlen = sizeof(int),
1468 .mode = 0200,
1469 .proc_handler = sysctl_compaction_handler,
1470 },
Mel Gorman5e771902010-05-24 14:32:31 -07001471 {
1472 .procname = "extfrag_threshold",
1473 .data = &sysctl_extfrag_threshold,
1474 .maxlen = sizeof(int),
1475 .mode = 0644,
Matthew Wilcox6b7e5ca2019-03-05 15:43:41 -08001476 .proc_handler = proc_dointvec_minmax,
Mel Gorman5e771902010-05-24 14:32:31 -07001477 .extra1 = &min_extfrag_threshold,
1478 .extra2 = &max_extfrag_threshold,
1479 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001480 {
1481 .procname = "compact_unevictable_allowed",
1482 .data = &sysctl_compact_unevictable_allowed,
1483 .maxlen = sizeof(int),
1484 .mode = 0644,
1485 .proc_handler = proc_dointvec,
1486 .extra1 = &zero,
1487 .extra2 = &one,
1488 },
Mel Gorman5e771902010-05-24 14:32:31 -07001489
Mel Gorman76ab0f52010-05-24 14:32:28 -07001490#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001491 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 .procname = "min_free_kbytes",
1493 .data = &min_free_kbytes,
1494 .maxlen = sizeof(min_free_kbytes),
1495 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001496 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 .extra1 = &zero,
1498 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001499 {
Mel Gorman1c308442018-12-28 00:35:52 -08001500 .procname = "watermark_boost_factor",
1501 .data = &watermark_boost_factor,
1502 .maxlen = sizeof(watermark_boost_factor),
1503 .mode = 0644,
1504 .proc_handler = watermark_boost_factor_sysctl_handler,
1505 .extra1 = &zero,
1506 },
1507 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001508 .procname = "watermark_scale_factor",
1509 .data = &watermark_scale_factor,
1510 .maxlen = sizeof(watermark_scale_factor),
1511 .mode = 0644,
1512 .proc_handler = watermark_scale_factor_sysctl_handler,
1513 .extra1 = &one,
1514 .extra2 = &one_thousand,
1515 },
1516 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001517 .procname = "percpu_pagelist_fraction",
1518 .data = &percpu_pagelist_fraction,
1519 .maxlen = sizeof(percpu_pagelist_fraction),
1520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001521 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001522 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001523 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524#ifdef CONFIG_MMU
1525 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 .procname = "max_map_count",
1527 .data = &sysctl_max_map_count,
1528 .maxlen = sizeof(sysctl_max_map_count),
1529 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001530 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001531 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001533#else
1534 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001535 .procname = "nr_trim_pages",
1536 .data = &sysctl_nr_trim_pages,
1537 .maxlen = sizeof(sysctl_nr_trim_pages),
1538 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001539 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001540 .extra1 = &zero,
1541 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542#endif
1543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 .procname = "laptop_mode",
1545 .data = &laptop_mode,
1546 .maxlen = sizeof(laptop_mode),
1547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001548 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 },
1550 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 .procname = "block_dump",
1552 .data = &block_dump,
1553 .maxlen = sizeof(block_dump),
1554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001555 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 .extra1 = &zero,
1557 },
1558 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 .procname = "vfs_cache_pressure",
1560 .data = &sysctl_vfs_cache_pressure,
1561 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1562 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001563 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 .extra1 = &zero,
1565 },
1566#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1567 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 .procname = "legacy_va_layout",
1569 .data = &sysctl_legacy_va_layout,
1570 .maxlen = sizeof(sysctl_legacy_va_layout),
1571 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001572 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 .extra1 = &zero,
1574 },
1575#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001576#ifdef CONFIG_NUMA
1577 {
Christoph Lameter17436602006-01-18 17:42:32 -08001578 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001579 .data = &node_reclaim_mode,
1580 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001581 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001582 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001583 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001584 },
Christoph Lameter96146342006-07-03 00:24:13 -07001585 {
Christoph Lameter96146342006-07-03 00:24:13 -07001586 .procname = "min_unmapped_ratio",
1587 .data = &sysctl_min_unmapped_ratio,
1588 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1589 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001590 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001591 .extra1 = &zero,
1592 .extra2 = &one_hundred,
1593 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001594 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001595 .procname = "min_slab_ratio",
1596 .data = &sysctl_min_slab_ratio,
1597 .maxlen = sizeof(sysctl_min_slab_ratio),
1598 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001599 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001600 .extra1 = &zero,
1601 .extra2 = &one_hundred,
1602 },
Christoph Lameter17436602006-01-18 17:42:32 -08001603#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001604#ifdef CONFIG_SMP
1605 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001606 .procname = "stat_interval",
1607 .data = &sysctl_stat_interval,
1608 .maxlen = sizeof(sysctl_stat_interval),
1609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001610 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001611 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001612 {
1613 .procname = "stat_refresh",
1614 .data = NULL,
1615 .maxlen = 0,
1616 .mode = 0600,
1617 .proc_handler = vmstat_refresh,
1618 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001619#endif
David Howells6e141542009-12-15 19:27:45 +00001620#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001621 {
Eric Parised032182007-06-28 15:55:21 -04001622 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001623 .data = &dac_mmap_min_addr,
1624 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001626 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001627 },
David Howells6e141542009-12-15 19:27:45 +00001628#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001629#ifdef CONFIG_NUMA
1630 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001631 .procname = "numa_zonelist_order",
1632 .data = &numa_zonelist_order,
1633 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1634 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001635 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001636 },
1637#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001638#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001639 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001640 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001641 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001642#ifdef CONFIG_X86_32
1643 .data = &vdso32_enabled,
1644 .maxlen = sizeof(vdso32_enabled),
1645#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001646 .data = &vdso_enabled,
1647 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001648#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001649 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001650 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001651 .extra1 = &zero,
1652 },
1653#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001654#ifdef CONFIG_HIGHMEM
1655 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001656 .procname = "highmem_is_dirtyable",
1657 .data = &vm_highmem_is_dirtyable,
1658 .maxlen = sizeof(vm_highmem_is_dirtyable),
1659 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001660 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001661 .extra1 = &zero,
1662 .extra2 = &one,
1663 },
1664#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001665#ifdef CONFIG_MEMORY_FAILURE
1666 {
Andi Kleen6a460792009-09-16 11:50:15 +02001667 .procname = "memory_failure_early_kill",
1668 .data = &sysctl_memory_failure_early_kill,
1669 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001671 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001672 .extra1 = &zero,
1673 .extra2 = &one,
1674 },
1675 {
Andi Kleen6a460792009-09-16 11:50:15 +02001676 .procname = "memory_failure_recovery",
1677 .data = &sysctl_memory_failure_recovery,
1678 .maxlen = sizeof(sysctl_memory_failure_recovery),
1679 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001680 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001681 .extra1 = &zero,
1682 .extra2 = &one,
1683 },
1684#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001685 {
1686 .procname = "user_reserve_kbytes",
1687 .data = &sysctl_user_reserve_kbytes,
1688 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1689 .mode = 0644,
1690 .proc_handler = proc_doulongvec_minmax,
1691 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001692 {
1693 .procname = "admin_reserve_kbytes",
1694 .data = &sysctl_admin_reserve_kbytes,
1695 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1696 .mode = 0644,
1697 .proc_handler = proc_doulongvec_minmax,
1698 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001699#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1700 {
1701 .procname = "mmap_rnd_bits",
1702 .data = &mmap_rnd_bits,
1703 .maxlen = sizeof(mmap_rnd_bits),
1704 .mode = 0600,
1705 .proc_handler = proc_dointvec_minmax,
1706 .extra1 = (void *)&mmap_rnd_bits_min,
1707 .extra2 = (void *)&mmap_rnd_bits_max,
1708 },
1709#endif
1710#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1711 {
1712 .procname = "mmap_rnd_compat_bits",
1713 .data = &mmap_rnd_compat_bits,
1714 .maxlen = sizeof(mmap_rnd_compat_bits),
1715 .mode = 0600,
1716 .proc_handler = proc_dointvec_minmax,
1717 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1718 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1719 },
1720#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001721 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722};
1723
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001724static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 .procname = "inode-nr",
1727 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001728 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001730 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 },
1732 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 .procname = "inode-state",
1734 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001735 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001737 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 },
1739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 .procname = "file-nr",
1741 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001742 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001744 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 },
1746 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 .procname = "file-max",
1748 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001749 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001751 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 },
1753 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001754 .procname = "nr_open",
1755 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001756 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001757 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001758 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001759 .extra1 = &sysctl_nr_open_min,
1760 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001761 },
1762 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 .procname = "dentry-state",
1764 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001765 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001767 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 },
1769 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 .procname = "overflowuid",
1771 .data = &fs_overflowuid,
1772 .maxlen = sizeof(int),
1773 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001774 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 .extra1 = &minolduid,
1776 .extra2 = &maxolduid,
1777 },
1778 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 .procname = "overflowgid",
1780 .data = &fs_overflowgid,
1781 .maxlen = sizeof(int),
1782 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001783 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 .extra1 = &minolduid,
1785 .extra2 = &maxolduid,
1786 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001787#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 .procname = "leases-enable",
1790 .data = &leases_enable,
1791 .maxlen = sizeof(int),
1792 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001793 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001795#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796#ifdef CONFIG_DNOTIFY
1797 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 .procname = "dir-notify-enable",
1799 .data = &dir_notify_enable,
1800 .maxlen = sizeof(int),
1801 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001802 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 },
1804#endif
1805#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001806#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 .procname = "lease-break-time",
1809 .data = &lease_break_time,
1810 .maxlen = sizeof(int),
1811 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001812 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001814#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001815#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 .procname = "aio-nr",
1818 .data = &aio_nr,
1819 .maxlen = sizeof(aio_nr),
1820 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001821 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 },
1823 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 .procname = "aio-max-nr",
1825 .data = &aio_max_nr,
1826 .maxlen = sizeof(aio_max_nr),
1827 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001828 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001830#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001831#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001832 {
Robert Love0399cb02005-07-13 12:38:18 -04001833 .procname = "inotify",
1834 .mode = 0555,
1835 .child = inotify_table,
1836 },
1837#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001838#ifdef CONFIG_EPOLL
1839 {
1840 .procname = "epoll",
1841 .mode = 0555,
1842 .child = epoll_table,
1843 },
1844#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001846 {
Kees Cook800179c2012-07-25 17:29:07 -07001847 .procname = "protected_symlinks",
1848 .data = &sysctl_protected_symlinks,
1849 .maxlen = sizeof(int),
1850 .mode = 0600,
1851 .proc_handler = proc_dointvec_minmax,
1852 .extra1 = &zero,
1853 .extra2 = &one,
1854 },
1855 {
1856 .procname = "protected_hardlinks",
1857 .data = &sysctl_protected_hardlinks,
1858 .maxlen = sizeof(int),
1859 .mode = 0600,
1860 .proc_handler = proc_dointvec_minmax,
1861 .extra1 = &zero,
1862 .extra2 = &one,
1863 },
1864 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001865 .procname = "protected_fifos",
1866 .data = &sysctl_protected_fifos,
1867 .maxlen = sizeof(int),
1868 .mode = 0600,
1869 .proc_handler = proc_dointvec_minmax,
1870 .extra1 = &zero,
1871 .extra2 = &two,
1872 },
1873 {
1874 .procname = "protected_regular",
1875 .data = &sysctl_protected_regular,
1876 .maxlen = sizeof(int),
1877 .mode = 0600,
1878 .proc_handler = proc_dointvec_minmax,
1879 .extra1 = &zero,
1880 .extra2 = &two,
1881 },
1882 {
Alan Coxd6e71142005-06-23 00:09:43 -07001883 .procname = "suid_dumpable",
1884 .data = &suid_dumpable,
1885 .maxlen = sizeof(int),
1886 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001887 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001888 .extra1 = &zero,
1889 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001890 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001891#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1892 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001893 .procname = "binfmt_misc",
1894 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001895 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001896 },
1897#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001898 {
Jens Axboeff9da692010-06-03 14:54:39 +02001899 .procname = "pipe-max-size",
1900 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001901 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001902 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001903 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001904 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001905 {
1906 .procname = "pipe-user-pages-hard",
1907 .data = &pipe_user_pages_hard,
1908 .maxlen = sizeof(pipe_user_pages_hard),
1909 .mode = 0644,
1910 .proc_handler = proc_doulongvec_minmax,
1911 },
1912 {
1913 .procname = "pipe-user-pages-soft",
1914 .data = &pipe_user_pages_soft,
1915 .maxlen = sizeof(pipe_user_pages_soft),
1916 .mode = 0644,
1917 .proc_handler = proc_doulongvec_minmax,
1918 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001919 {
1920 .procname = "mount-max",
1921 .data = &sysctl_mount_max,
1922 .maxlen = sizeof(unsigned int),
1923 .mode = 0644,
1924 .proc_handler = proc_dointvec_minmax,
1925 .extra1 = &one,
1926 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001927 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928};
1929
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001930static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001931#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001932 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001933 .procname = "exception-trace",
1934 .data = &show_unhandled_signals,
1935 .maxlen = sizeof(int),
1936 .mode = 0644,
1937 .proc_handler = proc_dointvec
1938 },
1939#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001940#if defined(CONFIG_OPTPROBES)
1941 {
1942 .procname = "kprobes-optimization",
1943 .data = &sysctl_kprobes_optimization,
1944 .maxlen = sizeof(int),
1945 .mode = 0644,
1946 .proc_handler = proc_kprobes_optimization_handler,
1947 .extra1 = &zero,
1948 .extra2 = &one,
1949 },
1950#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001951 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952};
1953
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001954static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001955 { }
Robert Love0eeca282005-07-12 17:06:03 -04001956};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001958int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001959{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001960 struct ctl_table_header *hdr;
1961
1962 hdr = register_sysctl_table(sysctl_base_table);
1963 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001964 return 0;
1965}
1966
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001967#endif /* CONFIG_SYSCTL */
1968
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969/*
1970 * /proc/sys support
1971 */
1972
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001973#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974
Kees Cookf8808302014-06-06 14:37:17 -07001975static int _proc_do_string(char *data, int maxlen, int write,
1976 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001977 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001978{
1979 size_t len;
1980 char __user *p;
1981 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001982
1983 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001984 *lenp = 0;
1985 return 0;
1986 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001987
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001988 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001989 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1990 /* Only continue writes not past the end of buffer. */
1991 len = strlen(data);
1992 if (len > maxlen - 1)
1993 len = maxlen - 1;
1994
1995 if (*ppos > len)
1996 return 0;
1997 len = *ppos;
1998 } else {
1999 /* Start writing from beginning of buffer. */
2000 len = 0;
2001 }
2002
Kees Cook2ca9bb42014-06-06 14:37:18 -07002003 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002004 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002005 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002006 if (get_user(c, p++))
2007 return -EFAULT;
2008 if (c == 0 || c == '\n')
2009 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002010 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002011 }
Kees Cookf8808302014-06-06 14:37:17 -07002012 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002013 } else {
2014 len = strlen(data);
2015 if (len > maxlen)
2016 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002017
2018 if (*ppos > len) {
2019 *lenp = 0;
2020 return 0;
2021 }
2022
2023 data += *ppos;
2024 len -= *ppos;
2025
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002026 if (len > *lenp)
2027 len = *lenp;
2028 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002029 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002030 return -EFAULT;
2031 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002032 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002033 return -EFAULT;
2034 len++;
2035 }
2036 *lenp = len;
2037 *ppos += len;
2038 }
2039 return 0;
2040}
2041
Kees Cookf4aacea2014-06-06 14:37:19 -07002042static void warn_sysctl_write(struct ctl_table *table)
2043{
2044 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2045 "This will not be supported in the future. To silence this\n"
2046 "warning, set kernel.sysctl_writes_strict = -1\n",
2047 current->comm, table->procname);
2048}
2049
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002051 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002052 * @ppos: file position
2053 * @table: the sysctl table
2054 *
2055 * Returns true if the first position is non-zero and the sysctl_writes_strict
2056 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002057 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002058 */
2059static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2060 struct ctl_table *table)
2061{
2062 if (!*ppos)
2063 return false;
2064
2065 switch (sysctl_writes_strict) {
2066 case SYSCTL_WRITES_STRICT:
2067 return true;
2068 case SYSCTL_WRITES_WARN:
2069 warn_sysctl_write(table);
2070 return false;
2071 default:
2072 return false;
2073 }
2074}
2075
2076/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 * proc_dostring - read a string sysctl
2078 * @table: the sysctl table
2079 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 * @buffer: the user buffer
2081 * @lenp: the size of the user buffer
2082 * @ppos: file position
2083 *
2084 * Reads/writes a string from/to the user buffer. If the kernel
2085 * buffer provided is not large enough to hold the string, the
2086 * string is truncated. The copied string is %NULL-terminated.
2087 * If the string is being read by the user process, it is copied
2088 * and a newline '\n' is added. It is truncated if the buffer is
2089 * not large enough.
2090 *
2091 * Returns 0 on success.
2092 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002093int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 void __user *buffer, size_t *lenp, loff_t *ppos)
2095{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002096 if (write)
2097 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002098
Kees Cookf8808302014-06-06 14:37:17 -07002099 return _proc_do_string((char *)(table->data), table->maxlen, write,
2100 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101}
2102
Amerigo Wang00b7c332010-05-05 00:26:45 +00002103static size_t proc_skip_spaces(char **buf)
2104{
2105 size_t ret;
2106 char *tmp = skip_spaces(*buf);
2107 ret = tmp - *buf;
2108 *buf = tmp;
2109 return ret;
2110}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002112static void proc_skip_char(char **buf, size_t *size, const char v)
2113{
2114 while (*size) {
2115 if (**buf != v)
2116 break;
2117 (*size)--;
2118 (*buf)++;
2119 }
2120}
2121
Christian Brauner7f2923c2019-03-07 16:29:40 -08002122/**
2123 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2124 * fail on overflow
2125 *
2126 * @cp: kernel buffer containing the string to parse
2127 * @endp: pointer to store the trailing characters
2128 * @base: the base to use
2129 * @res: where the parsed integer will be stored
2130 *
2131 * In case of success 0 is returned and @res will contain the parsed integer,
2132 * @endp will hold any trailing characters.
2133 * This function will fail the parse on overflow. If there wasn't an overflow
2134 * the function will defer the decision what characters count as invalid to the
2135 * caller.
2136 */
2137static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2138 unsigned long *res)
2139{
2140 unsigned long long result;
2141 unsigned int rv;
2142
2143 cp = _parse_integer_fixup_radix(cp, &base);
2144 rv = _parse_integer(cp, base, &result);
2145 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2146 return -ERANGE;
2147
2148 cp += rv;
2149
2150 if (endp)
2151 *endp = (char *)cp;
2152
2153 *res = (unsigned long)result;
2154 return 0;
2155}
2156
Amerigo Wang00b7c332010-05-05 00:26:45 +00002157#define TMPBUFLEN 22
2158/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002159 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002160 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002161 * @buf: a kernel buffer
2162 * @size: size of the kernel buffer
2163 * @val: this is where the number will be stored
2164 * @neg: set to %TRUE if number is negative
2165 * @perm_tr: a vector which contains the allowed trailers
2166 * @perm_tr_len: size of the perm_tr vector
2167 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002168 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002169 * In case of success %0 is returned and @buf and @size are updated with
2170 * the amount of bytes read. If @tr is non-NULL and a trailing
2171 * character exists (size is non-zero after returning from this
2172 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002173 */
2174static int proc_get_long(char **buf, size_t *size,
2175 unsigned long *val, bool *neg,
2176 const char *perm_tr, unsigned perm_tr_len, char *tr)
2177{
2178 int len;
2179 char *p, tmp[TMPBUFLEN];
2180
2181 if (!*size)
2182 return -EINVAL;
2183
2184 len = *size;
2185 if (len > TMPBUFLEN - 1)
2186 len = TMPBUFLEN - 1;
2187
2188 memcpy(tmp, *buf, len);
2189
2190 tmp[len] = 0;
2191 p = tmp;
2192 if (*p == '-' && *size > 1) {
2193 *neg = true;
2194 p++;
2195 } else
2196 *neg = false;
2197 if (!isdigit(*p))
2198 return -EINVAL;
2199
Christian Brauner7f2923c2019-03-07 16:29:40 -08002200 if (strtoul_lenient(p, &p, 0, val))
2201 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002202
2203 len = p - tmp;
2204
2205 /* We don't know if the next char is whitespace thus we may accept
2206 * invalid integers (e.g. 1234...a) or two integers instead of one
2207 * (e.g. 123...1). So lets not allow such large numbers. */
2208 if (len == TMPBUFLEN - 1)
2209 return -EINVAL;
2210
2211 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2212 return -EINVAL;
2213
2214 if (tr && (len < *size))
2215 *tr = *p;
2216
2217 *buf += len;
2218 *size -= len;
2219
2220 return 0;
2221}
2222
2223/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002224 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002225 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002226 * @buf: the user buffer
2227 * @size: the size of the user buffer
2228 * @val: the integer to be converted
2229 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002230 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002231 * In case of success %0 is returned and @buf and @size are updated with
2232 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002233 */
2234static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2235 bool neg)
2236{
2237 int len;
2238 char tmp[TMPBUFLEN], *p = tmp;
2239
2240 sprintf(p, "%s%lu", neg ? "-" : "", val);
2241 len = strlen(tmp);
2242 if (len > *size)
2243 len = *size;
2244 if (copy_to_user(*buf, tmp, len))
2245 return -EFAULT;
2246 *size -= len;
2247 *buf += len;
2248 return 0;
2249}
2250#undef TMPBUFLEN
2251
2252static int proc_put_char(void __user **buf, size_t *size, char c)
2253{
2254 if (*size) {
2255 char __user **buffer = (char __user **)buf;
2256 if (put_user(c, *buffer))
2257 return -EFAULT;
2258 (*size)--, (*buffer)++;
2259 *buf = *buffer;
2260 }
2261 return 0;
2262}
2263
2264static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 int *valp,
2266 int write, void *data)
2267{
2268 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002269 if (*negp) {
2270 if (*lvalp > (unsigned long) INT_MAX + 1)
2271 return -EINVAL;
2272 *valp = -*lvalp;
2273 } else {
2274 if (*lvalp > (unsigned long) INT_MAX)
2275 return -EINVAL;
2276 *valp = *lvalp;
2277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 } else {
2279 int val = *valp;
2280 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002281 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002282 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002284 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 *lvalp = (unsigned long)val;
2286 }
2287 }
2288 return 0;
2289}
2290
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002291static int do_proc_douintvec_conv(unsigned long *lvalp,
2292 unsigned int *valp,
2293 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002294{
2295 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002296 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002297 return -EINVAL;
2298 *valp = *lvalp;
2299 } else {
2300 unsigned int val = *valp;
2301 *lvalp = (unsigned long)val;
2302 }
2303 return 0;
2304}
2305
Amerigo Wang00b7c332010-05-05 00:26:45 +00002306static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2307
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002308static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002309 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002310 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002311 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 int write, void *data),
2313 void *data)
2314{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002315 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002316 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002317 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
Amerigo Wang00b7c332010-05-05 00:26:45 +00002319 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 *lenp = 0;
2321 return 0;
2322 }
2323
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002324 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 vleft = table->maxlen / sizeof(*i);
2326 left = *lenp;
2327
2328 if (!conv)
2329 conv = do_proc_dointvec_conv;
2330
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002332 if (proc_first_pos_non_zero_ignore(ppos, table))
2333 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002334
Amerigo Wang00b7c332010-05-05 00:26:45 +00002335 if (left > PAGE_SIZE - 1)
2336 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002337 p = kbuf = memdup_user_nul(buffer, left);
2338 if (IS_ERR(kbuf))
2339 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002340 }
2341
2342 for (; left && vleft--; i++, first=0) {
2343 unsigned long lval;
2344 bool neg;
2345
2346 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002347 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002348
J. R. Okajima563b0462010-05-25 16:10:14 -07002349 if (!left)
2350 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002351 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002352 proc_wspace_sep,
2353 sizeof(proc_wspace_sep), NULL);
2354 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002356 if (conv(&neg, &lval, i, 1, data)) {
2357 err = -EINVAL;
2358 break;
2359 }
2360 } else {
2361 if (conv(&neg, &lval, i, 0, data)) {
2362 err = -EINVAL;
2363 break;
2364 }
2365 if (!first)
2366 err = proc_put_char(&buffer, &left, '\t');
2367 if (err)
2368 break;
2369 err = proc_put_long(&buffer, &left, lval, neg);
2370 if (err)
2371 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 }
2373 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002374
2375 if (!write && !first && left && !err)
2376 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002377 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002378 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002379 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002380 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002381 if (first)
2382 return err ? : -EINVAL;
2383 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002385out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002387 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388}
2389
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002390static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002391 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002392 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002393 int write, void *data),
2394 void *data)
2395{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002396 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002397 buffer, lenp, ppos, conv, data);
2398}
2399
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002400static int do_proc_douintvec_w(unsigned int *tbl_data,
2401 struct ctl_table *table,
2402 void __user *buffer,
2403 size_t *lenp, loff_t *ppos,
2404 int (*conv)(unsigned long *lvalp,
2405 unsigned int *valp,
2406 int write, void *data),
2407 void *data)
2408{
2409 unsigned long lval;
2410 int err = 0;
2411 size_t left;
2412 bool neg;
2413 char *kbuf = NULL, *p;
2414
2415 left = *lenp;
2416
2417 if (proc_first_pos_non_zero_ignore(ppos, table))
2418 goto bail_early;
2419
2420 if (left > PAGE_SIZE - 1)
2421 left = PAGE_SIZE - 1;
2422
2423 p = kbuf = memdup_user_nul(buffer, left);
2424 if (IS_ERR(kbuf))
2425 return -EINVAL;
2426
2427 left -= proc_skip_spaces(&p);
2428 if (!left) {
2429 err = -EINVAL;
2430 goto out_free;
2431 }
2432
2433 err = proc_get_long(&p, &left, &lval, &neg,
2434 proc_wspace_sep,
2435 sizeof(proc_wspace_sep), NULL);
2436 if (err || neg) {
2437 err = -EINVAL;
2438 goto out_free;
2439 }
2440
2441 if (conv(&lval, tbl_data, 1, data)) {
2442 err = -EINVAL;
2443 goto out_free;
2444 }
2445
2446 if (!err && left)
2447 left -= proc_skip_spaces(&p);
2448
2449out_free:
2450 kfree(kbuf);
2451 if (err)
2452 return -EINVAL;
2453
2454 return 0;
2455
2456 /* This is in keeping with old __do_proc_dointvec() */
2457bail_early:
2458 *ppos += *lenp;
2459 return err;
2460}
2461
2462static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2463 size_t *lenp, loff_t *ppos,
2464 int (*conv)(unsigned long *lvalp,
2465 unsigned int *valp,
2466 int write, void *data),
2467 void *data)
2468{
2469 unsigned long lval;
2470 int err = 0;
2471 size_t left;
2472
2473 left = *lenp;
2474
2475 if (conv(&lval, tbl_data, 0, data)) {
2476 err = -EINVAL;
2477 goto out;
2478 }
2479
2480 err = proc_put_long(&buffer, &left, lval, false);
2481 if (err || !left)
2482 goto out;
2483
2484 err = proc_put_char(&buffer, &left, '\n');
2485
2486out:
2487 *lenp -= left;
2488 *ppos += *lenp;
2489
2490 return err;
2491}
2492
2493static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2494 int write, void __user *buffer,
2495 size_t *lenp, loff_t *ppos,
2496 int (*conv)(unsigned long *lvalp,
2497 unsigned int *valp,
2498 int write, void *data),
2499 void *data)
2500{
2501 unsigned int *i, vleft;
2502
2503 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2504 *lenp = 0;
2505 return 0;
2506 }
2507
2508 i = (unsigned int *) tbl_data;
2509 vleft = table->maxlen / sizeof(*i);
2510
2511 /*
2512 * Arrays are not supported, keep this simple. *Do not* add
2513 * support for them.
2514 */
2515 if (vleft != 1) {
2516 *lenp = 0;
2517 return -EINVAL;
2518 }
2519
2520 if (!conv)
2521 conv = do_proc_douintvec_conv;
2522
2523 if (write)
2524 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2525 conv, data);
2526 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2527}
2528
2529static int do_proc_douintvec(struct ctl_table *table, int write,
2530 void __user *buffer, size_t *lenp, loff_t *ppos,
2531 int (*conv)(unsigned long *lvalp,
2532 unsigned int *valp,
2533 int write, void *data),
2534 void *data)
2535{
2536 return __do_proc_douintvec(table->data, table, write,
2537 buffer, lenp, ppos, conv, data);
2538}
2539
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540/**
2541 * proc_dointvec - read a vector of integers
2542 * @table: the sysctl table
2543 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 * @buffer: the user buffer
2545 * @lenp: the size of the user buffer
2546 * @ppos: file position
2547 *
2548 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2549 * values from/to the user buffer, treated as an ASCII string.
2550 *
2551 * Returns 0 on success.
2552 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002553int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 void __user *buffer, size_t *lenp, loff_t *ppos)
2555{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002556 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2557}
2558
2559/**
2560 * proc_douintvec - read a vector of unsigned integers
2561 * @table: the sysctl table
2562 * @write: %TRUE if this is a write to the sysctl file
2563 * @buffer: the user buffer
2564 * @lenp: the size of the user buffer
2565 * @ppos: file position
2566 *
2567 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2568 * values from/to the user buffer, treated as an ASCII string.
2569 *
2570 * Returns 0 on success.
2571 */
2572int proc_douintvec(struct ctl_table *table, int write,
2573 void __user *buffer, size_t *lenp, loff_t *ppos)
2574{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002575 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2576 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577}
2578
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002579/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002580 * Taint values can only be increased
2581 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002582 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002583static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002584 void __user *buffer, size_t *lenp, loff_t *ppos)
2585{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002586 struct ctl_table t;
2587 unsigned long tmptaint = get_taint();
2588 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002589
Bastian Blank91fcd412007-04-23 14:41:14 -07002590 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002591 return -EPERM;
2592
Andi Kleen25ddbb12008-10-15 22:01:41 -07002593 t = *table;
2594 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002595 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002596 if (err < 0)
2597 return err;
2598
2599 if (write) {
2600 /*
2601 * Poor man's atomic or. Not worth adding a primitive
2602 * to everyone's atomic.h for this
2603 */
2604 int i;
2605 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2606 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302607 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002608 }
2609 }
2610
2611 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002612}
2613
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002614#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002615static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002616 void __user *buffer, size_t *lenp, loff_t *ppos)
2617{
2618 if (write && !capable(CAP_SYS_ADMIN))
2619 return -EPERM;
2620
2621 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2622}
2623#endif
2624
Waiman Long24704f32018-04-10 16:35:38 -07002625/**
2626 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2627 * @min: pointer to minimum allowable value
2628 * @max: pointer to maximum allowable value
2629 *
2630 * The do_proc_dointvec_minmax_conv_param structure provides the
2631 * minimum and maximum values for doing range checking for those sysctl
2632 * parameters that use the proc_dointvec_minmax() handler.
2633 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634struct do_proc_dointvec_minmax_conv_param {
2635 int *min;
2636 int *max;
2637};
2638
Amerigo Wang00b7c332010-05-05 00:26:45 +00002639static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2640 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 int write, void *data)
2642{
2643 struct do_proc_dointvec_minmax_conv_param *param = data;
2644 if (write) {
2645 int val = *negp ? -*lvalp : *lvalp;
2646 if ((param->min && *param->min > val) ||
2647 (param->max && *param->max < val))
2648 return -EINVAL;
2649 *valp = val;
2650 } else {
2651 int val = *valp;
2652 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002653 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002654 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002656 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 *lvalp = (unsigned long)val;
2658 }
2659 }
2660 return 0;
2661}
2662
2663/**
2664 * proc_dointvec_minmax - read a vector of integers with min/max values
2665 * @table: the sysctl table
2666 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 * @buffer: the user buffer
2668 * @lenp: the size of the user buffer
2669 * @ppos: file position
2670 *
2671 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2672 * values from/to the user buffer, treated as an ASCII string.
2673 *
2674 * This routine will ensure the values are within the range specified by
2675 * table->extra1 (min) and table->extra2 (max).
2676 *
Waiman Long24704f32018-04-10 16:35:38 -07002677 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002679int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 void __user *buffer, size_t *lenp, loff_t *ppos)
2681{
2682 struct do_proc_dointvec_minmax_conv_param param = {
2683 .min = (int *) table->extra1,
2684 .max = (int *) table->extra2,
2685 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002686 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 do_proc_dointvec_minmax_conv, &param);
2688}
2689
Waiman Long24704f32018-04-10 16:35:38 -07002690/**
2691 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2692 * @min: pointer to minimum allowable value
2693 * @max: pointer to maximum allowable value
2694 *
2695 * The do_proc_douintvec_minmax_conv_param structure provides the
2696 * minimum and maximum values for doing range checking for those sysctl
2697 * parameters that use the proc_douintvec_minmax() handler.
2698 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002699struct do_proc_douintvec_minmax_conv_param {
2700 unsigned int *min;
2701 unsigned int *max;
2702};
2703
2704static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2705 unsigned int *valp,
2706 int write, void *data)
2707{
2708 struct do_proc_douintvec_minmax_conv_param *param = data;
2709
2710 if (write) {
2711 unsigned int val = *lvalp;
2712
Joe Lawrencefb910c42017-11-17 15:29:28 -08002713 if (*lvalp > UINT_MAX)
2714 return -EINVAL;
2715
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002716 if ((param->min && *param->min > val) ||
2717 (param->max && *param->max < val))
2718 return -ERANGE;
2719
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002720 *valp = val;
2721 } else {
2722 unsigned int val = *valp;
2723 *lvalp = (unsigned long) val;
2724 }
2725
2726 return 0;
2727}
2728
2729/**
2730 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2731 * @table: the sysctl table
2732 * @write: %TRUE if this is a write to the sysctl file
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
2735 * @ppos: file position
2736 *
2737 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2738 * values from/to the user buffer, treated as an ASCII string. Negative
2739 * strings are not allowed.
2740 *
2741 * This routine will ensure the values are within the range specified by
2742 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2743 * check for UINT_MAX to avoid having to support wrap around uses from
2744 * userspace.
2745 *
Waiman Long24704f32018-04-10 16:35:38 -07002746 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002747 */
2748int proc_douintvec_minmax(struct ctl_table *table, int write,
2749 void __user *buffer, size_t *lenp, loff_t *ppos)
2750{
2751 struct do_proc_douintvec_minmax_conv_param param = {
2752 .min = (unsigned int *) table->extra1,
2753 .max = (unsigned int *) table->extra2,
2754 };
2755 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2756 do_proc_douintvec_minmax_conv, &param);
2757}
2758
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002759static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2760 unsigned int *valp,
2761 int write, void *data)
2762{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002763 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002764 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002765
Joe Lawrencefb910c42017-11-17 15:29:28 -08002766 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002767 if (val == 0)
2768 return -EINVAL;
2769
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002770 *valp = val;
2771 } else {
2772 unsigned int val = *valp;
2773 *lvalp = (unsigned long) val;
2774 }
2775
2776 return 0;
2777}
2778
Eric Biggers319e0a22018-02-06 15:41:49 -08002779static int proc_dopipe_max_size(struct ctl_table *table, int write,
2780 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002781{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002782 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002783 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002784}
2785
Kees Cook54b50192012-07-30 14:39:18 -07002786static void validate_coredump_safety(void)
2787{
Alex Kelly046d6622012-10-04 17:15:23 -07002788#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002789 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002790 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002791 printk(KERN_WARNING
2792"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2793"Pipe handler or fully qualified core dump path required.\n"
2794"Set kernel.core_pattern before fs.suid_dumpable.\n"
2795 );
Kees Cook54b50192012-07-30 14:39:18 -07002796 }
Alex Kelly046d6622012-10-04 17:15:23 -07002797#endif
Kees Cook54b50192012-07-30 14:39:18 -07002798}
2799
2800static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2801 void __user *buffer, size_t *lenp, loff_t *ppos)
2802{
2803 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2804 if (!error)
2805 validate_coredump_safety();
2806 return error;
2807}
2808
Alex Kelly046d6622012-10-04 17:15:23 -07002809#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002810static int proc_dostring_coredump(struct ctl_table *table, int write,
2811 void __user *buffer, size_t *lenp, loff_t *ppos)
2812{
2813 int error = proc_dostring(table, write, buffer, lenp, ppos);
2814 if (!error)
2815 validate_coredump_safety();
2816 return error;
2817}
Alex Kelly046d6622012-10-04 17:15:23 -07002818#endif
Kees Cook54b50192012-07-30 14:39:18 -07002819
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002820static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 void __user *buffer,
2822 size_t *lenp, loff_t *ppos,
2823 unsigned long convmul,
2824 unsigned long convdiv)
2825{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002826 unsigned long *i, *min, *max;
2827 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002828 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002829 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002830
2831 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 *lenp = 0;
2833 return 0;
2834 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002835
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002836 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 min = (unsigned long *) table->extra1;
2838 max = (unsigned long *) table->extra2;
2839 vleft = table->maxlen / sizeof(unsigned long);
2840 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002841
2842 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002843 if (proc_first_pos_non_zero_ignore(ppos, table))
2844 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002845
Amerigo Wang00b7c332010-05-05 00:26:45 +00002846 if (left > PAGE_SIZE - 1)
2847 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002848 p = kbuf = memdup_user_nul(buffer, left);
2849 if (IS_ERR(kbuf))
2850 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002851 }
2852
Eric Dumazet27b3d802010-10-07 12:59:29 -07002853 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002854 unsigned long val;
2855
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002857 bool neg;
2858
Al Viro70f6cbb2015-12-24 00:13:10 -05002859 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08002860 if (!left)
2861 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002862
Al Viro70f6cbb2015-12-24 00:13:10 -05002863 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002864 proc_wspace_sep,
2865 sizeof(proc_wspace_sep), NULL);
2866 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 break;
2868 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002870 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 if ((min && val < *min) || (max && val > *max))
2872 continue;
2873 *i = val;
2874 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002875 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002876 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002877 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002878 if (err)
2879 break;
2880 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002881 err = proc_put_long(&buffer, &left, val, false);
2882 if (err)
2883 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 }
2885 }
2886
Amerigo Wang00b7c332010-05-05 00:26:45 +00002887 if (!write && !first && left && !err)
2888 err = proc_put_char(&buffer, &left, '\n');
2889 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002890 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002892 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002893 if (first)
2894 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002897out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002899 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900}
2901
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002902static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002903 void __user *buffer,
2904 size_t *lenp, loff_t *ppos,
2905 unsigned long convmul,
2906 unsigned long convdiv)
2907{
2908 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002909 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002910}
2911
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912/**
2913 * proc_doulongvec_minmax - read a vector of long integers with min/max values
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
2918 * @ppos: file position
2919 *
2920 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2921 * values from/to the user buffer, treated as an ASCII string.
2922 *
2923 * This routine will ensure the values are within the range specified by
2924 * table->extra1 (min) and table->extra2 (max).
2925 *
2926 * Returns 0 on success.
2927 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002928int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 void __user *buffer, size_t *lenp, loff_t *ppos)
2930{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002931 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932}
2933
2934/**
2935 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
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
2940 * @ppos: file position
2941 *
2942 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2943 * values from/to the user buffer, treated as an ASCII string. The values
2944 * are treated as milliseconds, and converted to jiffies when they are stored.
2945 *
2946 * This routine will ensure the values are within the range specified by
2947 * table->extra1 (min) and table->extra2 (max).
2948 *
2949 * Returns 0 on success.
2950 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002951int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 void __user *buffer,
2953 size_t *lenp, loff_t *ppos)
2954{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002955 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 lenp, ppos, HZ, 1000l);
2957}
2958
2959
Amerigo Wang00b7c332010-05-05 00:26:45 +00002960static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 int *valp,
2962 int write, void *data)
2963{
2964 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002965 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002966 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2968 } else {
2969 int val = *valp;
2970 unsigned long lval;
2971 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002972 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002973 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002975 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 lval = (unsigned long)val;
2977 }
2978 *lvalp = lval / HZ;
2979 }
2980 return 0;
2981}
2982
Amerigo Wang00b7c332010-05-05 00:26:45 +00002983static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 int *valp,
2985 int write, void *data)
2986{
2987 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002988 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2989 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2991 } else {
2992 int val = *valp;
2993 unsigned long lval;
2994 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002995 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002996 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002998 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 lval = (unsigned long)val;
3000 }
3001 *lvalp = jiffies_to_clock_t(lval);
3002 }
3003 return 0;
3004}
3005
Amerigo Wang00b7c332010-05-05 00:26:45 +00003006static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 int *valp,
3008 int write, void *data)
3009{
3010 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02003011 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3012
3013 if (jif > INT_MAX)
3014 return 1;
3015 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 } else {
3017 int val = *valp;
3018 unsigned long lval;
3019 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003020 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003021 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003023 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 lval = (unsigned long)val;
3025 }
3026 *lvalp = jiffies_to_msecs(lval);
3027 }
3028 return 0;
3029}
3030
3031/**
3032 * proc_dointvec_jiffies - read a vector of integers as seconds
3033 * @table: the sysctl table
3034 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 * @buffer: the user buffer
3036 * @lenp: the size of the user buffer
3037 * @ppos: file position
3038 *
3039 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3040 * values from/to the user buffer, treated as an ASCII string.
3041 * The values read are assumed to be in seconds, and are converted into
3042 * jiffies.
3043 *
3044 * Returns 0 on success.
3045 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003046int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 void __user *buffer, size_t *lenp, loff_t *ppos)
3048{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003049 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 do_proc_dointvec_jiffies_conv,NULL);
3051}
3052
3053/**
3054 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3055 * @table: the sysctl table
3056 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 * @buffer: the user buffer
3058 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003059 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 *
3061 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3062 * values from/to the user buffer, treated as an ASCII string.
3063 * The values read are assumed to be in 1/USER_HZ seconds, and
3064 * are converted into jiffies.
3065 *
3066 * Returns 0 on success.
3067 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003068int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 void __user *buffer, size_t *lenp, loff_t *ppos)
3070{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003071 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 do_proc_dointvec_userhz_jiffies_conv,NULL);
3073}
3074
3075/**
3076 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3077 * @table: the sysctl table
3078 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 * @buffer: the user buffer
3080 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003081 * @ppos: file position
3082 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 *
3084 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3085 * values from/to the user buffer, treated as an ASCII string.
3086 * The values read are assumed to be in 1/1000 seconds, and
3087 * are converted into jiffies.
3088 *
3089 * Returns 0 on success.
3090 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003091int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 void __user *buffer, size_t *lenp, loff_t *ppos)
3093{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003094 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 do_proc_dointvec_ms_jiffies_conv, NULL);
3096}
3097
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003098static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003099 void __user *buffer, size_t *lenp, loff_t *ppos)
3100{
3101 struct pid *new_pid;
3102 pid_t tmp;
3103 int r;
3104
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003105 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003106
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003107 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003108 lenp, ppos, NULL, NULL);
3109 if (r || !write)
3110 return r;
3111
3112 new_pid = find_get_pid(tmp);
3113 if (!new_pid)
3114 return -ESRCH;
3115
3116 put_pid(xchg(&cad_pid, new_pid));
3117 return 0;
3118}
3119
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003120/**
3121 * proc_do_large_bitmap - read/write from/to a large bitmap
3122 * @table: the sysctl table
3123 * @write: %TRUE if this is a write to the sysctl file
3124 * @buffer: the user buffer
3125 * @lenp: the size of the user buffer
3126 * @ppos: file position
3127 *
3128 * The bitmap is stored at table->data and the bitmap length (in bits)
3129 * in table->maxlen.
3130 *
3131 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3132 * large bitmaps may be represented in a compact manner. Writing into
3133 * the file will clear the bitmap then update it with the given input.
3134 *
3135 * Returns 0 on success.
3136 */
3137int proc_do_large_bitmap(struct ctl_table *table, int write,
3138 void __user *buffer, size_t *lenp, loff_t *ppos)
3139{
3140 int err = 0;
3141 bool first = 1;
3142 size_t left = *lenp;
3143 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003144 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003145 unsigned long *tmp_bitmap = NULL;
3146 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3147
WANG Cong122ff242014-05-12 16:04:53 -07003148 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003149 *lenp = 0;
3150 return 0;
3151 }
3152
3153 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003154 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003155
3156 if (left > PAGE_SIZE - 1)
3157 left = PAGE_SIZE - 1;
3158
Al Viro70f6cbb2015-12-24 00:13:10 -05003159 p = kbuf = memdup_user_nul(buffer, left);
3160 if (IS_ERR(kbuf))
3161 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003162
Kees Cook6396bb22018-06-12 14:03:40 -07003163 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3164 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003165 GFP_KERNEL);
3166 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003167 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003168 return -ENOMEM;
3169 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003170 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003171 while (!err && left) {
3172 unsigned long val_a, val_b;
3173 bool neg;
3174
Al Viro70f6cbb2015-12-24 00:13:10 -05003175 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003176 sizeof(tr_a), &c);
3177 if (err)
3178 break;
3179 if (val_a >= bitmap_len || neg) {
3180 err = -EINVAL;
3181 break;
3182 }
3183
3184 val_b = val_a;
3185 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003186 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003187 left--;
3188 }
3189
3190 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003191 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003192 &neg, tr_b, sizeof(tr_b),
3193 &c);
3194 if (err)
3195 break;
3196 if (val_b >= bitmap_len || neg ||
3197 val_a > val_b) {
3198 err = -EINVAL;
3199 break;
3200 }
3201 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003202 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003203 left--;
3204 }
3205 }
3206
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003207 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003208 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003209 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003210 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003211 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003212 } else {
3213 unsigned long bit_a, bit_b = 0;
3214
3215 while (left) {
3216 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3217 if (bit_a >= bitmap_len)
3218 break;
3219 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3220 bit_a + 1) - 1;
3221
3222 if (!first) {
3223 err = proc_put_char(&buffer, &left, ',');
3224 if (err)
3225 break;
3226 }
3227 err = proc_put_long(&buffer, &left, bit_a, false);
3228 if (err)
3229 break;
3230 if (bit_a != bit_b) {
3231 err = proc_put_char(&buffer, &left, '-');
3232 if (err)
3233 break;
3234 err = proc_put_long(&buffer, &left, bit_b, false);
3235 if (err)
3236 break;
3237 }
3238
3239 first = 0; bit_b++;
3240 }
3241 if (!err)
3242 err = proc_put_char(&buffer, &left, '\n');
3243 }
3244
3245 if (!err) {
3246 if (write) {
3247 if (*ppos)
3248 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3249 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003250 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003251 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003252 *lenp -= left;
3253 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003254 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003255
3256 kfree(tmp_bitmap);
3257 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003258}
3259
Jovi Zhang55610502011-01-12 17:00:45 -08003260#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003262int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 void __user *buffer, size_t *lenp, loff_t *ppos)
3264{
3265 return -ENOSYS;
3266}
3267
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003268int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 void __user *buffer, size_t *lenp, loff_t *ppos)
3270{
3271 return -ENOSYS;
3272}
3273
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003274int proc_douintvec(struct ctl_table *table, int write,
3275 void __user *buffer, size_t *lenp, loff_t *ppos)
3276{
3277 return -ENOSYS;
3278}
3279
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003280int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 void __user *buffer, size_t *lenp, loff_t *ppos)
3282{
3283 return -ENOSYS;
3284}
3285
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003286int proc_douintvec_minmax(struct ctl_table *table, int write,
3287 void __user *buffer, size_t *lenp, loff_t *ppos)
3288{
3289 return -ENOSYS;
3290}
3291
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003292int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 void __user *buffer, size_t *lenp, loff_t *ppos)
3294{
3295 return -ENOSYS;
3296}
3297
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003298int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299 void __user *buffer, size_t *lenp, loff_t *ppos)
3300{
3301 return -ENOSYS;
3302}
3303
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003304int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 void __user *buffer, size_t *lenp, loff_t *ppos)
3306{
3307 return -ENOSYS;
3308}
3309
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003310int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 void __user *buffer, size_t *lenp, loff_t *ppos)
3312{
3313 return -ENOSYS;
3314}
3315
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003316int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 void __user *buffer,
3318 size_t *lenp, loff_t *ppos)
3319{
3320 return -ENOSYS;
3321}
3322
3323
Jovi Zhang55610502011-01-12 17:00:45 -08003324#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003326#ifdef CONFIG_BPF_SYSCALL
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003327static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
3328 void __user *buffer, size_t *lenp,
3329 loff_t *ppos)
3330{
3331 int ret, bpf_stats = *(int *)table->data;
3332 struct ctl_table tmp = *table;
3333
3334 if (write && !capable(CAP_SYS_ADMIN))
3335 return -EPERM;
3336
3337 tmp.data = &bpf_stats;
3338 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3339 if (write && !ret) {
3340 *(int *)table->data = bpf_stats;
3341 if (bpf_stats)
3342 static_branch_enable(&bpf_stats_enabled_key);
3343 else
3344 static_branch_disable(&bpf_stats_enabled_key);
3345 }
3346 return ret;
3347}
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003348#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349/*
3350 * No sense putting this after each symbol definition, twice,
3351 * exception granted :-)
3352 */
3353EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003354EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355EXPORT_SYMBOL(proc_dointvec_jiffies);
3356EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003357EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3359EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3360EXPORT_SYMBOL(proc_dostring);
3361EXPORT_SYMBOL(proc_doulongvec_minmax);
3362EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);