All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Pawel Moll <pawel.moll@arm.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	Olof Johansson <olof@lixom.net>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Lee Jones <lee.jones@linaro.org>,
	Samuel Ortiz <sameo@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>
Subject: Re: [patch v2] mfd: vexpress: fix error handling vexpress_syscfg_regmap_init()
Date: Fri, 13 Jun 2014 14:02:46 +0000	[thread overview]
Message-ID: <201406131602.46893.arnd@arndb.de> (raw)
In-Reply-To: <1402482800.3523.20.camel@hornet>

On Wednesday 11 June 2014, Pawel Moll wrote:
> On Wed, 2014-06-11 at 11:17 +0100, Dan Carpenter wrote:
> > This function should be returning an ERR_PTR() on failure instead of
> > NULL.  Also there is a use after free bug if regmap_init() fails because
> > we free "func" and then dereference doing the return.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/misc/vexpress-syscfg.c b/drivers/misc/vexpress-syscfg.c
> > index 73068e5..3250fc1 100644
> > --- a/drivers/misc/vexpress-syscfg.c
> > +++ b/drivers/misc/vexpress-syscfg.c
> > @@ -199,7 +199,7 @@ static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
> >       func = kzalloc(sizeof(*func) + sizeof(*func->template) * num,
> >                       GFP_KERNEL);
> >       if (!func)
> > -             return NULL;
> > +             return ERR_PTR(-ENOMEM);
> >  
> >       func->syscfg = syscfg;
> >       func->num_templates = num;
> > @@ -231,10 +231,14 @@ static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
> >       func->regmap = regmap_init(dev, NULL, func,
> >                       &vexpress_syscfg_regmap_config);
> >  
> > -     if (IS_ERR(func->regmap))
> > +     if (IS_ERR(func->regmap)) {
> > +             void *err = func->regmap;
> > +
> >               kfree(func);
> > -     else
> > -             list_add(&func->list, &syscfg->funcs);
> > +             return err;
> > +     }
> > +
> > +     list_add(&func->list, &syscfg->funcs);
> >  
> >       return func->regmap;
> >  }
> 
> Uh, right. Dereferencing a freed structure. My bad. Thanks for spotting
> this!
> 
> Acked-by: Pawel Moll <pawel.moll@arm.com>
> 
> (nit: the subject should be "misc: vexpress:" rather then "mfd:")
> 
> Arnd, Olof, can you pick this one as an early fix or do you want me to
> queue it for rc1-based fixes branch?

I've applied it to the fixes branch now. Thanks!

	Arnd

WARNING: multiple messages have this Message-ID (diff)
From: Arnd Bergmann <arnd@arndb.de>
To: Pawel Moll <pawel.moll@arm.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
	Olof Johansson <olof@lixom.net>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	Lee Jones <lee.jones@linaro.org>,
	Samuel Ortiz <sameo@linux.intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kernel-janitors@vger.kernel.org"
	<kernel-janitors@vger.kernel.org>
Subject: Re: [patch v2] mfd: vexpress: fix error handling vexpress_syscfg_regmap_init()
Date: Fri, 13 Jun 2014 16:02:46 +0200	[thread overview]
Message-ID: <201406131602.46893.arnd@arndb.de> (raw)
In-Reply-To: <1402482800.3523.20.camel@hornet>

On Wednesday 11 June 2014, Pawel Moll wrote:
> On Wed, 2014-06-11 at 11:17 +0100, Dan Carpenter wrote:
> > This function should be returning an ERR_PTR() on failure instead of
> > NULL.  Also there is a use after free bug if regmap_init() fails because
> > we free "func" and then dereference doing the return.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/misc/vexpress-syscfg.c b/drivers/misc/vexpress-syscfg.c
> > index 73068e5..3250fc1 100644
> > --- a/drivers/misc/vexpress-syscfg.c
> > +++ b/drivers/misc/vexpress-syscfg.c
> > @@ -199,7 +199,7 @@ static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
> >       func = kzalloc(sizeof(*func) + sizeof(*func->template) * num,
> >                       GFP_KERNEL);
> >       if (!func)
> > -             return NULL;
> > +             return ERR_PTR(-ENOMEM);
> >  
> >       func->syscfg = syscfg;
> >       func->num_templates = num;
> > @@ -231,10 +231,14 @@ static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
> >       func->regmap = regmap_init(dev, NULL, func,
> >                       &vexpress_syscfg_regmap_config);
> >  
> > -     if (IS_ERR(func->regmap))
> > +     if (IS_ERR(func->regmap)) {
> > +             void *err = func->regmap;
> > +
> >               kfree(func);
> > -     else
> > -             list_add(&func->list, &syscfg->funcs);
> > +             return err;
> > +     }
> > +
> > +     list_add(&func->list, &syscfg->funcs);
> >  
> >       return func->regmap;
> >  }
> 
> Uh, right. Dereferencing a freed structure. My bad. Thanks for spotting
> this!
> 
> Acked-by: Pawel Moll <pawel.moll@arm.com>
> 
> (nit: the subject should be "misc: vexpress:" rather then "mfd:")
> 
> Arnd, Olof, can you pick this one as an early fix or do you want me to
> queue it for rc1-based fixes branch?

I've applied it to the fixes branch now. Thanks!

	Arnd

  parent reply	other threads:[~2014-06-13 14:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-11  6:07 [patch] mfd: vexpress: use after free in vexpress_syscfg_regmap_init() Dan Carpenter
2014-06-11  6:07 ` Dan Carpenter
2014-06-11  9:22 ` Pawel Moll
2014-06-11  9:22   ` Pawel Moll
2014-06-11 10:07   ` Dan Carpenter
2014-06-11 10:07     ` Dan Carpenter
2014-06-11 10:17   ` [patch v2] mfd: vexpress: fix error handling vexpress_syscfg_regmap_init() Dan Carpenter
2014-06-11 10:17     ` Dan Carpenter
2014-06-11 10:33     ` Pawel Moll
2014-06-11 10:33       ` Pawel Moll
2014-06-11 17:12       ` Greg Kroah-Hartman
2014-06-11 17:12         ` Greg Kroah-Hartman
2014-06-11 17:11         ` Pawel Moll
2014-06-11 17:11           ` Pawel Moll
2014-06-13 14:02       ` Arnd Bergmann [this message]
2014-06-13 14:02         ` Arnd Bergmann

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=201406131602.46893.arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=dan.carpenter@oracle.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olof@lixom.net \
    --cc=pawel.moll@arm.com \
    --cc=sameo@linux.intel.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 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.