Skip to content

Commit

Permalink
netfilter: nf_tables: take AF module reference when creating a table
Browse files Browse the repository at this point in the history
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: Patrick McHardy <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
kaber authored and ummakynes committed Jan 9, 2014
1 parent c5c1f97 commit 7047f9d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,14 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,
return -EINVAL;
}

if (!try_module_get(afi->owner))
return -EAFNOSUPPORT;

table = kzalloc(sizeof(*table) + nla_len(name), GFP_KERNEL);
if (table == NULL)
if (table == NULL) {
module_put(afi->owner);
return -ENOMEM;
}

nla_strlcpy(table->name, name, nla_len(name));
INIT_LIST_HEAD(&table->chains);
Expand Down Expand Up @@ -468,6 +473,7 @@ static int nf_tables_deltable(struct sock *nlsk, struct sk_buff *skb,
list_del(&table->list);
nf_tables_table_notify(skb, nlh, table, NFT_MSG_DELTABLE, family);
kfree(table);
module_put(afi->owner);
return 0;
}

Expand Down

0 comments on commit 7047f9d

Please sign in to comment.