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, kuba@kernel.org
Subject: [PATCH net 2/8] netfilter: nft_ct: fix use after free when attaching zone template
Date: Fri, 28 Jan 2022 00:52:29 +0100	[thread overview]
Message-ID: <20220127235235.656931-3-pablo@netfilter.org> (raw)
In-Reply-To: <20220127235235.656931-1-pablo@netfilter.org>

From: Florian Westphal <fw@strlen.de>

The conversion erroneously removed the refcount increment.
In case we can use the percpu template, we need to increment
the refcount, else it will be released when the skb gets freed.

In case the slowpath is taken, the new template already has a
refcount of 1.

Fixes: 719774377622 ("netfilter: conntrack: convert to refcount_t api")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/nft_ct.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index 518d96c8c247..5adf8bb628a8 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -260,9 +260,12 @@ static void nft_ct_set_zone_eval(const struct nft_expr *expr,
 	ct = this_cpu_read(nft_ct_pcpu_template);
 
 	if (likely(refcount_read(&ct->ct_general.use) == 1)) {
+		refcount_inc(&ct->ct_general.use);
 		nf_ct_zone_add(ct, &zone);
 	} else {
-		/* previous skb got queued to userspace */
+		/* previous skb got queued to userspace, allocate temporary
+		 * one until percpu template can be reused.
+		 */
 		ct = nf_ct_tmpl_alloc(nft_net(pkt), &zone, GFP_ATOMIC);
 		if (!ct) {
 			regs->verdict.code = NF_DROP;
-- 
2.30.2


  parent reply	other threads:[~2022-01-27 23:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27 23:52 [PATCH net 0/8] Netfilter fixes for net Pablo Neira Ayuso
2022-01-27 23:52 ` [PATCH net 1/8] netfilter: Remove flowtable relics Pablo Neira Ayuso
2022-01-28  3:00   ` patchwork-bot+netdevbpf
2022-01-27 23:52 ` Pablo Neira Ayuso [this message]
2022-01-27 23:52 ` [PATCH net 3/8] selftests: netfilter: reduce zone stress test running time Pablo Neira Ayuso
2022-01-27 23:52 ` [PATCH net 4/8] selftests: netfilter: check stateless nat udp checksum fixup Pablo Neira Ayuso
2022-01-27 23:52 ` [PATCH net 5/8] netfilter: nft_reject_bridge: Fix for missing reply from prerouting Pablo Neira Ayuso
2022-01-27 23:52 ` [PATCH net 6/8] netfilter: nft_byteorder: track register operations Pablo Neira Ayuso
2022-01-27 23:52 ` [PATCH net 7/8] selftests: nft_concat_range: add test for reload with no element add/del Pablo Neira Ayuso
2022-01-27 23:52 ` [PATCH net 8/8] netfilter: nf_tables: remove assignment with no effect in chain blob builder Pablo Neira Ayuso

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=20220127235235.656931-3-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --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).