netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Ehrhardt <christian.ehrhardt@canonical.com>
To: netfilter-devel@vger.kernel.org
Cc: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Subject: [RFC 1/1] nft: abort cache creation if mnl_genid_get fails
Date: Wed, 21 Aug 2019 09:56:11 +0200	[thread overview]
Message-ID: <20190821075611.30918-2-christian.ehrhardt@canonical.com> (raw)
In-Reply-To: <20190821075611.30918-1-christian.ehrhardt@canonical.com>

mnl_genid_get can fail and in this case not update the genid which leads
to a busy loop that never recovers.

To avoid that check the return value and abort __nft_build_cache
if mnl_genid_get fails.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
---
 iptables/nft.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/iptables/nft.c b/iptables/nft.c
index ae3740be..c9b7edbb 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -1597,11 +1597,13 @@ static void __nft_build_cache(struct nft_handle *h)
 	uint32_t genid_start, genid_stop;
 
 retry:
-	mnl_genid_get(h, &genid_start);
+	if (mnl_genid_get(h, &genid_start) == -1)
+		goto fatal;
 	fetch_chain_cache(h);
 	fetch_rule_cache(h);
 	h->have_cache = true;
-	mnl_genid_get(h, &genid_stop);
+	if (mnl_genid_get(h, &genid_stop) == -1)
+		goto fatal;
 
 	if (genid_start != genid_stop) {
 		flush_chain_cache(h, NULL);
@@ -1609,6 +1611,10 @@ retry:
 	}
 
 	h->nft_genid = genid_start;
+
+fatal:
+	flush_chain_cache(h, NULL);
+	h->have_cache = false;
 }
 
 void nft_build_cache(struct nft_handle *h)
@@ -1651,6 +1657,8 @@ struct nftnl_chain_list *nft_chain_list_get(struct nft_handle *h,
 		return NULL;
 
 	nft_build_cache(h);
+	if (!h->have_cache)
+		return NULL;
 
 	return h->cache->table[t->type].chains;
 }
@@ -2047,6 +2055,8 @@ int nft_chain_user_rename(struct nft_handle *h,const char *chain,
 static struct nftnl_table_list *nftnl_table_list_get(struct nft_handle *h)
 {
 	nft_build_cache(h);
+	if (!h->have_cache)
+		return NULL;
 
 	return h->cache->tables;
 }
-- 
2.22.0


  reply	other threads:[~2019-08-21  7:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21  7:56 [RFC 0/1] avoid busy loop in __nft_build_cache Christian Ehrhardt
2019-08-21  7:56 ` Christian Ehrhardt [this message]
2019-08-21 11:13   ` [RFC 1/1] nft: abort cache creation if mnl_genid_get fails Florian Westphal
2019-08-21 12:56     ` Christian Ehrhardt

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=20190821075611.30918-2-christian.ehrhardt@canonical.com \
    --to=christian.ehrhardt@canonical.com \
    --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).