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: Thomas Graf <tgraf@suug.ch>,
	bart.de.schuymer@pandora.be, kaber@trash.net,
	kadlec@blackhole.kfki.hu, stephen@networkplumber.org,
	netfilter-devel@vger.kernel.org, Florian Westphal <fw@strlen.de>
Subject: Re: [PATCH] netfilter: Can't fail and free after table replacement
Date: Fri, 4 Apr 2014 00:08:26 +0200	[thread overview]
Message-ID: <20140403220826.GC6769@breakpoint.cc> (raw)
In-Reply-To: <20140403213757.GA3834@localhost>

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Wed, Apr 02, 2014 at 05:35:13PM +0200, Thomas Graf wrote:
> > All xtables variants suffer from the defect that the copy_to_user()
> > to copy the counters to user memory may fail after the table has
> > already been exchanged and thus exposed. Return an error at this
> > point will result in freeing the already exposed table. Any
> > subsequent packet processing will result in a kernel panic.
> > 
> > We can't copy the counters before exposing the new tables as we
> > want provide the counter state after the old table has been
> > unhooked. Therefore convert this into a silent error.
> > 
> > Cc: Florian Westphal <fw@strlen.de>
> > Signed-off-by: Thomas Graf <tgraf@suug.ch>
> > ---
> >  net/bridge/netfilter/ebtables.c | 4 +---
> >  net/ipv4/netfilter/arp_tables.c | 5 +++--
> >  net/ipv4/netfilter/ip_tables.c  | 5 +++--
> >  net/ipv6/netfilter/ip6_tables.c | 5 +++--
> >  4 files changed, 10 insertions(+), 9 deletions(-)
> > 
> > diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
> > index 0e474b1..7a3dc98 100644
> > --- a/net/bridge/netfilter/ebtables.c
> > +++ b/net/bridge/netfilter/ebtables.c
> > @@ -1044,10 +1044,8 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,
> >  	if (repl->num_counters &&
> >  	   copy_to_user(repl->counters, counterstmp,
> >  	   repl->num_counters * sizeof(struct ebt_counter))) {
> > -		ret = -EFAULT;
> > +		/* Silent error, can't fail, new table is already in place */
> >  	}
> > -	else
> > -		ret = 0;
> >  
> 
> This seems good to me.
> 
> Perhaps we can spot a warning like in rtnetlink to inform the user
> that counters are not reliable anymore?

you mean net_warn_ratelimit() ?

Sure, can be added.

However given that this bug has been around for 9 years I don't think
its really needed, if it fails kernel panic'd, so its safe to say
that the counters are reliable ;)

With vanilla iptables this only fails if the userspace buffer was
swapped out and could not be paged back in due to OOM.

  reply	other threads:[~2014-04-03 22:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-02 15:35 [PATCH] netfilter: Can't fail and free after table replacement Thomas Graf
2014-04-03 21:37 ` Pablo Neira Ayuso
2014-04-03 22:08   ` Florian Westphal [this message]
2014-04-04  8:13     ` 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=20140403220826.GC6769@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=bart.de.schuymer@pandora.be \
    --cc=kaber@trash.net \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=stephen@networkplumber.org \
    --cc=tgraf@suug.ch \
    /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).