OSDN Git Service

netfilter: nf_tables: fix *leak* when expr clone fail
authorLiping Zhang <zlpnobody@gmail.com>
Sat, 22 Oct 2016 10:51:25 +0000 (18:51 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 27 Oct 2016 16:20:45 +0000 (18:20 +0200)
commit61f9e2924f4981d626b3a931fed935f2fa3cb4de
tree77d9f1c293690b43f9d858294e3164b464edd5fa
parentbb6a6e8e091353770074608c1d1bfde0e20b8154
netfilter: nf_tables: fix *leak* when expr clone fail

When nft_expr_clone failed, a series of problems will happen:

1. module refcnt will leak, we call __module_get at the beginning but
   we forget to put it back if ops->clone returns fail
2. memory will be leaked, if clone fail, we just return NULL and forget
   to free the alloced element
3. set->nelems will become incorrect when set->size is specified. If
   clone fail, we should decrease the set->nelems

Now this patch fixes these problems. And fortunately, clone fail will
only happen on counter expression when memory is exhausted.

Fixes: 086f332167d6 ("netfilter: nf_tables: add clone interface to expression operations")
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netfilter/nf_tables.h
net/netfilter/nf_tables_api.c
net/netfilter/nft_dynset.c
net/netfilter/nft_set_hash.c
net/netfilter/nft_set_rbtree.c