diff options
author | Akinobu Mita <mita@miraclelinux.com> | 2006-08-29 05:15:24 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-08-30 00:22:18 -0400 |
commit | fab2caf62ed03d83bd3a3598b859c3c345a8e8b5 (patch) | |
tree | b72cbc8e158fe6d7f71f21d3007a47eba41123b3 /net | |
parent | 3fdf3f0c99e90e167f0d0643fcc8739e27456697 (diff) |
[NETLINK]: Call panic if nl_table allocation fails
This patch makes crash happen if initialization of nl_table fails
in initcalls. It is better than getting use after free crash later.
Signed-off-by: Akinobu Mita <mita@miraclelinux.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/netlink/af_netlink.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index b85c1f9f1288..8b85036ba8e3 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c | |||
@@ -1273,8 +1273,7 @@ netlink_kernel_create(int unit, unsigned int groups, | |||
1273 | struct netlink_sock *nlk; | 1273 | struct netlink_sock *nlk; |
1274 | unsigned long *listeners = NULL; | 1274 | unsigned long *listeners = NULL; |
1275 | 1275 | ||
1276 | if (!nl_table) | 1276 | BUG_ON(!nl_table); |
1277 | return NULL; | ||
1278 | 1277 | ||
1279 | if (unit<0 || unit>=MAX_LINKS) | 1278 | if (unit<0 || unit>=MAX_LINKS) |
1280 | return NULL; | 1279 | return NULL; |
@@ -1745,11 +1744,8 @@ static int __init netlink_proto_init(void) | |||
1745 | netlink_skb_parms_too_large(); | 1744 | netlink_skb_parms_too_large(); |
1746 | 1745 | ||
1747 | nl_table = kcalloc(MAX_LINKS, sizeof(*nl_table), GFP_KERNEL); | 1746 | nl_table = kcalloc(MAX_LINKS, sizeof(*nl_table), GFP_KERNEL); |
1748 | if (!nl_table) { | 1747 | if (!nl_table) |
1749 | enomem: | 1748 | goto panic; |
1750 | printk(KERN_CRIT "netlink_init: Cannot allocate nl_table\n"); | ||
1751 | return -ENOMEM; | ||
1752 | } | ||
1753 | 1749 | ||
1754 | if (num_physpages >= (128 * 1024)) | 1750 | if (num_physpages >= (128 * 1024)) |
1755 | max = num_physpages >> (21 - PAGE_SHIFT); | 1751 | max = num_physpages >> (21 - PAGE_SHIFT); |
@@ -1769,7 +1765,7 @@ enomem: | |||
1769 | nl_pid_hash_free(nl_table[i].hash.table, | 1765 | nl_pid_hash_free(nl_table[i].hash.table, |
1770 | 1 * sizeof(*hash->table)); | 1766 | 1 * sizeof(*hash->table)); |
1771 | kfree(nl_table); | 1767 | kfree(nl_table); |
1772 | goto enomem; | 1768 | goto panic; |
1773 | } | 1769 | } |
1774 | memset(hash->table, 0, 1 * sizeof(*hash->table)); | 1770 | memset(hash->table, 0, 1 * sizeof(*hash->table)); |
1775 | hash->max_shift = order; | 1771 | hash->max_shift = order; |
@@ -1786,6 +1782,8 @@ enomem: | |||
1786 | rtnetlink_init(); | 1782 | rtnetlink_init(); |
1787 | out: | 1783 | out: |
1788 | return err; | 1784 | return err; |
1785 | panic: | ||
1786 | panic("netlink_init: Cannot allocate nl_table\n"); | ||
1789 | } | 1787 | } |
1790 | 1788 | ||
1791 | core_initcall(netlink_proto_init); | 1789 | core_initcall(netlink_proto_init); |