blob: 7578e21a711b45c8ecddc86ae280c7965e177cac [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 Starovoitov3fcc5532019-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 Starovoitov3fcc5532019-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
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700475#ifdef CONFIG_PROVE_LOCKING
476 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700477 .procname = "prove_locking",
478 .data = &prove_locking,
479 .maxlen = sizeof(int),
480 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800481 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700482 },
483#endif
484#ifdef CONFIG_LOCK_STAT
485 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700486 .procname = "lock_stat",
487 .data = &lock_stat,
488 .maxlen = sizeof(int),
489 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800490 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700491 },
492#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200493 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 .procname = "panic",
495 .data = &panic_timeout,
496 .maxlen = sizeof(int),
497 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800498 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 },
Alex Kelly046d6622012-10-04 17:15:23 -0700500#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 .procname = "core_uses_pid",
503 .data = &core_uses_pid,
504 .maxlen = sizeof(int),
505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800506 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 },
508 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 .procname = "core_pattern",
510 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700511 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700513 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 },
Neil Hormana2939802009-09-23 15:56:56 -0700515 {
Neil Hormana2939802009-09-23 15:56:56 -0700516 .procname = "core_pipe_limit",
517 .data = &core_pipe_limit,
518 .maxlen = sizeof(unsigned int),
519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800520 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700521 },
Alex Kelly046d6622012-10-04 17:15:23 -0700522#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800523#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700526 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800527 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800528 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700530 {
531 .procname = "sysctl_writes_strict",
532 .data = &sysctl_writes_strict,
533 .maxlen = sizeof(int),
534 .mode = 0644,
535 .proc_handler = proc_dointvec_minmax,
536 .extra1 = &neg_one,
537 .extra2 = &one,
538 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800539#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100540#ifdef CONFIG_LATENCYTOP
541 {
542 .procname = "latencytop",
543 .data = &latencytop_enabled,
544 .maxlen = sizeof(int),
545 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000546 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100547 },
548#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549#ifdef CONFIG_BLK_DEV_INITRD
550 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 .procname = "real-root-dev",
552 .data = &real_root_dev,
553 .maxlen = sizeof(int),
554 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800555 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 },
557#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700558 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700559 .procname = "print-fatal-signals",
560 .data = &print_fatal_signals,
561 .maxlen = sizeof(int),
562 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800563 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700564 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700565#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 .procname = "reboot-cmd",
568 .data = reboot_command,
569 .maxlen = 256,
570 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800571 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 },
573 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 .procname = "stop-a",
575 .data = &stop_a_enabled,
576 .maxlen = sizeof (int),
577 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800578 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 },
580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "scons-poweroff",
582 .data = &scons_pwroff,
583 .maxlen = sizeof (int),
584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800585 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
587#endif
David S. Miller08714202008-11-16 23:49:24 -0800588#ifdef CONFIG_SPARC64
589 {
David S. Miller08714202008-11-16 23:49:24 -0800590 .procname = "tsb-ratio",
591 .data = &sysctl_tsb_ratio,
592 .maxlen = sizeof (int),
593 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800594 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800595 },
596#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597#ifdef __hppa__
598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .procname = "soft-power",
600 .data = &pwrsw_enabled,
601 .maxlen = sizeof (int),
602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800603 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530605#endif
606#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 .procname = "unaligned-trap",
609 .data = &unaligned_enabled,
610 .maxlen = sizeof (int),
611 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800612 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 },
614#endif
615 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 .procname = "ctrl-alt-del",
617 .data = &C_A_D,
618 .maxlen = sizeof(int),
619 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800620 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400622#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200623 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200624 .procname = "ftrace_enabled",
625 .data = &ftrace_enabled,
626 .maxlen = sizeof(int),
627 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800628 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200629 },
630#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500631#ifdef CONFIG_STACK_TRACER
632 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500633 .procname = "stack_tracer_enabled",
634 .data = &stack_tracer_enabled,
635 .maxlen = sizeof(int),
636 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800637 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500638 },
639#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400640#ifdef CONFIG_TRACING
641 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100642 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400643 .data = &ftrace_dump_on_oops,
644 .maxlen = sizeof(int),
645 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800646 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400647 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400648 {
649 .procname = "traceoff_on_warning",
650 .data = &__disable_trace_on_warning,
651 .maxlen = sizeof(__disable_trace_on_warning),
652 .mode = 0644,
653 .proc_handler = proc_dointvec,
654 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500655 {
656 .procname = "tracepoint_printk",
657 .data = &tracepoint_printk,
658 .maxlen = sizeof(tracepoint_printk),
659 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500660 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500661 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400662#endif
Dave Young2965faa2015-09-09 15:38:55 -0700663#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800664 {
665 .procname = "kexec_load_disabled",
666 .data = &kexec_load_disabled,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 /* only handle a transition from default "0" to "1" */
670 .proc_handler = proc_dointvec_minmax,
671 .extra1 = &one,
672 .extra2 = &one,
673 },
674#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200675#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 .procname = "modprobe",
678 .data = &modprobe_path,
679 .maxlen = KMOD_PATH_LEN,
680 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800681 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 },
Kees Cook3d433212009-04-02 15:49:29 -0700683 {
Kees Cook3d433212009-04-02 15:49:29 -0700684 .procname = "modules_disabled",
685 .data = &modules_disabled,
686 .maxlen = sizeof(int),
687 .mode = 0644,
688 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800689 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700690 .extra1 = &one,
691 .extra2 = &one,
692 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700694#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100697 .data = &uevent_helper,
698 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 },
Michael Marineau86d56132014-04-10 14:09:31 -0700702#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703#ifdef CONFIG_CHR_DEV_SG
704 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 .procname = "sg-big-buff",
706 .data = &sg_big_buff,
707 .maxlen = sizeof (int),
708 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800709 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 },
711#endif
712#ifdef CONFIG_BSD_PROCESS_ACCT
713 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 .procname = "acct",
715 .data = &acct_parm,
716 .maxlen = 3*sizeof(int),
717 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800718 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 },
720#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#ifdef CONFIG_MAGIC_SYSRQ
722 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800724 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 .maxlen = sizeof (int),
726 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700727 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 },
729#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700730#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700733 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 .maxlen = sizeof (int),
735 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800736 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700738#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700741 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 .maxlen = sizeof(int),
743 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700744 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 },
746 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 .procname = "random",
748 .mode = 0555,
749 .child = random_table,
750 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 {
Eric Paris17f60a72011-04-01 17:07:50 -0400752 .procname = "usermodehelper",
753 .mode = 0555,
754 .child = usermodehelper_table,
755 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800756#ifdef CONFIG_FW_LOADER_USER_HELPER
757 {
758 .procname = "firmware_config",
759 .mode = 0555,
760 .child = firmware_config_table,
761 },
762#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400763 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .procname = "overflowuid",
765 .data = &overflowuid,
766 .maxlen = sizeof(int),
767 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800768 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 .extra1 = &minolduid,
770 .extra2 = &maxolduid,
771 },
772 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 .procname = "overflowgid",
774 .data = &overflowgid,
775 .maxlen = sizeof(int),
776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800777 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 .extra1 = &minolduid,
779 .extra2 = &maxolduid,
780 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800781#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782#ifdef CONFIG_MATHEMU
783 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 .procname = "ieee_emulation_warnings",
785 .data = &sysctl_ieee_emulation_warnings,
786 .maxlen = sizeof(int),
787 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800788 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 },
790#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200793 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .maxlen = sizeof(int),
795 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800796 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 },
798#endif
799 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 .procname = "pid_max",
801 .data = &pid_max,
802 .maxlen = sizeof (int),
803 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800804 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 .extra1 = &pid_max_min,
806 .extra2 = &pid_max_max,
807 },
808 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 .procname = "panic_on_oops",
810 .data = &panic_on_oops,
811 .maxlen = sizeof(int),
812 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800813 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 },
Feng Tang81c9d432019-01-03 15:28:20 -0800815 {
816 .procname = "panic_print",
817 .data = &panic_print,
818 .maxlen = sizeof(unsigned long),
819 .mode = 0644,
820 .proc_handler = proc_doulongvec_minmax,
821 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800822#if defined CONFIG_PRINTK
823 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800824 .procname = "printk",
825 .data = &console_loglevel,
826 .maxlen = 4*sizeof(int),
827 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800828 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800829 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700832 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 .maxlen = sizeof(int),
834 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800835 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 },
837 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700839 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 .maxlen = sizeof(int),
841 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800842 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 },
Dave Youngaf913222009-09-22 16:43:33 -0700844 {
Dave Youngaf913222009-09-22 16:43:33 -0700845 .procname = "printk_delay",
846 .data = &printk_delay_msec,
847 .maxlen = sizeof(int),
848 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800849 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700850 .extra1 = &zero,
851 .extra2 = &ten_thousand,
852 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700854 .procname = "printk_devkmsg",
855 .data = devkmsg_log_str,
856 .maxlen = DEVKMSG_STR_MAX_SIZE,
857 .mode = 0644,
858 .proc_handler = devkmsg_sysctl_set_loglvl,
859 },
860 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800861 .procname = "dmesg_restrict",
862 .data = &dmesg_restrict,
863 .maxlen = sizeof(int),
864 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700865 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800866 .extra1 = &zero,
867 .extra2 = &one,
868 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800869 {
870 .procname = "kptr_restrict",
871 .data = &kptr_restrict,
872 .maxlen = sizeof(int),
873 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700874 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800875 .extra1 = &zero,
876 .extra2 = &two,
877 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800878#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800879 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 .procname = "ngroups_max",
881 .data = &ngroups_max,
882 .maxlen = sizeof (int),
883 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800884 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 },
Dan Ballard73efc032011-10-31 17:11:20 -0700886 {
887 .procname = "cap_last_cap",
888 .data = (void *)&cap_last_cap,
889 .maxlen = sizeof(int),
890 .mode = 0444,
891 .proc_handler = proc_dointvec,
892 },
Don Zickus58687ac2010-05-07 17:11:44 -0400893#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500894 {
Don Zickus58687ac2010-05-07 17:11:44 -0400895 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200896 .data = &watchdog_user_enabled,
897 .maxlen = sizeof(int),
898 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700899 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700900 .extra1 = &zero,
901 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400902 },
903 {
904 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700905 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400906 .maxlen = sizeof(int),
907 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700908 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800909 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400910 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500911 },
Don Zickus2508ce12010-05-07 17:11:46 -0400912 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700913 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200914 .data = &nmi_watchdog_user_enabled,
915 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200916 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700917 .proc_handler = proc_nmi_watchdog,
918 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700919 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700920 },
921 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700922 .procname = "watchdog_cpumask",
923 .data = &watchdog_cpumask_bits,
924 .maxlen = NR_CPUS,
925 .mode = 0644,
926 .proc_handler = proc_watchdog_cpumask,
927 },
928#ifdef CONFIG_SOFTLOCKUP_DETECTOR
929 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700930 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200931 .data = &soft_watchdog_user_enabled,
932 .maxlen = sizeof(int),
933 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700934 .proc_handler = proc_soft_watchdog,
935 .extra1 = &zero,
936 .extra2 = &one,
937 },
938 {
Don Zickus2508ce12010-05-07 17:11:46 -0400939 .procname = "softlockup_panic",
940 .data = &softlockup_panic,
941 .maxlen = sizeof(int),
942 .mode = 0644,
943 .proc_handler = proc_dointvec_minmax,
944 .extra1 = &zero,
945 .extra2 = &one,
946 },
Aaron Tomlined235872014-06-23 13:22:05 -0700947#ifdef CONFIG_SMP
948 {
949 .procname = "softlockup_all_cpu_backtrace",
950 .data = &sysctl_softlockup_all_cpu_backtrace,
951 .maxlen = sizeof(int),
952 .mode = 0644,
953 .proc_handler = proc_dointvec_minmax,
954 .extra1 = &zero,
955 .extra2 = &one,
956 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700957#endif /* CONFIG_SMP */
958#endif
959#ifdef CONFIG_HARDLOCKUP_DETECTOR
960 {
961 .procname = "hardlockup_panic",
962 .data = &hardlockup_panic,
963 .maxlen = sizeof(int),
964 .mode = 0644,
965 .proc_handler = proc_dointvec_minmax,
966 .extra1 = &zero,
967 .extra2 = &one,
968 },
969#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800970 {
971 .procname = "hardlockup_all_cpu_backtrace",
972 .data = &sysctl_hardlockup_all_cpu_backtrace,
973 .maxlen = sizeof(int),
974 .mode = 0644,
975 .proc_handler = proc_dointvec_minmax,
976 .extra1 = &zero,
977 .extra2 = &one,
978 },
Aaron Tomlined235872014-06-23 13:22:05 -0700979#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500980#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700981#endif
982
Don Zickus5dc30552010-11-29 17:07:17 -0500983#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
984 {
985 .procname = "unknown_nmi_panic",
986 .data = &unknown_nmi_panic,
987 .maxlen = sizeof (int),
988 .mode = 0644,
989 .proc_handler = proc_dointvec,
990 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500991#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992#if defined(CONFIG_X86)
993 {
Don Zickus8da5add2006-09-26 10:52:27 +0200994 .procname = "panic_on_unrecovered_nmi",
995 .data = &panic_on_unrecovered_nmi,
996 .maxlen = sizeof(int),
997 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800998 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200999 },
1000 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001001 .procname = "panic_on_io_nmi",
1002 .data = &panic_on_io_nmi,
1003 .maxlen = sizeof(int),
1004 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001005 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001006 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001007#ifdef CONFIG_DEBUG_STACKOVERFLOW
1008 {
1009 .procname = "panic_on_stackoverflow",
1010 .data = &sysctl_panic_on_stackoverflow,
1011 .maxlen = sizeof(int),
1012 .mode = 0644,
1013 .proc_handler = proc_dointvec,
1014 },
1015#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001016 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 .procname = "bootloader_type",
1018 .data = &bootloader_type,
1019 .maxlen = sizeof (int),
1020 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001021 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001023 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001024 .procname = "bootloader_version",
1025 .data = &bootloader_version,
1026 .maxlen = sizeof (int),
1027 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001028 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001029 },
1030 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001031 .procname = "io_delay_type",
1032 .data = &io_delay_type,
1033 .maxlen = sizeof(int),
1034 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001035 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001036 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001038#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .procname = "randomize_va_space",
1041 .data = &randomize_va_space,
1042 .maxlen = sizeof(int),
1043 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001044 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001046#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001047#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001048 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001049 .procname = "spin_retry",
1050 .data = &spin_retry,
1051 .maxlen = sizeof (int),
1052 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001054 },
1055#endif
Len Brown673d5b42007-07-28 03:33:16 -04001056#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001057 {
Pavel Machekc255d842006-02-20 18:27:58 -08001058 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001059 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001060 .maxlen = sizeof (unsigned long),
1061 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001062 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001063 },
1064#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301065#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001066 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001067 .procname = "ignore-unaligned-usertrap",
1068 .data = &no_unaligned_warning,
1069 .maxlen = sizeof (int),
1070 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001071 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001072 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301073#endif
1074#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001075 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001076 .procname = "unaligned-dump-stack",
1077 .data = &unaligned_dump_stack,
1078 .maxlen = sizeof (int),
1079 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001080 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001081 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001082#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001083#ifdef CONFIG_DETECT_HUNG_TASK
1084 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001085 .procname = "hung_task_panic",
1086 .data = &sysctl_hung_task_panic,
1087 .maxlen = sizeof(int),
1088 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001089 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001090 .extra1 = &zero,
1091 .extra2 = &one,
1092 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001093 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001094 .procname = "hung_task_check_count",
1095 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001096 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001097 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001098 .proc_handler = proc_dointvec_minmax,
1099 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001100 },
1101 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001102 .procname = "hung_task_timeout_secs",
1103 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001104 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001105 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001106 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001107 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001108 },
1109 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001110 .procname = "hung_task_check_interval_secs",
1111 .data = &sysctl_hung_task_check_interval_secs,
1112 .maxlen = sizeof(unsigned long),
1113 .mode = 0644,
1114 .proc_handler = proc_dohung_task_timeout_secs,
1115 .extra2 = &hung_task_timeout_max,
1116 },
1117 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001118 .procname = "hung_task_warnings",
1119 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001120 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001121 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001122 .proc_handler = proc_dointvec_minmax,
1123 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001124 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001125#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001126#ifdef CONFIG_RT_MUTEXES
1127 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001128 .procname = "max_lock_depth",
1129 .data = &max_lock_depth,
1130 .maxlen = sizeof(int),
1131 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001132 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001133 },
1134#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001135 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001136 .procname = "poweroff_cmd",
1137 .data = &poweroff_cmd,
1138 .maxlen = POWEROFF_CMD_PATH_LEN,
1139 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001140 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001141 },
David Howells0b77f5b2008-04-29 01:01:32 -07001142#ifdef CONFIG_KEYS
1143 {
David Howells0b77f5b2008-04-29 01:01:32 -07001144 .procname = "keys",
1145 .mode = 0555,
1146 .child = key_sysctls,
1147 },
1148#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001149#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001150 /*
1151 * User-space scripts rely on the existence of this file
1152 * as a feature check for perf_events being enabled.
1153 *
1154 * So it's an ABI, do not remove!
1155 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001156 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001157 .procname = "perf_event_paranoid",
1158 .data = &sysctl_perf_event_paranoid,
1159 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001160 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001161 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001162 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001163 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001164 .procname = "perf_event_mlock_kb",
1165 .data = &sysctl_perf_event_mlock,
1166 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001167 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001168 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001169 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001170 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001171 .procname = "perf_event_max_sample_rate",
1172 .data = &sysctl_perf_event_sample_rate,
1173 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001174 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001175 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001176 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001177 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001178 {
1179 .procname = "perf_cpu_time_max_percent",
1180 .data = &sysctl_perf_cpu_time_max_percent,
1181 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1182 .mode = 0644,
1183 .proc_handler = perf_cpu_time_max_percent_handler,
1184 .extra1 = &zero,
1185 .extra2 = &one_hundred,
1186 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001187 {
1188 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001189 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001190 .maxlen = sizeof(sysctl_perf_event_max_stack),
1191 .mode = 0644,
1192 .proc_handler = perf_event_max_stack_handler,
1193 .extra1 = &zero,
1194 .extra2 = &six_hundred_forty_kb,
1195 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001196 {
1197 .procname = "perf_event_max_contexts_per_stack",
1198 .data = &sysctl_perf_event_max_contexts_per_stack,
1199 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1200 .mode = 0644,
1201 .proc_handler = perf_event_max_stack_handler,
1202 .extra1 = &zero,
1203 .extra2 = &one_thousand,
1204 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001205#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001206 {
1207 .procname = "panic_on_warn",
1208 .data = &panic_on_warn,
1209 .maxlen = sizeof(int),
1210 .mode = 0644,
1211 .proc_handler = proc_dointvec_minmax,
1212 .extra1 = &zero,
1213 .extra2 = &one,
1214 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001215#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1216 {
1217 .procname = "timer_migration",
1218 .data = &sysctl_timer_migration,
1219 .maxlen = sizeof(unsigned int),
1220 .mode = 0644,
1221 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001222 .extra1 = &zero,
1223 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001224 },
1225#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001226#ifdef CONFIG_BPF_SYSCALL
1227 {
1228 .procname = "unprivileged_bpf_disabled",
1229 .data = &sysctl_unprivileged_bpf_disabled,
1230 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1231 .mode = 0644,
1232 /* only handle a transition from default "0" to "1" */
1233 .proc_handler = proc_dointvec_minmax,
1234 .extra1 = &one,
1235 .extra2 = &one,
1236 },
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001237 {
1238 .procname = "bpf_stats_enabled",
1239 .data = &sysctl_bpf_stats_enabled,
1240 .maxlen = sizeof(sysctl_bpf_stats_enabled),
1241 .mode = 0644,
1242 .proc_handler = proc_dointvec_minmax_bpf_stats,
1243 .extra1 = &zero,
1244 .extra2 = &one,
1245 },
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08001246#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001247#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1248 {
1249 .procname = "panic_on_rcu_stall",
1250 .data = &sysctl_panic_on_rcu_stall,
1251 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1252 .mode = 0644,
1253 .proc_handler = proc_dointvec_minmax,
1254 .extra1 = &zero,
1255 .extra2 = &one,
1256 },
1257#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001258#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1259 {
1260 .procname = "stack_erasing",
1261 .data = NULL,
1262 .maxlen = sizeof(int),
1263 .mode = 0600,
1264 .proc_handler = stack_erasing_sysctl,
1265 .extra1 = &zero,
1266 .extra2 = &one,
1267 },
1268#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001269 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270};
1271
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001272static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 .procname = "overcommit_memory",
1275 .data = &sysctl_overcommit_memory,
1276 .maxlen = sizeof(sysctl_overcommit_memory),
1277 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001278 .proc_handler = proc_dointvec_minmax,
1279 .extra1 = &zero,
1280 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 },
1282 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001283 .procname = "panic_on_oom",
1284 .data = &sysctl_panic_on_oom,
1285 .maxlen = sizeof(sysctl_panic_on_oom),
1286 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001287 .proc_handler = proc_dointvec_minmax,
1288 .extra1 = &zero,
1289 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001290 },
1291 {
David Rientjesfe071d72007-10-16 23:25:56 -07001292 .procname = "oom_kill_allocating_task",
1293 .data = &sysctl_oom_kill_allocating_task,
1294 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1295 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001296 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001297 },
1298 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001299 .procname = "oom_dump_tasks",
1300 .data = &sysctl_oom_dump_tasks,
1301 .maxlen = sizeof(sysctl_oom_dump_tasks),
1302 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001303 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001304 },
1305 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 .procname = "overcommit_ratio",
1307 .data = &sysctl_overcommit_ratio,
1308 .maxlen = sizeof(sysctl_overcommit_ratio),
1309 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001310 .proc_handler = overcommit_ratio_handler,
1311 },
1312 {
1313 .procname = "overcommit_kbytes",
1314 .data = &sysctl_overcommit_kbytes,
1315 .maxlen = sizeof(sysctl_overcommit_kbytes),
1316 .mode = 0644,
1317 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 },
1319 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 .procname = "page-cluster",
1321 .data = &page_cluster,
1322 .maxlen = sizeof(int),
1323 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001324 .proc_handler = proc_dointvec_minmax,
1325 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 },
1327 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 .procname = "dirty_background_ratio",
1329 .data = &dirty_background_ratio,
1330 .maxlen = sizeof(dirty_background_ratio),
1331 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001332 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 .extra1 = &zero,
1334 .extra2 = &one_hundred,
1335 },
1336 {
David Rientjes2da02992009-01-06 14:39:31 -08001337 .procname = "dirty_background_bytes",
1338 .data = &dirty_background_bytes,
1339 .maxlen = sizeof(dirty_background_bytes),
1340 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001341 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001342 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001343 },
1344 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 .procname = "dirty_ratio",
1346 .data = &vm_dirty_ratio,
1347 .maxlen = sizeof(vm_dirty_ratio),
1348 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001349 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 .extra1 = &zero,
1351 .extra2 = &one_hundred,
1352 },
1353 {
David Rientjes2da02992009-01-06 14:39:31 -08001354 .procname = "dirty_bytes",
1355 .data = &vm_dirty_bytes,
1356 .maxlen = sizeof(vm_dirty_bytes),
1357 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001358 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001359 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001360 },
1361 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001363 .data = &dirty_writeback_interval,
1364 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001366 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 },
1368 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001370 .data = &dirty_expire_interval,
1371 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001373 .proc_handler = proc_dointvec_minmax,
1374 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 },
1376 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001377 .procname = "dirtytime_expire_seconds",
1378 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001379 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001380 .mode = 0644,
1381 .proc_handler = dirtytime_interval_handler,
1382 .extra1 = &zero,
1383 },
1384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 .procname = "swappiness",
1386 .data = &vm_swappiness,
1387 .maxlen = sizeof(vm_swappiness),
1388 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001389 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 .extra1 = &zero,
1391 .extra2 = &one_hundred,
1392 },
1393#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001394 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001396 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 .maxlen = sizeof(unsigned long),
1398 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001399 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001400 },
1401#ifdef CONFIG_NUMA
1402 {
1403 .procname = "nr_hugepages_mempolicy",
1404 .data = NULL,
1405 .maxlen = sizeof(unsigned long),
1406 .mode = 0644,
1407 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001408 },
Kemi Wang45180852017-11-15 17:38:22 -08001409 {
1410 .procname = "numa_stat",
1411 .data = &sysctl_vm_numa_stat,
1412 .maxlen = sizeof(int),
1413 .mode = 0644,
1414 .proc_handler = sysctl_vm_numa_stat_handler,
1415 .extra1 = &zero,
1416 .extra2 = &one,
1417 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001418#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 .procname = "hugetlb_shm_group",
1421 .data = &sysctl_hugetlb_shm_group,
1422 .maxlen = sizeof(gid_t),
1423 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001424 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 },
Adam Litke54f9f802007-10-16 01:26:20 -07001426 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001427 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001428 .data = NULL,
1429 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001431 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001432 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433#endif
1434 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 .procname = "lowmem_reserve_ratio",
1436 .data = &sysctl_lowmem_reserve_ratio,
1437 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1438 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001439 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 },
1441 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001442 .procname = "drop_caches",
1443 .data = &sysctl_drop_caches,
1444 .maxlen = sizeof(int),
1445 .mode = 0644,
1446 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001447 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001448 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001449 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001450#ifdef CONFIG_COMPACTION
1451 {
1452 .procname = "compact_memory",
1453 .data = &sysctl_compact_memory,
1454 .maxlen = sizeof(int),
1455 .mode = 0200,
1456 .proc_handler = sysctl_compaction_handler,
1457 },
Mel Gorman5e771902010-05-24 14:32:31 -07001458 {
1459 .procname = "extfrag_threshold",
1460 .data = &sysctl_extfrag_threshold,
1461 .maxlen = sizeof(int),
1462 .mode = 0644,
1463 .proc_handler = sysctl_extfrag_handler,
1464 .extra1 = &min_extfrag_threshold,
1465 .extra2 = &max_extfrag_threshold,
1466 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001467 {
1468 .procname = "compact_unevictable_allowed",
1469 .data = &sysctl_compact_unevictable_allowed,
1470 .maxlen = sizeof(int),
1471 .mode = 0644,
1472 .proc_handler = proc_dointvec,
1473 .extra1 = &zero,
1474 .extra2 = &one,
1475 },
Mel Gorman5e771902010-05-24 14:32:31 -07001476
Mel Gorman76ab0f52010-05-24 14:32:28 -07001477#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001478 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 .procname = "min_free_kbytes",
1480 .data = &min_free_kbytes,
1481 .maxlen = sizeof(min_free_kbytes),
1482 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001483 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 .extra1 = &zero,
1485 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001486 {
Mel Gorman1c308442018-12-28 00:35:52 -08001487 .procname = "watermark_boost_factor",
1488 .data = &watermark_boost_factor,
1489 .maxlen = sizeof(watermark_boost_factor),
1490 .mode = 0644,
1491 .proc_handler = watermark_boost_factor_sysctl_handler,
1492 .extra1 = &zero,
1493 },
1494 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001495 .procname = "watermark_scale_factor",
1496 .data = &watermark_scale_factor,
1497 .maxlen = sizeof(watermark_scale_factor),
1498 .mode = 0644,
1499 .proc_handler = watermark_scale_factor_sysctl_handler,
1500 .extra1 = &one,
1501 .extra2 = &one_thousand,
1502 },
1503 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001504 .procname = "percpu_pagelist_fraction",
1505 .data = &percpu_pagelist_fraction,
1506 .maxlen = sizeof(percpu_pagelist_fraction),
1507 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001508 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001509 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001510 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511#ifdef CONFIG_MMU
1512 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 .procname = "max_map_count",
1514 .data = &sysctl_max_map_count,
1515 .maxlen = sizeof(sysctl_max_map_count),
1516 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001517 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001518 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001520#else
1521 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001522 .procname = "nr_trim_pages",
1523 .data = &sysctl_nr_trim_pages,
1524 .maxlen = sizeof(sysctl_nr_trim_pages),
1525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001526 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001527 .extra1 = &zero,
1528 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529#endif
1530 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 .procname = "laptop_mode",
1532 .data = &laptop_mode,
1533 .maxlen = sizeof(laptop_mode),
1534 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001535 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 },
1537 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 .procname = "block_dump",
1539 .data = &block_dump,
1540 .maxlen = sizeof(block_dump),
1541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001542 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 .extra1 = &zero,
1544 },
1545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 .procname = "vfs_cache_pressure",
1547 .data = &sysctl_vfs_cache_pressure,
1548 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1549 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001550 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 .extra1 = &zero,
1552 },
1553#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1554 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 .procname = "legacy_va_layout",
1556 .data = &sysctl_legacy_va_layout,
1557 .maxlen = sizeof(sysctl_legacy_va_layout),
1558 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001559 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 .extra1 = &zero,
1561 },
1562#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001563#ifdef CONFIG_NUMA
1564 {
Christoph Lameter17436602006-01-18 17:42:32 -08001565 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001566 .data = &node_reclaim_mode,
1567 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001569 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001570 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001571 },
Christoph Lameter96146342006-07-03 00:24:13 -07001572 {
Christoph Lameter96146342006-07-03 00:24:13 -07001573 .procname = "min_unmapped_ratio",
1574 .data = &sysctl_min_unmapped_ratio,
1575 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001577 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001578 .extra1 = &zero,
1579 .extra2 = &one_hundred,
1580 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001581 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001582 .procname = "min_slab_ratio",
1583 .data = &sysctl_min_slab_ratio,
1584 .maxlen = sizeof(sysctl_min_slab_ratio),
1585 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001586 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001587 .extra1 = &zero,
1588 .extra2 = &one_hundred,
1589 },
Christoph Lameter17436602006-01-18 17:42:32 -08001590#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001591#ifdef CONFIG_SMP
1592 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001593 .procname = "stat_interval",
1594 .data = &sysctl_stat_interval,
1595 .maxlen = sizeof(sysctl_stat_interval),
1596 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001597 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001598 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001599 {
1600 .procname = "stat_refresh",
1601 .data = NULL,
1602 .maxlen = 0,
1603 .mode = 0600,
1604 .proc_handler = vmstat_refresh,
1605 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001606#endif
David Howells6e141542009-12-15 19:27:45 +00001607#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001608 {
Eric Parised032182007-06-28 15:55:21 -04001609 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001610 .data = &dac_mmap_min_addr,
1611 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001612 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001613 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001614 },
David Howells6e141542009-12-15 19:27:45 +00001615#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001616#ifdef CONFIG_NUMA
1617 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001618 .procname = "numa_zonelist_order",
1619 .data = &numa_zonelist_order,
1620 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1621 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001622 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001623 },
1624#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001625#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001626 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001627 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001628 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001629#ifdef CONFIG_X86_32
1630 .data = &vdso32_enabled,
1631 .maxlen = sizeof(vdso32_enabled),
1632#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001633 .data = &vdso_enabled,
1634 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001635#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001636 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001637 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001638 .extra1 = &zero,
1639 },
1640#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001641#ifdef CONFIG_HIGHMEM
1642 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001643 .procname = "highmem_is_dirtyable",
1644 .data = &vm_highmem_is_dirtyable,
1645 .maxlen = sizeof(vm_highmem_is_dirtyable),
1646 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001647 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001648 .extra1 = &zero,
1649 .extra2 = &one,
1650 },
1651#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001652#ifdef CONFIG_MEMORY_FAILURE
1653 {
Andi Kleen6a460792009-09-16 11:50:15 +02001654 .procname = "memory_failure_early_kill",
1655 .data = &sysctl_memory_failure_early_kill,
1656 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1657 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001658 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001659 .extra1 = &zero,
1660 .extra2 = &one,
1661 },
1662 {
Andi Kleen6a460792009-09-16 11:50:15 +02001663 .procname = "memory_failure_recovery",
1664 .data = &sysctl_memory_failure_recovery,
1665 .maxlen = sizeof(sysctl_memory_failure_recovery),
1666 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001667 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001668 .extra1 = &zero,
1669 .extra2 = &one,
1670 },
1671#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001672 {
1673 .procname = "user_reserve_kbytes",
1674 .data = &sysctl_user_reserve_kbytes,
1675 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1676 .mode = 0644,
1677 .proc_handler = proc_doulongvec_minmax,
1678 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001679 {
1680 .procname = "admin_reserve_kbytes",
1681 .data = &sysctl_admin_reserve_kbytes,
1682 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1683 .mode = 0644,
1684 .proc_handler = proc_doulongvec_minmax,
1685 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001686#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1687 {
1688 .procname = "mmap_rnd_bits",
1689 .data = &mmap_rnd_bits,
1690 .maxlen = sizeof(mmap_rnd_bits),
1691 .mode = 0600,
1692 .proc_handler = proc_dointvec_minmax,
1693 .extra1 = (void *)&mmap_rnd_bits_min,
1694 .extra2 = (void *)&mmap_rnd_bits_max,
1695 },
1696#endif
1697#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1698 {
1699 .procname = "mmap_rnd_compat_bits",
1700 .data = &mmap_rnd_compat_bits,
1701 .maxlen = sizeof(mmap_rnd_compat_bits),
1702 .mode = 0600,
1703 .proc_handler = proc_dointvec_minmax,
1704 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1705 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1706 },
1707#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001708 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709};
1710
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001711static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 .procname = "inode-nr",
1714 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001715 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001717 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 },
1719 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 .procname = "inode-state",
1721 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001722 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001724 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 },
1726 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 .procname = "file-nr",
1728 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001729 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001731 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 },
1733 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 .procname = "file-max",
1735 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001736 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001738 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 },
1740 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001741 .procname = "nr_open",
1742 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001743 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001744 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001745 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001746 .extra1 = &sysctl_nr_open_min,
1747 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001748 },
1749 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 .procname = "dentry-state",
1751 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001752 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001754 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 },
1756 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 .procname = "overflowuid",
1758 .data = &fs_overflowuid,
1759 .maxlen = sizeof(int),
1760 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001761 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 .extra1 = &minolduid,
1763 .extra2 = &maxolduid,
1764 },
1765 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 .procname = "overflowgid",
1767 .data = &fs_overflowgid,
1768 .maxlen = sizeof(int),
1769 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001770 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 .extra1 = &minolduid,
1772 .extra2 = &maxolduid,
1773 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001774#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 .procname = "leases-enable",
1777 .data = &leases_enable,
1778 .maxlen = sizeof(int),
1779 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001780 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001782#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783#ifdef CONFIG_DNOTIFY
1784 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 .procname = "dir-notify-enable",
1786 .data = &dir_notify_enable,
1787 .maxlen = sizeof(int),
1788 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001789 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 },
1791#endif
1792#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001793#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 .procname = "lease-break-time",
1796 .data = &lease_break_time,
1797 .maxlen = sizeof(int),
1798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001799 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001801#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001802#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 .procname = "aio-nr",
1805 .data = &aio_nr,
1806 .maxlen = sizeof(aio_nr),
1807 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001808 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 },
1810 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 .procname = "aio-max-nr",
1812 .data = &aio_max_nr,
1813 .maxlen = sizeof(aio_max_nr),
1814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001815 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001817#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001818#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001819 {
Robert Love0399cb02005-07-13 12:38:18 -04001820 .procname = "inotify",
1821 .mode = 0555,
1822 .child = inotify_table,
1823 },
1824#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001825#ifdef CONFIG_EPOLL
1826 {
1827 .procname = "epoll",
1828 .mode = 0555,
1829 .child = epoll_table,
1830 },
1831#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001833 {
Kees Cook800179c2012-07-25 17:29:07 -07001834 .procname = "protected_symlinks",
1835 .data = &sysctl_protected_symlinks,
1836 .maxlen = sizeof(int),
1837 .mode = 0600,
1838 .proc_handler = proc_dointvec_minmax,
1839 .extra1 = &zero,
1840 .extra2 = &one,
1841 },
1842 {
1843 .procname = "protected_hardlinks",
1844 .data = &sysctl_protected_hardlinks,
1845 .maxlen = sizeof(int),
1846 .mode = 0600,
1847 .proc_handler = proc_dointvec_minmax,
1848 .extra1 = &zero,
1849 .extra2 = &one,
1850 },
1851 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001852 .procname = "protected_fifos",
1853 .data = &sysctl_protected_fifos,
1854 .maxlen = sizeof(int),
1855 .mode = 0600,
1856 .proc_handler = proc_dointvec_minmax,
1857 .extra1 = &zero,
1858 .extra2 = &two,
1859 },
1860 {
1861 .procname = "protected_regular",
1862 .data = &sysctl_protected_regular,
1863 .maxlen = sizeof(int),
1864 .mode = 0600,
1865 .proc_handler = proc_dointvec_minmax,
1866 .extra1 = &zero,
1867 .extra2 = &two,
1868 },
1869 {
Alan Coxd6e71142005-06-23 00:09:43 -07001870 .procname = "suid_dumpable",
1871 .data = &suid_dumpable,
1872 .maxlen = sizeof(int),
1873 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001874 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001875 .extra1 = &zero,
1876 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001877 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001878#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1879 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001880 .procname = "binfmt_misc",
1881 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001882 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001883 },
1884#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001885 {
Jens Axboeff9da692010-06-03 14:54:39 +02001886 .procname = "pipe-max-size",
1887 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001888 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001889 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001890 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001891 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001892 {
1893 .procname = "pipe-user-pages-hard",
1894 .data = &pipe_user_pages_hard,
1895 .maxlen = sizeof(pipe_user_pages_hard),
1896 .mode = 0644,
1897 .proc_handler = proc_doulongvec_minmax,
1898 },
1899 {
1900 .procname = "pipe-user-pages-soft",
1901 .data = &pipe_user_pages_soft,
1902 .maxlen = sizeof(pipe_user_pages_soft),
1903 .mode = 0644,
1904 .proc_handler = proc_doulongvec_minmax,
1905 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001906 {
1907 .procname = "mount-max",
1908 .data = &sysctl_mount_max,
1909 .maxlen = sizeof(unsigned int),
1910 .mode = 0644,
1911 .proc_handler = proc_dointvec_minmax,
1912 .extra1 = &one,
1913 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001914 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915};
1916
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001917static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001918#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001919 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001920 .procname = "exception-trace",
1921 .data = &show_unhandled_signals,
1922 .maxlen = sizeof(int),
1923 .mode = 0644,
1924 .proc_handler = proc_dointvec
1925 },
1926#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001927#if defined(CONFIG_OPTPROBES)
1928 {
1929 .procname = "kprobes-optimization",
1930 .data = &sysctl_kprobes_optimization,
1931 .maxlen = sizeof(int),
1932 .mode = 0644,
1933 .proc_handler = proc_kprobes_optimization_handler,
1934 .extra1 = &zero,
1935 .extra2 = &one,
1936 },
1937#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001938 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939};
1940
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001941static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001942 { }
Robert Love0eeca282005-07-12 17:06:03 -04001943};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001945int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001946{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001947 struct ctl_table_header *hdr;
1948
1949 hdr = register_sysctl_table(sysctl_base_table);
1950 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001951 return 0;
1952}
1953
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001954#endif /* CONFIG_SYSCTL */
1955
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956/*
1957 * /proc/sys support
1958 */
1959
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001960#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Kees Cookf8808302014-06-06 14:37:17 -07001962static int _proc_do_string(char *data, int maxlen, int write,
1963 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001964 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001965{
1966 size_t len;
1967 char __user *p;
1968 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001969
1970 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001971 *lenp = 0;
1972 return 0;
1973 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001974
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001975 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001976 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1977 /* Only continue writes not past the end of buffer. */
1978 len = strlen(data);
1979 if (len > maxlen - 1)
1980 len = maxlen - 1;
1981
1982 if (*ppos > len)
1983 return 0;
1984 len = *ppos;
1985 } else {
1986 /* Start writing from beginning of buffer. */
1987 len = 0;
1988 }
1989
Kees Cook2ca9bb42014-06-06 14:37:18 -07001990 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001991 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001992 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001993 if (get_user(c, p++))
1994 return -EFAULT;
1995 if (c == 0 || c == '\n')
1996 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001997 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001998 }
Kees Cookf8808302014-06-06 14:37:17 -07001999 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002000 } else {
2001 len = strlen(data);
2002 if (len > maxlen)
2003 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002004
2005 if (*ppos > len) {
2006 *lenp = 0;
2007 return 0;
2008 }
2009
2010 data += *ppos;
2011 len -= *ppos;
2012
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002013 if (len > *lenp)
2014 len = *lenp;
2015 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002016 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002017 return -EFAULT;
2018 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002019 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002020 return -EFAULT;
2021 len++;
2022 }
2023 *lenp = len;
2024 *ppos += len;
2025 }
2026 return 0;
2027}
2028
Kees Cookf4aacea2014-06-06 14:37:19 -07002029static void warn_sysctl_write(struct ctl_table *table)
2030{
2031 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2032 "This will not be supported in the future. To silence this\n"
2033 "warning, set kernel.sysctl_writes_strict = -1\n",
2034 current->comm, table->procname);
2035}
2036
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002038 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002039 * @ppos: file position
2040 * @table: the sysctl table
2041 *
2042 * Returns true if the first position is non-zero and the sysctl_writes_strict
2043 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002044 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002045 */
2046static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2047 struct ctl_table *table)
2048{
2049 if (!*ppos)
2050 return false;
2051
2052 switch (sysctl_writes_strict) {
2053 case SYSCTL_WRITES_STRICT:
2054 return true;
2055 case SYSCTL_WRITES_WARN:
2056 warn_sysctl_write(table);
2057 return false;
2058 default:
2059 return false;
2060 }
2061}
2062
2063/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 * proc_dostring - read a string sysctl
2065 * @table: the sysctl table
2066 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 * @buffer: the user buffer
2068 * @lenp: the size of the user buffer
2069 * @ppos: file position
2070 *
2071 * Reads/writes a string from/to the user buffer. If the kernel
2072 * buffer provided is not large enough to hold the string, the
2073 * string is truncated. The copied string is %NULL-terminated.
2074 * If the string is being read by the user process, it is copied
2075 * and a newline '\n' is added. It is truncated if the buffer is
2076 * not large enough.
2077 *
2078 * Returns 0 on success.
2079 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002080int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 void __user *buffer, size_t *lenp, loff_t *ppos)
2082{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002083 if (write)
2084 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002085
Kees Cookf8808302014-06-06 14:37:17 -07002086 return _proc_do_string((char *)(table->data), table->maxlen, write,
2087 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088}
2089
Amerigo Wang00b7c332010-05-05 00:26:45 +00002090static size_t proc_skip_spaces(char **buf)
2091{
2092 size_t ret;
2093 char *tmp = skip_spaces(*buf);
2094 ret = tmp - *buf;
2095 *buf = tmp;
2096 return ret;
2097}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002099static void proc_skip_char(char **buf, size_t *size, const char v)
2100{
2101 while (*size) {
2102 if (**buf != v)
2103 break;
2104 (*size)--;
2105 (*buf)++;
2106 }
2107}
2108
Amerigo Wang00b7c332010-05-05 00:26:45 +00002109#define TMPBUFLEN 22
2110/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002111 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002112 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002113 * @buf: a kernel buffer
2114 * @size: size of the kernel buffer
2115 * @val: this is where the number will be stored
2116 * @neg: set to %TRUE if number is negative
2117 * @perm_tr: a vector which contains the allowed trailers
2118 * @perm_tr_len: size of the perm_tr vector
2119 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002120 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002121 * In case of success %0 is returned and @buf and @size are updated with
2122 * the amount of bytes read. If @tr is non-NULL and a trailing
2123 * character exists (size is non-zero after returning from this
2124 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002125 */
2126static int proc_get_long(char **buf, size_t *size,
2127 unsigned long *val, bool *neg,
2128 const char *perm_tr, unsigned perm_tr_len, char *tr)
2129{
2130 int len;
2131 char *p, tmp[TMPBUFLEN];
2132
2133 if (!*size)
2134 return -EINVAL;
2135
2136 len = *size;
2137 if (len > TMPBUFLEN - 1)
2138 len = TMPBUFLEN - 1;
2139
2140 memcpy(tmp, *buf, len);
2141
2142 tmp[len] = 0;
2143 p = tmp;
2144 if (*p == '-' && *size > 1) {
2145 *neg = true;
2146 p++;
2147 } else
2148 *neg = false;
2149 if (!isdigit(*p))
2150 return -EINVAL;
2151
2152 *val = simple_strtoul(p, &p, 0);
2153
2154 len = p - tmp;
2155
2156 /* We don't know if the next char is whitespace thus we may accept
2157 * invalid integers (e.g. 1234...a) or two integers instead of one
2158 * (e.g. 123...1). So lets not allow such large numbers. */
2159 if (len == TMPBUFLEN - 1)
2160 return -EINVAL;
2161
2162 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2163 return -EINVAL;
2164
2165 if (tr && (len < *size))
2166 *tr = *p;
2167
2168 *buf += len;
2169 *size -= len;
2170
2171 return 0;
2172}
2173
2174/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002175 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002176 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002177 * @buf: the user buffer
2178 * @size: the size of the user buffer
2179 * @val: the integer to be converted
2180 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002181 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002182 * In case of success %0 is returned and @buf and @size are updated with
2183 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002184 */
2185static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2186 bool neg)
2187{
2188 int len;
2189 char tmp[TMPBUFLEN], *p = tmp;
2190
2191 sprintf(p, "%s%lu", neg ? "-" : "", val);
2192 len = strlen(tmp);
2193 if (len > *size)
2194 len = *size;
2195 if (copy_to_user(*buf, tmp, len))
2196 return -EFAULT;
2197 *size -= len;
2198 *buf += len;
2199 return 0;
2200}
2201#undef TMPBUFLEN
2202
2203static int proc_put_char(void __user **buf, size_t *size, char c)
2204{
2205 if (*size) {
2206 char __user **buffer = (char __user **)buf;
2207 if (put_user(c, *buffer))
2208 return -EFAULT;
2209 (*size)--, (*buffer)++;
2210 *buf = *buffer;
2211 }
2212 return 0;
2213}
2214
2215static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 int *valp,
2217 int write, void *data)
2218{
2219 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002220 if (*negp) {
2221 if (*lvalp > (unsigned long) INT_MAX + 1)
2222 return -EINVAL;
2223 *valp = -*lvalp;
2224 } else {
2225 if (*lvalp > (unsigned long) INT_MAX)
2226 return -EINVAL;
2227 *valp = *lvalp;
2228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 } else {
2230 int val = *valp;
2231 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002232 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002233 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002235 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 *lvalp = (unsigned long)val;
2237 }
2238 }
2239 return 0;
2240}
2241
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002242static int do_proc_douintvec_conv(unsigned long *lvalp,
2243 unsigned int *valp,
2244 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002245{
2246 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002247 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002248 return -EINVAL;
2249 *valp = *lvalp;
2250 } else {
2251 unsigned int val = *valp;
2252 *lvalp = (unsigned long)val;
2253 }
2254 return 0;
2255}
2256
Amerigo Wang00b7c332010-05-05 00:26:45 +00002257static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2258
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002259static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002260 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002261 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002262 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 int write, void *data),
2264 void *data)
2265{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002266 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002267 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002268 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 *lenp = 0;
2272 return 0;
2273 }
2274
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002275 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 vleft = table->maxlen / sizeof(*i);
2277 left = *lenp;
2278
2279 if (!conv)
2280 conv = do_proc_dointvec_conv;
2281
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002283 if (proc_first_pos_non_zero_ignore(ppos, table))
2284 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002285
Amerigo Wang00b7c332010-05-05 00:26:45 +00002286 if (left > PAGE_SIZE - 1)
2287 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002288 p = kbuf = memdup_user_nul(buffer, left);
2289 if (IS_ERR(kbuf))
2290 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002291 }
2292
2293 for (; left && vleft--; i++, first=0) {
2294 unsigned long lval;
2295 bool neg;
2296
2297 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002298 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002299
J. R. Okajima563b0462010-05-25 16:10:14 -07002300 if (!left)
2301 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002302 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002303 proc_wspace_sep,
2304 sizeof(proc_wspace_sep), NULL);
2305 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307 if (conv(&neg, &lval, i, 1, data)) {
2308 err = -EINVAL;
2309 break;
2310 }
2311 } else {
2312 if (conv(&neg, &lval, i, 0, data)) {
2313 err = -EINVAL;
2314 break;
2315 }
2316 if (!first)
2317 err = proc_put_char(&buffer, &left, '\t');
2318 if (err)
2319 break;
2320 err = proc_put_long(&buffer, &left, lval, neg);
2321 if (err)
2322 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 }
2324 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002325
2326 if (!write && !first && left && !err)
2327 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002328 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002329 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002330 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002331 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002332 if (first)
2333 return err ? : -EINVAL;
2334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002336out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002338 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339}
2340
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002341static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002342 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002343 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002344 int write, void *data),
2345 void *data)
2346{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002347 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002348 buffer, lenp, ppos, conv, data);
2349}
2350
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002351static int do_proc_douintvec_w(unsigned int *tbl_data,
2352 struct ctl_table *table,
2353 void __user *buffer,
2354 size_t *lenp, loff_t *ppos,
2355 int (*conv)(unsigned long *lvalp,
2356 unsigned int *valp,
2357 int write, void *data),
2358 void *data)
2359{
2360 unsigned long lval;
2361 int err = 0;
2362 size_t left;
2363 bool neg;
2364 char *kbuf = NULL, *p;
2365
2366 left = *lenp;
2367
2368 if (proc_first_pos_non_zero_ignore(ppos, table))
2369 goto bail_early;
2370
2371 if (left > PAGE_SIZE - 1)
2372 left = PAGE_SIZE - 1;
2373
2374 p = kbuf = memdup_user_nul(buffer, left);
2375 if (IS_ERR(kbuf))
2376 return -EINVAL;
2377
2378 left -= proc_skip_spaces(&p);
2379 if (!left) {
2380 err = -EINVAL;
2381 goto out_free;
2382 }
2383
2384 err = proc_get_long(&p, &left, &lval, &neg,
2385 proc_wspace_sep,
2386 sizeof(proc_wspace_sep), NULL);
2387 if (err || neg) {
2388 err = -EINVAL;
2389 goto out_free;
2390 }
2391
2392 if (conv(&lval, tbl_data, 1, data)) {
2393 err = -EINVAL;
2394 goto out_free;
2395 }
2396
2397 if (!err && left)
2398 left -= proc_skip_spaces(&p);
2399
2400out_free:
2401 kfree(kbuf);
2402 if (err)
2403 return -EINVAL;
2404
2405 return 0;
2406
2407 /* This is in keeping with old __do_proc_dointvec() */
2408bail_early:
2409 *ppos += *lenp;
2410 return err;
2411}
2412
2413static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2414 size_t *lenp, loff_t *ppos,
2415 int (*conv)(unsigned long *lvalp,
2416 unsigned int *valp,
2417 int write, void *data),
2418 void *data)
2419{
2420 unsigned long lval;
2421 int err = 0;
2422 size_t left;
2423
2424 left = *lenp;
2425
2426 if (conv(&lval, tbl_data, 0, data)) {
2427 err = -EINVAL;
2428 goto out;
2429 }
2430
2431 err = proc_put_long(&buffer, &left, lval, false);
2432 if (err || !left)
2433 goto out;
2434
2435 err = proc_put_char(&buffer, &left, '\n');
2436
2437out:
2438 *lenp -= left;
2439 *ppos += *lenp;
2440
2441 return err;
2442}
2443
2444static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2445 int write, void __user *buffer,
2446 size_t *lenp, loff_t *ppos,
2447 int (*conv)(unsigned long *lvalp,
2448 unsigned int *valp,
2449 int write, void *data),
2450 void *data)
2451{
2452 unsigned int *i, vleft;
2453
2454 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2455 *lenp = 0;
2456 return 0;
2457 }
2458
2459 i = (unsigned int *) tbl_data;
2460 vleft = table->maxlen / sizeof(*i);
2461
2462 /*
2463 * Arrays are not supported, keep this simple. *Do not* add
2464 * support for them.
2465 */
2466 if (vleft != 1) {
2467 *lenp = 0;
2468 return -EINVAL;
2469 }
2470
2471 if (!conv)
2472 conv = do_proc_douintvec_conv;
2473
2474 if (write)
2475 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2476 conv, data);
2477 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2478}
2479
2480static int do_proc_douintvec(struct ctl_table *table, int write,
2481 void __user *buffer, size_t *lenp, loff_t *ppos,
2482 int (*conv)(unsigned long *lvalp,
2483 unsigned int *valp,
2484 int write, void *data),
2485 void *data)
2486{
2487 return __do_proc_douintvec(table->data, table, write,
2488 buffer, lenp, ppos, conv, data);
2489}
2490
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491/**
2492 * proc_dointvec - read a vector of integers
2493 * @table: the sysctl table
2494 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 * @buffer: the user buffer
2496 * @lenp: the size of the user buffer
2497 * @ppos: file position
2498 *
2499 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2500 * values from/to the user buffer, treated as an ASCII string.
2501 *
2502 * Returns 0 on success.
2503 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002504int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 void __user *buffer, size_t *lenp, loff_t *ppos)
2506{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002507 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2508}
2509
2510/**
2511 * proc_douintvec - read a vector of unsigned integers
2512 * @table: the sysctl table
2513 * @write: %TRUE if this is a write to the sysctl file
2514 * @buffer: the user buffer
2515 * @lenp: the size of the user buffer
2516 * @ppos: file position
2517 *
2518 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2519 * values from/to the user buffer, treated as an ASCII string.
2520 *
2521 * Returns 0 on success.
2522 */
2523int proc_douintvec(struct ctl_table *table, int write,
2524 void __user *buffer, size_t *lenp, loff_t *ppos)
2525{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002526 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2527 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528}
2529
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002530/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002531 * Taint values can only be increased
2532 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002533 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002534static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002535 void __user *buffer, size_t *lenp, loff_t *ppos)
2536{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002537 struct ctl_table t;
2538 unsigned long tmptaint = get_taint();
2539 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002540
Bastian Blank91fcd412007-04-23 14:41:14 -07002541 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002542 return -EPERM;
2543
Andi Kleen25ddbb12008-10-15 22:01:41 -07002544 t = *table;
2545 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002546 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002547 if (err < 0)
2548 return err;
2549
2550 if (write) {
2551 /*
2552 * Poor man's atomic or. Not worth adding a primitive
2553 * to everyone's atomic.h for this
2554 */
2555 int i;
2556 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2557 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302558 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002559 }
2560 }
2561
2562 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002563}
2564
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002565#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002566static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002567 void __user *buffer, size_t *lenp, loff_t *ppos)
2568{
2569 if (write && !capable(CAP_SYS_ADMIN))
2570 return -EPERM;
2571
2572 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2573}
2574#endif
2575
Waiman Long24704f32018-04-10 16:35:38 -07002576/**
2577 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2578 * @min: pointer to minimum allowable value
2579 * @max: pointer to maximum allowable value
2580 *
2581 * The do_proc_dointvec_minmax_conv_param structure provides the
2582 * minimum and maximum values for doing range checking for those sysctl
2583 * parameters that use the proc_dointvec_minmax() handler.
2584 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585struct do_proc_dointvec_minmax_conv_param {
2586 int *min;
2587 int *max;
2588};
2589
Amerigo Wang00b7c332010-05-05 00:26:45 +00002590static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2591 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 int write, void *data)
2593{
2594 struct do_proc_dointvec_minmax_conv_param *param = data;
2595 if (write) {
2596 int val = *negp ? -*lvalp : *lvalp;
2597 if ((param->min && *param->min > val) ||
2598 (param->max && *param->max < val))
2599 return -EINVAL;
2600 *valp = val;
2601 } else {
2602 int val = *valp;
2603 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002604 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002605 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002607 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 *lvalp = (unsigned long)val;
2609 }
2610 }
2611 return 0;
2612}
2613
2614/**
2615 * proc_dointvec_minmax - read a vector of integers with min/max values
2616 * @table: the sysctl table
2617 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 * @buffer: the user buffer
2619 * @lenp: the size of the user buffer
2620 * @ppos: file position
2621 *
2622 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2623 * values from/to the user buffer, treated as an ASCII string.
2624 *
2625 * This routine will ensure the values are within the range specified by
2626 * table->extra1 (min) and table->extra2 (max).
2627 *
Waiman Long24704f32018-04-10 16:35:38 -07002628 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002630int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 void __user *buffer, size_t *lenp, loff_t *ppos)
2632{
2633 struct do_proc_dointvec_minmax_conv_param param = {
2634 .min = (int *) table->extra1,
2635 .max = (int *) table->extra2,
2636 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002637 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 do_proc_dointvec_minmax_conv, &param);
2639}
2640
Waiman Long24704f32018-04-10 16:35:38 -07002641/**
2642 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2643 * @min: pointer to minimum allowable value
2644 * @max: pointer to maximum allowable value
2645 *
2646 * The do_proc_douintvec_minmax_conv_param structure provides the
2647 * minimum and maximum values for doing range checking for those sysctl
2648 * parameters that use the proc_douintvec_minmax() handler.
2649 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002650struct do_proc_douintvec_minmax_conv_param {
2651 unsigned int *min;
2652 unsigned int *max;
2653};
2654
2655static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2656 unsigned int *valp,
2657 int write, void *data)
2658{
2659 struct do_proc_douintvec_minmax_conv_param *param = data;
2660
2661 if (write) {
2662 unsigned int val = *lvalp;
2663
Joe Lawrencefb910c42017-11-17 15:29:28 -08002664 if (*lvalp > UINT_MAX)
2665 return -EINVAL;
2666
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002667 if ((param->min && *param->min > val) ||
2668 (param->max && *param->max < val))
2669 return -ERANGE;
2670
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002671 *valp = val;
2672 } else {
2673 unsigned int val = *valp;
2674 *lvalp = (unsigned long) val;
2675 }
2676
2677 return 0;
2678}
2679
2680/**
2681 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2682 * @table: the sysctl table
2683 * @write: %TRUE if this is a write to the sysctl file
2684 * @buffer: the user buffer
2685 * @lenp: the size of the user buffer
2686 * @ppos: file position
2687 *
2688 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2689 * values from/to the user buffer, treated as an ASCII string. Negative
2690 * strings are not allowed.
2691 *
2692 * This routine will ensure the values are within the range specified by
2693 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2694 * check for UINT_MAX to avoid having to support wrap around uses from
2695 * userspace.
2696 *
Waiman Long24704f32018-04-10 16:35:38 -07002697 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002698 */
2699int proc_douintvec_minmax(struct ctl_table *table, int write,
2700 void __user *buffer, size_t *lenp, loff_t *ppos)
2701{
2702 struct do_proc_douintvec_minmax_conv_param param = {
2703 .min = (unsigned int *) table->extra1,
2704 .max = (unsigned int *) table->extra2,
2705 };
2706 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2707 do_proc_douintvec_minmax_conv, &param);
2708}
2709
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002710static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2711 unsigned int *valp,
2712 int write, void *data)
2713{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002714 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002715 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002716
Joe Lawrencefb910c42017-11-17 15:29:28 -08002717 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002718 if (val == 0)
2719 return -EINVAL;
2720
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002721 *valp = val;
2722 } else {
2723 unsigned int val = *valp;
2724 *lvalp = (unsigned long) val;
2725 }
2726
2727 return 0;
2728}
2729
Eric Biggers319e0a22018-02-06 15:41:49 -08002730static int proc_dopipe_max_size(struct ctl_table *table, int write,
2731 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002732{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002733 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002734 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002735}
2736
Kees Cook54b50192012-07-30 14:39:18 -07002737static void validate_coredump_safety(void)
2738{
Alex Kelly046d6622012-10-04 17:15:23 -07002739#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002740 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002741 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002742 printk(KERN_WARNING
2743"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2744"Pipe handler or fully qualified core dump path required.\n"
2745"Set kernel.core_pattern before fs.suid_dumpable.\n"
2746 );
Kees Cook54b50192012-07-30 14:39:18 -07002747 }
Alex Kelly046d6622012-10-04 17:15:23 -07002748#endif
Kees Cook54b50192012-07-30 14:39:18 -07002749}
2750
2751static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2752 void __user *buffer, size_t *lenp, loff_t *ppos)
2753{
2754 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2755 if (!error)
2756 validate_coredump_safety();
2757 return error;
2758}
2759
Alex Kelly046d6622012-10-04 17:15:23 -07002760#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002761static int proc_dostring_coredump(struct ctl_table *table, int write,
2762 void __user *buffer, size_t *lenp, loff_t *ppos)
2763{
2764 int error = proc_dostring(table, write, buffer, lenp, ppos);
2765 if (!error)
2766 validate_coredump_safety();
2767 return error;
2768}
Alex Kelly046d6622012-10-04 17:15:23 -07002769#endif
Kees Cook54b50192012-07-30 14:39:18 -07002770
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002771static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 void __user *buffer,
2773 size_t *lenp, loff_t *ppos,
2774 unsigned long convmul,
2775 unsigned long convdiv)
2776{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002777 unsigned long *i, *min, *max;
2778 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002779 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002780 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002781
2782 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 *lenp = 0;
2784 return 0;
2785 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002786
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002787 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 min = (unsigned long *) table->extra1;
2789 max = (unsigned long *) table->extra2;
2790 vleft = table->maxlen / sizeof(unsigned long);
2791 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002792
2793 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002794 if (proc_first_pos_non_zero_ignore(ppos, table))
2795 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002796
Amerigo Wang00b7c332010-05-05 00:26:45 +00002797 if (left > PAGE_SIZE - 1)
2798 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002799 p = kbuf = memdup_user_nul(buffer, left);
2800 if (IS_ERR(kbuf))
2801 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002802 }
2803
Eric Dumazet27b3d802010-10-07 12:59:29 -07002804 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002805 unsigned long val;
2806
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002808 bool neg;
2809
Al Viro70f6cbb2015-12-24 00:13:10 -05002810 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08002811 if (!left)
2812 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002813
Al Viro70f6cbb2015-12-24 00:13:10 -05002814 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002815 proc_wspace_sep,
2816 sizeof(proc_wspace_sep), NULL);
2817 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 break;
2819 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002821 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 if ((min && val < *min) || (max && val > *max))
2823 continue;
2824 *i = val;
2825 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002826 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002827 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002828 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002829 if (err)
2830 break;
2831 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002832 err = proc_put_long(&buffer, &left, val, false);
2833 if (err)
2834 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 }
2836 }
2837
Amerigo Wang00b7c332010-05-05 00:26:45 +00002838 if (!write && !first && left && !err)
2839 err = proc_put_char(&buffer, &left, '\n');
2840 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002841 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002843 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002844 if (first)
2845 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002848out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002850 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851}
2852
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002853static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002854 void __user *buffer,
2855 size_t *lenp, loff_t *ppos,
2856 unsigned long convmul,
2857 unsigned long convdiv)
2858{
2859 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002860 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002861}
2862
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863/**
2864 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2865 * @table: the sysctl table
2866 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 * @buffer: the user buffer
2868 * @lenp: the size of the user buffer
2869 * @ppos: file position
2870 *
2871 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2872 * values from/to the user buffer, treated as an ASCII string.
2873 *
2874 * This routine will ensure the values are within the range specified by
2875 * table->extra1 (min) and table->extra2 (max).
2876 *
2877 * Returns 0 on success.
2878 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002879int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 void __user *buffer, size_t *lenp, loff_t *ppos)
2881{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002882 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883}
2884
2885/**
2886 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2887 * @table: the sysctl table
2888 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 * @buffer: the user buffer
2890 * @lenp: the size of the user buffer
2891 * @ppos: file position
2892 *
2893 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2894 * values from/to the user buffer, treated as an ASCII string. The values
2895 * are treated as milliseconds, and converted to jiffies when they are stored.
2896 *
2897 * This routine will ensure the values are within the range specified by
2898 * table->extra1 (min) and table->extra2 (max).
2899 *
2900 * Returns 0 on success.
2901 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002902int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 void __user *buffer,
2904 size_t *lenp, loff_t *ppos)
2905{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002906 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 lenp, ppos, HZ, 1000l);
2908}
2909
2910
Amerigo Wang00b7c332010-05-05 00:26:45 +00002911static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 int *valp,
2913 int write, void *data)
2914{
2915 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002916 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002917 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2919 } else {
2920 int val = *valp;
2921 unsigned long lval;
2922 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002923 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002924 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002926 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 lval = (unsigned long)val;
2928 }
2929 *lvalp = lval / HZ;
2930 }
2931 return 0;
2932}
2933
Amerigo Wang00b7c332010-05-05 00:26:45 +00002934static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 int *valp,
2936 int write, void *data)
2937{
2938 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002939 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2940 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2942 } else {
2943 int val = *valp;
2944 unsigned long lval;
2945 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002946 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002947 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002949 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 lval = (unsigned long)val;
2951 }
2952 *lvalp = jiffies_to_clock_t(lval);
2953 }
2954 return 0;
2955}
2956
Amerigo Wang00b7c332010-05-05 00:26:45 +00002957static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 int *valp,
2959 int write, void *data)
2960{
2961 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002962 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2963
2964 if (jif > INT_MAX)
2965 return 1;
2966 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 } else {
2968 int val = *valp;
2969 unsigned long lval;
2970 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002971 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002972 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002974 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 lval = (unsigned long)val;
2976 }
2977 *lvalp = jiffies_to_msecs(lval);
2978 }
2979 return 0;
2980}
2981
2982/**
2983 * proc_dointvec_jiffies - read a vector of integers as seconds
2984 * @table: the sysctl table
2985 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 * @buffer: the user buffer
2987 * @lenp: the size of the user buffer
2988 * @ppos: file position
2989 *
2990 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2991 * values from/to the user buffer, treated as an ASCII string.
2992 * The values read are assumed to be in seconds, and are converted into
2993 * jiffies.
2994 *
2995 * Returns 0 on success.
2996 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002997int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 void __user *buffer, size_t *lenp, loff_t *ppos)
2999{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003000 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 do_proc_dointvec_jiffies_conv,NULL);
3002}
3003
3004/**
3005 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3006 * @table: the sysctl table
3007 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 * @buffer: the user buffer
3009 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003010 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 *
3012 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3013 * values from/to the user buffer, treated as an ASCII string.
3014 * The values read are assumed to be in 1/USER_HZ seconds, and
3015 * are converted into jiffies.
3016 *
3017 * Returns 0 on success.
3018 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003019int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 void __user *buffer, size_t *lenp, loff_t *ppos)
3021{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003022 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 do_proc_dointvec_userhz_jiffies_conv,NULL);
3024}
3025
3026/**
3027 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3028 * @table: the sysctl table
3029 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 * @buffer: the user buffer
3031 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003032 * @ppos: file position
3033 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 *
3035 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3036 * values from/to the user buffer, treated as an ASCII string.
3037 * The values read are assumed to be in 1/1000 seconds, and
3038 * are converted into jiffies.
3039 *
3040 * Returns 0 on success.
3041 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003042int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 void __user *buffer, size_t *lenp, loff_t *ppos)
3044{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003045 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 do_proc_dointvec_ms_jiffies_conv, NULL);
3047}
3048
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003049static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003050 void __user *buffer, size_t *lenp, loff_t *ppos)
3051{
3052 struct pid *new_pid;
3053 pid_t tmp;
3054 int r;
3055
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003056 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003057
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003058 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003059 lenp, ppos, NULL, NULL);
3060 if (r || !write)
3061 return r;
3062
3063 new_pid = find_get_pid(tmp);
3064 if (!new_pid)
3065 return -ESRCH;
3066
3067 put_pid(xchg(&cad_pid, new_pid));
3068 return 0;
3069}
3070
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003071/**
3072 * proc_do_large_bitmap - read/write from/to a large bitmap
3073 * @table: the sysctl table
3074 * @write: %TRUE if this is a write to the sysctl file
3075 * @buffer: the user buffer
3076 * @lenp: the size of the user buffer
3077 * @ppos: file position
3078 *
3079 * The bitmap is stored at table->data and the bitmap length (in bits)
3080 * in table->maxlen.
3081 *
3082 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3083 * large bitmaps may be represented in a compact manner. Writing into
3084 * the file will clear the bitmap then update it with the given input.
3085 *
3086 * Returns 0 on success.
3087 */
3088int proc_do_large_bitmap(struct ctl_table *table, int write,
3089 void __user *buffer, size_t *lenp, loff_t *ppos)
3090{
3091 int err = 0;
3092 bool first = 1;
3093 size_t left = *lenp;
3094 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003095 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003096 unsigned long *tmp_bitmap = NULL;
3097 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3098
WANG Cong122ff242014-05-12 16:04:53 -07003099 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003100 *lenp = 0;
3101 return 0;
3102 }
3103
3104 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003105 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003106
3107 if (left > PAGE_SIZE - 1)
3108 left = PAGE_SIZE - 1;
3109
Al Viro70f6cbb2015-12-24 00:13:10 -05003110 p = kbuf = memdup_user_nul(buffer, left);
3111 if (IS_ERR(kbuf))
3112 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003113
Kees Cook6396bb22018-06-12 14:03:40 -07003114 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3115 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003116 GFP_KERNEL);
3117 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003118 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003119 return -ENOMEM;
3120 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003121 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003122 while (!err && left) {
3123 unsigned long val_a, val_b;
3124 bool neg;
3125
Al Viro70f6cbb2015-12-24 00:13:10 -05003126 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003127 sizeof(tr_a), &c);
3128 if (err)
3129 break;
3130 if (val_a >= bitmap_len || neg) {
3131 err = -EINVAL;
3132 break;
3133 }
3134
3135 val_b = val_a;
3136 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003137 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003138 left--;
3139 }
3140
3141 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003142 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003143 &neg, tr_b, sizeof(tr_b),
3144 &c);
3145 if (err)
3146 break;
3147 if (val_b >= bitmap_len || neg ||
3148 val_a > val_b) {
3149 err = -EINVAL;
3150 break;
3151 }
3152 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003153 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003154 left--;
3155 }
3156 }
3157
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003158 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003159 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003160 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003161 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003162 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003163 } else {
3164 unsigned long bit_a, bit_b = 0;
3165
3166 while (left) {
3167 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3168 if (bit_a >= bitmap_len)
3169 break;
3170 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3171 bit_a + 1) - 1;
3172
3173 if (!first) {
3174 err = proc_put_char(&buffer, &left, ',');
3175 if (err)
3176 break;
3177 }
3178 err = proc_put_long(&buffer, &left, bit_a, false);
3179 if (err)
3180 break;
3181 if (bit_a != bit_b) {
3182 err = proc_put_char(&buffer, &left, '-');
3183 if (err)
3184 break;
3185 err = proc_put_long(&buffer, &left, bit_b, false);
3186 if (err)
3187 break;
3188 }
3189
3190 first = 0; bit_b++;
3191 }
3192 if (!err)
3193 err = proc_put_char(&buffer, &left, '\n');
3194 }
3195
3196 if (!err) {
3197 if (write) {
3198 if (*ppos)
3199 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3200 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003201 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003202 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003203 *lenp -= left;
3204 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003205 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003206
3207 kfree(tmp_bitmap);
3208 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003209}
3210
Jovi Zhang55610502011-01-12 17:00:45 -08003211#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003213int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 void __user *buffer, size_t *lenp, loff_t *ppos)
3215{
3216 return -ENOSYS;
3217}
3218
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003219int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220 void __user *buffer, size_t *lenp, loff_t *ppos)
3221{
3222 return -ENOSYS;
3223}
3224
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003225int proc_douintvec(struct ctl_table *table, int write,
3226 void __user *buffer, size_t *lenp, loff_t *ppos)
3227{
3228 return -ENOSYS;
3229}
3230
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003231int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 void __user *buffer, size_t *lenp, loff_t *ppos)
3233{
3234 return -ENOSYS;
3235}
3236
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003237int proc_douintvec_minmax(struct ctl_table *table, int write,
3238 void __user *buffer, size_t *lenp, loff_t *ppos)
3239{
3240 return -ENOSYS;
3241}
3242
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003243int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 void __user *buffer, size_t *lenp, loff_t *ppos)
3245{
3246 return -ENOSYS;
3247}
3248
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003249int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 void __user *buffer, size_t *lenp, loff_t *ppos)
3251{
3252 return -ENOSYS;
3253}
3254
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003255int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 void __user *buffer, size_t *lenp, loff_t *ppos)
3257{
3258 return -ENOSYS;
3259}
3260
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003261int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 void __user *buffer, size_t *lenp, loff_t *ppos)
3263{
3264 return -ENOSYS;
3265}
3266
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003267int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 void __user *buffer,
3269 size_t *lenp, loff_t *ppos)
3270{
3271 return -ENOSYS;
3272}
3273
3274
Jovi Zhang55610502011-01-12 17:00:45 -08003275#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003277#ifdef CONFIG_BPF_SYSCALL
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003278static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
3279 void __user *buffer, size_t *lenp,
3280 loff_t *ppos)
3281{
3282 int ret, bpf_stats = *(int *)table->data;
3283 struct ctl_table tmp = *table;
3284
3285 if (write && !capable(CAP_SYS_ADMIN))
3286 return -EPERM;
3287
3288 tmp.data = &bpf_stats;
3289 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3290 if (write && !ret) {
3291 *(int *)table->data = bpf_stats;
3292 if (bpf_stats)
3293 static_branch_enable(&bpf_stats_enabled_key);
3294 else
3295 static_branch_disable(&bpf_stats_enabled_key);
3296 }
3297 return ret;
3298}
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003299#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300/*
3301 * No sense putting this after each symbol definition, twice,
3302 * exception granted :-)
3303 */
3304EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003305EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306EXPORT_SYMBOL(proc_dointvec_jiffies);
3307EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003308EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3310EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3311EXPORT_SYMBOL(proc_dostring);
3312EXPORT_SYMBOL(proc_doulongvec_minmax);
3313EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);