1 /* 2 * sysctl.c: General linux system control interface 3 * 4 * Begun 24 March 1995, Stephen Tweedie 5 * Added /proc support, Dec 1995 6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. 7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. 8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver. 9 * Dynamic registration fixes, Stephen Tweedie. 10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn. 11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris 12 * Horn. 13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer. 14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer. 15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill 16 * Wendling. 17 * The list_for_each() macro wasn't appropriate for the sysctl loop. 18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling 19 */ 20 21 #include <linux/module.h> 22 #include <linux/mm.h> 23 #include <linux/swap.h> 24 #include <linux/slab.h> 25 #include <linux/sysctl.h> 26 #include <linux/proc_fs.h> 27 #include <linux/security.h> 28 #include <linux/ctype.h> 29 #include <linux/utsname.h> 30 #include <linux/smp_lock.h> 31 #include <linux/fs.h> 32 #include <linux/init.h> 33 #include <linux/kernel.h> 34 #include <linux/kobject.h> 35 #include <linux/net.h> 36 #include <linux/sysrq.h> 37 #include <linux/highuid.h> 38 #include <linux/writeback.h> 39 #include <linux/hugetlb.h> 40 #include <linux/initrd.h> 41 #include <linux/key.h> 42 #include <linux/times.h> 43 #include <linux/limits.h> 44 #include <linux/dcache.h> 45 #include <linux/syscalls.h> 46 #include <linux/vmstat.h> 47 #include <linux/nfs_fs.h> 48 #include <linux/acpi.h> 49 #include <linux/reboot.h> 50 #include <linux/ftrace.h> 51 52 #include <asm/uaccess.h> 53 #include <asm/processor.h> 54 55 #ifdef CONFIG_X86 56 #include <asm/nmi.h> 57 #include <asm/stacktrace.h> 58 #include <asm/io.h> 59 #endif 60 61 static int deprecated_sysctl_warning(struct __sysctl_args *args); 62 63 #if defined(CONFIG_SYSCTL) 64 65 /* External variables not in a header file. */ 66 extern int C_A_D; 67 extern int print_fatal_signals; 68 extern int sysctl_overcommit_memory; 69 extern int sysctl_overcommit_ratio; 70 extern int sysctl_panic_on_oom; 71 extern int sysctl_oom_kill_allocating_task; 72 extern int sysctl_oom_dump_tasks; 73 extern int max_threads; 74 extern int core_uses_pid; 75 extern int suid_dumpable; 76 extern char core_pattern[]; 77 extern int pid_max; 78 extern int min_free_kbytes; 79 extern int pid_max_min, pid_max_max; 80 extern int sysctl_drop_caches; 81 extern int percpu_pagelist_fraction; 82 extern int compat_log; 83 extern int latencytop_enabled; 84 extern int sysctl_nr_open_min, sysctl_nr_open_max; 85 #ifdef CONFIG_RCU_TORTURE_TEST 86 extern int rcutorture_runnable; 87 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ 88 89 /* Constants used for minimum and maximum */ 90 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP) 91 static int one = 1; 92 #endif 93 94 #ifdef CONFIG_DETECT_SOFTLOCKUP 95 static int sixty = 60; 96 static int neg_one = -1; 97 #endif 98 99 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING) 100 static int two = 2; 101 #endif 102 103 static int zero; 104 static int one_hundred = 100; 105 106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ 107 static int maxolduid = 65535; 108 static int minolduid; 109 static int min_percpu_pagelist_fract = 8; 110 111 static int ngroups_max = NGROUPS_MAX; 112 113 #ifdef CONFIG_MODULES 114 extern char modprobe_path[]; 115 #endif 116 #ifdef CONFIG_CHR_DEV_SG 117 extern int sg_big_buff; 118 #endif 119 120 #ifdef CONFIG_SPARC 121 #include <asm/system.h> 122 #endif 123 124 #ifdef __hppa__ 125 extern int pwrsw_enabled; 126 extern int unaligned_enabled; 127 #endif 128 129 #ifdef CONFIG_S390 130 #ifdef CONFIG_MATHEMU 131 extern int sysctl_ieee_emulation_warnings; 132 #endif 133 extern int sysctl_userprocess_debug; 134 extern int spin_retry; 135 #endif 136 137 #ifdef CONFIG_BSD_PROCESS_ACCT 138 extern int acct_parm[]; 139 #endif 140 141 #ifdef CONFIG_IA64 142 extern int no_unaligned_warning; 143 #endif 144 145 #ifdef CONFIG_RT_MUTEXES 146 extern int max_lock_depth; 147 #endif 148 149 #ifdef CONFIG_PROC_SYSCTL 150 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, 151 void __user *buffer, size_t *lenp, loff_t *ppos); 152 static int proc_taint(struct ctl_table *table, int write, struct file *filp, 153 void __user *buffer, size_t *lenp, loff_t *ppos); 154 #endif 155 156 static struct ctl_table root_table[]; 157 static struct ctl_table_root sysctl_table_root; 158 static struct ctl_table_header root_table_header = { 159 .count = 1, 160 .ctl_table = root_table, 161 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list), 162 .root = &sysctl_table_root, 163 .set = &sysctl_table_root.default_set, 164 }; 165 static struct ctl_table_root sysctl_table_root = { 166 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), 167 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry), 168 }; 169 170 static struct ctl_table kern_table[]; 171 static struct ctl_table vm_table[]; 172 static struct ctl_table fs_table[]; 173 static struct ctl_table debug_table[]; 174 static struct ctl_table dev_table[]; 175 extern struct ctl_table random_table[]; 176 #ifdef CONFIG_INOTIFY_USER 177 extern struct ctl_table inotify_table[]; 178 #endif 179 180 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 181 int sysctl_legacy_va_layout; 182 #endif 183 184 extern int prove_locking; 185 extern int lock_stat; 186 187 /* The default sysctl tables: */ 188 189 static struct ctl_table root_table[] = { 190 { 191 .ctl_name = CTL_KERN, 192 .procname = "kernel", 193 .mode = 0555, 194 .child = kern_table, 195 }, 196 { 197 .ctl_name = CTL_VM, 198 .procname = "vm", 199 .mode = 0555, 200 .child = vm_table, 201 }, 202 { 203 .ctl_name = CTL_FS, 204 .procname = "fs", 205 .mode = 0555, 206 .child = fs_table, 207 }, 208 { 209 .ctl_name = CTL_DEBUG, 210 .procname = "debug", 211 .mode = 0555, 212 .child = debug_table, 213 }, 214 { 215 .ctl_name = CTL_DEV, 216 .procname = "dev", 217 .mode = 0555, 218 .child = dev_table, 219 }, 220 /* 221 * NOTE: do not add new entries to this table unless you have read 222 * Documentation/sysctl/ctl_unnumbered.txt 223 */ 224 { .ctl_name = 0 } 225 }; 226 227 #ifdef CONFIG_SCHED_DEBUG 228 static int min_sched_granularity_ns = 100000; /* 100 usecs */ 229 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */ 230 static int min_wakeup_granularity_ns; /* 0 usecs */ 231 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */ 232 #endif 233 234 static struct ctl_table kern_table[] = { 235 #ifdef CONFIG_SCHED_DEBUG 236 { 237 .ctl_name = CTL_UNNUMBERED, 238 .procname = "sched_min_granularity_ns", 239 .data = &sysctl_sched_min_granularity, 240 .maxlen = sizeof(unsigned int), 241 .mode = 0644, 242 .proc_handler = &sched_nr_latency_handler, 243 .strategy = &sysctl_intvec, 244 .extra1 = &min_sched_granularity_ns, 245 .extra2 = &max_sched_granularity_ns, 246 }, 247 { 248 .ctl_name = CTL_UNNUMBERED, 249 .procname = "sched_latency_ns", 250 .data = &sysctl_sched_latency, 251 .maxlen = sizeof(unsigned int), 252 .mode = 0644, 253 .proc_handler = &sched_nr_latency_handler, 254 .strategy = &sysctl_intvec, 255 .extra1 = &min_sched_granularity_ns, 256 .extra2 = &max_sched_granularity_ns, 257 }, 258 { 259 .ctl_name = CTL_UNNUMBERED, 260 .procname = "sched_wakeup_granularity_ns", 261 .data = &sysctl_sched_wakeup_granularity, 262 .maxlen = sizeof(unsigned int), 263 .mode = 0644, 264 .proc_handler = &proc_dointvec_minmax, 265 .strategy = &sysctl_intvec, 266 .extra1 = &min_wakeup_granularity_ns, 267 .extra2 = &max_wakeup_granularity_ns, 268 }, 269 { 270 .ctl_name = CTL_UNNUMBERED, 271 .procname = "sched_shares_ratelimit", 272 .data = &sysctl_sched_shares_ratelimit, 273 .maxlen = sizeof(unsigned int), 274 .mode = 0644, 275 .proc_handler = &proc_dointvec, 276 }, 277 { 278 .ctl_name = CTL_UNNUMBERED, 279 .procname = "sched_child_runs_first", 280 .data = &sysctl_sched_child_runs_first, 281 .maxlen = sizeof(unsigned int), 282 .mode = 0644, 283 .proc_handler = &proc_dointvec, 284 }, 285 { 286 .ctl_name = CTL_UNNUMBERED, 287 .procname = "sched_features", 288 .data = &sysctl_sched_features, 289 .maxlen = sizeof(unsigned int), 290 .mode = 0644, 291 .proc_handler = &proc_dointvec, 292 }, 293 { 294 .ctl_name = CTL_UNNUMBERED, 295 .procname = "sched_migration_cost", 296 .data = &sysctl_sched_migration_cost, 297 .maxlen = sizeof(unsigned int), 298 .mode = 0644, 299 .proc_handler = &proc_dointvec, 300 }, 301 { 302 .ctl_name = CTL_UNNUMBERED, 303 .procname = "sched_nr_migrate", 304 .data = &sysctl_sched_nr_migrate, 305 .maxlen = sizeof(unsigned int), 306 .mode = 0644, 307 .proc_handler = &proc_dointvec, 308 }, 309 #endif 310 { 311 .ctl_name = CTL_UNNUMBERED, 312 .procname = "sched_rt_period_us", 313 .data = &sysctl_sched_rt_period, 314 .maxlen = sizeof(unsigned int), 315 .mode = 0644, 316 .proc_handler = &sched_rt_handler, 317 }, 318 { 319 .ctl_name = CTL_UNNUMBERED, 320 .procname = "sched_rt_runtime_us", 321 .data = &sysctl_sched_rt_runtime, 322 .maxlen = sizeof(int), 323 .mode = 0644, 324 .proc_handler = &sched_rt_handler, 325 }, 326 { 327 .ctl_name = CTL_UNNUMBERED, 328 .procname = "sched_compat_yield", 329 .data = &sysctl_sched_compat_yield, 330 .maxlen = sizeof(unsigned int), 331 .mode = 0644, 332 .proc_handler = &proc_dointvec, 333 }, 334 #ifdef CONFIG_PROVE_LOCKING 335 { 336 .ctl_name = CTL_UNNUMBERED, 337 .procname = "prove_locking", 338 .data = &prove_locking, 339 .maxlen = sizeof(int), 340 .mode = 0644, 341 .proc_handler = &proc_dointvec, 342 }, 343 #endif 344 #ifdef CONFIG_LOCK_STAT 345 { 346 .ctl_name = CTL_UNNUMBERED, 347 .procname = "lock_stat", 348 .data = &lock_stat, 349 .maxlen = sizeof(int), 350 .mode = 0644, 351 .proc_handler = &proc_dointvec, 352 }, 353 #endif 354 { 355 .ctl_name = KERN_PANIC, 356 .procname = "panic", 357 .data = &panic_timeout, 358 .maxlen = sizeof(int), 359 .mode = 0644, 360 .proc_handler = &proc_dointvec, 361 }, 362 { 363 .ctl_name = KERN_CORE_USES_PID, 364 .procname = "core_uses_pid", 365 .data = &core_uses_pid, 366 .maxlen = sizeof(int), 367 .mode = 0644, 368 .proc_handler = &proc_dointvec, 369 }, 370 { 371 .ctl_name = KERN_CORE_PATTERN, 372 .procname = "core_pattern", 373 .data = core_pattern, 374 .maxlen = CORENAME_MAX_SIZE, 375 .mode = 0644, 376 .proc_handler = &proc_dostring, 377 .strategy = &sysctl_string, 378 }, 379 #ifdef CONFIG_PROC_SYSCTL 380 { 381 .procname = "tainted", 382 .maxlen = sizeof(long), 383 .mode = 0644, 384 .proc_handler = &proc_taint, 385 }, 386 #endif 387 #ifdef CONFIG_LATENCYTOP 388 { 389 .procname = "latencytop", 390 .data = &latencytop_enabled, 391 .maxlen = sizeof(int), 392 .mode = 0644, 393 .proc_handler = &proc_dointvec, 394 }, 395 #endif 396 #ifdef CONFIG_BLK_DEV_INITRD 397 { 398 .ctl_name = KERN_REALROOTDEV, 399 .procname = "real-root-dev", 400 .data = &real_root_dev, 401 .maxlen = sizeof(int), 402 .mode = 0644, 403 .proc_handler = &proc_dointvec, 404 }, 405 #endif 406 { 407 .ctl_name = CTL_UNNUMBERED, 408 .procname = "print-fatal-signals", 409 .data = &print_fatal_signals, 410 .maxlen = sizeof(int), 411 .mode = 0644, 412 .proc_handler = &proc_dointvec, 413 }, 414 #ifdef CONFIG_SPARC 415 { 416 .ctl_name = KERN_SPARC_REBOOT, 417 .procname = "reboot-cmd", 418 .data = reboot_command, 419 .maxlen = 256, 420 .mode = 0644, 421 .proc_handler = &proc_dostring, 422 .strategy = &sysctl_string, 423 }, 424 { 425 .ctl_name = KERN_SPARC_STOP_A, 426 .procname = "stop-a", 427 .data = &stop_a_enabled, 428 .maxlen = sizeof (int), 429 .mode = 0644, 430 .proc_handler = &proc_dointvec, 431 }, 432 { 433 .ctl_name = KERN_SPARC_SCONS_PWROFF, 434 .procname = "scons-poweroff", 435 .data = &scons_pwroff, 436 .maxlen = sizeof (int), 437 .mode = 0644, 438 .proc_handler = &proc_dointvec, 439 }, 440 #endif 441 #ifdef __hppa__ 442 { 443 .ctl_name = KERN_HPPA_PWRSW, 444 .procname = "soft-power", 445 .data = &pwrsw_enabled, 446 .maxlen = sizeof (int), 447 .mode = 0644, 448 .proc_handler = &proc_dointvec, 449 }, 450 { 451 .ctl_name = KERN_HPPA_UNALIGNED, 452 .procname = "unaligned-trap", 453 .data = &unaligned_enabled, 454 .maxlen = sizeof (int), 455 .mode = 0644, 456 .proc_handler = &proc_dointvec, 457 }, 458 #endif 459 { 460 .ctl_name = KERN_CTLALTDEL, 461 .procname = "ctrl-alt-del", 462 .data = &C_A_D, 463 .maxlen = sizeof(int), 464 .mode = 0644, 465 .proc_handler = &proc_dointvec, 466 }, 467 #ifdef CONFIG_FTRACE 468 { 469 .ctl_name = CTL_UNNUMBERED, 470 .procname = "ftrace_enabled", 471 .data = &ftrace_enabled, 472 .maxlen = sizeof(int), 473 .mode = 0644, 474 .proc_handler = &ftrace_enable_sysctl, 475 }, 476 #endif 477 #ifdef CONFIG_MODULES 478 { 479 .ctl_name = KERN_MODPROBE, 480 .procname = "modprobe", 481 .data = &modprobe_path, 482 .maxlen = KMOD_PATH_LEN, 483 .mode = 0644, 484 .proc_handler = &proc_dostring, 485 .strategy = &sysctl_string, 486 }, 487 #endif 488 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) 489 { 490 .ctl_name = KERN_HOTPLUG, 491 .procname = "hotplug", 492 .data = &uevent_helper, 493 .maxlen = UEVENT_HELPER_PATH_LEN, 494 .mode = 0644, 495 .proc_handler = &proc_dostring, 496 .strategy = &sysctl_string, 497 }, 498 #endif 499 #ifdef CONFIG_CHR_DEV_SG 500 { 501 .ctl_name = KERN_SG_BIG_BUFF, 502 .procname = "sg-big-buff", 503 .data = &sg_big_buff, 504 .maxlen = sizeof (int), 505 .mode = 0444, 506 .proc_handler = &proc_dointvec, 507 }, 508 #endif 509 #ifdef CONFIG_BSD_PROCESS_ACCT 510 { 511 .ctl_name = KERN_ACCT, 512 .procname = "acct", 513 .data = &acct_parm, 514 .maxlen = 3*sizeof(int), 515 .mode = 0644, 516 .proc_handler = &proc_dointvec, 517 }, 518 #endif 519 #ifdef CONFIG_MAGIC_SYSRQ 520 { 521 .ctl_name = KERN_SYSRQ, 522 .procname = "sysrq", 523 .data = &__sysrq_enabled, 524 .maxlen = sizeof (int), 525 .mode = 0644, 526 .proc_handler = &proc_dointvec, 527 }, 528 #endif 529 #ifdef CONFIG_PROC_SYSCTL 530 { 531 .procname = "cad_pid", 532 .data = NULL, 533 .maxlen = sizeof (int), 534 .mode = 0600, 535 .proc_handler = &proc_do_cad_pid, 536 }, 537 #endif 538 { 539 .ctl_name = KERN_MAX_THREADS, 540 .procname = "threads-max", 541 .data = &max_threads, 542 .maxlen = sizeof(int), 543 .mode = 0644, 544 .proc_handler = &proc_dointvec, 545 }, 546 { 547 .ctl_name = KERN_RANDOM, 548 .procname = "random", 549 .mode = 0555, 550 .child = random_table, 551 }, 552 { 553 .ctl_name = KERN_OVERFLOWUID, 554 .procname = "overflowuid", 555 .data = &overflowuid, 556 .maxlen = sizeof(int), 557 .mode = 0644, 558 .proc_handler = &proc_dointvec_minmax, 559 .strategy = &sysctl_intvec, 560 .extra1 = &minolduid, 561 .extra2 = &maxolduid, 562 }, 563 { 564 .ctl_name = KERN_OVERFLOWGID, 565 .procname = "overflowgid", 566 .data = &overflowgid, 567 .maxlen = sizeof(int), 568 .mode = 0644, 569 .proc_handler = &proc_dointvec_minmax, 570 .strategy = &sysctl_intvec, 571 .extra1 = &minolduid, 572 .extra2 = &maxolduid, 573 }, 574 #ifdef CONFIG_S390 575 #ifdef CONFIG_MATHEMU 576 { 577 .ctl_name = KERN_IEEE_EMULATION_WARNINGS, 578 .procname = "ieee_emulation_warnings", 579 .data = &sysctl_ieee_emulation_warnings, 580 .maxlen = sizeof(int), 581 .mode = 0644, 582 .proc_handler = &proc_dointvec, 583 }, 584 #endif 585 { 586 .ctl_name = KERN_S390_USER_DEBUG_LOGGING, 587 .procname = "userprocess_debug", 588 .data = &sysctl_userprocess_debug, 589 .maxlen = sizeof(int), 590 .mode = 0644, 591 .proc_handler = &proc_dointvec, 592 }, 593 #endif 594 { 595 .ctl_name = KERN_PIDMAX, 596 .procname = "pid_max", 597 .data = &pid_max, 598 .maxlen = sizeof (int), 599 .mode = 0644, 600 .proc_handler = &proc_dointvec_minmax, 601 .strategy = sysctl_intvec, 602 .extra1 = &pid_max_min, 603 .extra2 = &pid_max_max, 604 }, 605 { 606 .ctl_name = KERN_PANIC_ON_OOPS, 607 .procname = "panic_on_oops", 608 .data = &panic_on_oops, 609 .maxlen = sizeof(int), 610 .mode = 0644, 611 .proc_handler = &proc_dointvec, 612 }, 613 #if defined CONFIG_PRINTK 614 { 615 .ctl_name = KERN_PRINTK, 616 .procname = "printk", 617 .data = &console_loglevel, 618 .maxlen = 4*sizeof(int), 619 .mode = 0644, 620 .proc_handler = &proc_dointvec, 621 }, 622 { 623 .ctl_name = KERN_PRINTK_RATELIMIT, 624 .procname = "printk_ratelimit", 625 .data = &printk_ratelimit_state.interval, 626 .maxlen = sizeof(int), 627 .mode = 0644, 628 .proc_handler = &proc_dointvec_jiffies, 629 .strategy = &sysctl_jiffies, 630 }, 631 { 632 .ctl_name = KERN_PRINTK_RATELIMIT_BURST, 633 .procname = "printk_ratelimit_burst", 634 .data = &printk_ratelimit_state.burst, 635 .maxlen = sizeof(int), 636 .mode = 0644, 637 .proc_handler = &proc_dointvec, 638 }, 639 #endif 640 { 641 .ctl_name = KERN_NGROUPS_MAX, 642 .procname = "ngroups_max", 643 .data = &ngroups_max, 644 .maxlen = sizeof (int), 645 .mode = 0444, 646 .proc_handler = &proc_dointvec, 647 }, 648 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) 649 { 650 .ctl_name = KERN_UNKNOWN_NMI_PANIC, 651 .procname = "unknown_nmi_panic", 652 .data = &unknown_nmi_panic, 653 .maxlen = sizeof (int), 654 .mode = 0644, 655 .proc_handler = &proc_dointvec, 656 }, 657 { 658 .procname = "nmi_watchdog", 659 .data = &nmi_watchdog_enabled, 660 .maxlen = sizeof (int), 661 .mode = 0644, 662 .proc_handler = &proc_nmi_enabled, 663 }, 664 #endif 665 #if defined(CONFIG_X86) 666 { 667 .ctl_name = KERN_PANIC_ON_NMI, 668 .procname = "panic_on_unrecovered_nmi", 669 .data = &panic_on_unrecovered_nmi, 670 .maxlen = sizeof(int), 671 .mode = 0644, 672 .proc_handler = &proc_dointvec, 673 }, 674 { 675 .ctl_name = KERN_BOOTLOADER_TYPE, 676 .procname = "bootloader_type", 677 .data = &bootloader_type, 678 .maxlen = sizeof (int), 679 .mode = 0444, 680 .proc_handler = &proc_dointvec, 681 }, 682 { 683 .ctl_name = CTL_UNNUMBERED, 684 .procname = "kstack_depth_to_print", 685 .data = &kstack_depth_to_print, 686 .maxlen = sizeof(int), 687 .mode = 0644, 688 .proc_handler = &proc_dointvec, 689 }, 690 { 691 .ctl_name = CTL_UNNUMBERED, 692 .procname = "io_delay_type", 693 .data = &io_delay_type, 694 .maxlen = sizeof(int), 695 .mode = 0644, 696 .proc_handler = &proc_dointvec, 697 }, 698 #endif 699 #if defined(CONFIG_MMU) 700 { 701 .ctl_name = KERN_RANDOMIZE, 702 .procname = "randomize_va_space", 703 .data = &randomize_va_space, 704 .maxlen = sizeof(int), 705 .mode = 0644, 706 .proc_handler = &proc_dointvec, 707 }, 708 #endif 709 #if defined(CONFIG_S390) && defined(CONFIG_SMP) 710 { 711 .ctl_name = KERN_SPIN_RETRY, 712 .procname = "spin_retry", 713 .data = &spin_retry, 714 .maxlen = sizeof (int), 715 .mode = 0644, 716 .proc_handler = &proc_dointvec, 717 }, 718 #endif 719 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 720 { 721 .procname = "acpi_video_flags", 722 .data = &acpi_realmode_flags, 723 .maxlen = sizeof (unsigned long), 724 .mode = 0644, 725 .proc_handler = &proc_doulongvec_minmax, 726 }, 727 #endif 728 #ifdef CONFIG_IA64 729 { 730 .ctl_name = KERN_IA64_UNALIGNED, 731 .procname = "ignore-unaligned-usertrap", 732 .data = &no_unaligned_warning, 733 .maxlen = sizeof (int), 734 .mode = 0644, 735 .proc_handler = &proc_dointvec, 736 }, 737 #endif 738 #ifdef CONFIG_DETECT_SOFTLOCKUP 739 { 740 .ctl_name = CTL_UNNUMBERED, 741 .procname = "softlockup_panic", 742 .data = &softlockup_panic, 743 .maxlen = sizeof(int), 744 .mode = 0644, 745 .proc_handler = &proc_dointvec_minmax, 746 .strategy = &sysctl_intvec, 747 .extra1 = &zero, 748 .extra2 = &one, 749 }, 750 { 751 .ctl_name = CTL_UNNUMBERED, 752 .procname = "softlockup_thresh", 753 .data = &softlockup_thresh, 754 .maxlen = sizeof(int), 755 .mode = 0644, 756 .proc_handler = &proc_dointvec_minmax, 757 .strategy = &sysctl_intvec, 758 .extra1 = &neg_one, 759 .extra2 = &sixty, 760 }, 761 { 762 .ctl_name = CTL_UNNUMBERED, 763 .procname = "hung_task_check_count", 764 .data = &sysctl_hung_task_check_count, 765 .maxlen = sizeof(unsigned long), 766 .mode = 0644, 767 .proc_handler = &proc_doulongvec_minmax, 768 .strategy = &sysctl_intvec, 769 }, 770 { 771 .ctl_name = CTL_UNNUMBERED, 772 .procname = "hung_task_timeout_secs", 773 .data = &sysctl_hung_task_timeout_secs, 774 .maxlen = sizeof(unsigned long), 775 .mode = 0644, 776 .proc_handler = &proc_doulongvec_minmax, 777 .strategy = &sysctl_intvec, 778 }, 779 { 780 .ctl_name = CTL_UNNUMBERED, 781 .procname = "hung_task_warnings", 782 .data = &sysctl_hung_task_warnings, 783 .maxlen = sizeof(unsigned long), 784 .mode = 0644, 785 .proc_handler = &proc_doulongvec_minmax, 786 .strategy = &sysctl_intvec, 787 }, 788 #endif 789 #ifdef CONFIG_COMPAT 790 { 791 .ctl_name = KERN_COMPAT_LOG, 792 .procname = "compat-log", 793 .data = &compat_log, 794 .maxlen = sizeof (int), 795 .mode = 0644, 796 .proc_handler = &proc_dointvec, 797 }, 798 #endif 799 #ifdef CONFIG_RT_MUTEXES 800 { 801 .ctl_name = KERN_MAX_LOCK_DEPTH, 802 .procname = "max_lock_depth", 803 .data = &max_lock_depth, 804 .maxlen = sizeof(int), 805 .mode = 0644, 806 .proc_handler = &proc_dointvec, 807 }, 808 #endif 809 { 810 .ctl_name = CTL_UNNUMBERED, 811 .procname = "poweroff_cmd", 812 .data = &poweroff_cmd, 813 .maxlen = POWEROFF_CMD_PATH_LEN, 814 .mode = 0644, 815 .proc_handler = &proc_dostring, 816 .strategy = &sysctl_string, 817 }, 818 #ifdef CONFIG_KEYS 819 { 820 .ctl_name = CTL_UNNUMBERED, 821 .procname = "keys", 822 .mode = 0555, 823 .child = key_sysctls, 824 }, 825 #endif 826 #ifdef CONFIG_RCU_TORTURE_TEST 827 { 828 .ctl_name = CTL_UNNUMBERED, 829 .procname = "rcutorture_runnable", 830 .data = &rcutorture_runnable, 831 .maxlen = sizeof(int), 832 .mode = 0644, 833 .proc_handler = &proc_dointvec, 834 }, 835 #endif 836 /* 837 * NOTE: do not add new entries to this table unless you have read 838 * Documentation/sysctl/ctl_unnumbered.txt 839 */ 840 { .ctl_name = 0 } 841 }; 842 843 static struct ctl_table vm_table[] = { 844 { 845 .ctl_name = VM_OVERCOMMIT_MEMORY, 846 .procname = "overcommit_memory", 847 .data = &sysctl_overcommit_memory, 848 .maxlen = sizeof(sysctl_overcommit_memory), 849 .mode = 0644, 850 .proc_handler = &proc_dointvec, 851 }, 852 { 853 .ctl_name = VM_PANIC_ON_OOM, 854 .procname = "panic_on_oom", 855 .data = &sysctl_panic_on_oom, 856 .maxlen = sizeof(sysctl_panic_on_oom), 857 .mode = 0644, 858 .proc_handler = &proc_dointvec, 859 }, 860 { 861 .ctl_name = CTL_UNNUMBERED, 862 .procname = "oom_kill_allocating_task", 863 .data = &sysctl_oom_kill_allocating_task, 864 .maxlen = sizeof(sysctl_oom_kill_allocating_task), 865 .mode = 0644, 866 .proc_handler = &proc_dointvec, 867 }, 868 { 869 .ctl_name = CTL_UNNUMBERED, 870 .procname = "oom_dump_tasks", 871 .data = &sysctl_oom_dump_tasks, 872 .maxlen = sizeof(sysctl_oom_dump_tasks), 873 .mode = 0644, 874 .proc_handler = &proc_dointvec, 875 }, 876 { 877 .ctl_name = VM_OVERCOMMIT_RATIO, 878 .procname = "overcommit_ratio", 879 .data = &sysctl_overcommit_ratio, 880 .maxlen = sizeof(sysctl_overcommit_ratio), 881 .mode = 0644, 882 .proc_handler = &proc_dointvec, 883 }, 884 { 885 .ctl_name = VM_PAGE_CLUSTER, 886 .procname = "page-cluster", 887 .data = &page_cluster, 888 .maxlen = sizeof(int), 889 .mode = 0644, 890 .proc_handler = &proc_dointvec, 891 }, 892 { 893 .ctl_name = VM_DIRTY_BACKGROUND, 894 .procname = "dirty_background_ratio", 895 .data = &dirty_background_ratio, 896 .maxlen = sizeof(dirty_background_ratio), 897 .mode = 0644, 898 .proc_handler = &proc_dointvec_minmax, 899 .strategy = &sysctl_intvec, 900 .extra1 = &zero, 901 .extra2 = &one_hundred, 902 }, 903 { 904 .ctl_name = VM_DIRTY_RATIO, 905 .procname = "dirty_ratio", 906 .data = &vm_dirty_ratio, 907 .maxlen = sizeof(vm_dirty_ratio), 908 .mode = 0644, 909 .proc_handler = &dirty_ratio_handler, 910 .strategy = &sysctl_intvec, 911 .extra1 = &zero, 912 .extra2 = &one_hundred, 913 }, 914 { 915 .procname = "dirty_writeback_centisecs", 916 .data = &dirty_writeback_interval, 917 .maxlen = sizeof(dirty_writeback_interval), 918 .mode = 0644, 919 .proc_handler = &dirty_writeback_centisecs_handler, 920 }, 921 { 922 .procname = "dirty_expire_centisecs", 923 .data = &dirty_expire_interval, 924 .maxlen = sizeof(dirty_expire_interval), 925 .mode = 0644, 926 .proc_handler = &proc_dointvec_userhz_jiffies, 927 }, 928 { 929 .ctl_name = VM_NR_PDFLUSH_THREADS, 930 .procname = "nr_pdflush_threads", 931 .data = &nr_pdflush_threads, 932 .maxlen = sizeof nr_pdflush_threads, 933 .mode = 0444 /* read-only*/, 934 .proc_handler = &proc_dointvec, 935 }, 936 { 937 .ctl_name = VM_SWAPPINESS, 938 .procname = "swappiness", 939 .data = &vm_swappiness, 940 .maxlen = sizeof(vm_swappiness), 941 .mode = 0644, 942 .proc_handler = &proc_dointvec_minmax, 943 .strategy = &sysctl_intvec, 944 .extra1 = &zero, 945 .extra2 = &one_hundred, 946 }, 947 #ifdef CONFIG_HUGETLB_PAGE 948 { 949 .procname = "nr_hugepages", 950 .data = NULL, 951 .maxlen = sizeof(unsigned long), 952 .mode = 0644, 953 .proc_handler = &hugetlb_sysctl_handler, 954 .extra1 = (void *)&hugetlb_zero, 955 .extra2 = (void *)&hugetlb_infinity, 956 }, 957 { 958 .ctl_name = VM_HUGETLB_GROUP, 959 .procname = "hugetlb_shm_group", 960 .data = &sysctl_hugetlb_shm_group, 961 .maxlen = sizeof(gid_t), 962 .mode = 0644, 963 .proc_handler = &proc_dointvec, 964 }, 965 { 966 .ctl_name = CTL_UNNUMBERED, 967 .procname = "hugepages_treat_as_movable", 968 .data = &hugepages_treat_as_movable, 969 .maxlen = sizeof(int), 970 .mode = 0644, 971 .proc_handler = &hugetlb_treat_movable_handler, 972 }, 973 { 974 .ctl_name = CTL_UNNUMBERED, 975 .procname = "nr_overcommit_hugepages", 976 .data = NULL, 977 .maxlen = sizeof(unsigned long), 978 .mode = 0644, 979 .proc_handler = &hugetlb_overcommit_handler, 980 .extra1 = (void *)&hugetlb_zero, 981 .extra2 = (void *)&hugetlb_infinity, 982 }, 983 #endif 984 { 985 .ctl_name = VM_LOWMEM_RESERVE_RATIO, 986 .procname = "lowmem_reserve_ratio", 987 .data = &sysctl_lowmem_reserve_ratio, 988 .maxlen = sizeof(sysctl_lowmem_reserve_ratio), 989 .mode = 0644, 990 .proc_handler = &lowmem_reserve_ratio_sysctl_handler, 991 .strategy = &sysctl_intvec, 992 }, 993 { 994 .ctl_name = VM_DROP_PAGECACHE, 995 .procname = "drop_caches", 996 .data = &sysctl_drop_caches, 997 .maxlen = sizeof(int), 998 .mode = 0644, 999 .proc_handler = drop_caches_sysctl_handler, 1000 .strategy = &sysctl_intvec, 1001 }, 1002 { 1003 .ctl_name = VM_MIN_FREE_KBYTES, 1004 .procname = "min_free_kbytes", 1005 .data = &min_free_kbytes, 1006 .maxlen = sizeof(min_free_kbytes), 1007 .mode = 0644, 1008 .proc_handler = &min_free_kbytes_sysctl_handler, 1009 .strategy = &sysctl_intvec, 1010 .extra1 = &zero, 1011 }, 1012 { 1013 .ctl_name = VM_PERCPU_PAGELIST_FRACTION, 1014 .procname = "percpu_pagelist_fraction", 1015 .data = &percpu_pagelist_fraction, 1016 .maxlen = sizeof(percpu_pagelist_fraction), 1017 .mode = 0644, 1018 .proc_handler = &percpu_pagelist_fraction_sysctl_handler, 1019 .strategy = &sysctl_intvec, 1020 .extra1 = &min_percpu_pagelist_fract, 1021 }, 1022 #ifdef CONFIG_MMU 1023 { 1024 .ctl_name = VM_MAX_MAP_COUNT, 1025 .procname = "max_map_count", 1026 .data = &sysctl_max_map_count, 1027 .maxlen = sizeof(sysctl_max_map_count), 1028 .mode = 0644, 1029 .proc_handler = &proc_dointvec 1030 }, 1031 #endif 1032 { 1033 .ctl_name = VM_LAPTOP_MODE, 1034 .procname = "laptop_mode", 1035 .data = &laptop_mode, 1036 .maxlen = sizeof(laptop_mode), 1037 .mode = 0644, 1038 .proc_handler = &proc_dointvec_jiffies, 1039 .strategy = &sysctl_jiffies, 1040 }, 1041 { 1042 .ctl_name = VM_BLOCK_DUMP, 1043 .procname = "block_dump", 1044 .data = &block_dump, 1045 .maxlen = sizeof(block_dump), 1046 .mode = 0644, 1047 .proc_handler = &proc_dointvec, 1048 .strategy = &sysctl_intvec, 1049 .extra1 = &zero, 1050 }, 1051 { 1052 .ctl_name = VM_VFS_CACHE_PRESSURE, 1053 .procname = "vfs_cache_pressure", 1054 .data = &sysctl_vfs_cache_pressure, 1055 .maxlen = sizeof(sysctl_vfs_cache_pressure), 1056 .mode = 0644, 1057 .proc_handler = &proc_dointvec, 1058 .strategy = &sysctl_intvec, 1059 .extra1 = &zero, 1060 }, 1061 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 1062 { 1063 .ctl_name = VM_LEGACY_VA_LAYOUT, 1064 .procname = "legacy_va_layout", 1065 .data = &sysctl_legacy_va_layout, 1066 .maxlen = sizeof(sysctl_legacy_va_layout), 1067 .mode = 0644, 1068 .proc_handler = &proc_dointvec, 1069 .strategy = &sysctl_intvec, 1070 .extra1 = &zero, 1071 }, 1072 #endif 1073 #ifdef CONFIG_NUMA 1074 { 1075 .ctl_name = VM_ZONE_RECLAIM_MODE, 1076 .procname = "zone_reclaim_mode", 1077 .data = &zone_reclaim_mode, 1078 .maxlen = sizeof(zone_reclaim_mode), 1079 .mode = 0644, 1080 .proc_handler = &proc_dointvec, 1081 .strategy = &sysctl_intvec, 1082 .extra1 = &zero, 1083 }, 1084 { 1085 .ctl_name = VM_MIN_UNMAPPED, 1086 .procname = "min_unmapped_ratio", 1087 .data = &sysctl_min_unmapped_ratio, 1088 .maxlen = sizeof(sysctl_min_unmapped_ratio), 1089 .mode = 0644, 1090 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler, 1091 .strategy = &sysctl_intvec, 1092 .extra1 = &zero, 1093 .extra2 = &one_hundred, 1094 }, 1095 { 1096 .ctl_name = VM_MIN_SLAB, 1097 .procname = "min_slab_ratio", 1098 .data = &sysctl_min_slab_ratio, 1099 .maxlen = sizeof(sysctl_min_slab_ratio), 1100 .mode = 0644, 1101 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler, 1102 .strategy = &sysctl_intvec, 1103 .extra1 = &zero, 1104 .extra2 = &one_hundred, 1105 }, 1106 #endif 1107 #ifdef CONFIG_SMP 1108 { 1109 .ctl_name = CTL_UNNUMBERED, 1110 .procname = "stat_interval", 1111 .data = &sysctl_stat_interval, 1112 .maxlen = sizeof(sysctl_stat_interval), 1113 .mode = 0644, 1114 .proc_handler = &proc_dointvec_jiffies, 1115 .strategy = &sysctl_jiffies, 1116 }, 1117 #endif 1118 #ifdef CONFIG_SECURITY 1119 { 1120 .ctl_name = CTL_UNNUMBERED, 1121 .procname = "mmap_min_addr", 1122 .data = &mmap_min_addr, 1123 .maxlen = sizeof(unsigned long), 1124 .mode = 0644, 1125 .proc_handler = &proc_doulongvec_minmax, 1126 }, 1127 #endif 1128 #ifdef CONFIG_NUMA 1129 { 1130 .ctl_name = CTL_UNNUMBERED, 1131 .procname = "numa_zonelist_order", 1132 .data = &numa_zonelist_order, 1133 .maxlen = NUMA_ZONELIST_ORDER_LEN, 1134 .mode = 0644, 1135 .proc_handler = &numa_zonelist_order_handler, 1136 .strategy = &sysctl_string, 1137 }, 1138 #endif 1139 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 1140 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 1141 { 1142 .ctl_name = VM_VDSO_ENABLED, 1143 .procname = "vdso_enabled", 1144 .data = &vdso_enabled, 1145 .maxlen = sizeof(vdso_enabled), 1146 .mode = 0644, 1147 .proc_handler = &proc_dointvec, 1148 .strategy = &sysctl_intvec, 1149 .extra1 = &zero, 1150 }, 1151 #endif 1152 #ifdef CONFIG_HIGHMEM 1153 { 1154 .ctl_name = CTL_UNNUMBERED, 1155 .procname = "highmem_is_dirtyable", 1156 .data = &vm_highmem_is_dirtyable, 1157 .maxlen = sizeof(vm_highmem_is_dirtyable), 1158 .mode = 0644, 1159 .proc_handler = &proc_dointvec_minmax, 1160 .strategy = &sysctl_intvec, 1161 .extra1 = &zero, 1162 .extra2 = &one, 1163 }, 1164 #endif 1165 /* 1166 * NOTE: do not add new entries to this table unless you have read 1167 * Documentation/sysctl/ctl_unnumbered.txt 1168 */ 1169 { .ctl_name = 0 } 1170 }; 1171 1172 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1173 static struct ctl_table binfmt_misc_table[] = { 1174 { .ctl_name = 0 } 1175 }; 1176 #endif 1177 1178 static struct ctl_table fs_table[] = { 1179 { 1180 .ctl_name = FS_NRINODE, 1181 .procname = "inode-nr", 1182 .data = &inodes_stat, 1183 .maxlen = 2*sizeof(int), 1184 .mode = 0444, 1185 .proc_handler = &proc_dointvec, 1186 }, 1187 { 1188 .ctl_name = FS_STATINODE, 1189 .procname = "inode-state", 1190 .data = &inodes_stat, 1191 .maxlen = 7*sizeof(int), 1192 .mode = 0444, 1193 .proc_handler = &proc_dointvec, 1194 }, 1195 { 1196 .procname = "file-nr", 1197 .data = &files_stat, 1198 .maxlen = 3*sizeof(int), 1199 .mode = 0444, 1200 .proc_handler = &proc_nr_files, 1201 }, 1202 { 1203 .ctl_name = FS_MAXFILE, 1204 .procname = "file-max", 1205 .data = &files_stat.max_files, 1206 .maxlen = sizeof(int), 1207 .mode = 0644, 1208 .proc_handler = &proc_dointvec, 1209 }, 1210 { 1211 .ctl_name = CTL_UNNUMBERED, 1212 .procname = "nr_open", 1213 .data = &sysctl_nr_open, 1214 .maxlen = sizeof(int), 1215 .mode = 0644, 1216 .proc_handler = &proc_dointvec_minmax, 1217 .extra1 = &sysctl_nr_open_min, 1218 .extra2 = &sysctl_nr_open_max, 1219 }, 1220 { 1221 .ctl_name = FS_DENTRY, 1222 .procname = "dentry-state", 1223 .data = &dentry_stat, 1224 .maxlen = 6*sizeof(int), 1225 .mode = 0444, 1226 .proc_handler = &proc_dointvec, 1227 }, 1228 { 1229 .ctl_name = FS_OVERFLOWUID, 1230 .procname = "overflowuid", 1231 .data = &fs_overflowuid, 1232 .maxlen = sizeof(int), 1233 .mode = 0644, 1234 .proc_handler = &proc_dointvec_minmax, 1235 .strategy = &sysctl_intvec, 1236 .extra1 = &minolduid, 1237 .extra2 = &maxolduid, 1238 }, 1239 { 1240 .ctl_name = FS_OVERFLOWGID, 1241 .procname = "overflowgid", 1242 .data = &fs_overflowgid, 1243 .maxlen = sizeof(int), 1244 .mode = 0644, 1245 .proc_handler = &proc_dointvec_minmax, 1246 .strategy = &sysctl_intvec, 1247 .extra1 = &minolduid, 1248 .extra2 = &maxolduid, 1249 }, 1250 #ifdef CONFIG_FILE_LOCKING 1251 { 1252 .ctl_name = FS_LEASES, 1253 .procname = "leases-enable", 1254 .data = &leases_enable, 1255 .maxlen = sizeof(int), 1256 .mode = 0644, 1257 .proc_handler = &proc_dointvec, 1258 }, 1259 #endif 1260 #ifdef CONFIG_DNOTIFY 1261 { 1262 .ctl_name = FS_DIR_NOTIFY, 1263 .procname = "dir-notify-enable", 1264 .data = &dir_notify_enable, 1265 .maxlen = sizeof(int), 1266 .mode = 0644, 1267 .proc_handler = &proc_dointvec, 1268 }, 1269 #endif 1270 #ifdef CONFIG_MMU 1271 #ifdef CONFIG_FILE_LOCKING 1272 { 1273 .ctl_name = FS_LEASE_TIME, 1274 .procname = "lease-break-time", 1275 .data = &lease_break_time, 1276 .maxlen = sizeof(int), 1277 .mode = 0644, 1278 .proc_handler = &proc_dointvec_minmax, 1279 .strategy = &sysctl_intvec, 1280 .extra1 = &zero, 1281 .extra2 = &two, 1282 }, 1283 #endif 1284 #ifdef CONFIG_AIO 1285 { 1286 .procname = "aio-nr", 1287 .data = &aio_nr, 1288 .maxlen = sizeof(aio_nr), 1289 .mode = 0444, 1290 .proc_handler = &proc_doulongvec_minmax, 1291 }, 1292 { 1293 .procname = "aio-max-nr", 1294 .data = &aio_max_nr, 1295 .maxlen = sizeof(aio_max_nr), 1296 .mode = 0644, 1297 .proc_handler = &proc_doulongvec_minmax, 1298 }, 1299 #endif /* CONFIG_AIO */ 1300 #ifdef CONFIG_INOTIFY_USER 1301 { 1302 .ctl_name = FS_INOTIFY, 1303 .procname = "inotify", 1304 .mode = 0555, 1305 .child = inotify_table, 1306 }, 1307 #endif 1308 #endif 1309 { 1310 .ctl_name = KERN_SETUID_DUMPABLE, 1311 .procname = "suid_dumpable", 1312 .data = &suid_dumpable, 1313 .maxlen = sizeof(int), 1314 .mode = 0644, 1315 .proc_handler = &proc_dointvec, 1316 }, 1317 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1318 { 1319 .ctl_name = CTL_UNNUMBERED, 1320 .procname = "binfmt_misc", 1321 .mode = 0555, 1322 .child = binfmt_misc_table, 1323 }, 1324 #endif 1325 /* 1326 * NOTE: do not add new entries to this table unless you have read 1327 * Documentation/sysctl/ctl_unnumbered.txt 1328 */ 1329 { .ctl_name = 0 } 1330 }; 1331 1332 static struct ctl_table debug_table[] = { 1333 #if defined(CONFIG_X86) || defined(CONFIG_PPC) 1334 { 1335 .ctl_name = CTL_UNNUMBERED, 1336 .procname = "exception-trace", 1337 .data = &show_unhandled_signals, 1338 .maxlen = sizeof(int), 1339 .mode = 0644, 1340 .proc_handler = proc_dointvec 1341 }, 1342 #endif 1343 { .ctl_name = 0 } 1344 }; 1345 1346 static struct ctl_table dev_table[] = { 1347 { .ctl_name = 0 } 1348 }; 1349 1350 static DEFINE_SPINLOCK(sysctl_lock); 1351 1352 /* called under sysctl_lock */ 1353 static int use_table(struct ctl_table_header *p) 1354 { 1355 if (unlikely(p->unregistering)) 1356 return 0; 1357 p->used++; 1358 return 1; 1359 } 1360 1361 /* called under sysctl_lock */ 1362 static void unuse_table(struct ctl_table_header *p) 1363 { 1364 if (!--p->used) 1365 if (unlikely(p->unregistering)) 1366 complete(p->unregistering); 1367 } 1368 1369 /* called under sysctl_lock, will reacquire if has to wait */ 1370 static void start_unregistering(struct ctl_table_header *p) 1371 { 1372 /* 1373 * if p->used is 0, nobody will ever touch that entry again; 1374 * we'll eliminate all paths to it before dropping sysctl_lock 1375 */ 1376 if (unlikely(p->used)) { 1377 struct completion wait; 1378 init_completion(&wait); 1379 p->unregistering = &wait; 1380 spin_unlock(&sysctl_lock); 1381 wait_for_completion(&wait); 1382 spin_lock(&sysctl_lock); 1383 } else { 1384 /* anything non-NULL; we'll never dereference it */ 1385 p->unregistering = ERR_PTR(-EINVAL); 1386 } 1387 /* 1388 * do not remove from the list until nobody holds it; walking the 1389 * list in do_sysctl() relies on that. 1390 */ 1391 list_del_init(&p->ctl_entry); 1392 } 1393 1394 void sysctl_head_get(struct ctl_table_header *head) 1395 { 1396 spin_lock(&sysctl_lock); 1397 head->count++; 1398 spin_unlock(&sysctl_lock); 1399 } 1400 1401 void sysctl_head_put(struct ctl_table_header *head) 1402 { 1403 spin_lock(&sysctl_lock); 1404 if (!--head->count) 1405 kfree(head); 1406 spin_unlock(&sysctl_lock); 1407 } 1408 1409 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) 1410 { 1411 if (!head) 1412 BUG(); 1413 spin_lock(&sysctl_lock); 1414 if (!use_table(head)) 1415 head = ERR_PTR(-ENOENT); 1416 spin_unlock(&sysctl_lock); 1417 return head; 1418 } 1419 1420 void sysctl_head_finish(struct ctl_table_header *head) 1421 { 1422 if (!head) 1423 return; 1424 spin_lock(&sysctl_lock); 1425 unuse_table(head); 1426 spin_unlock(&sysctl_lock); 1427 } 1428 1429 static struct ctl_table_set * 1430 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) 1431 { 1432 struct ctl_table_set *set = &root->default_set; 1433 if (root->lookup) 1434 set = root->lookup(root, namespaces); 1435 return set; 1436 } 1437 1438 static struct list_head * 1439 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) 1440 { 1441 struct ctl_table_set *set = lookup_header_set(root, namespaces); 1442 return &set->list; 1443 } 1444 1445 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, 1446 struct ctl_table_header *prev) 1447 { 1448 struct ctl_table_root *root; 1449 struct list_head *header_list; 1450 struct ctl_table_header *head; 1451 struct list_head *tmp; 1452 1453 spin_lock(&sysctl_lock); 1454 if (prev) { 1455 head = prev; 1456 tmp = &prev->ctl_entry; 1457 unuse_table(prev); 1458 goto next; 1459 } 1460 tmp = &root_table_header.ctl_entry; 1461 for (;;) { 1462 head = list_entry(tmp, struct ctl_table_header, ctl_entry); 1463 1464 if (!use_table(head)) 1465 goto next; 1466 spin_unlock(&sysctl_lock); 1467 return head; 1468 next: 1469 root = head->root; 1470 tmp = tmp->next; 1471 header_list = lookup_header_list(root, namespaces); 1472 if (tmp != header_list) 1473 continue; 1474 1475 do { 1476 root = list_entry(root->root_list.next, 1477 struct ctl_table_root, root_list); 1478 if (root == &sysctl_table_root) 1479 goto out; 1480 header_list = lookup_header_list(root, namespaces); 1481 } while (list_empty(header_list)); 1482 tmp = header_list->next; 1483 } 1484 out: 1485 spin_unlock(&sysctl_lock); 1486 return NULL; 1487 } 1488 1489 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) 1490 { 1491 return __sysctl_head_next(current->nsproxy, prev); 1492 } 1493 1494 void register_sysctl_root(struct ctl_table_root *root) 1495 { 1496 spin_lock(&sysctl_lock); 1497 list_add_tail(&root->root_list, &sysctl_table_root.root_list); 1498 spin_unlock(&sysctl_lock); 1499 } 1500 1501 #ifdef CONFIG_SYSCTL_SYSCALL 1502 /* Perform the actual read/write of a sysctl table entry. */ 1503 static int do_sysctl_strategy(struct ctl_table_root *root, 1504 struct ctl_table *table, 1505 void __user *oldval, size_t __user *oldlenp, 1506 void __user *newval, size_t newlen) 1507 { 1508 int op = 0, rc; 1509 1510 if (oldval) 1511 op |= MAY_READ; 1512 if (newval) 1513 op |= MAY_WRITE; 1514 if (sysctl_perm(root, table, op)) 1515 return -EPERM; 1516 1517 if (table->strategy) { 1518 rc = table->strategy(table, oldval, oldlenp, newval, newlen); 1519 if (rc < 0) 1520 return rc; 1521 if (rc > 0) 1522 return 0; 1523 } 1524 1525 /* If there is no strategy routine, or if the strategy returns 1526 * zero, proceed with automatic r/w */ 1527 if (table->data && table->maxlen) { 1528 rc = sysctl_data(table, oldval, oldlenp, newval, newlen); 1529 if (rc < 0) 1530 return rc; 1531 } 1532 return 0; 1533 } 1534 1535 static int parse_table(int __user *name, int nlen, 1536 void __user *oldval, size_t __user *oldlenp, 1537 void __user *newval, size_t newlen, 1538 struct ctl_table_root *root, 1539 struct ctl_table *table) 1540 { 1541 int n; 1542 repeat: 1543 if (!nlen) 1544 return -ENOTDIR; 1545 if (get_user(n, name)) 1546 return -EFAULT; 1547 for ( ; table->ctl_name || table->procname; table++) { 1548 if (!table->ctl_name) 1549 continue; 1550 if (n == table->ctl_name) { 1551 int error; 1552 if (table->child) { 1553 if (sysctl_perm(root, table, MAY_EXEC)) 1554 return -EPERM; 1555 name++; 1556 nlen--; 1557 table = table->child; 1558 goto repeat; 1559 } 1560 error = do_sysctl_strategy(root, table, 1561 oldval, oldlenp, 1562 newval, newlen); 1563 return error; 1564 } 1565 } 1566 return -ENOTDIR; 1567 } 1568 1569 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, 1570 void __user *newval, size_t newlen) 1571 { 1572 struct ctl_table_header *head; 1573 int error = -ENOTDIR; 1574 1575 if (nlen <= 0 || nlen >= CTL_MAXNAME) 1576 return -ENOTDIR; 1577 if (oldval) { 1578 int old_len; 1579 if (!oldlenp || get_user(old_len, oldlenp)) 1580 return -EFAULT; 1581 } 1582 1583 for (head = sysctl_head_next(NULL); head; 1584 head = sysctl_head_next(head)) { 1585 error = parse_table(name, nlen, oldval, oldlenp, 1586 newval, newlen, 1587 head->root, head->ctl_table); 1588 if (error != -ENOTDIR) { 1589 sysctl_head_finish(head); 1590 break; 1591 } 1592 } 1593 return error; 1594 } 1595 1596 asmlinkage long sys_sysctl(struct __sysctl_args __user *args) 1597 { 1598 struct __sysctl_args tmp; 1599 int error; 1600 1601 if (copy_from_user(&tmp, args, sizeof(tmp))) 1602 return -EFAULT; 1603 1604 error = deprecated_sysctl_warning(&tmp); 1605 if (error) 1606 goto out; 1607 1608 lock_kernel(); 1609 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp, 1610 tmp.newval, tmp.newlen); 1611 unlock_kernel(); 1612 out: 1613 return error; 1614 } 1615 #endif /* CONFIG_SYSCTL_SYSCALL */ 1616 1617 /* 1618 * sysctl_perm does NOT grant the superuser all rights automatically, because 1619 * some sysctl variables are readonly even to root. 1620 */ 1621 1622 static int test_perm(int mode, int op) 1623 { 1624 if (!current->euid) 1625 mode >>= 6; 1626 else if (in_egroup_p(0)) 1627 mode >>= 3; 1628 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0) 1629 return 0; 1630 return -EACCES; 1631 } 1632 1633 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) 1634 { 1635 int error; 1636 int mode; 1637 1638 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC)); 1639 if (error) 1640 return error; 1641 1642 if (root->permissions) 1643 mode = root->permissions(root, current->nsproxy, table); 1644 else 1645 mode = table->mode; 1646 1647 return test_perm(mode, op); 1648 } 1649 1650 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) 1651 { 1652 for (; table->ctl_name || table->procname; table++) { 1653 table->parent = parent; 1654 if (table->child) 1655 sysctl_set_parent(table, table->child); 1656 } 1657 } 1658 1659 static __init int sysctl_init(void) 1660 { 1661 sysctl_set_parent(NULL, root_table); 1662 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1663 { 1664 int err; 1665 err = sysctl_check_table(current->nsproxy, root_table); 1666 } 1667 #endif 1668 return 0; 1669 } 1670 1671 core_initcall(sysctl_init); 1672 1673 static struct ctl_table *is_branch_in(struct ctl_table *branch, 1674 struct ctl_table *table) 1675 { 1676 struct ctl_table *p; 1677 const char *s = branch->procname; 1678 1679 /* branch should have named subdirectory as its first element */ 1680 if (!s || !branch->child) 1681 return NULL; 1682 1683 /* ... and nothing else */ 1684 if (branch[1].procname || branch[1].ctl_name) 1685 return NULL; 1686 1687 /* table should contain subdirectory with the same name */ 1688 for (p = table; p->procname || p->ctl_name; p++) { 1689 if (!p->child) 1690 continue; 1691 if (p->procname && strcmp(p->procname, s) == 0) 1692 return p; 1693 } 1694 return NULL; 1695 } 1696 1697 /* see if attaching q to p would be an improvement */ 1698 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q) 1699 { 1700 struct ctl_table *to = p->ctl_table, *by = q->ctl_table; 1701 struct ctl_table *next; 1702 int is_better = 0; 1703 int not_in_parent = !p->attached_by; 1704 1705 while ((next = is_branch_in(by, to)) != NULL) { 1706 if (by == q->attached_by) 1707 is_better = 1; 1708 if (to == p->attached_by) 1709 not_in_parent = 1; 1710 by = by->child; 1711 to = next->child; 1712 } 1713 1714 if (is_better && not_in_parent) { 1715 q->attached_by = by; 1716 q->attached_to = to; 1717 q->parent = p; 1718 } 1719 } 1720 1721 /** 1722 * __register_sysctl_paths - register a sysctl hierarchy 1723 * @root: List of sysctl headers to register on 1724 * @namespaces: Data to compute which lists of sysctl entries are visible 1725 * @path: The path to the directory the sysctl table is in. 1726 * @table: the top-level table structure 1727 * 1728 * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1729 * array. A completely 0 filled entry terminates the table. 1730 * 1731 * The members of the &struct ctl_table structure are used as follows: 1732 * 1733 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number 1734 * must be unique within that level of sysctl 1735 * 1736 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not 1737 * enter a sysctl file 1738 * 1739 * data - a pointer to data for use by proc_handler 1740 * 1741 * maxlen - the maximum size in bytes of the data 1742 * 1743 * mode - the file permissions for the /proc/sys file, and for sysctl(2) 1744 * 1745 * child - a pointer to the child sysctl table if this entry is a directory, or 1746 * %NULL. 1747 * 1748 * proc_handler - the text handler routine (described below) 1749 * 1750 * strategy - the strategy routine (described below) 1751 * 1752 * de - for internal use by the sysctl routines 1753 * 1754 * extra1, extra2 - extra pointers usable by the proc handler routines 1755 * 1756 * Leaf nodes in the sysctl tree will be represented by a single file 1757 * under /proc; non-leaf nodes will be represented by directories. 1758 * 1759 * sysctl(2) can automatically manage read and write requests through 1760 * the sysctl table. The data and maxlen fields of the ctl_table 1761 * struct enable minimal validation of the values being written to be 1762 * performed, and the mode field allows minimal authentication. 1763 * 1764 * More sophisticated management can be enabled by the provision of a 1765 * strategy routine with the table entry. This will be called before 1766 * any automatic read or write of the data is performed. 1767 * 1768 * The strategy routine may return 1769 * 1770 * < 0 - Error occurred (error is passed to user process) 1771 * 1772 * 0 - OK - proceed with automatic read or write. 1773 * 1774 * > 0 - OK - read or write has been done by the strategy routine, so 1775 * return immediately. 1776 * 1777 * There must be a proc_handler routine for any terminal nodes 1778 * mirrored under /proc/sys (non-terminals are handled by a built-in 1779 * directory handler). Several default handlers are available to 1780 * cover common cases - 1781 * 1782 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), 1783 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 1784 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() 1785 * 1786 * It is the handler's job to read the input buffer from user memory 1787 * and process it. The handler should return 0 on success. 1788 * 1789 * This routine returns %NULL on a failure to register, and a pointer 1790 * to the table header on success. 1791 */ 1792 struct ctl_table_header *__register_sysctl_paths( 1793 struct ctl_table_root *root, 1794 struct nsproxy *namespaces, 1795 const struct ctl_path *path, struct ctl_table *table) 1796 { 1797 struct ctl_table_header *header; 1798 struct ctl_table *new, **prevp; 1799 unsigned int n, npath; 1800 struct ctl_table_set *set; 1801 1802 /* Count the path components */ 1803 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) 1804 ; 1805 1806 /* 1807 * For each path component, allocate a 2-element ctl_table array. 1808 * The first array element will be filled with the sysctl entry 1809 * for this, the second will be the sentinel (ctl_name == 0). 1810 * 1811 * We allocate everything in one go so that we don't have to 1812 * worry about freeing additional memory in unregister_sysctl_table. 1813 */ 1814 header = kzalloc(sizeof(struct ctl_table_header) + 1815 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); 1816 if (!header) 1817 return NULL; 1818 1819 new = (struct ctl_table *) (header + 1); 1820 1821 /* Now connect the dots */ 1822 prevp = &header->ctl_table; 1823 for (n = 0; n < npath; ++n, ++path) { 1824 /* Copy the procname */ 1825 new->procname = path->procname; 1826 new->ctl_name = path->ctl_name; 1827 new->mode = 0555; 1828 1829 *prevp = new; 1830 prevp = &new->child; 1831 1832 new += 2; 1833 } 1834 *prevp = table; 1835 header->ctl_table_arg = table; 1836 1837 INIT_LIST_HEAD(&header->ctl_entry); 1838 header->used = 0; 1839 header->unregistering = NULL; 1840 header->root = root; 1841 sysctl_set_parent(NULL, header->ctl_table); 1842 header->count = 1; 1843 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1844 if (sysctl_check_table(namespaces, header->ctl_table)) { 1845 kfree(header); 1846 return NULL; 1847 } 1848 #endif 1849 spin_lock(&sysctl_lock); 1850 header->set = lookup_header_set(root, namespaces); 1851 header->attached_by = header->ctl_table; 1852 header->attached_to = root_table; 1853 header->parent = &root_table_header; 1854 for (set = header->set; set; set = set->parent) { 1855 struct ctl_table_header *p; 1856 list_for_each_entry(p, &set->list, ctl_entry) { 1857 if (p->unregistering) 1858 continue; 1859 try_attach(p, header); 1860 } 1861 } 1862 header->parent->count++; 1863 list_add_tail(&header->ctl_entry, &header->set->list); 1864 spin_unlock(&sysctl_lock); 1865 1866 return header; 1867 } 1868 1869 /** 1870 * register_sysctl_table_path - register a sysctl table hierarchy 1871 * @path: The path to the directory the sysctl table is in. 1872 * @table: the top-level table structure 1873 * 1874 * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1875 * array. A completely 0 filled entry terminates the table. 1876 * 1877 * See __register_sysctl_paths for more details. 1878 */ 1879 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 1880 struct ctl_table *table) 1881 { 1882 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, 1883 path, table); 1884 } 1885 1886 /** 1887 * register_sysctl_table - register a sysctl table hierarchy 1888 * @table: the top-level table structure 1889 * 1890 * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1891 * array. A completely 0 filled entry terminates the table. 1892 * 1893 * See register_sysctl_paths for more details. 1894 */ 1895 struct ctl_table_header *register_sysctl_table(struct ctl_table *table) 1896 { 1897 static const struct ctl_path null_path[] = { {} }; 1898 1899 return register_sysctl_paths(null_path, table); 1900 } 1901 1902 /** 1903 * unregister_sysctl_table - unregister a sysctl table hierarchy 1904 * @header: the header returned from register_sysctl_table 1905 * 1906 * Unregisters the sysctl table and all children. proc entries may not 1907 * actually be removed until they are no longer used by anyone. 1908 */ 1909 void unregister_sysctl_table(struct ctl_table_header * header) 1910 { 1911 might_sleep(); 1912 1913 if (header == NULL) 1914 return; 1915 1916 spin_lock(&sysctl_lock); 1917 start_unregistering(header); 1918 if (!--header->parent->count) { 1919 WARN_ON(1); 1920 kfree(header->parent); 1921 } 1922 if (!--header->count) 1923 kfree(header); 1924 spin_unlock(&sysctl_lock); 1925 } 1926 1927 int sysctl_is_seen(struct ctl_table_header *p) 1928 { 1929 struct ctl_table_set *set = p->set; 1930 int res; 1931 spin_lock(&sysctl_lock); 1932 if (p->unregistering) 1933 res = 0; 1934 else if (!set->is_seen) 1935 res = 1; 1936 else 1937 res = set->is_seen(set); 1938 spin_unlock(&sysctl_lock); 1939 return res; 1940 } 1941 1942 void setup_sysctl_set(struct ctl_table_set *p, 1943 struct ctl_table_set *parent, 1944 int (*is_seen)(struct ctl_table_set *)) 1945 { 1946 INIT_LIST_HEAD(&p->list); 1947 p->parent = parent ? parent : &sysctl_table_root.default_set; 1948 p->is_seen = is_seen; 1949 } 1950 1951 #else /* !CONFIG_SYSCTL */ 1952 struct ctl_table_header *register_sysctl_table(struct ctl_table * table) 1953 { 1954 return NULL; 1955 } 1956 1957 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 1958 struct ctl_table *table) 1959 { 1960 return NULL; 1961 } 1962 1963 void unregister_sysctl_table(struct ctl_table_header * table) 1964 { 1965 } 1966 1967 void setup_sysctl_set(struct ctl_table_set *p, 1968 struct ctl_table_set *parent, 1969 int (*is_seen)(struct ctl_table_set *)) 1970 { 1971 } 1972 1973 void sysctl_head_put(struct ctl_table_header *head) 1974 { 1975 } 1976 1977 #endif /* CONFIG_SYSCTL */ 1978 1979 /* 1980 * /proc/sys support 1981 */ 1982 1983 #ifdef CONFIG_PROC_SYSCTL 1984 1985 static int _proc_do_string(void* data, int maxlen, int write, 1986 struct file *filp, void __user *buffer, 1987 size_t *lenp, loff_t *ppos) 1988 { 1989 size_t len; 1990 char __user *p; 1991 char c; 1992 1993 if (!data || !maxlen || !*lenp) { 1994 *lenp = 0; 1995 return 0; 1996 } 1997 1998 if (write) { 1999 len = 0; 2000 p = buffer; 2001 while (len < *lenp) { 2002 if (get_user(c, p++)) 2003 return -EFAULT; 2004 if (c == 0 || c == '\n') 2005 break; 2006 len++; 2007 } 2008 if (len >= maxlen) 2009 len = maxlen-1; 2010 if(copy_from_user(data, buffer, len)) 2011 return -EFAULT; 2012 ((char *) data)[len] = 0; 2013 *ppos += *lenp; 2014 } else { 2015 len = strlen(data); 2016 if (len > maxlen) 2017 len = maxlen; 2018 2019 if (*ppos > len) { 2020 *lenp = 0; 2021 return 0; 2022 } 2023 2024 data += *ppos; 2025 len -= *ppos; 2026 2027 if (len > *lenp) 2028 len = *lenp; 2029 if (len) 2030 if(copy_to_user(buffer, data, len)) 2031 return -EFAULT; 2032 if (len < *lenp) { 2033 if(put_user('\n', ((char __user *) buffer) + len)) 2034 return -EFAULT; 2035 len++; 2036 } 2037 *lenp = len; 2038 *ppos += len; 2039 } 2040 return 0; 2041 } 2042 2043 /** 2044 * proc_dostring - read a string sysctl 2045 * @table: the sysctl table 2046 * @write: %TRUE if this is a write to the sysctl file 2047 * @filp: the file structure 2048 * @buffer: the user buffer 2049 * @lenp: the size of the user buffer 2050 * @ppos: file position 2051 * 2052 * Reads/writes a string from/to the user buffer. If the kernel 2053 * buffer provided is not large enough to hold the string, the 2054 * string is truncated. The copied string is %NULL-terminated. 2055 * If the string is being read by the user process, it is copied 2056 * and a newline '\n' is added. It is truncated if the buffer is 2057 * not large enough. 2058 * 2059 * Returns 0 on success. 2060 */ 2061 int proc_dostring(struct ctl_table *table, int write, struct file *filp, 2062 void __user *buffer, size_t *lenp, loff_t *ppos) 2063 { 2064 return _proc_do_string(table->data, table->maxlen, write, filp, 2065 buffer, lenp, ppos); 2066 } 2067 2068 2069 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, 2070 int *valp, 2071 int write, void *data) 2072 { 2073 if (write) { 2074 *valp = *negp ? -*lvalp : *lvalp; 2075 } else { 2076 int val = *valp; 2077 if (val < 0) { 2078 *negp = -1; 2079 *lvalp = (unsigned long)-val; 2080 } else { 2081 *negp = 0; 2082 *lvalp = (unsigned long)val; 2083 } 2084 } 2085 return 0; 2086 } 2087 2088 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 2089 int write, struct file *filp, void __user *buffer, 2090 size_t *lenp, loff_t *ppos, 2091 int (*conv)(int *negp, unsigned long *lvalp, int *valp, 2092 int write, void *data), 2093 void *data) 2094 { 2095 #define TMPBUFLEN 21 2096 int *i, vleft, first=1, neg, val; 2097 unsigned long lval; 2098 size_t left, len; 2099 2100 char buf[TMPBUFLEN], *p; 2101 char __user *s = buffer; 2102 2103 if (!tbl_data || !table->maxlen || !*lenp || 2104 (*ppos && !write)) { 2105 *lenp = 0; 2106 return 0; 2107 } 2108 2109 i = (int *) tbl_data; 2110 vleft = table->maxlen / sizeof(*i); 2111 left = *lenp; 2112 2113 if (!conv) 2114 conv = do_proc_dointvec_conv; 2115 2116 for (; left && vleft--; i++, first=0) { 2117 if (write) { 2118 while (left) { 2119 char c; 2120 if (get_user(c, s)) 2121 return -EFAULT; 2122 if (!isspace(c)) 2123 break; 2124 left--; 2125 s++; 2126 } 2127 if (!left) 2128 break; 2129 neg = 0; 2130 len = left; 2131 if (len > sizeof(buf) - 1) 2132 len = sizeof(buf) - 1; 2133 if (copy_from_user(buf, s, len)) 2134 return -EFAULT; 2135 buf[len] = 0; 2136 p = buf; 2137 if (*p == '-' && left > 1) { 2138 neg = 1; 2139 p++; 2140 } 2141 if (*p < '0' || *p > '9') 2142 break; 2143 2144 lval = simple_strtoul(p, &p, 0); 2145 2146 len = p-buf; 2147 if ((len < left) && *p && !isspace(*p)) 2148 break; 2149 if (neg) 2150 val = -val; 2151 s += len; 2152 left -= len; 2153 2154 if (conv(&neg, &lval, i, 1, data)) 2155 break; 2156 } else { 2157 p = buf; 2158 if (!first) 2159 *p++ = '\t'; 2160 2161 if (conv(&neg, &lval, i, 0, data)) 2162 break; 2163 2164 sprintf(p, "%s%lu", neg ? "-" : "", lval); 2165 len = strlen(buf); 2166 if (len > left) 2167 len = left; 2168 if(copy_to_user(s, buf, len)) 2169 return -EFAULT; 2170 left -= len; 2171 s += len; 2172 } 2173 } 2174 2175 if (!write && !first && left) { 2176 if(put_user('\n', s)) 2177 return -EFAULT; 2178 left--, s++; 2179 } 2180 if (write) { 2181 while (left) { 2182 char c; 2183 if (get_user(c, s++)) 2184 return -EFAULT; 2185 if (!isspace(c)) 2186 break; 2187 left--; 2188 } 2189 } 2190 if (write && first) 2191 return -EINVAL; 2192 *lenp -= left; 2193 *ppos += *lenp; 2194 return 0; 2195 #undef TMPBUFLEN 2196 } 2197 2198 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp, 2199 void __user *buffer, size_t *lenp, loff_t *ppos, 2200 int (*conv)(int *negp, unsigned long *lvalp, int *valp, 2201 int write, void *data), 2202 void *data) 2203 { 2204 return __do_proc_dointvec(table->data, table, write, filp, 2205 buffer, lenp, ppos, conv, data); 2206 } 2207 2208 /** 2209 * proc_dointvec - read a vector of integers 2210 * @table: the sysctl table 2211 * @write: %TRUE if this is a write to the sysctl file 2212 * @filp: the file structure 2213 * @buffer: the user buffer 2214 * @lenp: the size of the user buffer 2215 * @ppos: file position 2216 * 2217 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 2218 * values from/to the user buffer, treated as an ASCII string. 2219 * 2220 * Returns 0 on success. 2221 */ 2222 int proc_dointvec(struct ctl_table *table, int write, struct file *filp, 2223 void __user *buffer, size_t *lenp, loff_t *ppos) 2224 { 2225 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 2226 NULL,NULL); 2227 } 2228 2229 /* 2230 * Taint values can only be increased 2231 * This means we can safely use a temporary. 2232 */ 2233 static int proc_taint(struct ctl_table *table, int write, struct file *filp, 2234 void __user *buffer, size_t *lenp, loff_t *ppos) 2235 { 2236 struct ctl_table t; 2237 unsigned long tmptaint = get_taint(); 2238 int err; 2239 2240 if (write && !capable(CAP_SYS_ADMIN)) 2241 return -EPERM; 2242 2243 t = *table; 2244 t.data = &tmptaint; 2245 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos); 2246 if (err < 0) 2247 return err; 2248 2249 if (write) { 2250 /* 2251 * Poor man's atomic or. Not worth adding a primitive 2252 * to everyone's atomic.h for this 2253 */ 2254 int i; 2255 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { 2256 if ((tmptaint >> i) & 1) 2257 add_taint(i); 2258 } 2259 } 2260 2261 return err; 2262 } 2263 2264 struct do_proc_dointvec_minmax_conv_param { 2265 int *min; 2266 int *max; 2267 }; 2268 2269 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 2270 int *valp, 2271 int write, void *data) 2272 { 2273 struct do_proc_dointvec_minmax_conv_param *param = data; 2274 if (write) { 2275 int val = *negp ? -*lvalp : *lvalp; 2276 if ((param->min && *param->min > val) || 2277 (param->max && *param->max < val)) 2278 return -EINVAL; 2279 *valp = val; 2280 } else { 2281 int val = *valp; 2282 if (val < 0) { 2283 *negp = -1; 2284 *lvalp = (unsigned long)-val; 2285 } else { 2286 *negp = 0; 2287 *lvalp = (unsigned long)val; 2288 } 2289 } 2290 return 0; 2291 } 2292 2293 /** 2294 * proc_dointvec_minmax - read a vector of integers with min/max values 2295 * @table: the sysctl table 2296 * @write: %TRUE if this is a write to the sysctl file 2297 * @filp: the file structure 2298 * @buffer: the user buffer 2299 * @lenp: the size of the user buffer 2300 * @ppos: file position 2301 * 2302 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 2303 * values from/to the user buffer, treated as an ASCII string. 2304 * 2305 * This routine will ensure the values are within the range specified by 2306 * table->extra1 (min) and table->extra2 (max). 2307 * 2308 * Returns 0 on success. 2309 */ 2310 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, 2311 void __user *buffer, size_t *lenp, loff_t *ppos) 2312 { 2313 struct do_proc_dointvec_minmax_conv_param param = { 2314 .min = (int *) table->extra1, 2315 .max = (int *) table->extra2, 2316 }; 2317 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, 2318 do_proc_dointvec_minmax_conv, ¶m); 2319 } 2320 2321 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, 2322 struct file *filp, 2323 void __user *buffer, 2324 size_t *lenp, loff_t *ppos, 2325 unsigned long convmul, 2326 unsigned long convdiv) 2327 { 2328 #define TMPBUFLEN 21 2329 unsigned long *i, *min, *max, val; 2330 int vleft, first=1, neg; 2331 size_t len, left; 2332 char buf[TMPBUFLEN], *p; 2333 char __user *s = buffer; 2334 2335 if (!data || !table->maxlen || !*lenp || 2336 (*ppos && !write)) { 2337 *lenp = 0; 2338 return 0; 2339 } 2340 2341 i = (unsigned long *) data; 2342 min = (unsigned long *) table->extra1; 2343 max = (unsigned long *) table->extra2; 2344 vleft = table->maxlen / sizeof(unsigned long); 2345 left = *lenp; 2346 2347 for (; left && vleft--; i++, min++, max++, first=0) { 2348 if (write) { 2349 while (left) { 2350 char c; 2351 if (get_user(c, s)) 2352 return -EFAULT; 2353 if (!isspace(c)) 2354 break; 2355 left--; 2356 s++; 2357 } 2358 if (!left) 2359 break; 2360 neg = 0; 2361 len = left; 2362 if (len > TMPBUFLEN-1) 2363 len = TMPBUFLEN-1; 2364 if (copy_from_user(buf, s, len)) 2365 return -EFAULT; 2366 buf[len] = 0; 2367 p = buf; 2368 if (*p == '-' && left > 1) { 2369 neg = 1; 2370 p++; 2371 } 2372 if (*p < '0' || *p > '9') 2373 break; 2374 val = simple_strtoul(p, &p, 0) * convmul / convdiv ; 2375 len = p-buf; 2376 if ((len < left) && *p && !isspace(*p)) 2377 break; 2378 if (neg) 2379 val = -val; 2380 s += len; 2381 left -= len; 2382 2383 if(neg) 2384 continue; 2385 if ((min && val < *min) || (max && val > *max)) 2386 continue; 2387 *i = val; 2388 } else { 2389 p = buf; 2390 if (!first) 2391 *p++ = '\t'; 2392 sprintf(p, "%lu", convdiv * (*i) / convmul); 2393 len = strlen(buf); 2394 if (len > left) 2395 len = left; 2396 if(copy_to_user(s, buf, len)) 2397 return -EFAULT; 2398 left -= len; 2399 s += len; 2400 } 2401 } 2402 2403 if (!write && !first && left) { 2404 if(put_user('\n', s)) 2405 return -EFAULT; 2406 left--, s++; 2407 } 2408 if (write) { 2409 while (left) { 2410 char c; 2411 if (get_user(c, s++)) 2412 return -EFAULT; 2413 if (!isspace(c)) 2414 break; 2415 left--; 2416 } 2417 } 2418 if (write && first) 2419 return -EINVAL; 2420 *lenp -= left; 2421 *ppos += *lenp; 2422 return 0; 2423 #undef TMPBUFLEN 2424 } 2425 2426 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 2427 struct file *filp, 2428 void __user *buffer, 2429 size_t *lenp, loff_t *ppos, 2430 unsigned long convmul, 2431 unsigned long convdiv) 2432 { 2433 return __do_proc_doulongvec_minmax(table->data, table, write, 2434 filp, buffer, lenp, ppos, convmul, convdiv); 2435 } 2436 2437 /** 2438 * proc_doulongvec_minmax - read a vector of long integers with min/max values 2439 * @table: the sysctl table 2440 * @write: %TRUE if this is a write to the sysctl file 2441 * @filp: the file structure 2442 * @buffer: the user buffer 2443 * @lenp: the size of the user buffer 2444 * @ppos: file position 2445 * 2446 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 2447 * values from/to the user buffer, treated as an ASCII string. 2448 * 2449 * This routine will ensure the values are within the range specified by 2450 * table->extra1 (min) and table->extra2 (max). 2451 * 2452 * Returns 0 on success. 2453 */ 2454 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, 2455 void __user *buffer, size_t *lenp, loff_t *ppos) 2456 { 2457 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l); 2458 } 2459 2460 /** 2461 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 2462 * @table: the sysctl table 2463 * @write: %TRUE if this is a write to the sysctl file 2464 * @filp: the file structure 2465 * @buffer: the user buffer 2466 * @lenp: the size of the user buffer 2467 * @ppos: file position 2468 * 2469 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 2470 * values from/to the user buffer, treated as an ASCII string. The values 2471 * are treated as milliseconds, and converted to jiffies when they are stored. 2472 * 2473 * This routine will ensure the values are within the range specified by 2474 * table->extra1 (min) and table->extra2 (max). 2475 * 2476 * Returns 0 on success. 2477 */ 2478 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 2479 struct file *filp, 2480 void __user *buffer, 2481 size_t *lenp, loff_t *ppos) 2482 { 2483 return do_proc_doulongvec_minmax(table, write, filp, buffer, 2484 lenp, ppos, HZ, 1000l); 2485 } 2486 2487 2488 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, 2489 int *valp, 2490 int write, void *data) 2491 { 2492 if (write) { 2493 if (*lvalp > LONG_MAX / HZ) 2494 return 1; 2495 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); 2496 } else { 2497 int val = *valp; 2498 unsigned long lval; 2499 if (val < 0) { 2500 *negp = -1; 2501 lval = (unsigned long)-val; 2502 } else { 2503 *negp = 0; 2504 lval = (unsigned long)val; 2505 } 2506 *lvalp = lval / HZ; 2507 } 2508 return 0; 2509 } 2510 2511 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, 2512 int *valp, 2513 int write, void *data) 2514 { 2515 if (write) { 2516 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 2517 return 1; 2518 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 2519 } else { 2520 int val = *valp; 2521 unsigned long lval; 2522 if (val < 0) { 2523 *negp = -1; 2524 lval = (unsigned long)-val; 2525 } else { 2526 *negp = 0; 2527 lval = (unsigned long)val; 2528 } 2529 *lvalp = jiffies_to_clock_t(lval); 2530 } 2531 return 0; 2532 } 2533 2534 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, 2535 int *valp, 2536 int write, void *data) 2537 { 2538 if (write) { 2539 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 2540 } else { 2541 int val = *valp; 2542 unsigned long lval; 2543 if (val < 0) { 2544 *negp = -1; 2545 lval = (unsigned long)-val; 2546 } else { 2547 *negp = 0; 2548 lval = (unsigned long)val; 2549 } 2550 *lvalp = jiffies_to_msecs(lval); 2551 } 2552 return 0; 2553 } 2554 2555 /** 2556 * proc_dointvec_jiffies - read a vector of integers as seconds 2557 * @table: the sysctl table 2558 * @write: %TRUE if this is a write to the sysctl file 2559 * @filp: the file structure 2560 * @buffer: the user buffer 2561 * @lenp: the size of the user buffer 2562 * @ppos: file position 2563 * 2564 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 2565 * values from/to the user buffer, treated as an ASCII string. 2566 * The values read are assumed to be in seconds, and are converted into 2567 * jiffies. 2568 * 2569 * Returns 0 on success. 2570 */ 2571 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, 2572 void __user *buffer, size_t *lenp, loff_t *ppos) 2573 { 2574 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 2575 do_proc_dointvec_jiffies_conv,NULL); 2576 } 2577 2578 /** 2579 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 2580 * @table: the sysctl table 2581 * @write: %TRUE if this is a write to the sysctl file 2582 * @filp: the file structure 2583 * @buffer: the user buffer 2584 * @lenp: the size of the user buffer 2585 * @ppos: pointer to the file position 2586 * 2587 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 2588 * values from/to the user buffer, treated as an ASCII string. 2589 * The values read are assumed to be in 1/USER_HZ seconds, and 2590 * are converted into jiffies. 2591 * 2592 * Returns 0 on success. 2593 */ 2594 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, 2595 void __user *buffer, size_t *lenp, loff_t *ppos) 2596 { 2597 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, 2598 do_proc_dointvec_userhz_jiffies_conv,NULL); 2599 } 2600 2601 /** 2602 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 2603 * @table: the sysctl table 2604 * @write: %TRUE if this is a write to the sysctl file 2605 * @filp: the file structure 2606 * @buffer: the user buffer 2607 * @lenp: the size of the user buffer 2608 * @ppos: file position 2609 * @ppos: the current position in the file 2610 * 2611 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 2612 * values from/to the user buffer, treated as an ASCII string. 2613 * The values read are assumed to be in 1/1000 seconds, and 2614 * are converted into jiffies. 2615 * 2616 * Returns 0 on success. 2617 */ 2618 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, 2619 void __user *buffer, size_t *lenp, loff_t *ppos) 2620 { 2621 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, 2622 do_proc_dointvec_ms_jiffies_conv, NULL); 2623 } 2624 2625 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, 2626 void __user *buffer, size_t *lenp, loff_t *ppos) 2627 { 2628 struct pid *new_pid; 2629 pid_t tmp; 2630 int r; 2631 2632 tmp = pid_vnr(cad_pid); 2633 2634 r = __do_proc_dointvec(&tmp, table, write, filp, buffer, 2635 lenp, ppos, NULL, NULL); 2636 if (r || !write) 2637 return r; 2638 2639 new_pid = find_get_pid(tmp); 2640 if (!new_pid) 2641 return -ESRCH; 2642 2643 put_pid(xchg(&cad_pid, new_pid)); 2644 return 0; 2645 } 2646 2647 #else /* CONFIG_PROC_FS */ 2648 2649 int proc_dostring(struct ctl_table *table, int write, struct file *filp, 2650 void __user *buffer, size_t *lenp, loff_t *ppos) 2651 { 2652 return -ENOSYS; 2653 } 2654 2655 int proc_dointvec(struct ctl_table *table, int write, struct file *filp, 2656 void __user *buffer, size_t *lenp, loff_t *ppos) 2657 { 2658 return -ENOSYS; 2659 } 2660 2661 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, 2662 void __user *buffer, size_t *lenp, loff_t *ppos) 2663 { 2664 return -ENOSYS; 2665 } 2666 2667 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, 2668 void __user *buffer, size_t *lenp, loff_t *ppos) 2669 { 2670 return -ENOSYS; 2671 } 2672 2673 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, 2674 void __user *buffer, size_t *lenp, loff_t *ppos) 2675 { 2676 return -ENOSYS; 2677 } 2678 2679 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, 2680 void __user *buffer, size_t *lenp, loff_t *ppos) 2681 { 2682 return -ENOSYS; 2683 } 2684 2685 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, 2686 void __user *buffer, size_t *lenp, loff_t *ppos) 2687 { 2688 return -ENOSYS; 2689 } 2690 2691 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 2692 struct file *filp, 2693 void __user *buffer, 2694 size_t *lenp, loff_t *ppos) 2695 { 2696 return -ENOSYS; 2697 } 2698 2699 2700 #endif /* CONFIG_PROC_FS */ 2701 2702 2703 #ifdef CONFIG_SYSCTL_SYSCALL 2704 /* 2705 * General sysctl support routines 2706 */ 2707 2708 /* The generic sysctl data routine (used if no strategy routine supplied) */ 2709 int sysctl_data(struct ctl_table *table, 2710 void __user *oldval, size_t __user *oldlenp, 2711 void __user *newval, size_t newlen) 2712 { 2713 size_t len; 2714 2715 /* Get out of I don't have a variable */ 2716 if (!table->data || !table->maxlen) 2717 return -ENOTDIR; 2718 2719 if (oldval && oldlenp) { 2720 if (get_user(len, oldlenp)) 2721 return -EFAULT; 2722 if (len) { 2723 if (len > table->maxlen) 2724 len = table->maxlen; 2725 if (copy_to_user(oldval, table->data, len)) 2726 return -EFAULT; 2727 if (put_user(len, oldlenp)) 2728 return -EFAULT; 2729 } 2730 } 2731 2732 if (newval && newlen) { 2733 if (newlen > table->maxlen) 2734 newlen = table->maxlen; 2735 2736 if (copy_from_user(table->data, newval, newlen)) 2737 return -EFAULT; 2738 } 2739 return 1; 2740 } 2741 2742 /* The generic string strategy routine: */ 2743 int sysctl_string(struct ctl_table *table, 2744 void __user *oldval, size_t __user *oldlenp, 2745 void __user *newval, size_t newlen) 2746 { 2747 if (!table->data || !table->maxlen) 2748 return -ENOTDIR; 2749 2750 if (oldval && oldlenp) { 2751 size_t bufsize; 2752 if (get_user(bufsize, oldlenp)) 2753 return -EFAULT; 2754 if (bufsize) { 2755 size_t len = strlen(table->data), copied; 2756 2757 /* This shouldn't trigger for a well-formed sysctl */ 2758 if (len > table->maxlen) 2759 len = table->maxlen; 2760 2761 /* Copy up to a max of bufsize-1 bytes of the string */ 2762 copied = (len >= bufsize) ? bufsize - 1 : len; 2763 2764 if (copy_to_user(oldval, table->data, copied) || 2765 put_user(0, (char __user *)(oldval + copied))) 2766 return -EFAULT; 2767 if (put_user(len, oldlenp)) 2768 return -EFAULT; 2769 } 2770 } 2771 if (newval && newlen) { 2772 size_t len = newlen; 2773 if (len > table->maxlen) 2774 len = table->maxlen; 2775 if(copy_from_user(table->data, newval, len)) 2776 return -EFAULT; 2777 if (len == table->maxlen) 2778 len--; 2779 ((char *) table->data)[len] = 0; 2780 } 2781 return 1; 2782 } 2783 2784 /* 2785 * This function makes sure that all of the integers in the vector 2786 * are between the minimum and maximum values given in the arrays 2787 * table->extra1 and table->extra2, respectively. 2788 */ 2789 int sysctl_intvec(struct ctl_table *table, 2790 void __user *oldval, size_t __user *oldlenp, 2791 void __user *newval, size_t newlen) 2792 { 2793 2794 if (newval && newlen) { 2795 int __user *vec = (int __user *) newval; 2796 int *min = (int *) table->extra1; 2797 int *max = (int *) table->extra2; 2798 size_t length; 2799 int i; 2800 2801 if (newlen % sizeof(int) != 0) 2802 return -EINVAL; 2803 2804 if (!table->extra1 && !table->extra2) 2805 return 0; 2806 2807 if (newlen > table->maxlen) 2808 newlen = table->maxlen; 2809 length = newlen / sizeof(int); 2810 2811 for (i = 0; i < length; i++) { 2812 int value; 2813 if (get_user(value, vec + i)) 2814 return -EFAULT; 2815 if (min && value < min[i]) 2816 return -EINVAL; 2817 if (max && value > max[i]) 2818 return -EINVAL; 2819 } 2820 } 2821 return 0; 2822 } 2823 2824 /* Strategy function to convert jiffies to seconds */ 2825 int sysctl_jiffies(struct ctl_table *table, 2826 void __user *oldval, size_t __user *oldlenp, 2827 void __user *newval, size_t newlen) 2828 { 2829 if (oldval && oldlenp) { 2830 size_t olen; 2831 2832 if (get_user(olen, oldlenp)) 2833 return -EFAULT; 2834 if (olen) { 2835 int val; 2836 2837 if (olen < sizeof(int)) 2838 return -EINVAL; 2839 2840 val = *(int *)(table->data) / HZ; 2841 if (put_user(val, (int __user *)oldval)) 2842 return -EFAULT; 2843 if (put_user(sizeof(int), oldlenp)) 2844 return -EFAULT; 2845 } 2846 } 2847 if (newval && newlen) { 2848 int new; 2849 if (newlen != sizeof(int)) 2850 return -EINVAL; 2851 if (get_user(new, (int __user *)newval)) 2852 return -EFAULT; 2853 *(int *)(table->data) = new*HZ; 2854 } 2855 return 1; 2856 } 2857 2858 /* Strategy function to convert jiffies to seconds */ 2859 int sysctl_ms_jiffies(struct ctl_table *table, 2860 void __user *oldval, size_t __user *oldlenp, 2861 void __user *newval, size_t newlen) 2862 { 2863 if (oldval && oldlenp) { 2864 size_t olen; 2865 2866 if (get_user(olen, oldlenp)) 2867 return -EFAULT; 2868 if (olen) { 2869 int val; 2870 2871 if (olen < sizeof(int)) 2872 return -EINVAL; 2873 2874 val = jiffies_to_msecs(*(int *)(table->data)); 2875 if (put_user(val, (int __user *)oldval)) 2876 return -EFAULT; 2877 if (put_user(sizeof(int), oldlenp)) 2878 return -EFAULT; 2879 } 2880 } 2881 if (newval && newlen) { 2882 int new; 2883 if (newlen != sizeof(int)) 2884 return -EINVAL; 2885 if (get_user(new, (int __user *)newval)) 2886 return -EFAULT; 2887 *(int *)(table->data) = msecs_to_jiffies(new); 2888 } 2889 return 1; 2890 } 2891 2892 2893 2894 #else /* CONFIG_SYSCTL_SYSCALL */ 2895 2896 2897 asmlinkage long sys_sysctl(struct __sysctl_args __user *args) 2898 { 2899 struct __sysctl_args tmp; 2900 int error; 2901 2902 if (copy_from_user(&tmp, args, sizeof(tmp))) 2903 return -EFAULT; 2904 2905 error = deprecated_sysctl_warning(&tmp); 2906 2907 /* If no error reading the parameters then just -ENOSYS ... */ 2908 if (!error) 2909 error = -ENOSYS; 2910 2911 return error; 2912 } 2913 2914 int sysctl_data(struct ctl_table *table, 2915 void __user *oldval, size_t __user *oldlenp, 2916 void __user *newval, size_t newlen) 2917 { 2918 return -ENOSYS; 2919 } 2920 2921 int sysctl_string(struct ctl_table *table, 2922 void __user *oldval, size_t __user *oldlenp, 2923 void __user *newval, size_t newlen) 2924 { 2925 return -ENOSYS; 2926 } 2927 2928 int sysctl_intvec(struct ctl_table *table, 2929 void __user *oldval, size_t __user *oldlenp, 2930 void __user *newval, size_t newlen) 2931 { 2932 return -ENOSYS; 2933 } 2934 2935 int sysctl_jiffies(struct ctl_table *table, 2936 void __user *oldval, size_t __user *oldlenp, 2937 void __user *newval, size_t newlen) 2938 { 2939 return -ENOSYS; 2940 } 2941 2942 int sysctl_ms_jiffies(struct ctl_table *table, 2943 void __user *oldval, size_t __user *oldlenp, 2944 void __user *newval, size_t newlen) 2945 { 2946 return -ENOSYS; 2947 } 2948 2949 #endif /* CONFIG_SYSCTL_SYSCALL */ 2950 2951 static int deprecated_sysctl_warning(struct __sysctl_args *args) 2952 { 2953 static int msg_count; 2954 int name[CTL_MAXNAME]; 2955 int i; 2956 2957 /* Check args->nlen. */ 2958 if (args->nlen < 0 || args->nlen > CTL_MAXNAME) 2959 return -ENOTDIR; 2960 2961 /* Read in the sysctl name for better debug message logging */ 2962 for (i = 0; i < args->nlen; i++) 2963 if (get_user(name[i], args->name + i)) 2964 return -EFAULT; 2965 2966 /* Ignore accesses to kernel.version */ 2967 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION)) 2968 return 0; 2969 2970 if (msg_count < 5) { 2971 msg_count++; 2972 printk(KERN_INFO 2973 "warning: process `%s' used the deprecated sysctl " 2974 "system call with ", current->comm); 2975 for (i = 0; i < args->nlen; i++) 2976 printk("%d.", name[i]); 2977 printk("\n"); 2978 } 2979 return 0; 2980 } 2981 2982 /* 2983 * No sense putting this after each symbol definition, twice, 2984 * exception granted :-) 2985 */ 2986 EXPORT_SYMBOL(proc_dointvec); 2987 EXPORT_SYMBOL(proc_dointvec_jiffies); 2988 EXPORT_SYMBOL(proc_dointvec_minmax); 2989 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 2990 EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 2991 EXPORT_SYMBOL(proc_dostring); 2992 EXPORT_SYMBOL(proc_doulongvec_minmax); 2993 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 2994 EXPORT_SYMBOL(register_sysctl_table); 2995 EXPORT_SYMBOL(register_sysctl_paths); 2996 EXPORT_SYMBOL(sysctl_intvec); 2997 EXPORT_SYMBOL(sysctl_jiffies); 2998 EXPORT_SYMBOL(sysctl_ms_jiffies); 2999 EXPORT_SYMBOL(sysctl_string); 3000 EXPORT_SYMBOL(sysctl_data); 3001 EXPORT_SYMBOL(unregister_sysctl_table); 3002