From: Patrick McHardy <kaber@trash.net>
To: Florian Westphal <fw@strlen.de>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 1/1] netfilter: nat: work around shared nfct struct in bridge case
Date: Tue, 30 Aug 2011 15:44:11 +0200 [thread overview]
Message-ID: <4E5CE92B.2010006@trash.net> (raw)
In-Reply-To: <1314710938-25342-1-git-send-email-fw@strlen.de>
On 30.08.2011 15:28, Florian Westphal wrote:
> diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
> index 9c71b27..bd89744 100644
> --- a/net/ipv4/netfilter/nf_nat_core.c
> +++ b/net/ipv4/netfilter/nf_nat_core.c
> @@ -265,6 +265,35 @@ out:
> rcu_read_unlock();
> }
>
> +/* bridge netfilter uses cloned skbs when forwarding to multiple bridge ports.
> + * when userspace queueing is involved, we might try to set up NAT bindings
> + * on the same conntrack simultaneoulsy. Can happen e.g. when broadcast has
> + * to be forwarded by the bridge but is also passed up the stack.
> + *
> + * Thus, when bridge netfilter is enabled, we need to serialize and silently
> + * accept the packet in the collision case.
> + */
> +static inline bool nf_nat_bridge_lock(struct nf_conn *ct, enum nf_nat_manip_type maniptype)
> +{
> +#ifdef CONFIG_BRIDGE_NETFILTER
> + spin_lock_bh(&ct->lock);
> +
> + if (unlikely(nf_nat_initialized(ct, maniptype))) {
> + pr_debug("race with cloned skb? Not adding NAT extension\n");
> + spin_unlock_bh(&ct->lock);
> + return false;
> + }
> +#endif
> + return true;
> +}
Ugh, what beauty :) I can't see a much nicer way how to fix this right
now, but I really want to have another look for different possibilities
before applying this.
Unfortunately pushing this down to nf_nat_setup_info() could only fix
the BUG(), but we'd still have a possible memory leak when adding the
NAT extension simulaneously on multiple CPUs. I also fear this is not
going to be the only problem caused by breaking the "unconfirmed means
non-shared nfct" assumption.
> +
> +static inline void nf_nat_bridge_unlock(struct nf_conn *ct)
> +{
> +#ifdef CONFIG_BRIDGE_NETFILTER
> + spin_unlock_bh(&ct->lock);
> +#endif
> +}
> +
> unsigned int
> nf_nat_setup_info(struct nf_conn *ct,
> const struct nf_nat_range *range,
> @@ -274,18 +303,23 @@ nf_nat_setup_info(struct nf_conn *ct,
> struct nf_conntrack_tuple curr_tuple, new_tuple;
> struct nf_conn_nat *nat;
>
> + NF_CT_ASSERT(maniptype == IP_NAT_MANIP_SRC ||
> + maniptype == IP_NAT_MANIP_DST);
> +
> + if (!nf_nat_bridge_lock(ct, maniptype))
> + return NF_ACCEPT;
> +
> /* nat helper or nfctnetlink also setup binding */
> nat = nfct_nat(ct);
> if (!nat) {
> nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC);
> if (nat == NULL) {
> + nf_nat_bridge_unlock(ct);
> pr_debug("failed to add NAT extension\n");
> return NF_ACCEPT;
> }
> }
>
> - NF_CT_ASSERT(maniptype == IP_NAT_MANIP_SRC ||
> - maniptype == IP_NAT_MANIP_DST);
> BUG_ON(nf_nat_initialized(ct, maniptype));
>
> /* What we've got will look like inverse of reply. Normally
> @@ -332,6 +366,7 @@ nf_nat_setup_info(struct nf_conn *ct,
> else
> ct->status |= IPS_SRC_NAT_DONE;
>
> + nf_nat_bridge_unlock(ct);
> return NF_ACCEPT;
> }
> EXPORT_SYMBOL(nf_nat_setup_info);
next prev parent reply other threads:[~2011-08-30 13:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-30 13:28 [PATCH 1/1] netfilter: nat: work around shared nfct struct in bridge case Florian Westphal
2011-08-30 13:44 ` Patrick McHardy [this message]
2011-08-30 14:00 ` Florian Westphal
2011-08-30 14:07 ` Patrick McHardy
2011-08-30 15:27 ` Florian Westphal
2011-08-31 10:05 ` Patrick McHardy
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=4E5CE92B.2010006@trash.net \
--to=kaber@trash.net \
--cc=fw@strlen.de \
--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).