netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH 1/4] nft: cache: Avoid double free of unrecognized base-chains
Date: Wed, 22 Sep 2021 18:06:29 +0200	[thread overview]
Message-ID: <20210922160632.15635-2-phil@nwl.cc> (raw)
In-Reply-To: <20210922160632.15635-1-phil@nwl.cc>

On error, nft_cache_add_chain() frees the allocated nft_chain object
along with the nftnl_chain it points at. Fix nftnl_chain_list_cb() to
not free the nftnl_chain again in that case.

Fixes: 176c92c26bfc9 ("nft: Introduce a dedicated base chain array")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 iptables/nft-cache.c                          |  4 +--
 .../shell/testcases/chain/0004extra-base_0    | 27 +++++++++++++++++++
 2 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100755 iptables/tests/shell/testcases/chain/0004extra-base_0

diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c
index 2c88301cc7445..9a03bbfbb32bb 100644
--- a/iptables/nft-cache.c
+++ b/iptables/nft-cache.c
@@ -314,9 +314,7 @@ static int nftnl_chain_list_cb(const struct nlmsghdr *nlh, void *data)
 		goto out;
 	}
 
-	if (nft_cache_add_chain(h, t, c))
-		goto out;
-
+	nft_cache_add_chain(h, t, c);
 	return MNL_CB_OK;
 out:
 	nftnl_chain_free(c);
diff --git a/iptables/tests/shell/testcases/chain/0004extra-base_0 b/iptables/tests/shell/testcases/chain/0004extra-base_0
new file mode 100755
index 0000000000000..1b85b060c1487
--- /dev/null
+++ b/iptables/tests/shell/testcases/chain/0004extra-base_0
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+case $XT_MULTI in
+*xtables-nft-multi)
+	;;
+*)
+	echo skip $XT_MULTI
+	exit 0
+	;;
+esac
+
+set -e
+
+nft -f - <<EOF
+table ip filter {
+        chain INPUT {
+                type filter hook input priority filter
+                counter packets 218 bytes 91375 accept
+        }
+
+        chain x {
+                type filter hook input priority filter
+        }
+}
+EOF
+
+$XT_MULTI iptables -L
-- 
2.33.0


  reply	other threads:[~2021-09-22 16:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22 16:06 [iptables PATCH 0/4] nft: Fix and improve base chain handling Phil Sutter
2021-09-22 16:06 ` Phil Sutter [this message]
2021-09-22 16:06 ` [iptables PATCH 2/4] nft: Check base-chain compatibility when adding to cache Phil Sutter
2021-09-22 16:06 ` [iptables PATCH 3/4] nft-chain: Introduce base_slot field Phil Sutter
2021-09-22 16:06 ` [iptables PATCH 4/4] nft: Delete builtin chains compatibly Phil Sutter
2021-09-27  7:32   ` Florian Westphal

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=20210922160632.15635-2-phil@nwl.cc \
    --to=phil@nwl.cc \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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).