blob: 1825f712e73bb74809e921503622dd5511b94923 [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);
Kees Cook54b50192012-07-30 14:39:18 -0700227
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700228#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700229/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100230static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700231
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700232static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700233 void __user *buffer, size_t *lenp,
234 loff_t *ppos)
235{
236 int error;
237
238 error = proc_dointvec(table, write, buffer, lenp, ppos);
239 if (error)
240 return error;
241
242 if (write)
243 sysrq_toggle_support(__sysrq_enabled);
244
245 return 0;
246}
247
248#endif
249
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700250static struct ctl_table kern_table[];
251static struct ctl_table vm_table[];
252static struct ctl_table fs_table[];
253static struct ctl_table debug_table[];
254static struct ctl_table dev_table[];
255extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800256#ifdef CONFIG_EPOLL
257extern struct ctl_table epoll_table[];
258#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800260#ifdef CONFIG_FW_LOADER_USER_HELPER
261extern struct ctl_table firmware_config_table[];
262#endif
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
265int sysctl_legacy_va_layout;
266#endif
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268/* The default sysctl tables: */
269
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800270static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 .procname = "kernel",
273 .mode = 0555,
274 .child = kern_table,
275 },
276 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 .procname = "vm",
278 .mode = 0555,
279 .child = vm_table,
280 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 .procname = "fs",
283 .mode = 0555,
284 .child = fs_table,
285 },
286 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 .procname = "debug",
288 .mode = 0555,
289 .child = debug_table,
290 },
291 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 .procname = "dev",
293 .mode = 0555,
294 .child = dev_table,
295 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700296 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297};
298
Ingo Molnar77e54a12007-07-09 18:52:00 +0200299#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100300static int min_sched_granularity_ns = 100000; /* 100 usecs */
301static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
302static int min_wakeup_granularity_ns; /* 0 usecs */
303static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200304#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100305static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
306static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200307#endif /* CONFIG_SMP */
308#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200309
Mel Gorman5e771902010-05-24 14:32:31 -0700310#ifdef CONFIG_COMPACTION
311static int min_extfrag_threshold;
312static int max_extfrag_threshold = 1000;
313#endif
314
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700315static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200316 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200317 .procname = "sched_child_runs_first",
318 .data = &sysctl_sched_child_runs_first,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800321 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200322 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200323#ifdef CONFIG_SCHED_DEBUG
324 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100325 .procname = "sched_min_granularity_ns",
326 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200327 .maxlen = sizeof(unsigned int),
328 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800329 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100330 .extra1 = &min_sched_granularity_ns,
331 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200332 },
333 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200334 .procname = "sched_latency_ns",
335 .data = &sysctl_sched_latency,
336 .maxlen = sizeof(unsigned int),
337 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800338 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200339 .extra1 = &min_sched_granularity_ns,
340 .extra2 = &max_sched_granularity_ns,
341 },
342 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200343 .procname = "sched_wakeup_granularity_ns",
344 .data = &sysctl_sched_wakeup_granularity,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800347 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200348 .extra1 = &min_wakeup_granularity_ns,
349 .extra2 = &max_wakeup_granularity_ns,
350 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200351#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200352 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100353 .procname = "sched_tunable_scaling",
354 .data = &sysctl_sched_tunable_scaling,
355 .maxlen = sizeof(enum sched_tunable_scaling),
356 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800357 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100358 .extra1 = &min_sched_tunable_scaling,
359 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200360 },
361 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900362 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200363 .data = &sysctl_sched_migration_cost,
364 .maxlen = sizeof(unsigned int),
365 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800366 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200367 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100368 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100369 .procname = "sched_nr_migrate",
370 .data = &sysctl_sched_nr_migrate,
371 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100372 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800373 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100374 },
Mel Gormancb251762016-02-05 09:08:36 +0000375#ifdef CONFIG_SCHEDSTATS
376 {
377 .procname = "sched_schedstats",
378 .data = NULL,
379 .maxlen = sizeof(unsigned int),
380 .mode = 0644,
381 .proc_handler = sysctl_schedstats,
382 .extra1 = &zero,
383 .extra2 = &one,
384 },
385#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200386#endif /* CONFIG_SMP */
387#ifdef CONFIG_NUMA_BALANCING
388 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200389 .procname = "numa_balancing_scan_delay_ms",
390 .data = &sysctl_numa_balancing_scan_delay,
391 .maxlen = sizeof(unsigned int),
392 .mode = 0644,
393 .proc_handler = proc_dointvec,
394 },
395 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200396 .procname = "numa_balancing_scan_period_min_ms",
397 .data = &sysctl_numa_balancing_scan_period_min,
398 .maxlen = sizeof(unsigned int),
399 .mode = 0644,
400 .proc_handler = proc_dointvec,
401 },
402 {
403 .procname = "numa_balancing_scan_period_max_ms",
404 .data = &sysctl_numa_balancing_scan_period_max,
405 .maxlen = sizeof(unsigned int),
406 .mode = 0644,
407 .proc_handler = proc_dointvec,
408 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200409 {
410 .procname = "numa_balancing_scan_size_mb",
411 .data = &sysctl_numa_balancing_scan_size,
412 .maxlen = sizeof(unsigned int),
413 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400414 .proc_handler = proc_dointvec_minmax,
415 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200416 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100417 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800418 .procname = "numa_balancing",
419 .data = NULL, /* filled in by handler */
420 .maxlen = sizeof(unsigned int),
421 .mode = 0644,
422 .proc_handler = sysctl_numa_balancing,
423 .extra1 = &zero,
424 .extra2 = &one,
425 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200426#endif /* CONFIG_NUMA_BALANCING */
427#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200428 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100429 .procname = "sched_rt_period_us",
430 .data = &sysctl_sched_rt_period,
431 .maxlen = sizeof(unsigned int),
432 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800433 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100434 },
435 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100436 .procname = "sched_rt_runtime_us",
437 .data = &sysctl_sched_rt_runtime,
438 .maxlen = sizeof(int),
439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800440 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100441 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600442 {
443 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800444 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600445 .maxlen = sizeof(int),
446 .mode = 0644,
447 .proc_handler = sched_rr_handler,
448 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100449#ifdef CONFIG_SCHED_AUTOGROUP
450 {
451 .procname = "sched_autogroup_enabled",
452 .data = &sysctl_sched_autogroup_enabled,
453 .maxlen = sizeof(unsigned int),
454 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800455 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100456 .extra1 = &zero,
457 .extra2 = &one,
458 },
459#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700460#ifdef CONFIG_CFS_BANDWIDTH
461 {
462 .procname = "sched_cfs_bandwidth_slice_us",
463 .data = &sysctl_sched_cfs_bandwidth_slice,
464 .maxlen = sizeof(unsigned int),
465 .mode = 0644,
466 .proc_handler = proc_dointvec_minmax,
467 .extra1 = &one,
468 },
469#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700470#ifdef CONFIG_PROVE_LOCKING
471 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700472 .procname = "prove_locking",
473 .data = &prove_locking,
474 .maxlen = sizeof(int),
475 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800476 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700477 },
478#endif
479#ifdef CONFIG_LOCK_STAT
480 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700481 .procname = "lock_stat",
482 .data = &lock_stat,
483 .maxlen = sizeof(int),
484 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800485 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700486 },
487#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200488 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 .procname = "panic",
490 .data = &panic_timeout,
491 .maxlen = sizeof(int),
492 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800493 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 },
Alex Kelly046d6622012-10-04 17:15:23 -0700495#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 .procname = "core_uses_pid",
498 .data = &core_uses_pid,
499 .maxlen = sizeof(int),
500 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800501 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 },
503 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 .procname = "core_pattern",
505 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700506 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700508 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 },
Neil Hormana2939802009-09-23 15:56:56 -0700510 {
Neil Hormana2939802009-09-23 15:56:56 -0700511 .procname = "core_pipe_limit",
512 .data = &core_pipe_limit,
513 .maxlen = sizeof(unsigned int),
514 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800515 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700516 },
Alex Kelly046d6622012-10-04 17:15:23 -0700517#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800518#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700521 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800522 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800523 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700525 {
526 .procname = "sysctl_writes_strict",
527 .data = &sysctl_writes_strict,
528 .maxlen = sizeof(int),
529 .mode = 0644,
530 .proc_handler = proc_dointvec_minmax,
531 .extra1 = &neg_one,
532 .extra2 = &one,
533 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800534#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100535#ifdef CONFIG_LATENCYTOP
536 {
537 .procname = "latencytop",
538 .data = &latencytop_enabled,
539 .maxlen = sizeof(int),
540 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000541 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100542 },
543#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544#ifdef CONFIG_BLK_DEV_INITRD
545 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 .procname = "real-root-dev",
547 .data = &real_root_dev,
548 .maxlen = sizeof(int),
549 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800550 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 },
552#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700553 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700554 .procname = "print-fatal-signals",
555 .data = &print_fatal_signals,
556 .maxlen = sizeof(int),
557 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800558 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700559 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700560#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 .procname = "reboot-cmd",
563 .data = reboot_command,
564 .maxlen = 256,
565 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800566 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 },
568 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 .procname = "stop-a",
570 .data = &stop_a_enabled,
571 .maxlen = sizeof (int),
572 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800573 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 },
575 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 .procname = "scons-poweroff",
577 .data = &scons_pwroff,
578 .maxlen = sizeof (int),
579 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800580 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 },
582#endif
David S. Miller08714202008-11-16 23:49:24 -0800583#ifdef CONFIG_SPARC64
584 {
David S. Miller08714202008-11-16 23:49:24 -0800585 .procname = "tsb-ratio",
586 .data = &sysctl_tsb_ratio,
587 .maxlen = sizeof (int),
588 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800589 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800590 },
591#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592#ifdef __hppa__
593 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 .procname = "soft-power",
595 .data = &pwrsw_enabled,
596 .maxlen = sizeof (int),
597 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800598 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530600#endif
601#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 .procname = "unaligned-trap",
604 .data = &unaligned_enabled,
605 .maxlen = sizeof (int),
606 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800607 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 },
609#endif
610 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 .procname = "ctrl-alt-del",
612 .data = &C_A_D,
613 .maxlen = sizeof(int),
614 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800615 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400617#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200618 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200619 .procname = "ftrace_enabled",
620 .data = &ftrace_enabled,
621 .maxlen = sizeof(int),
622 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800623 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200624 },
625#endif
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500626#ifdef CONFIG_STACK_TRACER
627 {
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500628 .procname = "stack_tracer_enabled",
629 .data = &stack_tracer_enabled,
630 .maxlen = sizeof(int),
631 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800632 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d2a2008-12-16 23:06:40 -0500633 },
634#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400635#ifdef CONFIG_TRACING
636 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100637 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400638 .data = &ftrace_dump_on_oops,
639 .maxlen = sizeof(int),
640 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800641 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400642 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400643 {
644 .procname = "traceoff_on_warning",
645 .data = &__disable_trace_on_warning,
646 .maxlen = sizeof(__disable_trace_on_warning),
647 .mode = 0644,
648 .proc_handler = proc_dointvec,
649 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500650 {
651 .procname = "tracepoint_printk",
652 .data = &tracepoint_printk,
653 .maxlen = sizeof(tracepoint_printk),
654 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500655 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500656 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400657#endif
Dave Young2965faa2015-09-09 15:38:55 -0700658#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800659 {
660 .procname = "kexec_load_disabled",
661 .data = &kexec_load_disabled,
662 .maxlen = sizeof(int),
663 .mode = 0644,
664 /* only handle a transition from default "0" to "1" */
665 .proc_handler = proc_dointvec_minmax,
666 .extra1 = &one,
667 .extra2 = &one,
668 },
669#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200670#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 .procname = "modprobe",
673 .data = &modprobe_path,
674 .maxlen = KMOD_PATH_LEN,
675 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800676 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 },
Kees Cook3d433212009-04-02 15:49:29 -0700678 {
Kees Cook3d433212009-04-02 15:49:29 -0700679 .procname = "modules_disabled",
680 .data = &modules_disabled,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800684 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700685 .extra1 = &one,
686 .extra2 = &one,
687 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700689#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100692 .data = &uevent_helper,
693 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800695 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 },
Michael Marineau86d56132014-04-10 14:09:31 -0700697#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698#ifdef CONFIG_CHR_DEV_SG
699 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 .procname = "sg-big-buff",
701 .data = &sg_big_buff,
702 .maxlen = sizeof (int),
703 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800704 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 },
706#endif
707#ifdef CONFIG_BSD_PROCESS_ACCT
708 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 .procname = "acct",
710 .data = &acct_parm,
711 .maxlen = 3*sizeof(int),
712 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800713 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 },
715#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716#ifdef CONFIG_MAGIC_SYSRQ
717 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800719 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 .maxlen = sizeof (int),
721 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700722 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 },
724#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700725#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700728 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .maxlen = sizeof (int),
730 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800731 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700733#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700736 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 .maxlen = sizeof(int),
738 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700739 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 },
741 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 .procname = "random",
743 .mode = 0555,
744 .child = random_table,
745 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 {
Eric Paris17f60a72011-04-01 17:07:50 -0400747 .procname = "usermodehelper",
748 .mode = 0555,
749 .child = usermodehelper_table,
750 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800751#ifdef CONFIG_FW_LOADER_USER_HELPER
752 {
753 .procname = "firmware_config",
754 .mode = 0555,
755 .child = firmware_config_table,
756 },
757#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400758 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 .procname = "overflowuid",
760 .data = &overflowuid,
761 .maxlen = sizeof(int),
762 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800763 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 .extra1 = &minolduid,
765 .extra2 = &maxolduid,
766 },
767 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 .procname = "overflowgid",
769 .data = &overflowgid,
770 .maxlen = sizeof(int),
771 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800772 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 .extra1 = &minolduid,
774 .extra2 = &maxolduid,
775 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800776#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777#ifdef CONFIG_MATHEMU
778 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 .procname = "ieee_emulation_warnings",
780 .data = &sysctl_ieee_emulation_warnings,
781 .maxlen = sizeof(int),
782 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800783 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 },
785#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200788 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .maxlen = sizeof(int),
790 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 },
793#endif
794 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 .procname = "pid_max",
796 .data = &pid_max,
797 .maxlen = sizeof (int),
798 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800799 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 .extra1 = &pid_max_min,
801 .extra2 = &pid_max_max,
802 },
803 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 .procname = "panic_on_oops",
805 .data = &panic_on_oops,
806 .maxlen = sizeof(int),
807 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800808 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800810#if defined CONFIG_PRINTK
811 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800812 .procname = "printk",
813 .data = &console_loglevel,
814 .maxlen = 4*sizeof(int),
815 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800816 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800817 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700820 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 .maxlen = sizeof(int),
822 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800823 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 },
825 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700827 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 .maxlen = sizeof(int),
829 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800830 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 },
Dave Youngaf913222009-09-22 16:43:33 -0700832 {
Dave Youngaf913222009-09-22 16:43:33 -0700833 .procname = "printk_delay",
834 .data = &printk_delay_msec,
835 .maxlen = sizeof(int),
836 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800837 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700838 .extra1 = &zero,
839 .extra2 = &ten_thousand,
840 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700842 .procname = "printk_devkmsg",
843 .data = devkmsg_log_str,
844 .maxlen = DEVKMSG_STR_MAX_SIZE,
845 .mode = 0644,
846 .proc_handler = devkmsg_sysctl_set_loglvl,
847 },
848 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800849 .procname = "dmesg_restrict",
850 .data = &dmesg_restrict,
851 .maxlen = sizeof(int),
852 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700853 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800854 .extra1 = &zero,
855 .extra2 = &one,
856 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800857 {
858 .procname = "kptr_restrict",
859 .data = &kptr_restrict,
860 .maxlen = sizeof(int),
861 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700862 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800863 .extra1 = &zero,
864 .extra2 = &two,
865 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800866#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800867 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 .procname = "ngroups_max",
869 .data = &ngroups_max,
870 .maxlen = sizeof (int),
871 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800872 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 },
Dan Ballard73efc032011-10-31 17:11:20 -0700874 {
875 .procname = "cap_last_cap",
876 .data = (void *)&cap_last_cap,
877 .maxlen = sizeof(int),
878 .mode = 0444,
879 .proc_handler = proc_dointvec,
880 },
Don Zickus58687ac2010-05-07 17:11:44 -0400881#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500882 {
Don Zickus58687ac2010-05-07 17:11:44 -0400883 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200884 .data = &watchdog_user_enabled,
885 .maxlen = sizeof(int),
886 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700887 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700888 .extra1 = &zero,
889 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400890 },
891 {
892 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700893 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400894 .maxlen = sizeof(int),
895 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700896 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800897 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400898 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500899 },
Don Zickus2508ce12010-05-07 17:11:46 -0400900 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700901 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200902 .data = &nmi_watchdog_user_enabled,
903 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200904 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700905 .proc_handler = proc_nmi_watchdog,
906 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700907 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700908 },
909 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700910 .procname = "watchdog_cpumask",
911 .data = &watchdog_cpumask_bits,
912 .maxlen = NR_CPUS,
913 .mode = 0644,
914 .proc_handler = proc_watchdog_cpumask,
915 },
916#ifdef CONFIG_SOFTLOCKUP_DETECTOR
917 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700918 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200919 .data = &soft_watchdog_user_enabled,
920 .maxlen = sizeof(int),
921 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700922 .proc_handler = proc_soft_watchdog,
923 .extra1 = &zero,
924 .extra2 = &one,
925 },
926 {
Don Zickus2508ce12010-05-07 17:11:46 -0400927 .procname = "softlockup_panic",
928 .data = &softlockup_panic,
929 .maxlen = sizeof(int),
930 .mode = 0644,
931 .proc_handler = proc_dointvec_minmax,
932 .extra1 = &zero,
933 .extra2 = &one,
934 },
Aaron Tomlined235872014-06-23 13:22:05 -0700935#ifdef CONFIG_SMP
936 {
937 .procname = "softlockup_all_cpu_backtrace",
938 .data = &sysctl_softlockup_all_cpu_backtrace,
939 .maxlen = sizeof(int),
940 .mode = 0644,
941 .proc_handler = proc_dointvec_minmax,
942 .extra1 = &zero,
943 .extra2 = &one,
944 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700945#endif /* CONFIG_SMP */
946#endif
947#ifdef CONFIG_HARDLOCKUP_DETECTOR
948 {
949 .procname = "hardlockup_panic",
950 .data = &hardlockup_panic,
951 .maxlen = sizeof(int),
952 .mode = 0644,
953 .proc_handler = proc_dointvec_minmax,
954 .extra1 = &zero,
955 .extra2 = &one,
956 },
957#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800958 {
959 .procname = "hardlockup_all_cpu_backtrace",
960 .data = &sysctl_hardlockup_all_cpu_backtrace,
961 .maxlen = sizeof(int),
962 .mode = 0644,
963 .proc_handler = proc_dointvec_minmax,
964 .extra1 = &zero,
965 .extra2 = &one,
966 },
Aaron Tomlined235872014-06-23 13:22:05 -0700967#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500968#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700969#endif
970
Don Zickus5dc30552010-11-29 17:07:17 -0500971#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
972 {
973 .procname = "unknown_nmi_panic",
974 .data = &unknown_nmi_panic,
975 .maxlen = sizeof (int),
976 .mode = 0644,
977 .proc_handler = proc_dointvec,
978 },
Don Zickus504d7cf2010-02-12 17:19:19 -0500979#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980#if defined(CONFIG_X86)
981 {
Don Zickus8da5add2006-09-26 10:52:27 +0200982 .procname = "panic_on_unrecovered_nmi",
983 .data = &panic_on_unrecovered_nmi,
984 .maxlen = sizeof(int),
985 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800986 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +0200987 },
988 {
Kurt Garloff5211a242009-06-24 14:32:11 -0700989 .procname = "panic_on_io_nmi",
990 .data = &panic_on_io_nmi,
991 .maxlen = sizeof(int),
992 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800993 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -0700994 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +0900995#ifdef CONFIG_DEBUG_STACKOVERFLOW
996 {
997 .procname = "panic_on_stackoverflow",
998 .data = &sysctl_panic_on_stackoverflow,
999 .maxlen = sizeof(int),
1000 .mode = 0644,
1001 .proc_handler = proc_dointvec,
1002 },
1003#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001004 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 .procname = "bootloader_type",
1006 .data = &bootloader_type,
1007 .maxlen = sizeof (int),
1008 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001009 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001011 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001012 .procname = "bootloader_version",
1013 .data = &bootloader_version,
1014 .maxlen = sizeof (int),
1015 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001016 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001017 },
1018 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001019 .procname = "io_delay_type",
1020 .data = &io_delay_type,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001024 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001026#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 .procname = "randomize_va_space",
1029 .data = &randomize_va_space,
1030 .maxlen = sizeof(int),
1031 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001032 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001034#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001035#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001036 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001037 .procname = "spin_retry",
1038 .data = &spin_retry,
1039 .maxlen = sizeof (int),
1040 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001041 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001042 },
1043#endif
Len Brown673d5b42007-07-28 03:33:16 -04001044#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001045 {
Pavel Machekc255d842006-02-20 18:27:58 -08001046 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001047 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001048 .maxlen = sizeof (unsigned long),
1049 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001050 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001051 },
1052#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301053#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001054 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001055 .procname = "ignore-unaligned-usertrap",
1056 .data = &no_unaligned_warning,
1057 .maxlen = sizeof (int),
1058 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001059 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001060 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301061#endif
1062#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001063 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001064 .procname = "unaligned-dump-stack",
1065 .data = &unaligned_dump_stack,
1066 .maxlen = sizeof (int),
1067 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001068 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001069 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001070#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001071#ifdef CONFIG_DETECT_HUNG_TASK
1072 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001073 .procname = "hung_task_panic",
1074 .data = &sysctl_hung_task_panic,
1075 .maxlen = sizeof(int),
1076 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001077 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001078 .extra1 = &zero,
1079 .extra2 = &one,
1080 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001081 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001082 .procname = "hung_task_check_count",
1083 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001084 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001085 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001086 .proc_handler = proc_dointvec_minmax,
1087 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001088 },
1089 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001090 .procname = "hung_task_timeout_secs",
1091 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001092 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001093 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001094 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001095 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001096 },
1097 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001098 .procname = "hung_task_check_interval_secs",
1099 .data = &sysctl_hung_task_check_interval_secs,
1100 .maxlen = sizeof(unsigned long),
1101 .mode = 0644,
1102 .proc_handler = proc_dohung_task_timeout_secs,
1103 .extra2 = &hung_task_timeout_max,
1104 },
1105 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001106 .procname = "hung_task_warnings",
1107 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001108 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001109 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001110 .proc_handler = proc_dointvec_minmax,
1111 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001112 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001113#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001114#ifdef CONFIG_RT_MUTEXES
1115 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001116 .procname = "max_lock_depth",
1117 .data = &max_lock_depth,
1118 .maxlen = sizeof(int),
1119 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001120 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001121 },
1122#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001123 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001124 .procname = "poweroff_cmd",
1125 .data = &poweroff_cmd,
1126 .maxlen = POWEROFF_CMD_PATH_LEN,
1127 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001128 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001129 },
David Howells0b77f5b2008-04-29 01:01:32 -07001130#ifdef CONFIG_KEYS
1131 {
David Howells0b77f5b2008-04-29 01:01:32 -07001132 .procname = "keys",
1133 .mode = 0555,
1134 .child = key_sysctls,
1135 },
1136#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001137#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001138 /*
1139 * User-space scripts rely on the existence of this file
1140 * as a feature check for perf_events being enabled.
1141 *
1142 * So it's an ABI, do not remove!
1143 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001144 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001145 .procname = "perf_event_paranoid",
1146 .data = &sysctl_perf_event_paranoid,
1147 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001148 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001149 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001150 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001151 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001152 .procname = "perf_event_mlock_kb",
1153 .data = &sysctl_perf_event_mlock,
1154 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001155 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001156 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001157 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001158 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001159 .procname = "perf_event_max_sample_rate",
1160 .data = &sysctl_perf_event_sample_rate,
1161 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001162 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001163 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001164 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001165 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001166 {
1167 .procname = "perf_cpu_time_max_percent",
1168 .data = &sysctl_perf_cpu_time_max_percent,
1169 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1170 .mode = 0644,
1171 .proc_handler = perf_cpu_time_max_percent_handler,
1172 .extra1 = &zero,
1173 .extra2 = &one_hundred,
1174 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001175 {
1176 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001177 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001178 .maxlen = sizeof(sysctl_perf_event_max_stack),
1179 .mode = 0644,
1180 .proc_handler = perf_event_max_stack_handler,
1181 .extra1 = &zero,
1182 .extra2 = &six_hundred_forty_kb,
1183 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001184 {
1185 .procname = "perf_event_max_contexts_per_stack",
1186 .data = &sysctl_perf_event_max_contexts_per_stack,
1187 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1188 .mode = 0644,
1189 .proc_handler = perf_event_max_stack_handler,
1190 .extra1 = &zero,
1191 .extra2 = &one_thousand,
1192 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001193#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001194 {
1195 .procname = "panic_on_warn",
1196 .data = &panic_on_warn,
1197 .maxlen = sizeof(int),
1198 .mode = 0644,
1199 .proc_handler = proc_dointvec_minmax,
1200 .extra1 = &zero,
1201 .extra2 = &one,
1202 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001203#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1204 {
1205 .procname = "timer_migration",
1206 .data = &sysctl_timer_migration,
1207 .maxlen = sizeof(unsigned int),
1208 .mode = 0644,
1209 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001210 .extra1 = &zero,
1211 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001212 },
1213#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001214#ifdef CONFIG_BPF_SYSCALL
1215 {
1216 .procname = "unprivileged_bpf_disabled",
1217 .data = &sysctl_unprivileged_bpf_disabled,
1218 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1219 .mode = 0644,
1220 /* only handle a transition from default "0" to "1" */
1221 .proc_handler = proc_dointvec_minmax,
1222 .extra1 = &one,
1223 .extra2 = &one,
1224 },
1225#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001226#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1227 {
1228 .procname = "panic_on_rcu_stall",
1229 .data = &sysctl_panic_on_rcu_stall,
1230 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1231 .mode = 0644,
1232 .proc_handler = proc_dointvec_minmax,
1233 .extra1 = &zero,
1234 .extra2 = &one,
1235 },
1236#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001237#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1238 {
1239 .procname = "stack_erasing",
1240 .data = NULL,
1241 .maxlen = sizeof(int),
1242 .mode = 0600,
1243 .proc_handler = stack_erasing_sysctl,
1244 .extra1 = &zero,
1245 .extra2 = &one,
1246 },
1247#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001248 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249};
1250
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001251static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 .procname = "overcommit_memory",
1254 .data = &sysctl_overcommit_memory,
1255 .maxlen = sizeof(sysctl_overcommit_memory),
1256 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001257 .proc_handler = proc_dointvec_minmax,
1258 .extra1 = &zero,
1259 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 },
1261 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001262 .procname = "panic_on_oom",
1263 .data = &sysctl_panic_on_oom,
1264 .maxlen = sizeof(sysctl_panic_on_oom),
1265 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001266 .proc_handler = proc_dointvec_minmax,
1267 .extra1 = &zero,
1268 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001269 },
1270 {
David Rientjesfe071d72007-10-16 23:25:56 -07001271 .procname = "oom_kill_allocating_task",
1272 .data = &sysctl_oom_kill_allocating_task,
1273 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1274 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001275 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001276 },
1277 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001278 .procname = "oom_dump_tasks",
1279 .data = &sysctl_oom_dump_tasks,
1280 .maxlen = sizeof(sysctl_oom_dump_tasks),
1281 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001282 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001283 },
1284 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 .procname = "overcommit_ratio",
1286 .data = &sysctl_overcommit_ratio,
1287 .maxlen = sizeof(sysctl_overcommit_ratio),
1288 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001289 .proc_handler = overcommit_ratio_handler,
1290 },
1291 {
1292 .procname = "overcommit_kbytes",
1293 .data = &sysctl_overcommit_kbytes,
1294 .maxlen = sizeof(sysctl_overcommit_kbytes),
1295 .mode = 0644,
1296 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 },
1298 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 .procname = "page-cluster",
1300 .data = &page_cluster,
1301 .maxlen = sizeof(int),
1302 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001303 .proc_handler = proc_dointvec_minmax,
1304 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 },
1306 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 .procname = "dirty_background_ratio",
1308 .data = &dirty_background_ratio,
1309 .maxlen = sizeof(dirty_background_ratio),
1310 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001311 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 .extra1 = &zero,
1313 .extra2 = &one_hundred,
1314 },
1315 {
David Rientjes2da02992009-01-06 14:39:31 -08001316 .procname = "dirty_background_bytes",
1317 .data = &dirty_background_bytes,
1318 .maxlen = sizeof(dirty_background_bytes),
1319 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001320 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001321 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001322 },
1323 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 .procname = "dirty_ratio",
1325 .data = &vm_dirty_ratio,
1326 .maxlen = sizeof(vm_dirty_ratio),
1327 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001328 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 .extra1 = &zero,
1330 .extra2 = &one_hundred,
1331 },
1332 {
David Rientjes2da02992009-01-06 14:39:31 -08001333 .procname = "dirty_bytes",
1334 .data = &vm_dirty_bytes,
1335 .maxlen = sizeof(vm_dirty_bytes),
1336 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001337 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001338 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001339 },
1340 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001342 .data = &dirty_writeback_interval,
1343 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001345 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 },
1347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001349 .data = &dirty_expire_interval,
1350 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001352 .proc_handler = proc_dointvec_minmax,
1353 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 },
1355 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001356 .procname = "dirtytime_expire_seconds",
1357 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001358 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001359 .mode = 0644,
1360 .proc_handler = dirtytime_interval_handler,
1361 .extra1 = &zero,
1362 },
1363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .procname = "swappiness",
1365 .data = &vm_swappiness,
1366 .maxlen = sizeof(vm_swappiness),
1367 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001368 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 .extra1 = &zero,
1370 .extra2 = &one_hundred,
1371 },
1372#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001373 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001375 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .maxlen = sizeof(unsigned long),
1377 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001378 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001379 },
1380#ifdef CONFIG_NUMA
1381 {
1382 .procname = "nr_hugepages_mempolicy",
1383 .data = NULL,
1384 .maxlen = sizeof(unsigned long),
1385 .mode = 0644,
1386 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001387 },
Kemi Wang45180852017-11-15 17:38:22 -08001388 {
1389 .procname = "numa_stat",
1390 .data = &sysctl_vm_numa_stat,
1391 .maxlen = sizeof(int),
1392 .mode = 0644,
1393 .proc_handler = sysctl_vm_numa_stat_handler,
1394 .extra1 = &zero,
1395 .extra2 = &one,
1396 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001397#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "hugetlb_shm_group",
1400 .data = &sysctl_hugetlb_shm_group,
1401 .maxlen = sizeof(gid_t),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 },
Adam Litke54f9f802007-10-16 01:26:20 -07001405 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001406 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001407 .data = NULL,
1408 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001409 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001410 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001411 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412#endif
1413 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .procname = "lowmem_reserve_ratio",
1415 .data = &sysctl_lowmem_reserve_ratio,
1416 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1417 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001418 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 },
1420 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001421 .procname = "drop_caches",
1422 .data = &sysctl_drop_caches,
1423 .maxlen = sizeof(int),
1424 .mode = 0644,
1425 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001426 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001427 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001428 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001429#ifdef CONFIG_COMPACTION
1430 {
1431 .procname = "compact_memory",
1432 .data = &sysctl_compact_memory,
1433 .maxlen = sizeof(int),
1434 .mode = 0200,
1435 .proc_handler = sysctl_compaction_handler,
1436 },
Mel Gorman5e771902010-05-24 14:32:31 -07001437 {
1438 .procname = "extfrag_threshold",
1439 .data = &sysctl_extfrag_threshold,
1440 .maxlen = sizeof(int),
1441 .mode = 0644,
1442 .proc_handler = sysctl_extfrag_handler,
1443 .extra1 = &min_extfrag_threshold,
1444 .extra2 = &max_extfrag_threshold,
1445 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001446 {
1447 .procname = "compact_unevictable_allowed",
1448 .data = &sysctl_compact_unevictable_allowed,
1449 .maxlen = sizeof(int),
1450 .mode = 0644,
1451 .proc_handler = proc_dointvec,
1452 .extra1 = &zero,
1453 .extra2 = &one,
1454 },
Mel Gorman5e771902010-05-24 14:32:31 -07001455
Mel Gorman76ab0f52010-05-24 14:32:28 -07001456#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001457 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 .procname = "min_free_kbytes",
1459 .data = &min_free_kbytes,
1460 .maxlen = sizeof(min_free_kbytes),
1461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001462 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 .extra1 = &zero,
1464 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001465 {
Mel Gorman1c308442018-12-28 00:35:52 -08001466 .procname = "watermark_boost_factor",
1467 .data = &watermark_boost_factor,
1468 .maxlen = sizeof(watermark_boost_factor),
1469 .mode = 0644,
1470 .proc_handler = watermark_boost_factor_sysctl_handler,
1471 .extra1 = &zero,
1472 },
1473 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001474 .procname = "watermark_scale_factor",
1475 .data = &watermark_scale_factor,
1476 .maxlen = sizeof(watermark_scale_factor),
1477 .mode = 0644,
1478 .proc_handler = watermark_scale_factor_sysctl_handler,
1479 .extra1 = &one,
1480 .extra2 = &one_thousand,
1481 },
1482 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001483 .procname = "percpu_pagelist_fraction",
1484 .data = &percpu_pagelist_fraction,
1485 .maxlen = sizeof(percpu_pagelist_fraction),
1486 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001487 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001488 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001489 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490#ifdef CONFIG_MMU
1491 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 .procname = "max_map_count",
1493 .data = &sysctl_max_map_count,
1494 .maxlen = sizeof(sysctl_max_map_count),
1495 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001496 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001497 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001499#else
1500 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001501 .procname = "nr_trim_pages",
1502 .data = &sysctl_nr_trim_pages,
1503 .maxlen = sizeof(sysctl_nr_trim_pages),
1504 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001505 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001506 .extra1 = &zero,
1507 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508#endif
1509 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 .procname = "laptop_mode",
1511 .data = &laptop_mode,
1512 .maxlen = sizeof(laptop_mode),
1513 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001514 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 },
1516 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 .procname = "block_dump",
1518 .data = &block_dump,
1519 .maxlen = sizeof(block_dump),
1520 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001521 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 .extra1 = &zero,
1523 },
1524 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 .procname = "vfs_cache_pressure",
1526 .data = &sysctl_vfs_cache_pressure,
1527 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1528 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001529 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 .extra1 = &zero,
1531 },
1532#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1533 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 .procname = "legacy_va_layout",
1535 .data = &sysctl_legacy_va_layout,
1536 .maxlen = sizeof(sysctl_legacy_va_layout),
1537 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001538 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 .extra1 = &zero,
1540 },
1541#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001542#ifdef CONFIG_NUMA
1543 {
Christoph Lameter17436602006-01-18 17:42:32 -08001544 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001545 .data = &node_reclaim_mode,
1546 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001547 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001548 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001549 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001550 },
Christoph Lameter96146342006-07-03 00:24:13 -07001551 {
Christoph Lameter96146342006-07-03 00:24:13 -07001552 .procname = "min_unmapped_ratio",
1553 .data = &sysctl_min_unmapped_ratio,
1554 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001556 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001557 .extra1 = &zero,
1558 .extra2 = &one_hundred,
1559 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001560 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001561 .procname = "min_slab_ratio",
1562 .data = &sysctl_min_slab_ratio,
1563 .maxlen = sizeof(sysctl_min_slab_ratio),
1564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001565 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001566 .extra1 = &zero,
1567 .extra2 = &one_hundred,
1568 },
Christoph Lameter17436602006-01-18 17:42:32 -08001569#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001570#ifdef CONFIG_SMP
1571 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001572 .procname = "stat_interval",
1573 .data = &sysctl_stat_interval,
1574 .maxlen = sizeof(sysctl_stat_interval),
1575 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001576 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001577 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001578 {
1579 .procname = "stat_refresh",
1580 .data = NULL,
1581 .maxlen = 0,
1582 .mode = 0600,
1583 .proc_handler = vmstat_refresh,
1584 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001585#endif
David Howells6e141542009-12-15 19:27:45 +00001586#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001587 {
Eric Parised032182007-06-28 15:55:21 -04001588 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001589 .data = &dac_mmap_min_addr,
1590 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001592 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001593 },
David Howells6e141542009-12-15 19:27:45 +00001594#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001595#ifdef CONFIG_NUMA
1596 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001597 .procname = "numa_zonelist_order",
1598 .data = &numa_zonelist_order,
1599 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1600 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001601 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001602 },
1603#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001604#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001605 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001606 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001607 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001608#ifdef CONFIG_X86_32
1609 .data = &vdso32_enabled,
1610 .maxlen = sizeof(vdso32_enabled),
1611#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001612 .data = &vdso_enabled,
1613 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001614#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001615 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001616 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001617 .extra1 = &zero,
1618 },
1619#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001620#ifdef CONFIG_HIGHMEM
1621 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001622 .procname = "highmem_is_dirtyable",
1623 .data = &vm_highmem_is_dirtyable,
1624 .maxlen = sizeof(vm_highmem_is_dirtyable),
1625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001626 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001627 .extra1 = &zero,
1628 .extra2 = &one,
1629 },
1630#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001631#ifdef CONFIG_MEMORY_FAILURE
1632 {
Andi Kleen6a460792009-09-16 11:50:15 +02001633 .procname = "memory_failure_early_kill",
1634 .data = &sysctl_memory_failure_early_kill,
1635 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1636 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001637 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001638 .extra1 = &zero,
1639 .extra2 = &one,
1640 },
1641 {
Andi Kleen6a460792009-09-16 11:50:15 +02001642 .procname = "memory_failure_recovery",
1643 .data = &sysctl_memory_failure_recovery,
1644 .maxlen = sizeof(sysctl_memory_failure_recovery),
1645 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001646 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001647 .extra1 = &zero,
1648 .extra2 = &one,
1649 },
1650#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001651 {
1652 .procname = "user_reserve_kbytes",
1653 .data = &sysctl_user_reserve_kbytes,
1654 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1655 .mode = 0644,
1656 .proc_handler = proc_doulongvec_minmax,
1657 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001658 {
1659 .procname = "admin_reserve_kbytes",
1660 .data = &sysctl_admin_reserve_kbytes,
1661 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1662 .mode = 0644,
1663 .proc_handler = proc_doulongvec_minmax,
1664 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001665#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1666 {
1667 .procname = "mmap_rnd_bits",
1668 .data = &mmap_rnd_bits,
1669 .maxlen = sizeof(mmap_rnd_bits),
1670 .mode = 0600,
1671 .proc_handler = proc_dointvec_minmax,
1672 .extra1 = (void *)&mmap_rnd_bits_min,
1673 .extra2 = (void *)&mmap_rnd_bits_max,
1674 },
1675#endif
1676#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1677 {
1678 .procname = "mmap_rnd_compat_bits",
1679 .data = &mmap_rnd_compat_bits,
1680 .maxlen = sizeof(mmap_rnd_compat_bits),
1681 .mode = 0600,
1682 .proc_handler = proc_dointvec_minmax,
1683 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1684 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1685 },
1686#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001687 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688};
1689
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001690static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 .procname = "inode-nr",
1693 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001694 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001696 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 },
1698 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 .procname = "inode-state",
1700 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001701 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001703 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 },
1705 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 .procname = "file-nr",
1707 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001708 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001710 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 },
1712 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 .procname = "file-max",
1714 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001715 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001717 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 },
1719 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001720 .procname = "nr_open",
1721 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001722 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001723 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001724 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001725 .extra1 = &sysctl_nr_open_min,
1726 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001727 },
1728 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 .procname = "dentry-state",
1730 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001731 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001733 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 },
1735 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 .procname = "overflowuid",
1737 .data = &fs_overflowuid,
1738 .maxlen = sizeof(int),
1739 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001740 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 .extra1 = &minolduid,
1742 .extra2 = &maxolduid,
1743 },
1744 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 .procname = "overflowgid",
1746 .data = &fs_overflowgid,
1747 .maxlen = sizeof(int),
1748 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001749 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 .extra1 = &minolduid,
1751 .extra2 = &maxolduid,
1752 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001753#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 .procname = "leases-enable",
1756 .data = &leases_enable,
1757 .maxlen = sizeof(int),
1758 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001759 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001761#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762#ifdef CONFIG_DNOTIFY
1763 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 .procname = "dir-notify-enable",
1765 .data = &dir_notify_enable,
1766 .maxlen = sizeof(int),
1767 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001768 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 },
1770#endif
1771#ifdef CONFIG_MMU
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 = "lease-break-time",
1775 .data = &lease_break_time,
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
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001781#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 .procname = "aio-nr",
1784 .data = &aio_nr,
1785 .maxlen = sizeof(aio_nr),
1786 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001787 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 },
1789 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 .procname = "aio-max-nr",
1791 .data = &aio_max_nr,
1792 .maxlen = sizeof(aio_max_nr),
1793 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001794 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001796#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001797#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001798 {
Robert Love0399cb02005-07-13 12:38:18 -04001799 .procname = "inotify",
1800 .mode = 0555,
1801 .child = inotify_table,
1802 },
1803#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001804#ifdef CONFIG_EPOLL
1805 {
1806 .procname = "epoll",
1807 .mode = 0555,
1808 .child = epoll_table,
1809 },
1810#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001812 {
Kees Cook800179c2012-07-25 17:29:07 -07001813 .procname = "protected_symlinks",
1814 .data = &sysctl_protected_symlinks,
1815 .maxlen = sizeof(int),
1816 .mode = 0600,
1817 .proc_handler = proc_dointvec_minmax,
1818 .extra1 = &zero,
1819 .extra2 = &one,
1820 },
1821 {
1822 .procname = "protected_hardlinks",
1823 .data = &sysctl_protected_hardlinks,
1824 .maxlen = sizeof(int),
1825 .mode = 0600,
1826 .proc_handler = proc_dointvec_minmax,
1827 .extra1 = &zero,
1828 .extra2 = &one,
1829 },
1830 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001831 .procname = "protected_fifos",
1832 .data = &sysctl_protected_fifos,
1833 .maxlen = sizeof(int),
1834 .mode = 0600,
1835 .proc_handler = proc_dointvec_minmax,
1836 .extra1 = &zero,
1837 .extra2 = &two,
1838 },
1839 {
1840 .procname = "protected_regular",
1841 .data = &sysctl_protected_regular,
1842 .maxlen = sizeof(int),
1843 .mode = 0600,
1844 .proc_handler = proc_dointvec_minmax,
1845 .extra1 = &zero,
1846 .extra2 = &two,
1847 },
1848 {
Alan Coxd6e71142005-06-23 00:09:43 -07001849 .procname = "suid_dumpable",
1850 .data = &suid_dumpable,
1851 .maxlen = sizeof(int),
1852 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001853 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001854 .extra1 = &zero,
1855 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001856 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001857#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1858 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001859 .procname = "binfmt_misc",
1860 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001861 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001862 },
1863#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001864 {
Jens Axboeff9da692010-06-03 14:54:39 +02001865 .procname = "pipe-max-size",
1866 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001867 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001868 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001869 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001870 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001871 {
1872 .procname = "pipe-user-pages-hard",
1873 .data = &pipe_user_pages_hard,
1874 .maxlen = sizeof(pipe_user_pages_hard),
1875 .mode = 0644,
1876 .proc_handler = proc_doulongvec_minmax,
1877 },
1878 {
1879 .procname = "pipe-user-pages-soft",
1880 .data = &pipe_user_pages_soft,
1881 .maxlen = sizeof(pipe_user_pages_soft),
1882 .mode = 0644,
1883 .proc_handler = proc_doulongvec_minmax,
1884 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001885 {
1886 .procname = "mount-max",
1887 .data = &sysctl_mount_max,
1888 .maxlen = sizeof(unsigned int),
1889 .mode = 0644,
1890 .proc_handler = proc_dointvec_minmax,
1891 .extra1 = &one,
1892 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001893 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894};
1895
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001896static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001897#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001898 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001899 .procname = "exception-trace",
1900 .data = &show_unhandled_signals,
1901 .maxlen = sizeof(int),
1902 .mode = 0644,
1903 .proc_handler = proc_dointvec
1904 },
1905#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001906#if defined(CONFIG_OPTPROBES)
1907 {
1908 .procname = "kprobes-optimization",
1909 .data = &sysctl_kprobes_optimization,
1910 .maxlen = sizeof(int),
1911 .mode = 0644,
1912 .proc_handler = proc_kprobes_optimization_handler,
1913 .extra1 = &zero,
1914 .extra2 = &one,
1915 },
1916#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001917 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918};
1919
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001920static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001921 { }
Robert Love0eeca282005-07-12 17:06:03 -04001922};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001924int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001925{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001926 struct ctl_table_header *hdr;
1927
1928 hdr = register_sysctl_table(sysctl_base_table);
1929 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001930 return 0;
1931}
1932
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001933#endif /* CONFIG_SYSCTL */
1934
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935/*
1936 * /proc/sys support
1937 */
1938
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001939#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Kees Cookf8808302014-06-06 14:37:17 -07001941static int _proc_do_string(char *data, int maxlen, int write,
1942 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001943 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001944{
1945 size_t len;
1946 char __user *p;
1947 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001948
1949 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001950 *lenp = 0;
1951 return 0;
1952 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001953
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001954 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001955 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1956 /* Only continue writes not past the end of buffer. */
1957 len = strlen(data);
1958 if (len > maxlen - 1)
1959 len = maxlen - 1;
1960
1961 if (*ppos > len)
1962 return 0;
1963 len = *ppos;
1964 } else {
1965 /* Start writing from beginning of buffer. */
1966 len = 0;
1967 }
1968
Kees Cook2ca9bb42014-06-06 14:37:18 -07001969 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001970 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001971 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001972 if (get_user(c, p++))
1973 return -EFAULT;
1974 if (c == 0 || c == '\n')
1975 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07001976 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001977 }
Kees Cookf8808302014-06-06 14:37:17 -07001978 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001979 } else {
1980 len = strlen(data);
1981 if (len > maxlen)
1982 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001983
1984 if (*ppos > len) {
1985 *lenp = 0;
1986 return 0;
1987 }
1988
1989 data += *ppos;
1990 len -= *ppos;
1991
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001992 if (len > *lenp)
1993 len = *lenp;
1994 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07001995 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001996 return -EFAULT;
1997 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07001998 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001999 return -EFAULT;
2000 len++;
2001 }
2002 *lenp = len;
2003 *ppos += len;
2004 }
2005 return 0;
2006}
2007
Kees Cookf4aacea2014-06-06 14:37:19 -07002008static void warn_sysctl_write(struct ctl_table *table)
2009{
2010 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2011 "This will not be supported in the future. To silence this\n"
2012 "warning, set kernel.sysctl_writes_strict = -1\n",
2013 current->comm, table->procname);
2014}
2015
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002017 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002018 * @ppos: file position
2019 * @table: the sysctl table
2020 *
2021 * Returns true if the first position is non-zero and the sysctl_writes_strict
2022 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002023 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002024 */
2025static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2026 struct ctl_table *table)
2027{
2028 if (!*ppos)
2029 return false;
2030
2031 switch (sysctl_writes_strict) {
2032 case SYSCTL_WRITES_STRICT:
2033 return true;
2034 case SYSCTL_WRITES_WARN:
2035 warn_sysctl_write(table);
2036 return false;
2037 default:
2038 return false;
2039 }
2040}
2041
2042/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 * proc_dostring - read a string sysctl
2044 * @table: the sysctl table
2045 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 * @buffer: the user buffer
2047 * @lenp: the size of the user buffer
2048 * @ppos: file position
2049 *
2050 * Reads/writes a string from/to the user buffer. If the kernel
2051 * buffer provided is not large enough to hold the string, the
2052 * string is truncated. The copied string is %NULL-terminated.
2053 * If the string is being read by the user process, it is copied
2054 * and a newline '\n' is added. It is truncated if the buffer is
2055 * not large enough.
2056 *
2057 * Returns 0 on success.
2058 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002059int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 void __user *buffer, size_t *lenp, loff_t *ppos)
2061{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002062 if (write)
2063 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002064
Kees Cookf8808302014-06-06 14:37:17 -07002065 return _proc_do_string((char *)(table->data), table->maxlen, write,
2066 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067}
2068
Amerigo Wang00b7c332010-05-05 00:26:45 +00002069static size_t proc_skip_spaces(char **buf)
2070{
2071 size_t ret;
2072 char *tmp = skip_spaces(*buf);
2073 ret = tmp - *buf;
2074 *buf = tmp;
2075 return ret;
2076}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002078static void proc_skip_char(char **buf, size_t *size, const char v)
2079{
2080 while (*size) {
2081 if (**buf != v)
2082 break;
2083 (*size)--;
2084 (*buf)++;
2085 }
2086}
2087
Amerigo Wang00b7c332010-05-05 00:26:45 +00002088#define TMPBUFLEN 22
2089/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002090 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002091 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002092 * @buf: a kernel buffer
2093 * @size: size of the kernel buffer
2094 * @val: this is where the number will be stored
2095 * @neg: set to %TRUE if number is negative
2096 * @perm_tr: a vector which contains the allowed trailers
2097 * @perm_tr_len: size of the perm_tr vector
2098 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002099 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002100 * In case of success %0 is returned and @buf and @size are updated with
2101 * the amount of bytes read. If @tr is non-NULL and a trailing
2102 * character exists (size is non-zero after returning from this
2103 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002104 */
2105static int proc_get_long(char **buf, size_t *size,
2106 unsigned long *val, bool *neg,
2107 const char *perm_tr, unsigned perm_tr_len, char *tr)
2108{
2109 int len;
2110 char *p, tmp[TMPBUFLEN];
2111
2112 if (!*size)
2113 return -EINVAL;
2114
2115 len = *size;
2116 if (len > TMPBUFLEN - 1)
2117 len = TMPBUFLEN - 1;
2118
2119 memcpy(tmp, *buf, len);
2120
2121 tmp[len] = 0;
2122 p = tmp;
2123 if (*p == '-' && *size > 1) {
2124 *neg = true;
2125 p++;
2126 } else
2127 *neg = false;
2128 if (!isdigit(*p))
2129 return -EINVAL;
2130
2131 *val = simple_strtoul(p, &p, 0);
2132
2133 len = p - tmp;
2134
2135 /* We don't know if the next char is whitespace thus we may accept
2136 * invalid integers (e.g. 1234...a) or two integers instead of one
2137 * (e.g. 123...1). So lets not allow such large numbers. */
2138 if (len == TMPBUFLEN - 1)
2139 return -EINVAL;
2140
2141 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2142 return -EINVAL;
2143
2144 if (tr && (len < *size))
2145 *tr = *p;
2146
2147 *buf += len;
2148 *size -= len;
2149
2150 return 0;
2151}
2152
2153/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002154 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002155 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002156 * @buf: the user buffer
2157 * @size: the size of the user buffer
2158 * @val: the integer to be converted
2159 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002160 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002161 * In case of success %0 is returned and @buf and @size are updated with
2162 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002163 */
2164static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2165 bool neg)
2166{
2167 int len;
2168 char tmp[TMPBUFLEN], *p = tmp;
2169
2170 sprintf(p, "%s%lu", neg ? "-" : "", val);
2171 len = strlen(tmp);
2172 if (len > *size)
2173 len = *size;
2174 if (copy_to_user(*buf, tmp, len))
2175 return -EFAULT;
2176 *size -= len;
2177 *buf += len;
2178 return 0;
2179}
2180#undef TMPBUFLEN
2181
2182static int proc_put_char(void __user **buf, size_t *size, char c)
2183{
2184 if (*size) {
2185 char __user **buffer = (char __user **)buf;
2186 if (put_user(c, *buffer))
2187 return -EFAULT;
2188 (*size)--, (*buffer)++;
2189 *buf = *buffer;
2190 }
2191 return 0;
2192}
2193
2194static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 int *valp,
2196 int write, void *data)
2197{
2198 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002199 if (*negp) {
2200 if (*lvalp > (unsigned long) INT_MAX + 1)
2201 return -EINVAL;
2202 *valp = -*lvalp;
2203 } else {
2204 if (*lvalp > (unsigned long) INT_MAX)
2205 return -EINVAL;
2206 *valp = *lvalp;
2207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 } else {
2209 int val = *valp;
2210 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002211 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002212 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002214 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 *lvalp = (unsigned long)val;
2216 }
2217 }
2218 return 0;
2219}
2220
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002221static int do_proc_douintvec_conv(unsigned long *lvalp,
2222 unsigned int *valp,
2223 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002224{
2225 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002226 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002227 return -EINVAL;
2228 *valp = *lvalp;
2229 } else {
2230 unsigned int val = *valp;
2231 *lvalp = (unsigned long)val;
2232 }
2233 return 0;
2234}
2235
Amerigo Wang00b7c332010-05-05 00:26:45 +00002236static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2237
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002238static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002239 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002240 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002241 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 int write, void *data),
2243 void *data)
2244{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002245 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002246 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002247 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
Amerigo Wang00b7c332010-05-05 00:26:45 +00002249 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 *lenp = 0;
2251 return 0;
2252 }
2253
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002254 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 vleft = table->maxlen / sizeof(*i);
2256 left = *lenp;
2257
2258 if (!conv)
2259 conv = do_proc_dointvec_conv;
2260
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002262 if (proc_first_pos_non_zero_ignore(ppos, table))
2263 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002264
Amerigo Wang00b7c332010-05-05 00:26:45 +00002265 if (left > PAGE_SIZE - 1)
2266 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002267 p = kbuf = memdup_user_nul(buffer, left);
2268 if (IS_ERR(kbuf))
2269 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002270 }
2271
2272 for (; left && vleft--; i++, first=0) {
2273 unsigned long lval;
2274 bool neg;
2275
2276 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002277 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002278
J. R. Okajima563b0462010-05-25 16:10:14 -07002279 if (!left)
2280 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002281 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002282 proc_wspace_sep,
2283 sizeof(proc_wspace_sep), NULL);
2284 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002286 if (conv(&neg, &lval, i, 1, data)) {
2287 err = -EINVAL;
2288 break;
2289 }
2290 } else {
2291 if (conv(&neg, &lval, i, 0, data)) {
2292 err = -EINVAL;
2293 break;
2294 }
2295 if (!first)
2296 err = proc_put_char(&buffer, &left, '\t');
2297 if (err)
2298 break;
2299 err = proc_put_long(&buffer, &left, lval, neg);
2300 if (err)
2301 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 }
2303 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002304
2305 if (!write && !first && left && !err)
2306 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002307 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002308 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002309 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002310 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002311 if (first)
2312 return err ? : -EINVAL;
2313 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002315out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002317 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318}
2319
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002320static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002321 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002322 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002323 int write, void *data),
2324 void *data)
2325{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002326 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002327 buffer, lenp, ppos, conv, data);
2328}
2329
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002330static int do_proc_douintvec_w(unsigned int *tbl_data,
2331 struct ctl_table *table,
2332 void __user *buffer,
2333 size_t *lenp, loff_t *ppos,
2334 int (*conv)(unsigned long *lvalp,
2335 unsigned int *valp,
2336 int write, void *data),
2337 void *data)
2338{
2339 unsigned long lval;
2340 int err = 0;
2341 size_t left;
2342 bool neg;
2343 char *kbuf = NULL, *p;
2344
2345 left = *lenp;
2346
2347 if (proc_first_pos_non_zero_ignore(ppos, table))
2348 goto bail_early;
2349
2350 if (left > PAGE_SIZE - 1)
2351 left = PAGE_SIZE - 1;
2352
2353 p = kbuf = memdup_user_nul(buffer, left);
2354 if (IS_ERR(kbuf))
2355 return -EINVAL;
2356
2357 left -= proc_skip_spaces(&p);
2358 if (!left) {
2359 err = -EINVAL;
2360 goto out_free;
2361 }
2362
2363 err = proc_get_long(&p, &left, &lval, &neg,
2364 proc_wspace_sep,
2365 sizeof(proc_wspace_sep), NULL);
2366 if (err || neg) {
2367 err = -EINVAL;
2368 goto out_free;
2369 }
2370
2371 if (conv(&lval, tbl_data, 1, data)) {
2372 err = -EINVAL;
2373 goto out_free;
2374 }
2375
2376 if (!err && left)
2377 left -= proc_skip_spaces(&p);
2378
2379out_free:
2380 kfree(kbuf);
2381 if (err)
2382 return -EINVAL;
2383
2384 return 0;
2385
2386 /* This is in keeping with old __do_proc_dointvec() */
2387bail_early:
2388 *ppos += *lenp;
2389 return err;
2390}
2391
2392static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2393 size_t *lenp, loff_t *ppos,
2394 int (*conv)(unsigned long *lvalp,
2395 unsigned int *valp,
2396 int write, void *data),
2397 void *data)
2398{
2399 unsigned long lval;
2400 int err = 0;
2401 size_t left;
2402
2403 left = *lenp;
2404
2405 if (conv(&lval, tbl_data, 0, data)) {
2406 err = -EINVAL;
2407 goto out;
2408 }
2409
2410 err = proc_put_long(&buffer, &left, lval, false);
2411 if (err || !left)
2412 goto out;
2413
2414 err = proc_put_char(&buffer, &left, '\n');
2415
2416out:
2417 *lenp -= left;
2418 *ppos += *lenp;
2419
2420 return err;
2421}
2422
2423static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2424 int write, void __user *buffer,
2425 size_t *lenp, loff_t *ppos,
2426 int (*conv)(unsigned long *lvalp,
2427 unsigned int *valp,
2428 int write, void *data),
2429 void *data)
2430{
2431 unsigned int *i, vleft;
2432
2433 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2434 *lenp = 0;
2435 return 0;
2436 }
2437
2438 i = (unsigned int *) tbl_data;
2439 vleft = table->maxlen / sizeof(*i);
2440
2441 /*
2442 * Arrays are not supported, keep this simple. *Do not* add
2443 * support for them.
2444 */
2445 if (vleft != 1) {
2446 *lenp = 0;
2447 return -EINVAL;
2448 }
2449
2450 if (!conv)
2451 conv = do_proc_douintvec_conv;
2452
2453 if (write)
2454 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2455 conv, data);
2456 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2457}
2458
2459static int do_proc_douintvec(struct ctl_table *table, int write,
2460 void __user *buffer, size_t *lenp, loff_t *ppos,
2461 int (*conv)(unsigned long *lvalp,
2462 unsigned int *valp,
2463 int write, void *data),
2464 void *data)
2465{
2466 return __do_proc_douintvec(table->data, table, write,
2467 buffer, lenp, ppos, conv, data);
2468}
2469
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470/**
2471 * proc_dointvec - read a vector of integers
2472 * @table: the sysctl table
2473 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 * @buffer: the user buffer
2475 * @lenp: the size of the user buffer
2476 * @ppos: file position
2477 *
2478 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2479 * values from/to the user buffer, treated as an ASCII string.
2480 *
2481 * Returns 0 on success.
2482 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002483int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 void __user *buffer, size_t *lenp, loff_t *ppos)
2485{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002486 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2487}
2488
2489/**
2490 * proc_douintvec - read a vector of unsigned integers
2491 * @table: the sysctl table
2492 * @write: %TRUE if this is a write to the sysctl file
2493 * @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) unsigned integer
2498 * values from/to the user buffer, treated as an ASCII string.
2499 *
2500 * Returns 0 on success.
2501 */
2502int proc_douintvec(struct ctl_table *table, int write,
2503 void __user *buffer, size_t *lenp, loff_t *ppos)
2504{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002505 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2506 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507}
2508
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002509/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002510 * Taint values can only be increased
2511 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002512 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002513static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002514 void __user *buffer, size_t *lenp, loff_t *ppos)
2515{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002516 struct ctl_table t;
2517 unsigned long tmptaint = get_taint();
2518 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002519
Bastian Blank91fcd412007-04-23 14:41:14 -07002520 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002521 return -EPERM;
2522
Andi Kleen25ddbb12008-10-15 22:01:41 -07002523 t = *table;
2524 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002525 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002526 if (err < 0)
2527 return err;
2528
2529 if (write) {
2530 /*
2531 * Poor man's atomic or. Not worth adding a primitive
2532 * to everyone's atomic.h for this
2533 */
2534 int i;
2535 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2536 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302537 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002538 }
2539 }
2540
2541 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002542}
2543
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002544#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002545static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002546 void __user *buffer, size_t *lenp, loff_t *ppos)
2547{
2548 if (write && !capable(CAP_SYS_ADMIN))
2549 return -EPERM;
2550
2551 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2552}
2553#endif
2554
Waiman Long24704f32018-04-10 16:35:38 -07002555/**
2556 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2557 * @min: pointer to minimum allowable value
2558 * @max: pointer to maximum allowable value
2559 *
2560 * The do_proc_dointvec_minmax_conv_param structure provides the
2561 * minimum and maximum values for doing range checking for those sysctl
2562 * parameters that use the proc_dointvec_minmax() handler.
2563 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564struct do_proc_dointvec_minmax_conv_param {
2565 int *min;
2566 int *max;
2567};
2568
Amerigo Wang00b7c332010-05-05 00:26:45 +00002569static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2570 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 int write, void *data)
2572{
2573 struct do_proc_dointvec_minmax_conv_param *param = data;
2574 if (write) {
2575 int val = *negp ? -*lvalp : *lvalp;
2576 if ((param->min && *param->min > val) ||
2577 (param->max && *param->max < val))
2578 return -EINVAL;
2579 *valp = val;
2580 } else {
2581 int val = *valp;
2582 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002583 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002584 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002586 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 *lvalp = (unsigned long)val;
2588 }
2589 }
2590 return 0;
2591}
2592
2593/**
2594 * proc_dointvec_minmax - read a vector of integers with min/max values
2595 * @table: the sysctl table
2596 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 * @buffer: the user buffer
2598 * @lenp: the size of the user buffer
2599 * @ppos: file position
2600 *
2601 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2602 * values from/to the user buffer, treated as an ASCII string.
2603 *
2604 * This routine will ensure the values are within the range specified by
2605 * table->extra1 (min) and table->extra2 (max).
2606 *
Waiman Long24704f32018-04-10 16:35:38 -07002607 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002609int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 void __user *buffer, size_t *lenp, loff_t *ppos)
2611{
2612 struct do_proc_dointvec_minmax_conv_param param = {
2613 .min = (int *) table->extra1,
2614 .max = (int *) table->extra2,
2615 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002616 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 do_proc_dointvec_minmax_conv, &param);
2618}
2619
Waiman Long24704f32018-04-10 16:35:38 -07002620/**
2621 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2622 * @min: pointer to minimum allowable value
2623 * @max: pointer to maximum allowable value
2624 *
2625 * The do_proc_douintvec_minmax_conv_param structure provides the
2626 * minimum and maximum values for doing range checking for those sysctl
2627 * parameters that use the proc_douintvec_minmax() handler.
2628 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002629struct do_proc_douintvec_minmax_conv_param {
2630 unsigned int *min;
2631 unsigned int *max;
2632};
2633
2634static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2635 unsigned int *valp,
2636 int write, void *data)
2637{
2638 struct do_proc_douintvec_minmax_conv_param *param = data;
2639
2640 if (write) {
2641 unsigned int val = *lvalp;
2642
Joe Lawrencefb910c42017-11-17 15:29:28 -08002643 if (*lvalp > UINT_MAX)
2644 return -EINVAL;
2645
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002646 if ((param->min && *param->min > val) ||
2647 (param->max && *param->max < val))
2648 return -ERANGE;
2649
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002650 *valp = val;
2651 } else {
2652 unsigned int val = *valp;
2653 *lvalp = (unsigned long) val;
2654 }
2655
2656 return 0;
2657}
2658
2659/**
2660 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2661 * @table: the sysctl table
2662 * @write: %TRUE if this is a write to the sysctl file
2663 * @buffer: the user buffer
2664 * @lenp: the size of the user buffer
2665 * @ppos: file position
2666 *
2667 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2668 * values from/to the user buffer, treated as an ASCII string. Negative
2669 * strings are not allowed.
2670 *
2671 * This routine will ensure the values are within the range specified by
2672 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2673 * check for UINT_MAX to avoid having to support wrap around uses from
2674 * userspace.
2675 *
Waiman Long24704f32018-04-10 16:35:38 -07002676 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002677 */
2678int proc_douintvec_minmax(struct ctl_table *table, int write,
2679 void __user *buffer, size_t *lenp, loff_t *ppos)
2680{
2681 struct do_proc_douintvec_minmax_conv_param param = {
2682 .min = (unsigned int *) table->extra1,
2683 .max = (unsigned int *) table->extra2,
2684 };
2685 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2686 do_proc_douintvec_minmax_conv, &param);
2687}
2688
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002689static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2690 unsigned int *valp,
2691 int write, void *data)
2692{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002693 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002694 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002695
Joe Lawrencefb910c42017-11-17 15:29:28 -08002696 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002697 if (val == 0)
2698 return -EINVAL;
2699
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002700 *valp = val;
2701 } else {
2702 unsigned int val = *valp;
2703 *lvalp = (unsigned long) val;
2704 }
2705
2706 return 0;
2707}
2708
Eric Biggers319e0a22018-02-06 15:41:49 -08002709static int proc_dopipe_max_size(struct ctl_table *table, int write,
2710 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002711{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002712 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002713 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002714}
2715
Kees Cook54b50192012-07-30 14:39:18 -07002716static void validate_coredump_safety(void)
2717{
Alex Kelly046d6622012-10-04 17:15:23 -07002718#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002719 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002720 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002721 printk(KERN_WARNING
2722"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2723"Pipe handler or fully qualified core dump path required.\n"
2724"Set kernel.core_pattern before fs.suid_dumpable.\n"
2725 );
Kees Cook54b50192012-07-30 14:39:18 -07002726 }
Alex Kelly046d6622012-10-04 17:15:23 -07002727#endif
Kees Cook54b50192012-07-30 14:39:18 -07002728}
2729
2730static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2731 void __user *buffer, size_t *lenp, loff_t *ppos)
2732{
2733 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2734 if (!error)
2735 validate_coredump_safety();
2736 return error;
2737}
2738
Alex Kelly046d6622012-10-04 17:15:23 -07002739#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002740static int proc_dostring_coredump(struct ctl_table *table, int write,
2741 void __user *buffer, size_t *lenp, loff_t *ppos)
2742{
2743 int error = proc_dostring(table, write, buffer, lenp, ppos);
2744 if (!error)
2745 validate_coredump_safety();
2746 return error;
2747}
Alex Kelly046d6622012-10-04 17:15:23 -07002748#endif
Kees Cook54b50192012-07-30 14:39:18 -07002749
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002750static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 void __user *buffer,
2752 size_t *lenp, loff_t *ppos,
2753 unsigned long convmul,
2754 unsigned long convdiv)
2755{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002756 unsigned long *i, *min, *max;
2757 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002758 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002759 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002760
2761 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 *lenp = 0;
2763 return 0;
2764 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002765
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002766 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 min = (unsigned long *) table->extra1;
2768 max = (unsigned long *) table->extra2;
2769 vleft = table->maxlen / sizeof(unsigned long);
2770 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002771
2772 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002773 if (proc_first_pos_non_zero_ignore(ppos, table))
2774 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002775
Amerigo Wang00b7c332010-05-05 00:26:45 +00002776 if (left > PAGE_SIZE - 1)
2777 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002778 p = kbuf = memdup_user_nul(buffer, left);
2779 if (IS_ERR(kbuf))
2780 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002781 }
2782
Eric Dumazet27b3d802010-10-07 12:59:29 -07002783 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002784 unsigned long val;
2785
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002787 bool neg;
2788
Al Viro70f6cbb2015-12-24 00:13:10 -05002789 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002790
Al Viro70f6cbb2015-12-24 00:13:10 -05002791 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002792 proc_wspace_sep,
2793 sizeof(proc_wspace_sep), NULL);
2794 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 break;
2796 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002798 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 if ((min && val < *min) || (max && val > *max))
2800 continue;
2801 *i = val;
2802 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002803 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002804 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002805 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002806 if (err)
2807 break;
2808 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002809 err = proc_put_long(&buffer, &left, val, false);
2810 if (err)
2811 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 }
2813 }
2814
Amerigo Wang00b7c332010-05-05 00:26:45 +00002815 if (!write && !first && left && !err)
2816 err = proc_put_char(&buffer, &left, '\n');
2817 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002818 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002820 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002821 if (first)
2822 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002825out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002827 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828}
2829
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002830static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002831 void __user *buffer,
2832 size_t *lenp, loff_t *ppos,
2833 unsigned long convmul,
2834 unsigned long convdiv)
2835{
2836 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002837 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002838}
2839
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840/**
2841 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2842 * @table: the sysctl table
2843 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 * @buffer: the user buffer
2845 * @lenp: the size of the user buffer
2846 * @ppos: file position
2847 *
2848 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2849 * values from/to the user buffer, treated as an ASCII string.
2850 *
2851 * This routine will ensure the values are within the range specified by
2852 * table->extra1 (min) and table->extra2 (max).
2853 *
2854 * Returns 0 on success.
2855 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002856int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 void __user *buffer, size_t *lenp, loff_t *ppos)
2858{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002859 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860}
2861
2862/**
2863 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2864 * @table: the sysctl table
2865 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 * @buffer: the user buffer
2867 * @lenp: the size of the user buffer
2868 * @ppos: file position
2869 *
2870 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2871 * values from/to the user buffer, treated as an ASCII string. The values
2872 * are treated as milliseconds, and converted to jiffies when they are stored.
2873 *
2874 * This routine will ensure the values are within the range specified by
2875 * table->extra1 (min) and table->extra2 (max).
2876 *
2877 * Returns 0 on success.
2878 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002879int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 void __user *buffer,
2881 size_t *lenp, loff_t *ppos)
2882{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002883 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 lenp, ppos, HZ, 1000l);
2885}
2886
2887
Amerigo Wang00b7c332010-05-05 00:26:45 +00002888static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 int *valp,
2890 int write, void *data)
2891{
2892 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002893 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002894 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2896 } else {
2897 int val = *valp;
2898 unsigned long lval;
2899 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002900 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002901 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002903 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 lval = (unsigned long)val;
2905 }
2906 *lvalp = lval / HZ;
2907 }
2908 return 0;
2909}
2910
Amerigo Wang00b7c332010-05-05 00:26:45 +00002911static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 int *valp,
2913 int write, void *data)
2914{
2915 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002916 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2917 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2919 } else {
2920 int val = *valp;
2921 unsigned long lval;
2922 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002923 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002924 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002926 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 lval = (unsigned long)val;
2928 }
2929 *lvalp = jiffies_to_clock_t(lval);
2930 }
2931 return 0;
2932}
2933
Amerigo Wang00b7c332010-05-05 00:26:45 +00002934static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 int *valp,
2936 int write, void *data)
2937{
2938 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02002939 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2940
2941 if (jif > INT_MAX)
2942 return 1;
2943 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 } else {
2945 int val = *valp;
2946 unsigned long lval;
2947 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002948 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002949 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002951 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 lval = (unsigned long)val;
2953 }
2954 *lvalp = jiffies_to_msecs(lval);
2955 }
2956 return 0;
2957}
2958
2959/**
2960 * proc_dointvec_jiffies - read a vector of integers as seconds
2961 * @table: the sysctl table
2962 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 * @buffer: the user buffer
2964 * @lenp: the size of the user buffer
2965 * @ppos: file position
2966 *
2967 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2968 * values from/to the user buffer, treated as an ASCII string.
2969 * The values read are assumed to be in seconds, and are converted into
2970 * jiffies.
2971 *
2972 * Returns 0 on success.
2973 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002974int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 void __user *buffer, size_t *lenp, loff_t *ppos)
2976{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002977 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 do_proc_dointvec_jiffies_conv,NULL);
2979}
2980
2981/**
2982 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2983 * @table: the sysctl table
2984 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 * @buffer: the user buffer
2986 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08002987 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 *
2989 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2990 * values from/to the user buffer, treated as an ASCII string.
2991 * The values read are assumed to be in 1/USER_HZ seconds, and
2992 * are converted into jiffies.
2993 *
2994 * Returns 0 on success.
2995 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002996int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 void __user *buffer, size_t *lenp, loff_t *ppos)
2998{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002999 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 do_proc_dointvec_userhz_jiffies_conv,NULL);
3001}
3002
3003/**
3004 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3005 * @table: the sysctl table
3006 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 * @buffer: the user buffer
3008 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003009 * @ppos: file position
3010 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 *
3012 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3013 * values from/to the user buffer, treated as an ASCII string.
3014 * The values read are assumed to be in 1/1000 seconds, and
3015 * are converted into jiffies.
3016 *
3017 * Returns 0 on success.
3018 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003019int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 void __user *buffer, size_t *lenp, loff_t *ppos)
3021{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003022 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 do_proc_dointvec_ms_jiffies_conv, NULL);
3024}
3025
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003026static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003027 void __user *buffer, size_t *lenp, loff_t *ppos)
3028{
3029 struct pid *new_pid;
3030 pid_t tmp;
3031 int r;
3032
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003033 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003034
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003035 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003036 lenp, ppos, NULL, NULL);
3037 if (r || !write)
3038 return r;
3039
3040 new_pid = find_get_pid(tmp);
3041 if (!new_pid)
3042 return -ESRCH;
3043
3044 put_pid(xchg(&cad_pid, new_pid));
3045 return 0;
3046}
3047
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003048/**
3049 * proc_do_large_bitmap - read/write from/to a large bitmap
3050 * @table: the sysctl table
3051 * @write: %TRUE if this is a write to the sysctl file
3052 * @buffer: the user buffer
3053 * @lenp: the size of the user buffer
3054 * @ppos: file position
3055 *
3056 * The bitmap is stored at table->data and the bitmap length (in bits)
3057 * in table->maxlen.
3058 *
3059 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3060 * large bitmaps may be represented in a compact manner. Writing into
3061 * the file will clear the bitmap then update it with the given input.
3062 *
3063 * Returns 0 on success.
3064 */
3065int proc_do_large_bitmap(struct ctl_table *table, int write,
3066 void __user *buffer, size_t *lenp, loff_t *ppos)
3067{
3068 int err = 0;
3069 bool first = 1;
3070 size_t left = *lenp;
3071 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003072 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003073 unsigned long *tmp_bitmap = NULL;
3074 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3075
WANG Cong122ff242014-05-12 16:04:53 -07003076 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003077 *lenp = 0;
3078 return 0;
3079 }
3080
3081 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003082 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003083
3084 if (left > PAGE_SIZE - 1)
3085 left = PAGE_SIZE - 1;
3086
Al Viro70f6cbb2015-12-24 00:13:10 -05003087 p = kbuf = memdup_user_nul(buffer, left);
3088 if (IS_ERR(kbuf))
3089 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003090
Kees Cook6396bb22018-06-12 14:03:40 -07003091 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3092 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003093 GFP_KERNEL);
3094 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003095 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003096 return -ENOMEM;
3097 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003098 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003099 while (!err && left) {
3100 unsigned long val_a, val_b;
3101 bool neg;
3102
Al Viro70f6cbb2015-12-24 00:13:10 -05003103 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003104 sizeof(tr_a), &c);
3105 if (err)
3106 break;
3107 if (val_a >= bitmap_len || neg) {
3108 err = -EINVAL;
3109 break;
3110 }
3111
3112 val_b = val_a;
3113 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003114 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003115 left--;
3116 }
3117
3118 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003119 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003120 &neg, tr_b, sizeof(tr_b),
3121 &c);
3122 if (err)
3123 break;
3124 if (val_b >= bitmap_len || neg ||
3125 val_a > val_b) {
3126 err = -EINVAL;
3127 break;
3128 }
3129 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003130 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003131 left--;
3132 }
3133 }
3134
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003135 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003136 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003137 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003138 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003139 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003140 } else {
3141 unsigned long bit_a, bit_b = 0;
3142
3143 while (left) {
3144 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3145 if (bit_a >= bitmap_len)
3146 break;
3147 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3148 bit_a + 1) - 1;
3149
3150 if (!first) {
3151 err = proc_put_char(&buffer, &left, ',');
3152 if (err)
3153 break;
3154 }
3155 err = proc_put_long(&buffer, &left, bit_a, false);
3156 if (err)
3157 break;
3158 if (bit_a != bit_b) {
3159 err = proc_put_char(&buffer, &left, '-');
3160 if (err)
3161 break;
3162 err = proc_put_long(&buffer, &left, bit_b, false);
3163 if (err)
3164 break;
3165 }
3166
3167 first = 0; bit_b++;
3168 }
3169 if (!err)
3170 err = proc_put_char(&buffer, &left, '\n');
3171 }
3172
3173 if (!err) {
3174 if (write) {
3175 if (*ppos)
3176 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3177 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003178 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003179 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003180 *lenp -= left;
3181 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003182 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003183
3184 kfree(tmp_bitmap);
3185 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003186}
3187
Jovi Zhang55610502011-01-12 17:00:45 -08003188#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003190int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 void __user *buffer, size_t *lenp, loff_t *ppos)
3192{
3193 return -ENOSYS;
3194}
3195
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003196int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 void __user *buffer, size_t *lenp, loff_t *ppos)
3198{
3199 return -ENOSYS;
3200}
3201
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003202int proc_douintvec(struct ctl_table *table, int write,
3203 void __user *buffer, size_t *lenp, loff_t *ppos)
3204{
3205 return -ENOSYS;
3206}
3207
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003208int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 void __user *buffer, size_t *lenp, loff_t *ppos)
3210{
3211 return -ENOSYS;
3212}
3213
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003214int proc_douintvec_minmax(struct ctl_table *table, int write,
3215 void __user *buffer, size_t *lenp, loff_t *ppos)
3216{
3217 return -ENOSYS;
3218}
3219
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003220int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 void __user *buffer, size_t *lenp, loff_t *ppos)
3222{
3223 return -ENOSYS;
3224}
3225
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003226int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 void __user *buffer, size_t *lenp, loff_t *ppos)
3228{
3229 return -ENOSYS;
3230}
3231
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003232int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 void __user *buffer, size_t *lenp, loff_t *ppos)
3234{
3235 return -ENOSYS;
3236}
3237
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003238int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 void __user *buffer, size_t *lenp, loff_t *ppos)
3240{
3241 return -ENOSYS;
3242}
3243
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003244int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 void __user *buffer,
3246 size_t *lenp, loff_t *ppos)
3247{
3248 return -ENOSYS;
3249}
3250
3251
Jovi Zhang55610502011-01-12 17:00:45 -08003252#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254/*
3255 * No sense putting this after each symbol definition, twice,
3256 * exception granted :-)
3257 */
3258EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003259EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260EXPORT_SYMBOL(proc_dointvec_jiffies);
3261EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003262EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3264EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3265EXPORT_SYMBOL(proc_dostring);
3266EXPORT_SYMBOL(proc_doulongvec_minmax);
3267EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);