From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Gao feng <gaofeng@cn.fujitsu.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH v2] netfilter: bridge: unshare bridge info before change it
Date: Wed, 19 Nov 2014 14:07:51 +0100 [thread overview]
Message-ID: <20141119130751.GA10748@salvia> (raw)
In-Reply-To: <1416366453-12090-1-git-send-email-gaofeng@cn.fujitsu.com>
On Wed, Nov 19, 2014 at 11:07:32AM +0800, Gao feng wrote:
> diff --git a/include/linux/netfilter_bridge.h b/include/linux/netfilter_bridge.h
> index c755e49..dca7337 100644
> --- a/include/linux/netfilter_bridge.h
> +++ b/include/linux/netfilter_bridge.h
> @@ -81,14 +81,64 @@ static inline unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb)
> return 0;
> }
>
> +static inline struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
> +{
> + skb->nf_bridge = kzalloc(sizeof(struct nf_bridge_info), GFP_ATOMIC);
> + if (likely(skb->nf_bridge))
> + atomic_set(&(skb->nf_bridge->use), 1);
> +
> + return skb->nf_bridge;
> +}
> +
> +static inline struct nf_bridge_info *nf_bridge_unshare(struct sk_buff *skb)
> +{
> + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
> +
> + if (atomic_read(&nf_bridge->use) > 1) {
> + struct nf_bridge_info *tmp = nf_bridge_alloc(skb);
nf_bridge_alloc() overwrites the original skb->nf_bridge when
unsharing, so this leaks and likely breaks other things.
> +
> + if (tmp) {
> + memcpy(tmp, nf_bridge, sizeof(struct nf_bridge_info));
> + atomic_set(&tmp->use, 1);
> + }
> + nf_bridge_put(nf_bridge);
> + nf_bridge = tmp;
> + }
> + return nf_bridge;
> +}
next prev parent reply other threads:[~2014-11-19 13:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-19 3:07 [PATCH v2] netfilter: bridge: unshare bridge info before change it Gao feng
2014-11-19 3:07 ` [PATCH] use NF_BR_PRI_BRNF in NF_HOOK_THRESH Gao feng
2014-11-19 13:35 ` Pablo Neira Ayuso
2014-11-19 13:07 ` Pablo Neira Ayuso [this message]
2014-11-19 13:32 ` [PATCH v2] netfilter: bridge: unshare bridge info before change it Pablo Neira Ayuso
2014-11-20 1:22 ` Gao feng
2014-11-20 1:16 ` Gao feng
2014-11-20 11:42 ` 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=20141119130751.GA10748@salvia \
--to=pablo@netfilter.org \
--cc=gaofeng@cn.fujitsu.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.