netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gao feng <gaofeng@cn.fujitsu.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH v2] netfilter: bridge: unshare bridge info before change it
Date: Thu, 20 Nov 2014 09:16:12 +0800	[thread overview]
Message-ID: <546D40DC.6060505@cn.fujitsu.com> (raw)
In-Reply-To: <20141119130751.GA10748@salvia>

On 11/19/2014 09:07 PM, Pablo Neira Ayuso wrote:
> 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.
> 

overwrite is what we expected, we store the original nfbridge in the var
nf_bridge, copy the original to the new. and release the reference of original
nfbridge. I cannot find anything wrong.

>> +
>> +		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;
>> +}
> 


  parent reply	other threads:[~2014-11-20  1:16 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 ` [PATCH v2] netfilter: bridge: unshare bridge info before change it Pablo Neira Ayuso
2014-11-19 13:32   ` Pablo Neira Ayuso
2014-11-20  1:22     ` Gao feng
2014-11-20  1:16   ` Gao feng [this message]
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=546D40DC.6060505@cn.fujitsu.com \
    --to=gaofeng@cn.fujitsu.com \
    --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).