blob: 078950d9605ba2f6c109c5837f52b1a6cc07d186 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl.c: General linux system control interface
4 *
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Horn.
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * Wendling.
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080023#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/mm.h>
25#include <linux/swap.h>
26#include <linux/slab.h>
27#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070028#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080029#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080030#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070032#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010066#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080067#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070068#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050069#include <linux/mount.h>
Peter Xucefdca02019-05-13 17:16:41 -070070#include <linux/userfaultfd_k.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Christian Brauner7f2923c2019-03-07 16:29:40 -080072#include "../lib/kstrtox.h"
73
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080074#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#include <asm/processor.h>
76
Andi Kleen29cbc782006-09-30 01:47:55 +020077#ifdef CONFIG_X86
78#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010079#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010080#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020081#endif
David Howellsd550bbd2012-03-28 18:30:03 +010082#ifdef CONFIG_SPARC
83#include <asm/setup.h>
84#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080085#ifdef CONFIG_BSD_PROCESS_ACCT
86#include <linux/acct.h>
87#endif
Dave Young4f0e0562010-03-10 15:24:09 -080088#ifdef CONFIG_RT_MUTEXES
89#include <linux/rtmutex.h>
90#endif
Dave Young2edf5e42010-03-10 15:24:10 -080091#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
92#include <linux/lockdep.h>
93#endif
Dave Young15485a42010-03-10 15:24:07 -080094#ifdef CONFIG_CHR_DEV_SG
95#include <scsi/sg.h>
96#endif
Alexander Popov964c9df2018-08-17 01:17:03 +030097#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
98#include <linux/stackleak.h>
99#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400100#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -0500101#include <linux/nmi.h>
102#endif
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#if defined(CONFIG_SYSCTL)
105
106/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700107extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700108#ifdef CONFIG_COREDUMP
109extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700111extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700112#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800115extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100116extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300117extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000118#ifndef CONFIG_MMU
119extern int sysctl_nr_trim_pages;
120#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400123#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700124static int sixty = 60;
125#endif
126
Aaron Tomlin270750db2014-01-20 17:34:13 +0000127static int __maybe_unused neg_one = -1;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700128static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700129static int __maybe_unused four = 4;
Will Deacon9002b212019-04-05 18:39:38 -0700130static unsigned long zero_ul;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800131static unsigned long one_ul = 1;
Christian Brauner32a5ad92019-03-07 16:29:43 -0800132static unsigned long long_max = LONG_MAX;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700133static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700134static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700135#ifdef CONFIG_PRINTK
136static int ten_thousand = 10000;
137#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300138#ifdef CONFIG_PERF_EVENTS
139static int six_hundred_forty_kb = 640 * 1024;
140#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700141
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700142/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146static int maxolduid = 65535;
147static int minolduid;
148
149static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700150static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700152/*
153 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154 * and hung_task_check_interval_secs
155 */
Liu Hua80df2842014-04-07 15:38:57 -0700156#ifdef CONFIG_DETECT_HUNG_TASK
157static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
158#endif
159
Dave Youngd14f1722010-02-25 20:28:57 -0500160#ifdef CONFIG_INOTIFY_USER
161#include <linux/inotify.h>
162#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700163#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#endif
165
166#ifdef __hppa__
167extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530168#endif
169
170#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171extern int unaligned_enabled;
172#endif
173
Jes Sorensend2b176e2006-02-28 09:42:23 -0800174#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800175extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800176#endif
177
Vineet Guptab6fca722013-01-09 20:06:28 +0530178#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179extern int no_unaligned_warning;
180#endif
181
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700182#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700183
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700184/**
185 * enum sysctl_writes_mode - supported sysctl write modes
186 *
187 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
Weitao Hou65f50f22019-07-16 16:26:54 -0700188 * to be written, and multiple writes on the same sysctl file descriptor
189 * will rewrite the sysctl value, regardless of file position. No warning
190 * is issued when the initial position is not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700191 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
Weitao Hou65f50f22019-07-16 16:26:54 -0700192 * not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700193 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
Weitao Hou65f50f22019-07-16 16:26:54 -0700194 * file position 0 and the value must be fully contained in the buffer
195 * sent to the write syscall. If dealing with strings respect the file
196 * position, but restrict this to the max length of the buffer, anything
197 * passed the max length will be ignored. Multiple writes will append
198 * to the buffer.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700199 *
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
202 */
203enum sysctl_writes_mode {
204 SYSCTL_WRITES_LEGACY = -1,
205 SYSCTL_WRITES_WARN = 0,
206 SYSCTL_WRITES_STRICT = 1,
207};
Kees Cookf4aacea2014-06-06 14:37:19 -0700208
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700209static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700210
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700211static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700212 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700213static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800214 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700215#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700216
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700217#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700218static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700219 void __user *buffer, size_t *lenp, loff_t *ppos);
220#endif
221
Kees Cook54b50192012-07-30 14:39:18 -0700222static int proc_dointvec_minmax_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#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700225static int proc_dostring_coredump(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700227#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800228static int proc_dopipe_max_size(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp, loff_t *ppos);
Kees Cook54b50192012-07-30 14:39:18 -0700230
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700231#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700232/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100233static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700234
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700235static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700236 void __user *buffer, size_t *lenp,
237 loff_t *ppos)
238{
239 int error;
240
241 error = proc_dointvec(table, write, buffer, lenp, ppos);
242 if (error)
243 return error;
244
245 if (write)
246 sysrq_toggle_support(__sysrq_enabled);
247
248 return 0;
249}
250
251#endif
252
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700253static struct ctl_table kern_table[];
254static struct ctl_table vm_table[];
255static struct ctl_table fs_table[];
256static struct ctl_table debug_table[];
257static struct ctl_table dev_table[];
258extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800259#ifdef CONFIG_EPOLL
260extern struct ctl_table epoll_table[];
261#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800263#ifdef CONFIG_FW_LOADER_USER_HELPER
264extern struct ctl_table firmware_config_table[];
265#endif
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
268int sysctl_legacy_va_layout;
269#endif
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/* The default sysctl tables: */
272
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800273static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 .procname = "kernel",
276 .mode = 0555,
277 .child = kern_table,
278 },
279 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 .procname = "vm",
281 .mode = 0555,
282 .child = vm_table,
283 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 .procname = "fs",
286 .mode = 0555,
287 .child = fs_table,
288 },
289 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 .procname = "debug",
291 .mode = 0555,
292 .child = debug_table,
293 },
294 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 .procname = "dev",
296 .mode = 0555,
297 .child = dev_table,
298 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700299 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300};
301
Ingo Molnar77e54a12007-07-09 18:52:00 +0200302#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100303static int min_sched_granularity_ns = 100000; /* 100 usecs */
304static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
305static int min_wakeup_granularity_ns; /* 0 usecs */
306static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200307#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100308static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
309static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200310#endif /* CONFIG_SMP */
311#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200312
Mel Gorman5e771902010-05-24 14:32:31 -0700313#ifdef CONFIG_COMPACTION
314static int min_extfrag_threshold;
315static int max_extfrag_threshold = 1000;
316#endif
317
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700318static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200319 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200320 .procname = "sched_child_runs_first",
321 .data = &sysctl_sched_child_runs_first,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800324 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200325 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200326#ifdef CONFIG_SCHED_DEBUG
327 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100328 .procname = "sched_min_granularity_ns",
329 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200330 .maxlen = sizeof(unsigned int),
331 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800332 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100333 .extra1 = &min_sched_granularity_ns,
334 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200335 },
336 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200337 .procname = "sched_latency_ns",
338 .data = &sysctl_sched_latency,
339 .maxlen = sizeof(unsigned int),
340 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800341 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200342 .extra1 = &min_sched_granularity_ns,
343 .extra2 = &max_sched_granularity_ns,
344 },
345 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200346 .procname = "sched_wakeup_granularity_ns",
347 .data = &sysctl_sched_wakeup_granularity,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800350 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200351 .extra1 = &min_wakeup_granularity_ns,
352 .extra2 = &max_wakeup_granularity_ns,
353 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200354#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200355 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100356 .procname = "sched_tunable_scaling",
357 .data = &sysctl_sched_tunable_scaling,
358 .maxlen = sizeof(enum sched_tunable_scaling),
359 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800360 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100361 .extra1 = &min_sched_tunable_scaling,
362 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200363 },
364 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900365 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200366 .data = &sysctl_sched_migration_cost,
367 .maxlen = sizeof(unsigned int),
368 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800369 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200370 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100371 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100372 .procname = "sched_nr_migrate",
373 .data = &sysctl_sched_nr_migrate,
374 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100375 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800376 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100377 },
Mel Gormancb251762016-02-05 09:08:36 +0000378#ifdef CONFIG_SCHEDSTATS
379 {
380 .procname = "sched_schedstats",
381 .data = NULL,
382 .maxlen = sizeof(unsigned int),
383 .mode = 0644,
384 .proc_handler = sysctl_schedstats,
Matteo Croceeec48442019-07-18 15:58:50 -0700385 .extra1 = SYSCTL_ZERO,
386 .extra2 = SYSCTL_ONE,
Mel Gormancb251762016-02-05 09:08:36 +0000387 },
388#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200389#endif /* CONFIG_SMP */
390#ifdef CONFIG_NUMA_BALANCING
391 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200392 .procname = "numa_balancing_scan_delay_ms",
393 .data = &sysctl_numa_balancing_scan_delay,
394 .maxlen = sizeof(unsigned int),
395 .mode = 0644,
396 .proc_handler = proc_dointvec,
397 },
398 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200399 .procname = "numa_balancing_scan_period_min_ms",
400 .data = &sysctl_numa_balancing_scan_period_min,
401 .maxlen = sizeof(unsigned int),
402 .mode = 0644,
403 .proc_handler = proc_dointvec,
404 },
405 {
406 .procname = "numa_balancing_scan_period_max_ms",
407 .data = &sysctl_numa_balancing_scan_period_max,
408 .maxlen = sizeof(unsigned int),
409 .mode = 0644,
410 .proc_handler = proc_dointvec,
411 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200412 {
413 .procname = "numa_balancing_scan_size_mb",
414 .data = &sysctl_numa_balancing_scan_size,
415 .maxlen = sizeof(unsigned int),
416 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400417 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700418 .extra1 = SYSCTL_ONE,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200419 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100420 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800421 .procname = "numa_balancing",
422 .data = NULL, /* filled in by handler */
423 .maxlen = sizeof(unsigned int),
424 .mode = 0644,
425 .proc_handler = sysctl_numa_balancing,
Matteo Croceeec48442019-07-18 15:58:50 -0700426 .extra1 = SYSCTL_ZERO,
427 .extra2 = SYSCTL_ONE,
Andi Kleen54a43d52014-01-23 15:53:13 -0800428 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200429#endif /* CONFIG_NUMA_BALANCING */
430#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200431 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100432 .procname = "sched_rt_period_us",
433 .data = &sysctl_sched_rt_period,
434 .maxlen = sizeof(unsigned int),
435 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800436 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100437 },
438 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100439 .procname = "sched_rt_runtime_us",
440 .data = &sysctl_sched_rt_runtime,
441 .maxlen = sizeof(int),
442 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800443 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100444 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600445 {
446 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800447 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600448 .maxlen = sizeof(int),
449 .mode = 0644,
450 .proc_handler = sched_rr_handler,
451 },
Patrick Bellasie8f14172019-06-21 09:42:05 +0100452#ifdef CONFIG_UCLAMP_TASK
453 {
454 .procname = "sched_util_clamp_min",
455 .data = &sysctl_sched_uclamp_util_min,
456 .maxlen = sizeof(unsigned int),
457 .mode = 0644,
458 .proc_handler = sysctl_sched_uclamp_handler,
459 },
460 {
461 .procname = "sched_util_clamp_max",
462 .data = &sysctl_sched_uclamp_util_max,
463 .maxlen = sizeof(unsigned int),
464 .mode = 0644,
465 .proc_handler = sysctl_sched_uclamp_handler,
466 },
467#endif
Mike Galbraith5091faa2010-11-30 14:18:03 +0100468#ifdef CONFIG_SCHED_AUTOGROUP
469 {
470 .procname = "sched_autogroup_enabled",
471 .data = &sysctl_sched_autogroup_enabled,
472 .maxlen = sizeof(unsigned int),
473 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800474 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700475 .extra1 = SYSCTL_ZERO,
476 .extra2 = SYSCTL_ONE,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100477 },
478#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700479#ifdef CONFIG_CFS_BANDWIDTH
480 {
481 .procname = "sched_cfs_bandwidth_slice_us",
482 .data = &sysctl_sched_cfs_bandwidth_slice,
483 .maxlen = sizeof(unsigned int),
484 .mode = 0644,
485 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700486 .extra1 = SYSCTL_ONE,
Paul Turnerec12cb72011-07-21 09:43:30 -0700487 },
488#endif
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000489#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
490 {
491 .procname = "sched_energy_aware",
492 .data = &sysctl_sched_energy_aware,
493 .maxlen = sizeof(unsigned int),
494 .mode = 0644,
495 .proc_handler = sched_energy_aware_handler,
Matteo Croceeec48442019-07-18 15:58:50 -0700496 .extra1 = SYSCTL_ZERO,
497 .extra2 = SYSCTL_ONE,
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000498 },
499#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700500#ifdef CONFIG_PROVE_LOCKING
501 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700502 .procname = "prove_locking",
503 .data = &prove_locking,
504 .maxlen = sizeof(int),
505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800506 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700507 },
508#endif
509#ifdef CONFIG_LOCK_STAT
510 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700511 .procname = "lock_stat",
512 .data = &lock_stat,
513 .maxlen = sizeof(int),
514 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800515 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700516 },
517#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200518 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 .procname = "panic",
520 .data = &panic_timeout,
521 .maxlen = sizeof(int),
522 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800523 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 },
Alex Kelly046d6622012-10-04 17:15:23 -0700525#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 .procname = "core_uses_pid",
528 .data = &core_uses_pid,
529 .maxlen = sizeof(int),
530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800531 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 },
533 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 .procname = "core_pattern",
535 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700536 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700538 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 },
Neil Hormana2939802009-09-23 15:56:56 -0700540 {
Neil Hormana2939802009-09-23 15:56:56 -0700541 .procname = "core_pipe_limit",
542 .data = &core_pipe_limit,
543 .maxlen = sizeof(unsigned int),
544 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800545 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700546 },
Alex Kelly046d6622012-10-04 17:15:23 -0700547#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800548#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700551 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800552 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800553 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700555 {
556 .procname = "sysctl_writes_strict",
557 .data = &sysctl_writes_strict,
558 .maxlen = sizeof(int),
559 .mode = 0644,
560 .proc_handler = proc_dointvec_minmax,
561 .extra1 = &neg_one,
Matteo Croceeec48442019-07-18 15:58:50 -0700562 .extra2 = SYSCTL_ONE,
Kees Cookf4aacea2014-06-06 14:37:19 -0700563 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800564#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100565#ifdef CONFIG_LATENCYTOP
566 {
567 .procname = "latencytop",
568 .data = &latencytop_enabled,
569 .maxlen = sizeof(int),
570 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000571 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100572 },
573#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574#ifdef CONFIG_BLK_DEV_INITRD
575 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 .procname = "real-root-dev",
577 .data = &real_root_dev,
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
Ingo Molnar45807a12007-07-15 23:40:10 -0700583 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700584 .procname = "print-fatal-signals",
585 .data = &print_fatal_signals,
586 .maxlen = sizeof(int),
587 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800588 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700589 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700590#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 .procname = "reboot-cmd",
593 .data = reboot_command,
594 .maxlen = 256,
595 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800596 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 },
598 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .procname = "stop-a",
600 .data = &stop_a_enabled,
601 .maxlen = sizeof (int),
602 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800603 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 },
605 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 .procname = "scons-poweroff",
607 .data = &scons_pwroff,
608 .maxlen = sizeof (int),
609 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800610 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 },
612#endif
David S. Miller08714202008-11-16 23:49:24 -0800613#ifdef CONFIG_SPARC64
614 {
David S. Miller08714202008-11-16 23:49:24 -0800615 .procname = "tsb-ratio",
616 .data = &sysctl_tsb_ratio,
617 .maxlen = sizeof (int),
618 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800619 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800620 },
621#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622#ifdef __hppa__
623 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 .procname = "soft-power",
625 .data = &pwrsw_enabled,
626 .maxlen = sizeof (int),
627 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800628 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530630#endif
631#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 .procname = "unaligned-trap",
634 .data = &unaligned_enabled,
635 .maxlen = sizeof (int),
636 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800637 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 },
639#endif
640 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .procname = "ctrl-alt-del",
642 .data = &C_A_D,
643 .maxlen = sizeof(int),
644 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800645 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400647#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200648 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200649 .procname = "ftrace_enabled",
650 .data = &ftrace_enabled,
651 .maxlen = sizeof(int),
652 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800653 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200654 },
655#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500656#ifdef CONFIG_STACK_TRACER
657 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500658 .procname = "stack_tracer_enabled",
659 .data = &stack_tracer_enabled,
660 .maxlen = sizeof(int),
661 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800662 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500663 },
664#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400665#ifdef CONFIG_TRACING
666 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100667 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400668 .data = &ftrace_dump_on_oops,
669 .maxlen = sizeof(int),
670 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800671 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400672 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400673 {
674 .procname = "traceoff_on_warning",
675 .data = &__disable_trace_on_warning,
676 .maxlen = sizeof(__disable_trace_on_warning),
677 .mode = 0644,
678 .proc_handler = proc_dointvec,
679 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500680 {
681 .procname = "tracepoint_printk",
682 .data = &tracepoint_printk,
683 .maxlen = sizeof(tracepoint_printk),
684 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500685 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500686 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400687#endif
Dave Young2965faa2015-09-09 15:38:55 -0700688#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800689 {
690 .procname = "kexec_load_disabled",
691 .data = &kexec_load_disabled,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 /* only handle a transition from default "0" to "1" */
695 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700696 .extra1 = SYSCTL_ONE,
697 .extra2 = SYSCTL_ONE,
Kees Cook79847542014-01-23 15:55:59 -0800698 },
699#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200700#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 .procname = "modprobe",
703 .data = &modprobe_path,
704 .maxlen = KMOD_PATH_LEN,
705 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800706 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 },
Kees Cook3d433212009-04-02 15:49:29 -0700708 {
Kees Cook3d433212009-04-02 15:49:29 -0700709 .procname = "modules_disabled",
710 .data = &modules_disabled,
711 .maxlen = sizeof(int),
712 .mode = 0644,
713 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800714 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700715 .extra1 = SYSCTL_ONE,
716 .extra2 = SYSCTL_ONE,
Kees Cook3d433212009-04-02 15:49:29 -0700717 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700719#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100722 .data = &uevent_helper,
723 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800725 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 },
Michael Marineau86d56132014-04-10 14:09:31 -0700727#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728#ifdef CONFIG_CHR_DEV_SG
729 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 .procname = "sg-big-buff",
731 .data = &sg_big_buff,
732 .maxlen = sizeof (int),
733 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800734 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 },
736#endif
737#ifdef CONFIG_BSD_PROCESS_ACCT
738 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .procname = "acct",
740 .data = &acct_parm,
741 .maxlen = 3*sizeof(int),
742 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800743 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 },
745#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746#ifdef CONFIG_MAGIC_SYSRQ
747 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800749 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .maxlen = sizeof (int),
751 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700752 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 },
754#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700755#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700758 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 .maxlen = sizeof (int),
760 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800761 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700763#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700766 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 .maxlen = sizeof(int),
768 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700769 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 },
771 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 .procname = "random",
773 .mode = 0555,
774 .child = random_table,
775 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 {
Eric Paris17f60a72011-04-01 17:07:50 -0400777 .procname = "usermodehelper",
778 .mode = 0555,
779 .child = usermodehelper_table,
780 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800781#ifdef CONFIG_FW_LOADER_USER_HELPER
782 {
783 .procname = "firmware_config",
784 .mode = 0555,
785 .child = firmware_config_table,
786 },
787#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400788 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 .procname = "overflowuid",
790 .data = &overflowuid,
791 .maxlen = sizeof(int),
792 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800793 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 .extra1 = &minolduid,
795 .extra2 = &maxolduid,
796 },
797 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 .procname = "overflowgid",
799 .data = &overflowgid,
800 .maxlen = sizeof(int),
801 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800802 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 .extra1 = &minolduid,
804 .extra2 = &maxolduid,
805 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800806#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807#ifdef CONFIG_MATHEMU
808 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 .procname = "ieee_emulation_warnings",
810 .data = &sysctl_ieee_emulation_warnings,
811 .maxlen = sizeof(int),
812 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800813 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 },
815#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200818 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 .maxlen = sizeof(int),
820 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800821 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 },
823#endif
824 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 .procname = "pid_max",
826 .data = &pid_max,
827 .maxlen = sizeof (int),
828 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800829 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 .extra1 = &pid_max_min,
831 .extra2 = &pid_max_max,
832 },
833 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 .procname = "panic_on_oops",
835 .data = &panic_on_oops,
836 .maxlen = sizeof(int),
837 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800838 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 },
Feng Tang81c9d432019-01-03 15:28:20 -0800840 {
841 .procname = "panic_print",
842 .data = &panic_print,
843 .maxlen = sizeof(unsigned long),
844 .mode = 0644,
845 .proc_handler = proc_doulongvec_minmax,
846 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800847#if defined CONFIG_PRINTK
848 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800849 .procname = "printk",
850 .data = &console_loglevel,
851 .maxlen = 4*sizeof(int),
852 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800853 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800854 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700857 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 .maxlen = sizeof(int),
859 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800860 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 },
862 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700864 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 .maxlen = sizeof(int),
866 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800867 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 },
Dave Youngaf913222009-09-22 16:43:33 -0700869 {
Dave Youngaf913222009-09-22 16:43:33 -0700870 .procname = "printk_delay",
871 .data = &printk_delay_msec,
872 .maxlen = sizeof(int),
873 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800874 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700875 .extra1 = SYSCTL_ZERO,
Dave Youngaf913222009-09-22 16:43:33 -0700876 .extra2 = &ten_thousand,
877 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700879 .procname = "printk_devkmsg",
880 .data = devkmsg_log_str,
881 .maxlen = DEVKMSG_STR_MAX_SIZE,
882 .mode = 0644,
883 .proc_handler = devkmsg_sysctl_set_loglvl,
884 },
885 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800886 .procname = "dmesg_restrict",
887 .data = &dmesg_restrict,
888 .maxlen = sizeof(int),
889 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700890 .proc_handler = proc_dointvec_minmax_sysadmin,
Matteo Croceeec48442019-07-18 15:58:50 -0700891 .extra1 = SYSCTL_ZERO,
892 .extra2 = SYSCTL_ONE,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800893 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800894 {
895 .procname = "kptr_restrict",
896 .data = &kptr_restrict,
897 .maxlen = sizeof(int),
898 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700899 .proc_handler = proc_dointvec_minmax_sysadmin,
Matteo Croceeec48442019-07-18 15:58:50 -0700900 .extra1 = SYSCTL_ZERO,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800901 .extra2 = &two,
902 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800903#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800904 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 .procname = "ngroups_max",
906 .data = &ngroups_max,
907 .maxlen = sizeof (int),
908 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800909 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 },
Dan Ballard73efc032011-10-31 17:11:20 -0700911 {
912 .procname = "cap_last_cap",
913 .data = (void *)&cap_last_cap,
914 .maxlen = sizeof(int),
915 .mode = 0444,
916 .proc_handler = proc_dointvec,
917 },
Don Zickus58687ac2010-05-07 17:11:44 -0400918#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500919 {
Don Zickus58687ac2010-05-07 17:11:44 -0400920 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200921 .data = &watchdog_user_enabled,
922 .maxlen = sizeof(int),
923 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700924 .proc_handler = proc_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -0700925 .extra1 = SYSCTL_ZERO,
926 .extra2 = SYSCTL_ONE,
Don Zickus58687ac2010-05-07 17:11:44 -0400927 },
928 {
929 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700930 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400931 .maxlen = sizeof(int),
932 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700933 .proc_handler = proc_watchdog_thresh,
Matteo Croceeec48442019-07-18 15:58:50 -0700934 .extra1 = SYSCTL_ZERO,
Don Zickus58687ac2010-05-07 17:11:44 -0400935 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500936 },
Don Zickus2508ce12010-05-07 17:11:46 -0400937 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700938 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200939 .data = &nmi_watchdog_user_enabled,
940 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200941 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700942 .proc_handler = proc_nmi_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -0700943 .extra1 = SYSCTL_ZERO,
944 .extra2 = SYSCTL_ONE,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700945 },
946 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700947 .procname = "watchdog_cpumask",
948 .data = &watchdog_cpumask_bits,
949 .maxlen = NR_CPUS,
950 .mode = 0644,
951 .proc_handler = proc_watchdog_cpumask,
952 },
953#ifdef CONFIG_SOFTLOCKUP_DETECTOR
954 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700955 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200956 .data = &soft_watchdog_user_enabled,
957 .maxlen = sizeof(int),
958 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700959 .proc_handler = proc_soft_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -0700960 .extra1 = SYSCTL_ZERO,
961 .extra2 = SYSCTL_ONE,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700962 },
963 {
Don Zickus2508ce12010-05-07 17:11:46 -0400964 .procname = "softlockup_panic",
965 .data = &softlockup_panic,
966 .maxlen = sizeof(int),
967 .mode = 0644,
968 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700969 .extra1 = SYSCTL_ZERO,
970 .extra2 = SYSCTL_ONE,
Don Zickus2508ce12010-05-07 17:11:46 -0400971 },
Aaron Tomlined235872014-06-23 13:22:05 -0700972#ifdef CONFIG_SMP
973 {
974 .procname = "softlockup_all_cpu_backtrace",
975 .data = &sysctl_softlockup_all_cpu_backtrace,
976 .maxlen = sizeof(int),
977 .mode = 0644,
978 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700979 .extra1 = SYSCTL_ZERO,
980 .extra2 = SYSCTL_ONE,
Aaron Tomlined235872014-06-23 13:22:05 -0700981 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700982#endif /* CONFIG_SMP */
983#endif
984#ifdef CONFIG_HARDLOCKUP_DETECTOR
985 {
986 .procname = "hardlockup_panic",
987 .data = &hardlockup_panic,
988 .maxlen = sizeof(int),
989 .mode = 0644,
990 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700991 .extra1 = SYSCTL_ZERO,
992 .extra2 = SYSCTL_ONE,
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700993 },
994#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800995 {
996 .procname = "hardlockup_all_cpu_backtrace",
997 .data = &sysctl_hardlockup_all_cpu_backtrace,
998 .maxlen = sizeof(int),
999 .mode = 0644,
1000 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001001 .extra1 = SYSCTL_ZERO,
1002 .extra2 = SYSCTL_ONE,
Jiri Kosina55537872015-11-05 18:44:41 -08001003 },
Aaron Tomlined235872014-06-23 13:22:05 -07001004#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -05001005#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -07001006#endif
1007
Don Zickus5dc30552010-11-29 17:07:17 -05001008#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1009 {
1010 .procname = "unknown_nmi_panic",
1011 .data = &unknown_nmi_panic,
1012 .maxlen = sizeof (int),
1013 .mode = 0644,
1014 .proc_handler = proc_dointvec,
1015 },
Don Zickus504d7cf2010-02-12 17:19:19 -05001016#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017#if defined(CONFIG_X86)
1018 {
Don Zickus8da5add2006-09-26 10:52:27 +02001019 .procname = "panic_on_unrecovered_nmi",
1020 .data = &panic_on_unrecovered_nmi,
1021 .maxlen = sizeof(int),
1022 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001023 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001024 },
1025 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001026 .procname = "panic_on_io_nmi",
1027 .data = &panic_on_io_nmi,
1028 .maxlen = sizeof(int),
1029 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001030 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001031 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001032#ifdef CONFIG_DEBUG_STACKOVERFLOW
1033 {
1034 .procname = "panic_on_stackoverflow",
1035 .data = &sysctl_panic_on_stackoverflow,
1036 .maxlen = sizeof(int),
1037 .mode = 0644,
1038 .proc_handler = proc_dointvec,
1039 },
1040#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001041 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 .procname = "bootloader_type",
1043 .data = &bootloader_type,
1044 .maxlen = sizeof (int),
1045 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001046 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001048 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001049 .procname = "bootloader_version",
1050 .data = &bootloader_version,
1051 .maxlen = sizeof (int),
1052 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001053 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001054 },
1055 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001056 .procname = "io_delay_type",
1057 .data = &io_delay_type,
1058 .maxlen = sizeof(int),
1059 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001060 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001061 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001063#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 .procname = "randomize_va_space",
1066 .data = &randomize_va_space,
1067 .maxlen = sizeof(int),
1068 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001069 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001071#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001072#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001073 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001074 .procname = "spin_retry",
1075 .data = &spin_retry,
1076 .maxlen = sizeof (int),
1077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001079 },
1080#endif
Len Brown673d5b42007-07-28 03:33:16 -04001081#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001082 {
Pavel Machekc255d842006-02-20 18:27:58 -08001083 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001084 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001085 .maxlen = sizeof (unsigned long),
1086 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001088 },
1089#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301090#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001091 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001092 .procname = "ignore-unaligned-usertrap",
1093 .data = &no_unaligned_warning,
1094 .maxlen = sizeof (int),
1095 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001096 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001097 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301098#endif
1099#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001100 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001101 .procname = "unaligned-dump-stack",
1102 .data = &unaligned_dump_stack,
1103 .maxlen = sizeof (int),
1104 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001105 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001106 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001107#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001108#ifdef CONFIG_DETECT_HUNG_TASK
1109 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001110 .procname = "hung_task_panic",
1111 .data = &sysctl_hung_task_panic,
1112 .maxlen = sizeof(int),
1113 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001114 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001115 .extra1 = SYSCTL_ZERO,
1116 .extra2 = SYSCTL_ONE,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001117 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001118 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001119 .procname = "hung_task_check_count",
1120 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001121 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001122 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001123 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001124 .extra1 = SYSCTL_ZERO,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001125 },
1126 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001127 .procname = "hung_task_timeout_secs",
1128 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001129 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001130 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001131 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001132 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001133 },
1134 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001135 .procname = "hung_task_check_interval_secs",
1136 .data = &sysctl_hung_task_check_interval_secs,
1137 .maxlen = sizeof(unsigned long),
1138 .mode = 0644,
1139 .proc_handler = proc_dohung_task_timeout_secs,
1140 .extra2 = &hung_task_timeout_max,
1141 },
1142 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001143 .procname = "hung_task_warnings",
1144 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001145 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001146 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001147 .proc_handler = proc_dointvec_minmax,
1148 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001149 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001150#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001151#ifdef CONFIG_RT_MUTEXES
1152 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001153 .procname = "max_lock_depth",
1154 .data = &max_lock_depth,
1155 .maxlen = sizeof(int),
1156 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001157 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001158 },
1159#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001160 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001161 .procname = "poweroff_cmd",
1162 .data = &poweroff_cmd,
1163 .maxlen = POWEROFF_CMD_PATH_LEN,
1164 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001165 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001166 },
David Howells0b77f5b2008-04-29 01:01:32 -07001167#ifdef CONFIG_KEYS
1168 {
David Howells0b77f5b2008-04-29 01:01:32 -07001169 .procname = "keys",
1170 .mode = 0555,
1171 .child = key_sysctls,
1172 },
1173#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001174#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001175 /*
1176 * User-space scripts rely on the existence of this file
1177 * as a feature check for perf_events being enabled.
1178 *
1179 * So it's an ABI, do not remove!
1180 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001181 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001182 .procname = "perf_event_paranoid",
1183 .data = &sysctl_perf_event_paranoid,
1184 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001185 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001186 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001187 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001188 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001189 .procname = "perf_event_mlock_kb",
1190 .data = &sysctl_perf_event_mlock,
1191 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001192 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001193 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001194 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001195 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001196 .procname = "perf_event_max_sample_rate",
1197 .data = &sysctl_perf_event_sample_rate,
1198 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001199 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001200 .proc_handler = perf_proc_update_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001201 .extra1 = SYSCTL_ONE,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001202 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001203 {
1204 .procname = "perf_cpu_time_max_percent",
1205 .data = &sysctl_perf_cpu_time_max_percent,
1206 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1207 .mode = 0644,
1208 .proc_handler = perf_cpu_time_max_percent_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001209 .extra1 = SYSCTL_ZERO,
Dave Hansen14c63f12013-06-21 08:51:36 -07001210 .extra2 = &one_hundred,
1211 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001212 {
1213 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001214 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001215 .maxlen = sizeof(sysctl_perf_event_max_stack),
1216 .mode = 0644,
1217 .proc_handler = perf_event_max_stack_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001218 .extra1 = SYSCTL_ZERO,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001219 .extra2 = &six_hundred_forty_kb,
1220 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001221 {
1222 .procname = "perf_event_max_contexts_per_stack",
1223 .data = &sysctl_perf_event_max_contexts_per_stack,
1224 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1225 .mode = 0644,
1226 .proc_handler = perf_event_max_stack_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001227 .extra1 = SYSCTL_ZERO,
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001228 .extra2 = &one_thousand,
1229 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001230#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001231 {
1232 .procname = "panic_on_warn",
1233 .data = &panic_on_warn,
1234 .maxlen = sizeof(int),
1235 .mode = 0644,
1236 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001237 .extra1 = SYSCTL_ZERO,
1238 .extra2 = SYSCTL_ONE,
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001239 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001240#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1241 {
1242 .procname = "timer_migration",
1243 .data = &sysctl_timer_migration,
1244 .maxlen = sizeof(unsigned int),
1245 .mode = 0644,
1246 .proc_handler = timer_migration_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001247 .extra1 = SYSCTL_ZERO,
1248 .extra2 = SYSCTL_ONE,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001249 },
1250#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001251#ifdef CONFIG_BPF_SYSCALL
1252 {
1253 .procname = "unprivileged_bpf_disabled",
1254 .data = &sysctl_unprivileged_bpf_disabled,
1255 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1256 .mode = 0644,
1257 /* only handle a transition from default "0" to "1" */
1258 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001259 .extra1 = SYSCTL_ONE,
1260 .extra2 = SYSCTL_ONE,
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001261 },
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001262 {
1263 .procname = "bpf_stats_enabled",
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001264 .data = &bpf_stats_enabled_key.key,
1265 .maxlen = sizeof(bpf_stats_enabled_key),
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001266 .mode = 0644,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001267 .proc_handler = proc_do_static_key,
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001268 },
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08001269#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001270#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1271 {
1272 .procname = "panic_on_rcu_stall",
1273 .data = &sysctl_panic_on_rcu_stall,
1274 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1275 .mode = 0644,
1276 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001277 .extra1 = SYSCTL_ZERO,
1278 .extra2 = SYSCTL_ONE,
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001279 },
1280#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001281#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1282 {
1283 .procname = "stack_erasing",
1284 .data = NULL,
1285 .maxlen = sizeof(int),
1286 .mode = 0600,
1287 .proc_handler = stack_erasing_sysctl,
Matteo Croceeec48442019-07-18 15:58:50 -07001288 .extra1 = SYSCTL_ZERO,
1289 .extra2 = SYSCTL_ONE,
Alexander Popov964c9df2018-08-17 01:17:03 +03001290 },
1291#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001292 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293};
1294
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001295static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 .procname = "overcommit_memory",
1298 .data = &sysctl_overcommit_memory,
1299 .maxlen = sizeof(sysctl_overcommit_memory),
1300 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001301 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001302 .extra1 = SYSCTL_ZERO,
Petr Holasekcb16e952011-03-23 16:43:09 -07001303 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 },
1305 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001306 .procname = "panic_on_oom",
1307 .data = &sysctl_panic_on_oom,
1308 .maxlen = sizeof(sysctl_panic_on_oom),
1309 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001310 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001311 .extra1 = SYSCTL_ZERO,
Petr Holasekcb16e952011-03-23 16:43:09 -07001312 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001313 },
1314 {
David Rientjesfe071d72007-10-16 23:25:56 -07001315 .procname = "oom_kill_allocating_task",
1316 .data = &sysctl_oom_kill_allocating_task,
1317 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1318 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001319 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001320 },
1321 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001322 .procname = "oom_dump_tasks",
1323 .data = &sysctl_oom_dump_tasks,
1324 .maxlen = sizeof(sysctl_oom_dump_tasks),
1325 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001326 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001327 },
1328 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 .procname = "overcommit_ratio",
1330 .data = &sysctl_overcommit_ratio,
1331 .maxlen = sizeof(sysctl_overcommit_ratio),
1332 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001333 .proc_handler = overcommit_ratio_handler,
1334 },
1335 {
1336 .procname = "overcommit_kbytes",
1337 .data = &sysctl_overcommit_kbytes,
1338 .maxlen = sizeof(sysctl_overcommit_kbytes),
1339 .mode = 0644,
1340 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 },
1342 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 .procname = "page-cluster",
1344 .data = &page_cluster,
1345 .maxlen = sizeof(int),
1346 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001347 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001348 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 },
1350 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 .procname = "dirty_background_ratio",
1352 .data = &dirty_background_ratio,
1353 .maxlen = sizeof(dirty_background_ratio),
1354 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001355 .proc_handler = dirty_background_ratio_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001356 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 .extra2 = &one_hundred,
1358 },
1359 {
David Rientjes2da02992009-01-06 14:39:31 -08001360 .procname = "dirty_background_bytes",
1361 .data = &dirty_background_bytes,
1362 .maxlen = sizeof(dirty_background_bytes),
1363 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001364 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001365 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001366 },
1367 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 .procname = "dirty_ratio",
1369 .data = &vm_dirty_ratio,
1370 .maxlen = sizeof(vm_dirty_ratio),
1371 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001372 .proc_handler = dirty_ratio_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001373 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 .extra2 = &one_hundred,
1375 },
1376 {
David Rientjes2da02992009-01-06 14:39:31 -08001377 .procname = "dirty_bytes",
1378 .data = &vm_dirty_bytes,
1379 .maxlen = sizeof(vm_dirty_bytes),
1380 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001381 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001382 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001383 },
1384 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001386 .data = &dirty_writeback_interval,
1387 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001389 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 },
1391 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001393 .data = &dirty_expire_interval,
1394 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001396 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001397 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 },
1399 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001400 .procname = "dirtytime_expire_seconds",
1401 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001402 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001403 .mode = 0644,
1404 .proc_handler = dirtytime_interval_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001405 .extra1 = SYSCTL_ZERO,
Theodore Ts'o1efff912015-03-17 12:23:32 -04001406 },
1407 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 .procname = "swappiness",
1409 .data = &vm_swappiness,
1410 .maxlen = sizeof(vm_swappiness),
1411 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001412 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001413 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 .extra2 = &one_hundred,
1415 },
1416#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001419 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 .maxlen = sizeof(unsigned long),
1421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001423 },
1424#ifdef CONFIG_NUMA
1425 {
1426 .procname = "nr_hugepages_mempolicy",
1427 .data = NULL,
1428 .maxlen = sizeof(unsigned long),
1429 .mode = 0644,
1430 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001431 },
Kemi Wang45180852017-11-15 17:38:22 -08001432 {
1433 .procname = "numa_stat",
1434 .data = &sysctl_vm_numa_stat,
1435 .maxlen = sizeof(int),
1436 .mode = 0644,
1437 .proc_handler = sysctl_vm_numa_stat_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001438 .extra1 = SYSCTL_ZERO,
1439 .extra2 = SYSCTL_ONE,
Kemi Wang45180852017-11-15 17:38:22 -08001440 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001441#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 .procname = "hugetlb_shm_group",
1444 .data = &sysctl_hugetlb_shm_group,
1445 .maxlen = sizeof(gid_t),
1446 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001447 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 },
Adam Litke54f9f802007-10-16 01:26:20 -07001449 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001450 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001451 .data = NULL,
1452 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001453 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001454 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001455 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456#endif
1457 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 .procname = "lowmem_reserve_ratio",
1459 .data = &sysctl_lowmem_reserve_ratio,
1460 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1461 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001462 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 },
1464 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001465 .procname = "drop_caches",
1466 .data = &sysctl_drop_caches,
1467 .maxlen = sizeof(int),
1468 .mode = 0644,
1469 .proc_handler = drop_caches_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001470 .extra1 = SYSCTL_ONE,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001471 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001472 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001473#ifdef CONFIG_COMPACTION
1474 {
1475 .procname = "compact_memory",
1476 .data = &sysctl_compact_memory,
1477 .maxlen = sizeof(int),
1478 .mode = 0200,
1479 .proc_handler = sysctl_compaction_handler,
1480 },
Mel Gorman5e771902010-05-24 14:32:31 -07001481 {
1482 .procname = "extfrag_threshold",
1483 .data = &sysctl_extfrag_threshold,
1484 .maxlen = sizeof(int),
1485 .mode = 0644,
Matthew Wilcox6b7e5ca2019-03-05 15:43:41 -08001486 .proc_handler = proc_dointvec_minmax,
Mel Gorman5e771902010-05-24 14:32:31 -07001487 .extra1 = &min_extfrag_threshold,
1488 .extra2 = &max_extfrag_threshold,
1489 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001490 {
1491 .procname = "compact_unevictable_allowed",
1492 .data = &sysctl_compact_unevictable_allowed,
1493 .maxlen = sizeof(int),
1494 .mode = 0644,
1495 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001496 .extra1 = SYSCTL_ZERO,
1497 .extra2 = SYSCTL_ONE,
Eric B Munson5bbe3542015-04-15 16:13:20 -07001498 },
Mel Gorman5e771902010-05-24 14:32:31 -07001499
Mel Gorman76ab0f52010-05-24 14:32:28 -07001500#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001501 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 .procname = "min_free_kbytes",
1503 .data = &min_free_kbytes,
1504 .maxlen = sizeof(min_free_kbytes),
1505 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001506 .proc_handler = min_free_kbytes_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001507 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001509 {
Mel Gorman1c308442018-12-28 00:35:52 -08001510 .procname = "watermark_boost_factor",
1511 .data = &watermark_boost_factor,
1512 .maxlen = sizeof(watermark_boost_factor),
1513 .mode = 0644,
1514 .proc_handler = watermark_boost_factor_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001515 .extra1 = SYSCTL_ZERO,
Mel Gorman1c308442018-12-28 00:35:52 -08001516 },
1517 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001518 .procname = "watermark_scale_factor",
1519 .data = &watermark_scale_factor,
1520 .maxlen = sizeof(watermark_scale_factor),
1521 .mode = 0644,
1522 .proc_handler = watermark_scale_factor_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001523 .extra1 = SYSCTL_ONE,
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001524 .extra2 = &one_thousand,
1525 },
1526 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001527 .procname = "percpu_pagelist_fraction",
1528 .data = &percpu_pagelist_fraction,
1529 .maxlen = sizeof(percpu_pagelist_fraction),
1530 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001531 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001532 .extra1 = SYSCTL_ZERO,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001533 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534#ifdef CONFIG_MMU
1535 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 .procname = "max_map_count",
1537 .data = &sysctl_max_map_count,
1538 .maxlen = sizeof(sysctl_max_map_count),
1539 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001540 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001541 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001543#else
1544 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001545 .procname = "nr_trim_pages",
1546 .data = &sysctl_nr_trim_pages,
1547 .maxlen = sizeof(sysctl_nr_trim_pages),
1548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001549 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001550 .extra1 = SYSCTL_ZERO,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001551 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552#endif
1553 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 .procname = "laptop_mode",
1555 .data = &laptop_mode,
1556 .maxlen = sizeof(laptop_mode),
1557 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001558 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 },
1560 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 .procname = "block_dump",
1562 .data = &block_dump,
1563 .maxlen = sizeof(block_dump),
1564 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001565 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001566 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 },
1568 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 .procname = "vfs_cache_pressure",
1570 .data = &sysctl_vfs_cache_pressure,
1571 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1572 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001573 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001574 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 },
1576#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1577 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 .procname = "legacy_va_layout",
1579 .data = &sysctl_legacy_va_layout,
1580 .maxlen = sizeof(sysctl_legacy_va_layout),
1581 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001582 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001583 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 },
1585#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001586#ifdef CONFIG_NUMA
1587 {
Christoph Lameter17436602006-01-18 17:42:32 -08001588 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001589 .data = &node_reclaim_mode,
1590 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001592 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001593 .extra1 = SYSCTL_ZERO,
Christoph Lameter17436602006-01-18 17:42:32 -08001594 },
Christoph Lameter96146342006-07-03 00:24:13 -07001595 {
Christoph Lameter96146342006-07-03 00:24:13 -07001596 .procname = "min_unmapped_ratio",
1597 .data = &sysctl_min_unmapped_ratio,
1598 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1599 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001600 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001601 .extra1 = SYSCTL_ZERO,
Christoph Lameter96146342006-07-03 00:24:13 -07001602 .extra2 = &one_hundred,
1603 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001604 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001605 .procname = "min_slab_ratio",
1606 .data = &sysctl_min_slab_ratio,
1607 .maxlen = sizeof(sysctl_min_slab_ratio),
1608 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001609 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001610 .extra1 = SYSCTL_ZERO,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001611 .extra2 = &one_hundred,
1612 },
Christoph Lameter17436602006-01-18 17:42:32 -08001613#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001614#ifdef CONFIG_SMP
1615 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001616 .procname = "stat_interval",
1617 .data = &sysctl_stat_interval,
1618 .maxlen = sizeof(sysctl_stat_interval),
1619 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001620 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001621 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001622 {
1623 .procname = "stat_refresh",
1624 .data = NULL,
1625 .maxlen = 0,
1626 .mode = 0600,
1627 .proc_handler = vmstat_refresh,
1628 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001629#endif
David Howells6e141542009-12-15 19:27:45 +00001630#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001631 {
Eric Parised032182007-06-28 15:55:21 -04001632 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001633 .data = &dac_mmap_min_addr,
1634 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001636 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001637 },
David Howells6e141542009-12-15 19:27:45 +00001638#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001639#ifdef CONFIG_NUMA
1640 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001641 .procname = "numa_zonelist_order",
1642 .data = &numa_zonelist_order,
1643 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1644 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001645 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001646 },
1647#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001648#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001649 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001650 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001651 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001652#ifdef CONFIG_X86_32
1653 .data = &vdso32_enabled,
1654 .maxlen = sizeof(vdso32_enabled),
1655#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001656 .data = &vdso_enabled,
1657 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001658#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001659 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001660 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001661 .extra1 = SYSCTL_ZERO,
Ingo Molnare6e54942006-06-27 02:53:50 -07001662 },
1663#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001664#ifdef CONFIG_HIGHMEM
1665 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001666 .procname = "highmem_is_dirtyable",
1667 .data = &vm_highmem_is_dirtyable,
1668 .maxlen = sizeof(vm_highmem_is_dirtyable),
1669 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001670 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001671 .extra1 = SYSCTL_ZERO,
1672 .extra2 = SYSCTL_ONE,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001673 },
1674#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001675#ifdef CONFIG_MEMORY_FAILURE
1676 {
Andi Kleen6a460792009-09-16 11:50:15 +02001677 .procname = "memory_failure_early_kill",
1678 .data = &sysctl_memory_failure_early_kill,
1679 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1680 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001681 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001682 .extra1 = SYSCTL_ZERO,
1683 .extra2 = SYSCTL_ONE,
Andi Kleen6a460792009-09-16 11:50:15 +02001684 },
1685 {
Andi Kleen6a460792009-09-16 11:50:15 +02001686 .procname = "memory_failure_recovery",
1687 .data = &sysctl_memory_failure_recovery,
1688 .maxlen = sizeof(sysctl_memory_failure_recovery),
1689 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001690 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001691 .extra1 = SYSCTL_ZERO,
1692 .extra2 = SYSCTL_ONE,
Andi Kleen6a460792009-09-16 11:50:15 +02001693 },
1694#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001695 {
1696 .procname = "user_reserve_kbytes",
1697 .data = &sysctl_user_reserve_kbytes,
1698 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1699 .mode = 0644,
1700 .proc_handler = proc_doulongvec_minmax,
1701 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001702 {
1703 .procname = "admin_reserve_kbytes",
1704 .data = &sysctl_admin_reserve_kbytes,
1705 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1706 .mode = 0644,
1707 .proc_handler = proc_doulongvec_minmax,
1708 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001709#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1710 {
1711 .procname = "mmap_rnd_bits",
1712 .data = &mmap_rnd_bits,
1713 .maxlen = sizeof(mmap_rnd_bits),
1714 .mode = 0600,
1715 .proc_handler = proc_dointvec_minmax,
1716 .extra1 = (void *)&mmap_rnd_bits_min,
1717 .extra2 = (void *)&mmap_rnd_bits_max,
1718 },
1719#endif
1720#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1721 {
1722 .procname = "mmap_rnd_compat_bits",
1723 .data = &mmap_rnd_compat_bits,
1724 .maxlen = sizeof(mmap_rnd_compat_bits),
1725 .mode = 0600,
1726 .proc_handler = proc_dointvec_minmax,
1727 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1728 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1729 },
1730#endif
Peter Xucefdca02019-05-13 17:16:41 -07001731#ifdef CONFIG_USERFAULTFD
1732 {
1733 .procname = "unprivileged_userfaultfd",
1734 .data = &sysctl_unprivileged_userfaultfd,
1735 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1736 .mode = 0644,
1737 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001738 .extra1 = SYSCTL_ZERO,
1739 .extra2 = SYSCTL_ONE,
Peter Xucefdca02019-05-13 17:16:41 -07001740 },
1741#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001742 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743};
1744
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001745static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 .procname = "inode-nr",
1748 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001749 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001751 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 },
1753 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 .procname = "inode-state",
1755 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001756 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001758 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 },
1760 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 .procname = "file-nr",
1762 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001763 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001765 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 },
1767 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 .procname = "file-max",
1769 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001770 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001772 .proc_handler = proc_doulongvec_minmax,
Will Deacon9002b212019-04-05 18:39:38 -07001773 .extra1 = &zero_ul,
Christian Brauner32a5ad92019-03-07 16:29:43 -08001774 .extra2 = &long_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 },
1776 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001777 .procname = "nr_open",
1778 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001779 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001780 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001781 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001782 .extra1 = &sysctl_nr_open_min,
1783 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001784 },
1785 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 .procname = "dentry-state",
1787 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001788 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001790 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 },
1792 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 .procname = "overflowuid",
1794 .data = &fs_overflowuid,
1795 .maxlen = sizeof(int),
1796 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001797 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 .extra1 = &minolduid,
1799 .extra2 = &maxolduid,
1800 },
1801 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 .procname = "overflowgid",
1803 .data = &fs_overflowgid,
1804 .maxlen = sizeof(int),
1805 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001806 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 .extra1 = &minolduid,
1808 .extra2 = &maxolduid,
1809 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001810#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 .procname = "leases-enable",
1813 .data = &leases_enable,
1814 .maxlen = sizeof(int),
1815 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001816 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001818#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819#ifdef CONFIG_DNOTIFY
1820 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 .procname = "dir-notify-enable",
1822 .data = &dir_notify_enable,
1823 .maxlen = sizeof(int),
1824 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001825 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 },
1827#endif
1828#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001829#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 .procname = "lease-break-time",
1832 .data = &lease_break_time,
1833 .maxlen = sizeof(int),
1834 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001835 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001837#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001838#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 .procname = "aio-nr",
1841 .data = &aio_nr,
1842 .maxlen = sizeof(aio_nr),
1843 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001844 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 },
1846 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 .procname = "aio-max-nr",
1848 .data = &aio_max_nr,
1849 .maxlen = sizeof(aio_max_nr),
1850 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001851 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001853#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001854#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001855 {
Robert Love0399cb02005-07-13 12:38:18 -04001856 .procname = "inotify",
1857 .mode = 0555,
1858 .child = inotify_table,
1859 },
1860#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001861#ifdef CONFIG_EPOLL
1862 {
1863 .procname = "epoll",
1864 .mode = 0555,
1865 .child = epoll_table,
1866 },
1867#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001869 {
Kees Cook800179c2012-07-25 17:29:07 -07001870 .procname = "protected_symlinks",
1871 .data = &sysctl_protected_symlinks,
1872 .maxlen = sizeof(int),
1873 .mode = 0600,
1874 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001875 .extra1 = SYSCTL_ZERO,
1876 .extra2 = SYSCTL_ONE,
Kees Cook800179c2012-07-25 17:29:07 -07001877 },
1878 {
1879 .procname = "protected_hardlinks",
1880 .data = &sysctl_protected_hardlinks,
1881 .maxlen = sizeof(int),
1882 .mode = 0600,
1883 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001884 .extra1 = SYSCTL_ZERO,
1885 .extra2 = SYSCTL_ONE,
Kees Cook800179c2012-07-25 17:29:07 -07001886 },
1887 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001888 .procname = "protected_fifos",
1889 .data = &sysctl_protected_fifos,
1890 .maxlen = sizeof(int),
1891 .mode = 0600,
1892 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001893 .extra1 = SYSCTL_ZERO,
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001894 .extra2 = &two,
1895 },
1896 {
1897 .procname = "protected_regular",
1898 .data = &sysctl_protected_regular,
1899 .maxlen = sizeof(int),
1900 .mode = 0600,
1901 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001902 .extra1 = SYSCTL_ZERO,
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001903 .extra2 = &two,
1904 },
1905 {
Alan Coxd6e71142005-06-23 00:09:43 -07001906 .procname = "suid_dumpable",
1907 .data = &suid_dumpable,
1908 .maxlen = sizeof(int),
1909 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001910 .proc_handler = proc_dointvec_minmax_coredump,
Matteo Croceeec48442019-07-18 15:58:50 -07001911 .extra1 = SYSCTL_ZERO,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001912 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001913 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001914#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1915 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001916 .procname = "binfmt_misc",
1917 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001918 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001919 },
1920#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001921 {
Jens Axboeff9da692010-06-03 14:54:39 +02001922 .procname = "pipe-max-size",
1923 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001924 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001925 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001926 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001927 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001928 {
1929 .procname = "pipe-user-pages-hard",
1930 .data = &pipe_user_pages_hard,
1931 .maxlen = sizeof(pipe_user_pages_hard),
1932 .mode = 0644,
1933 .proc_handler = proc_doulongvec_minmax,
1934 },
1935 {
1936 .procname = "pipe-user-pages-soft",
1937 .data = &pipe_user_pages_soft,
1938 .maxlen = sizeof(pipe_user_pages_soft),
1939 .mode = 0644,
1940 .proc_handler = proc_doulongvec_minmax,
1941 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001942 {
1943 .procname = "mount-max",
1944 .data = &sysctl_mount_max,
1945 .maxlen = sizeof(unsigned int),
1946 .mode = 0644,
1947 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001948 .extra1 = SYSCTL_ONE,
Eric W. Biedermand2921682016-09-28 00:27:17 -05001949 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001950 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951};
1952
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001953static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001954#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001955 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001956 .procname = "exception-trace",
1957 .data = &show_unhandled_signals,
1958 .maxlen = sizeof(int),
1959 .mode = 0644,
1960 .proc_handler = proc_dointvec
1961 },
1962#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001963#if defined(CONFIG_OPTPROBES)
1964 {
1965 .procname = "kprobes-optimization",
1966 .data = &sysctl_kprobes_optimization,
1967 .maxlen = sizeof(int),
1968 .mode = 0644,
1969 .proc_handler = proc_kprobes_optimization_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001970 .extra1 = SYSCTL_ZERO,
1971 .extra2 = SYSCTL_ONE,
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001972 },
1973#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001974 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975};
1976
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001977static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001978 { }
Robert Love0eeca282005-07-12 17:06:03 -04001979};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001981int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001982{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001983 struct ctl_table_header *hdr;
1984
1985 hdr = register_sysctl_table(sysctl_base_table);
1986 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001987 return 0;
1988}
1989
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001990#endif /* CONFIG_SYSCTL */
1991
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992/*
1993 * /proc/sys support
1994 */
1995
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001996#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
Kees Cookf8808302014-06-06 14:37:17 -07001998static int _proc_do_string(char *data, int maxlen, int write,
1999 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002000 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002001{
2002 size_t len;
2003 char __user *p;
2004 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002005
2006 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002007 *lenp = 0;
2008 return 0;
2009 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002010
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002011 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002012 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
2013 /* Only continue writes not past the end of buffer. */
2014 len = strlen(data);
2015 if (len > maxlen - 1)
2016 len = maxlen - 1;
2017
2018 if (*ppos > len)
2019 return 0;
2020 len = *ppos;
2021 } else {
2022 /* Start writing from beginning of buffer. */
2023 len = 0;
2024 }
2025
Kees Cook2ca9bb42014-06-06 14:37:18 -07002026 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002027 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002028 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002029 if (get_user(c, p++))
2030 return -EFAULT;
2031 if (c == 0 || c == '\n')
2032 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002033 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002034 }
Kees Cookf8808302014-06-06 14:37:17 -07002035 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002036 } else {
2037 len = strlen(data);
2038 if (len > maxlen)
2039 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002040
2041 if (*ppos > len) {
2042 *lenp = 0;
2043 return 0;
2044 }
2045
2046 data += *ppos;
2047 len -= *ppos;
2048
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002049 if (len > *lenp)
2050 len = *lenp;
2051 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002052 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002053 return -EFAULT;
2054 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002055 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002056 return -EFAULT;
2057 len++;
2058 }
2059 *lenp = len;
2060 *ppos += len;
2061 }
2062 return 0;
2063}
2064
Kees Cookf4aacea2014-06-06 14:37:19 -07002065static void warn_sysctl_write(struct ctl_table *table)
2066{
2067 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2068 "This will not be supported in the future. To silence this\n"
2069 "warning, set kernel.sysctl_writes_strict = -1\n",
2070 current->comm, table->procname);
2071}
2072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002074 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002075 * @ppos: file position
2076 * @table: the sysctl table
2077 *
2078 * Returns true if the first position is non-zero and the sysctl_writes_strict
2079 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002080 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002081 */
2082static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2083 struct ctl_table *table)
2084{
2085 if (!*ppos)
2086 return false;
2087
2088 switch (sysctl_writes_strict) {
2089 case SYSCTL_WRITES_STRICT:
2090 return true;
2091 case SYSCTL_WRITES_WARN:
2092 warn_sysctl_write(table);
2093 return false;
2094 default:
2095 return false;
2096 }
2097}
2098
2099/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 * proc_dostring - read a string sysctl
2101 * @table: the sysctl table
2102 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 * @buffer: the user buffer
2104 * @lenp: the size of the user buffer
2105 * @ppos: file position
2106 *
2107 * Reads/writes a string from/to the user buffer. If the kernel
2108 * buffer provided is not large enough to hold the string, the
2109 * string is truncated. The copied string is %NULL-terminated.
2110 * If the string is being read by the user process, it is copied
2111 * and a newline '\n' is added. It is truncated if the buffer is
2112 * not large enough.
2113 *
2114 * Returns 0 on success.
2115 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002116int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 void __user *buffer, size_t *lenp, loff_t *ppos)
2118{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002119 if (write)
2120 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002121
Kees Cookf8808302014-06-06 14:37:17 -07002122 return _proc_do_string((char *)(table->data), table->maxlen, write,
2123 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
Amerigo Wang00b7c332010-05-05 00:26:45 +00002126static size_t proc_skip_spaces(char **buf)
2127{
2128 size_t ret;
2129 char *tmp = skip_spaces(*buf);
2130 ret = tmp - *buf;
2131 *buf = tmp;
2132 return ret;
2133}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002135static void proc_skip_char(char **buf, size_t *size, const char v)
2136{
2137 while (*size) {
2138 if (**buf != v)
2139 break;
2140 (*size)--;
2141 (*buf)++;
2142 }
2143}
2144
Christian Brauner7f2923c2019-03-07 16:29:40 -08002145/**
2146 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2147 * fail on overflow
2148 *
2149 * @cp: kernel buffer containing the string to parse
2150 * @endp: pointer to store the trailing characters
2151 * @base: the base to use
2152 * @res: where the parsed integer will be stored
2153 *
2154 * In case of success 0 is returned and @res will contain the parsed integer,
2155 * @endp will hold any trailing characters.
2156 * This function will fail the parse on overflow. If there wasn't an overflow
2157 * the function will defer the decision what characters count as invalid to the
2158 * caller.
2159 */
2160static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2161 unsigned long *res)
2162{
2163 unsigned long long result;
2164 unsigned int rv;
2165
2166 cp = _parse_integer_fixup_radix(cp, &base);
2167 rv = _parse_integer(cp, base, &result);
2168 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2169 return -ERANGE;
2170
2171 cp += rv;
2172
2173 if (endp)
2174 *endp = (char *)cp;
2175
2176 *res = (unsigned long)result;
2177 return 0;
2178}
2179
Amerigo Wang00b7c332010-05-05 00:26:45 +00002180#define TMPBUFLEN 22
2181/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002182 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002183 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002184 * @buf: a kernel buffer
2185 * @size: size of the kernel buffer
2186 * @val: this is where the number will be stored
2187 * @neg: set to %TRUE if number is negative
2188 * @perm_tr: a vector which contains the allowed trailers
2189 * @perm_tr_len: size of the perm_tr vector
2190 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002191 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002192 * In case of success %0 is returned and @buf and @size are updated with
2193 * the amount of bytes read. If @tr is non-NULL and a trailing
2194 * character exists (size is non-zero after returning from this
2195 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002196 */
2197static int proc_get_long(char **buf, size_t *size,
2198 unsigned long *val, bool *neg,
2199 const char *perm_tr, unsigned perm_tr_len, char *tr)
2200{
2201 int len;
2202 char *p, tmp[TMPBUFLEN];
2203
2204 if (!*size)
2205 return -EINVAL;
2206
2207 len = *size;
2208 if (len > TMPBUFLEN - 1)
2209 len = TMPBUFLEN - 1;
2210
2211 memcpy(tmp, *buf, len);
2212
2213 tmp[len] = 0;
2214 p = tmp;
2215 if (*p == '-' && *size > 1) {
2216 *neg = true;
2217 p++;
2218 } else
2219 *neg = false;
2220 if (!isdigit(*p))
2221 return -EINVAL;
2222
Christian Brauner7f2923c2019-03-07 16:29:40 -08002223 if (strtoul_lenient(p, &p, 0, val))
2224 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002225
2226 len = p - tmp;
2227
2228 /* We don't know if the next char is whitespace thus we may accept
2229 * invalid integers (e.g. 1234...a) or two integers instead of one
2230 * (e.g. 123...1). So lets not allow such large numbers. */
2231 if (len == TMPBUFLEN - 1)
2232 return -EINVAL;
2233
2234 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2235 return -EINVAL;
2236
2237 if (tr && (len < *size))
2238 *tr = *p;
2239
2240 *buf += len;
2241 *size -= len;
2242
2243 return 0;
2244}
2245
2246/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002247 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002248 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002249 * @buf: the user buffer
2250 * @size: the size of the user buffer
2251 * @val: the integer to be converted
2252 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002253 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002254 * In case of success %0 is returned and @buf and @size are updated with
2255 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002256 */
2257static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2258 bool neg)
2259{
2260 int len;
2261 char tmp[TMPBUFLEN], *p = tmp;
2262
2263 sprintf(p, "%s%lu", neg ? "-" : "", val);
2264 len = strlen(tmp);
2265 if (len > *size)
2266 len = *size;
2267 if (copy_to_user(*buf, tmp, len))
2268 return -EFAULT;
2269 *size -= len;
2270 *buf += len;
2271 return 0;
2272}
2273#undef TMPBUFLEN
2274
2275static int proc_put_char(void __user **buf, size_t *size, char c)
2276{
2277 if (*size) {
2278 char __user **buffer = (char __user **)buf;
2279 if (put_user(c, *buffer))
2280 return -EFAULT;
2281 (*size)--, (*buffer)++;
2282 *buf = *buffer;
2283 }
2284 return 0;
2285}
2286
2287static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 int *valp,
2289 int write, void *data)
2290{
2291 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002292 if (*negp) {
2293 if (*lvalp > (unsigned long) INT_MAX + 1)
2294 return -EINVAL;
2295 *valp = -*lvalp;
2296 } else {
2297 if (*lvalp > (unsigned long) INT_MAX)
2298 return -EINVAL;
2299 *valp = *lvalp;
2300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 } else {
2302 int val = *valp;
2303 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002304 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002305 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002307 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 *lvalp = (unsigned long)val;
2309 }
2310 }
2311 return 0;
2312}
2313
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002314static int do_proc_douintvec_conv(unsigned long *lvalp,
2315 unsigned int *valp,
2316 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002317{
2318 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002319 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002320 return -EINVAL;
2321 *valp = *lvalp;
2322 } else {
2323 unsigned int val = *valp;
2324 *lvalp = (unsigned long)val;
2325 }
2326 return 0;
2327}
2328
Amerigo Wang00b7c332010-05-05 00:26:45 +00002329static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2330
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002331static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002332 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002333 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002334 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 int write, void *data),
2336 void *data)
2337{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002338 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002339 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002340 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Amerigo Wang00b7c332010-05-05 00:26:45 +00002342 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 *lenp = 0;
2344 return 0;
2345 }
2346
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002347 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 vleft = table->maxlen / sizeof(*i);
2349 left = *lenp;
2350
2351 if (!conv)
2352 conv = do_proc_dointvec_conv;
2353
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002355 if (proc_first_pos_non_zero_ignore(ppos, table))
2356 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002357
Amerigo Wang00b7c332010-05-05 00:26:45 +00002358 if (left > PAGE_SIZE - 1)
2359 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002360 p = kbuf = memdup_user_nul(buffer, left);
2361 if (IS_ERR(kbuf))
2362 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002363 }
2364
2365 for (; left && vleft--; i++, first=0) {
2366 unsigned long lval;
2367 bool neg;
2368
2369 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002370 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002371
J. R. Okajima563b0462010-05-25 16:10:14 -07002372 if (!left)
2373 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002374 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002375 proc_wspace_sep,
2376 sizeof(proc_wspace_sep), NULL);
2377 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002379 if (conv(&neg, &lval, i, 1, data)) {
2380 err = -EINVAL;
2381 break;
2382 }
2383 } else {
2384 if (conv(&neg, &lval, i, 0, data)) {
2385 err = -EINVAL;
2386 break;
2387 }
2388 if (!first)
2389 err = proc_put_char(&buffer, &left, '\t');
2390 if (err)
2391 break;
2392 err = proc_put_long(&buffer, &left, lval, neg);
2393 if (err)
2394 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 }
2396 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002397
2398 if (!write && !first && left && !err)
2399 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002400 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002401 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002402 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002403 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002404 if (first)
2405 return err ? : -EINVAL;
2406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002408out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002410 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002413static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002414 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002415 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002416 int write, void *data),
2417 void *data)
2418{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002419 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002420 buffer, lenp, ppos, conv, data);
2421}
2422
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002423static int do_proc_douintvec_w(unsigned int *tbl_data,
2424 struct ctl_table *table,
2425 void __user *buffer,
2426 size_t *lenp, loff_t *ppos,
2427 int (*conv)(unsigned long *lvalp,
2428 unsigned int *valp,
2429 int write, void *data),
2430 void *data)
2431{
2432 unsigned long lval;
2433 int err = 0;
2434 size_t left;
2435 bool neg;
2436 char *kbuf = NULL, *p;
2437
2438 left = *lenp;
2439
2440 if (proc_first_pos_non_zero_ignore(ppos, table))
2441 goto bail_early;
2442
2443 if (left > PAGE_SIZE - 1)
2444 left = PAGE_SIZE - 1;
2445
2446 p = kbuf = memdup_user_nul(buffer, left);
2447 if (IS_ERR(kbuf))
2448 return -EINVAL;
2449
2450 left -= proc_skip_spaces(&p);
2451 if (!left) {
2452 err = -EINVAL;
2453 goto out_free;
2454 }
2455
2456 err = proc_get_long(&p, &left, &lval, &neg,
2457 proc_wspace_sep,
2458 sizeof(proc_wspace_sep), NULL);
2459 if (err || neg) {
2460 err = -EINVAL;
2461 goto out_free;
2462 }
2463
2464 if (conv(&lval, tbl_data, 1, data)) {
2465 err = -EINVAL;
2466 goto out_free;
2467 }
2468
2469 if (!err && left)
2470 left -= proc_skip_spaces(&p);
2471
2472out_free:
2473 kfree(kbuf);
2474 if (err)
2475 return -EINVAL;
2476
2477 return 0;
2478
2479 /* This is in keeping with old __do_proc_dointvec() */
2480bail_early:
2481 *ppos += *lenp;
2482 return err;
2483}
2484
2485static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2486 size_t *lenp, loff_t *ppos,
2487 int (*conv)(unsigned long *lvalp,
2488 unsigned int *valp,
2489 int write, void *data),
2490 void *data)
2491{
2492 unsigned long lval;
2493 int err = 0;
2494 size_t left;
2495
2496 left = *lenp;
2497
2498 if (conv(&lval, tbl_data, 0, data)) {
2499 err = -EINVAL;
2500 goto out;
2501 }
2502
2503 err = proc_put_long(&buffer, &left, lval, false);
2504 if (err || !left)
2505 goto out;
2506
2507 err = proc_put_char(&buffer, &left, '\n');
2508
2509out:
2510 *lenp -= left;
2511 *ppos += *lenp;
2512
2513 return err;
2514}
2515
2516static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2517 int write, void __user *buffer,
2518 size_t *lenp, loff_t *ppos,
2519 int (*conv)(unsigned long *lvalp,
2520 unsigned int *valp,
2521 int write, void *data),
2522 void *data)
2523{
2524 unsigned int *i, vleft;
2525
2526 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2527 *lenp = 0;
2528 return 0;
2529 }
2530
2531 i = (unsigned int *) tbl_data;
2532 vleft = table->maxlen / sizeof(*i);
2533
2534 /*
2535 * Arrays are not supported, keep this simple. *Do not* add
2536 * support for them.
2537 */
2538 if (vleft != 1) {
2539 *lenp = 0;
2540 return -EINVAL;
2541 }
2542
2543 if (!conv)
2544 conv = do_proc_douintvec_conv;
2545
2546 if (write)
2547 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2548 conv, data);
2549 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2550}
2551
2552static int do_proc_douintvec(struct ctl_table *table, int write,
2553 void __user *buffer, size_t *lenp, loff_t *ppos,
2554 int (*conv)(unsigned long *lvalp,
2555 unsigned int *valp,
2556 int write, void *data),
2557 void *data)
2558{
2559 return __do_proc_douintvec(table->data, table, write,
2560 buffer, lenp, ppos, conv, data);
2561}
2562
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563/**
2564 * proc_dointvec - read a vector of integers
2565 * @table: the sysctl table
2566 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 * @buffer: the user buffer
2568 * @lenp: the size of the user buffer
2569 * @ppos: file position
2570 *
2571 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2572 * values from/to the user buffer, treated as an ASCII string.
2573 *
2574 * Returns 0 on success.
2575 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002576int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 void __user *buffer, size_t *lenp, loff_t *ppos)
2578{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002579 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2580}
2581
2582/**
2583 * proc_douintvec - read a vector of unsigned integers
2584 * @table: the sysctl table
2585 * @write: %TRUE if this is a write to the sysctl file
2586 * @buffer: the user buffer
2587 * @lenp: the size of the user buffer
2588 * @ppos: file position
2589 *
2590 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2591 * values from/to the user buffer, treated as an ASCII string.
2592 *
2593 * Returns 0 on success.
2594 */
2595int proc_douintvec(struct ctl_table *table, int write,
2596 void __user *buffer, size_t *lenp, loff_t *ppos)
2597{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002598 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2599 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600}
2601
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002602/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002603 * Taint values can only be increased
2604 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002605 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002606static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002607 void __user *buffer, size_t *lenp, loff_t *ppos)
2608{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002609 struct ctl_table t;
2610 unsigned long tmptaint = get_taint();
2611 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002612
Bastian Blank91fcd412007-04-23 14:41:14 -07002613 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002614 return -EPERM;
2615
Andi Kleen25ddbb12008-10-15 22:01:41 -07002616 t = *table;
2617 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002618 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002619 if (err < 0)
2620 return err;
2621
2622 if (write) {
2623 /*
2624 * Poor man's atomic or. Not worth adding a primitive
2625 * to everyone's atomic.h for this
2626 */
2627 int i;
2628 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2629 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302630 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002631 }
2632 }
2633
2634 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002635}
2636
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002637#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002638static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002639 void __user *buffer, size_t *lenp, loff_t *ppos)
2640{
2641 if (write && !capable(CAP_SYS_ADMIN))
2642 return -EPERM;
2643
2644 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2645}
2646#endif
2647
Waiman Long24704f32018-04-10 16:35:38 -07002648/**
2649 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2650 * @min: pointer to minimum allowable value
2651 * @max: pointer to maximum allowable value
2652 *
2653 * The do_proc_dointvec_minmax_conv_param structure provides the
2654 * minimum and maximum values for doing range checking for those sysctl
2655 * parameters that use the proc_dointvec_minmax() handler.
2656 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657struct do_proc_dointvec_minmax_conv_param {
2658 int *min;
2659 int *max;
2660};
2661
Amerigo Wang00b7c332010-05-05 00:26:45 +00002662static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2663 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 int write, void *data)
2665{
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002666 int tmp, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 struct do_proc_dointvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002668 /*
2669 * If writing, first do so via a temporary local int so we can
2670 * bounds-check it before touching *valp.
2671 */
2672 int *ip = write ? &tmp : valp;
2673
2674 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2675 if (ret)
2676 return ret;
2677
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002679 if ((param->min && *param->min > tmp) ||
2680 (param->max && *param->max < tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 return -EINVAL;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002682 *valp = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 }
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002684
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 return 0;
2686}
2687
2688/**
2689 * proc_dointvec_minmax - read a vector of integers with min/max values
2690 * @table: the sysctl table
2691 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 * @buffer: the user buffer
2693 * @lenp: the size of the user buffer
2694 * @ppos: file position
2695 *
2696 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2697 * values from/to the user buffer, treated as an ASCII string.
2698 *
2699 * This routine will ensure the values are within the range specified by
2700 * table->extra1 (min) and table->extra2 (max).
2701 *
Waiman Long24704f32018-04-10 16:35:38 -07002702 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002704int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 void __user *buffer, size_t *lenp, loff_t *ppos)
2706{
2707 struct do_proc_dointvec_minmax_conv_param param = {
2708 .min = (int *) table->extra1,
2709 .max = (int *) table->extra2,
2710 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002711 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 do_proc_dointvec_minmax_conv, &param);
2713}
2714
Waiman Long24704f32018-04-10 16:35:38 -07002715/**
2716 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2717 * @min: pointer to minimum allowable value
2718 * @max: pointer to maximum allowable value
2719 *
2720 * The do_proc_douintvec_minmax_conv_param structure provides the
2721 * minimum and maximum values for doing range checking for those sysctl
2722 * parameters that use the proc_douintvec_minmax() handler.
2723 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002724struct do_proc_douintvec_minmax_conv_param {
2725 unsigned int *min;
2726 unsigned int *max;
2727};
2728
2729static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2730 unsigned int *valp,
2731 int write, void *data)
2732{
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002733 int ret;
2734 unsigned int tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002735 struct do_proc_douintvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002736 /* write via temporary local uint for bounds-checking */
2737 unsigned int *up = write ? &tmp : valp;
2738
2739 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2740 if (ret)
2741 return ret;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002742
2743 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002744 if ((param->min && *param->min > tmp) ||
2745 (param->max && *param->max < tmp))
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002746 return -ERANGE;
2747
Zev Weiss2bc4fc62019-03-11 23:28:06 -07002748 *valp = tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002749 }
2750
2751 return 0;
2752}
2753
2754/**
2755 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2756 * @table: the sysctl table
2757 * @write: %TRUE if this is a write to the sysctl file
2758 * @buffer: the user buffer
2759 * @lenp: the size of the user buffer
2760 * @ppos: file position
2761 *
2762 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2763 * values from/to the user buffer, treated as an ASCII string. Negative
2764 * strings are not allowed.
2765 *
2766 * This routine will ensure the values are within the range specified by
2767 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2768 * check for UINT_MAX to avoid having to support wrap around uses from
2769 * userspace.
2770 *
Waiman Long24704f32018-04-10 16:35:38 -07002771 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002772 */
2773int proc_douintvec_minmax(struct ctl_table *table, int write,
2774 void __user *buffer, size_t *lenp, loff_t *ppos)
2775{
2776 struct do_proc_douintvec_minmax_conv_param param = {
2777 .min = (unsigned int *) table->extra1,
2778 .max = (unsigned int *) table->extra2,
2779 };
2780 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2781 do_proc_douintvec_minmax_conv, &param);
2782}
2783
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002784static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2785 unsigned int *valp,
2786 int write, void *data)
2787{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002788 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002789 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002790
Joe Lawrencefb910c42017-11-17 15:29:28 -08002791 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002792 if (val == 0)
2793 return -EINVAL;
2794
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002795 *valp = val;
2796 } else {
2797 unsigned int val = *valp;
2798 *lvalp = (unsigned long) val;
2799 }
2800
2801 return 0;
2802}
2803
Eric Biggers319e0a22018-02-06 15:41:49 -08002804static int proc_dopipe_max_size(struct ctl_table *table, int write,
2805 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002806{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002807 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002808 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002809}
2810
Kees Cook54b50192012-07-30 14:39:18 -07002811static void validate_coredump_safety(void)
2812{
Alex Kelly046d6622012-10-04 17:15:23 -07002813#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002814 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002815 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002816 printk(KERN_WARNING
2817"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2818"Pipe handler or fully qualified core dump path required.\n"
2819"Set kernel.core_pattern before fs.suid_dumpable.\n"
2820 );
Kees Cook54b50192012-07-30 14:39:18 -07002821 }
Alex Kelly046d6622012-10-04 17:15:23 -07002822#endif
Kees Cook54b50192012-07-30 14:39:18 -07002823}
2824
2825static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2826 void __user *buffer, size_t *lenp, loff_t *ppos)
2827{
2828 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2829 if (!error)
2830 validate_coredump_safety();
2831 return error;
2832}
2833
Alex Kelly046d6622012-10-04 17:15:23 -07002834#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002835static int proc_dostring_coredump(struct ctl_table *table, int write,
2836 void __user *buffer, size_t *lenp, loff_t *ppos)
2837{
2838 int error = proc_dostring(table, write, buffer, lenp, ppos);
2839 if (!error)
2840 validate_coredump_safety();
2841 return error;
2842}
Alex Kelly046d6622012-10-04 17:15:23 -07002843#endif
Kees Cook54b50192012-07-30 14:39:18 -07002844
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002845static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 void __user *buffer,
2847 size_t *lenp, loff_t *ppos,
2848 unsigned long convmul,
2849 unsigned long convdiv)
2850{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002851 unsigned long *i, *min, *max;
2852 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002853 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002854 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002855
2856 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 *lenp = 0;
2858 return 0;
2859 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002860
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002861 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 min = (unsigned long *) table->extra1;
2863 max = (unsigned long *) table->extra2;
2864 vleft = table->maxlen / sizeof(unsigned long);
2865 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002866
2867 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002868 if (proc_first_pos_non_zero_ignore(ppos, table))
2869 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002870
Amerigo Wang00b7c332010-05-05 00:26:45 +00002871 if (left > PAGE_SIZE - 1)
2872 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002873 p = kbuf = memdup_user_nul(buffer, left);
2874 if (IS_ERR(kbuf))
2875 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002876 }
2877
Eric Dumazet27b3d802010-10-07 12:59:29 -07002878 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002879 unsigned long val;
2880
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002882 bool neg;
2883
Al Viro70f6cbb2015-12-24 00:13:10 -05002884 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08002885 if (!left)
2886 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002887
Al Viro70f6cbb2015-12-24 00:13:10 -05002888 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002889 proc_wspace_sep,
2890 sizeof(proc_wspace_sep), NULL);
2891 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 break;
2893 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002895 val = convmul * val / convdiv;
Christian Braunere260ad02019-05-14 15:44:55 -07002896 if ((min && val < *min) || (max && val > *max)) {
2897 err = -EINVAL;
2898 break;
2899 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 *i = val;
2901 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002902 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002903 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002904 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002905 if (err)
2906 break;
2907 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002908 err = proc_put_long(&buffer, &left, val, false);
2909 if (err)
2910 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 }
2912 }
2913
Amerigo Wang00b7c332010-05-05 00:26:45 +00002914 if (!write && !first && left && !err)
2915 err = proc_put_char(&buffer, &left, '\n');
2916 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002917 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002919 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002920 if (first)
2921 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002924out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002926 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927}
2928
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002929static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002930 void __user *buffer,
2931 size_t *lenp, loff_t *ppos,
2932 unsigned long convmul,
2933 unsigned long convdiv)
2934{
2935 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002936 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002937}
2938
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939/**
2940 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2941 * @table: the sysctl table
2942 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 * @buffer: the user buffer
2944 * @lenp: the size of the user buffer
2945 * @ppos: file position
2946 *
2947 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2948 * values from/to the user buffer, treated as an ASCII string.
2949 *
2950 * This routine will ensure the values are within the range specified by
2951 * table->extra1 (min) and table->extra2 (max).
2952 *
2953 * Returns 0 on success.
2954 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002955int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 void __user *buffer, size_t *lenp, loff_t *ppos)
2957{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002958 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959}
2960
2961/**
2962 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2963 * @table: the sysctl table
2964 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 * @buffer: the user buffer
2966 * @lenp: the size of the user buffer
2967 * @ppos: file position
2968 *
2969 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2970 * values from/to the user buffer, treated as an ASCII string. The values
2971 * are treated as milliseconds, and converted to jiffies when they are stored.
2972 *
2973 * This routine will ensure the values are within the range specified by
2974 * table->extra1 (min) and table->extra2 (max).
2975 *
2976 * Returns 0 on success.
2977 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002978int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 void __user *buffer,
2980 size_t *lenp, loff_t *ppos)
2981{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002982 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 lenp, ppos, HZ, 1000l);
2984}
2985
2986
Amerigo Wang00b7c332010-05-05 00:26:45 +00002987static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 int *valp,
2989 int write, void *data)
2990{
2991 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002992 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002993 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2995 } else {
2996 int val = *valp;
2997 unsigned long lval;
2998 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002999 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003000 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003002 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 lval = (unsigned long)val;
3004 }
3005 *lvalp = lval / HZ;
3006 }
3007 return 0;
3008}
3009
Amerigo Wang00b7c332010-05-05 00:26:45 +00003010static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 int *valp,
3012 int write, void *data)
3013{
3014 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08003015 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3016 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3018 } else {
3019 int val = *valp;
3020 unsigned long lval;
3021 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003022 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003023 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003025 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 lval = (unsigned long)val;
3027 }
3028 *lvalp = jiffies_to_clock_t(lval);
3029 }
3030 return 0;
3031}
3032
Amerigo Wang00b7c332010-05-05 00:26:45 +00003033static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 int *valp,
3035 int write, void *data)
3036{
3037 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02003038 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3039
3040 if (jif > INT_MAX)
3041 return 1;
3042 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 } else {
3044 int val = *valp;
3045 unsigned long lval;
3046 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003047 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003048 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003050 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 lval = (unsigned long)val;
3052 }
3053 *lvalp = jiffies_to_msecs(lval);
3054 }
3055 return 0;
3056}
3057
3058/**
3059 * proc_dointvec_jiffies - read a vector of integers as seconds
3060 * @table: the sysctl table
3061 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 * @buffer: the user buffer
3063 * @lenp: the size of the user buffer
3064 * @ppos: file position
3065 *
3066 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3067 * values from/to the user buffer, treated as an ASCII string.
3068 * The values read are assumed to be in seconds, and are converted into
3069 * jiffies.
3070 *
3071 * Returns 0 on success.
3072 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003073int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 void __user *buffer, size_t *lenp, loff_t *ppos)
3075{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003076 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 do_proc_dointvec_jiffies_conv,NULL);
3078}
3079
3080/**
3081 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3082 * @table: the sysctl table
3083 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 * @buffer: the user buffer
3085 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003086 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 *
3088 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3089 * values from/to the user buffer, treated as an ASCII string.
3090 * The values read are assumed to be in 1/USER_HZ seconds, and
3091 * are converted into jiffies.
3092 *
3093 * Returns 0 on success.
3094 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003095int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 void __user *buffer, size_t *lenp, loff_t *ppos)
3097{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003098 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 do_proc_dointvec_userhz_jiffies_conv,NULL);
3100}
3101
3102/**
3103 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3104 * @table: the sysctl table
3105 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 * @buffer: the user buffer
3107 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003108 * @ppos: file position
3109 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 *
3111 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3112 * values from/to the user buffer, treated as an ASCII string.
3113 * The values read are assumed to be in 1/1000 seconds, and
3114 * are converted into jiffies.
3115 *
3116 * Returns 0 on success.
3117 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003118int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 void __user *buffer, size_t *lenp, loff_t *ppos)
3120{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003121 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 do_proc_dointvec_ms_jiffies_conv, NULL);
3123}
3124
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003125static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003126 void __user *buffer, size_t *lenp, loff_t *ppos)
3127{
3128 struct pid *new_pid;
3129 pid_t tmp;
3130 int r;
3131
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003132 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003133
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003134 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003135 lenp, ppos, NULL, NULL);
3136 if (r || !write)
3137 return r;
3138
3139 new_pid = find_get_pid(tmp);
3140 if (!new_pid)
3141 return -ESRCH;
3142
3143 put_pid(xchg(&cad_pid, new_pid));
3144 return 0;
3145}
3146
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003147/**
3148 * proc_do_large_bitmap - read/write from/to a large bitmap
3149 * @table: the sysctl table
3150 * @write: %TRUE if this is a write to the sysctl file
3151 * @buffer: the user buffer
3152 * @lenp: the size of the user buffer
3153 * @ppos: file position
3154 *
3155 * The bitmap is stored at table->data and the bitmap length (in bits)
3156 * in table->maxlen.
3157 *
3158 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3159 * large bitmaps may be represented in a compact manner. Writing into
3160 * the file will clear the bitmap then update it with the given input.
3161 *
3162 * Returns 0 on success.
3163 */
3164int proc_do_large_bitmap(struct ctl_table *table, int write,
3165 void __user *buffer, size_t *lenp, loff_t *ppos)
3166{
3167 int err = 0;
3168 bool first = 1;
3169 size_t left = *lenp;
3170 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003171 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003172 unsigned long *tmp_bitmap = NULL;
3173 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3174
WANG Cong122ff242014-05-12 16:04:53 -07003175 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003176 *lenp = 0;
3177 return 0;
3178 }
3179
3180 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003181 char *kbuf, *p;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003182 size_t skipped = 0;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003183
Eric Sandeen3116ad32019-05-14 15:45:13 -07003184 if (left > PAGE_SIZE - 1) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003185 left = PAGE_SIZE - 1;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003186 /* How much of the buffer we'll skip this pass */
3187 skipped = *lenp - left;
3188 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003189
Al Viro70f6cbb2015-12-24 00:13:10 -05003190 p = kbuf = memdup_user_nul(buffer, left);
3191 if (IS_ERR(kbuf))
3192 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003193
Andy Shevchenko475dae32019-05-14 15:44:52 -07003194 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003195 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003196 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003197 return -ENOMEM;
3198 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003199 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003200 while (!err && left) {
3201 unsigned long val_a, val_b;
3202 bool neg;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003203 size_t saved_left;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003204
Eric Sandeen3116ad32019-05-14 15:45:13 -07003205 /* In case we stop parsing mid-number, we can reset */
3206 saved_left = left;
Al Viro70f6cbb2015-12-24 00:13:10 -05003207 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003208 sizeof(tr_a), &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003209 /*
3210 * If we consumed the entirety of a truncated buffer or
3211 * only one char is left (may be a "-"), then stop here,
3212 * reset, & come back for more.
3213 */
3214 if ((left <= 1) && skipped) {
3215 left = saved_left;
3216 break;
3217 }
3218
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003219 if (err)
3220 break;
3221 if (val_a >= bitmap_len || neg) {
3222 err = -EINVAL;
3223 break;
3224 }
3225
3226 val_b = val_a;
3227 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003228 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003229 left--;
3230 }
3231
3232 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003233 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003234 &neg, tr_b, sizeof(tr_b),
3235 &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003236 /*
3237 * If we consumed all of a truncated buffer or
3238 * then stop here, reset, & come back for more.
3239 */
3240 if (!left && skipped) {
3241 left = saved_left;
3242 break;
3243 }
3244
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003245 if (err)
3246 break;
3247 if (val_b >= bitmap_len || neg ||
3248 val_a > val_b) {
3249 err = -EINVAL;
3250 break;
3251 }
3252 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003253 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003254 left--;
3255 }
3256 }
3257
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003258 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003259 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003260 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003261 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003262 kfree(kbuf);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003263 left += skipped;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003264 } else {
3265 unsigned long bit_a, bit_b = 0;
3266
3267 while (left) {
3268 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3269 if (bit_a >= bitmap_len)
3270 break;
3271 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3272 bit_a + 1) - 1;
3273
3274 if (!first) {
3275 err = proc_put_char(&buffer, &left, ',');
3276 if (err)
3277 break;
3278 }
3279 err = proc_put_long(&buffer, &left, bit_a, false);
3280 if (err)
3281 break;
3282 if (bit_a != bit_b) {
3283 err = proc_put_char(&buffer, &left, '-');
3284 if (err)
3285 break;
3286 err = proc_put_long(&buffer, &left, bit_b, false);
3287 if (err)
3288 break;
3289 }
3290
3291 first = 0; bit_b++;
3292 }
3293 if (!err)
3294 err = proc_put_char(&buffer, &left, '\n');
3295 }
3296
3297 if (!err) {
3298 if (write) {
3299 if (*ppos)
3300 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3301 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003302 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003303 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003304 *lenp -= left;
3305 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003306 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003307
Andy Shevchenko475dae32019-05-14 15:44:52 -07003308 bitmap_free(tmp_bitmap);
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003309 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003310}
3311
Jovi Zhang55610502011-01-12 17:00:45 -08003312#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003314int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 void __user *buffer, size_t *lenp, loff_t *ppos)
3316{
3317 return -ENOSYS;
3318}
3319
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003320int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 void __user *buffer, size_t *lenp, loff_t *ppos)
3322{
3323 return -ENOSYS;
3324}
3325
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003326int proc_douintvec(struct ctl_table *table, int write,
3327 void __user *buffer, size_t *lenp, loff_t *ppos)
3328{
3329 return -ENOSYS;
3330}
3331
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003332int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 void __user *buffer, size_t *lenp, loff_t *ppos)
3334{
3335 return -ENOSYS;
3336}
3337
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003338int proc_douintvec_minmax(struct ctl_table *table, int write,
3339 void __user *buffer, size_t *lenp, loff_t *ppos)
3340{
3341 return -ENOSYS;
3342}
3343
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003344int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 void __user *buffer, size_t *lenp, loff_t *ppos)
3346{
3347 return -ENOSYS;
3348}
3349
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003350int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 void __user *buffer, size_t *lenp, loff_t *ppos)
3352{
3353 return -ENOSYS;
3354}
3355
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003356int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 void __user *buffer, size_t *lenp, loff_t *ppos)
3358{
3359 return -ENOSYS;
3360}
3361
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003362int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 void __user *buffer, size_t *lenp, loff_t *ppos)
3364{
3365 return -ENOSYS;
3366}
3367
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003368int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 void __user *buffer,
3370 size_t *lenp, loff_t *ppos)
3371{
3372 return -ENOSYS;
3373}
3374
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003375int proc_do_large_bitmap(struct ctl_table *table, int write,
3376 void __user *buffer, size_t *lenp, loff_t *ppos)
3377{
3378 return -ENOSYS;
3379}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380
Jovi Zhang55610502011-01-12 17:00:45 -08003381#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003383#if defined(CONFIG_SYSCTL)
3384int proc_do_static_key(struct ctl_table *table, int write,
3385 void __user *buffer, size_t *lenp,
3386 loff_t *ppos)
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003387{
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003388 struct static_key *key = (struct static_key *)table->data;
3389 static DEFINE_MUTEX(static_key_mutex);
3390 int val, ret;
3391 struct ctl_table tmp = {
3392 .data = &val,
3393 .maxlen = sizeof(val),
3394 .mode = table->mode,
Matteo Croceeec48442019-07-18 15:58:50 -07003395 .extra1 = SYSCTL_ZERO,
3396 .extra2 = SYSCTL_ONE,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003397 };
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003398
3399 if (write && !capable(CAP_SYS_ADMIN))
3400 return -EPERM;
3401
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003402 mutex_lock(&static_key_mutex);
3403 val = static_key_enabled(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003404 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3405 if (write && !ret) {
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003406 if (val)
3407 static_key_enable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003408 else
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003409 static_key_disable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003410 }
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003411 mutex_unlock(&static_key_mutex);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003412 return ret;
3413}
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003414#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415/*
3416 * No sense putting this after each symbol definition, twice,
3417 * exception granted :-)
3418 */
3419EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003420EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421EXPORT_SYMBOL(proc_dointvec_jiffies);
3422EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003423EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3425EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3426EXPORT_SYMBOL(proc_dostring);
3427EXPORT_SYMBOL(proc_doulongvec_minmax);
3428EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003429EXPORT_SYMBOL(proc_do_large_bitmap);