From: Florian Westphal <fw@strlen.de>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Florian Westphal <fw@strlen.de>,
Pablo Neira Ayuso <pablo@netfilter.org>,
netfilter-devel@vger.kernel.org, dale.4d@gmail.com,
netdev@vger.kernel.org
Subject: Re: [PATCH nf V2] netfilter: fix oops in nfqueue during netns error unwinding
Date: Fri, 13 May 2016 22:04:42 +0200 [thread overview]
Message-ID: <20160513200442.GA29941@breakpoint.cc> (raw)
In-Reply-To: <87a8jtrbk3.fsf@x220.int.ebiederm.org>
Eric W. Biederman <ebiederm@xmission.com> wrote:
> > AFAICS no other callers do something similar, but yes,
> > we'd need this all over the place if there are others.
> >
> > Maybe we need a saner fix, e.g. by adding bounds check to net_generic(),
> > and making sure that net_generic() returns non-NULL only if the per
> > netns memory was allocated properly.
>
> As a first approximiation I am thinking we should fix by making
> nf_queue_register_handler a per netns operation.
We can do that but then we'd end up storing the very same address
for each namespace which I think isn't nice either.
> Either that or give nfnetlink_queue it's own dedicated place in
> struct net for struct nfnl_queue_net.
That would work too, but then I don't see why that is preferrable
to this proposed patch. We could add a helper for this so that
we have something like
static bool netns_was_inited(const struct net *n)
{
return net->list.next != NULL;
}
Another alternative is this patch (not even compile tested, just to
illustrate the idea):
diff --git a/include/net/netns/generic.h b/include/net/netns/generic.h
--- a/include/net/netns/generic.h
+++ b/include/net/netns/generic.h
@@ -38,7 +38,11 @@ static inline void *net_generic(const struct net *net, int id)
rcu_read_lock();
ng = rcu_dereference(net->gen);
- ptr = ng->ptr[id - 1];
+
+ if (ng->len < id)
+ ptr = ng->ptr[id - 1];
+ else
+ ptr = NULL;
rcu_read_unlock();
return ptr;
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -111,6 +111,7 @@ static int ops_init(const struct pernet_operations *ops, struct net *net)
return 0;
cleanup:
+ net_assign_generic(net, *ops->id, NULL);
kfree(data);
out:
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -927,6 +927,9 @@ static void nfqnl_nf_hook_drop(struct net *net, struct nf_hook_ops *hook)
struct nfnl_queue_net *q = nfnl_queue_pernet(net);
int i;
+ if (!q)
+ return;
+
rcu_read_lock();
for (i = 0; i < INSTANCE_BUCKETS; i++) {
struct nfqnl_instance *inst;
What do you think?
next prev parent reply other threads:[~2016-05-13 20:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-11 15:41 [PATCH nf V2] netfilter: fix oops in nfqueue during netns error unwinding Florian Westphal
2016-05-12 9:47 ` Pablo Neira Ayuso
2016-05-12 16:15 ` Eric W. Biederman
2016-05-12 16:40 ` Florian Westphal
2016-05-13 19:40 ` Eric W. Biederman
2016-05-13 20:04 ` Florian Westphal [this message]
2016-05-13 20:26 ` Eric W. Biederman
2016-05-13 21:07 ` Florian Westphal
2016-05-13 20:44 ` Eric W. Biederman
2016-05-13 21:20 ` Florian Westphal
2016-05-14 0:58 ` Eric W. Biederman
2016-05-14 10:33 ` Florian Westphal
2016-05-15 3:00 ` Eric W. Biederman
2016-05-14 2:18 ` [PATCH] nf_queue: Make the queue_handler pernet Eric W. Biederman
2016-05-30 9:31 ` 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=20160513200442.GA29941@breakpoint.cc \
--to=fw@strlen.de \
--cc=dale.4d@gmail.com \
--cc=ebiederm@xmission.com \
--cc=netdev@vger.kernel.org \
--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).