Commit 7047f9d0 authored by Patrick McHardy's avatar Patrick McHardy Committed by Pablo Neira Ayuso

netfilter: nf_tables: take AF module reference when creating a table

The table refers to data of the AF module, so we need to make sure the
module isn't unloaded while the table exists.
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent c5c1f975
...@@ -430,9 +430,14 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb, ...@@ -430,9 +430,14 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,
return -EINVAL; return -EINVAL;
} }
if (!try_module_get(afi->owner))
return -EAFNOSUPPORT;
table = kzalloc(sizeof(*table) + nla_len(name), GFP_KERNEL); table = kzalloc(sizeof(*table) + nla_len(name), GFP_KERNEL);
if (table == NULL) if (table == NULL) {
module_put(afi->owner);
return -ENOMEM; return -ENOMEM;
}
nla_strlcpy(table->name, name, nla_len(name)); nla_strlcpy(table->name, name, nla_len(name));
INIT_LIST_HEAD(&table->chains); INIT_LIST_HEAD(&table->chains);
...@@ -468,6 +473,7 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb, ...@@ -468,6 +473,7 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,
list_del(&table->list); list_del(&table->list);
nf_tables_table_notify(skb, nlh, table, NFT_MSG_DELTABLE, family); nf_tables_table_notify(skb, nlh, table, NFT_MSG_DELTABLE, family);
kfree(table); kfree(table);
module_put(afi->owner);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment