aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sysctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/sysctl.c')
-rw-r--r--kernel/sysctl.c250
1 files changed, 210 insertions, 40 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 29116652dca8..fe4713347275 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -43,9 +43,11 @@
43#include <linux/limits.h> 43#include <linux/limits.h>
44#include <linux/dcache.h> 44#include <linux/dcache.h>
45#include <linux/syscalls.h> 45#include <linux/syscalls.h>
46#include <linux/vmstat.h>
46#include <linux/nfs_fs.h> 47#include <linux/nfs_fs.h>
47#include <linux/acpi.h> 48#include <linux/acpi.h>
48#include <linux/reboot.h> 49#include <linux/reboot.h>
50#include <linux/ftrace.h>
49 51
50#include <asm/uaccess.h> 52#include <asm/uaccess.h>
51#include <asm/processor.h> 53#include <asm/processor.h>
@@ -79,17 +81,20 @@ extern int sysctl_drop_caches;
79extern int percpu_pagelist_fraction; 81extern int percpu_pagelist_fraction;
80extern int compat_log; 82extern int compat_log;
81extern int maps_protect; 83extern int maps_protect;
82extern int sysctl_stat_interval;
83extern int latencytop_enabled; 84extern int latencytop_enabled;
84extern int sysctl_nr_open_min, sysctl_nr_open_max; 85extern int sysctl_nr_open_min, sysctl_nr_open_max;
86#ifdef CONFIG_RCU_TORTURE_TEST
87extern int rcutorture_runnable;
88#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
85 89
86/* Constants used for minimum and maximum */ 90/* Constants used for minimum and maximum */
87#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM) 91#if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
88static int one = 1; 92static int one = 1;
89#endif 93#endif
90 94
91#ifdef CONFIG_DETECT_SOFTLOCKUP 95#ifdef CONFIG_DETECT_SOFTLOCKUP
92static int sixty = 60; 96static int sixty = 60;
97static int neg_one = -1;
93#endif 98#endif
94 99
95#ifdef CONFIG_MMU 100#ifdef CONFIG_MMU
@@ -106,7 +111,7 @@ static int min_percpu_pagelist_fract = 8;
106 111
107static int ngroups_max = NGROUPS_MAX; 112static int ngroups_max = NGROUPS_MAX;
108 113
109#ifdef CONFIG_KMOD 114#ifdef CONFIG_MODULES
110extern char modprobe_path[]; 115extern char modprobe_path[];
111#endif 116#endif
112#ifdef CONFIG_CHR_DEV_SG 117#ifdef CONFIG_CHR_DEV_SG
@@ -132,8 +137,6 @@ extern int sysctl_userprocess_debug;
132extern int spin_retry; 137extern int spin_retry;
133#endif 138#endif
134 139
135extern int sysctl_hz_timer;
136
137#ifdef CONFIG_BSD_PROCESS_ACCT 140#ifdef CONFIG_BSD_PROCESS_ACCT
138extern int acct_parm[]; 141extern int acct_parm[];
139#endif 142#endif
@@ -157,12 +160,13 @@ static struct ctl_table root_table[];
157static struct ctl_table_root sysctl_table_root; 160static struct ctl_table_root sysctl_table_root;
158static struct ctl_table_header root_table_header = { 161static struct ctl_table_header root_table_header = {
159 .ctl_table = root_table, 162 .ctl_table = root_table,
160 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list), 163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
161 .root = &sysctl_table_root, 164 .root = &sysctl_table_root,
165 .set = &sysctl_table_root.default_set,
162}; 166};
163static struct ctl_table_root sysctl_table_root = { 167static struct ctl_table_root sysctl_table_root = {
164 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), 168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
165 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry), 169 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
166}; 170};
167 171
168static struct ctl_table kern_table[]; 172static struct ctl_table kern_table[];
@@ -266,6 +270,14 @@ static struct ctl_table kern_table[] = {
266 }, 270 },
267 { 271 {
268 .ctl_name = CTL_UNNUMBERED, 272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_shares_ratelimit",
274 .data = &sysctl_sched_shares_ratelimit,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
277 .proc_handler = &proc_dointvec,
278 },
279 {
280 .ctl_name = CTL_UNNUMBERED,
269 .procname = "sched_child_runs_first", 281 .procname = "sched_child_runs_first",
270 .data = &sysctl_sched_child_runs_first, 282 .data = &sysctl_sched_child_runs_first,
271 .maxlen = sizeof(unsigned int), 283 .maxlen = sizeof(unsigned int),
@@ -455,7 +467,17 @@ static struct ctl_table kern_table[] = {
455 .mode = 0644, 467 .mode = 0644,
456 .proc_handler = &proc_dointvec, 468 .proc_handler = &proc_dointvec,
457 }, 469 },
458#ifdef CONFIG_KMOD 470#ifdef CONFIG_FTRACE
471 {
472 .ctl_name = CTL_UNNUMBERED,
473 .procname = "ftrace_enabled",
474 .data = &ftrace_enabled,
475 .maxlen = sizeof(int),
476 .mode = 0644,
477 .proc_handler = &ftrace_enable_sysctl,
478 },
479#endif
480#ifdef CONFIG_MODULES
459 { 481 {
460 .ctl_name = KERN_MODPROBE, 482 .ctl_name = KERN_MODPROBE,
461 .procname = "modprobe", 483 .procname = "modprobe",
@@ -563,16 +585,6 @@ static struct ctl_table kern_table[] = {
563 .proc_handler = &proc_dointvec, 585 .proc_handler = &proc_dointvec,
564 }, 586 },
565#endif 587#endif
566#ifdef CONFIG_NO_IDLE_HZ
567 {
568 .ctl_name = KERN_HZ_TIMER,
569 .procname = "hz_timer",
570 .data = &sysctl_hz_timer,
571 .maxlen = sizeof(int),
572 .mode = 0644,
573 .proc_handler = &proc_dointvec,
574 },
575#endif
576 { 588 {
577 .ctl_name = KERN_S390_USER_DEBUG_LOGGING, 589 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
578 .procname = "userprocess_debug", 590 .procname = "userprocess_debug",
@@ -613,7 +625,7 @@ static struct ctl_table kern_table[] = {
613 { 625 {
614 .ctl_name = KERN_PRINTK_RATELIMIT, 626 .ctl_name = KERN_PRINTK_RATELIMIT,
615 .procname = "printk_ratelimit", 627 .procname = "printk_ratelimit",
616 .data = &printk_ratelimit_jiffies, 628 .data = &printk_ratelimit_state.interval,
617 .maxlen = sizeof(int), 629 .maxlen = sizeof(int),
618 .mode = 0644, 630 .mode = 0644,
619 .proc_handler = &proc_dointvec_jiffies, 631 .proc_handler = &proc_dointvec_jiffies,
@@ -622,7 +634,7 @@ static struct ctl_table kern_table[] = {
622 { 634 {
623 .ctl_name = KERN_PRINTK_RATELIMIT_BURST, 635 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
624 .procname = "printk_ratelimit_burst", 636 .procname = "printk_ratelimit_burst",
625 .data = &printk_ratelimit_burst, 637 .data = &printk_ratelimit_state.burst,
626 .maxlen = sizeof(int), 638 .maxlen = sizeof(int),
627 .mode = 0644, 639 .mode = 0644,
628 .proc_handler = &proc_dointvec, 640 .proc_handler = &proc_dointvec,
@@ -729,13 +741,24 @@ static struct ctl_table kern_table[] = {
729#ifdef CONFIG_DETECT_SOFTLOCKUP 741#ifdef CONFIG_DETECT_SOFTLOCKUP
730 { 742 {
731 .ctl_name = CTL_UNNUMBERED, 743 .ctl_name = CTL_UNNUMBERED,
744 .procname = "softlockup_panic",
745 .data = &softlockup_panic,
746 .maxlen = sizeof(int),
747 .mode = 0644,
748 .proc_handler = &proc_dointvec_minmax,
749 .strategy = &sysctl_intvec,
750 .extra1 = &zero,
751 .extra2 = &one,
752 },
753 {
754 .ctl_name = CTL_UNNUMBERED,
732 .procname = "softlockup_thresh", 755 .procname = "softlockup_thresh",
733 .data = &softlockup_thresh, 756 .data = &softlockup_thresh,
734 .maxlen = sizeof(unsigned long), 757 .maxlen = sizeof(int),
735 .mode = 0644, 758 .mode = 0644,
736 .proc_handler = &proc_doulongvec_minmax, 759 .proc_handler = &proc_dointvec_minmax,
737 .strategy = &sysctl_intvec, 760 .strategy = &sysctl_intvec,
738 .extra1 = &one, 761 .extra1 = &neg_one,
739 .extra2 = &sixty, 762 .extra2 = &sixty,
740 }, 763 },
741 { 764 {
@@ -813,6 +836,16 @@ static struct ctl_table kern_table[] = {
813 .child = key_sysctls, 836 .child = key_sysctls,
814 }, 837 },
815#endif 838#endif
839#ifdef CONFIG_RCU_TORTURE_TEST
840 {
841 .ctl_name = CTL_UNNUMBERED,
842 .procname = "rcutorture_runnable",
843 .data = &rcutorture_runnable,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec,
847 },
848#endif
816/* 849/*
817 * NOTE: do not add new entries to this table unless you have read 850 * NOTE: do not add new entries to this table unless you have read
818 * Documentation/sysctl/ctl_unnumbered.txt 851 * Documentation/sysctl/ctl_unnumbered.txt
@@ -927,7 +960,7 @@ static struct ctl_table vm_table[] = {
927#ifdef CONFIG_HUGETLB_PAGE 960#ifdef CONFIG_HUGETLB_PAGE
928 { 961 {
929 .procname = "nr_hugepages", 962 .procname = "nr_hugepages",
930 .data = &max_huge_pages, 963 .data = NULL,
931 .maxlen = sizeof(unsigned long), 964 .maxlen = sizeof(unsigned long),
932 .mode = 0644, 965 .mode = 0644,
933 .proc_handler = &hugetlb_sysctl_handler, 966 .proc_handler = &hugetlb_sysctl_handler,
@@ -953,10 +986,12 @@ static struct ctl_table vm_table[] = {
953 { 986 {
954 .ctl_name = CTL_UNNUMBERED, 987 .ctl_name = CTL_UNNUMBERED,
955 .procname = "nr_overcommit_hugepages", 988 .procname = "nr_overcommit_hugepages",
956 .data = &sysctl_overcommit_huge_pages, 989 .data = NULL,
957 .maxlen = sizeof(sysctl_overcommit_huge_pages), 990 .maxlen = sizeof(unsigned long),
958 .mode = 0644, 991 .mode = 0644,
959 .proc_handler = &hugetlb_overcommit_handler, 992 .proc_handler = &hugetlb_overcommit_handler,
993 .extra1 = (void *)&hugetlb_zero,
994 .extra2 = (void *)&hugetlb_infinity,
960 }, 995 },
961#endif 996#endif
962 { 997 {
@@ -1352,6 +1387,9 @@ static void start_unregistering(struct ctl_table_header *p)
1352 spin_unlock(&sysctl_lock); 1387 spin_unlock(&sysctl_lock);
1353 wait_for_completion(&wait); 1388 wait_for_completion(&wait);
1354 spin_lock(&sysctl_lock); 1389 spin_lock(&sysctl_lock);
1390 } else {
1391 /* anything non-NULL; we'll never dereference it */
1392 p->unregistering = ERR_PTR(-EINVAL);
1355 } 1393 }
1356 /* 1394 /*
1357 * do not remove from the list until nobody holds it; walking the 1395 * do not remove from the list until nobody holds it; walking the
@@ -1360,6 +1398,32 @@ static void start_unregistering(struct ctl_table_header *p)
1360 list_del_init(&p->ctl_entry); 1398 list_del_init(&p->ctl_entry);
1361} 1399}
1362 1400
1401void sysctl_head_get(struct ctl_table_header *head)
1402{
1403 spin_lock(&sysctl_lock);
1404 head->count++;
1405 spin_unlock(&sysctl_lock);
1406}
1407
1408void sysctl_head_put(struct ctl_table_header *head)
1409{
1410 spin_lock(&sysctl_lock);
1411 if (!--head->count)
1412 kfree(head);
1413 spin_unlock(&sysctl_lock);
1414}
1415
1416struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1417{
1418 if (!head)
1419 BUG();
1420 spin_lock(&sysctl_lock);
1421 if (!use_table(head))
1422 head = ERR_PTR(-ENOENT);
1423 spin_unlock(&sysctl_lock);
1424 return head;
1425}
1426
1363void sysctl_head_finish(struct ctl_table_header *head) 1427void sysctl_head_finish(struct ctl_table_header *head)
1364{ 1428{
1365 if (!head) 1429 if (!head)
@@ -1369,14 +1433,20 @@ void sysctl_head_finish(struct ctl_table_header *head)
1369 spin_unlock(&sysctl_lock); 1433 spin_unlock(&sysctl_lock);
1370} 1434}
1371 1435
1436static struct ctl_table_set *
1437lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1438{
1439 struct ctl_table_set *set = &root->default_set;
1440 if (root->lookup)
1441 set = root->lookup(root, namespaces);
1442 return set;
1443}
1444
1372static struct list_head * 1445static struct list_head *
1373lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) 1446lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1374{ 1447{
1375 struct list_head *header_list; 1448 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1376 header_list = &root->header_list; 1449 return &set->list;
1377 if (root->lookup)
1378 header_list = root->lookup(root, namespaces);
1379 return header_list;
1380} 1450}
1381 1451
1382struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, 1452struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
@@ -1446,9 +1516,9 @@ static int do_sysctl_strategy(struct ctl_table_root *root,
1446 int op = 0, rc; 1516 int op = 0, rc;
1447 1517
1448 if (oldval) 1518 if (oldval)
1449 op |= 004; 1519 op |= MAY_READ;
1450 if (newval) 1520 if (newval)
1451 op |= 002; 1521 op |= MAY_WRITE;
1452 if (sysctl_perm(root, table, op)) 1522 if (sysctl_perm(root, table, op))
1453 return -EPERM; 1523 return -EPERM;
1454 1524
@@ -1490,7 +1560,7 @@ repeat:
1490 if (n == table->ctl_name) { 1560 if (n == table->ctl_name) {
1491 int error; 1561 int error;
1492 if (table->child) { 1562 if (table->child) {
1493 if (sysctl_perm(root, table, 001)) 1563 if (sysctl_perm(root, table, MAY_EXEC))
1494 return -EPERM; 1564 return -EPERM;
1495 name++; 1565 name++;
1496 nlen--; 1566 nlen--;
@@ -1565,7 +1635,7 @@ static int test_perm(int mode, int op)
1565 mode >>= 6; 1635 mode >>= 6;
1566 else if (in_egroup_p(0)) 1636 else if (in_egroup_p(0))
1567 mode >>= 3; 1637 mode >>= 3;
1568 if ((mode & op & 0007) == op) 1638 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1569 return 0; 1639 return 0;
1570 return -EACCES; 1640 return -EACCES;
1571} 1641}
@@ -1575,7 +1645,7 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1575 int error; 1645 int error;
1576 int mode; 1646 int mode;
1577 1647
1578 error = security_sysctl(table, op); 1648 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1579 if (error) 1649 if (error)
1580 return error; 1650 return error;
1581 1651
@@ -1610,6 +1680,54 @@ static __init int sysctl_init(void)
1610 1680
1611core_initcall(sysctl_init); 1681core_initcall(sysctl_init);
1612 1682
1683static struct ctl_table *is_branch_in(struct ctl_table *branch,
1684 struct ctl_table *table)
1685{
1686 struct ctl_table *p;
1687 const char *s = branch->procname;
1688
1689 /* branch should have named subdirectory as its first element */
1690 if (!s || !branch->child)
1691 return NULL;
1692
1693 /* ... and nothing else */
1694 if (branch[1].procname || branch[1].ctl_name)
1695 return NULL;
1696
1697 /* table should contain subdirectory with the same name */
1698 for (p = table; p->procname || p->ctl_name; p++) {
1699 if (!p->child)
1700 continue;
1701 if (p->procname && strcmp(p->procname, s) == 0)
1702 return p;
1703 }
1704 return NULL;
1705}
1706
1707/* see if attaching q to p would be an improvement */
1708static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1709{
1710 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1711 struct ctl_table *next;
1712 int is_better = 0;
1713 int not_in_parent = !p->attached_by;
1714
1715 while ((next = is_branch_in(by, to)) != NULL) {
1716 if (by == q->attached_by)
1717 is_better = 1;
1718 if (to == p->attached_by)
1719 not_in_parent = 1;
1720 by = by->child;
1721 to = next->child;
1722 }
1723
1724 if (is_better && not_in_parent) {
1725 q->attached_by = by;
1726 q->attached_to = to;
1727 q->parent = p;
1728 }
1729}
1730
1613/** 1731/**
1614 * __register_sysctl_paths - register a sysctl hierarchy 1732 * __register_sysctl_paths - register a sysctl hierarchy
1615 * @root: List of sysctl headers to register on 1733 * @root: List of sysctl headers to register on
@@ -1686,10 +1804,10 @@ struct ctl_table_header *__register_sysctl_paths(
1686 struct nsproxy *namespaces, 1804 struct nsproxy *namespaces,
1687 const struct ctl_path *path, struct ctl_table *table) 1805 const struct ctl_path *path, struct ctl_table *table)
1688{ 1806{
1689 struct list_head *header_list;
1690 struct ctl_table_header *header; 1807 struct ctl_table_header *header;
1691 struct ctl_table *new, **prevp; 1808 struct ctl_table *new, **prevp;
1692 unsigned int n, npath; 1809 unsigned int n, npath;
1810 struct ctl_table_set *set;
1693 1811
1694 /* Count the path components */ 1812 /* Count the path components */
1695 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) 1813 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
@@ -1731,6 +1849,7 @@ struct ctl_table_header *__register_sysctl_paths(
1731 header->unregistering = NULL; 1849 header->unregistering = NULL;
1732 header->root = root; 1850 header->root = root;
1733 sysctl_set_parent(NULL, header->ctl_table); 1851 sysctl_set_parent(NULL, header->ctl_table);
1852 header->count = 1;
1734#ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1853#ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1735 if (sysctl_check_table(namespaces, header->ctl_table)) { 1854 if (sysctl_check_table(namespaces, header->ctl_table)) {
1736 kfree(header); 1855 kfree(header);
@@ -1738,8 +1857,20 @@ struct ctl_table_header *__register_sysctl_paths(
1738 } 1857 }
1739#endif 1858#endif
1740 spin_lock(&sysctl_lock); 1859 spin_lock(&sysctl_lock);
1741 header_list = lookup_header_list(root, namespaces); 1860 header->set = lookup_header_set(root, namespaces);
1742 list_add_tail(&header->ctl_entry, header_list); 1861 header->attached_by = header->ctl_table;
1862 header->attached_to = root_table;
1863 header->parent = &root_table_header;
1864 for (set = header->set; set; set = set->parent) {
1865 struct ctl_table_header *p;
1866 list_for_each_entry(p, &set->list, ctl_entry) {
1867 if (p->unregistering)
1868 continue;
1869 try_attach(p, header);
1870 }
1871 }
1872 header->parent->count++;
1873 list_add_tail(&header->ctl_entry, &header->set->list);
1743 spin_unlock(&sysctl_lock); 1874 spin_unlock(&sysctl_lock);
1744 1875
1745 return header; 1876 return header;
@@ -1794,8 +1925,37 @@ void unregister_sysctl_table(struct ctl_table_header * header)
1794 1925
1795 spin_lock(&sysctl_lock); 1926 spin_lock(&sysctl_lock);
1796 start_unregistering(header); 1927 start_unregistering(header);
1928 if (!--header->parent->count) {
1929 WARN_ON(1);
1930 kfree(header->parent);
1931 }
1932 if (!--header->count)
1933 kfree(header);
1934 spin_unlock(&sysctl_lock);
1935}
1936
1937int sysctl_is_seen(struct ctl_table_header *p)
1938{
1939 struct ctl_table_set *set = p->set;
1940 int res;
1941 spin_lock(&sysctl_lock);
1942 if (p->unregistering)
1943 res = 0;
1944 else if (!set->is_seen)
1945 res = 1;
1946 else
1947 res = set->is_seen(set);
1797 spin_unlock(&sysctl_lock); 1948 spin_unlock(&sysctl_lock);
1798 kfree(header); 1949 return res;
1950}
1951
1952void setup_sysctl_set(struct ctl_table_set *p,
1953 struct ctl_table_set *parent,
1954 int (*is_seen)(struct ctl_table_set *))
1955{
1956 INIT_LIST_HEAD(&p->list);
1957 p->parent = parent ? parent : &sysctl_table_root.default_set;
1958 p->is_seen = is_seen;
1799} 1959}
1800 1960
1801#else /* !CONFIG_SYSCTL */ 1961#else /* !CONFIG_SYSCTL */
@@ -1814,6 +1974,16 @@ void unregister_sysctl_table(struct ctl_table_header * table)
1814{ 1974{
1815} 1975}
1816 1976
1977void setup_sysctl_set(struct ctl_table_set *p,
1978 struct ctl_table_set *parent,
1979 int (*is_seen)(struct ctl_table_set *))
1980{
1981}
1982
1983void sysctl_head_put(struct ctl_table_header *head)
1984{
1985}
1986
1817#endif /* CONFIG_SYSCTL */ 1987#endif /* CONFIG_SYSCTL */
1818 1988
1819/* 1989/*