Netdev List
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@vyatta.com>
To: Jeff Hansen <x@jeffhansen.com>
Cc: netdev@vger.kernel.org, jeff@jeffhansen.com,
	Dave Miller <davem@davemloft.net>, Jeff Hansen <x@jeffhansen.com>
Subject: Re: [PATCH] [bridge] Fix double-free in br_add_if.
Date: Fri, 25 Sep 2009 14:33:08 -0700	[thread overview]
Message-ID: <20090925143308.7f38227d@s6510> (raw)
In-Reply-To: <1253910324-19006-1-git-send-email-x@jeffhansen.com>

On Fri, 25 Sep 2009 14:25:24 -0600
Jeff Hansen <x@jeffhansen.com> wrote:

> There is a potential double-kfree in net/bridge/br_if.c.  If br_fdb_insert
> fails, then the kobject is put back (which calls kfree due to the kobject
> release), and then kfree is called again on the net_bridge_port.  This
> patch fixes the crash.
> 
> Signed-off-by: Jeff Hansen <x@jeffhansen.com>
> ---
>  net/bridge/br_if.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
> index eb404dc..1becec1 100644
> --- a/net/bridge/br_if.c
> +++ b/net/bridge/br_if.c
> @@ -368,7 +368,7 @@ done:
>  int br_add_if(struct net_bridge *br, struct net_device *dev)
>  {
>  	struct net_bridge_port *p;
> -	int err = 0;
> +	int err = 0, kobj_initted = 0;
>  
>  	if (dev->flags & IFF_LOOPBACK || dev->type != ARPHRD_ETHER)
>  		return -EINVAL;
> @@ -391,6 +391,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev)
>  				   SYSFS_BRIDGE_PORT_ATTR);
>  	if (err)
>  		goto err0;
> +	kobj_initted = 1;
>  
>  	err = br_fdb_insert(br, p, dev->dev_addr);
>  	if (err)
> @@ -429,7 +430,8 @@ err0:
>  	dev_set_promiscuity(dev, -1);
>  put_back:
>  	dev_put(dev);
> -	kfree(p);
> +	if (!kobj_initted)
> +		kfree(p);
>  	return err;
>  }
>  

I'll look at it, probably needs fixing, but the code style with condition
variables is out of place in this code.

           reply	other threads:[~2009-09-25 21:33 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <1253910324-19006-1-git-send-email-x@jeffhansen.com>]

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=20090925143308.7f38227d@s6510 \
    --to=shemminger@vyatta.com \
    --cc=davem@davemloft.net \
    --cc=jeff@jeffhansen.com \
    --cc=netdev@vger.kernel.org \
    --cc=x@jeffhansen.com \
    /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