netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 2/2 v2] netfilter: nf_tables: fix oops when using gotos
Date: Fri, 7 Feb 2014 16:34:33 +0000	[thread overview]
Message-ID: <20140207163432.GB24391@macbook.localnet> (raw)
In-Reply-To: <1391790598-5390-2-git-send-email-pablo@netfilter.org>

On Fri, Feb 07, 2014 at 05:29:58PM +0100, Pablo Neira Ayuso wrote:
> Fix an oops if you use the "goto" operation, you will end up in
> non-base chain with no counters and no default policy.
> 
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
> v2: recover inline to nft_chain_stats.
> 
>  net/netfilter/nf_tables_core.c |   11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/net/netfilter/nf_tables_core.c b/net/netfilter/nf_tables_core.c
> index 0d879fc..13fecde 100644
> --- a/net/netfilter/nf_tables_core.c
> +++ b/net/netfilter/nf_tables_core.c
> @@ -67,18 +67,24 @@ struct nft_jumpstack {
>  	int			rulenum;
>  };
>  
> -static inline void
> +static inline int
>  nft_chain_stats(const struct nft_chain *this, const struct nft_pktinfo *pkt,
>  		struct nft_jumpstack *jumpstack, unsigned int stackptr)
>  {
>  	struct nft_stats __percpu *stats;
>  	const struct nft_chain *chain = stackptr ? jumpstack[0].chain : this;
>  
> +	/* You can reach this through goto chain */
> +	if (!(chain->flags & NFT_BASE_CHAIN))
> +		return NF_ACCEPT;
> +
>  	rcu_read_lock_bh();
>  	stats = rcu_dereference(nft_base_chain(chain)->stats);
>  	__this_cpu_inc(stats->pkts);
>  	__this_cpu_add(stats->bytes, pkt->skb->len);
>  	rcu_read_unlock_bh();
> +
> +	return nft_base_chain(chain)->policy;
>  }
>  
>  enum nft_trace {
> @@ -209,12 +215,11 @@ next_rule:
>  		rulenum = jumpstack[stackptr].rulenum;
>  		goto next_rule;
>  	}
> -	nft_chain_stats(chain, pkt, jumpstack, stackptr);
>  
>  	if (unlikely(pkt->skb->nf_trace))
>  		nft_trace_packet(pkt, chain, ++rulenum, NFT_TRACE_POLICY);
>  
> -	return nft_base_chain(chain)->policy;
> +	return nft_chain_stats(chain, pkt, jumpstack, stackptr);

I think we should just inline the function manually, it doesn't help
readability to have it take care of goto-specific cases and handle
verdicts/policies.

Also, what about NFT_TRACE_POLICY for the goto case? Should be generate
a message even through there is no policy?

      reply	other threads:[~2014-02-07 16:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-07 16:29 [PATCH 1/2 v2] netfilter: nf_tables: fix loop checking with end interval elements Pablo Neira Ayuso
2014-02-07 16:29 ` [PATCH 2/2 v2] netfilter: nf_tables: fix oops when using gotos Pablo Neira Ayuso
2014-02-07 16:34   ` Patrick McHardy [this message]

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=20140207163432.GB24391@macbook.localnet \
    --to=kaber@trash.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).