netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 2/7] netfilter: nf_tables: fix leaking object reference count
Date: Mon, 14 Jan 2019 22:29:35 +0100	[thread overview]
Message-ID: <20190114212940.5704-3-pablo@netfilter.org> (raw)
In-Reply-To: <20190114212940.5704-1-pablo@netfilter.org>

From: Taehee Yoo <ap420073@gmail.com>

There is no code that decreases the reference count of stateful objects
in error path of the nft_add_set_elem(). this causes a leak of reference
count of stateful objects.

Test commands:
   $nft add table ip filter
   $nft add counter ip filter c1
   $nft add map ip filter m1 { type ipv4_addr : counter \;}
   $nft add element ip filter m1 { 1 : c1 }
   $nft add element ip filter m1 { 1 : c1 }
   $nft delete element ip filter m1 { 1 }
   $nft delete counter ip filter c1

Result:
   Error: Could not process rule: Device or resource busy
   delete counter ip filter c1
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

At the second 'nft add element ip filter m1 { 1 : c1 }', the reference
count of the 'c1' is increased then it tries to insert into the 'm1'. but
the 'm1' already has same element so it returns -EEXIST.
But it doesn't decrease the reference count of the 'c1' in the error path.
Due to a leak of the reference count of the 'c1', the 'c1' can't be
removed by 'nft delete counter ip filter c1'.

Fixes: 8aeff920dcc9 ("netfilter: nf_tables: add stateful object reference to set elements")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nf_tables_api.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index e3ddd8e95e58..dcea979423bc 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -4506,6 +4506,8 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
 err5:
 	kfree(trans);
 err4:
+	if (obj)
+		obj->use--;
 	kfree(elem.priv);
 err3:
 	if (nla[NFTA_SET_ELEM_DATA] != NULL)
-- 
2.11.0

  parent reply	other threads:[~2019-01-14 21:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-14 21:29 [PATCH 0/7] Netfilter fixes for net Pablo Neira Ayuso
2019-01-14 21:29 ` [PATCH 1/7] netfilter: nf_tables: Fix for endless loop when dumping ruleset Pablo Neira Ayuso
2019-01-14 21:29 ` Pablo Neira Ayuso [this message]
2019-01-14 21:29 ` [PATCH 3/7] netfilter: nf_tables: selective rule dump needs table to be specified Pablo Neira Ayuso
2019-01-14 21:29 ` [PATCH 4/7] netfilter: nft_flow_offload: Fix reverse route lookup Pablo Neira Ayuso
2019-01-14 21:29 ` [PATCH 5/7] netfilter: ebtables: account ebt_table_info to kmemcg Pablo Neira Ayuso
2019-01-14 21:29 ` [PATCH 6/7] netfilter: nft_flow_offload: fix interaction with vrf slave device Pablo Neira Ayuso
2019-01-14 21:29 ` [PATCH 7/7] netfilter: nft_flow_offload: fix checking method of conntrack helper Pablo Neira Ayuso
2019-01-15 21:32 ` [PATCH 0/7] Netfilter fixes for net David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190114212940.5704-3-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).