netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: Florian Westphal <fw@strlen.de>,
	netfilter-devel@vger.kernel.org, kfm@plushkava.net
Subject: Re: [PATCH nf] netfilter: nf_tables: fix set double-free in abort path
Date: Fri, 8 Mar 2019 11:22:17 +0100	[thread overview]
Message-ID: <20190308102217.ty3x6bncjucqcczi@breakpoint.cc> (raw)
In-Reply-To: <20190308003415.i5kkbpferkhae3rm@salvia>

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> So the problem is only the use-after-free from the NEWSETELEM abort
> path, right?

That and the double-freeing of the set.

> Probably we can fix this problem with this patch too? Idea is to keep
> this 'bound' internal flag, in that case, this turns the NEWSET and
> NEWSETELEM abort path into noop.

Good idea, but your patch still causes UAF.

> @@ -6617,10 +6617,13 @@ static void nf_tables_abort_release(struct nft_trans *trans)
>  		nf_tables_rule_destroy(&trans->ctx, nft_trans_rule(trans));
>  		break;
>  	case NFT_MSG_NEWSET:
> -		if (!nft_trans_set_bound(trans))
> -			nft_set_destroy(nft_trans_set(trans));
> +		if (nft_trans_set(trans)->bound)
> +			break;
> +		nft_set_destroy(nft_trans_set(trans));

Its not safe to use nft_trans_set() here anymore, as the set
has already been released by nf_tables_rule_destroy().

>  	case NFT_MSG_NEWSETELEM:
> +		if (nft_trans_elem_set(trans)->bound)
> +			break;

Same here.

Either the transactions themselves need to be yanked here, before
nf_tables_abort_release() is run, or the 'bound' flag needs to be
stored in the transaction struct.

I'd guess nft_trans_delete() is enough instead of plain break,
in case the set is bound we know expr destructor removes the set,
and if we avoid removal of the elements then those are removed too
when the set is destroyed.

This seems to make things work for me, on top of your patch:

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -6786,8 +6786,10 @@ static int __nf_tables_abort(struct net *net)
 			break;
 		case NFT_MSG_NEWSET:
 			trans->ctx.table->use--;
-			if (nft_trans_set(trans)->bound)
+			if (nft_trans_set(trans)->bound) {
+				nft_trans_destroy(trans);
 				break;
+			}
 			list_del_rcu(&nft_trans_set(trans)->list);
 			break;
 		case NFT_MSG_DELSET:
@@ -6796,8 +6798,10 @@ static int __nf_tables_abort(struct net *net)
 			nft_trans_destroy(trans);
 			break;
 		case NFT_MSG_NEWSETELEM:
-			if (nft_trans_elem_set(trans)->bound)
+			if (nft_trans_elem_set(trans)->bound) {
+				nft_trans_destroy(trans);
 				break;
+			}
 			te = (struct nft_trans_elem *)trans->data;
 			te->set->ops->remove(net, te->set, &te->elem);
 			atomic_dec(&te->set->nelems);

  reply	other threads:[~2019-03-08 10:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-07 19:30 [PATCH nf] netfilter: nf_tables: fix set double-free in abort path Florian Westphal
2019-03-07 22:13 ` kfm
2019-03-08  0:34 ` Pablo Neira Ayuso
2019-03-08 10:22   ` Florian Westphal [this message]
2019-03-08 11:03     ` 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=20190308102217.ty3x6bncjucqcczi@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=kfm@plushkava.net \
    --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).