From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 03/13] netfilter: ctnetlink: fix refcnt leak in dying/unconfirmed list dumper
Date: Wed, 18 Jun 2014 11:44:29 +0200 [thread overview]
Message-ID: <1403084679-11227-4-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1403084679-11227-1-git-send-email-pablo@netfilter.org>
From: Florian Westphal <fw@strlen.de>
'last' keeps track of the ct that had its refcnt bumped during previous
dump cycle. Thus it must not be overwritten until end-of-function.
Another (unrelated, theoretical) issue: Don't attempt to bump refcnt of a conntrack
whose reference count is already 0. Such conntrack is being destroyed
right now, its memory is freed once we release the percpu dying spinlock.
Fixes: b7779d06 ('netfilter: conntrack: spinlock per cpu to protect special lists.')
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
net/netfilter/nf_conntrack_netlink.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index ef0eedd..70123f4 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -1150,7 +1150,7 @@ static int ctnetlink_done_list(struct netlink_callback *cb)
static int
ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dying)
{
- struct nf_conn *ct, *last = NULL;
+ struct nf_conn *ct, *last;
struct nf_conntrack_tuple_hash *h;
struct hlist_nulls_node *n;
struct nfgenmsg *nfmsg = nlmsg_data(cb->nlh);
@@ -1163,6 +1163,8 @@ ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dying
if (cb->args[2])
return 0;
+ last = (struct nf_conn *)cb->args[1];
+
for (cpu = cb->args[0]; cpu < nr_cpu_ids; cpu++) {
struct ct_pcpu *pcpu;
@@ -1171,7 +1173,6 @@ ctnetlink_dump_list(struct sk_buff *skb, struct netlink_callback *cb, bool dying
pcpu = per_cpu_ptr(net->ct.pcpu_lists, cpu);
spin_lock_bh(&pcpu->lock);
- last = (struct nf_conn *)cb->args[1];
list = dying ? &pcpu->dying : &pcpu->unconfirmed;
restart:
hlist_nulls_for_each_entry(h, n, list, hnnode) {
@@ -1190,7 +1191,8 @@ restart:
ct);
rcu_read_unlock();
if (res < 0) {
- nf_conntrack_get(&ct->ct_general);
+ if (!atomic_inc_not_zero(&ct->ct_general.use))
+ continue;
cb->args[0] = cpu;
cb->args[1] = (unsigned long)ct;
spin_unlock_bh(&pcpu->lock);
--
1.7.10.4
next prev parent reply other threads:[~2014-06-18 9:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-18 9:44 [PATCH 00/13] netfilter fixes for net Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 01/13] ipvs: stop tot_stats estimator only under CONFIG_SYSCTL Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 02/13] netfilter: ctnetlink: fix dumping of dying/unconfirmed conntracks Pablo Neira Ayuso
2014-06-18 9:44 ` Pablo Neira Ayuso [this message]
2014-06-18 9:44 ` [PATCH 04/13] netfilter: nf_tables: use RCU-safe list insertion when replacing rules Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 05/13] netfilter: nf_tables: use u32 for chain use counter Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 06/13] netfilter: nf_tables: decrement chain use counter when replacing rules Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 07/13] netfilter: nf_tables: fix wrong type in transaction " Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 08/13] netfilter: nft_compat: call {target, match}->destroy() to cleanup entry Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 09/13] netfilter: nf_tables: indicate family when dumping set elements Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 10/13] netfilter: nft_nat: don't dump port information if unset Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 11/13] netfilter: ctnetlink: add zone size to length Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 12/13] netfilter: nf_nat: fix oops on netns removal Pablo Neira Ayuso
2014-06-18 9:44 ` [PATCH 13/13] MAINTAINERS: merge ebtables into netfilter entry Pablo Neira Ayuso
2014-06-18 23:10 ` [PATCH 00/13] 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=1403084679-11227-4-git-send-email-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).