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/initrd.h> 410b77f5bfSDavid Howells #include <linux/key.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> 49b0fc494fSSteven Rostedt #include <linux/ftrace.h> 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds #include <asm/uaccess.h> 521da177e4SLinus Torvalds #include <asm/processor.h> 531da177e4SLinus Torvalds 5429cbc78bSAndi Kleen #ifdef CONFIG_X86 5529cbc78bSAndi Kleen #include <asm/nmi.h> 560741f4d2SChuck Ebbert #include <asm/stacktrace.h> 576e7c4025SIngo Molnar #include <asm/io.h> 5829cbc78bSAndi Kleen #endif 5929cbc78bSAndi Kleen 607058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args); 617058cb02SEric W. Biederman 621da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds /* External variables not in a header file. */ 651da177e4SLinus Torvalds extern int C_A_D; 6645807a1dSIngo Molnar extern int print_fatal_signals; 671da177e4SLinus Torvalds extern int sysctl_overcommit_memory; 681da177e4SLinus Torvalds extern int sysctl_overcommit_ratio; 69fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom; 70fe071d7eSDavid Rientjes extern int sysctl_oom_kill_allocating_task; 71fef1bdd6SDavid Rientjes extern int sysctl_oom_dump_tasks; 721da177e4SLinus Torvalds extern int max_threads; 731da177e4SLinus Torvalds extern int core_uses_pid; 74d6e71144SAlan Cox extern int suid_dumpable; 751da177e4SLinus Torvalds extern char core_pattern[]; 761da177e4SLinus Torvalds extern int pid_max; 771da177e4SLinus Torvalds extern int min_free_kbytes; 781da177e4SLinus Torvalds extern int pid_max_min, pid_max_max; 799d0243bcSAndrew Morton extern int sysctl_drop_caches; 808ad4b1fbSRohit Seth extern int percpu_pagelist_fraction; 81bebfa101SAndi Kleen extern int compat_log; 825096add8SKees Cook extern int maps_protect; 8377461ab3SChristoph Lameter extern int sysctl_stat_interval; 849745512cSArjan van de Ven extern int latencytop_enabled; 85eceea0b3SAl Viro extern int sysctl_nr_open_min, sysctl_nr_open_max; 8631a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST 8731a72bceSPaul E. McKenney extern int rcutorture_runnable; 8831a72bceSPaul E. McKenney #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ 891da177e4SLinus Torvalds 90c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */ 91195cf453SBron Gondwana #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM) 92c4f3b63fSRavikiran G Thirumalai static int one = 1; 93195cf453SBron Gondwana #endif 94195cf453SBron Gondwana 95195cf453SBron Gondwana #ifdef CONFIG_DETECT_SOFTLOCKUP 96c4f3b63fSRavikiran G Thirumalai static int sixty = 60; 97c4f3b63fSRavikiran G Thirumalai #endif 98c4f3b63fSRavikiran G Thirumalai 99c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_MMU 100c4f3b63fSRavikiran G Thirumalai static int two = 2; 101c4f3b63fSRavikiran G Thirumalai #endif 102c4f3b63fSRavikiran G Thirumalai 103c4f3b63fSRavikiran G Thirumalai static int zero; 104c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100; 105c4f3b63fSRavikiran G Thirumalai 1061da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ 1071da177e4SLinus Torvalds static int maxolduid = 65535; 1081da177e4SLinus Torvalds static int minolduid; 1098ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8; 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX; 1121da177e4SLinus Torvalds 113*a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES 1141da177e4SLinus Torvalds extern char modprobe_path[]; 1151da177e4SLinus Torvalds #endif 1161da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG 1171da177e4SLinus Torvalds extern int sg_big_buff; 1181da177e4SLinus Torvalds #endif 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds #ifdef __sparc__ 1211da177e4SLinus Torvalds extern char reboot_command []; 1221da177e4SLinus Torvalds extern int stop_a_enabled; 1231da177e4SLinus Torvalds extern int scons_pwroff; 1241da177e4SLinus Torvalds #endif 1251da177e4SLinus Torvalds 1261da177e4SLinus Torvalds #ifdef __hppa__ 1271da177e4SLinus Torvalds extern int pwrsw_enabled; 1281da177e4SLinus Torvalds extern int unaligned_enabled; 1291da177e4SLinus Torvalds #endif 1301da177e4SLinus Torvalds 131347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 1321da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 1331da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings; 1341da177e4SLinus Torvalds #endif 1351da177e4SLinus Torvalds extern int sysctl_userprocess_debug; 136951f22d5SMartin Schwidefsky extern int spin_retry; 1371da177e4SLinus Torvalds #endif 1381da177e4SLinus Torvalds 1391da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT 1401da177e4SLinus Torvalds extern int acct_parm[]; 1411da177e4SLinus Torvalds #endif 1421da177e4SLinus Torvalds 143d2b176edSJes Sorensen #ifdef CONFIG_IA64 144d2b176edSJes Sorensen extern int no_unaligned_warning; 145d2b176edSJes Sorensen #endif 146d2b176edSJes Sorensen 14723f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 14823f78d4aSIngo Molnar extern int max_lock_depth; 14923f78d4aSIngo Molnar #endif 15023f78d4aSIngo Molnar 151d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 152d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, 1539ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos); 154d8217f07SEric W. Biederman static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp, 15534f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos); 156d6f8ff73SRandy Dunlap #endif 1579ec52099SCedric Le Goater 158d8217f07SEric W. Biederman static struct ctl_table root_table[]; 159e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root; 160e51b6ba0SEric W. Biederman static struct ctl_table_header root_table_header = { 161e51b6ba0SEric W. Biederman .ctl_table = root_table, 162e51b6ba0SEric W. Biederman .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list), 163e51b6ba0SEric W. Biederman .root = &sysctl_table_root, 164e51b6ba0SEric W. Biederman }; 165e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root = { 166e51b6ba0SEric W. Biederman .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), 167e51b6ba0SEric W. Biederman .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry), 168e51b6ba0SEric W. Biederman }; 1691da177e4SLinus Torvalds 170d8217f07SEric W. Biederman static struct ctl_table kern_table[]; 171d8217f07SEric W. Biederman static struct ctl_table vm_table[]; 172d8217f07SEric W. Biederman static struct ctl_table fs_table[]; 173d8217f07SEric W. Biederman static struct ctl_table debug_table[]; 174d8217f07SEric W. Biederman static struct ctl_table dev_table[]; 175d8217f07SEric W. Biederman extern struct ctl_table random_table[]; 1762d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 177d8217f07SEric W. Biederman extern struct ctl_table inotify_table[]; 1780399cb08SRobert Love #endif 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 1811da177e4SLinus Torvalds int sysctl_legacy_va_layout; 1821da177e4SLinus Torvalds #endif 1831da177e4SLinus Torvalds 184f20786ffSPeter Zijlstra extern int prove_locking; 185f20786ffSPeter Zijlstra extern int lock_stat; 1869bc9a6bdSEric W. Biederman 1871da177e4SLinus Torvalds /* The default sysctl tables: */ 1881da177e4SLinus Torvalds 189d8217f07SEric W. Biederman static struct ctl_table root_table[] = { 1901da177e4SLinus Torvalds { 1911da177e4SLinus Torvalds .ctl_name = CTL_KERN, 1921da177e4SLinus Torvalds .procname = "kernel", 1931da177e4SLinus Torvalds .mode = 0555, 1941da177e4SLinus Torvalds .child = kern_table, 1951da177e4SLinus Torvalds }, 1961da177e4SLinus Torvalds { 1971da177e4SLinus Torvalds .ctl_name = CTL_VM, 1981da177e4SLinus Torvalds .procname = "vm", 1991da177e4SLinus Torvalds .mode = 0555, 2001da177e4SLinus Torvalds .child = vm_table, 2011da177e4SLinus Torvalds }, 2021da177e4SLinus Torvalds { 2031da177e4SLinus Torvalds .ctl_name = CTL_FS, 2041da177e4SLinus Torvalds .procname = "fs", 2051da177e4SLinus Torvalds .mode = 0555, 2061da177e4SLinus Torvalds .child = fs_table, 2071da177e4SLinus Torvalds }, 2081da177e4SLinus Torvalds { 2091da177e4SLinus Torvalds .ctl_name = CTL_DEBUG, 2101da177e4SLinus Torvalds .procname = "debug", 2111da177e4SLinus Torvalds .mode = 0555, 2121da177e4SLinus Torvalds .child = debug_table, 2131da177e4SLinus Torvalds }, 2141da177e4SLinus Torvalds { 2151da177e4SLinus Torvalds .ctl_name = CTL_DEV, 2161da177e4SLinus Torvalds .procname = "dev", 2171da177e4SLinus Torvalds .mode = 0555, 2181da177e4SLinus Torvalds .child = dev_table, 2191da177e4SLinus Torvalds }, 2202be7fe07SAndrew Morton /* 2212be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 2222be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 2232be7fe07SAndrew Morton */ 2241da177e4SLinus Torvalds { .ctl_name = 0 } 2251da177e4SLinus Torvalds }; 2261da177e4SLinus Torvalds 22777e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 22873c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000; /* 100 usecs */ 22973c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */ 23073c4efd2SEric Dumazet static int min_wakeup_granularity_ns; /* 0 usecs */ 23173c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */ 23277e54a1fSIngo Molnar #endif 23377e54a1fSIngo Molnar 234d8217f07SEric W. Biederman static struct ctl_table kern_table[] = { 23577e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 23677e54a1fSIngo Molnar { 23777e54a1fSIngo Molnar .ctl_name = CTL_UNNUMBERED, 238b2be5e96SPeter Zijlstra .procname = "sched_min_granularity_ns", 239b2be5e96SPeter Zijlstra .data = &sysctl_sched_min_granularity, 24077e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 24177e54a1fSIngo Molnar .mode = 0644, 242b2be5e96SPeter Zijlstra .proc_handler = &sched_nr_latency_handler, 243b2be5e96SPeter Zijlstra .strategy = &sysctl_intvec, 244b2be5e96SPeter Zijlstra .extra1 = &min_sched_granularity_ns, 245b2be5e96SPeter Zijlstra .extra2 = &max_sched_granularity_ns, 24677e54a1fSIngo Molnar }, 24777e54a1fSIngo Molnar { 24877e54a1fSIngo Molnar .ctl_name = CTL_UNNUMBERED, 24921805085SPeter Zijlstra .procname = "sched_latency_ns", 25021805085SPeter Zijlstra .data = &sysctl_sched_latency, 25121805085SPeter Zijlstra .maxlen = sizeof(unsigned int), 25221805085SPeter Zijlstra .mode = 0644, 253b2be5e96SPeter Zijlstra .proc_handler = &sched_nr_latency_handler, 25421805085SPeter Zijlstra .strategy = &sysctl_intvec, 25521805085SPeter Zijlstra .extra1 = &min_sched_granularity_ns, 25621805085SPeter Zijlstra .extra2 = &max_sched_granularity_ns, 25721805085SPeter Zijlstra }, 25821805085SPeter Zijlstra { 25921805085SPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 26077e54a1fSIngo Molnar .procname = "sched_wakeup_granularity_ns", 26177e54a1fSIngo Molnar .data = &sysctl_sched_wakeup_granularity, 26277e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 26377e54a1fSIngo Molnar .mode = 0644, 26477e54a1fSIngo Molnar .proc_handler = &proc_dointvec_minmax, 26577e54a1fSIngo Molnar .strategy = &sysctl_intvec, 26677e54a1fSIngo Molnar .extra1 = &min_wakeup_granularity_ns, 26777e54a1fSIngo Molnar .extra2 = &max_wakeup_granularity_ns, 26877e54a1fSIngo Molnar }, 26977e54a1fSIngo Molnar { 27077e54a1fSIngo Molnar .ctl_name = CTL_UNNUMBERED, 2712398f2c6SPeter Zijlstra .procname = "sched_shares_ratelimit", 2722398f2c6SPeter Zijlstra .data = &sysctl_sched_shares_ratelimit, 2732398f2c6SPeter Zijlstra .maxlen = sizeof(unsigned int), 2742398f2c6SPeter Zijlstra .mode = 0644, 2752398f2c6SPeter Zijlstra .proc_handler = &proc_dointvec, 2762398f2c6SPeter Zijlstra }, 2772398f2c6SPeter Zijlstra { 2782398f2c6SPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 27977e54a1fSIngo Molnar .procname = "sched_child_runs_first", 28077e54a1fSIngo Molnar .data = &sysctl_sched_child_runs_first, 28177e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 28277e54a1fSIngo Molnar .mode = 0644, 28377e54a1fSIngo Molnar .proc_handler = &proc_dointvec, 28477e54a1fSIngo Molnar }, 2851fc84aaaSPeter Zijlstra { 2861fc84aaaSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 2871fc84aaaSPeter Zijlstra .procname = "sched_features", 2881fc84aaaSPeter Zijlstra .data = &sysctl_sched_features, 2891fc84aaaSPeter Zijlstra .maxlen = sizeof(unsigned int), 2901fc84aaaSPeter Zijlstra .mode = 0644, 2911fc84aaaSPeter Zijlstra .proc_handler = &proc_dointvec, 2921fc84aaaSPeter Zijlstra }, 293da84d961SIngo Molnar { 294da84d961SIngo Molnar .ctl_name = CTL_UNNUMBERED, 295da84d961SIngo Molnar .procname = "sched_migration_cost", 296da84d961SIngo Molnar .data = &sysctl_sched_migration_cost, 297da84d961SIngo Molnar .maxlen = sizeof(unsigned int), 298da84d961SIngo Molnar .mode = 0644, 299da84d961SIngo Molnar .proc_handler = &proc_dointvec, 300da84d961SIngo Molnar }, 301b82d9fddSPeter Zijlstra { 302b82d9fddSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 303b82d9fddSPeter Zijlstra .procname = "sched_nr_migrate", 304b82d9fddSPeter Zijlstra .data = &sysctl_sched_nr_migrate, 305b82d9fddSPeter Zijlstra .maxlen = sizeof(unsigned int), 306fa85ae24SPeter Zijlstra .mode = 0644, 307fa85ae24SPeter Zijlstra .proc_handler = &proc_dointvec, 308fa85ae24SPeter Zijlstra }, 3091fc84aaaSPeter Zijlstra #endif 3101799e35dSIngo Molnar { 3111799e35dSIngo Molnar .ctl_name = CTL_UNNUMBERED, 3129f0c1e56SPeter Zijlstra .procname = "sched_rt_period_us", 3139f0c1e56SPeter Zijlstra .data = &sysctl_sched_rt_period, 3149f0c1e56SPeter Zijlstra .maxlen = sizeof(unsigned int), 3159f0c1e56SPeter Zijlstra .mode = 0644, 316d0b27fa7SPeter Zijlstra .proc_handler = &sched_rt_handler, 3179f0c1e56SPeter Zijlstra }, 3189f0c1e56SPeter Zijlstra { 3199f0c1e56SPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 3209f0c1e56SPeter Zijlstra .procname = "sched_rt_runtime_us", 3219f0c1e56SPeter Zijlstra .data = &sysctl_sched_rt_runtime, 3229f0c1e56SPeter Zijlstra .maxlen = sizeof(int), 3239f0c1e56SPeter Zijlstra .mode = 0644, 324d0b27fa7SPeter Zijlstra .proc_handler = &sched_rt_handler, 3259f0c1e56SPeter Zijlstra }, 3269f0c1e56SPeter Zijlstra { 3279f0c1e56SPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 3281799e35dSIngo Molnar .procname = "sched_compat_yield", 3291799e35dSIngo Molnar .data = &sysctl_sched_compat_yield, 3301799e35dSIngo Molnar .maxlen = sizeof(unsigned int), 3311799e35dSIngo Molnar .mode = 0644, 3321799e35dSIngo Molnar .proc_handler = &proc_dointvec, 3331799e35dSIngo Molnar }, 334f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING 335f20786ffSPeter Zijlstra { 336f20786ffSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 337f20786ffSPeter Zijlstra .procname = "prove_locking", 338f20786ffSPeter Zijlstra .data = &prove_locking, 339f20786ffSPeter Zijlstra .maxlen = sizeof(int), 340f20786ffSPeter Zijlstra .mode = 0644, 341f20786ffSPeter Zijlstra .proc_handler = &proc_dointvec, 342f20786ffSPeter Zijlstra }, 343f20786ffSPeter Zijlstra #endif 344f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT 345f20786ffSPeter Zijlstra { 346f20786ffSPeter Zijlstra .ctl_name = CTL_UNNUMBERED, 347f20786ffSPeter Zijlstra .procname = "lock_stat", 348f20786ffSPeter Zijlstra .data = &lock_stat, 349f20786ffSPeter Zijlstra .maxlen = sizeof(int), 350f20786ffSPeter Zijlstra .mode = 0644, 351f20786ffSPeter Zijlstra .proc_handler = &proc_dointvec, 352f20786ffSPeter Zijlstra }, 353f20786ffSPeter Zijlstra #endif 35477e54a1fSIngo Molnar { 3551da177e4SLinus Torvalds .ctl_name = KERN_PANIC, 3561da177e4SLinus Torvalds .procname = "panic", 3571da177e4SLinus Torvalds .data = &panic_timeout, 3581da177e4SLinus Torvalds .maxlen = sizeof(int), 3591da177e4SLinus Torvalds .mode = 0644, 3601da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 3611da177e4SLinus Torvalds }, 3621da177e4SLinus Torvalds { 3631da177e4SLinus Torvalds .ctl_name = KERN_CORE_USES_PID, 3641da177e4SLinus Torvalds .procname = "core_uses_pid", 3651da177e4SLinus Torvalds .data = &core_uses_pid, 3661da177e4SLinus Torvalds .maxlen = sizeof(int), 3671da177e4SLinus Torvalds .mode = 0644, 3681da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 3691da177e4SLinus Torvalds }, 3701da177e4SLinus Torvalds { 3711da177e4SLinus Torvalds .ctl_name = KERN_CORE_PATTERN, 3721da177e4SLinus Torvalds .procname = "core_pattern", 3731da177e4SLinus Torvalds .data = core_pattern, 37471ce92f3SDan Aloni .maxlen = CORENAME_MAX_SIZE, 3751da177e4SLinus Torvalds .mode = 0644, 3761da177e4SLinus Torvalds .proc_handler = &proc_dostring, 3771da177e4SLinus Torvalds .strategy = &sysctl_string, 3781da177e4SLinus Torvalds }, 37934f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL 3801da177e4SLinus Torvalds { 3811da177e4SLinus Torvalds .procname = "tainted", 3821da177e4SLinus Torvalds .data = &tainted, 3831da177e4SLinus Torvalds .maxlen = sizeof(int), 38434f5a398STheodore Ts'o .mode = 0644, 38534f5a398STheodore Ts'o .proc_handler = &proc_dointvec_taint, 3861da177e4SLinus Torvalds }, 38734f5a398STheodore Ts'o #endif 3889745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 3899745512cSArjan van de Ven { 3909745512cSArjan van de Ven .procname = "latencytop", 3919745512cSArjan van de Ven .data = &latencytop_enabled, 3929745512cSArjan van de Ven .maxlen = sizeof(int), 3939745512cSArjan van de Ven .mode = 0644, 3949745512cSArjan van de Ven .proc_handler = &proc_dointvec, 3959745512cSArjan van de Ven }, 3969745512cSArjan van de Ven #endif 3971da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 3981da177e4SLinus Torvalds { 3991da177e4SLinus Torvalds .ctl_name = KERN_REALROOTDEV, 4001da177e4SLinus Torvalds .procname = "real-root-dev", 4011da177e4SLinus Torvalds .data = &real_root_dev, 4021da177e4SLinus Torvalds .maxlen = sizeof(int), 4031da177e4SLinus Torvalds .mode = 0644, 4041da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4051da177e4SLinus Torvalds }, 4061da177e4SLinus Torvalds #endif 40745807a1dSIngo Molnar { 40845807a1dSIngo Molnar .ctl_name = CTL_UNNUMBERED, 40945807a1dSIngo Molnar .procname = "print-fatal-signals", 41045807a1dSIngo Molnar .data = &print_fatal_signals, 41145807a1dSIngo Molnar .maxlen = sizeof(int), 41245807a1dSIngo Molnar .mode = 0644, 41345807a1dSIngo Molnar .proc_handler = &proc_dointvec, 41445807a1dSIngo Molnar }, 4151da177e4SLinus Torvalds #ifdef __sparc__ 4161da177e4SLinus Torvalds { 4171da177e4SLinus Torvalds .ctl_name = KERN_SPARC_REBOOT, 4181da177e4SLinus Torvalds .procname = "reboot-cmd", 4191da177e4SLinus Torvalds .data = reboot_command, 4201da177e4SLinus Torvalds .maxlen = 256, 4211da177e4SLinus Torvalds .mode = 0644, 4221da177e4SLinus Torvalds .proc_handler = &proc_dostring, 4231da177e4SLinus Torvalds .strategy = &sysctl_string, 4241da177e4SLinus Torvalds }, 4251da177e4SLinus Torvalds { 4261da177e4SLinus Torvalds .ctl_name = KERN_SPARC_STOP_A, 4271da177e4SLinus Torvalds .procname = "stop-a", 4281da177e4SLinus Torvalds .data = &stop_a_enabled, 4291da177e4SLinus Torvalds .maxlen = sizeof (int), 4301da177e4SLinus Torvalds .mode = 0644, 4311da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4321da177e4SLinus Torvalds }, 4331da177e4SLinus Torvalds { 4341da177e4SLinus Torvalds .ctl_name = KERN_SPARC_SCONS_PWROFF, 4351da177e4SLinus Torvalds .procname = "scons-poweroff", 4361da177e4SLinus Torvalds .data = &scons_pwroff, 4371da177e4SLinus Torvalds .maxlen = sizeof (int), 4381da177e4SLinus Torvalds .mode = 0644, 4391da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4401da177e4SLinus Torvalds }, 4411da177e4SLinus Torvalds #endif 4421da177e4SLinus Torvalds #ifdef __hppa__ 4431da177e4SLinus Torvalds { 4441da177e4SLinus Torvalds .ctl_name = KERN_HPPA_PWRSW, 4451da177e4SLinus Torvalds .procname = "soft-power", 4461da177e4SLinus Torvalds .data = &pwrsw_enabled, 4471da177e4SLinus Torvalds .maxlen = sizeof (int), 4481da177e4SLinus Torvalds .mode = 0644, 4491da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4501da177e4SLinus Torvalds }, 4511da177e4SLinus Torvalds { 4521da177e4SLinus Torvalds .ctl_name = KERN_HPPA_UNALIGNED, 4531da177e4SLinus Torvalds .procname = "unaligned-trap", 4541da177e4SLinus Torvalds .data = &unaligned_enabled, 4551da177e4SLinus Torvalds .maxlen = sizeof (int), 4561da177e4SLinus Torvalds .mode = 0644, 4571da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4581da177e4SLinus Torvalds }, 4591da177e4SLinus Torvalds #endif 4601da177e4SLinus Torvalds { 4611da177e4SLinus Torvalds .ctl_name = KERN_CTLALTDEL, 4621da177e4SLinus Torvalds .procname = "ctrl-alt-del", 4631da177e4SLinus Torvalds .data = &C_A_D, 4641da177e4SLinus Torvalds .maxlen = sizeof(int), 4651da177e4SLinus Torvalds .mode = 0644, 4661da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4671da177e4SLinus Torvalds }, 468b0fc494fSSteven Rostedt #ifdef CONFIG_FTRACE 469b0fc494fSSteven Rostedt { 470b0fc494fSSteven Rostedt .ctl_name = CTL_UNNUMBERED, 471b0fc494fSSteven Rostedt .procname = "ftrace_enabled", 472b0fc494fSSteven Rostedt .data = &ftrace_enabled, 473b0fc494fSSteven Rostedt .maxlen = sizeof(int), 474b0fc494fSSteven Rostedt .mode = 0644, 475b0fc494fSSteven Rostedt .proc_handler = &ftrace_enable_sysctl, 476b0fc494fSSteven Rostedt }, 477b0fc494fSSteven Rostedt #endif 478*a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES 4791da177e4SLinus Torvalds { 4801da177e4SLinus Torvalds .ctl_name = KERN_MODPROBE, 4811da177e4SLinus Torvalds .procname = "modprobe", 4821da177e4SLinus Torvalds .data = &modprobe_path, 4831da177e4SLinus Torvalds .maxlen = KMOD_PATH_LEN, 4841da177e4SLinus Torvalds .mode = 0644, 4851da177e4SLinus Torvalds .proc_handler = &proc_dostring, 4861da177e4SLinus Torvalds .strategy = &sysctl_string, 4871da177e4SLinus Torvalds }, 4881da177e4SLinus Torvalds #endif 48957ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) 4901da177e4SLinus Torvalds { 4911da177e4SLinus Torvalds .ctl_name = KERN_HOTPLUG, 4921da177e4SLinus Torvalds .procname = "hotplug", 493312c004dSKay Sievers .data = &uevent_helper, 494312c004dSKay Sievers .maxlen = UEVENT_HELPER_PATH_LEN, 4951da177e4SLinus Torvalds .mode = 0644, 4961da177e4SLinus Torvalds .proc_handler = &proc_dostring, 4971da177e4SLinus Torvalds .strategy = &sysctl_string, 4981da177e4SLinus Torvalds }, 4991da177e4SLinus Torvalds #endif 5001da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG 5011da177e4SLinus Torvalds { 5021da177e4SLinus Torvalds .ctl_name = KERN_SG_BIG_BUFF, 5031da177e4SLinus Torvalds .procname = "sg-big-buff", 5041da177e4SLinus Torvalds .data = &sg_big_buff, 5051da177e4SLinus Torvalds .maxlen = sizeof (int), 5061da177e4SLinus Torvalds .mode = 0444, 5071da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5081da177e4SLinus Torvalds }, 5091da177e4SLinus Torvalds #endif 5101da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT 5111da177e4SLinus Torvalds { 5121da177e4SLinus Torvalds .ctl_name = KERN_ACCT, 5131da177e4SLinus Torvalds .procname = "acct", 5141da177e4SLinus Torvalds .data = &acct_parm, 5151da177e4SLinus Torvalds .maxlen = 3*sizeof(int), 5161da177e4SLinus Torvalds .mode = 0644, 5171da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5181da177e4SLinus Torvalds }, 5191da177e4SLinus Torvalds #endif 5201da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ 5211da177e4SLinus Torvalds { 5221da177e4SLinus Torvalds .ctl_name = KERN_SYSRQ, 5231da177e4SLinus Torvalds .procname = "sysrq", 5245d6f647fSIngo Molnar .data = &__sysrq_enabled, 5251da177e4SLinus Torvalds .maxlen = sizeof (int), 5261da177e4SLinus Torvalds .mode = 0644, 5271da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5281da177e4SLinus Torvalds }, 5291da177e4SLinus Torvalds #endif 530d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 5311da177e4SLinus Torvalds { 5321da177e4SLinus Torvalds .procname = "cad_pid", 5339ec52099SCedric Le Goater .data = NULL, 5341da177e4SLinus Torvalds .maxlen = sizeof (int), 5351da177e4SLinus Torvalds .mode = 0600, 5369ec52099SCedric Le Goater .proc_handler = &proc_do_cad_pid, 5371da177e4SLinus Torvalds }, 538d6f8ff73SRandy Dunlap #endif 5391da177e4SLinus Torvalds { 5401da177e4SLinus Torvalds .ctl_name = KERN_MAX_THREADS, 5411da177e4SLinus Torvalds .procname = "threads-max", 5421da177e4SLinus Torvalds .data = &max_threads, 5431da177e4SLinus Torvalds .maxlen = sizeof(int), 5441da177e4SLinus Torvalds .mode = 0644, 5451da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5461da177e4SLinus Torvalds }, 5471da177e4SLinus Torvalds { 5481da177e4SLinus Torvalds .ctl_name = KERN_RANDOM, 5491da177e4SLinus Torvalds .procname = "random", 5501da177e4SLinus Torvalds .mode = 0555, 5511da177e4SLinus Torvalds .child = random_table, 5521da177e4SLinus Torvalds }, 5531da177e4SLinus Torvalds { 5541da177e4SLinus Torvalds .ctl_name = KERN_OVERFLOWUID, 5551da177e4SLinus Torvalds .procname = "overflowuid", 5561da177e4SLinus Torvalds .data = &overflowuid, 5571da177e4SLinus Torvalds .maxlen = sizeof(int), 5581da177e4SLinus Torvalds .mode = 0644, 5591da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 5601da177e4SLinus Torvalds .strategy = &sysctl_intvec, 5611da177e4SLinus Torvalds .extra1 = &minolduid, 5621da177e4SLinus Torvalds .extra2 = &maxolduid, 5631da177e4SLinus Torvalds }, 5641da177e4SLinus Torvalds { 5651da177e4SLinus Torvalds .ctl_name = KERN_OVERFLOWGID, 5661da177e4SLinus Torvalds .procname = "overflowgid", 5671da177e4SLinus Torvalds .data = &overflowgid, 5681da177e4SLinus Torvalds .maxlen = sizeof(int), 5691da177e4SLinus Torvalds .mode = 0644, 5701da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 5711da177e4SLinus Torvalds .strategy = &sysctl_intvec, 5721da177e4SLinus Torvalds .extra1 = &minolduid, 5731da177e4SLinus Torvalds .extra2 = &maxolduid, 5741da177e4SLinus Torvalds }, 575347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 5761da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 5771da177e4SLinus Torvalds { 5781da177e4SLinus Torvalds .ctl_name = KERN_IEEE_EMULATION_WARNINGS, 5791da177e4SLinus Torvalds .procname = "ieee_emulation_warnings", 5801da177e4SLinus Torvalds .data = &sysctl_ieee_emulation_warnings, 5811da177e4SLinus Torvalds .maxlen = sizeof(int), 5821da177e4SLinus Torvalds .mode = 0644, 5831da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5841da177e4SLinus Torvalds }, 5851da177e4SLinus Torvalds #endif 5861da177e4SLinus Torvalds { 5871da177e4SLinus Torvalds .ctl_name = KERN_S390_USER_DEBUG_LOGGING, 5881da177e4SLinus Torvalds .procname = "userprocess_debug", 5891da177e4SLinus Torvalds .data = &sysctl_userprocess_debug, 5901da177e4SLinus Torvalds .maxlen = sizeof(int), 5911da177e4SLinus Torvalds .mode = 0644, 5921da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5931da177e4SLinus Torvalds }, 5941da177e4SLinus Torvalds #endif 5951da177e4SLinus Torvalds { 5961da177e4SLinus Torvalds .ctl_name = KERN_PIDMAX, 5971da177e4SLinus Torvalds .procname = "pid_max", 5981da177e4SLinus Torvalds .data = &pid_max, 5991da177e4SLinus Torvalds .maxlen = sizeof (int), 6001da177e4SLinus Torvalds .mode = 0644, 6011da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 6021da177e4SLinus Torvalds .strategy = sysctl_intvec, 6031da177e4SLinus Torvalds .extra1 = &pid_max_min, 6041da177e4SLinus Torvalds .extra2 = &pid_max_max, 6051da177e4SLinus Torvalds }, 6061da177e4SLinus Torvalds { 6071da177e4SLinus Torvalds .ctl_name = KERN_PANIC_ON_OOPS, 6081da177e4SLinus Torvalds .procname = "panic_on_oops", 6091da177e4SLinus Torvalds .data = &panic_on_oops, 6101da177e4SLinus Torvalds .maxlen = sizeof(int), 6111da177e4SLinus Torvalds .mode = 0644, 6121da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6131da177e4SLinus Torvalds }, 6147ef3d2fdSJoe Perches #if defined CONFIG_PRINTK 6157ef3d2fdSJoe Perches { 6167ef3d2fdSJoe Perches .ctl_name = KERN_PRINTK, 6177ef3d2fdSJoe Perches .procname = "printk", 6187ef3d2fdSJoe Perches .data = &console_loglevel, 6197ef3d2fdSJoe Perches .maxlen = 4*sizeof(int), 6207ef3d2fdSJoe Perches .mode = 0644, 6217ef3d2fdSJoe Perches .proc_handler = &proc_dointvec, 6227ef3d2fdSJoe Perches }, 6231da177e4SLinus Torvalds { 6241da177e4SLinus Torvalds .ctl_name = KERN_PRINTK_RATELIMIT, 6251da177e4SLinus Torvalds .procname = "printk_ratelimit", 6261da177e4SLinus Torvalds .data = &printk_ratelimit_jiffies, 6271da177e4SLinus Torvalds .maxlen = sizeof(int), 6281da177e4SLinus Torvalds .mode = 0644, 6291da177e4SLinus Torvalds .proc_handler = &proc_dointvec_jiffies, 6301da177e4SLinus Torvalds .strategy = &sysctl_jiffies, 6311da177e4SLinus Torvalds }, 6321da177e4SLinus Torvalds { 6331da177e4SLinus Torvalds .ctl_name = KERN_PRINTK_RATELIMIT_BURST, 6341da177e4SLinus Torvalds .procname = "printk_ratelimit_burst", 6351da177e4SLinus Torvalds .data = &printk_ratelimit_burst, 6361da177e4SLinus Torvalds .maxlen = sizeof(int), 6371da177e4SLinus Torvalds .mode = 0644, 6381da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6391da177e4SLinus Torvalds }, 6407ef3d2fdSJoe Perches #endif 6411da177e4SLinus Torvalds { 6421da177e4SLinus Torvalds .ctl_name = KERN_NGROUPS_MAX, 6431da177e4SLinus Torvalds .procname = "ngroups_max", 6441da177e4SLinus Torvalds .data = &ngroups_max, 6451da177e4SLinus Torvalds .maxlen = sizeof (int), 6461da177e4SLinus Torvalds .mode = 0444, 6471da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6481da177e4SLinus Torvalds }, 6491da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) 6501da177e4SLinus Torvalds { 6511da177e4SLinus Torvalds .ctl_name = KERN_UNKNOWN_NMI_PANIC, 6521da177e4SLinus Torvalds .procname = "unknown_nmi_panic", 6531da177e4SLinus Torvalds .data = &unknown_nmi_panic, 6541da177e4SLinus Torvalds .maxlen = sizeof (int), 6551da177e4SLinus Torvalds .mode = 0644, 6562fbe7b25SDon Zickus .proc_handler = &proc_dointvec, 6571da177e4SLinus Torvalds }, 658407984f1SDon Zickus { 659407984f1SDon Zickus .procname = "nmi_watchdog", 660407984f1SDon Zickus .data = &nmi_watchdog_enabled, 661407984f1SDon Zickus .maxlen = sizeof (int), 662407984f1SDon Zickus .mode = 0644, 663407984f1SDon Zickus .proc_handler = &proc_nmi_enabled, 6641da177e4SLinus Torvalds }, 6651da177e4SLinus Torvalds #endif 6661da177e4SLinus Torvalds #if defined(CONFIG_X86) 6671da177e4SLinus Torvalds { 6688da5addaSDon Zickus .ctl_name = KERN_PANIC_ON_NMI, 6698da5addaSDon Zickus .procname = "panic_on_unrecovered_nmi", 6708da5addaSDon Zickus .data = &panic_on_unrecovered_nmi, 6718da5addaSDon Zickus .maxlen = sizeof(int), 6728da5addaSDon Zickus .mode = 0644, 6738da5addaSDon Zickus .proc_handler = &proc_dointvec, 6748da5addaSDon Zickus }, 6758da5addaSDon Zickus { 6761da177e4SLinus Torvalds .ctl_name = KERN_BOOTLOADER_TYPE, 6771da177e4SLinus Torvalds .procname = "bootloader_type", 6781da177e4SLinus Torvalds .data = &bootloader_type, 6791da177e4SLinus Torvalds .maxlen = sizeof (int), 6801da177e4SLinus Torvalds .mode = 0444, 6811da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6821da177e4SLinus Torvalds }, 6830741f4d2SChuck Ebbert { 6840741f4d2SChuck Ebbert .ctl_name = CTL_UNNUMBERED, 6850741f4d2SChuck Ebbert .procname = "kstack_depth_to_print", 6860741f4d2SChuck Ebbert .data = &kstack_depth_to_print, 6870741f4d2SChuck Ebbert .maxlen = sizeof(int), 6880741f4d2SChuck Ebbert .mode = 0644, 6890741f4d2SChuck Ebbert .proc_handler = &proc_dointvec, 6900741f4d2SChuck Ebbert }, 6916e7c4025SIngo Molnar { 6926e7c4025SIngo Molnar .ctl_name = CTL_UNNUMBERED, 6936e7c4025SIngo Molnar .procname = "io_delay_type", 6946e7c4025SIngo Molnar .data = &io_delay_type, 6956e7c4025SIngo Molnar .maxlen = sizeof(int), 6966e7c4025SIngo Molnar .mode = 0644, 6976e7c4025SIngo Molnar .proc_handler = &proc_dointvec, 6986e7c4025SIngo Molnar }, 6991da177e4SLinus Torvalds #endif 7007a9166e3SLuke Yang #if defined(CONFIG_MMU) 7011da177e4SLinus Torvalds { 7021da177e4SLinus Torvalds .ctl_name = KERN_RANDOMIZE, 7031da177e4SLinus Torvalds .procname = "randomize_va_space", 7041da177e4SLinus Torvalds .data = &randomize_va_space, 7051da177e4SLinus Torvalds .maxlen = sizeof(int), 7061da177e4SLinus Torvalds .mode = 0644, 7071da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 7081da177e4SLinus Torvalds }, 7097a9166e3SLuke Yang #endif 7100152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP) 711951f22d5SMartin Schwidefsky { 712951f22d5SMartin Schwidefsky .ctl_name = KERN_SPIN_RETRY, 713951f22d5SMartin Schwidefsky .procname = "spin_retry", 714951f22d5SMartin Schwidefsky .data = &spin_retry, 715951f22d5SMartin Schwidefsky .maxlen = sizeof (int), 716951f22d5SMartin Schwidefsky .mode = 0644, 717951f22d5SMartin Schwidefsky .proc_handler = &proc_dointvec, 718951f22d5SMartin Schwidefsky }, 719951f22d5SMartin Schwidefsky #endif 720673d5b43SLen Brown #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 721c255d844SPavel Machek { 722c255d844SPavel Machek .procname = "acpi_video_flags", 72377afcf78SPavel Machek .data = &acpi_realmode_flags, 724c255d844SPavel Machek .maxlen = sizeof (unsigned long), 725c255d844SPavel Machek .mode = 0644, 7267f99f06fSStefan Seyfried .proc_handler = &proc_doulongvec_minmax, 727c255d844SPavel Machek }, 728c255d844SPavel Machek #endif 729d2b176edSJes Sorensen #ifdef CONFIG_IA64 730d2b176edSJes Sorensen { 731d2b176edSJes Sorensen .ctl_name = KERN_IA64_UNALIGNED, 732d2b176edSJes Sorensen .procname = "ignore-unaligned-usertrap", 733d2b176edSJes Sorensen .data = &no_unaligned_warning, 734d2b176edSJes Sorensen .maxlen = sizeof (int), 735d2b176edSJes Sorensen .mode = 0644, 736d2b176edSJes Sorensen .proc_handler = &proc_dointvec, 737d2b176edSJes Sorensen }, 738d2b176edSJes Sorensen #endif 739c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_DETECT_SOFTLOCKUP 740c4f3b63fSRavikiran G Thirumalai { 741c4f3b63fSRavikiran G Thirumalai .ctl_name = CTL_UNNUMBERED, 742c4f3b63fSRavikiran G Thirumalai .procname = "softlockup_thresh", 743c4f3b63fSRavikiran G Thirumalai .data = &softlockup_thresh, 74490739081SIngo Molnar .maxlen = sizeof(unsigned long), 745c4f3b63fSRavikiran G Thirumalai .mode = 0644, 74690739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 747c4f3b63fSRavikiran G Thirumalai .strategy = &sysctl_intvec, 748c4f3b63fSRavikiran G Thirumalai .extra1 = &one, 749c4f3b63fSRavikiran G Thirumalai .extra2 = &sixty, 750c4f3b63fSRavikiran G Thirumalai }, 75182a1fcb9SIngo Molnar { 75282a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 75382a1fcb9SIngo Molnar .procname = "hung_task_check_count", 75482a1fcb9SIngo Molnar .data = &sysctl_hung_task_check_count, 75590739081SIngo Molnar .maxlen = sizeof(unsigned long), 75682a1fcb9SIngo Molnar .mode = 0644, 75790739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 75882a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 75982a1fcb9SIngo Molnar }, 76082a1fcb9SIngo Molnar { 76182a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 76282a1fcb9SIngo Molnar .procname = "hung_task_timeout_secs", 76382a1fcb9SIngo Molnar .data = &sysctl_hung_task_timeout_secs, 76490739081SIngo Molnar .maxlen = sizeof(unsigned long), 76582a1fcb9SIngo Molnar .mode = 0644, 76690739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 76782a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 76882a1fcb9SIngo Molnar }, 76982a1fcb9SIngo Molnar { 77082a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 77182a1fcb9SIngo Molnar .procname = "hung_task_warnings", 77282a1fcb9SIngo Molnar .data = &sysctl_hung_task_warnings, 77390739081SIngo Molnar .maxlen = sizeof(unsigned long), 77482a1fcb9SIngo Molnar .mode = 0644, 77590739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 77682a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 77782a1fcb9SIngo Molnar }, 778c4f3b63fSRavikiran G Thirumalai #endif 779bebfa101SAndi Kleen #ifdef CONFIG_COMPAT 780bebfa101SAndi Kleen { 781bebfa101SAndi Kleen .ctl_name = KERN_COMPAT_LOG, 782bebfa101SAndi Kleen .procname = "compat-log", 783bebfa101SAndi Kleen .data = &compat_log, 784bebfa101SAndi Kleen .maxlen = sizeof (int), 785bebfa101SAndi Kleen .mode = 0644, 786bebfa101SAndi Kleen .proc_handler = &proc_dointvec, 787bebfa101SAndi Kleen }, 788bebfa101SAndi Kleen #endif 78923f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 79023f78d4aSIngo Molnar { 79123f78d4aSIngo Molnar .ctl_name = KERN_MAX_LOCK_DEPTH, 79223f78d4aSIngo Molnar .procname = "max_lock_depth", 79323f78d4aSIngo Molnar .data = &max_lock_depth, 79423f78d4aSIngo Molnar .maxlen = sizeof(int), 79523f78d4aSIngo Molnar .mode = 0644, 79623f78d4aSIngo Molnar .proc_handler = &proc_dointvec, 79723f78d4aSIngo Molnar }, 79823f78d4aSIngo Molnar #endif 7995096add8SKees Cook #ifdef CONFIG_PROC_FS 8005096add8SKees Cook { 8015096add8SKees Cook .ctl_name = CTL_UNNUMBERED, 8025096add8SKees Cook .procname = "maps_protect", 8035096add8SKees Cook .data = &maps_protect, 8045096add8SKees Cook .maxlen = sizeof(int), 8055096add8SKees Cook .mode = 0644, 8065096add8SKees Cook .proc_handler = &proc_dointvec, 8075096add8SKees Cook }, 8085096add8SKees Cook #endif 80910a0a8d4SJeremy Fitzhardinge { 81010a0a8d4SJeremy Fitzhardinge .ctl_name = CTL_UNNUMBERED, 81110a0a8d4SJeremy Fitzhardinge .procname = "poweroff_cmd", 81210a0a8d4SJeremy Fitzhardinge .data = &poweroff_cmd, 81310a0a8d4SJeremy Fitzhardinge .maxlen = POWEROFF_CMD_PATH_LEN, 81410a0a8d4SJeremy Fitzhardinge .mode = 0644, 81510a0a8d4SJeremy Fitzhardinge .proc_handler = &proc_dostring, 81610a0a8d4SJeremy Fitzhardinge .strategy = &sysctl_string, 81710a0a8d4SJeremy Fitzhardinge }, 8180b77f5bfSDavid Howells #ifdef CONFIG_KEYS 8190b77f5bfSDavid Howells { 8200b77f5bfSDavid Howells .ctl_name = CTL_UNNUMBERED, 8210b77f5bfSDavid Howells .procname = "keys", 8220b77f5bfSDavid Howells .mode = 0555, 8230b77f5bfSDavid Howells .child = key_sysctls, 8240b77f5bfSDavid Howells }, 8250b77f5bfSDavid Howells #endif 82631a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST 82731a72bceSPaul E. McKenney { 82831a72bceSPaul E. McKenney .ctl_name = CTL_UNNUMBERED, 82931a72bceSPaul E. McKenney .procname = "rcutorture_runnable", 83031a72bceSPaul E. McKenney .data = &rcutorture_runnable, 83131a72bceSPaul E. McKenney .maxlen = sizeof(int), 83231a72bceSPaul E. McKenney .mode = 0644, 83331a72bceSPaul E. McKenney .proc_handler = &proc_dointvec, 83431a72bceSPaul E. McKenney }, 83531a72bceSPaul E. McKenney #endif 836ed2c12f3SAndrew Morton /* 837ed2c12f3SAndrew Morton * NOTE: do not add new entries to this table unless you have read 838ed2c12f3SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 839ed2c12f3SAndrew Morton */ 8401da177e4SLinus Torvalds { .ctl_name = 0 } 8411da177e4SLinus Torvalds }; 8421da177e4SLinus Torvalds 843d8217f07SEric W. Biederman static struct ctl_table vm_table[] = { 8441da177e4SLinus Torvalds { 8451da177e4SLinus Torvalds .ctl_name = VM_OVERCOMMIT_MEMORY, 8461da177e4SLinus Torvalds .procname = "overcommit_memory", 8471da177e4SLinus Torvalds .data = &sysctl_overcommit_memory, 8481da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_memory), 8491da177e4SLinus Torvalds .mode = 0644, 8501da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 8511da177e4SLinus Torvalds }, 8521da177e4SLinus Torvalds { 853fadd8fbdSKAMEZAWA Hiroyuki .ctl_name = VM_PANIC_ON_OOM, 854fadd8fbdSKAMEZAWA Hiroyuki .procname = "panic_on_oom", 855fadd8fbdSKAMEZAWA Hiroyuki .data = &sysctl_panic_on_oom, 856fadd8fbdSKAMEZAWA Hiroyuki .maxlen = sizeof(sysctl_panic_on_oom), 857fadd8fbdSKAMEZAWA Hiroyuki .mode = 0644, 858fadd8fbdSKAMEZAWA Hiroyuki .proc_handler = &proc_dointvec, 859fadd8fbdSKAMEZAWA Hiroyuki }, 860fadd8fbdSKAMEZAWA Hiroyuki { 861fe071d7eSDavid Rientjes .ctl_name = CTL_UNNUMBERED, 862fe071d7eSDavid Rientjes .procname = "oom_kill_allocating_task", 863fe071d7eSDavid Rientjes .data = &sysctl_oom_kill_allocating_task, 864fe071d7eSDavid Rientjes .maxlen = sizeof(sysctl_oom_kill_allocating_task), 865fe071d7eSDavid Rientjes .mode = 0644, 866fe071d7eSDavid Rientjes .proc_handler = &proc_dointvec, 867fe071d7eSDavid Rientjes }, 868fe071d7eSDavid Rientjes { 869fef1bdd6SDavid Rientjes .ctl_name = CTL_UNNUMBERED, 870fef1bdd6SDavid Rientjes .procname = "oom_dump_tasks", 871fef1bdd6SDavid Rientjes .data = &sysctl_oom_dump_tasks, 872fef1bdd6SDavid Rientjes .maxlen = sizeof(sysctl_oom_dump_tasks), 873fef1bdd6SDavid Rientjes .mode = 0644, 874fef1bdd6SDavid Rientjes .proc_handler = &proc_dointvec, 875fef1bdd6SDavid Rientjes }, 876fef1bdd6SDavid Rientjes { 8771da177e4SLinus Torvalds .ctl_name = VM_OVERCOMMIT_RATIO, 8781da177e4SLinus Torvalds .procname = "overcommit_ratio", 8791da177e4SLinus Torvalds .data = &sysctl_overcommit_ratio, 8801da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_ratio), 8811da177e4SLinus Torvalds .mode = 0644, 8821da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 8831da177e4SLinus Torvalds }, 8841da177e4SLinus Torvalds { 8851da177e4SLinus Torvalds .ctl_name = VM_PAGE_CLUSTER, 8861da177e4SLinus Torvalds .procname = "page-cluster", 8871da177e4SLinus Torvalds .data = &page_cluster, 8881da177e4SLinus Torvalds .maxlen = sizeof(int), 8891da177e4SLinus Torvalds .mode = 0644, 8901da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 8911da177e4SLinus Torvalds }, 8921da177e4SLinus Torvalds { 8931da177e4SLinus Torvalds .ctl_name = VM_DIRTY_BACKGROUND, 8941da177e4SLinus Torvalds .procname = "dirty_background_ratio", 8951da177e4SLinus Torvalds .data = &dirty_background_ratio, 8961da177e4SLinus Torvalds .maxlen = sizeof(dirty_background_ratio), 8971da177e4SLinus Torvalds .mode = 0644, 8981da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 8991da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9001da177e4SLinus Torvalds .extra1 = &zero, 9011da177e4SLinus Torvalds .extra2 = &one_hundred, 9021da177e4SLinus Torvalds }, 9031da177e4SLinus Torvalds { 9041da177e4SLinus Torvalds .ctl_name = VM_DIRTY_RATIO, 9051da177e4SLinus Torvalds .procname = "dirty_ratio", 9061da177e4SLinus Torvalds .data = &vm_dirty_ratio, 9071da177e4SLinus Torvalds .maxlen = sizeof(vm_dirty_ratio), 9081da177e4SLinus Torvalds .mode = 0644, 90904fbfdc1SPeter Zijlstra .proc_handler = &dirty_ratio_handler, 9101da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9111da177e4SLinus Torvalds .extra1 = &zero, 9121da177e4SLinus Torvalds .extra2 = &one_hundred, 9131da177e4SLinus Torvalds }, 9141da177e4SLinus Torvalds { 9151da177e4SLinus Torvalds .procname = "dirty_writeback_centisecs", 916f6ef9438SBart Samwel .data = &dirty_writeback_interval, 917f6ef9438SBart Samwel .maxlen = sizeof(dirty_writeback_interval), 9181da177e4SLinus Torvalds .mode = 0644, 9191da177e4SLinus Torvalds .proc_handler = &dirty_writeback_centisecs_handler, 9201da177e4SLinus Torvalds }, 9211da177e4SLinus Torvalds { 9221da177e4SLinus Torvalds .procname = "dirty_expire_centisecs", 923f6ef9438SBart Samwel .data = &dirty_expire_interval, 924f6ef9438SBart Samwel .maxlen = sizeof(dirty_expire_interval), 9251da177e4SLinus Torvalds .mode = 0644, 926f6ef9438SBart Samwel .proc_handler = &proc_dointvec_userhz_jiffies, 9271da177e4SLinus Torvalds }, 9281da177e4SLinus Torvalds { 9291da177e4SLinus Torvalds .ctl_name = VM_NR_PDFLUSH_THREADS, 9301da177e4SLinus Torvalds .procname = "nr_pdflush_threads", 9311da177e4SLinus Torvalds .data = &nr_pdflush_threads, 9321da177e4SLinus Torvalds .maxlen = sizeof nr_pdflush_threads, 9331da177e4SLinus Torvalds .mode = 0444 /* read-only*/, 9341da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 9351da177e4SLinus Torvalds }, 9361da177e4SLinus Torvalds { 9371da177e4SLinus Torvalds .ctl_name = VM_SWAPPINESS, 9381da177e4SLinus Torvalds .procname = "swappiness", 9391da177e4SLinus Torvalds .data = &vm_swappiness, 9401da177e4SLinus Torvalds .maxlen = sizeof(vm_swappiness), 9411da177e4SLinus Torvalds .mode = 0644, 9421da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 9431da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9441da177e4SLinus Torvalds .extra1 = &zero, 9451da177e4SLinus Torvalds .extra2 = &one_hundred, 9461da177e4SLinus Torvalds }, 9471da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE 9481da177e4SLinus Torvalds { 9491da177e4SLinus Torvalds .procname = "nr_hugepages", 9501da177e4SLinus Torvalds .data = &max_huge_pages, 9511da177e4SLinus Torvalds .maxlen = sizeof(unsigned long), 9521da177e4SLinus Torvalds .mode = 0644, 9531da177e4SLinus Torvalds .proc_handler = &hugetlb_sysctl_handler, 9541da177e4SLinus Torvalds .extra1 = (void *)&hugetlb_zero, 9551da177e4SLinus Torvalds .extra2 = (void *)&hugetlb_infinity, 9561da177e4SLinus Torvalds }, 9571da177e4SLinus Torvalds { 9581da177e4SLinus Torvalds .ctl_name = VM_HUGETLB_GROUP, 9591da177e4SLinus Torvalds .procname = "hugetlb_shm_group", 9601da177e4SLinus Torvalds .data = &sysctl_hugetlb_shm_group, 9611da177e4SLinus Torvalds .maxlen = sizeof(gid_t), 9621da177e4SLinus Torvalds .mode = 0644, 9631da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 9641da177e4SLinus Torvalds }, 965396faf03SMel Gorman { 966396faf03SMel Gorman .ctl_name = CTL_UNNUMBERED, 967396faf03SMel Gorman .procname = "hugepages_treat_as_movable", 968396faf03SMel Gorman .data = &hugepages_treat_as_movable, 969396faf03SMel Gorman .maxlen = sizeof(int), 970396faf03SMel Gorman .mode = 0644, 971396faf03SMel Gorman .proc_handler = &hugetlb_treat_movable_handler, 972396faf03SMel Gorman }, 97354f9f80dSAdam Litke { 97454f9f80dSAdam Litke .ctl_name = CTL_UNNUMBERED, 975d1c3fb1fSNishanth Aravamudan .procname = "nr_overcommit_hugepages", 976064d9efeSNishanth Aravamudan .data = &sysctl_overcommit_huge_pages, 977064d9efeSNishanth Aravamudan .maxlen = sizeof(sysctl_overcommit_huge_pages), 978d1c3fb1fSNishanth Aravamudan .mode = 0644, 979a3d0c6aaSNishanth Aravamudan .proc_handler = &hugetlb_overcommit_handler, 980d1c3fb1fSNishanth Aravamudan }, 9811da177e4SLinus Torvalds #endif 9821da177e4SLinus Torvalds { 9831da177e4SLinus Torvalds .ctl_name = VM_LOWMEM_RESERVE_RATIO, 9841da177e4SLinus Torvalds .procname = "lowmem_reserve_ratio", 9851da177e4SLinus Torvalds .data = &sysctl_lowmem_reserve_ratio, 9861da177e4SLinus Torvalds .maxlen = sizeof(sysctl_lowmem_reserve_ratio), 9871da177e4SLinus Torvalds .mode = 0644, 9881da177e4SLinus Torvalds .proc_handler = &lowmem_reserve_ratio_sysctl_handler, 9891da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9901da177e4SLinus Torvalds }, 9911da177e4SLinus Torvalds { 9929d0243bcSAndrew Morton .ctl_name = VM_DROP_PAGECACHE, 9939d0243bcSAndrew Morton .procname = "drop_caches", 9949d0243bcSAndrew Morton .data = &sysctl_drop_caches, 9959d0243bcSAndrew Morton .maxlen = sizeof(int), 9969d0243bcSAndrew Morton .mode = 0644, 9979d0243bcSAndrew Morton .proc_handler = drop_caches_sysctl_handler, 9989d0243bcSAndrew Morton .strategy = &sysctl_intvec, 9999d0243bcSAndrew Morton }, 10009d0243bcSAndrew Morton { 10011da177e4SLinus Torvalds .ctl_name = VM_MIN_FREE_KBYTES, 10021da177e4SLinus Torvalds .procname = "min_free_kbytes", 10031da177e4SLinus Torvalds .data = &min_free_kbytes, 10041da177e4SLinus Torvalds .maxlen = sizeof(min_free_kbytes), 10051da177e4SLinus Torvalds .mode = 0644, 10061da177e4SLinus Torvalds .proc_handler = &min_free_kbytes_sysctl_handler, 10071da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10081da177e4SLinus Torvalds .extra1 = &zero, 10091da177e4SLinus Torvalds }, 10108ad4b1fbSRohit Seth { 10118ad4b1fbSRohit Seth .ctl_name = VM_PERCPU_PAGELIST_FRACTION, 10128ad4b1fbSRohit Seth .procname = "percpu_pagelist_fraction", 10138ad4b1fbSRohit Seth .data = &percpu_pagelist_fraction, 10148ad4b1fbSRohit Seth .maxlen = sizeof(percpu_pagelist_fraction), 10158ad4b1fbSRohit Seth .mode = 0644, 10168ad4b1fbSRohit Seth .proc_handler = &percpu_pagelist_fraction_sysctl_handler, 10178ad4b1fbSRohit Seth .strategy = &sysctl_intvec, 10188ad4b1fbSRohit Seth .extra1 = &min_percpu_pagelist_fract, 10198ad4b1fbSRohit Seth }, 10201da177e4SLinus Torvalds #ifdef CONFIG_MMU 10211da177e4SLinus Torvalds { 10221da177e4SLinus Torvalds .ctl_name = VM_MAX_MAP_COUNT, 10231da177e4SLinus Torvalds .procname = "max_map_count", 10241da177e4SLinus Torvalds .data = &sysctl_max_map_count, 10251da177e4SLinus Torvalds .maxlen = sizeof(sysctl_max_map_count), 10261da177e4SLinus Torvalds .mode = 0644, 10271da177e4SLinus Torvalds .proc_handler = &proc_dointvec 10281da177e4SLinus Torvalds }, 10291da177e4SLinus Torvalds #endif 10301da177e4SLinus Torvalds { 10311da177e4SLinus Torvalds .ctl_name = VM_LAPTOP_MODE, 10321da177e4SLinus Torvalds .procname = "laptop_mode", 10331da177e4SLinus Torvalds .data = &laptop_mode, 10341da177e4SLinus Torvalds .maxlen = sizeof(laptop_mode), 10351da177e4SLinus Torvalds .mode = 0644, 1036ed5b43f1SBart Samwel .proc_handler = &proc_dointvec_jiffies, 1037ed5b43f1SBart Samwel .strategy = &sysctl_jiffies, 10381da177e4SLinus Torvalds }, 10391da177e4SLinus Torvalds { 10401da177e4SLinus Torvalds .ctl_name = VM_BLOCK_DUMP, 10411da177e4SLinus Torvalds .procname = "block_dump", 10421da177e4SLinus Torvalds .data = &block_dump, 10431da177e4SLinus Torvalds .maxlen = sizeof(block_dump), 10441da177e4SLinus Torvalds .mode = 0644, 10451da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10461da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10471da177e4SLinus Torvalds .extra1 = &zero, 10481da177e4SLinus Torvalds }, 10491da177e4SLinus Torvalds { 10501da177e4SLinus Torvalds .ctl_name = VM_VFS_CACHE_PRESSURE, 10511da177e4SLinus Torvalds .procname = "vfs_cache_pressure", 10521da177e4SLinus Torvalds .data = &sysctl_vfs_cache_pressure, 10531da177e4SLinus Torvalds .maxlen = sizeof(sysctl_vfs_cache_pressure), 10541da177e4SLinus Torvalds .mode = 0644, 10551da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10561da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10571da177e4SLinus Torvalds .extra1 = &zero, 10581da177e4SLinus Torvalds }, 10591da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 10601da177e4SLinus Torvalds { 10611da177e4SLinus Torvalds .ctl_name = VM_LEGACY_VA_LAYOUT, 10621da177e4SLinus Torvalds .procname = "legacy_va_layout", 10631da177e4SLinus Torvalds .data = &sysctl_legacy_va_layout, 10641da177e4SLinus Torvalds .maxlen = sizeof(sysctl_legacy_va_layout), 10651da177e4SLinus Torvalds .mode = 0644, 10661da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10671da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10681da177e4SLinus Torvalds .extra1 = &zero, 10691da177e4SLinus Torvalds }, 10701da177e4SLinus Torvalds #endif 10711743660bSChristoph Lameter #ifdef CONFIG_NUMA 10721743660bSChristoph Lameter { 10731743660bSChristoph Lameter .ctl_name = VM_ZONE_RECLAIM_MODE, 10741743660bSChristoph Lameter .procname = "zone_reclaim_mode", 10751743660bSChristoph Lameter .data = &zone_reclaim_mode, 10761743660bSChristoph Lameter .maxlen = sizeof(zone_reclaim_mode), 10771743660bSChristoph Lameter .mode = 0644, 10781743660bSChristoph Lameter .proc_handler = &proc_dointvec, 1079c84db23cSChristoph Lameter .strategy = &sysctl_intvec, 1080c84db23cSChristoph Lameter .extra1 = &zero, 10811743660bSChristoph Lameter }, 10829614634fSChristoph Lameter { 10839614634fSChristoph Lameter .ctl_name = VM_MIN_UNMAPPED, 10849614634fSChristoph Lameter .procname = "min_unmapped_ratio", 10859614634fSChristoph Lameter .data = &sysctl_min_unmapped_ratio, 10869614634fSChristoph Lameter .maxlen = sizeof(sysctl_min_unmapped_ratio), 10879614634fSChristoph Lameter .mode = 0644, 10889614634fSChristoph Lameter .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler, 10899614634fSChristoph Lameter .strategy = &sysctl_intvec, 10909614634fSChristoph Lameter .extra1 = &zero, 10919614634fSChristoph Lameter .extra2 = &one_hundred, 10929614634fSChristoph Lameter }, 10930ff38490SChristoph Lameter { 10940ff38490SChristoph Lameter .ctl_name = VM_MIN_SLAB, 10950ff38490SChristoph Lameter .procname = "min_slab_ratio", 10960ff38490SChristoph Lameter .data = &sysctl_min_slab_ratio, 10970ff38490SChristoph Lameter .maxlen = sizeof(sysctl_min_slab_ratio), 10980ff38490SChristoph Lameter .mode = 0644, 10990ff38490SChristoph Lameter .proc_handler = &sysctl_min_slab_ratio_sysctl_handler, 11000ff38490SChristoph Lameter .strategy = &sysctl_intvec, 11010ff38490SChristoph Lameter .extra1 = &zero, 11020ff38490SChristoph Lameter .extra2 = &one_hundred, 11030ff38490SChristoph Lameter }, 11041743660bSChristoph Lameter #endif 110577461ab3SChristoph Lameter #ifdef CONFIG_SMP 110677461ab3SChristoph Lameter { 110777461ab3SChristoph Lameter .ctl_name = CTL_UNNUMBERED, 110877461ab3SChristoph Lameter .procname = "stat_interval", 110977461ab3SChristoph Lameter .data = &sysctl_stat_interval, 111077461ab3SChristoph Lameter .maxlen = sizeof(sysctl_stat_interval), 111177461ab3SChristoph Lameter .mode = 0644, 111277461ab3SChristoph Lameter .proc_handler = &proc_dointvec_jiffies, 111377461ab3SChristoph Lameter .strategy = &sysctl_jiffies, 111477461ab3SChristoph Lameter }, 111577461ab3SChristoph Lameter #endif 1116ed032189SEric Paris #ifdef CONFIG_SECURITY 1117ed032189SEric Paris { 1118ed032189SEric Paris .ctl_name = CTL_UNNUMBERED, 1119ed032189SEric Paris .procname = "mmap_min_addr", 1120ed032189SEric Paris .data = &mmap_min_addr, 1121ed032189SEric Paris .maxlen = sizeof(unsigned long), 1122ed032189SEric Paris .mode = 0644, 1123ed032189SEric Paris .proc_handler = &proc_doulongvec_minmax, 1124ed032189SEric Paris }, 11258daec965SLee Schermerhorn #endif 1126f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA 1127f0c0b2b8SKAMEZAWA Hiroyuki { 1128f0c0b2b8SKAMEZAWA Hiroyuki .ctl_name = CTL_UNNUMBERED, 1129f0c0b2b8SKAMEZAWA Hiroyuki .procname = "numa_zonelist_order", 1130f0c0b2b8SKAMEZAWA Hiroyuki .data = &numa_zonelist_order, 1131f0c0b2b8SKAMEZAWA Hiroyuki .maxlen = NUMA_ZONELIST_ORDER_LEN, 1132f0c0b2b8SKAMEZAWA Hiroyuki .mode = 0644, 1133f0c0b2b8SKAMEZAWA Hiroyuki .proc_handler = &numa_zonelist_order_handler, 1134f0c0b2b8SKAMEZAWA Hiroyuki .strategy = &sysctl_string, 1135f0c0b2b8SKAMEZAWA Hiroyuki }, 1136f0c0b2b8SKAMEZAWA Hiroyuki #endif 11372b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 11385c36e657SPaul Mundt (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 1139e6e5494cSIngo Molnar { 1140e6e5494cSIngo Molnar .ctl_name = VM_VDSO_ENABLED, 1141e6e5494cSIngo Molnar .procname = "vdso_enabled", 1142e6e5494cSIngo Molnar .data = &vdso_enabled, 1143e6e5494cSIngo Molnar .maxlen = sizeof(vdso_enabled), 1144e6e5494cSIngo Molnar .mode = 0644, 1145e6e5494cSIngo Molnar .proc_handler = &proc_dointvec, 1146e6e5494cSIngo Molnar .strategy = &sysctl_intvec, 1147e6e5494cSIngo Molnar .extra1 = &zero, 1148e6e5494cSIngo Molnar }, 1149e6e5494cSIngo Molnar #endif 1150195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM 1151195cf453SBron Gondwana { 1152195cf453SBron Gondwana .ctl_name = CTL_UNNUMBERED, 1153195cf453SBron Gondwana .procname = "highmem_is_dirtyable", 1154195cf453SBron Gondwana .data = &vm_highmem_is_dirtyable, 1155195cf453SBron Gondwana .maxlen = sizeof(vm_highmem_is_dirtyable), 1156195cf453SBron Gondwana .mode = 0644, 1157195cf453SBron Gondwana .proc_handler = &proc_dointvec_minmax, 1158195cf453SBron Gondwana .strategy = &sysctl_intvec, 1159195cf453SBron Gondwana .extra1 = &zero, 1160195cf453SBron Gondwana .extra2 = &one, 1161195cf453SBron Gondwana }, 1162195cf453SBron Gondwana #endif 11632be7fe07SAndrew Morton /* 11642be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 11652be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 11662be7fe07SAndrew Morton */ 11671da177e4SLinus Torvalds { .ctl_name = 0 } 11681da177e4SLinus Torvalds }; 11691da177e4SLinus Torvalds 11702abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1171d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = { 11722abc26fcSEric W. Biederman { .ctl_name = 0 } 11732abc26fcSEric W. Biederman }; 11742abc26fcSEric W. Biederman #endif 11752abc26fcSEric W. Biederman 1176d8217f07SEric W. Biederman static struct ctl_table fs_table[] = { 11771da177e4SLinus Torvalds { 11781da177e4SLinus Torvalds .ctl_name = FS_NRINODE, 11791da177e4SLinus Torvalds .procname = "inode-nr", 11801da177e4SLinus Torvalds .data = &inodes_stat, 11811da177e4SLinus Torvalds .maxlen = 2*sizeof(int), 11821da177e4SLinus Torvalds .mode = 0444, 11831da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 11841da177e4SLinus Torvalds }, 11851da177e4SLinus Torvalds { 11861da177e4SLinus Torvalds .ctl_name = FS_STATINODE, 11871da177e4SLinus Torvalds .procname = "inode-state", 11881da177e4SLinus Torvalds .data = &inodes_stat, 11891da177e4SLinus Torvalds .maxlen = 7*sizeof(int), 11901da177e4SLinus Torvalds .mode = 0444, 11911da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 11921da177e4SLinus Torvalds }, 11931da177e4SLinus Torvalds { 11941da177e4SLinus Torvalds .procname = "file-nr", 11951da177e4SLinus Torvalds .data = &files_stat, 11961da177e4SLinus Torvalds .maxlen = 3*sizeof(int), 11971da177e4SLinus Torvalds .mode = 0444, 1198529bf6beSDipankar Sarma .proc_handler = &proc_nr_files, 11991da177e4SLinus Torvalds }, 12001da177e4SLinus Torvalds { 12011da177e4SLinus Torvalds .ctl_name = FS_MAXFILE, 12021da177e4SLinus Torvalds .procname = "file-max", 12031da177e4SLinus Torvalds .data = &files_stat.max_files, 12041da177e4SLinus Torvalds .maxlen = sizeof(int), 12051da177e4SLinus Torvalds .mode = 0644, 12061da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12071da177e4SLinus Torvalds }, 12081da177e4SLinus Torvalds { 12099cfe015aSEric Dumazet .ctl_name = CTL_UNNUMBERED, 12109cfe015aSEric Dumazet .procname = "nr_open", 12119cfe015aSEric Dumazet .data = &sysctl_nr_open, 12129cfe015aSEric Dumazet .maxlen = sizeof(int), 12139cfe015aSEric Dumazet .mode = 0644, 1214eceea0b3SAl Viro .proc_handler = &proc_dointvec_minmax, 1215eceea0b3SAl Viro .extra1 = &sysctl_nr_open_min, 1216eceea0b3SAl Viro .extra2 = &sysctl_nr_open_max, 12179cfe015aSEric Dumazet }, 12189cfe015aSEric Dumazet { 12191da177e4SLinus Torvalds .ctl_name = FS_DENTRY, 12201da177e4SLinus Torvalds .procname = "dentry-state", 12211da177e4SLinus Torvalds .data = &dentry_stat, 12221da177e4SLinus Torvalds .maxlen = 6*sizeof(int), 12231da177e4SLinus Torvalds .mode = 0444, 12241da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12251da177e4SLinus Torvalds }, 12261da177e4SLinus Torvalds { 12271da177e4SLinus Torvalds .ctl_name = FS_OVERFLOWUID, 12281da177e4SLinus Torvalds .procname = "overflowuid", 12291da177e4SLinus Torvalds .data = &fs_overflowuid, 12301da177e4SLinus Torvalds .maxlen = sizeof(int), 12311da177e4SLinus Torvalds .mode = 0644, 12321da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 12331da177e4SLinus Torvalds .strategy = &sysctl_intvec, 12341da177e4SLinus Torvalds .extra1 = &minolduid, 12351da177e4SLinus Torvalds .extra2 = &maxolduid, 12361da177e4SLinus Torvalds }, 12371da177e4SLinus Torvalds { 12381da177e4SLinus Torvalds .ctl_name = FS_OVERFLOWGID, 12391da177e4SLinus Torvalds .procname = "overflowgid", 12401da177e4SLinus Torvalds .data = &fs_overflowgid, 12411da177e4SLinus Torvalds .maxlen = sizeof(int), 12421da177e4SLinus Torvalds .mode = 0644, 12431da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 12441da177e4SLinus Torvalds .strategy = &sysctl_intvec, 12451da177e4SLinus Torvalds .extra1 = &minolduid, 12461da177e4SLinus Torvalds .extra2 = &maxolduid, 12471da177e4SLinus Torvalds }, 12481da177e4SLinus Torvalds { 12491da177e4SLinus Torvalds .ctl_name = FS_LEASES, 12501da177e4SLinus Torvalds .procname = "leases-enable", 12511da177e4SLinus Torvalds .data = &leases_enable, 12521da177e4SLinus Torvalds .maxlen = sizeof(int), 12531da177e4SLinus Torvalds .mode = 0644, 12541da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12551da177e4SLinus Torvalds }, 12561da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY 12571da177e4SLinus Torvalds { 12581da177e4SLinus Torvalds .ctl_name = FS_DIR_NOTIFY, 12591da177e4SLinus Torvalds .procname = "dir-notify-enable", 12601da177e4SLinus Torvalds .data = &dir_notify_enable, 12611da177e4SLinus Torvalds .maxlen = sizeof(int), 12621da177e4SLinus Torvalds .mode = 0644, 12631da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12641da177e4SLinus Torvalds }, 12651da177e4SLinus Torvalds #endif 12661da177e4SLinus Torvalds #ifdef CONFIG_MMU 12671da177e4SLinus Torvalds { 12681da177e4SLinus Torvalds .ctl_name = FS_LEASE_TIME, 12691da177e4SLinus Torvalds .procname = "lease-break-time", 12701da177e4SLinus Torvalds .data = &lease_break_time, 12711da177e4SLinus Torvalds .maxlen = sizeof(int), 12721da177e4SLinus Torvalds .mode = 0644, 127376fdbb25SKawai, Hidehiro .proc_handler = &proc_dointvec_minmax, 127476fdbb25SKawai, Hidehiro .strategy = &sysctl_intvec, 127576fdbb25SKawai, Hidehiro .extra1 = &zero, 127676fdbb25SKawai, Hidehiro .extra2 = &two, 12771da177e4SLinus Torvalds }, 12781da177e4SLinus Torvalds { 12791da177e4SLinus Torvalds .procname = "aio-nr", 12801da177e4SLinus Torvalds .data = &aio_nr, 12811da177e4SLinus Torvalds .maxlen = sizeof(aio_nr), 12821da177e4SLinus Torvalds .mode = 0444, 1283d55b5fdaSZach Brown .proc_handler = &proc_doulongvec_minmax, 12841da177e4SLinus Torvalds }, 12851da177e4SLinus Torvalds { 12861da177e4SLinus Torvalds .procname = "aio-max-nr", 12871da177e4SLinus Torvalds .data = &aio_max_nr, 12881da177e4SLinus Torvalds .maxlen = sizeof(aio_max_nr), 12891da177e4SLinus Torvalds .mode = 0644, 1290d55b5fdaSZach Brown .proc_handler = &proc_doulongvec_minmax, 12911da177e4SLinus Torvalds }, 12922d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 12930399cb08SRobert Love { 12940399cb08SRobert Love .ctl_name = FS_INOTIFY, 12950399cb08SRobert Love .procname = "inotify", 12960399cb08SRobert Love .mode = 0555, 12970399cb08SRobert Love .child = inotify_table, 12980399cb08SRobert Love }, 12990399cb08SRobert Love #endif 13001da177e4SLinus Torvalds #endif 1301d6e71144SAlan Cox { 1302d6e71144SAlan Cox .ctl_name = KERN_SETUID_DUMPABLE, 1303d6e71144SAlan Cox .procname = "suid_dumpable", 1304d6e71144SAlan Cox .data = &suid_dumpable, 1305d6e71144SAlan Cox .maxlen = sizeof(int), 1306d6e71144SAlan Cox .mode = 0644, 1307d6e71144SAlan Cox .proc_handler = &proc_dointvec, 1308d6e71144SAlan Cox }, 13092abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 13102abc26fcSEric W. Biederman { 13112abc26fcSEric W. Biederman .ctl_name = CTL_UNNUMBERED, 13122abc26fcSEric W. Biederman .procname = "binfmt_misc", 13132abc26fcSEric W. Biederman .mode = 0555, 13142abc26fcSEric W. Biederman .child = binfmt_misc_table, 13152abc26fcSEric W. Biederman }, 13162abc26fcSEric W. Biederman #endif 13172be7fe07SAndrew Morton /* 13182be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 13192be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 13202be7fe07SAndrew Morton */ 13211da177e4SLinus Torvalds { .ctl_name = 0 } 13221da177e4SLinus Torvalds }; 13231da177e4SLinus Torvalds 1324d8217f07SEric W. Biederman static struct ctl_table debug_table[] = { 1325d0c3d534SOlof Johansson #if defined(CONFIG_X86) || defined(CONFIG_PPC) 1326abd4f750SMasoud Asgharifard Sharbiani { 1327abd4f750SMasoud Asgharifard Sharbiani .ctl_name = CTL_UNNUMBERED, 1328abd4f750SMasoud Asgharifard Sharbiani .procname = "exception-trace", 1329abd4f750SMasoud Asgharifard Sharbiani .data = &show_unhandled_signals, 1330abd4f750SMasoud Asgharifard Sharbiani .maxlen = sizeof(int), 1331abd4f750SMasoud Asgharifard Sharbiani .mode = 0644, 1332abd4f750SMasoud Asgharifard Sharbiani .proc_handler = proc_dointvec 1333abd4f750SMasoud Asgharifard Sharbiani }, 1334abd4f750SMasoud Asgharifard Sharbiani #endif 13351da177e4SLinus Torvalds { .ctl_name = 0 } 13361da177e4SLinus Torvalds }; 13371da177e4SLinus Torvalds 1338d8217f07SEric W. Biederman static struct ctl_table dev_table[] = { 13391da177e4SLinus Torvalds { .ctl_name = 0 } 13401da177e4SLinus Torvalds }; 13411da177e4SLinus Torvalds 1342330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock); 1343330d57fbSAl Viro 1344330d57fbSAl Viro /* called under sysctl_lock */ 1345330d57fbSAl Viro static int use_table(struct ctl_table_header *p) 1346330d57fbSAl Viro { 1347330d57fbSAl Viro if (unlikely(p->unregistering)) 1348330d57fbSAl Viro return 0; 1349330d57fbSAl Viro p->used++; 1350330d57fbSAl Viro return 1; 1351330d57fbSAl Viro } 1352330d57fbSAl Viro 1353330d57fbSAl Viro /* called under sysctl_lock */ 1354330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p) 1355330d57fbSAl Viro { 1356330d57fbSAl Viro if (!--p->used) 1357330d57fbSAl Viro if (unlikely(p->unregistering)) 1358330d57fbSAl Viro complete(p->unregistering); 1359330d57fbSAl Viro } 1360330d57fbSAl Viro 1361330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */ 1362330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p) 1363330d57fbSAl Viro { 1364330d57fbSAl Viro /* 1365330d57fbSAl Viro * if p->used is 0, nobody will ever touch that entry again; 1366330d57fbSAl Viro * we'll eliminate all paths to it before dropping sysctl_lock 1367330d57fbSAl Viro */ 1368330d57fbSAl Viro if (unlikely(p->used)) { 1369330d57fbSAl Viro struct completion wait; 1370330d57fbSAl Viro init_completion(&wait); 1371330d57fbSAl Viro p->unregistering = &wait; 1372330d57fbSAl Viro spin_unlock(&sysctl_lock); 1373330d57fbSAl Viro wait_for_completion(&wait); 1374330d57fbSAl Viro spin_lock(&sysctl_lock); 1375330d57fbSAl Viro } 1376330d57fbSAl Viro /* 1377330d57fbSAl Viro * do not remove from the list until nobody holds it; walking the 1378330d57fbSAl Viro * list in do_sysctl() relies on that. 1379330d57fbSAl Viro */ 1380330d57fbSAl Viro list_del_init(&p->ctl_entry); 1381330d57fbSAl Viro } 1382330d57fbSAl Viro 1383805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head) 1384805b5d5eSEric W. Biederman { 1385805b5d5eSEric W. Biederman if (!head) 1386805b5d5eSEric W. Biederman return; 1387805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1388805b5d5eSEric W. Biederman unuse_table(head); 1389805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1390805b5d5eSEric W. Biederman } 1391805b5d5eSEric W. Biederman 1392e51b6ba0SEric W. Biederman static struct list_head * 1393e51b6ba0SEric W. Biederman lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) 1394805b5d5eSEric W. Biederman { 1395e51b6ba0SEric W. Biederman struct list_head *header_list; 1396e51b6ba0SEric W. Biederman header_list = &root->header_list; 1397e51b6ba0SEric W. Biederman if (root->lookup) 1398e51b6ba0SEric W. Biederman header_list = root->lookup(root, namespaces); 1399e51b6ba0SEric W. Biederman return header_list; 1400e51b6ba0SEric W. Biederman } 1401e51b6ba0SEric W. Biederman 1402e51b6ba0SEric W. Biederman struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, 1403e51b6ba0SEric W. Biederman struct ctl_table_header *prev) 1404e51b6ba0SEric W. Biederman { 1405e51b6ba0SEric W. Biederman struct ctl_table_root *root; 1406e51b6ba0SEric W. Biederman struct list_head *header_list; 1407805b5d5eSEric W. Biederman struct ctl_table_header *head; 1408805b5d5eSEric W. Biederman struct list_head *tmp; 1409e51b6ba0SEric W. Biederman 1410805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1411805b5d5eSEric W. Biederman if (prev) { 1412e51b6ba0SEric W. Biederman head = prev; 1413805b5d5eSEric W. Biederman tmp = &prev->ctl_entry; 1414805b5d5eSEric W. Biederman unuse_table(prev); 1415805b5d5eSEric W. Biederman goto next; 1416805b5d5eSEric W. Biederman } 1417805b5d5eSEric W. Biederman tmp = &root_table_header.ctl_entry; 1418805b5d5eSEric W. Biederman for (;;) { 1419805b5d5eSEric W. Biederman head = list_entry(tmp, struct ctl_table_header, ctl_entry); 1420805b5d5eSEric W. Biederman 1421805b5d5eSEric W. Biederman if (!use_table(head)) 1422805b5d5eSEric W. Biederman goto next; 1423805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1424805b5d5eSEric W. Biederman return head; 1425805b5d5eSEric W. Biederman next: 1426e51b6ba0SEric W. Biederman root = head->root; 1427805b5d5eSEric W. Biederman tmp = tmp->next; 1428e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1429e51b6ba0SEric W. Biederman if (tmp != header_list) 1430e51b6ba0SEric W. Biederman continue; 1431e51b6ba0SEric W. Biederman 1432e51b6ba0SEric W. Biederman do { 1433e51b6ba0SEric W. Biederman root = list_entry(root->root_list.next, 1434e51b6ba0SEric W. Biederman struct ctl_table_root, root_list); 1435e51b6ba0SEric W. Biederman if (root == &sysctl_table_root) 1436e51b6ba0SEric W. Biederman goto out; 1437e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1438e51b6ba0SEric W. Biederman } while (list_empty(header_list)); 1439e51b6ba0SEric W. Biederman tmp = header_list->next; 1440805b5d5eSEric W. Biederman } 1441e51b6ba0SEric W. Biederman out: 1442805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1443805b5d5eSEric W. Biederman return NULL; 1444805b5d5eSEric W. Biederman } 1445805b5d5eSEric W. Biederman 1446e51b6ba0SEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) 1447e51b6ba0SEric W. Biederman { 1448e51b6ba0SEric W. Biederman return __sysctl_head_next(current->nsproxy, prev); 1449e51b6ba0SEric W. Biederman } 1450e51b6ba0SEric W. Biederman 1451e51b6ba0SEric W. Biederman void register_sysctl_root(struct ctl_table_root *root) 1452e51b6ba0SEric W. Biederman { 1453e51b6ba0SEric W. Biederman spin_lock(&sysctl_lock); 1454e51b6ba0SEric W. Biederman list_add_tail(&root->root_list, &sysctl_table_root.root_list); 1455e51b6ba0SEric W. Biederman spin_unlock(&sysctl_lock); 1456e51b6ba0SEric W. Biederman } 1457e51b6ba0SEric W. Biederman 1458b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 14592c4c7155SPavel Emelyanov /* Perform the actual read/write of a sysctl table entry. */ 1460d7321cd6SPavel Emelyanov static int do_sysctl_strategy(struct ctl_table_root *root, 1461d7321cd6SPavel Emelyanov struct ctl_table *table, 14622c4c7155SPavel Emelyanov int __user *name, int nlen, 14632c4c7155SPavel Emelyanov void __user *oldval, size_t __user *oldlenp, 14642c4c7155SPavel Emelyanov void __user *newval, size_t newlen) 14652c4c7155SPavel Emelyanov { 14662c4c7155SPavel Emelyanov int op = 0, rc; 14672c4c7155SPavel Emelyanov 14682c4c7155SPavel Emelyanov if (oldval) 14692c4c7155SPavel Emelyanov op |= 004; 14702c4c7155SPavel Emelyanov if (newval) 14712c4c7155SPavel Emelyanov op |= 002; 1472d7321cd6SPavel Emelyanov if (sysctl_perm(root, table, op)) 14732c4c7155SPavel Emelyanov return -EPERM; 14742c4c7155SPavel Emelyanov 14752c4c7155SPavel Emelyanov if (table->strategy) { 14762c4c7155SPavel Emelyanov rc = table->strategy(table, name, nlen, oldval, oldlenp, 14772c4c7155SPavel Emelyanov newval, newlen); 14782c4c7155SPavel Emelyanov if (rc < 0) 14792c4c7155SPavel Emelyanov return rc; 14802c4c7155SPavel Emelyanov if (rc > 0) 14812c4c7155SPavel Emelyanov return 0; 14822c4c7155SPavel Emelyanov } 14832c4c7155SPavel Emelyanov 14842c4c7155SPavel Emelyanov /* If there is no strategy routine, or if the strategy returns 14852c4c7155SPavel Emelyanov * zero, proceed with automatic r/w */ 14862c4c7155SPavel Emelyanov if (table->data && table->maxlen) { 14872c4c7155SPavel Emelyanov rc = sysctl_data(table, name, nlen, oldval, oldlenp, 14882c4c7155SPavel Emelyanov newval, newlen); 14892c4c7155SPavel Emelyanov if (rc < 0) 14902c4c7155SPavel Emelyanov return rc; 14912c4c7155SPavel Emelyanov } 14922c4c7155SPavel Emelyanov return 0; 14932c4c7155SPavel Emelyanov } 14942c4c7155SPavel Emelyanov 14952c4c7155SPavel Emelyanov static int parse_table(int __user *name, int nlen, 14962c4c7155SPavel Emelyanov void __user *oldval, size_t __user *oldlenp, 14972c4c7155SPavel Emelyanov void __user *newval, size_t newlen, 1498d7321cd6SPavel Emelyanov struct ctl_table_root *root, 14992c4c7155SPavel Emelyanov struct ctl_table *table) 15002c4c7155SPavel Emelyanov { 15012c4c7155SPavel Emelyanov int n; 15022c4c7155SPavel Emelyanov repeat: 15032c4c7155SPavel Emelyanov if (!nlen) 15042c4c7155SPavel Emelyanov return -ENOTDIR; 15052c4c7155SPavel Emelyanov if (get_user(n, name)) 15062c4c7155SPavel Emelyanov return -EFAULT; 15072c4c7155SPavel Emelyanov for ( ; table->ctl_name || table->procname; table++) { 15082c4c7155SPavel Emelyanov if (!table->ctl_name) 15092c4c7155SPavel Emelyanov continue; 15102c4c7155SPavel Emelyanov if (n == table->ctl_name) { 15112c4c7155SPavel Emelyanov int error; 15122c4c7155SPavel Emelyanov if (table->child) { 1513d7321cd6SPavel Emelyanov if (sysctl_perm(root, table, 001)) 15142c4c7155SPavel Emelyanov return -EPERM; 15152c4c7155SPavel Emelyanov name++; 15162c4c7155SPavel Emelyanov nlen--; 15172c4c7155SPavel Emelyanov table = table->child; 15182c4c7155SPavel Emelyanov goto repeat; 15192c4c7155SPavel Emelyanov } 1520d7321cd6SPavel Emelyanov error = do_sysctl_strategy(root, table, name, nlen, 15212c4c7155SPavel Emelyanov oldval, oldlenp, 15222c4c7155SPavel Emelyanov newval, newlen); 15232c4c7155SPavel Emelyanov return error; 15242c4c7155SPavel Emelyanov } 15252c4c7155SPavel Emelyanov } 15262c4c7155SPavel Emelyanov return -ENOTDIR; 15272c4c7155SPavel Emelyanov } 15282c4c7155SPavel Emelyanov 15291da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, 15301da177e4SLinus Torvalds void __user *newval, size_t newlen) 15311da177e4SLinus Torvalds { 1532805b5d5eSEric W. Biederman struct ctl_table_header *head; 1533330d57fbSAl Viro int error = -ENOTDIR; 15341da177e4SLinus Torvalds 15351da177e4SLinus Torvalds if (nlen <= 0 || nlen >= CTL_MAXNAME) 15361da177e4SLinus Torvalds return -ENOTDIR; 15371da177e4SLinus Torvalds if (oldval) { 15381da177e4SLinus Torvalds int old_len; 15391da177e4SLinus Torvalds if (!oldlenp || get_user(old_len, oldlenp)) 15401da177e4SLinus Torvalds return -EFAULT; 15411da177e4SLinus Torvalds } 1542330d57fbSAl Viro 1543805b5d5eSEric W. Biederman for (head = sysctl_head_next(NULL); head; 1544805b5d5eSEric W. Biederman head = sysctl_head_next(head)) { 1545330d57fbSAl Viro error = parse_table(name, nlen, oldval, oldlenp, 1546d7321cd6SPavel Emelyanov newval, newlen, 1547d7321cd6SPavel Emelyanov head->root, head->ctl_table); 1548805b5d5eSEric W. Biederman if (error != -ENOTDIR) { 1549805b5d5eSEric W. Biederman sysctl_head_finish(head); 1550330d57fbSAl Viro break; 1551805b5d5eSEric W. Biederman } 1552805b5d5eSEric W. Biederman } 15531da177e4SLinus Torvalds return error; 15541da177e4SLinus Torvalds } 15551da177e4SLinus Torvalds 15561da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args) 15571da177e4SLinus Torvalds { 15581da177e4SLinus Torvalds struct __sysctl_args tmp; 15591da177e4SLinus Torvalds int error; 15601da177e4SLinus Torvalds 15611da177e4SLinus Torvalds if (copy_from_user(&tmp, args, sizeof(tmp))) 15621da177e4SLinus Torvalds return -EFAULT; 15631da177e4SLinus Torvalds 15647058cb02SEric W. Biederman error = deprecated_sysctl_warning(&tmp); 15657058cb02SEric W. Biederman if (error) 15667058cb02SEric W. Biederman goto out; 15677058cb02SEric W. Biederman 15681da177e4SLinus Torvalds lock_kernel(); 15691da177e4SLinus Torvalds error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp, 15701da177e4SLinus Torvalds tmp.newval, tmp.newlen); 15711da177e4SLinus Torvalds unlock_kernel(); 15727058cb02SEric W. Biederman out: 15731da177e4SLinus Torvalds return error; 15741da177e4SLinus Torvalds } 1575b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */ 15761da177e4SLinus Torvalds 15771da177e4SLinus Torvalds /* 15781ff007ebSEric W. Biederman * sysctl_perm does NOT grant the superuser all rights automatically, because 15791da177e4SLinus Torvalds * some sysctl variables are readonly even to root. 15801da177e4SLinus Torvalds */ 15811da177e4SLinus Torvalds 15821da177e4SLinus Torvalds static int test_perm(int mode, int op) 15831da177e4SLinus Torvalds { 15841da177e4SLinus Torvalds if (!current->euid) 15851da177e4SLinus Torvalds mode >>= 6; 15861da177e4SLinus Torvalds else if (in_egroup_p(0)) 15871da177e4SLinus Torvalds mode >>= 3; 15881da177e4SLinus Torvalds if ((mode & op & 0007) == op) 15891da177e4SLinus Torvalds return 0; 15901da177e4SLinus Torvalds return -EACCES; 15911da177e4SLinus Torvalds } 15921da177e4SLinus Torvalds 1593d7321cd6SPavel Emelyanov int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) 15941da177e4SLinus Torvalds { 15951da177e4SLinus Torvalds int error; 1596d7321cd6SPavel Emelyanov int mode; 1597d7321cd6SPavel Emelyanov 15981da177e4SLinus Torvalds error = security_sysctl(table, op); 15991da177e4SLinus Torvalds if (error) 16001da177e4SLinus Torvalds return error; 1601d7321cd6SPavel Emelyanov 1602d7321cd6SPavel Emelyanov if (root->permissions) 1603d7321cd6SPavel Emelyanov mode = root->permissions(root, current->nsproxy, table); 1604d7321cd6SPavel Emelyanov else 1605d7321cd6SPavel Emelyanov mode = table->mode; 1606d7321cd6SPavel Emelyanov 1607d7321cd6SPavel Emelyanov return test_perm(mode, op); 16081da177e4SLinus Torvalds } 16091da177e4SLinus Torvalds 1610d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) 1611d912b0ccSEric W. Biederman { 1612d912b0ccSEric W. Biederman for (; table->ctl_name || table->procname; table++) { 1613d912b0ccSEric W. Biederman table->parent = parent; 1614d912b0ccSEric W. Biederman if (table->child) 1615d912b0ccSEric W. Biederman sysctl_set_parent(table, table->child); 1616d912b0ccSEric W. Biederman } 1617d912b0ccSEric W. Biederman } 1618d912b0ccSEric W. Biederman 1619d912b0ccSEric W. Biederman static __init int sysctl_init(void) 1620d912b0ccSEric W. Biederman { 1621d912b0ccSEric W. Biederman sysctl_set_parent(NULL, root_table); 162288f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 162388f458e4SHolger Schurig { 162488f458e4SHolger Schurig int err; 1625e51b6ba0SEric W. Biederman err = sysctl_check_table(current->nsproxy, root_table); 162688f458e4SHolger Schurig } 162788f458e4SHolger Schurig #endif 1628d912b0ccSEric W. Biederman return 0; 1629d912b0ccSEric W. Biederman } 1630d912b0ccSEric W. Biederman 1631d912b0ccSEric W. Biederman core_initcall(sysctl_init); 1632d912b0ccSEric W. Biederman 16331da177e4SLinus Torvalds /** 1634e51b6ba0SEric W. Biederman * __register_sysctl_paths - register a sysctl hierarchy 1635e51b6ba0SEric W. Biederman * @root: List of sysctl headers to register on 1636e51b6ba0SEric W. Biederman * @namespaces: Data to compute which lists of sysctl entries are visible 163729e796fdSEric W. Biederman * @path: The path to the directory the sysctl table is in. 16381da177e4SLinus Torvalds * @table: the top-level table structure 16391da177e4SLinus Torvalds * 16401da177e4SLinus Torvalds * Register a sysctl table hierarchy. @table should be a filled in ctl_table 164129e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 16421da177e4SLinus Torvalds * 1643d8217f07SEric W. Biederman * The members of the &struct ctl_table structure are used as follows: 16441da177e4SLinus Torvalds * 16451da177e4SLinus Torvalds * ctl_name - This is the numeric sysctl value used by sysctl(2). The number 16461da177e4SLinus Torvalds * must be unique within that level of sysctl 16471da177e4SLinus Torvalds * 16481da177e4SLinus Torvalds * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not 16491da177e4SLinus Torvalds * enter a sysctl file 16501da177e4SLinus Torvalds * 16511da177e4SLinus Torvalds * data - a pointer to data for use by proc_handler 16521da177e4SLinus Torvalds * 16531da177e4SLinus Torvalds * maxlen - the maximum size in bytes of the data 16541da177e4SLinus Torvalds * 16551da177e4SLinus Torvalds * mode - the file permissions for the /proc/sys file, and for sysctl(2) 16561da177e4SLinus Torvalds * 16571da177e4SLinus Torvalds * child - a pointer to the child sysctl table if this entry is a directory, or 16581da177e4SLinus Torvalds * %NULL. 16591da177e4SLinus Torvalds * 16601da177e4SLinus Torvalds * proc_handler - the text handler routine (described below) 16611da177e4SLinus Torvalds * 16621da177e4SLinus Torvalds * strategy - the strategy routine (described below) 16631da177e4SLinus Torvalds * 16641da177e4SLinus Torvalds * de - for internal use by the sysctl routines 16651da177e4SLinus Torvalds * 16661da177e4SLinus Torvalds * extra1, extra2 - extra pointers usable by the proc handler routines 16671da177e4SLinus Torvalds * 16681da177e4SLinus Torvalds * Leaf nodes in the sysctl tree will be represented by a single file 16691da177e4SLinus Torvalds * under /proc; non-leaf nodes will be represented by directories. 16701da177e4SLinus Torvalds * 16711da177e4SLinus Torvalds * sysctl(2) can automatically manage read and write requests through 16721da177e4SLinus Torvalds * the sysctl table. The data and maxlen fields of the ctl_table 16731da177e4SLinus Torvalds * struct enable minimal validation of the values being written to be 16741da177e4SLinus Torvalds * performed, and the mode field allows minimal authentication. 16751da177e4SLinus Torvalds * 16761da177e4SLinus Torvalds * More sophisticated management can be enabled by the provision of a 16771da177e4SLinus Torvalds * strategy routine with the table entry. This will be called before 16781da177e4SLinus Torvalds * any automatic read or write of the data is performed. 16791da177e4SLinus Torvalds * 16801da177e4SLinus Torvalds * The strategy routine may return 16811da177e4SLinus Torvalds * 16821da177e4SLinus Torvalds * < 0 - Error occurred (error is passed to user process) 16831da177e4SLinus Torvalds * 16841da177e4SLinus Torvalds * 0 - OK - proceed with automatic read or write. 16851da177e4SLinus Torvalds * 16861da177e4SLinus Torvalds * > 0 - OK - read or write has been done by the strategy routine, so 16871da177e4SLinus Torvalds * return immediately. 16881da177e4SLinus Torvalds * 16891da177e4SLinus Torvalds * There must be a proc_handler routine for any terminal nodes 16901da177e4SLinus Torvalds * mirrored under /proc/sys (non-terminals are handled by a built-in 16911da177e4SLinus Torvalds * directory handler). Several default handlers are available to 16921da177e4SLinus Torvalds * cover common cases - 16931da177e4SLinus Torvalds * 16941da177e4SLinus Torvalds * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), 16951da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 16961da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() 16971da177e4SLinus Torvalds * 16981da177e4SLinus Torvalds * It is the handler's job to read the input buffer from user memory 16991da177e4SLinus Torvalds * and process it. The handler should return 0 on success. 17001da177e4SLinus Torvalds * 17011da177e4SLinus Torvalds * This routine returns %NULL on a failure to register, and a pointer 17021da177e4SLinus Torvalds * to the table header on success. 17031da177e4SLinus Torvalds */ 1704e51b6ba0SEric W. Biederman struct ctl_table_header *__register_sysctl_paths( 1705e51b6ba0SEric W. Biederman struct ctl_table_root *root, 1706e51b6ba0SEric W. Biederman struct nsproxy *namespaces, 1707e51b6ba0SEric W. Biederman const struct ctl_path *path, struct ctl_table *table) 17081da177e4SLinus Torvalds { 1709e51b6ba0SEric W. Biederman struct list_head *header_list; 171029e796fdSEric W. Biederman struct ctl_table_header *header; 171129e796fdSEric W. Biederman struct ctl_table *new, **prevp; 171229e796fdSEric W. Biederman unsigned int n, npath; 171329e796fdSEric W. Biederman 171429e796fdSEric W. Biederman /* Count the path components */ 171529e796fdSEric W. Biederman for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) 171629e796fdSEric W. Biederman ; 171729e796fdSEric W. Biederman 171829e796fdSEric W. Biederman /* 171929e796fdSEric W. Biederman * For each path component, allocate a 2-element ctl_table array. 172029e796fdSEric W. Biederman * The first array element will be filled with the sysctl entry 172129e796fdSEric W. Biederman * for this, the second will be the sentinel (ctl_name == 0). 172229e796fdSEric W. Biederman * 172329e796fdSEric W. Biederman * We allocate everything in one go so that we don't have to 172429e796fdSEric W. Biederman * worry about freeing additional memory in unregister_sysctl_table. 172529e796fdSEric W. Biederman */ 172629e796fdSEric W. Biederman header = kzalloc(sizeof(struct ctl_table_header) + 172729e796fdSEric W. Biederman (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); 172829e796fdSEric W. Biederman if (!header) 17291da177e4SLinus Torvalds return NULL; 173029e796fdSEric W. Biederman 173129e796fdSEric W. Biederman new = (struct ctl_table *) (header + 1); 173229e796fdSEric W. Biederman 173329e796fdSEric W. Biederman /* Now connect the dots */ 173429e796fdSEric W. Biederman prevp = &header->ctl_table; 173529e796fdSEric W. Biederman for (n = 0; n < npath; ++n, ++path) { 173629e796fdSEric W. Biederman /* Copy the procname */ 173729e796fdSEric W. Biederman new->procname = path->procname; 173829e796fdSEric W. Biederman new->ctl_name = path->ctl_name; 173929e796fdSEric W. Biederman new->mode = 0555; 174029e796fdSEric W. Biederman 174129e796fdSEric W. Biederman *prevp = new; 174229e796fdSEric W. Biederman prevp = &new->child; 174329e796fdSEric W. Biederman 174429e796fdSEric W. Biederman new += 2; 174529e796fdSEric W. Biederman } 174629e796fdSEric W. Biederman *prevp = table; 174723eb06deSEric W. Biederman header->ctl_table_arg = table; 174829e796fdSEric W. Biederman 174929e796fdSEric W. Biederman INIT_LIST_HEAD(&header->ctl_entry); 175029e796fdSEric W. Biederman header->used = 0; 175129e796fdSEric W. Biederman header->unregistering = NULL; 1752e51b6ba0SEric W. Biederman header->root = root; 175329e796fdSEric W. Biederman sysctl_set_parent(NULL, header->ctl_table); 175488f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1755e51b6ba0SEric W. Biederman if (sysctl_check_table(namespaces, header->ctl_table)) { 175629e796fdSEric W. Biederman kfree(header); 1757fc6cd25bSEric W. Biederman return NULL; 1758fc6cd25bSEric W. Biederman } 175988f458e4SHolger Schurig #endif 1760330d57fbSAl Viro spin_lock(&sysctl_lock); 1761e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1762e51b6ba0SEric W. Biederman list_add_tail(&header->ctl_entry, header_list); 1763330d57fbSAl Viro spin_unlock(&sysctl_lock); 176429e796fdSEric W. Biederman 176529e796fdSEric W. Biederman return header; 176629e796fdSEric W. Biederman } 176729e796fdSEric W. Biederman 176829e796fdSEric W. Biederman /** 1769e51b6ba0SEric W. Biederman * register_sysctl_table_path - register a sysctl table hierarchy 1770e51b6ba0SEric W. Biederman * @path: The path to the directory the sysctl table is in. 1771e51b6ba0SEric W. Biederman * @table: the top-level table structure 1772e51b6ba0SEric W. Biederman * 1773e51b6ba0SEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1774e51b6ba0SEric W. Biederman * array. A completely 0 filled entry terminates the table. 1775e51b6ba0SEric W. Biederman * 1776e51b6ba0SEric W. Biederman * See __register_sysctl_paths for more details. 1777e51b6ba0SEric W. Biederman */ 1778e51b6ba0SEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 1779e51b6ba0SEric W. Biederman struct ctl_table *table) 1780e51b6ba0SEric W. Biederman { 1781e51b6ba0SEric W. Biederman return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, 1782e51b6ba0SEric W. Biederman path, table); 1783e51b6ba0SEric W. Biederman } 1784e51b6ba0SEric W. Biederman 1785e51b6ba0SEric W. Biederman /** 178629e796fdSEric W. Biederman * register_sysctl_table - register a sysctl table hierarchy 178729e796fdSEric W. Biederman * @table: the top-level table structure 178829e796fdSEric W. Biederman * 178929e796fdSEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 179029e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 179129e796fdSEric W. Biederman * 179229e796fdSEric W. Biederman * See register_sysctl_paths for more details. 179329e796fdSEric W. Biederman */ 179429e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table) 179529e796fdSEric W. Biederman { 179629e796fdSEric W. Biederman static const struct ctl_path null_path[] = { {} }; 179729e796fdSEric W. Biederman 179829e796fdSEric W. Biederman return register_sysctl_paths(null_path, table); 17991da177e4SLinus Torvalds } 18001da177e4SLinus Torvalds 18011da177e4SLinus Torvalds /** 18021da177e4SLinus Torvalds * unregister_sysctl_table - unregister a sysctl table hierarchy 18031da177e4SLinus Torvalds * @header: the header returned from register_sysctl_table 18041da177e4SLinus Torvalds * 18051da177e4SLinus Torvalds * Unregisters the sysctl table and all children. proc entries may not 18061da177e4SLinus Torvalds * actually be removed until they are no longer used by anyone. 18071da177e4SLinus Torvalds */ 18081da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header) 18091da177e4SLinus Torvalds { 1810330d57fbSAl Viro might_sleep(); 1811f1dad166SPavel Emelyanov 1812f1dad166SPavel Emelyanov if (header == NULL) 1813f1dad166SPavel Emelyanov return; 1814f1dad166SPavel Emelyanov 1815330d57fbSAl Viro spin_lock(&sysctl_lock); 1816330d57fbSAl Viro start_unregistering(header); 1817330d57fbSAl Viro spin_unlock(&sysctl_lock); 18181da177e4SLinus Torvalds kfree(header); 18191da177e4SLinus Torvalds } 18201da177e4SLinus Torvalds 1821b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */ 1822d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table) 1823b89a8171SEric W. Biederman { 1824b89a8171SEric W. Biederman return NULL; 1825b89a8171SEric W. Biederman } 1826b89a8171SEric W. Biederman 182729e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 182829e796fdSEric W. Biederman struct ctl_table *table) 182929e796fdSEric W. Biederman { 183029e796fdSEric W. Biederman return NULL; 183129e796fdSEric W. Biederman } 183229e796fdSEric W. Biederman 1833b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table) 1834b89a8171SEric W. Biederman { 1835b89a8171SEric W. Biederman } 1836b89a8171SEric W. Biederman 1837b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */ 1838b89a8171SEric W. Biederman 18391da177e4SLinus Torvalds /* 18401da177e4SLinus Torvalds * /proc/sys support 18411da177e4SLinus Torvalds */ 18421da177e4SLinus Torvalds 1843b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL 18441da177e4SLinus Torvalds 1845b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write, 1846b1ba4dddSAdrian Bunk struct file *filp, void __user *buffer, 1847b1ba4dddSAdrian Bunk size_t *lenp, loff_t *ppos) 1848f5dd3d6fSSam Vilain { 1849f5dd3d6fSSam Vilain size_t len; 1850f5dd3d6fSSam Vilain char __user *p; 1851f5dd3d6fSSam Vilain char c; 1852f5dd3d6fSSam Vilain 18538d060877SOleg Nesterov if (!data || !maxlen || !*lenp) { 1854f5dd3d6fSSam Vilain *lenp = 0; 1855f5dd3d6fSSam Vilain return 0; 1856f5dd3d6fSSam Vilain } 1857f5dd3d6fSSam Vilain 1858f5dd3d6fSSam Vilain if (write) { 1859f5dd3d6fSSam Vilain len = 0; 1860f5dd3d6fSSam Vilain p = buffer; 1861f5dd3d6fSSam Vilain while (len < *lenp) { 1862f5dd3d6fSSam Vilain if (get_user(c, p++)) 1863f5dd3d6fSSam Vilain return -EFAULT; 1864f5dd3d6fSSam Vilain if (c == 0 || c == '\n') 1865f5dd3d6fSSam Vilain break; 1866f5dd3d6fSSam Vilain len++; 1867f5dd3d6fSSam Vilain } 1868f5dd3d6fSSam Vilain if (len >= maxlen) 1869f5dd3d6fSSam Vilain len = maxlen-1; 1870f5dd3d6fSSam Vilain if(copy_from_user(data, buffer, len)) 1871f5dd3d6fSSam Vilain return -EFAULT; 1872f5dd3d6fSSam Vilain ((char *) data)[len] = 0; 1873f5dd3d6fSSam Vilain *ppos += *lenp; 1874f5dd3d6fSSam Vilain } else { 1875f5dd3d6fSSam Vilain len = strlen(data); 1876f5dd3d6fSSam Vilain if (len > maxlen) 1877f5dd3d6fSSam Vilain len = maxlen; 18788d060877SOleg Nesterov 18798d060877SOleg Nesterov if (*ppos > len) { 18808d060877SOleg Nesterov *lenp = 0; 18818d060877SOleg Nesterov return 0; 18828d060877SOleg Nesterov } 18838d060877SOleg Nesterov 18848d060877SOleg Nesterov data += *ppos; 18858d060877SOleg Nesterov len -= *ppos; 18868d060877SOleg Nesterov 1887f5dd3d6fSSam Vilain if (len > *lenp) 1888f5dd3d6fSSam Vilain len = *lenp; 1889f5dd3d6fSSam Vilain if (len) 1890f5dd3d6fSSam Vilain if(copy_to_user(buffer, data, len)) 1891f5dd3d6fSSam Vilain return -EFAULT; 1892f5dd3d6fSSam Vilain if (len < *lenp) { 1893f5dd3d6fSSam Vilain if(put_user('\n', ((char __user *) buffer) + len)) 1894f5dd3d6fSSam Vilain return -EFAULT; 1895f5dd3d6fSSam Vilain len++; 1896f5dd3d6fSSam Vilain } 1897f5dd3d6fSSam Vilain *lenp = len; 1898f5dd3d6fSSam Vilain *ppos += len; 1899f5dd3d6fSSam Vilain } 1900f5dd3d6fSSam Vilain return 0; 1901f5dd3d6fSSam Vilain } 1902f5dd3d6fSSam Vilain 19031da177e4SLinus Torvalds /** 19041da177e4SLinus Torvalds * proc_dostring - read a string sysctl 19051da177e4SLinus Torvalds * @table: the sysctl table 19061da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 19071da177e4SLinus Torvalds * @filp: the file structure 19081da177e4SLinus Torvalds * @buffer: the user buffer 19091da177e4SLinus Torvalds * @lenp: the size of the user buffer 19101da177e4SLinus Torvalds * @ppos: file position 19111da177e4SLinus Torvalds * 19121da177e4SLinus Torvalds * Reads/writes a string from/to the user buffer. If the kernel 19131da177e4SLinus Torvalds * buffer provided is not large enough to hold the string, the 19141da177e4SLinus Torvalds * string is truncated. The copied string is %NULL-terminated. 19151da177e4SLinus Torvalds * If the string is being read by the user process, it is copied 19161da177e4SLinus Torvalds * and a newline '\n' is added. It is truncated if the buffer is 19171da177e4SLinus Torvalds * not large enough. 19181da177e4SLinus Torvalds * 19191da177e4SLinus Torvalds * Returns 0 on success. 19201da177e4SLinus Torvalds */ 1921d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp, 19221da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 19231da177e4SLinus Torvalds { 1924f5dd3d6fSSam Vilain return _proc_do_string(table->data, table->maxlen, write, filp, 1925f5dd3d6fSSam Vilain buffer, lenp, ppos); 19261da177e4SLinus Torvalds } 19271da177e4SLinus Torvalds 19281da177e4SLinus Torvalds 19291da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, 19301da177e4SLinus Torvalds int *valp, 19311da177e4SLinus Torvalds int write, void *data) 19321da177e4SLinus Torvalds { 19331da177e4SLinus Torvalds if (write) { 19341da177e4SLinus Torvalds *valp = *negp ? -*lvalp : *lvalp; 19351da177e4SLinus Torvalds } else { 19361da177e4SLinus Torvalds int val = *valp; 19371da177e4SLinus Torvalds if (val < 0) { 19381da177e4SLinus Torvalds *negp = -1; 19391da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 19401da177e4SLinus Torvalds } else { 19411da177e4SLinus Torvalds *negp = 0; 19421da177e4SLinus Torvalds *lvalp = (unsigned long)val; 19431da177e4SLinus Torvalds } 19441da177e4SLinus Torvalds } 19451da177e4SLinus Torvalds return 0; 19461da177e4SLinus Torvalds } 19471da177e4SLinus Torvalds 1948d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 1949fcfbd547SKirill Korotaev int write, struct file *filp, void __user *buffer, 1950fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 19511da177e4SLinus Torvalds int (*conv)(int *negp, unsigned long *lvalp, int *valp, 19521da177e4SLinus Torvalds int write, void *data), 19531da177e4SLinus Torvalds void *data) 19541da177e4SLinus Torvalds { 19551da177e4SLinus Torvalds #define TMPBUFLEN 21 19561da177e4SLinus Torvalds int *i, vleft, first=1, neg, val; 19571da177e4SLinus Torvalds unsigned long lval; 19581da177e4SLinus Torvalds size_t left, len; 19591da177e4SLinus Torvalds 19601da177e4SLinus Torvalds char buf[TMPBUFLEN], *p; 19611da177e4SLinus Torvalds char __user *s = buffer; 19621da177e4SLinus Torvalds 1963fcfbd547SKirill Korotaev if (!tbl_data || !table->maxlen || !*lenp || 19641da177e4SLinus Torvalds (*ppos && !write)) { 19651da177e4SLinus Torvalds *lenp = 0; 19661da177e4SLinus Torvalds return 0; 19671da177e4SLinus Torvalds } 19681da177e4SLinus Torvalds 1969fcfbd547SKirill Korotaev i = (int *) tbl_data; 19701da177e4SLinus Torvalds vleft = table->maxlen / sizeof(*i); 19711da177e4SLinus Torvalds left = *lenp; 19721da177e4SLinus Torvalds 19731da177e4SLinus Torvalds if (!conv) 19741da177e4SLinus Torvalds conv = do_proc_dointvec_conv; 19751da177e4SLinus Torvalds 19761da177e4SLinus Torvalds for (; left && vleft--; i++, first=0) { 19771da177e4SLinus Torvalds if (write) { 19781da177e4SLinus Torvalds while (left) { 19791da177e4SLinus Torvalds char c; 19801da177e4SLinus Torvalds if (get_user(c, s)) 19811da177e4SLinus Torvalds return -EFAULT; 19821da177e4SLinus Torvalds if (!isspace(c)) 19831da177e4SLinus Torvalds break; 19841da177e4SLinus Torvalds left--; 19851da177e4SLinus Torvalds s++; 19861da177e4SLinus Torvalds } 19871da177e4SLinus Torvalds if (!left) 19881da177e4SLinus Torvalds break; 19891da177e4SLinus Torvalds neg = 0; 19901da177e4SLinus Torvalds len = left; 19911da177e4SLinus Torvalds if (len > sizeof(buf) - 1) 19921da177e4SLinus Torvalds len = sizeof(buf) - 1; 19931da177e4SLinus Torvalds if (copy_from_user(buf, s, len)) 19941da177e4SLinus Torvalds return -EFAULT; 19951da177e4SLinus Torvalds buf[len] = 0; 19961da177e4SLinus Torvalds p = buf; 19971da177e4SLinus Torvalds if (*p == '-' && left > 1) { 19981da177e4SLinus Torvalds neg = 1; 1999bd9b0bacSBP, Praveen p++; 20001da177e4SLinus Torvalds } 20011da177e4SLinus Torvalds if (*p < '0' || *p > '9') 20021da177e4SLinus Torvalds break; 20031da177e4SLinus Torvalds 20041da177e4SLinus Torvalds lval = simple_strtoul(p, &p, 0); 20051da177e4SLinus Torvalds 20061da177e4SLinus Torvalds len = p-buf; 20071da177e4SLinus Torvalds if ((len < left) && *p && !isspace(*p)) 20081da177e4SLinus Torvalds break; 20091da177e4SLinus Torvalds if (neg) 20101da177e4SLinus Torvalds val = -val; 20111da177e4SLinus Torvalds s += len; 20121da177e4SLinus Torvalds left -= len; 20131da177e4SLinus Torvalds 20141da177e4SLinus Torvalds if (conv(&neg, &lval, i, 1, data)) 20151da177e4SLinus Torvalds break; 20161da177e4SLinus Torvalds } else { 20171da177e4SLinus Torvalds p = buf; 20181da177e4SLinus Torvalds if (!first) 20191da177e4SLinus Torvalds *p++ = '\t'; 20201da177e4SLinus Torvalds 20211da177e4SLinus Torvalds if (conv(&neg, &lval, i, 0, data)) 20221da177e4SLinus Torvalds break; 20231da177e4SLinus Torvalds 20241da177e4SLinus Torvalds sprintf(p, "%s%lu", neg ? "-" : "", lval); 20251da177e4SLinus Torvalds len = strlen(buf); 20261da177e4SLinus Torvalds if (len > left) 20271da177e4SLinus Torvalds len = left; 20281da177e4SLinus Torvalds if(copy_to_user(s, buf, len)) 20291da177e4SLinus Torvalds return -EFAULT; 20301da177e4SLinus Torvalds left -= len; 20311da177e4SLinus Torvalds s += len; 20321da177e4SLinus Torvalds } 20331da177e4SLinus Torvalds } 20341da177e4SLinus Torvalds 20351da177e4SLinus Torvalds if (!write && !first && left) { 20361da177e4SLinus Torvalds if(put_user('\n', s)) 20371da177e4SLinus Torvalds return -EFAULT; 20381da177e4SLinus Torvalds left--, s++; 20391da177e4SLinus Torvalds } 20401da177e4SLinus Torvalds if (write) { 20411da177e4SLinus Torvalds while (left) { 20421da177e4SLinus Torvalds char c; 20431da177e4SLinus Torvalds if (get_user(c, s++)) 20441da177e4SLinus Torvalds return -EFAULT; 20451da177e4SLinus Torvalds if (!isspace(c)) 20461da177e4SLinus Torvalds break; 20471da177e4SLinus Torvalds left--; 20481da177e4SLinus Torvalds } 20491da177e4SLinus Torvalds } 20501da177e4SLinus Torvalds if (write && first) 20511da177e4SLinus Torvalds return -EINVAL; 20521da177e4SLinus Torvalds *lenp -= left; 20531da177e4SLinus Torvalds *ppos += *lenp; 20541da177e4SLinus Torvalds return 0; 20551da177e4SLinus Torvalds #undef TMPBUFLEN 20561da177e4SLinus Torvalds } 20571da177e4SLinus Torvalds 2058d8217f07SEric W. Biederman static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp, 2059fcfbd547SKirill Korotaev void __user *buffer, size_t *lenp, loff_t *ppos, 2060fcfbd547SKirill Korotaev int (*conv)(int *negp, unsigned long *lvalp, int *valp, 2061fcfbd547SKirill Korotaev int write, void *data), 2062fcfbd547SKirill Korotaev void *data) 2063fcfbd547SKirill Korotaev { 2064fcfbd547SKirill Korotaev return __do_proc_dointvec(table->data, table, write, filp, 2065fcfbd547SKirill Korotaev buffer, lenp, ppos, conv, data); 2066fcfbd547SKirill Korotaev } 2067fcfbd547SKirill Korotaev 20681da177e4SLinus Torvalds /** 20691da177e4SLinus Torvalds * proc_dointvec - read a vector of integers 20701da177e4SLinus Torvalds * @table: the sysctl table 20711da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 20721da177e4SLinus Torvalds * @filp: the file structure 20731da177e4SLinus Torvalds * @buffer: the user buffer 20741da177e4SLinus Torvalds * @lenp: the size of the user buffer 20751da177e4SLinus Torvalds * @ppos: file position 20761da177e4SLinus Torvalds * 20771da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 20781da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 20791da177e4SLinus Torvalds * 20801da177e4SLinus Torvalds * Returns 0 on success. 20811da177e4SLinus Torvalds */ 2082d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp, 20831da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 20841da177e4SLinus Torvalds { 20851da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 20861da177e4SLinus Torvalds NULL,NULL); 20871da177e4SLinus Torvalds } 20881da177e4SLinus Torvalds 20891da177e4SLinus Torvalds #define OP_SET 0 20901da177e4SLinus Torvalds #define OP_AND 1 209134f5a398STheodore Ts'o #define OP_OR 2 20921da177e4SLinus Torvalds 20931da177e4SLinus Torvalds static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp, 20941da177e4SLinus Torvalds int *valp, 20951da177e4SLinus Torvalds int write, void *data) 20961da177e4SLinus Torvalds { 20971da177e4SLinus Torvalds int op = *(int *)data; 20981da177e4SLinus Torvalds if (write) { 20991da177e4SLinus Torvalds int val = *negp ? -*lvalp : *lvalp; 21001da177e4SLinus Torvalds switch(op) { 21011da177e4SLinus Torvalds case OP_SET: *valp = val; break; 21021da177e4SLinus Torvalds case OP_AND: *valp &= val; break; 210334f5a398STheodore Ts'o case OP_OR: *valp |= val; break; 21041da177e4SLinus Torvalds } 21051da177e4SLinus Torvalds } else { 21061da177e4SLinus Torvalds int val = *valp; 21071da177e4SLinus Torvalds if (val < 0) { 21081da177e4SLinus Torvalds *negp = -1; 21091da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 21101da177e4SLinus Torvalds } else { 21111da177e4SLinus Torvalds *negp = 0; 21121da177e4SLinus Torvalds *lvalp = (unsigned long)val; 21131da177e4SLinus Torvalds } 21141da177e4SLinus Torvalds } 21151da177e4SLinus Torvalds return 0; 21161da177e4SLinus Torvalds } 21171da177e4SLinus Torvalds 211834f5a398STheodore Ts'o /* 211934f5a398STheodore Ts'o * Taint values can only be increased 212034f5a398STheodore Ts'o */ 2121d8217f07SEric W. Biederman static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp, 212234f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos) 212334f5a398STheodore Ts'o { 212434f5a398STheodore Ts'o int op; 212534f5a398STheodore Ts'o 212691fcd412SBastian Blank if (write && !capable(CAP_SYS_ADMIN)) 212734f5a398STheodore Ts'o return -EPERM; 212834f5a398STheodore Ts'o 212934f5a398STheodore Ts'o op = OP_OR; 213034f5a398STheodore Ts'o return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 213134f5a398STheodore Ts'o do_proc_dointvec_bset_conv,&op); 213234f5a398STheodore Ts'o } 213334f5a398STheodore Ts'o 21341da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param { 21351da177e4SLinus Torvalds int *min; 21361da177e4SLinus Torvalds int *max; 21371da177e4SLinus Torvalds }; 21381da177e4SLinus Torvalds 21391da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 21401da177e4SLinus Torvalds int *valp, 21411da177e4SLinus Torvalds int write, void *data) 21421da177e4SLinus Torvalds { 21431da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param *param = data; 21441da177e4SLinus Torvalds if (write) { 21451da177e4SLinus Torvalds int val = *negp ? -*lvalp : *lvalp; 21461da177e4SLinus Torvalds if ((param->min && *param->min > val) || 21471da177e4SLinus Torvalds (param->max && *param->max < val)) 21481da177e4SLinus Torvalds return -EINVAL; 21491da177e4SLinus Torvalds *valp = val; 21501da177e4SLinus Torvalds } else { 21511da177e4SLinus Torvalds int val = *valp; 21521da177e4SLinus Torvalds if (val < 0) { 21531da177e4SLinus Torvalds *negp = -1; 21541da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 21551da177e4SLinus Torvalds } else { 21561da177e4SLinus Torvalds *negp = 0; 21571da177e4SLinus Torvalds *lvalp = (unsigned long)val; 21581da177e4SLinus Torvalds } 21591da177e4SLinus Torvalds } 21601da177e4SLinus Torvalds return 0; 21611da177e4SLinus Torvalds } 21621da177e4SLinus Torvalds 21631da177e4SLinus Torvalds /** 21641da177e4SLinus Torvalds * proc_dointvec_minmax - read a vector of integers with min/max values 21651da177e4SLinus Torvalds * @table: the sysctl table 21661da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 21671da177e4SLinus Torvalds * @filp: the file structure 21681da177e4SLinus Torvalds * @buffer: the user buffer 21691da177e4SLinus Torvalds * @lenp: the size of the user buffer 21701da177e4SLinus Torvalds * @ppos: file position 21711da177e4SLinus Torvalds * 21721da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 21731da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 21741da177e4SLinus Torvalds * 21751da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 21761da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 21771da177e4SLinus Torvalds * 21781da177e4SLinus Torvalds * Returns 0 on success. 21791da177e4SLinus Torvalds */ 2180d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, 21811da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 21821da177e4SLinus Torvalds { 21831da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param param = { 21841da177e4SLinus Torvalds .min = (int *) table->extra1, 21851da177e4SLinus Torvalds .max = (int *) table->extra2, 21861da177e4SLinus Torvalds }; 21871da177e4SLinus Torvalds return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, 21881da177e4SLinus Torvalds do_proc_dointvec_minmax_conv, ¶m); 21891da177e4SLinus Torvalds } 21901da177e4SLinus Torvalds 2191d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, 21921da177e4SLinus Torvalds struct file *filp, 21931da177e4SLinus Torvalds void __user *buffer, 21941da177e4SLinus Torvalds size_t *lenp, loff_t *ppos, 21951da177e4SLinus Torvalds unsigned long convmul, 21961da177e4SLinus Torvalds unsigned long convdiv) 21971da177e4SLinus Torvalds { 21981da177e4SLinus Torvalds #define TMPBUFLEN 21 21991da177e4SLinus Torvalds unsigned long *i, *min, *max, val; 22001da177e4SLinus Torvalds int vleft, first=1, neg; 22011da177e4SLinus Torvalds size_t len, left; 22021da177e4SLinus Torvalds char buf[TMPBUFLEN], *p; 22031da177e4SLinus Torvalds char __user *s = buffer; 22041da177e4SLinus Torvalds 2205fcfbd547SKirill Korotaev if (!data || !table->maxlen || !*lenp || 22061da177e4SLinus Torvalds (*ppos && !write)) { 22071da177e4SLinus Torvalds *lenp = 0; 22081da177e4SLinus Torvalds return 0; 22091da177e4SLinus Torvalds } 22101da177e4SLinus Torvalds 2211fcfbd547SKirill Korotaev i = (unsigned long *) data; 22121da177e4SLinus Torvalds min = (unsigned long *) table->extra1; 22131da177e4SLinus Torvalds max = (unsigned long *) table->extra2; 22141da177e4SLinus Torvalds vleft = table->maxlen / sizeof(unsigned long); 22151da177e4SLinus Torvalds left = *lenp; 22161da177e4SLinus Torvalds 22171da177e4SLinus Torvalds for (; left && vleft--; i++, min++, max++, first=0) { 22181da177e4SLinus Torvalds if (write) { 22191da177e4SLinus Torvalds while (left) { 22201da177e4SLinus Torvalds char c; 22211da177e4SLinus Torvalds if (get_user(c, s)) 22221da177e4SLinus Torvalds return -EFAULT; 22231da177e4SLinus Torvalds if (!isspace(c)) 22241da177e4SLinus Torvalds break; 22251da177e4SLinus Torvalds left--; 22261da177e4SLinus Torvalds s++; 22271da177e4SLinus Torvalds } 22281da177e4SLinus Torvalds if (!left) 22291da177e4SLinus Torvalds break; 22301da177e4SLinus Torvalds neg = 0; 22311da177e4SLinus Torvalds len = left; 22321da177e4SLinus Torvalds if (len > TMPBUFLEN-1) 22331da177e4SLinus Torvalds len = TMPBUFLEN-1; 22341da177e4SLinus Torvalds if (copy_from_user(buf, s, len)) 22351da177e4SLinus Torvalds return -EFAULT; 22361da177e4SLinus Torvalds buf[len] = 0; 22371da177e4SLinus Torvalds p = buf; 22381da177e4SLinus Torvalds if (*p == '-' && left > 1) { 22391da177e4SLinus Torvalds neg = 1; 2240bd9b0bacSBP, Praveen p++; 22411da177e4SLinus Torvalds } 22421da177e4SLinus Torvalds if (*p < '0' || *p > '9') 22431da177e4SLinus Torvalds break; 22441da177e4SLinus Torvalds val = simple_strtoul(p, &p, 0) * convmul / convdiv ; 22451da177e4SLinus Torvalds len = p-buf; 22461da177e4SLinus Torvalds if ((len < left) && *p && !isspace(*p)) 22471da177e4SLinus Torvalds break; 22481da177e4SLinus Torvalds if (neg) 22491da177e4SLinus Torvalds val = -val; 22501da177e4SLinus Torvalds s += len; 22511da177e4SLinus Torvalds left -= len; 22521da177e4SLinus Torvalds 22531da177e4SLinus Torvalds if(neg) 22541da177e4SLinus Torvalds continue; 22551da177e4SLinus Torvalds if ((min && val < *min) || (max && val > *max)) 22561da177e4SLinus Torvalds continue; 22571da177e4SLinus Torvalds *i = val; 22581da177e4SLinus Torvalds } else { 22591da177e4SLinus Torvalds p = buf; 22601da177e4SLinus Torvalds if (!first) 22611da177e4SLinus Torvalds *p++ = '\t'; 22621da177e4SLinus Torvalds sprintf(p, "%lu", convdiv * (*i) / convmul); 22631da177e4SLinus Torvalds len = strlen(buf); 22641da177e4SLinus Torvalds if (len > left) 22651da177e4SLinus Torvalds len = left; 22661da177e4SLinus Torvalds if(copy_to_user(s, buf, len)) 22671da177e4SLinus Torvalds return -EFAULT; 22681da177e4SLinus Torvalds left -= len; 22691da177e4SLinus Torvalds s += len; 22701da177e4SLinus Torvalds } 22711da177e4SLinus Torvalds } 22721da177e4SLinus Torvalds 22731da177e4SLinus Torvalds if (!write && !first && left) { 22741da177e4SLinus Torvalds if(put_user('\n', s)) 22751da177e4SLinus Torvalds return -EFAULT; 22761da177e4SLinus Torvalds left--, s++; 22771da177e4SLinus Torvalds } 22781da177e4SLinus Torvalds if (write) { 22791da177e4SLinus Torvalds while (left) { 22801da177e4SLinus Torvalds char c; 22811da177e4SLinus Torvalds if (get_user(c, s++)) 22821da177e4SLinus Torvalds return -EFAULT; 22831da177e4SLinus Torvalds if (!isspace(c)) 22841da177e4SLinus Torvalds break; 22851da177e4SLinus Torvalds left--; 22861da177e4SLinus Torvalds } 22871da177e4SLinus Torvalds } 22881da177e4SLinus Torvalds if (write && first) 22891da177e4SLinus Torvalds return -EINVAL; 22901da177e4SLinus Torvalds *lenp -= left; 22911da177e4SLinus Torvalds *ppos += *lenp; 22921da177e4SLinus Torvalds return 0; 22931da177e4SLinus Torvalds #undef TMPBUFLEN 22941da177e4SLinus Torvalds } 22951da177e4SLinus Torvalds 2296d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 2297fcfbd547SKirill Korotaev struct file *filp, 2298fcfbd547SKirill Korotaev void __user *buffer, 2299fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 2300fcfbd547SKirill Korotaev unsigned long convmul, 2301fcfbd547SKirill Korotaev unsigned long convdiv) 2302fcfbd547SKirill Korotaev { 2303fcfbd547SKirill Korotaev return __do_proc_doulongvec_minmax(table->data, table, write, 2304fcfbd547SKirill Korotaev filp, buffer, lenp, ppos, convmul, convdiv); 2305fcfbd547SKirill Korotaev } 2306fcfbd547SKirill Korotaev 23071da177e4SLinus Torvalds /** 23081da177e4SLinus Torvalds * proc_doulongvec_minmax - read a vector of long integers with min/max values 23091da177e4SLinus Torvalds * @table: the sysctl table 23101da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 23111da177e4SLinus Torvalds * @filp: the file structure 23121da177e4SLinus Torvalds * @buffer: the user buffer 23131da177e4SLinus Torvalds * @lenp: the size of the user buffer 23141da177e4SLinus Torvalds * @ppos: file position 23151da177e4SLinus Torvalds * 23161da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 23171da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 23181da177e4SLinus Torvalds * 23191da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 23201da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 23211da177e4SLinus Torvalds * 23221da177e4SLinus Torvalds * Returns 0 on success. 23231da177e4SLinus Torvalds */ 2324d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, 23251da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 23261da177e4SLinus Torvalds { 23271da177e4SLinus Torvalds return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l); 23281da177e4SLinus Torvalds } 23291da177e4SLinus Torvalds 23301da177e4SLinus Torvalds /** 23311da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 23321da177e4SLinus Torvalds * @table: the sysctl table 23331da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 23341da177e4SLinus Torvalds * @filp: the file structure 23351da177e4SLinus Torvalds * @buffer: the user buffer 23361da177e4SLinus Torvalds * @lenp: the size of the user buffer 23371da177e4SLinus Torvalds * @ppos: file position 23381da177e4SLinus Torvalds * 23391da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 23401da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. The values 23411da177e4SLinus Torvalds * are treated as milliseconds, and converted to jiffies when they are stored. 23421da177e4SLinus Torvalds * 23431da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 23441da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 23451da177e4SLinus Torvalds * 23461da177e4SLinus Torvalds * Returns 0 on success. 23471da177e4SLinus Torvalds */ 2348d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 23491da177e4SLinus Torvalds struct file *filp, 23501da177e4SLinus Torvalds void __user *buffer, 23511da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 23521da177e4SLinus Torvalds { 23531da177e4SLinus Torvalds return do_proc_doulongvec_minmax(table, write, filp, buffer, 23541da177e4SLinus Torvalds lenp, ppos, HZ, 1000l); 23551da177e4SLinus Torvalds } 23561da177e4SLinus Torvalds 23571da177e4SLinus Torvalds 23581da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, 23591da177e4SLinus Torvalds int *valp, 23601da177e4SLinus Torvalds int write, void *data) 23611da177e4SLinus Torvalds { 23621da177e4SLinus Torvalds if (write) { 2363cba9f33dSBart Samwel if (*lvalp > LONG_MAX / HZ) 2364cba9f33dSBart Samwel return 1; 23651da177e4SLinus Torvalds *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); 23661da177e4SLinus Torvalds } else { 23671da177e4SLinus Torvalds int val = *valp; 23681da177e4SLinus Torvalds unsigned long lval; 23691da177e4SLinus Torvalds if (val < 0) { 23701da177e4SLinus Torvalds *negp = -1; 23711da177e4SLinus Torvalds lval = (unsigned long)-val; 23721da177e4SLinus Torvalds } else { 23731da177e4SLinus Torvalds *negp = 0; 23741da177e4SLinus Torvalds lval = (unsigned long)val; 23751da177e4SLinus Torvalds } 23761da177e4SLinus Torvalds *lvalp = lval / HZ; 23771da177e4SLinus Torvalds } 23781da177e4SLinus Torvalds return 0; 23791da177e4SLinus Torvalds } 23801da177e4SLinus Torvalds 23811da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, 23821da177e4SLinus Torvalds int *valp, 23831da177e4SLinus Torvalds int write, void *data) 23841da177e4SLinus Torvalds { 23851da177e4SLinus Torvalds if (write) { 2386cba9f33dSBart Samwel if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 2387cba9f33dSBart Samwel return 1; 23881da177e4SLinus Torvalds *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 23891da177e4SLinus Torvalds } else { 23901da177e4SLinus Torvalds int val = *valp; 23911da177e4SLinus Torvalds unsigned long lval; 23921da177e4SLinus Torvalds if (val < 0) { 23931da177e4SLinus Torvalds *negp = -1; 23941da177e4SLinus Torvalds lval = (unsigned long)-val; 23951da177e4SLinus Torvalds } else { 23961da177e4SLinus Torvalds *negp = 0; 23971da177e4SLinus Torvalds lval = (unsigned long)val; 23981da177e4SLinus Torvalds } 23991da177e4SLinus Torvalds *lvalp = jiffies_to_clock_t(lval); 24001da177e4SLinus Torvalds } 24011da177e4SLinus Torvalds return 0; 24021da177e4SLinus Torvalds } 24031da177e4SLinus Torvalds 24041da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, 24051da177e4SLinus Torvalds int *valp, 24061da177e4SLinus Torvalds int write, void *data) 24071da177e4SLinus Torvalds { 24081da177e4SLinus Torvalds if (write) { 24091da177e4SLinus Torvalds *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 24101da177e4SLinus Torvalds } else { 24111da177e4SLinus Torvalds int val = *valp; 24121da177e4SLinus Torvalds unsigned long lval; 24131da177e4SLinus Torvalds if (val < 0) { 24141da177e4SLinus Torvalds *negp = -1; 24151da177e4SLinus Torvalds lval = (unsigned long)-val; 24161da177e4SLinus Torvalds } else { 24171da177e4SLinus Torvalds *negp = 0; 24181da177e4SLinus Torvalds lval = (unsigned long)val; 24191da177e4SLinus Torvalds } 24201da177e4SLinus Torvalds *lvalp = jiffies_to_msecs(lval); 24211da177e4SLinus Torvalds } 24221da177e4SLinus Torvalds return 0; 24231da177e4SLinus Torvalds } 24241da177e4SLinus Torvalds 24251da177e4SLinus Torvalds /** 24261da177e4SLinus Torvalds * proc_dointvec_jiffies - read a vector of integers as seconds 24271da177e4SLinus Torvalds * @table: the sysctl table 24281da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 24291da177e4SLinus Torvalds * @filp: the file structure 24301da177e4SLinus Torvalds * @buffer: the user buffer 24311da177e4SLinus Torvalds * @lenp: the size of the user buffer 24321da177e4SLinus Torvalds * @ppos: file position 24331da177e4SLinus Torvalds * 24341da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 24351da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 24361da177e4SLinus Torvalds * The values read are assumed to be in seconds, and are converted into 24371da177e4SLinus Torvalds * jiffies. 24381da177e4SLinus Torvalds * 24391da177e4SLinus Torvalds * Returns 0 on success. 24401da177e4SLinus Torvalds */ 2441d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, 24421da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24431da177e4SLinus Torvalds { 24441da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 24451da177e4SLinus Torvalds do_proc_dointvec_jiffies_conv,NULL); 24461da177e4SLinus Torvalds } 24471da177e4SLinus Torvalds 24481da177e4SLinus Torvalds /** 24491da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 24501da177e4SLinus Torvalds * @table: the sysctl table 24511da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 24521da177e4SLinus Torvalds * @filp: the file structure 24531da177e4SLinus Torvalds * @buffer: the user buffer 24541da177e4SLinus Torvalds * @lenp: the size of the user buffer 24551e5d5331SRandy Dunlap * @ppos: pointer to the file position 24561da177e4SLinus Torvalds * 24571da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 24581da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 24591da177e4SLinus Torvalds * The values read are assumed to be in 1/USER_HZ seconds, and 24601da177e4SLinus Torvalds * are converted into jiffies. 24611da177e4SLinus Torvalds * 24621da177e4SLinus Torvalds * Returns 0 on success. 24631da177e4SLinus Torvalds */ 2464d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, 24651da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24661da177e4SLinus Torvalds { 24671da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 24681da177e4SLinus Torvalds do_proc_dointvec_userhz_jiffies_conv,NULL); 24691da177e4SLinus Torvalds } 24701da177e4SLinus Torvalds 24711da177e4SLinus Torvalds /** 24721da177e4SLinus Torvalds * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 24731da177e4SLinus Torvalds * @table: the sysctl table 24741da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 24751da177e4SLinus Torvalds * @filp: the file structure 24761da177e4SLinus Torvalds * @buffer: the user buffer 24771da177e4SLinus Torvalds * @lenp: the size of the user buffer 247867be2dd1SMartin Waitz * @ppos: file position 247967be2dd1SMartin Waitz * @ppos: the current position in the file 24801da177e4SLinus Torvalds * 24811da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 24821da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 24831da177e4SLinus Torvalds * The values read are assumed to be in 1/1000 seconds, and 24841da177e4SLinus Torvalds * are converted into jiffies. 24851da177e4SLinus Torvalds * 24861da177e4SLinus Torvalds * Returns 0 on success. 24871da177e4SLinus Torvalds */ 2488d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, 24891da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24901da177e4SLinus Torvalds { 24911da177e4SLinus Torvalds return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, 24921da177e4SLinus Torvalds do_proc_dointvec_ms_jiffies_conv, NULL); 24931da177e4SLinus Torvalds } 24941da177e4SLinus Torvalds 2495d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, 24969ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos) 24979ec52099SCedric Le Goater { 24989ec52099SCedric Le Goater struct pid *new_pid; 24999ec52099SCedric Le Goater pid_t tmp; 25009ec52099SCedric Le Goater int r; 25019ec52099SCedric Le Goater 25026c5f3e7bSPavel Emelyanov tmp = pid_vnr(cad_pid); 25039ec52099SCedric Le Goater 25049ec52099SCedric Le Goater r = __do_proc_dointvec(&tmp, table, write, filp, buffer, 25059ec52099SCedric Le Goater lenp, ppos, NULL, NULL); 25069ec52099SCedric Le Goater if (r || !write) 25079ec52099SCedric Le Goater return r; 25089ec52099SCedric Le Goater 25099ec52099SCedric Le Goater new_pid = find_get_pid(tmp); 25109ec52099SCedric Le Goater if (!new_pid) 25119ec52099SCedric Le Goater return -ESRCH; 25129ec52099SCedric Le Goater 25139ec52099SCedric Le Goater put_pid(xchg(&cad_pid, new_pid)); 25149ec52099SCedric Le Goater return 0; 25159ec52099SCedric Le Goater } 25169ec52099SCedric Le Goater 25171da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */ 25181da177e4SLinus Torvalds 2519d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp, 25201da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25211da177e4SLinus Torvalds { 25221da177e4SLinus Torvalds return -ENOSYS; 25231da177e4SLinus Torvalds } 25241da177e4SLinus Torvalds 2525d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp, 25261da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25271da177e4SLinus Torvalds { 25281da177e4SLinus Torvalds return -ENOSYS; 25291da177e4SLinus Torvalds } 25301da177e4SLinus Torvalds 2531d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, 25321da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25331da177e4SLinus Torvalds { 25341da177e4SLinus Torvalds return -ENOSYS; 25351da177e4SLinus Torvalds } 25361da177e4SLinus Torvalds 2537d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, 25381da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25391da177e4SLinus Torvalds { 25401da177e4SLinus Torvalds return -ENOSYS; 25411da177e4SLinus Torvalds } 25421da177e4SLinus Torvalds 2543d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, 25441da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25451da177e4SLinus Torvalds { 25461da177e4SLinus Torvalds return -ENOSYS; 25471da177e4SLinus Torvalds } 25481da177e4SLinus Torvalds 2549d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, 25501da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25511da177e4SLinus Torvalds { 25521da177e4SLinus Torvalds return -ENOSYS; 25531da177e4SLinus Torvalds } 25541da177e4SLinus Torvalds 2555d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, 25561da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25571da177e4SLinus Torvalds { 25581da177e4SLinus Torvalds return -ENOSYS; 25591da177e4SLinus Torvalds } 25601da177e4SLinus Torvalds 2561d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 25621da177e4SLinus Torvalds struct file *filp, 25631da177e4SLinus Torvalds void __user *buffer, 25641da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 25651da177e4SLinus Torvalds { 25661da177e4SLinus Torvalds return -ENOSYS; 25671da177e4SLinus Torvalds } 25681da177e4SLinus Torvalds 25691da177e4SLinus Torvalds 25701da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */ 25711da177e4SLinus Torvalds 25721da177e4SLinus Torvalds 2573b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 25741da177e4SLinus Torvalds /* 25751da177e4SLinus Torvalds * General sysctl support routines 25761da177e4SLinus Torvalds */ 25771da177e4SLinus Torvalds 257849a0c458SEric W. Biederman /* The generic sysctl data routine (used if no strategy routine supplied) */ 257949a0c458SEric W. Biederman int sysctl_data(struct ctl_table *table, int __user *name, int nlen, 258049a0c458SEric W. Biederman void __user *oldval, size_t __user *oldlenp, 258149a0c458SEric W. Biederman void __user *newval, size_t newlen) 258249a0c458SEric W. Biederman { 258349a0c458SEric W. Biederman size_t len; 258449a0c458SEric W. Biederman 258549a0c458SEric W. Biederman /* Get out of I don't have a variable */ 258649a0c458SEric W. Biederman if (!table->data || !table->maxlen) 258749a0c458SEric W. Biederman return -ENOTDIR; 258849a0c458SEric W. Biederman 258949a0c458SEric W. Biederman if (oldval && oldlenp) { 259049a0c458SEric W. Biederman if (get_user(len, oldlenp)) 259149a0c458SEric W. Biederman return -EFAULT; 259249a0c458SEric W. Biederman if (len) { 259349a0c458SEric W. Biederman if (len > table->maxlen) 259449a0c458SEric W. Biederman len = table->maxlen; 259549a0c458SEric W. Biederman if (copy_to_user(oldval, table->data, len)) 259649a0c458SEric W. Biederman return -EFAULT; 259749a0c458SEric W. Biederman if (put_user(len, oldlenp)) 259849a0c458SEric W. Biederman return -EFAULT; 259949a0c458SEric W. Biederman } 260049a0c458SEric W. Biederman } 260149a0c458SEric W. Biederman 260249a0c458SEric W. Biederman if (newval && newlen) { 260349a0c458SEric W. Biederman if (newlen > table->maxlen) 260449a0c458SEric W. Biederman newlen = table->maxlen; 260549a0c458SEric W. Biederman 260649a0c458SEric W. Biederman if (copy_from_user(table->data, newval, newlen)) 260749a0c458SEric W. Biederman return -EFAULT; 260849a0c458SEric W. Biederman } 260949a0c458SEric W. Biederman return 1; 261049a0c458SEric W. Biederman } 261149a0c458SEric W. Biederman 26121da177e4SLinus Torvalds /* The generic string strategy routine: */ 2613d8217f07SEric W. Biederman int sysctl_string(struct ctl_table *table, int __user *name, int nlen, 26141da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 26151f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 26161da177e4SLinus Torvalds { 26171da177e4SLinus Torvalds if (!table->data || !table->maxlen) 26181da177e4SLinus Torvalds return -ENOTDIR; 26191da177e4SLinus Torvalds 26201da177e4SLinus Torvalds if (oldval && oldlenp) { 2621de9e007dSLinus Torvalds size_t bufsize; 2622de9e007dSLinus Torvalds if (get_user(bufsize, oldlenp)) 26231da177e4SLinus Torvalds return -EFAULT; 2624de9e007dSLinus Torvalds if (bufsize) { 2625de9e007dSLinus Torvalds size_t len = strlen(table->data), copied; 2626de9e007dSLinus Torvalds 2627de9e007dSLinus Torvalds /* This shouldn't trigger for a well-formed sysctl */ 2628de9e007dSLinus Torvalds if (len > table->maxlen) 26291da177e4SLinus Torvalds len = table->maxlen; 2630de9e007dSLinus Torvalds 2631de9e007dSLinus Torvalds /* Copy up to a max of bufsize-1 bytes of the string */ 2632de9e007dSLinus Torvalds copied = (len >= bufsize) ? bufsize - 1 : len; 2633de9e007dSLinus Torvalds 2634de9e007dSLinus Torvalds if (copy_to_user(oldval, table->data, copied) || 2635de9e007dSLinus Torvalds put_user(0, (char __user *)(oldval + copied))) 26361da177e4SLinus Torvalds return -EFAULT; 26371da177e4SLinus Torvalds if (put_user(len, oldlenp)) 26381da177e4SLinus Torvalds return -EFAULT; 26391da177e4SLinus Torvalds } 26401da177e4SLinus Torvalds } 26411da177e4SLinus Torvalds if (newval && newlen) { 2642de9e007dSLinus Torvalds size_t len = newlen; 26431da177e4SLinus Torvalds if (len > table->maxlen) 26441da177e4SLinus Torvalds len = table->maxlen; 26451da177e4SLinus Torvalds if(copy_from_user(table->data, newval, len)) 26461da177e4SLinus Torvalds return -EFAULT; 26471da177e4SLinus Torvalds if (len == table->maxlen) 26481da177e4SLinus Torvalds len--; 26491da177e4SLinus Torvalds ((char *) table->data)[len] = 0; 26501da177e4SLinus Torvalds } 265182c9df82SYi Yang return 1; 26521da177e4SLinus Torvalds } 26531da177e4SLinus Torvalds 26541da177e4SLinus Torvalds /* 26551da177e4SLinus Torvalds * This function makes sure that all of the integers in the vector 26561da177e4SLinus Torvalds * are between the minimum and maximum values given in the arrays 26571da177e4SLinus Torvalds * table->extra1 and table->extra2, respectively. 26581da177e4SLinus Torvalds */ 2659d8217f07SEric W. Biederman int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, 26601da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 26611f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 26621da177e4SLinus Torvalds { 26631da177e4SLinus Torvalds 26641da177e4SLinus Torvalds if (newval && newlen) { 26651da177e4SLinus Torvalds int __user *vec = (int __user *) newval; 26661da177e4SLinus Torvalds int *min = (int *) table->extra1; 26671da177e4SLinus Torvalds int *max = (int *) table->extra2; 26681da177e4SLinus Torvalds size_t length; 26691da177e4SLinus Torvalds int i; 26701da177e4SLinus Torvalds 26711da177e4SLinus Torvalds if (newlen % sizeof(int) != 0) 26721da177e4SLinus Torvalds return -EINVAL; 26731da177e4SLinus Torvalds 26741da177e4SLinus Torvalds if (!table->extra1 && !table->extra2) 26751da177e4SLinus Torvalds return 0; 26761da177e4SLinus Torvalds 26771da177e4SLinus Torvalds if (newlen > table->maxlen) 26781da177e4SLinus Torvalds newlen = table->maxlen; 26791da177e4SLinus Torvalds length = newlen / sizeof(int); 26801da177e4SLinus Torvalds 26811da177e4SLinus Torvalds for (i = 0; i < length; i++) { 26821da177e4SLinus Torvalds int value; 26831da177e4SLinus Torvalds if (get_user(value, vec + i)) 26841da177e4SLinus Torvalds return -EFAULT; 26851da177e4SLinus Torvalds if (min && value < min[i]) 26861da177e4SLinus Torvalds return -EINVAL; 26871da177e4SLinus Torvalds if (max && value > max[i]) 26881da177e4SLinus Torvalds return -EINVAL; 26891da177e4SLinus Torvalds } 26901da177e4SLinus Torvalds } 26911da177e4SLinus Torvalds return 0; 26921da177e4SLinus Torvalds } 26931da177e4SLinus Torvalds 26941da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */ 2695d8217f07SEric W. Biederman int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, 26961da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 26971f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 26981da177e4SLinus Torvalds { 26993ee75ac3SAlexey Dobriyan if (oldval && oldlenp) { 27001da177e4SLinus Torvalds size_t olen; 27013ee75ac3SAlexey Dobriyan 27021da177e4SLinus Torvalds if (get_user(olen, oldlenp)) 27031da177e4SLinus Torvalds return -EFAULT; 27043ee75ac3SAlexey Dobriyan if (olen) { 27053ee75ac3SAlexey Dobriyan int val; 27063ee75ac3SAlexey Dobriyan 27073ee75ac3SAlexey Dobriyan if (olen < sizeof(int)) 27081da177e4SLinus Torvalds return -EINVAL; 27093ee75ac3SAlexey Dobriyan 27103ee75ac3SAlexey Dobriyan val = *(int *)(table->data) / HZ; 27113ee75ac3SAlexey Dobriyan if (put_user(val, (int __user *)oldval)) 27121da177e4SLinus Torvalds return -EFAULT; 27133ee75ac3SAlexey Dobriyan if (put_user(sizeof(int), oldlenp)) 27143ee75ac3SAlexey Dobriyan return -EFAULT; 27153ee75ac3SAlexey Dobriyan } 27161da177e4SLinus Torvalds } 27171da177e4SLinus Torvalds if (newval && newlen) { 27181da177e4SLinus Torvalds int new; 27191da177e4SLinus Torvalds if (newlen != sizeof(int)) 27201da177e4SLinus Torvalds return -EINVAL; 27211da177e4SLinus Torvalds if (get_user(new, (int __user *)newval)) 27221da177e4SLinus Torvalds return -EFAULT; 27231da177e4SLinus Torvalds *(int *)(table->data) = new*HZ; 27241da177e4SLinus Torvalds } 27251da177e4SLinus Torvalds return 1; 27261da177e4SLinus Torvalds } 27271da177e4SLinus Torvalds 27281da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */ 2729d8217f07SEric W. Biederman int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen, 27301da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 27311f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 27321da177e4SLinus Torvalds { 27333ee75ac3SAlexey Dobriyan if (oldval && oldlenp) { 27341da177e4SLinus Torvalds size_t olen; 27353ee75ac3SAlexey Dobriyan 27361da177e4SLinus Torvalds if (get_user(olen, oldlenp)) 27371da177e4SLinus Torvalds return -EFAULT; 27383ee75ac3SAlexey Dobriyan if (olen) { 27393ee75ac3SAlexey Dobriyan int val; 27403ee75ac3SAlexey Dobriyan 27413ee75ac3SAlexey Dobriyan if (olen < sizeof(int)) 27421da177e4SLinus Torvalds return -EINVAL; 27433ee75ac3SAlexey Dobriyan 27443ee75ac3SAlexey Dobriyan val = jiffies_to_msecs(*(int *)(table->data)); 27453ee75ac3SAlexey Dobriyan if (put_user(val, (int __user *)oldval)) 27461da177e4SLinus Torvalds return -EFAULT; 27473ee75ac3SAlexey Dobriyan if (put_user(sizeof(int), oldlenp)) 27483ee75ac3SAlexey Dobriyan return -EFAULT; 27493ee75ac3SAlexey Dobriyan } 27501da177e4SLinus Torvalds } 27511da177e4SLinus Torvalds if (newval && newlen) { 27521da177e4SLinus Torvalds int new; 27531da177e4SLinus Torvalds if (newlen != sizeof(int)) 27541da177e4SLinus Torvalds return -EINVAL; 27551da177e4SLinus Torvalds if (get_user(new, (int __user *)newval)) 27561da177e4SLinus Torvalds return -EFAULT; 27571da177e4SLinus Torvalds *(int *)(table->data) = msecs_to_jiffies(new); 27581da177e4SLinus Torvalds } 27591da177e4SLinus Torvalds return 1; 27601da177e4SLinus Torvalds } 27611da177e4SLinus Torvalds 2762c4b8b769SEric W. Biederman 2763c4b8b769SEric W. Biederman 2764b89a8171SEric W. Biederman #else /* CONFIG_SYSCTL_SYSCALL */ 27651da177e4SLinus Torvalds 27661da177e4SLinus Torvalds 27671da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args) 27681da177e4SLinus Torvalds { 27690e009be8SEric W. Biederman struct __sysctl_args tmp; 27707058cb02SEric W. Biederman int error; 27710e009be8SEric W. Biederman 27720e009be8SEric W. Biederman if (copy_from_user(&tmp, args, sizeof(tmp))) 27730e009be8SEric W. Biederman return -EFAULT; 27740e009be8SEric W. Biederman 27757058cb02SEric W. Biederman error = deprecated_sysctl_warning(&tmp); 2776b89a8171SEric W. Biederman 27777058cb02SEric W. Biederman /* If no error reading the parameters then just -ENOSYS ... */ 27787058cb02SEric W. Biederman if (!error) 27797058cb02SEric W. Biederman error = -ENOSYS; 27807058cb02SEric W. Biederman 27817058cb02SEric W. Biederman return error; 27821da177e4SLinus Torvalds } 27831da177e4SLinus Torvalds 278449a0c458SEric W. Biederman int sysctl_data(struct ctl_table *table, int __user *name, int nlen, 278549a0c458SEric W. Biederman void __user *oldval, size_t __user *oldlenp, 278649a0c458SEric W. Biederman void __user *newval, size_t newlen) 278749a0c458SEric W. Biederman { 278849a0c458SEric W. Biederman return -ENOSYS; 278949a0c458SEric W. Biederman } 279049a0c458SEric W. Biederman 2791d8217f07SEric W. Biederman int sysctl_string(struct ctl_table *table, int __user *name, int nlen, 27921da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 27931f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 27941da177e4SLinus Torvalds { 27951da177e4SLinus Torvalds return -ENOSYS; 27961da177e4SLinus Torvalds } 27971da177e4SLinus Torvalds 2798d8217f07SEric W. Biederman int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen, 27991da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 28001f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 28011da177e4SLinus Torvalds { 28021da177e4SLinus Torvalds return -ENOSYS; 28031da177e4SLinus Torvalds } 28041da177e4SLinus Torvalds 2805d8217f07SEric W. Biederman int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen, 28061da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 28071f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 28081da177e4SLinus Torvalds { 28091da177e4SLinus Torvalds return -ENOSYS; 28101da177e4SLinus Torvalds } 28111da177e4SLinus Torvalds 2812d8217f07SEric W. Biederman int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen, 28131da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 28141f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 28151da177e4SLinus Torvalds { 28161da177e4SLinus Torvalds return -ENOSYS; 28171da177e4SLinus Torvalds } 28181da177e4SLinus Torvalds 2819b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */ 28201da177e4SLinus Torvalds 28217058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args) 28227058cb02SEric W. Biederman { 28237058cb02SEric W. Biederman static int msg_count; 28247058cb02SEric W. Biederman int name[CTL_MAXNAME]; 28257058cb02SEric W. Biederman int i; 28267058cb02SEric W. Biederman 28276fc48af8STetsuo Handa /* Check args->nlen. */ 28286fc48af8STetsuo Handa if (args->nlen < 0 || args->nlen > CTL_MAXNAME) 28296fc48af8STetsuo Handa return -ENOTDIR; 28306fc48af8STetsuo Handa 28317058cb02SEric W. Biederman /* Read in the sysctl name for better debug message logging */ 28327058cb02SEric W. Biederman for (i = 0; i < args->nlen; i++) 28337058cb02SEric W. Biederman if (get_user(name[i], args->name + i)) 28347058cb02SEric W. Biederman return -EFAULT; 28357058cb02SEric W. Biederman 28367058cb02SEric W. Biederman /* Ignore accesses to kernel.version */ 28377058cb02SEric W. Biederman if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION)) 28387058cb02SEric W. Biederman return 0; 28397058cb02SEric W. Biederman 28407058cb02SEric W. Biederman if (msg_count < 5) { 28417058cb02SEric W. Biederman msg_count++; 28427058cb02SEric W. Biederman printk(KERN_INFO 28437058cb02SEric W. Biederman "warning: process `%s' used the deprecated sysctl " 28447058cb02SEric W. Biederman "system call with ", current->comm); 28457058cb02SEric W. Biederman for (i = 0; i < args->nlen; i++) 28467058cb02SEric W. Biederman printk("%d.", name[i]); 28477058cb02SEric W. Biederman printk("\n"); 28487058cb02SEric W. Biederman } 28497058cb02SEric W. Biederman return 0; 28507058cb02SEric W. Biederman } 28517058cb02SEric W. Biederman 28521da177e4SLinus Torvalds /* 28531da177e4SLinus Torvalds * No sense putting this after each symbol definition, twice, 28541da177e4SLinus Torvalds * exception granted :-) 28551da177e4SLinus Torvalds */ 28561da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec); 28571da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies); 28581da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax); 28591da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 28601da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 28611da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring); 28621da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax); 28631da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 28641da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table); 286529e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths); 28661da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec); 28671da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies); 28681da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies); 28691da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string); 287049a0c458SEric W. Biederman EXPORT_SYMBOL(sysctl_data); 28711da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table); 2872