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> 46c748e134SAdrian Bunk #include <linux/vmstat.h> 47c255d844SPavel Machek #include <linux/nfs_fs.h> 48c255d844SPavel Machek #include <linux/acpi.h> 4910a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h> 50b0fc494fSSteven Rostedt #include <linux/ftrace.h> 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds #include <asm/uaccess.h> 531da177e4SLinus Torvalds #include <asm/processor.h> 541da177e4SLinus Torvalds 5529cbc78bSAndi Kleen #ifdef CONFIG_X86 5629cbc78bSAndi Kleen #include <asm/nmi.h> 570741f4d2SChuck Ebbert #include <asm/stacktrace.h> 586e7c4025SIngo Molnar #include <asm/io.h> 5929cbc78bSAndi Kleen #endif 6029cbc78bSAndi Kleen 617058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args); 627058cb02SEric W. Biederman 631da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds /* External variables not in a header file. */ 661da177e4SLinus Torvalds extern int C_A_D; 6745807a1dSIngo Molnar extern int print_fatal_signals; 681da177e4SLinus Torvalds extern int sysctl_overcommit_memory; 691da177e4SLinus Torvalds extern int sysctl_overcommit_ratio; 70fadd8fbdSKAMEZAWA Hiroyuki extern int sysctl_panic_on_oom; 71fe071d7eSDavid Rientjes extern int sysctl_oom_kill_allocating_task; 72fef1bdd6SDavid Rientjes extern int sysctl_oom_dump_tasks; 731da177e4SLinus Torvalds extern int max_threads; 741da177e4SLinus Torvalds extern int core_uses_pid; 75d6e71144SAlan Cox extern int suid_dumpable; 761da177e4SLinus Torvalds extern char core_pattern[]; 771da177e4SLinus Torvalds extern int pid_max; 781da177e4SLinus Torvalds extern int min_free_kbytes; 791da177e4SLinus Torvalds extern int pid_max_min, pid_max_max; 809d0243bcSAndrew Morton extern int sysctl_drop_caches; 818ad4b1fbSRohit Seth extern int percpu_pagelist_fraction; 82bebfa101SAndi Kleen extern int compat_log; 839745512cSArjan van de Ven extern int latencytop_enabled; 84eceea0b3SAl Viro extern int sysctl_nr_open_min, sysctl_nr_open_max; 8531a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST 8631a72bceSPaul E. McKenney extern int rcutorture_runnable; 8731a72bceSPaul E. McKenney #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ 881da177e4SLinus Torvalds 89c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */ 901c4cd6ddSIngo Molnar #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP) 91c4f3b63fSRavikiran G Thirumalai static int one = 1; 92195cf453SBron Gondwana #endif 93195cf453SBron Gondwana 94195cf453SBron Gondwana #ifdef CONFIG_DETECT_SOFTLOCKUP 95c4f3b63fSRavikiran G Thirumalai static int sixty = 60; 969383d967SDimitri Sivanich static int neg_one = -1; 97c4f3b63fSRavikiran G Thirumalai #endif 98c4f3b63fSRavikiran G Thirumalai 99bfcd17a6SThomas Petazzoni #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING) 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 113a1ef5adbSJohannes 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 12072c57ed5SDavid S. Miller #ifdef CONFIG_SPARC 12117f04fbbSDavid S. Miller #include <asm/system.h> 1221da177e4SLinus Torvalds #endif 1231da177e4SLinus Torvalds 1241da177e4SLinus Torvalds #ifdef __hppa__ 1251da177e4SLinus Torvalds extern int pwrsw_enabled; 1261da177e4SLinus Torvalds extern int unaligned_enabled; 1271da177e4SLinus Torvalds #endif 1281da177e4SLinus Torvalds 129347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 1301da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 1311da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings; 1321da177e4SLinus Torvalds #endif 1331da177e4SLinus Torvalds extern int sysctl_userprocess_debug; 134951f22d5SMartin Schwidefsky extern int spin_retry; 1351da177e4SLinus Torvalds #endif 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT 1381da177e4SLinus Torvalds extern int acct_parm[]; 1391da177e4SLinus Torvalds #endif 1401da177e4SLinus Torvalds 141d2b176edSJes Sorensen #ifdef CONFIG_IA64 142d2b176edSJes Sorensen extern int no_unaligned_warning; 143d2b176edSJes Sorensen #endif 144d2b176edSJes Sorensen 14523f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 14623f78d4aSIngo Molnar extern int max_lock_depth; 14723f78d4aSIngo Molnar #endif 14823f78d4aSIngo Molnar 149d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 150d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, 1519ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos); 15225ddbb18SAndi Kleen static int proc_taint(struct ctl_table *table, int write, struct file *filp, 15334f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos); 154d6f8ff73SRandy Dunlap #endif 1559ec52099SCedric Le Goater 156d8217f07SEric W. Biederman static struct ctl_table root_table[]; 157e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root; 158e51b6ba0SEric W. Biederman static struct ctl_table_header root_table_header = { 159b380b0d4SAl Viro .count = 1, 160e51b6ba0SEric W. Biederman .ctl_table = root_table, 16173455092SAl Viro .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list), 162e51b6ba0SEric W. Biederman .root = &sysctl_table_root, 16373455092SAl Viro .set = &sysctl_table_root.default_set, 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), 16773455092SAl Viro .default_set.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", 38225ddbb18SAndi Kleen .maxlen = sizeof(long), 38334f5a398STheodore Ts'o .mode = 0644, 38425ddbb18SAndi Kleen .proc_handler = &proc_taint, 3851da177e4SLinus Torvalds }, 38634f5a398STheodore Ts'o #endif 3879745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 3889745512cSArjan van de Ven { 3899745512cSArjan van de Ven .procname = "latencytop", 3909745512cSArjan van de Ven .data = &latencytop_enabled, 3919745512cSArjan van de Ven .maxlen = sizeof(int), 3929745512cSArjan van de Ven .mode = 0644, 3939745512cSArjan van de Ven .proc_handler = &proc_dointvec, 3949745512cSArjan van de Ven }, 3959745512cSArjan van de Ven #endif 3961da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 3971da177e4SLinus Torvalds { 3981da177e4SLinus Torvalds .ctl_name = KERN_REALROOTDEV, 3991da177e4SLinus Torvalds .procname = "real-root-dev", 4001da177e4SLinus Torvalds .data = &real_root_dev, 4011da177e4SLinus Torvalds .maxlen = sizeof(int), 4021da177e4SLinus Torvalds .mode = 0644, 4031da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4041da177e4SLinus Torvalds }, 4051da177e4SLinus Torvalds #endif 40645807a1dSIngo Molnar { 40745807a1dSIngo Molnar .ctl_name = CTL_UNNUMBERED, 40845807a1dSIngo Molnar .procname = "print-fatal-signals", 40945807a1dSIngo Molnar .data = &print_fatal_signals, 41045807a1dSIngo Molnar .maxlen = sizeof(int), 41145807a1dSIngo Molnar .mode = 0644, 41245807a1dSIngo Molnar .proc_handler = &proc_dointvec, 41345807a1dSIngo Molnar }, 41472c57ed5SDavid S. Miller #ifdef CONFIG_SPARC 4151da177e4SLinus Torvalds { 4161da177e4SLinus Torvalds .ctl_name = KERN_SPARC_REBOOT, 4171da177e4SLinus Torvalds .procname = "reboot-cmd", 4181da177e4SLinus Torvalds .data = reboot_command, 4191da177e4SLinus Torvalds .maxlen = 256, 4201da177e4SLinus Torvalds .mode = 0644, 4211da177e4SLinus Torvalds .proc_handler = &proc_dostring, 4221da177e4SLinus Torvalds .strategy = &sysctl_string, 4231da177e4SLinus Torvalds }, 4241da177e4SLinus Torvalds { 4251da177e4SLinus Torvalds .ctl_name = KERN_SPARC_STOP_A, 4261da177e4SLinus Torvalds .procname = "stop-a", 4271da177e4SLinus Torvalds .data = &stop_a_enabled, 4281da177e4SLinus Torvalds .maxlen = sizeof (int), 4291da177e4SLinus Torvalds .mode = 0644, 4301da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4311da177e4SLinus Torvalds }, 4321da177e4SLinus Torvalds { 4331da177e4SLinus Torvalds .ctl_name = KERN_SPARC_SCONS_PWROFF, 4341da177e4SLinus Torvalds .procname = "scons-poweroff", 4351da177e4SLinus Torvalds .data = &scons_pwroff, 4361da177e4SLinus Torvalds .maxlen = sizeof (int), 4371da177e4SLinus Torvalds .mode = 0644, 4381da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4391da177e4SLinus Torvalds }, 4401da177e4SLinus Torvalds #endif 4411da177e4SLinus Torvalds #ifdef __hppa__ 4421da177e4SLinus Torvalds { 4431da177e4SLinus Torvalds .ctl_name = KERN_HPPA_PWRSW, 4441da177e4SLinus Torvalds .procname = "soft-power", 4451da177e4SLinus Torvalds .data = &pwrsw_enabled, 4461da177e4SLinus Torvalds .maxlen = sizeof (int), 4471da177e4SLinus Torvalds .mode = 0644, 4481da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4491da177e4SLinus Torvalds }, 4501da177e4SLinus Torvalds { 4511da177e4SLinus Torvalds .ctl_name = KERN_HPPA_UNALIGNED, 4521da177e4SLinus Torvalds .procname = "unaligned-trap", 4531da177e4SLinus Torvalds .data = &unaligned_enabled, 4541da177e4SLinus Torvalds .maxlen = sizeof (int), 4551da177e4SLinus Torvalds .mode = 0644, 4561da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4571da177e4SLinus Torvalds }, 4581da177e4SLinus Torvalds #endif 4591da177e4SLinus Torvalds { 4601da177e4SLinus Torvalds .ctl_name = KERN_CTLALTDEL, 4611da177e4SLinus Torvalds .procname = "ctrl-alt-del", 4621da177e4SLinus Torvalds .data = &C_A_D, 4631da177e4SLinus Torvalds .maxlen = sizeof(int), 4641da177e4SLinus Torvalds .mode = 0644, 4651da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 4661da177e4SLinus Torvalds }, 467*606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER 468b0fc494fSSteven Rostedt { 469b0fc494fSSteven Rostedt .ctl_name = CTL_UNNUMBERED, 470b0fc494fSSteven Rostedt .procname = "ftrace_enabled", 471b0fc494fSSteven Rostedt .data = &ftrace_enabled, 472b0fc494fSSteven Rostedt .maxlen = sizeof(int), 473b0fc494fSSteven Rostedt .mode = 0644, 474b0fc494fSSteven Rostedt .proc_handler = &ftrace_enable_sysctl, 475b0fc494fSSteven Rostedt }, 476b0fc494fSSteven Rostedt #endif 477a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES 4781da177e4SLinus Torvalds { 4791da177e4SLinus Torvalds .ctl_name = KERN_MODPROBE, 4801da177e4SLinus Torvalds .procname = "modprobe", 4811da177e4SLinus Torvalds .data = &modprobe_path, 4821da177e4SLinus Torvalds .maxlen = KMOD_PATH_LEN, 4831da177e4SLinus Torvalds .mode = 0644, 4841da177e4SLinus Torvalds .proc_handler = &proc_dostring, 4851da177e4SLinus Torvalds .strategy = &sysctl_string, 4861da177e4SLinus Torvalds }, 4871da177e4SLinus Torvalds #endif 48857ae2508SAndrew Morton #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) 4891da177e4SLinus Torvalds { 4901da177e4SLinus Torvalds .ctl_name = KERN_HOTPLUG, 4911da177e4SLinus Torvalds .procname = "hotplug", 492312c004dSKay Sievers .data = &uevent_helper, 493312c004dSKay Sievers .maxlen = UEVENT_HELPER_PATH_LEN, 4941da177e4SLinus Torvalds .mode = 0644, 4951da177e4SLinus Torvalds .proc_handler = &proc_dostring, 4961da177e4SLinus Torvalds .strategy = &sysctl_string, 4971da177e4SLinus Torvalds }, 4981da177e4SLinus Torvalds #endif 4991da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG 5001da177e4SLinus Torvalds { 5011da177e4SLinus Torvalds .ctl_name = KERN_SG_BIG_BUFF, 5021da177e4SLinus Torvalds .procname = "sg-big-buff", 5031da177e4SLinus Torvalds .data = &sg_big_buff, 5041da177e4SLinus Torvalds .maxlen = sizeof (int), 5051da177e4SLinus Torvalds .mode = 0444, 5061da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5071da177e4SLinus Torvalds }, 5081da177e4SLinus Torvalds #endif 5091da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT 5101da177e4SLinus Torvalds { 5111da177e4SLinus Torvalds .ctl_name = KERN_ACCT, 5121da177e4SLinus Torvalds .procname = "acct", 5131da177e4SLinus Torvalds .data = &acct_parm, 5141da177e4SLinus Torvalds .maxlen = 3*sizeof(int), 5151da177e4SLinus Torvalds .mode = 0644, 5161da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5171da177e4SLinus Torvalds }, 5181da177e4SLinus Torvalds #endif 5191da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ 5201da177e4SLinus Torvalds { 5211da177e4SLinus Torvalds .ctl_name = KERN_SYSRQ, 5221da177e4SLinus Torvalds .procname = "sysrq", 5235d6f647fSIngo Molnar .data = &__sysrq_enabled, 5241da177e4SLinus Torvalds .maxlen = sizeof (int), 5251da177e4SLinus Torvalds .mode = 0644, 5261da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5271da177e4SLinus Torvalds }, 5281da177e4SLinus Torvalds #endif 529d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 5301da177e4SLinus Torvalds { 5311da177e4SLinus Torvalds .procname = "cad_pid", 5329ec52099SCedric Le Goater .data = NULL, 5331da177e4SLinus Torvalds .maxlen = sizeof (int), 5341da177e4SLinus Torvalds .mode = 0600, 5359ec52099SCedric Le Goater .proc_handler = &proc_do_cad_pid, 5361da177e4SLinus Torvalds }, 537d6f8ff73SRandy Dunlap #endif 5381da177e4SLinus Torvalds { 5391da177e4SLinus Torvalds .ctl_name = KERN_MAX_THREADS, 5401da177e4SLinus Torvalds .procname = "threads-max", 5411da177e4SLinus Torvalds .data = &max_threads, 5421da177e4SLinus Torvalds .maxlen = sizeof(int), 5431da177e4SLinus Torvalds .mode = 0644, 5441da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5451da177e4SLinus Torvalds }, 5461da177e4SLinus Torvalds { 5471da177e4SLinus Torvalds .ctl_name = KERN_RANDOM, 5481da177e4SLinus Torvalds .procname = "random", 5491da177e4SLinus Torvalds .mode = 0555, 5501da177e4SLinus Torvalds .child = random_table, 5511da177e4SLinus Torvalds }, 5521da177e4SLinus Torvalds { 5531da177e4SLinus Torvalds .ctl_name = KERN_OVERFLOWUID, 5541da177e4SLinus Torvalds .procname = "overflowuid", 5551da177e4SLinus Torvalds .data = &overflowuid, 5561da177e4SLinus Torvalds .maxlen = sizeof(int), 5571da177e4SLinus Torvalds .mode = 0644, 5581da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 5591da177e4SLinus Torvalds .strategy = &sysctl_intvec, 5601da177e4SLinus Torvalds .extra1 = &minolduid, 5611da177e4SLinus Torvalds .extra2 = &maxolduid, 5621da177e4SLinus Torvalds }, 5631da177e4SLinus Torvalds { 5641da177e4SLinus Torvalds .ctl_name = KERN_OVERFLOWGID, 5651da177e4SLinus Torvalds .procname = "overflowgid", 5661da177e4SLinus Torvalds .data = &overflowgid, 5671da177e4SLinus Torvalds .maxlen = sizeof(int), 5681da177e4SLinus Torvalds .mode = 0644, 5691da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 5701da177e4SLinus Torvalds .strategy = &sysctl_intvec, 5711da177e4SLinus Torvalds .extra1 = &minolduid, 5721da177e4SLinus Torvalds .extra2 = &maxolduid, 5731da177e4SLinus Torvalds }, 574347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 5751da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 5761da177e4SLinus Torvalds { 5771da177e4SLinus Torvalds .ctl_name = KERN_IEEE_EMULATION_WARNINGS, 5781da177e4SLinus Torvalds .procname = "ieee_emulation_warnings", 5791da177e4SLinus Torvalds .data = &sysctl_ieee_emulation_warnings, 5801da177e4SLinus Torvalds .maxlen = sizeof(int), 5811da177e4SLinus Torvalds .mode = 0644, 5821da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5831da177e4SLinus Torvalds }, 5841da177e4SLinus Torvalds #endif 5851da177e4SLinus Torvalds { 5861da177e4SLinus Torvalds .ctl_name = KERN_S390_USER_DEBUG_LOGGING, 5871da177e4SLinus Torvalds .procname = "userprocess_debug", 5881da177e4SLinus Torvalds .data = &sysctl_userprocess_debug, 5891da177e4SLinus Torvalds .maxlen = sizeof(int), 5901da177e4SLinus Torvalds .mode = 0644, 5911da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 5921da177e4SLinus Torvalds }, 5931da177e4SLinus Torvalds #endif 5941da177e4SLinus Torvalds { 5951da177e4SLinus Torvalds .ctl_name = KERN_PIDMAX, 5961da177e4SLinus Torvalds .procname = "pid_max", 5971da177e4SLinus Torvalds .data = &pid_max, 5981da177e4SLinus Torvalds .maxlen = sizeof (int), 5991da177e4SLinus Torvalds .mode = 0644, 6001da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 6011da177e4SLinus Torvalds .strategy = sysctl_intvec, 6021da177e4SLinus Torvalds .extra1 = &pid_max_min, 6031da177e4SLinus Torvalds .extra2 = &pid_max_max, 6041da177e4SLinus Torvalds }, 6051da177e4SLinus Torvalds { 6061da177e4SLinus Torvalds .ctl_name = KERN_PANIC_ON_OOPS, 6071da177e4SLinus Torvalds .procname = "panic_on_oops", 6081da177e4SLinus Torvalds .data = &panic_on_oops, 6091da177e4SLinus Torvalds .maxlen = sizeof(int), 6101da177e4SLinus Torvalds .mode = 0644, 6111da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6121da177e4SLinus Torvalds }, 6137ef3d2fdSJoe Perches #if defined CONFIG_PRINTK 6147ef3d2fdSJoe Perches { 6157ef3d2fdSJoe Perches .ctl_name = KERN_PRINTK, 6167ef3d2fdSJoe Perches .procname = "printk", 6177ef3d2fdSJoe Perches .data = &console_loglevel, 6187ef3d2fdSJoe Perches .maxlen = 4*sizeof(int), 6197ef3d2fdSJoe Perches .mode = 0644, 6207ef3d2fdSJoe Perches .proc_handler = &proc_dointvec, 6217ef3d2fdSJoe Perches }, 6221da177e4SLinus Torvalds { 6231da177e4SLinus Torvalds .ctl_name = KERN_PRINTK_RATELIMIT, 6241da177e4SLinus Torvalds .procname = "printk_ratelimit", 625717115e1SDave Young .data = &printk_ratelimit_state.interval, 6261da177e4SLinus Torvalds .maxlen = sizeof(int), 6271da177e4SLinus Torvalds .mode = 0644, 6281da177e4SLinus Torvalds .proc_handler = &proc_dointvec_jiffies, 6291da177e4SLinus Torvalds .strategy = &sysctl_jiffies, 6301da177e4SLinus Torvalds }, 6311da177e4SLinus Torvalds { 6321da177e4SLinus Torvalds .ctl_name = KERN_PRINTK_RATELIMIT_BURST, 6331da177e4SLinus Torvalds .procname = "printk_ratelimit_burst", 634717115e1SDave Young .data = &printk_ratelimit_state.burst, 6351da177e4SLinus Torvalds .maxlen = sizeof(int), 6361da177e4SLinus Torvalds .mode = 0644, 6371da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6381da177e4SLinus Torvalds }, 6397ef3d2fdSJoe Perches #endif 6401da177e4SLinus Torvalds { 6411da177e4SLinus Torvalds .ctl_name = KERN_NGROUPS_MAX, 6421da177e4SLinus Torvalds .procname = "ngroups_max", 6431da177e4SLinus Torvalds .data = &ngroups_max, 6441da177e4SLinus Torvalds .maxlen = sizeof (int), 6451da177e4SLinus Torvalds .mode = 0444, 6461da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6471da177e4SLinus Torvalds }, 6481da177e4SLinus Torvalds #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) 6491da177e4SLinus Torvalds { 6501da177e4SLinus Torvalds .ctl_name = KERN_UNKNOWN_NMI_PANIC, 6511da177e4SLinus Torvalds .procname = "unknown_nmi_panic", 6521da177e4SLinus Torvalds .data = &unknown_nmi_panic, 6531da177e4SLinus Torvalds .maxlen = sizeof (int), 6541da177e4SLinus Torvalds .mode = 0644, 6552fbe7b25SDon Zickus .proc_handler = &proc_dointvec, 6561da177e4SLinus Torvalds }, 657407984f1SDon Zickus { 658407984f1SDon Zickus .procname = "nmi_watchdog", 659407984f1SDon Zickus .data = &nmi_watchdog_enabled, 660407984f1SDon Zickus .maxlen = sizeof (int), 661407984f1SDon Zickus .mode = 0644, 662407984f1SDon Zickus .proc_handler = &proc_nmi_enabled, 6631da177e4SLinus Torvalds }, 6641da177e4SLinus Torvalds #endif 6651da177e4SLinus Torvalds #if defined(CONFIG_X86) 6661da177e4SLinus Torvalds { 6678da5addaSDon Zickus .ctl_name = KERN_PANIC_ON_NMI, 6688da5addaSDon Zickus .procname = "panic_on_unrecovered_nmi", 6698da5addaSDon Zickus .data = &panic_on_unrecovered_nmi, 6708da5addaSDon Zickus .maxlen = sizeof(int), 6718da5addaSDon Zickus .mode = 0644, 6728da5addaSDon Zickus .proc_handler = &proc_dointvec, 6738da5addaSDon Zickus }, 6748da5addaSDon Zickus { 6751da177e4SLinus Torvalds .ctl_name = KERN_BOOTLOADER_TYPE, 6761da177e4SLinus Torvalds .procname = "bootloader_type", 6771da177e4SLinus Torvalds .data = &bootloader_type, 6781da177e4SLinus Torvalds .maxlen = sizeof (int), 6791da177e4SLinus Torvalds .mode = 0444, 6801da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 6811da177e4SLinus Torvalds }, 6820741f4d2SChuck Ebbert { 6830741f4d2SChuck Ebbert .ctl_name = CTL_UNNUMBERED, 6840741f4d2SChuck Ebbert .procname = "kstack_depth_to_print", 6850741f4d2SChuck Ebbert .data = &kstack_depth_to_print, 6860741f4d2SChuck Ebbert .maxlen = sizeof(int), 6870741f4d2SChuck Ebbert .mode = 0644, 6880741f4d2SChuck Ebbert .proc_handler = &proc_dointvec, 6890741f4d2SChuck Ebbert }, 6906e7c4025SIngo Molnar { 6916e7c4025SIngo Molnar .ctl_name = CTL_UNNUMBERED, 6926e7c4025SIngo Molnar .procname = "io_delay_type", 6936e7c4025SIngo Molnar .data = &io_delay_type, 6946e7c4025SIngo Molnar .maxlen = sizeof(int), 6956e7c4025SIngo Molnar .mode = 0644, 6966e7c4025SIngo Molnar .proc_handler = &proc_dointvec, 6976e7c4025SIngo Molnar }, 6981da177e4SLinus Torvalds #endif 6997a9166e3SLuke Yang #if defined(CONFIG_MMU) 7001da177e4SLinus Torvalds { 7011da177e4SLinus Torvalds .ctl_name = KERN_RANDOMIZE, 7021da177e4SLinus Torvalds .procname = "randomize_va_space", 7031da177e4SLinus Torvalds .data = &randomize_va_space, 7041da177e4SLinus Torvalds .maxlen = sizeof(int), 7051da177e4SLinus Torvalds .mode = 0644, 7061da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 7071da177e4SLinus Torvalds }, 7087a9166e3SLuke Yang #endif 7090152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP) 710951f22d5SMartin Schwidefsky { 711951f22d5SMartin Schwidefsky .ctl_name = KERN_SPIN_RETRY, 712951f22d5SMartin Schwidefsky .procname = "spin_retry", 713951f22d5SMartin Schwidefsky .data = &spin_retry, 714951f22d5SMartin Schwidefsky .maxlen = sizeof (int), 715951f22d5SMartin Schwidefsky .mode = 0644, 716951f22d5SMartin Schwidefsky .proc_handler = &proc_dointvec, 717951f22d5SMartin Schwidefsky }, 718951f22d5SMartin Schwidefsky #endif 719673d5b43SLen Brown #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 720c255d844SPavel Machek { 721c255d844SPavel Machek .procname = "acpi_video_flags", 72277afcf78SPavel Machek .data = &acpi_realmode_flags, 723c255d844SPavel Machek .maxlen = sizeof (unsigned long), 724c255d844SPavel Machek .mode = 0644, 7257f99f06fSStefan Seyfried .proc_handler = &proc_doulongvec_minmax, 726c255d844SPavel Machek }, 727c255d844SPavel Machek #endif 728d2b176edSJes Sorensen #ifdef CONFIG_IA64 729d2b176edSJes Sorensen { 730d2b176edSJes Sorensen .ctl_name = KERN_IA64_UNALIGNED, 731d2b176edSJes Sorensen .procname = "ignore-unaligned-usertrap", 732d2b176edSJes Sorensen .data = &no_unaligned_warning, 733d2b176edSJes Sorensen .maxlen = sizeof (int), 734d2b176edSJes Sorensen .mode = 0644, 735d2b176edSJes Sorensen .proc_handler = &proc_dointvec, 736d2b176edSJes Sorensen }, 737d2b176edSJes Sorensen #endif 738c4f3b63fSRavikiran G Thirumalai #ifdef CONFIG_DETECT_SOFTLOCKUP 739c4f3b63fSRavikiran G Thirumalai { 740c4f3b63fSRavikiran G Thirumalai .ctl_name = CTL_UNNUMBERED, 7419c44bc03SIngo Molnar .procname = "softlockup_panic", 7429c44bc03SIngo Molnar .data = &softlockup_panic, 7439c44bc03SIngo Molnar .maxlen = sizeof(int), 7449c44bc03SIngo Molnar .mode = 0644, 7454dca10a9SHiroshi Shimamoto .proc_handler = &proc_dointvec_minmax, 7469c44bc03SIngo Molnar .strategy = &sysctl_intvec, 7479c44bc03SIngo Molnar .extra1 = &zero, 7489c44bc03SIngo Molnar .extra2 = &one, 7499c44bc03SIngo Molnar }, 7509c44bc03SIngo Molnar { 7519c44bc03SIngo Molnar .ctl_name = CTL_UNNUMBERED, 752c4f3b63fSRavikiran G Thirumalai .procname = "softlockup_thresh", 753c4f3b63fSRavikiran G Thirumalai .data = &softlockup_thresh, 7549383d967SDimitri Sivanich .maxlen = sizeof(int), 755c4f3b63fSRavikiran G Thirumalai .mode = 0644, 7569383d967SDimitri Sivanich .proc_handler = &proc_dointvec_minmax, 757c4f3b63fSRavikiran G Thirumalai .strategy = &sysctl_intvec, 7589383d967SDimitri Sivanich .extra1 = &neg_one, 759c4f3b63fSRavikiran G Thirumalai .extra2 = &sixty, 760c4f3b63fSRavikiran G Thirumalai }, 76182a1fcb9SIngo Molnar { 76282a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 76382a1fcb9SIngo Molnar .procname = "hung_task_check_count", 76482a1fcb9SIngo Molnar .data = &sysctl_hung_task_check_count, 76590739081SIngo Molnar .maxlen = sizeof(unsigned long), 76682a1fcb9SIngo Molnar .mode = 0644, 76790739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 76882a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 76982a1fcb9SIngo Molnar }, 77082a1fcb9SIngo Molnar { 77182a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 77282a1fcb9SIngo Molnar .procname = "hung_task_timeout_secs", 77382a1fcb9SIngo Molnar .data = &sysctl_hung_task_timeout_secs, 77490739081SIngo Molnar .maxlen = sizeof(unsigned long), 77582a1fcb9SIngo Molnar .mode = 0644, 77690739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 77782a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 77882a1fcb9SIngo Molnar }, 77982a1fcb9SIngo Molnar { 78082a1fcb9SIngo Molnar .ctl_name = CTL_UNNUMBERED, 78182a1fcb9SIngo Molnar .procname = "hung_task_warnings", 78282a1fcb9SIngo Molnar .data = &sysctl_hung_task_warnings, 78390739081SIngo Molnar .maxlen = sizeof(unsigned long), 78482a1fcb9SIngo Molnar .mode = 0644, 78590739081SIngo Molnar .proc_handler = &proc_doulongvec_minmax, 78682a1fcb9SIngo Molnar .strategy = &sysctl_intvec, 78782a1fcb9SIngo Molnar }, 788c4f3b63fSRavikiran G Thirumalai #endif 789bebfa101SAndi Kleen #ifdef CONFIG_COMPAT 790bebfa101SAndi Kleen { 791bebfa101SAndi Kleen .ctl_name = KERN_COMPAT_LOG, 792bebfa101SAndi Kleen .procname = "compat-log", 793bebfa101SAndi Kleen .data = &compat_log, 794bebfa101SAndi Kleen .maxlen = sizeof (int), 795bebfa101SAndi Kleen .mode = 0644, 796bebfa101SAndi Kleen .proc_handler = &proc_dointvec, 797bebfa101SAndi Kleen }, 798bebfa101SAndi Kleen #endif 79923f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 80023f78d4aSIngo Molnar { 80123f78d4aSIngo Molnar .ctl_name = KERN_MAX_LOCK_DEPTH, 80223f78d4aSIngo Molnar .procname = "max_lock_depth", 80323f78d4aSIngo Molnar .data = &max_lock_depth, 80423f78d4aSIngo Molnar .maxlen = sizeof(int), 80523f78d4aSIngo Molnar .mode = 0644, 80623f78d4aSIngo Molnar .proc_handler = &proc_dointvec, 80723f78d4aSIngo Molnar }, 80823f78d4aSIngo Molnar #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", 950e5ff2159SAndi Kleen .data = NULL, 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", 976e5ff2159SAndi Kleen .data = NULL, 977e5ff2159SAndi Kleen .maxlen = sizeof(unsigned long), 978d1c3fb1fSNishanth Aravamudan .mode = 0644, 979a3d0c6aaSNishanth Aravamudan .proc_handler = &hugetlb_overcommit_handler, 980e5ff2159SAndi Kleen .extra1 = (void *)&hugetlb_zero, 981e5ff2159SAndi Kleen .extra2 = (void *)&hugetlb_infinity, 982d1c3fb1fSNishanth Aravamudan }, 9831da177e4SLinus Torvalds #endif 9841da177e4SLinus Torvalds { 9851da177e4SLinus Torvalds .ctl_name = VM_LOWMEM_RESERVE_RATIO, 9861da177e4SLinus Torvalds .procname = "lowmem_reserve_ratio", 9871da177e4SLinus Torvalds .data = &sysctl_lowmem_reserve_ratio, 9881da177e4SLinus Torvalds .maxlen = sizeof(sysctl_lowmem_reserve_ratio), 9891da177e4SLinus Torvalds .mode = 0644, 9901da177e4SLinus Torvalds .proc_handler = &lowmem_reserve_ratio_sysctl_handler, 9911da177e4SLinus Torvalds .strategy = &sysctl_intvec, 9921da177e4SLinus Torvalds }, 9931da177e4SLinus Torvalds { 9949d0243bcSAndrew Morton .ctl_name = VM_DROP_PAGECACHE, 9959d0243bcSAndrew Morton .procname = "drop_caches", 9969d0243bcSAndrew Morton .data = &sysctl_drop_caches, 9979d0243bcSAndrew Morton .maxlen = sizeof(int), 9989d0243bcSAndrew Morton .mode = 0644, 9999d0243bcSAndrew Morton .proc_handler = drop_caches_sysctl_handler, 10009d0243bcSAndrew Morton .strategy = &sysctl_intvec, 10019d0243bcSAndrew Morton }, 10029d0243bcSAndrew Morton { 10031da177e4SLinus Torvalds .ctl_name = VM_MIN_FREE_KBYTES, 10041da177e4SLinus Torvalds .procname = "min_free_kbytes", 10051da177e4SLinus Torvalds .data = &min_free_kbytes, 10061da177e4SLinus Torvalds .maxlen = sizeof(min_free_kbytes), 10071da177e4SLinus Torvalds .mode = 0644, 10081da177e4SLinus Torvalds .proc_handler = &min_free_kbytes_sysctl_handler, 10091da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10101da177e4SLinus Torvalds .extra1 = &zero, 10111da177e4SLinus Torvalds }, 10128ad4b1fbSRohit Seth { 10138ad4b1fbSRohit Seth .ctl_name = VM_PERCPU_PAGELIST_FRACTION, 10148ad4b1fbSRohit Seth .procname = "percpu_pagelist_fraction", 10158ad4b1fbSRohit Seth .data = &percpu_pagelist_fraction, 10168ad4b1fbSRohit Seth .maxlen = sizeof(percpu_pagelist_fraction), 10178ad4b1fbSRohit Seth .mode = 0644, 10188ad4b1fbSRohit Seth .proc_handler = &percpu_pagelist_fraction_sysctl_handler, 10198ad4b1fbSRohit Seth .strategy = &sysctl_intvec, 10208ad4b1fbSRohit Seth .extra1 = &min_percpu_pagelist_fract, 10218ad4b1fbSRohit Seth }, 10221da177e4SLinus Torvalds #ifdef CONFIG_MMU 10231da177e4SLinus Torvalds { 10241da177e4SLinus Torvalds .ctl_name = VM_MAX_MAP_COUNT, 10251da177e4SLinus Torvalds .procname = "max_map_count", 10261da177e4SLinus Torvalds .data = &sysctl_max_map_count, 10271da177e4SLinus Torvalds .maxlen = sizeof(sysctl_max_map_count), 10281da177e4SLinus Torvalds .mode = 0644, 10291da177e4SLinus Torvalds .proc_handler = &proc_dointvec 10301da177e4SLinus Torvalds }, 10311da177e4SLinus Torvalds #endif 10321da177e4SLinus Torvalds { 10331da177e4SLinus Torvalds .ctl_name = VM_LAPTOP_MODE, 10341da177e4SLinus Torvalds .procname = "laptop_mode", 10351da177e4SLinus Torvalds .data = &laptop_mode, 10361da177e4SLinus Torvalds .maxlen = sizeof(laptop_mode), 10371da177e4SLinus Torvalds .mode = 0644, 1038ed5b43f1SBart Samwel .proc_handler = &proc_dointvec_jiffies, 1039ed5b43f1SBart Samwel .strategy = &sysctl_jiffies, 10401da177e4SLinus Torvalds }, 10411da177e4SLinus Torvalds { 10421da177e4SLinus Torvalds .ctl_name = VM_BLOCK_DUMP, 10431da177e4SLinus Torvalds .procname = "block_dump", 10441da177e4SLinus Torvalds .data = &block_dump, 10451da177e4SLinus Torvalds .maxlen = sizeof(block_dump), 10461da177e4SLinus Torvalds .mode = 0644, 10471da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10481da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10491da177e4SLinus Torvalds .extra1 = &zero, 10501da177e4SLinus Torvalds }, 10511da177e4SLinus Torvalds { 10521da177e4SLinus Torvalds .ctl_name = VM_VFS_CACHE_PRESSURE, 10531da177e4SLinus Torvalds .procname = "vfs_cache_pressure", 10541da177e4SLinus Torvalds .data = &sysctl_vfs_cache_pressure, 10551da177e4SLinus Torvalds .maxlen = sizeof(sysctl_vfs_cache_pressure), 10561da177e4SLinus Torvalds .mode = 0644, 10571da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10581da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10591da177e4SLinus Torvalds .extra1 = &zero, 10601da177e4SLinus Torvalds }, 10611da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 10621da177e4SLinus Torvalds { 10631da177e4SLinus Torvalds .ctl_name = VM_LEGACY_VA_LAYOUT, 10641da177e4SLinus Torvalds .procname = "legacy_va_layout", 10651da177e4SLinus Torvalds .data = &sysctl_legacy_va_layout, 10661da177e4SLinus Torvalds .maxlen = sizeof(sysctl_legacy_va_layout), 10671da177e4SLinus Torvalds .mode = 0644, 10681da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 10691da177e4SLinus Torvalds .strategy = &sysctl_intvec, 10701da177e4SLinus Torvalds .extra1 = &zero, 10711da177e4SLinus Torvalds }, 10721da177e4SLinus Torvalds #endif 10731743660bSChristoph Lameter #ifdef CONFIG_NUMA 10741743660bSChristoph Lameter { 10751743660bSChristoph Lameter .ctl_name = VM_ZONE_RECLAIM_MODE, 10761743660bSChristoph Lameter .procname = "zone_reclaim_mode", 10771743660bSChristoph Lameter .data = &zone_reclaim_mode, 10781743660bSChristoph Lameter .maxlen = sizeof(zone_reclaim_mode), 10791743660bSChristoph Lameter .mode = 0644, 10801743660bSChristoph Lameter .proc_handler = &proc_dointvec, 1081c84db23cSChristoph Lameter .strategy = &sysctl_intvec, 1082c84db23cSChristoph Lameter .extra1 = &zero, 10831743660bSChristoph Lameter }, 10849614634fSChristoph Lameter { 10859614634fSChristoph Lameter .ctl_name = VM_MIN_UNMAPPED, 10869614634fSChristoph Lameter .procname = "min_unmapped_ratio", 10879614634fSChristoph Lameter .data = &sysctl_min_unmapped_ratio, 10889614634fSChristoph Lameter .maxlen = sizeof(sysctl_min_unmapped_ratio), 10899614634fSChristoph Lameter .mode = 0644, 10909614634fSChristoph Lameter .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler, 10919614634fSChristoph Lameter .strategy = &sysctl_intvec, 10929614634fSChristoph Lameter .extra1 = &zero, 10939614634fSChristoph Lameter .extra2 = &one_hundred, 10949614634fSChristoph Lameter }, 10950ff38490SChristoph Lameter { 10960ff38490SChristoph Lameter .ctl_name = VM_MIN_SLAB, 10970ff38490SChristoph Lameter .procname = "min_slab_ratio", 10980ff38490SChristoph Lameter .data = &sysctl_min_slab_ratio, 10990ff38490SChristoph Lameter .maxlen = sizeof(sysctl_min_slab_ratio), 11000ff38490SChristoph Lameter .mode = 0644, 11010ff38490SChristoph Lameter .proc_handler = &sysctl_min_slab_ratio_sysctl_handler, 11020ff38490SChristoph Lameter .strategy = &sysctl_intvec, 11030ff38490SChristoph Lameter .extra1 = &zero, 11040ff38490SChristoph Lameter .extra2 = &one_hundred, 11050ff38490SChristoph Lameter }, 11061743660bSChristoph Lameter #endif 110777461ab3SChristoph Lameter #ifdef CONFIG_SMP 110877461ab3SChristoph Lameter { 110977461ab3SChristoph Lameter .ctl_name = CTL_UNNUMBERED, 111077461ab3SChristoph Lameter .procname = "stat_interval", 111177461ab3SChristoph Lameter .data = &sysctl_stat_interval, 111277461ab3SChristoph Lameter .maxlen = sizeof(sysctl_stat_interval), 111377461ab3SChristoph Lameter .mode = 0644, 111477461ab3SChristoph Lameter .proc_handler = &proc_dointvec_jiffies, 111577461ab3SChristoph Lameter .strategy = &sysctl_jiffies, 111677461ab3SChristoph Lameter }, 111777461ab3SChristoph Lameter #endif 1118ed032189SEric Paris #ifdef CONFIG_SECURITY 1119ed032189SEric Paris { 1120ed032189SEric Paris .ctl_name = CTL_UNNUMBERED, 1121ed032189SEric Paris .procname = "mmap_min_addr", 1122ed032189SEric Paris .data = &mmap_min_addr, 1123ed032189SEric Paris .maxlen = sizeof(unsigned long), 1124ed032189SEric Paris .mode = 0644, 1125ed032189SEric Paris .proc_handler = &proc_doulongvec_minmax, 1126ed032189SEric Paris }, 11278daec965SLee Schermerhorn #endif 1128f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA 1129f0c0b2b8SKAMEZAWA Hiroyuki { 1130f0c0b2b8SKAMEZAWA Hiroyuki .ctl_name = CTL_UNNUMBERED, 1131f0c0b2b8SKAMEZAWA Hiroyuki .procname = "numa_zonelist_order", 1132f0c0b2b8SKAMEZAWA Hiroyuki .data = &numa_zonelist_order, 1133f0c0b2b8SKAMEZAWA Hiroyuki .maxlen = NUMA_ZONELIST_ORDER_LEN, 1134f0c0b2b8SKAMEZAWA Hiroyuki .mode = 0644, 1135f0c0b2b8SKAMEZAWA Hiroyuki .proc_handler = &numa_zonelist_order_handler, 1136f0c0b2b8SKAMEZAWA Hiroyuki .strategy = &sysctl_string, 1137f0c0b2b8SKAMEZAWA Hiroyuki }, 1138f0c0b2b8SKAMEZAWA Hiroyuki #endif 11392b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 11405c36e657SPaul Mundt (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 1141e6e5494cSIngo Molnar { 1142e6e5494cSIngo Molnar .ctl_name = VM_VDSO_ENABLED, 1143e6e5494cSIngo Molnar .procname = "vdso_enabled", 1144e6e5494cSIngo Molnar .data = &vdso_enabled, 1145e6e5494cSIngo Molnar .maxlen = sizeof(vdso_enabled), 1146e6e5494cSIngo Molnar .mode = 0644, 1147e6e5494cSIngo Molnar .proc_handler = &proc_dointvec, 1148e6e5494cSIngo Molnar .strategy = &sysctl_intvec, 1149e6e5494cSIngo Molnar .extra1 = &zero, 1150e6e5494cSIngo Molnar }, 1151e6e5494cSIngo Molnar #endif 1152195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM 1153195cf453SBron Gondwana { 1154195cf453SBron Gondwana .ctl_name = CTL_UNNUMBERED, 1155195cf453SBron Gondwana .procname = "highmem_is_dirtyable", 1156195cf453SBron Gondwana .data = &vm_highmem_is_dirtyable, 1157195cf453SBron Gondwana .maxlen = sizeof(vm_highmem_is_dirtyable), 1158195cf453SBron Gondwana .mode = 0644, 1159195cf453SBron Gondwana .proc_handler = &proc_dointvec_minmax, 1160195cf453SBron Gondwana .strategy = &sysctl_intvec, 1161195cf453SBron Gondwana .extra1 = &zero, 1162195cf453SBron Gondwana .extra2 = &one, 1163195cf453SBron Gondwana }, 1164195cf453SBron Gondwana #endif 11652be7fe07SAndrew Morton /* 11662be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 11672be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 11682be7fe07SAndrew Morton */ 11691da177e4SLinus Torvalds { .ctl_name = 0 } 11701da177e4SLinus Torvalds }; 11711da177e4SLinus Torvalds 11722abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1173d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = { 11742abc26fcSEric W. Biederman { .ctl_name = 0 } 11752abc26fcSEric W. Biederman }; 11762abc26fcSEric W. Biederman #endif 11772abc26fcSEric W. Biederman 1178d8217f07SEric W. Biederman static struct ctl_table fs_table[] = { 11791da177e4SLinus Torvalds { 11801da177e4SLinus Torvalds .ctl_name = FS_NRINODE, 11811da177e4SLinus Torvalds .procname = "inode-nr", 11821da177e4SLinus Torvalds .data = &inodes_stat, 11831da177e4SLinus Torvalds .maxlen = 2*sizeof(int), 11841da177e4SLinus Torvalds .mode = 0444, 11851da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 11861da177e4SLinus Torvalds }, 11871da177e4SLinus Torvalds { 11881da177e4SLinus Torvalds .ctl_name = FS_STATINODE, 11891da177e4SLinus Torvalds .procname = "inode-state", 11901da177e4SLinus Torvalds .data = &inodes_stat, 11911da177e4SLinus Torvalds .maxlen = 7*sizeof(int), 11921da177e4SLinus Torvalds .mode = 0444, 11931da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 11941da177e4SLinus Torvalds }, 11951da177e4SLinus Torvalds { 11961da177e4SLinus Torvalds .procname = "file-nr", 11971da177e4SLinus Torvalds .data = &files_stat, 11981da177e4SLinus Torvalds .maxlen = 3*sizeof(int), 11991da177e4SLinus Torvalds .mode = 0444, 1200529bf6beSDipankar Sarma .proc_handler = &proc_nr_files, 12011da177e4SLinus Torvalds }, 12021da177e4SLinus Torvalds { 12031da177e4SLinus Torvalds .ctl_name = FS_MAXFILE, 12041da177e4SLinus Torvalds .procname = "file-max", 12051da177e4SLinus Torvalds .data = &files_stat.max_files, 12061da177e4SLinus Torvalds .maxlen = sizeof(int), 12071da177e4SLinus Torvalds .mode = 0644, 12081da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12091da177e4SLinus Torvalds }, 12101da177e4SLinus Torvalds { 12119cfe015aSEric Dumazet .ctl_name = CTL_UNNUMBERED, 12129cfe015aSEric Dumazet .procname = "nr_open", 12139cfe015aSEric Dumazet .data = &sysctl_nr_open, 12149cfe015aSEric Dumazet .maxlen = sizeof(int), 12159cfe015aSEric Dumazet .mode = 0644, 1216eceea0b3SAl Viro .proc_handler = &proc_dointvec_minmax, 1217eceea0b3SAl Viro .extra1 = &sysctl_nr_open_min, 1218eceea0b3SAl Viro .extra2 = &sysctl_nr_open_max, 12199cfe015aSEric Dumazet }, 12209cfe015aSEric Dumazet { 12211da177e4SLinus Torvalds .ctl_name = FS_DENTRY, 12221da177e4SLinus Torvalds .procname = "dentry-state", 12231da177e4SLinus Torvalds .data = &dentry_stat, 12241da177e4SLinus Torvalds .maxlen = 6*sizeof(int), 12251da177e4SLinus Torvalds .mode = 0444, 12261da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12271da177e4SLinus Torvalds }, 12281da177e4SLinus Torvalds { 12291da177e4SLinus Torvalds .ctl_name = FS_OVERFLOWUID, 12301da177e4SLinus Torvalds .procname = "overflowuid", 12311da177e4SLinus Torvalds .data = &fs_overflowuid, 12321da177e4SLinus Torvalds .maxlen = sizeof(int), 12331da177e4SLinus Torvalds .mode = 0644, 12341da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 12351da177e4SLinus Torvalds .strategy = &sysctl_intvec, 12361da177e4SLinus Torvalds .extra1 = &minolduid, 12371da177e4SLinus Torvalds .extra2 = &maxolduid, 12381da177e4SLinus Torvalds }, 12391da177e4SLinus Torvalds { 12401da177e4SLinus Torvalds .ctl_name = FS_OVERFLOWGID, 12411da177e4SLinus Torvalds .procname = "overflowgid", 12421da177e4SLinus Torvalds .data = &fs_overflowgid, 12431da177e4SLinus Torvalds .maxlen = sizeof(int), 12441da177e4SLinus Torvalds .mode = 0644, 12451da177e4SLinus Torvalds .proc_handler = &proc_dointvec_minmax, 12461da177e4SLinus Torvalds .strategy = &sysctl_intvec, 12471da177e4SLinus Torvalds .extra1 = &minolduid, 12481da177e4SLinus Torvalds .extra2 = &maxolduid, 12491da177e4SLinus Torvalds }, 1250bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING 12511da177e4SLinus Torvalds { 12521da177e4SLinus Torvalds .ctl_name = FS_LEASES, 12531da177e4SLinus Torvalds .procname = "leases-enable", 12541da177e4SLinus Torvalds .data = &leases_enable, 12551da177e4SLinus Torvalds .maxlen = sizeof(int), 12561da177e4SLinus Torvalds .mode = 0644, 12571da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12581da177e4SLinus Torvalds }, 1259bfcd17a6SThomas Petazzoni #endif 12601da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY 12611da177e4SLinus Torvalds { 12621da177e4SLinus Torvalds .ctl_name = FS_DIR_NOTIFY, 12631da177e4SLinus Torvalds .procname = "dir-notify-enable", 12641da177e4SLinus Torvalds .data = &dir_notify_enable, 12651da177e4SLinus Torvalds .maxlen = sizeof(int), 12661da177e4SLinus Torvalds .mode = 0644, 12671da177e4SLinus Torvalds .proc_handler = &proc_dointvec, 12681da177e4SLinus Torvalds }, 12691da177e4SLinus Torvalds #endif 12701da177e4SLinus Torvalds #ifdef CONFIG_MMU 1271bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING 12721da177e4SLinus Torvalds { 12731da177e4SLinus Torvalds .ctl_name = FS_LEASE_TIME, 12741da177e4SLinus Torvalds .procname = "lease-break-time", 12751da177e4SLinus Torvalds .data = &lease_break_time, 12761da177e4SLinus Torvalds .maxlen = sizeof(int), 12771da177e4SLinus Torvalds .mode = 0644, 127876fdbb25SKawai, Hidehiro .proc_handler = &proc_dointvec_minmax, 127976fdbb25SKawai, Hidehiro .strategy = &sysctl_intvec, 128076fdbb25SKawai, Hidehiro .extra1 = &zero, 128176fdbb25SKawai, Hidehiro .extra2 = &two, 12821da177e4SLinus Torvalds }, 1283bfcd17a6SThomas Petazzoni #endif 1284ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO 12851da177e4SLinus Torvalds { 12861da177e4SLinus Torvalds .procname = "aio-nr", 12871da177e4SLinus Torvalds .data = &aio_nr, 12881da177e4SLinus Torvalds .maxlen = sizeof(aio_nr), 12891da177e4SLinus Torvalds .mode = 0444, 1290d55b5fdaSZach Brown .proc_handler = &proc_doulongvec_minmax, 12911da177e4SLinus Torvalds }, 12921da177e4SLinus Torvalds { 12931da177e4SLinus Torvalds .procname = "aio-max-nr", 12941da177e4SLinus Torvalds .data = &aio_max_nr, 12951da177e4SLinus Torvalds .maxlen = sizeof(aio_max_nr), 12961da177e4SLinus Torvalds .mode = 0644, 1297d55b5fdaSZach Brown .proc_handler = &proc_doulongvec_minmax, 12981da177e4SLinus Torvalds }, 1299ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */ 13002d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 13010399cb08SRobert Love { 13020399cb08SRobert Love .ctl_name = FS_INOTIFY, 13030399cb08SRobert Love .procname = "inotify", 13040399cb08SRobert Love .mode = 0555, 13050399cb08SRobert Love .child = inotify_table, 13060399cb08SRobert Love }, 13070399cb08SRobert Love #endif 13081da177e4SLinus Torvalds #endif 1309d6e71144SAlan Cox { 1310d6e71144SAlan Cox .ctl_name = KERN_SETUID_DUMPABLE, 1311d6e71144SAlan Cox .procname = "suid_dumpable", 1312d6e71144SAlan Cox .data = &suid_dumpable, 1313d6e71144SAlan Cox .maxlen = sizeof(int), 1314d6e71144SAlan Cox .mode = 0644, 1315d6e71144SAlan Cox .proc_handler = &proc_dointvec, 1316d6e71144SAlan Cox }, 13172abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 13182abc26fcSEric W. Biederman { 13192abc26fcSEric W. Biederman .ctl_name = CTL_UNNUMBERED, 13202abc26fcSEric W. Biederman .procname = "binfmt_misc", 13212abc26fcSEric W. Biederman .mode = 0555, 13222abc26fcSEric W. Biederman .child = binfmt_misc_table, 13232abc26fcSEric W. Biederman }, 13242abc26fcSEric W. Biederman #endif 13252be7fe07SAndrew Morton /* 13262be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 13272be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 13282be7fe07SAndrew Morton */ 13291da177e4SLinus Torvalds { .ctl_name = 0 } 13301da177e4SLinus Torvalds }; 13311da177e4SLinus Torvalds 1332d8217f07SEric W. Biederman static struct ctl_table debug_table[] = { 1333d0c3d534SOlof Johansson #if defined(CONFIG_X86) || defined(CONFIG_PPC) 1334abd4f750SMasoud Asgharifard Sharbiani { 1335abd4f750SMasoud Asgharifard Sharbiani .ctl_name = CTL_UNNUMBERED, 1336abd4f750SMasoud Asgharifard Sharbiani .procname = "exception-trace", 1337abd4f750SMasoud Asgharifard Sharbiani .data = &show_unhandled_signals, 1338abd4f750SMasoud Asgharifard Sharbiani .maxlen = sizeof(int), 1339abd4f750SMasoud Asgharifard Sharbiani .mode = 0644, 1340abd4f750SMasoud Asgharifard Sharbiani .proc_handler = proc_dointvec 1341abd4f750SMasoud Asgharifard Sharbiani }, 1342abd4f750SMasoud Asgharifard Sharbiani #endif 13431da177e4SLinus Torvalds { .ctl_name = 0 } 13441da177e4SLinus Torvalds }; 13451da177e4SLinus Torvalds 1346d8217f07SEric W. Biederman static struct ctl_table dev_table[] = { 13471da177e4SLinus Torvalds { .ctl_name = 0 } 13481da177e4SLinus Torvalds }; 13491da177e4SLinus Torvalds 1350330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock); 1351330d57fbSAl Viro 1352330d57fbSAl Viro /* called under sysctl_lock */ 1353330d57fbSAl Viro static int use_table(struct ctl_table_header *p) 1354330d57fbSAl Viro { 1355330d57fbSAl Viro if (unlikely(p->unregistering)) 1356330d57fbSAl Viro return 0; 1357330d57fbSAl Viro p->used++; 1358330d57fbSAl Viro return 1; 1359330d57fbSAl Viro } 1360330d57fbSAl Viro 1361330d57fbSAl Viro /* called under sysctl_lock */ 1362330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p) 1363330d57fbSAl Viro { 1364330d57fbSAl Viro if (!--p->used) 1365330d57fbSAl Viro if (unlikely(p->unregistering)) 1366330d57fbSAl Viro complete(p->unregistering); 1367330d57fbSAl Viro } 1368330d57fbSAl Viro 1369330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */ 1370330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p) 1371330d57fbSAl Viro { 1372330d57fbSAl Viro /* 1373330d57fbSAl Viro * if p->used is 0, nobody will ever touch that entry again; 1374330d57fbSAl Viro * we'll eliminate all paths to it before dropping sysctl_lock 1375330d57fbSAl Viro */ 1376330d57fbSAl Viro if (unlikely(p->used)) { 1377330d57fbSAl Viro struct completion wait; 1378330d57fbSAl Viro init_completion(&wait); 1379330d57fbSAl Viro p->unregistering = &wait; 1380330d57fbSAl Viro spin_unlock(&sysctl_lock); 1381330d57fbSAl Viro wait_for_completion(&wait); 1382330d57fbSAl Viro spin_lock(&sysctl_lock); 1383f7e6ced4SAl Viro } else { 1384f7e6ced4SAl Viro /* anything non-NULL; we'll never dereference it */ 1385f7e6ced4SAl Viro p->unregistering = ERR_PTR(-EINVAL); 1386330d57fbSAl Viro } 1387330d57fbSAl Viro /* 1388330d57fbSAl Viro * do not remove from the list until nobody holds it; walking the 1389330d57fbSAl Viro * list in do_sysctl() relies on that. 1390330d57fbSAl Viro */ 1391330d57fbSAl Viro list_del_init(&p->ctl_entry); 1392330d57fbSAl Viro } 1393330d57fbSAl Viro 1394f7e6ced4SAl Viro void sysctl_head_get(struct ctl_table_header *head) 1395f7e6ced4SAl Viro { 1396f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1397f7e6ced4SAl Viro head->count++; 1398f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1399f7e6ced4SAl Viro } 1400f7e6ced4SAl Viro 1401f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head) 1402f7e6ced4SAl Viro { 1403f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1404f7e6ced4SAl Viro if (!--head->count) 1405f7e6ced4SAl Viro kfree(head); 1406f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1407f7e6ced4SAl Viro } 1408f7e6ced4SAl Viro 1409f7e6ced4SAl Viro struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) 1410f7e6ced4SAl Viro { 1411f7e6ced4SAl Viro if (!head) 1412f7e6ced4SAl Viro BUG(); 1413f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1414f7e6ced4SAl Viro if (!use_table(head)) 1415f7e6ced4SAl Viro head = ERR_PTR(-ENOENT); 1416f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1417f7e6ced4SAl Viro return head; 1418f7e6ced4SAl Viro } 1419f7e6ced4SAl Viro 1420805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head) 1421805b5d5eSEric W. Biederman { 1422805b5d5eSEric W. Biederman if (!head) 1423805b5d5eSEric W. Biederman return; 1424805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1425805b5d5eSEric W. Biederman unuse_table(head); 1426805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1427805b5d5eSEric W. Biederman } 1428805b5d5eSEric W. Biederman 142973455092SAl Viro static struct ctl_table_set * 143073455092SAl Viro lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) 143173455092SAl Viro { 143273455092SAl Viro struct ctl_table_set *set = &root->default_set; 143373455092SAl Viro if (root->lookup) 143473455092SAl Viro set = root->lookup(root, namespaces); 143573455092SAl Viro return set; 143673455092SAl Viro } 143773455092SAl Viro 1438e51b6ba0SEric W. Biederman static struct list_head * 1439e51b6ba0SEric W. Biederman lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) 1440805b5d5eSEric W. Biederman { 144173455092SAl Viro struct ctl_table_set *set = lookup_header_set(root, namespaces); 144273455092SAl Viro return &set->list; 1443e51b6ba0SEric W. Biederman } 1444e51b6ba0SEric W. Biederman 1445e51b6ba0SEric W. Biederman struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, 1446e51b6ba0SEric W. Biederman struct ctl_table_header *prev) 1447e51b6ba0SEric W. Biederman { 1448e51b6ba0SEric W. Biederman struct ctl_table_root *root; 1449e51b6ba0SEric W. Biederman struct list_head *header_list; 1450805b5d5eSEric W. Biederman struct ctl_table_header *head; 1451805b5d5eSEric W. Biederman struct list_head *tmp; 1452e51b6ba0SEric W. Biederman 1453805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1454805b5d5eSEric W. Biederman if (prev) { 1455e51b6ba0SEric W. Biederman head = prev; 1456805b5d5eSEric W. Biederman tmp = &prev->ctl_entry; 1457805b5d5eSEric W. Biederman unuse_table(prev); 1458805b5d5eSEric W. Biederman goto next; 1459805b5d5eSEric W. Biederman } 1460805b5d5eSEric W. Biederman tmp = &root_table_header.ctl_entry; 1461805b5d5eSEric W. Biederman for (;;) { 1462805b5d5eSEric W. Biederman head = list_entry(tmp, struct ctl_table_header, ctl_entry); 1463805b5d5eSEric W. Biederman 1464805b5d5eSEric W. Biederman if (!use_table(head)) 1465805b5d5eSEric W. Biederman goto next; 1466805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1467805b5d5eSEric W. Biederman return head; 1468805b5d5eSEric W. Biederman next: 1469e51b6ba0SEric W. Biederman root = head->root; 1470805b5d5eSEric W. Biederman tmp = tmp->next; 1471e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1472e51b6ba0SEric W. Biederman if (tmp != header_list) 1473e51b6ba0SEric W. Biederman continue; 1474e51b6ba0SEric W. Biederman 1475e51b6ba0SEric W. Biederman do { 1476e51b6ba0SEric W. Biederman root = list_entry(root->root_list.next, 1477e51b6ba0SEric W. Biederman struct ctl_table_root, root_list); 1478e51b6ba0SEric W. Biederman if (root == &sysctl_table_root) 1479e51b6ba0SEric W. Biederman goto out; 1480e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1481e51b6ba0SEric W. Biederman } while (list_empty(header_list)); 1482e51b6ba0SEric W. Biederman tmp = header_list->next; 1483805b5d5eSEric W. Biederman } 1484e51b6ba0SEric W. Biederman out: 1485805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1486805b5d5eSEric W. Biederman return NULL; 1487805b5d5eSEric W. Biederman } 1488805b5d5eSEric W. Biederman 1489e51b6ba0SEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) 1490e51b6ba0SEric W. Biederman { 1491e51b6ba0SEric W. Biederman return __sysctl_head_next(current->nsproxy, prev); 1492e51b6ba0SEric W. Biederman } 1493e51b6ba0SEric W. Biederman 1494e51b6ba0SEric W. Biederman void register_sysctl_root(struct ctl_table_root *root) 1495e51b6ba0SEric W. Biederman { 1496e51b6ba0SEric W. Biederman spin_lock(&sysctl_lock); 1497e51b6ba0SEric W. Biederman list_add_tail(&root->root_list, &sysctl_table_root.root_list); 1498e51b6ba0SEric W. Biederman spin_unlock(&sysctl_lock); 1499e51b6ba0SEric W. Biederman } 1500e51b6ba0SEric W. Biederman 1501b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 15022c4c7155SPavel Emelyanov /* Perform the actual read/write of a sysctl table entry. */ 1503d7321cd6SPavel Emelyanov static int do_sysctl_strategy(struct ctl_table_root *root, 1504d7321cd6SPavel Emelyanov struct ctl_table *table, 15052c4c7155SPavel Emelyanov void __user *oldval, size_t __user *oldlenp, 15062c4c7155SPavel Emelyanov void __user *newval, size_t newlen) 15072c4c7155SPavel Emelyanov { 15082c4c7155SPavel Emelyanov int op = 0, rc; 15092c4c7155SPavel Emelyanov 15102c4c7155SPavel Emelyanov if (oldval) 1511e6305c43SAl Viro op |= MAY_READ; 15122c4c7155SPavel Emelyanov if (newval) 1513e6305c43SAl Viro op |= MAY_WRITE; 1514d7321cd6SPavel Emelyanov if (sysctl_perm(root, table, op)) 15152c4c7155SPavel Emelyanov return -EPERM; 15162c4c7155SPavel Emelyanov 15172c4c7155SPavel Emelyanov if (table->strategy) { 1518f221e726SAlexey Dobriyan rc = table->strategy(table, oldval, oldlenp, newval, newlen); 15192c4c7155SPavel Emelyanov if (rc < 0) 15202c4c7155SPavel Emelyanov return rc; 15212c4c7155SPavel Emelyanov if (rc > 0) 15222c4c7155SPavel Emelyanov return 0; 15232c4c7155SPavel Emelyanov } 15242c4c7155SPavel Emelyanov 15252c4c7155SPavel Emelyanov /* If there is no strategy routine, or if the strategy returns 15262c4c7155SPavel Emelyanov * zero, proceed with automatic r/w */ 15272c4c7155SPavel Emelyanov if (table->data && table->maxlen) { 1528f221e726SAlexey Dobriyan rc = sysctl_data(table, oldval, oldlenp, newval, newlen); 15292c4c7155SPavel Emelyanov if (rc < 0) 15302c4c7155SPavel Emelyanov return rc; 15312c4c7155SPavel Emelyanov } 15322c4c7155SPavel Emelyanov return 0; 15332c4c7155SPavel Emelyanov } 15342c4c7155SPavel Emelyanov 15352c4c7155SPavel Emelyanov static int parse_table(int __user *name, int nlen, 15362c4c7155SPavel Emelyanov void __user *oldval, size_t __user *oldlenp, 15372c4c7155SPavel Emelyanov void __user *newval, size_t newlen, 1538d7321cd6SPavel Emelyanov struct ctl_table_root *root, 15392c4c7155SPavel Emelyanov struct ctl_table *table) 15402c4c7155SPavel Emelyanov { 15412c4c7155SPavel Emelyanov int n; 15422c4c7155SPavel Emelyanov repeat: 15432c4c7155SPavel Emelyanov if (!nlen) 15442c4c7155SPavel Emelyanov return -ENOTDIR; 15452c4c7155SPavel Emelyanov if (get_user(n, name)) 15462c4c7155SPavel Emelyanov return -EFAULT; 15472c4c7155SPavel Emelyanov for ( ; table->ctl_name || table->procname; table++) { 15482c4c7155SPavel Emelyanov if (!table->ctl_name) 15492c4c7155SPavel Emelyanov continue; 15502c4c7155SPavel Emelyanov if (n == table->ctl_name) { 15512c4c7155SPavel Emelyanov int error; 15522c4c7155SPavel Emelyanov if (table->child) { 1553e6305c43SAl Viro if (sysctl_perm(root, table, MAY_EXEC)) 15542c4c7155SPavel Emelyanov return -EPERM; 15552c4c7155SPavel Emelyanov name++; 15562c4c7155SPavel Emelyanov nlen--; 15572c4c7155SPavel Emelyanov table = table->child; 15582c4c7155SPavel Emelyanov goto repeat; 15592c4c7155SPavel Emelyanov } 1560f221e726SAlexey Dobriyan error = do_sysctl_strategy(root, table, 15612c4c7155SPavel Emelyanov oldval, oldlenp, 15622c4c7155SPavel Emelyanov newval, newlen); 15632c4c7155SPavel Emelyanov return error; 15642c4c7155SPavel Emelyanov } 15652c4c7155SPavel Emelyanov } 15662c4c7155SPavel Emelyanov return -ENOTDIR; 15672c4c7155SPavel Emelyanov } 15682c4c7155SPavel Emelyanov 15691da177e4SLinus Torvalds int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, 15701da177e4SLinus Torvalds void __user *newval, size_t newlen) 15711da177e4SLinus Torvalds { 1572805b5d5eSEric W. Biederman struct ctl_table_header *head; 1573330d57fbSAl Viro int error = -ENOTDIR; 15741da177e4SLinus Torvalds 15751da177e4SLinus Torvalds if (nlen <= 0 || nlen >= CTL_MAXNAME) 15761da177e4SLinus Torvalds return -ENOTDIR; 15771da177e4SLinus Torvalds if (oldval) { 15781da177e4SLinus Torvalds int old_len; 15791da177e4SLinus Torvalds if (!oldlenp || get_user(old_len, oldlenp)) 15801da177e4SLinus Torvalds return -EFAULT; 15811da177e4SLinus Torvalds } 1582330d57fbSAl Viro 1583805b5d5eSEric W. Biederman for (head = sysctl_head_next(NULL); head; 1584805b5d5eSEric W. Biederman head = sysctl_head_next(head)) { 1585330d57fbSAl Viro error = parse_table(name, nlen, oldval, oldlenp, 1586d7321cd6SPavel Emelyanov newval, newlen, 1587d7321cd6SPavel Emelyanov head->root, head->ctl_table); 1588805b5d5eSEric W. Biederman if (error != -ENOTDIR) { 1589805b5d5eSEric W. Biederman sysctl_head_finish(head); 1590330d57fbSAl Viro break; 1591805b5d5eSEric W. Biederman } 1592805b5d5eSEric W. Biederman } 15931da177e4SLinus Torvalds return error; 15941da177e4SLinus Torvalds } 15951da177e4SLinus Torvalds 15961da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args) 15971da177e4SLinus Torvalds { 15981da177e4SLinus Torvalds struct __sysctl_args tmp; 15991da177e4SLinus Torvalds int error; 16001da177e4SLinus Torvalds 16011da177e4SLinus Torvalds if (copy_from_user(&tmp, args, sizeof(tmp))) 16021da177e4SLinus Torvalds return -EFAULT; 16031da177e4SLinus Torvalds 16047058cb02SEric W. Biederman error = deprecated_sysctl_warning(&tmp); 16057058cb02SEric W. Biederman if (error) 16067058cb02SEric W. Biederman goto out; 16077058cb02SEric W. Biederman 16081da177e4SLinus Torvalds lock_kernel(); 16091da177e4SLinus Torvalds error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp, 16101da177e4SLinus Torvalds tmp.newval, tmp.newlen); 16111da177e4SLinus Torvalds unlock_kernel(); 16127058cb02SEric W. Biederman out: 16131da177e4SLinus Torvalds return error; 16141da177e4SLinus Torvalds } 1615b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */ 16161da177e4SLinus Torvalds 16171da177e4SLinus Torvalds /* 16181ff007ebSEric W. Biederman * sysctl_perm does NOT grant the superuser all rights automatically, because 16191da177e4SLinus Torvalds * some sysctl variables are readonly even to root. 16201da177e4SLinus Torvalds */ 16211da177e4SLinus Torvalds 16221da177e4SLinus Torvalds static int test_perm(int mode, int op) 16231da177e4SLinus Torvalds { 16241da177e4SLinus Torvalds if (!current->euid) 16251da177e4SLinus Torvalds mode >>= 6; 16261da177e4SLinus Torvalds else if (in_egroup_p(0)) 16271da177e4SLinus Torvalds mode >>= 3; 1628e6305c43SAl Viro if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0) 16291da177e4SLinus Torvalds return 0; 16301da177e4SLinus Torvalds return -EACCES; 16311da177e4SLinus Torvalds } 16321da177e4SLinus Torvalds 1633d7321cd6SPavel Emelyanov int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) 16341da177e4SLinus Torvalds { 16351da177e4SLinus Torvalds int error; 1636d7321cd6SPavel Emelyanov int mode; 1637d7321cd6SPavel Emelyanov 1638e6305c43SAl Viro error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC)); 16391da177e4SLinus Torvalds if (error) 16401da177e4SLinus Torvalds return error; 1641d7321cd6SPavel Emelyanov 1642d7321cd6SPavel Emelyanov if (root->permissions) 1643d7321cd6SPavel Emelyanov mode = root->permissions(root, current->nsproxy, table); 1644d7321cd6SPavel Emelyanov else 1645d7321cd6SPavel Emelyanov mode = table->mode; 1646d7321cd6SPavel Emelyanov 1647d7321cd6SPavel Emelyanov return test_perm(mode, op); 16481da177e4SLinus Torvalds } 16491da177e4SLinus Torvalds 1650d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) 1651d912b0ccSEric W. Biederman { 1652d912b0ccSEric W. Biederman for (; table->ctl_name || table->procname; table++) { 1653d912b0ccSEric W. Biederman table->parent = parent; 1654d912b0ccSEric W. Biederman if (table->child) 1655d912b0ccSEric W. Biederman sysctl_set_parent(table, table->child); 1656d912b0ccSEric W. Biederman } 1657d912b0ccSEric W. Biederman } 1658d912b0ccSEric W. Biederman 1659d912b0ccSEric W. Biederman static __init int sysctl_init(void) 1660d912b0ccSEric W. Biederman { 1661d912b0ccSEric W. Biederman sysctl_set_parent(NULL, root_table); 166288f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 166388f458e4SHolger Schurig { 166488f458e4SHolger Schurig int err; 1665e51b6ba0SEric W. Biederman err = sysctl_check_table(current->nsproxy, root_table); 166688f458e4SHolger Schurig } 166788f458e4SHolger Schurig #endif 1668d912b0ccSEric W. Biederman return 0; 1669d912b0ccSEric W. Biederman } 1670d912b0ccSEric W. Biederman 1671d912b0ccSEric W. Biederman core_initcall(sysctl_init); 1672d912b0ccSEric W. Biederman 1673bfbcf034SAl Viro static struct ctl_table *is_branch_in(struct ctl_table *branch, 1674bfbcf034SAl Viro struct ctl_table *table) 1675ae7edeccSAl Viro { 1676ae7edeccSAl Viro struct ctl_table *p; 1677ae7edeccSAl Viro const char *s = branch->procname; 1678ae7edeccSAl Viro 1679ae7edeccSAl Viro /* branch should have named subdirectory as its first element */ 1680ae7edeccSAl Viro if (!s || !branch->child) 1681bfbcf034SAl Viro return NULL; 1682ae7edeccSAl Viro 1683ae7edeccSAl Viro /* ... and nothing else */ 1684ae7edeccSAl Viro if (branch[1].procname || branch[1].ctl_name) 1685bfbcf034SAl Viro return NULL; 1686ae7edeccSAl Viro 1687ae7edeccSAl Viro /* table should contain subdirectory with the same name */ 1688ae7edeccSAl Viro for (p = table; p->procname || p->ctl_name; p++) { 1689ae7edeccSAl Viro if (!p->child) 1690ae7edeccSAl Viro continue; 1691ae7edeccSAl Viro if (p->procname && strcmp(p->procname, s) == 0) 1692bfbcf034SAl Viro return p; 1693ae7edeccSAl Viro } 1694bfbcf034SAl Viro return NULL; 1695ae7edeccSAl Viro } 1696ae7edeccSAl Viro 1697ae7edeccSAl Viro /* see if attaching q to p would be an improvement */ 1698ae7edeccSAl Viro static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q) 1699ae7edeccSAl Viro { 1700ae7edeccSAl Viro struct ctl_table *to = p->ctl_table, *by = q->ctl_table; 1701bfbcf034SAl Viro struct ctl_table *next; 1702ae7edeccSAl Viro int is_better = 0; 1703ae7edeccSAl Viro int not_in_parent = !p->attached_by; 1704ae7edeccSAl Viro 1705bfbcf034SAl Viro while ((next = is_branch_in(by, to)) != NULL) { 1706ae7edeccSAl Viro if (by == q->attached_by) 1707ae7edeccSAl Viro is_better = 1; 1708ae7edeccSAl Viro if (to == p->attached_by) 1709ae7edeccSAl Viro not_in_parent = 1; 1710ae7edeccSAl Viro by = by->child; 1711bfbcf034SAl Viro to = next->child; 1712ae7edeccSAl Viro } 1713ae7edeccSAl Viro 1714ae7edeccSAl Viro if (is_better && not_in_parent) { 1715ae7edeccSAl Viro q->attached_by = by; 1716ae7edeccSAl Viro q->attached_to = to; 1717ae7edeccSAl Viro q->parent = p; 1718ae7edeccSAl Viro } 1719ae7edeccSAl Viro } 1720ae7edeccSAl Viro 17211da177e4SLinus Torvalds /** 1722e51b6ba0SEric W. Biederman * __register_sysctl_paths - register a sysctl hierarchy 1723e51b6ba0SEric W. Biederman * @root: List of sysctl headers to register on 1724e51b6ba0SEric W. Biederman * @namespaces: Data to compute which lists of sysctl entries are visible 172529e796fdSEric W. Biederman * @path: The path to the directory the sysctl table is in. 17261da177e4SLinus Torvalds * @table: the top-level table structure 17271da177e4SLinus Torvalds * 17281da177e4SLinus Torvalds * Register a sysctl table hierarchy. @table should be a filled in ctl_table 172929e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 17301da177e4SLinus Torvalds * 1731d8217f07SEric W. Biederman * The members of the &struct ctl_table structure are used as follows: 17321da177e4SLinus Torvalds * 17331da177e4SLinus Torvalds * ctl_name - This is the numeric sysctl value used by sysctl(2). The number 17341da177e4SLinus Torvalds * must be unique within that level of sysctl 17351da177e4SLinus Torvalds * 17361da177e4SLinus Torvalds * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not 17371da177e4SLinus Torvalds * enter a sysctl file 17381da177e4SLinus Torvalds * 17391da177e4SLinus Torvalds * data - a pointer to data for use by proc_handler 17401da177e4SLinus Torvalds * 17411da177e4SLinus Torvalds * maxlen - the maximum size in bytes of the data 17421da177e4SLinus Torvalds * 17431da177e4SLinus Torvalds * mode - the file permissions for the /proc/sys file, and for sysctl(2) 17441da177e4SLinus Torvalds * 17451da177e4SLinus Torvalds * child - a pointer to the child sysctl table if this entry is a directory, or 17461da177e4SLinus Torvalds * %NULL. 17471da177e4SLinus Torvalds * 17481da177e4SLinus Torvalds * proc_handler - the text handler routine (described below) 17491da177e4SLinus Torvalds * 17501da177e4SLinus Torvalds * strategy - the strategy routine (described below) 17511da177e4SLinus Torvalds * 17521da177e4SLinus Torvalds * de - for internal use by the sysctl routines 17531da177e4SLinus Torvalds * 17541da177e4SLinus Torvalds * extra1, extra2 - extra pointers usable by the proc handler routines 17551da177e4SLinus Torvalds * 17561da177e4SLinus Torvalds * Leaf nodes in the sysctl tree will be represented by a single file 17571da177e4SLinus Torvalds * under /proc; non-leaf nodes will be represented by directories. 17581da177e4SLinus Torvalds * 17591da177e4SLinus Torvalds * sysctl(2) can automatically manage read and write requests through 17601da177e4SLinus Torvalds * the sysctl table. The data and maxlen fields of the ctl_table 17611da177e4SLinus Torvalds * struct enable minimal validation of the values being written to be 17621da177e4SLinus Torvalds * performed, and the mode field allows minimal authentication. 17631da177e4SLinus Torvalds * 17641da177e4SLinus Torvalds * More sophisticated management can be enabled by the provision of a 17651da177e4SLinus Torvalds * strategy routine with the table entry. This will be called before 17661da177e4SLinus Torvalds * any automatic read or write of the data is performed. 17671da177e4SLinus Torvalds * 17681da177e4SLinus Torvalds * The strategy routine may return 17691da177e4SLinus Torvalds * 17701da177e4SLinus Torvalds * < 0 - Error occurred (error is passed to user process) 17711da177e4SLinus Torvalds * 17721da177e4SLinus Torvalds * 0 - OK - proceed with automatic read or write. 17731da177e4SLinus Torvalds * 17741da177e4SLinus Torvalds * > 0 - OK - read or write has been done by the strategy routine, so 17751da177e4SLinus Torvalds * return immediately. 17761da177e4SLinus Torvalds * 17771da177e4SLinus Torvalds * There must be a proc_handler routine for any terminal nodes 17781da177e4SLinus Torvalds * mirrored under /proc/sys (non-terminals are handled by a built-in 17791da177e4SLinus Torvalds * directory handler). Several default handlers are available to 17801da177e4SLinus Torvalds * cover common cases - 17811da177e4SLinus Torvalds * 17821da177e4SLinus Torvalds * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), 17831da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 17841da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() 17851da177e4SLinus Torvalds * 17861da177e4SLinus Torvalds * It is the handler's job to read the input buffer from user memory 17871da177e4SLinus Torvalds * and process it. The handler should return 0 on success. 17881da177e4SLinus Torvalds * 17891da177e4SLinus Torvalds * This routine returns %NULL on a failure to register, and a pointer 17901da177e4SLinus Torvalds * to the table header on success. 17911da177e4SLinus Torvalds */ 1792e51b6ba0SEric W. Biederman struct ctl_table_header *__register_sysctl_paths( 1793e51b6ba0SEric W. Biederman struct ctl_table_root *root, 1794e51b6ba0SEric W. Biederman struct nsproxy *namespaces, 1795e51b6ba0SEric W. Biederman const struct ctl_path *path, struct ctl_table *table) 17961da177e4SLinus Torvalds { 179729e796fdSEric W. Biederman struct ctl_table_header *header; 179829e796fdSEric W. Biederman struct ctl_table *new, **prevp; 179929e796fdSEric W. Biederman unsigned int n, npath; 1800ae7edeccSAl Viro struct ctl_table_set *set; 180129e796fdSEric W. Biederman 180229e796fdSEric W. Biederman /* Count the path components */ 180329e796fdSEric W. Biederman for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) 180429e796fdSEric W. Biederman ; 180529e796fdSEric W. Biederman 180629e796fdSEric W. Biederman /* 180729e796fdSEric W. Biederman * For each path component, allocate a 2-element ctl_table array. 180829e796fdSEric W. Biederman * The first array element will be filled with the sysctl entry 180929e796fdSEric W. Biederman * for this, the second will be the sentinel (ctl_name == 0). 181029e796fdSEric W. Biederman * 181129e796fdSEric W. Biederman * We allocate everything in one go so that we don't have to 181229e796fdSEric W. Biederman * worry about freeing additional memory in unregister_sysctl_table. 181329e796fdSEric W. Biederman */ 181429e796fdSEric W. Biederman header = kzalloc(sizeof(struct ctl_table_header) + 181529e796fdSEric W. Biederman (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); 181629e796fdSEric W. Biederman if (!header) 18171da177e4SLinus Torvalds return NULL; 181829e796fdSEric W. Biederman 181929e796fdSEric W. Biederman new = (struct ctl_table *) (header + 1); 182029e796fdSEric W. Biederman 182129e796fdSEric W. Biederman /* Now connect the dots */ 182229e796fdSEric W. Biederman prevp = &header->ctl_table; 182329e796fdSEric W. Biederman for (n = 0; n < npath; ++n, ++path) { 182429e796fdSEric W. Biederman /* Copy the procname */ 182529e796fdSEric W. Biederman new->procname = path->procname; 182629e796fdSEric W. Biederman new->ctl_name = path->ctl_name; 182729e796fdSEric W. Biederman new->mode = 0555; 182829e796fdSEric W. Biederman 182929e796fdSEric W. Biederman *prevp = new; 183029e796fdSEric W. Biederman prevp = &new->child; 183129e796fdSEric W. Biederman 183229e796fdSEric W. Biederman new += 2; 183329e796fdSEric W. Biederman } 183429e796fdSEric W. Biederman *prevp = table; 183523eb06deSEric W. Biederman header->ctl_table_arg = table; 183629e796fdSEric W. Biederman 183729e796fdSEric W. Biederman INIT_LIST_HEAD(&header->ctl_entry); 183829e796fdSEric W. Biederman header->used = 0; 183929e796fdSEric W. Biederman header->unregistering = NULL; 1840e51b6ba0SEric W. Biederman header->root = root; 184129e796fdSEric W. Biederman sysctl_set_parent(NULL, header->ctl_table); 1842f7e6ced4SAl Viro header->count = 1; 184388f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1844e51b6ba0SEric W. Biederman if (sysctl_check_table(namespaces, header->ctl_table)) { 184529e796fdSEric W. Biederman kfree(header); 1846fc6cd25bSEric W. Biederman return NULL; 1847fc6cd25bSEric W. Biederman } 184888f458e4SHolger Schurig #endif 1849330d57fbSAl Viro spin_lock(&sysctl_lock); 185073455092SAl Viro header->set = lookup_header_set(root, namespaces); 1851ae7edeccSAl Viro header->attached_by = header->ctl_table; 1852ae7edeccSAl Viro header->attached_to = root_table; 1853ae7edeccSAl Viro header->parent = &root_table_header; 1854ae7edeccSAl Viro for (set = header->set; set; set = set->parent) { 1855ae7edeccSAl Viro struct ctl_table_header *p; 1856ae7edeccSAl Viro list_for_each_entry(p, &set->list, ctl_entry) { 1857ae7edeccSAl Viro if (p->unregistering) 1858ae7edeccSAl Viro continue; 1859ae7edeccSAl Viro try_attach(p, header); 1860ae7edeccSAl Viro } 1861ae7edeccSAl Viro } 1862ae7edeccSAl Viro header->parent->count++; 186373455092SAl Viro list_add_tail(&header->ctl_entry, &header->set->list); 1864330d57fbSAl Viro spin_unlock(&sysctl_lock); 186529e796fdSEric W. Biederman 186629e796fdSEric W. Biederman return header; 186729e796fdSEric W. Biederman } 186829e796fdSEric W. Biederman 186929e796fdSEric W. Biederman /** 1870e51b6ba0SEric W. Biederman * register_sysctl_table_path - register a sysctl table hierarchy 1871e51b6ba0SEric W. Biederman * @path: The path to the directory the sysctl table is in. 1872e51b6ba0SEric W. Biederman * @table: the top-level table structure 1873e51b6ba0SEric W. Biederman * 1874e51b6ba0SEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1875e51b6ba0SEric W. Biederman * array. A completely 0 filled entry terminates the table. 1876e51b6ba0SEric W. Biederman * 1877e51b6ba0SEric W. Biederman * See __register_sysctl_paths for more details. 1878e51b6ba0SEric W. Biederman */ 1879e51b6ba0SEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 1880e51b6ba0SEric W. Biederman struct ctl_table *table) 1881e51b6ba0SEric W. Biederman { 1882e51b6ba0SEric W. Biederman return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, 1883e51b6ba0SEric W. Biederman path, table); 1884e51b6ba0SEric W. Biederman } 1885e51b6ba0SEric W. Biederman 1886e51b6ba0SEric W. Biederman /** 188729e796fdSEric W. Biederman * register_sysctl_table - register a sysctl table hierarchy 188829e796fdSEric W. Biederman * @table: the top-level table structure 188929e796fdSEric W. Biederman * 189029e796fdSEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 189129e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 189229e796fdSEric W. Biederman * 189329e796fdSEric W. Biederman * See register_sysctl_paths for more details. 189429e796fdSEric W. Biederman */ 189529e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table) 189629e796fdSEric W. Biederman { 189729e796fdSEric W. Biederman static const struct ctl_path null_path[] = { {} }; 189829e796fdSEric W. Biederman 189929e796fdSEric W. Biederman return register_sysctl_paths(null_path, table); 19001da177e4SLinus Torvalds } 19011da177e4SLinus Torvalds 19021da177e4SLinus Torvalds /** 19031da177e4SLinus Torvalds * unregister_sysctl_table - unregister a sysctl table hierarchy 19041da177e4SLinus Torvalds * @header: the header returned from register_sysctl_table 19051da177e4SLinus Torvalds * 19061da177e4SLinus Torvalds * Unregisters the sysctl table and all children. proc entries may not 19071da177e4SLinus Torvalds * actually be removed until they are no longer used by anyone. 19081da177e4SLinus Torvalds */ 19091da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header) 19101da177e4SLinus Torvalds { 1911330d57fbSAl Viro might_sleep(); 1912f1dad166SPavel Emelyanov 1913f1dad166SPavel Emelyanov if (header == NULL) 1914f1dad166SPavel Emelyanov return; 1915f1dad166SPavel Emelyanov 1916330d57fbSAl Viro spin_lock(&sysctl_lock); 1917330d57fbSAl Viro start_unregistering(header); 1918ae7edeccSAl Viro if (!--header->parent->count) { 1919ae7edeccSAl Viro WARN_ON(1); 1920ae7edeccSAl Viro kfree(header->parent); 1921ae7edeccSAl Viro } 1922f7e6ced4SAl Viro if (!--header->count) 19231da177e4SLinus Torvalds kfree(header); 1924f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 19251da177e4SLinus Torvalds } 19261da177e4SLinus Torvalds 19279043476fSAl Viro int sysctl_is_seen(struct ctl_table_header *p) 19289043476fSAl Viro { 19299043476fSAl Viro struct ctl_table_set *set = p->set; 19309043476fSAl Viro int res; 19319043476fSAl Viro spin_lock(&sysctl_lock); 19329043476fSAl Viro if (p->unregistering) 19339043476fSAl Viro res = 0; 19349043476fSAl Viro else if (!set->is_seen) 19359043476fSAl Viro res = 1; 19369043476fSAl Viro else 19379043476fSAl Viro res = set->is_seen(set); 19389043476fSAl Viro spin_unlock(&sysctl_lock); 19399043476fSAl Viro return res; 19409043476fSAl Viro } 19419043476fSAl Viro 194273455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p, 194373455092SAl Viro struct ctl_table_set *parent, 194473455092SAl Viro int (*is_seen)(struct ctl_table_set *)) 194573455092SAl Viro { 194673455092SAl Viro INIT_LIST_HEAD(&p->list); 194773455092SAl Viro p->parent = parent ? parent : &sysctl_table_root.default_set; 194873455092SAl Viro p->is_seen = is_seen; 194973455092SAl Viro } 195073455092SAl Viro 1951b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */ 1952d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table) 1953b89a8171SEric W. Biederman { 1954b89a8171SEric W. Biederman return NULL; 1955b89a8171SEric W. Biederman } 1956b89a8171SEric W. Biederman 195729e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 195829e796fdSEric W. Biederman struct ctl_table *table) 195929e796fdSEric W. Biederman { 196029e796fdSEric W. Biederman return NULL; 196129e796fdSEric W. Biederman } 196229e796fdSEric W. Biederman 1963b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table) 1964b89a8171SEric W. Biederman { 1965b89a8171SEric W. Biederman } 1966b89a8171SEric W. Biederman 196773455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p, 196873455092SAl Viro struct ctl_table_set *parent, 196973455092SAl Viro int (*is_seen)(struct ctl_table_set *)) 197073455092SAl Viro { 197173455092SAl Viro } 197273455092SAl Viro 1973f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head) 1974f7e6ced4SAl Viro { 1975f7e6ced4SAl Viro } 1976f7e6ced4SAl Viro 1977b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */ 1978b89a8171SEric W. Biederman 19791da177e4SLinus Torvalds /* 19801da177e4SLinus Torvalds * /proc/sys support 19811da177e4SLinus Torvalds */ 19821da177e4SLinus Torvalds 1983b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL 19841da177e4SLinus Torvalds 1985b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write, 1986b1ba4dddSAdrian Bunk struct file *filp, void __user *buffer, 1987b1ba4dddSAdrian Bunk size_t *lenp, loff_t *ppos) 1988f5dd3d6fSSam Vilain { 1989f5dd3d6fSSam Vilain size_t len; 1990f5dd3d6fSSam Vilain char __user *p; 1991f5dd3d6fSSam Vilain char c; 1992f5dd3d6fSSam Vilain 19938d060877SOleg Nesterov if (!data || !maxlen || !*lenp) { 1994f5dd3d6fSSam Vilain *lenp = 0; 1995f5dd3d6fSSam Vilain return 0; 1996f5dd3d6fSSam Vilain } 1997f5dd3d6fSSam Vilain 1998f5dd3d6fSSam Vilain if (write) { 1999f5dd3d6fSSam Vilain len = 0; 2000f5dd3d6fSSam Vilain p = buffer; 2001f5dd3d6fSSam Vilain while (len < *lenp) { 2002f5dd3d6fSSam Vilain if (get_user(c, p++)) 2003f5dd3d6fSSam Vilain return -EFAULT; 2004f5dd3d6fSSam Vilain if (c == 0 || c == '\n') 2005f5dd3d6fSSam Vilain break; 2006f5dd3d6fSSam Vilain len++; 2007f5dd3d6fSSam Vilain } 2008f5dd3d6fSSam Vilain if (len >= maxlen) 2009f5dd3d6fSSam Vilain len = maxlen-1; 2010f5dd3d6fSSam Vilain if(copy_from_user(data, buffer, len)) 2011f5dd3d6fSSam Vilain return -EFAULT; 2012f5dd3d6fSSam Vilain ((char *) data)[len] = 0; 2013f5dd3d6fSSam Vilain *ppos += *lenp; 2014f5dd3d6fSSam Vilain } else { 2015f5dd3d6fSSam Vilain len = strlen(data); 2016f5dd3d6fSSam Vilain if (len > maxlen) 2017f5dd3d6fSSam Vilain len = maxlen; 20188d060877SOleg Nesterov 20198d060877SOleg Nesterov if (*ppos > len) { 20208d060877SOleg Nesterov *lenp = 0; 20218d060877SOleg Nesterov return 0; 20228d060877SOleg Nesterov } 20238d060877SOleg Nesterov 20248d060877SOleg Nesterov data += *ppos; 20258d060877SOleg Nesterov len -= *ppos; 20268d060877SOleg Nesterov 2027f5dd3d6fSSam Vilain if (len > *lenp) 2028f5dd3d6fSSam Vilain len = *lenp; 2029f5dd3d6fSSam Vilain if (len) 2030f5dd3d6fSSam Vilain if(copy_to_user(buffer, data, len)) 2031f5dd3d6fSSam Vilain return -EFAULT; 2032f5dd3d6fSSam Vilain if (len < *lenp) { 2033f5dd3d6fSSam Vilain if(put_user('\n', ((char __user *) buffer) + len)) 2034f5dd3d6fSSam Vilain return -EFAULT; 2035f5dd3d6fSSam Vilain len++; 2036f5dd3d6fSSam Vilain } 2037f5dd3d6fSSam Vilain *lenp = len; 2038f5dd3d6fSSam Vilain *ppos += len; 2039f5dd3d6fSSam Vilain } 2040f5dd3d6fSSam Vilain return 0; 2041f5dd3d6fSSam Vilain } 2042f5dd3d6fSSam Vilain 20431da177e4SLinus Torvalds /** 20441da177e4SLinus Torvalds * proc_dostring - read a string sysctl 20451da177e4SLinus Torvalds * @table: the sysctl table 20461da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 20471da177e4SLinus Torvalds * @filp: the file structure 20481da177e4SLinus Torvalds * @buffer: the user buffer 20491da177e4SLinus Torvalds * @lenp: the size of the user buffer 20501da177e4SLinus Torvalds * @ppos: file position 20511da177e4SLinus Torvalds * 20521da177e4SLinus Torvalds * Reads/writes a string from/to the user buffer. If the kernel 20531da177e4SLinus Torvalds * buffer provided is not large enough to hold the string, the 20541da177e4SLinus Torvalds * string is truncated. The copied string is %NULL-terminated. 20551da177e4SLinus Torvalds * If the string is being read by the user process, it is copied 20561da177e4SLinus Torvalds * and a newline '\n' is added. It is truncated if the buffer is 20571da177e4SLinus Torvalds * not large enough. 20581da177e4SLinus Torvalds * 20591da177e4SLinus Torvalds * Returns 0 on success. 20601da177e4SLinus Torvalds */ 2061d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp, 20621da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 20631da177e4SLinus Torvalds { 2064f5dd3d6fSSam Vilain return _proc_do_string(table->data, table->maxlen, write, filp, 2065f5dd3d6fSSam Vilain buffer, lenp, ppos); 20661da177e4SLinus Torvalds } 20671da177e4SLinus Torvalds 20681da177e4SLinus Torvalds 20691da177e4SLinus Torvalds static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, 20701da177e4SLinus Torvalds int *valp, 20711da177e4SLinus Torvalds int write, void *data) 20721da177e4SLinus Torvalds { 20731da177e4SLinus Torvalds if (write) { 20741da177e4SLinus Torvalds *valp = *negp ? -*lvalp : *lvalp; 20751da177e4SLinus Torvalds } else { 20761da177e4SLinus Torvalds int val = *valp; 20771da177e4SLinus Torvalds if (val < 0) { 20781da177e4SLinus Torvalds *negp = -1; 20791da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 20801da177e4SLinus Torvalds } else { 20811da177e4SLinus Torvalds *negp = 0; 20821da177e4SLinus Torvalds *lvalp = (unsigned long)val; 20831da177e4SLinus Torvalds } 20841da177e4SLinus Torvalds } 20851da177e4SLinus Torvalds return 0; 20861da177e4SLinus Torvalds } 20871da177e4SLinus Torvalds 2088d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 2089fcfbd547SKirill Korotaev int write, struct file *filp, void __user *buffer, 2090fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 20911da177e4SLinus Torvalds int (*conv)(int *negp, unsigned long *lvalp, int *valp, 20921da177e4SLinus Torvalds int write, void *data), 20931da177e4SLinus Torvalds void *data) 20941da177e4SLinus Torvalds { 20951da177e4SLinus Torvalds #define TMPBUFLEN 21 20961da177e4SLinus Torvalds int *i, vleft, first=1, neg, val; 20971da177e4SLinus Torvalds unsigned long lval; 20981da177e4SLinus Torvalds size_t left, len; 20991da177e4SLinus Torvalds 21001da177e4SLinus Torvalds char buf[TMPBUFLEN], *p; 21011da177e4SLinus Torvalds char __user *s = buffer; 21021da177e4SLinus Torvalds 2103fcfbd547SKirill Korotaev if (!tbl_data || !table->maxlen || !*lenp || 21041da177e4SLinus Torvalds (*ppos && !write)) { 21051da177e4SLinus Torvalds *lenp = 0; 21061da177e4SLinus Torvalds return 0; 21071da177e4SLinus Torvalds } 21081da177e4SLinus Torvalds 2109fcfbd547SKirill Korotaev i = (int *) tbl_data; 21101da177e4SLinus Torvalds vleft = table->maxlen / sizeof(*i); 21111da177e4SLinus Torvalds left = *lenp; 21121da177e4SLinus Torvalds 21131da177e4SLinus Torvalds if (!conv) 21141da177e4SLinus Torvalds conv = do_proc_dointvec_conv; 21151da177e4SLinus Torvalds 21161da177e4SLinus Torvalds for (; left && vleft--; i++, first=0) { 21171da177e4SLinus Torvalds if (write) { 21181da177e4SLinus Torvalds while (left) { 21191da177e4SLinus Torvalds char c; 21201da177e4SLinus Torvalds if (get_user(c, s)) 21211da177e4SLinus Torvalds return -EFAULT; 21221da177e4SLinus Torvalds if (!isspace(c)) 21231da177e4SLinus Torvalds break; 21241da177e4SLinus Torvalds left--; 21251da177e4SLinus Torvalds s++; 21261da177e4SLinus Torvalds } 21271da177e4SLinus Torvalds if (!left) 21281da177e4SLinus Torvalds break; 21291da177e4SLinus Torvalds neg = 0; 21301da177e4SLinus Torvalds len = left; 21311da177e4SLinus Torvalds if (len > sizeof(buf) - 1) 21321da177e4SLinus Torvalds len = sizeof(buf) - 1; 21331da177e4SLinus Torvalds if (copy_from_user(buf, s, len)) 21341da177e4SLinus Torvalds return -EFAULT; 21351da177e4SLinus Torvalds buf[len] = 0; 21361da177e4SLinus Torvalds p = buf; 21371da177e4SLinus Torvalds if (*p == '-' && left > 1) { 21381da177e4SLinus Torvalds neg = 1; 2139bd9b0bacSBP, Praveen p++; 21401da177e4SLinus Torvalds } 21411da177e4SLinus Torvalds if (*p < '0' || *p > '9') 21421da177e4SLinus Torvalds break; 21431da177e4SLinus Torvalds 21441da177e4SLinus Torvalds lval = simple_strtoul(p, &p, 0); 21451da177e4SLinus Torvalds 21461da177e4SLinus Torvalds len = p-buf; 21471da177e4SLinus Torvalds if ((len < left) && *p && !isspace(*p)) 21481da177e4SLinus Torvalds break; 21491da177e4SLinus Torvalds if (neg) 21501da177e4SLinus Torvalds val = -val; 21511da177e4SLinus Torvalds s += len; 21521da177e4SLinus Torvalds left -= len; 21531da177e4SLinus Torvalds 21541da177e4SLinus Torvalds if (conv(&neg, &lval, i, 1, data)) 21551da177e4SLinus Torvalds break; 21561da177e4SLinus Torvalds } else { 21571da177e4SLinus Torvalds p = buf; 21581da177e4SLinus Torvalds if (!first) 21591da177e4SLinus Torvalds *p++ = '\t'; 21601da177e4SLinus Torvalds 21611da177e4SLinus Torvalds if (conv(&neg, &lval, i, 0, data)) 21621da177e4SLinus Torvalds break; 21631da177e4SLinus Torvalds 21641da177e4SLinus Torvalds sprintf(p, "%s%lu", neg ? "-" : "", lval); 21651da177e4SLinus Torvalds len = strlen(buf); 21661da177e4SLinus Torvalds if (len > left) 21671da177e4SLinus Torvalds len = left; 21681da177e4SLinus Torvalds if(copy_to_user(s, buf, len)) 21691da177e4SLinus Torvalds return -EFAULT; 21701da177e4SLinus Torvalds left -= len; 21711da177e4SLinus Torvalds s += len; 21721da177e4SLinus Torvalds } 21731da177e4SLinus Torvalds } 21741da177e4SLinus Torvalds 21751da177e4SLinus Torvalds if (!write && !first && left) { 21761da177e4SLinus Torvalds if(put_user('\n', s)) 21771da177e4SLinus Torvalds return -EFAULT; 21781da177e4SLinus Torvalds left--, s++; 21791da177e4SLinus Torvalds } 21801da177e4SLinus Torvalds if (write) { 21811da177e4SLinus Torvalds while (left) { 21821da177e4SLinus Torvalds char c; 21831da177e4SLinus Torvalds if (get_user(c, s++)) 21841da177e4SLinus Torvalds return -EFAULT; 21851da177e4SLinus Torvalds if (!isspace(c)) 21861da177e4SLinus Torvalds break; 21871da177e4SLinus Torvalds left--; 21881da177e4SLinus Torvalds } 21891da177e4SLinus Torvalds } 21901da177e4SLinus Torvalds if (write && first) 21911da177e4SLinus Torvalds return -EINVAL; 21921da177e4SLinus Torvalds *lenp -= left; 21931da177e4SLinus Torvalds *ppos += *lenp; 21941da177e4SLinus Torvalds return 0; 21951da177e4SLinus Torvalds #undef TMPBUFLEN 21961da177e4SLinus Torvalds } 21971da177e4SLinus Torvalds 2198d8217f07SEric W. Biederman static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp, 2199fcfbd547SKirill Korotaev void __user *buffer, size_t *lenp, loff_t *ppos, 2200fcfbd547SKirill Korotaev int (*conv)(int *negp, unsigned long *lvalp, int *valp, 2201fcfbd547SKirill Korotaev int write, void *data), 2202fcfbd547SKirill Korotaev void *data) 2203fcfbd547SKirill Korotaev { 2204fcfbd547SKirill Korotaev return __do_proc_dointvec(table->data, table, write, filp, 2205fcfbd547SKirill Korotaev buffer, lenp, ppos, conv, data); 2206fcfbd547SKirill Korotaev } 2207fcfbd547SKirill Korotaev 22081da177e4SLinus Torvalds /** 22091da177e4SLinus Torvalds * proc_dointvec - read a vector of integers 22101da177e4SLinus Torvalds * @table: the sysctl table 22111da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 22121da177e4SLinus Torvalds * @filp: the file structure 22131da177e4SLinus Torvalds * @buffer: the user buffer 22141da177e4SLinus Torvalds * @lenp: the size of the user buffer 22151da177e4SLinus Torvalds * @ppos: file position 22161da177e4SLinus Torvalds * 22171da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 22181da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 22191da177e4SLinus Torvalds * 22201da177e4SLinus Torvalds * Returns 0 on success. 22211da177e4SLinus Torvalds */ 2222d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp, 22231da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 22241da177e4SLinus Torvalds { 22251da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 22261da177e4SLinus Torvalds NULL,NULL); 22271da177e4SLinus Torvalds } 22281da177e4SLinus Torvalds 222934f5a398STheodore Ts'o /* 223034f5a398STheodore Ts'o * Taint values can only be increased 223125ddbb18SAndi Kleen * This means we can safely use a temporary. 223234f5a398STheodore Ts'o */ 223325ddbb18SAndi Kleen static int proc_taint(struct ctl_table *table, int write, struct file *filp, 223434f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos) 223534f5a398STheodore Ts'o { 223625ddbb18SAndi Kleen struct ctl_table t; 223725ddbb18SAndi Kleen unsigned long tmptaint = get_taint(); 223825ddbb18SAndi Kleen int err; 223934f5a398STheodore Ts'o 224091fcd412SBastian Blank if (write && !capable(CAP_SYS_ADMIN)) 224134f5a398STheodore Ts'o return -EPERM; 224234f5a398STheodore Ts'o 224325ddbb18SAndi Kleen t = *table; 224425ddbb18SAndi Kleen t.data = &tmptaint; 224525ddbb18SAndi Kleen err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos); 224625ddbb18SAndi Kleen if (err < 0) 224725ddbb18SAndi Kleen return err; 224825ddbb18SAndi Kleen 224925ddbb18SAndi Kleen if (write) { 225025ddbb18SAndi Kleen /* 225125ddbb18SAndi Kleen * Poor man's atomic or. Not worth adding a primitive 225225ddbb18SAndi Kleen * to everyone's atomic.h for this 225325ddbb18SAndi Kleen */ 225425ddbb18SAndi Kleen int i; 225525ddbb18SAndi Kleen for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { 225625ddbb18SAndi Kleen if ((tmptaint >> i) & 1) 225725ddbb18SAndi Kleen add_taint(i); 225825ddbb18SAndi Kleen } 225925ddbb18SAndi Kleen } 226025ddbb18SAndi Kleen 226125ddbb18SAndi Kleen return err; 226234f5a398STheodore Ts'o } 226334f5a398STheodore Ts'o 22641da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param { 22651da177e4SLinus Torvalds int *min; 22661da177e4SLinus Torvalds int *max; 22671da177e4SLinus Torvalds }; 22681da177e4SLinus Torvalds 22691da177e4SLinus Torvalds static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 22701da177e4SLinus Torvalds int *valp, 22711da177e4SLinus Torvalds int write, void *data) 22721da177e4SLinus Torvalds { 22731da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param *param = data; 22741da177e4SLinus Torvalds if (write) { 22751da177e4SLinus Torvalds int val = *negp ? -*lvalp : *lvalp; 22761da177e4SLinus Torvalds if ((param->min && *param->min > val) || 22771da177e4SLinus Torvalds (param->max && *param->max < val)) 22781da177e4SLinus Torvalds return -EINVAL; 22791da177e4SLinus Torvalds *valp = val; 22801da177e4SLinus Torvalds } else { 22811da177e4SLinus Torvalds int val = *valp; 22821da177e4SLinus Torvalds if (val < 0) { 22831da177e4SLinus Torvalds *negp = -1; 22841da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 22851da177e4SLinus Torvalds } else { 22861da177e4SLinus Torvalds *negp = 0; 22871da177e4SLinus Torvalds *lvalp = (unsigned long)val; 22881da177e4SLinus Torvalds } 22891da177e4SLinus Torvalds } 22901da177e4SLinus Torvalds return 0; 22911da177e4SLinus Torvalds } 22921da177e4SLinus Torvalds 22931da177e4SLinus Torvalds /** 22941da177e4SLinus Torvalds * proc_dointvec_minmax - read a vector of integers with min/max values 22951da177e4SLinus Torvalds * @table: the sysctl table 22961da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 22971da177e4SLinus Torvalds * @filp: the file structure 22981da177e4SLinus Torvalds * @buffer: the user buffer 22991da177e4SLinus Torvalds * @lenp: the size of the user buffer 23001da177e4SLinus Torvalds * @ppos: file position 23011da177e4SLinus Torvalds * 23021da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 23031da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 23041da177e4SLinus Torvalds * 23051da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 23061da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 23071da177e4SLinus Torvalds * 23081da177e4SLinus Torvalds * Returns 0 on success. 23091da177e4SLinus Torvalds */ 2310d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, 23111da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 23121da177e4SLinus Torvalds { 23131da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param param = { 23141da177e4SLinus Torvalds .min = (int *) table->extra1, 23151da177e4SLinus Torvalds .max = (int *) table->extra2, 23161da177e4SLinus Torvalds }; 23171da177e4SLinus Torvalds return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, 23181da177e4SLinus Torvalds do_proc_dointvec_minmax_conv, ¶m); 23191da177e4SLinus Torvalds } 23201da177e4SLinus Torvalds 2321d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, 23221da177e4SLinus Torvalds struct file *filp, 23231da177e4SLinus Torvalds void __user *buffer, 23241da177e4SLinus Torvalds size_t *lenp, loff_t *ppos, 23251da177e4SLinus Torvalds unsigned long convmul, 23261da177e4SLinus Torvalds unsigned long convdiv) 23271da177e4SLinus Torvalds { 23281da177e4SLinus Torvalds #define TMPBUFLEN 21 23291da177e4SLinus Torvalds unsigned long *i, *min, *max, val; 23301da177e4SLinus Torvalds int vleft, first=1, neg; 23311da177e4SLinus Torvalds size_t len, left; 23321da177e4SLinus Torvalds char buf[TMPBUFLEN], *p; 23331da177e4SLinus Torvalds char __user *s = buffer; 23341da177e4SLinus Torvalds 2335fcfbd547SKirill Korotaev if (!data || !table->maxlen || !*lenp || 23361da177e4SLinus Torvalds (*ppos && !write)) { 23371da177e4SLinus Torvalds *lenp = 0; 23381da177e4SLinus Torvalds return 0; 23391da177e4SLinus Torvalds } 23401da177e4SLinus Torvalds 2341fcfbd547SKirill Korotaev i = (unsigned long *) data; 23421da177e4SLinus Torvalds min = (unsigned long *) table->extra1; 23431da177e4SLinus Torvalds max = (unsigned long *) table->extra2; 23441da177e4SLinus Torvalds vleft = table->maxlen / sizeof(unsigned long); 23451da177e4SLinus Torvalds left = *lenp; 23461da177e4SLinus Torvalds 23471da177e4SLinus Torvalds for (; left && vleft--; i++, min++, max++, first=0) { 23481da177e4SLinus Torvalds if (write) { 23491da177e4SLinus Torvalds while (left) { 23501da177e4SLinus Torvalds char c; 23511da177e4SLinus Torvalds if (get_user(c, s)) 23521da177e4SLinus Torvalds return -EFAULT; 23531da177e4SLinus Torvalds if (!isspace(c)) 23541da177e4SLinus Torvalds break; 23551da177e4SLinus Torvalds left--; 23561da177e4SLinus Torvalds s++; 23571da177e4SLinus Torvalds } 23581da177e4SLinus Torvalds if (!left) 23591da177e4SLinus Torvalds break; 23601da177e4SLinus Torvalds neg = 0; 23611da177e4SLinus Torvalds len = left; 23621da177e4SLinus Torvalds if (len > TMPBUFLEN-1) 23631da177e4SLinus Torvalds len = TMPBUFLEN-1; 23641da177e4SLinus Torvalds if (copy_from_user(buf, s, len)) 23651da177e4SLinus Torvalds return -EFAULT; 23661da177e4SLinus Torvalds buf[len] = 0; 23671da177e4SLinus Torvalds p = buf; 23681da177e4SLinus Torvalds if (*p == '-' && left > 1) { 23691da177e4SLinus Torvalds neg = 1; 2370bd9b0bacSBP, Praveen p++; 23711da177e4SLinus Torvalds } 23721da177e4SLinus Torvalds if (*p < '0' || *p > '9') 23731da177e4SLinus Torvalds break; 23741da177e4SLinus Torvalds val = simple_strtoul(p, &p, 0) * convmul / convdiv ; 23751da177e4SLinus Torvalds len = p-buf; 23761da177e4SLinus Torvalds if ((len < left) && *p && !isspace(*p)) 23771da177e4SLinus Torvalds break; 23781da177e4SLinus Torvalds if (neg) 23791da177e4SLinus Torvalds val = -val; 23801da177e4SLinus Torvalds s += len; 23811da177e4SLinus Torvalds left -= len; 23821da177e4SLinus Torvalds 23831da177e4SLinus Torvalds if(neg) 23841da177e4SLinus Torvalds continue; 23851da177e4SLinus Torvalds if ((min && val < *min) || (max && val > *max)) 23861da177e4SLinus Torvalds continue; 23871da177e4SLinus Torvalds *i = val; 23881da177e4SLinus Torvalds } else { 23891da177e4SLinus Torvalds p = buf; 23901da177e4SLinus Torvalds if (!first) 23911da177e4SLinus Torvalds *p++ = '\t'; 23921da177e4SLinus Torvalds sprintf(p, "%lu", convdiv * (*i) / convmul); 23931da177e4SLinus Torvalds len = strlen(buf); 23941da177e4SLinus Torvalds if (len > left) 23951da177e4SLinus Torvalds len = left; 23961da177e4SLinus Torvalds if(copy_to_user(s, buf, len)) 23971da177e4SLinus Torvalds return -EFAULT; 23981da177e4SLinus Torvalds left -= len; 23991da177e4SLinus Torvalds s += len; 24001da177e4SLinus Torvalds } 24011da177e4SLinus Torvalds } 24021da177e4SLinus Torvalds 24031da177e4SLinus Torvalds if (!write && !first && left) { 24041da177e4SLinus Torvalds if(put_user('\n', s)) 24051da177e4SLinus Torvalds return -EFAULT; 24061da177e4SLinus Torvalds left--, s++; 24071da177e4SLinus Torvalds } 24081da177e4SLinus Torvalds if (write) { 24091da177e4SLinus Torvalds while (left) { 24101da177e4SLinus Torvalds char c; 24111da177e4SLinus Torvalds if (get_user(c, s++)) 24121da177e4SLinus Torvalds return -EFAULT; 24131da177e4SLinus Torvalds if (!isspace(c)) 24141da177e4SLinus Torvalds break; 24151da177e4SLinus Torvalds left--; 24161da177e4SLinus Torvalds } 24171da177e4SLinus Torvalds } 24181da177e4SLinus Torvalds if (write && first) 24191da177e4SLinus Torvalds return -EINVAL; 24201da177e4SLinus Torvalds *lenp -= left; 24211da177e4SLinus Torvalds *ppos += *lenp; 24221da177e4SLinus Torvalds return 0; 24231da177e4SLinus Torvalds #undef TMPBUFLEN 24241da177e4SLinus Torvalds } 24251da177e4SLinus Torvalds 2426d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 2427fcfbd547SKirill Korotaev struct file *filp, 2428fcfbd547SKirill Korotaev void __user *buffer, 2429fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 2430fcfbd547SKirill Korotaev unsigned long convmul, 2431fcfbd547SKirill Korotaev unsigned long convdiv) 2432fcfbd547SKirill Korotaev { 2433fcfbd547SKirill Korotaev return __do_proc_doulongvec_minmax(table->data, table, write, 2434fcfbd547SKirill Korotaev filp, buffer, lenp, ppos, convmul, convdiv); 2435fcfbd547SKirill Korotaev } 2436fcfbd547SKirill Korotaev 24371da177e4SLinus Torvalds /** 24381da177e4SLinus Torvalds * proc_doulongvec_minmax - read a vector of long integers with min/max values 24391da177e4SLinus Torvalds * @table: the sysctl table 24401da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 24411da177e4SLinus Torvalds * @filp: the file structure 24421da177e4SLinus Torvalds * @buffer: the user buffer 24431da177e4SLinus Torvalds * @lenp: the size of the user buffer 24441da177e4SLinus Torvalds * @ppos: file position 24451da177e4SLinus Torvalds * 24461da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 24471da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 24481da177e4SLinus Torvalds * 24491da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 24501da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 24511da177e4SLinus Torvalds * 24521da177e4SLinus Torvalds * Returns 0 on success. 24531da177e4SLinus Torvalds */ 2454d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, 24551da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24561da177e4SLinus Torvalds { 24571da177e4SLinus Torvalds return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l); 24581da177e4SLinus Torvalds } 24591da177e4SLinus Torvalds 24601da177e4SLinus Torvalds /** 24611da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 24621da177e4SLinus Torvalds * @table: the sysctl table 24631da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 24641da177e4SLinus Torvalds * @filp: the file structure 24651da177e4SLinus Torvalds * @buffer: the user buffer 24661da177e4SLinus Torvalds * @lenp: the size of the user buffer 24671da177e4SLinus Torvalds * @ppos: file position 24681da177e4SLinus Torvalds * 24691da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 24701da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. The values 24711da177e4SLinus Torvalds * are treated as milliseconds, and converted to jiffies when they are stored. 24721da177e4SLinus Torvalds * 24731da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 24741da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 24751da177e4SLinus Torvalds * 24761da177e4SLinus Torvalds * Returns 0 on success. 24771da177e4SLinus Torvalds */ 2478d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 24791da177e4SLinus Torvalds struct file *filp, 24801da177e4SLinus Torvalds void __user *buffer, 24811da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 24821da177e4SLinus Torvalds { 24831da177e4SLinus Torvalds return do_proc_doulongvec_minmax(table, write, filp, buffer, 24841da177e4SLinus Torvalds lenp, ppos, HZ, 1000l); 24851da177e4SLinus Torvalds } 24861da177e4SLinus Torvalds 24871da177e4SLinus Torvalds 24881da177e4SLinus Torvalds static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, 24891da177e4SLinus Torvalds int *valp, 24901da177e4SLinus Torvalds int write, void *data) 24911da177e4SLinus Torvalds { 24921da177e4SLinus Torvalds if (write) { 2493cba9f33dSBart Samwel if (*lvalp > LONG_MAX / HZ) 2494cba9f33dSBart Samwel return 1; 24951da177e4SLinus Torvalds *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); 24961da177e4SLinus Torvalds } else { 24971da177e4SLinus Torvalds int val = *valp; 24981da177e4SLinus Torvalds unsigned long lval; 24991da177e4SLinus Torvalds if (val < 0) { 25001da177e4SLinus Torvalds *negp = -1; 25011da177e4SLinus Torvalds lval = (unsigned long)-val; 25021da177e4SLinus Torvalds } else { 25031da177e4SLinus Torvalds *negp = 0; 25041da177e4SLinus Torvalds lval = (unsigned long)val; 25051da177e4SLinus Torvalds } 25061da177e4SLinus Torvalds *lvalp = lval / HZ; 25071da177e4SLinus Torvalds } 25081da177e4SLinus Torvalds return 0; 25091da177e4SLinus Torvalds } 25101da177e4SLinus Torvalds 25111da177e4SLinus Torvalds static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, 25121da177e4SLinus Torvalds int *valp, 25131da177e4SLinus Torvalds int write, void *data) 25141da177e4SLinus Torvalds { 25151da177e4SLinus Torvalds if (write) { 2516cba9f33dSBart Samwel if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 2517cba9f33dSBart Samwel return 1; 25181da177e4SLinus Torvalds *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 25191da177e4SLinus Torvalds } else { 25201da177e4SLinus Torvalds int val = *valp; 25211da177e4SLinus Torvalds unsigned long lval; 25221da177e4SLinus Torvalds if (val < 0) { 25231da177e4SLinus Torvalds *negp = -1; 25241da177e4SLinus Torvalds lval = (unsigned long)-val; 25251da177e4SLinus Torvalds } else { 25261da177e4SLinus Torvalds *negp = 0; 25271da177e4SLinus Torvalds lval = (unsigned long)val; 25281da177e4SLinus Torvalds } 25291da177e4SLinus Torvalds *lvalp = jiffies_to_clock_t(lval); 25301da177e4SLinus Torvalds } 25311da177e4SLinus Torvalds return 0; 25321da177e4SLinus Torvalds } 25331da177e4SLinus Torvalds 25341da177e4SLinus Torvalds static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, 25351da177e4SLinus Torvalds int *valp, 25361da177e4SLinus Torvalds int write, void *data) 25371da177e4SLinus Torvalds { 25381da177e4SLinus Torvalds if (write) { 25391da177e4SLinus Torvalds *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 25401da177e4SLinus Torvalds } else { 25411da177e4SLinus Torvalds int val = *valp; 25421da177e4SLinus Torvalds unsigned long lval; 25431da177e4SLinus Torvalds if (val < 0) { 25441da177e4SLinus Torvalds *negp = -1; 25451da177e4SLinus Torvalds lval = (unsigned long)-val; 25461da177e4SLinus Torvalds } else { 25471da177e4SLinus Torvalds *negp = 0; 25481da177e4SLinus Torvalds lval = (unsigned long)val; 25491da177e4SLinus Torvalds } 25501da177e4SLinus Torvalds *lvalp = jiffies_to_msecs(lval); 25511da177e4SLinus Torvalds } 25521da177e4SLinus Torvalds return 0; 25531da177e4SLinus Torvalds } 25541da177e4SLinus Torvalds 25551da177e4SLinus Torvalds /** 25561da177e4SLinus Torvalds * proc_dointvec_jiffies - read a vector of integers as seconds 25571da177e4SLinus Torvalds * @table: the sysctl table 25581da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 25591da177e4SLinus Torvalds * @filp: the file structure 25601da177e4SLinus Torvalds * @buffer: the user buffer 25611da177e4SLinus Torvalds * @lenp: the size of the user buffer 25621da177e4SLinus Torvalds * @ppos: file position 25631da177e4SLinus Torvalds * 25641da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 25651da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 25661da177e4SLinus Torvalds * The values read are assumed to be in seconds, and are converted into 25671da177e4SLinus Torvalds * jiffies. 25681da177e4SLinus Torvalds * 25691da177e4SLinus Torvalds * Returns 0 on success. 25701da177e4SLinus Torvalds */ 2571d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, 25721da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25731da177e4SLinus Torvalds { 25741da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 25751da177e4SLinus Torvalds do_proc_dointvec_jiffies_conv,NULL); 25761da177e4SLinus Torvalds } 25771da177e4SLinus Torvalds 25781da177e4SLinus Torvalds /** 25791da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 25801da177e4SLinus Torvalds * @table: the sysctl table 25811da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 25821da177e4SLinus Torvalds * @filp: the file structure 25831da177e4SLinus Torvalds * @buffer: the user buffer 25841da177e4SLinus Torvalds * @lenp: the size of the user buffer 25851e5d5331SRandy Dunlap * @ppos: pointer to the file position 25861da177e4SLinus Torvalds * 25871da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 25881da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 25891da177e4SLinus Torvalds * The values read are assumed to be in 1/USER_HZ seconds, and 25901da177e4SLinus Torvalds * are converted into jiffies. 25911da177e4SLinus Torvalds * 25921da177e4SLinus Torvalds * Returns 0 on success. 25931da177e4SLinus Torvalds */ 2594d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, 25951da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25961da177e4SLinus Torvalds { 25971da177e4SLinus Torvalds return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 25981da177e4SLinus Torvalds do_proc_dointvec_userhz_jiffies_conv,NULL); 25991da177e4SLinus Torvalds } 26001da177e4SLinus Torvalds 26011da177e4SLinus Torvalds /** 26021da177e4SLinus Torvalds * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 26031da177e4SLinus Torvalds * @table: the sysctl table 26041da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 26051da177e4SLinus Torvalds * @filp: the file structure 26061da177e4SLinus Torvalds * @buffer: the user buffer 26071da177e4SLinus Torvalds * @lenp: the size of the user buffer 260867be2dd1SMartin Waitz * @ppos: file position 260967be2dd1SMartin Waitz * @ppos: the current position in the file 26101da177e4SLinus Torvalds * 26111da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 26121da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 26131da177e4SLinus Torvalds * The values read are assumed to be in 1/1000 seconds, and 26141da177e4SLinus Torvalds * are converted into jiffies. 26151da177e4SLinus Torvalds * 26161da177e4SLinus Torvalds * Returns 0 on success. 26171da177e4SLinus Torvalds */ 2618d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, 26191da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26201da177e4SLinus Torvalds { 26211da177e4SLinus Torvalds return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, 26221da177e4SLinus Torvalds do_proc_dointvec_ms_jiffies_conv, NULL); 26231da177e4SLinus Torvalds } 26241da177e4SLinus Torvalds 2625d8217f07SEric W. Biederman static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, 26269ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos) 26279ec52099SCedric Le Goater { 26289ec52099SCedric Le Goater struct pid *new_pid; 26299ec52099SCedric Le Goater pid_t tmp; 26309ec52099SCedric Le Goater int r; 26319ec52099SCedric Le Goater 26326c5f3e7bSPavel Emelyanov tmp = pid_vnr(cad_pid); 26339ec52099SCedric Le Goater 26349ec52099SCedric Le Goater r = __do_proc_dointvec(&tmp, table, write, filp, buffer, 26359ec52099SCedric Le Goater lenp, ppos, NULL, NULL); 26369ec52099SCedric Le Goater if (r || !write) 26379ec52099SCedric Le Goater return r; 26389ec52099SCedric Le Goater 26399ec52099SCedric Le Goater new_pid = find_get_pid(tmp); 26409ec52099SCedric Le Goater if (!new_pid) 26419ec52099SCedric Le Goater return -ESRCH; 26429ec52099SCedric Le Goater 26439ec52099SCedric Le Goater put_pid(xchg(&cad_pid, new_pid)); 26449ec52099SCedric Le Goater return 0; 26459ec52099SCedric Le Goater } 26469ec52099SCedric Le Goater 26471da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */ 26481da177e4SLinus Torvalds 2649d8217f07SEric W. Biederman int proc_dostring(struct ctl_table *table, int write, struct file *filp, 26501da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26511da177e4SLinus Torvalds { 26521da177e4SLinus Torvalds return -ENOSYS; 26531da177e4SLinus Torvalds } 26541da177e4SLinus Torvalds 2655d8217f07SEric W. Biederman int proc_dointvec(struct ctl_table *table, int write, struct file *filp, 26561da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26571da177e4SLinus Torvalds { 26581da177e4SLinus Torvalds return -ENOSYS; 26591da177e4SLinus Torvalds } 26601da177e4SLinus Torvalds 2661d8217f07SEric W. Biederman int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, 26621da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26631da177e4SLinus Torvalds { 26641da177e4SLinus Torvalds return -ENOSYS; 26651da177e4SLinus Torvalds } 26661da177e4SLinus Torvalds 2667d8217f07SEric W. Biederman int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, 26681da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26691da177e4SLinus Torvalds { 26701da177e4SLinus Torvalds return -ENOSYS; 26711da177e4SLinus Torvalds } 26721da177e4SLinus Torvalds 2673d8217f07SEric W. Biederman int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, 26741da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26751da177e4SLinus Torvalds { 26761da177e4SLinus Torvalds return -ENOSYS; 26771da177e4SLinus Torvalds } 26781da177e4SLinus Torvalds 2679d8217f07SEric W. Biederman int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, 26801da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26811da177e4SLinus Torvalds { 26821da177e4SLinus Torvalds return -ENOSYS; 26831da177e4SLinus Torvalds } 26841da177e4SLinus Torvalds 2685d8217f07SEric W. Biederman int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, 26861da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26871da177e4SLinus Torvalds { 26881da177e4SLinus Torvalds return -ENOSYS; 26891da177e4SLinus Torvalds } 26901da177e4SLinus Torvalds 2691d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 26921da177e4SLinus Torvalds struct file *filp, 26931da177e4SLinus Torvalds void __user *buffer, 26941da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 26951da177e4SLinus Torvalds { 26961da177e4SLinus Torvalds return -ENOSYS; 26971da177e4SLinus Torvalds } 26981da177e4SLinus Torvalds 26991da177e4SLinus Torvalds 27001da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */ 27011da177e4SLinus Torvalds 27021da177e4SLinus Torvalds 2703b89a8171SEric W. Biederman #ifdef CONFIG_SYSCTL_SYSCALL 27041da177e4SLinus Torvalds /* 27051da177e4SLinus Torvalds * General sysctl support routines 27061da177e4SLinus Torvalds */ 27071da177e4SLinus Torvalds 270849a0c458SEric W. Biederman /* The generic sysctl data routine (used if no strategy routine supplied) */ 2709f221e726SAlexey Dobriyan int sysctl_data(struct ctl_table *table, 271049a0c458SEric W. Biederman void __user *oldval, size_t __user *oldlenp, 271149a0c458SEric W. Biederman void __user *newval, size_t newlen) 271249a0c458SEric W. Biederman { 271349a0c458SEric W. Biederman size_t len; 271449a0c458SEric W. Biederman 271549a0c458SEric W. Biederman /* Get out of I don't have a variable */ 271649a0c458SEric W. Biederman if (!table->data || !table->maxlen) 271749a0c458SEric W. Biederman return -ENOTDIR; 271849a0c458SEric W. Biederman 271949a0c458SEric W. Biederman if (oldval && oldlenp) { 272049a0c458SEric W. Biederman if (get_user(len, oldlenp)) 272149a0c458SEric W. Biederman return -EFAULT; 272249a0c458SEric W. Biederman if (len) { 272349a0c458SEric W. Biederman if (len > table->maxlen) 272449a0c458SEric W. Biederman len = table->maxlen; 272549a0c458SEric W. Biederman if (copy_to_user(oldval, table->data, len)) 272649a0c458SEric W. Biederman return -EFAULT; 272749a0c458SEric W. Biederman if (put_user(len, oldlenp)) 272849a0c458SEric W. Biederman return -EFAULT; 272949a0c458SEric W. Biederman } 273049a0c458SEric W. Biederman } 273149a0c458SEric W. Biederman 273249a0c458SEric W. Biederman if (newval && newlen) { 273349a0c458SEric W. Biederman if (newlen > table->maxlen) 273449a0c458SEric W. Biederman newlen = table->maxlen; 273549a0c458SEric W. Biederman 273649a0c458SEric W. Biederman if (copy_from_user(table->data, newval, newlen)) 273749a0c458SEric W. Biederman return -EFAULT; 273849a0c458SEric W. Biederman } 273949a0c458SEric W. Biederman return 1; 274049a0c458SEric W. Biederman } 274149a0c458SEric W. Biederman 27421da177e4SLinus Torvalds /* The generic string strategy routine: */ 2743f221e726SAlexey Dobriyan int sysctl_string(struct ctl_table *table, 27441da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 27451f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 27461da177e4SLinus Torvalds { 27471da177e4SLinus Torvalds if (!table->data || !table->maxlen) 27481da177e4SLinus Torvalds return -ENOTDIR; 27491da177e4SLinus Torvalds 27501da177e4SLinus Torvalds if (oldval && oldlenp) { 2751de9e007dSLinus Torvalds size_t bufsize; 2752de9e007dSLinus Torvalds if (get_user(bufsize, oldlenp)) 27531da177e4SLinus Torvalds return -EFAULT; 2754de9e007dSLinus Torvalds if (bufsize) { 2755de9e007dSLinus Torvalds size_t len = strlen(table->data), copied; 2756de9e007dSLinus Torvalds 2757de9e007dSLinus Torvalds /* This shouldn't trigger for a well-formed sysctl */ 2758de9e007dSLinus Torvalds if (len > table->maxlen) 27591da177e4SLinus Torvalds len = table->maxlen; 2760de9e007dSLinus Torvalds 2761de9e007dSLinus Torvalds /* Copy up to a max of bufsize-1 bytes of the string */ 2762de9e007dSLinus Torvalds copied = (len >= bufsize) ? bufsize - 1 : len; 2763de9e007dSLinus Torvalds 2764de9e007dSLinus Torvalds if (copy_to_user(oldval, table->data, copied) || 2765de9e007dSLinus Torvalds put_user(0, (char __user *)(oldval + copied))) 27661da177e4SLinus Torvalds return -EFAULT; 27671da177e4SLinus Torvalds if (put_user(len, oldlenp)) 27681da177e4SLinus Torvalds return -EFAULT; 27691da177e4SLinus Torvalds } 27701da177e4SLinus Torvalds } 27711da177e4SLinus Torvalds if (newval && newlen) { 2772de9e007dSLinus Torvalds size_t len = newlen; 27731da177e4SLinus Torvalds if (len > table->maxlen) 27741da177e4SLinus Torvalds len = table->maxlen; 27751da177e4SLinus Torvalds if(copy_from_user(table->data, newval, len)) 27761da177e4SLinus Torvalds return -EFAULT; 27771da177e4SLinus Torvalds if (len == table->maxlen) 27781da177e4SLinus Torvalds len--; 27791da177e4SLinus Torvalds ((char *) table->data)[len] = 0; 27801da177e4SLinus Torvalds } 278182c9df82SYi Yang return 1; 27821da177e4SLinus Torvalds } 27831da177e4SLinus Torvalds 27841da177e4SLinus Torvalds /* 27851da177e4SLinus Torvalds * This function makes sure that all of the integers in the vector 27861da177e4SLinus Torvalds * are between the minimum and maximum values given in the arrays 27871da177e4SLinus Torvalds * table->extra1 and table->extra2, respectively. 27881da177e4SLinus Torvalds */ 2789f221e726SAlexey Dobriyan int sysctl_intvec(struct ctl_table *table, 27901da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 27911f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 27921da177e4SLinus Torvalds { 27931da177e4SLinus Torvalds 27941da177e4SLinus Torvalds if (newval && newlen) { 27951da177e4SLinus Torvalds int __user *vec = (int __user *) newval; 27961da177e4SLinus Torvalds int *min = (int *) table->extra1; 27971da177e4SLinus Torvalds int *max = (int *) table->extra2; 27981da177e4SLinus Torvalds size_t length; 27991da177e4SLinus Torvalds int i; 28001da177e4SLinus Torvalds 28011da177e4SLinus Torvalds if (newlen % sizeof(int) != 0) 28021da177e4SLinus Torvalds return -EINVAL; 28031da177e4SLinus Torvalds 28041da177e4SLinus Torvalds if (!table->extra1 && !table->extra2) 28051da177e4SLinus Torvalds return 0; 28061da177e4SLinus Torvalds 28071da177e4SLinus Torvalds if (newlen > table->maxlen) 28081da177e4SLinus Torvalds newlen = table->maxlen; 28091da177e4SLinus Torvalds length = newlen / sizeof(int); 28101da177e4SLinus Torvalds 28111da177e4SLinus Torvalds for (i = 0; i < length; i++) { 28121da177e4SLinus Torvalds int value; 28131da177e4SLinus Torvalds if (get_user(value, vec + i)) 28141da177e4SLinus Torvalds return -EFAULT; 28151da177e4SLinus Torvalds if (min && value < min[i]) 28161da177e4SLinus Torvalds return -EINVAL; 28171da177e4SLinus Torvalds if (max && value > max[i]) 28181da177e4SLinus Torvalds return -EINVAL; 28191da177e4SLinus Torvalds } 28201da177e4SLinus Torvalds } 28211da177e4SLinus Torvalds return 0; 28221da177e4SLinus Torvalds } 28231da177e4SLinus Torvalds 28241da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */ 2825f221e726SAlexey Dobriyan int sysctl_jiffies(struct ctl_table *table, 28261da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 28271f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 28281da177e4SLinus Torvalds { 28293ee75ac3SAlexey Dobriyan if (oldval && oldlenp) { 28301da177e4SLinus Torvalds size_t olen; 28313ee75ac3SAlexey Dobriyan 28321da177e4SLinus Torvalds if (get_user(olen, oldlenp)) 28331da177e4SLinus Torvalds return -EFAULT; 28343ee75ac3SAlexey Dobriyan if (olen) { 28353ee75ac3SAlexey Dobriyan int val; 28363ee75ac3SAlexey Dobriyan 28373ee75ac3SAlexey Dobriyan if (olen < sizeof(int)) 28381da177e4SLinus Torvalds return -EINVAL; 28393ee75ac3SAlexey Dobriyan 28403ee75ac3SAlexey Dobriyan val = *(int *)(table->data) / HZ; 28413ee75ac3SAlexey Dobriyan if (put_user(val, (int __user *)oldval)) 28421da177e4SLinus Torvalds return -EFAULT; 28433ee75ac3SAlexey Dobriyan if (put_user(sizeof(int), oldlenp)) 28443ee75ac3SAlexey Dobriyan return -EFAULT; 28453ee75ac3SAlexey Dobriyan } 28461da177e4SLinus Torvalds } 28471da177e4SLinus Torvalds if (newval && newlen) { 28481da177e4SLinus Torvalds int new; 28491da177e4SLinus Torvalds if (newlen != sizeof(int)) 28501da177e4SLinus Torvalds return -EINVAL; 28511da177e4SLinus Torvalds if (get_user(new, (int __user *)newval)) 28521da177e4SLinus Torvalds return -EFAULT; 28531da177e4SLinus Torvalds *(int *)(table->data) = new*HZ; 28541da177e4SLinus Torvalds } 28551da177e4SLinus Torvalds return 1; 28561da177e4SLinus Torvalds } 28571da177e4SLinus Torvalds 28581da177e4SLinus Torvalds /* Strategy function to convert jiffies to seconds */ 2859f221e726SAlexey Dobriyan int sysctl_ms_jiffies(struct ctl_table *table, 28601da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 28611f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 28621da177e4SLinus Torvalds { 28633ee75ac3SAlexey Dobriyan if (oldval && oldlenp) { 28641da177e4SLinus Torvalds size_t olen; 28653ee75ac3SAlexey Dobriyan 28661da177e4SLinus Torvalds if (get_user(olen, oldlenp)) 28671da177e4SLinus Torvalds return -EFAULT; 28683ee75ac3SAlexey Dobriyan if (olen) { 28693ee75ac3SAlexey Dobriyan int val; 28703ee75ac3SAlexey Dobriyan 28713ee75ac3SAlexey Dobriyan if (olen < sizeof(int)) 28721da177e4SLinus Torvalds return -EINVAL; 28733ee75ac3SAlexey Dobriyan 28743ee75ac3SAlexey Dobriyan val = jiffies_to_msecs(*(int *)(table->data)); 28753ee75ac3SAlexey Dobriyan if (put_user(val, (int __user *)oldval)) 28761da177e4SLinus Torvalds return -EFAULT; 28773ee75ac3SAlexey Dobriyan if (put_user(sizeof(int), oldlenp)) 28783ee75ac3SAlexey Dobriyan return -EFAULT; 28793ee75ac3SAlexey Dobriyan } 28801da177e4SLinus Torvalds } 28811da177e4SLinus Torvalds if (newval && newlen) { 28821da177e4SLinus Torvalds int new; 28831da177e4SLinus Torvalds if (newlen != sizeof(int)) 28841da177e4SLinus Torvalds return -EINVAL; 28851da177e4SLinus Torvalds if (get_user(new, (int __user *)newval)) 28861da177e4SLinus Torvalds return -EFAULT; 28871da177e4SLinus Torvalds *(int *)(table->data) = msecs_to_jiffies(new); 28881da177e4SLinus Torvalds } 28891da177e4SLinus Torvalds return 1; 28901da177e4SLinus Torvalds } 28911da177e4SLinus Torvalds 2892c4b8b769SEric W. Biederman 2893c4b8b769SEric W. Biederman 2894b89a8171SEric W. Biederman #else /* CONFIG_SYSCTL_SYSCALL */ 28951da177e4SLinus Torvalds 28961da177e4SLinus Torvalds 28971da177e4SLinus Torvalds asmlinkage long sys_sysctl(struct __sysctl_args __user *args) 28981da177e4SLinus Torvalds { 28990e009be8SEric W. Biederman struct __sysctl_args tmp; 29007058cb02SEric W. Biederman int error; 29010e009be8SEric W. Biederman 29020e009be8SEric W. Biederman if (copy_from_user(&tmp, args, sizeof(tmp))) 29030e009be8SEric W. Biederman return -EFAULT; 29040e009be8SEric W. Biederman 29057058cb02SEric W. Biederman error = deprecated_sysctl_warning(&tmp); 2906b89a8171SEric W. Biederman 29077058cb02SEric W. Biederman /* If no error reading the parameters then just -ENOSYS ... */ 29087058cb02SEric W. Biederman if (!error) 29097058cb02SEric W. Biederman error = -ENOSYS; 29107058cb02SEric W. Biederman 29117058cb02SEric W. Biederman return error; 29121da177e4SLinus Torvalds } 29131da177e4SLinus Torvalds 2914f221e726SAlexey Dobriyan int sysctl_data(struct ctl_table *table, 291549a0c458SEric W. Biederman void __user *oldval, size_t __user *oldlenp, 291649a0c458SEric W. Biederman void __user *newval, size_t newlen) 291749a0c458SEric W. Biederman { 291849a0c458SEric W. Biederman return -ENOSYS; 291949a0c458SEric W. Biederman } 292049a0c458SEric W. Biederman 2921f221e726SAlexey Dobriyan int sysctl_string(struct ctl_table *table, 29221da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 29231f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 29241da177e4SLinus Torvalds { 29251da177e4SLinus Torvalds return -ENOSYS; 29261da177e4SLinus Torvalds } 29271da177e4SLinus Torvalds 2928f221e726SAlexey Dobriyan int sysctl_intvec(struct ctl_table *table, 29291da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 29301f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 29311da177e4SLinus Torvalds { 29321da177e4SLinus Torvalds return -ENOSYS; 29331da177e4SLinus Torvalds } 29341da177e4SLinus Torvalds 2935f221e726SAlexey Dobriyan int sysctl_jiffies(struct ctl_table *table, 29361da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 29371f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 29381da177e4SLinus Torvalds { 29391da177e4SLinus Torvalds return -ENOSYS; 29401da177e4SLinus Torvalds } 29411da177e4SLinus Torvalds 2942f221e726SAlexey Dobriyan int sysctl_ms_jiffies(struct ctl_table *table, 29431da177e4SLinus Torvalds void __user *oldval, size_t __user *oldlenp, 29441f29bcd7SAlexey Dobriyan void __user *newval, size_t newlen) 29451da177e4SLinus Torvalds { 29461da177e4SLinus Torvalds return -ENOSYS; 29471da177e4SLinus Torvalds } 29481da177e4SLinus Torvalds 2949b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL_SYSCALL */ 29501da177e4SLinus Torvalds 29517058cb02SEric W. Biederman static int deprecated_sysctl_warning(struct __sysctl_args *args) 29527058cb02SEric W. Biederman { 29537058cb02SEric W. Biederman static int msg_count; 29547058cb02SEric W. Biederman int name[CTL_MAXNAME]; 29557058cb02SEric W. Biederman int i; 29567058cb02SEric W. Biederman 29576fc48af8STetsuo Handa /* Check args->nlen. */ 29586fc48af8STetsuo Handa if (args->nlen < 0 || args->nlen > CTL_MAXNAME) 29596fc48af8STetsuo Handa return -ENOTDIR; 29606fc48af8STetsuo Handa 29617058cb02SEric W. Biederman /* Read in the sysctl name for better debug message logging */ 29627058cb02SEric W. Biederman for (i = 0; i < args->nlen; i++) 29637058cb02SEric W. Biederman if (get_user(name[i], args->name + i)) 29647058cb02SEric W. Biederman return -EFAULT; 29657058cb02SEric W. Biederman 29667058cb02SEric W. Biederman /* Ignore accesses to kernel.version */ 29677058cb02SEric W. Biederman if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION)) 29687058cb02SEric W. Biederman return 0; 29697058cb02SEric W. Biederman 29707058cb02SEric W. Biederman if (msg_count < 5) { 29717058cb02SEric W. Biederman msg_count++; 29727058cb02SEric W. Biederman printk(KERN_INFO 29737058cb02SEric W. Biederman "warning: process `%s' used the deprecated sysctl " 29747058cb02SEric W. Biederman "system call with ", current->comm); 29757058cb02SEric W. Biederman for (i = 0; i < args->nlen; i++) 29767058cb02SEric W. Biederman printk("%d.", name[i]); 29777058cb02SEric W. Biederman printk("\n"); 29787058cb02SEric W. Biederman } 29797058cb02SEric W. Biederman return 0; 29807058cb02SEric W. Biederman } 29817058cb02SEric W. Biederman 29821da177e4SLinus Torvalds /* 29831da177e4SLinus Torvalds * No sense putting this after each symbol definition, twice, 29841da177e4SLinus Torvalds * exception granted :-) 29851da177e4SLinus Torvalds */ 29861da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec); 29871da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies); 29881da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax); 29891da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 29901da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 29911da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring); 29921da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax); 29931da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 29941da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table); 299529e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths); 29961da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_intvec); 29971da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_jiffies); 29981da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_ms_jiffies); 29991da177e4SLinus Torvalds EXPORT_SYMBOL(sysctl_string); 300049a0c458SEric W. Biederman EXPORT_SYMBOL(sysctl_data); 30011da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table); 3002