blob: 86e0771352f2452d68b87ef27ac77a7846cf152d [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 Starovoitov492ecee2019-02-25 14:28:39 -0800227static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
228 void __user *buffer, size_t *lenp,
229 loff_t *ppos);
Kees Cook54b50192012-07-30 14:39:18 -0700230
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700231#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700232/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100233static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700234
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700235static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700236 void __user *buffer, size_t *lenp,
237 loff_t *ppos)
238{
239 int error;
240
241 error = proc_dointvec(table, write, buffer, lenp, ppos);
242 if (error)
243 return error;
244
245 if (write)
246 sysrq_toggle_support(__sysrq_enabled);
247
248 return 0;
249}
250
251#endif
252
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700253static struct ctl_table kern_table[];
254static struct ctl_table vm_table[];
255static struct ctl_table fs_table[];
256static struct ctl_table debug_table[];
257static struct ctl_table dev_table[];
258extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800259#ifdef CONFIG_EPOLL
260extern struct ctl_table epoll_table[];
261#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800263#ifdef CONFIG_FW_LOADER_USER_HELPER
264extern struct ctl_table firmware_config_table[];
265#endif
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
268int sysctl_legacy_va_layout;
269#endif
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/* The default sysctl tables: */
272
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800273static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 .procname = "kernel",
276 .mode = 0555,
277 .child = kern_table,
278 },
279 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 .procname = "vm",
281 .mode = 0555,
282 .child = vm_table,
283 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 .procname = "fs",
286 .mode = 0555,
287 .child = fs_table,
288 },
289 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 .procname = "debug",
291 .mode = 0555,
292 .child = debug_table,
293 },
294 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 .procname = "dev",
296 .mode = 0555,
297 .child = dev_table,
298 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700299 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300};
301
Ingo Molnar77e54a12007-07-09 18:52:00 +0200302#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100303static int min_sched_granularity_ns = 100000; /* 100 usecs */
304static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
305static int min_wakeup_granularity_ns; /* 0 usecs */
306static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200307#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100308static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
309static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200310#endif /* CONFIG_SMP */
311#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200312
Mel Gorman5e771902010-05-24 14:32:31 -0700313#ifdef CONFIG_COMPACTION
314static int min_extfrag_threshold;
315static int max_extfrag_threshold = 1000;
316#endif
317
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700318static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200319 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200320 .procname = "sched_child_runs_first",
321 .data = &sysctl_sched_child_runs_first,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800324 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200325 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200326#ifdef CONFIG_SCHED_DEBUG
327 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100328 .procname = "sched_min_granularity_ns",
329 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200330 .maxlen = sizeof(unsigned int),
331 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800332 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100333 .extra1 = &min_sched_granularity_ns,
334 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200335 },
336 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200337 .procname = "sched_latency_ns",
338 .data = &sysctl_sched_latency,
339 .maxlen = sizeof(unsigned int),
340 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800341 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200342 .extra1 = &min_sched_granularity_ns,
343 .extra2 = &max_sched_granularity_ns,
344 },
345 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200346 .procname = "sched_wakeup_granularity_ns",
347 .data = &sysctl_sched_wakeup_granularity,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800350 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200351 .extra1 = &min_wakeup_granularity_ns,
352 .extra2 = &max_wakeup_granularity_ns,
353 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200354#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200355 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100356 .procname = "sched_tunable_scaling",
357 .data = &sysctl_sched_tunable_scaling,
358 .maxlen = sizeof(enum sched_tunable_scaling),
359 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800360 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100361 .extra1 = &min_sched_tunable_scaling,
362 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200363 },
364 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900365 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200366 .data = &sysctl_sched_migration_cost,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800369 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200370 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100371 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100372 .procname = "sched_nr_migrate",
373 .data = &sysctl_sched_nr_migrate,
374 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100375 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800376 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100377 },
Mel Gormancb251762016-02-05 09:08:36 +0000378#ifdef CONFIG_SCHEDSTATS
379 {
380 .procname = "sched_schedstats",
381 .data = NULL,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
384 .proc_handler = sysctl_schedstats,
385 .extra1 = &zero,
386 .extra2 = &one,
387 },
388#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200389#endif /* CONFIG_SMP */
390#ifdef CONFIG_NUMA_BALANCING
391 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200392 .procname = "numa_balancing_scan_delay_ms",
393 .data = &sysctl_numa_balancing_scan_delay,
394 .maxlen = sizeof(unsigned int),
395 .mode = 0644,
396 .proc_handler = proc_dointvec,
397 },
398 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200399 .procname = "numa_balancing_scan_period_min_ms",
400 .data = &sysctl_numa_balancing_scan_period_min,
401 .maxlen = sizeof(unsigned int),
402 .mode = 0644,
403 .proc_handler = proc_dointvec,
404 },
405 {
406 .procname = "numa_balancing_scan_period_max_ms",
407 .data = &sysctl_numa_balancing_scan_period_max,
408 .maxlen = sizeof(unsigned int),
409 .mode = 0644,
410 .proc_handler = proc_dointvec,
411 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200412 {
413 .procname = "numa_balancing_scan_size_mb",
414 .data = &sysctl_numa_balancing_scan_size,
415 .maxlen = sizeof(unsigned int),
416 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400417 .proc_handler = proc_dointvec_minmax,
418 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200419 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100420 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800421 .procname = "numa_balancing",
422 .data = NULL, /* filled in by handler */
423 .maxlen = sizeof(unsigned int),
424 .mode = 0644,
425 .proc_handler = sysctl_numa_balancing,
426 .extra1 = &zero,
427 .extra2 = &one,
428 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200429#endif /* CONFIG_NUMA_BALANCING */
430#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200431 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100432 .procname = "sched_rt_period_us",
433 .data = &sysctl_sched_rt_period,
434 .maxlen = sizeof(unsigned int),
435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800436 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100437 },
438 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100439 .procname = "sched_rt_runtime_us",
440 .data = &sysctl_sched_rt_runtime,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800443 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100444 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600445 {
446 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800447 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600448 .maxlen = sizeof(int),
449 .mode = 0644,
450 .proc_handler = sched_rr_handler,
451 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100452#ifdef CONFIG_SCHED_AUTOGROUP
453 {
454 .procname = "sched_autogroup_enabled",
455 .data = &sysctl_sched_autogroup_enabled,
456 .maxlen = sizeof(unsigned int),
457 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800458 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100459 .extra1 = &zero,
460 .extra2 = &one,
461 },
462#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700463#ifdef CONFIG_CFS_BANDWIDTH
464 {
465 .procname = "sched_cfs_bandwidth_slice_us",
466 .data = &sysctl_sched_cfs_bandwidth_slice,
467 .maxlen = sizeof(unsigned int),
468 .mode = 0644,
469 .proc_handler = proc_dointvec_minmax,
470 .extra1 = &one,
471 },
472#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700473#ifdef CONFIG_PROVE_LOCKING
474 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700475 .procname = "prove_locking",
476 .data = &prove_locking,
477 .maxlen = sizeof(int),
478 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800479 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700480 },
481#endif
482#ifdef CONFIG_LOCK_STAT
483 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700484 .procname = "lock_stat",
485 .data = &lock_stat,
486 .maxlen = sizeof(int),
487 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800488 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700489 },
490#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200491 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 .procname = "panic",
493 .data = &panic_timeout,
494 .maxlen = sizeof(int),
495 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800496 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 },
Alex Kelly046d6622012-10-04 17:15:23 -0700498#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 .procname = "core_uses_pid",
501 .data = &core_uses_pid,
502 .maxlen = sizeof(int),
503 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800504 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 },
506 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .procname = "core_pattern",
508 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700509 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700511 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 },
Neil Hormana2939802009-09-23 15:56:56 -0700513 {
Neil Hormana2939802009-09-23 15:56:56 -0700514 .procname = "core_pipe_limit",
515 .data = &core_pipe_limit,
516 .maxlen = sizeof(unsigned int),
517 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800518 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700519 },
Alex Kelly046d6622012-10-04 17:15:23 -0700520#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800521#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700524 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800525 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800526 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700528 {
529 .procname = "sysctl_writes_strict",
530 .data = &sysctl_writes_strict,
531 .maxlen = sizeof(int),
532 .mode = 0644,
533 .proc_handler = proc_dointvec_minmax,
534 .extra1 = &neg_one,
535 .extra2 = &one,
536 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800537#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100538#ifdef CONFIG_LATENCYTOP
539 {
540 .procname = "latencytop",
541 .data = &latencytop_enabled,
542 .maxlen = sizeof(int),
543 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000544 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100545 },
546#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#ifdef CONFIG_BLK_DEV_INITRD
548 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 .procname = "real-root-dev",
550 .data = &real_root_dev,
551 .maxlen = sizeof(int),
552 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800553 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 },
555#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700556 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700557 .procname = "print-fatal-signals",
558 .data = &print_fatal_signals,
559 .maxlen = sizeof(int),
560 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800561 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700562 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700563#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .procname = "reboot-cmd",
566 .data = reboot_command,
567 .maxlen = 256,
568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800569 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 },
571 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 .procname = "stop-a",
573 .data = &stop_a_enabled,
574 .maxlen = sizeof (int),
575 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800576 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 },
578 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 .procname = "scons-poweroff",
580 .data = &scons_pwroff,
581 .maxlen = sizeof (int),
582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800583 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 },
585#endif
David S. Miller08714202008-11-16 23:49:24 -0800586#ifdef CONFIG_SPARC64
587 {
David S. Miller08714202008-11-16 23:49:24 -0800588 .procname = "tsb-ratio",
589 .data = &sysctl_tsb_ratio,
590 .maxlen = sizeof (int),
591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800592 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800593 },
594#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#ifdef __hppa__
596 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .procname = "soft-power",
598 .data = &pwrsw_enabled,
599 .maxlen = sizeof (int),
600 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800601 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530603#endif
604#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .procname = "unaligned-trap",
607 .data = &unaligned_enabled,
608 .maxlen = sizeof (int),
609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800610 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 },
612#endif
613 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 .procname = "ctrl-alt-del",
615 .data = &C_A_D,
616 .maxlen = sizeof(int),
617 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800618 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400620#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200621 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200622 .procname = "ftrace_enabled",
623 .data = &ftrace_enabled,
624 .maxlen = sizeof(int),
625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800626 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200627 },
628#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500629#ifdef CONFIG_STACK_TRACER
630 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500631 .procname = "stack_tracer_enabled",
632 .data = &stack_tracer_enabled,
633 .maxlen = sizeof(int),
634 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800635 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500636 },
637#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400638#ifdef CONFIG_TRACING
639 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100640 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400641 .data = &ftrace_dump_on_oops,
642 .maxlen = sizeof(int),
643 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800644 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400645 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400646 {
647 .procname = "traceoff_on_warning",
648 .data = &__disable_trace_on_warning,
649 .maxlen = sizeof(__disable_trace_on_warning),
650 .mode = 0644,
651 .proc_handler = proc_dointvec,
652 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500653 {
654 .procname = "tracepoint_printk",
655 .data = &tracepoint_printk,
656 .maxlen = sizeof(tracepoint_printk),
657 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500658 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500659 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400660#endif
Dave Young2965faa2015-09-09 15:38:55 -0700661#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800662 {
663 .procname = "kexec_load_disabled",
664 .data = &kexec_load_disabled,
665 .maxlen = sizeof(int),
666 .mode = 0644,
667 /* only handle a transition from default "0" to "1" */
668 .proc_handler = proc_dointvec_minmax,
669 .extra1 = &one,
670 .extra2 = &one,
671 },
672#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200673#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 .procname = "modprobe",
676 .data = &modprobe_path,
677 .maxlen = KMOD_PATH_LEN,
678 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800679 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 },
Kees Cook3d433212009-04-02 15:49:29 -0700681 {
Kees Cook3d433212009-04-02 15:49:29 -0700682 .procname = "modules_disabled",
683 .data = &modules_disabled,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800687 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700688 .extra1 = &one,
689 .extra2 = &one,
690 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700692#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100695 .data = &uevent_helper,
696 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800698 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 },
Michael Marineau86d56132014-04-10 14:09:31 -0700700#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701#ifdef CONFIG_CHR_DEV_SG
702 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 .procname = "sg-big-buff",
704 .data = &sg_big_buff,
705 .maxlen = sizeof (int),
706 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800707 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 },
709#endif
710#ifdef CONFIG_BSD_PROCESS_ACCT
711 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 .procname = "acct",
713 .data = &acct_parm,
714 .maxlen = 3*sizeof(int),
715 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800716 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 },
718#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#ifdef CONFIG_MAGIC_SYSRQ
720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800722 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 .maxlen = sizeof (int),
724 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700725 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 },
727#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700728#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700731 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 .maxlen = sizeof (int),
733 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800734 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700736#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700739 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 .maxlen = sizeof(int),
741 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700742 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 },
744 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 .procname = "random",
746 .mode = 0555,
747 .child = random_table,
748 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 {
Eric Paris17f60a72011-04-01 17:07:50 -0400750 .procname = "usermodehelper",
751 .mode = 0555,
752 .child = usermodehelper_table,
753 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800754#ifdef CONFIG_FW_LOADER_USER_HELPER
755 {
756 .procname = "firmware_config",
757 .mode = 0555,
758 .child = firmware_config_table,
759 },
760#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400761 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 .procname = "overflowuid",
763 .data = &overflowuid,
764 .maxlen = sizeof(int),
765 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800766 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 .extra1 = &minolduid,
768 .extra2 = &maxolduid,
769 },
770 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 .procname = "overflowgid",
772 .data = &overflowgid,
773 .maxlen = sizeof(int),
774 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800775 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 .extra1 = &minolduid,
777 .extra2 = &maxolduid,
778 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800779#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780#ifdef CONFIG_MATHEMU
781 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 .procname = "ieee_emulation_warnings",
783 .data = &sysctl_ieee_emulation_warnings,
784 .maxlen = sizeof(int),
785 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800786 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 },
788#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200791 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .maxlen = sizeof(int),
793 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800794 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 },
796#endif
797 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 .procname = "pid_max",
799 .data = &pid_max,
800 .maxlen = sizeof (int),
801 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800802 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 .extra1 = &pid_max_min,
804 .extra2 = &pid_max_max,
805 },
806 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 .procname = "panic_on_oops",
808 .data = &panic_on_oops,
809 .maxlen = sizeof(int),
810 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800811 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 },
Feng Tang81c9d432019-01-03 15:28:20 -0800813 {
814 .procname = "panic_print",
815 .data = &panic_print,
816 .maxlen = sizeof(unsigned long),
817 .mode = 0644,
818 .proc_handler = proc_doulongvec_minmax,
819 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800820#if defined CONFIG_PRINTK
821 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800822 .procname = "printk",
823 .data = &console_loglevel,
824 .maxlen = 4*sizeof(int),
825 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800826 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800827 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700830 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 .maxlen = sizeof(int),
832 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800833 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 },
835 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700837 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 .maxlen = sizeof(int),
839 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800840 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 },
Dave Youngaf913222009-09-22 16:43:33 -0700842 {
Dave Youngaf913222009-09-22 16:43:33 -0700843 .procname = "printk_delay",
844 .data = &printk_delay_msec,
845 .maxlen = sizeof(int),
846 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800847 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700848 .extra1 = &zero,
849 .extra2 = &ten_thousand,
850 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700852 .procname = "printk_devkmsg",
853 .data = devkmsg_log_str,
854 .maxlen = DEVKMSG_STR_MAX_SIZE,
855 .mode = 0644,
856 .proc_handler = devkmsg_sysctl_set_loglvl,
857 },
858 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800859 .procname = "dmesg_restrict",
860 .data = &dmesg_restrict,
861 .maxlen = sizeof(int),
862 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700863 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800864 .extra1 = &zero,
865 .extra2 = &one,
866 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800867 {
868 .procname = "kptr_restrict",
869 .data = &kptr_restrict,
870 .maxlen = sizeof(int),
871 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700872 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800873 .extra1 = &zero,
874 .extra2 = &two,
875 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800876#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800877 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 .procname = "ngroups_max",
879 .data = &ngroups_max,
880 .maxlen = sizeof (int),
881 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800882 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 },
Dan Ballard73efc032011-10-31 17:11:20 -0700884 {
885 .procname = "cap_last_cap",
886 .data = (void *)&cap_last_cap,
887 .maxlen = sizeof(int),
888 .mode = 0444,
889 .proc_handler = proc_dointvec,
890 },
Don Zickus58687ac2010-05-07 17:11:44 -0400891#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500892 {
Don Zickus58687ac2010-05-07 17:11:44 -0400893 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200894 .data = &watchdog_user_enabled,
895 .maxlen = sizeof(int),
896 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700897 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700898 .extra1 = &zero,
899 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400900 },
901 {
902 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700903 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400904 .maxlen = sizeof(int),
905 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700906 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800907 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400908 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500909 },
Don Zickus2508ce12010-05-07 17:11:46 -0400910 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700911 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200912 .data = &nmi_watchdog_user_enabled,
913 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200914 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700915 .proc_handler = proc_nmi_watchdog,
916 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700917 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700918 },
919 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700920 .procname = "watchdog_cpumask",
921 .data = &watchdog_cpumask_bits,
922 .maxlen = NR_CPUS,
923 .mode = 0644,
924 .proc_handler = proc_watchdog_cpumask,
925 },
926#ifdef CONFIG_SOFTLOCKUP_DETECTOR
927 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700928 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200929 .data = &soft_watchdog_user_enabled,
930 .maxlen = sizeof(int),
931 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700932 .proc_handler = proc_soft_watchdog,
933 .extra1 = &zero,
934 .extra2 = &one,
935 },
936 {
Don Zickus2508ce12010-05-07 17:11:46 -0400937 .procname = "softlockup_panic",
938 .data = &softlockup_panic,
939 .maxlen = sizeof(int),
940 .mode = 0644,
941 .proc_handler = proc_dointvec_minmax,
942 .extra1 = &zero,
943 .extra2 = &one,
944 },
Aaron Tomlined235872014-06-23 13:22:05 -0700945#ifdef CONFIG_SMP
946 {
947 .procname = "softlockup_all_cpu_backtrace",
948 .data = &sysctl_softlockup_all_cpu_backtrace,
949 .maxlen = sizeof(int),
950 .mode = 0644,
951 .proc_handler = proc_dointvec_minmax,
952 .extra1 = &zero,
953 .extra2 = &one,
954 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700955#endif /* CONFIG_SMP */
956#endif
957#ifdef CONFIG_HARDLOCKUP_DETECTOR
958 {
959 .procname = "hardlockup_panic",
960 .data = &hardlockup_panic,
961 .maxlen = sizeof(int),
962 .mode = 0644,
963 .proc_handler = proc_dointvec_minmax,
964 .extra1 = &zero,
965 .extra2 = &one,
966 },
967#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800968 {
969 .procname = "hardlockup_all_cpu_backtrace",
970 .data = &sysctl_hardlockup_all_cpu_backtrace,
971 .maxlen = sizeof(int),
972 .mode = 0644,
973 .proc_handler = proc_dointvec_minmax,
974 .extra1 = &zero,
975 .extra2 = &one,
976 },
Aaron Tomlined235872014-06-23 13:22:05 -0700977#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500978#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700979#endif
980
Don Zickus5dc30552010-11-29 17:07:17 -0500981#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
982 {
983 .procname = "unknown_nmi_panic",
984 .data = &unknown_nmi_panic,
985 .maxlen = sizeof (int),
986 .mode = 0644,
987 .proc_handler = proc_dointvec,
988 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500989#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990#if defined(CONFIG_X86)
991 {
Don Zickus8da5add2006-09-26 10:52:27 +0200992 .procname = "panic_on_unrecovered_nmi",
993 .data = &panic_on_unrecovered_nmi,
994 .maxlen = sizeof(int),
995 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800996 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200997 },
998 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700999 .procname = "panic_on_io_nmi",
1000 .data = &panic_on_io_nmi,
1001 .maxlen = sizeof(int),
1002 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001003 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001004 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001005#ifdef CONFIG_DEBUG_STACKOVERFLOW
1006 {
1007 .procname = "panic_on_stackoverflow",
1008 .data = &sysctl_panic_on_stackoverflow,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
1011 .proc_handler = proc_dointvec,
1012 },
1013#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001014 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 .procname = "bootloader_type",
1016 .data = &bootloader_type,
1017 .maxlen = sizeof (int),
1018 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001019 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001021 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001022 .procname = "bootloader_version",
1023 .data = &bootloader_version,
1024 .maxlen = sizeof (int),
1025 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001026 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001027 },
1028 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001029 .procname = "io_delay_type",
1030 .data = &io_delay_type,
1031 .maxlen = sizeof(int),
1032 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001033 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001034 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001036#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 .procname = "randomize_va_space",
1039 .data = &randomize_va_space,
1040 .maxlen = sizeof(int),
1041 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001042 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001044#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001045#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001046 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001047 .procname = "spin_retry",
1048 .data = &spin_retry,
1049 .maxlen = sizeof (int),
1050 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001051 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001052 },
1053#endif
Len Brown673d5b42007-07-28 03:33:16 -04001054#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001055 {
Pavel Machekc255d842006-02-20 18:27:58 -08001056 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001057 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001058 .maxlen = sizeof (unsigned long),
1059 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001060 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001061 },
1062#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301063#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001064 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001065 .procname = "ignore-unaligned-usertrap",
1066 .data = &no_unaligned_warning,
1067 .maxlen = sizeof (int),
1068 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001069 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001070 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301071#endif
1072#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001073 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001074 .procname = "unaligned-dump-stack",
1075 .data = &unaligned_dump_stack,
1076 .maxlen = sizeof (int),
1077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001079 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001080#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001081#ifdef CONFIG_DETECT_HUNG_TASK
1082 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001083 .procname = "hung_task_panic",
1084 .data = &sysctl_hung_task_panic,
1085 .maxlen = sizeof(int),
1086 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001088 .extra1 = &zero,
1089 .extra2 = &one,
1090 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001091 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001092 .procname = "hung_task_check_count",
1093 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001094 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001095 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001096 .proc_handler = proc_dointvec_minmax,
1097 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001098 },
1099 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001100 .procname = "hung_task_timeout_secs",
1101 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001102 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001103 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001104 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001105 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001106 },
1107 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001108 .procname = "hung_task_check_interval_secs",
1109 .data = &sysctl_hung_task_check_interval_secs,
1110 .maxlen = sizeof(unsigned long),
1111 .mode = 0644,
1112 .proc_handler = proc_dohung_task_timeout_secs,
1113 .extra2 = &hung_task_timeout_max,
1114 },
1115 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001116 .procname = "hung_task_warnings",
1117 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001118 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001119 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001120 .proc_handler = proc_dointvec_minmax,
1121 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001122 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001123#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001124#ifdef CONFIG_RT_MUTEXES
1125 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001126 .procname = "max_lock_depth",
1127 .data = &max_lock_depth,
1128 .maxlen = sizeof(int),
1129 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001130 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001131 },
1132#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001133 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001134 .procname = "poweroff_cmd",
1135 .data = &poweroff_cmd,
1136 .maxlen = POWEROFF_CMD_PATH_LEN,
1137 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001138 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001139 },
David Howells0b77f5b2008-04-29 01:01:32 -07001140#ifdef CONFIG_KEYS
1141 {
David Howells0b77f5b2008-04-29 01:01:32 -07001142 .procname = "keys",
1143 .mode = 0555,
1144 .child = key_sysctls,
1145 },
1146#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001147#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001148 /*
1149 * User-space scripts rely on the existence of this file
1150 * as a feature check for perf_events being enabled.
1151 *
1152 * So it's an ABI, do not remove!
1153 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001154 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001155 .procname = "perf_event_paranoid",
1156 .data = &sysctl_perf_event_paranoid,
1157 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001158 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001159 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001160 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001161 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001162 .procname = "perf_event_mlock_kb",
1163 .data = &sysctl_perf_event_mlock,
1164 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001165 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001166 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001167 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001168 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001169 .procname = "perf_event_max_sample_rate",
1170 .data = &sysctl_perf_event_sample_rate,
1171 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001172 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001173 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001174 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001175 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001176 {
1177 .procname = "perf_cpu_time_max_percent",
1178 .data = &sysctl_perf_cpu_time_max_percent,
1179 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1180 .mode = 0644,
1181 .proc_handler = perf_cpu_time_max_percent_handler,
1182 .extra1 = &zero,
1183 .extra2 = &one_hundred,
1184 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001185 {
1186 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001187 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001188 .maxlen = sizeof(sysctl_perf_event_max_stack),
1189 .mode = 0644,
1190 .proc_handler = perf_event_max_stack_handler,
1191 .extra1 = &zero,
1192 .extra2 = &six_hundred_forty_kb,
1193 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001194 {
1195 .procname = "perf_event_max_contexts_per_stack",
1196 .data = &sysctl_perf_event_max_contexts_per_stack,
1197 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1198 .mode = 0644,
1199 .proc_handler = perf_event_max_stack_handler,
1200 .extra1 = &zero,
1201 .extra2 = &one_thousand,
1202 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001203#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001204 {
1205 .procname = "panic_on_warn",
1206 .data = &panic_on_warn,
1207 .maxlen = sizeof(int),
1208 .mode = 0644,
1209 .proc_handler = proc_dointvec_minmax,
1210 .extra1 = &zero,
1211 .extra2 = &one,
1212 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001213#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1214 {
1215 .procname = "timer_migration",
1216 .data = &sysctl_timer_migration,
1217 .maxlen = sizeof(unsigned int),
1218 .mode = 0644,
1219 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001220 .extra1 = &zero,
1221 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001222 },
1223#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001224#ifdef CONFIG_BPF_SYSCALL
1225 {
1226 .procname = "unprivileged_bpf_disabled",
1227 .data = &sysctl_unprivileged_bpf_disabled,
1228 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1229 .mode = 0644,
1230 /* only handle a transition from default "0" to "1" */
1231 .proc_handler = proc_dointvec_minmax,
1232 .extra1 = &one,
1233 .extra2 = &one,
1234 },
1235#endif
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001236 {
1237 .procname = "bpf_stats_enabled",
1238 .data = &sysctl_bpf_stats_enabled,
1239 .maxlen = sizeof(sysctl_bpf_stats_enabled),
1240 .mode = 0644,
1241 .proc_handler = proc_dointvec_minmax_bpf_stats,
1242 .extra1 = &zero,
1243 .extra2 = &one,
1244 },
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001245#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1246 {
1247 .procname = "panic_on_rcu_stall",
1248 .data = &sysctl_panic_on_rcu_stall,
1249 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1250 .mode = 0644,
1251 .proc_handler = proc_dointvec_minmax,
1252 .extra1 = &zero,
1253 .extra2 = &one,
1254 },
1255#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001256#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1257 {
1258 .procname = "stack_erasing",
1259 .data = NULL,
1260 .maxlen = sizeof(int),
1261 .mode = 0600,
1262 .proc_handler = stack_erasing_sysctl,
1263 .extra1 = &zero,
1264 .extra2 = &one,
1265 },
1266#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001267 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268};
1269
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001270static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 .procname = "overcommit_memory",
1273 .data = &sysctl_overcommit_memory,
1274 .maxlen = sizeof(sysctl_overcommit_memory),
1275 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001276 .proc_handler = proc_dointvec_minmax,
1277 .extra1 = &zero,
1278 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 },
1280 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001281 .procname = "panic_on_oom",
1282 .data = &sysctl_panic_on_oom,
1283 .maxlen = sizeof(sysctl_panic_on_oom),
1284 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001285 .proc_handler = proc_dointvec_minmax,
1286 .extra1 = &zero,
1287 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001288 },
1289 {
David Rientjesfe071d72007-10-16 23:25:56 -07001290 .procname = "oom_kill_allocating_task",
1291 .data = &sysctl_oom_kill_allocating_task,
1292 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1293 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001294 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001295 },
1296 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001297 .procname = "oom_dump_tasks",
1298 .data = &sysctl_oom_dump_tasks,
1299 .maxlen = sizeof(sysctl_oom_dump_tasks),
1300 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001301 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001302 },
1303 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 .procname = "overcommit_ratio",
1305 .data = &sysctl_overcommit_ratio,
1306 .maxlen = sizeof(sysctl_overcommit_ratio),
1307 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001308 .proc_handler = overcommit_ratio_handler,
1309 },
1310 {
1311 .procname = "overcommit_kbytes",
1312 .data = &sysctl_overcommit_kbytes,
1313 .maxlen = sizeof(sysctl_overcommit_kbytes),
1314 .mode = 0644,
1315 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 },
1317 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 .procname = "page-cluster",
1319 .data = &page_cluster,
1320 .maxlen = sizeof(int),
1321 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001322 .proc_handler = proc_dointvec_minmax,
1323 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 },
1325 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 .procname = "dirty_background_ratio",
1327 .data = &dirty_background_ratio,
1328 .maxlen = sizeof(dirty_background_ratio),
1329 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001330 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 .extra1 = &zero,
1332 .extra2 = &one_hundred,
1333 },
1334 {
David Rientjes2da02992009-01-06 14:39:31 -08001335 .procname = "dirty_background_bytes",
1336 .data = &dirty_background_bytes,
1337 .maxlen = sizeof(dirty_background_bytes),
1338 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001339 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001340 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001341 },
1342 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 .procname = "dirty_ratio",
1344 .data = &vm_dirty_ratio,
1345 .maxlen = sizeof(vm_dirty_ratio),
1346 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001347 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .extra1 = &zero,
1349 .extra2 = &one_hundred,
1350 },
1351 {
David Rientjes2da02992009-01-06 14:39:31 -08001352 .procname = "dirty_bytes",
1353 .data = &vm_dirty_bytes,
1354 .maxlen = sizeof(vm_dirty_bytes),
1355 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001356 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001357 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001358 },
1359 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001361 .data = &dirty_writeback_interval,
1362 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001364 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 },
1366 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001368 .data = &dirty_expire_interval,
1369 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001371 .proc_handler = proc_dointvec_minmax,
1372 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 },
1374 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001375 .procname = "dirtytime_expire_seconds",
1376 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001377 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001378 .mode = 0644,
1379 .proc_handler = dirtytime_interval_handler,
1380 .extra1 = &zero,
1381 },
1382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "swappiness",
1384 .data = &vm_swappiness,
1385 .maxlen = sizeof(vm_swappiness),
1386 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001387 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .extra1 = &zero,
1389 .extra2 = &one_hundred,
1390 },
1391#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001392 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001394 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .maxlen = sizeof(unsigned long),
1396 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001397 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001398 },
1399#ifdef CONFIG_NUMA
1400 {
1401 .procname = "nr_hugepages_mempolicy",
1402 .data = NULL,
1403 .maxlen = sizeof(unsigned long),
1404 .mode = 0644,
1405 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001406 },
Kemi Wang45180852017-11-15 17:38:22 -08001407 {
1408 .procname = "numa_stat",
1409 .data = &sysctl_vm_numa_stat,
1410 .maxlen = sizeof(int),
1411 .mode = 0644,
1412 .proc_handler = sysctl_vm_numa_stat_handler,
1413 .extra1 = &zero,
1414 .extra2 = &one,
1415 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001416#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "hugetlb_shm_group",
1419 .data = &sysctl_hugetlb_shm_group,
1420 .maxlen = sizeof(gid_t),
1421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 },
Adam Litke54f9f802007-10-16 01:26:20 -07001424 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001425 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001426 .data = NULL,
1427 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001428 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001429 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001430 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431#endif
1432 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 .procname = "lowmem_reserve_ratio",
1434 .data = &sysctl_lowmem_reserve_ratio,
1435 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1436 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001437 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 },
1439 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001440 .procname = "drop_caches",
1441 .data = &sysctl_drop_caches,
1442 .maxlen = sizeof(int),
1443 .mode = 0644,
1444 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001445 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001446 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001447 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001448#ifdef CONFIG_COMPACTION
1449 {
1450 .procname = "compact_memory",
1451 .data = &sysctl_compact_memory,
1452 .maxlen = sizeof(int),
1453 .mode = 0200,
1454 .proc_handler = sysctl_compaction_handler,
1455 },
Mel Gorman5e771902010-05-24 14:32:31 -07001456 {
1457 .procname = "extfrag_threshold",
1458 .data = &sysctl_extfrag_threshold,
1459 .maxlen = sizeof(int),
1460 .mode = 0644,
1461 .proc_handler = sysctl_extfrag_handler,
1462 .extra1 = &min_extfrag_threshold,
1463 .extra2 = &max_extfrag_threshold,
1464 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001465 {
1466 .procname = "compact_unevictable_allowed",
1467 .data = &sysctl_compact_unevictable_allowed,
1468 .maxlen = sizeof(int),
1469 .mode = 0644,
1470 .proc_handler = proc_dointvec,
1471 .extra1 = &zero,
1472 .extra2 = &one,
1473 },
Mel Gorman5e771902010-05-24 14:32:31 -07001474
Mel Gorman76ab0f52010-05-24 14:32:28 -07001475#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001476 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 .procname = "min_free_kbytes",
1478 .data = &min_free_kbytes,
1479 .maxlen = sizeof(min_free_kbytes),
1480 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001481 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 .extra1 = &zero,
1483 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001484 {
Mel Gorman1c308442018-12-28 00:35:52 -08001485 .procname = "watermark_boost_factor",
1486 .data = &watermark_boost_factor,
1487 .maxlen = sizeof(watermark_boost_factor),
1488 .mode = 0644,
1489 .proc_handler = watermark_boost_factor_sysctl_handler,
1490 .extra1 = &zero,
1491 },
1492 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001493 .procname = "watermark_scale_factor",
1494 .data = &watermark_scale_factor,
1495 .maxlen = sizeof(watermark_scale_factor),
1496 .mode = 0644,
1497 .proc_handler = watermark_scale_factor_sysctl_handler,
1498 .extra1 = &one,
1499 .extra2 = &one_thousand,
1500 },
1501 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001502 .procname = "percpu_pagelist_fraction",
1503 .data = &percpu_pagelist_fraction,
1504 .maxlen = sizeof(percpu_pagelist_fraction),
1505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001506 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001507 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001508 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509#ifdef CONFIG_MMU
1510 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 .procname = "max_map_count",
1512 .data = &sysctl_max_map_count,
1513 .maxlen = sizeof(sysctl_max_map_count),
1514 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001515 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001516 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001518#else
1519 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001520 .procname = "nr_trim_pages",
1521 .data = &sysctl_nr_trim_pages,
1522 .maxlen = sizeof(sysctl_nr_trim_pages),
1523 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001524 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001525 .extra1 = &zero,
1526 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527#endif
1528 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 .procname = "laptop_mode",
1530 .data = &laptop_mode,
1531 .maxlen = sizeof(laptop_mode),
1532 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001533 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 },
1535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 .procname = "block_dump",
1537 .data = &block_dump,
1538 .maxlen = sizeof(block_dump),
1539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001540 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 .extra1 = &zero,
1542 },
1543 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 .procname = "vfs_cache_pressure",
1545 .data = &sysctl_vfs_cache_pressure,
1546 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001548 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 .extra1 = &zero,
1550 },
1551#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1552 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 .procname = "legacy_va_layout",
1554 .data = &sysctl_legacy_va_layout,
1555 .maxlen = sizeof(sysctl_legacy_va_layout),
1556 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001557 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 .extra1 = &zero,
1559 },
1560#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001561#ifdef CONFIG_NUMA
1562 {
Christoph Lameter17436602006-01-18 17:42:32 -08001563 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001564 .data = &node_reclaim_mode,
1565 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001566 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001567 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001568 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001569 },
Christoph Lameter96146342006-07-03 00:24:13 -07001570 {
Christoph Lameter96146342006-07-03 00:24:13 -07001571 .procname = "min_unmapped_ratio",
1572 .data = &sysctl_min_unmapped_ratio,
1573 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1574 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001575 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001576 .extra1 = &zero,
1577 .extra2 = &one_hundred,
1578 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001579 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001580 .procname = "min_slab_ratio",
1581 .data = &sysctl_min_slab_ratio,
1582 .maxlen = sizeof(sysctl_min_slab_ratio),
1583 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001584 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001585 .extra1 = &zero,
1586 .extra2 = &one_hundred,
1587 },
Christoph Lameter17436602006-01-18 17:42:32 -08001588#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001589#ifdef CONFIG_SMP
1590 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001591 .procname = "stat_interval",
1592 .data = &sysctl_stat_interval,
1593 .maxlen = sizeof(sysctl_stat_interval),
1594 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001595 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001596 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001597 {
1598 .procname = "stat_refresh",
1599 .data = NULL,
1600 .maxlen = 0,
1601 .mode = 0600,
1602 .proc_handler = vmstat_refresh,
1603 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001604#endif
David Howells6e141542009-12-15 19:27:45 +00001605#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001606 {
Eric Parised032182007-06-28 15:55:21 -04001607 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001608 .data = &dac_mmap_min_addr,
1609 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001610 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001611 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001612 },
David Howells6e141542009-12-15 19:27:45 +00001613#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001614#ifdef CONFIG_NUMA
1615 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001616 .procname = "numa_zonelist_order",
1617 .data = &numa_zonelist_order,
1618 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1619 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001620 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001621 },
1622#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001623#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001624 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001625 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001626 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001627#ifdef CONFIG_X86_32
1628 .data = &vdso32_enabled,
1629 .maxlen = sizeof(vdso32_enabled),
1630#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001631 .data = &vdso_enabled,
1632 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001633#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001634 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001635 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001636 .extra1 = &zero,
1637 },
1638#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001639#ifdef CONFIG_HIGHMEM
1640 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001641 .procname = "highmem_is_dirtyable",
1642 .data = &vm_highmem_is_dirtyable,
1643 .maxlen = sizeof(vm_highmem_is_dirtyable),
1644 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001645 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001646 .extra1 = &zero,
1647 .extra2 = &one,
1648 },
1649#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001650#ifdef CONFIG_MEMORY_FAILURE
1651 {
Andi Kleen6a460792009-09-16 11:50:15 +02001652 .procname = "memory_failure_early_kill",
1653 .data = &sysctl_memory_failure_early_kill,
1654 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1655 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001656 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001657 .extra1 = &zero,
1658 .extra2 = &one,
1659 },
1660 {
Andi Kleen6a460792009-09-16 11:50:15 +02001661 .procname = "memory_failure_recovery",
1662 .data = &sysctl_memory_failure_recovery,
1663 .maxlen = sizeof(sysctl_memory_failure_recovery),
1664 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001665 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001666 .extra1 = &zero,
1667 .extra2 = &one,
1668 },
1669#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001670 {
1671 .procname = "user_reserve_kbytes",
1672 .data = &sysctl_user_reserve_kbytes,
1673 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1674 .mode = 0644,
1675 .proc_handler = proc_doulongvec_minmax,
1676 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001677 {
1678 .procname = "admin_reserve_kbytes",
1679 .data = &sysctl_admin_reserve_kbytes,
1680 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1681 .mode = 0644,
1682 .proc_handler = proc_doulongvec_minmax,
1683 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001684#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1685 {
1686 .procname = "mmap_rnd_bits",
1687 .data = &mmap_rnd_bits,
1688 .maxlen = sizeof(mmap_rnd_bits),
1689 .mode = 0600,
1690 .proc_handler = proc_dointvec_minmax,
1691 .extra1 = (void *)&mmap_rnd_bits_min,
1692 .extra2 = (void *)&mmap_rnd_bits_max,
1693 },
1694#endif
1695#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1696 {
1697 .procname = "mmap_rnd_compat_bits",
1698 .data = &mmap_rnd_compat_bits,
1699 .maxlen = sizeof(mmap_rnd_compat_bits),
1700 .mode = 0600,
1701 .proc_handler = proc_dointvec_minmax,
1702 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1703 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1704 },
1705#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001706 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707};
1708
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001709static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 .procname = "inode-nr",
1712 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001713 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001715 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 },
1717 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 .procname = "inode-state",
1719 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001720 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001722 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 },
1724 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 .procname = "file-nr",
1726 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001727 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001729 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 },
1731 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 .procname = "file-max",
1733 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001734 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001736 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 },
1738 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001739 .procname = "nr_open",
1740 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001741 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001742 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001743 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001744 .extra1 = &sysctl_nr_open_min,
1745 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001746 },
1747 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 .procname = "dentry-state",
1749 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001750 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001752 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 },
1754 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 .procname = "overflowuid",
1756 .data = &fs_overflowuid,
1757 .maxlen = sizeof(int),
1758 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001759 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 .extra1 = &minolduid,
1761 .extra2 = &maxolduid,
1762 },
1763 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 .procname = "overflowgid",
1765 .data = &fs_overflowgid,
1766 .maxlen = sizeof(int),
1767 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001768 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 .extra1 = &minolduid,
1770 .extra2 = &maxolduid,
1771 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001772#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 .procname = "leases-enable",
1775 .data = &leases_enable,
1776 .maxlen = sizeof(int),
1777 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001778 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001780#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781#ifdef CONFIG_DNOTIFY
1782 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 .procname = "dir-notify-enable",
1784 .data = &dir_notify_enable,
1785 .maxlen = sizeof(int),
1786 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001787 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 },
1789#endif
1790#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001791#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 .procname = "lease-break-time",
1794 .data = &lease_break_time,
1795 .maxlen = sizeof(int),
1796 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001797 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001799#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001800#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 .procname = "aio-nr",
1803 .data = &aio_nr,
1804 .maxlen = sizeof(aio_nr),
1805 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001806 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 },
1808 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 .procname = "aio-max-nr",
1810 .data = &aio_max_nr,
1811 .maxlen = sizeof(aio_max_nr),
1812 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001813 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001815#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001816#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001817 {
Robert Love0399cb02005-07-13 12:38:18 -04001818 .procname = "inotify",
1819 .mode = 0555,
1820 .child = inotify_table,
1821 },
1822#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001823#ifdef CONFIG_EPOLL
1824 {
1825 .procname = "epoll",
1826 .mode = 0555,
1827 .child = epoll_table,
1828 },
1829#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001831 {
Kees Cook800179c2012-07-25 17:29:07 -07001832 .procname = "protected_symlinks",
1833 .data = &sysctl_protected_symlinks,
1834 .maxlen = sizeof(int),
1835 .mode = 0600,
1836 .proc_handler = proc_dointvec_minmax,
1837 .extra1 = &zero,
1838 .extra2 = &one,
1839 },
1840 {
1841 .procname = "protected_hardlinks",
1842 .data = &sysctl_protected_hardlinks,
1843 .maxlen = sizeof(int),
1844 .mode = 0600,
1845 .proc_handler = proc_dointvec_minmax,
1846 .extra1 = &zero,
1847 .extra2 = &one,
1848 },
1849 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001850 .procname = "protected_fifos",
1851 .data = &sysctl_protected_fifos,
1852 .maxlen = sizeof(int),
1853 .mode = 0600,
1854 .proc_handler = proc_dointvec_minmax,
1855 .extra1 = &zero,
1856 .extra2 = &two,
1857 },
1858 {
1859 .procname = "protected_regular",
1860 .data = &sysctl_protected_regular,
1861 .maxlen = sizeof(int),
1862 .mode = 0600,
1863 .proc_handler = proc_dointvec_minmax,
1864 .extra1 = &zero,
1865 .extra2 = &two,
1866 },
1867 {
Alan Coxd6e71142005-06-23 00:09:43 -07001868 .procname = "suid_dumpable",
1869 .data = &suid_dumpable,
1870 .maxlen = sizeof(int),
1871 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001872 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001873 .extra1 = &zero,
1874 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001875 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001876#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1877 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001878 .procname = "binfmt_misc",
1879 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001880 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001881 },
1882#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001883 {
Jens Axboeff9da692010-06-03 14:54:39 +02001884 .procname = "pipe-max-size",
1885 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001886 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001887 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001888 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001889 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001890 {
1891 .procname = "pipe-user-pages-hard",
1892 .data = &pipe_user_pages_hard,
1893 .maxlen = sizeof(pipe_user_pages_hard),
1894 .mode = 0644,
1895 .proc_handler = proc_doulongvec_minmax,
1896 },
1897 {
1898 .procname = "pipe-user-pages-soft",
1899 .data = &pipe_user_pages_soft,
1900 .maxlen = sizeof(pipe_user_pages_soft),
1901 .mode = 0644,
1902 .proc_handler = proc_doulongvec_minmax,
1903 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001904 {
1905 .procname = "mount-max",
1906 .data = &sysctl_mount_max,
1907 .maxlen = sizeof(unsigned int),
1908 .mode = 0644,
1909 .proc_handler = proc_dointvec_minmax,
1910 .extra1 = &one,
1911 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001912 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913};
1914
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001915static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001916#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001917 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001918 .procname = "exception-trace",
1919 .data = &show_unhandled_signals,
1920 .maxlen = sizeof(int),
1921 .mode = 0644,
1922 .proc_handler = proc_dointvec
1923 },
1924#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001925#if defined(CONFIG_OPTPROBES)
1926 {
1927 .procname = "kprobes-optimization",
1928 .data = &sysctl_kprobes_optimization,
1929 .maxlen = sizeof(int),
1930 .mode = 0644,
1931 .proc_handler = proc_kprobes_optimization_handler,
1932 .extra1 = &zero,
1933 .extra2 = &one,
1934 },
1935#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001936 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937};
1938
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001939static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001940 { }
Robert Love0eeca282005-07-12 17:06:03 -04001941};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001943int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001944{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001945 struct ctl_table_header *hdr;
1946
1947 hdr = register_sysctl_table(sysctl_base_table);
1948 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001949 return 0;
1950}
1951
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001952#endif /* CONFIG_SYSCTL */
1953
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954/*
1955 * /proc/sys support
1956 */
1957
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001958#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
Kees Cookf8808302014-06-06 14:37:17 -07001960static int _proc_do_string(char *data, int maxlen, int write,
1961 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001962 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001963{
1964 size_t len;
1965 char __user *p;
1966 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001967
1968 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001969 *lenp = 0;
1970 return 0;
1971 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001972
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001973 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001974 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1975 /* Only continue writes not past the end of buffer. */
1976 len = strlen(data);
1977 if (len > maxlen - 1)
1978 len = maxlen - 1;
1979
1980 if (*ppos > len)
1981 return 0;
1982 len = *ppos;
1983 } else {
1984 /* Start writing from beginning of buffer. */
1985 len = 0;
1986 }
1987
Kees Cook2ca9bb42014-06-06 14:37:18 -07001988 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001989 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001990 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001991 if (get_user(c, p++))
1992 return -EFAULT;
1993 if (c == 0 || c == '\n')
1994 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001995 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001996 }
Kees Cookf8808302014-06-06 14:37:17 -07001997 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001998 } else {
1999 len = strlen(data);
2000 if (len > maxlen)
2001 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002002
2003 if (*ppos > len) {
2004 *lenp = 0;
2005 return 0;
2006 }
2007
2008 data += *ppos;
2009 len -= *ppos;
2010
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002011 if (len > *lenp)
2012 len = *lenp;
2013 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002014 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002015 return -EFAULT;
2016 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002017 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002018 return -EFAULT;
2019 len++;
2020 }
2021 *lenp = len;
2022 *ppos += len;
2023 }
2024 return 0;
2025}
2026
Kees Cookf4aacea2014-06-06 14:37:19 -07002027static void warn_sysctl_write(struct ctl_table *table)
2028{
2029 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2030 "This will not be supported in the future. To silence this\n"
2031 "warning, set kernel.sysctl_writes_strict = -1\n",
2032 current->comm, table->procname);
2033}
2034
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002036 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002037 * @ppos: file position
2038 * @table: the sysctl table
2039 *
2040 * Returns true if the first position is non-zero and the sysctl_writes_strict
2041 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002042 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002043 */
2044static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2045 struct ctl_table *table)
2046{
2047 if (!*ppos)
2048 return false;
2049
2050 switch (sysctl_writes_strict) {
2051 case SYSCTL_WRITES_STRICT:
2052 return true;
2053 case SYSCTL_WRITES_WARN:
2054 warn_sysctl_write(table);
2055 return false;
2056 default:
2057 return false;
2058 }
2059}
2060
2061/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 * proc_dostring - read a string sysctl
2063 * @table: the sysctl table
2064 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 * @buffer: the user buffer
2066 * @lenp: the size of the user buffer
2067 * @ppos: file position
2068 *
2069 * Reads/writes a string from/to the user buffer. If the kernel
2070 * buffer provided is not large enough to hold the string, the
2071 * string is truncated. The copied string is %NULL-terminated.
2072 * If the string is being read by the user process, it is copied
2073 * and a newline '\n' is added. It is truncated if the buffer is
2074 * not large enough.
2075 *
2076 * Returns 0 on success.
2077 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002078int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 void __user *buffer, size_t *lenp, loff_t *ppos)
2080{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002081 if (write)
2082 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002083
Kees Cookf8808302014-06-06 14:37:17 -07002084 return _proc_do_string((char *)(table->data), table->maxlen, write,
2085 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086}
2087
Amerigo Wang00b7c332010-05-05 00:26:45 +00002088static size_t proc_skip_spaces(char **buf)
2089{
2090 size_t ret;
2091 char *tmp = skip_spaces(*buf);
2092 ret = tmp - *buf;
2093 *buf = tmp;
2094 return ret;
2095}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002097static void proc_skip_char(char **buf, size_t *size, const char v)
2098{
2099 while (*size) {
2100 if (**buf != v)
2101 break;
2102 (*size)--;
2103 (*buf)++;
2104 }
2105}
2106
Amerigo Wang00b7c332010-05-05 00:26:45 +00002107#define TMPBUFLEN 22
2108/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002109 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002110 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002111 * @buf: a kernel buffer
2112 * @size: size of the kernel buffer
2113 * @val: this is where the number will be stored
2114 * @neg: set to %TRUE if number is negative
2115 * @perm_tr: a vector which contains the allowed trailers
2116 * @perm_tr_len: size of the perm_tr vector
2117 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002118 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002119 * In case of success %0 is returned and @buf and @size are updated with
2120 * the amount of bytes read. If @tr is non-NULL and a trailing
2121 * character exists (size is non-zero after returning from this
2122 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002123 */
2124static int proc_get_long(char **buf, size_t *size,
2125 unsigned long *val, bool *neg,
2126 const char *perm_tr, unsigned perm_tr_len, char *tr)
2127{
2128 int len;
2129 char *p, tmp[TMPBUFLEN];
2130
2131 if (!*size)
2132 return -EINVAL;
2133
2134 len = *size;
2135 if (len > TMPBUFLEN - 1)
2136 len = TMPBUFLEN - 1;
2137
2138 memcpy(tmp, *buf, len);
2139
2140 tmp[len] = 0;
2141 p = tmp;
2142 if (*p == '-' && *size > 1) {
2143 *neg = true;
2144 p++;
2145 } else
2146 *neg = false;
2147 if (!isdigit(*p))
2148 return -EINVAL;
2149
2150 *val = simple_strtoul(p, &p, 0);
2151
2152 len = p - tmp;
2153
2154 /* We don't know if the next char is whitespace thus we may accept
2155 * invalid integers (e.g. 1234...a) or two integers instead of one
2156 * (e.g. 123...1). So lets not allow such large numbers. */
2157 if (len == TMPBUFLEN - 1)
2158 return -EINVAL;
2159
2160 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2161 return -EINVAL;
2162
2163 if (tr && (len < *size))
2164 *tr = *p;
2165
2166 *buf += len;
2167 *size -= len;
2168
2169 return 0;
2170}
2171
2172/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002173 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002174 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002175 * @buf: the user buffer
2176 * @size: the size of the user buffer
2177 * @val: the integer to be converted
2178 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002179 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002180 * In case of success %0 is returned and @buf and @size are updated with
2181 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002182 */
2183static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2184 bool neg)
2185{
2186 int len;
2187 char tmp[TMPBUFLEN], *p = tmp;
2188
2189 sprintf(p, "%s%lu", neg ? "-" : "", val);
2190 len = strlen(tmp);
2191 if (len > *size)
2192 len = *size;
2193 if (copy_to_user(*buf, tmp, len))
2194 return -EFAULT;
2195 *size -= len;
2196 *buf += len;
2197 return 0;
2198}
2199#undef TMPBUFLEN
2200
2201static int proc_put_char(void __user **buf, size_t *size, char c)
2202{
2203 if (*size) {
2204 char __user **buffer = (char __user **)buf;
2205 if (put_user(c, *buffer))
2206 return -EFAULT;
2207 (*size)--, (*buffer)++;
2208 *buf = *buffer;
2209 }
2210 return 0;
2211}
2212
2213static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 int *valp,
2215 int write, void *data)
2216{
2217 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002218 if (*negp) {
2219 if (*lvalp > (unsigned long) INT_MAX + 1)
2220 return -EINVAL;
2221 *valp = -*lvalp;
2222 } else {
2223 if (*lvalp > (unsigned long) INT_MAX)
2224 return -EINVAL;
2225 *valp = *lvalp;
2226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 } else {
2228 int val = *valp;
2229 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002230 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002231 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002233 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 *lvalp = (unsigned long)val;
2235 }
2236 }
2237 return 0;
2238}
2239
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002240static int do_proc_douintvec_conv(unsigned long *lvalp,
2241 unsigned int *valp,
2242 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002243{
2244 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002245 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002246 return -EINVAL;
2247 *valp = *lvalp;
2248 } else {
2249 unsigned int val = *valp;
2250 *lvalp = (unsigned long)val;
2251 }
2252 return 0;
2253}
2254
Amerigo Wang00b7c332010-05-05 00:26:45 +00002255static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2256
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002257static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002258 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002259 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002260 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 int write, void *data),
2262 void *data)
2263{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002264 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002265 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002266 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Amerigo Wang00b7c332010-05-05 00:26:45 +00002268 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 *lenp = 0;
2270 return 0;
2271 }
2272
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002273 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 vleft = table->maxlen / sizeof(*i);
2275 left = *lenp;
2276
2277 if (!conv)
2278 conv = do_proc_dointvec_conv;
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002281 if (proc_first_pos_non_zero_ignore(ppos, table))
2282 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002283
Amerigo Wang00b7c332010-05-05 00:26:45 +00002284 if (left > PAGE_SIZE - 1)
2285 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002286 p = kbuf = memdup_user_nul(buffer, left);
2287 if (IS_ERR(kbuf))
2288 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002289 }
2290
2291 for (; left && vleft--; i++, first=0) {
2292 unsigned long lval;
2293 bool neg;
2294
2295 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002296 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002297
J. R. Okajima563b0462010-05-25 16:10:14 -07002298 if (!left)
2299 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002300 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002301 proc_wspace_sep,
2302 sizeof(proc_wspace_sep), NULL);
2303 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002305 if (conv(&neg, &lval, i, 1, data)) {
2306 err = -EINVAL;
2307 break;
2308 }
2309 } else {
2310 if (conv(&neg, &lval, i, 0, data)) {
2311 err = -EINVAL;
2312 break;
2313 }
2314 if (!first)
2315 err = proc_put_char(&buffer, &left, '\t');
2316 if (err)
2317 break;
2318 err = proc_put_long(&buffer, &left, lval, neg);
2319 if (err)
2320 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 }
2322 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002323
2324 if (!write && !first && left && !err)
2325 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002326 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002327 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002328 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002329 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002330 if (first)
2331 return err ? : -EINVAL;
2332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002334out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002336 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337}
2338
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002339static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002340 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002341 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002342 int write, void *data),
2343 void *data)
2344{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002345 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002346 buffer, lenp, ppos, conv, data);
2347}
2348
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002349static int do_proc_douintvec_w(unsigned int *tbl_data,
2350 struct ctl_table *table,
2351 void __user *buffer,
2352 size_t *lenp, loff_t *ppos,
2353 int (*conv)(unsigned long *lvalp,
2354 unsigned int *valp,
2355 int write, void *data),
2356 void *data)
2357{
2358 unsigned long lval;
2359 int err = 0;
2360 size_t left;
2361 bool neg;
2362 char *kbuf = NULL, *p;
2363
2364 left = *lenp;
2365
2366 if (proc_first_pos_non_zero_ignore(ppos, table))
2367 goto bail_early;
2368
2369 if (left > PAGE_SIZE - 1)
2370 left = PAGE_SIZE - 1;
2371
2372 p = kbuf = memdup_user_nul(buffer, left);
2373 if (IS_ERR(kbuf))
2374 return -EINVAL;
2375
2376 left -= proc_skip_spaces(&p);
2377 if (!left) {
2378 err = -EINVAL;
2379 goto out_free;
2380 }
2381
2382 err = proc_get_long(&p, &left, &lval, &neg,
2383 proc_wspace_sep,
2384 sizeof(proc_wspace_sep), NULL);
2385 if (err || neg) {
2386 err = -EINVAL;
2387 goto out_free;
2388 }
2389
2390 if (conv(&lval, tbl_data, 1, data)) {
2391 err = -EINVAL;
2392 goto out_free;
2393 }
2394
2395 if (!err && left)
2396 left -= proc_skip_spaces(&p);
2397
2398out_free:
2399 kfree(kbuf);
2400 if (err)
2401 return -EINVAL;
2402
2403 return 0;
2404
2405 /* This is in keeping with old __do_proc_dointvec() */
2406bail_early:
2407 *ppos += *lenp;
2408 return err;
2409}
2410
2411static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2412 size_t *lenp, loff_t *ppos,
2413 int (*conv)(unsigned long *lvalp,
2414 unsigned int *valp,
2415 int write, void *data),
2416 void *data)
2417{
2418 unsigned long lval;
2419 int err = 0;
2420 size_t left;
2421
2422 left = *lenp;
2423
2424 if (conv(&lval, tbl_data, 0, data)) {
2425 err = -EINVAL;
2426 goto out;
2427 }
2428
2429 err = proc_put_long(&buffer, &left, lval, false);
2430 if (err || !left)
2431 goto out;
2432
2433 err = proc_put_char(&buffer, &left, '\n');
2434
2435out:
2436 *lenp -= left;
2437 *ppos += *lenp;
2438
2439 return err;
2440}
2441
2442static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2443 int write, void __user *buffer,
2444 size_t *lenp, loff_t *ppos,
2445 int (*conv)(unsigned long *lvalp,
2446 unsigned int *valp,
2447 int write, void *data),
2448 void *data)
2449{
2450 unsigned int *i, vleft;
2451
2452 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2453 *lenp = 0;
2454 return 0;
2455 }
2456
2457 i = (unsigned int *) tbl_data;
2458 vleft = table->maxlen / sizeof(*i);
2459
2460 /*
2461 * Arrays are not supported, keep this simple. *Do not* add
2462 * support for them.
2463 */
2464 if (vleft != 1) {
2465 *lenp = 0;
2466 return -EINVAL;
2467 }
2468
2469 if (!conv)
2470 conv = do_proc_douintvec_conv;
2471
2472 if (write)
2473 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2474 conv, data);
2475 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2476}
2477
2478static int do_proc_douintvec(struct ctl_table *table, int write,
2479 void __user *buffer, size_t *lenp, loff_t *ppos,
2480 int (*conv)(unsigned long *lvalp,
2481 unsigned int *valp,
2482 int write, void *data),
2483 void *data)
2484{
2485 return __do_proc_douintvec(table->data, table, write,
2486 buffer, lenp, ppos, conv, data);
2487}
2488
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489/**
2490 * proc_dointvec - read a vector of integers
2491 * @table: the sysctl table
2492 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 * @buffer: the user buffer
2494 * @lenp: the size of the user buffer
2495 * @ppos: file position
2496 *
2497 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2498 * values from/to the user buffer, treated as an ASCII string.
2499 *
2500 * Returns 0 on success.
2501 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002502int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 void __user *buffer, size_t *lenp, loff_t *ppos)
2504{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002505 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2506}
2507
2508/**
2509 * proc_douintvec - read a vector of unsigned integers
2510 * @table: the sysctl table
2511 * @write: %TRUE if this is a write to the sysctl file
2512 * @buffer: the user buffer
2513 * @lenp: the size of the user buffer
2514 * @ppos: file position
2515 *
2516 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2517 * values from/to the user buffer, treated as an ASCII string.
2518 *
2519 * Returns 0 on success.
2520 */
2521int proc_douintvec(struct ctl_table *table, int write,
2522 void __user *buffer, size_t *lenp, loff_t *ppos)
2523{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002524 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2525 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526}
2527
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002528/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002529 * Taint values can only be increased
2530 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002531 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002532static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002533 void __user *buffer, size_t *lenp, loff_t *ppos)
2534{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002535 struct ctl_table t;
2536 unsigned long tmptaint = get_taint();
2537 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002538
Bastian Blank91fcd412007-04-23 14:41:14 -07002539 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002540 return -EPERM;
2541
Andi Kleen25ddbb12008-10-15 22:01:41 -07002542 t = *table;
2543 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002544 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002545 if (err < 0)
2546 return err;
2547
2548 if (write) {
2549 /*
2550 * Poor man's atomic or. Not worth adding a primitive
2551 * to everyone's atomic.h for this
2552 */
2553 int i;
2554 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2555 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302556 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002557 }
2558 }
2559
2560 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002561}
2562
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002563#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002564static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002565 void __user *buffer, size_t *lenp, loff_t *ppos)
2566{
2567 if (write && !capable(CAP_SYS_ADMIN))
2568 return -EPERM;
2569
2570 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2571}
2572#endif
2573
Waiman Long24704f32018-04-10 16:35:38 -07002574/**
2575 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2576 * @min: pointer to minimum allowable value
2577 * @max: pointer to maximum allowable value
2578 *
2579 * The do_proc_dointvec_minmax_conv_param structure provides the
2580 * minimum and maximum values for doing range checking for those sysctl
2581 * parameters that use the proc_dointvec_minmax() handler.
2582 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583struct do_proc_dointvec_minmax_conv_param {
2584 int *min;
2585 int *max;
2586};
2587
Amerigo Wang00b7c332010-05-05 00:26:45 +00002588static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2589 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 int write, void *data)
2591{
2592 struct do_proc_dointvec_minmax_conv_param *param = data;
2593 if (write) {
2594 int val = *negp ? -*lvalp : *lvalp;
2595 if ((param->min && *param->min > val) ||
2596 (param->max && *param->max < val))
2597 return -EINVAL;
2598 *valp = val;
2599 } else {
2600 int val = *valp;
2601 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002602 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002603 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002605 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 *lvalp = (unsigned long)val;
2607 }
2608 }
2609 return 0;
2610}
2611
2612/**
2613 * proc_dointvec_minmax - read a vector of integers with min/max values
2614 * @table: the sysctl table
2615 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 * @buffer: the user buffer
2617 * @lenp: the size of the user buffer
2618 * @ppos: file position
2619 *
2620 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2621 * values from/to the user buffer, treated as an ASCII string.
2622 *
2623 * This routine will ensure the values are within the range specified by
2624 * table->extra1 (min) and table->extra2 (max).
2625 *
Waiman Long24704f32018-04-10 16:35:38 -07002626 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002628int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 void __user *buffer, size_t *lenp, loff_t *ppos)
2630{
2631 struct do_proc_dointvec_minmax_conv_param param = {
2632 .min = (int *) table->extra1,
2633 .max = (int *) table->extra2,
2634 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002635 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 do_proc_dointvec_minmax_conv, &param);
2637}
2638
Waiman Long24704f32018-04-10 16:35:38 -07002639/**
2640 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2641 * @min: pointer to minimum allowable value
2642 * @max: pointer to maximum allowable value
2643 *
2644 * The do_proc_douintvec_minmax_conv_param structure provides the
2645 * minimum and maximum values for doing range checking for those sysctl
2646 * parameters that use the proc_douintvec_minmax() handler.
2647 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002648struct do_proc_douintvec_minmax_conv_param {
2649 unsigned int *min;
2650 unsigned int *max;
2651};
2652
2653static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2654 unsigned int *valp,
2655 int write, void *data)
2656{
2657 struct do_proc_douintvec_minmax_conv_param *param = data;
2658
2659 if (write) {
2660 unsigned int val = *lvalp;
2661
Joe Lawrencefb910c42017-11-17 15:29:28 -08002662 if (*lvalp > UINT_MAX)
2663 return -EINVAL;
2664
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002665 if ((param->min && *param->min > val) ||
2666 (param->max && *param->max < val))
2667 return -ERANGE;
2668
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002669 *valp = val;
2670 } else {
2671 unsigned int val = *valp;
2672 *lvalp = (unsigned long) val;
2673 }
2674
2675 return 0;
2676}
2677
2678/**
2679 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2680 * @table: the sysctl table
2681 * @write: %TRUE if this is a write to the sysctl file
2682 * @buffer: the user buffer
2683 * @lenp: the size of the user buffer
2684 * @ppos: file position
2685 *
2686 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2687 * values from/to the user buffer, treated as an ASCII string. Negative
2688 * strings are not allowed.
2689 *
2690 * This routine will ensure the values are within the range specified by
2691 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2692 * check for UINT_MAX to avoid having to support wrap around uses from
2693 * userspace.
2694 *
Waiman Long24704f32018-04-10 16:35:38 -07002695 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002696 */
2697int proc_douintvec_minmax(struct ctl_table *table, int write,
2698 void __user *buffer, size_t *lenp, loff_t *ppos)
2699{
2700 struct do_proc_douintvec_minmax_conv_param param = {
2701 .min = (unsigned int *) table->extra1,
2702 .max = (unsigned int *) table->extra2,
2703 };
2704 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2705 do_proc_douintvec_minmax_conv, &param);
2706}
2707
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002708static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2709 unsigned int *valp,
2710 int write, void *data)
2711{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002712 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002713 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002714
Joe Lawrencefb910c42017-11-17 15:29:28 -08002715 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002716 if (val == 0)
2717 return -EINVAL;
2718
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002719 *valp = val;
2720 } else {
2721 unsigned int val = *valp;
2722 *lvalp = (unsigned long) val;
2723 }
2724
2725 return 0;
2726}
2727
Eric Biggers319e0a22018-02-06 15:41:49 -08002728static int proc_dopipe_max_size(struct ctl_table *table, int write,
2729 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002730{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002731 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002732 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002733}
2734
Kees Cook54b50192012-07-30 14:39:18 -07002735static void validate_coredump_safety(void)
2736{
Alex Kelly046d6622012-10-04 17:15:23 -07002737#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002738 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002739 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002740 printk(KERN_WARNING
2741"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2742"Pipe handler or fully qualified core dump path required.\n"
2743"Set kernel.core_pattern before fs.suid_dumpable.\n"
2744 );
Kees Cook54b50192012-07-30 14:39:18 -07002745 }
Alex Kelly046d6622012-10-04 17:15:23 -07002746#endif
Kees Cook54b50192012-07-30 14:39:18 -07002747}
2748
2749static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2750 void __user *buffer, size_t *lenp, loff_t *ppos)
2751{
2752 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2753 if (!error)
2754 validate_coredump_safety();
2755 return error;
2756}
2757
Alex Kelly046d6622012-10-04 17:15:23 -07002758#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002759static int proc_dostring_coredump(struct ctl_table *table, int write,
2760 void __user *buffer, size_t *lenp, loff_t *ppos)
2761{
2762 int error = proc_dostring(table, write, buffer, lenp, ppos);
2763 if (!error)
2764 validate_coredump_safety();
2765 return error;
2766}
Alex Kelly046d6622012-10-04 17:15:23 -07002767#endif
Kees Cook54b50192012-07-30 14:39:18 -07002768
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002769static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 void __user *buffer,
2771 size_t *lenp, loff_t *ppos,
2772 unsigned long convmul,
2773 unsigned long convdiv)
2774{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002775 unsigned long *i, *min, *max;
2776 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002777 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002778 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002779
2780 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 *lenp = 0;
2782 return 0;
2783 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002784
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002785 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 min = (unsigned long *) table->extra1;
2787 max = (unsigned long *) table->extra2;
2788 vleft = table->maxlen / sizeof(unsigned long);
2789 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002790
2791 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002792 if (proc_first_pos_non_zero_ignore(ppos, table))
2793 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002794
Amerigo Wang00b7c332010-05-05 00:26:45 +00002795 if (left > PAGE_SIZE - 1)
2796 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002797 p = kbuf = memdup_user_nul(buffer, left);
2798 if (IS_ERR(kbuf))
2799 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002800 }
2801
Eric Dumazet27b3d802010-10-07 12:59:29 -07002802 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002803 unsigned long val;
2804
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002806 bool neg;
2807
Al Viro70f6cbb2015-12-24 00:13:10 -05002808 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08002809 if (!left)
2810 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002811
Al Viro70f6cbb2015-12-24 00:13:10 -05002812 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002813 proc_wspace_sep,
2814 sizeof(proc_wspace_sep), NULL);
2815 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 break;
2817 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002819 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 if ((min && val < *min) || (max && val > *max))
2821 continue;
2822 *i = val;
2823 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002824 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002825 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002826 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002827 if (err)
2828 break;
2829 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002830 err = proc_put_long(&buffer, &left, val, false);
2831 if (err)
2832 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 }
2834 }
2835
Amerigo Wang00b7c332010-05-05 00:26:45 +00002836 if (!write && !first && left && !err)
2837 err = proc_put_char(&buffer, &left, '\n');
2838 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002839 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002841 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002842 if (first)
2843 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002846out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002848 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849}
2850
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002851static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002852 void __user *buffer,
2853 size_t *lenp, loff_t *ppos,
2854 unsigned long convmul,
2855 unsigned long convdiv)
2856{
2857 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002858 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002859}
2860
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861/**
2862 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2863 * @table: the sysctl table
2864 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 * @buffer: the user buffer
2866 * @lenp: the size of the user buffer
2867 * @ppos: file position
2868 *
2869 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2870 * values from/to the user buffer, treated as an ASCII string.
2871 *
2872 * This routine will ensure the values are within the range specified by
2873 * table->extra1 (min) and table->extra2 (max).
2874 *
2875 * Returns 0 on success.
2876 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002877int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 void __user *buffer, size_t *lenp, loff_t *ppos)
2879{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002880 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881}
2882
2883/**
2884 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2885 * @table: the sysctl table
2886 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 * @buffer: the user buffer
2888 * @lenp: the size of the user buffer
2889 * @ppos: file position
2890 *
2891 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2892 * values from/to the user buffer, treated as an ASCII string. The values
2893 * are treated as milliseconds, and converted to jiffies when they are stored.
2894 *
2895 * This routine will ensure the values are within the range specified by
2896 * table->extra1 (min) and table->extra2 (max).
2897 *
2898 * Returns 0 on success.
2899 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002900int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 void __user *buffer,
2902 size_t *lenp, loff_t *ppos)
2903{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002904 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 lenp, ppos, HZ, 1000l);
2906}
2907
2908
Amerigo Wang00b7c332010-05-05 00:26:45 +00002909static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 int *valp,
2911 int write, void *data)
2912{
2913 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002914 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002915 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2917 } else {
2918 int val = *valp;
2919 unsigned long lval;
2920 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002921 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002922 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002924 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 lval = (unsigned long)val;
2926 }
2927 *lvalp = lval / HZ;
2928 }
2929 return 0;
2930}
2931
Amerigo Wang00b7c332010-05-05 00:26:45 +00002932static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 int *valp,
2934 int write, void *data)
2935{
2936 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002937 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2938 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2940 } else {
2941 int val = *valp;
2942 unsigned long lval;
2943 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002944 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002945 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002947 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 lval = (unsigned long)val;
2949 }
2950 *lvalp = jiffies_to_clock_t(lval);
2951 }
2952 return 0;
2953}
2954
Amerigo Wang00b7c332010-05-05 00:26:45 +00002955static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 int *valp,
2957 int write, void *data)
2958{
2959 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002960 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2961
2962 if (jif > INT_MAX)
2963 return 1;
2964 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 } else {
2966 int val = *valp;
2967 unsigned long lval;
2968 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002969 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002970 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002972 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 lval = (unsigned long)val;
2974 }
2975 *lvalp = jiffies_to_msecs(lval);
2976 }
2977 return 0;
2978}
2979
2980/**
2981 * proc_dointvec_jiffies - read a vector of integers as seconds
2982 * @table: the sysctl table
2983 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 * @buffer: the user buffer
2985 * @lenp: the size of the user buffer
2986 * @ppos: file position
2987 *
2988 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2989 * values from/to the user buffer, treated as an ASCII string.
2990 * The values read are assumed to be in seconds, and are converted into
2991 * jiffies.
2992 *
2993 * Returns 0 on success.
2994 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002995int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 void __user *buffer, size_t *lenp, loff_t *ppos)
2997{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002998 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 do_proc_dointvec_jiffies_conv,NULL);
3000}
3001
3002/**
3003 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3004 * @table: the sysctl table
3005 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 * @buffer: the user buffer
3007 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003008 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 *
3010 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3011 * values from/to the user buffer, treated as an ASCII string.
3012 * The values read are assumed to be in 1/USER_HZ seconds, and
3013 * are converted into jiffies.
3014 *
3015 * Returns 0 on success.
3016 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003017int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 void __user *buffer, size_t *lenp, loff_t *ppos)
3019{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003020 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 do_proc_dointvec_userhz_jiffies_conv,NULL);
3022}
3023
3024/**
3025 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3026 * @table: the sysctl table
3027 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 * @buffer: the user buffer
3029 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003030 * @ppos: file position
3031 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 *
3033 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3034 * values from/to the user buffer, treated as an ASCII string.
3035 * The values read are assumed to be in 1/1000 seconds, and
3036 * are converted into jiffies.
3037 *
3038 * Returns 0 on success.
3039 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003040int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 void __user *buffer, size_t *lenp, loff_t *ppos)
3042{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003043 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 do_proc_dointvec_ms_jiffies_conv, NULL);
3045}
3046
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003047static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003048 void __user *buffer, size_t *lenp, loff_t *ppos)
3049{
3050 struct pid *new_pid;
3051 pid_t tmp;
3052 int r;
3053
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003054 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003055
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003056 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003057 lenp, ppos, NULL, NULL);
3058 if (r || !write)
3059 return r;
3060
3061 new_pid = find_get_pid(tmp);
3062 if (!new_pid)
3063 return -ESRCH;
3064
3065 put_pid(xchg(&cad_pid, new_pid));
3066 return 0;
3067}
3068
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003069/**
3070 * proc_do_large_bitmap - read/write from/to a large bitmap
3071 * @table: the sysctl table
3072 * @write: %TRUE if this is a write to the sysctl file
3073 * @buffer: the user buffer
3074 * @lenp: the size of the user buffer
3075 * @ppos: file position
3076 *
3077 * The bitmap is stored at table->data and the bitmap length (in bits)
3078 * in table->maxlen.
3079 *
3080 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3081 * large bitmaps may be represented in a compact manner. Writing into
3082 * the file will clear the bitmap then update it with the given input.
3083 *
3084 * Returns 0 on success.
3085 */
3086int proc_do_large_bitmap(struct ctl_table *table, int write,
3087 void __user *buffer, size_t *lenp, loff_t *ppos)
3088{
3089 int err = 0;
3090 bool first = 1;
3091 size_t left = *lenp;
3092 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003093 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003094 unsigned long *tmp_bitmap = NULL;
3095 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3096
WANG Cong122ff242014-05-12 16:04:53 -07003097 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003098 *lenp = 0;
3099 return 0;
3100 }
3101
3102 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003103 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003104
3105 if (left > PAGE_SIZE - 1)
3106 left = PAGE_SIZE - 1;
3107
Al Viro70f6cbb2015-12-24 00:13:10 -05003108 p = kbuf = memdup_user_nul(buffer, left);
3109 if (IS_ERR(kbuf))
3110 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003111
Kees Cook6396bb22018-06-12 14:03:40 -07003112 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3113 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003114 GFP_KERNEL);
3115 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003116 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003117 return -ENOMEM;
3118 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003119 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003120 while (!err && left) {
3121 unsigned long val_a, val_b;
3122 bool neg;
3123
Al Viro70f6cbb2015-12-24 00:13:10 -05003124 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003125 sizeof(tr_a), &c);
3126 if (err)
3127 break;
3128 if (val_a >= bitmap_len || neg) {
3129 err = -EINVAL;
3130 break;
3131 }
3132
3133 val_b = val_a;
3134 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003135 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003136 left--;
3137 }
3138
3139 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003140 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003141 &neg, tr_b, sizeof(tr_b),
3142 &c);
3143 if (err)
3144 break;
3145 if (val_b >= bitmap_len || neg ||
3146 val_a > val_b) {
3147 err = -EINVAL;
3148 break;
3149 }
3150 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003151 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003152 left--;
3153 }
3154 }
3155
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003156 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003157 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003158 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003159 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003160 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003161 } else {
3162 unsigned long bit_a, bit_b = 0;
3163
3164 while (left) {
3165 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3166 if (bit_a >= bitmap_len)
3167 break;
3168 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3169 bit_a + 1) - 1;
3170
3171 if (!first) {
3172 err = proc_put_char(&buffer, &left, ',');
3173 if (err)
3174 break;
3175 }
3176 err = proc_put_long(&buffer, &left, bit_a, false);
3177 if (err)
3178 break;
3179 if (bit_a != bit_b) {
3180 err = proc_put_char(&buffer, &left, '-');
3181 if (err)
3182 break;
3183 err = proc_put_long(&buffer, &left, bit_b, false);
3184 if (err)
3185 break;
3186 }
3187
3188 first = 0; bit_b++;
3189 }
3190 if (!err)
3191 err = proc_put_char(&buffer, &left, '\n');
3192 }
3193
3194 if (!err) {
3195 if (write) {
3196 if (*ppos)
3197 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3198 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003199 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003200 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003201 *lenp -= left;
3202 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003203 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003204
3205 kfree(tmp_bitmap);
3206 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003207}
3208
Jovi Zhang55610502011-01-12 17:00:45 -08003209#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003211int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 void __user *buffer, size_t *lenp, loff_t *ppos)
3213{
3214 return -ENOSYS;
3215}
3216
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003217int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 void __user *buffer, size_t *lenp, loff_t *ppos)
3219{
3220 return -ENOSYS;
3221}
3222
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003223int proc_douintvec(struct ctl_table *table, int write,
3224 void __user *buffer, size_t *lenp, loff_t *ppos)
3225{
3226 return -ENOSYS;
3227}
3228
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003229int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 void __user *buffer, size_t *lenp, loff_t *ppos)
3231{
3232 return -ENOSYS;
3233}
3234
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003235int proc_douintvec_minmax(struct ctl_table *table, int write,
3236 void __user *buffer, size_t *lenp, loff_t *ppos)
3237{
3238 return -ENOSYS;
3239}
3240
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003241int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 void __user *buffer, size_t *lenp, loff_t *ppos)
3243{
3244 return -ENOSYS;
3245}
3246
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003247int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 void __user *buffer, size_t *lenp, loff_t *ppos)
3249{
3250 return -ENOSYS;
3251}
3252
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003253int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 void __user *buffer, size_t *lenp, loff_t *ppos)
3255{
3256 return -ENOSYS;
3257}
3258
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003259int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 void __user *buffer, size_t *lenp, loff_t *ppos)
3261{
3262 return -ENOSYS;
3263}
3264
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003265int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 void __user *buffer,
3267 size_t *lenp, loff_t *ppos)
3268{
3269 return -ENOSYS;
3270}
3271
3272
Jovi Zhang55610502011-01-12 17:00:45 -08003273#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003275static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
3276 void __user *buffer, size_t *lenp,
3277 loff_t *ppos)
3278{
3279 int ret, bpf_stats = *(int *)table->data;
3280 struct ctl_table tmp = *table;
3281
3282 if (write && !capable(CAP_SYS_ADMIN))
3283 return -EPERM;
3284
3285 tmp.data = &bpf_stats;
3286 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3287 if (write && !ret) {
3288 *(int *)table->data = bpf_stats;
3289 if (bpf_stats)
3290 static_branch_enable(&bpf_stats_enabled_key);
3291 else
3292 static_branch_disable(&bpf_stats_enabled_key);
3293 }
3294 return ret;
3295}
3296
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297/*
3298 * No sense putting this after each symbol definition, twice,
3299 * exception granted :-)
3300 */
3301EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003302EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303EXPORT_SYMBOL(proc_dointvec_jiffies);
3304EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003305EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3307EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3308EXPORT_SYMBOL(proc_dostring);
3309EXPORT_SYMBOL(proc_doulongvec_minmax);
3310EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);