blob: 14f30b4a1b64c237a2fa32ce067559e9881faa84 [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
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080070#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#include <asm/processor.h>
72
Andi Kleen29cbc782006-09-30 01:47:55 +020073#ifdef CONFIG_X86
74#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010075#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010076#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020077#endif
David Howellsd550bbd2012-03-28 18:30:03 +010078#ifdef CONFIG_SPARC
79#include <asm/setup.h>
80#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080081#ifdef CONFIG_BSD_PROCESS_ACCT
82#include <linux/acct.h>
83#endif
Dave Young4f0e0562010-03-10 15:24:09 -080084#ifdef CONFIG_RT_MUTEXES
85#include <linux/rtmutex.h>
86#endif
Dave Young2edf5e42010-03-10 15:24:10 -080087#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
88#include <linux/lockdep.h>
89#endif
Dave Young15485a42010-03-10 15:24:07 -080090#ifdef CONFIG_CHR_DEV_SG
91#include <scsi/sg.h>
92#endif
Alexander Popov964c9df2018-08-17 01:17:03 +030093#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
94#include <linux/stackleak.h>
95#endif
Don Zickus58687ac2010-05-07 17:11:44 -040096#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050097#include <linux/nmi.h>
98#endif
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#if defined(CONFIG_SYSCTL)
101
102/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700103extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700104#ifdef CONFIG_COREDUMP
105extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700107extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700108#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800111extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100112extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300113extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000114#ifndef CONFIG_MMU
115extern int sysctl_nr_trim_pages;
116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700118/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400119#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120static int sixty = 60;
121#endif
122
Aaron Tomlin270750db2014-01-20 17:34:13 +0000123static int __maybe_unused neg_one = -1;
124
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700125static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700126static int __maybe_unused one = 1;
127static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700128static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800129static unsigned long one_ul = 1;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700130static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700131static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700132#ifdef CONFIG_PRINTK
133static int ten_thousand = 10000;
134#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300135#ifdef CONFIG_PERF_EVENTS
136static int six_hundred_forty_kb = 640 * 1024;
137#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700138
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700139/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
140static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
143static int maxolduid = 65535;
144static int minolduid;
145
146static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700147static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700149/*
150 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
151 * and hung_task_check_interval_secs
152 */
Liu Hua80df2842014-04-07 15:38:57 -0700153#ifdef CONFIG_DETECT_HUNG_TASK
154static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
155#endif
156
Dave Youngd14f1722010-02-25 20:28:57 -0500157#ifdef CONFIG_INOTIFY_USER
158#include <linux/inotify.h>
159#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700160#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161#endif
162
163#ifdef __hppa__
164extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530165#endif
166
167#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168extern int unaligned_enabled;
169#endif
170
Jes Sorensend2b176e2006-02-28 09:42:23 -0800171#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800172extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800173#endif
174
Vineet Guptab6fca722013-01-09 20:06:28 +0530175#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
176extern int no_unaligned_warning;
177#endif
178
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700179#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700180
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700181/**
182 * enum sysctl_writes_mode - supported sysctl write modes
183 *
184 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
185 * to be written, and multiple writes on the same sysctl file descriptor
186 * will rewrite the sysctl value, regardless of file position. No warning
187 * is issued when the initial position is not 0.
188 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
189 * not 0.
190 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
191 * file position 0 and the value must be fully contained in the buffer
192 * sent to the write syscall. If dealing with strings respect the file
193 * position, but restrict this to the max length of the buffer, anything
194 * passed the max lenght will be ignored. Multiple writes will append
195 * to the buffer.
196 *
197 * These write modes control how current file position affects the behavior of
198 * updating sysctl values through the proc interface on each write.
199 */
200enum sysctl_writes_mode {
201 SYSCTL_WRITES_LEGACY = -1,
202 SYSCTL_WRITES_WARN = 0,
203 SYSCTL_WRITES_STRICT = 1,
204};
Kees Cookf4aacea2014-06-06 14:37:19 -0700205
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700206static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700207
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700208static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700209 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700210static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800211 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700212#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700213
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700214#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700215static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700216 void __user *buffer, size_t *lenp, loff_t *ppos);
217#endif
218
Kees Cook54b50192012-07-30 14:39:18 -0700219static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
220 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700221#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700222static int proc_dostring_coredump(struct ctl_table *table, int write,
223 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700224#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800225static int proc_dopipe_max_size(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexei Starovoitov3fcc55302019-02-27 18:30:44 -0800227#ifdef CONFIG_BPF_SYSCALL
Alexei Starovoitov492ecee2019-02-25 14:28:39 -0800228static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp,
230 loff_t *ppos);
Alexei Starovoitov3fcc55302019-02-27 18:30:44 -0800231#endif
Kees Cook54b50192012-07-30 14:39:18 -0700232
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700233#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700234/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100235static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700236
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700237static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700238 void __user *buffer, size_t *lenp,
239 loff_t *ppos)
240{
241 int error;
242
243 error = proc_dointvec(table, write, buffer, lenp, ppos);
244 if (error)
245 return error;
246
247 if (write)
248 sysrq_toggle_support(__sysrq_enabled);
249
250 return 0;
251}
252
253#endif
254
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700255static struct ctl_table kern_table[];
256static struct ctl_table vm_table[];
257static struct ctl_table fs_table[];
258static struct ctl_table debug_table[];
259static struct ctl_table dev_table[];
260extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800261#ifdef CONFIG_EPOLL
262extern struct ctl_table epoll_table[];
263#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800265#ifdef CONFIG_FW_LOADER_USER_HELPER
266extern struct ctl_table firmware_config_table[];
267#endif
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
270int sysctl_legacy_va_layout;
271#endif
272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273/* The default sysctl tables: */
274
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800275static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .procname = "kernel",
278 .mode = 0555,
279 .child = kern_table,
280 },
281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .procname = "vm",
283 .mode = 0555,
284 .child = vm_table,
285 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 .procname = "fs",
288 .mode = 0555,
289 .child = fs_table,
290 },
291 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 .procname = "debug",
293 .mode = 0555,
294 .child = debug_table,
295 },
296 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 .procname = "dev",
298 .mode = 0555,
299 .child = dev_table,
300 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700301 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302};
303
Ingo Molnar77e54a12007-07-09 18:52:00 +0200304#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100305static int min_sched_granularity_ns = 100000; /* 100 usecs */
306static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
307static int min_wakeup_granularity_ns; /* 0 usecs */
308static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200309#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100310static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
311static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200312#endif /* CONFIG_SMP */
313#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200314
Mel Gorman5e771902010-05-24 14:32:31 -0700315#ifdef CONFIG_COMPACTION
316static int min_extfrag_threshold;
317static int max_extfrag_threshold = 1000;
318#endif
319
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700320static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200321 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200322 .procname = "sched_child_runs_first",
323 .data = &sysctl_sched_child_runs_first,
324 .maxlen = sizeof(unsigned int),
325 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800326 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200327 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200328#ifdef CONFIG_SCHED_DEBUG
329 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100330 .procname = "sched_min_granularity_ns",
331 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200332 .maxlen = sizeof(unsigned int),
333 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800334 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100335 .extra1 = &min_sched_granularity_ns,
336 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200337 },
338 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200339 .procname = "sched_latency_ns",
340 .data = &sysctl_sched_latency,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800343 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200344 .extra1 = &min_sched_granularity_ns,
345 .extra2 = &max_sched_granularity_ns,
346 },
347 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200348 .procname = "sched_wakeup_granularity_ns",
349 .data = &sysctl_sched_wakeup_granularity,
350 .maxlen = sizeof(unsigned int),
351 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800352 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200353 .extra1 = &min_wakeup_granularity_ns,
354 .extra2 = &max_wakeup_granularity_ns,
355 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200356#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200357 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100358 .procname = "sched_tunable_scaling",
359 .data = &sysctl_sched_tunable_scaling,
360 .maxlen = sizeof(enum sched_tunable_scaling),
361 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800362 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100363 .extra1 = &min_sched_tunable_scaling,
364 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200365 },
366 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900367 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200368 .data = &sysctl_sched_migration_cost,
369 .maxlen = sizeof(unsigned int),
370 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800371 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200372 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100373 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100374 .procname = "sched_nr_migrate",
375 .data = &sysctl_sched_nr_migrate,
376 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100377 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800378 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100379 },
Mel Gormancb251762016-02-05 09:08:36 +0000380#ifdef CONFIG_SCHEDSTATS
381 {
382 .procname = "sched_schedstats",
383 .data = NULL,
384 .maxlen = sizeof(unsigned int),
385 .mode = 0644,
386 .proc_handler = sysctl_schedstats,
387 .extra1 = &zero,
388 .extra2 = &one,
389 },
390#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200391#endif /* CONFIG_SMP */
392#ifdef CONFIG_NUMA_BALANCING
393 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200394 .procname = "numa_balancing_scan_delay_ms",
395 .data = &sysctl_numa_balancing_scan_delay,
396 .maxlen = sizeof(unsigned int),
397 .mode = 0644,
398 .proc_handler = proc_dointvec,
399 },
400 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200401 .procname = "numa_balancing_scan_period_min_ms",
402 .data = &sysctl_numa_balancing_scan_period_min,
403 .maxlen = sizeof(unsigned int),
404 .mode = 0644,
405 .proc_handler = proc_dointvec,
406 },
407 {
408 .procname = "numa_balancing_scan_period_max_ms",
409 .data = &sysctl_numa_balancing_scan_period_max,
410 .maxlen = sizeof(unsigned int),
411 .mode = 0644,
412 .proc_handler = proc_dointvec,
413 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200414 {
415 .procname = "numa_balancing_scan_size_mb",
416 .data = &sysctl_numa_balancing_scan_size,
417 .maxlen = sizeof(unsigned int),
418 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400419 .proc_handler = proc_dointvec_minmax,
420 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200421 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100422 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800423 .procname = "numa_balancing",
424 .data = NULL, /* filled in by handler */
425 .maxlen = sizeof(unsigned int),
426 .mode = 0644,
427 .proc_handler = sysctl_numa_balancing,
428 .extra1 = &zero,
429 .extra2 = &one,
430 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200431#endif /* CONFIG_NUMA_BALANCING */
432#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200433 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100434 .procname = "sched_rt_period_us",
435 .data = &sysctl_sched_rt_period,
436 .maxlen = sizeof(unsigned int),
437 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800438 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100439 },
440 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100441 .procname = "sched_rt_runtime_us",
442 .data = &sysctl_sched_rt_runtime,
443 .maxlen = sizeof(int),
444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800445 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100446 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600447 {
448 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800449 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = sched_rr_handler,
453 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100454#ifdef CONFIG_SCHED_AUTOGROUP
455 {
456 .procname = "sched_autogroup_enabled",
457 .data = &sysctl_sched_autogroup_enabled,
458 .maxlen = sizeof(unsigned int),
459 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800460 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100461 .extra1 = &zero,
462 .extra2 = &one,
463 },
464#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700465#ifdef CONFIG_CFS_BANDWIDTH
466 {
467 .procname = "sched_cfs_bandwidth_slice_us",
468 .data = &sysctl_sched_cfs_bandwidth_slice,
469 .maxlen = sizeof(unsigned int),
470 .mode = 0644,
471 .proc_handler = proc_dointvec_minmax,
472 .extra1 = &one,
473 },
474#endif
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000475#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
476 {
477 .procname = "sched_energy_aware",
478 .data = &sysctl_sched_energy_aware,
479 .maxlen = sizeof(unsigned int),
480 .mode = 0644,
481 .proc_handler = sched_energy_aware_handler,
482 .extra1 = &zero,
483 .extra2 = &one,
484 },
485#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700486#ifdef CONFIG_PROVE_LOCKING
487 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700488 .procname = "prove_locking",
489 .data = &prove_locking,
490 .maxlen = sizeof(int),
491 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800492 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700493 },
494#endif
495#ifdef CONFIG_LOCK_STAT
496 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700497 .procname = "lock_stat",
498 .data = &lock_stat,
499 .maxlen = sizeof(int),
500 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800501 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700502 },
503#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200504 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 .procname = "panic",
506 .data = &panic_timeout,
507 .maxlen = sizeof(int),
508 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800509 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 },
Alex Kelly046d6622012-10-04 17:15:23 -0700511#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 .procname = "core_uses_pid",
514 .data = &core_uses_pid,
515 .maxlen = sizeof(int),
516 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800517 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 },
519 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .procname = "core_pattern",
521 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700522 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700524 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 },
Neil Hormana2939802009-09-23 15:56:56 -0700526 {
Neil Hormana2939802009-09-23 15:56:56 -0700527 .procname = "core_pipe_limit",
528 .data = &core_pipe_limit,
529 .maxlen = sizeof(unsigned int),
530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800531 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700532 },
Alex Kelly046d6622012-10-04 17:15:23 -0700533#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800534#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700537 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800538 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800539 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700541 {
542 .procname = "sysctl_writes_strict",
543 .data = &sysctl_writes_strict,
544 .maxlen = sizeof(int),
545 .mode = 0644,
546 .proc_handler = proc_dointvec_minmax,
547 .extra1 = &neg_one,
548 .extra2 = &one,
549 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800550#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100551#ifdef CONFIG_LATENCYTOP
552 {
553 .procname = "latencytop",
554 .data = &latencytop_enabled,
555 .maxlen = sizeof(int),
556 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000557 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100558 },
559#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560#ifdef CONFIG_BLK_DEV_INITRD
561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .procname = "real-root-dev",
563 .data = &real_root_dev,
564 .maxlen = sizeof(int),
565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800566 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 },
568#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700569 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700570 .procname = "print-fatal-signals",
571 .data = &print_fatal_signals,
572 .maxlen = sizeof(int),
573 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800574 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700575 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700576#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 .procname = "reboot-cmd",
579 .data = reboot_command,
580 .maxlen = 256,
581 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800582 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 },
584 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 .procname = "stop-a",
586 .data = &stop_a_enabled,
587 .maxlen = sizeof (int),
588 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800589 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 },
591 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .procname = "scons-poweroff",
593 .data = &scons_pwroff,
594 .maxlen = sizeof (int),
595 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800596 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 },
598#endif
David S. Miller08714202008-11-16 23:49:24 -0800599#ifdef CONFIG_SPARC64
600 {
David S. Miller08714202008-11-16 23:49:24 -0800601 .procname = "tsb-ratio",
602 .data = &sysctl_tsb_ratio,
603 .maxlen = sizeof (int),
604 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800605 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800606 },
607#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608#ifdef __hppa__
609 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 .procname = "soft-power",
611 .data = &pwrsw_enabled,
612 .maxlen = sizeof (int),
613 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800614 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530616#endif
617#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 .procname = "unaligned-trap",
620 .data = &unaligned_enabled,
621 .maxlen = sizeof (int),
622 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800623 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 },
625#endif
626 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 .procname = "ctrl-alt-del",
628 .data = &C_A_D,
629 .maxlen = sizeof(int),
630 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800631 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400633#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200634 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200635 .procname = "ftrace_enabled",
636 .data = &ftrace_enabled,
637 .maxlen = sizeof(int),
638 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800639 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200640 },
641#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500642#ifdef CONFIG_STACK_TRACER
643 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500644 .procname = "stack_tracer_enabled",
645 .data = &stack_tracer_enabled,
646 .maxlen = sizeof(int),
647 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800648 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500649 },
650#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400651#ifdef CONFIG_TRACING
652 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100653 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400654 .data = &ftrace_dump_on_oops,
655 .maxlen = sizeof(int),
656 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800657 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400658 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400659 {
660 .procname = "traceoff_on_warning",
661 .data = &__disable_trace_on_warning,
662 .maxlen = sizeof(__disable_trace_on_warning),
663 .mode = 0644,
664 .proc_handler = proc_dointvec,
665 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500666 {
667 .procname = "tracepoint_printk",
668 .data = &tracepoint_printk,
669 .maxlen = sizeof(tracepoint_printk),
670 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500671 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500672 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400673#endif
Dave Young2965faa2015-09-09 15:38:55 -0700674#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800675 {
676 .procname = "kexec_load_disabled",
677 .data = &kexec_load_disabled,
678 .maxlen = sizeof(int),
679 .mode = 0644,
680 /* only handle a transition from default "0" to "1" */
681 .proc_handler = proc_dointvec_minmax,
682 .extra1 = &one,
683 .extra2 = &one,
684 },
685#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200686#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 .procname = "modprobe",
689 .data = &modprobe_path,
690 .maxlen = KMOD_PATH_LEN,
691 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800692 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 },
Kees Cook3d433212009-04-02 15:49:29 -0700694 {
Kees Cook3d433212009-04-02 15:49:29 -0700695 .procname = "modules_disabled",
696 .data = &modules_disabled,
697 .maxlen = sizeof(int),
698 .mode = 0644,
699 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700701 .extra1 = &one,
702 .extra2 = &one,
703 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700705#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100708 .data = &uevent_helper,
709 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800711 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 },
Michael Marineau86d56132014-04-10 14:09:31 -0700713#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714#ifdef CONFIG_CHR_DEV_SG
715 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 .procname = "sg-big-buff",
717 .data = &sg_big_buff,
718 .maxlen = sizeof (int),
719 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800720 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 },
722#endif
723#ifdef CONFIG_BSD_PROCESS_ACCT
724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .procname = "acct",
726 .data = &acct_parm,
727 .maxlen = 3*sizeof(int),
728 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800729 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 },
731#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732#ifdef CONFIG_MAGIC_SYSRQ
733 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800735 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 .maxlen = sizeof (int),
737 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700738 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 },
740#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700741#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700744 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .maxlen = sizeof (int),
746 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800747 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700749#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700752 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 .maxlen = sizeof(int),
754 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700755 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 },
757 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .procname = "random",
759 .mode = 0555,
760 .child = random_table,
761 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 {
Eric Paris17f60a72011-04-01 17:07:50 -0400763 .procname = "usermodehelper",
764 .mode = 0555,
765 .child = usermodehelper_table,
766 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800767#ifdef CONFIG_FW_LOADER_USER_HELPER
768 {
769 .procname = "firmware_config",
770 .mode = 0555,
771 .child = firmware_config_table,
772 },
773#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400774 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 .procname = "overflowuid",
776 .data = &overflowuid,
777 .maxlen = sizeof(int),
778 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800779 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 .extra1 = &minolduid,
781 .extra2 = &maxolduid,
782 },
783 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 .procname = "overflowgid",
785 .data = &overflowgid,
786 .maxlen = sizeof(int),
787 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800788 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .extra1 = &minolduid,
790 .extra2 = &maxolduid,
791 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800792#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793#ifdef CONFIG_MATHEMU
794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 .procname = "ieee_emulation_warnings",
796 .data = &sysctl_ieee_emulation_warnings,
797 .maxlen = sizeof(int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 },
801#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200804 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 .maxlen = sizeof(int),
806 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800807 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 },
809#endif
810 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .procname = "pid_max",
812 .data = &pid_max,
813 .maxlen = sizeof (int),
814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800815 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 .extra1 = &pid_max_min,
817 .extra2 = &pid_max_max,
818 },
819 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 .procname = "panic_on_oops",
821 .data = &panic_on_oops,
822 .maxlen = sizeof(int),
823 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800824 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 },
Feng Tang81c9d432019-01-03 15:28:20 -0800826 {
827 .procname = "panic_print",
828 .data = &panic_print,
829 .maxlen = sizeof(unsigned long),
830 .mode = 0644,
831 .proc_handler = proc_doulongvec_minmax,
832 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800833#if defined CONFIG_PRINTK
834 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800835 .procname = "printk",
836 .data = &console_loglevel,
837 .maxlen = 4*sizeof(int),
838 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800839 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800840 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700843 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 .maxlen = sizeof(int),
845 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800846 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 },
848 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700850 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 .maxlen = sizeof(int),
852 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800853 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 },
Dave Youngaf913222009-09-22 16:43:33 -0700855 {
Dave Youngaf913222009-09-22 16:43:33 -0700856 .procname = "printk_delay",
857 .data = &printk_delay_msec,
858 .maxlen = sizeof(int),
859 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800860 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700861 .extra1 = &zero,
862 .extra2 = &ten_thousand,
863 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700865 .procname = "printk_devkmsg",
866 .data = devkmsg_log_str,
867 .maxlen = DEVKMSG_STR_MAX_SIZE,
868 .mode = 0644,
869 .proc_handler = devkmsg_sysctl_set_loglvl,
870 },
871 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800872 .procname = "dmesg_restrict",
873 .data = &dmesg_restrict,
874 .maxlen = sizeof(int),
875 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700876 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800877 .extra1 = &zero,
878 .extra2 = &one,
879 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800880 {
881 .procname = "kptr_restrict",
882 .data = &kptr_restrict,
883 .maxlen = sizeof(int),
884 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700885 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800886 .extra1 = &zero,
887 .extra2 = &two,
888 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800889#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800890 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 .procname = "ngroups_max",
892 .data = &ngroups_max,
893 .maxlen = sizeof (int),
894 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800895 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 },
Dan Ballard73efc032011-10-31 17:11:20 -0700897 {
898 .procname = "cap_last_cap",
899 .data = (void *)&cap_last_cap,
900 .maxlen = sizeof(int),
901 .mode = 0444,
902 .proc_handler = proc_dointvec,
903 },
Don Zickus58687ac2010-05-07 17:11:44 -0400904#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500905 {
Don Zickus58687ac2010-05-07 17:11:44 -0400906 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200907 .data = &watchdog_user_enabled,
908 .maxlen = sizeof(int),
909 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700910 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700911 .extra1 = &zero,
912 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400913 },
914 {
915 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700916 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400917 .maxlen = sizeof(int),
918 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700919 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800920 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400921 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500922 },
Don Zickus2508ce12010-05-07 17:11:46 -0400923 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700924 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200925 .data = &nmi_watchdog_user_enabled,
926 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200927 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700928 .proc_handler = proc_nmi_watchdog,
929 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700930 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700931 },
932 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700933 .procname = "watchdog_cpumask",
934 .data = &watchdog_cpumask_bits,
935 .maxlen = NR_CPUS,
936 .mode = 0644,
937 .proc_handler = proc_watchdog_cpumask,
938 },
939#ifdef CONFIG_SOFTLOCKUP_DETECTOR
940 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700941 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200942 .data = &soft_watchdog_user_enabled,
943 .maxlen = sizeof(int),
944 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700945 .proc_handler = proc_soft_watchdog,
946 .extra1 = &zero,
947 .extra2 = &one,
948 },
949 {
Don Zickus2508ce12010-05-07 17:11:46 -0400950 .procname = "softlockup_panic",
951 .data = &softlockup_panic,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = proc_dointvec_minmax,
955 .extra1 = &zero,
956 .extra2 = &one,
957 },
Aaron Tomlined235872014-06-23 13:22:05 -0700958#ifdef CONFIG_SMP
959 {
960 .procname = "softlockup_all_cpu_backtrace",
961 .data = &sysctl_softlockup_all_cpu_backtrace,
962 .maxlen = sizeof(int),
963 .mode = 0644,
964 .proc_handler = proc_dointvec_minmax,
965 .extra1 = &zero,
966 .extra2 = &one,
967 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700968#endif /* CONFIG_SMP */
969#endif
970#ifdef CONFIG_HARDLOCKUP_DETECTOR
971 {
972 .procname = "hardlockup_panic",
973 .data = &hardlockup_panic,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = proc_dointvec_minmax,
977 .extra1 = &zero,
978 .extra2 = &one,
979 },
980#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800981 {
982 .procname = "hardlockup_all_cpu_backtrace",
983 .data = &sysctl_hardlockup_all_cpu_backtrace,
984 .maxlen = sizeof(int),
985 .mode = 0644,
986 .proc_handler = proc_dointvec_minmax,
987 .extra1 = &zero,
988 .extra2 = &one,
989 },
Aaron Tomlined235872014-06-23 13:22:05 -0700990#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500991#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700992#endif
993
Don Zickus5dc30552010-11-29 17:07:17 -0500994#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
995 {
996 .procname = "unknown_nmi_panic",
997 .data = &unknown_nmi_panic,
998 .maxlen = sizeof (int),
999 .mode = 0644,
1000 .proc_handler = proc_dointvec,
1001 },
Don Zickus504d7cf2010-02-12 17:19:19 -05001002#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003#if defined(CONFIG_X86)
1004 {
Don Zickus8da5add2006-09-26 10:52:27 +02001005 .procname = "panic_on_unrecovered_nmi",
1006 .data = &panic_on_unrecovered_nmi,
1007 .maxlen = sizeof(int),
1008 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001010 },
1011 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001012 .procname = "panic_on_io_nmi",
1013 .data = &panic_on_io_nmi,
1014 .maxlen = sizeof(int),
1015 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001016 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001017 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001018#ifdef CONFIG_DEBUG_STACKOVERFLOW
1019 {
1020 .procname = "panic_on_stackoverflow",
1021 .data = &sysctl_panic_on_stackoverflow,
1022 .maxlen = sizeof(int),
1023 .mode = 0644,
1024 .proc_handler = proc_dointvec,
1025 },
1026#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001027 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 .procname = "bootloader_type",
1029 .data = &bootloader_type,
1030 .maxlen = sizeof (int),
1031 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001034 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001035 .procname = "bootloader_version",
1036 .data = &bootloader_version,
1037 .maxlen = sizeof (int),
1038 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001039 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001040 },
1041 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001042 .procname = "io_delay_type",
1043 .data = &io_delay_type,
1044 .maxlen = sizeof(int),
1045 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001046 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001047 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001049#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 .procname = "randomize_va_space",
1052 .data = &randomize_va_space,
1053 .maxlen = sizeof(int),
1054 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001055 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001057#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001058#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001059 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001060 .procname = "spin_retry",
1061 .data = &spin_retry,
1062 .maxlen = sizeof (int),
1063 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001064 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001065 },
1066#endif
Len Brown673d5b42007-07-28 03:33:16 -04001067#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001068 {
Pavel Machekc255d842006-02-20 18:27:58 -08001069 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001070 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001071 .maxlen = sizeof (unsigned long),
1072 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001073 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001074 },
1075#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301076#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001077 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001078 .procname = "ignore-unaligned-usertrap",
1079 .data = &no_unaligned_warning,
1080 .maxlen = sizeof (int),
1081 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001082 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001083 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301084#endif
1085#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001086 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001087 .procname = "unaligned-dump-stack",
1088 .data = &unaligned_dump_stack,
1089 .maxlen = sizeof (int),
1090 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001091 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001092 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001093#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001094#ifdef CONFIG_DETECT_HUNG_TASK
1095 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001096 .procname = "hung_task_panic",
1097 .data = &sysctl_hung_task_panic,
1098 .maxlen = sizeof(int),
1099 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001100 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001101 .extra1 = &zero,
1102 .extra2 = &one,
1103 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001104 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001105 .procname = "hung_task_check_count",
1106 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001107 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001108 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001109 .proc_handler = proc_dointvec_minmax,
1110 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001111 },
1112 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001113 .procname = "hung_task_timeout_secs",
1114 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001115 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001116 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001117 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001118 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001119 },
1120 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001121 .procname = "hung_task_check_interval_secs",
1122 .data = &sysctl_hung_task_check_interval_secs,
1123 .maxlen = sizeof(unsigned long),
1124 .mode = 0644,
1125 .proc_handler = proc_dohung_task_timeout_secs,
1126 .extra2 = &hung_task_timeout_max,
1127 },
1128 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001129 .procname = "hung_task_warnings",
1130 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001131 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001132 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001133 .proc_handler = proc_dointvec_minmax,
1134 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001135 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001136#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001137#ifdef CONFIG_RT_MUTEXES
1138 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001139 .procname = "max_lock_depth",
1140 .data = &max_lock_depth,
1141 .maxlen = sizeof(int),
1142 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001143 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001144 },
1145#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001146 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001147 .procname = "poweroff_cmd",
1148 .data = &poweroff_cmd,
1149 .maxlen = POWEROFF_CMD_PATH_LEN,
1150 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001151 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001152 },
David Howells0b77f5b2008-04-29 01:01:32 -07001153#ifdef CONFIG_KEYS
1154 {
David Howells0b77f5b2008-04-29 01:01:32 -07001155 .procname = "keys",
1156 .mode = 0555,
1157 .child = key_sysctls,
1158 },
1159#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001160#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001161 /*
1162 * User-space scripts rely on the existence of this file
1163 * as a feature check for perf_events being enabled.
1164 *
1165 * So it's an ABI, do not remove!
1166 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001167 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001168 .procname = "perf_event_paranoid",
1169 .data = &sysctl_perf_event_paranoid,
1170 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001171 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001172 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001173 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001174 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001175 .procname = "perf_event_mlock_kb",
1176 .data = &sysctl_perf_event_mlock,
1177 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001178 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001179 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001180 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001181 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001182 .procname = "perf_event_max_sample_rate",
1183 .data = &sysctl_perf_event_sample_rate,
1184 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001185 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001186 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001187 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001188 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001189 {
1190 .procname = "perf_cpu_time_max_percent",
1191 .data = &sysctl_perf_cpu_time_max_percent,
1192 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1193 .mode = 0644,
1194 .proc_handler = perf_cpu_time_max_percent_handler,
1195 .extra1 = &zero,
1196 .extra2 = &one_hundred,
1197 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001198 {
1199 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001200 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001201 .maxlen = sizeof(sysctl_perf_event_max_stack),
1202 .mode = 0644,
1203 .proc_handler = perf_event_max_stack_handler,
1204 .extra1 = &zero,
1205 .extra2 = &six_hundred_forty_kb,
1206 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001207 {
1208 .procname = "perf_event_max_contexts_per_stack",
1209 .data = &sysctl_perf_event_max_contexts_per_stack,
1210 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1211 .mode = 0644,
1212 .proc_handler = perf_event_max_stack_handler,
1213 .extra1 = &zero,
1214 .extra2 = &one_thousand,
1215 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001216#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001217 {
1218 .procname = "panic_on_warn",
1219 .data = &panic_on_warn,
1220 .maxlen = sizeof(int),
1221 .mode = 0644,
1222 .proc_handler = proc_dointvec_minmax,
1223 .extra1 = &zero,
1224 .extra2 = &one,
1225 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001226#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1227 {
1228 .procname = "timer_migration",
1229 .data = &sysctl_timer_migration,
1230 .maxlen = sizeof(unsigned int),
1231 .mode = 0644,
1232 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001233 .extra1 = &zero,
1234 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001235 },
1236#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001237#ifdef CONFIG_BPF_SYSCALL
1238 {
1239 .procname = "unprivileged_bpf_disabled",
1240 .data = &sysctl_unprivileged_bpf_disabled,
1241 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1242 .mode = 0644,
1243 /* only handle a transition from default "0" to "1" */
1244 .proc_handler = proc_dointvec_minmax,
1245 .extra1 = &one,
1246 .extra2 = &one,
1247 },
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001248 {
1249 .procname = "bpf_stats_enabled",
1250 .data = &sysctl_bpf_stats_enabled,
1251 .maxlen = sizeof(sysctl_bpf_stats_enabled),
1252 .mode = 0644,
1253 .proc_handler = proc_dointvec_minmax_bpf_stats,
1254 .extra1 = &zero,
1255 .extra2 = &one,
1256 },
Alexei Starovoitov3fcc55302019-02-27 18:30:44 -08001257#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001258#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1259 {
1260 .procname = "panic_on_rcu_stall",
1261 .data = &sysctl_panic_on_rcu_stall,
1262 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1263 .mode = 0644,
1264 .proc_handler = proc_dointvec_minmax,
1265 .extra1 = &zero,
1266 .extra2 = &one,
1267 },
1268#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001269#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1270 {
1271 .procname = "stack_erasing",
1272 .data = NULL,
1273 .maxlen = sizeof(int),
1274 .mode = 0600,
1275 .proc_handler = stack_erasing_sysctl,
1276 .extra1 = &zero,
1277 .extra2 = &one,
1278 },
1279#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001280 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281};
1282
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001283static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 .procname = "overcommit_memory",
1286 .data = &sysctl_overcommit_memory,
1287 .maxlen = sizeof(sysctl_overcommit_memory),
1288 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001289 .proc_handler = proc_dointvec_minmax,
1290 .extra1 = &zero,
1291 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 },
1293 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001294 .procname = "panic_on_oom",
1295 .data = &sysctl_panic_on_oom,
1296 .maxlen = sizeof(sysctl_panic_on_oom),
1297 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001298 .proc_handler = proc_dointvec_minmax,
1299 .extra1 = &zero,
1300 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001301 },
1302 {
David Rientjesfe071d72007-10-16 23:25:56 -07001303 .procname = "oom_kill_allocating_task",
1304 .data = &sysctl_oom_kill_allocating_task,
1305 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1306 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001307 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001308 },
1309 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001310 .procname = "oom_dump_tasks",
1311 .data = &sysctl_oom_dump_tasks,
1312 .maxlen = sizeof(sysctl_oom_dump_tasks),
1313 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001314 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001315 },
1316 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 .procname = "overcommit_ratio",
1318 .data = &sysctl_overcommit_ratio,
1319 .maxlen = sizeof(sysctl_overcommit_ratio),
1320 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001321 .proc_handler = overcommit_ratio_handler,
1322 },
1323 {
1324 .procname = "overcommit_kbytes",
1325 .data = &sysctl_overcommit_kbytes,
1326 .maxlen = sizeof(sysctl_overcommit_kbytes),
1327 .mode = 0644,
1328 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 },
1330 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 .procname = "page-cluster",
1332 .data = &page_cluster,
1333 .maxlen = sizeof(int),
1334 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001335 .proc_handler = proc_dointvec_minmax,
1336 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 },
1338 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 .procname = "dirty_background_ratio",
1340 .data = &dirty_background_ratio,
1341 .maxlen = sizeof(dirty_background_ratio),
1342 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001343 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 .extra1 = &zero,
1345 .extra2 = &one_hundred,
1346 },
1347 {
David Rientjes2da02992009-01-06 14:39:31 -08001348 .procname = "dirty_background_bytes",
1349 .data = &dirty_background_bytes,
1350 .maxlen = sizeof(dirty_background_bytes),
1351 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001352 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001353 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001354 },
1355 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 .procname = "dirty_ratio",
1357 .data = &vm_dirty_ratio,
1358 .maxlen = sizeof(vm_dirty_ratio),
1359 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001360 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .extra1 = &zero,
1362 .extra2 = &one_hundred,
1363 },
1364 {
David Rientjes2da02992009-01-06 14:39:31 -08001365 .procname = "dirty_bytes",
1366 .data = &vm_dirty_bytes,
1367 .maxlen = sizeof(vm_dirty_bytes),
1368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001369 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001370 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001371 },
1372 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001374 .data = &dirty_writeback_interval,
1375 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001377 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 },
1379 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001381 .data = &dirty_expire_interval,
1382 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001384 .proc_handler = proc_dointvec_minmax,
1385 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 },
1387 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001388 .procname = "dirtytime_expire_seconds",
1389 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001390 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001391 .mode = 0644,
1392 .proc_handler = dirtytime_interval_handler,
1393 .extra1 = &zero,
1394 },
1395 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 .procname = "swappiness",
1397 .data = &vm_swappiness,
1398 .maxlen = sizeof(vm_swappiness),
1399 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001400 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 .extra1 = &zero,
1402 .extra2 = &one_hundred,
1403 },
1404#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001405 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001407 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 .maxlen = sizeof(unsigned long),
1409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001410 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001411 },
1412#ifdef CONFIG_NUMA
1413 {
1414 .procname = "nr_hugepages_mempolicy",
1415 .data = NULL,
1416 .maxlen = sizeof(unsigned long),
1417 .mode = 0644,
1418 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001419 },
Kemi Wang45180852017-11-15 17:38:22 -08001420 {
1421 .procname = "numa_stat",
1422 .data = &sysctl_vm_numa_stat,
1423 .maxlen = sizeof(int),
1424 .mode = 0644,
1425 .proc_handler = sysctl_vm_numa_stat_handler,
1426 .extra1 = &zero,
1427 .extra2 = &one,
1428 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001429#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 .procname = "hugetlb_shm_group",
1432 .data = &sysctl_hugetlb_shm_group,
1433 .maxlen = sizeof(gid_t),
1434 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001435 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 },
Adam Litke54f9f802007-10-16 01:26:20 -07001437 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001438 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001439 .data = NULL,
1440 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001441 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001442 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001443 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444#endif
1445 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 .procname = "lowmem_reserve_ratio",
1447 .data = &sysctl_lowmem_reserve_ratio,
1448 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1449 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001450 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 },
1452 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001453 .procname = "drop_caches",
1454 .data = &sysctl_drop_caches,
1455 .maxlen = sizeof(int),
1456 .mode = 0644,
1457 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001458 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001459 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001460 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001461#ifdef CONFIG_COMPACTION
1462 {
1463 .procname = "compact_memory",
1464 .data = &sysctl_compact_memory,
1465 .maxlen = sizeof(int),
1466 .mode = 0200,
1467 .proc_handler = sysctl_compaction_handler,
1468 },
Mel Gorman5e771902010-05-24 14:32:31 -07001469 {
1470 .procname = "extfrag_threshold",
1471 .data = &sysctl_extfrag_threshold,
1472 .maxlen = sizeof(int),
1473 .mode = 0644,
Matthew Wilcox6b7e5ca2019-03-05 15:43:41 -08001474 .proc_handler = proc_dointvec_minmax,
Mel Gorman5e771902010-05-24 14:32:31 -07001475 .extra1 = &min_extfrag_threshold,
1476 .extra2 = &max_extfrag_threshold,
1477 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001478 {
1479 .procname = "compact_unevictable_allowed",
1480 .data = &sysctl_compact_unevictable_allowed,
1481 .maxlen = sizeof(int),
1482 .mode = 0644,
1483 .proc_handler = proc_dointvec,
1484 .extra1 = &zero,
1485 .extra2 = &one,
1486 },
Mel Gorman5e771902010-05-24 14:32:31 -07001487
Mel Gorman76ab0f52010-05-24 14:32:28 -07001488#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001489 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 .procname = "min_free_kbytes",
1491 .data = &min_free_kbytes,
1492 .maxlen = sizeof(min_free_kbytes),
1493 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001494 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 .extra1 = &zero,
1496 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001497 {
Mel Gorman1c308442018-12-28 00:35:52 -08001498 .procname = "watermark_boost_factor",
1499 .data = &watermark_boost_factor,
1500 .maxlen = sizeof(watermark_boost_factor),
1501 .mode = 0644,
1502 .proc_handler = watermark_boost_factor_sysctl_handler,
1503 .extra1 = &zero,
1504 },
1505 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001506 .procname = "watermark_scale_factor",
1507 .data = &watermark_scale_factor,
1508 .maxlen = sizeof(watermark_scale_factor),
1509 .mode = 0644,
1510 .proc_handler = watermark_scale_factor_sysctl_handler,
1511 .extra1 = &one,
1512 .extra2 = &one_thousand,
1513 },
1514 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001515 .procname = "percpu_pagelist_fraction",
1516 .data = &percpu_pagelist_fraction,
1517 .maxlen = sizeof(percpu_pagelist_fraction),
1518 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001519 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001520 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001521 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522#ifdef CONFIG_MMU
1523 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 .procname = "max_map_count",
1525 .data = &sysctl_max_map_count,
1526 .maxlen = sizeof(sysctl_max_map_count),
1527 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001528 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001529 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001531#else
1532 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001533 .procname = "nr_trim_pages",
1534 .data = &sysctl_nr_trim_pages,
1535 .maxlen = sizeof(sysctl_nr_trim_pages),
1536 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001537 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001538 .extra1 = &zero,
1539 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540#endif
1541 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 .procname = "laptop_mode",
1543 .data = &laptop_mode,
1544 .maxlen = sizeof(laptop_mode),
1545 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001546 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 },
1548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 .procname = "block_dump",
1550 .data = &block_dump,
1551 .maxlen = sizeof(block_dump),
1552 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001553 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 .extra1 = &zero,
1555 },
1556 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 .procname = "vfs_cache_pressure",
1558 .data = &sysctl_vfs_cache_pressure,
1559 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1560 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001561 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 .extra1 = &zero,
1563 },
1564#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1565 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 .procname = "legacy_va_layout",
1567 .data = &sysctl_legacy_va_layout,
1568 .maxlen = sizeof(sysctl_legacy_va_layout),
1569 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001570 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 .extra1 = &zero,
1572 },
1573#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001574#ifdef CONFIG_NUMA
1575 {
Christoph Lameter17436602006-01-18 17:42:32 -08001576 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001577 .data = &node_reclaim_mode,
1578 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001579 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001580 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001581 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001582 },
Christoph Lameter96146342006-07-03 00:24:13 -07001583 {
Christoph Lameter96146342006-07-03 00:24:13 -07001584 .procname = "min_unmapped_ratio",
1585 .data = &sysctl_min_unmapped_ratio,
1586 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1587 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001588 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001589 .extra1 = &zero,
1590 .extra2 = &one_hundred,
1591 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001592 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001593 .procname = "min_slab_ratio",
1594 .data = &sysctl_min_slab_ratio,
1595 .maxlen = sizeof(sysctl_min_slab_ratio),
1596 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001597 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001598 .extra1 = &zero,
1599 .extra2 = &one_hundred,
1600 },
Christoph Lameter17436602006-01-18 17:42:32 -08001601#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001602#ifdef CONFIG_SMP
1603 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001604 .procname = "stat_interval",
1605 .data = &sysctl_stat_interval,
1606 .maxlen = sizeof(sysctl_stat_interval),
1607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001608 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001609 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001610 {
1611 .procname = "stat_refresh",
1612 .data = NULL,
1613 .maxlen = 0,
1614 .mode = 0600,
1615 .proc_handler = vmstat_refresh,
1616 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001617#endif
David Howells6e141542009-12-15 19:27:45 +00001618#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001619 {
Eric Parised032182007-06-28 15:55:21 -04001620 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001621 .data = &dac_mmap_min_addr,
1622 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001623 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001624 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001625 },
David Howells6e141542009-12-15 19:27:45 +00001626#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001627#ifdef CONFIG_NUMA
1628 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001629 .procname = "numa_zonelist_order",
1630 .data = &numa_zonelist_order,
1631 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1632 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001633 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001634 },
1635#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001636#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001637 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001638 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001639 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001640#ifdef CONFIG_X86_32
1641 .data = &vdso32_enabled,
1642 .maxlen = sizeof(vdso32_enabled),
1643#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001644 .data = &vdso_enabled,
1645 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001646#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001647 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001648 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001649 .extra1 = &zero,
1650 },
1651#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001652#ifdef CONFIG_HIGHMEM
1653 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001654 .procname = "highmem_is_dirtyable",
1655 .data = &vm_highmem_is_dirtyable,
1656 .maxlen = sizeof(vm_highmem_is_dirtyable),
1657 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001658 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001659 .extra1 = &zero,
1660 .extra2 = &one,
1661 },
1662#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001663#ifdef CONFIG_MEMORY_FAILURE
1664 {
Andi Kleen6a460792009-09-16 11:50:15 +02001665 .procname = "memory_failure_early_kill",
1666 .data = &sysctl_memory_failure_early_kill,
1667 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1668 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001669 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001670 .extra1 = &zero,
1671 .extra2 = &one,
1672 },
1673 {
Andi Kleen6a460792009-09-16 11:50:15 +02001674 .procname = "memory_failure_recovery",
1675 .data = &sysctl_memory_failure_recovery,
1676 .maxlen = sizeof(sysctl_memory_failure_recovery),
1677 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001678 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001679 .extra1 = &zero,
1680 .extra2 = &one,
1681 },
1682#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001683 {
1684 .procname = "user_reserve_kbytes",
1685 .data = &sysctl_user_reserve_kbytes,
1686 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1687 .mode = 0644,
1688 .proc_handler = proc_doulongvec_minmax,
1689 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001690 {
1691 .procname = "admin_reserve_kbytes",
1692 .data = &sysctl_admin_reserve_kbytes,
1693 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1694 .mode = 0644,
1695 .proc_handler = proc_doulongvec_minmax,
1696 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001697#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1698 {
1699 .procname = "mmap_rnd_bits",
1700 .data = &mmap_rnd_bits,
1701 .maxlen = sizeof(mmap_rnd_bits),
1702 .mode = 0600,
1703 .proc_handler = proc_dointvec_minmax,
1704 .extra1 = (void *)&mmap_rnd_bits_min,
1705 .extra2 = (void *)&mmap_rnd_bits_max,
1706 },
1707#endif
1708#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1709 {
1710 .procname = "mmap_rnd_compat_bits",
1711 .data = &mmap_rnd_compat_bits,
1712 .maxlen = sizeof(mmap_rnd_compat_bits),
1713 .mode = 0600,
1714 .proc_handler = proc_dointvec_minmax,
1715 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1716 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1717 },
1718#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001719 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720};
1721
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001722static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 .procname = "inode-nr",
1725 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001726 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001728 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 },
1730 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 .procname = "inode-state",
1732 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001733 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001735 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 },
1737 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 .procname = "file-nr",
1739 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001740 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001742 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 },
1744 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 .procname = "file-max",
1746 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001747 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001749 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 },
1751 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001752 .procname = "nr_open",
1753 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001754 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001755 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001756 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001757 .extra1 = &sysctl_nr_open_min,
1758 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001759 },
1760 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 .procname = "dentry-state",
1762 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001763 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001765 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 },
1767 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 .procname = "overflowuid",
1769 .data = &fs_overflowuid,
1770 .maxlen = sizeof(int),
1771 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001772 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 .extra1 = &minolduid,
1774 .extra2 = &maxolduid,
1775 },
1776 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 .procname = "overflowgid",
1778 .data = &fs_overflowgid,
1779 .maxlen = sizeof(int),
1780 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001781 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 .extra1 = &minolduid,
1783 .extra2 = &maxolduid,
1784 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001785#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 .procname = "leases-enable",
1788 .data = &leases_enable,
1789 .maxlen = sizeof(int),
1790 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001791 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001793#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794#ifdef CONFIG_DNOTIFY
1795 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 .procname = "dir-notify-enable",
1797 .data = &dir_notify_enable,
1798 .maxlen = sizeof(int),
1799 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001800 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 },
1802#endif
1803#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001804#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 .procname = "lease-break-time",
1807 .data = &lease_break_time,
1808 .maxlen = sizeof(int),
1809 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001810 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001812#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001813#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 .procname = "aio-nr",
1816 .data = &aio_nr,
1817 .maxlen = sizeof(aio_nr),
1818 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001819 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 },
1821 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 .procname = "aio-max-nr",
1823 .data = &aio_max_nr,
1824 .maxlen = sizeof(aio_max_nr),
1825 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001826 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001828#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001829#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001830 {
Robert Love0399cb02005-07-13 12:38:18 -04001831 .procname = "inotify",
1832 .mode = 0555,
1833 .child = inotify_table,
1834 },
1835#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001836#ifdef CONFIG_EPOLL
1837 {
1838 .procname = "epoll",
1839 .mode = 0555,
1840 .child = epoll_table,
1841 },
1842#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001844 {
Kees Cook800179c2012-07-25 17:29:07 -07001845 .procname = "protected_symlinks",
1846 .data = &sysctl_protected_symlinks,
1847 .maxlen = sizeof(int),
1848 .mode = 0600,
1849 .proc_handler = proc_dointvec_minmax,
1850 .extra1 = &zero,
1851 .extra2 = &one,
1852 },
1853 {
1854 .procname = "protected_hardlinks",
1855 .data = &sysctl_protected_hardlinks,
1856 .maxlen = sizeof(int),
1857 .mode = 0600,
1858 .proc_handler = proc_dointvec_minmax,
1859 .extra1 = &zero,
1860 .extra2 = &one,
1861 },
1862 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001863 .procname = "protected_fifos",
1864 .data = &sysctl_protected_fifos,
1865 .maxlen = sizeof(int),
1866 .mode = 0600,
1867 .proc_handler = proc_dointvec_minmax,
1868 .extra1 = &zero,
1869 .extra2 = &two,
1870 },
1871 {
1872 .procname = "protected_regular",
1873 .data = &sysctl_protected_regular,
1874 .maxlen = sizeof(int),
1875 .mode = 0600,
1876 .proc_handler = proc_dointvec_minmax,
1877 .extra1 = &zero,
1878 .extra2 = &two,
1879 },
1880 {
Alan Coxd6e71142005-06-23 00:09:43 -07001881 .procname = "suid_dumpable",
1882 .data = &suid_dumpable,
1883 .maxlen = sizeof(int),
1884 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001885 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001886 .extra1 = &zero,
1887 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001888 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001889#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1890 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001891 .procname = "binfmt_misc",
1892 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001893 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001894 },
1895#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001896 {
Jens Axboeff9da692010-06-03 14:54:39 +02001897 .procname = "pipe-max-size",
1898 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001899 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001900 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001901 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001902 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001903 {
1904 .procname = "pipe-user-pages-hard",
1905 .data = &pipe_user_pages_hard,
1906 .maxlen = sizeof(pipe_user_pages_hard),
1907 .mode = 0644,
1908 .proc_handler = proc_doulongvec_minmax,
1909 },
1910 {
1911 .procname = "pipe-user-pages-soft",
1912 .data = &pipe_user_pages_soft,
1913 .maxlen = sizeof(pipe_user_pages_soft),
1914 .mode = 0644,
1915 .proc_handler = proc_doulongvec_minmax,
1916 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001917 {
1918 .procname = "mount-max",
1919 .data = &sysctl_mount_max,
1920 .maxlen = sizeof(unsigned int),
1921 .mode = 0644,
1922 .proc_handler = proc_dointvec_minmax,
1923 .extra1 = &one,
1924 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001925 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926};
1927
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001928static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001929#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001930 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001931 .procname = "exception-trace",
1932 .data = &show_unhandled_signals,
1933 .maxlen = sizeof(int),
1934 .mode = 0644,
1935 .proc_handler = proc_dointvec
1936 },
1937#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001938#if defined(CONFIG_OPTPROBES)
1939 {
1940 .procname = "kprobes-optimization",
1941 .data = &sysctl_kprobes_optimization,
1942 .maxlen = sizeof(int),
1943 .mode = 0644,
1944 .proc_handler = proc_kprobes_optimization_handler,
1945 .extra1 = &zero,
1946 .extra2 = &one,
1947 },
1948#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001949 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950};
1951
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001952static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001953 { }
Robert Love0eeca282005-07-12 17:06:03 -04001954};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001956int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001957{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001958 struct ctl_table_header *hdr;
1959
1960 hdr = register_sysctl_table(sysctl_base_table);
1961 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001962 return 0;
1963}
1964
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001965#endif /* CONFIG_SYSCTL */
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967/*
1968 * /proc/sys support
1969 */
1970
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001971#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
Kees Cookf8808302014-06-06 14:37:17 -07001973static int _proc_do_string(char *data, int maxlen, int write,
1974 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001975 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001976{
1977 size_t len;
1978 char __user *p;
1979 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001980
1981 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001982 *lenp = 0;
1983 return 0;
1984 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001985
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001986 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001987 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1988 /* Only continue writes not past the end of buffer. */
1989 len = strlen(data);
1990 if (len > maxlen - 1)
1991 len = maxlen - 1;
1992
1993 if (*ppos > len)
1994 return 0;
1995 len = *ppos;
1996 } else {
1997 /* Start writing from beginning of buffer. */
1998 len = 0;
1999 }
2000
Kees Cook2ca9bb42014-06-06 14:37:18 -07002001 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002002 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002003 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002004 if (get_user(c, p++))
2005 return -EFAULT;
2006 if (c == 0 || c == '\n')
2007 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002008 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002009 }
Kees Cookf8808302014-06-06 14:37:17 -07002010 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002011 } else {
2012 len = strlen(data);
2013 if (len > maxlen)
2014 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002015
2016 if (*ppos > len) {
2017 *lenp = 0;
2018 return 0;
2019 }
2020
2021 data += *ppos;
2022 len -= *ppos;
2023
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002024 if (len > *lenp)
2025 len = *lenp;
2026 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002027 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002028 return -EFAULT;
2029 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002030 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002031 return -EFAULT;
2032 len++;
2033 }
2034 *lenp = len;
2035 *ppos += len;
2036 }
2037 return 0;
2038}
2039
Kees Cookf4aacea2014-06-06 14:37:19 -07002040static void warn_sysctl_write(struct ctl_table *table)
2041{
2042 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2043 "This will not be supported in the future. To silence this\n"
2044 "warning, set kernel.sysctl_writes_strict = -1\n",
2045 current->comm, table->procname);
2046}
2047
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002049 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002050 * @ppos: file position
2051 * @table: the sysctl table
2052 *
2053 * Returns true if the first position is non-zero and the sysctl_writes_strict
2054 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002055 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002056 */
2057static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2058 struct ctl_table *table)
2059{
2060 if (!*ppos)
2061 return false;
2062
2063 switch (sysctl_writes_strict) {
2064 case SYSCTL_WRITES_STRICT:
2065 return true;
2066 case SYSCTL_WRITES_WARN:
2067 warn_sysctl_write(table);
2068 return false;
2069 default:
2070 return false;
2071 }
2072}
2073
2074/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 * proc_dostring - read a string sysctl
2076 * @table: the sysctl table
2077 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 * @buffer: the user buffer
2079 * @lenp: the size of the user buffer
2080 * @ppos: file position
2081 *
2082 * Reads/writes a string from/to the user buffer. If the kernel
2083 * buffer provided is not large enough to hold the string, the
2084 * string is truncated. The copied string is %NULL-terminated.
2085 * If the string is being read by the user process, it is copied
2086 * and a newline '\n' is added. It is truncated if the buffer is
2087 * not large enough.
2088 *
2089 * Returns 0 on success.
2090 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002091int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 void __user *buffer, size_t *lenp, loff_t *ppos)
2093{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002094 if (write)
2095 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002096
Kees Cookf8808302014-06-06 14:37:17 -07002097 return _proc_do_string((char *)(table->data), table->maxlen, write,
2098 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099}
2100
Amerigo Wang00b7c332010-05-05 00:26:45 +00002101static size_t proc_skip_spaces(char **buf)
2102{
2103 size_t ret;
2104 char *tmp = skip_spaces(*buf);
2105 ret = tmp - *buf;
2106 *buf = tmp;
2107 return ret;
2108}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002110static void proc_skip_char(char **buf, size_t *size, const char v)
2111{
2112 while (*size) {
2113 if (**buf != v)
2114 break;
2115 (*size)--;
2116 (*buf)++;
2117 }
2118}
2119
Amerigo Wang00b7c332010-05-05 00:26:45 +00002120#define TMPBUFLEN 22
2121/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002122 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002123 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002124 * @buf: a kernel buffer
2125 * @size: size of the kernel buffer
2126 * @val: this is where the number will be stored
2127 * @neg: set to %TRUE if number is negative
2128 * @perm_tr: a vector which contains the allowed trailers
2129 * @perm_tr_len: size of the perm_tr vector
2130 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002131 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002132 * In case of success %0 is returned and @buf and @size are updated with
2133 * the amount of bytes read. If @tr is non-NULL and a trailing
2134 * character exists (size is non-zero after returning from this
2135 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002136 */
2137static int proc_get_long(char **buf, size_t *size,
2138 unsigned long *val, bool *neg,
2139 const char *perm_tr, unsigned perm_tr_len, char *tr)
2140{
2141 int len;
2142 char *p, tmp[TMPBUFLEN];
2143
2144 if (!*size)
2145 return -EINVAL;
2146
2147 len = *size;
2148 if (len > TMPBUFLEN - 1)
2149 len = TMPBUFLEN - 1;
2150
2151 memcpy(tmp, *buf, len);
2152
2153 tmp[len] = 0;
2154 p = tmp;
2155 if (*p == '-' && *size > 1) {
2156 *neg = true;
2157 p++;
2158 } else
2159 *neg = false;
2160 if (!isdigit(*p))
2161 return -EINVAL;
2162
2163 *val = simple_strtoul(p, &p, 0);
2164
2165 len = p - tmp;
2166
2167 /* We don't know if the next char is whitespace thus we may accept
2168 * invalid integers (e.g. 1234...a) or two integers instead of one
2169 * (e.g. 123...1). So lets not allow such large numbers. */
2170 if (len == TMPBUFLEN - 1)
2171 return -EINVAL;
2172
2173 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2174 return -EINVAL;
2175
2176 if (tr && (len < *size))
2177 *tr = *p;
2178
2179 *buf += len;
2180 *size -= len;
2181
2182 return 0;
2183}
2184
2185/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002186 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002187 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002188 * @buf: the user buffer
2189 * @size: the size of the user buffer
2190 * @val: the integer to be converted
2191 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002192 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002193 * In case of success %0 is returned and @buf and @size are updated with
2194 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002195 */
2196static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2197 bool neg)
2198{
2199 int len;
2200 char tmp[TMPBUFLEN], *p = tmp;
2201
2202 sprintf(p, "%s%lu", neg ? "-" : "", val);
2203 len = strlen(tmp);
2204 if (len > *size)
2205 len = *size;
2206 if (copy_to_user(*buf, tmp, len))
2207 return -EFAULT;
2208 *size -= len;
2209 *buf += len;
2210 return 0;
2211}
2212#undef TMPBUFLEN
2213
2214static int proc_put_char(void __user **buf, size_t *size, char c)
2215{
2216 if (*size) {
2217 char __user **buffer = (char __user **)buf;
2218 if (put_user(c, *buffer))
2219 return -EFAULT;
2220 (*size)--, (*buffer)++;
2221 *buf = *buffer;
2222 }
2223 return 0;
2224}
2225
2226static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 int *valp,
2228 int write, void *data)
2229{
2230 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002231 if (*negp) {
2232 if (*lvalp > (unsigned long) INT_MAX + 1)
2233 return -EINVAL;
2234 *valp = -*lvalp;
2235 } else {
2236 if (*lvalp > (unsigned long) INT_MAX)
2237 return -EINVAL;
2238 *valp = *lvalp;
2239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 } else {
2241 int val = *valp;
2242 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002243 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002244 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002246 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 *lvalp = (unsigned long)val;
2248 }
2249 }
2250 return 0;
2251}
2252
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002253static int do_proc_douintvec_conv(unsigned long *lvalp,
2254 unsigned int *valp,
2255 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002256{
2257 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002258 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002259 return -EINVAL;
2260 *valp = *lvalp;
2261 } else {
2262 unsigned int val = *valp;
2263 *lvalp = (unsigned long)val;
2264 }
2265 return 0;
2266}
2267
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2269
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002270static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002271 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002272 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002273 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 int write, void *data),
2275 void *data)
2276{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002277 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002278 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002279 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Amerigo Wang00b7c332010-05-05 00:26:45 +00002281 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 *lenp = 0;
2283 return 0;
2284 }
2285
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002286 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 vleft = table->maxlen / sizeof(*i);
2288 left = *lenp;
2289
2290 if (!conv)
2291 conv = do_proc_dointvec_conv;
2292
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002294 if (proc_first_pos_non_zero_ignore(ppos, table))
2295 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002296
Amerigo Wang00b7c332010-05-05 00:26:45 +00002297 if (left > PAGE_SIZE - 1)
2298 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002299 p = kbuf = memdup_user_nul(buffer, left);
2300 if (IS_ERR(kbuf))
2301 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002302 }
2303
2304 for (; left && vleft--; i++, first=0) {
2305 unsigned long lval;
2306 bool neg;
2307
2308 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002309 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002310
J. R. Okajima563b0462010-05-25 16:10:14 -07002311 if (!left)
2312 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002313 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002314 proc_wspace_sep,
2315 sizeof(proc_wspace_sep), NULL);
2316 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318 if (conv(&neg, &lval, i, 1, data)) {
2319 err = -EINVAL;
2320 break;
2321 }
2322 } else {
2323 if (conv(&neg, &lval, i, 0, data)) {
2324 err = -EINVAL;
2325 break;
2326 }
2327 if (!first)
2328 err = proc_put_char(&buffer, &left, '\t');
2329 if (err)
2330 break;
2331 err = proc_put_long(&buffer, &left, lval, neg);
2332 if (err)
2333 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 }
2335 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002336
2337 if (!write && !first && left && !err)
2338 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002339 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002340 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002341 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002342 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002343 if (first)
2344 return err ? : -EINVAL;
2345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002347out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002349 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350}
2351
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002352static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002353 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002354 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002355 int write, void *data),
2356 void *data)
2357{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002358 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002359 buffer, lenp, ppos, conv, data);
2360}
2361
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002362static int do_proc_douintvec_w(unsigned int *tbl_data,
2363 struct ctl_table *table,
2364 void __user *buffer,
2365 size_t *lenp, loff_t *ppos,
2366 int (*conv)(unsigned long *lvalp,
2367 unsigned int *valp,
2368 int write, void *data),
2369 void *data)
2370{
2371 unsigned long lval;
2372 int err = 0;
2373 size_t left;
2374 bool neg;
2375 char *kbuf = NULL, *p;
2376
2377 left = *lenp;
2378
2379 if (proc_first_pos_non_zero_ignore(ppos, table))
2380 goto bail_early;
2381
2382 if (left > PAGE_SIZE - 1)
2383 left = PAGE_SIZE - 1;
2384
2385 p = kbuf = memdup_user_nul(buffer, left);
2386 if (IS_ERR(kbuf))
2387 return -EINVAL;
2388
2389 left -= proc_skip_spaces(&p);
2390 if (!left) {
2391 err = -EINVAL;
2392 goto out_free;
2393 }
2394
2395 err = proc_get_long(&p, &left, &lval, &neg,
2396 proc_wspace_sep,
2397 sizeof(proc_wspace_sep), NULL);
2398 if (err || neg) {
2399 err = -EINVAL;
2400 goto out_free;
2401 }
2402
2403 if (conv(&lval, tbl_data, 1, data)) {
2404 err = -EINVAL;
2405 goto out_free;
2406 }
2407
2408 if (!err && left)
2409 left -= proc_skip_spaces(&p);
2410
2411out_free:
2412 kfree(kbuf);
2413 if (err)
2414 return -EINVAL;
2415
2416 return 0;
2417
2418 /* This is in keeping with old __do_proc_dointvec() */
2419bail_early:
2420 *ppos += *lenp;
2421 return err;
2422}
2423
2424static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2425 size_t *lenp, loff_t *ppos,
2426 int (*conv)(unsigned long *lvalp,
2427 unsigned int *valp,
2428 int write, void *data),
2429 void *data)
2430{
2431 unsigned long lval;
2432 int err = 0;
2433 size_t left;
2434
2435 left = *lenp;
2436
2437 if (conv(&lval, tbl_data, 0, data)) {
2438 err = -EINVAL;
2439 goto out;
2440 }
2441
2442 err = proc_put_long(&buffer, &left, lval, false);
2443 if (err || !left)
2444 goto out;
2445
2446 err = proc_put_char(&buffer, &left, '\n');
2447
2448out:
2449 *lenp -= left;
2450 *ppos += *lenp;
2451
2452 return err;
2453}
2454
2455static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2456 int write, void __user *buffer,
2457 size_t *lenp, loff_t *ppos,
2458 int (*conv)(unsigned long *lvalp,
2459 unsigned int *valp,
2460 int write, void *data),
2461 void *data)
2462{
2463 unsigned int *i, vleft;
2464
2465 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2466 *lenp = 0;
2467 return 0;
2468 }
2469
2470 i = (unsigned int *) tbl_data;
2471 vleft = table->maxlen / sizeof(*i);
2472
2473 /*
2474 * Arrays are not supported, keep this simple. *Do not* add
2475 * support for them.
2476 */
2477 if (vleft != 1) {
2478 *lenp = 0;
2479 return -EINVAL;
2480 }
2481
2482 if (!conv)
2483 conv = do_proc_douintvec_conv;
2484
2485 if (write)
2486 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2487 conv, data);
2488 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2489}
2490
2491static int do_proc_douintvec(struct ctl_table *table, int write,
2492 void __user *buffer, size_t *lenp, loff_t *ppos,
2493 int (*conv)(unsigned long *lvalp,
2494 unsigned int *valp,
2495 int write, void *data),
2496 void *data)
2497{
2498 return __do_proc_douintvec(table->data, table, write,
2499 buffer, lenp, ppos, conv, data);
2500}
2501
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502/**
2503 * proc_dointvec - read a vector of integers
2504 * @table: the sysctl table
2505 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 * @buffer: the user buffer
2507 * @lenp: the size of the user buffer
2508 * @ppos: file position
2509 *
2510 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2511 * values from/to the user buffer, treated as an ASCII string.
2512 *
2513 * Returns 0 on success.
2514 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002515int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 void __user *buffer, size_t *lenp, loff_t *ppos)
2517{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002518 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2519}
2520
2521/**
2522 * proc_douintvec - read a vector of unsigned integers
2523 * @table: the sysctl table
2524 * @write: %TRUE if this is a write to the sysctl file
2525 * @buffer: the user buffer
2526 * @lenp: the size of the user buffer
2527 * @ppos: file position
2528 *
2529 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2530 * values from/to the user buffer, treated as an ASCII string.
2531 *
2532 * Returns 0 on success.
2533 */
2534int proc_douintvec(struct ctl_table *table, int write,
2535 void __user *buffer, size_t *lenp, loff_t *ppos)
2536{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002537 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2538 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539}
2540
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002541/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002542 * Taint values can only be increased
2543 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002544 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002545static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002546 void __user *buffer, size_t *lenp, loff_t *ppos)
2547{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002548 struct ctl_table t;
2549 unsigned long tmptaint = get_taint();
2550 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002551
Bastian Blank91fcd412007-04-23 14:41:14 -07002552 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002553 return -EPERM;
2554
Andi Kleen25ddbb12008-10-15 22:01:41 -07002555 t = *table;
2556 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002557 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002558 if (err < 0)
2559 return err;
2560
2561 if (write) {
2562 /*
2563 * Poor man's atomic or. Not worth adding a primitive
2564 * to everyone's atomic.h for this
2565 */
2566 int i;
2567 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2568 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302569 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002570 }
2571 }
2572
2573 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002574}
2575
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002576#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002577static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002578 void __user *buffer, size_t *lenp, loff_t *ppos)
2579{
2580 if (write && !capable(CAP_SYS_ADMIN))
2581 return -EPERM;
2582
2583 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2584}
2585#endif
2586
Waiman Long24704f32018-04-10 16:35:38 -07002587/**
2588 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2589 * @min: pointer to minimum allowable value
2590 * @max: pointer to maximum allowable value
2591 *
2592 * The do_proc_dointvec_minmax_conv_param structure provides the
2593 * minimum and maximum values for doing range checking for those sysctl
2594 * parameters that use the proc_dointvec_minmax() handler.
2595 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596struct do_proc_dointvec_minmax_conv_param {
2597 int *min;
2598 int *max;
2599};
2600
Amerigo Wang00b7c332010-05-05 00:26:45 +00002601static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2602 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 int write, void *data)
2604{
2605 struct do_proc_dointvec_minmax_conv_param *param = data;
2606 if (write) {
2607 int val = *negp ? -*lvalp : *lvalp;
2608 if ((param->min && *param->min > val) ||
2609 (param->max && *param->max < val))
2610 return -EINVAL;
2611 *valp = val;
2612 } else {
2613 int val = *valp;
2614 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002615 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002616 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002618 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 *lvalp = (unsigned long)val;
2620 }
2621 }
2622 return 0;
2623}
2624
2625/**
2626 * proc_dointvec_minmax - read a vector of integers with min/max values
2627 * @table: the sysctl table
2628 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 * @buffer: the user buffer
2630 * @lenp: the size of the user buffer
2631 * @ppos: file position
2632 *
2633 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2634 * values from/to the user buffer, treated as an ASCII string.
2635 *
2636 * This routine will ensure the values are within the range specified by
2637 * table->extra1 (min) and table->extra2 (max).
2638 *
Waiman Long24704f32018-04-10 16:35:38 -07002639 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002641int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 void __user *buffer, size_t *lenp, loff_t *ppos)
2643{
2644 struct do_proc_dointvec_minmax_conv_param param = {
2645 .min = (int *) table->extra1,
2646 .max = (int *) table->extra2,
2647 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002648 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 do_proc_dointvec_minmax_conv, &param);
2650}
2651
Waiman Long24704f32018-04-10 16:35:38 -07002652/**
2653 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2654 * @min: pointer to minimum allowable value
2655 * @max: pointer to maximum allowable value
2656 *
2657 * The do_proc_douintvec_minmax_conv_param structure provides the
2658 * minimum and maximum values for doing range checking for those sysctl
2659 * parameters that use the proc_douintvec_minmax() handler.
2660 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002661struct do_proc_douintvec_minmax_conv_param {
2662 unsigned int *min;
2663 unsigned int *max;
2664};
2665
2666static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2667 unsigned int *valp,
2668 int write, void *data)
2669{
2670 struct do_proc_douintvec_minmax_conv_param *param = data;
2671
2672 if (write) {
2673 unsigned int val = *lvalp;
2674
Joe Lawrencefb910c42017-11-17 15:29:28 -08002675 if (*lvalp > UINT_MAX)
2676 return -EINVAL;
2677
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002678 if ((param->min && *param->min > val) ||
2679 (param->max && *param->max < val))
2680 return -ERANGE;
2681
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002682 *valp = val;
2683 } else {
2684 unsigned int val = *valp;
2685 *lvalp = (unsigned long) val;
2686 }
2687
2688 return 0;
2689}
2690
2691/**
2692 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2693 * @table: the sysctl table
2694 * @write: %TRUE if this is a write to the sysctl file
2695 * @buffer: the user buffer
2696 * @lenp: the size of the user buffer
2697 * @ppos: file position
2698 *
2699 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2700 * values from/to the user buffer, treated as an ASCII string. Negative
2701 * strings are not allowed.
2702 *
2703 * This routine will ensure the values are within the range specified by
2704 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2705 * check for UINT_MAX to avoid having to support wrap around uses from
2706 * userspace.
2707 *
Waiman Long24704f32018-04-10 16:35:38 -07002708 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002709 */
2710int proc_douintvec_minmax(struct ctl_table *table, int write,
2711 void __user *buffer, size_t *lenp, loff_t *ppos)
2712{
2713 struct do_proc_douintvec_minmax_conv_param param = {
2714 .min = (unsigned int *) table->extra1,
2715 .max = (unsigned int *) table->extra2,
2716 };
2717 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2718 do_proc_douintvec_minmax_conv, &param);
2719}
2720
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002721static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2722 unsigned int *valp,
2723 int write, void *data)
2724{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002725 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002726 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002727
Joe Lawrencefb910c42017-11-17 15:29:28 -08002728 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002729 if (val == 0)
2730 return -EINVAL;
2731
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002732 *valp = val;
2733 } else {
2734 unsigned int val = *valp;
2735 *lvalp = (unsigned long) val;
2736 }
2737
2738 return 0;
2739}
2740
Eric Biggers319e0a22018-02-06 15:41:49 -08002741static int proc_dopipe_max_size(struct ctl_table *table, int write,
2742 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002743{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002744 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002745 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002746}
2747
Kees Cook54b50192012-07-30 14:39:18 -07002748static void validate_coredump_safety(void)
2749{
Alex Kelly046d6622012-10-04 17:15:23 -07002750#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002751 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002752 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002753 printk(KERN_WARNING
2754"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2755"Pipe handler or fully qualified core dump path required.\n"
2756"Set kernel.core_pattern before fs.suid_dumpable.\n"
2757 );
Kees Cook54b50192012-07-30 14:39:18 -07002758 }
Alex Kelly046d6622012-10-04 17:15:23 -07002759#endif
Kees Cook54b50192012-07-30 14:39:18 -07002760}
2761
2762static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2763 void __user *buffer, size_t *lenp, loff_t *ppos)
2764{
2765 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2766 if (!error)
2767 validate_coredump_safety();
2768 return error;
2769}
2770
Alex Kelly046d6622012-10-04 17:15:23 -07002771#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002772static int proc_dostring_coredump(struct ctl_table *table, int write,
2773 void __user *buffer, size_t *lenp, loff_t *ppos)
2774{
2775 int error = proc_dostring(table, write, buffer, lenp, ppos);
2776 if (!error)
2777 validate_coredump_safety();
2778 return error;
2779}
Alex Kelly046d6622012-10-04 17:15:23 -07002780#endif
Kees Cook54b50192012-07-30 14:39:18 -07002781
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002782static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 void __user *buffer,
2784 size_t *lenp, loff_t *ppos,
2785 unsigned long convmul,
2786 unsigned long convdiv)
2787{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002788 unsigned long *i, *min, *max;
2789 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002790 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002791 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002792
2793 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 *lenp = 0;
2795 return 0;
2796 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002797
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002798 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 min = (unsigned long *) table->extra1;
2800 max = (unsigned long *) table->extra2;
2801 vleft = table->maxlen / sizeof(unsigned long);
2802 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002803
2804 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002805 if (proc_first_pos_non_zero_ignore(ppos, table))
2806 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002807
Amerigo Wang00b7c332010-05-05 00:26:45 +00002808 if (left > PAGE_SIZE - 1)
2809 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002810 p = kbuf = memdup_user_nul(buffer, left);
2811 if (IS_ERR(kbuf))
2812 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002813 }
2814
Eric Dumazet27b3d802010-10-07 12:59:29 -07002815 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002816 unsigned long val;
2817
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002819 bool neg;
2820
Al Viro70f6cbb2015-12-24 00:13:10 -05002821 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08002822 if (!left)
2823 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002824
Al Viro70f6cbb2015-12-24 00:13:10 -05002825 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002826 proc_wspace_sep,
2827 sizeof(proc_wspace_sep), NULL);
2828 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 break;
2830 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002832 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 if ((min && val < *min) || (max && val > *max))
2834 continue;
2835 *i = val;
2836 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002837 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002838 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002839 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002840 if (err)
2841 break;
2842 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002843 err = proc_put_long(&buffer, &left, val, false);
2844 if (err)
2845 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 }
2847 }
2848
Amerigo Wang00b7c332010-05-05 00:26:45 +00002849 if (!write && !first && left && !err)
2850 err = proc_put_char(&buffer, &left, '\n');
2851 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002852 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002854 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002855 if (first)
2856 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002859out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002861 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862}
2863
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002864static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002865 void __user *buffer,
2866 size_t *lenp, loff_t *ppos,
2867 unsigned long convmul,
2868 unsigned long convdiv)
2869{
2870 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002871 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002872}
2873
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874/**
2875 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2876 * @table: the sysctl table
2877 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 * @buffer: the user buffer
2879 * @lenp: the size of the user buffer
2880 * @ppos: file position
2881 *
2882 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2883 * values from/to the user buffer, treated as an ASCII string.
2884 *
2885 * This routine will ensure the values are within the range specified by
2886 * table->extra1 (min) and table->extra2 (max).
2887 *
2888 * Returns 0 on success.
2889 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002890int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 void __user *buffer, size_t *lenp, loff_t *ppos)
2892{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002893 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894}
2895
2896/**
2897 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2898 * @table: the sysctl table
2899 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 * @buffer: the user buffer
2901 * @lenp: the size of the user buffer
2902 * @ppos: file position
2903 *
2904 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2905 * values from/to the user buffer, treated as an ASCII string. The values
2906 * are treated as milliseconds, and converted to jiffies when they are stored.
2907 *
2908 * This routine will ensure the values are within the range specified by
2909 * table->extra1 (min) and table->extra2 (max).
2910 *
2911 * Returns 0 on success.
2912 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002913int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 void __user *buffer,
2915 size_t *lenp, loff_t *ppos)
2916{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002917 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 lenp, ppos, HZ, 1000l);
2919}
2920
2921
Amerigo Wang00b7c332010-05-05 00:26:45 +00002922static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 int *valp,
2924 int write, void *data)
2925{
2926 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002927 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002928 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2930 } else {
2931 int val = *valp;
2932 unsigned long lval;
2933 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002934 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002935 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002937 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 lval = (unsigned long)val;
2939 }
2940 *lvalp = lval / HZ;
2941 }
2942 return 0;
2943}
2944
Amerigo Wang00b7c332010-05-05 00:26:45 +00002945static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 int *valp,
2947 int write, void *data)
2948{
2949 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002950 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2951 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2953 } else {
2954 int val = *valp;
2955 unsigned long lval;
2956 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002957 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002958 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002960 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 lval = (unsigned long)val;
2962 }
2963 *lvalp = jiffies_to_clock_t(lval);
2964 }
2965 return 0;
2966}
2967
Amerigo Wang00b7c332010-05-05 00:26:45 +00002968static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 int *valp,
2970 int write, void *data)
2971{
2972 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002973 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2974
2975 if (jif > INT_MAX)
2976 return 1;
2977 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 } else {
2979 int val = *valp;
2980 unsigned long lval;
2981 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002982 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002983 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002985 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 lval = (unsigned long)val;
2987 }
2988 *lvalp = jiffies_to_msecs(lval);
2989 }
2990 return 0;
2991}
2992
2993/**
2994 * proc_dointvec_jiffies - read a vector of integers as seconds
2995 * @table: the sysctl table
2996 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 * @buffer: the user buffer
2998 * @lenp: the size of the user buffer
2999 * @ppos: file position
3000 *
3001 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3002 * values from/to the user buffer, treated as an ASCII string.
3003 * The values read are assumed to be in seconds, and are converted into
3004 * jiffies.
3005 *
3006 * Returns 0 on success.
3007 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003008int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 void __user *buffer, size_t *lenp, loff_t *ppos)
3010{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003011 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 do_proc_dointvec_jiffies_conv,NULL);
3013}
3014
3015/**
3016 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3017 * @table: the sysctl table
3018 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 * @buffer: the user buffer
3020 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003021 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 *
3023 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3024 * values from/to the user buffer, treated as an ASCII string.
3025 * The values read are assumed to be in 1/USER_HZ seconds, and
3026 * are converted into jiffies.
3027 *
3028 * Returns 0 on success.
3029 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003030int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 void __user *buffer, size_t *lenp, loff_t *ppos)
3032{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003033 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 do_proc_dointvec_userhz_jiffies_conv,NULL);
3035}
3036
3037/**
3038 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3039 * @table: the sysctl table
3040 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 * @buffer: the user buffer
3042 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003043 * @ppos: file position
3044 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 *
3046 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3047 * values from/to the user buffer, treated as an ASCII string.
3048 * The values read are assumed to be in 1/1000 seconds, and
3049 * are converted into jiffies.
3050 *
3051 * Returns 0 on success.
3052 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003053int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 void __user *buffer, size_t *lenp, loff_t *ppos)
3055{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003056 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 do_proc_dointvec_ms_jiffies_conv, NULL);
3058}
3059
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003060static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003061 void __user *buffer, size_t *lenp, loff_t *ppos)
3062{
3063 struct pid *new_pid;
3064 pid_t tmp;
3065 int r;
3066
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003067 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003068
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003069 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003070 lenp, ppos, NULL, NULL);
3071 if (r || !write)
3072 return r;
3073
3074 new_pid = find_get_pid(tmp);
3075 if (!new_pid)
3076 return -ESRCH;
3077
3078 put_pid(xchg(&cad_pid, new_pid));
3079 return 0;
3080}
3081
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003082/**
3083 * proc_do_large_bitmap - read/write from/to a large bitmap
3084 * @table: the sysctl table
3085 * @write: %TRUE if this is a write to the sysctl file
3086 * @buffer: the user buffer
3087 * @lenp: the size of the user buffer
3088 * @ppos: file position
3089 *
3090 * The bitmap is stored at table->data and the bitmap length (in bits)
3091 * in table->maxlen.
3092 *
3093 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3094 * large bitmaps may be represented in a compact manner. Writing into
3095 * the file will clear the bitmap then update it with the given input.
3096 *
3097 * Returns 0 on success.
3098 */
3099int proc_do_large_bitmap(struct ctl_table *table, int write,
3100 void __user *buffer, size_t *lenp, loff_t *ppos)
3101{
3102 int err = 0;
3103 bool first = 1;
3104 size_t left = *lenp;
3105 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003106 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003107 unsigned long *tmp_bitmap = NULL;
3108 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3109
WANG Cong122ff242014-05-12 16:04:53 -07003110 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003111 *lenp = 0;
3112 return 0;
3113 }
3114
3115 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003116 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003117
3118 if (left > PAGE_SIZE - 1)
3119 left = PAGE_SIZE - 1;
3120
Al Viro70f6cbb2015-12-24 00:13:10 -05003121 p = kbuf = memdup_user_nul(buffer, left);
3122 if (IS_ERR(kbuf))
3123 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003124
Kees Cook6396bb22018-06-12 14:03:40 -07003125 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3126 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003127 GFP_KERNEL);
3128 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003129 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003130 return -ENOMEM;
3131 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003132 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003133 while (!err && left) {
3134 unsigned long val_a, val_b;
3135 bool neg;
3136
Al Viro70f6cbb2015-12-24 00:13:10 -05003137 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003138 sizeof(tr_a), &c);
3139 if (err)
3140 break;
3141 if (val_a >= bitmap_len || neg) {
3142 err = -EINVAL;
3143 break;
3144 }
3145
3146 val_b = val_a;
3147 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003148 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003149 left--;
3150 }
3151
3152 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003153 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003154 &neg, tr_b, sizeof(tr_b),
3155 &c);
3156 if (err)
3157 break;
3158 if (val_b >= bitmap_len || neg ||
3159 val_a > val_b) {
3160 err = -EINVAL;
3161 break;
3162 }
3163 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003164 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003165 left--;
3166 }
3167 }
3168
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003169 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003170 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003171 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003172 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003173 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003174 } else {
3175 unsigned long bit_a, bit_b = 0;
3176
3177 while (left) {
3178 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3179 if (bit_a >= bitmap_len)
3180 break;
3181 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3182 bit_a + 1) - 1;
3183
3184 if (!first) {
3185 err = proc_put_char(&buffer, &left, ',');
3186 if (err)
3187 break;
3188 }
3189 err = proc_put_long(&buffer, &left, bit_a, false);
3190 if (err)
3191 break;
3192 if (bit_a != bit_b) {
3193 err = proc_put_char(&buffer, &left, '-');
3194 if (err)
3195 break;
3196 err = proc_put_long(&buffer, &left, bit_b, false);
3197 if (err)
3198 break;
3199 }
3200
3201 first = 0; bit_b++;
3202 }
3203 if (!err)
3204 err = proc_put_char(&buffer, &left, '\n');
3205 }
3206
3207 if (!err) {
3208 if (write) {
3209 if (*ppos)
3210 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3211 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003212 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003213 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003214 *lenp -= left;
3215 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003216 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003217
3218 kfree(tmp_bitmap);
3219 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003220}
3221
Jovi Zhang55610502011-01-12 17:00:45 -08003222#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003224int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 void __user *buffer, size_t *lenp, loff_t *ppos)
3226{
3227 return -ENOSYS;
3228}
3229
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003230int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 void __user *buffer, size_t *lenp, loff_t *ppos)
3232{
3233 return -ENOSYS;
3234}
3235
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003236int proc_douintvec(struct ctl_table *table, int write,
3237 void __user *buffer, size_t *lenp, loff_t *ppos)
3238{
3239 return -ENOSYS;
3240}
3241
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003242int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 void __user *buffer, size_t *lenp, loff_t *ppos)
3244{
3245 return -ENOSYS;
3246}
3247
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003248int proc_douintvec_minmax(struct ctl_table *table, int write,
3249 void __user *buffer, size_t *lenp, loff_t *ppos)
3250{
3251 return -ENOSYS;
3252}
3253
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003254int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 void __user *buffer, size_t *lenp, loff_t *ppos)
3256{
3257 return -ENOSYS;
3258}
3259
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003260int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 void __user *buffer, size_t *lenp, loff_t *ppos)
3262{
3263 return -ENOSYS;
3264}
3265
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003266int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 void __user *buffer, size_t *lenp, loff_t *ppos)
3268{
3269 return -ENOSYS;
3270}
3271
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003272int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 void __user *buffer, size_t *lenp, loff_t *ppos)
3274{
3275 return -ENOSYS;
3276}
3277
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003278int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 void __user *buffer,
3280 size_t *lenp, loff_t *ppos)
3281{
3282 return -ENOSYS;
3283}
3284
3285
Jovi Zhang55610502011-01-12 17:00:45 -08003286#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287
Alexei Starovoitov3fcc55302019-02-27 18:30:44 -08003288#ifdef CONFIG_BPF_SYSCALL
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003289static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
3290 void __user *buffer, size_t *lenp,
3291 loff_t *ppos)
3292{
3293 int ret, bpf_stats = *(int *)table->data;
3294 struct ctl_table tmp = *table;
3295
3296 if (write && !capable(CAP_SYS_ADMIN))
3297 return -EPERM;
3298
3299 tmp.data = &bpf_stats;
3300 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3301 if (write && !ret) {
3302 *(int *)table->data = bpf_stats;
3303 if (bpf_stats)
3304 static_branch_enable(&bpf_stats_enabled_key);
3305 else
3306 static_branch_disable(&bpf_stats_enabled_key);
3307 }
3308 return ret;
3309}
Alexei Starovoitov3fcc55302019-02-27 18:30:44 -08003310#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311/*
3312 * No sense putting this after each symbol definition, twice,
3313 * exception granted :-)
3314 */
3315EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003316EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317EXPORT_SYMBOL(proc_dointvec_jiffies);
3318EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003319EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3321EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3322EXPORT_SYMBOL(proc_dostring);
3323EXPORT_SYMBOL(proc_doulongvec_minmax);
3324EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);