11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * sysctl.c: General linux system control interface 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Begun 24 March 1995, Stephen Tweedie 51da177e4SLinus Torvalds * Added /proc support, Dec 1995 61da177e4SLinus Torvalds * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. 71da177e4SLinus Torvalds * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. 81da177e4SLinus Torvalds * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver. 91da177e4SLinus Torvalds * Dynamic registration fixes, Stephen Tweedie. 101da177e4SLinus Torvalds * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn. 111da177e4SLinus Torvalds * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris 121da177e4SLinus Torvalds * Horn. 131da177e4SLinus Torvalds * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer. 141da177e4SLinus Torvalds * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer. 151da177e4SLinus Torvalds * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill 161da177e4SLinus Torvalds * Wendling. 171da177e4SLinus Torvalds * The list_for_each() macro wasn't appropriate for the sysctl loop. 181da177e4SLinus Torvalds * Removed it and replaced it with older style, 03/23/00, Bill Wendling 191da177e4SLinus Torvalds */ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds #include <linux/module.h> 221da177e4SLinus Torvalds #include <linux/mm.h> 231da177e4SLinus Torvalds #include <linux/swap.h> 241da177e4SLinus Torvalds #include <linux/slab.h> 251da177e4SLinus Torvalds #include <linux/sysctl.h> 261da177e4SLinus Torvalds #include <linux/proc_fs.h> 2772c2d582SAndrew Morgan #include <linux/security.h> 281da177e4SLinus Torvalds #include <linux/ctype.h> 291da177e4SLinus Torvalds #include <linux/utsname.h> 301da177e4SLinus Torvalds #include <linux/smp_lock.h> 3162239ac2SAdrian Bunk #include <linux/fs.h> 321da177e4SLinus Torvalds #include <linux/init.h> 331da177e4SLinus Torvalds #include <linux/kernel.h> 340296b228SKay Sievers #include <linux/kobject.h> 3520380731SArnaldo Carvalho de Melo #include <linux/net.h> 361da177e4SLinus Torvalds #include <linux/sysrq.h> 371da177e4SLinus Torvalds #include <linux/highuid.h> 381da177e4SLinus Torvalds #include <linux/writeback.h> 391da177e4SLinus Torvalds #include <linux/hugetlb.h> 401da177e4SLinus Torvalds #include <linux/security.h> 411da177e4SLinus Torvalds #include <linux/initrd.h> 421da177e4SLinus Torvalds #include <linux/times.h> 431da177e4SLinus Torvalds #include <linux/limits.h> 441da177e4SLinus Torvalds #include <linux/dcache.h> 451da177e4SLinus Torvalds #include <linux/syscalls.h> 46c255d844SPavel Machek #include <linux/nfs_fs.h> 47c255d844SPavel Machek #include <linux/acpi.h> 4810a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h> 491da177e4SLinus Torvalds 501da177e4SLinus Torvalds #include <asm/uaccess.h> 511da177e4SLinus Torvalds #include <asm/processor.h> 521da177e4SLinus Torvalds 5329cbc78bSAndi Kleen #ifdef CONFIG_X86 5429cbc78bSAndi Kleen #include <asm/nmi.h> 550741f4d2SChuck Ebbert #include <asm/stacktrace.h> 5629cbc78bSAndi Kleen #endif 5729cbc78bSAndi Kleen 587058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args); 597058cb02SEric W. Biederman 601da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds /* External variables not in a header file. */ 631da177e4SLinus Torvalds extern int C_A_D; 6445807a1dSIngo Molnar extern int print_fatal_signals; 651da177e4SLinus Torvalds extern int sysctl_overcommit_memory; 661da177e4SLinus Torvalds extern int sysctl_overcommit_ratio; 67fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom; 68fe071d7eSDavid Rientjes extern int sysctl_oom_kill_allocating_task; 691da177e4SLinus Torvalds extern int max_threads; 701da177e4SLinus Torvalds extern int core_uses_pid; 71d6e71144SAlan Cox extern int suid_dumpable; 721da177e4SLinus Torvalds extern char core_pattern[]; 731da177e4SLinus Torvalds extern int pid_max; 741da177e4SLinus Torvalds extern int min_free_kbytes; 751da177e4SLinus Torvalds extern int printk_ratelimit_jiffies; 761da177e4SLinus Torvalds extern int printk_ratelimit_burst; 771da177e4SLinus Torvalds extern int pid_max_min, pid_max_max; 789d0243bcSAndrew Morton extern int sysctl_drop_caches; 798ad4b1fbSRohit Seth extern int percpu_pagelist_fraction; 80bebfa101SAndi Kleen extern int compat_log; 815096add8SKees Cook extern int maps_protect; 8277461ab3SChristoph Lameter extern int sysctl_stat_interval; 83bdf4c48aSPeter Zijlstra extern int audit_argv_kb; 849745512cSArjan van de Ven extern int latencytop_enabled; 851da177e4SLinus Torvalds 86c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */ 87c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_DETECT_SOFTLOCKUP 88c4f3b63fSRavikiran G Thirumalai static int one = 1; 89c4f3b63fSRavikiran G Thirumalai static int sixty = 60; 90c4f3b63fSRavikiran G Thirumalai #endif 91c4f3b63fSRavikiran G Thirumalai 92c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_MMU 93c4f3b63fSRavikiran G Thirumalai static int two = 2; 94c4f3b63fSRavikiran G Thirumalai #endif 95c4f3b63fSRavikiran G Thirumalai 96c4f3b63fSRavikiran G Thirumalai static int zero; 97c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100; 98c4f3b63fSRavikiran G Thirumalai 991da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ 1001da177e4SLinus Torvalds static int maxolduid = 65535; 1011da177e4SLinus Torvalds static int minolduid; 1028ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8; 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX; 1051da177e4SLinus Torvalds 1061da177e4SLinus Torvalds #ifdef CONFIG_KMOD 1071da177e4SLinus Torvalds extern char modprobe_path[]; 1081da177e4SLinus Torvalds #endif 1091da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG 1101da177e4SLinus Torvalds extern int sg_big_buff; 1111da177e4SLinus Torvalds #endif 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds #ifdef __sparc__ 1141da177e4SLinus Torvalds extern char reboot_command []; 1151da177e4SLinus Torvalds extern int stop_a_enabled; 1161da177e4SLinus Torvalds extern int scons_pwroff; 1171da177e4SLinus Torvalds #endif 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds #ifdef __hppa__ 1201da177e4SLinus Torvalds extern int pwrsw_enabled; 1211da177e4SLinus Torvalds extern int unaligned_enabled; 1221da177e4SLinus Torvalds #endif 1231da177e4SLinus Torvalds 124347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 1251da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 1261da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings; 1271da177e4SLinus Torvalds #endif 1281da177e4SLinus Torvalds extern int sysctl_userprocess_debug; 129951f22d5SMartin Schwidefsky extern int spin_retry; 1301da177e4SLinus Torvalds #endif 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds extern int sysctl_hz_timer; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT 1351da177e4SLinus Torvalds extern int acct_parm[]; 1361da177e4SLinus Torvalds #endif 1371da177e4SLinus Torvalds 138d2b176edSJes Sorensen #ifdef CONFIG_IA64 139d2b176edSJes Sorensen extern int no_unaligned_warning; 140d2b176edSJes Sorensen #endif 141d2b176edSJes Sorensen 14223f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 14323f78d4aSIngo Molnar extern int max_lock_depth; 14423f78d4aSIngo Molnar #endif 14523f78d4aSIngo Molnar 146b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 147b89a8171SEric W. Biederman static int parse_table(int __user *, int, void __user *, size_t __user *, 148d8217f07SEric W. Biederman void __user *, size_t, struct ctl_table *); 149b89a8171SEric W. Biederman #endif 150b89a8171SEric W. Biederman 1516b49a257SEric W. Biederman 152d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 153d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, 1549ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos); 155d8217f07SEric W. Biederman static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp, 15634f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos); 157d6f8ff73SRandy Dunlap #endif 1589ec52099SCedric Le Goater 159d8217f07SEric W. Biederman static struct ctl_table root_table[]; 1601da177e4SLinus Torvalds static struct ctl_table_header root_table_header = 1611da177e4SLinus Torvalds { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) }; 1621da177e4SLinus Torvalds 163d8217f07SEric W. Biederman static struct ctl_table kern_table[]; 164d8217f07SEric W. Biederman static struct ctl_table vm_table[]; 165d8217f07SEric W. Biederman static struct ctl_table fs_table[]; 166d8217f07SEric W. Biederman static struct ctl_table debug_table[]; 167d8217f07SEric W. Biederman static struct ctl_table dev_table[]; 168d8217f07SEric W. Biederman extern struct ctl_table random_table[]; 1692d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 170d8217f07SEric W. Biederman extern struct ctl_table inotify_table[]; 1710399cb08SRobert Love #endif 1721da177e4SLinus Torvalds 1731da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 1741da177e4SLinus Torvalds int sysctl_legacy_va_layout; 1751da177e4SLinus Torvalds #endif 1761da177e4SLinus Torvalds 177f20786ffSPeter Zijlstra extern int prove_locking; 178f20786ffSPeter Zijlstra extern int lock_stat; 1799bc9a6bdSEric W. Biederman 1801da177e4SLinus Torvalds /* The default sysctl tables: */ 1811da177e4SLinus Torvalds 182d8217f07SEric W. Biederman static struct ctl_table root_table[] = { 1831da177e4SLinus Torvalds { 1841da177e4SLinus Torvalds .ctl_name = CTL_KERN, 1851da177e4SLinus Torvalds .procname = "kernel", 1861da177e4SLinus Torvalds .mode = 0555, 1871da177e4SLinus Torvalds .child = kern_table, 1881da177e4SLinus Torvalds }, 1891da177e4SLinus Torvalds { 1901da177e4SLinus Torvalds .ctl_name = CTL_VM, 1911da177e4SLinus Torvalds .procname = "vm", 1921da177e4SLinus Torvalds .mode = 0555, 1931da177e4SLinus Torvalds .child = vm_table, 1941da177e4SLinus Torvalds }, 1951da177e4SLinus Torvalds #ifdef CONFIG_NET 1961da177e4SLinus Torvalds { 1971da177e4SLinus Torvalds .ctl_name = CTL_NET, 1981da177e4SLinus Torvalds .procname = "net", 1991da177e4SLinus Torvalds .mode = 0555, 2001da177e4SLinus Torvalds .child = net_table, 2011da177e4SLinus Torvalds }, 2021da177e4SLinus Torvalds #endif 2031da177e4SLinus Torvalds { 2041da177e4SLinus Torvalds .ctl_name = CTL_FS, 2051da177e4SLinus Torvalds .procname = "fs", 2061da177e4SLinus Torvalds .mode = 0555, 2071da177e4SLinus Torvalds .child = fs_table, 2081da177e4SLinus Torvalds }, 2091da177e4SLinus Torvalds { 2101da177e4SLinus Torvalds .ctl_name = CTL_DEBUG, 2111da177e4SLinus Torvalds .procname = "debug", 2121da177e4SLinus Torvalds .mode = 0555, 2131da177e4SLinus Torvalds .child = debug_table, 2141da177e4SLinus Torvalds }, 2151da177e4SLinus Torvalds { 2161da177e4SLinus Torvalds .ctl_name = CTL_DEV, 2171da177e4SLinus Torvalds .procname = "dev", 2181da177e4SLinus Torvalds .mode = 0555, 2191da177e4SLinus Torvalds .child = dev_table, 2201da177e4SLinus Torvalds }, 2212be7fe07SAndrew Morton /* 2222be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 2232be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 2242be7fe07SAndrew Morton */ 2251da177e4SLinus Torvalds { .ctl_name = 0 } 2261da177e4SLinus Torvalds }; 2271da177e4SLinus Torvalds 22877e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 22973c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000; /* 100 usecs */ 23073c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */ 23173c4efd2SEric Dumazet static int min_wakeup_granularity_ns; /* 0 usecs */ 23273c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */ 23377e54a1fSIngo Molnar #endif 23477e54a1fSIngo Molnar 235d8217f07SEric W. Biederman static struct ctl_table kern_table[] = { 23677e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 23777e54a1fSIngo Molnar { 23877e54a1fSIngo Molnar .ctl_name = CTL_UNNUMBERED, 239b2be5e96SPeter Zijlstra .procname = "sched_min_granularity_ns", 240b2be5e96SPeter Zijlstra .data = &sysctl_sched_min_granularity, 24177e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 24277e54a1fSIngo Molnar .mode = 0644, 243b2be5e96SPeter Zijlstra .proc_handler = &sched_nr_latency_handler, 244b2be5e96SPeter Zijlstra .strategy = &sysctl_intvec, 245b2be5e96SPeter Zijlstra .extra1 = &min_sched_granularity_ns, 246b2be5e96SPeter Zijlstra .extra2 = &max_sched_granularity_ns, 24777e54a1fSIngo Molnar }, 24877e54a1fSIngo Molnar { 24977e54a1fSIngo Molnar .ctl_name = CTL_UNNUMBERED, 25021805085SPeter Zijlstra .procname = "sched_latency_ns", 25121805085SPeter Zijlstra .data = &sysctl_sched_latency, 25221805085SPeter Zijlstra .maxlen = sizeof(unsigned int), 25321805085SPeter Zijlstra .mode = 0644, 254b2be5e96SPeter Zijlstra .proc_handler = &sched_nr_latency_handler, 25521805085SPeter Zijlstra .strategy = &sysctl_intvec, 25621805085SPeter Zijlstra .extra1 = &min_sched_granularity_ns, 25721805085SPeter Zijlstra .extra2 = &max_sched_granularity_ns, 25821805085SPeter Zijlstra }, 25921805085SPeter Zijlstra { 26021805085SPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 26177e54a1fSIngo Molnar .procname = "sched_wakeup_granularity_ns", 26277e54a1fSIngo Molnar .data = &sysctl_sched_wakeup_granularity, 26377e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 26477e54a1fSIngo Molnar .mode = 0644, 26577e54a1fSIngo Molnar .proc_handler = &proc_dointvec_minmax, 26677e54a1fSIngo Molnar .strategy = &sysctl_intvec, 26777e54a1fSIngo Molnar .extra1 = &min_wakeup_granularity_ns, 26877e54a1fSIngo Molnar .extra2 = &max_wakeup_granularity_ns, 26977e54a1fSIngo Molnar }, 27077e54a1fSIngo Molnar { 27177e54a1fSIngo Molnar .ctl_name = CTL_UNNUMBERED, 27277e54a1fSIngo Molnar .procname = "sched_batch_wakeup_granularity_ns", 27377e54a1fSIngo Molnar .data = &sysctl_sched_batch_wakeup_granularity, 27477e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 27577e54a1fSIngo Molnar .mode = 0644, 27677e54a1fSIngo Molnar .proc_handler = &proc_dointvec_minmax, 27777e54a1fSIngo Molnar .strategy = &sysctl_intvec, 27877e54a1fSIngo Molnar .extra1 = &min_wakeup_granularity_ns, 27977e54a1fSIngo Molnar .extra2 = &max_wakeup_granularity_ns, 28077e54a1fSIngo Molnar }, 28177e54a1fSIngo Molnar { 28277e54a1fSIngo Molnar .ctl_name = CTL_UNNUMBERED, 28377e54a1fSIngo Molnar .procname = "sched_child_runs_first", 28477e54a1fSIngo Molnar .data = &sysctl_sched_child_runs_first, 28577e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 28677e54a1fSIngo Molnar .mode = 0644, 28777e54a1fSIngo Molnar .proc_handler = &proc_dointvec, 28877e54a1fSIngo Molnar }, 2891fc84aaaSPeter Zijlstra { 2901fc84aaaSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 2911fc84aaaSPeter Zijlstra .procname = "sched_features", 2921fc84aaaSPeter Zijlstra .data = &sysctl_sched_features, 2931fc84aaaSPeter Zijlstra .maxlen = sizeof(unsigned int), 2941fc84aaaSPeter Zijlstra .mode = 0644, 2951fc84aaaSPeter Zijlstra .proc_handler = &proc_dointvec, 2961fc84aaaSPeter Zijlstra }, 297da84d961SIngo Molnar { 298da84d961SIngo Molnar .ctl_name = CTL_UNNUMBERED, 299da84d961SIngo Molnar .procname = "sched_migration_cost", 300da84d961SIngo Molnar .data = &sysctl_sched_migration_cost, 301da84d961SIngo Molnar .maxlen = sizeof(unsigned int), 302da84d961SIngo Molnar .mode = 0644, 303da84d961SIngo Molnar .proc_handler = &proc_dointvec, 304da84d961SIngo Molnar }, 305b82d9fddSPeter Zijlstra { 306b82d9fddSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 307b82d9fddSPeter Zijlstra .procname = "sched_nr_migrate", 308b82d9fddSPeter Zijlstra .data = &sysctl_sched_nr_migrate, 309b82d9fddSPeter Zijlstra .maxlen = sizeof(unsigned int), 310fa85ae24SPeter Zijlstra .mode = 0644, 311fa85ae24SPeter Zijlstra .proc_handler = &proc_dointvec, 312fa85ae24SPeter Zijlstra }, 313fa85ae24SPeter Zijlstra { 314fa85ae24SPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 315fa85ae24SPeter Zijlstra .procname = "sched_rt_period_ms", 316fa85ae24SPeter Zijlstra .data = &sysctl_sched_rt_period, 317fa85ae24SPeter Zijlstra .maxlen = sizeof(unsigned int), 318fa85ae24SPeter Zijlstra .mode = 0644, 319fa85ae24SPeter Zijlstra .proc_handler = &proc_dointvec, 320fa85ae24SPeter Zijlstra }, 321fa85ae24SPeter Zijlstra { 322fa85ae24SPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 323fa85ae24SPeter Zijlstra .procname = "sched_rt_ratio", 324fa85ae24SPeter Zijlstra .data = &sysctl_sched_rt_ratio, 325fa85ae24SPeter Zijlstra .maxlen = sizeof(unsigned int), 326fa85ae24SPeter Zijlstra .mode = 0644, 327b82d9fddSPeter Zijlstra .proc_handler = &proc_dointvec, 328b82d9fddSPeter Zijlstra }, 3296b2d7700SSrivatsa Vaddagiri #if defined(CONFIG_FAIR_GROUP_SCHED) && defined(CONFIG_SMP) 3306b2d7700SSrivatsa Vaddagiri { 3316b2d7700SSrivatsa Vaddagiri .ctl_name = CTL_UNNUMBERED, 3326b2d7700SSrivatsa Vaddagiri .procname = "sched_min_bal_int_shares", 3336b2d7700SSrivatsa Vaddagiri .data = &sysctl_sched_min_bal_int_shares, 3346b2d7700SSrivatsa Vaddagiri .maxlen = sizeof(unsigned int), 3356b2d7700SSrivatsa Vaddagiri .mode = 0644, 3366b2d7700SSrivatsa Vaddagiri .proc_handler = &proc_dointvec, 3376b2d7700SSrivatsa Vaddagiri }, 3386b2d7700SSrivatsa Vaddagiri { 3396b2d7700SSrivatsa Vaddagiri .ctl_name = CTL_UNNUMBERED, 3406b2d7700SSrivatsa Vaddagiri .procname = "sched_max_bal_int_shares", 3416b2d7700SSrivatsa Vaddagiri .data = &sysctl_sched_max_bal_int_shares, 3426b2d7700SSrivatsa Vaddagiri .maxlen = sizeof(unsigned int), 3436b2d7700SSrivatsa Vaddagiri .mode = 0644, 3446b2d7700SSrivatsa Vaddagiri .proc_handler = &proc_dointvec, 3456b2d7700SSrivatsa Vaddagiri }, 3466b2d7700SSrivatsa Vaddagiri #endif 3471fc84aaaSPeter Zijlstra #endif 3481799e35dSIngo Molnar { 3491799e35dSIngo Molnar .ctl_name = CTL_UNNUMBERED, 3501799e35dSIngo Molnar .procname = "sched_compat_yield", 3511799e35dSIngo Molnar .data = &sysctl_sched_compat_yield, 3521799e35dSIngo Molnar .maxlen = sizeof(unsigned int), 3531799e35dSIngo Molnar .mode = 0644, 3541799e35dSIngo Molnar .proc_handler = &proc_dointvec, 3551799e35dSIngo Molnar }, 356f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING 357f20786ffSPeter Zijlstra { 358f20786ffSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 359f20786ffSPeter Zijlstra .procname = "prove_locking", 360f20786ffSPeter Zijlstra .data = &prove_locking, 361f20786ffSPeter Zijlstra .maxlen = sizeof(int), 362f20786ffSPeter Zijlstra .mode = 0644, 363f20786ffSPeter Zijlstra .proc_handler = &proc_dointvec, 364f20786ffSPeter Zijlstra }, 365f20786ffSPeter Zijlstra #endif 366f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT 367f20786ffSPeter Zijlstra { 368f20786ffSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 369f20786ffSPeter Zijlstra .procname = "lock_stat", 370f20786ffSPeter Zijlstra .data = &lock_stat, 371f20786ffSPeter Zijlstra .maxlen = sizeof(int), 372f20786ffSPeter Zijlstra .mode = 0644, 373f20786ffSPeter Zijlstra .proc_handler = &proc_dointvec, 374f20786ffSPeter Zijlstra }, 375f20786ffSPeter Zijlstra #endif 37677e54a1fSIngo Molnar { 3771da177e4SLinus Torvalds .ctl_name = KERN_PANIC, 3781da177e4SLinus Torvalds .procname = "panic", 3791da177e4SLinus Torvalds .data = &panic_timeout, 3801da177e4SLinus Torvalds .maxlen = sizeof(int), 3811da177e4SLinus Torvalds .mode = 0644, 3821da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 3831da177e4SLinus Torvalds }, 3841da177e4SLinus Torvalds { 3851da177e4SLinus Torvalds .ctl_name = KERN_CORE_USES_PID, 3861da177e4SLinus Torvalds .procname = "core_uses_pid", 3871da177e4SLinus Torvalds .data = &core_uses_pid, 3881da177e4SLinus Torvalds .maxlen = sizeof(int), 3891da177e4SLinus Torvalds .mode = 0644, 3901da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 3911da177e4SLinus Torvalds }, 392bdf4c48aSPeter Zijlstra #ifdef CONFIG_AUDITSYSCALL 393bdf4c48aSPeter Zijlstra { 394bdf4c48aSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 395bdf4c48aSPeter Zijlstra .procname = "audit_argv_kb", 396bdf4c48aSPeter Zijlstra .data = &audit_argv_kb, 397bdf4c48aSPeter Zijlstra .maxlen = sizeof(int), 398bdf4c48aSPeter Zijlstra .mode = 0644, 399bdf4c48aSPeter Zijlstra .proc_handler = &proc_dointvec, 400bdf4c48aSPeter Zijlstra }, 401bdf4c48aSPeter Zijlstra #endif 4021da177e4SLinus Torvalds { 4031da177e4SLinus Torvalds .ctl_name = KERN_CORE_PATTERN, 4041da177e4SLinus Torvalds .procname = "core_pattern", 4051da177e4SLinus Torvalds .data = core_pattern, 40671ce92f3SDan Aloni .maxlen = CORENAME_MAX_SIZE, 4071da177e4SLinus Torvalds .mode = 0644, 4081da177e4SLinus Torvalds .proc_handler = &proc_dostring, 4091da177e4SLinus Torvalds .strategy = &sysctl_string, 4101da177e4SLinus Torvalds }, 41134f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL 4121da177e4SLinus Torvalds { 4131da177e4SLinus Torvalds .procname = "tainted", 4141da177e4SLinus Torvalds .data = &tainted, 4151da177e4SLinus Torvalds .maxlen = sizeof(int), 41634f5a398STheodore Ts'o .mode = 0644, 41734f5a398STheodore Ts'o .proc_handler = &proc_dointvec_taint, 4181da177e4SLinus Torvalds }, 41934f5a398STheodore Ts'o #endif 4209745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 4219745512cSArjan van de Ven { 4229745512cSArjan van de Ven .procname = "latencytop", 4239745512cSArjan van de Ven .data = &latencytop_enabled, 4249745512cSArjan van de Ven .maxlen = sizeof(int), 4259745512cSArjan van de Ven .mode = 0644, 4269745512cSArjan van de Ven .proc_handler = &proc_dointvec, 4279745512cSArjan van de Ven }, 4289745512cSArjan van de Ven #endif 42972c2d582SAndrew Morgan #ifdef CONFIG_SECURITY_CAPABILITIES 4301da177e4SLinus Torvalds { 4311da177e4SLinus Torvalds .procname = "cap-bound", 4321da177e4SLinus Torvalds .data = &cap_bset, 4331da177e4SLinus Torvalds .maxlen = sizeof(kernel_cap_t), 4341da177e4SLinus Torvalds .mode = 0600, 4351da177e4SLinus Torvalds .proc_handler = &proc_dointvec_bset, 4361da177e4SLinus Torvalds }, 43772c2d582SAndrew Morgan #endif /* def CONFIG_SECURITY_CAPABILITIES */ 4381da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 4391da177e4SLinus Torvalds { 4401da177e4SLinus Torvalds .ctl_name = KERN_REALROOTDEV, 4411da177e4SLinus Torvalds .procname = "real-root-dev", 4421da177e4SLinus Torvalds .data = &real_root_dev, 4431da177e4SLinus Torvalds .maxlen = sizeof(int), 4441da177e4SLinus Torvalds .mode = 0644, 4451da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4461da177e4SLinus Torvalds }, 4471da177e4SLinus Torvalds #endif 44845807a1dSIngo Molnar { 44945807a1dSIngo Molnar .ctl_name = CTL_UNNUMBERED, 45045807a1dSIngo Molnar .procname = "print-fatal-signals", 45145807a1dSIngo Molnar .data = &print_fatal_signals, 45245807a1dSIngo Molnar .maxlen = sizeof(int), 45345807a1dSIngo Molnar .mode = 0644, 45445807a1dSIngo Molnar .proc_handler = &proc_dointvec, 45545807a1dSIngo Molnar }, 4561da177e4SLinus Torvalds #ifdef __sparc__ 4571da177e4SLinus Torvalds { 4581da177e4SLinus Torvalds .ctl_name = KERN_SPARC_REBOOT, 4591da177e4SLinus Torvalds .procname = "reboot-cmd", 4601da177e4SLinus Torvalds .data = reboot_command, 4611da177e4SLinus Torvalds .maxlen = 256, 4621da177e4SLinus Torvalds .mode = 0644, 4631da177e4SLinus Torvalds .proc_handler = &proc_dostring, 4641da177e4SLinus Torvalds .strategy = &sysctl_string, 4651da177e4SLinus Torvalds }, 4661da177e4SLinus Torvalds { 4671da177e4SLinus Torvalds .ctl_name = KERN_SPARC_STOP_A, 4681da177e4SLinus Torvalds .procname = "stop-a", 4691da177e4SLinus Torvalds .data = &stop_a_enabled, 4701da177e4SLinus Torvalds .maxlen = sizeof (int), 4711da177e4SLinus Torvalds .mode = 0644, 4721da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4731da177e4SLinus Torvalds }, 4741da177e4SLinus Torvalds { 4751da177e4SLinus Torvalds .ctl_name = KERN_SPARC_SCONS_PWROFF, 4761da177e4SLinus Torvalds .procname = "scons-poweroff", 4771da177e4SLinus Torvalds .data = &scons_pwroff, 4781da177e4SLinus Torvalds .maxlen = sizeof (int), 4791da177e4SLinus Torvalds .mode = 0644, 4801da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4811da177e4SLinus Torvalds }, 4821da177e4SLinus Torvalds #endif 4831da177e4SLinus Torvalds #ifdef __hppa__ 4841da177e4SLinus Torvalds { 4851da177e4SLinus Torvalds .ctl_name = KERN_HPPA_PWRSW, 4861da177e4SLinus Torvalds .procname = "soft-power", 4871da177e4SLinus Torvalds .data = &pwrsw_enabled, 4881da177e4SLinus Torvalds .maxlen = sizeof (int), 4891da177e4SLinus Torvalds .mode = 0644, 4901da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4911da177e4SLinus Torvalds }, 4921da177e4SLinus Torvalds { 4931da177e4SLinus Torvalds .ctl_name = KERN_HPPA_UNALIGNED, 4941da177e4SLinus Torvalds .procname = "unaligned-trap", 4951da177e4SLinus Torvalds .data = &unaligned_enabled, 4961da177e4SLinus Torvalds .maxlen = sizeof (int), 4971da177e4SLinus Torvalds .mode = 0644, 4981da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4991da177e4SLinus Torvalds }, 5001da177e4SLinus Torvalds #endif 5011da177e4SLinus Torvalds { 5021da177e4SLinus Torvalds .ctl_name = KERN_CTLALTDEL, 5031da177e4SLinus Torvalds .procname = "ctrl-alt-del", 5041da177e4SLinus Torvalds .data = &C_A_D, 5051da177e4SLinus Torvalds .maxlen = sizeof(int), 5061da177e4SLinus Torvalds .mode = 0644, 5071da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5081da177e4SLinus Torvalds }, 5091da177e4SLinus Torvalds { 5101da177e4SLinus Torvalds .ctl_name = KERN_PRINTK, 5111da177e4SLinus Torvalds .procname = "printk", 5121da177e4SLinus Torvalds .data = &console_loglevel, 5131da177e4SLinus Torvalds .maxlen = 4*sizeof(int), 5141da177e4SLinus Torvalds .mode = 0644, 5151da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5161da177e4SLinus Torvalds }, 5171da177e4SLinus Torvalds #ifdef CONFIG_KMOD 5181da177e4SLinus Torvalds { 5191da177e4SLinus Torvalds .ctl_name = KERN_MODPROBE, 5201da177e4SLinus Torvalds .procname = "modprobe", 5211da177e4SLinus Torvalds .data = &modprobe_path, 5221da177e4SLinus Torvalds .maxlen = KMOD_PATH_LEN, 5231da177e4SLinus Torvalds .mode = 0644, 5241da177e4SLinus Torvalds .proc_handler = &proc_dostring, 5251da177e4SLinus Torvalds .strategy = &sysctl_string, 5261da177e4SLinus Torvalds }, 5271da177e4SLinus Torvalds #endif 52857ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) 5291da177e4SLinus Torvalds { 5301da177e4SLinus Torvalds .ctl_name = KERN_HOTPLUG, 5311da177e4SLinus Torvalds .procname = "hotplug", 532312c004dSKay Sievers .data = &uevent_helper, 533312c004dSKay Sievers .maxlen = UEVENT_HELPER_PATH_LEN, 5341da177e4SLinus Torvalds .mode = 0644, 5351da177e4SLinus Torvalds .proc_handler = &proc_dostring, 5361da177e4SLinus Torvalds .strategy = &sysctl_string, 5371da177e4SLinus Torvalds }, 5381da177e4SLinus Torvalds #endif 5391da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG 5401da177e4SLinus Torvalds { 5411da177e4SLinus Torvalds .ctl_name = KERN_SG_BIG_BUFF, 5421da177e4SLinus Torvalds .procname = "sg-big-buff", 5431da177e4SLinus Torvalds .data = &sg_big_buff, 5441da177e4SLinus Torvalds .maxlen = sizeof (int), 5451da177e4SLinus Torvalds .mode = 0444, 5461da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5471da177e4SLinus Torvalds }, 5481da177e4SLinus Torvalds #endif 5491da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT 5501da177e4SLinus Torvalds { 5511da177e4SLinus Torvalds .ctl_name = KERN_ACCT, 5521da177e4SLinus Torvalds .procname = "acct", 5531da177e4SLinus Torvalds .data = &acct_parm, 5541da177e4SLinus Torvalds .maxlen = 3*sizeof(int), 5551da177e4SLinus Torvalds .mode = 0644, 5561da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5571da177e4SLinus Torvalds }, 5581da177e4SLinus Torvalds #endif 5591da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ 5601da177e4SLinus Torvalds { 5611da177e4SLinus Torvalds .ctl_name = KERN_SYSRQ, 5621da177e4SLinus Torvalds .procname = "sysrq", 5635d6f647fSIngo Molnar .data = &__sysrq_enabled, 5641da177e4SLinus Torvalds .maxlen = sizeof (int), 5651da177e4SLinus Torvalds .mode = 0644, 5661da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5671da177e4SLinus Torvalds }, 5681da177e4SLinus Torvalds #endif 569d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 5701da177e4SLinus Torvalds { 5711da177e4SLinus Torvalds .procname = "cad_pid", 5729ec52099SCedric Le Goater .data = NULL, 5731da177e4SLinus Torvalds .maxlen = sizeof (int), 5741da177e4SLinus Torvalds .mode = 0600, 5759ec52099SCedric Le Goater .proc_handler = &proc_do_cad_pid, 5761da177e4SLinus Torvalds }, 577d6f8ff73SRandy Dunlap #endif 5781da177e4SLinus Torvalds { 5791da177e4SLinus Torvalds .ctl_name = KERN_MAX_THREADS, 5801da177e4SLinus Torvalds .procname = "threads-max", 5811da177e4SLinus Torvalds .data = &max_threads, 5821da177e4SLinus Torvalds .maxlen = sizeof(int), 5831da177e4SLinus Torvalds .mode = 0644, 5841da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5851da177e4SLinus Torvalds }, 5861da177e4SLinus Torvalds { 5871da177e4SLinus Torvalds .ctl_name = KERN_RANDOM, 5881da177e4SLinus Torvalds .procname = "random", 5891da177e4SLinus Torvalds .mode = 0555, 5901da177e4SLinus Torvalds .child = random_table, 5911da177e4SLinus Torvalds }, 5921da177e4SLinus Torvalds { 5931da177e4SLinus Torvalds .ctl_name = KERN_OVERFLOWUID, 5941da177e4SLinus Torvalds .procname = "overflowuid", 5951da177e4SLinus Torvalds .data = &overflowuid, 5961da177e4SLinus Torvalds .maxlen = sizeof(int), 5971da177e4SLinus Torvalds .mode = 0644, 5981da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 5991da177e4SLinus Torvalds .strategy = &sysctl_intvec, 6001da177e4SLinus Torvalds .extra1 = &minolduid, 6011da177e4SLinus Torvalds .extra2 = &maxolduid, 6021da177e4SLinus Torvalds }, 6031da177e4SLinus Torvalds { 6041da177e4SLinus Torvalds .ctl_name = KERN_OVERFLOWGID, 6051da177e4SLinus Torvalds .procname = "overflowgid", 6061da177e4SLinus Torvalds .data = &overflowgid, 6071da177e4SLinus Torvalds .maxlen = sizeof(int), 6081da177e4SLinus Torvalds .mode = 0644, 6091da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 6101da177e4SLinus Torvalds .strategy = &sysctl_intvec, 6111da177e4SLinus Torvalds .extra1 = &minolduid, 6121da177e4SLinus Torvalds .extra2 = &maxolduid, 6131da177e4SLinus Torvalds }, 614347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 6151da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 6161da177e4SLinus Torvalds { 6171da177e4SLinus Torvalds .ctl_name = KERN_IEEE_EMULATION_WARNINGS, 6181da177e4SLinus Torvalds .procname = "ieee_emulation_warnings", 6191da177e4SLinus Torvalds .data = &sysctl_ieee_emulation_warnings, 6201da177e4SLinus Torvalds .maxlen = sizeof(int), 6211da177e4SLinus Torvalds .mode = 0644, 6221da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6231da177e4SLinus Torvalds }, 6241da177e4SLinus Torvalds #endif 6251da177e4SLinus Torvalds #ifdef CONFIG_NO_IDLE_HZ 6261da177e4SLinus Torvalds { 6271da177e4SLinus Torvalds .ctl_name = KERN_HZ_TIMER, 6281da177e4SLinus Torvalds .procname = "hz_timer", 6291da177e4SLinus Torvalds .data = &sysctl_hz_timer, 6301da177e4SLinus Torvalds .maxlen = sizeof(int), 6311da177e4SLinus Torvalds .mode = 0644, 6321da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6331da177e4SLinus Torvalds }, 6341da177e4SLinus Torvalds #endif 6351da177e4SLinus Torvalds { 6361da177e4SLinus Torvalds .ctl_name = KERN_S390_USER_DEBUG_LOGGING, 6371da177e4SLinus Torvalds .procname = "userprocess_debug", 6381da177e4SLinus Torvalds .data = &sysctl_userprocess_debug, 6391da177e4SLinus Torvalds .maxlen = sizeof(int), 6401da177e4SLinus Torvalds .mode = 0644, 6411da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6421da177e4SLinus Torvalds }, 6431da177e4SLinus Torvalds #endif 6441da177e4SLinus Torvalds { 6451da177e4SLinus Torvalds .ctl_name = KERN_PIDMAX, 6461da177e4SLinus Torvalds .procname = "pid_max", 6471da177e4SLinus Torvalds .data = &pid_max, 6481da177e4SLinus Torvalds .maxlen = sizeof (int), 6491da177e4SLinus Torvalds .mode = 0644, 6501da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 6511da177e4SLinus Torvalds .strategy = sysctl_intvec, 6521da177e4SLinus Torvalds .extra1 = &pid_max_min, 6531da177e4SLinus Torvalds .extra2 = &pid_max_max, 6541da177e4SLinus Torvalds }, 6551da177e4SLinus Torvalds { 6561da177e4SLinus Torvalds .ctl_name = KERN_PANIC_ON_OOPS, 6571da177e4SLinus Torvalds .procname = "panic_on_oops", 6581da177e4SLinus Torvalds .data = &panic_on_oops, 6591da177e4SLinus Torvalds .maxlen = sizeof(int), 6601da177e4SLinus Torvalds .mode = 0644, 6611da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6621da177e4SLinus Torvalds }, 6631da177e4SLinus Torvalds { 6641da177e4SLinus Torvalds .ctl_name = KERN_PRINTK_RATELIMIT, 6651da177e4SLinus Torvalds .procname = "printk_ratelimit", 6661da177e4SLinus Torvalds .data = &printk_ratelimit_jiffies, 6671da177e4SLinus Torvalds .maxlen = sizeof(int), 6681da177e4SLinus Torvalds .mode = 0644, 6691da177e4SLinus Torvalds .proc_handler = &proc_dointvec_jiffies, 6701da177e4SLinus Torvalds .strategy = &sysctl_jiffies, 6711da177e4SLinus Torvalds }, 6721da177e4SLinus Torvalds { 6731da177e4SLinus Torvalds .ctl_name = KERN_PRINTK_RATELIMIT_BURST, 6741da177e4SLinus Torvalds .procname = "printk_ratelimit_burst", 6751da177e4SLinus Torvalds .data = &printk_ratelimit_burst, 6761da177e4SLinus Torvalds .maxlen = sizeof(int), 6771da177e4SLinus Torvalds .mode = 0644, 6781da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6791da177e4SLinus Torvalds }, 6801da177e4SLinus Torvalds { 6811da177e4SLinus Torvalds .ctl_name = KERN_NGROUPS_MAX, 6821da177e4SLinus Torvalds .procname = "ngroups_max", 6831da177e4SLinus Torvalds .data = &ngroups_max, 6841da177e4SLinus Torvalds .maxlen = sizeof (int), 6851da177e4SLinus Torvalds .mode = 0444, 6861da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6871da177e4SLinus Torvalds }, 6881da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) 6891da177e4SLinus Torvalds { 6901da177e4SLinus Torvalds .ctl_name = KERN_UNKNOWN_NMI_PANIC, 6911da177e4SLinus Torvalds .procname = "unknown_nmi_panic", 6921da177e4SLinus Torvalds .data = &unknown_nmi_panic, 6931da177e4SLinus Torvalds .maxlen = sizeof (int), 6941da177e4SLinus Torvalds .mode = 0644, 6952fbe7b25SDon Zickus .proc_handler = &proc_dointvec, 6961da177e4SLinus Torvalds }, 697407984f1SDon Zickus { 698407984f1SDon Zickus .procname = "nmi_watchdog", 699407984f1SDon Zickus .data = &nmi_watchdog_enabled, 700407984f1SDon Zickus .maxlen = sizeof (int), 701407984f1SDon Zickus .mode = 0644, 702407984f1SDon Zickus .proc_handler = &proc_nmi_enabled, 7031da177e4SLinus Torvalds }, 7041da177e4SLinus Torvalds #endif 7051da177e4SLinus Torvalds #if defined(CONFIG_X86) 7061da177e4SLinus Torvalds { 7078da5addaSDon Zickus .ctl_name = KERN_PANIC_ON_NMI, 7088da5addaSDon Zickus .procname = "panic_on_unrecovered_nmi", 7098da5addaSDon Zickus .data = &panic_on_unrecovered_nmi, 7108da5addaSDon Zickus .maxlen = sizeof(int), 7118da5addaSDon Zickus .mode = 0644, 7128da5addaSDon Zickus .proc_handler = &proc_dointvec, 7138da5addaSDon Zickus }, 7148da5addaSDon Zickus { 7151da177e4SLinus Torvalds .ctl_name = KERN_BOOTLOADER_TYPE, 7161da177e4SLinus Torvalds .procname = "bootloader_type", 7171da177e4SLinus Torvalds .data = &bootloader_type, 7181da177e4SLinus Torvalds .maxlen = sizeof (int), 7191da177e4SLinus Torvalds .mode = 0444, 7201da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 7211da177e4SLinus Torvalds }, 7220741f4d2SChuck Ebbert { 7230741f4d2SChuck Ebbert .ctl_name = CTL_UNNUMBERED, 7240741f4d2SChuck Ebbert .procname = "kstack_depth_to_print", 7250741f4d2SChuck Ebbert .data = &kstack_depth_to_print, 7260741f4d2SChuck Ebbert .maxlen = sizeof(int), 7270741f4d2SChuck Ebbert .mode = 0644, 7280741f4d2SChuck Ebbert .proc_handler = &proc_dointvec, 7290741f4d2SChuck Ebbert }, 7301da177e4SLinus Torvalds #endif 7317a9166e3SLuke Yang #if defined(CONFIG_MMU) 7321da177e4SLinus Torvalds { 7331da177e4SLinus Torvalds .ctl_name = KERN_RANDOMIZE, 7341da177e4SLinus Torvalds .procname = "randomize_va_space", 7351da177e4SLinus Torvalds .data = &randomize_va_space, 7361da177e4SLinus Torvalds .maxlen = sizeof(int), 7371da177e4SLinus Torvalds .mode = 0644, 7381da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 7391da177e4SLinus Torvalds }, 7407a9166e3SLuke Yang #endif 7410152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP) 742951f22d5SMartin Schwidefsky { 743951f22d5SMartin Schwidefsky .ctl_name = KERN_SPIN_RETRY, 744951f22d5SMartin Schwidefsky .procname = "spin_retry", 745951f22d5SMartin Schwidefsky .data = &spin_retry, 746951f22d5SMartin Schwidefsky .maxlen = sizeof (int), 747951f22d5SMartin Schwidefsky .mode = 0644, 748951f22d5SMartin Schwidefsky .proc_handler = &proc_dointvec, 749951f22d5SMartin Schwidefsky }, 750951f22d5SMartin Schwidefsky #endif 751673d5b43SLen Brown #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 752c255d844SPavel Machek { 753c255d844SPavel Machek .procname = "acpi_video_flags", 75477afcf78SPavel Machek .data = &acpi_realmode_flags, 755c255d844SPavel Machek .maxlen = sizeof (unsigned long), 756c255d844SPavel Machek .mode = 0644, 7577f99f06fSStefan Seyfried .proc_handler = &proc_doulongvec_minmax, 758c255d844SPavel Machek }, 759c255d844SPavel Machek #endif 760d2b176edSJes Sorensen #ifdef CONFIG_IA64 761d2b176edSJes Sorensen { 762d2b176edSJes Sorensen .ctl_name = KERN_IA64_UNALIGNED, 763d2b176edSJes Sorensen .procname = "ignore-unaligned-usertrap", 764d2b176edSJes Sorensen .data = &no_unaligned_warning, 765d2b176edSJes Sorensen .maxlen = sizeof (int), 766d2b176edSJes Sorensen .mode = 0644, 767d2b176edSJes Sorensen .proc_handler = &proc_dointvec, 768d2b176edSJes Sorensen }, 769d2b176edSJes Sorensen #endif 770c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_DETECT_SOFTLOCKUP 771c4f3b63fSRavikiran G Thirumalai { 772c4f3b63fSRavikiran G Thirumalai .ctl_name = CTL_UNNUMBERED, 773c4f3b63fSRavikiran G Thirumalai .procname = "softlockup_thresh", 774c4f3b63fSRavikiran G Thirumalai .data = &softlockup_thresh, 77590739081SIngo Molnar .maxlen = sizeof(unsigned long), 776c4f3b63fSRavikiran G Thirumalai .mode = 0644, 77790739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 778c4f3b63fSRavikiran G Thirumalai .strategy = &sysctl_intvec, 779c4f3b63fSRavikiran G Thirumalai .extra1 = &one, 780c4f3b63fSRavikiran G Thirumalai .extra2 = &sixty, 781c4f3b63fSRavikiran G Thirumalai }, 78282a1fcb9SIngo Molnar { 78382a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 78482a1fcb9SIngo Molnar .procname = "hung_task_check_count", 78582a1fcb9SIngo Molnar .data = &sysctl_hung_task_check_count, 78690739081SIngo Molnar .maxlen = sizeof(unsigned long), 78782a1fcb9SIngo Molnar .mode = 0644, 78890739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 78982a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 79082a1fcb9SIngo Molnar }, 79182a1fcb9SIngo Molnar { 79282a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 79382a1fcb9SIngo Molnar .procname = "hung_task_timeout_secs", 79482a1fcb9SIngo Molnar .data = &sysctl_hung_task_timeout_secs, 79590739081SIngo Molnar .maxlen = sizeof(unsigned long), 79682a1fcb9SIngo Molnar .mode = 0644, 79790739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 79882a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 79982a1fcb9SIngo Molnar }, 80082a1fcb9SIngo Molnar { 80182a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 80282a1fcb9SIngo Molnar .procname = "hung_task_warnings", 80382a1fcb9SIngo Molnar .data = &sysctl_hung_task_warnings, 80490739081SIngo Molnar .maxlen = sizeof(unsigned long), 80582a1fcb9SIngo Molnar .mode = 0644, 80690739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 80782a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 80882a1fcb9SIngo Molnar }, 809c4f3b63fSRavikiran G Thirumalai #endif 810bebfa101SAndi Kleen #ifdef CONFIG_COMPAT 811bebfa101SAndi Kleen { 812bebfa101SAndi Kleen .ctl_name = KERN_COMPAT_LOG, 813bebfa101SAndi Kleen .procname = "compat-log", 814bebfa101SAndi Kleen .data = &compat_log, 815bebfa101SAndi Kleen .maxlen = sizeof (int), 816bebfa101SAndi Kleen .mode = 0644, 817bebfa101SAndi Kleen .proc_handler = &proc_dointvec, 818bebfa101SAndi Kleen }, 819bebfa101SAndi Kleen #endif 82023f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 82123f78d4aSIngo Molnar { 82223f78d4aSIngo Molnar .ctl_name = KERN_MAX_LOCK_DEPTH, 82323f78d4aSIngo Molnar .procname = "max_lock_depth", 82423f78d4aSIngo Molnar .data = &max_lock_depth, 82523f78d4aSIngo Molnar .maxlen = sizeof(int), 82623f78d4aSIngo Molnar .mode = 0644, 82723f78d4aSIngo Molnar .proc_handler = &proc_dointvec, 82823f78d4aSIngo Molnar }, 82923f78d4aSIngo Molnar #endif 8305096add8SKees Cook #ifdef CONFIG_PROC_FS 8315096add8SKees Cook { 8325096add8SKees Cook .ctl_name = CTL_UNNUMBERED, 8335096add8SKees Cook .procname = "maps_protect", 8345096add8SKees Cook .data = &maps_protect, 8355096add8SKees Cook .maxlen = sizeof(int), 8365096add8SKees Cook .mode = 0644, 8375096add8SKees Cook .proc_handler = &proc_dointvec, 8385096add8SKees Cook }, 8395096add8SKees Cook #endif 84010a0a8d4SJeremy Fitzhardinge { 84110a0a8d4SJeremy Fitzhardinge .ctl_name = CTL_UNNUMBERED, 84210a0a8d4SJeremy Fitzhardinge .procname = "poweroff_cmd", 84310a0a8d4SJeremy Fitzhardinge .data = &poweroff_cmd, 84410a0a8d4SJeremy Fitzhardinge .maxlen = POWEROFF_CMD_PATH_LEN, 84510a0a8d4SJeremy Fitzhardinge .mode = 0644, 84610a0a8d4SJeremy Fitzhardinge .proc_handler = &proc_dostring, 84710a0a8d4SJeremy Fitzhardinge .strategy = &sysctl_string, 84810a0a8d4SJeremy Fitzhardinge }, 849ed2c12f3SAndrew Morton /* 850ed2c12f3SAndrew Morton * NOTE: do not add new entries to this table unless you have read 851ed2c12f3SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 852ed2c12f3SAndrew Morton */ 8531da177e4SLinus Torvalds { .ctl_name = 0 } 8541da177e4SLinus Torvalds }; 8551da177e4SLinus Torvalds 856d8217f07SEric W. Biederman static struct ctl_table vm_table[] = { 8571da177e4SLinus Torvalds { 8581da177e4SLinus Torvalds .ctl_name = VM_OVERCOMMIT_MEMORY, 8591da177e4SLinus Torvalds .procname = "overcommit_memory", 8601da177e4SLinus Torvalds .data = &sysctl_overcommit_memory, 8611da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_memory), 8621da177e4SLinus Torvalds .mode = 0644, 8631da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 8641da177e4SLinus Torvalds }, 8651da177e4SLinus Torvalds { 866fadd8fbdSKAMEZAWA Hiroyuki .ctl_name = VM_PANIC_ON_OOM, 867fadd8fbdSKAMEZAWA Hiroyuki .procname = "panic_on_oom", 868fadd8fbdSKAMEZAWA Hiroyuki .data = &sysctl_panic_on_oom, 869fadd8fbdSKAMEZAWA Hiroyuki .maxlen = sizeof(sysctl_panic_on_oom), 870fadd8fbdSKAMEZAWA Hiroyuki .mode = 0644, 871fadd8fbdSKAMEZAWA Hiroyuki .proc_handler = &proc_dointvec, 872fadd8fbdSKAMEZAWA Hiroyuki }, 873fadd8fbdSKAMEZAWA Hiroyuki { 874fe071d7eSDavid Rientjes .ctl_name = CTL_UNNUMBERED, 875fe071d7eSDavid Rientjes .procname = "oom_kill_allocating_task", 876fe071d7eSDavid Rientjes .data = &sysctl_oom_kill_allocating_task, 877fe071d7eSDavid Rientjes .maxlen = sizeof(sysctl_oom_kill_allocating_task), 878fe071d7eSDavid Rientjes .mode = 0644, 879fe071d7eSDavid Rientjes .proc_handler = &proc_dointvec, 880fe071d7eSDavid Rientjes }, 881fe071d7eSDavid Rientjes { 8821da177e4SLinus Torvalds .ctl_name = VM_OVERCOMMIT_RATIO, 8831da177e4SLinus Torvalds .procname = "overcommit_ratio", 8841da177e4SLinus Torvalds .data = &sysctl_overcommit_ratio, 8851da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_ratio), 8861da177e4SLinus Torvalds .mode = 0644, 8871da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 8881da177e4SLinus Torvalds }, 8891da177e4SLinus Torvalds { 8901da177e4SLinus Torvalds .ctl_name = VM_PAGE_CLUSTER, 8911da177e4SLinus Torvalds .procname = "page-cluster", 8921da177e4SLinus Torvalds .data = &page_cluster, 8931da177e4SLinus Torvalds .maxlen = sizeof(int), 8941da177e4SLinus Torvalds .mode = 0644, 8951da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 8961da177e4SLinus Torvalds }, 8971da177e4SLinus Torvalds { 8981da177e4SLinus Torvalds .ctl_name = VM_DIRTY_BACKGROUND, 8991da177e4SLinus Torvalds .procname = "dirty_background_ratio", 9001da177e4SLinus Torvalds .data = &dirty_background_ratio, 9011da177e4SLinus Torvalds .maxlen = sizeof(dirty_background_ratio), 9021da177e4SLinus Torvalds .mode = 0644, 9031da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 9041da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9051da177e4SLinus Torvalds .extra1 = &zero, 9061da177e4SLinus Torvalds .extra2 = &one_hundred, 9071da177e4SLinus Torvalds }, 9081da177e4SLinus Torvalds { 9091da177e4SLinus Torvalds .ctl_name = VM_DIRTY_RATIO, 9101da177e4SLinus Torvalds .procname = "dirty_ratio", 9111da177e4SLinus Torvalds .data = &vm_dirty_ratio, 9121da177e4SLinus Torvalds .maxlen = sizeof(vm_dirty_ratio), 9131da177e4SLinus Torvalds .mode = 0644, 91404fbfdc1SPeter Zijlstra .proc_handler = &dirty_ratio_handler, 9151da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9161da177e4SLinus Torvalds .extra1 = &zero, 9171da177e4SLinus Torvalds .extra2 = &one_hundred, 9181da177e4SLinus Torvalds }, 9191da177e4SLinus Torvalds { 9201da177e4SLinus Torvalds .procname = "dirty_writeback_centisecs", 921f6ef9438SBart Samwel .data = &dirty_writeback_interval, 922f6ef9438SBart Samwel .maxlen = sizeof(dirty_writeback_interval), 9231da177e4SLinus Torvalds .mode = 0644, 9241da177e4SLinus Torvalds .proc_handler = &dirty_writeback_centisecs_handler, 9251da177e4SLinus Torvalds }, 9261da177e4SLinus Torvalds { 9271da177e4SLinus Torvalds .procname = "dirty_expire_centisecs", 928f6ef9438SBart Samwel .data = &dirty_expire_interval, 929f6ef9438SBart Samwel .maxlen = sizeof(dirty_expire_interval), 9301da177e4SLinus Torvalds .mode = 0644, 931f6ef9438SBart Samwel .proc_handler = &proc_dointvec_userhz_jiffies, 9321da177e4SLinus Torvalds }, 9331da177e4SLinus Torvalds { 9341da177e4SLinus Torvalds .ctl_name = VM_NR_PDFLUSH_THREADS, 9351da177e4SLinus Torvalds .procname = "nr_pdflush_threads", 9361da177e4SLinus Torvalds .data = &nr_pdflush_threads, 9371da177e4SLinus Torvalds .maxlen = sizeof nr_pdflush_threads, 9381da177e4SLinus Torvalds .mode = 0444 /* read-only*/, 9391da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 9401da177e4SLinus Torvalds }, 9411da177e4SLinus Torvalds { 9421da177e4SLinus Torvalds .ctl_name = VM_SWAPPINESS, 9431da177e4SLinus Torvalds .procname = "swappiness", 9441da177e4SLinus Torvalds .data = &vm_swappiness, 9451da177e4SLinus Torvalds .maxlen = sizeof(vm_swappiness), 9461da177e4SLinus Torvalds .mode = 0644, 9471da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 9481da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9491da177e4SLinus Torvalds .extra1 = &zero, 9501da177e4SLinus Torvalds .extra2 = &one_hundred, 9511da177e4SLinus Torvalds }, 9521da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE 9531da177e4SLinus Torvalds { 9541da177e4SLinus Torvalds .procname = "nr_hugepages", 9551da177e4SLinus Torvalds .data = &max_huge_pages, 9561da177e4SLinus Torvalds .maxlen = sizeof(unsigned long), 9571da177e4SLinus Torvalds .mode = 0644, 9581da177e4SLinus Torvalds .proc_handler = &hugetlb_sysctl_handler, 9591da177e4SLinus Torvalds .extra1 = (void *)&hugetlb_zero, 9601da177e4SLinus Torvalds .extra2 = (void *)&hugetlb_infinity, 9611da177e4SLinus Torvalds }, 9621da177e4SLinus Torvalds { 9631da177e4SLinus Torvalds .ctl_name = VM_HUGETLB_GROUP, 9641da177e4SLinus Torvalds .procname = "hugetlb_shm_group", 9651da177e4SLinus Torvalds .data = &sysctl_hugetlb_shm_group, 9661da177e4SLinus Torvalds .maxlen = sizeof(gid_t), 9671da177e4SLinus Torvalds .mode = 0644, 9681da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 9691da177e4SLinus Torvalds }, 970396faf03SMel Gorman { 971396faf03SMel Gorman .ctl_name = CTL_UNNUMBERED, 972396faf03SMel Gorman .procname = "hugepages_treat_as_movable", 973396faf03SMel Gorman .data = &hugepages_treat_as_movable, 974396faf03SMel Gorman .maxlen = sizeof(int), 975396faf03SMel Gorman .mode = 0644, 976396faf03SMel Gorman .proc_handler = &hugetlb_treat_movable_handler, 977396faf03SMel Gorman }, 97854f9f80dSAdam Litke { 97954f9f80dSAdam Litke .ctl_name = CTL_UNNUMBERED, 980d1c3fb1fSNishanth Aravamudan .procname = "nr_overcommit_hugepages", 981d1c3fb1fSNishanth Aravamudan .data = &nr_overcommit_huge_pages, 982d1c3fb1fSNishanth Aravamudan .maxlen = sizeof(nr_overcommit_huge_pages), 983d1c3fb1fSNishanth Aravamudan .mode = 0644, 984d1c3fb1fSNishanth Aravamudan .proc_handler = &proc_doulongvec_minmax, 985d1c3fb1fSNishanth Aravamudan }, 9861da177e4SLinus Torvalds #endif 9871da177e4SLinus Torvalds { 9881da177e4SLinus Torvalds .ctl_name = VM_LOWMEM_RESERVE_RATIO, 9891da177e4SLinus Torvalds .procname = "lowmem_reserve_ratio", 9901da177e4SLinus Torvalds .data = &sysctl_lowmem_reserve_ratio, 9911da177e4SLinus Torvalds .maxlen = sizeof(sysctl_lowmem_reserve_ratio), 9921da177e4SLinus Torvalds .mode = 0644, 9931da177e4SLinus Torvalds .proc_handler = &lowmem_reserve_ratio_sysctl_handler, 9941da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9951da177e4SLinus Torvalds }, 9961da177e4SLinus Torvalds { 9979d0243bcSAndrew Morton .ctl_name = VM_DROP_PAGECACHE, 9989d0243bcSAndrew Morton .procname = "drop_caches", 9999d0243bcSAndrew Morton .data = &sysctl_drop_caches, 10009d0243bcSAndrew Morton .maxlen = sizeof(int), 10019d0243bcSAndrew Morton .mode = 0644, 10029d0243bcSAndrew Morton .proc_handler = drop_caches_sysctl_handler, 10039d0243bcSAndrew Morton .strategy = &sysctl_intvec, 10049d0243bcSAndrew Morton }, 10059d0243bcSAndrew Morton { 10061da177e4SLinus Torvalds .ctl_name = VM_MIN_FREE_KBYTES, 10071da177e4SLinus Torvalds .procname = "min_free_kbytes", 10081da177e4SLinus Torvalds .data = &min_free_kbytes, 10091da177e4SLinus Torvalds .maxlen = sizeof(min_free_kbytes), 10101da177e4SLinus Torvalds .mode = 0644, 10111da177e4SLinus Torvalds .proc_handler = &min_free_kbytes_sysctl_handler, 10121da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10131da177e4SLinus Torvalds .extra1 = &zero, 10141da177e4SLinus Torvalds }, 10158ad4b1fbSRohit Seth { 10168ad4b1fbSRohit Seth .ctl_name = VM_PERCPU_PAGELIST_FRACTION, 10178ad4b1fbSRohit Seth .procname = "percpu_pagelist_fraction", 10188ad4b1fbSRohit Seth .data = &percpu_pagelist_fraction, 10198ad4b1fbSRohit Seth .maxlen = sizeof(percpu_pagelist_fraction), 10208ad4b1fbSRohit Seth .mode = 0644, 10218ad4b1fbSRohit Seth .proc_handler = &percpu_pagelist_fraction_sysctl_handler, 10228ad4b1fbSRohit Seth .strategy = &sysctl_intvec, 10238ad4b1fbSRohit Seth .extra1 = &min_percpu_pagelist_fract, 10248ad4b1fbSRohit Seth }, 10251da177e4SLinus Torvalds #ifdef CONFIG_MMU 10261da177e4SLinus Torvalds { 10271da177e4SLinus Torvalds .ctl_name = VM_MAX_MAP_COUNT, 10281da177e4SLinus Torvalds .procname = "max_map_count", 10291da177e4SLinus Torvalds .data = &sysctl_max_map_count, 10301da177e4SLinus Torvalds .maxlen = sizeof(sysctl_max_map_count), 10311da177e4SLinus Torvalds .mode = 0644, 10321da177e4SLinus Torvalds .proc_handler = &proc_dointvec 10331da177e4SLinus Torvalds }, 10341da177e4SLinus Torvalds #endif 10351da177e4SLinus Torvalds { 10361da177e4SLinus Torvalds .ctl_name = VM_LAPTOP_MODE, 10371da177e4SLinus Torvalds .procname = "laptop_mode", 10381da177e4SLinus Torvalds .data = &laptop_mode, 10391da177e4SLinus Torvalds .maxlen = sizeof(laptop_mode), 10401da177e4SLinus Torvalds .mode = 0644, 1041ed5b43f1SBart Samwel .proc_handler = &proc_dointvec_jiffies, 1042ed5b43f1SBart Samwel .strategy = &sysctl_jiffies, 10431da177e4SLinus Torvalds }, 10441da177e4SLinus Torvalds { 10451da177e4SLinus Torvalds .ctl_name = VM_BLOCK_DUMP, 10461da177e4SLinus Torvalds .procname = "block_dump", 10471da177e4SLinus Torvalds .data = &block_dump, 10481da177e4SLinus Torvalds .maxlen = sizeof(block_dump), 10491da177e4SLinus Torvalds .mode = 0644, 10501da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10511da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10521da177e4SLinus Torvalds .extra1 = &zero, 10531da177e4SLinus Torvalds }, 10541da177e4SLinus Torvalds { 10551da177e4SLinus Torvalds .ctl_name = VM_VFS_CACHE_PRESSURE, 10561da177e4SLinus Torvalds .procname = "vfs_cache_pressure", 10571da177e4SLinus Torvalds .data = &sysctl_vfs_cache_pressure, 10581da177e4SLinus Torvalds .maxlen = sizeof(sysctl_vfs_cache_pressure), 10591da177e4SLinus Torvalds .mode = 0644, 10601da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10611da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10621da177e4SLinus Torvalds .extra1 = &zero, 10631da177e4SLinus Torvalds }, 10641da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 10651da177e4SLinus Torvalds { 10661da177e4SLinus Torvalds .ctl_name = VM_LEGACY_VA_LAYOUT, 10671da177e4SLinus Torvalds .procname = "legacy_va_layout", 10681da177e4SLinus Torvalds .data = &sysctl_legacy_va_layout, 10691da177e4SLinus Torvalds .maxlen = sizeof(sysctl_legacy_va_layout), 10701da177e4SLinus Torvalds .mode = 0644, 10711da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10721da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10731da177e4SLinus Torvalds .extra1 = &zero, 10741da177e4SLinus Torvalds }, 10751da177e4SLinus Torvalds #endif 10761743660bSChristoph Lameter #ifdef CONFIG_NUMA 10771743660bSChristoph Lameter { 10781743660bSChristoph Lameter .ctl_name = VM_ZONE_RECLAIM_MODE, 10791743660bSChristoph Lameter .procname = "zone_reclaim_mode", 10801743660bSChristoph Lameter .data = &zone_reclaim_mode, 10811743660bSChristoph Lameter .maxlen = sizeof(zone_reclaim_mode), 10821743660bSChristoph Lameter .mode = 0644, 10831743660bSChristoph Lameter .proc_handler = &proc_dointvec, 1084c84db23cSChristoph Lameter .strategy = &sysctl_intvec, 1085c84db23cSChristoph Lameter .extra1 = &zero, 10861743660bSChristoph Lameter }, 10879614634fSChristoph Lameter { 10889614634fSChristoph Lameter .ctl_name = VM_MIN_UNMAPPED, 10899614634fSChristoph Lameter .procname = "min_unmapped_ratio", 10909614634fSChristoph Lameter .data = &sysctl_min_unmapped_ratio, 10919614634fSChristoph Lameter .maxlen = sizeof(sysctl_min_unmapped_ratio), 10929614634fSChristoph Lameter .mode = 0644, 10939614634fSChristoph Lameter .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler, 10949614634fSChristoph Lameter .strategy = &sysctl_intvec, 10959614634fSChristoph Lameter .extra1 = &zero, 10969614634fSChristoph Lameter .extra2 = &one_hundred, 10979614634fSChristoph Lameter }, 10980ff38490SChristoph Lameter { 10990ff38490SChristoph Lameter .ctl_name = VM_MIN_SLAB, 11000ff38490SChristoph Lameter .procname = "min_slab_ratio", 11010ff38490SChristoph Lameter .data = &sysctl_min_slab_ratio, 11020ff38490SChristoph Lameter .maxlen = sizeof(sysctl_min_slab_ratio), 11030ff38490SChristoph Lameter .mode = 0644, 11040ff38490SChristoph Lameter .proc_handler = &sysctl_min_slab_ratio_sysctl_handler, 11050ff38490SChristoph Lameter .strategy = &sysctl_intvec, 11060ff38490SChristoph Lameter .extra1 = &zero, 11070ff38490SChristoph Lameter .extra2 = &one_hundred, 11080ff38490SChristoph Lameter }, 11091743660bSChristoph Lameter #endif 111077461ab3SChristoph Lameter #ifdef CONFIG_SMP 111177461ab3SChristoph Lameter { 111277461ab3SChristoph Lameter .ctl_name = CTL_UNNUMBERED, 111377461ab3SChristoph Lameter .procname = "stat_interval", 111477461ab3SChristoph Lameter .data = &sysctl_stat_interval, 111577461ab3SChristoph Lameter .maxlen = sizeof(sysctl_stat_interval), 111677461ab3SChristoph Lameter .mode = 0644, 111777461ab3SChristoph Lameter .proc_handler = &proc_dointvec_jiffies, 111877461ab3SChristoph Lameter .strategy = &sysctl_jiffies, 111977461ab3SChristoph Lameter }, 112077461ab3SChristoph Lameter #endif 1121ed032189SEric Paris #ifdef CONFIG_SECURITY 1122ed032189SEric Paris { 1123ed032189SEric Paris .ctl_name = CTL_UNNUMBERED, 1124ed032189SEric Paris .procname = "mmap_min_addr", 1125ed032189SEric Paris .data = &mmap_min_addr, 1126ed032189SEric Paris .maxlen = sizeof(unsigned long), 1127ed032189SEric Paris .mode = 0644, 1128ed032189SEric Paris .proc_handler = &proc_doulongvec_minmax, 1129ed032189SEric Paris }, 11308daec965SLee Schermerhorn #endif 1131f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA 1132f0c0b2b8SKAMEZAWA Hiroyuki { 1133f0c0b2b8SKAMEZAWA Hiroyuki .ctl_name = CTL_UNNUMBERED, 1134f0c0b2b8SKAMEZAWA Hiroyuki .procname = "numa_zonelist_order", 1135f0c0b2b8SKAMEZAWA Hiroyuki .data = &numa_zonelist_order, 1136f0c0b2b8SKAMEZAWA Hiroyuki .maxlen = NUMA_ZONELIST_ORDER_LEN, 1137f0c0b2b8SKAMEZAWA Hiroyuki .mode = 0644, 1138f0c0b2b8SKAMEZAWA Hiroyuki .proc_handler = &numa_zonelist_order_handler, 1139f0c0b2b8SKAMEZAWA Hiroyuki .strategy = &sysctl_string, 1140f0c0b2b8SKAMEZAWA Hiroyuki }, 1141f0c0b2b8SKAMEZAWA Hiroyuki #endif 11422b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 11435c36e657SPaul Mundt (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 1144e6e5494cSIngo Molnar { 1145e6e5494cSIngo Molnar .ctl_name = VM_VDSO_ENABLED, 1146e6e5494cSIngo Molnar .procname = "vdso_enabled", 1147e6e5494cSIngo Molnar .data = &vdso_enabled, 1148e6e5494cSIngo Molnar .maxlen = sizeof(vdso_enabled), 1149e6e5494cSIngo Molnar .mode = 0644, 1150e6e5494cSIngo Molnar .proc_handler = &proc_dointvec, 1151e6e5494cSIngo Molnar .strategy = &sysctl_intvec, 1152e6e5494cSIngo Molnar .extra1 = &zero, 1153e6e5494cSIngo Molnar }, 1154e6e5494cSIngo Molnar #endif 11552be7fe07SAndrew Morton /* 11562be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 11572be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 11582be7fe07SAndrew Morton */ 11591da177e4SLinus Torvalds { .ctl_name = 0 } 11601da177e4SLinus Torvalds }; 11611da177e4SLinus Torvalds 11622abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1163d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = { 11642abc26fcSEric W. Biederman { .ctl_name = 0 } 11652abc26fcSEric W. Biederman }; 11662abc26fcSEric W. Biederman #endif 11672abc26fcSEric W. Biederman 1168d8217f07SEric W. Biederman static struct ctl_table fs_table[] = { 11691da177e4SLinus Torvalds { 11701da177e4SLinus Torvalds .ctl_name = FS_NRINODE, 11711da177e4SLinus Torvalds .procname = "inode-nr", 11721da177e4SLinus Torvalds .data = &inodes_stat, 11731da177e4SLinus Torvalds .maxlen = 2*sizeof(int), 11741da177e4SLinus Torvalds .mode = 0444, 11751da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 11761da177e4SLinus Torvalds }, 11771da177e4SLinus Torvalds { 11781da177e4SLinus Torvalds .ctl_name = FS_STATINODE, 11791da177e4SLinus Torvalds .procname = "inode-state", 11801da177e4SLinus Torvalds .data = &inodes_stat, 11811da177e4SLinus Torvalds .maxlen = 7*sizeof(int), 11821da177e4SLinus Torvalds .mode = 0444, 11831da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 11841da177e4SLinus Torvalds }, 11851da177e4SLinus Torvalds { 11861da177e4SLinus Torvalds .procname = "file-nr", 11871da177e4SLinus Torvalds .data = &files_stat, 11881da177e4SLinus Torvalds .maxlen = 3*sizeof(int), 11891da177e4SLinus Torvalds .mode = 0444, 1190529bf6beSDipankar Sarma .proc_handler = &proc_nr_files, 11911da177e4SLinus Torvalds }, 11921da177e4SLinus Torvalds { 11931da177e4SLinus Torvalds .ctl_name = FS_MAXFILE, 11941da177e4SLinus Torvalds .procname = "file-max", 11951da177e4SLinus Torvalds .data = &files_stat.max_files, 11961da177e4SLinus Torvalds .maxlen = sizeof(int), 11971da177e4SLinus Torvalds .mode = 0644, 11981da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 11991da177e4SLinus Torvalds }, 12001da177e4SLinus Torvalds { 12011da177e4SLinus Torvalds .ctl_name = FS_DENTRY, 12021da177e4SLinus Torvalds .procname = "dentry-state", 12031da177e4SLinus Torvalds .data = &dentry_stat, 12041da177e4SLinus Torvalds .maxlen = 6*sizeof(int), 12051da177e4SLinus Torvalds .mode = 0444, 12061da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12071da177e4SLinus Torvalds }, 12081da177e4SLinus Torvalds { 12091da177e4SLinus Torvalds .ctl_name = FS_OVERFLOWUID, 12101da177e4SLinus Torvalds .procname = "overflowuid", 12111da177e4SLinus Torvalds .data = &fs_overflowuid, 12121da177e4SLinus Torvalds .maxlen = sizeof(int), 12131da177e4SLinus Torvalds .mode = 0644, 12141da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 12151da177e4SLinus Torvalds .strategy = &sysctl_intvec, 12161da177e4SLinus Torvalds .extra1 = &minolduid, 12171da177e4SLinus Torvalds .extra2 = &maxolduid, 12181da177e4SLinus Torvalds }, 12191da177e4SLinus Torvalds { 12201da177e4SLinus Torvalds .ctl_name = FS_OVERFLOWGID, 12211da177e4SLinus Torvalds .procname = "overflowgid", 12221da177e4SLinus Torvalds .data = &fs_overflowgid, 12231da177e4SLinus Torvalds .maxlen = sizeof(int), 12241da177e4SLinus Torvalds .mode = 0644, 12251da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 12261da177e4SLinus Torvalds .strategy = &sysctl_intvec, 12271da177e4SLinus Torvalds .extra1 = &minolduid, 12281da177e4SLinus Torvalds .extra2 = &maxolduid, 12291da177e4SLinus Torvalds }, 12301da177e4SLinus Torvalds { 12311da177e4SLinus Torvalds .ctl_name = FS_LEASES, 12321da177e4SLinus Torvalds .procname = "leases-enable", 12331da177e4SLinus Torvalds .data = &leases_enable, 12341da177e4SLinus Torvalds .maxlen = sizeof(int), 12351da177e4SLinus Torvalds .mode = 0644, 12361da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12371da177e4SLinus Torvalds }, 12381da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY 12391da177e4SLinus Torvalds { 12401da177e4SLinus Torvalds .ctl_name = FS_DIR_NOTIFY, 12411da177e4SLinus Torvalds .procname = "dir-notify-enable", 12421da177e4SLinus Torvalds .data = &dir_notify_enable, 12431da177e4SLinus Torvalds .maxlen = sizeof(int), 12441da177e4SLinus Torvalds .mode = 0644, 12451da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12461da177e4SLinus Torvalds }, 12471da177e4SLinus Torvalds #endif 12481da177e4SLinus Torvalds #ifdef CONFIG_MMU 12491da177e4SLinus Torvalds { 12501da177e4SLinus Torvalds .ctl_name = FS_LEASE_TIME, 12511da177e4SLinus Torvalds .procname = "lease-break-time", 12521da177e4SLinus Torvalds .data = &lease_break_time, 12531da177e4SLinus Torvalds .maxlen = sizeof(int), 12541da177e4SLinus Torvalds .mode = 0644, 125576fdbb25SKawai, Hidehiro .proc_handler = &proc_dointvec_minmax, 125676fdbb25SKawai, Hidehiro .strategy = &sysctl_intvec, 125776fdbb25SKawai, Hidehiro .extra1 = &zero, 125876fdbb25SKawai, Hidehiro .extra2 = &two, 12591da177e4SLinus Torvalds }, 12601da177e4SLinus Torvalds { 12611da177e4SLinus Torvalds .procname = "aio-nr", 12621da177e4SLinus Torvalds .data = &aio_nr, 12631da177e4SLinus Torvalds .maxlen = sizeof(aio_nr), 12641da177e4SLinus Torvalds .mode = 0444, 1265d55b5fdaSZach Brown .proc_handler = &proc_doulongvec_minmax, 12661da177e4SLinus Torvalds }, 12671da177e4SLinus Torvalds { 12681da177e4SLinus Torvalds .procname = "aio-max-nr", 12691da177e4SLinus Torvalds .data = &aio_max_nr, 12701da177e4SLinus Torvalds .maxlen = sizeof(aio_max_nr), 12711da177e4SLinus Torvalds .mode = 0644, 1272d55b5fdaSZach Brown .proc_handler = &proc_doulongvec_minmax, 12731da177e4SLinus Torvalds }, 12742d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 12750399cb08SRobert Love { 12760399cb08SRobert Love .ctl_name = FS_INOTIFY, 12770399cb08SRobert Love .procname = "inotify", 12780399cb08SRobert Love .mode = 0555, 12790399cb08SRobert Love .child = inotify_table, 12800399cb08SRobert Love }, 12810399cb08SRobert Love #endif 12821da177e4SLinus Torvalds #endif 1283d6e71144SAlan Cox { 1284d6e71144SAlan Cox .ctl_name = KERN_SETUID_DUMPABLE, 1285d6e71144SAlan Cox .procname = "suid_dumpable", 1286d6e71144SAlan Cox .data = &suid_dumpable, 1287d6e71144SAlan Cox .maxlen = sizeof(int), 1288d6e71144SAlan Cox .mode = 0644, 1289d6e71144SAlan Cox .proc_handler = &proc_dointvec, 1290d6e71144SAlan Cox }, 12912abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 12922abc26fcSEric W. Biederman { 12932abc26fcSEric W. Biederman .ctl_name = CTL_UNNUMBERED, 12942abc26fcSEric W. Biederman .procname = "binfmt_misc", 12952abc26fcSEric W. Biederman .mode = 0555, 12962abc26fcSEric W. Biederman .child = binfmt_misc_table, 12972abc26fcSEric W. Biederman }, 12982abc26fcSEric W. Biederman #endif 12992be7fe07SAndrew Morton /* 13002be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 13012be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 13022be7fe07SAndrew Morton */ 13031da177e4SLinus Torvalds { .ctl_name = 0 } 13041da177e4SLinus Torvalds }; 13051da177e4SLinus Torvalds 1306d8217f07SEric W. Biederman static struct ctl_table debug_table[] = { 1307d0c3d534SOlof Johansson #if defined(CONFIG_X86) || defined(CONFIG_PPC) 1308abd4f750SMasoud Asgharifard Sharbiani { 1309abd4f750SMasoud Asgharifard Sharbiani .ctl_name = CTL_UNNUMBERED, 1310abd4f750SMasoud Asgharifard Sharbiani .procname = "exception-trace", 1311abd4f750SMasoud Asgharifard Sharbiani .data = &show_unhandled_signals, 1312abd4f750SMasoud Asgharifard Sharbiani .maxlen = sizeof(int), 1313abd4f750SMasoud Asgharifard Sharbiani .mode = 0644, 1314abd4f750SMasoud Asgharifard Sharbiani .proc_handler = proc_dointvec 1315abd4f750SMasoud Asgharifard Sharbiani }, 1316abd4f750SMasoud Asgharifard Sharbiani #endif 13171da177e4SLinus Torvalds { .ctl_name = 0 } 13181da177e4SLinus Torvalds }; 13191da177e4SLinus Torvalds 1320d8217f07SEric W. Biederman static struct ctl_table dev_table[] = { 13211da177e4SLinus Torvalds { .ctl_name = 0 } 13221da177e4SLinus Torvalds }; 13231da177e4SLinus Torvalds 1324330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock); 1325330d57fbSAl Viro 1326330d57fbSAl Viro /* called under sysctl_lock */ 1327330d57fbSAl Viro static int use_table(struct ctl_table_header *p) 1328330d57fbSAl Viro { 1329330d57fbSAl Viro if (unlikely(p->unregistering)) 1330330d57fbSAl Viro return 0; 1331330d57fbSAl Viro p->used++; 1332330d57fbSAl Viro return 1; 1333330d57fbSAl Viro } 1334330d57fbSAl Viro 1335330d57fbSAl Viro /* called under sysctl_lock */ 1336330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p) 1337330d57fbSAl Viro { 1338330d57fbSAl Viro if (!--p->used) 1339330d57fbSAl Viro if (unlikely(p->unregistering)) 1340330d57fbSAl Viro complete(p->unregistering); 1341330d57fbSAl Viro } 1342330d57fbSAl Viro 1343330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */ 1344330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p) 1345330d57fbSAl Viro { 1346330d57fbSAl Viro /* 1347330d57fbSAl Viro * if p->used is 0, nobody will ever touch that entry again; 1348330d57fbSAl Viro * we'll eliminate all paths to it before dropping sysctl_lock 1349330d57fbSAl Viro */ 1350330d57fbSAl Viro if (unlikely(p->used)) { 1351330d57fbSAl Viro struct completion wait; 1352330d57fbSAl Viro init_completion(&wait); 1353330d57fbSAl Viro p->unregistering = &wait; 1354330d57fbSAl Viro spin_unlock(&sysctl_lock); 1355330d57fbSAl Viro wait_for_completion(&wait); 1356330d57fbSAl Viro spin_lock(&sysctl_lock); 1357330d57fbSAl Viro } 1358330d57fbSAl Viro /* 1359330d57fbSAl Viro * do not remove from the list until nobody holds it; walking the 1360330d57fbSAl Viro * list in do_sysctl() relies on that. 1361330d57fbSAl Viro */ 1362330d57fbSAl Viro list_del_init(&p->ctl_entry); 1363330d57fbSAl Viro } 1364330d57fbSAl Viro 1365805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head) 1366805b5d5eSEric W. Biederman { 1367805b5d5eSEric W. Biederman if (!head) 1368805b5d5eSEric W. Biederman return; 1369805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1370805b5d5eSEric W. Biederman unuse_table(head); 1371805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1372805b5d5eSEric W. Biederman } 1373805b5d5eSEric W. Biederman 1374805b5d5eSEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) 1375805b5d5eSEric W. Biederman { 1376805b5d5eSEric W. Biederman struct ctl_table_header *head; 1377805b5d5eSEric W. Biederman struct list_head *tmp; 1378805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1379805b5d5eSEric W. Biederman if (prev) { 1380805b5d5eSEric W. Biederman tmp = &prev->ctl_entry; 1381805b5d5eSEric W. Biederman unuse_table(prev); 1382805b5d5eSEric W. Biederman goto next; 1383805b5d5eSEric W. Biederman } 1384805b5d5eSEric W. Biederman tmp = &root_table_header.ctl_entry; 1385805b5d5eSEric W. Biederman for (;;) { 1386805b5d5eSEric W. Biederman head = list_entry(tmp, struct ctl_table_header, ctl_entry); 1387805b5d5eSEric W. Biederman 1388805b5d5eSEric W. Biederman if (!use_table(head)) 1389805b5d5eSEric W. Biederman goto next; 1390805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1391805b5d5eSEric W. Biederman return head; 1392805b5d5eSEric W. Biederman next: 1393805b5d5eSEric W. Biederman tmp = tmp->next; 1394805b5d5eSEric W. Biederman if (tmp == &root_table_header.ctl_entry) 1395805b5d5eSEric W. Biederman break; 1396805b5d5eSEric W. Biederman } 1397805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1398805b5d5eSEric W. Biederman return NULL; 1399805b5d5eSEric W. Biederman } 1400805b5d5eSEric W. Biederman 1401b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 14021da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, 14031da177e4SLinus Torvalds void __user *newval, size_t newlen) 14041da177e4SLinus Torvalds { 1405805b5d5eSEric W. Biederman struct ctl_table_header *head; 1406330d57fbSAl Viro int error = -ENOTDIR; 14071da177e4SLinus Torvalds 14081da177e4SLinus Torvalds if (nlen <= 0 || nlen >= CTL_MAXNAME) 14091da177e4SLinus Torvalds return -ENOTDIR; 14101da177e4SLinus Torvalds if (oldval) { 14111da177e4SLinus Torvalds int old_len; 14121da177e4SLinus Torvalds if (!oldlenp || get_user(old_len, oldlenp)) 14131da177e4SLinus Torvalds return -EFAULT; 14141da177e4SLinus Torvalds } 1415330d57fbSAl Viro 1416805b5d5eSEric W. Biederman for (head = sysctl_head_next(NULL); head; 1417805b5d5eSEric W. Biederman head = sysctl_head_next(head)) { 1418330d57fbSAl Viro error = parse_table(name, nlen, oldval, oldlenp, 14191f29bcd7SAlexey Dobriyan newval, newlen, head->ctl_table); 1420805b5d5eSEric W. Biederman if (error != -ENOTDIR) { 1421805b5d5eSEric W. Biederman sysctl_head_finish(head); 1422330d57fbSAl Viro break; 1423805b5d5eSEric W. Biederman } 1424805b5d5eSEric W. Biederman } 14251da177e4SLinus Torvalds return error; 14261da177e4SLinus Torvalds } 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args) 14291da177e4SLinus Torvalds { 14301da177e4SLinus Torvalds struct __sysctl_args tmp; 14311da177e4SLinus Torvalds int error; 14321da177e4SLinus Torvalds 14331da177e4SLinus Torvalds if (copy_from_user(&tmp, args, sizeof(tmp))) 14341da177e4SLinus Torvalds return -EFAULT; 14351da177e4SLinus Torvalds 14367058cb02SEric W. Biederman error = deprecated_sysctl_warning(&tmp); 14377058cb02SEric W. Biederman if (error) 14387058cb02SEric W. Biederman goto out; 14397058cb02SEric W. Biederman 14401da177e4SLinus Torvalds lock_kernel(); 14411da177e4SLinus Torvalds error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp, 14421da177e4SLinus Torvalds tmp.newval, tmp.newlen); 14431da177e4SLinus Torvalds unlock_kernel(); 14447058cb02SEric W. Biederman out: 14451da177e4SLinus Torvalds return error; 14461da177e4SLinus Torvalds } 1447b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */ 14481da177e4SLinus Torvalds 14491da177e4SLinus Torvalds /* 14501ff007ebSEric W. Biederman * sysctl_perm does NOT grant the superuser all rights automatically, because 14511da177e4SLinus Torvalds * some sysctl variables are readonly even to root. 14521da177e4SLinus Torvalds */ 14531da177e4SLinus Torvalds 14541da177e4SLinus Torvalds static int test_perm(int mode, int op) 14551da177e4SLinus Torvalds { 14561da177e4SLinus Torvalds if (!current->euid) 14571da177e4SLinus Torvalds mode >>= 6; 14581da177e4SLinus Torvalds else if (in_egroup_p(0)) 14591da177e4SLinus Torvalds mode >>= 3; 14601da177e4SLinus Torvalds if ((mode & op & 0007) == op) 14611da177e4SLinus Torvalds return 0; 14621da177e4SLinus Torvalds return -EACCES; 14631da177e4SLinus Torvalds } 14641da177e4SLinus Torvalds 1465d8217f07SEric W. Biederman int sysctl_perm(struct ctl_table *table, int op) 14661da177e4SLinus Torvalds { 14671da177e4SLinus Torvalds int error; 14681da177e4SLinus Torvalds error = security_sysctl(table, op); 14691da177e4SLinus Torvalds if (error) 14701da177e4SLinus Torvalds return error; 14711da177e4SLinus Torvalds return test_perm(table->mode, op); 14721da177e4SLinus Torvalds } 14731da177e4SLinus Torvalds 1474b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 14751da177e4SLinus Torvalds static int parse_table(int __user *name, int nlen, 14761da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 14771da177e4SLinus Torvalds void __user *newval, size_t newlen, 1478d8217f07SEric W. Biederman struct ctl_table *table) 14791da177e4SLinus Torvalds { 14801da177e4SLinus Torvalds int n; 14811da177e4SLinus Torvalds repeat: 14821da177e4SLinus Torvalds if (!nlen) 14831da177e4SLinus Torvalds return -ENOTDIR; 14841da177e4SLinus Torvalds if (get_user(n, name)) 14851da177e4SLinus Torvalds return -EFAULT; 1486d99f160aSEric W. Biederman for ( ; table->ctl_name || table->procname; table++) { 1487d99f160aSEric W. Biederman if (!table->ctl_name) 1488d99f160aSEric W. Biederman continue; 14896703ddfcSEric W. Biederman if (n == table->ctl_name) { 14901da177e4SLinus Torvalds int error; 14911da177e4SLinus Torvalds if (table->child) { 14921ff007ebSEric W. Biederman if (sysctl_perm(table, 001)) 14931da177e4SLinus Torvalds return -EPERM; 14941da177e4SLinus Torvalds name++; 14951da177e4SLinus Torvalds nlen--; 14961da177e4SLinus Torvalds table = table->child; 14971da177e4SLinus Torvalds goto repeat; 14981da177e4SLinus Torvalds } 14991da177e4SLinus Torvalds error = do_sysctl_strategy(table, name, nlen, 15001da177e4SLinus Torvalds oldval, oldlenp, 15011f29bcd7SAlexey Dobriyan newval, newlen); 15021da177e4SLinus Torvalds return error; 15031da177e4SLinus Torvalds } 15041da177e4SLinus Torvalds } 15051da177e4SLinus Torvalds return -ENOTDIR; 15061da177e4SLinus Torvalds } 15071da177e4SLinus Torvalds 15081da177e4SLinus Torvalds /* Perform the actual read/write of a sysctl table entry. */ 1509d8217f07SEric W. Biederman int do_sysctl_strategy (struct ctl_table *table, 15101da177e4SLinus Torvalds int __user *name, int nlen, 15111da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 15121f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 15131da177e4SLinus Torvalds { 15141da177e4SLinus Torvalds int op = 0, rc; 15151da177e4SLinus Torvalds 15161da177e4SLinus Torvalds if (oldval) 15171da177e4SLinus Torvalds op |= 004; 15181da177e4SLinus Torvalds if (newval) 15191da177e4SLinus Torvalds op |= 002; 15201ff007ebSEric W. Biederman if (sysctl_perm(table, op)) 15211da177e4SLinus Torvalds return -EPERM; 15221da177e4SLinus Torvalds 15231da177e4SLinus Torvalds if (table->strategy) { 15241da177e4SLinus Torvalds rc = table->strategy(table, name, nlen, oldval, oldlenp, 15251f29bcd7SAlexey Dobriyan newval, newlen); 15261da177e4SLinus Torvalds if (rc < 0) 15271da177e4SLinus Torvalds return rc; 15281da177e4SLinus Torvalds if (rc > 0) 15291da177e4SLinus Torvalds return 0; 15301da177e4SLinus Torvalds } 15311da177e4SLinus Torvalds 15321da177e4SLinus Torvalds /* If there is no strategy routine, or if the strategy returns 15331da177e4SLinus Torvalds * zero, proceed with automatic r/w */ 15341da177e4SLinus Torvalds if (table->data && table->maxlen) { 153549a0c458SEric W. Biederman rc = sysctl_data(table, name, nlen, oldval, oldlenp, 153649a0c458SEric W. Biederman newval, newlen); 153749a0c458SEric W. Biederman if (rc < 0) 153849a0c458SEric W. Biederman return rc; 15391da177e4SLinus Torvalds } 15401da177e4SLinus Torvalds return 0; 15411da177e4SLinus Torvalds } 1542b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */ 15431da177e4SLinus Torvalds 1544d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) 1545d912b0ccSEric W. Biederman { 1546d912b0ccSEric W. Biederman for (; table->ctl_name || table->procname; table++) { 1547d912b0ccSEric W. Biederman table->parent = parent; 1548d912b0ccSEric W. Biederman if (table->child) 1549d912b0ccSEric W. Biederman sysctl_set_parent(table, table->child); 1550d912b0ccSEric W. Biederman } 1551d912b0ccSEric W. Biederman } 1552d912b0ccSEric W. Biederman 1553d912b0ccSEric W. Biederman static __init int sysctl_init(void) 1554d912b0ccSEric W. Biederman { 1555fc6cd25bSEric W. Biederman int err; 1556d912b0ccSEric W. Biederman sysctl_set_parent(NULL, root_table); 1557fc6cd25bSEric W. Biederman err = sysctl_check_table(root_table); 1558d912b0ccSEric W. Biederman return 0; 1559d912b0ccSEric W. Biederman } 1560d912b0ccSEric W. Biederman 1561d912b0ccSEric W. Biederman core_initcall(sysctl_init); 1562d912b0ccSEric W. Biederman 15631da177e4SLinus Torvalds /** 1564*29e796fdSEric W. Biederman * register_sysctl_paths - register a sysctl hierarchy 1565*29e796fdSEric W. Biederman * @path: The path to the directory the sysctl table is in. 15661da177e4SLinus Torvalds * @table: the top-level table structure 15671da177e4SLinus Torvalds * 15681da177e4SLinus Torvalds * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1569*29e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 15701da177e4SLinus Torvalds * 1571d8217f07SEric W. Biederman * The members of the &struct ctl_table structure are used as follows: 15721da177e4SLinus Torvalds * 15731da177e4SLinus Torvalds * ctl_name - This is the numeric sysctl value used by sysctl(2). The number 15741da177e4SLinus Torvalds * must be unique within that level of sysctl 15751da177e4SLinus Torvalds * 15761da177e4SLinus Torvalds * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not 15771da177e4SLinus Torvalds * enter a sysctl file 15781da177e4SLinus Torvalds * 15791da177e4SLinus Torvalds * data - a pointer to data for use by proc_handler 15801da177e4SLinus Torvalds * 15811da177e4SLinus Torvalds * maxlen - the maximum size in bytes of the data 15821da177e4SLinus Torvalds * 15831da177e4SLinus Torvalds * mode - the file permissions for the /proc/sys file, and for sysctl(2) 15841da177e4SLinus Torvalds * 15851da177e4SLinus Torvalds * child - a pointer to the child sysctl table if this entry is a directory, or 15861da177e4SLinus Torvalds * %NULL. 15871da177e4SLinus Torvalds * 15881da177e4SLinus Torvalds * proc_handler - the text handler routine (described below) 15891da177e4SLinus Torvalds * 15901da177e4SLinus Torvalds * strategy - the strategy routine (described below) 15911da177e4SLinus Torvalds * 15921da177e4SLinus Torvalds * de - for internal use by the sysctl routines 15931da177e4SLinus Torvalds * 15941da177e4SLinus Torvalds * extra1, extra2 - extra pointers usable by the proc handler routines 15951da177e4SLinus Torvalds * 15961da177e4SLinus Torvalds * Leaf nodes in the sysctl tree will be represented by a single file 15971da177e4SLinus Torvalds * under /proc; non-leaf nodes will be represented by directories. 15981da177e4SLinus Torvalds * 15991da177e4SLinus Torvalds * sysctl(2) can automatically manage read and write requests through 16001da177e4SLinus Torvalds * the sysctl table. The data and maxlen fields of the ctl_table 16011da177e4SLinus Torvalds * struct enable minimal validation of the values being written to be 16021da177e4SLinus Torvalds * performed, and the mode field allows minimal authentication. 16031da177e4SLinus Torvalds * 16041da177e4SLinus Torvalds * More sophisticated management can be enabled by the provision of a 16051da177e4SLinus Torvalds * strategy routine with the table entry. This will be called before 16061da177e4SLinus Torvalds * any automatic read or write of the data is performed. 16071da177e4SLinus Torvalds * 16081da177e4SLinus Torvalds * The strategy routine may return 16091da177e4SLinus Torvalds * 16101da177e4SLinus Torvalds * < 0 - Error occurred (error is passed to user process) 16111da177e4SLinus Torvalds * 16121da177e4SLinus Torvalds * 0 - OK - proceed with automatic read or write. 16131da177e4SLinus Torvalds * 16141da177e4SLinus Torvalds * > 0 - OK - read or write has been done by the strategy routine, so 16151da177e4SLinus Torvalds * return immediately. 16161da177e4SLinus Torvalds * 16171da177e4SLinus Torvalds * There must be a proc_handler routine for any terminal nodes 16181da177e4SLinus Torvalds * mirrored under /proc/sys (non-terminals are handled by a built-in 16191da177e4SLinus Torvalds * directory handler). Several default handlers are available to 16201da177e4SLinus Torvalds * cover common cases - 16211da177e4SLinus Torvalds * 16221da177e4SLinus Torvalds * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), 16231da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 16241da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() 16251da177e4SLinus Torvalds * 16261da177e4SLinus Torvalds * It is the handler's job to read the input buffer from user memory 16271da177e4SLinus Torvalds * and process it. The handler should return 0 on success. 16281da177e4SLinus Torvalds * 16291da177e4SLinus Torvalds * This routine returns %NULL on a failure to register, and a pointer 16301da177e4SLinus Torvalds * to the table header on success. 16311da177e4SLinus Torvalds */ 1632*29e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 1633*29e796fdSEric W. Biederman struct ctl_table *table) 16341da177e4SLinus Torvalds { 1635*29e796fdSEric W. Biederman struct ctl_table_header *header; 1636*29e796fdSEric W. Biederman struct ctl_table *new, **prevp; 1637*29e796fdSEric W. Biederman unsigned int n, npath; 1638*29e796fdSEric W. Biederman 1639*29e796fdSEric W. Biederman /* Count the path components */ 1640*29e796fdSEric W. Biederman for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) 1641*29e796fdSEric W. Biederman ; 1642*29e796fdSEric W. Biederman 1643*29e796fdSEric W. Biederman /* 1644*29e796fdSEric W. Biederman * For each path component, allocate a 2-element ctl_table array. 1645*29e796fdSEric W. Biederman * The first array element will be filled with the sysctl entry 1646*29e796fdSEric W. Biederman * for this, the second will be the sentinel (ctl_name == 0). 1647*29e796fdSEric W. Biederman * 1648*29e796fdSEric W. Biederman * We allocate everything in one go so that we don't have to 1649*29e796fdSEric W. Biederman * worry about freeing additional memory in unregister_sysctl_table. 1650*29e796fdSEric W. Biederman */ 1651*29e796fdSEric W. Biederman header = kzalloc(sizeof(struct ctl_table_header) + 1652*29e796fdSEric W. Biederman (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); 1653*29e796fdSEric W. Biederman if (!header) 16541da177e4SLinus Torvalds return NULL; 1655*29e796fdSEric W. Biederman 1656*29e796fdSEric W. Biederman new = (struct ctl_table *) (header + 1); 1657*29e796fdSEric W. Biederman 1658*29e796fdSEric W. Biederman /* Now connect the dots */ 1659*29e796fdSEric W. Biederman prevp = &header->ctl_table; 1660*29e796fdSEric W. Biederman for (n = 0; n < npath; ++n, ++path) { 1661*29e796fdSEric W. Biederman /* Copy the procname */ 1662*29e796fdSEric W. Biederman new->procname = path->procname; 1663*29e796fdSEric W. Biederman new->ctl_name = path->ctl_name; 1664*29e796fdSEric W. Biederman new->mode = 0555; 1665*29e796fdSEric W. Biederman 1666*29e796fdSEric W. Biederman *prevp = new; 1667*29e796fdSEric W. Biederman prevp = &new->child; 1668*29e796fdSEric W. Biederman 1669*29e796fdSEric W. Biederman new += 2; 1670*29e796fdSEric W. Biederman } 1671*29e796fdSEric W. Biederman *prevp = table; 1672*29e796fdSEric W. Biederman 1673*29e796fdSEric W. Biederman INIT_LIST_HEAD(&header->ctl_entry); 1674*29e796fdSEric W. Biederman header->used = 0; 1675*29e796fdSEric W. Biederman header->unregistering = NULL; 1676*29e796fdSEric W. Biederman sysctl_set_parent(NULL, header->ctl_table); 1677*29e796fdSEric W. Biederman if (sysctl_check_table(header->ctl_table)) { 1678*29e796fdSEric W. Biederman kfree(header); 1679fc6cd25bSEric W. Biederman return NULL; 1680fc6cd25bSEric W. Biederman } 1681330d57fbSAl Viro spin_lock(&sysctl_lock); 1682*29e796fdSEric W. Biederman list_add_tail(&header->ctl_entry, &root_table_header.ctl_entry); 1683330d57fbSAl Viro spin_unlock(&sysctl_lock); 1684*29e796fdSEric W. Biederman 1685*29e796fdSEric W. Biederman return header; 1686*29e796fdSEric W. Biederman } 1687*29e796fdSEric W. Biederman 1688*29e796fdSEric W. Biederman /** 1689*29e796fdSEric W. Biederman * register_sysctl_table - register a sysctl table hierarchy 1690*29e796fdSEric W. Biederman * @table: the top-level table structure 1691*29e796fdSEric W. Biederman * 1692*29e796fdSEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1693*29e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 1694*29e796fdSEric W. Biederman * 1695*29e796fdSEric W. Biederman * See register_sysctl_paths for more details. 1696*29e796fdSEric W. Biederman */ 1697*29e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table) 1698*29e796fdSEric W. Biederman { 1699*29e796fdSEric W. Biederman static const struct ctl_path null_path[] = { {} }; 1700*29e796fdSEric W. Biederman 1701*29e796fdSEric W. Biederman return register_sysctl_paths(null_path, table); 17021da177e4SLinus Torvalds } 17031da177e4SLinus Torvalds 17041da177e4SLinus Torvalds /** 17051da177e4SLinus Torvalds * unregister_sysctl_table - unregister a sysctl table hierarchy 17061da177e4SLinus Torvalds * @header: the header returned from register_sysctl_table 17071da177e4SLinus Torvalds * 17081da177e4SLinus Torvalds * Unregisters the sysctl table and all children. proc entries may not 17091da177e4SLinus Torvalds * actually be removed until they are no longer used by anyone. 17101da177e4SLinus Torvalds */ 17111da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header) 17121da177e4SLinus Torvalds { 1713330d57fbSAl Viro might_sleep(); 1714f1dad166SPavel Emelyanov 1715f1dad166SPavel Emelyanov if (header == NULL) 1716f1dad166SPavel Emelyanov return; 1717f1dad166SPavel Emelyanov 1718330d57fbSAl Viro spin_lock(&sysctl_lock); 1719330d57fbSAl Viro start_unregistering(header); 1720330d57fbSAl Viro spin_unlock(&sysctl_lock); 17211da177e4SLinus Torvalds kfree(header); 17221da177e4SLinus Torvalds } 17231da177e4SLinus Torvalds 1724b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */ 1725d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table) 1726b89a8171SEric W. Biederman { 1727b89a8171SEric W. Biederman return NULL; 1728b89a8171SEric W. Biederman } 1729b89a8171SEric W. Biederman 1730*29e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 1731*29e796fdSEric W. Biederman struct ctl_table *table) 1732*29e796fdSEric W. Biederman { 1733*29e796fdSEric W. Biederman return NULL; 1734*29e796fdSEric W. Biederman } 1735*29e796fdSEric W. Biederman 1736b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table) 1737b89a8171SEric W. Biederman { 1738b89a8171SEric W. Biederman } 1739b89a8171SEric W. Biederman 1740b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */ 1741b89a8171SEric W. Biederman 17421da177e4SLinus Torvalds /* 17431da177e4SLinus Torvalds * /proc/sys support 17441da177e4SLinus Torvalds */ 17451da177e4SLinus Torvalds 1746b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL 17471da177e4SLinus Torvalds 1748b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write, 1749b1ba4dddSAdrian Bunk struct file *filp, void __user *buffer, 1750b1ba4dddSAdrian Bunk size_t *lenp, loff_t *ppos) 1751f5dd3d6fSSam Vilain { 1752f5dd3d6fSSam Vilain size_t len; 1753f5dd3d6fSSam Vilain char __user *p; 1754f5dd3d6fSSam Vilain char c; 1755f5dd3d6fSSam Vilain 17568d060877SOleg Nesterov if (!data || !maxlen || !*lenp) { 1757f5dd3d6fSSam Vilain *lenp = 0; 1758f5dd3d6fSSam Vilain return 0; 1759f5dd3d6fSSam Vilain } 1760f5dd3d6fSSam Vilain 1761f5dd3d6fSSam Vilain if (write) { 1762f5dd3d6fSSam Vilain len = 0; 1763f5dd3d6fSSam Vilain p = buffer; 1764f5dd3d6fSSam Vilain while (len < *lenp) { 1765f5dd3d6fSSam Vilain if (get_user(c, p++)) 1766f5dd3d6fSSam Vilain return -EFAULT; 1767f5dd3d6fSSam Vilain if (c == 0 || c == '\n') 1768f5dd3d6fSSam Vilain break; 1769f5dd3d6fSSam Vilain len++; 1770f5dd3d6fSSam Vilain } 1771f5dd3d6fSSam Vilain if (len >= maxlen) 1772f5dd3d6fSSam Vilain len = maxlen-1; 1773f5dd3d6fSSam Vilain if(copy_from_user(data, buffer, len)) 1774f5dd3d6fSSam Vilain return -EFAULT; 1775f5dd3d6fSSam Vilain ((char *) data)[len] = 0; 1776f5dd3d6fSSam Vilain *ppos += *lenp; 1777f5dd3d6fSSam Vilain } else { 1778f5dd3d6fSSam Vilain len = strlen(data); 1779f5dd3d6fSSam Vilain if (len > maxlen) 1780f5dd3d6fSSam Vilain len = maxlen; 17818d060877SOleg Nesterov 17828d060877SOleg Nesterov if (*ppos > len) { 17838d060877SOleg Nesterov *lenp = 0; 17848d060877SOleg Nesterov return 0; 17858d060877SOleg Nesterov } 17868d060877SOleg Nesterov 17878d060877SOleg Nesterov data += *ppos; 17888d060877SOleg Nesterov len -= *ppos; 17898d060877SOleg Nesterov 1790f5dd3d6fSSam Vilain if (len > *lenp) 1791f5dd3d6fSSam Vilain len = *lenp; 1792f5dd3d6fSSam Vilain if (len) 1793f5dd3d6fSSam Vilain if(copy_to_user(buffer, data, len)) 1794f5dd3d6fSSam Vilain return -EFAULT; 1795f5dd3d6fSSam Vilain if (len < *lenp) { 1796f5dd3d6fSSam Vilain if(put_user('\n', ((char __user *) buffer) + len)) 1797f5dd3d6fSSam Vilain return -EFAULT; 1798f5dd3d6fSSam Vilain len++; 1799f5dd3d6fSSam Vilain } 1800f5dd3d6fSSam Vilain *lenp = len; 1801f5dd3d6fSSam Vilain *ppos += len; 1802f5dd3d6fSSam Vilain } 1803f5dd3d6fSSam Vilain return 0; 1804f5dd3d6fSSam Vilain } 1805f5dd3d6fSSam Vilain 18061da177e4SLinus Torvalds /** 18071da177e4SLinus Torvalds * proc_dostring - read a string sysctl 18081da177e4SLinus Torvalds * @table: the sysctl table 18091da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 18101da177e4SLinus Torvalds * @filp: the file structure 18111da177e4SLinus Torvalds * @buffer: the user buffer 18121da177e4SLinus Torvalds * @lenp: the size of the user buffer 18131da177e4SLinus Torvalds * @ppos: file position 18141da177e4SLinus Torvalds * 18151da177e4SLinus Torvalds * Reads/writes a string from/to the user buffer. If the kernel 18161da177e4SLinus Torvalds * buffer provided is not large enough to hold the string, the 18171da177e4SLinus Torvalds * string is truncated. The copied string is %NULL-terminated. 18181da177e4SLinus Torvalds * If the string is being read by the user process, it is copied 18191da177e4SLinus Torvalds * and a newline '\n' is added. It is truncated if the buffer is 18201da177e4SLinus Torvalds * not large enough. 18211da177e4SLinus Torvalds * 18221da177e4SLinus Torvalds * Returns 0 on success. 18231da177e4SLinus Torvalds */ 1824d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp, 18251da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 18261da177e4SLinus Torvalds { 1827f5dd3d6fSSam Vilain return _proc_do_string(table->data, table->maxlen, write, filp, 1828f5dd3d6fSSam Vilain buffer, lenp, ppos); 18291da177e4SLinus Torvalds } 18301da177e4SLinus Torvalds 18311da177e4SLinus Torvalds 18321da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, 18331da177e4SLinus Torvalds int *valp, 18341da177e4SLinus Torvalds int write, void *data) 18351da177e4SLinus Torvalds { 18361da177e4SLinus Torvalds if (write) { 18371da177e4SLinus Torvalds *valp = *negp ? -*lvalp : *lvalp; 18381da177e4SLinus Torvalds } else { 18391da177e4SLinus Torvalds int val = *valp; 18401da177e4SLinus Torvalds if (val < 0) { 18411da177e4SLinus Torvalds *negp = -1; 18421da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 18431da177e4SLinus Torvalds } else { 18441da177e4SLinus Torvalds *negp = 0; 18451da177e4SLinus Torvalds *lvalp = (unsigned long)val; 18461da177e4SLinus Torvalds } 18471da177e4SLinus Torvalds } 18481da177e4SLinus Torvalds return 0; 18491da177e4SLinus Torvalds } 18501da177e4SLinus Torvalds 1851d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 1852fcfbd547SKirill Korotaev int write, struct file *filp, void __user *buffer, 1853fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 18541da177e4SLinus Torvalds int (*conv)(int *negp, unsigned long *lvalp, int *valp, 18551da177e4SLinus Torvalds int write, void *data), 18561da177e4SLinus Torvalds void *data) 18571da177e4SLinus Torvalds { 18581da177e4SLinus Torvalds #define TMPBUFLEN 21 18591da177e4SLinus Torvalds int *i, vleft, first=1, neg, val; 18601da177e4SLinus Torvalds unsigned long lval; 18611da177e4SLinus Torvalds size_t left, len; 18621da177e4SLinus Torvalds 18631da177e4SLinus Torvalds char buf[TMPBUFLEN], *p; 18641da177e4SLinus Torvalds char __user *s = buffer; 18651da177e4SLinus Torvalds 1866fcfbd547SKirill Korotaev if (!tbl_data || !table->maxlen || !*lenp || 18671da177e4SLinus Torvalds (*ppos && !write)) { 18681da177e4SLinus Torvalds *lenp = 0; 18691da177e4SLinus Torvalds return 0; 18701da177e4SLinus Torvalds } 18711da177e4SLinus Torvalds 1872fcfbd547SKirill Korotaev i = (int *) tbl_data; 18731da177e4SLinus Torvalds vleft = table->maxlen / sizeof(*i); 18741da177e4SLinus Torvalds left = *lenp; 18751da177e4SLinus Torvalds 18761da177e4SLinus Torvalds if (!conv) 18771da177e4SLinus Torvalds conv = do_proc_dointvec_conv; 18781da177e4SLinus Torvalds 18791da177e4SLinus Torvalds for (; left && vleft--; i++, first=0) { 18801da177e4SLinus Torvalds if (write) { 18811da177e4SLinus Torvalds while (left) { 18821da177e4SLinus Torvalds char c; 18831da177e4SLinus Torvalds if (get_user(c, s)) 18841da177e4SLinus Torvalds return -EFAULT; 18851da177e4SLinus Torvalds if (!isspace(c)) 18861da177e4SLinus Torvalds break; 18871da177e4SLinus Torvalds left--; 18881da177e4SLinus Torvalds s++; 18891da177e4SLinus Torvalds } 18901da177e4SLinus Torvalds if (!left) 18911da177e4SLinus Torvalds break; 18921da177e4SLinus Torvalds neg = 0; 18931da177e4SLinus Torvalds len = left; 18941da177e4SLinus Torvalds if (len > sizeof(buf) - 1) 18951da177e4SLinus Torvalds len = sizeof(buf) - 1; 18961da177e4SLinus Torvalds if (copy_from_user(buf, s, len)) 18971da177e4SLinus Torvalds return -EFAULT; 18981da177e4SLinus Torvalds buf[len] = 0; 18991da177e4SLinus Torvalds p = buf; 19001da177e4SLinus Torvalds if (*p == '-' && left > 1) { 19011da177e4SLinus Torvalds neg = 1; 1902bd9b0bacSBP, Praveen p++; 19031da177e4SLinus Torvalds } 19041da177e4SLinus Torvalds if (*p < '0' || *p > '9') 19051da177e4SLinus Torvalds break; 19061da177e4SLinus Torvalds 19071da177e4SLinus Torvalds lval = simple_strtoul(p, &p, 0); 19081da177e4SLinus Torvalds 19091da177e4SLinus Torvalds len = p-buf; 19101da177e4SLinus Torvalds if ((len < left) && *p && !isspace(*p)) 19111da177e4SLinus Torvalds break; 19121da177e4SLinus Torvalds if (neg) 19131da177e4SLinus Torvalds val = -val; 19141da177e4SLinus Torvalds s += len; 19151da177e4SLinus Torvalds left -= len; 19161da177e4SLinus Torvalds 19171da177e4SLinus Torvalds if (conv(&neg, &lval, i, 1, data)) 19181da177e4SLinus Torvalds break; 19191da177e4SLinus Torvalds } else { 19201da177e4SLinus Torvalds p = buf; 19211da177e4SLinus Torvalds if (!first) 19221da177e4SLinus Torvalds *p++ = '\t'; 19231da177e4SLinus Torvalds 19241da177e4SLinus Torvalds if (conv(&neg, &lval, i, 0, data)) 19251da177e4SLinus Torvalds break; 19261da177e4SLinus Torvalds 19271da177e4SLinus Torvalds sprintf(p, "%s%lu", neg ? "-" : "", lval); 19281da177e4SLinus Torvalds len = strlen(buf); 19291da177e4SLinus Torvalds if (len > left) 19301da177e4SLinus Torvalds len = left; 19311da177e4SLinus Torvalds if(copy_to_user(s, buf, len)) 19321da177e4SLinus Torvalds return -EFAULT; 19331da177e4SLinus Torvalds left -= len; 19341da177e4SLinus Torvalds s += len; 19351da177e4SLinus Torvalds } 19361da177e4SLinus Torvalds } 19371da177e4SLinus Torvalds 19381da177e4SLinus Torvalds if (!write && !first && left) { 19391da177e4SLinus Torvalds if(put_user('\n', s)) 19401da177e4SLinus Torvalds return -EFAULT; 19411da177e4SLinus Torvalds left--, s++; 19421da177e4SLinus Torvalds } 19431da177e4SLinus Torvalds if (write) { 19441da177e4SLinus Torvalds while (left) { 19451da177e4SLinus Torvalds char c; 19461da177e4SLinus Torvalds if (get_user(c, s++)) 19471da177e4SLinus Torvalds return -EFAULT; 19481da177e4SLinus Torvalds if (!isspace(c)) 19491da177e4SLinus Torvalds break; 19501da177e4SLinus Torvalds left--; 19511da177e4SLinus Torvalds } 19521da177e4SLinus Torvalds } 19531da177e4SLinus Torvalds if (write && first) 19541da177e4SLinus Torvalds return -EINVAL; 19551da177e4SLinus Torvalds *lenp -= left; 19561da177e4SLinus Torvalds *ppos += *lenp; 19571da177e4SLinus Torvalds return 0; 19581da177e4SLinus Torvalds #undef TMPBUFLEN 19591da177e4SLinus Torvalds } 19601da177e4SLinus Torvalds 1961d8217f07SEric W. Biederman static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp, 1962fcfbd547SKirill Korotaev void __user *buffer, size_t *lenp, loff_t *ppos, 1963fcfbd547SKirill Korotaev int (*conv)(int *negp, unsigned long *lvalp, int *valp, 1964fcfbd547SKirill Korotaev int write, void *data), 1965fcfbd547SKirill Korotaev void *data) 1966fcfbd547SKirill Korotaev { 1967fcfbd547SKirill Korotaev return __do_proc_dointvec(table->data, table, write, filp, 1968fcfbd547SKirill Korotaev buffer, lenp, ppos, conv, data); 1969fcfbd547SKirill Korotaev } 1970fcfbd547SKirill Korotaev 19711da177e4SLinus Torvalds /** 19721da177e4SLinus Torvalds * proc_dointvec - read a vector of integers 19731da177e4SLinus Torvalds * @table: the sysctl table 19741da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 19751da177e4SLinus Torvalds * @filp: the file structure 19761da177e4SLinus Torvalds * @buffer: the user buffer 19771da177e4SLinus Torvalds * @lenp: the size of the user buffer 19781da177e4SLinus Torvalds * @ppos: file position 19791da177e4SLinus Torvalds * 19801da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 19811da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 19821da177e4SLinus Torvalds * 19831da177e4SLinus Torvalds * Returns 0 on success. 19841da177e4SLinus Torvalds */ 1985d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp, 19861da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 19871da177e4SLinus Torvalds { 19881da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 19891da177e4SLinus Torvalds NULL,NULL); 19901da177e4SLinus Torvalds } 19911da177e4SLinus Torvalds 19921da177e4SLinus Torvalds #define OP_SET 0 19931da177e4SLinus Torvalds #define OP_AND 1 199434f5a398STheodore Ts'o #define OP_OR 2 19951da177e4SLinus Torvalds 19961da177e4SLinus Torvalds static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp, 19971da177e4SLinus Torvalds int *valp, 19981da177e4SLinus Torvalds int write, void *data) 19991da177e4SLinus Torvalds { 20001da177e4SLinus Torvalds int op = *(int *)data; 20011da177e4SLinus Torvalds if (write) { 20021da177e4SLinus Torvalds int val = *negp ? -*lvalp : *lvalp; 20031da177e4SLinus Torvalds switch(op) { 20041da177e4SLinus Torvalds case OP_SET: *valp = val; break; 20051da177e4SLinus Torvalds case OP_AND: *valp &= val; break; 200634f5a398STheodore Ts'o case OP_OR: *valp |= val; break; 20071da177e4SLinus Torvalds } 20081da177e4SLinus Torvalds } else { 20091da177e4SLinus Torvalds int val = *valp; 20101da177e4SLinus Torvalds if (val < 0) { 20111da177e4SLinus Torvalds *negp = -1; 20121da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 20131da177e4SLinus Torvalds } else { 20141da177e4SLinus Torvalds *negp = 0; 20151da177e4SLinus Torvalds *lvalp = (unsigned long)val; 20161da177e4SLinus Torvalds } 20171da177e4SLinus Torvalds } 20181da177e4SLinus Torvalds return 0; 20191da177e4SLinus Torvalds } 20201da177e4SLinus Torvalds 202172c2d582SAndrew Morgan #ifdef CONFIG_SECURITY_CAPABILITIES 20221da177e4SLinus Torvalds /* 20231da177e4SLinus Torvalds * init may raise the set. 20241da177e4SLinus Torvalds */ 20251da177e4SLinus Torvalds 2026d8217f07SEric W. Biederman int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp, 20271da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 20281da177e4SLinus Torvalds { 20291da177e4SLinus Torvalds int op; 20301da177e4SLinus Torvalds 20316ff1b442SEric Paris if (write && !capable(CAP_SYS_MODULE)) { 20321da177e4SLinus Torvalds return -EPERM; 20331da177e4SLinus Torvalds } 20341da177e4SLinus Torvalds 2035b460cbc5SSerge E. Hallyn op = is_global_init(current) ? OP_SET : OP_AND; 20361da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 20371da177e4SLinus Torvalds do_proc_dointvec_bset_conv,&op); 20381da177e4SLinus Torvalds } 203972c2d582SAndrew Morgan #endif /* def CONFIG_SECURITY_CAPABILITIES */ 20401da177e4SLinus Torvalds 204134f5a398STheodore Ts'o /* 204234f5a398STheodore Ts'o * Taint values can only be increased 204334f5a398STheodore Ts'o */ 2044d8217f07SEric W. Biederman static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp, 204534f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos) 204634f5a398STheodore Ts'o { 204734f5a398STheodore Ts'o int op; 204834f5a398STheodore Ts'o 204991fcd412SBastian Blank if (write && !capable(CAP_SYS_ADMIN)) 205034f5a398STheodore Ts'o return -EPERM; 205134f5a398STheodore Ts'o 205234f5a398STheodore Ts'o op = OP_OR; 205334f5a398STheodore Ts'o return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 205434f5a398STheodore Ts'o do_proc_dointvec_bset_conv,&op); 205534f5a398STheodore Ts'o } 205634f5a398STheodore Ts'o 20571da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param { 20581da177e4SLinus Torvalds int *min; 20591da177e4SLinus Torvalds int *max; 20601da177e4SLinus Torvalds }; 20611da177e4SLinus Torvalds 20621da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 20631da177e4SLinus Torvalds int *valp, 20641da177e4SLinus Torvalds int write, void *data) 20651da177e4SLinus Torvalds { 20661da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param *param = data; 20671da177e4SLinus Torvalds if (write) { 20681da177e4SLinus Torvalds int val = *negp ? -*lvalp : *lvalp; 20691da177e4SLinus Torvalds if ((param->min && *param->min > val) || 20701da177e4SLinus Torvalds (param->max && *param->max < val)) 20711da177e4SLinus Torvalds return -EINVAL; 20721da177e4SLinus Torvalds *valp = val; 20731da177e4SLinus Torvalds } else { 20741da177e4SLinus Torvalds int val = *valp; 20751da177e4SLinus Torvalds if (val < 0) { 20761da177e4SLinus Torvalds *negp = -1; 20771da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 20781da177e4SLinus Torvalds } else { 20791da177e4SLinus Torvalds *negp = 0; 20801da177e4SLinus Torvalds *lvalp = (unsigned long)val; 20811da177e4SLinus Torvalds } 20821da177e4SLinus Torvalds } 20831da177e4SLinus Torvalds return 0; 20841da177e4SLinus Torvalds } 20851da177e4SLinus Torvalds 20861da177e4SLinus Torvalds /** 20871da177e4SLinus Torvalds * proc_dointvec_minmax - read a vector of integers with min/max values 20881da177e4SLinus Torvalds * @table: the sysctl table 20891da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 20901da177e4SLinus Torvalds * @filp: the file structure 20911da177e4SLinus Torvalds * @buffer: the user buffer 20921da177e4SLinus Torvalds * @lenp: the size of the user buffer 20931da177e4SLinus Torvalds * @ppos: file position 20941da177e4SLinus Torvalds * 20951da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 20961da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 20971da177e4SLinus Torvalds * 20981da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 20991da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 21001da177e4SLinus Torvalds * 21011da177e4SLinus Torvalds * Returns 0 on success. 21021da177e4SLinus Torvalds */ 2103d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, 21041da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 21051da177e4SLinus Torvalds { 21061da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param param = { 21071da177e4SLinus Torvalds .min = (int *) table->extra1, 21081da177e4SLinus Torvalds .max = (int *) table->extra2, 21091da177e4SLinus Torvalds }; 21101da177e4SLinus Torvalds return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, 21111da177e4SLinus Torvalds do_proc_dointvec_minmax_conv, ¶m); 21121da177e4SLinus Torvalds } 21131da177e4SLinus Torvalds 2114d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, 21151da177e4SLinus Torvalds struct file *filp, 21161da177e4SLinus Torvalds void __user *buffer, 21171da177e4SLinus Torvalds size_t *lenp, loff_t *ppos, 21181da177e4SLinus Torvalds unsigned long convmul, 21191da177e4SLinus Torvalds unsigned long convdiv) 21201da177e4SLinus Torvalds { 21211da177e4SLinus Torvalds #define TMPBUFLEN 21 21221da177e4SLinus Torvalds unsigned long *i, *min, *max, val; 21231da177e4SLinus Torvalds int vleft, first=1, neg; 21241da177e4SLinus Torvalds size_t len, left; 21251da177e4SLinus Torvalds char buf[TMPBUFLEN], *p; 21261da177e4SLinus Torvalds char __user *s = buffer; 21271da177e4SLinus Torvalds 2128fcfbd547SKirill Korotaev if (!data || !table->maxlen || !*lenp || 21291da177e4SLinus Torvalds (*ppos && !write)) { 21301da177e4SLinus Torvalds *lenp = 0; 21311da177e4SLinus Torvalds return 0; 21321da177e4SLinus Torvalds } 21331da177e4SLinus Torvalds 2134fcfbd547SKirill Korotaev i = (unsigned long *) data; 21351da177e4SLinus Torvalds min = (unsigned long *) table->extra1; 21361da177e4SLinus Torvalds max = (unsigned long *) table->extra2; 21371da177e4SLinus Torvalds vleft = table->maxlen / sizeof(unsigned long); 21381da177e4SLinus Torvalds left = *lenp; 21391da177e4SLinus Torvalds 21401da177e4SLinus Torvalds for (; left && vleft--; i++, min++, max++, first=0) { 21411da177e4SLinus Torvalds if (write) { 21421da177e4SLinus Torvalds while (left) { 21431da177e4SLinus Torvalds char c; 21441da177e4SLinus Torvalds if (get_user(c, s)) 21451da177e4SLinus Torvalds return -EFAULT; 21461da177e4SLinus Torvalds if (!isspace(c)) 21471da177e4SLinus Torvalds break; 21481da177e4SLinus Torvalds left--; 21491da177e4SLinus Torvalds s++; 21501da177e4SLinus Torvalds } 21511da177e4SLinus Torvalds if (!left) 21521da177e4SLinus Torvalds break; 21531da177e4SLinus Torvalds neg = 0; 21541da177e4SLinus Torvalds len = left; 21551da177e4SLinus Torvalds if (len > TMPBUFLEN-1) 21561da177e4SLinus Torvalds len = TMPBUFLEN-1; 21571da177e4SLinus Torvalds if (copy_from_user(buf, s, len)) 21581da177e4SLinus Torvalds return -EFAULT; 21591da177e4SLinus Torvalds buf[len] = 0; 21601da177e4SLinus Torvalds p = buf; 21611da177e4SLinus Torvalds if (*p == '-' && left > 1) { 21621da177e4SLinus Torvalds neg = 1; 2163bd9b0bacSBP, Praveen p++; 21641da177e4SLinus Torvalds } 21651da177e4SLinus Torvalds if (*p < '0' || *p > '9') 21661da177e4SLinus Torvalds break; 21671da177e4SLinus Torvalds val = simple_strtoul(p, &p, 0) * convmul / convdiv ; 21681da177e4SLinus Torvalds len = p-buf; 21691da177e4SLinus Torvalds if ((len < left) && *p && !isspace(*p)) 21701da177e4SLinus Torvalds break; 21711da177e4SLinus Torvalds if (neg) 21721da177e4SLinus Torvalds val = -val; 21731da177e4SLinus Torvalds s += len; 21741da177e4SLinus Torvalds left -= len; 21751da177e4SLinus Torvalds 21761da177e4SLinus Torvalds if(neg) 21771da177e4SLinus Torvalds continue; 21781da177e4SLinus Torvalds if ((min && val < *min) || (max && val > *max)) 21791da177e4SLinus Torvalds continue; 21801da177e4SLinus Torvalds *i = val; 21811da177e4SLinus Torvalds } else { 21821da177e4SLinus Torvalds p = buf; 21831da177e4SLinus Torvalds if (!first) 21841da177e4SLinus Torvalds *p++ = '\t'; 21851da177e4SLinus Torvalds sprintf(p, "%lu", convdiv * (*i) / convmul); 21861da177e4SLinus Torvalds len = strlen(buf); 21871da177e4SLinus Torvalds if (len > left) 21881da177e4SLinus Torvalds len = left; 21891da177e4SLinus Torvalds if(copy_to_user(s, buf, len)) 21901da177e4SLinus Torvalds return -EFAULT; 21911da177e4SLinus Torvalds left -= len; 21921da177e4SLinus Torvalds s += len; 21931da177e4SLinus Torvalds } 21941da177e4SLinus Torvalds } 21951da177e4SLinus Torvalds 21961da177e4SLinus Torvalds if (!write && !first && left) { 21971da177e4SLinus Torvalds if(put_user('\n', s)) 21981da177e4SLinus Torvalds return -EFAULT; 21991da177e4SLinus Torvalds left--, s++; 22001da177e4SLinus Torvalds } 22011da177e4SLinus Torvalds if (write) { 22021da177e4SLinus Torvalds while (left) { 22031da177e4SLinus Torvalds char c; 22041da177e4SLinus Torvalds if (get_user(c, s++)) 22051da177e4SLinus Torvalds return -EFAULT; 22061da177e4SLinus Torvalds if (!isspace(c)) 22071da177e4SLinus Torvalds break; 22081da177e4SLinus Torvalds left--; 22091da177e4SLinus Torvalds } 22101da177e4SLinus Torvalds } 22111da177e4SLinus Torvalds if (write && first) 22121da177e4SLinus Torvalds return -EINVAL; 22131da177e4SLinus Torvalds *lenp -= left; 22141da177e4SLinus Torvalds *ppos += *lenp; 22151da177e4SLinus Torvalds return 0; 22161da177e4SLinus Torvalds #undef TMPBUFLEN 22171da177e4SLinus Torvalds } 22181da177e4SLinus Torvalds 2219d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 2220fcfbd547SKirill Korotaev struct file *filp, 2221fcfbd547SKirill Korotaev void __user *buffer, 2222fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 2223fcfbd547SKirill Korotaev unsigned long convmul, 2224fcfbd547SKirill Korotaev unsigned long convdiv) 2225fcfbd547SKirill Korotaev { 2226fcfbd547SKirill Korotaev return __do_proc_doulongvec_minmax(table->data, table, write, 2227fcfbd547SKirill Korotaev filp, buffer, lenp, ppos, convmul, convdiv); 2228fcfbd547SKirill Korotaev } 2229fcfbd547SKirill Korotaev 22301da177e4SLinus Torvalds /** 22311da177e4SLinus Torvalds * proc_doulongvec_minmax - read a vector of long integers with min/max values 22321da177e4SLinus Torvalds * @table: the sysctl table 22331da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 22341da177e4SLinus Torvalds * @filp: the file structure 22351da177e4SLinus Torvalds * @buffer: the user buffer 22361da177e4SLinus Torvalds * @lenp: the size of the user buffer 22371da177e4SLinus Torvalds * @ppos: file position 22381da177e4SLinus Torvalds * 22391da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 22401da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 22411da177e4SLinus Torvalds * 22421da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 22431da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 22441da177e4SLinus Torvalds * 22451da177e4SLinus Torvalds * Returns 0 on success. 22461da177e4SLinus Torvalds */ 2247d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, 22481da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 22491da177e4SLinus Torvalds { 22501da177e4SLinus Torvalds return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l); 22511da177e4SLinus Torvalds } 22521da177e4SLinus Torvalds 22531da177e4SLinus Torvalds /** 22541da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 22551da177e4SLinus Torvalds * @table: the sysctl table 22561da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 22571da177e4SLinus Torvalds * @filp: the file structure 22581da177e4SLinus Torvalds * @buffer: the user buffer 22591da177e4SLinus Torvalds * @lenp: the size of the user buffer 22601da177e4SLinus Torvalds * @ppos: file position 22611da177e4SLinus Torvalds * 22621da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 22631da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. The values 22641da177e4SLinus Torvalds * are treated as milliseconds, and converted to jiffies when they are stored. 22651da177e4SLinus Torvalds * 22661da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 22671da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 22681da177e4SLinus Torvalds * 22691da177e4SLinus Torvalds * Returns 0 on success. 22701da177e4SLinus Torvalds */ 2271d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 22721da177e4SLinus Torvalds struct file *filp, 22731da177e4SLinus Torvalds void __user *buffer, 22741da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 22751da177e4SLinus Torvalds { 22761da177e4SLinus Torvalds return do_proc_doulongvec_minmax(table, write, filp, buffer, 22771da177e4SLinus Torvalds lenp, ppos, HZ, 1000l); 22781da177e4SLinus Torvalds } 22791da177e4SLinus Torvalds 22801da177e4SLinus Torvalds 22811da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, 22821da177e4SLinus Torvalds int *valp, 22831da177e4SLinus Torvalds int write, void *data) 22841da177e4SLinus Torvalds { 22851da177e4SLinus Torvalds if (write) { 2286cba9f33dSBart Samwel if (*lvalp > LONG_MAX / HZ) 2287cba9f33dSBart Samwel return 1; 22881da177e4SLinus Torvalds *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); 22891da177e4SLinus Torvalds } else { 22901da177e4SLinus Torvalds int val = *valp; 22911da177e4SLinus Torvalds unsigned long lval; 22921da177e4SLinus Torvalds if (val < 0) { 22931da177e4SLinus Torvalds *negp = -1; 22941da177e4SLinus Torvalds lval = (unsigned long)-val; 22951da177e4SLinus Torvalds } else { 22961da177e4SLinus Torvalds *negp = 0; 22971da177e4SLinus Torvalds lval = (unsigned long)val; 22981da177e4SLinus Torvalds } 22991da177e4SLinus Torvalds *lvalp = lval / HZ; 23001da177e4SLinus Torvalds } 23011da177e4SLinus Torvalds return 0; 23021da177e4SLinus Torvalds } 23031da177e4SLinus Torvalds 23041da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, 23051da177e4SLinus Torvalds int *valp, 23061da177e4SLinus Torvalds int write, void *data) 23071da177e4SLinus Torvalds { 23081da177e4SLinus Torvalds if (write) { 2309cba9f33dSBart Samwel if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 2310cba9f33dSBart Samwel return 1; 23111da177e4SLinus Torvalds *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 23121da177e4SLinus Torvalds } else { 23131da177e4SLinus Torvalds int val = *valp; 23141da177e4SLinus Torvalds unsigned long lval; 23151da177e4SLinus Torvalds if (val < 0) { 23161da177e4SLinus Torvalds *negp = -1; 23171da177e4SLinus Torvalds lval = (unsigned long)-val; 23181da177e4SLinus Torvalds } else { 23191da177e4SLinus Torvalds *negp = 0; 23201da177e4SLinus Torvalds lval = (unsigned long)val; 23211da177e4SLinus Torvalds } 23221da177e4SLinus Torvalds *lvalp = jiffies_to_clock_t(lval); 23231da177e4SLinus Torvalds } 23241da177e4SLinus Torvalds return 0; 23251da177e4SLinus Torvalds } 23261da177e4SLinus Torvalds 23271da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, 23281da177e4SLinus Torvalds int *valp, 23291da177e4SLinus Torvalds int write, void *data) 23301da177e4SLinus Torvalds { 23311da177e4SLinus Torvalds if (write) { 23321da177e4SLinus Torvalds *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 23331da177e4SLinus Torvalds } else { 23341da177e4SLinus Torvalds int val = *valp; 23351da177e4SLinus Torvalds unsigned long lval; 23361da177e4SLinus Torvalds if (val < 0) { 23371da177e4SLinus Torvalds *negp = -1; 23381da177e4SLinus Torvalds lval = (unsigned long)-val; 23391da177e4SLinus Torvalds } else { 23401da177e4SLinus Torvalds *negp = 0; 23411da177e4SLinus Torvalds lval = (unsigned long)val; 23421da177e4SLinus Torvalds } 23431da177e4SLinus Torvalds *lvalp = jiffies_to_msecs(lval); 23441da177e4SLinus Torvalds } 23451da177e4SLinus Torvalds return 0; 23461da177e4SLinus Torvalds } 23471da177e4SLinus Torvalds 23481da177e4SLinus Torvalds /** 23491da177e4SLinus Torvalds * proc_dointvec_jiffies - read a vector of integers as seconds 23501da177e4SLinus Torvalds * @table: the sysctl table 23511da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 23521da177e4SLinus Torvalds * @filp: the file structure 23531da177e4SLinus Torvalds * @buffer: the user buffer 23541da177e4SLinus Torvalds * @lenp: the size of the user buffer 23551da177e4SLinus Torvalds * @ppos: file position 23561da177e4SLinus Torvalds * 23571da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 23581da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 23591da177e4SLinus Torvalds * The values read are assumed to be in seconds, and are converted into 23601da177e4SLinus Torvalds * jiffies. 23611da177e4SLinus Torvalds * 23621da177e4SLinus Torvalds * Returns 0 on success. 23631da177e4SLinus Torvalds */ 2364d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, 23651da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 23661da177e4SLinus Torvalds { 23671da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 23681da177e4SLinus Torvalds do_proc_dointvec_jiffies_conv,NULL); 23691da177e4SLinus Torvalds } 23701da177e4SLinus Torvalds 23711da177e4SLinus Torvalds /** 23721da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 23731da177e4SLinus Torvalds * @table: the sysctl table 23741da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 23751da177e4SLinus Torvalds * @filp: the file structure 23761da177e4SLinus Torvalds * @buffer: the user buffer 23771da177e4SLinus Torvalds * @lenp: the size of the user buffer 23781e5d5331SRandy Dunlap * @ppos: pointer to the file position 23791da177e4SLinus Torvalds * 23801da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 23811da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 23821da177e4SLinus Torvalds * The values read are assumed to be in 1/USER_HZ seconds, and 23831da177e4SLinus Torvalds * are converted into jiffies. 23841da177e4SLinus Torvalds * 23851da177e4SLinus Torvalds * Returns 0 on success. 23861da177e4SLinus Torvalds */ 2387d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, 23881da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 23891da177e4SLinus Torvalds { 23901da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 23911da177e4SLinus Torvalds do_proc_dointvec_userhz_jiffies_conv,NULL); 23921da177e4SLinus Torvalds } 23931da177e4SLinus Torvalds 23941da177e4SLinus Torvalds /** 23951da177e4SLinus Torvalds * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 23961da177e4SLinus Torvalds * @table: the sysctl table 23971da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 23981da177e4SLinus Torvalds * @filp: the file structure 23991da177e4SLinus Torvalds * @buffer: the user buffer 24001da177e4SLinus Torvalds * @lenp: the size of the user buffer 240167be2dd1SMartin Waitz * @ppos: file position 240267be2dd1SMartin Waitz * @ppos: the current position in the file 24031da177e4SLinus Torvalds * 24041da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 24051da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 24061da177e4SLinus Torvalds * The values read are assumed to be in 1/1000 seconds, and 24071da177e4SLinus Torvalds * are converted into jiffies. 24081da177e4SLinus Torvalds * 24091da177e4SLinus Torvalds * Returns 0 on success. 24101da177e4SLinus Torvalds */ 2411d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, 24121da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24131da177e4SLinus Torvalds { 24141da177e4SLinus Torvalds return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, 24151da177e4SLinus Torvalds do_proc_dointvec_ms_jiffies_conv, NULL); 24161da177e4SLinus Torvalds } 24171da177e4SLinus Torvalds 2418d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, 24199ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos) 24209ec52099SCedric Le Goater { 24219ec52099SCedric Le Goater struct pid *new_pid; 24229ec52099SCedric Le Goater pid_t tmp; 24239ec52099SCedric Le Goater int r; 24249ec52099SCedric Le Goater 2425b488893aSPavel Emelyanov tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns); 24269ec52099SCedric Le Goater 24279ec52099SCedric Le Goater r = __do_proc_dointvec(&tmp, table, write, filp, buffer, 24289ec52099SCedric Le Goater lenp, ppos, NULL, NULL); 24299ec52099SCedric Le Goater if (r || !write) 24309ec52099SCedric Le Goater return r; 24319ec52099SCedric Le Goater 24329ec52099SCedric Le Goater new_pid = find_get_pid(tmp); 24339ec52099SCedric Le Goater if (!new_pid) 24349ec52099SCedric Le Goater return -ESRCH; 24359ec52099SCedric Le Goater 24369ec52099SCedric Le Goater put_pid(xchg(&cad_pid, new_pid)); 24379ec52099SCedric Le Goater return 0; 24389ec52099SCedric Le Goater } 24399ec52099SCedric Le Goater 24401da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */ 24411da177e4SLinus Torvalds 2442d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp, 24431da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24441da177e4SLinus Torvalds { 24451da177e4SLinus Torvalds return -ENOSYS; 24461da177e4SLinus Torvalds } 24471da177e4SLinus Torvalds 2448d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp, 24491da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24501da177e4SLinus Torvalds { 24511da177e4SLinus Torvalds return -ENOSYS; 24521da177e4SLinus Torvalds } 24531da177e4SLinus Torvalds 2454d8217f07SEric W. Biederman int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp, 24551da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24561da177e4SLinus Torvalds { 24571da177e4SLinus Torvalds return -ENOSYS; 24581da177e4SLinus Torvalds } 24591da177e4SLinus Torvalds 2460d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, 24611da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24621da177e4SLinus Torvalds { 24631da177e4SLinus Torvalds return -ENOSYS; 24641da177e4SLinus Torvalds } 24651da177e4SLinus Torvalds 2466d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, 24671da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24681da177e4SLinus Torvalds { 24691da177e4SLinus Torvalds return -ENOSYS; 24701da177e4SLinus Torvalds } 24711da177e4SLinus Torvalds 2472d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, 24731da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24741da177e4SLinus Torvalds { 24751da177e4SLinus Torvalds return -ENOSYS; 24761da177e4SLinus Torvalds } 24771da177e4SLinus Torvalds 2478d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, 24791da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24801da177e4SLinus Torvalds { 24811da177e4SLinus Torvalds return -ENOSYS; 24821da177e4SLinus Torvalds } 24831da177e4SLinus Torvalds 2484d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, 24851da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24861da177e4SLinus Torvalds { 24871da177e4SLinus Torvalds return -ENOSYS; 24881da177e4SLinus Torvalds } 24891da177e4SLinus Torvalds 2490d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 24911da177e4SLinus Torvalds struct file *filp, 24921da177e4SLinus Torvalds void __user *buffer, 24931da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 24941da177e4SLinus Torvalds { 24951da177e4SLinus Torvalds return -ENOSYS; 24961da177e4SLinus Torvalds } 24971da177e4SLinus Torvalds 24981da177e4SLinus Torvalds 24991da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */ 25001da177e4SLinus Torvalds 25011da177e4SLinus Torvalds 2502b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 25031da177e4SLinus Torvalds /* 25041da177e4SLinus Torvalds * General sysctl support routines 25051da177e4SLinus Torvalds */ 25061da177e4SLinus Torvalds 250749a0c458SEric W. Biederman /* The generic sysctl data routine (used if no strategy routine supplied) */ 250849a0c458SEric W. Biederman int sysctl_data(struct ctl_table *table, int __user *name, int nlen, 250949a0c458SEric W. Biederman void __user *oldval, size_t __user *oldlenp, 251049a0c458SEric W. Biederman void __user *newval, size_t newlen) 251149a0c458SEric W. Biederman { 251249a0c458SEric W. Biederman size_t len; 251349a0c458SEric W. Biederman 251449a0c458SEric W. Biederman /* Get out of I don't have a variable */ 251549a0c458SEric W. Biederman if (!table->data || !table->maxlen) 251649a0c458SEric W. Biederman return -ENOTDIR; 251749a0c458SEric W. Biederman 251849a0c458SEric W. Biederman if (oldval && oldlenp) { 251949a0c458SEric W. Biederman if (get_user(len, oldlenp)) 252049a0c458SEric W. Biederman return -EFAULT; 252149a0c458SEric W. Biederman if (len) { 252249a0c458SEric W. Biederman if (len > table->maxlen) 252349a0c458SEric W. Biederman len = table->maxlen; 252449a0c458SEric W. Biederman if (copy_to_user(oldval, table->data, len)) 252549a0c458SEric W. Biederman return -EFAULT; 252649a0c458SEric W. Biederman if (put_user(len, oldlenp)) 252749a0c458SEric W. Biederman return -EFAULT; 252849a0c458SEric W. Biederman } 252949a0c458SEric W. Biederman } 253049a0c458SEric W. Biederman 253149a0c458SEric W. Biederman if (newval && newlen) { 253249a0c458SEric W. Biederman if (newlen > table->maxlen) 253349a0c458SEric W. Biederman newlen = table->maxlen; 253449a0c458SEric W. Biederman 253549a0c458SEric W. Biederman if (copy_from_user(table->data, newval, newlen)) 253649a0c458SEric W. Biederman return -EFAULT; 253749a0c458SEric W. Biederman } 253849a0c458SEric W. Biederman return 1; 253949a0c458SEric W. Biederman } 254049a0c458SEric W. Biederman 25411da177e4SLinus Torvalds /* The generic string strategy routine: */ 2542d8217f07SEric W. Biederman int sysctl_string(struct ctl_table *table, int __user *name, int nlen, 25431da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 25441f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 25451da177e4SLinus Torvalds { 25461da177e4SLinus Torvalds if (!table->data || !table->maxlen) 25471da177e4SLinus Torvalds return -ENOTDIR; 25481da177e4SLinus Torvalds 25491da177e4SLinus Torvalds if (oldval && oldlenp) { 2550de9e007dSLinus Torvalds size_t bufsize; 2551de9e007dSLinus Torvalds if (get_user(bufsize, oldlenp)) 25521da177e4SLinus Torvalds return -EFAULT; 2553de9e007dSLinus Torvalds if (bufsize) { 2554de9e007dSLinus Torvalds size_t len = strlen(table->data), copied; 2555de9e007dSLinus Torvalds 2556de9e007dSLinus Torvalds /* This shouldn't trigger for a well-formed sysctl */ 2557de9e007dSLinus Torvalds if (len > table->maxlen) 25581da177e4SLinus Torvalds len = table->maxlen; 2559de9e007dSLinus Torvalds 2560de9e007dSLinus Torvalds /* Copy up to a max of bufsize-1 bytes of the string */ 2561de9e007dSLinus Torvalds copied = (len >= bufsize) ? bufsize - 1 : len; 2562de9e007dSLinus Torvalds 2563de9e007dSLinus Torvalds if (copy_to_user(oldval, table->data, copied) || 2564de9e007dSLinus Torvalds put_user(0, (char __user *)(oldval + copied))) 25651da177e4SLinus Torvalds return -EFAULT; 25661da177e4SLinus Torvalds if (put_user(len, oldlenp)) 25671da177e4SLinus Torvalds return -EFAULT; 25681da177e4SLinus Torvalds } 25691da177e4SLinus Torvalds } 25701da177e4SLinus Torvalds if (newval && newlen) { 2571de9e007dSLinus Torvalds size_t len = newlen; 25721da177e4SLinus Torvalds if (len > table->maxlen) 25731da177e4SLinus Torvalds len = table->maxlen; 25741da177e4SLinus Torvalds if(copy_from_user(table->data, newval, len)) 25751da177e4SLinus Torvalds return -EFAULT; 25761da177e4SLinus Torvalds if (len == table->maxlen) 25771da177e4SLinus Torvalds len--; 25781da177e4SLinus Torvalds ((char *) table->data)[len] = 0; 25791da177e4SLinus Torvalds } 258082c9df82SYi Yang return 1; 25811da177e4SLinus Torvalds } 25821da177e4SLinus Torvalds 25831da177e4SLinus Torvalds /* 25841da177e4SLinus Torvalds * This function makes sure that all of the integers in the vector 25851da177e4SLinus Torvalds * are between the minimum and maximum values given in the arrays 25861da177e4SLinus Torvalds * table->extra1 and table->extra2, respectively. 25871da177e4SLinus Torvalds */ 2588d8217f07SEric W. Biederman int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, 25891da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 25901f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 25911da177e4SLinus Torvalds { 25921da177e4SLinus Torvalds 25931da177e4SLinus Torvalds if (newval && newlen) { 25941da177e4SLinus Torvalds int __user *vec = (int __user *) newval; 25951da177e4SLinus Torvalds int *min = (int *) table->extra1; 25961da177e4SLinus Torvalds int *max = (int *) table->extra2; 25971da177e4SLinus Torvalds size_t length; 25981da177e4SLinus Torvalds int i; 25991da177e4SLinus Torvalds 26001da177e4SLinus Torvalds if (newlen % sizeof(int) != 0) 26011da177e4SLinus Torvalds return -EINVAL; 26021da177e4SLinus Torvalds 26031da177e4SLinus Torvalds if (!table->extra1 && !table->extra2) 26041da177e4SLinus Torvalds return 0; 26051da177e4SLinus Torvalds 26061da177e4SLinus Torvalds if (newlen > table->maxlen) 26071da177e4SLinus Torvalds newlen = table->maxlen; 26081da177e4SLinus Torvalds length = newlen / sizeof(int); 26091da177e4SLinus Torvalds 26101da177e4SLinus Torvalds for (i = 0; i < length; i++) { 26111da177e4SLinus Torvalds int value; 26121da177e4SLinus Torvalds if (get_user(value, vec + i)) 26131da177e4SLinus Torvalds return -EFAULT; 26141da177e4SLinus Torvalds if (min && value < min[i]) 26151da177e4SLinus Torvalds return -EINVAL; 26161da177e4SLinus Torvalds if (max && value > max[i]) 26171da177e4SLinus Torvalds return -EINVAL; 26181da177e4SLinus Torvalds } 26191da177e4SLinus Torvalds } 26201da177e4SLinus Torvalds return 0; 26211da177e4SLinus Torvalds } 26221da177e4SLinus Torvalds 26231da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */ 2624d8217f07SEric W. Biederman int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, 26251da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 26261f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 26271da177e4SLinus Torvalds { 26283ee75ac3SAlexey Dobriyan if (oldval && oldlenp) { 26291da177e4SLinus Torvalds size_t olen; 26303ee75ac3SAlexey Dobriyan 26311da177e4SLinus Torvalds if (get_user(olen, oldlenp)) 26321da177e4SLinus Torvalds return -EFAULT; 26333ee75ac3SAlexey Dobriyan if (olen) { 26343ee75ac3SAlexey Dobriyan int val; 26353ee75ac3SAlexey Dobriyan 26363ee75ac3SAlexey Dobriyan if (olen < sizeof(int)) 26371da177e4SLinus Torvalds return -EINVAL; 26383ee75ac3SAlexey Dobriyan 26393ee75ac3SAlexey Dobriyan val = *(int *)(table->data) / HZ; 26403ee75ac3SAlexey Dobriyan if (put_user(val, (int __user *)oldval)) 26411da177e4SLinus Torvalds return -EFAULT; 26423ee75ac3SAlexey Dobriyan if (put_user(sizeof(int), oldlenp)) 26433ee75ac3SAlexey Dobriyan return -EFAULT; 26443ee75ac3SAlexey Dobriyan } 26451da177e4SLinus Torvalds } 26461da177e4SLinus Torvalds if (newval && newlen) { 26471da177e4SLinus Torvalds int new; 26481da177e4SLinus Torvalds if (newlen != sizeof(int)) 26491da177e4SLinus Torvalds return -EINVAL; 26501da177e4SLinus Torvalds if (get_user(new, (int __user *)newval)) 26511da177e4SLinus Torvalds return -EFAULT; 26521da177e4SLinus Torvalds *(int *)(table->data) = new*HZ; 26531da177e4SLinus Torvalds } 26541da177e4SLinus Torvalds return 1; 26551da177e4SLinus Torvalds } 26561da177e4SLinus Torvalds 26571da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */ 2658d8217f07SEric W. Biederman int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen, 26591da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 26601f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 26611da177e4SLinus Torvalds { 26623ee75ac3SAlexey Dobriyan if (oldval && oldlenp) { 26631da177e4SLinus Torvalds size_t olen; 26643ee75ac3SAlexey Dobriyan 26651da177e4SLinus Torvalds if (get_user(olen, oldlenp)) 26661da177e4SLinus Torvalds return -EFAULT; 26673ee75ac3SAlexey Dobriyan if (olen) { 26683ee75ac3SAlexey Dobriyan int val; 26693ee75ac3SAlexey Dobriyan 26703ee75ac3SAlexey Dobriyan if (olen < sizeof(int)) 26711da177e4SLinus Torvalds return -EINVAL; 26723ee75ac3SAlexey Dobriyan 26733ee75ac3SAlexey Dobriyan val = jiffies_to_msecs(*(int *)(table->data)); 26743ee75ac3SAlexey Dobriyan if (put_user(val, (int __user *)oldval)) 26751da177e4SLinus Torvalds return -EFAULT; 26763ee75ac3SAlexey Dobriyan if (put_user(sizeof(int), oldlenp)) 26773ee75ac3SAlexey Dobriyan return -EFAULT; 26783ee75ac3SAlexey Dobriyan } 26791da177e4SLinus Torvalds } 26801da177e4SLinus Torvalds if (newval && newlen) { 26811da177e4SLinus Torvalds int new; 26821da177e4SLinus Torvalds if (newlen != sizeof(int)) 26831da177e4SLinus Torvalds return -EINVAL; 26841da177e4SLinus Torvalds if (get_user(new, (int __user *)newval)) 26851da177e4SLinus Torvalds return -EFAULT; 26861da177e4SLinus Torvalds *(int *)(table->data) = msecs_to_jiffies(new); 26871da177e4SLinus Torvalds } 26881da177e4SLinus Torvalds return 1; 26891da177e4SLinus Torvalds } 26901da177e4SLinus Torvalds 2691c4b8b769SEric W. Biederman 2692c4b8b769SEric W. Biederman 2693b89a8171SEric W. Biederman #else /* CONFIG_SYSCTL_SYSCALL */ 26941da177e4SLinus Torvalds 26951da177e4SLinus Torvalds 26961da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args) 26971da177e4SLinus Torvalds { 26980e009be8SEric W. Biederman struct __sysctl_args tmp; 26997058cb02SEric W. Biederman int error; 27000e009be8SEric W. Biederman 27010e009be8SEric W. Biederman if (copy_from_user(&tmp, args, sizeof(tmp))) 27020e009be8SEric W. Biederman return -EFAULT; 27030e009be8SEric W. Biederman 27047058cb02SEric W. Biederman error = deprecated_sysctl_warning(&tmp); 2705b89a8171SEric W. Biederman 27067058cb02SEric W. Biederman /* If no error reading the parameters then just -ENOSYS ... */ 27077058cb02SEric W. Biederman if (!error) 27087058cb02SEric W. Biederman error = -ENOSYS; 27097058cb02SEric W. Biederman 27107058cb02SEric W. Biederman return error; 27111da177e4SLinus Torvalds } 27121da177e4SLinus Torvalds 271349a0c458SEric W. Biederman int sysctl_data(struct ctl_table *table, int __user *name, int nlen, 271449a0c458SEric W. Biederman void __user *oldval, size_t __user *oldlenp, 271549a0c458SEric W. Biederman void __user *newval, size_t newlen) 271649a0c458SEric W. Biederman { 271749a0c458SEric W. Biederman return -ENOSYS; 271849a0c458SEric W. Biederman } 271949a0c458SEric W. Biederman 2720d8217f07SEric W. Biederman int sysctl_string(struct ctl_table *table, int __user *name, int nlen, 27211da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 27221f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 27231da177e4SLinus Torvalds { 27241da177e4SLinus Torvalds return -ENOSYS; 27251da177e4SLinus Torvalds } 27261da177e4SLinus Torvalds 2727d8217f07SEric W. Biederman int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, 27281da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 27291f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 27301da177e4SLinus Torvalds { 27311da177e4SLinus Torvalds return -ENOSYS; 27321da177e4SLinus Torvalds } 27331da177e4SLinus Torvalds 2734d8217f07SEric W. Biederman int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, 27351da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 27361f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 27371da177e4SLinus Torvalds { 27381da177e4SLinus Torvalds return -ENOSYS; 27391da177e4SLinus Torvalds } 27401da177e4SLinus Torvalds 2741d8217f07SEric W. Biederman int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen, 27421da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 27431f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 27441da177e4SLinus Torvalds { 27451da177e4SLinus Torvalds return -ENOSYS; 27461da177e4SLinus Torvalds } 27471da177e4SLinus Torvalds 2748b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */ 27491da177e4SLinus Torvalds 27507058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args) 27517058cb02SEric W. Biederman { 27527058cb02SEric W. Biederman static int msg_count; 27537058cb02SEric W. Biederman int name[CTL_MAXNAME]; 27547058cb02SEric W. Biederman int i; 27557058cb02SEric W. Biederman 27566fc48af8STetsuo Handa /* Check args->nlen. */ 27576fc48af8STetsuo Handa if (args->nlen < 0 || args->nlen > CTL_MAXNAME) 27586fc48af8STetsuo Handa return -ENOTDIR; 27596fc48af8STetsuo Handa 27607058cb02SEric W. Biederman /* Read in the sysctl name for better debug message logging */ 27617058cb02SEric W. Biederman for (i = 0; i < args->nlen; i++) 27627058cb02SEric W. Biederman if (get_user(name[i], args->name + i)) 27637058cb02SEric W. Biederman return -EFAULT; 27647058cb02SEric W. Biederman 27657058cb02SEric W. Biederman /* Ignore accesses to kernel.version */ 27667058cb02SEric W. Biederman if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION)) 27677058cb02SEric W. Biederman return 0; 27687058cb02SEric W. Biederman 27697058cb02SEric W. Biederman if (msg_count < 5) { 27707058cb02SEric W. Biederman msg_count++; 27717058cb02SEric W. Biederman printk(KERN_INFO 27727058cb02SEric W. Biederman "warning: process `%s' used the deprecated sysctl " 27737058cb02SEric W. Biederman "system call with ", current->comm); 27747058cb02SEric W. Biederman for (i = 0; i < args->nlen; i++) 27757058cb02SEric W. Biederman printk("%d.", name[i]); 27767058cb02SEric W. Biederman printk("\n"); 27777058cb02SEric W. Biederman } 27787058cb02SEric W. Biederman return 0; 27797058cb02SEric W. Biederman } 27807058cb02SEric W. Biederman 27811da177e4SLinus Torvalds /* 27821da177e4SLinus Torvalds * No sense putting this after each symbol definition, twice, 27831da177e4SLinus Torvalds * exception granted :-) 27841da177e4SLinus Torvalds */ 27851da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec); 27861da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies); 27871da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax); 27881da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 27891da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 27901da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring); 27911da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax); 27921da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 27931da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table); 2794*29e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths); 27951da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec); 27961da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies); 27971da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies); 27981da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string); 279949a0c458SEric W. Biederman EXPORT_SYMBOL(sysctl_data); 28001da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table); 2801