diff options
Diffstat (limited to 'kernel/sysctl.c')
| -rw-r--r-- | kernel/sysctl.c | 514 |
1 files changed, 10 insertions, 504 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index f487f257e05e..52b3a06a02f8 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include <linux/swap.h> | 23 | #include <linux/swap.h> |
| 24 | #include <linux/slab.h> | 24 | #include <linux/slab.h> |
| 25 | #include <linux/sysctl.h> | 25 | #include <linux/sysctl.h> |
| 26 | #include <linux/bitmap.h> | ||
| 26 | #include <linux/signal.h> | 27 | #include <linux/signal.h> |
| 27 | #include <linux/printk.h> | 28 | #include <linux/printk.h> |
| 28 | #include <linux/proc_fs.h> | 29 | #include <linux/proc_fs.h> |
| @@ -58,6 +59,7 @@ | |||
| 58 | #include <linux/oom.h> | 59 | #include <linux/oom.h> |
| 59 | #include <linux/kmod.h> | 60 | #include <linux/kmod.h> |
| 60 | #include <linux/capability.h> | 61 | #include <linux/capability.h> |
| 62 | #include <linux/binfmts.h> | ||
| 61 | 63 | ||
| 62 | #include <asm/uaccess.h> | 64 | #include <asm/uaccess.h> |
| 63 | #include <asm/processor.h> | 65 | #include <asm/processor.h> |
| @@ -67,6 +69,9 @@ | |||
| 67 | #include <asm/stacktrace.h> | 69 | #include <asm/stacktrace.h> |
| 68 | #include <asm/io.h> | 70 | #include <asm/io.h> |
| 69 | #endif | 71 | #endif |
| 72 | #ifdef CONFIG_SPARC | ||
| 73 | #include <asm/setup.h> | ||
| 74 | #endif | ||
| 70 | #ifdef CONFIG_BSD_PROCESS_ACCT | 75 | #ifdef CONFIG_BSD_PROCESS_ACCT |
| 71 | #include <linux/acct.h> | 76 | #include <linux/acct.h> |
| 72 | #endif | 77 | #endif |
| @@ -141,7 +146,6 @@ static const int cap_last_cap = CAP_LAST_CAP; | |||
| 141 | #include <linux/inotify.h> | 146 | #include <linux/inotify.h> |
| 142 | #endif | 147 | #endif |
| 143 | #ifdef CONFIG_SPARC | 148 | #ifdef CONFIG_SPARC |
| 144 | #include <asm/system.h> | ||
| 145 | #endif | 149 | #endif |
| 146 | 150 | ||
| 147 | #ifdef CONFIG_SPARC64 | 151 | #ifdef CONFIG_SPARC64 |
| @@ -192,20 +196,6 @@ static int sysrq_sysctl_handler(ctl_table *table, int write, | |||
| 192 | 196 | ||
| 193 | #endif | 197 | #endif |
| 194 | 198 | ||
| 195 | static struct ctl_table root_table[]; | ||
| 196 | static struct ctl_table_root sysctl_table_root; | ||
| 197 | static struct ctl_table_header root_table_header = { | ||
| 198 | {{.count = 1, | ||
| 199 | .ctl_table = root_table, | ||
| 200 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}}, | ||
| 201 | .root = &sysctl_table_root, | ||
| 202 | .set = &sysctl_table_root.default_set, | ||
| 203 | }; | ||
| 204 | static struct ctl_table_root sysctl_table_root = { | ||
| 205 | .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), | ||
| 206 | .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry), | ||
| 207 | }; | ||
| 208 | |||
| 209 | static struct ctl_table kern_table[]; | 199 | static struct ctl_table kern_table[]; |
| 210 | static struct ctl_table vm_table[]; | 200 | static struct ctl_table vm_table[]; |
| 211 | static struct ctl_table fs_table[]; | 201 | static struct ctl_table fs_table[]; |
| @@ -222,7 +212,7 @@ int sysctl_legacy_va_layout; | |||
| 222 | 212 | ||
| 223 | /* The default sysctl tables: */ | 213 | /* The default sysctl tables: */ |
| 224 | 214 | ||
| 225 | static struct ctl_table root_table[] = { | 215 | static struct ctl_table sysctl_base_table[] = { |
| 226 | { | 216 | { |
| 227 | .procname = "kernel", | 217 | .procname = "kernel", |
| 228 | .mode = 0555, | 218 | .mode = 0555, |
| @@ -1559,490 +1549,12 @@ static struct ctl_table dev_table[] = { | |||
| 1559 | { } | 1549 | { } |
| 1560 | }; | 1550 | }; |
| 1561 | 1551 | ||
| 1562 | static DEFINE_SPINLOCK(sysctl_lock); | 1552 | int __init sysctl_init(void) |
| 1563 | |||
| 1564 | /* called under sysctl_lock */ | ||
| 1565 | static int use_table(struct ctl_table_header *p) | ||
| 1566 | { | 1553 | { |
| 1567 | if (unlikely(p->unregistering)) | 1554 | register_sysctl_table(sysctl_base_table); |
| 1568 | return 0; | ||
| 1569 | p->used++; | ||
| 1570 | return 1; | ||
| 1571 | } | ||
| 1572 | |||
| 1573 | /* called under sysctl_lock */ | ||
| 1574 | static void unuse_table(struct ctl_table_header *p) | ||
| 1575 | { | ||
| 1576 | if (!--p->used) | ||
| 1577 | if (unlikely(p->unregistering)) | ||
| 1578 | complete(p->unregistering); | ||
| 1579 | } | ||
| 1580 | |||
| 1581 | /* called under sysctl_lock, will reacquire if has to wait */ | ||
| 1582 | static void start_unregistering(struct ctl_table_header *p) | ||
| 1583 | { | ||
| 1584 | /* | ||
| 1585 | * if p->used is 0, nobody will ever touch that entry again; | ||
| 1586 | * we'll eliminate all paths to it before dropping sysctl_lock | ||
| 1587 | */ | ||
| 1588 | if (unlikely(p->used)) { | ||
| 1589 | struct completion wait; | ||
| 1590 | init_completion(&wait); | ||
| 1591 | p->unregistering = &wait; | ||
| 1592 | spin_unlock(&sysctl_lock); | ||
| 1593 | wait_for_completion(&wait); | ||
| 1594 | spin_lock(&sysctl_lock); | ||
| 1595 | } else { | ||
| 1596 | /* anything non-NULL; we'll never dereference it */ | ||
| 1597 | p->unregistering = ERR_PTR(-EINVAL); | ||
| 1598 | } | ||
| 1599 | /* | ||
| 1600 | * do not remove from the list until nobody holds it; walking the | ||
| 1601 | * list in do_sysctl() relies on that. | ||
| 1602 | */ | ||
| 1603 | list_del_init(&p->ctl_entry); | ||
| 1604 | } | ||
| 1605 | |||
| 1606 | void sysctl_head_get(struct ctl_table_header *head) | ||
| 1607 | { | ||
| 1608 | spin_lock(&sysctl_lock); | ||
| 1609 | head->count++; | ||
| 1610 | spin_unlock(&sysctl_lock); | ||
| 1611 | } | ||
| 1612 | |||
| 1613 | void sysctl_head_put(struct ctl_table_header *head) | ||
| 1614 | { | ||
| 1615 | spin_lock(&sysctl_lock); | ||
| 1616 | if (!--head->count) | ||
| 1617 | kfree_rcu(head, rcu); | ||
| 1618 | spin_unlock(&sysctl_lock); | ||
| 1619 | } | ||
| 1620 | |||
| 1621 | struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) | ||
| 1622 | { | ||
| 1623 | if (!head) | ||
| 1624 | BUG(); | ||
| 1625 | spin_lock(&sysctl_lock); | ||
| 1626 | if (!use_table(head)) | ||
| 1627 | head = ERR_PTR(-ENOENT); | ||
| 1628 | spin_unlock(&sysctl_lock); | ||
| 1629 | return head; | ||
| 1630 | } | ||
| 1631 | |||
| 1632 | void sysctl_head_finish(struct ctl_table_header *head) | ||
| 1633 | { | ||
| 1634 | if (!head) | ||
| 1635 | return; | ||
| 1636 | spin_lock(&sysctl_lock); | ||
| 1637 | unuse_table(head); | ||
| 1638 | spin_unlock(&sysctl_lock); | ||
| 1639 | } | ||
| 1640 | |||
| 1641 | static struct ctl_table_set * | ||
| 1642 | lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) | ||
| 1643 | { | ||
| 1644 | struct ctl_table_set *set = &root->default_set; | ||
| 1645 | if (root->lookup) | ||
| 1646 | set = root->lookup(root, namespaces); | ||
| 1647 | return set; | ||
| 1648 | } | ||
| 1649 | |||
| 1650 | static struct list_head * | ||
| 1651 | lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) | ||
| 1652 | { | ||
| 1653 | struct ctl_table_set *set = lookup_header_set(root, namespaces); | ||
| 1654 | return &set->list; | ||
| 1655 | } | ||
| 1656 | |||
| 1657 | struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, | ||
| 1658 | struct ctl_table_header *prev) | ||
| 1659 | { | ||
| 1660 | struct ctl_table_root *root; | ||
| 1661 | struct list_head *header_list; | ||
| 1662 | struct ctl_table_header *head; | ||
| 1663 | struct list_head *tmp; | ||
| 1664 | |||
| 1665 | spin_lock(&sysctl_lock); | ||
| 1666 | if (prev) { | ||
| 1667 | head = prev; | ||
| 1668 | tmp = &prev->ctl_entry; | ||
| 1669 | unuse_table(prev); | ||
| 1670 | goto next; | ||
| 1671 | } | ||
| 1672 | tmp = &root_table_header.ctl_entry; | ||
| 1673 | for (;;) { | ||
| 1674 | head = list_entry(tmp, struct ctl_table_header, ctl_entry); | ||
| 1675 | |||
| 1676 | if (!use_table(head)) | ||
| 1677 | goto next; | ||
| 1678 | spin_unlock(&sysctl_lock); | ||
| 1679 | return head; | ||
| 1680 | next: | ||
| 1681 | root = head->root; | ||
| 1682 | tmp = tmp->next; | ||
| 1683 | header_list = lookup_header_list(root, namespaces); | ||
| 1684 | if (tmp != header_list) | ||
| 1685 | continue; | ||
| 1686 | |||
| 1687 | do { | ||
| 1688 | root = list_entry(root->root_list.next, | ||
| 1689 | struct ctl_table_root, root_list); | ||
| 1690 | if (root == &sysctl_table_root) | ||
| 1691 | goto out; | ||
| 1692 | header_list = lookup_header_list(root, namespaces); | ||
| 1693 | } while (list_empty(header_list)); | ||
| 1694 | tmp = header_list->next; | ||
| 1695 | } | ||
| 1696 | out: | ||
| 1697 | spin_unlock(&sysctl_lock); | ||
| 1698 | return NULL; | ||
| 1699 | } | ||
| 1700 | |||
| 1701 | struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) | ||
| 1702 | { | ||
| 1703 | return __sysctl_head_next(current->nsproxy, prev); | ||
| 1704 | } | ||
| 1705 | |||
| 1706 | void register_sysctl_root(struct ctl_table_root *root) | ||
| 1707 | { | ||
| 1708 | spin_lock(&sysctl_lock); | ||
| 1709 | list_add_tail(&root->root_list, &sysctl_table_root.root_list); | ||
| 1710 | spin_unlock(&sysctl_lock); | ||
| 1711 | } | ||
| 1712 | |||
| 1713 | /* | ||
| 1714 | * sysctl_perm does NOT grant the superuser all rights automatically, because | ||
| 1715 | * some sysctl variables are readonly even to root. | ||
| 1716 | */ | ||
| 1717 | |||
| 1718 | static int test_perm(int mode, int op) | ||
| 1719 | { | ||
| 1720 | if (!current_euid()) | ||
| 1721 | mode >>= 6; | ||
| 1722 | else if (in_egroup_p(0)) | ||
| 1723 | mode >>= 3; | ||
| 1724 | if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0) | ||
| 1725 | return 0; | ||
| 1726 | return -EACCES; | ||
| 1727 | } | ||
| 1728 | |||
| 1729 | int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) | ||
| 1730 | { | ||
| 1731 | int mode; | ||
| 1732 | |||
| 1733 | if (root->permissions) | ||
| 1734 | mode = root->permissions(root, current->nsproxy, table); | ||
| 1735 | else | ||
| 1736 | mode = table->mode; | ||
| 1737 | |||
| 1738 | return test_perm(mode, op); | ||
| 1739 | } | ||
| 1740 | |||
| 1741 | static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) | ||
| 1742 | { | ||
| 1743 | for (; table->procname; table++) { | ||
| 1744 | table->parent = parent; | ||
| 1745 | if (table->child) | ||
| 1746 | sysctl_set_parent(table, table->child); | ||
| 1747 | } | ||
| 1748 | } | ||
| 1749 | |||
| 1750 | static __init int sysctl_init(void) | ||
| 1751 | { | ||
| 1752 | sysctl_set_parent(NULL, root_table); | ||
| 1753 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK | ||
| 1754 | sysctl_check_table(current->nsproxy, root_table); | ||
| 1755 | #endif | ||
| 1756 | return 0; | 1555 | return 0; |
| 1757 | } | 1556 | } |
| 1758 | 1557 | ||
| 1759 | core_initcall(sysctl_init); | ||
| 1760 | |||
| 1761 | static struct ctl_table *is_branch_in(struct ctl_table *branch, | ||
| 1762 | struct ctl_table *table) | ||
| 1763 | { | ||
| 1764 | struct ctl_table *p; | ||
| 1765 | const char *s = branch->procname; | ||
| 1766 | |||
| 1767 | /* branch should have named subdirectory as its first element */ | ||
| 1768 | if (!s || !branch->child) | ||
| 1769 | return NULL; | ||
| 1770 | |||
| 1771 | /* ... and nothing else */ | ||
| 1772 | if (branch[1].procname) | ||
| 1773 | return NULL; | ||
| 1774 | |||
| 1775 | /* table should contain subdirectory with the same name */ | ||
| 1776 | for (p = table; p->procname; p++) { | ||
| 1777 | if (!p->child) | ||
| 1778 | continue; | ||
| 1779 | if (p->procname && strcmp(p->procname, s) == 0) | ||
| 1780 | return p; | ||
| 1781 | } | ||
| 1782 | return NULL; | ||
| 1783 | } | ||
| 1784 | |||
| 1785 | /* see if attaching q to p would be an improvement */ | ||
| 1786 | static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q) | ||
| 1787 | { | ||
| 1788 | struct ctl_table *to = p->ctl_table, *by = q->ctl_table; | ||
| 1789 | struct ctl_table *next; | ||
| 1790 | int is_better = 0; | ||
| 1791 | int not_in_parent = !p->attached_by; | ||
| 1792 | |||
| 1793 | while ((next = is_branch_in(by, to)) != NULL) { | ||
| 1794 | if (by == q->attached_by) | ||
| 1795 | is_better = 1; | ||
| 1796 | if (to == p->attached_by) | ||
| 1797 | not_in_parent = 1; | ||
| 1798 | by = by->child; | ||
| 1799 | to = next->child; | ||
| 1800 | } | ||
| 1801 | |||
| 1802 | if (is_better && not_in_parent) { | ||
| 1803 | q->attached_by = by; | ||
| 1804 | q->attached_to = to; | ||
| 1805 | q->parent = p; | ||
| 1806 | } | ||
| 1807 | } | ||
| 1808 | |||
| 1809 | /** | ||
| 1810 | * __register_sysctl_paths - register a sysctl hierarchy | ||
| 1811 | * @root: List of sysctl headers to register on | ||
| 1812 | * @namespaces: Data to compute which lists of sysctl entries are visible | ||
| 1813 | * @path: The path to the directory the sysctl table is in. | ||
| 1814 | * @table: the top-level table structure | ||
| 1815 | * | ||
| 1816 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | ||
| 1817 | * array. A completely 0 filled entry terminates the table. | ||
| 1818 | * | ||
| 1819 | * The members of the &struct ctl_table structure are used as follows: | ||
| 1820 | * | ||
| 1821 | * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not | ||
| 1822 | * enter a sysctl file | ||
| 1823 | * | ||
| 1824 | * data - a pointer to data for use by proc_handler | ||
| 1825 | * | ||
| 1826 | * maxlen - the maximum size in bytes of the data | ||
| 1827 | * | ||
| 1828 | * mode - the file permissions for the /proc/sys file, and for sysctl(2) | ||
| 1829 | * | ||
| 1830 | * child - a pointer to the child sysctl table if this entry is a directory, or | ||
| 1831 | * %NULL. | ||
| 1832 | * | ||
| 1833 | * proc_handler - the text handler routine (described below) | ||
| 1834 | * | ||
| 1835 | * de - for internal use by the sysctl routines | ||
| 1836 | * | ||
| 1837 | * extra1, extra2 - extra pointers usable by the proc handler routines | ||
| 1838 | * | ||
| 1839 | * Leaf nodes in the sysctl tree will be represented by a single file | ||
| 1840 | * under /proc; non-leaf nodes will be represented by directories. | ||
| 1841 | * | ||
| 1842 | * sysctl(2) can automatically manage read and write requests through | ||
| 1843 | * the sysctl table. The data and maxlen fields of the ctl_table | ||
| 1844 | * struct enable minimal validation of the values being written to be | ||
| 1845 | * performed, and the mode field allows minimal authentication. | ||
| 1846 | * | ||
| 1847 | * There must be a proc_handler routine for any terminal nodes | ||
| 1848 | * mirrored under /proc/sys (non-terminals are handled by a built-in | ||
| 1849 | * directory handler). Several default handlers are available to | ||
| 1850 | * cover common cases - | ||
| 1851 | * | ||
| 1852 | * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), | ||
| 1853 | * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), | ||
| 1854 | * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() | ||
| 1855 | * | ||
| 1856 | * It is the handler's job to read the input buffer from user memory | ||
| 1857 | * and process it. The handler should return 0 on success. | ||
| 1858 | * | ||
| 1859 | * This routine returns %NULL on a failure to register, and a pointer | ||
| 1860 | * to the table header on success. | ||
| 1861 | */ | ||
| 1862 | struct ctl_table_header *__register_sysctl_paths( | ||
| 1863 | struct ctl_table_root *root, | ||
| 1864 | struct nsproxy *namespaces, | ||
| 1865 | const struct ctl_path *path, struct ctl_table *table) | ||
| 1866 | { | ||
| 1867 | struct ctl_table_header *header; | ||
| 1868 | struct ctl_table *new, **prevp; | ||
| 1869 | unsigned int n, npath; | ||
| 1870 | struct ctl_table_set *set; | ||
| 1871 | |||
| 1872 | /* Count the path components */ | ||
| 1873 | for (npath = 0; path[npath].procname; ++npath) | ||
| 1874 | ; | ||
| 1875 | |||
| 1876 | /* | ||
| 1877 | * For each path component, allocate a 2-element ctl_table array. | ||
| 1878 | * The first array element will be filled with the sysctl entry | ||
| 1879 | * for this, the second will be the sentinel (procname == 0). | ||
| 1880 | * | ||
| 1881 | * We allocate everything in one go so that we don't have to | ||
| 1882 | * worry about freeing additional memory in unregister_sysctl_table. | ||
| 1883 | */ | ||
| 1884 | header = kzalloc(sizeof(struct ctl_table_header) + | ||
| 1885 | (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); | ||
| 1886 | if (!header) | ||
| 1887 | return NULL; | ||
| 1888 | |||
| 1889 | new = (struct ctl_table *) (header + 1); | ||
| 1890 | |||
| 1891 | /* Now connect the dots */ | ||
| 1892 | prevp = &header->ctl_table; | ||
| 1893 | for (n = 0; n < npath; ++n, ++path) { | ||
| 1894 | /* Copy the procname */ | ||
| 1895 | new->procname = path->procname; | ||
| 1896 | new->mode = 0555; | ||
| 1897 | |||
| 1898 | *prevp = new; | ||
| 1899 | prevp = &new->child; | ||
| 1900 | |||
| 1901 | new += 2; | ||
| 1902 | } | ||
| 1903 | *prevp = table; | ||
| 1904 | header->ctl_table_arg = table; | ||
| 1905 | |||
| 1906 | INIT_LIST_HEAD(&header->ctl_entry); | ||
| 1907 | header->used = 0; | ||
| 1908 | header->unregistering = NULL; | ||
| 1909 | header->root = root; | ||
| 1910 | sysctl_set_parent(NULL, header->ctl_table); | ||
| 1911 | header->count = 1; | ||
| 1912 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK | ||
| 1913 | if (sysctl_check_table(namespaces, header->ctl_table)) { | ||
| 1914 | kfree(header); | ||
| 1915 | return NULL; | ||
| 1916 | } | ||
| 1917 | #endif | ||
| 1918 | spin_lock(&sysctl_lock); | ||
| 1919 | header->set = lookup_header_set(root, namespaces); | ||
| 1920 | header->attached_by = header->ctl_table; | ||
| 1921 | header->attached_to = root_table; | ||
| 1922 | header->parent = &root_table_header; | ||
| 1923 | for (set = header->set; set; set = set->parent) { | ||
| 1924 | struct ctl_table_header *p; | ||
| 1925 | list_for_each_entry(p, &set->list, ctl_entry) { | ||
| 1926 | if (p->unregistering) | ||
| 1927 | continue; | ||
| 1928 | try_attach(p, header); | ||
| 1929 | } | ||
| 1930 | } | ||
| 1931 | header->parent->count++; | ||
| 1932 | list_add_tail(&header->ctl_entry, &header->set->list); | ||
| 1933 | spin_unlock(&sysctl_lock); | ||
| 1934 | |||
| 1935 | return header; | ||
| 1936 | } | ||
| 1937 | |||
| 1938 | /** | ||
| 1939 | * register_sysctl_table_path - register a sysctl table hierarchy | ||
| 1940 | * @path: The path to the directory the sysctl table is in. | ||
| 1941 | * @table: the top-level table structure | ||
| 1942 | * | ||
| 1943 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | ||
| 1944 | * array. A completely 0 filled entry terminates the table. | ||
| 1945 | * | ||
| 1946 | * See __register_sysctl_paths for more details. | ||
| 1947 | */ | ||
| 1948 | struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, | ||
| 1949 | struct ctl_table *table) | ||
| 1950 | { | ||
| 1951 | return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, | ||
| 1952 | path, table); | ||
| 1953 | } | ||
| 1954 | |||
| 1955 | /** | ||
| 1956 | * register_sysctl_table - register a sysctl table hierarchy | ||
| 1957 | * @table: the top-level table structure | ||
| 1958 | * | ||
| 1959 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | ||
| 1960 | * array. A completely 0 filled entry terminates the table. | ||
| 1961 | * | ||
| 1962 | * See register_sysctl_paths for more details. | ||
| 1963 | */ | ||
| 1964 | struct ctl_table_header *register_sysctl_table(struct ctl_table *table) | ||
| 1965 | { | ||
| 1966 | static const struct ctl_path null_path[] = { {} }; | ||
| 1967 | |||
| 1968 | return register_sysctl_paths(null_path, table); | ||
| 1969 | } | ||
| 1970 | |||
| 1971 | /** | ||
| 1972 | * unregister_sysctl_table - unregister a sysctl table hierarchy | ||
| 1973 | * @header: the header returned from register_sysctl_table | ||
| 1974 | * | ||
| 1975 | * Unregisters the sysctl table and all children. proc entries may not | ||
| 1976 | * actually be removed until they are no longer used by anyone. | ||
| 1977 | */ | ||
| 1978 | void unregister_sysctl_table(struct ctl_table_header * header) | ||
| 1979 | { | ||
| 1980 | might_sleep(); | ||
| 1981 | |||
| 1982 | if (header == NULL) | ||
| 1983 | return; | ||
| 1984 | |||
| 1985 | spin_lock(&sysctl_lock); | ||
| 1986 | start_unregistering(header); | ||
| 1987 | if (!--header->parent->count) { | ||
| 1988 | WARN_ON(1); | ||
| 1989 | kfree_rcu(header->parent, rcu); | ||
| 1990 | } | ||
| 1991 | if (!--header->count) | ||
| 1992 | kfree_rcu(header, rcu); | ||
| 1993 | spin_unlock(&sysctl_lock); | ||
| 1994 | } | ||
| 1995 | |||
| 1996 | int sysctl_is_seen(struct ctl_table_header *p) | ||
| 1997 | { | ||
| 1998 | struct ctl_table_set *set = p->set; | ||
| 1999 | int res; | ||
| 2000 | spin_lock(&sysctl_lock); | ||
| 2001 | if (p->unregistering) | ||
| 2002 | res = 0; | ||
| 2003 | else if (!set->is_seen) | ||
| 2004 | res = 1; | ||
| 2005 | else | ||
| 2006 | res = set->is_seen(set); | ||
| 2007 | spin_unlock(&sysctl_lock); | ||
| 2008 | return res; | ||
| 2009 | } | ||
| 2010 | |||
| 2011 | void setup_sysctl_set(struct ctl_table_set *p, | ||
| 2012 | struct ctl_table_set *parent, | ||
| 2013 | int (*is_seen)(struct ctl_table_set *)) | ||
| 2014 | { | ||
| 2015 | INIT_LIST_HEAD(&p->list); | ||
| 2016 | p->parent = parent ? parent : &sysctl_table_root.default_set; | ||
| 2017 | p->is_seen = is_seen; | ||
| 2018 | } | ||
| 2019 | |||
| 2020 | #else /* !CONFIG_SYSCTL */ | ||
| 2021 | struct ctl_table_header *register_sysctl_table(struct ctl_table * table) | ||
| 2022 | { | ||
| 2023 | return NULL; | ||
| 2024 | } | ||
| 2025 | |||
| 2026 | struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, | ||
| 2027 | struct ctl_table *table) | ||
| 2028 | { | ||
| 2029 | return NULL; | ||
| 2030 | } | ||
| 2031 | |||
| 2032 | void unregister_sysctl_table(struct ctl_table_header * table) | ||
| 2033 | { | ||
| 2034 | } | ||
| 2035 | |||
| 2036 | void setup_sysctl_set(struct ctl_table_set *p, | ||
| 2037 | struct ctl_table_set *parent, | ||
| 2038 | int (*is_seen)(struct ctl_table_set *)) | ||
| 2039 | { | ||
| 2040 | } | ||
| 2041 | |||
| 2042 | void sysctl_head_put(struct ctl_table_header *head) | ||
| 2043 | { | ||
| 2044 | } | ||
| 2045 | |||
| 2046 | #endif /* CONFIG_SYSCTL */ | 1558 | #endif /* CONFIG_SYSCTL */ |
| 2047 | 1559 | ||
| 2048 | /* | 1560 | /* |
| @@ -2884,9 +2396,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, | |||
| 2884 | } | 2396 | } |
| 2885 | } | 2397 | } |
| 2886 | 2398 | ||
| 2887 | while (val_a <= val_b) | 2399 | bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); |
| 2888 | set_bit(val_a++, tmp_bitmap); | ||
| 2889 | |||
| 2890 | first = 0; | 2400 | first = 0; |
| 2891 | proc_skip_char(&kbuf, &left, '\n'); | 2401 | proc_skip_char(&kbuf, &left, '\n'); |
| 2892 | } | 2402 | } |
| @@ -2929,8 +2439,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, | |||
| 2929 | if (*ppos) | 2439 | if (*ppos) |
| 2930 | bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); | 2440 | bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); |
| 2931 | else | 2441 | else |
| 2932 | memcpy(bitmap, tmp_bitmap, | 2442 | bitmap_copy(bitmap, tmp_bitmap, bitmap_len); |
| 2933 | BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long)); | ||
| 2934 | } | 2443 | } |
| 2935 | kfree(tmp_bitmap); | 2444 | kfree(tmp_bitmap); |
| 2936 | *lenp -= left; | 2445 | *lenp -= left; |
| @@ -3008,6 +2517,3 @@ EXPORT_SYMBOL(proc_dointvec_ms_jiffies); | |||
| 3008 | EXPORT_SYMBOL(proc_dostring); | 2517 | EXPORT_SYMBOL(proc_dostring); |
| 3009 | EXPORT_SYMBOL(proc_doulongvec_minmax); | 2518 | EXPORT_SYMBOL(proc_doulongvec_minmax); |
| 3010 | EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); | 2519 | EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); |
| 3011 | EXPORT_SYMBOL(register_sysctl_table); | ||
| 3012 | EXPORT_SYMBOL(register_sysctl_paths); | ||
| 3013 | EXPORT_SYMBOL(unregister_sysctl_table); | ||
