blob: 6a8fd496fd2f7724e5ffbb22f113681a12ab1b94 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
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;
Rik van Riel92501cb2011-09-01 15:26:50 -0400114extern int extra_free_kbytes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800116extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100117extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300118extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000119#ifndef CONFIG_MMU
120extern int sysctl_nr_trim_pages;
121#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700123/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400124#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700125static int sixty = 60;
126#endif
127
Aaron Tomlin270750db2014-01-20 17:34:13 +0000128static int __maybe_unused neg_one = -1;
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700129
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700130static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700131static int __maybe_unused four = 4;
Will Deacon9002b212019-04-05 18:39:38 -0700132static unsigned long zero_ul;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800133static unsigned long one_ul = 1;
Christian Brauner32a5ad92019-03-07 16:29:43 -0800134static unsigned long long_max = LONG_MAX;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700135static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700136static int one_thousand = 1000;
Sai Harshini Nimmalaf89f67e2020-09-18 12:53:34 -0700137#ifdef CONFIG_QCOM_HYP_CORE_CTL
138static int five_hundred = 500;
139static int five_thousand = 5000;
140#endif
Dave Youngaf913222009-09-22 16:43:33 -0700141#ifdef CONFIG_PRINTK
142static int ten_thousand = 10000;
143#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300144#ifdef CONFIG_PERF_EVENTS
145static int six_hundred_forty_kb = 640 * 1024;
146#endif
Buddy Lumpkin767f6472018-04-02 09:24:22 +0000147static int __maybe_unused max_kswapd_threads = MAX_KSWAPD_THREADS;
148
Satya Durga Srinivasu Prabhala93f140f2019-09-17 11:33:01 -0700149#ifdef CONFIG_SCHED_WALT
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700150static int neg_three = -3;
151static int three = 3;
Lingutla Chandrasekhar7214dad2021-07-07 12:18:57 +0530152static int fifty = 50;
Satya Durga Srinivasu Prabhala93f140f2019-09-17 11:33:01 -0700153static int two_hundred_fifty_five = 255;
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700154const int sched_user_hint_max = 1000;
155static unsigned int ns_per_sec = NSEC_PER_SEC;
156static unsigned int one_hundred_thousand = 100000;
Sai Harshini Nimmala44a9fe82019-11-20 17:21:15 -0800157static unsigned int two_hundred_million = 200000000;
Tengfei Fan7a8045d2020-04-21 09:01:51 +0800158/*
159 * CFS task prio range is [100 ... 139]
160 * 120 is the default prio.
161 * RTG boost range is [100 ... 119] because giving
162 * boost for [120 .. 139] does not make sense.
163 * 99 means disabled and it is the default value.
164 */
165static unsigned int min_cfs_boost_prio = 99;
166static unsigned int max_cfs_boost_prio = 119;
Satya Durga Srinivasu Prabhala93f140f2019-09-17 11:33:01 -0700167#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700168
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700169/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
170static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
173static int maxolduid = 65535;
174static int minolduid;
175
176static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700177static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700179/*
180 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
181 * and hung_task_check_interval_secs
182 */
Liu Hua80df2842014-04-07 15:38:57 -0700183#ifdef CONFIG_DETECT_HUNG_TASK
184static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
185#endif
186
Dave Youngd14f1722010-02-25 20:28:57 -0500187#ifdef CONFIG_INOTIFY_USER
188#include <linux/inotify.h>
189#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700190#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#endif
192
Helge Dellerb67114d2019-10-04 13:10:09 +0200193#ifdef CONFIG_PARISC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530195#endif
196
197#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198extern int unaligned_enabled;
199#endif
200
Jes Sorensend2b176e2006-02-28 09:42:23 -0800201#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800202extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800203#endif
204
Vineet Guptab6fca722013-01-09 20:06:28 +0530205#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
206extern int no_unaligned_warning;
207#endif
208
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700209#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700210
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700211/**
212 * enum sysctl_writes_mode - supported sysctl write modes
213 *
214 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
Weitao Hou65f50f22019-07-16 16:26:54 -0700215 * to be written, and multiple writes on the same sysctl file descriptor
216 * will rewrite the sysctl value, regardless of file position. No warning
217 * is issued when the initial position is not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700218 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
Weitao Hou65f50f22019-07-16 16:26:54 -0700219 * not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700220 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
Weitao Hou65f50f22019-07-16 16:26:54 -0700221 * file position 0 and the value must be fully contained in the buffer
222 * sent to the write syscall. If dealing with strings respect the file
223 * position, but restrict this to the max length of the buffer, anything
224 * passed the max length will be ignored. Multiple writes will append
225 * to the buffer.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700226 *
227 * These write modes control how current file position affects the behavior of
228 * updating sysctl values through the proc interface on each write.
229 */
230enum sysctl_writes_mode {
231 SYSCTL_WRITES_LEGACY = -1,
232 SYSCTL_WRITES_WARN = 0,
233 SYSCTL_WRITES_STRICT = 1,
234};
Kees Cookf4aacea2014-06-06 14:37:19 -0700235
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700236static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700237
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700238static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700239 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700240static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800241 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700242#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700243
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700244#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700245static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700246 void __user *buffer, size_t *lenp, loff_t *ppos);
247#endif
248
Kees Cook54b50192012-07-30 14:39:18 -0700249static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
250 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700251#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700252static int proc_dostring_coredump(struct ctl_table *table, int write,
253 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700254#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800255static int proc_dopipe_max_size(struct ctl_table *table, int write,
256 void __user *buffer, size_t *lenp, loff_t *ppos);
Kees Cook54b50192012-07-30 14:39:18 -0700257
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700258#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700259/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100260static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700261
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700262static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700263 void __user *buffer, size_t *lenp,
264 loff_t *ppos)
265{
266 int error;
267
268 error = proc_dointvec(table, write, buffer, lenp, ppos);
269 if (error)
270 return error;
271
272 if (write)
273 sysrq_toggle_support(__sysrq_enabled);
274
275 return 0;
276}
277
278#endif
279
Daniel Borkmann508711c2021-05-11 22:35:17 +0200280#ifdef CONFIG_BPF_SYSCALL
Josh Poimboeuf4e9fffd2022-02-18 11:49:08 -0800281
282void __weak unpriv_ebpf_notify(int new_state)
283{
284}
285
Daniel Borkmann508711c2021-05-11 22:35:17 +0200286static int bpf_unpriv_handler(struct ctl_table *table, int write,
287 void *buffer, size_t *lenp, loff_t *ppos)
288{
289 int ret, unpriv_enable = *(int *)table->data;
290 bool locked_state = unpriv_enable == 1;
291 struct ctl_table tmp = *table;
292
293 if (write && !capable(CAP_SYS_ADMIN))
294 return -EPERM;
295
296 tmp.data = &unpriv_enable;
297 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
298 if (write && !ret) {
299 if (locked_state && unpriv_enable != 1)
300 return -EPERM;
301 *(int *)table->data = unpriv_enable;
302 }
Josh Poimboeuf4e9fffd2022-02-18 11:49:08 -0800303
304 unpriv_ebpf_notify(unpriv_enable);
305
Daniel Borkmann508711c2021-05-11 22:35:17 +0200306 return ret;
307}
308#endif
309
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700310static struct ctl_table kern_table[];
311static struct ctl_table vm_table[];
312static struct ctl_table fs_table[];
313static struct ctl_table debug_table[];
314static struct ctl_table dev_table[];
315extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800316#ifdef CONFIG_EPOLL
317extern struct ctl_table epoll_table[];
318#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800320#ifdef CONFIG_FW_LOADER_USER_HELPER
321extern struct ctl_table firmware_config_table[];
322#endif
323
Alexandre Ghiti67f39772019-09-23 15:38:47 -0700324#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
325 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326int sysctl_legacy_va_layout;
327#endif
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329/* The default sysctl tables: */
330
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800331static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 .procname = "kernel",
334 .mode = 0555,
335 .child = kern_table,
336 },
337 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 .procname = "vm",
339 .mode = 0555,
340 .child = vm_table,
341 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 .procname = "fs",
344 .mode = 0555,
345 .child = fs_table,
346 },
347 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 .procname = "debug",
349 .mode = 0555,
350 .child = debug_table,
351 },
352 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 .procname = "dev",
354 .mode = 0555,
355 .child = dev_table,
356 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700357 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358};
359
Ingo Molnar77e54a12007-07-09 18:52:00 +0200360#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100361static int min_sched_granularity_ns = 100000; /* 100 usecs */
362static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
363static int min_wakeup_granularity_ns; /* 0 usecs */
364static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200365#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100366static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
367static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200368#endif /* CONFIG_SMP */
369#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200370
Mel Gorman5e771902010-05-24 14:32:31 -0700371#ifdef CONFIG_COMPACTION
372static int min_extfrag_threshold;
373static int max_extfrag_threshold = 1000;
374#endif
375
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700376static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200377 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200378 .procname = "sched_child_runs_first",
379 .data = &sysctl_sched_child_runs_first,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800382 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200383 },
Sai Harshini Nimmalaf89f67e2020-09-18 12:53:34 -0700384#ifdef CONFIG_QCOM_HYP_CORE_CTL
385 {
386 .procname = "hh_suspend_timeout_ms",
387 .data = &sysctl_hh_suspend_timeout_ms,
388 .maxlen = sizeof(unsigned int),
389 .mode = 0644,
390 .proc_handler = proc_douintvec_minmax,
391 .extra1 = &five_hundred,
392 .extra2 = &five_thousand,
393 },
394#endif
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700395#ifdef CONFIG_SCHED_WALT
396 {
397 .procname = "sched_user_hint",
398 .data = &sysctl_sched_user_hint,
399 .maxlen = sizeof(unsigned int),
400 .mode = 0644,
401 .proc_handler = walt_proc_user_hint_handler,
402 .extra1 = SYSCTL_ZERO,
403 .extra2 = (void *)&sched_user_hint_max,
404 },
405 {
406 .procname = "sched_window_stats_policy",
407 .data = &sysctl_sched_window_stats_policy,
408 .maxlen = sizeof(unsigned int),
409 .mode = 0644,
410 .proc_handler = proc_dointvec_minmax,
411 .extra1 = SYSCTL_ZERO,
412 .extra2 = &four,
413 },
414 {
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700415 .procname = "sched_group_upmigrate",
416 .data = &sysctl_sched_group_upmigrate_pct,
417 .maxlen = sizeof(unsigned int),
418 .mode = 0644,
419 .proc_handler = walt_proc_group_thresholds_handler,
420 .extra1 = &sysctl_sched_group_downmigrate_pct,
421 },
422 {
423 .procname = "sched_group_downmigrate",
424 .data = &sysctl_sched_group_downmigrate_pct,
425 .maxlen = sizeof(unsigned int),
426 .mode = 0644,
427 .proc_handler = walt_proc_group_thresholds_handler,
428 .extra1 = SYSCTL_ZERO,
429 .extra2 = &sysctl_sched_group_upmigrate_pct,
430 },
431 {
432 .procname = "sched_boost",
433 .data = &sysctl_sched_boost,
434 .maxlen = sizeof(unsigned int),
435 .mode = 0644,
436 .proc_handler = sched_boost_handler,
437 .extra1 = &neg_three,
438 .extra2 = &three,
439 },
440 {
441 .procname = "sched_conservative_pl",
442 .data = &sysctl_sched_conservative_pl,
443 .maxlen = sizeof(unsigned int),
444 .mode = 0644,
445 .proc_handler = proc_dointvec_minmax,
446 .extra1 = SYSCTL_ZERO,
447 .extra2 = SYSCTL_ONE,
448 },
449 {
Maria Yu692aa6b2019-06-12 14:56:54 +0800450 .procname = "sched_many_wakeup_threshold",
451 .data = &sysctl_sched_many_wakeup_threshold,
452 .maxlen = sizeof(unsigned int),
453 .mode = 0644,
454 .proc_handler = proc_dointvec_minmax,
455 .extra1 = &two,
456 .extra2 = &one_thousand,
457 },
458 {
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700459 .procname = "sched_walt_rotate_big_tasks",
460 .data = &sysctl_sched_walt_rotate_big_tasks,
461 .maxlen = sizeof(unsigned int),
462 .mode = 0644,
463 .proc_handler = proc_dointvec_minmax,
464 .extra1 = SYSCTL_ZERO,
465 .extra2 = SYSCTL_ONE,
466 },
467 {
468 .procname = "sched_min_task_util_for_boost",
469 .data = &sysctl_sched_min_task_util_for_boost,
470 .maxlen = sizeof(unsigned int),
471 .mode = 0644,
472 .proc_handler = proc_dointvec_minmax,
473 .extra1 = SYSCTL_ZERO,
474 .extra2 = &one_thousand,
475 },
476 {
477 .procname = "sched_min_task_util_for_colocation",
478 .data = &sysctl_sched_min_task_util_for_colocation,
479 .maxlen = sizeof(unsigned int),
480 .mode = 0644,
481 .proc_handler = proc_dointvec_minmax,
482 .extra1 = SYSCTL_ZERO,
483 .extra2 = &one_thousand,
484 },
485 {
486 .procname = "sched_asym_cap_sibling_freq_match_pct",
487 .data = &sysctl_sched_asym_cap_sibling_freq_match_pct,
488 .maxlen = sizeof(unsigned int),
489 .mode = 0644,
490 .proc_handler = proc_dointvec_minmax,
491 .extra1 = SYSCTL_ONE,
492 .extra2 = &one_hundred,
493 },
494 {
Lingutla Chandrasekharda935c6b2021-01-12 16:54:11 +0530495 .procname = "sched_asym_cap_sibling_freq_match_enable",
496 .data = &sysctl_sched_asym_cap_sibling_freq_match_en,
497 .maxlen = sizeof(unsigned int),
498 .mode = 0644,
499 .proc_handler = proc_dointvec_minmax,
500 .extra1 = SYSCTL_ZERO,
501 .extra2 = SYSCTL_ONE,
502 },
503 {
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700504 .procname = "sched_coloc_downmigrate_ns",
505 .data = &sysctl_sched_coloc_downmigrate_ns,
506 .maxlen = sizeof(unsigned int),
507 .mode = 0644,
508 .proc_handler = proc_douintvec_minmax,
509 },
510 {
Sai Harshini Nimmala44a9fe82019-11-20 17:21:15 -0800511 .procname = "sched_task_unfilter_period",
512 .data = &sysctl_sched_task_unfilter_period,
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700513 .maxlen = sizeof(unsigned int),
514 .mode = 0644,
515 .proc_handler = proc_dointvec_minmax,
516 .extra1 = SYSCTL_ONE,
Sai Harshini Nimmala44a9fe82019-11-20 17:21:15 -0800517 .extra2 = &two_hundred_million,
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700518 },
519 {
520 .procname = "sched_busy_hysteresis_enable_cpus",
521 .data = &sysctl_sched_busy_hyst_enable_cpus,
522 .maxlen = sizeof(unsigned int),
523 .mode = 0644,
Amir Vajidf777e922020-04-14 12:58:43 -0700524 .proc_handler = sched_busy_hyst_handler,
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700525 .extra1 = SYSCTL_ZERO,
526 .extra2 = &two_hundred_fifty_five,
527 },
528 {
529 .procname = "sched_busy_hyst_ns",
530 .data = &sysctl_sched_busy_hyst,
531 .maxlen = sizeof(unsigned int),
532 .mode = 0644,
Amir Vajidf777e922020-04-14 12:58:43 -0700533 .proc_handler = sched_busy_hyst_handler,
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700534 .extra1 = SYSCTL_ZERO,
535 .extra2 = &ns_per_sec,
536 },
537 {
538 .procname = "sched_coloc_busy_hysteresis_enable_cpus",
539 .data = &sysctl_sched_coloc_busy_hyst_enable_cpus,
540 .maxlen = sizeof(unsigned int),
541 .mode = 0644,
Amir Vajidf777e922020-04-14 12:58:43 -0700542 .proc_handler = sched_busy_hyst_handler,
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700543 .extra1 = SYSCTL_ZERO,
544 .extra2 = &two_hundred_fifty_five,
545 },
546 {
Amir Vajidf777e922020-04-14 12:58:43 -0700547 .procname = "sched_coloc_busy_hyst_cpu_ns",
548 .data = &sysctl_sched_coloc_busy_hyst_cpu,
549 .maxlen = sizeof(unsigned int) * NR_CPUS,
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700550 .mode = 0644,
Amir Vajidf777e922020-04-14 12:58:43 -0700551 .proc_handler = sched_busy_hyst_handler,
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700552 .extra1 = SYSCTL_ZERO,
553 .extra2 = &ns_per_sec,
554 },
555 {
556 .procname = "sched_coloc_busy_hyst_max_ms",
557 .data = &sysctl_sched_coloc_busy_hyst_max_ms,
558 .maxlen = sizeof(unsigned int),
559 .mode = 0644,
Amir Vajidf777e922020-04-14 12:58:43 -0700560 .proc_handler = sched_busy_hyst_handler,
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700561 .extra1 = SYSCTL_ZERO,
562 .extra2 = &one_hundred_thousand,
563 },
564 {
Amir Vajidf777e922020-04-14 12:58:43 -0700565 .procname = "sched_coloc_busy_hyst_cpu_busy_pct",
566 .data = &sysctl_sched_coloc_busy_hyst_cpu_busy_pct,
567 .maxlen = sizeof(unsigned int) * NR_CPUS,
568 .mode = 0644,
569 .proc_handler = sched_busy_hyst_handler,
570 .extra1 = SYSCTL_ZERO,
571 .extra2 = &one_hundred,
572 },
573 {
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700574 .procname = "sched_ravg_window_nr_ticks",
575 .data = &sysctl_sched_ravg_window_nr_ticks,
576 .maxlen = sizeof(unsigned int),
577 .mode = 0644,
578 .proc_handler = sched_ravg_window_handler,
579 },
Satya Durga Srinivasu Prabhalad7a8a672018-11-14 17:01:12 -0800580 {
Lingutla Chandrasekhar609fb2b2019-12-04 14:04:20 +0530581 .procname = "sched_dynamic_ravg_window_enable",
582 .data = &sysctl_sched_dynamic_ravg_window_enable,
583 .maxlen = sizeof(unsigned int),
584 .mode = 0644,
585 .proc_handler = proc_dointvec_minmax,
586 .extra1 = SYSCTL_ZERO,
587 .extra2 = SYSCTL_ONE,
588 },
589 {
Satya Durga Srinivasu Prabhalad7a8a672018-11-14 17:01:12 -0800590 .procname = "sched_upmigrate",
591 .data = &sysctl_sched_capacity_margin_up,
592 .maxlen = sizeof(unsigned int) * MAX_MARGIN_LEVELS,
593 .mode = 0644,
594 .proc_handler = sched_updown_migrate_handler,
595 },
596 {
597 .procname = "sched_downmigrate",
598 .data = &sysctl_sched_capacity_margin_down,
599 .maxlen = sizeof(unsigned int) * MAX_MARGIN_LEVELS,
600 .mode = 0644,
601 .proc_handler = sched_updown_migrate_handler,
602 },
Lingutla Chandrasekhar50a92952020-01-08 10:30:04 +0530603 {
604 .procname = "sched_prefer_spread",
605 .data = &sysctl_sched_prefer_spread,
606 .maxlen = sizeof(unsigned int),
607 .mode = 0644,
608 .proc_handler = proc_dointvec_minmax,
609 .extra1 = SYSCTL_ZERO,
Satya Durga Srinivasu Prabhala611e7f22020-06-03 20:23:34 -0700610 .extra2 = &four,
Lingutla Chandrasekhar50a92952020-01-08 10:30:04 +0530611 },
Tengfei Fan7a8045d2020-04-21 09:01:51 +0800612 {
613 .procname = "walt_rtg_cfs_boost_prio",
614 .data = &sysctl_walt_rtg_cfs_boost_prio,
615 .maxlen = sizeof(unsigned int),
616 .mode = 0644,
617 .proc_handler = proc_dointvec_minmax,
618 .extra1 = &min_cfs_boost_prio,
619 .extra2 = &max_cfs_boost_prio,
620 },
Pavankumar Kondeti2c80b142020-08-12 09:36:11 +0530621 {
Pavankumar Kondetieb115782020-09-07 09:35:49 +0530622 .procname = "walt_low_latency_task_threshold",
623 .data = &sysctl_walt_low_latency_task_threshold,
Pavankumar Kondeti2c80b142020-08-12 09:36:11 +0530624 .maxlen = sizeof(unsigned int),
625 .mode = 0644,
626 .proc_handler = proc_dointvec_minmax,
627 .extra1 = SYSCTL_ZERO,
Pavankumar Kondetieb115782020-09-07 09:35:49 +0530628 .extra2 = &one_thousand,
Pavankumar Kondeti2c80b142020-08-12 09:36:11 +0530629 },
Biao Longe8f61132021-01-20 10:16:58 +0800630 {
631 .procname = "sched_sync_hint_enable",
632 .data = &sysctl_sched_sync_hint_enable,
633 .maxlen = sizeof(unsigned int),
634 .mode = 0644,
635 .proc_handler = proc_dointvec,
636 },
Lingutla Chandrasekhar7214dad2021-07-07 12:18:57 +0530637 {
638 .procname = "sched_cpu_high_irqload",
639 .data = &sysctl_walt_cpu_high_irqload,
640 .maxlen = sizeof(unsigned int),
641 .mode = 0644,
642 .proc_handler = walt_high_irqload_handler,
643 .extra1 = &fifty,
644 .extra2 = &one_hundred,
645 },
646
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -0700647#endif
Biao Longf1627cb2020-09-02 16:52:05 +0800648 {
649 .procname = "sched_force_lb_enable",
650 .data = &sysctl_sched_force_lb_enable,
651 .maxlen = sizeof(unsigned int),
652 .mode = 0644,
653 .proc_handler = proc_dointvec_minmax,
654 .extra1 = SYSCTL_ZERO,
655 .extra2 = SYSCTL_ONE,
656 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200657#ifdef CONFIG_SCHED_DEBUG
658 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100659 .procname = "sched_min_granularity_ns",
660 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200661 .maxlen = sizeof(unsigned int),
662 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800663 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100664 .extra1 = &min_sched_granularity_ns,
665 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200666 },
667 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200668 .procname = "sched_latency_ns",
669 .data = &sysctl_sched_latency,
670 .maxlen = sizeof(unsigned int),
671 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800672 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200673 .extra1 = &min_sched_granularity_ns,
674 .extra2 = &max_sched_granularity_ns,
675 },
676 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200677 .procname = "sched_wakeup_granularity_ns",
678 .data = &sysctl_sched_wakeup_granularity,
679 .maxlen = sizeof(unsigned int),
680 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800681 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200682 .extra1 = &min_wakeup_granularity_ns,
683 .extra2 = &max_wakeup_granularity_ns,
684 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200685#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200686 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100687 .procname = "sched_tunable_scaling",
688 .data = &sysctl_sched_tunable_scaling,
689 .maxlen = sizeof(enum sched_tunable_scaling),
690 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800691 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100692 .extra1 = &min_sched_tunable_scaling,
693 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200694 },
695 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900696 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200697 .data = &sysctl_sched_migration_cost,
698 .maxlen = sizeof(unsigned int),
699 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800700 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200701 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100702 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100703 .procname = "sched_nr_migrate",
704 .data = &sysctl_sched_nr_migrate,
705 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100706 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800707 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100708 },
Mel Gormancb251762016-02-05 09:08:36 +0000709#ifdef CONFIG_SCHEDSTATS
710 {
711 .procname = "sched_schedstats",
712 .data = NULL,
713 .maxlen = sizeof(unsigned int),
714 .mode = 0644,
715 .proc_handler = sysctl_schedstats,
Matteo Croceeec48442019-07-18 15:58:50 -0700716 .extra1 = SYSCTL_ZERO,
717 .extra2 = SYSCTL_ONE,
Mel Gormancb251762016-02-05 09:08:36 +0000718 },
719#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200720#endif /* CONFIG_SMP */
721#ifdef CONFIG_NUMA_BALANCING
722 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200723 .procname = "numa_balancing_scan_delay_ms",
724 .data = &sysctl_numa_balancing_scan_delay,
725 .maxlen = sizeof(unsigned int),
726 .mode = 0644,
727 .proc_handler = proc_dointvec,
728 },
729 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200730 .procname = "numa_balancing_scan_period_min_ms",
731 .data = &sysctl_numa_balancing_scan_period_min,
732 .maxlen = sizeof(unsigned int),
733 .mode = 0644,
734 .proc_handler = proc_dointvec,
735 },
736 {
737 .procname = "numa_balancing_scan_period_max_ms",
738 .data = &sysctl_numa_balancing_scan_period_max,
739 .maxlen = sizeof(unsigned int),
740 .mode = 0644,
741 .proc_handler = proc_dointvec,
742 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200743 {
744 .procname = "numa_balancing_scan_size_mb",
745 .data = &sysctl_numa_balancing_scan_size,
746 .maxlen = sizeof(unsigned int),
747 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400748 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700749 .extra1 = SYSCTL_ONE,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200750 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100751 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800752 .procname = "numa_balancing",
753 .data = NULL, /* filled in by handler */
754 .maxlen = sizeof(unsigned int),
755 .mode = 0644,
756 .proc_handler = sysctl_numa_balancing,
Matteo Croceeec48442019-07-18 15:58:50 -0700757 .extra1 = SYSCTL_ZERO,
758 .extra2 = SYSCTL_ONE,
Andi Kleen54a43d52014-01-23 15:53:13 -0800759 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200760#endif /* CONFIG_NUMA_BALANCING */
761#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200762 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100763 .procname = "sched_rt_period_us",
764 .data = &sysctl_sched_rt_period,
765 .maxlen = sizeof(unsigned int),
766 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800767 .proc_handler = sched_rt_handler,
Cyril Hrubisd2fc4132023-10-02 13:55:51 +0200768 .extra1 = SYSCTL_ONE,
769 .extra2 = SYSCTL_INT_MAX,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100770 },
771 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100772 .procname = "sched_rt_runtime_us",
773 .data = &sysctl_sched_rt_runtime,
774 .maxlen = sizeof(int),
775 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800776 .proc_handler = sched_rt_handler,
Cyril Hrubisd2fc4132023-10-02 13:55:51 +0200777 .extra1 = &neg_one,
778 .extra2 = SYSCTL_INT_MAX,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100779 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600780 {
781 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800782 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600783 .maxlen = sizeof(int),
784 .mode = 0644,
785 .proc_handler = sched_rr_handler,
786 },
Patrick Bellasie8f14172019-06-21 09:42:05 +0100787#ifdef CONFIG_UCLAMP_TASK
788 {
789 .procname = "sched_util_clamp_min",
790 .data = &sysctl_sched_uclamp_util_min,
791 .maxlen = sizeof(unsigned int),
792 .mode = 0644,
793 .proc_handler = sysctl_sched_uclamp_handler,
794 },
795 {
796 .procname = "sched_util_clamp_max",
797 .data = &sysctl_sched_uclamp_util_max,
798 .maxlen = sizeof(unsigned int),
799 .mode = 0644,
800 .proc_handler = sysctl_sched_uclamp_handler,
801 },
802#endif
Mike Galbraith5091faa2010-11-30 14:18:03 +0100803#ifdef CONFIG_SCHED_AUTOGROUP
804 {
805 .procname = "sched_autogroup_enabled",
806 .data = &sysctl_sched_autogroup_enabled,
807 .maxlen = sizeof(unsigned int),
808 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800809 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700810 .extra1 = SYSCTL_ZERO,
811 .extra2 = SYSCTL_ONE,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100812 },
813#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700814#ifdef CONFIG_CFS_BANDWIDTH
815 {
816 .procname = "sched_cfs_bandwidth_slice_us",
817 .data = &sysctl_sched_cfs_bandwidth_slice,
818 .maxlen = sizeof(unsigned int),
819 .mode = 0644,
820 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -0700821 .extra1 = SYSCTL_ONE,
Paul Turnerec12cb72011-07-21 09:43:30 -0700822 },
823#endif
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000824#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
825 {
826 .procname = "sched_energy_aware",
827 .data = &sysctl_sched_energy_aware,
828 .maxlen = sizeof(unsigned int),
829 .mode = 0644,
830 .proc_handler = sched_energy_aware_handler,
Matteo Croceeec48442019-07-18 15:58:50 -0700831 .extra1 = SYSCTL_ZERO,
832 .extra2 = SYSCTL_ONE,
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000833 },
834#endif
Satya Durga Srinivasu Prabhala93f140f2019-09-17 11:33:01 -0700835#ifdef CONFIG_SCHED_WALT
836 {
837 .procname = "sched_lib_name",
838 .data = sched_lib_name,
839 .maxlen = LIB_PATH_LENGTH,
840 .mode = 0644,
841 .proc_handler = proc_dostring,
842 },
843 {
844 .procname = "sched_lib_mask_force",
845 .data = &sched_lib_mask_force,
846 .maxlen = sizeof(unsigned int),
847 .mode = 0644,
848 .proc_handler = proc_douintvec_minmax,
849 .extra1 = SYSCTL_ZERO,
850 .extra2 = &two_hundred_fifty_five,
851 },
852#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700853#ifdef CONFIG_PROVE_LOCKING
854 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700855 .procname = "prove_locking",
856 .data = &prove_locking,
857 .maxlen = sizeof(int),
858 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800859 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700860 },
861#endif
862#ifdef CONFIG_LOCK_STAT
863 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700864 .procname = "lock_stat",
865 .data = &lock_stat,
866 .maxlen = sizeof(int),
867 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800868 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700869 },
870#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200871 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 .procname = "panic",
873 .data = &panic_timeout,
874 .maxlen = sizeof(int),
875 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800876 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 },
Alex Kelly046d6622012-10-04 17:15:23 -0700878#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 .procname = "core_uses_pid",
881 .data = &core_uses_pid,
882 .maxlen = sizeof(int),
883 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800884 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 },
886 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 .procname = "core_pattern",
888 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700889 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700891 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 },
Neil Hormana2939802009-09-23 15:56:56 -0700893 {
Neil Hormana2939802009-09-23 15:56:56 -0700894 .procname = "core_pipe_limit",
895 .data = &core_pipe_limit,
896 .maxlen = sizeof(unsigned int),
897 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800898 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700899 },
Alex Kelly046d6622012-10-04 17:15:23 -0700900#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800901#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700904 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800905 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800906 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700908 {
909 .procname = "sysctl_writes_strict",
910 .data = &sysctl_writes_strict,
911 .maxlen = sizeof(int),
912 .mode = 0644,
913 .proc_handler = proc_dointvec_minmax,
914 .extra1 = &neg_one,
Matteo Croceeec48442019-07-18 15:58:50 -0700915 .extra2 = SYSCTL_ONE,
Kees Cookf4aacea2014-06-06 14:37:19 -0700916 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800917#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100918#ifdef CONFIG_LATENCYTOP
919 {
920 .procname = "latencytop",
921 .data = &latencytop_enabled,
922 .maxlen = sizeof(int),
923 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000924 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100925 },
926#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927#ifdef CONFIG_BLK_DEV_INITRD
928 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 .procname = "real-root-dev",
930 .data = &real_root_dev,
931 .maxlen = sizeof(int),
932 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800933 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 },
935#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700936 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700937 .procname = "print-fatal-signals",
938 .data = &print_fatal_signals,
939 .maxlen = sizeof(int),
940 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800941 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700942 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700943#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 .procname = "reboot-cmd",
946 .data = reboot_command,
947 .maxlen = 256,
948 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800949 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 },
951 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 .procname = "stop-a",
953 .data = &stop_a_enabled,
954 .maxlen = sizeof (int),
955 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800956 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 },
958 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 .procname = "scons-poweroff",
960 .data = &scons_pwroff,
961 .maxlen = sizeof (int),
962 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800963 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 },
965#endif
David S. Miller08714202008-11-16 23:49:24 -0800966#ifdef CONFIG_SPARC64
967 {
David S. Miller08714202008-11-16 23:49:24 -0800968 .procname = "tsb-ratio",
969 .data = &sysctl_tsb_ratio,
970 .maxlen = sizeof (int),
971 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800972 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800973 },
974#endif
Helge Dellerb67114d2019-10-04 13:10:09 +0200975#ifdef CONFIG_PARISC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 .procname = "soft-power",
978 .data = &pwrsw_enabled,
979 .maxlen = sizeof (int),
980 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800981 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530983#endif
984#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 .procname = "unaligned-trap",
987 .data = &unaligned_enabled,
988 .maxlen = sizeof (int),
989 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800990 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 },
992#endif
993 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 .procname = "ctrl-alt-del",
995 .data = &C_A_D,
996 .maxlen = sizeof(int),
997 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800998 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 },
Steven Rostedt606576c2008-10-06 19:06:12 -04001000#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +02001001 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +02001002 .procname = "ftrace_enabled",
1003 .data = &ftrace_enabled,
1004 .maxlen = sizeof(int),
1005 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001006 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +02001007 },
1008#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -05001009#ifdef CONFIG_STACK_TRACER
1010 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -05001011 .procname = "stack_tracer_enabled",
1012 .data = &stack_tracer_enabled,
1013 .maxlen = sizeof(int),
1014 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001015 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -05001016 },
1017#endif
Steven Rostedt944ac422008-10-23 19:26:08 -04001018#ifdef CONFIG_TRACING
1019 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +01001020 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -04001021 .data = &ftrace_dump_on_oops,
1022 .maxlen = sizeof(int),
1023 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001024 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -04001025 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -04001026 {
1027 .procname = "traceoff_on_warning",
1028 .data = &__disable_trace_on_warning,
1029 .maxlen = sizeof(__disable_trace_on_warning),
1030 .mode = 0644,
1031 .proc_handler = proc_dointvec,
1032 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -05001033 {
1034 .procname = "tracepoint_printk",
1035 .data = &tracepoint_printk,
1036 .maxlen = sizeof(tracepoint_printk),
1037 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -05001038 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -05001039 },
Steven Rostedt944ac422008-10-23 19:26:08 -04001040#endif
Dave Young2965faa2015-09-09 15:38:55 -07001041#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -08001042 {
1043 .procname = "kexec_load_disabled",
1044 .data = &kexec_load_disabled,
1045 .maxlen = sizeof(int),
1046 .mode = 0644,
1047 /* only handle a transition from default "0" to "1" */
1048 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001049 .extra1 = SYSCTL_ONE,
1050 .extra2 = SYSCTL_ONE,
Kees Cook79847542014-01-23 15:55:59 -08001051 },
1052#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +02001053#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 .procname = "modprobe",
1056 .data = &modprobe_path,
1057 .maxlen = KMOD_PATH_LEN,
1058 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001059 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 },
Kees Cook3d433212009-04-02 15:49:29 -07001061 {
Kees Cook3d433212009-04-02 15:49:29 -07001062 .procname = "modules_disabled",
1063 .data = &modules_disabled,
1064 .maxlen = sizeof(int),
1065 .mode = 0644,
1066 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -08001067 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001068 .extra1 = SYSCTL_ONE,
1069 .extra2 = SYSCTL_ONE,
Kees Cook3d433212009-04-02 15:49:29 -07001070 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071#endif
Michael Marineau86d56132014-04-10 14:09:31 -07001072#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +01001075 .data = &uevent_helper,
1076 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001078 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 },
Michael Marineau86d56132014-04-10 14:09:31 -07001080#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081#ifdef CONFIG_CHR_DEV_SG
1082 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 .procname = "sg-big-buff",
1084 .data = &sg_big_buff,
1085 .maxlen = sizeof (int),
1086 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001087 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 },
1089#endif
1090#ifdef CONFIG_BSD_PROCESS_ACCT
1091 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 .procname = "acct",
1093 .data = &acct_parm,
1094 .maxlen = 3*sizeof(int),
1095 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001096 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 },
1098#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099#ifdef CONFIG_MAGIC_SYSRQ
1100 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -08001102 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 .maxlen = sizeof (int),
1104 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -07001105 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 },
1107#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -07001108#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001111 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 .maxlen = sizeof (int),
1113 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001114 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -07001116#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -07001119 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 .maxlen = sizeof(int),
1121 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -07001122 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 },
1124 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 .procname = "random",
1126 .mode = 0555,
1127 .child = random_table,
1128 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 {
Eric Paris17f60a72011-04-01 17:07:50 -04001130 .procname = "usermodehelper",
1131 .mode = 0555,
1132 .child = usermodehelper_table,
1133 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -08001134#ifdef CONFIG_FW_LOADER_USER_HELPER
1135 {
1136 .procname = "firmware_config",
1137 .mode = 0555,
1138 .child = firmware_config_table,
1139 },
1140#endif
Eric Paris17f60a72011-04-01 17:07:50 -04001141 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 .procname = "overflowuid",
1143 .data = &overflowuid,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001146 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 .extra1 = &minolduid,
1148 .extra2 = &maxolduid,
1149 },
1150 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 .procname = "overflowgid",
1152 .data = &overflowgid,
1153 .maxlen = sizeof(int),
1154 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001155 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 .extra1 = &minolduid,
1157 .extra2 = &maxolduid,
1158 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -08001159#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160#ifdef CONFIG_MATHEMU
1161 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 .procname = "ieee_emulation_warnings",
1163 .data = &sysctl_ieee_emulation_warnings,
1164 .maxlen = sizeof(int),
1165 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001166 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 },
1168#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +02001171 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 .maxlen = sizeof(int),
1173 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001174 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 },
1176#endif
1177 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 .procname = "pid_max",
1179 .data = &pid_max,
1180 .maxlen = sizeof (int),
1181 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001182 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 .extra1 = &pid_max_min,
1184 .extra2 = &pid_max_max,
1185 },
1186 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 .procname = "panic_on_oops",
1188 .data = &panic_on_oops,
1189 .maxlen = sizeof(int),
1190 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001191 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 },
Feng Tang81c9d432019-01-03 15:28:20 -08001193 {
1194 .procname = "panic_print",
1195 .data = &panic_print,
1196 .maxlen = sizeof(unsigned long),
1197 .mode = 0644,
1198 .proc_handler = proc_doulongvec_minmax,
1199 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -08001200#if defined CONFIG_PRINTK
1201 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -08001202 .procname = "printk",
1203 .data = &console_loglevel,
1204 .maxlen = 4*sizeof(int),
1205 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001206 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -08001207 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -07001210 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 .maxlen = sizeof(int),
1212 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001213 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 },
1215 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -07001217 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 .maxlen = sizeof(int),
1219 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001220 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 },
Dave Youngaf913222009-09-22 16:43:33 -07001222 {
Dave Youngaf913222009-09-22 16:43:33 -07001223 .procname = "printk_delay",
1224 .data = &printk_delay_msec,
1225 .maxlen = sizeof(int),
1226 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001227 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001228 .extra1 = SYSCTL_ZERO,
Dave Youngaf913222009-09-22 16:43:33 -07001229 .extra2 = &ten_thousand,
1230 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 {
Borislav Petkov750afe72016-08-02 14:04:07 -07001232 .procname = "printk_devkmsg",
1233 .data = devkmsg_log_str,
1234 .maxlen = DEVKMSG_STR_MAX_SIZE,
1235 .mode = 0644,
1236 .proc_handler = devkmsg_sysctl_set_loglvl,
1237 },
1238 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -08001239 .procname = "dmesg_restrict",
1240 .data = &dmesg_restrict,
1241 .maxlen = sizeof(int),
1242 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -07001243 .proc_handler = proc_dointvec_minmax_sysadmin,
Matteo Croceeec48442019-07-18 15:58:50 -07001244 .extra1 = SYSCTL_ZERO,
1245 .extra2 = SYSCTL_ONE,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -08001246 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -08001247 {
1248 .procname = "kptr_restrict",
1249 .data = &kptr_restrict,
1250 .maxlen = sizeof(int),
1251 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -07001252 .proc_handler = proc_dointvec_minmax_sysadmin,
Matteo Croceeec48442019-07-18 15:58:50 -07001253 .extra1 = SYSCTL_ZERO,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -08001254 .extra2 = &two,
1255 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -08001256#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -08001257 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 .procname = "ngroups_max",
1259 .data = &ngroups_max,
1260 .maxlen = sizeof (int),
1261 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001262 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 },
Dan Ballard73efc032011-10-31 17:11:20 -07001264 {
1265 .procname = "cap_last_cap",
1266 .data = (void *)&cap_last_cap,
1267 .maxlen = sizeof(int),
1268 .mode = 0444,
1269 .proc_handler = proc_dointvec,
1270 },
Don Zickus58687ac2010-05-07 17:11:44 -04001271#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -05001272 {
Don Zickus58687ac2010-05-07 17:11:44 -04001273 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +02001274 .data = &watchdog_user_enabled,
1275 .maxlen = sizeof(int),
1276 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -07001277 .proc_handler = proc_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -07001278 .extra1 = SYSCTL_ZERO,
1279 .extra2 = SYSCTL_ONE,
Don Zickus58687ac2010-05-07 17:11:44 -04001280 },
1281 {
1282 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -07001283 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -04001284 .maxlen = sizeof(int),
1285 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -07001286 .proc_handler = proc_watchdog_thresh,
Matteo Croceeec48442019-07-18 15:58:50 -07001287 .extra1 = SYSCTL_ZERO,
Don Zickus58687ac2010-05-07 17:11:44 -04001288 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -05001289 },
Don Zickus2508ce12010-05-07 17:11:46 -04001290 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -07001291 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +02001292 .data = &nmi_watchdog_user_enabled,
1293 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +02001294 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -07001295 .proc_handler = proc_nmi_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -07001296 .extra1 = SYSCTL_ZERO,
1297 .extra2 = SYSCTL_ONE,
Ulrich Obergfell195daf62015-04-14 15:44:13 -07001298 },
1299 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -07001300 .procname = "watchdog_cpumask",
1301 .data = &watchdog_cpumask_bits,
1302 .maxlen = NR_CPUS,
1303 .mode = 0644,
1304 .proc_handler = proc_watchdog_cpumask,
1305 },
1306#ifdef CONFIG_SOFTLOCKUP_DETECTOR
1307 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -07001308 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +02001309 .data = &soft_watchdog_user_enabled,
1310 .maxlen = sizeof(int),
1311 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -07001312 .proc_handler = proc_soft_watchdog,
Matteo Croceeec48442019-07-18 15:58:50 -07001313 .extra1 = SYSCTL_ZERO,
1314 .extra2 = SYSCTL_ONE,
Ulrich Obergfell195daf62015-04-14 15:44:13 -07001315 },
1316 {
Don Zickus2508ce12010-05-07 17:11:46 -04001317 .procname = "softlockup_panic",
1318 .data = &softlockup_panic,
1319 .maxlen = sizeof(int),
1320 .mode = 0644,
1321 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001322 .extra1 = SYSCTL_ZERO,
1323 .extra2 = SYSCTL_ONE,
Don Zickus2508ce12010-05-07 17:11:46 -04001324 },
Aaron Tomlined235872014-06-23 13:22:05 -07001325#ifdef CONFIG_SMP
1326 {
1327 .procname = "softlockup_all_cpu_backtrace",
1328 .data = &sysctl_softlockup_all_cpu_backtrace,
1329 .maxlen = sizeof(int),
1330 .mode = 0644,
1331 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001332 .extra1 = SYSCTL_ZERO,
1333 .extra2 = SYSCTL_ONE,
Aaron Tomlined235872014-06-23 13:22:05 -07001334 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -07001335#endif /* CONFIG_SMP */
1336#endif
1337#ifdef CONFIG_HARDLOCKUP_DETECTOR
1338 {
1339 .procname = "hardlockup_panic",
1340 .data = &hardlockup_panic,
1341 .maxlen = sizeof(int),
1342 .mode = 0644,
1343 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001344 .extra1 = SYSCTL_ZERO,
1345 .extra2 = SYSCTL_ONE,
Nicholas Piggin05a4a952017-07-12 14:35:46 -07001346 },
1347#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -08001348 {
1349 .procname = "hardlockup_all_cpu_backtrace",
1350 .data = &sysctl_hardlockup_all_cpu_backtrace,
1351 .maxlen = sizeof(int),
1352 .mode = 0644,
1353 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001354 .extra1 = SYSCTL_ZERO,
1355 .extra2 = SYSCTL_ONE,
Jiri Kosina55537872015-11-05 18:44:41 -08001356 },
Aaron Tomlined235872014-06-23 13:22:05 -07001357#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -05001358#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -07001359#endif
1360
Don Zickus5dc30552010-11-29 17:07:17 -05001361#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1362 {
1363 .procname = "unknown_nmi_panic",
1364 .data = &unknown_nmi_panic,
1365 .maxlen = sizeof (int),
1366 .mode = 0644,
1367 .proc_handler = proc_dointvec,
1368 },
Don Zickus504d7cf2010-02-12 17:19:19 -05001369#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370#if defined(CONFIG_X86)
1371 {
Don Zickus8da5add2006-09-26 10:52:27 +02001372 .procname = "panic_on_unrecovered_nmi",
1373 .data = &panic_on_unrecovered_nmi,
1374 .maxlen = sizeof(int),
1375 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001376 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001377 },
1378 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001379 .procname = "panic_on_io_nmi",
1380 .data = &panic_on_io_nmi,
1381 .maxlen = sizeof(int),
1382 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001383 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001384 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001385#ifdef CONFIG_DEBUG_STACKOVERFLOW
1386 {
1387 .procname = "panic_on_stackoverflow",
1388 .data = &sysctl_panic_on_stackoverflow,
1389 .maxlen = sizeof(int),
1390 .mode = 0644,
1391 .proc_handler = proc_dointvec,
1392 },
1393#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001394 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 .procname = "bootloader_type",
1396 .data = &bootloader_type,
1397 .maxlen = sizeof (int),
1398 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001399 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001401 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001402 .procname = "bootloader_version",
1403 .data = &bootloader_version,
1404 .maxlen = sizeof (int),
1405 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001406 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001407 },
1408 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001409 .procname = "io_delay_type",
1410 .data = &io_delay_type,
1411 .maxlen = sizeof(int),
1412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001413 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001414 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001416#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 .procname = "randomize_va_space",
1419 .data = &randomize_va_space,
1420 .maxlen = sizeof(int),
1421 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001422 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001424#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001425#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001426 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001427 .procname = "spin_retry",
1428 .data = &spin_retry,
1429 .maxlen = sizeof (int),
1430 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001431 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001432 },
1433#endif
Len Brown673d5b42007-07-28 03:33:16 -04001434#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001435 {
Pavel Machekc255d842006-02-20 18:27:58 -08001436 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001437 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001438 .maxlen = sizeof (unsigned long),
1439 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001440 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001441 },
1442#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301443#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001444 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001445 .procname = "ignore-unaligned-usertrap",
1446 .data = &no_unaligned_warning,
1447 .maxlen = sizeof (int),
1448 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001449 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001450 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301451#endif
1452#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001453 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001454 .procname = "unaligned-dump-stack",
1455 .data = &unaligned_dump_stack,
1456 .maxlen = sizeof (int),
1457 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001458 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001459 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001460#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001461#ifdef CONFIG_DETECT_HUNG_TASK
1462 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001463 .procname = "hung_task_panic",
1464 .data = &sysctl_hung_task_panic,
1465 .maxlen = sizeof(int),
1466 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001467 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001468 .extra1 = SYSCTL_ZERO,
1469 .extra2 = SYSCTL_ONE,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001470 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001471 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001472 .procname = "hung_task_check_count",
1473 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001474 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001475 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001476 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001477 .extra1 = SYSCTL_ZERO,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001478 },
1479 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001480 .procname = "hung_task_timeout_secs",
1481 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001482 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001483 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001484 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001485 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001486 },
1487 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001488 .procname = "hung_task_check_interval_secs",
1489 .data = &sysctl_hung_task_check_interval_secs,
1490 .maxlen = sizeof(unsigned long),
1491 .mode = 0644,
1492 .proc_handler = proc_dohung_task_timeout_secs,
1493 .extra2 = &hung_task_timeout_max,
1494 },
1495 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001496 .procname = "hung_task_warnings",
1497 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001498 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001499 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001500 .proc_handler = proc_dointvec_minmax,
1501 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001502 },
Imran Khandf5442d2017-09-18 15:48:30 +05301503 {
1504 .procname = "hung_task_selective_monitoring",
1505 .data = &sysctl_hung_task_selective_monitoring,
1506 .maxlen = sizeof(int),
1507 .mode = 0644,
1508 .proc_handler = proc_dointvec_minmax,
1509 .extra1 = SYSCTL_ZERO,
1510 .extra2 = SYSCTL_ONE,
1511 },
1512
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001513#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001514#ifdef CONFIG_RT_MUTEXES
1515 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001516 .procname = "max_lock_depth",
1517 .data = &max_lock_depth,
1518 .maxlen = sizeof(int),
1519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001520 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001521 },
1522#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001523 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001524 .procname = "poweroff_cmd",
1525 .data = &poweroff_cmd,
1526 .maxlen = POWEROFF_CMD_PATH_LEN,
1527 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001528 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001529 },
David Howells0b77f5b2008-04-29 01:01:32 -07001530#ifdef CONFIG_KEYS
1531 {
David Howells0b77f5b2008-04-29 01:01:32 -07001532 .procname = "keys",
1533 .mode = 0555,
1534 .child = key_sysctls,
1535 },
1536#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001537#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001538 /*
1539 * User-space scripts rely on the existence of this file
1540 * as a feature check for perf_events being enabled.
1541 *
1542 * So it's an ABI, do not remove!
1543 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001544 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001545 .procname = "perf_event_paranoid",
1546 .data = &sysctl_perf_event_paranoid,
1547 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001549 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001550 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001551 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001552 .procname = "perf_event_mlock_kb",
1553 .data = &sysctl_perf_event_mlock,
1554 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001556 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001557 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001558 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001559 .procname = "perf_event_max_sample_rate",
1560 .data = &sysctl_perf_event_sample_rate,
1561 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001562 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001563 .proc_handler = perf_proc_update_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001564 .extra1 = SYSCTL_ONE,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001565 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001566 {
1567 .procname = "perf_cpu_time_max_percent",
1568 .data = &sysctl_perf_cpu_time_max_percent,
1569 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1570 .mode = 0644,
1571 .proc_handler = perf_cpu_time_max_percent_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001572 .extra1 = SYSCTL_ZERO,
Dave Hansen14c63f12013-06-21 08:51:36 -07001573 .extra2 = &one_hundred,
1574 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001575 {
1576 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001577 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001578 .maxlen = sizeof(sysctl_perf_event_max_stack),
1579 .mode = 0644,
1580 .proc_handler = perf_event_max_stack_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001581 .extra1 = SYSCTL_ZERO,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001582 .extra2 = &six_hundred_forty_kb,
1583 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001584 {
1585 .procname = "perf_event_max_contexts_per_stack",
1586 .data = &sysctl_perf_event_max_contexts_per_stack,
1587 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1588 .mode = 0644,
1589 .proc_handler = perf_event_max_stack_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001590 .extra1 = SYSCTL_ZERO,
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001591 .extra2 = &one_thousand,
1592 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001593#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001594 {
1595 .procname = "panic_on_warn",
1596 .data = &panic_on_warn,
1597 .maxlen = sizeof(int),
1598 .mode = 0644,
1599 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001600 .extra1 = SYSCTL_ZERO,
1601 .extra2 = SYSCTL_ONE,
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001602 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001603#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1604 {
1605 .procname = "timer_migration",
1606 .data = &sysctl_timer_migration,
1607 .maxlen = sizeof(unsigned int),
1608 .mode = 0644,
1609 .proc_handler = timer_migration_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001610 .extra1 = SYSCTL_ZERO,
1611 .extra2 = SYSCTL_ONE,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001612 },
1613#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001614#ifdef CONFIG_BPF_SYSCALL
1615 {
1616 .procname = "unprivileged_bpf_disabled",
1617 .data = &sysctl_unprivileged_bpf_disabled,
1618 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1619 .mode = 0644,
Daniel Borkmann508711c2021-05-11 22:35:17 +02001620 .proc_handler = bpf_unpriv_handler,
1621 .extra1 = SYSCTL_ZERO,
1622 .extra2 = &two,
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001623 },
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001624 {
1625 .procname = "bpf_stats_enabled",
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001626 .data = &bpf_stats_enabled_key.key,
1627 .maxlen = sizeof(bpf_stats_enabled_key),
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001628 .mode = 0644,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001629 .proc_handler = proc_do_static_key,
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001630 },
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001631#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001632#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1633 {
1634 .procname = "panic_on_rcu_stall",
1635 .data = &sysctl_panic_on_rcu_stall,
1636 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1637 .mode = 0644,
1638 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001639 .extra1 = SYSCTL_ZERO,
1640 .extra2 = SYSCTL_ONE,
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001641 },
1642#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001643#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1644 {
1645 .procname = "stack_erasing",
1646 .data = NULL,
1647 .maxlen = sizeof(int),
1648 .mode = 0600,
1649 .proc_handler = stack_erasing_sysctl,
Matteo Croceeec48442019-07-18 15:58:50 -07001650 .extra1 = SYSCTL_ZERO,
1651 .extra2 = SYSCTL_ONE,
Alexander Popov964c9df2018-08-17 01:17:03 +03001652 },
1653#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001654 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655};
1656
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001657static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 .procname = "overcommit_memory",
1660 .data = &sysctl_overcommit_memory,
1661 .maxlen = sizeof(sysctl_overcommit_memory),
1662 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001663 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001664 .extra1 = SYSCTL_ZERO,
Petr Holasekcb16e952011-03-23 16:43:09 -07001665 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 },
1667 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001668 .procname = "panic_on_oom",
1669 .data = &sysctl_panic_on_oom,
1670 .maxlen = sizeof(sysctl_panic_on_oom),
1671 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001672 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001673 .extra1 = SYSCTL_ZERO,
Petr Holasekcb16e952011-03-23 16:43:09 -07001674 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001675 },
1676 {
David Rientjesfe071d72007-10-16 23:25:56 -07001677 .procname = "oom_kill_allocating_task",
1678 .data = &sysctl_oom_kill_allocating_task,
1679 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1680 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001681 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001682 },
1683 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001684 .procname = "oom_dump_tasks",
1685 .data = &sysctl_oom_dump_tasks,
1686 .maxlen = sizeof(sysctl_oom_dump_tasks),
1687 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001688 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001689 },
1690 {
Charan Teja Reddy372242b2018-05-01 20:20:20 +05301691 .procname = "reap_mem_on_sigkill",
1692 .data = &sysctl_reap_mem_on_sigkill,
1693 .maxlen = sizeof(sysctl_reap_mem_on_sigkill),
1694 .mode = 0644,
1695 .proc_handler = proc_dointvec,
1696 },
1697 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 .procname = "overcommit_ratio",
1699 .data = &sysctl_overcommit_ratio,
1700 .maxlen = sizeof(sysctl_overcommit_ratio),
1701 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001702 .proc_handler = overcommit_ratio_handler,
1703 },
1704 {
1705 .procname = "overcommit_kbytes",
1706 .data = &sysctl_overcommit_kbytes,
1707 .maxlen = sizeof(sysctl_overcommit_kbytes),
1708 .mode = 0644,
1709 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 },
1711 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 .procname = "page-cluster",
1713 .data = &page_cluster,
1714 .maxlen = sizeof(int),
1715 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001716 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001717 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 },
1719 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 .procname = "dirty_background_ratio",
1721 .data = &dirty_background_ratio,
1722 .maxlen = sizeof(dirty_background_ratio),
1723 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001724 .proc_handler = dirty_background_ratio_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001725 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 .extra2 = &one_hundred,
1727 },
1728 {
David Rientjes2da02992009-01-06 14:39:31 -08001729 .procname = "dirty_background_bytes",
1730 .data = &dirty_background_bytes,
1731 .maxlen = sizeof(dirty_background_bytes),
1732 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001733 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001734 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001735 },
1736 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 .procname = "dirty_ratio",
1738 .data = &vm_dirty_ratio,
1739 .maxlen = sizeof(vm_dirty_ratio),
1740 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001741 .proc_handler = dirty_ratio_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001742 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 .extra2 = &one_hundred,
1744 },
1745 {
David Rientjes2da02992009-01-06 14:39:31 -08001746 .procname = "dirty_bytes",
1747 .data = &vm_dirty_bytes,
1748 .maxlen = sizeof(vm_dirty_bytes),
1749 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001750 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001751 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001752 },
1753 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001755 .data = &dirty_writeback_interval,
1756 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001758 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 },
1760 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001762 .data = &dirty_expire_interval,
1763 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001765 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001766 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 },
1768 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001769 .procname = "dirtytime_expire_seconds",
1770 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001771 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001772 .mode = 0644,
1773 .proc_handler = dirtytime_interval_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001774 .extra1 = SYSCTL_ZERO,
Theodore Ts'o1efff912015-03-17 12:23:32 -04001775 },
1776 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 .procname = "swappiness",
1778 .data = &vm_swappiness,
1779 .maxlen = sizeof(vm_swappiness),
1780 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001781 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001782 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 .extra2 = &one_hundred,
1784 },
Vinayak Menon39c6b7d2016-05-20 16:58:41 -07001785 {
1786 .procname = "want_old_faultaround_pte",
1787 .data = &want_old_faultaround_pte,
1788 .maxlen = sizeof(want_old_faultaround_pte),
1789 .mode = 0644,
1790 .proc_handler = proc_dointvec_minmax,
1791 .extra1 = SYSCTL_ZERO,
1792 .extra2 = SYSCTL_ONE,
1793 },
Muchun Song70433d92022-06-09 18:40:32 +08001794#ifdef CONFIG_NUMA
1795 {
1796 .procname = "numa_stat",
1797 .data = &sysctl_vm_numa_stat,
1798 .maxlen = sizeof(int),
1799 .mode = 0644,
1800 .proc_handler = sysctl_vm_numa_stat_handler,
1801 .extra1 = SYSCTL_ZERO,
1802 .extra2 = SYSCTL_ONE,
1803 },
1804#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001806 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001808 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 .maxlen = sizeof(unsigned long),
1810 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001811 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001812 },
1813#ifdef CONFIG_NUMA
1814 {
1815 .procname = "nr_hugepages_mempolicy",
1816 .data = NULL,
1817 .maxlen = sizeof(unsigned long),
1818 .mode = 0644,
1819 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001820 },
1821#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 .procname = "hugetlb_shm_group",
1824 .data = &sysctl_hugetlb_shm_group,
1825 .maxlen = sizeof(gid_t),
1826 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001827 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 },
Adam Litke54f9f802007-10-16 01:26:20 -07001829 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001830 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001831 .data = NULL,
1832 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001833 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001834 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001835 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836#endif
1837 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 .procname = "lowmem_reserve_ratio",
1839 .data = &sysctl_lowmem_reserve_ratio,
1840 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1841 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001842 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 },
1844 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001845 .procname = "drop_caches",
1846 .data = &sysctl_drop_caches,
1847 .maxlen = sizeof(int),
Johannes Weineread87f12019-11-30 17:56:08 -08001848 .mode = 0200,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001849 .proc_handler = drop_caches_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001850 .extra1 = SYSCTL_ONE,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001851 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001852 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001853#ifdef CONFIG_COMPACTION
1854 {
1855 .procname = "compact_memory",
1856 .data = &sysctl_compact_memory,
1857 .maxlen = sizeof(int),
1858 .mode = 0200,
1859 .proc_handler = sysctl_compaction_handler,
1860 },
Mel Gorman5e771902010-05-24 14:32:31 -07001861 {
1862 .procname = "extfrag_threshold",
1863 .data = &sysctl_extfrag_threshold,
1864 .maxlen = sizeof(int),
1865 .mode = 0644,
Matthew Wilcox6b7e5ca2019-03-05 15:43:41 -08001866 .proc_handler = proc_dointvec_minmax,
Mel Gorman5e771902010-05-24 14:32:31 -07001867 .extra1 = &min_extfrag_threshold,
1868 .extra2 = &max_extfrag_threshold,
1869 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001870 {
1871 .procname = "compact_unevictable_allowed",
1872 .data = &sysctl_compact_unevictable_allowed,
1873 .maxlen = sizeof(int),
1874 .mode = 0644,
1875 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07001876 .extra1 = SYSCTL_ZERO,
1877 .extra2 = SYSCTL_ONE,
Eric B Munson5bbe3542015-04-15 16:13:20 -07001878 },
Mel Gorman5e771902010-05-24 14:32:31 -07001879
Mel Gorman76ab0f52010-05-24 14:32:28 -07001880#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001881 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 .procname = "min_free_kbytes",
1883 .data = &min_free_kbytes,
1884 .maxlen = sizeof(min_free_kbytes),
1885 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001886 .proc_handler = min_free_kbytes_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001887 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001889 {
Mel Gorman1c308442018-12-28 00:35:52 -08001890 .procname = "watermark_boost_factor",
1891 .data = &watermark_boost_factor,
1892 .maxlen = sizeof(watermark_boost_factor),
1893 .mode = 0644,
1894 .proc_handler = watermark_boost_factor_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001895 .extra1 = SYSCTL_ZERO,
Mel Gorman1c308442018-12-28 00:35:52 -08001896 },
Buddy Lumpkin767f6472018-04-02 09:24:22 +00001897#ifdef CONFIG_MULTIPLE_KSWAPD
1898 {
1899 .procname = "kswapd_threads",
1900 .data = &kswapd_threads,
1901 .maxlen = sizeof(kswapd_threads),
1902 .mode = 0644,
1903 .proc_handler = kswapd_threads_sysctl_handler,
1904 .extra1 = SYSCTL_ONE,
1905 .extra2 = &max_kswapd_threads,
1906 },
1907#endif
Mel Gorman1c308442018-12-28 00:35:52 -08001908 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001909 .procname = "watermark_scale_factor",
1910 .data = &watermark_scale_factor,
1911 .maxlen = sizeof(watermark_scale_factor),
1912 .mode = 0644,
1913 .proc_handler = watermark_scale_factor_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001914 .extra1 = SYSCTL_ONE,
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001915 .extra2 = &one_thousand,
1916 },
1917 {
Rik van Riel92501cb2011-09-01 15:26:50 -04001918 .procname = "extra_free_kbytes",
1919 .data = &extra_free_kbytes,
1920 .maxlen = sizeof(extra_free_kbytes),
1921 .mode = 0644,
1922 .proc_handler = min_free_kbytes_sysctl_handler,
Greg Kroah-Hartman37766c22019-07-23 09:23:56 +02001923 .extra1 = SYSCTL_ZERO,
Rik van Riel92501cb2011-09-01 15:26:50 -04001924 },
1925 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001926 .procname = "percpu_pagelist_fraction",
1927 .data = &percpu_pagelist_fraction,
1928 .maxlen = sizeof(percpu_pagelist_fraction),
1929 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001930 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07001931 .extra1 = SYSCTL_ZERO,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001932 },
Linus Torvaldsc404e1e2020-09-13 14:05:35 -07001933 {
1934 .procname = "page_lock_unfairness",
1935 .data = &sysctl_page_lock_unfairness,
1936 .maxlen = sizeof(sysctl_page_lock_unfairness),
1937 .mode = 0644,
1938 .proc_handler = proc_dointvec_minmax,
1939 .extra1 = SYSCTL_ZERO,
1940 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941#ifdef CONFIG_MMU
1942 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 .procname = "max_map_count",
1944 .data = &sysctl_max_map_count,
1945 .maxlen = sizeof(sysctl_max_map_count),
1946 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001947 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001948 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001950#else
1951 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001952 .procname = "nr_trim_pages",
1953 .data = &sysctl_nr_trim_pages,
1954 .maxlen = sizeof(sysctl_nr_trim_pages),
1955 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001956 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001957 .extra1 = SYSCTL_ZERO,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001958 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959#endif
1960 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 .procname = "laptop_mode",
1962 .data = &laptop_mode,
1963 .maxlen = sizeof(laptop_mode),
1964 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001965 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 },
1967 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 .procname = "block_dump",
1969 .data = &block_dump,
1970 .maxlen = sizeof(block_dump),
1971 .mode = 0644,
Lin Fengacf0e7b2021-02-25 17:20:53 -08001972 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001973 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 },
1975 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 .procname = "vfs_cache_pressure",
1977 .data = &sysctl_vfs_cache_pressure,
1978 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1979 .mode = 0644,
Lin Fengacf0e7b2021-02-25 17:20:53 -08001980 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001981 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 },
Alexandre Ghiti67f39772019-09-23 15:38:47 -07001983#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1984 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 .procname = "legacy_va_layout",
1987 .data = &sysctl_legacy_va_layout,
1988 .maxlen = sizeof(sysctl_legacy_va_layout),
1989 .mode = 0644,
Lin Fengacf0e7b2021-02-25 17:20:53 -08001990 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07001991 .extra1 = SYSCTL_ZERO,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 },
1993#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001994#ifdef CONFIG_NUMA
1995 {
Christoph Lameter17436602006-01-18 17:42:32 -08001996 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001997 .data = &node_reclaim_mode,
1998 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001999 .mode = 0644,
Lin Fengacf0e7b2021-02-25 17:20:53 -08002000 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002001 .extra1 = SYSCTL_ZERO,
Christoph Lameter17436602006-01-18 17:42:32 -08002002 },
Christoph Lameter96146342006-07-03 00:24:13 -07002003 {
Christoph Lameter96146342006-07-03 00:24:13 -07002004 .procname = "min_unmapped_ratio",
2005 .data = &sysctl_min_unmapped_ratio,
2006 .maxlen = sizeof(sysctl_min_unmapped_ratio),
2007 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002008 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07002009 .extra1 = SYSCTL_ZERO,
Christoph Lameter96146342006-07-03 00:24:13 -07002010 .extra2 = &one_hundred,
2011 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07002012 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07002013 .procname = "min_slab_ratio",
2014 .data = &sysctl_min_slab_ratio,
2015 .maxlen = sizeof(sysctl_min_slab_ratio),
2016 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002017 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07002018 .extra1 = SYSCTL_ZERO,
Christoph Lameter0ff38492006-09-25 23:31:52 -07002019 .extra2 = &one_hundred,
2020 },
Christoph Lameter17436602006-01-18 17:42:32 -08002021#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07002022#ifdef CONFIG_SMP
2023 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07002024 .procname = "stat_interval",
2025 .data = &sysctl_stat_interval,
2026 .maxlen = sizeof(sysctl_stat_interval),
2027 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002028 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07002029 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07002030 {
2031 .procname = "stat_refresh",
2032 .data = NULL,
2033 .maxlen = 0,
2034 .mode = 0600,
2035 .proc_handler = vmstat_refresh,
2036 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07002037#endif
David Howells6e141542009-12-15 19:27:45 +00002038#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04002039 {
Eric Parised032182007-06-28 15:55:21 -04002040 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04002041 .data = &dac_mmap_min_addr,
2042 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04002043 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002044 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04002045 },
David Howells6e141542009-12-15 19:27:45 +00002046#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07002047#ifdef CONFIG_NUMA
2048 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07002049 .procname = "numa_zonelist_order",
2050 .data = &numa_zonelist_order,
2051 .maxlen = NUMA_ZONELIST_ORDER_LEN,
2052 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002053 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07002054 },
2055#endif
Al Viro2b8232c2007-10-13 08:16:04 +01002056#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09002057 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07002058 {
Ingo Molnare6e54942006-06-27 02:53:50 -07002059 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07002060#ifdef CONFIG_X86_32
2061 .data = &vdso32_enabled,
2062 .maxlen = sizeof(vdso32_enabled),
2063#else
Ingo Molnare6e54942006-06-27 02:53:50 -07002064 .data = &vdso_enabled,
2065 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07002066#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07002067 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002068 .proc_handler = proc_dointvec,
Matteo Croceeec48442019-07-18 15:58:50 -07002069 .extra1 = SYSCTL_ZERO,
Ingo Molnare6e54942006-06-27 02:53:50 -07002070 },
2071#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08002072#ifdef CONFIG_HIGHMEM
2073 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08002074 .procname = "highmem_is_dirtyable",
2075 .data = &vm_highmem_is_dirtyable,
2076 .maxlen = sizeof(vm_highmem_is_dirtyable),
2077 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002078 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002079 .extra1 = SYSCTL_ZERO,
2080 .extra2 = SYSCTL_ONE,
Bron Gondwana195cf4532008-02-04 22:29:20 -08002081 },
2082#endif
Andi Kleen6a460792009-09-16 11:50:15 +02002083#ifdef CONFIG_MEMORY_FAILURE
2084 {
Andi Kleen6a460792009-09-16 11:50:15 +02002085 .procname = "memory_failure_early_kill",
2086 .data = &sysctl_memory_failure_early_kill,
2087 .maxlen = sizeof(sysctl_memory_failure_early_kill),
2088 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002089 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002090 .extra1 = SYSCTL_ZERO,
2091 .extra2 = SYSCTL_ONE,
Andi Kleen6a460792009-09-16 11:50:15 +02002092 },
2093 {
Andi Kleen6a460792009-09-16 11:50:15 +02002094 .procname = "memory_failure_recovery",
2095 .data = &sysctl_memory_failure_recovery,
2096 .maxlen = sizeof(sysctl_memory_failure_recovery),
2097 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002098 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002099 .extra1 = SYSCTL_ZERO,
2100 .extra2 = SYSCTL_ONE,
Andi Kleen6a460792009-09-16 11:50:15 +02002101 },
2102#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07002103 {
2104 .procname = "user_reserve_kbytes",
2105 .data = &sysctl_user_reserve_kbytes,
2106 .maxlen = sizeof(sysctl_user_reserve_kbytes),
2107 .mode = 0644,
2108 .proc_handler = proc_doulongvec_minmax,
2109 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07002110 {
2111 .procname = "admin_reserve_kbytes",
2112 .data = &sysctl_admin_reserve_kbytes,
2113 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
2114 .mode = 0644,
2115 .proc_handler = proc_doulongvec_minmax,
2116 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08002117#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2118 {
2119 .procname = "mmap_rnd_bits",
2120 .data = &mmap_rnd_bits,
2121 .maxlen = sizeof(mmap_rnd_bits),
2122 .mode = 0600,
2123 .proc_handler = proc_dointvec_minmax,
2124 .extra1 = (void *)&mmap_rnd_bits_min,
2125 .extra2 = (void *)&mmap_rnd_bits_max,
2126 },
2127#endif
2128#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2129 {
2130 .procname = "mmap_rnd_compat_bits",
2131 .data = &mmap_rnd_compat_bits,
2132 .maxlen = sizeof(mmap_rnd_compat_bits),
2133 .mode = 0600,
2134 .proc_handler = proc_dointvec_minmax,
2135 .extra1 = (void *)&mmap_rnd_compat_bits_min,
2136 .extra2 = (void *)&mmap_rnd_compat_bits_max,
2137 },
2138#endif
Peter Xucefdca02019-05-13 17:16:41 -07002139#ifdef CONFIG_USERFAULTFD
2140 {
2141 .procname = "unprivileged_userfaultfd",
2142 .data = &sysctl_unprivileged_userfaultfd,
2143 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
2144 .mode = 0644,
2145 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002146 .extra1 = SYSCTL_ZERO,
2147 .extra2 = SYSCTL_ONE,
Peter Xucefdca02019-05-13 17:16:41 -07002148 },
2149#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07002150 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151};
2152
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002153static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 .procname = "inode-nr",
2156 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10002157 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04002159 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 },
2161 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 .procname = "inode-state",
2163 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10002164 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04002166 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 },
2168 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 .procname = "file-nr",
2170 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07002171 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002173 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 },
2175 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 .procname = "file-max",
2177 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07002178 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07002180 .proc_handler = proc_doulongvec_minmax,
Will Deacon9002b212019-04-05 18:39:38 -07002181 .extra1 = &zero_ul,
Christian Brauner32a5ad92019-03-07 16:29:43 -08002182 .extra2 = &long_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 },
2184 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08002185 .procname = "nr_open",
2186 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03002187 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08002188 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002189 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04002190 .extra1 = &sysctl_nr_open_min,
2191 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08002192 },
2193 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 .procname = "dentry-state",
2195 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10002196 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04002198 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 },
2200 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 .procname = "overflowuid",
2202 .data = &fs_overflowuid,
2203 .maxlen = sizeof(int),
2204 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002205 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 .extra1 = &minolduid,
2207 .extra2 = &maxolduid,
2208 },
2209 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 .procname = "overflowgid",
2211 .data = &fs_overflowgid,
2212 .maxlen = sizeof(int),
2213 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002214 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 .extra1 = &minolduid,
2216 .extra2 = &maxolduid,
2217 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02002218#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 .procname = "leases-enable",
2221 .data = &leases_enable,
2222 .maxlen = sizeof(int),
2223 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002224 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02002226#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227#ifdef CONFIG_DNOTIFY
2228 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 .procname = "dir-notify-enable",
2230 .data = &dir_notify_enable,
2231 .maxlen = sizeof(int),
2232 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002233 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 },
2235#endif
2236#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02002237#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 .procname = "lease-break-time",
2240 .data = &lease_break_time,
2241 .maxlen = sizeof(int),
2242 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002243 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02002245#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07002246#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 .procname = "aio-nr",
2249 .data = &aio_nr,
2250 .maxlen = sizeof(aio_nr),
2251 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002252 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 },
2254 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 .procname = "aio-max-nr",
2256 .data = &aio_max_nr,
2257 .maxlen = sizeof(aio_max_nr),
2258 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08002259 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07002261#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07002262#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04002263 {
Robert Love0399cb02005-07-13 12:38:18 -04002264 .procname = "inotify",
2265 .mode = 0555,
2266 .child = inotify_table,
2267 },
2268#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08002269#ifdef CONFIG_EPOLL
2270 {
2271 .procname = "epoll",
2272 .mode = 0555,
2273 .child = epoll_table,
2274 },
2275#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276#endif
Alan Coxd6e71142005-06-23 00:09:43 -07002277 {
Kees Cook800179c2012-07-25 17:29:07 -07002278 .procname = "protected_symlinks",
2279 .data = &sysctl_protected_symlinks,
2280 .maxlen = sizeof(int),
2281 .mode = 0600,
2282 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002283 .extra1 = SYSCTL_ZERO,
2284 .extra2 = SYSCTL_ONE,
Kees Cook800179c2012-07-25 17:29:07 -07002285 },
2286 {
2287 .procname = "protected_hardlinks",
2288 .data = &sysctl_protected_hardlinks,
2289 .maxlen = sizeof(int),
2290 .mode = 0600,
2291 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002292 .extra1 = SYSCTL_ZERO,
2293 .extra2 = SYSCTL_ONE,
Kees Cook800179c2012-07-25 17:29:07 -07002294 },
2295 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07002296 .procname = "protected_fifos",
2297 .data = &sysctl_protected_fifos,
2298 .maxlen = sizeof(int),
2299 .mode = 0600,
2300 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002301 .extra1 = SYSCTL_ZERO,
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07002302 .extra2 = &two,
2303 },
2304 {
2305 .procname = "protected_regular",
2306 .data = &sysctl_protected_regular,
2307 .maxlen = sizeof(int),
2308 .mode = 0600,
2309 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002310 .extra1 = SYSCTL_ZERO,
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07002311 .extra2 = &two,
2312 },
2313 {
Alan Coxd6e71142005-06-23 00:09:43 -07002314 .procname = "suid_dumpable",
2315 .data = &suid_dumpable,
2316 .maxlen = sizeof(int),
2317 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07002318 .proc_handler = proc_dointvec_minmax_coredump,
Matteo Croceeec48442019-07-18 15:58:50 -07002319 .extra1 = SYSCTL_ZERO,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07002320 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07002321 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08002322#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
2323 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08002324 .procname = "binfmt_misc",
2325 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05002326 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08002327 },
2328#endif
Jens Axboeb492e952010-05-19 21:03:16 +02002329 {
Jens Axboeff9da692010-06-03 14:54:39 +02002330 .procname = "pipe-max-size",
2331 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08002332 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02002333 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08002334 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02002335 },
Willy Tarreau759c0112016-01-18 16:36:09 +01002336 {
2337 .procname = "pipe-user-pages-hard",
2338 .data = &pipe_user_pages_hard,
2339 .maxlen = sizeof(pipe_user_pages_hard),
2340 .mode = 0644,
2341 .proc_handler = proc_doulongvec_minmax,
2342 },
2343 {
2344 .procname = "pipe-user-pages-soft",
2345 .data = &pipe_user_pages_soft,
2346 .maxlen = sizeof(pipe_user_pages_soft),
2347 .mode = 0644,
2348 .proc_handler = proc_doulongvec_minmax,
2349 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05002350 {
2351 .procname = "mount-max",
2352 .data = &sysctl_mount_max,
2353 .maxlen = sizeof(unsigned int),
2354 .mode = 0644,
2355 .proc_handler = proc_dointvec_minmax,
Matteo Croceeec48442019-07-18 15:58:50 -07002356 .extra1 = SYSCTL_ONE,
Eric W. Biedermand2921682016-09-28 00:27:17 -05002357 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07002358 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359};
2360
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002361static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07002362#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02002363 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02002364 .procname = "exception-trace",
2365 .data = &show_unhandled_signals,
2366 .maxlen = sizeof(int),
2367 .mode = 0644,
2368 .proc_handler = proc_dointvec
2369 },
2370#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05002371#if defined(CONFIG_OPTPROBES)
2372 {
2373 .procname = "kprobes-optimization",
2374 .data = &sysctl_kprobes_optimization,
2375 .maxlen = sizeof(int),
2376 .mode = 0644,
2377 .proc_handler = proc_kprobes_optimization_handler,
Matteo Croceeec48442019-07-18 15:58:50 -07002378 .extra1 = SYSCTL_ZERO,
2379 .extra2 = SYSCTL_ONE,
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05002380 },
2381#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07002382 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383};
2384
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002385static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07002386 { }
Robert Love0eeca282005-07-12 17:06:03 -04002387};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08002389int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00002390{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07002391 struct ctl_table_header *hdr;
2392
2393 hdr = register_sysctl_table(sysctl_base_table);
2394 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08002395 return 0;
2396}
2397
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002398#endif /* CONFIG_SYSCTL */
2399
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400/*
2401 * /proc/sys support
2402 */
2403
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07002404#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
Kees Cookf8808302014-06-06 14:37:17 -07002406static int _proc_do_string(char *data, int maxlen, int write,
2407 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07002408 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002409{
2410 size_t len;
2411 char __user *p;
2412 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002413
2414 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002415 *lenp = 0;
2416 return 0;
2417 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08002418
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002419 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07002420 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
2421 /* Only continue writes not past the end of buffer. */
2422 len = strlen(data);
2423 if (len > maxlen - 1)
2424 len = maxlen - 1;
2425
2426 if (*ppos > len)
2427 return 0;
2428 len = *ppos;
2429 } else {
2430 /* Start writing from beginning of buffer. */
2431 len = 0;
2432 }
2433
Kees Cook2ca9bb42014-06-06 14:37:18 -07002434 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002435 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002436 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002437 if (get_user(c, p++))
2438 return -EFAULT;
2439 if (c == 0 || c == '\n')
2440 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002441 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002442 }
Kees Cookf8808302014-06-06 14:37:17 -07002443 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002444 } else {
2445 len = strlen(data);
2446 if (len > maxlen)
2447 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002448
2449 if (*ppos > len) {
2450 *lenp = 0;
2451 return 0;
2452 }
2453
2454 data += *ppos;
2455 len -= *ppos;
2456
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002457 if (len > *lenp)
2458 len = *lenp;
2459 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002460 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002461 return -EFAULT;
2462 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002463 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002464 return -EFAULT;
2465 len++;
2466 }
2467 *lenp = len;
2468 *ppos += len;
2469 }
2470 return 0;
2471}
2472
Kees Cookf4aacea2014-06-06 14:37:19 -07002473static void warn_sysctl_write(struct ctl_table *table)
2474{
2475 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2476 "This will not be supported in the future. To silence this\n"
2477 "warning, set kernel.sysctl_writes_strict = -1\n",
2478 current->comm, table->procname);
2479}
2480
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002482 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002483 * @ppos: file position
2484 * @table: the sysctl table
2485 *
2486 * Returns true if the first position is non-zero and the sysctl_writes_strict
2487 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -07002488 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002489 */
2490static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2491 struct ctl_table *table)
2492{
2493 if (!*ppos)
2494 return false;
2495
2496 switch (sysctl_writes_strict) {
2497 case SYSCTL_WRITES_STRICT:
2498 return true;
2499 case SYSCTL_WRITES_WARN:
2500 warn_sysctl_write(table);
2501 return false;
2502 default:
2503 return false;
2504 }
2505}
2506
2507/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 * proc_dostring - read a string sysctl
2509 * @table: the sysctl table
2510 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 * @buffer: the user buffer
2512 * @lenp: the size of the user buffer
2513 * @ppos: file position
2514 *
2515 * Reads/writes a string from/to the user buffer. If the kernel
2516 * buffer provided is not large enough to hold the string, the
2517 * string is truncated. The copied string is %NULL-terminated.
2518 * If the string is being read by the user process, it is copied
2519 * and a newline '\n' is added. It is truncated if the buffer is
2520 * not large enough.
2521 *
2522 * Returns 0 on success.
2523 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002524int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 void __user *buffer, size_t *lenp, loff_t *ppos)
2526{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002527 if (write)
2528 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002529
Kees Cookf8808302014-06-06 14:37:17 -07002530 return _proc_do_string((char *)(table->data), table->maxlen, write,
2531 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532}
2533
Linus Torvaldscffda192022-12-05 12:09:06 -08002534static void proc_skip_spaces(char **buf, size_t *size)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002535{
Linus Torvaldscffda192022-12-05 12:09:06 -08002536 while (*size) {
2537 if (!isspace(**buf))
2538 break;
2539 (*size)--;
2540 (*buf)++;
2541 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002542}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002544static void proc_skip_char(char **buf, size_t *size, const char v)
2545{
2546 while (*size) {
2547 if (**buf != v)
2548 break;
2549 (*size)--;
2550 (*buf)++;
2551 }
2552}
2553
Christian Brauner7f2923c2019-03-07 16:29:40 -08002554/**
2555 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2556 * fail on overflow
2557 *
2558 * @cp: kernel buffer containing the string to parse
2559 * @endp: pointer to store the trailing characters
2560 * @base: the base to use
2561 * @res: where the parsed integer will be stored
2562 *
2563 * In case of success 0 is returned and @res will contain the parsed integer,
2564 * @endp will hold any trailing characters.
2565 * This function will fail the parse on overflow. If there wasn't an overflow
2566 * the function will defer the decision what characters count as invalid to the
2567 * caller.
2568 */
2569static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2570 unsigned long *res)
2571{
2572 unsigned long long result;
2573 unsigned int rv;
2574
2575 cp = _parse_integer_fixup_radix(cp, &base);
2576 rv = _parse_integer(cp, base, &result);
2577 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2578 return -ERANGE;
2579
2580 cp += rv;
2581
2582 if (endp)
2583 *endp = (char *)cp;
2584
2585 *res = (unsigned long)result;
2586 return 0;
2587}
2588
Amerigo Wang00b7c332010-05-05 00:26:45 +00002589#define TMPBUFLEN 22
2590/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002591 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002592 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002593 * @buf: a kernel buffer
2594 * @size: size of the kernel buffer
2595 * @val: this is where the number will be stored
2596 * @neg: set to %TRUE if number is negative
2597 * @perm_tr: a vector which contains the allowed trailers
2598 * @perm_tr_len: size of the perm_tr vector
2599 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +00002600 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002601 * In case of success %0 is returned and @buf and @size are updated with
2602 * the amount of bytes read. If @tr is non-NULL and a trailing
2603 * character exists (size is non-zero after returning from this
2604 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002605 */
2606static int proc_get_long(char **buf, size_t *size,
2607 unsigned long *val, bool *neg,
2608 const char *perm_tr, unsigned perm_tr_len, char *tr)
2609{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002610 char *p, tmp[TMPBUFLEN];
Linus Torvalds5a9d3552022-12-05 11:33:40 -08002611 ssize_t len = *size;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002612
Linus Torvalds5a9d3552022-12-05 11:33:40 -08002613 if (len <= 0)
Amerigo Wang00b7c332010-05-05 00:26:45 +00002614 return -EINVAL;
2615
Amerigo Wang00b7c332010-05-05 00:26:45 +00002616 if (len > TMPBUFLEN - 1)
2617 len = TMPBUFLEN - 1;
2618
2619 memcpy(tmp, *buf, len);
2620
2621 tmp[len] = 0;
2622 p = tmp;
2623 if (*p == '-' && *size > 1) {
2624 *neg = true;
2625 p++;
2626 } else
2627 *neg = false;
2628 if (!isdigit(*p))
2629 return -EINVAL;
2630
Christian Brauner7f2923c2019-03-07 16:29:40 -08002631 if (strtoul_lenient(p, &p, 0, val))
2632 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002633
2634 len = p - tmp;
2635
2636 /* We don't know if the next char is whitespace thus we may accept
2637 * invalid integers (e.g. 1234...a) or two integers instead of one
2638 * (e.g. 123...1). So lets not allow such large numbers. */
2639 if (len == TMPBUFLEN - 1)
2640 return -EINVAL;
2641
2642 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2643 return -EINVAL;
2644
2645 if (tr && (len < *size))
2646 *tr = *p;
2647
2648 *buf += len;
2649 *size -= len;
2650
2651 return 0;
2652}
2653
2654/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002655 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002656 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002657 * @buf: the user buffer
2658 * @size: the size of the user buffer
2659 * @val: the integer to be converted
2660 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +00002661 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002662 * In case of success %0 is returned and @buf and @size are updated with
2663 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002664 */
2665static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2666 bool neg)
2667{
2668 int len;
2669 char tmp[TMPBUFLEN], *p = tmp;
2670
2671 sprintf(p, "%s%lu", neg ? "-" : "", val);
2672 len = strlen(tmp);
2673 if (len > *size)
2674 len = *size;
2675 if (copy_to_user(*buf, tmp, len))
2676 return -EFAULT;
2677 *size -= len;
2678 *buf += len;
2679 return 0;
2680}
2681#undef TMPBUFLEN
2682
2683static int proc_put_char(void __user **buf, size_t *size, char c)
2684{
2685 if (*size) {
2686 char __user **buffer = (char __user **)buf;
2687 if (put_user(c, *buffer))
2688 return -EFAULT;
2689 (*size)--, (*buffer)++;
2690 *buf = *buffer;
2691 }
2692 return 0;
2693}
2694
2695static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 int *valp,
2697 int write, void *data)
2698{
2699 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002700 if (*negp) {
2701 if (*lvalp > (unsigned long) INT_MAX + 1)
2702 return -EINVAL;
2703 *valp = -*lvalp;
2704 } else {
2705 if (*lvalp > (unsigned long) INT_MAX)
2706 return -EINVAL;
2707 *valp = *lvalp;
2708 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 } else {
2710 int val = *valp;
2711 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002712 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002713 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002715 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 *lvalp = (unsigned long)val;
2717 }
2718 }
2719 return 0;
2720}
2721
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002722static int do_proc_douintvec_conv(unsigned long *lvalp,
2723 unsigned int *valp,
2724 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002725{
2726 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002727 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002728 return -EINVAL;
2729 *valp = *lvalp;
2730 } else {
2731 unsigned int val = *valp;
2732 *lvalp = (unsigned long)val;
2733 }
2734 return 0;
2735}
2736
Amerigo Wang00b7c332010-05-05 00:26:45 +00002737static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2738
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002739static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002740 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002741 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002742 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 int write, void *data),
2744 void *data)
2745{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002746 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002747 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002748 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
Amerigo Wang00b7c332010-05-05 00:26:45 +00002750 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 *lenp = 0;
2752 return 0;
2753 }
2754
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002755 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 vleft = table->maxlen / sizeof(*i);
2757 left = *lenp;
2758
2759 if (!conv)
2760 conv = do_proc_dointvec_conv;
2761
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002763 if (proc_first_pos_non_zero_ignore(ppos, table))
2764 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002765
Amerigo Wang00b7c332010-05-05 00:26:45 +00002766 if (left > PAGE_SIZE - 1)
2767 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002768 p = kbuf = memdup_user_nul(buffer, left);
2769 if (IS_ERR(kbuf))
2770 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002771 }
2772
2773 for (; left && vleft--; i++, first=0) {
2774 unsigned long lval;
2775 bool neg;
2776
2777 if (write) {
Linus Torvaldscffda192022-12-05 12:09:06 -08002778 proc_skip_spaces(&p, &left);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002779
J. R. Okajima563b0462010-05-25 16:10:14 -07002780 if (!left)
2781 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002782 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002783 proc_wspace_sep,
2784 sizeof(proc_wspace_sep), NULL);
2785 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002787 if (conv(&neg, &lval, i, 1, data)) {
2788 err = -EINVAL;
2789 break;
2790 }
2791 } else {
2792 if (conv(&neg, &lval, i, 0, data)) {
2793 err = -EINVAL;
2794 break;
2795 }
2796 if (!first)
2797 err = proc_put_char(&buffer, &left, '\t');
2798 if (err)
2799 break;
2800 err = proc_put_long(&buffer, &left, lval, neg);
2801 if (err)
2802 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 }
2804 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002805
2806 if (!write && !first && left && !err)
2807 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002808 if (write && !err && left)
Linus Torvaldscffda192022-12-05 12:09:06 -08002809 proc_skip_spaces(&p, &left);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002810 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002811 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002812 if (first)
2813 return err ? : -EINVAL;
2814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002816out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002818 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819}
2820
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002821static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002822 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002823 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002824 int write, void *data),
2825 void *data)
2826{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002827 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002828 buffer, lenp, ppos, conv, data);
2829}
2830
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002831static int do_proc_douintvec_w(unsigned int *tbl_data,
2832 struct ctl_table *table,
2833 void __user *buffer,
2834 size_t *lenp, loff_t *ppos,
2835 int (*conv)(unsigned long *lvalp,
2836 unsigned int *valp,
2837 int write, void *data),
2838 void *data)
2839{
2840 unsigned long lval;
2841 int err = 0;
2842 size_t left;
2843 bool neg;
2844 char *kbuf = NULL, *p;
2845
2846 left = *lenp;
2847
2848 if (proc_first_pos_non_zero_ignore(ppos, table))
2849 goto bail_early;
2850
2851 if (left > PAGE_SIZE - 1)
2852 left = PAGE_SIZE - 1;
2853
2854 p = kbuf = memdup_user_nul(buffer, left);
2855 if (IS_ERR(kbuf))
2856 return -EINVAL;
2857
Linus Torvaldscffda192022-12-05 12:09:06 -08002858 proc_skip_spaces(&p, &left);
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002859 if (!left) {
2860 err = -EINVAL;
2861 goto out_free;
2862 }
2863
2864 err = proc_get_long(&p, &left, &lval, &neg,
2865 proc_wspace_sep,
2866 sizeof(proc_wspace_sep), NULL);
2867 if (err || neg) {
2868 err = -EINVAL;
2869 goto out_free;
2870 }
2871
2872 if (conv(&lval, tbl_data, 1, data)) {
2873 err = -EINVAL;
2874 goto out_free;
2875 }
2876
2877 if (!err && left)
Linus Torvaldscffda192022-12-05 12:09:06 -08002878 proc_skip_spaces(&p, &left);
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002879
2880out_free:
2881 kfree(kbuf);
2882 if (err)
2883 return -EINVAL;
2884
2885 return 0;
2886
2887 /* This is in keeping with old __do_proc_dointvec() */
2888bail_early:
2889 *ppos += *lenp;
2890 return err;
2891}
2892
2893static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2894 size_t *lenp, loff_t *ppos,
2895 int (*conv)(unsigned long *lvalp,
2896 unsigned int *valp,
2897 int write, void *data),
2898 void *data)
2899{
2900 unsigned long lval;
2901 int err = 0;
2902 size_t left;
2903
2904 left = *lenp;
2905
2906 if (conv(&lval, tbl_data, 0, data)) {
2907 err = -EINVAL;
2908 goto out;
2909 }
2910
2911 err = proc_put_long(&buffer, &left, lval, false);
2912 if (err || !left)
2913 goto out;
2914
2915 err = proc_put_char(&buffer, &left, '\n');
2916
2917out:
2918 *lenp -= left;
2919 *ppos += *lenp;
2920
2921 return err;
2922}
2923
2924static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2925 int write, void __user *buffer,
2926 size_t *lenp, loff_t *ppos,
2927 int (*conv)(unsigned long *lvalp,
2928 unsigned int *valp,
2929 int write, void *data),
2930 void *data)
2931{
2932 unsigned int *i, vleft;
2933
2934 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2935 *lenp = 0;
2936 return 0;
2937 }
2938
2939 i = (unsigned int *) tbl_data;
2940 vleft = table->maxlen / sizeof(*i);
2941
2942 /*
2943 * Arrays are not supported, keep this simple. *Do not* add
2944 * support for them.
2945 */
2946 if (vleft != 1) {
2947 *lenp = 0;
2948 return -EINVAL;
2949 }
2950
2951 if (!conv)
2952 conv = do_proc_douintvec_conv;
2953
2954 if (write)
2955 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2956 conv, data);
2957 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2958}
2959
2960static int do_proc_douintvec(struct ctl_table *table, int write,
2961 void __user *buffer, size_t *lenp, loff_t *ppos,
2962 int (*conv)(unsigned long *lvalp,
2963 unsigned int *valp,
2964 int write, void *data),
2965 void *data)
2966{
2967 return __do_proc_douintvec(table->data, table, write,
2968 buffer, lenp, ppos, conv, data);
2969}
2970
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971/**
2972 * proc_dointvec - read a vector of integers
2973 * @table: the sysctl table
2974 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 * @buffer: the user buffer
2976 * @lenp: the size of the user buffer
2977 * @ppos: file position
2978 *
2979 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2980 * values from/to the user buffer, treated as an ASCII string.
2981 *
2982 * Returns 0 on success.
2983 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002984int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 void __user *buffer, size_t *lenp, loff_t *ppos)
2986{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002987 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2988}
2989
2990/**
2991 * proc_douintvec - read a vector of unsigned integers
2992 * @table: the sysctl table
2993 * @write: %TRUE if this is a write to the sysctl file
2994 * @buffer: the user buffer
2995 * @lenp: the size of the user buffer
2996 * @ppos: file position
2997 *
2998 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2999 * values from/to the user buffer, treated as an ASCII string.
3000 *
3001 * Returns 0 on success.
3002 */
3003int proc_douintvec(struct ctl_table *table, int write,
3004 void __user *buffer, size_t *lenp, loff_t *ppos)
3005{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07003006 return do_proc_douintvec(table, write, buffer, lenp, ppos,
3007 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008}
3009
Theodore Ts'o34f5a392007-02-10 01:45:24 -08003010/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07003011 * Taint values can only be increased
3012 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08003013 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003014static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08003015 void __user *buffer, size_t *lenp, loff_t *ppos)
3016{
Andi Kleen25ddbb12008-10-15 22:01:41 -07003017 struct ctl_table t;
3018 unsigned long tmptaint = get_taint();
3019 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08003020
Bastian Blank91fcd412007-04-23 14:41:14 -07003021 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08003022 return -EPERM;
3023
Andi Kleen25ddbb12008-10-15 22:01:41 -07003024 t = *table;
3025 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003026 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07003027 if (err < 0)
3028 return err;
3029
3030 if (write) {
3031 /*
3032 * Poor man's atomic or. Not worth adding a primitive
3033 * to everyone's atomic.h for this
3034 */
3035 int i;
3036 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
3037 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10303038 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07003039 }
3040 }
3041
3042 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08003043}
3044
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07003045#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07003046static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07003047 void __user *buffer, size_t *lenp, loff_t *ppos)
3048{
3049 if (write && !capable(CAP_SYS_ADMIN))
3050 return -EPERM;
3051
3052 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
3053}
3054#endif
3055
Waiman Long24704f32018-04-10 16:35:38 -07003056/**
3057 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
3058 * @min: pointer to minimum allowable value
3059 * @max: pointer to maximum allowable value
3060 *
3061 * The do_proc_dointvec_minmax_conv_param structure provides the
3062 * minimum and maximum values for doing range checking for those sysctl
3063 * parameters that use the proc_dointvec_minmax() handler.
3064 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065struct do_proc_dointvec_minmax_conv_param {
3066 int *min;
3067 int *max;
3068};
3069
Amerigo Wang00b7c332010-05-05 00:26:45 +00003070static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
3071 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 int write, void *data)
3073{
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003074 int tmp, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 struct do_proc_dointvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003076 /*
3077 * If writing, first do so via a temporary local int so we can
3078 * bounds-check it before touching *valp.
3079 */
3080 int *ip = write ? &tmp : valp;
3081
3082 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
3083 if (ret)
3084 return ret;
3085
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003087 if ((param->min && *param->min > tmp) ||
3088 (param->max && *param->max < tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 return -EINVAL;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003090 *valp = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 }
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003092
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 return 0;
3094}
3095
3096/**
3097 * proc_dointvec_minmax - read a vector of integers with min/max values
3098 * @table: the sysctl table
3099 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 * @buffer: the user buffer
3101 * @lenp: the size of the user buffer
3102 * @ppos: file position
3103 *
3104 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3105 * values from/to the user buffer, treated as an ASCII string.
3106 *
3107 * This routine will ensure the values are within the range specified by
3108 * table->extra1 (min) and table->extra2 (max).
3109 *
Waiman Long24704f32018-04-10 16:35:38 -07003110 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003112int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 void __user *buffer, size_t *lenp, loff_t *ppos)
3114{
3115 struct do_proc_dointvec_minmax_conv_param param = {
3116 .min = (int *) table->extra1,
3117 .max = (int *) table->extra2,
3118 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003119 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 do_proc_dointvec_minmax_conv, &param);
3121}
3122
Waiman Long24704f32018-04-10 16:35:38 -07003123/**
3124 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
3125 * @min: pointer to minimum allowable value
3126 * @max: pointer to maximum allowable value
3127 *
3128 * The do_proc_douintvec_minmax_conv_param structure provides the
3129 * minimum and maximum values for doing range checking for those sysctl
3130 * parameters that use the proc_douintvec_minmax() handler.
3131 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003132struct do_proc_douintvec_minmax_conv_param {
3133 unsigned int *min;
3134 unsigned int *max;
3135};
3136
3137static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
3138 unsigned int *valp,
3139 int write, void *data)
3140{
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003141 int ret;
3142 unsigned int tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003143 struct do_proc_douintvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003144 /* write via temporary local uint for bounds-checking */
3145 unsigned int *up = write ? &tmp : valp;
3146
3147 ret = do_proc_douintvec_conv(lvalp, up, write, data);
3148 if (ret)
3149 return ret;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003150
3151 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003152 if ((param->min && *param->min > tmp) ||
3153 (param->max && *param->max < tmp))
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003154 return -ERANGE;
3155
Zev Weiss2bc4fc62019-03-11 23:28:06 -07003156 *valp = tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003157 }
3158
3159 return 0;
3160}
3161
3162/**
3163 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
3164 * @table: the sysctl table
3165 * @write: %TRUE if this is a write to the sysctl file
3166 * @buffer: the user buffer
3167 * @lenp: the size of the user buffer
3168 * @ppos: file position
3169 *
3170 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
3171 * values from/to the user buffer, treated as an ASCII string. Negative
3172 * strings are not allowed.
3173 *
3174 * This routine will ensure the values are within the range specified by
3175 * table->extra1 (min) and table->extra2 (max). There is a final sanity
3176 * check for UINT_MAX to avoid having to support wrap around uses from
3177 * userspace.
3178 *
Waiman Long24704f32018-04-10 16:35:38 -07003179 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003180 */
3181int proc_douintvec_minmax(struct ctl_table *table, int write,
3182 void __user *buffer, size_t *lenp, loff_t *ppos)
3183{
3184 struct do_proc_douintvec_minmax_conv_param param = {
3185 .min = (unsigned int *) table->extra1,
3186 .max = (unsigned int *) table->extra2,
3187 };
3188 return do_proc_douintvec(table, write, buffer, lenp, ppos,
3189 do_proc_douintvec_minmax_conv, &param);
3190}
3191
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003192static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
3193 unsigned int *valp,
3194 int write, void *data)
3195{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003196 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08003197 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003198
Joe Lawrencefb910c42017-11-17 15:29:28 -08003199 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003200 if (val == 0)
3201 return -EINVAL;
3202
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003203 *valp = val;
3204 } else {
3205 unsigned int val = *valp;
3206 *lvalp = (unsigned long) val;
3207 }
3208
3209 return 0;
3210}
3211
Eric Biggers319e0a22018-02-06 15:41:49 -08003212static int proc_dopipe_max_size(struct ctl_table *table, int write,
3213 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003214{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003215 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08003216 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08003217}
3218
Kees Cook54b50192012-07-30 14:39:18 -07003219static void validate_coredump_safety(void)
3220{
Alex Kelly046d6622012-10-04 17:15:23 -07003221#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08003222 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07003223 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08003224 printk(KERN_WARNING
3225"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
3226"Pipe handler or fully qualified core dump path required.\n"
3227"Set kernel.core_pattern before fs.suid_dumpable.\n"
3228 );
Kees Cook54b50192012-07-30 14:39:18 -07003229 }
Alex Kelly046d6622012-10-04 17:15:23 -07003230#endif
Kees Cook54b50192012-07-30 14:39:18 -07003231}
3232
3233static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
3234 void __user *buffer, size_t *lenp, loff_t *ppos)
3235{
3236 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
3237 if (!error)
3238 validate_coredump_safety();
3239 return error;
3240}
3241
Alex Kelly046d6622012-10-04 17:15:23 -07003242#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07003243static int proc_dostring_coredump(struct ctl_table *table, int write,
3244 void __user *buffer, size_t *lenp, loff_t *ppos)
3245{
3246 int error = proc_dostring(table, write, buffer, lenp, ppos);
3247 if (!error)
3248 validate_coredump_safety();
3249 return error;
3250}
Alex Kelly046d6622012-10-04 17:15:23 -07003251#endif
Kees Cook54b50192012-07-30 14:39:18 -07003252
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003253static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 void __user *buffer,
3255 size_t *lenp, loff_t *ppos,
3256 unsigned long convmul,
3257 unsigned long convdiv)
3258{
Amerigo Wang00b7c332010-05-05 00:26:45 +00003259 unsigned long *i, *min, *max;
3260 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00003261 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05003262 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00003263
3264 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 *lenp = 0;
3266 return 0;
3267 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00003268
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07003269 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 min = (unsigned long *) table->extra1;
3271 max = (unsigned long *) table->extra2;
3272 vleft = table->maxlen / sizeof(unsigned long);
3273 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00003274
3275 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07003276 if (proc_first_pos_non_zero_ignore(ppos, table))
3277 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07003278
Amerigo Wang00b7c332010-05-05 00:26:45 +00003279 if (left > PAGE_SIZE - 1)
3280 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05003281 p = kbuf = memdup_user_nul(buffer, left);
3282 if (IS_ERR(kbuf))
3283 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00003284 }
3285
Eric Dumazet27b3d802010-10-07 12:59:29 -07003286 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003287 unsigned long val;
3288
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003290 bool neg;
3291
Linus Torvaldscffda192022-12-05 12:09:06 -08003292 proc_skip_spaces(&p, &left);
Cheng Lin09be1782019-01-03 15:26:13 -08003293 if (!left)
3294 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00003295
Al Viro70f6cbb2015-12-24 00:13:10 -05003296 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00003297 proc_wspace_sep,
3298 sizeof(proc_wspace_sep), NULL);
3299 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 break;
3301 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08003303 val = convmul * val / convdiv;
Christian Braunere260ad02019-05-14 15:44:55 -07003304 if ((min && val < *min) || (max && val > *max)) {
3305 err = -EINVAL;
3306 break;
3307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 *i = val;
3309 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003310 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08003311 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003312 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08003313 if (err)
3314 break;
3315 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00003316 err = proc_put_long(&buffer, &left, val, false);
3317 if (err)
3318 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 }
3320 }
3321
Amerigo Wang00b7c332010-05-05 00:26:45 +00003322 if (!write && !first && left && !err)
3323 err = proc_put_char(&buffer, &left, '\n');
3324 if (write && !err)
Linus Torvaldscffda192022-12-05 12:09:06 -08003325 proc_skip_spaces(&p, &left);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003327 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00003328 if (first)
3329 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07003332out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00003334 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335}
3336
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003337static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07003338 void __user *buffer,
3339 size_t *lenp, loff_t *ppos,
3340 unsigned long convmul,
3341 unsigned long convdiv)
3342{
3343 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003344 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07003345}
3346
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347/**
3348 * proc_doulongvec_minmax - read a vector of long integers with min/max values
3349 * @table: the sysctl table
3350 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 * @buffer: the user buffer
3352 * @lenp: the size of the user buffer
3353 * @ppos: file position
3354 *
3355 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
3356 * values from/to the user buffer, treated as an ASCII string.
3357 *
3358 * This routine will ensure the values are within the range specified by
3359 * table->extra1 (min) and table->extra2 (max).
3360 *
3361 * Returns 0 on success.
3362 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003363int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 void __user *buffer, size_t *lenp, loff_t *ppos)
3365{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003366 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367}
3368
3369/**
3370 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
3371 * @table: the sysctl table
3372 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 * @buffer: the user buffer
3374 * @lenp: the size of the user buffer
3375 * @ppos: file position
3376 *
3377 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
3378 * values from/to the user buffer, treated as an ASCII string. The values
3379 * are treated as milliseconds, and converted to jiffies when they are stored.
3380 *
3381 * This routine will ensure the values are within the range specified by
3382 * table->extra1 (min) and table->extra2 (max).
3383 *
3384 * Returns 0 on success.
3385 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003386int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 void __user *buffer,
3388 size_t *lenp, loff_t *ppos)
3389{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003390 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391 lenp, ppos, HZ, 1000l);
3392}
3393
3394
Amerigo Wang00b7c332010-05-05 00:26:45 +00003395static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 int *valp,
3397 int write, void *data)
3398{
3399 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07003400 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08003401 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
3403 } else {
3404 int val = *valp;
3405 unsigned long lval;
3406 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003407 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003408 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003410 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 lval = (unsigned long)val;
3412 }
3413 *lvalp = lval / HZ;
3414 }
3415 return 0;
3416}
3417
Amerigo Wang00b7c332010-05-05 00:26:45 +00003418static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 int *valp,
3420 int write, void *data)
3421{
3422 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08003423 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3424 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3426 } else {
3427 int val = *valp;
3428 unsigned long lval;
3429 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003430 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003431 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003433 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 lval = (unsigned long)val;
3435 }
3436 *lvalp = jiffies_to_clock_t(lval);
3437 }
3438 return 0;
3439}
3440
Amerigo Wang00b7c332010-05-05 00:26:45 +00003441static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 int *valp,
3443 int write, void *data)
3444{
3445 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02003446 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3447
3448 if (jif > INT_MAX)
3449 return 1;
3450 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 } else {
3452 int val = *valp;
3453 unsigned long lval;
3454 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003455 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003456 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003458 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 lval = (unsigned long)val;
3460 }
3461 *lvalp = jiffies_to_msecs(lval);
3462 }
3463 return 0;
3464}
3465
3466/**
3467 * proc_dointvec_jiffies - read a vector of integers as seconds
3468 * @table: the sysctl table
3469 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 * @buffer: the user buffer
3471 * @lenp: the size of the user buffer
3472 * @ppos: file position
3473 *
3474 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3475 * values from/to the user buffer, treated as an ASCII string.
3476 * The values read are assumed to be in seconds, and are converted into
3477 * jiffies.
3478 *
3479 * Returns 0 on success.
3480 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003481int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 void __user *buffer, size_t *lenp, loff_t *ppos)
3483{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003484 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 do_proc_dointvec_jiffies_conv,NULL);
3486}
3487
3488/**
3489 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3490 * @table: the sysctl table
3491 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 * @buffer: the user buffer
3493 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003494 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 *
3496 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3497 * values from/to the user buffer, treated as an ASCII string.
3498 * The values read are assumed to be in 1/USER_HZ seconds, and
3499 * are converted into jiffies.
3500 *
3501 * Returns 0 on success.
3502 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003503int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 void __user *buffer, size_t *lenp, loff_t *ppos)
3505{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003506 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 do_proc_dointvec_userhz_jiffies_conv,NULL);
3508}
3509
3510/**
3511 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3512 * @table: the sysctl table
3513 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 * @buffer: the user buffer
3515 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003516 * @ppos: file position
3517 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 *
3519 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3520 * values from/to the user buffer, treated as an ASCII string.
3521 * The values read are assumed to be in 1/1000 seconds, and
3522 * are converted into jiffies.
3523 *
3524 * Returns 0 on success.
3525 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003526int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527 void __user *buffer, size_t *lenp, loff_t *ppos)
3528{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003529 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 do_proc_dointvec_ms_jiffies_conv, NULL);
3531}
3532
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003533static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003534 void __user *buffer, size_t *lenp, loff_t *ppos)
3535{
3536 struct pid *new_pid;
3537 pid_t tmp;
3538 int r;
3539
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003540 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003541
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003542 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003543 lenp, ppos, NULL, NULL);
3544 if (r || !write)
3545 return r;
3546
3547 new_pid = find_get_pid(tmp);
3548 if (!new_pid)
3549 return -ESRCH;
3550
3551 put_pid(xchg(&cad_pid, new_pid));
3552 return 0;
3553}
3554
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003555/**
3556 * proc_do_large_bitmap - read/write from/to a large bitmap
3557 * @table: the sysctl table
3558 * @write: %TRUE if this is a write to the sysctl file
3559 * @buffer: the user buffer
3560 * @lenp: the size of the user buffer
3561 * @ppos: file position
3562 *
3563 * The bitmap is stored at table->data and the bitmap length (in bits)
3564 * in table->maxlen.
3565 *
3566 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3567 * large bitmaps may be represented in a compact manner. Writing into
3568 * the file will clear the bitmap then update it with the given input.
3569 *
3570 * Returns 0 on success.
3571 */
3572int proc_do_large_bitmap(struct ctl_table *table, int write,
3573 void __user *buffer, size_t *lenp, loff_t *ppos)
3574{
3575 int err = 0;
3576 bool first = 1;
3577 size_t left = *lenp;
3578 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003579 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003580 unsigned long *tmp_bitmap = NULL;
3581 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3582
WANG Cong122ff242014-05-12 16:04:53 -07003583 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003584 *lenp = 0;
3585 return 0;
3586 }
3587
3588 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003589 char *kbuf, *p;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003590 size_t skipped = 0;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003591
Eric Sandeen3116ad32019-05-14 15:45:13 -07003592 if (left > PAGE_SIZE - 1) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003593 left = PAGE_SIZE - 1;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003594 /* How much of the buffer we'll skip this pass */
3595 skipped = *lenp - left;
3596 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003597
Al Viro70f6cbb2015-12-24 00:13:10 -05003598 p = kbuf = memdup_user_nul(buffer, left);
3599 if (IS_ERR(kbuf))
3600 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003601
Andy Shevchenko475dae32019-05-14 15:44:52 -07003602 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003603 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003604 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003605 return -ENOMEM;
3606 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003607 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003608 while (!err && left) {
3609 unsigned long val_a, val_b;
3610 bool neg;
Eric Sandeen3116ad32019-05-14 15:45:13 -07003611 size_t saved_left;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003612
Eric Sandeen3116ad32019-05-14 15:45:13 -07003613 /* In case we stop parsing mid-number, we can reset */
3614 saved_left = left;
Al Viro70f6cbb2015-12-24 00:13:10 -05003615 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003616 sizeof(tr_a), &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003617 /*
3618 * If we consumed the entirety of a truncated buffer or
3619 * only one char is left (may be a "-"), then stop here,
3620 * reset, & come back for more.
3621 */
3622 if ((left <= 1) && skipped) {
3623 left = saved_left;
3624 break;
3625 }
3626
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003627 if (err)
3628 break;
3629 if (val_a >= bitmap_len || neg) {
3630 err = -EINVAL;
3631 break;
3632 }
3633
3634 val_b = val_a;
3635 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003636 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003637 left--;
3638 }
3639
3640 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003641 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003642 &neg, tr_b, sizeof(tr_b),
3643 &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003644 /*
3645 * If we consumed all of a truncated buffer or
3646 * then stop here, reset, & come back for more.
3647 */
3648 if (!left && skipped) {
3649 left = saved_left;
3650 break;
3651 }
3652
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003653 if (err)
3654 break;
3655 if (val_b >= bitmap_len || neg ||
3656 val_a > val_b) {
3657 err = -EINVAL;
3658 break;
3659 }
3660 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003661 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003662 left--;
3663 }
3664 }
3665
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003666 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003667 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003668 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003669 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003670 kfree(kbuf);
Eric Sandeen3116ad32019-05-14 15:45:13 -07003671 left += skipped;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003672 } else {
3673 unsigned long bit_a, bit_b = 0;
3674
3675 while (left) {
3676 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3677 if (bit_a >= bitmap_len)
3678 break;
3679 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3680 bit_a + 1) - 1;
3681
3682 if (!first) {
3683 err = proc_put_char(&buffer, &left, ',');
3684 if (err)
3685 break;
3686 }
3687 err = proc_put_long(&buffer, &left, bit_a, false);
3688 if (err)
3689 break;
3690 if (bit_a != bit_b) {
3691 err = proc_put_char(&buffer, &left, '-');
3692 if (err)
3693 break;
3694 err = proc_put_long(&buffer, &left, bit_b, false);
3695 if (err)
3696 break;
3697 }
3698
3699 first = 0; bit_b++;
3700 }
3701 if (!err)
3702 err = proc_put_char(&buffer, &left, '\n');
3703 }
3704
3705 if (!err) {
3706 if (write) {
3707 if (*ppos)
3708 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3709 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003710 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003711 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003712 *lenp -= left;
3713 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003714 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003715
Andy Shevchenko475dae32019-05-14 15:44:52 -07003716 bitmap_free(tmp_bitmap);
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003717 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003718}
3719
Satya Durga Srinivasu Prabhalad7a8a672018-11-14 17:01:12 -08003720static int do_proc_douintvec_capacity_conv(bool *negp, unsigned long *lvalp,
3721 int *valp, int write, void *data)
3722{
3723 if (write) {
3724 /*
3725 * The sched_upmigrate/sched_downmigrate tunables are
3726 * accepted in percentage. Limit them to 100.
3727 */
3728 if (*negp || *lvalp == 0 || *lvalp > 100)
3729 return -EINVAL;
3730 *valp = SCHED_FIXEDPOINT_SCALE * 100 / *lvalp;
3731 } else {
3732 *negp = false;
3733 *lvalp = SCHED_FIXEDPOINT_SCALE * 100 / *valp;
3734 }
3735
3736 return 0;
3737}
3738
3739/**
3740 * proc_douintvec_capacity - read a vector of integers in percentage and convert
3741 * into sched capacity
3742 * @table: the sysctl table
3743 * @write: %TRUE if this is a write to the sysctl file
3744 * @buffer: the user buffer
3745 * @lenp: the size of the user buffer
3746 * @ppos: file position
3747 *
3748 * Returns 0 on success.
3749 */
3750int proc_douintvec_capacity(struct ctl_table *table, int write,
3751 void __user *buffer, size_t *lenp, loff_t *ppos)
3752{
3753 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3754 do_proc_douintvec_capacity_conv, NULL);
3755}
3756
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -07003757static int do_proc_douintvec_rwin(bool *negp, unsigned long *lvalp,
3758 int *valp, int write, void *data)
3759{
3760 if (write) {
Lingutla Chandrasekhar609fb2b2019-12-04 14:04:20 +05303761 if (*lvalp == 2 || *lvalp == 3 || *lvalp == 4 || *lvalp == 5 ||
3762 *lvalp == 8)
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -07003763 *valp = *lvalp;
3764 else
3765 return -EINVAL;
3766 } else {
3767 *negp = false;
3768 *lvalp = *valp;
3769 }
3770
3771 return 0;
3772}
3773
3774int proc_douintvec_ravg_window(struct ctl_table *table, int write,
3775 void __user *buffer, size_t *lenp, loff_t *ppos)
3776{
3777 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3778 do_proc_douintvec_rwin, NULL);
3779}
3780
Jovi Zhang55610502011-01-12 17:00:45 -08003781#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003783int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 void __user *buffer, size_t *lenp, loff_t *ppos)
3785{
3786 return -ENOSYS;
3787}
3788
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003789int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 void __user *buffer, size_t *lenp, loff_t *ppos)
3791{
3792 return -ENOSYS;
3793}
3794
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003795int proc_douintvec(struct ctl_table *table, int write,
3796 void __user *buffer, size_t *lenp, loff_t *ppos)
3797{
3798 return -ENOSYS;
3799}
3800
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003801int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 void __user *buffer, size_t *lenp, loff_t *ppos)
3803{
3804 return -ENOSYS;
3805}
3806
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003807int proc_douintvec_minmax(struct ctl_table *table, int write,
3808 void __user *buffer, size_t *lenp, loff_t *ppos)
3809{
3810 return -ENOSYS;
3811}
3812
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003813int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 void __user *buffer, size_t *lenp, loff_t *ppos)
3815{
3816 return -ENOSYS;
3817}
3818
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003819int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 void __user *buffer, size_t *lenp, loff_t *ppos)
3821{
3822 return -ENOSYS;
3823}
3824
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003825int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 void __user *buffer, size_t *lenp, loff_t *ppos)
3827{
3828 return -ENOSYS;
3829}
3830
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003831int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 void __user *buffer, size_t *lenp, loff_t *ppos)
3833{
3834 return -ENOSYS;
3835}
3836
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003837int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 void __user *buffer,
3839 size_t *lenp, loff_t *ppos)
3840{
3841 return -ENOSYS;
3842}
3843
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003844int proc_do_large_bitmap(struct ctl_table *table, int write,
3845 void __user *buffer, size_t *lenp, loff_t *ppos)
3846{
3847 return -ENOSYS;
3848}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849
Satya Durga Srinivasu Prabhala64b577b2019-09-09 15:32:44 -07003850int proc_douintvec_ravg_window(struct ctl_table *table, int write,
3851 void __user *buffer, size_t *lenp, loff_t *ppos)
3852{
3853 return -ENOSYS;
3854}
3855
Satya Durga Srinivasu Prabhalad7a8a672018-11-14 17:01:12 -08003856int proc_douintvec_capacity(struct ctl_table *table, int write,
3857 void __user *buffer, size_t *lenp, loff_t *ppos)
3858{
3859 return -ENOSYS;
3860}
3861
Jovi Zhang55610502011-01-12 17:00:45 -08003862#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003864#if defined(CONFIG_SYSCTL)
3865int proc_do_static_key(struct ctl_table *table, int write,
3866 void __user *buffer, size_t *lenp,
3867 loff_t *ppos)
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003868{
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003869 struct static_key *key = (struct static_key *)table->data;
3870 static DEFINE_MUTEX(static_key_mutex);
3871 int val, ret;
3872 struct ctl_table tmp = {
3873 .data = &val,
3874 .maxlen = sizeof(val),
3875 .mode = table->mode,
Matteo Croceeec48442019-07-18 15:58:50 -07003876 .extra1 = SYSCTL_ZERO,
3877 .extra2 = SYSCTL_ONE,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003878 };
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003879
3880 if (write && !capable(CAP_SYS_ADMIN))
3881 return -EPERM;
3882
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003883 mutex_lock(&static_key_mutex);
3884 val = static_key_enabled(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003885 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3886 if (write && !ret) {
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003887 if (val)
3888 static_key_enable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003889 else
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003890 static_key_disable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003891 }
Eric Dumazeta8e11e52019-06-14 16:22:18 -07003892 mutex_unlock(&static_key_mutex);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003893 return ret;
3894}
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003895#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896/*
3897 * No sense putting this after each symbol definition, twice,
3898 * exception granted :-)
3899 */
3900EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003901EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902EXPORT_SYMBOL(proc_dointvec_jiffies);
3903EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003904EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3906EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3907EXPORT_SYMBOL(proc_dostring);
3908EXPORT_SYMBOL(proc_doulongvec_minmax);
3909EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003910EXPORT_SYMBOL(proc_do_large_bitmap);