Skip to content

Commit

Permalink
netfilter: nf_tables: perform flags validation before table allocation
Browse files Browse the repository at this point in the history
Simplifies error handling. Additionally use the correct type u32 for the
host byte order flags value.

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 fa2c1de commit c5c1f97
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ static int nf_tables_updtable(struct sock *nlsk, struct sk_buff *skb,
int family = nfmsg->nfgen_family, ret = 0;

if (nla[NFTA_TABLE_FLAGS]) {
__be32 flags;
u32 flags;

flags = ntohl(nla_get_be32(nla[NFTA_TABLE_FLAGS]));
if (flags & ~NFT_TABLE_F_DORMANT)
Expand Down Expand Up @@ -402,6 +402,7 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,
struct nft_table *table;
struct net *net = sock_net(skb->sk);
int family = nfmsg->nfgen_family;
u32 flags = 0;

afi = nf_tables_afinfo_lookup(net, family, true);
if (IS_ERR(afi))
Expand All @@ -423,25 +424,20 @@ static int nf_tables_newtable(struct sock *nlsk, struct sk_buff *skb,
return nf_tables_updtable(nlsk, skb, nlh, nla, afi, table);
}

if (nla[NFTA_TABLE_FLAGS]) {
flags = ntohl(nla_get_be32(nla[NFTA_TABLE_FLAGS]));
if (flags & ~NFT_TABLE_F_DORMANT)
return -EINVAL;
}

table = kzalloc(sizeof(*table) + nla_len(name), GFP_KERNEL);
if (table == NULL)
return -ENOMEM;

nla_strlcpy(table->name, name, nla_len(name));
INIT_LIST_HEAD(&table->chains);
INIT_LIST_HEAD(&table->sets);

if (nla[NFTA_TABLE_FLAGS]) {
__be32 flags;

flags = ntohl(nla_get_be32(nla[NFTA_TABLE_FLAGS]));
if (flags & ~NFT_TABLE_F_DORMANT) {
kfree(table);
return -EINVAL;
}

table->flags |= flags;
}
table->flags = flags;

list_add_tail(&table->list, &afi->tables);
nf_tables_table_notify(skb, nlh, table, NFT_MSG_NEWTABLE, family);
Expand Down

0 comments on commit c5c1f97

Please sign in to comment.