Skip to content

Commit

Permalink
netfilter: nf_tables: fix potential oops when dumping sets
Browse files Browse the repository at this point in the history
Commit c9c8e48 (netfilter: nf_tables: dump sets in all existing families)
changed nft_ctx_init_from_setattr() to only look up the address family if it
is not NFPROTO_UNSPEC. However if it is NFPROTO_UNSPEC and a table attribute
is given, nftables_afinfo_lookup() will dereference the NULL afi pointer.

Fix by checking for non-NULL afi and also move a check added by that commit
to the proper position.

Signed-off-by: Patrick McHardy <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
kaber authored and ummakynes committed Feb 5, 2014
1 parent 53b7028 commit ec2c993
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions net/netfilter/nf_tables_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,9 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx,
}

if (nla[NFTA_SET_TABLE] != NULL) {
if (afi == NULL)
return -EAFNOSUPPORT;

table = nf_tables_table_lookup(afi, nla[NFTA_SET_TABLE]);
if (IS_ERR(table))
return PTR_ERR(table);
Expand Down Expand Up @@ -2428,16 +2431,15 @@ static int nf_tables_delset(struct sock *nlsk, struct sk_buff *skb,
struct nft_ctx ctx;
int err;

if (nfmsg->nfgen_family == NFPROTO_UNSPEC)
return -EAFNOSUPPORT;
if (nla[NFTA_SET_TABLE] == NULL)
return -EINVAL;

err = nft_ctx_init_from_setattr(&ctx, skb, nlh, nla);
if (err < 0)
return err;

if (nfmsg->nfgen_family == NFPROTO_UNSPEC)
return -EAFNOSUPPORT;

set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_NAME]);
if (IS_ERR(set))
return PTR_ERR(set);
Expand Down

0 comments on commit ec2c993

Please sign in to comment.