All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org, Holger Assmann <has@pengutronix.de>
Subject: Re: [PATCH master v2] nv: fix use-after-free when clearing from shell
Date: Fri, 13 Nov 2020 08:37:18 +0100	[thread overview]
Message-ID: <20201113073718.GP29830@pengutronix.de> (raw)
In-Reply-To: <20201112172524.1293-1-a.fatoum@pengutronix.de>

On Thu, Nov 12, 2020 at 06:25:24PM +0100, Ahmad Fatoum wrote:
> When we use hush to set the same nv.var twice to the empty string:
> 
>   $ nv.user=
>   $ nv.user=
> 
> nv_set is called twice with a NULL val argument leading
> to a double free and accompanied memory corruption.
> 
> Reorder the code, so p->value is freed just once.
> 
> Fixes: fa4c41ba60af ("nvvar: when setting a nvvar to NULL just free the content")
> Cc: Holger Assmann <has@pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
>   Use correct author email in DCO
> ---
>  common/globalvar.c | 12 ++++--------
>  1 file changed, 4 insertions(+), 8 deletions(-)

Took this one instead of v1

Sascha

> 
> diff --git a/common/globalvar.c b/common/globalvar.c
> index 60793d7a30c6..a55b38b00fd5 100644
> --- a/common/globalvar.c
> +++ b/common/globalvar.c
> @@ -179,16 +179,12 @@ static int nv_set(struct device_d *dev, struct param_d *p, const char *name, con
>  {
>  	int ret;
>  
> -	if (!val) {
> -		if (p)
> -			free(p->value);
> -		return 0;
> +	if (val) {
> +		ret = dev_set_param(&global_device, name, val);
> +		if (ret)
> +			return ret;
>  	}
>  
> -	ret = dev_set_param(&global_device, name, val);
> -	if (ret)
> -		return ret;
> -
>  	if (p) {
>  		free(p->value);
>  		p->value = xstrdup(val);
> -- 
> 2.28.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2020-11-13  7:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 17:25 [PATCH master v2] nv: fix use-after-free when clearing from shell Ahmad Fatoum
2020-11-13  7:37 ` Sascha Hauer [this message]

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=20201113073718.GP29830@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=has@pengutronix.de \
    /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.