aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sysctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/sysctl.c')
-rw-r--r--kernel/sysctl.c181
1 files changed, 152 insertions, 29 deletions
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 8e96558cb8f3..4bc8e48434a7 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -157,8 +157,16 @@ static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *
157#endif 157#endif
158 158
159static struct ctl_table root_table[]; 159static struct ctl_table root_table[];
160static struct ctl_table_header root_table_header = 160static struct ctl_table_root sysctl_table_root;
161 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) }; 161static struct ctl_table_header root_table_header = {
162 .ctl_table = root_table,
163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
164 .root = &sysctl_table_root,
165};
166static struct ctl_table_root sysctl_table_root = {
167 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
168 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
169};
162 170
163static struct ctl_table kern_table[]; 171static struct ctl_table kern_table[];
164static struct ctl_table vm_table[]; 172static struct ctl_table vm_table[];
@@ -192,14 +200,6 @@ static struct ctl_table root_table[] = {
192 .mode = 0555, 200 .mode = 0555,
193 .child = vm_table, 201 .child = vm_table,
194 }, 202 },
195#ifdef CONFIG_NET
196 {
197 .ctl_name = CTL_NET,
198 .procname = "net",
199 .mode = 0555,
200 .child = net_table,
201 },
202#endif
203 { 203 {
204 .ctl_name = CTL_FS, 204 .ctl_name = CTL_FS,
205 .procname = "fs", 205 .procname = "fs",
@@ -1371,12 +1371,27 @@ void sysctl_head_finish(struct ctl_table_header *head)
1371 spin_unlock(&sysctl_lock); 1371 spin_unlock(&sysctl_lock);
1372} 1372}
1373 1373
1374struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) 1374static struct list_head *
1375lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1375{ 1376{
1377 struct list_head *header_list;
1378 header_list = &root->header_list;
1379 if (root->lookup)
1380 header_list = root->lookup(root, namespaces);
1381 return header_list;
1382}
1383
1384struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1385 struct ctl_table_header *prev)
1386{
1387 struct ctl_table_root *root;
1388 struct list_head *header_list;
1376 struct ctl_table_header *head; 1389 struct ctl_table_header *head;
1377 struct list_head *tmp; 1390 struct list_head *tmp;
1391
1378 spin_lock(&sysctl_lock); 1392 spin_lock(&sysctl_lock);
1379 if (prev) { 1393 if (prev) {
1394 head = prev;
1380 tmp = &prev->ctl_entry; 1395 tmp = &prev->ctl_entry;
1381 unuse_table(prev); 1396 unuse_table(prev);
1382 goto next; 1397 goto next;
@@ -1390,14 +1405,38 @@ struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1390 spin_unlock(&sysctl_lock); 1405 spin_unlock(&sysctl_lock);
1391 return head; 1406 return head;
1392 next: 1407 next:
1408 root = head->root;
1393 tmp = tmp->next; 1409 tmp = tmp->next;
1394 if (tmp == &root_table_header.ctl_entry) 1410 header_list = lookup_header_list(root, namespaces);
1395 break; 1411 if (tmp != header_list)
1412 continue;
1413
1414 do {
1415 root = list_entry(root->root_list.next,
1416 struct ctl_table_root, root_list);
1417 if (root == &sysctl_table_root)
1418 goto out;
1419 header_list = lookup_header_list(root, namespaces);
1420 } while (list_empty(header_list));
1421 tmp = header_list->next;
1396 } 1422 }
1423out:
1397 spin_unlock(&sysctl_lock); 1424 spin_unlock(&sysctl_lock);
1398 return NULL; 1425 return NULL;
1399} 1426}
1400 1427
1428struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1429{
1430 return __sysctl_head_next(current->nsproxy, prev);
1431}
1432
1433void register_sysctl_root(struct ctl_table_root *root)
1434{
1435 spin_lock(&sysctl_lock);
1436 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1437 spin_unlock(&sysctl_lock);
1438}
1439
1401#ifdef CONFIG_SYSCTL_SYSCALL 1440#ifdef CONFIG_SYSCTL_SYSCALL
1402int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, 1441int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1403 void __user *newval, size_t newlen) 1442 void __user *newval, size_t newlen)
@@ -1554,18 +1593,21 @@ static __init int sysctl_init(void)
1554{ 1593{
1555 int err; 1594 int err;
1556 sysctl_set_parent(NULL, root_table); 1595 sysctl_set_parent(NULL, root_table);
1557 err = sysctl_check_table(root_table); 1596 err = sysctl_check_table(current->nsproxy, root_table);
1558 return 0; 1597 return 0;
1559} 1598}
1560 1599
1561core_initcall(sysctl_init); 1600core_initcall(sysctl_init);
1562 1601
1563/** 1602/**
1564 * register_sysctl_table - register a sysctl hierarchy 1603 * __register_sysctl_paths - register a sysctl hierarchy
1604 * @root: List of sysctl headers to register on
1605 * @namespaces: Data to compute which lists of sysctl entries are visible
1606 * @path: The path to the directory the sysctl table is in.
1565 * @table: the top-level table structure 1607 * @table: the top-level table structure
1566 * 1608 *
1567 * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1609 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1568 * array. An entry with a ctl_name of 0 terminates the table. 1610 * array. A completely 0 filled entry terminates the table.
1569 * 1611 *
1570 * The members of the &struct ctl_table structure are used as follows: 1612 * The members of the &struct ctl_table structure are used as follows:
1571 * 1613 *
@@ -1628,25 +1670,99 @@ core_initcall(sysctl_init);
1628 * This routine returns %NULL on a failure to register, and a pointer 1670 * This routine returns %NULL on a failure to register, and a pointer
1629 * to the table header on success. 1671 * to the table header on success.
1630 */ 1672 */
1631struct ctl_table_header *register_sysctl_table(struct ctl_table * table) 1673struct ctl_table_header *__register_sysctl_paths(
1674 struct ctl_table_root *root,
1675 struct nsproxy *namespaces,
1676 const struct ctl_path *path, struct ctl_table *table)
1632{ 1677{
1633 struct ctl_table_header *tmp; 1678 struct list_head *header_list;
1634 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL); 1679 struct ctl_table_header *header;
1635 if (!tmp) 1680 struct ctl_table *new, **prevp;
1681 unsigned int n, npath;
1682
1683 /* Count the path components */
1684 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1685 ;
1686
1687 /*
1688 * For each path component, allocate a 2-element ctl_table array.
1689 * The first array element will be filled with the sysctl entry
1690 * for this, the second will be the sentinel (ctl_name == 0).
1691 *
1692 * We allocate everything in one go so that we don't have to
1693 * worry about freeing additional memory in unregister_sysctl_table.
1694 */
1695 header = kzalloc(sizeof(struct ctl_table_header) +
1696 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1697 if (!header)
1636 return NULL; 1698 return NULL;
1637 tmp->ctl_table = table; 1699
1638 INIT_LIST_HEAD(&tmp->ctl_entry); 1700 new = (struct ctl_table *) (header + 1);
1639 tmp->used = 0; 1701
1640 tmp->unregistering = NULL; 1702 /* Now connect the dots */
1641 sysctl_set_parent(NULL, table); 1703 prevp = &header->ctl_table;
1642 if (sysctl_check_table(tmp->ctl_table)) { 1704 for (n = 0; n < npath; ++n, ++path) {
1643 kfree(tmp); 1705 /* Copy the procname */
1706 new->procname = path->procname;
1707 new->ctl_name = path->ctl_name;
1708 new->mode = 0555;
1709
1710 *prevp = new;
1711 prevp = &new->child;
1712
1713 new += 2;
1714 }
1715 *prevp = table;
1716 header->ctl_table_arg = table;
1717
1718 INIT_LIST_HEAD(&header->ctl_entry);
1719 header->used = 0;
1720 header->unregistering = NULL;
1721 header->root = root;
1722 sysctl_set_parent(NULL, header->ctl_table);
1723 if (sysctl_check_table(namespaces, header->ctl_table)) {
1724 kfree(header);
1644 return NULL; 1725 return NULL;
1645 } 1726 }
1646 spin_lock(&sysctl_lock); 1727 spin_lock(&sysctl_lock);
1647 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry); 1728 header_list = lookup_header_list(root, namespaces);
1729 list_add_tail(&header->ctl_entry, header_list);
1648 spin_unlock(&sysctl_lock); 1730 spin_unlock(&sysctl_lock);
1649 return tmp; 1731
1732 return header;
1733}
1734
1735/**
1736 * register_sysctl_table_path - register a sysctl table hierarchy
1737 * @path: The path to the directory the sysctl table is in.
1738 * @table: the top-level table structure
1739 *
1740 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1741 * array. A completely 0 filled entry terminates the table.
1742 *
1743 * See __register_sysctl_paths for more details.
1744 */
1745struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1746 struct ctl_table *table)
1747{
1748 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1749 path, table);
1750}
1751
1752/**
1753 * register_sysctl_table - register a sysctl table hierarchy
1754 * @table: the top-level table structure
1755 *
1756 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1757 * array. A completely 0 filled entry terminates the table.
1758 *
1759 * See register_sysctl_paths for more details.
1760 */
1761struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1762{
1763 static const struct ctl_path null_path[] = { {} };
1764
1765 return register_sysctl_paths(null_path, table);
1650} 1766}
1651 1767
1652/** 1768/**
@@ -1675,6 +1791,12 @@ struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1675 return NULL; 1791 return NULL;
1676} 1792}
1677 1793
1794struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1795 struct ctl_table *table)
1796{
1797 return NULL;
1798}
1799
1678void unregister_sysctl_table(struct ctl_table_header * table) 1800void unregister_sysctl_table(struct ctl_table_header * table)
1679{ 1801{
1680} 1802}
@@ -2733,6 +2855,7 @@ EXPORT_SYMBOL(proc_dostring);
2733EXPORT_SYMBOL(proc_doulongvec_minmax); 2855EXPORT_SYMBOL(proc_doulongvec_minmax);
2734EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 2856EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2735EXPORT_SYMBOL(register_sysctl_table); 2857EXPORT_SYMBOL(register_sysctl_table);
2858EXPORT_SYMBOL(register_sysctl_paths);
2736EXPORT_SYMBOL(sysctl_intvec); 2859EXPORT_SYMBOL(sysctl_intvec);
2737EXPORT_SYMBOL(sysctl_jiffies); 2860EXPORT_SYMBOL(sysctl_jiffies);
2738EXPORT_SYMBOL(sysctl_ms_jiffies); 2861EXPORT_SYMBOL(sysctl_ms_jiffies);